Using Feedcreator to generate ATOM 1.0 feeds

I’m going give out a tip on using feedcreator class library to ease up generating syndication feeds for your web project. As you might know, there are different kind of syndication format out there such as RSS 2.0, RSS 1.0, RSS0.91, ATOM0.3 and ATOM1.0. Each of the syndication format has its own markup (though RSS 0.91 and 2.0 are closely related), making generating feeds from scratch can be quite a chore for your project.

Feedcreator provides an easy way to create RSS and ATOM feeds from within PHP using ease to use classes. However, feedcreator has a couple of drawback :

  1. It does not support ATOM 1.0
  2. Doesn’t support Enclosure
  3. Can’t generate feeds on the fly

Though these drawbacks might not be as serious as I put in here, it is nice to have this features implemented on feedcreator. ATOM 1.0 is a new syndication format issued by IETF as a standard way to produce feeds, ATOM 1.0 has a nice features and more structured layout than the ever-inconsistent RSS feeds.

Though Enclosure tag is optional in RSS 2.0, the tag is significant for those who are into podcasting or photoblogging. Enclosure feature allows for the syndicated feed to not just serve text content, but also to package an enclosure (call it an attachment of some sort), as well. IIn the podcasting model, the RSS enclosure contains an audio file, which subscribers can listen to on their devices.

Generating feeds on the fly is one of the most requested feature of feedcreator. This allows feeds to be generated dynamically upon request as opposed to generating feed on certain event (such as posting new articles). Mambo and PhpGedView project uses modified Feedcreator to generate feeds on-the-fly.

I’ve published a modified version of Feedcreator (namely Feedcreator 1.7.2-ppt) that contains all of these enhancements (or hacks). Here’s a snippets on how to use the additional features :


/*

This demo is to illustrate how to use feedcreator
using outputFeed function, ATOM1.0 and enclosure
support.

Enclosure support is useful if you are into
podcasting or publishing photoblog.

the required parameter for enclosure is url, length
and type (as in MIME-type)

*/

< ? php include ("include/feedcreator.class.php"); //define channel $rss = new UniversalFeedCreator(); $rss->useCached();
$rss->title="Personal News Site";
$rss->description="daily news from me";
$rss->link="http://mydomain.net/";
$rss->syndicationURL="http://mydomain.net/$PHP_SELF";

//channel items/entries
$item = new FeedItem();
$item->title = "test berita pertama";
$item->link = "http://mydomain.net/news/somelinks.html";
$item->description = "hahaha aku berjaya!";
$item->source = "http://mydomain.net";
$item->author = "my_email@mydomain.net";

//optional enclosure support
$item->enclosure = new EnclosureItem();
$item->enclosure->url='http://mydomain.net/news/picture.jpg';
$item->enclosure->length="65905";
$item->enclosure->type='image/jpeg';

$rss->addItem($item);

//Valid parameters are RSS0.91, RSS1.0, RSS2.0, PIE0.1 (deprecated),
// MBOX, OPML, ATOM, ATOM1.0, ATOM0.3, HTML, JS

$rss->outputFeed("ATOM1.0");
//$rss->saveFeed("ATOM1.0", "news/feed.xml");

?>

You can download the modified version of Feedcreator 1.7.2 from my server, the zip package contains the modified class library, GNU/LGPL license, some demo php file and a diff file against the plain vanilla Feedcreator 1.7.2 for curious people.

p/s : all of the modifications are written by me except outputFeed function which is written by Fabian Wolf.

Download :
Feedcreator 1.7.2-ppt (zip)

Feedcreator website : http://www.bitfolge.de/rsscreator-en.html

