Blog Pile

Feed2JS: A Few More Tweaks and WordPress Date Woes

Thanks for the comments that have helped identify some minor and not so minor issues with our new Feed to Javascript site. See below for updates!

Some updates for folks that have implemented their own versions of this:

A few early versions had a typo where the MAGPIE_CACHE_DIR was defined (it said MAGPIE_DIR). Most problems with cache files not being created are permissions related- the web server must be able to write to the directory where you want cache files stored. If it cannot find this directory, it tries to create a new one named “cache” within the same directory the magpie include libraries reside. The easiest thing to do is to create a directory inside here named “cache” and make sure its privileges are set to the web server can create new files inside of it.

And as David Carter-Tod pointed out, Magpie is caching the requests for the RSS source, not the generated JavaScript content- so each request does reprocesses with a cached version of the feed content or a fresh one if the cache has expired. I am not that invested in creating another cache process– my goal was not to bombard RSS source servers with repeated calls.

Also, it was pointed out that WordPress puts “‘|” before quote characters in its published feeds (“escaping quotes”) so a slight tweak in the strip_returns function is able to cleanse these. Just change:

  $subquotes = ereg_replace("'", "'", $text);

to read:

  $subquotes = ereg_replace("'", "'", stripslashes($text));

Finally, I am not sure where the root of this problem lies, but it looks like the RSS 2.0 feeds oublished by WordPress are not being picked up by the Magpie parese, so our script in turn cannot display these. It looks like to me (not an expert) that WordPress is not publishing a correctly formatted time stamp (it lacks a time zone), e.g.:

<pubDate>Wed, 02 Jun 2004 01:34:27 +0000</pubDate>

where the RSS2.0 standard calls for “All date-times in RSS conform to the Date and Time Specification of RFC 822” and the example is:

<pubDate>Sat, 07 Sep 2002 00:00:01 GMT</pubDate>

I do not know if this is an issue that the Magpie code can circumvent (a request has been made) or it is something that WordPress needs to change, or that WordPress authors need to change in their templates. But until then, our code is unable to generate published dates for WordPress RSS feeds.

Update: June 3, 2004 Until I can figure this out, I have modified the latest versions of feed2js.php so that it sniffs the item arrays for either a date in the formation of $item[‘dc’][‘date’] or $item[‘pubdate’]– I guess I assumed wrongly that Magpie would find the date and always stuff it into the first variable. Each date format requires a different method to convert to a presentable date.

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for cogdog
An early 90s builder of the web and blogging Alan Levine barks at on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person.


  1. The RFC allows for a text timezone or offset

    / ( (“+” / “-“) 4DIGIT ) ; Local differential

    ; hours+min. (HHMM)

    The example you posted has +0000, an offet of 0 hours which is the same as GMT/UTC.

  2. I changed lines 193 and 194 to read

    if ($date == ‘y’ and $item[‘pubdate’]) {

    $my_date = $item[‘pubdate’];

    instead of using $item[‘dc’][‘date’] and it prints the date, but not in a pretty format. I’m not sure what to do to change the format but for now it’s good’nuff. You also have to change line 197 to use $my_date instead of $pretty_date.

    I’ll play around with an if-elif statement of some sort, since my example would not read a dc:date field. I’m not a programmer so I’ll see what other damage I can do.

  3. Thanks Dave- the WordPress date format should be legit.

    Todd, I found that magpie can return the date iin two different array places, so the latest script now has two methods for formatting the date… it is possible that the magpie utility in utils_inc.php may need a tweak, but the new script works for your feeds now:

Comments are closed.