<?php /** * Klasa Google PageRank * * Klasa pobiera PR dla podenego adresu URL, z google.com (domy�lny DC) lub z podanych DC * * @author nieznany * @modyfications Piotr 'shpyo' Cichosz * @version 1.0 2007/06/04 */ class googlePageRank { /** * Pole $googleMagic * * Stała dana Google */ var $googleMagic = 0xE6359A60; /** * Pole $arrResults * * Tablica z DC, na których będzie sprawdzany PR */ /** * Konstruktor * * Pobieranie PR na podanych DC */ { $strQuery = 'info:'.$resUrl; $ch = $this->GoogleCH( $this->strord( $strQuery ) ); { $resUrl = "http://".$arrDC[$i]."/search?client=navclient-auto&ch=6$ch&features=Rank&q=$strQuery"; $this->arrResults[$i]['dc'] = $arrDC[$i]; $this->arrResults[$i]['pagerank'] = $rankarray[2]; } } /** * Metoda GoogleCH * * Tworzenie sumy kontrolnej dla sprawdzanego URL */ function GoogleCH( $resUrl ) { $a = $b = 0x9E3779B9; $c = $this->googleMagic; $k = 0; $len = $length; while($len >= 12) { $a += ($resUrl[$k+0] +($resUrl[$k+1]<<8) +($resUrl[$k+2]<<16) +($resUrl[$k+3]<<24)); $b += ($resUrl[$k+4] +($resUrl[$k+5]<<8) +($resUrl[$k+6]<<16) +($resUrl[$k+7]<<24)); $c += ($resUrl[$k+8] +($resUrl[$k+9]<<8) +($resUrl[$k+10]<<16)+($resUrl[$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) { case 11: $c+=($resUrl[$k+10]<<24); case 10: $c+=($resUrl[$k+9]<<16); case 9 : $c+=($resUrl[$k+8]<<8); case 8 : $b+=($resUrl[$k+7]<<24); case 7 : $b+=($resUrl[$k+6]<<16); case 6 : $b+=($resUrl[$k+5]<<8); case 5 : $b+=($resUrl[$k+4]); case 4 : $a+=($resUrl[$k+3]<<24); case 3 : $a+=($resUrl[$k+2]<<16); case 2 : $a+=($resUrl[$k+1]<<8); case 1 : $a+=($resUrl[$k+0]); } $mix = $this->mix($a,$b,$c); return $mix[2]; } function zeroFill($a, $b) { 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 ^= ($this->zeroFill($c,13)); $b -= $c; $b -= $a; $b ^= ($a<<8); $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,13)); $a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,12)); $b -= $c; $b -= $a; $b ^= ($a<<16); $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,5)); $a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,3)); $b -= $c; $b -= $a; $b ^= ($a<<10); $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,15)); } /** * Metoda strord * * Zamienia każdy znak adresu URL na ASCII */ function strord($strUrl) { for($i=0;$i<strlen($strUrl);$i++) { $arrResult[$i] = ord($strUrl[$i]); } return $arrResult; } } ?>
Przykład użycia:
<?php //definiowanie tablicy z DC, na których będzie sprawdzany PR /*$arrDC[0] = "64.233.161.99"; $arrDC[1] = "64.233.161.104"; $arrDC[2] = "64.233.163.99"; $arrDC[3] = "216.239.57.99"; $arrDC[4] = "66.102.11.107";*/ if( $_GET['url'] ) { //tworzenie obiektu googlePageRank $intPR = new googlePageRank( $_GET['url']/*, $arrDC*/ ); //wydruk pobranych danych } ?>
Komentarze mile widziane

Na forum jak i na moim blogu: http://blog.shpyo.net/?newsID=51