76 Replies to “Using Feedcreator to generate ATOM 1.0 feeds”

  1. I’ll change it to UTF-8 by default. I’m planning to add a function that can change encoding easily, since the original feedcreator does not have that function

  2. Thanks for checking in the changes to SVN http://feedcreator.svn.sourceforge.net/viewvc/feedcreator/?sortby=date
    I am looking forward to testing this updated version for integration with PhpGedView ( http://phpgedview.sourceforge.net/ ). We use the current version and look forward to the updated version. As far as enclusure support, I think that a utility methods that would calculate the file size on the fly without having to have the user calculate it would make its use easier. I guess if we passed the file path to the class, so both the following lines would be optional:
    $item->enclosure->length=”950230″;
    $item->enclosure->type=’audio/x-mpeg’

    since they could be claculated. We should be able to do most common “types” without user intervension, but the user could easily overide this by manually setting both lines above.

  3. I filed one patch based on a comment above, but it is not a real patch, just a copy from above. Do you want every bug above entered as a bug??

  4. sorry i was busy with my MSc stuff, now that i’m done i can focus on feedcreator patches.

    to keep things in order, i think feature request and bug report should be addressed in http://sourceforge.net/projects/feedcreator, specifically the tracker: https://sourceforge.net/tracker/?group_id=172984

    patches should be submitted in patches tracker and you should submit your diff according to the latest stable feedcreator-ppt release (not the original feedcreator)

    diff -u feedcreator-1.7.2ppt.php modified.php > file.patch

    hopefully we can make this work and release as often as possible (with minimum bugs)

  5. were any patches added to SVN? I see that the _setMIME patch mentioned above is not in SVN

  6. Subversion is available, yeah.. using sourceforge’s.Refer to http://feedcreator.org

    For the roadmap, I think we should concentrate on improving feedcreator ATOM 1.0 support, the one included only have minimal support for ATOM 1.0 specs.

    Since creating ATOM 1.0 feed is rather complex, i think users will appreciate some helper class like feedcreator

  7. Or why not contact the author of FeedCreator and ask him if he’s willing to give you the permission to use the same name for this project (which is more an extension than a fork of the original class, right?)?

  8. My 2 cents.
    I find phpFeedGenerator a little longish, it also seems that the name phpFeedCreator is already taken – pity. Maybe we need to make a further creativity effort ;) I think the name should be short, easy to remember and (possibly) suggest that unlike other packages, this is a flexible class that can generate feeds in any of the existing standards.

    Looking forward to more updates…

  9. you asked for it folks! :)

    I will setup SVN/CVS server and a proper website for the new feedcreator (fork) website, where people can get latest snapshot of feedcreator.

    Watch this space :)

    p/s: I think we should have a different name to differentiate it with the original feedcreator

  10. The latest update of the original class was released on 2004-11-10 – I bet the author would be more than happy to see someone take over the development of his project.

  11. Why not just set it up as a sourceforge project? It is GPL and I do not think you need to ask anyone.

  12. After some testing, FeedCreator is likely to be included as 3rdparty plugin in Wikka Wiki (http://wikkawiki.org).

    mypapit, have you ever thought of putting the source in a SVN repository so more people can keep an eye on it and eventually contribute to its development?

    Best,

    Dario

  13. Pingback: MikeValstar.com
  14. hourly & 2 were part of some unescaped xml. I hope this works

    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>2</sy:updateFrequency>

  15. For the encoding issue and siplicity

    _setMIME($format) {
    …..
    …..
    }
    should probably be changed to
    _setMIME() {
    header(“content-type: ” . $this->contentType . “; charset=”.$this->encoding, true);
    }

  16. Hello there,

    I’m working on releasing the next feedcreator with my patch. It will feature some code clean up and more classes to help setup photo gallery and podcast

    stay tune

  17. As far as the missing email addresses, this is one validation that does not bother me. There is no way anyone in this day and age would want an actual unobfuscated email address in a feed. I doubt that any feed clent will fail based on a missing @ sign in the author field.

  18. Apologies for this comment bombing :)

    I’ve checked the specs for the different RSS and realized that if an item author is specified then it must contain an email. This is not appropriate for wikis, so we just decided to drop it. Atom 1.0, on the other hand, accepts an optional Author without an email.

  19. Some further notes:

    – I confirm the OPML validation error reported by KosherJava.

    – Furthermore, I have an issue with authorEmail. The feed validator seems to assume they are required for both RSS2.0 and Atom0.3, while FeedCreator doesn’t. This results in invalid RSS2.0 and Atom feeds.

  20. Hi,

    we are testing an integration of FeedCreator with Wikka Wiki, a PHP/MySQL wiki engine (http://wikka.jsnx.com/RSSHandler). I’ve made some first tests using the original version of the class. I bumped into your blogpost later and I’ll take a look asap at your enhanced version of the code, which looks very promising (Atom 1.0 is really a must!). This said I don’t quite understand when you say FeedCreator “can?t generate feeds on the fly”. I’ve used one of the native methods of the original FeedCreator, createFeed(), and I can easily generate feeds on the fly. Am I missing something?

  21. make sure that you use the future branch in CVS. The main branch has the 3.3.x code, while future has the 4.0 code. There has not yet been a beta release that includes the feedcreator changes that use your code.

  22. d) should read same warnings about HTML as ATOM 1.0
    to see our version in CVS check out http://cvs.sourceforge.net/viewcvs.py/phpgedview/phpGedView/includes/feedcreator.class.php?view=log&rev=1.1.2.5&sortby=date&only_with_tag=future
    Also see http://cvs.sourceforge.net/viewcvs.py/phpgedview/phpGedView/rss.php?view=log&rev=1.11.2.15&sortby=date&only_with_tag=future
    to see how we generate our script using feedcreator.
    I think that the changelog should be moved out of the main file to its own changelog.txt file. I also think that there is too much sample code in the main class that should be removed since they are in the demo files (I removed some from our version).

  23. Here is the feedback. Much of it is not specific to ATOM 1.0, but since you are the new maintainer, here goes:
    Our script gives the user the option to change RSS types so this was easy to test :). We use html within the feed and that explains some of the problems.
    Note you can test this live by going to http://phpgedview.net/registry.php and when at a site (try to stick to the 4.0 CVS version sites, though im not sure how many already have the ATOM1.0 changes yet)
    go to the url /rss.php?rssStyle=ATOM0.3
    or change the rssStyle to any flavor supported.

    Almost al are validation issues. Some errors and some warnings. Some will probably be trivial to fix. Thanks in advance.
    a) if I ommit the line
    $rss->cssStyleSheet=””;
    I get php errors. This should not be needed.
    b) When validating RSS2.0 I get the following errors:
    1) Thu, 08 Dec 2005 19:53:27
    — lastBuildDate must be an RFC-822 date-time
    2) Your feed appears to be encoded as “utf-8”, but your server is reporting “US-ASCII”
    3) Fri, 09 Dec 2005 03:53:26
    — pubDate must be an RFC-822 date-time
    b) When validating RSS 1.0
    1) Your feed appears to be encoded as “utf-8”, but your server is reporting “US-ASCII”
    c) When validating ATOM 1.0
    1) summary should not contain HTML unless declared in the type attribute
    — this is even though I set $rss->descriptionHtmlSyndicated = true;
    d) validating ATOM 0.3 same warning about HTML as 0.3
    e) validating RSS0.91
    same 3 warnings as RSS2.0
    f) OPML validation
    1) An element whose type is “rss” must have an “xmlUrl” attribute. (see http://feedvalidator.org/docs/warning/MissingXmlURL.html )
    2) Missing opml attribute: version

  24. “Have you seen http://rakaz.nl/item/moving_from_atom_03_to_10 ? Are all changes implemented in your release?”

    Yes, I’ve seen the article, I’ve implemented all the necessary changes to adapt Atom 0.3 to Atom 1.0. I’ve taken steps to make it as painless as possible to convert to Atom 1.0.

    But as feedcreator doesnt validate feeds it generated on its own, then I suggest that users should validate it http://feedvalidator.org first.

    :)

    I would love to hear from you, again

  25. PhpGedView has been updated to use your updated feedcreator. Thanks a lot.
    There are a few issues that I will post in the next few days, but they are minor ones.

  26. Yes I notice that too, and the problem was addressed to the original author of Feedcreator, but i’ve yet to received any response.

    “Do you plan on keeping your script up to date and maintaining it? The regular Feedcreator seems to be abandoned”
    Well, i dont think i’m a qualified person to maintain Feedcreator. But i do use feedcreator in my personal project, and yes I would keep it up to date.

  27. I am the one who is guilty of hacking the original script for use in PhpGedView. I am not a PHP developer, but somehow managed to get it working. Do you plan on keeping your script up to date and maintaining it? The regular Feedcreator seems to be abandoned, and I would be thrilled to actually switch to a maintainable version (time permitting sometime within the next few months). Enclosures are of possible interest so that I can include the random media block, but I doubt that I will actually bother. Did you notice that the char encoding used in the class seems to be flakey? Some use hardcoded UTF-8, one place uses ISO-8859-1 (this is the default) and one uses ISO-8859-15. I think that they should all be dynamic and should default to UTF-8 (that is certainly needed for PhpGedView). I am curious if you found anything of use in the changes that were made in the PhpGedView version.

  28. Well, just to be clear, there’s none of my name in the output, I only wrote my name in source code as part of the ChangeLog, that is only because I’m fulfilling the ChangeLog procedure and obeying the GNU/LPGL license obligation.

    Maybe you mean the version prefix. For your information, it’s customary for people to postfixed the patch version of the original software with 3 characters, symbolizing that it is not the original work.

    This has been explained deeply in the GNU/GPL, GNU/LGPL or the BSD license that the modified version of the software must be plainly marked as not being the original software. The “plainly marked” clause has been fulfilled in the documentations as well as in the feed output.

    You can verify this on other “patched” version of Feedcreator created by other author, some are postfixed with -mod (Fabian Wolf), some with -out (Otto Reilch) or (perhaps) -ac2, i choose to marked my patched version with -ppt.

    Linux kernel development is one of the projects that practised this type of version numbering. Just go to http://kernel.org, and you will see a series of patched version of linux kernel with the 3 character postfix, to mark that the patched (modified) version of the kernel is not the same as the released kernel. The most famous patched kernel is the Alan Cox series which is postfixed with -acX, where X is his own patch number.

    So when you go there (http://kernel.org) you will see a release kernel version first, release candidate, and patched version like 2.6.11-ac7 and 2.6.15-rc2-mm1, postfixed by their patch author.

  29. sory mr papit. actually, i is same guy that post to this entry with nick ‘aku’. sory for my post. actually i very tension when i try this script, it’s can’t work correctly. when i see feed source, i see your name (the version) as a output.

    sory for that & thank coz reply my 2nd question.

  30. can you show example, demo etc where to put the line that your show in this post.

    Sure akon-lonely. The zip file contains “demo.php” file, with an “include” directory. The line shown in this blog is the one that contains in the demo.php

    The “demo.php” file should work right away provided that you’ve put it into a webserver that have php support. The script should generate a (or almost) valid ATOM 1.0 feeds, you may test its validity in http://feedvalidator.org.

    Need I remind you that, Feedcreator doesn’t generate your feeds automatically, it merely help you to construct a different syndication format from the data you supplied.

    Usually you will have to create a loop which retrieve data from a database (eg mysql, postgresql), to generate a feed from Feedcreator.

    The file “official_demo.php” in the zip package illustrate this better, it shows you how to create a loop and retrieve data from mysql database.

    FYI, this is the same demo file which is featured in the Feedcreator official website : http://www.bitfolge.de/rsscreator-en.html

    Hope that helps for now… :D

  31. after generate, feed only show title and it’s have link to source. the title is link. why can’t generate description, entry, date etc? why enclosure aka attachment not working?

  32. Ya Allah, kenapa buat tuduhan melulu ni?

    “baru tambah sikit line dalam code dah sibuk nak mengaku code tu kau punya”
    Encik, saya tak mengaku pun yang saya yang buat semua, hanya kepada patch itu sahaja.

    Saya dah bagi pointer kat mana nak dpt original work, patch pun saya dah berikan sekiranya Encik nak convert balik hasil kerja saya kepada original work tu. Saya pun dah dapat kebenaran serta dah berikan kredit kepada Fabian Wolf.

    habis semua output dok keluar nama kau
    Encik, dimanakah output yang keluarnya nama saya?

    apa la lu? tak bagi credit langsung?
    “Credit is given where credit is due”

    Kredit sudah diberikan. Cumanya,

    1) Adakah anda tahu membaca artikel ni ?
    2) Adakah anda tahu procedure submit patch dengan tulis ChangeLog dalam source code?

    “p/s : all of the modifications are written by me except outputFeed function which is written by Fabian Wolf.”

    Semua perkara ni tercatat dlm artikel tentang tempat utk mendapatkan original source code, dengan kredit. Maklumat lanjut boleh di dapati dalam ChangeLog source code dengan dalam README file. file README tu pun specify kat mana nak dapatkan original source code, berserta dengan license GNU/LGPL. Semuanya di publish mengikut procedure yang ditetapkan oleh creator original Feedcreator.

    Di harap anda akan buat research sebelum membuat tuduhan melulu ini. :D

    p/s: Dalam sembahyang zohor, asar, maghrib, isyak hari ni, aku berdoa supaya Allah jauhkan orang-orang yang berhati busuk dari aku ini. Ya Allah, aku buat ni sebab aku nak berkongsi pengetahuan aku kepada semua, bukan untuk berlagak sombong dan “mencuri” harta orang lain seperti yang difitnahkan oleh orang kepada aku hari ini.

  33. apa la, baru tambah sikit line dalam code dah sibuk nak mengaku code tu kau punya… nak tumpang glemer le lu ni. apa la lu. habis semua output dok keluar nama kau… apa la lu… tak bagi credit langsung…

  34. Pingback: LAMP Guru
  35. Pingback: Site A Month

Comments are closed.