webfeed Webfeed creator (RSS, RDF and Atom)

  1. Documentation
  2. Change Log

This extension is allows you to create webfeeds (Atom 1.0 and RSS 1.0 and 2.0)

File checksums
  • 6ff18978ae9e3197a7767c8f9b56705b webfeed-1.0b.tar.bz2
  • 6a54a2a7faca5cee9ba2d7c6168835ba webfeed-1.0b.zip
Resources

Documentation

You can play like this in your action, and you'll get a valid (as per http://validator.w3.org/feed/check.cgi) RSS feed. I tried to follow the specifications as close as I understand them. The validator will throw some recommendations which are not in the specifications. Also, extensions/modules/etc. are not implemented yet (just the strict specs). Same comments apply to Atom 1.0 and RSS 1.0.

Since I tried to follow RFCs and specifications as close as possible, these classes are sometimes picky. For instance, you must specify URIs so they follow the respective RFC's rules, so http://www.microsoft.com is not valid, but http://www.microsoft.com/ is fine (notice the ending slash)

You should put the code inside the run() method of an action, and don't throw anything else to the client (dumpXML is a method which should take care of the XML code for you)

Requirements
  • Yii 1.0 or above
Installation
  • Extract the release file under protected/extensions
Usage

See the following code example for RSS 2.0:

// Import the extension's namespace
Yii::import('application.extensions.webfeed.EWebFeed');
// Instantiate a EWebFeed object, passing an instance of a feed type class, in this case RSS_2_0 (for RSS 2.0)
$feed = new EWebFeed(new RSS_2_0("Hello", "Hello world", "http://www.kernel.org/"));
// here you could stop, since the basic data for the channel is configured. However, if you want, you can add more fields:
$feed->charset = 'UTF-8';
$feed->pubDate = time();
$feed->skipDays = array('Monday');
$feed->ttl = 300;
$feed->addCategory('standards/xsl/implementations','http://www.superopendirectory.com/');
$feed->addCategory('standards/xsl/specifications','http://www.superopendirectory.com/');
// Now add the news items:
$feed->addItem('item 1', 'http://www.microsoft.com/', 'Mocosoft');
// Again, here you could stop with the item, since addItem adds the basic data. But if you want, you can add more fields, using the items array, starting with 0 for the first feed item:
$feed->items[0]->addEnclosure('http://www.scripting.com/mp3s/weatherReportSuite.mp3', 12216320, 'audio/mpeg');
$feed->items[0]->addEnclosure('http://www.scripting.com/mp3s/weatherReportSuite2.mp3', 12216320, 'audio/mpeg');
$feed->items[0]->addCategory('standards/xsl/implementations', 'http://www.superopendirectory.com/');
$feed->items[0]->addCategory('standards/xsl/specifications', 'http://www.superopendirectory.com/');
$feed->items[0]->addSource('AppleSurf', 'http://www.myapplemenu.com/cgi-bin/surfView.cgi?category=applesurf&mainfull=1000&fmt=scripting&template=scripting');
$feed->items[0]->pubDate = time()-86400;
$feed->items[0]->author = "billgates@microsoft.com";
$feed->items[0]->comments = 'http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290';
$feed->items[0]->guid = strval(md5(uniqid()));
$feed->items[0]->guidIsPermaLink = false;
// Add another item:
$feed->addItem('item 2', 'http://www.kernel.com/', 'Linus');
// And add more data to the feed:
$feed->addImage('Hallo', 'http://yiiframework.com/somepic.jpg', 'http://www.kernel.org/');
$feed->addCloud('data.ourfavoritesongs.com', 80, '/RPC2', 'ourFavoriteSongs.rssPleaseNotify', 'xml-rpc');
// Dump the XML:
$feed->dumpXML();

See the following code example for Atom 1.0:

$content =<<<EOP
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget felis non leo ullamcorper vestibulum. Nulla ipsum. Aliquam vitae nisl. Nulla pretium auctor elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In augue. Maecenas laoreet vehicula odio. Donec metus. Aenean et augue. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Morbi blandit vulputate sapien. Suspendisse potenti. Nam sit amet lorem fermentum enim commodo vulputate. Vestibulum varius. Duis euismod turpis nec sem. Donec eros lorem, tincidunt ut, varius eu, scelerisque a, nunc. Donec et metus. Morbi sed elit.
</p>
<p>
Suspendisse fringilla cursus odio. Donec eros nulla, scelerisque non, vulputate vitae, eleifend at, velit. In ornare, lectus et congue adipiscing, erat elit mollis quam, eu varius mauris neque sit amet pede. Morbi pulvinar egestas ipsum. Nulla a dui. Praesent sed nibh non ipsum auctor pulvinar. Fusce leo. Maecenas nec sapien. Sed eu enim. Proin non tellus at metus placerat ullamcorper. Nam semper augue non nunc. Curabitur nulla dolor, tempus eget, porttitor ac, vehicula nec, mi.
</p>
EOP;
    
Yii::import('application.extensions.webfeed.EWebFeed');
$feed = new EWebFeed(new Atom_1_0("http://www.kernel.org/", "Hola niños & überalles", time(), 'http://localhost/yii-svn/demos/helloworld2/'));
$feed->addAuthor('MetaYii', 'http://www.yiiframework.com/', 'metayii@yiiframework.com');
$feed->addLink('http://localhost/yii-svn/demos/helloworld2/', 'alternate', '', '', 'Link');
$feed->addCategory('X', '', 'X');
$feed->addCategory('MS', 'http://www.microsoft.com/', 'Mocosoft');
$feed->addContributor('Mr. T');
$feed->addContributor('Uncle Lucas', '', 'lucas@ms.com');
$feed->addContributor('Sancho Panza', 'http://www.sancho.es/', 'lucas@ms.com');
$feed->addGenerator('Yii Framework', '1.0', 'http://www.yiiframework.com/');
$feed->addRights('(c) 2008 Qiang & Wei');
$feed->addSubtitle('Something');

$feed->addEntry('http://www.www.com/1', time(), 'xxx', 'yyy');
$feed->items[0]->addAuthor('MetaYii', 'http://www.microsoft.com/', 'metayii@yiiframework.com');
$feed->items[0]->setPublished(time()-86400);
$feed->items[0]->setUpdated(time());
$feed->items[0]->addContent($content, 'xhtml');
$feed->items[0]->addLink('http://www.example.com/');
//$feed->items[0]->addSummary('Lore ipsum');
$feed->items[0]->addCategory('lore');
$feed->items[0]->addCategory('ipsum', 'http://www.ipsum.com/', 'Ipsum');
$feed->items[0]->addContributor('Qiang');
$feed->items[0]->addContributor('Wei', 'http://www.wei.cn/', 'wei@yiiframework.com');
$feed->items[0]->addSource('http://www.cnn.com/2008-12-01/12', 'Adasdasd', time());
$feed->dumpXML();

Change Log

20090630 (1.0b)
  • Fixed typo in RSS_2_0 so it now should work.
  • Updated the example for RSS 2.0, since it was based on a previous version (sorry, the code is 6 months old and was untouched since January)
20090629 (1.0)
  • Initial release.
3 4
4 followers
1 634 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Web Service
Tags:
Developed by: MetaYii
Created on: Jun 21, 2009
Last updated: 15 years ago

Downloads

show all