11/11/2007, 13:47
|
| | | Fecha de Ingreso: septiembre-2007
Mensajes: 419
Antigüedad: 17 años, 4 meses Puntos: 2 | |
Cómo uso esta clase ??? Nunca he utilizado clases en PHP y conseguí esta que, supuestamente, retorna el Google Page Rank de una URL entregada como variable.
Alguien me podría dar un ejemplo de cómo utilizarla ???
Gracias
Esta es la clase Código PHP: <?php
/**
* Google PageRank number for a URL
*
* LICENCE
* ========
* copyright (c) 2000 Patxi Echarte [[email protected]]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details at
* http://www.gnu.org/copyleft/lgpl.html
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @package GooglePageRank
* @version $Id: GooglePageRank.class.php,v 1.0 2006/10/04 $
* @author Patxi Echarte <[email protected]>
*/
class GooglePageRank {
var $_GOOGLE_MAGIC = 0xE6359A60;
var $_url = '';
var $_checksum = '';
/**
* Constructor
*
* @access public
*/
function GooglePageRank($url)
{
$this->_url = $url;
}
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 (is_float($Check)) {
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
// - 2^31
$Check = ($Check < -2147483647) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}
function _hashURL($String)
{
$Check1 = $this->_strToNum($String, 0x1505, 0x21);
$Check2 = $this->_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);
}
function checksum()
{
if($this->_checksum != '') return $this->_checksum;
$Hashnum = $this->_hashURL($this->_url);
$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;
}
}
$this->_checksum = '7'.$CheckByte.$HashStr;
return $this->_checksum;
}
/**
* obtiene la url donde obtener la información del pagerank
* @access public
*/
function pageRankUrl()
{
return 'http://www.google.com/search?client=navclient-auto&ch='
.$this->checksum().'&q=info:'.$this->_url;
}
/**
* devuelve el pagerank para la url indicada o -1 si error
* @access public
*/
function getPageRank()
{
$fh = @fopen($this->pageRankUrl(), "r");
if($fh)
{
$contenido = '';
while (!feof($fh)) {
$contenido .= fread($fh, 8192);
}
fclose($fh);
if(ereg("<RK>([0-9]+)<\/RK>", $contenido, $parts)){
return $parts[1];
}
}
return -1;
}
}
?>
Última edición por ASLAN; 11/11/2007 a las 16:26 |