[eluser]Michael Geeh[/eluser]
Hey guys,
After searching around for a while on the forum for a simple way to generate RSS feeds, I have come up with this
adaptation of this post.
Code:
<?php
class Rss extends Controller
{
function Rss()
{
parent::Controller();
$this->load->helper('xml');
}
function index()
{
$this->load->library('contentfeeder');
$feed =& new ContentFeeder_RSS2;
//$feed->setStylesheet(''.base_url().'/css/style.css','css');
$feed->addNamespace('dc', 'http://purl.org/dc/elements/1.1/');
$feed->setElement('title', 'FOOBAR CONTENT FEED');
$feed->setElement('link', 'http://www.foobar.com/');
$feed->setElement('description', 'my development site');
$feed->setElement('dc:author', 'by Joe Bloe');
$feed->setElementAttr('enclosure', 'url', 'http://www.foobar.com/');
$feed->setElementAttr('enclosure', 'length', '1234');
$feed->setElementAttr('enclosure', 'type', 'audio/mpeg');
$image =& new ContentFeederImage;
$image->setElement('url', 'http://www.foobar.com/logo.gif');
$image->setElement('title', 'Our Logo');
$image->setElement('link', 'http://www.foobar.com/');
$feed->setImage($image);
$this->db->select('id, headline, snippet, dateadded');
$this->db->orderby('dateadded', 'desc');
$this->db->limit(10);
$query = $this->db->get('news');
foreach($query->result() as $entry):
$item =& new ContentFeederItem;
$item->setElement('title', $entry->headline);
$item->setElement('link', 'Item link');
$item->setElement('description', $entry->snippet);
// ensure description does not conflict with XML
$item->setElementEscapeType('description', 'cdata');
$item->setElement('author', 'Item author');
$item->setElement('category', 'Item category');
$item->setElement('comments', 'Item comments');
$feed->addItem($item);
endforeach;
$feed->display();
}
}
And attached is the content feeder class.
Feel free to use it.