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

Classe sin documentación necesito orientación para usarla.

Estas en el tema de Classe sin documentación necesito orientación para usarla. en el foro de Frameworks y PHP orientado a objetos en Foros del Web. Hola buenas,mirad encontre por internet(hotscripts para ser mas exactos)un codigo para interpretar xml....pero cuando llamo a la funcion no funciona....este es el codigo: Código PHP: ...
  #1 (permalink)  
Antiguo 17/10/2006, 23:30
 
Fecha de Ingreso: febrero-2006
Mensajes: 87
Antigüedad: 18 años, 2 meses
Puntos: 0
Classe sin documentación necesito orientación para usarla.

Hola buenas,mirad encontre por internet(hotscripts para ser mas exactos)un codigo para interpretar xml....pero cuando llamo a la funcion no funciona....este es el codigo:

Código PHP:
<?php
/*
 ======================================================================
 lastRSS 0.9.1
 
 Simple yet powerfull PHP class to parse RSS files.
 
 by Vojtech Semecky, webmaster @ webdot . cz
 
 Latest version, features, manual and examples:
     http://lastrss.webdot.cz/

 ----------------------------------------------------------------------
 LICENSE

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License (GPL)
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program 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 General Public License for more details.

 To read the license please visit http://www.gnu.org/copyleft/gpl.html
 ======================================================================
*/

