4
« on: November 29, 2012 - 07:45 19:45 »
Hola que tal amigos de SMFSimple, bueno queria poner un lector de feeds en mi foro con feeds provenientes de mi blog, y pues me puse a buscar un rato y encontre unos lectores en php, y bien despues me puse a ver como crear un bloque para el portal, ya hice varios experimentos y no me queda el codigo por alguna razon... Al entrar a la configuracion de bloques me sale este mensaje... "Fatal error: Class 'Block' not found in /home/breacker/public_html/foro/Sources/ssp/FeedBlock.php on line 3"
Les dejo los dos codigos para que me ayuden a colocarlo bien dentro del codigo del bloque...
Codigos de lector
Primer Codigo de lector...
<?php
//$RSS = new LectorRSS ("http://www.tublogenwordpress.com/blog/feed/rss/";
$RSS = new LectorRSS ("http://www.taringa.net/rss/ultimos-post/";
class LectorRSS {
var $url;
var $data;
function LectorRSS ($url){
$this->url;
$this->data = implode ("", file ($url));
}
function obtener_items (){
preg_match_all ("/<item .*>.*<\/item>/xsmUi", $this->data, $matches);
$items = array ();
foreach ($matches[0] as $match){
$items[] = new RssItem ($match);
}
return $items;
}
}
class RssItem {
var $title, $url;
function RssItem ($xml){
$this->populate ($xml);
}
function populate ($xml){
preg_match ("/<title> (.*) <\/title>/xsmUi", $xml, $matches);
$this->title = $matches[1];
preg_match ("/<link> (.*) <\/link>/xsmUi", $xml, $matches);
$this->url = $matches[1];
}
function obtener_titulo (){
return $this->title;
}
function obtener_url (){
return $this->url;
}
}
foreach ($RSS->obtener_items () as $item){
printf ('<a target="_BLANK" href="%s">%s</a><br />',
$item->obtener_url (), $item->obtener_titulo ());
}
?>
Segundo codigo de lector...
<?php
$long_descripcion=400;
$num_noticias=4;
$n=0;
$noticias = simplexml_load_file('http://urldetuweb.sadas/rss.xml');
foreach ($noticias as $noticia) {
foreach($noticia as $reg){
if($reg->title!=NULL && $reg->title!='' && $reg->description!=NULL && $reg->description!='' && $n<$num_noticias){
echo '<b><a href="'.$reg->link.'" target="_blank">'.$reg->title.'</a></b><br>';
if(strlen($reg->description)>$long_descripcion)
echo '<p>'.substr($reg->description,0,$long_descripcion).'...</a></p><br>';
else
echo '<p>'.$reg->description.'</p><br>';
echo 'Publicado: '.$reg->pubDate.'<br><br>';
$n++;
}
}
}
?>
Y asi es como plantee el codigo...
<?
class FeedBlock extends Block{
const SYSKEY = 'FeedBlock';
function __construct()
{
}
public function show()
{
$long_descripcion=400;
$num_noticias=4;
$n=0;
$noticias = simplexml_load_file('http://www.breackerz.com//feeds/posts/default');
foreach ($noticias as $noticia) {
foreach($noticia as $reg){
if($reg->title!=NULL && $reg->title!='' && $reg->description!=NULL && $reg->description!='' && $n<$num_noticias){
echo '<b><a href="'.$reg->link.'" target="_blank">'.$reg->title.'</a></b><br>';
if(strlen($reg->description)>$long_descripcion)
echo '<p>'.substr($reg->description,0,$long_descripcion).'...</a></p><br>';
else
echo '<p>'.$reg->description.'</p><br>';
echo 'Publicado: '.$reg->pubDate.'<br><br>';
$n++;
}
}
}
Espero su ayuda! Saludos!