Autor Tópico: PageRank BBCode  (Lida 6368 vezes)

0 Membros e 1 Visitante estão a ver este tópico.

Offline candidosa2

  • Suporte Tecnico
  • Fundador
  • *
  • Mensagens: 5073
  • Rank: 1658
  • Sexo: Masculino
  • Suporte
    • Hosting Moçambique
PageRank BBCode
« em: 05 de Janeiro de 2009, 02:00 »
Subs.php
Pesquisar
Código: [Seleccione]
array(
'tag' => 'pre',
'before' => '<pre>',
'after' => '</pre>',
),

Adicionar
Código: [Seleccione]
array(
'tag' => 'pagerank',
'type' => 'unparsed_content',
'content' => '$1',
'validate' => create_function('&$tag, &$data, $disabled', '

$pagerank = pagerank($data);
$data = strtr($data, array(\'<br />\' => \'\'));
$data = "<a href=\"". $data ."\" target=\"_blank\">".$data."</a>".$pagerank;
'),
),
array(
'tag' => 'pagerank',
'type' => 'unparsed_equals_content',
'content' => '$1',
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_after' => ' ($1)',
'validate' => create_function('&$tag, &$data, $disabled', '
$data[1] = strtr($data[1], array(\'<br />\' => \'\'));
$pagerank = pagerank($data[1]);
$data[0] = "<a href=\"". $data[1] ."\" target=\"_blank\">".$data[0]."</a>".$pagerank;
'),
),

Pesquisar
Código: [Seleccione]
?>
Adicionar
Código: [Seleccione]
// PAGERANK FUNCTION
// MODIFIED FROM THE ORIGINAL PUBLIC DOMAIN CODE/API
//## PAGERANK FUNCTIONS ### //
// CONVERTS STRING TO 32-BIT INTEGER
function StrToNum($Str, $Check, $Magic) {
    $Int32Unit = 4294967296;  // 2^32
 
    $length = strlen($Str);
    for ($i = 0; $i < $length; $i++) {
        $Check *= $Magic;
        if ($Check >= $Int32Unit) {
            $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
            $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
        }
        $Check += ord($Str{$i});
    }
    return $Check;
}
 
// GENERATE HASH OF 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 CHECKSUM OF 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;
}
 
// RETURN PAGERANK BASED ON HASH URL CHECKSUM
function getch($url) {
return CheckHash(HashURL($url));
}
 
//RETURNS THE PAGERANK
function getpagerank($url) {

// SET HOST AND USERAGENT (PRETEND TO BE REQUESTING IT VIA GOOGLE TOOLBAR)
$host ='toolbarqueries.google.com';
$useragent ='Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';

$ch = getch($url);
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if ($fp) {
   $out = "GET /search?client=navclient-auto&ch=$ch&features=Rank&q=info:$url HTTP/1.1\r\n";
   $out .= "User-Agent: $useragent\r\n";
   $out .= "Host: $host\r\n";
   $out .= "Connection: Close\r\n\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)<br />\n"; } //debug only
   fclose($fp);
}
// NO PAGERANK TO RETURN 0
return "0";
}
//## END OF PAGERANK FUNCTIONS ### //
 
// TURNS THE RETURNED PAGERANK INTO SOME HTML
// YOU CAN CONTROL THE TEXT SIZE AND COLOR THROUGH THE CSS CLASS .PR
function pagerank($url){
global $settings, $txt;
$pagerank = (int) getpagerank($url);
$str = ' <div style="font-size:9px;color:#808080;display:inline;margin-left:2px;margin-right:5px;" class="pr">'.
$txt['pr'].$pagerank.
' <img src="'.$settings['default_images_url'].'/pr'.$pagerank.'.gif" alt="'.$txt['pagerank'].$pagerank. ' '.$txt['pagerank_outof'].'">'.
'</div> ' ;
return $str;
}
 


ModSettings.php
Pesquisar
Código: [Seleccione]
array('int', 'max_signatureLength'),
Adicionar
Código: [Seleccione]
array('check', 'usepagerankonprofiles'),

Post.template.php
Pesquisar
Código: [Seleccione]
'list' => array('code' => 'list', 'before' => '[list]\n[li]', 'after' => '[/li]\n[li][/li]\n[/list]', 'description' => $txt[261]),
Adicionar
Código: [Seleccione]
// ADDS THE PAGERANK BBCODE BUTTON
array(),
'pagerank' => array('code' => 'pagerank', 'before' => '[pagerank]', 'after' => '[/pagerank]','description' => $txt['pagerank_desc']),
 


Profile.template.php
Pesquisar
Código: [Seleccione]
<td><a href="', $context['member']['website']['url'], '" target="_blank">', $context['member']['website']['title'], '</a>
Adicionar
Código: [Seleccione]
<br/>';
// SHOW PAGERANK IF ENABLED
if(($modSettings['usepagerankonprofiles']) && (!empty($context['member']['website']['url']))) {
echo pagerank($context['member']['website']['url']);
}
echo '


Modifications.portuguese_pt.php
Pesquisar
Código: [Seleccione]
?>
Adicionar
Código: [Seleccione]
//Pagerank* Portuguese translation by Candidosa2*
$txt['usepagerankonprofiles'] = 'Utilizar PageRank no Perfil';
$txt['pr'] = 'PR:';
$txt['pagerank'] = 'PageRank #';
$txt['pagerank_desc'] = 'Google PageRank';
$txt['pagerank_outof'] = 'fora de 10';

Imagens no anexo