/**
* lastRSS
* Simple yet powerfull PHP class to parse RSS files.
*/
class lastRSS {
    
// -------------------------------------------------------------------
    // Public properties
    // -------------------------------------------------------------------
    
var $default_cp 'UTF-8';
    var 
$CDATA 'nochange';
    var 
$cp '';
    var 
$items_limit 0;
    var 
$stripHTML False;
    var 
$date_format '';

    
// -------------------------------------------------------------------
    // Private variables
    // -------------------------------------------------------------------
    
var $channeltags = array ('title''link''description''language''copyright''managingEditor''webMaster''lastBuildDate''rating''docs');
    var 
$itemtags = array('title''link''description''author''category''comments''enclosure''guid''pubDate''source');
    var 
$imagetags = array('title''url''link''width''height');
    var 
$textinputtags = array('title''description''name''link');

    
// -------------------------------------------------------------------
    // Parse RSS file and returns associative array.
    // -------------------------------------------------------------------
    
function Get ($rss_url) {
        
// If CACHE ENABLED
        
if ($this->cache_dir != '') {
            
$cache_file $this->cache_dir '/rsscache_' md5($rss_url);
            
$timedif = @(time() - filemtime($cache_file));
            if (
$timedif $this->cache_time) {
                
// cached file is fresh enough, return cached array
                
$result unserialize(join(''file($cache_file)));
                
// set 'cached' to 1 only if cached file is correct
                
if ($result$result['cached'] = 1;
            } else {
                
// cached file is too old, create new
                
$result $this->Parse($rss_url);
                
$serialized serialize($result);
                if (
$f = @fopen($cache_file'w')) {
                    
fwrite ($f$serializedstrlen($serialized));
                    
fclose($f);
                }
                if (
$result$result['cached'] = 0;
            }
        }
        
// If CACHE DISABLED >> load and parse the file directly
        
else {
            
$result $this->Parse($rss_url);
            if (
$result$result['cached'] = 0;
        }
        
// return result
        
return $result;
    }
    
    
// -------------------------------------------------------------------
    // Modification of preg_match(); return trimed field with index 1
    // from 'classic' preg_match() array output
    // -------------------------------------------------------------------
    
function my_preg_match ($pattern$subject) {
        
// start regullar expression
        
preg_match($pattern$subject$out);

        
// if there is some result... process it and return it
        
if(isset($out[1])) {
            
// Process CDATA (if present)
            
if ($this->CDATA == 'content') { // Get CDATA content (without CDATA tag)
                
$out[1] = strtr($out[1], array('<![CDATA['=>''']]>'=>''));
            } elseif (
$this->CDATA == 'strip') { // Strip CDATA
                
$out[1] = strtr($out[1], array('<![CDATA['=>''']]>'=>''));
            }

            
// If code page is set convert character encoding to required
            
if ($this->cp != '')
                
//$out[1] = $this->MyConvertEncoding($this->rsscp, $this->cp, $out[1]);
                
$out[1] = iconv($this->rsscp$this->cp.'//TRANSLIT'$out[1]);
            
// Return result
            
return trim($out[1]);
        } else {
        
// if there is NO result, return empty string
            
return '';
        }
    }

    
// -------------------------------------------------------------------
    // Replace HTML entities &something; by real characters
    // -------------------------------------------------------------------
    
function unhtmlentities ($string) {
        
// Get HTML entities table
        
$trans_tbl get_html_translation_table (HTML_ENTITIESENT_QUOTES);
        
// Flip keys<==>values
        
$trans_tbl array_flip ($trans_tbl);
        
// Add support for &apos; entity (missing in HTML_ENTITIES)
        
$trans_tbl += array('&apos;' => "'");
        
// Replace entities by values
        
return strtr ($string$trans_tbl);
    }

    
// -------------------------------------------------------------------
    // Parse() is private method used by Get() to load and parse RSS file.
    // Don't use Parse() in your scripts - use Get($rss_file) instead.
    // -------------------------------------------------------------------
    
function Parse ($rss_url) {
        
// Open and load RSS file
        
if ($f = @fopen($rss_url'r')) {
            
$rss_content '';
            while (!
feof($f)) {
                
$rss_content .= fgets($f4096);
            }
            
fclose($f);

            
// Parse document encoding
            
$result['encoding'] = $this->my_preg_match("'encoding=[\'\"](.*?)[\'\"]'si"$rss_content);
            
// if document codepage is specified, use it
            
if ($result['encoding'] != '')
                { 
$this->rsscp $result['encoding']; } // This is used in my_preg_match()
            // otherwise use the default codepage
            
else
                { 
$this->rsscp $this->default_cp; } // This is used in my_preg_match()

            // Parse CHANNEL info
            
preg_match("'<channel.*?>(.*?)</channel>'si"$rss_content$out_channel);
            foreach(
$this->channeltags as $channeltag)
            {
                
$temp $this->my_preg_match("'<$channeltag.*?>(.*?)</$channeltag>'si"$out_channel[1]);
                if (
$temp != ''$result[$channeltag] = $temp// Set only if not empty
            
}
            
// If date_format is specified and lastBuildDate is valid
            
if ($this->date_format != '' && ($timestamp strtotime($result['lastBuildDate'])) !==-1) {
                        
// convert lastBuildDate to specified date format
                        
$result['lastBuildDate'] = date($this->date_format$timestamp);
            }

            
// Parse TEXTINPUT info
            
preg_match("'<textinput(|[^>]*[^/])>(.*?)</textinput>'si"$rss_content$out_textinfo);
                
// This a little strange regexp means:
                // Look for tag <textinput> with or without any attributes, but skip truncated version <textinput /> (it's not beggining tag)
            
if (isset($out_textinfo[2])) {
                foreach(
$this->textinputtags as $textinputtag) {
                    
$temp $this->my_preg_match("'<$textinputtag.*?>(.*?)</$textinputtag>'si"$out_textinfo[2]);
                    if (
$temp != ''$result['textinput_'.$textinputtag] = $temp// Set only if not empty
                
}
            }
            
// Parse IMAGE info
            
preg_match("'<image.*?>(.*?)</image>'si"$rss_content$out_imageinfo);
            if (isset(
$out_imageinfo[1])) {
                foreach(
$this->imagetags as $imagetag) {
                    
$temp $this->my_preg_match("'<$imagetag.*?>(.*?)</$imagetag>'si"$out_imageinfo[1]);
                    if (
$temp != ''$result['image_'.$imagetag] = $temp// Set only if not empty
                
}
            }
            
// Parse ITEMS
            
preg_match_all("'<item(| .*?)>(.*?)</item>'si"$rss_content$items);
            
$rss_items $items[2];
            
$i 0;
            
$result['items'] = array(); // create array even if there are no items
            
foreach($rss_items as $rss_item) {
                
// If number of items is lower then limit: Parse one item
                
if ($i $this->items_limit || $this->items_limit == 0) {
                    foreach(
$this->itemtags as $itemtag) {
                        
$temp $this->my_preg_match("'<$itemtag.*?>(.*?)</$itemtag>'si"$rss_item);
                        if (
$temp != ''$result['items'][$i][$itemtag] = $temp// Set only if not empty
                    
}
                    
// Strip HTML tags and other bullshit from DESCRIPTION
                    
if ($this->stripHTML && $result['items'][$i]['description'])
                        
$result['items'][$i]['description'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['description'])));
                    
// Strip HTML tags and other bullshit from TITLE
                    
if ($this->stripHTML && $result['items'][$i]['title'])
                        
$result['items'][$i]['title'] = strip_tags($this->unhtmlentities(strip_tags($result['items'][$i]['title'])));
                    
// If date_format is specified and pubDate is valid
                    
if ($this->date_format != '' && ($timestamp strtotime($result['items'][$i]['pubDate'])) !==-1) {
                        
// convert pubDate to specified date format
                        
$result['items'][$i]['pubDate'] = date($this->date_format$timestamp);
                    }
                    
// Item counter
                    
$i++;
                }
            }

            
$result['items_count'] = $i;
            return 
$result;
        }
        else 
// Error in opening return False
        
{
            return 
False;
        }
    }
}

?>
Asi lo llamo:

Código PHP:
<?
require("lastRSS.php");
Get("la url del RSS");
?>

Que puede estar pasando?muchas gracias!
  #2 (permalink)  
Antiguo 18/10/2006, 03:05
Avatar de kennyhp  
Fecha de Ingreso: julio-2006
Mensajes: 370
Antigüedad: 17 años, 9 meses
Puntos: 5
¿te da algún error?
  #3 (permalink)  
Antiguo 18/10/2006, 03:32
 
Fecha de Ingreso: febrero-2006
Mensajes: 87
Antigüedad: 18 años, 2 meses
Puntos: 0
gracias por responder,si la verdad es que me da este error:

Fatal error: Call to undefined function: get() in c:\appserv\www\noticias.php on line 3

Gracias!
  #4 (permalink)  
Antiguo 18/10/2006, 04:16
Avatar de kennyhp  
Fecha de Ingreso: julio-2006
Mensajes: 370
Antigüedad: 17 años, 9 meses
Puntos: 5
a mi me paso algo parecido, si haces un include o un require en PHP y luego haces una llamada a una función que esta dentro del include no la lee.
Primero comprueba que el archivo del include se encuentre en el mismo directorio que en el que tienes la página desde la cual llamas a la función.

Si aún así no funciona prueba a meter la función al final de la página, para comprobar si lo que falla es lo que comento al principio, no olvides la clase que se declara antes de la función.

Si de esta última forma funciona es a causa de lo que digo al principio... si es así... ¿alguien sabe por que pasa esto? (a mi tb me vendria bien saberlo ;) )
  #5 (permalink)  
Antiguo 18/10/2006, 06:23
 
Fecha de Ingreso: febrero-2006
Mensajes: 87
Antigüedad: 18 años, 2 meses
Puntos: 0
Hola,si he hecho lo que comentas..y todo sigue igual :(.....me da error!!!!!!!!
  #6 (permalink)  
Antiguo 18/10/2006, 07:12
 
Fecha de Ingreso: junio-2005
Mensajes: 13
Antigüedad: 18 años, 10 meses
Puntos: 0
A ver la verdad es que solo mire el script por encima y igual estoy diciendo una tontería, pero yo creo que hay que hacer algo parecido a esto:


$miVble=new lastRSS();
$miVble->Get("url");

Seguramente no te esté ayudando pero la intención es lo que cuenta
  #7 (permalink)  
Antiguo 18/10/2006, 12:15
 
Fecha de Ingreso: febrero-2006
Mensajes: 87
Antigüedad: 18 años, 2 meses
Puntos: 0
gracias,pero donde pongo eso?gracias!^^
  #8 (permalink)  
Antiguo 18/10/2006, 12:49
 
Fecha de Ingreso: junio-2005
Mensajes: 13
Antigüedad: 18 años, 10 meses
Puntos: 0
Tu haces esto:

<?
require("lastRSS.php");
Get("la url del RSS");
?>


Y yo al tratar con clases haría esto:

<?
require("lastRSS.php");
$miVble=new lastRSS();
$miVble->Get("la url del RSS");
?>


A ver si hay suerte y te vale de algo.
  #9 (permalink)  
Antiguo 18/10/2006, 13:13
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Cita:
Iniciado por Arturo menda Ver Mensaje
gracias,pero donde pongo eso?gracias!^^
La classe que te bajastes no tienen ningún ejemplo de uso o documentación?

En principio se trata de que "instancies" la classe como ya te han comentado. El hecho de "instaciar" ese clase y como se haga o como se usen sus métodos es cosa que debería estar en algún ejemplo y/o documentación.

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #10 (permalink)  
Antiguo 18/10/2006, 16:39
 
Fecha de Ingreso: febrero-2006
Mensajes: 87
Antigüedad: 18 años, 2 meses
Puntos: 0
Hola gracias a todos,no lleva ningun documento extra :(.....lo he puesto como comentais y no me da ningun error,pero no me muestra nada en la pagina :(.....sabeis porque puede ser?

Gracias otra vez!
  #11 (permalink)  
Antiguo 18/10/2006, 17:17
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Cita:
Iniciado por Arturo menda Ver Mensaje
Hola gracias a todos,no lleva ningun documento extra :(.....lo he puesto como comentais y no me da ningun error,pero no me muestra nada en la pagina :(.....sabeis porque puede ser?

Gracias otra vez!
En ese caso .. muevo tu mensaje al foro de "PHP Orientado a objetos" a ver si pueden hacer "ingenería inversa" y te pueden mostrar como usar la classe que presentas.

PD: edité el título de tu mensaje para que quede más claro lo que necesitas.

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #12 (permalink)  
Antiguo 18/10/2006, 19:55
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Pues al parecer todo esta bien, que es lo que quieres hacer? (el metodo Get regresa un array donde tu tienes que ciclar para obtener el contenido del RSS)
  #13 (permalink)  
Antiguo 18/10/2006, 23:15
 
Fecha de Ingreso: febrero-2006
Mensajes: 87
Antigüedad: 18 años, 2 meses
Puntos: 0
gracias por moverme cluster!,como haria ese ciclo?es que soy bastante malo en php....gracias!


EDITO:
Soy tonto y en mi casa no san dao cuenta.........solucionado ya se como hacerlo!gracias a todos!!!!!!!!!!

Última edición por Arturo menda; 19/10/2006 a las 08:42
  #14 (permalink)  
Antiguo 20/10/2006, 09:53
Avatar de jam1138
/** @package Moderador */
 
Fecha de Ingreso: julio-2004
Ubicación: sèveR led onieR lE
Mensajes: 9.368
Antigüedad: 19 años, 9 meses
Puntos: 102
Para quienes lo necesiten: http://lastrss.webdot.cz/
__________________
٩(͡๏̯͡๏)۶
» Cómo hacer preguntas de manera inteligente «

"100 años después, la revolución no es con armas, es intelectual y digital"
  #15 (permalink)  
Antiguo 20/10/2006, 10:29
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Cita:
Iniciado por jam1138 Ver Mensaje
Para quienes lo necesiten: http://lastrss.webdot.cz/
Vaya .. pues tiene documentación y ejemplo ... De hecho en el código fuente dice su URL .. (yo no me dí cuenta .. pero es cosa de fijarse un poco más).

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
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 06:11.