<?php class RssGenerator { private $dom; private $channel; function __construct() { } function setLanguage($value) { $this->ChannelElement[language] = $value ; } function setCopyright($value) { $this->ChannelElement[copyright] = $value; } function setPubDate($value) { }else { $this->ChannelElement[pubdate] = $value; } } /** * generateRssChannel() * Funkcja generująca <channel>. * * @param $title - Tytul strumienia. * @param $link - Adres url do strony "własciciela" strumienia. * @param $description - Opis strumienia. * */ function generateRssChannel($title, $link, $description) { $this->channelElement[title] = $title; $this->channelElement[description] = $description; $this->dom = new DOMDocument('1.0', 'utf-8'); $mainNode = $this->dom->appendChild($this->dom->createElement('rss')); $mainNode->setAttribute('version', '2.0'); $this->channel = $mainNode->appendChild($this->dom->createElement('channel')); /*<channel>*/ /* Wymagane elementy */ $this->channel->appendChild($this->dom->createElement('title', $this->channelElement[title])); $this->channel->appendChild($this->dom->createElement('description', $this->channelElement[description])); /* Opcjonalne elementy */ $this->channel->appendChild($this->dom->createElement('language', $this->channelElement[language])); } $this->channel->appendChild($this->dom->createElement('copyright', $this->channelElement[copyright])); } $this->channel->appendChild($this->dom->createElement('pubdate', $this->channelElement[pubdate])); } } /** * generateRssItem() * Funkcja generująca <item>. * * @param $title - Tytul strumienia. * @param $link - Adres url itemu. * @param $description - Opis strumienia. * */ function generateRssItem($title, $link, $description) { $this->itemElement[title] = $title; $this->itemElement[description] = $description; $item = $this->channel->appendChild($this->dom->createElement('item')); $item->appendChild($this->dom->createElement('title', $this->itemElement[title])); $item->appendChild($this->dom->createElement('description', $this->itemElement[description])); } function getRss() { $this->dom->formatOutput = true; return $this->dom->saveXML(); } } ?>
I zastosowanko
<?php $rss = new RssGenerator(); $rss->setPubDate('Sat, 07 Sep 2002 00:00:01 GMT'); $rss->setLanguage('pl-pl'); $rss->setCopyright('Ja ja@as.pl'); $rss->generateRssChannel('Tytuł', 'http://www.onet.pl', 'afasf'); // Tutaj oczywiście symulacja działania while() ;] $rss->generateRssItem('Title1', 'link2', 'afasfasff'); $rss->generateRssItem('Title2', 'link2', 'afasfasff'); $rss->generateRssItem('Title3', 'link2', 'afasfasff'); $rss->generateRssItem('Title4', 'link2', 'afasfasff'); $feed = $rss->getRss(); ?>
pozdrawiam i dziękuję z góry za ewentualne wskazówki