PHP implementation code of GooglePR value
- // PageRank Lookup v1.1 by HM2K (update: 31/01/07)
- // Based on an alogoritham found here: http://pagerank.gamesaga.net/
-
- // Settings-host and user agent
- $ Googlehost = 'toolbarqueries .google.com ';
- $ Googleua = 'mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: 1.8.0.6) Gecko/20060728 Firefox/123456 ';
-
- // Convert the string to a 32-bit integer
- Function StrToNum ($ Str, $ Check, $ Magic ){
- $ Int32Unit = 4294967296; // 2 ^ 32
-
- $ Length = strlen ($ Str );
- For ($ I = 0; $ I <$ length; $ I ++ ){
- $ Check * = $ Magic;
- // If the float is beyond the boundaries of integer (usually +/-2.15e + 9 = 2 ^ 31 ),
- // The result of converting to integer is undefined
- // Refer to http://www.php.net/manual/en/language.types.integer.php
- If ($ Check >=$ Int32Unit ){
- $ Check = ($ Check-$ Int32Unit * (int) ($ Check/$ Int32Unit ));
- // If the check less than-2 ^ 31
- $ Check = ($ Check <-2147483648 )? ($ Check + $ Int32Unit): $ Check;
- }
- $ Check + = ord ($ Str {$ I });
- }
- Return $ Check;
- }
-
- // Hash the URL
- Function HashURL ($ String ){
- $ Check1 = StrToNum ($ String, 0x1505, 0x21 );
- $ Check2 = StrToNum ($ String, 0, 0x1003F );
-
- $ Check1 >>=2;
- $ Check1 = ($ Check1> 4) & 0x3FFFFC0) | ($ Check1 & 0x3F );
- $ Check1 = ($ Check1> 4) & 0x3FFC00) | ($ Check1 & 0x3FF );
- $ Check1 = ($ Check1> 4) & 0x3C000) | ($ Check1 & 0x3FFF );
-
- $ T1 = ($ Check1 & 0x3C0) <4) | ($ Check1 & 0x3C) <2) | ($ Check2 & 0xF0F );
- $ T2 = ($ Check1 & 0xFFFFC000) <4) | ($ Check1 & 0x3C00) <0xA) | ($ Check2 & 0xF0F0000 );
-
- Return ($ T1 | $ T2 );
- }
-
- // Generate a verification code for the hash string
- Function CheckHash ($ Hashnum ){
- $ CheckByte = 0;
- $ Flag = 0;
-
- $ HashStr = sprintf ('% u', $ Hashnum );
- $ Length = strlen ($ HashStr );
-
- For ($ I = $ length-1; $ I> = 0; $ I --){
- $ Re = $ HashStr {$ I };
- If (1 ===( $ Flag % 2 )){
- $ Re + = $ Re;
- $ Re = (int) ($ Re/10) + ($ Re % 10 );
- }
- $ CheckByte + = $ Re;
- $ Flag ++;
- }
-
- $ CheckByte % = 10;
- If (0! ==$ CheckByte ){
- $ CheckByte = 10-$ CheckByte;
- If (1 ===( $ Flag % 2 )){
- If (1 ===( $ CheckByte % 2 )){
- $ CheckByte + = 9;
- }
- $ CheckByte >>=1;
- }
- }
-
- Return '7'. $ CheckByte. $ HashStr;
- }
-
- // Returns the pagerank hash verification code.
- Function getch ($ url) {return CheckHash (HashURL ($ url ));}
-
- // Returns the prvalue.
- Function getpr ($ url ){
- Global $ googlehost, $ googleua;
- $ Ch = getch ($ url );
- $ Fp = fsockopen ($ googlehost, 80, $ errno, $ errstr, 30 );
- If ($ fp ){
- $ Out = "GET/search? Client = navclient-auto & ch = $ ch & features = Rank & q = info: $ url HTTP/1.1 \ r \ n ";
- // Echo"
$out \ N "; // debug only
- $ Out. = "User-Agent: $ googleua \ r \ n ";
- $ Out. = "Host: $ googlehost \ r \ n ";
- $ Out. = "Connection: Close \ r \ n ";
-
- Fwrite ($ fp, $ out );
-
- // $ Pagerank = substr (fgets ($ fp, 128), 4); // debug only
- // Echo $ pagerank; // debug only
- While (! Feof ($ fp )){
- $ Data = fgets ($ fp, 128 );
- // Echo $ data;
- $ Pos = strpos ($ data, "Rank _");
- If ($ pos = false) {} else {
- $ Pr = substr ($ data, $ pos + 9 );
- $ Pr = trim ($ pr );
- $ Pr = str_replace ("\ n", '', $ pr );
- Return $ pr;
- }
- }
- // Else {echo "$ errstr ($ errno)
\ N ";} // debug only
- Fclose ($ fp );
- }
- }
-
- // Generate pagerank graphics
- Function pagerank ($ url, $ width = 40, $ method = 'style '){
- If (! Preg_match ('/^ (http :\/\/)? ([^ \/] +)/I ', $ url) {$ url = 'http: //'. $ url ;}
- $ Pr = getpr ($ url );
- $ Pagerank = "PageRank: $ pr/10 ";
-
- // The (old) image method
- If ($ method = 'image '){
- $ Prpos = $ width * $ pr/10;
- $ Prneg = $ width-$ prpos;
- $ Html = '';
- }
- // The pre-styled method
- If ($ method = 'style '){
- $ Prpercent = 100 * $ pr/10;
- $ Html ='
';
- }
-
- $ Out = ''. $ html .'';
- Return $ out;
- }
-
- If ((! Isset ($ _ POST ['URL']) & (! Isset ($ _ GET ['URL']) {echo '';}
- If (isset ($ _ REQUEST ['URL']) {echo pagerank ($ _ REQUEST ['URL']);}
- ?>
|