Jak Wy, to i ja... Moja prosta klasa do RSSów. Funkcja do zmiany pliterek u¿yta dla mojej w³asnej wygody, by nie korzystaæ z iconv()
rss.class.php
<? class RSS { var $ver; var $items; var $channel; var $encoding; function RSS($version = 2, $encoding = 'utf-8') { if ($version != 2) $version = 1; $this->ver = $version; $this->items = http://www.php.net/array(); $this->channel = http://www.php.net/array(); $this->encoding = $encoding; } function channel($params) { $this->channel = $params; } function addItem($params) { $this->items[] = $params; } function addErrorItem($title, $url, $author, $description) { $this->items[] = http://www.php.net/array( 'title' => RSS::pl2utf(http://www.php.net/htmlspecialchars($title)), 'link' => $url, 'guid' => $url, 'author' => RSS::pl2utf(http://www.php.net/htmlspecialchars($author)), 'date' => http://www.php.net/time(), 'description' => RSS::pl2utf(http://www.php.net/htmlspecialchars($description))); } function output() { http://www.php.net/header(\"Content-Type: text/xml\"); http://www.php.net/header(\"Cache-Control: no-cache\"); http://www.php.net/echo(\"<?xml version=\"1.0\" encoding=\"\".$this->encoding.\"\"?>n\"); if ($this->ver == 2) { echo(\"<rss version=\"2.0\">n\"); echo(\"t<channel>n\"); echo(\"tt<title>\".$this->channel['title'].\"</title>n\"); echo(\"tt<link>\".$this->channel['link'].\"</link>n\"); echo(\"tt<description>\".$this->channel['description'].\"</description>n\"); echo(\"tt<generator>\".$this->channel['generator'].\"</generator>n\"); echo(\"tt<lastBuildDate>\".date(\"r\").\"</lastBuildDate>n\"); foreach ($this->items as $item) { echo(\"tt<item>n\"); echo(\"ttt<title>\".RSS::rment($item['title']).\"</title>n\"); echo(\"ttt<link>\".$item['link'].\"</link>n\"); echo(\"ttt<guid>\".$item['guid'].\"</guid>n\"); echo(\"ttt<author>\".RSS::rment($item['author']).\"</author>n\"); echo(\"ttt<pubDate>\".date(\"r\", $item['date']).\"</pubDate>n\"); if ($item['description'] != '') echo(\"ttt<description>\".$item['description'].\"</description>n\"); echo(\"tt</item>n\"); } echo(\"t</channel>n\"); echo(\"</rss>\"); } else { echo(\"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns=\"http://purl.org/rss/1.0/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">n\"); echo(\"t<channel rdf:about=\"\".$this->channel['link'].\"\">n\"); echo(\"tt<title>\".$this->channel['title'].\"</title>n\"); echo(\"tt<link>\".$this->channel['link'].\"</link>n\"); echo(\"tt<description>\".$this->channel['description'].\"</description>n\"); echo(\"tt<dc:publisher>\".$this->channel['generator'].\"</dc:publisher>n\"); echo(\"tt<items>n\"); echo(\"ttt<rdf:Seq>n\"); foreach ($this->items as $item) { echo(\"tttt<rdf:li resource=\"\".$item['guid'].\"\" />n\"); } echo(\"ttt</rdf:Seq>n\"); echo(\"tt</items>n\"); echo(\"t</channel>n\"); foreach ($this->items as $item) { echo(\"t<item rdf:about=\"\".$item['guid'].\"\">n\"); echo(\"tt<title>\".RSS::rment($item['title']).\"</title>n\"); echo(\"tt<link>\".$item['link'].\"</link>n\"); echo(\"tt<dc:date>\".date(\"Y-m-dTH:i:sZ\", $item['date']).\"</dc:date>n\"); if ($item['description'] != '') echo(\"tt<description>\".$item['description'].\"</description>n\"); echo(\"t</item>n\"); } echo(\"</rdf:RDF>\"); } } function rment($text) { $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); if (isset($trans_tbl['<'])) unset($trans_tbl['<']); if (isset($trans_tbl['>'])) unset($trans_tbl['>']); if (isset($trans_tbl['&'])) unset($trans_tbl['&']); if (isset($trans_tbl['''])) unset($trans_tbl[''']); if (isset($trans_tbl['"'])) unset($trans_tbl['"']); return strtr($text, $trans_tbl); } function pl2utf($tsource) { $pl2utf = array(\"±\" => \"±\", \"?\" => \"±\", \"æ\" => \"æ\", \"ê\" => \"ê\", \"³\" => \"³\", \"ñ\" => \"ñ\", \"ó\" => \"ó\", \"¶\" => \"¶\", \"?\" => \"¶\", \"¿\" => \"¿\", \"¥\" => \"¼\", \"¡\" => \"¼\", \"·\" => \"¡\", \"·\" => \"¡\", \"Æ\" => \"Æ\", \"\" => \"\", \"£\" => \"£\", \"Ñ\" => \"Ñ\", \"Ó\" => \"Ó\", \"¦\" => \"¦\", \"?\" => \"¦\", \"¯\" => \"¯\", \"¬\" => \"¬\", \"?\" => \"¬\"); return strtr($tsource, $pl2utf); } } ?>
<? require_once('rss.class.php'); $rss = new RSS(); $channel = http://www.php.net/array( 'title' => 'Tytu³', 'link' => 'http://www.adres.pl/', 'description' => 'Opis', 'generator' => 'rss.class.php'); $item = http://www.php.net/array( 'title' => 'Tytu³ wpisu', 'link' => 'http://link.do.wpisu/', 'guid' => 'guid', 'author' => 'Autor', 'date' => 'Data', 'description' => 'Opis'); $rss->addItem($item); $rss->channel($channel); $rss->output(); ?>
wydzielony z http://forum.php.pl/index.php?showtopic=21782 - ostatni punkt regulamiu tego forum prosze przeczytac.
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)