Foros del Web » Programando para Internet » PHP »

PHP y RSS

Estas en el tema de PHP y RSS en el foro de PHP en Foros del Web. Hola: Tengo un blog wordpress en mi sitio web, lo que quiero es poner los titulares del blog en mi página de index.php con RSS, ...
  #1 (permalink)  
Antiguo 16/05/2006, 17:52
 
Fecha de Ingreso: junio-2004
Mensajes: 45
Antigüedad: 19 años, 10 meses
Puntos: 0
PHP y RSS

Hola:
Tengo un blog wordpress en mi sitio web, lo que quiero es poner los titulares del blog en mi página de index.php con RSS, hasta hoy lo hago a través de un scripts, pero se vuelve un poco lento el proceso, pues bien, trabajo con Dreamweaver y su extension RSS.

Al momento de probar conectarme (desde mi localhost) al rss que genera mi blog (http://www.muestrate.cl/blog/?feed=rss2) se ve perfecto.

Si subo a internet la página ésta me dice que no puede conectarse a la url del RSS del blog. Este es el mensaje:
http://www.muestrate.cl/blog/?feed=rss2 could not be opened

No he encontrado casos parecidos en google, ¿alguien sabe que sucede?

Este es el código php de la conexión.

Cita:
<?php
$itemNum=0;
class RSSParser {
var $channel_title="";
var $channel_website="";
var $channel_description="";
var $channel_pubDate="";
var $channel_lastUpdated="";
var $channel_copyright="";
var $title="";
var $link="";
var $description="";
var $pubDate="";
var $author="";
var $url="";
var $width="";
var $height="";
var $inside_tag=false;
function RSSParser($file) {
$this->xml_parser = xml_parser_create();
xml_set_object( $this->xml_parser, $this );
xml_set_element_handler( $this->xml_parser, "startElement", "endElement" );
xml_set_character_data_handler( $this->xml_parser, "characterData" );
$fp = @fopen("$file","r") or die( "$file could not be opened" );
while ($data = fread($fp, 4096)){xml_parse( $this->xml_parser, $data, feof($fp)) or die( "XML error");}
fclose($fp);
xml_parser_free( $this->xml_parser );
}

function startElement($parser,$tag,$attributes=''){
$this->current_tag=$tag;
if($this->current_tag=="ITEM" || $this->current_tag=="IMAGE"){
$this->inside_tag=true;
$this->description="";
$this->link="";
$this->title="";
$this->pubDate="";
}
}

function endElement($parser, $tag){
switch($tag){
case "ITEM":
$this->titles[]=trim($this->title);
$this->links[]=trim($this->link);
$this->descriptions[]=trim($this->description);
$this->pubDates[]=trim($this->pubDate);
$this->authors[]=trim($this->author);
$this->author=""; $this->inside_tag=false;
break;
case "IMAGE":
$this->channel_image="<img src=\"".trim($this->url)."\" width=\"".trim($this->width)."\" height=\"".trim($this->height)."\" alt=\"".trim($this->title)."\" border=\"0\" title=\"".trim($this->title)."\" />";
$this->title=""; $this->inside_tag=false;
default:
break;
}
}

function characterData($parser,$data){
if($this->inside_tag){
switch($this->current_tag){
case "TITLE":
$this->title.=$data; break;
case "DESCRIPTION":
$this->description.=$data; break;
case "LINK":
$this->link.=$data; break;
case "URL":
$this->url.=$data; break;
case "WIDTH":
$this->width.=$data; break;
case "HEIGHT":
$this->height.=$data; break;
case "PUBDATE":
$this->pubDate.=$data; break;
case "AUTHOR":
$this->author.=$data; break;
default: break;
}//end switch
}else{
switch($this->current_tag){
case "DESCRIPTION":
$this->channel_description.=$data; break;
case "TITLE":
$this->channel_title.=$data; break;
case "LINK":
$this->channel_website.=$data; break;
case "COPYRIGHT":
$this->channel_copyright.=$data; break;
case "PUBDATE":
$this->channel_pubDate.=$data; break;
case "LASTBUILDDATE":
$this->channel_lastUpdated.=$data; break;
default:
break;
}
}
}
}

$blog = new RSSParser("http://www.muestrate.cl/blog/?feed=rss2");
?>
__________________
www.muestrate.cl, noticias y actualidad de Chillán, Chile
  #2 (permalink)  
Antiguo 17/05/2006, 06:17
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Si quitas los @ que tienen algunas funcions de tu código actual .. seguramente veras un mensaje de error más "técnico" sobre el problema.

Por ejemplo .. algo tipo que la función fopen() en tu servidor remoto no acepta una llamada externa por HTTP (wrappers externos no habilitados).

Te recomendaría usar (si es que tienes ese problema) usar una ruta absoluta hacia tu .rss y no relativa .. Es decir usar algo tipo:

$_SERVER['DOCUMENT_ROOT']."/blog/?feed=rss2"

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #3 (permalink)  
Antiguo 17/05/2006, 09:43
 
Fecha de Ingreso: junio-2004
Mensajes: 45
Antigüedad: 19 años, 10 meses
Puntos: 0
Estaba asi:
$blog = new RSSParser("http://www.muestrate.cl/blog/?feed=rss2");

y lo cambié así, pero no me funcionó
$blog = new RSSParser("$_SERVER['DOCUMENT_ROOT']."/blog/?feed=rss2"");

Así tampoco
$blog = new RSSParser("blog/?feed=rss2");

Perdón por mi ignorancia :(, la verdad es que no se como cambiar esto.
__________________
www.muestrate.cl, noticias y actualidad de Chillán, Chile
  #4 (permalink)  
Antiguo 17/05/2006, 09:50
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pero .. ya quitastes los @ que aparecen en tu código y observastes si muestra algún error de parte de PHP algo más coherente con el problema que tienes?

Por cierto .. te sobran comillas según la propuesta que te hice:
$blog = new RSSParser($_SERVER['DOCUMENT_ROOT']."/blog/?feed=rss2");

Asumo que todo (tu scritp "parser RSS" y donde quieres "parsearlo" junto con la fuente de datos RSS) está en el mismo servidor.

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #5 (permalink)  
Antiguo 17/05/2006, 16:11
 
Fecha de Ingreso: junio-2004
Mensajes: 45
Antigüedad: 19 años, 10 meses
Puntos: 0
ya quité el @, te acabo de enviar un mensaje privado con los errores que me arroja.
Tanto en mi localhost como en el servidor de internet index.php está dentro de una carpeta X, y la carpeta blog(con el blog) dentro de X
X (carpeta)
l L index.php
L /Blog (carpeta)

El script mostrado arriba (en mi primer post) está dentro de index.php, fuera de la carpeta Blog
__________________
www.muestrate.cl, noticias y actualidad de Chillán, Chile
  #6 (permalink)  
Antiguo 18/05/2006, 08:25
 
Fecha de Ingreso: junio-2004
Mensajes: 45
Antigüedad: 19 años, 10 meses
Puntos: 0
OK, consultaré a mi proveedor de hosting si puede habilitar "wrappers externos", luego te cuento como me fue.
__________________
www.muestrate.cl, noticias y actualidad de Chillán, Chile
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

SíEste tema le ha gustado a 1 personas (incluyéndote)




La zona horaria es GMT -6. Ahora son las 21:38.