GooglePR

Spear

почемучка
не знаю, актуально это или уже нет, но вот вам код, который показывает гуглевский PR нужного сайта.
Адрес сайта передавать параметром url=http://www.site.com
www - обязательно.

here goes...:

PHP:
<?
define('GOOGLE_MAGIC', 0xE6359A60);

//unsigned shift right
function zeroFill($a, $b)
{
$z = hexdec(80000000);
if ($z & $a)
{
$a = ($a>>1);
$a &= (~$z);
$a |= 0x40000000;
$a = ($a>>($b-1));
}
else
{
$a = ($a>>$b);
}
return $a;
}

function mix($a,$b,$c) {
$a -= $b; $a -= $c; $a ^= (zeroFill($c,13));
$b -= $c; $b -= $a; $b ^= ($a<<8);
$c -= $a; $c -= $b; $c ^= (zeroFill($b,13));
$a -= $b; $a -= $c; $a ^= (zeroFill($c,12));
$b -= $c; $b -= $a; $b ^= ($a<<16);
$c -= $a; $c -= $b; $c ^= (zeroFill($b,5));
$a -= $b; $a -= $c; $a ^= (zeroFill($c,3)); 
$b -= $c; $b -= $a; $b ^= ($a<<10);
$c -= $a; $c -= $b; $c ^= (zeroFill($b,15));

return array($a,$b,$c);
}

function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
if(is_null($length)) {
$length = sizeof($url);
}
$a = $b = 0x9E3779B9;
$c = $init;
$k = 0;
$len = $length;
while($len >= 12) {
$a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
$b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
$c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
$mix = mix($a,$b,$c);
$a = $mix[0]; $b = $mix[1]; $c = $mix[2];
$k += 12;
$len -= 12;
}

$c += $length;
switch($len) /* all the case statements fall through */
{
case 11: $c+=($url[$k+10]<<24);
case 10: $c+=($url[$k+9]<<16);
case 9 : $c+=($url[$k+8]<<8);
/* the first byte of c is reserved for the length */
case 8 : $b+=($url[$k+7]<<24);
case 7 : $b+=($url[$k+6]<<16);
case 6 : $b+=($url[$k+5]<<8);
case 5 : $b+=($url[$k+4]);
case 4 : $a+=($url[$k+3]<<24);
case 3 : $a+=($url[$k+2]<<16);
case 2 : $a+=($url[$k+1]<<8);
case 1 : $a+=($url[$k+0]);
/* case 0: nothing left to add */
}
$mix = mix($a,$b,$c);
/*-------------------------------------------- report the result */
return $mix[2];
}

//converts a string into an array of integers containing the numeric value of the char
function strord($string) {
for($i=0;$i<strlen($string);$i++) {
$result[$i] = ord($string{$i});
}
return $result;
}

function get_pr($url) {
$result=array("",-1);

if (($url.""!="")&&($url.""!="http://")):
// check for protocol 
if (substr(strtolower($url),0,7)!="http://"):
$url="http://".$url;
endif;

$url="info:".$url;
$checksum=GoogleCH(strord($url));
$google_url=sprintf("http://www.google.com/search?client=navclient-auto&ch=6%u&features=Rank&q=".$url,$checksum); // url to get from google 

$contents="";

$handle = fopen($google_url, "rb");
$contents = '';
while (!feof($handle)) {
  $contents.= fread($handle, 8192);
}
fclose($handle);
$p=explode(":",$contents);
if (isset($p[2])):
$result[1]=$p[2];
endif;
endif;

return $result;
}

function getPR_url($url)
{
  global $db;

  if (eregi('^http://www.',$url)) {
   $url_www = str_replace('http://www.','http://',$url);
  } else {
   $url_www = str_replace('http://','http://www.',$url);
  }

  $pr=get_pr($url);
  $output=$pr[0];
  $pagerank=$pr[1];
  sleep(1);
  $pr=get_pr($url_www);
  $output_www=$pr[0];
  $pagerank_www=$pr[1];

  if ($pagerank<$pagerank_www) {
   $pagerank=$pagerank_www;
  }
  if ($pagerank==-1) {
   $pagerank=0;
  }
 return intval($pagerank);
}
echo $_GET['url'].' '.getPR_url($_GET['url']);
?>
 

SiMM

Новичок
> не знаю, актуально это или уже нет, но вот вам код, который показывает гуглевский PR нужного сайта.
А кому он был нужен в этой теме?
 

Юзер

Новичок
Дополнение
PHP:
if (!isset($_GET['url'])) 
{ 
    $url_o   = $_SERVER['HTTP_REFERER'];  
} 
else 
{ 
    $url_o   = $_GET['url']; 
} 

$url_o = explode("?", $url_o); 
$url_o = $url_o[0]; 

$url    = 'info:'.$url_o; 
$ch     = GoogleCH(strord($url));  
$url    ='info:'.urlencode($url_o); 
$result = @file_get_contents("http://toolbarqueries.google.com/search?client=navclient-auto&ch=6$ch&ie=UTF-8&oe=UTF-8&features=Rank&q=$url"); 
$tmp    = @explode(":", $result); 
$rank   = intval($tmp[2]); 

//header("Content-type: image/png"); 
  
$style = isset($_GET['style']) ? 1 : intval($_GET['style']); 
$im    = $style == 1 ? imagecreate(47,17) : imagecreate(68,17); 

// define colors 
$co_white = ImageColorAllocateHEX($im, "#FFFFFF"); 
$co_gray  = ImageColorAllocateHEX($im, "#F3F3F3"); 
$co_black = ImageColorAllocateHEX($im, "#000000"); 
$co_dark  = ImageColorAllocateHEX($im, "#999999"); 
$co_red   = ImageColorAllocateHEX($im, "#FF0000"); 
$co_green = ImageColorAllocateHEX($im, "#5EAA5E"); 
$co_blue  = ImageColorAllocateHEX($im, "#FF3300"); 

// create image 
$im_dst   = imagecreatefrompng("pagerank.png"); 
ImageColorTransparent($im_dst, $co_white); 
imagecopy ( $im, $im_dst, 2, 1, 0, 0, 43, 9); 
imagedestroy($im_dst); 
ImageRectangle($im, 2, 11, 43, 15, $co_dark); 
imagefilledrectangle ( $im, 3, 12, 3 + $rank * 4, 14, $co_green); 
imagestring ($im, 5, 50, 3, $rank, $co_green); 
imagepng($im); 
imagedestroy($im); 


function ImageColorAllocateHEX($im,$s){ 
   if ($s[0]=="#") $s=substr($s,1); 
   $bg_dec=hexdec($s); 
   return imagecolorallocate($im, 
               ($bg_dec & 0xFF0000) >> 16, 
               ($bg_dec & 0x00FF00) >>  8, 
               ($bg_dec & 0x0000FF) 
               ); 
}
PR - в image
 

Camillo

Новичок
Интересный скриптец.
Тему в букмарк однозначно.

Спасибо.
 
Сверху