1 | <?php
|
---|
2 | /******************
|
---|
3 |
|
---|
4 | ******************/
|
---|
5 |
|
---|
6 | define('GOOGLE_MAGIC', 0xE6359A60);
|
---|
7 |
|
---|
8 | class ODLPagerank extends PageRank {
|
---|
9 | function xor32($a, $b) {
|
---|
10 | return $this->int32($a) ^ $this->int32($b);
|
---|
11 | }
|
---|
12 | function int32($x) {
|
---|
13 | return unserialize("i:$x;");
|
---|
14 | }
|
---|
15 |
|
---|
16 | function mix($a,$b,$c) {
|
---|
17 | $a -= $b; $a -= $c; $a = $this->xor32($a,$this->zeroFill($c,13));
|
---|
18 | $b -= $c; $b -= $a; $b = $this->xor32($b,$a<<8);
|
---|
19 | $c -= $a; $c -= $b; $c = $this->xor32($c,$this->zeroFill($b,13));
|
---|
20 | $a -= $b; $a -= $c; $a = $this->xor32($a,$this->zeroFill($c,12));
|
---|
21 | $b -= $c; $b -= $a; $b = $this->xor32($b,$a<<16);
|
---|
22 | $c -= $a; $c -= $b; $c = $this->xor32($c,$this->zeroFill($b,5));
|
---|
23 | $a -= $b; $a -= $c; $a = $this->xor32($a,$this->zeroFill($c,3));
|
---|
24 | $b -= $c; $b -= $a; $b = $this->xor32($b,$a<<10);
|
---|
25 | $c -= $a; $c -= $b; $c = $this->xor32($c,$this->zeroFill($b,15));
|
---|
26 | return array($a,$b,$c);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | class PageRank {
|
---|
31 | function zeroFill($a, $b){
|
---|
32 | $z = hexdec(80000000);
|
---|
33 | if ($z & $a){
|
---|
34 | $a = ($a>>1);
|
---|
35 | $a &= (~$z);
|
---|
36 | $a |= 0x40000000;
|
---|
37 | $a = ($a>>($b-1));
|
---|
38 | }else{
|
---|
39 | $a = ($a>>$b);
|
---|
40 | }
|
---|
41 | return $a;
|
---|
42 | }
|
---|
43 |
|
---|
44 | function mix($a,$b,$c) {
|
---|
45 | $a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,13));
|
---|
46 | $b -= $c; $b -= $a; $b ^= ($a<<8);
|
---|
47 | $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,13));
|
---|
48 | $a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,12));
|
---|
49 | $b -= $c; $b -= $a; $b ^= ($a<<16);
|
---|
50 | $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,5));
|
---|
51 | $a -= $b; $a -= $c; $a ^= ($this->zeroFill($c,3));
|
---|
52 | $b -= $c; $b -= $a; $b ^= ($a<<10);
|
---|
53 | $c -= $a; $c -= $b; $c ^= ($this->zeroFill($b,15));
|
---|
54 | return array($a,$b,$c);
|
---|
55 | }
|
---|
56 |
|
---|
57 | function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
|
---|
58 | if(is_null($length)) {
|
---|
59 | $length = sizeof($url);
|
---|
60 | }
|
---|
61 | $a = $b = 0x9E3779B9;
|
---|
62 | $c = $init;
|
---|
63 | $k = 0;
|
---|
64 | $len = $length;
|
---|
65 | while($len >= 12) {
|
---|
66 | $a += ($url[$k+0] +($url[$k+1]<<8) +($url[$k+2]<<16) +($url[$k+3]<<24));
|
---|
67 | $b += ($url[$k+4] +($url[$k+5]<<8) +($url[$k+6]<<16) +($url[$k+7]<<24));
|
---|
68 | $c += ($url[$k+8] +($url[$k+9]<<8) +($url[$k+10]<<16)+($url[$k+11]<<24));
|
---|
69 | $mix = $this->mix($a,$b,$c);
|
---|
70 | $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
|
---|
71 | $k += 12;
|
---|
72 | $len -= 12;
|
---|
73 | }
|
---|
74 | $c += $length;
|
---|
75 | switch($len){
|
---|
76 | case 11: $c+=($url[$k+10]<<24);
|
---|
77 | case 10: $c+=($url[$k+9]<<16);
|
---|
78 | case 9 : $c+=($url[$k+8]<<8);
|
---|
79 | case 8 : $b+=($url[$k+7]<<24);
|
---|
80 | case 7 : $b+=($url[$k+6]<<16);
|
---|
81 | case 6 : $b+=($url[$k+5]<<8);
|
---|
82 | case 5 : $b+=($url[$k+4]);
|
---|
83 | case 4 : $a+=($url[$k+3]<<24);
|
---|
84 | case 3 : $a+=($url[$k+2]<<16);
|
---|
85 | case 2 : $a+=($url[$k+1]<<8);
|
---|
86 | case 1 : $a+=($url[$k+0]);
|
---|
87 | }
|
---|
88 | $mix = $this->mix($a,$b,$c);
|
---|
89 | return $mix[2];
|
---|
90 | }
|
---|
91 |
|
---|
92 | function strord($string) {
|
---|
93 | for($i=0;$i<strlen($string);$i++) {
|
---|
94 | $result[$i] = ord($string{$i});
|
---|
95 | }
|
---|
96 | return $result;
|
---|
97 | }
|
---|
98 |
|
---|
99 | function getRank($url){
|
---|
100 | $ch = "6".$this->GoogleCH($this->strord("info:" . $url));
|
---|
101 |
|
---|
102 | $pagerank=-1;
|
---|
103 | $fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
|
---|
104 | if (!$fp) {
|
---|
105 | echo "$errstr ($errno)<br />\n";
|
---|
106 | } else {
|
---|
107 | $out = "GET /search?client=navclient-auto&ch=" . $ch . "&features=Rank&q=info:" . $url . " HTTP/1.1\r\n" ;
|
---|
108 | $out .= "Host: www.google.com\r\n" ;
|
---|
109 | $out .= "Connection: Close\r\n\r\n" ;
|
---|
110 | fwrite($fp, $out);
|
---|
111 | while (!feof($fp)) {
|
---|
112 | $data = fgets($fp, 128);
|
---|
113 | $pos = strpos($data, "Rank_");
|
---|
114 | if($pos === false){
|
---|
115 | }else{
|
---|
116 | $pagerank = trim(substr($data, $pos + 9));
|
---|
117 | }
|
---|
118 | }
|
---|
119 | fclose($fp);
|
---|
120 | }
|
---|
121 | return $pagerank;
|
---|
122 | }
|
---|
123 | }
|
---|
124 | ?>
|
---|