Ajax software
Free javascripts
↑
Main Page
function _escapeXML($str)
{
$translation = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
foreach ($translation as $key => $value)
{
$translation[$key] = ‘&#‘ . ord($key) . ‘;’;
}
$translation[chr(38)] = ‘&‘;
return preg_replace(“/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/“,”&”,
strtr($str, $translation));
}
// the class constructor is executed when creating an instance of the class
function RSSFactory($title, $link, $description,
$language = ‘en-us’, $items = array())
{
// save feed data to local class members
$this->_title = $title;
$this->_link = $link;
$this->_description = $description;
$this->_language = $language;
$this->_items = $items;
}
// adds a new feed item
function addItem($title, $link, $description, $additional_fields = array())
{
// add feed item
$this->_items[] =
array_merge(array(‘title’ => $title,
‘link’ => $link,
‘description’ => $description),
$additional_fields);
}
// generates feed
function get()
{
// initial preparations
ob_start();
header(‘Content-type: text/xml’);
// generate feed header
echo ‘<rss version=”2.0”>’ .
‘<channel>’ .
‘<title>’ . RSSFactory::_escapeXML($this->_title) . ‘</title>’ .
‘<link>’ . RSSFactory::_escapeXML($this->_link) . ‘</link>’ .
‘<description>’ .
RSSFactory::_escapeXML($this->_description) .
‘</description>’;
// add feed items
foreach ($this->_items as $feed_item)
{
155
Chapter 7: Web Feeds and Social Bookmarking
c07.qxd:c07 10:42 155
Ajax software
Free javascripts
→