Foros del Web » Programando para Internet » PHP » Frameworks y PHP orientado a objetos »

Cómo uso esta clase ???

Estas en el tema de Cómo uso esta clase ??? en el foro de Frameworks y PHP orientado a objetos en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 11/11/2007, 13:47
Avatar de ASLAN  
Fecha de Ingreso: septiembre-2007
Mensajes: 419
Antigüedad: 16 años, 8 meses
Puntos: 2
Pregunta 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($String0x15050x21);
        
$Check2 $this->_strToNum($String00x1003F);
       
        
$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)) <<) | ($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 (
== ($Flag 2)) {
                
$Re += $Re;
                
$Re = (int)($Re 10) + ($Re 10);
            }
            
$CheckByte += $Re;
            
$Flag ++;   
        }

        
$CheckByte %= 10;
        if (
!== $CheckByte) {
            
$CheckByte 10 $CheckByte;
            if (
=== ($Flag%2) ) {
                if (
=== ($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($fh8192);
            }
            
fclose($fh);

            if(
ereg("<RK>([0-9]+)<\/RK>"$contenido$parts)){
                return 
$parts[1];
            }
        }
        return -
1;
    }

}

?>
__________________
Registros Akáshicos

Última edición por ASLAN; 11/11/2007 a las 16:26
  #2 (permalink)  
Antiguo 11/11/2007, 14:30
Avatar de jerkan  
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Re: Cómo uso esta clase ???

Pues creo que sería algo así:
Código PHP:
incude'GooglePageRank.class.php ' );

$oGooglePageRank = new GooglePageRank($url);

echo 
$oGooglePageRank->getPageRank(); 
  #3 (permalink)  
Antiguo 11/11/2007, 16:15
Avatar de ASLAN  
Fecha de Ingreso: septiembre-2007
Mensajes: 419
Antigüedad: 16 años, 8 meses
Puntos: 2
Re: Cómo uso esta clase ???

Voy a probar
Gracias
__________________
Registros Akáshicos
  #4 (permalink)  
Antiguo 11/11/2007, 16:26
Avatar de ASLAN  
Fecha de Ingreso: septiembre-2007
Mensajes: 419
Antigüedad: 16 años, 8 meses
Puntos: 2
Re: Cómo uso esta clase ???

No me funcionó, pero con algunos cambios llegué a esto
Código PHP:
<?

include "GooglePageRank.php";

$oGooglePageRank = new GooglePageRank("http://www.google.com");

echo 
$oGooglePageRank->getPageRank();

?>
El problema es que con cualquier URL me da como resultado -1
Está bien aplicado el código ???
Gracias
__________________
Registros Akáshicos
  #5 (permalink)  
Antiguo 11/11/2007, 16:30
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: Cómo uso esta clase ???

El codigo indica en la funcion getPageRank que en caso de que tenga un problema regrese -1, por lo que no esta pudiendo abrir el URL, te recomiendo quitar el @ de la funcion fopen y cheques que error te esta lanzando.

Saludos.
  #6 (permalink)  
Antiguo 11/11/2007, 16:36
Avatar de ASLAN  
Fecha de Ingreso: septiembre-2007
Mensajes: 419
Antigüedad: 16 años, 8 meses
Puntos: 2
Re: Cómo uso esta clase ???

Aparentemente todo está correcto con la clase y la forma de usarla.
Acabo de probar en www mipagerank com y les está dando el mismo error.
Es probable que Google nuevamente haya cambiado el checksum y con ello todos los sitios que informan pagerank deberán esperar hasta que alguien descubra cómo calcular el nuevo checksum para hacer las consultas.
Voy a probar con otros sitios.

Gracias por la ayuda
__________________
Registros Akáshicos
  #7 (permalink)  
Antiguo 11/11/2007, 16:43
Avatar de ASLAN  
Fecha de Ingreso: septiembre-2007
Mensajes: 419
Antigüedad: 16 años, 8 meses
Puntos: 2
Re: Cómo uso esta clase ???

Efectívamente
Estan todos con problemas

Habrá que esperar entonces a que vuelvan a crackear el checksum, si es que a Google no se le haya ocurrido cambiar algo más ... espero que no.

ASLAN
__________________
Registros Akáshicos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:06.