Tengo la siguiente clase que me permite crear ficheros XML y hacer un RSS bien formado:
Código PHP:
<?
class rss_generator {
private $_encoding="UTF-8";
private $_title="";
private $_language="en-us";
private $_description="";
private $_link="";
private $_generator="Portal Joven Club Granma RSS Generator";
private $_version="2.0";
private $_category = "";
private $_author = "";
public function __construct($title) {
$this->_title=$title;
}
public function __get($name) {
if ($name=='encoding') return $this->_encoding;
if ($name=='title') return $this->_title;
if ($name=='language') return $this->_language;
if ($name=='description') return $this->_description;
if ($name=='generator') return $this->_generator;
if ($name=='link') return $this->_link;
if ($name=='category') return $this->_category;
if ($name=='author') return $this->_author;
}
public function __set($name,$value) {
if ($name=='encoding') $this->_encoding = stripslashes($value);
if ($name=='title') $this->_title = stripslashes($value);
if ($name=='language') $this->_language = stripslashes($value);
if ($name=='description') $this->_description = stripslashes($value);
if ($name=='generator') $this->_generator = stripslashes($value);
if ($name=='link') $this->_link = stripslashes($value);
if ($name=='category') $this->_category = stripslashes($value);
if ($name=='author') $this->_author = stripslashes($value);
}
/**
Make an xml document of the rss stream
@param: items: n row of associative array with theses field:
'title': title of the item
'description': short description of the item
'pubData': publication timestamp of the item
'link': url to show the item
@result: xml document of rss stream
**/
public function MakeRSS($items) {
$res="";
$res.="<?xml version=\"1.0\" encoding=\"".$this->_encoding."\"?>\n";
$res.="<rss version=\"2.0\">\n";
$res.="\t<channel>\n";
$res.="\t\t<title><![CDATA[".$this->_title."]]></title>\n";
$res.="\t\t<description><![CDATA[".$this->_description."]]></description>\n";
$res.="\t\t<language>".$this->_language."</language>\n";
$res.="\t\t<generator>".$this->_generator."</generator>\n";
foreach($items as $item) {
$res.="\t\t<item>\n";
$res.="\t\t\t<title><![CDATA[".stripslashes($item["title"])."]]></title>\n";
$res.="\t\t\t<description><![CDATA[".stripslashes($item["description"])."]]></description>\n";
if (!empty($item["pubDate"]))
$res.="\t\t\t<pubDate>".date("r", stripslashes($item["pubDate"]))."</pubDate>\n";
if (!empty($item["link"]))
$res.="\t\t\t<link>".stripslashes($item["link"])."</link>\n";
if (!empty($item["author"]))
$res.="\t\t\t<author>".stripslashes($item["author"])."</author>\n";
$res.="\t\t</item>\n";
}
$res.="\t</channel>\n";
$res.="</rss>\n";
return $res;
}
}
?>
Código PHP:
<?
setlocale(LC_ALL, 'esp_ESP');
include_once('../config.inc.php');
include_once('../includes/class_rss_generator.inc.php');
include_once('../includes/adodb/adodb.inc.php');
include_once('../includes/dBug.php');
# Inicializamos AdoDB
$db = ADONewConnection($tipo);
$db->PConnect($servidor,$usuario,$passwd,$base_de_datos);
$mod = isset($_GET['mod'])?$_GET['mod']:null;
$opt = isset($_GET['opt'])?$_GET['opt']:null;
$contar_noticias = $db->Execute("SELECT COUNT(IDN) AS cantidad FROM noticia");
$rscantidad = $contar_noticias->fetchRow();
$rss = new rss_generator('Portal de los Joven Club de Computación y Electronica de Granma');
if ( $rscantidad[0] > 0 ){
$noticias = array();
$fecha_noticias = $db->SQLDate('d M Y - h:i:s A','FechaN');
$noticia = $db->Execute("SELECT IDN, IDC, $fecha_noticias, TituloN, DescN, AutorN FROM noticia ORDER BY FechaN DESC");
while($rs = $noticia->fetchRow()){
$noticias[] = $rs;
}
}
new dBug($noticias);
$rss->MakeRSS($noticias);
?>
Cita:
Alguna ayuda? El arreglo $noticias tiene valores porque los he debugeado.Notice: Undefined index: title in d:\phprojects\includes\class_rss_generator.inc.php on line 59
Notice: Undefined index: description in d:\phprojects\includes\class_rss_generator.inc.php on line 60
Notice: Undefined index: title in d:\phprojects\includes\class_rss_generator.inc.php on line 59
Notice: Undefined index: description in d:\phprojects\includes\class_rss_generator.inc.php on line 60
Notice: Undefined index: title in d:\phprojects\includes\class_rss_generator.inc.php on line 59
Notice: Undefined index: description in d:\phprojects\includes\class_rss_generator.inc.php on line 60
Notice: Undefined index: description in d:\phprojects\includes\class_rss_generator.inc.php on line 60
Notice: Undefined index: title in d:\phprojects\includes\class_rss_generator.inc.php on line 59
Notice: Undefined index: description in d:\phprojects\includes\class_rss_generator.inc.php on line 60
Notice: Undefined index: title in d:\phprojects\includes\class_rss_generator.inc.php on line 59
Notice: Undefined index: description in d:\phprojects\includes\class_rss_generator.inc.php on line 60
Salu2