Am Samstag, den 14.07.2007, 12:38 +0200 schrieb Andries Seutens: > Hi all, > > I have written a small demo app for those of you looking for a quick > start with Zend Framework. > > You can view, and download the demo at: > http://andries.systray.be/zf-demos/feed-reader/
Hi Andries, just like you, I've been trying to write a generalized feed reader using Zend_Feed and I just stumbled upon an issue that affects your code as well. IMHO, it should be a design goal for Zend_Feed to be able to easily consume any common feed out there. However, I have seen quite a few feeds out there that currently can't be handled in a generalized way - that is, without writing tons of if/else statements to filter out special cases. Here's an example feed that doesn't work too well with Zend_Feed: http://toyflish.de/service/feed.php When you iterate through the feed items and try to access $item->title() or $item->description(), what you'll get instead of the expected string is an array with two DOMElement objects. The reason being, that there are two of these tags in each item: One with the namespace prefix "media" and one without. Check it out with your feed reader code - it won't work. The problem is: If you don't target a specific feed, you don't know in which of these items the relevant information is. You would have to check each item and see whether or not it's empty. If both have content, you would have to check which one is the media node and which is the standard one. The above feed is not the only one causing problems. Try http://feeds.feedburner.com/Techcrunch, for example, and try to get the feed link: $techCrunchFeed = 'http://feeds.feedburner.com/Techcrunch'; $feed = new Zend_Feed_Rss($techCrunchFeed); print_r($feed->link()); Personally, I would expect Zend_Feed to handle these cases: If there's more than one node, always return the first non-empty standard node (read: not namespaced), if that's empty, return the first non-empty namespaced node (like "media:description"). If you're targeting a specific feed, you could work around the auto-detection by giving the desired namespace as a parameter, and probably another parameter to toggle the empty-node auto-skipping: <example> // gets only the description nodes within the media namespace, // while auto-skipping empty nodes and just returning the first // non-empty node's content as a string: echo $item->description(true, 'media'); // gets only the description nodes within the media namespace, // but returns the array of DOMElement nodes if there is more than // one node: foreach($item->description(false, 'media') as $node) { print_r($node); } // gets the first non-namespaced, non-empty description node and // returns its content as a string. If all non-namespaced description // nodes are empty, it will look for the first non-empty description // node in any other namespace and return the first non-empty node's // content as a string: echo $item->description(true); // and this would resemble the behaviour as it is now: just return // an array with all description nodes as DOMElement objects... print_r($item->description(false); </example> When following the above API proposal, I would opt for making the first parameter 'true' by default, so you'll have an easy, intuitive API that should work in at least 90% of all cases. Now, who's with me? :-D CU Markus
