webfeed
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
Copyright © 2009 by MetaYii All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of MetaYii nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Available Downloads
| File | Summary | Uploaded on | Downloaded |
|---|---|---|---|
| webfeed-1.0b.zip (38.7 KB) | Webfeeds | June 30, 2009 | 280 |
| webfeed-1.0b.tar.bz2 (20.8 KB) | Webfeeds | June 30, 2009 | 131 |
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.
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();
