Written April 5, 2008 in apple, howto, php, webdev, wordpress

You might be wondering what these three things have to do with one another.

The basic gist is that I’m trying to use the Wordpress 2.5 RSS widget to read in my Google Reader ’shared items’ feed. Google Reader will publish your shared items in an Atom RSS feed. For a sample, you can see mine here.

The RSS feed is all fine and dandy. It’s valid, it’s namespaced correctly, and it’s got all but one of the required elements. The problem comes when you try to parse it with Magpie. Inside the “entry”, there’s a “title”. There’s also a “source”. The “source” has a “title” attribute as well.

Magpie merges these attributes into one string, which is then retrieved when wp_widget_rss_output pulls $item['title']. In other words, Magpie ignores the tag hierarchy, flattening all the content. Brilliant. This is what we in the business like to call an ‘irresponsible hack’.

There’s two places where this affected me, and I used different hacks to get around each. The first place it affected me was the aforementioned entry title vs. source title. The fix for that one was easy. I simply removed the title attribute from the _CONTENT_CONSTRUCTS array… and suddenly, I got the value I was looking for. The next one wasn’t so easy. The Magpie code parses together all of the link elements, and this is a special case handled in feed_start_element — basically, all of the link tags in each feed entry will be parsed together into one mangled hunk.

Whoever thought this was a good idea should be taken out back and shot. What a stupid hack. Sure, it’s XML! We can’t possibly have a one-to-many relationship! It works for me!

For the link fix, since I always just need the first link element, I added this to my wp_widget_rss_output function in wp-includes/widgets.php:

if($secondhttp = strpos($item['link'],’http’,5)) {
$item['link'] = substr($item['link'],0,$secondhttp);
}

It’s a stupid hack to compensate for a stupid hack, but I’m not going to spend an entire weekend mucking around inside of Wordpress’s retarded api just to get this RSS feed working.

As a side note, I’m really happy I no longer have to write PHP4 compliant code. More than an hour or two debugging this stuff now and my eyes and ears bleed.

Update: I made a forum post with some cleaner code examples on the wordpress forums.


Related:

2 comments on ' Wordpress 2.5, Google Reader’s RSS Feeds, and MagpieRSS '

  1. I’ve been trying to implement the same thing with a Google Reader feed. The problem still isn’t fixed.

Trackbacks/Pingbacks

Leave a comment

name (req'd)

email (req'd)

website