Dziś popołudniu nie miałem co robić i napisałem klasa do generowania plików rss.
<?php
/**
* Klasa do generowania pliku RSS
* @author Piotr 'bela_666' Belina
* @package belacms
*/
/**
* Klasa do generowania pliku RSS
*/
class RSS {
/**
* Zmienna ustawiająca kodowanie znaków
*/
var $strCharset = \"iso-8859-2\";
/**
* Adres pliku
*/
var $strURL;
/**
* Tytuł RSSa
*/
var $strTitle;
/**
* Adres strony
*/
var $strLink;
/**
* Opis kanału
*/
var $strDesc;
/**
* Adres obrazka
*/
var $mixURLImage = 0;
/**
* Adres strony pod obrazkiem
* Jeżeli $mixURLImage nie jest równy 0, to ta zmienna też musi być
*/
var $strImageLink;
/**
* Tablica z poszczególnymi itemami
*/
/**
* Konstruktor
*/
function RSS (){
}
/**
* Funkcja wyświetlająca początek pliku
*/
function startRSS(){
header(\"Content-type: text/xml; charset=\" . $this->strCharset); print('<'.'?xml version=\"1.0\" encoding=\"' . $this->strCharset . '\" ?' . '>'.\"n\"); xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
xmlns=\"http://purl.org/rss/1.0/\">'.\"n\");
print('<channel rdf:about=\"' . $this->strURL .'\">'.\"n\"); print('<title>'. $this->strTitle .'</title>'.\"n\"); print('<link>'. $this->strLink .'</link>'.\"n\"); print('<description>'. $this->strDesc .'</description>'.\"n\");
if($this->mixURLImage) {
print('<image rdf:about=\"' . $this->mixURLImage . '\">'.\"n\"); print('<title>'. $strTitle .'</title>'.\"n\"); print('<link>'. $strImageLink .'</link>'.\"n\"); print('<url>'. $mixURLImage .'</url>'.\"n\"); print('</image>'.\"n\"); }
}
/**
* Funkcja dodaje Item do tablicy
*/
function addItem($strItemLink, $strItemTitle, $strItemDesc) {
$this->arrItems[] = '<item rdf:about=\"'. $strItemLink .'\">'.\"n\".
'<title>'.$strItemTitle.'</title>'.\"n\".
'<link>'.$strItemLink.'</link>'.\"n\".
'<description>'.$strItemDesc.'</description>'.\"n\".
'</item>'.\"n\";
}
/**
* Funkcja wyświetlająca wszystkie Itemy
*/
function showAll() {
foreach($this->arrItems as $strItem) {
}
print('</channel>'.\"n\"); print '</rdf:RDF>'.\"n\"; }
}
?>
A oto przykład wykorzystania jej
<?php
/* Przykład wykorzystania klasy RSS */
require_once(\"rss_class.php\");
$rss = new rss();
$rss->strURL = \"http://localhost/rss_class/example.php\";
$rss->strTitle = \"BelaCMS RSS\";
$rss->strLink = \"http://localhost/belacms/index.php\";
$rss->strDesc = \"Na tym kanale będą zamieszczane informacje dotyczące BelaCMS\";
$rss->startRSS();
$rss->addItem(\"http://localhost/mmcms/index.php\", \"Pierwsza wersja alfa\", \"Właśnie ukazała się pierwsza wersja alfa\");
$rss->showAll();
?>
Klasa ta jest zgodna ze
specyfikacją 1.0Zapraszam do testowania, zgłaszania propozycji zmian.