Kompletna klasa do Google
Zniknal tylko RealPageRank (Zawsze = 0).
Testy na
www.pc2.pl LOGIN: DEMO HASLO: DEMO123
Klasa została wykorzystana na w/w stronie w: Słowa kluczowe, Podstrony, Adresy referencyjne.
Funkcja getrealrank wymaga PHP5, pozostałe chodza na PHP4. getrealrank mozna sobie odpuscic.
<?
define("GOOGLE_MAGIC", 0xE6359A60
);
class GOOGLE {
public function google_pozycja_strony($strona,$zapytanie)
{
$sLinkRegExp = '/<h2 class=r><a href="([^"]+)" class=l>/';
$sURLTpl = 'http://www.google.pl/search?hl=pl&q=%s&num=100';
$sQ = $zapytanie;
$sSite = $strona;
$rC = curl_init();
curl_setopt($rC, CURLOPT_HEADER, 0);
curl_setopt($rC, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rC, CURLOPT_VERBOSE, 1);
curl_setopt($rC, CURLOPT_REFERER, 'www.google.pl');
$sData = curl_exec($rC);
curl_close($rC);
$iPosition = '-';
foreach($aResults as $iKey => $sRow)
{
{
$iPosition = $iKey + 1;
}
}
if ($iPosition != '-' && $iPosition != '0') return "<font color='#FFFF00'>Pozycja GOOGLE ".($iPosition-1)."</font>";
else return "<font color='#FFFF00'>-</font>";
}
private function zeroFill($a, $b)
{
if ($z & $a)
{
$a = ($a>>1);
$a &= (~$z);
$a |= 0x40000000;
$a = ($a>>($b-1));
}
else
{
$a = ($a>>$b);
}
return $a;
}
private function toInt32(& $x)
{
$y = (int)$x;
if($y==-$z&&$x<-$z)
{
$y = (int)((-1)*$x);// this is the hack, make it positive before
$y = (-1)*$y; // switch back the sign
}
$x = $y;
}
private function mix($a,$b,$c)
{
$a -= $b; $a -= $c; $this -> toInt32($a); $a = (int)($a ^ ($this -> zeroFill($c,13)));
$b -= $c; $b -= $a; $this -> toInt32($b); $b = (int)($b ^ ($a<<8));
$c -= $a; $c -= $b; $this -> toInt32($c); $c = (int)($c ^ ($this -> zeroFill($b,13)));
$a -= $b; $a -= $c; $this -> toInt32($a); $a = (int)($a ^ ($this -> zeroFill($c,12)));
$b -= $c; $b -= $a; $this -> toInt32($b); $b = (int)($b ^ ($a<<16));
$c -= $a; $c -= $b; $this -> toInt32($c); $c = (int)($c ^ ($this -> zeroFill($b,5)));
$a -= $b; $a -= $c; $this -> toInt32($a); $a = (int)($a ^ ($this -> zeroFill($c,3)));
$b -= $c; $b -= $a; $this -> toInt32($b); $b = (int)($b ^ ($a<<10));
$c -= $a; $c -= $b; $this -> toInt32($c); $c = (int)($c ^ ($this -> zeroFill($b,15)));
}
private function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC)
{
{
}
$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 = $this -> 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);
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]);
}
$mix = $this -> mix($a,$b,$c);
return $mix[2];
}
private function strord($string)
{
for($i=0;$i<strlen($string);$i++)
{
$result[$i] = ord($string{$i});
}
return $result;
}
private function getrank($url, $prefix="info:", $datacenter="www.google.pl")
{
$url = $prefix.$url;
$ch = $this -> GoogleCH($this -> strord($url));
$file = "http://$datacenter/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url";
if(!$data || preg_match("/(.*).(.*)/i", $url)==0
) return "N/A"; $rankarray = explode (":", $data[2
]); $rank = trim($rankarray[2
]); if($rank=="") return "N/A";
return $rank;
}
private function getrealrank($url, $datacenter="www.google.pl")
{
$url = "info:".$url;
$ch = $this -> GoogleCH($this -> strord($url));
$file = "http://$datacenter/search?client=navclient-auto&ch=6$ch&q=$url";
//echo $file."<br />";
$tekst = ""; foreach ($data as $row) { $tekst .= $row."n"; }
$Iterator = new SimpleXMLIterator($tekst);
$Iterator->rewind();
$infoarray = $Iterator -> RES;
$urlpermutationsarray = array($url, "http://".$url,
"http://www.".$url, $url."/",
"http://".$url."/",
"http://www.".$url."/",
$nonwwwurl,
"http://".$nonwwwurl,
"http://www.".$nonwwwurl,
$nonwwwurl."/",
"http://".$nonwwwurl."/",
"http://www.".$nonwwwurl."/");
for($i=0; $i<count($infoarray); $i++)
{
$urlU = $infoarray -> R[$i] -> U;
//echo $urlU."<br />";
$urlrank = $infoarray -> R[$i] -> RK;
//echo $urlrank."<br />";
foreach($urlpermutationsarray as $permutation){ if(strtolower($permutation)==strtolower($urlU)) return $urlrank; } }
return "-";
}
public function bierz_page_rank ($url)
{
$zz = $z['host'].$z['path'];
$zz1 = $z['host'];
if ($zz)
{
$rank1 = $this -> getrank($zz);
$rank2 = $this -> getrank($zz1);
$rank3 = $this -> getrealrank($zz);
$rank4 = $this -> getrealrank($zz1);
return "<font color='#FFFF00'>Google Page Ranking:".$rank1."(".$rank3."),".$rank2."(".$rank4.")</font>";
}
else return "";
}
}
$GOOGLE = new GOOGLE;
?>