del.icio.us feed

blogging

I had been thinking for a while that I'd like to incorporate some quick links in the sidebar to things that I've read and enjoyed, but I was still deciding on the best way to do it. There are some nice WordPress solutions, like markku's excellent wp-recent-links, but I was feeling exceptionally lazy and thought that there must be another way to do it.

Then I remembered the service which allows you to quickly mark and categorise links, and display them publicly: del.icio.us. It's really easy to set up an account, and you can see my page here. There's also an easy method (using a query string) to get a raw HTML fragment containing the last x links in your feed, which you can then include in your blog page.

So, I put a bit of PHP in my sidebar to pull in the last 10 links. You should be able to include HTML files from remote sites using:

include 'http://somesite.com/file.inc';

but it seems that my hosts don't have the allowurlfopen option enabled, so I had to think of another way to do it.

I found this code in the Programming PHP book:


function include_remote($filename) {
 $data = implode("n", file($filename));
 if ($data) {
 $tempfile=tempnam(getenv("TEMP"),"inc");
 $fp = fopen( $tempfile,"w");
 fwrite( $fp, "$data");
 fclose( $fp );
 include($tempfile);
 unlink($tempfile);
 }
 return FALSE;
 }
include_remote("http://somesite.com/file.html");

This works very nicely when passed a formatted URI to my del.icio.us feed.

Update: Jens pointed out in the comments below, that such frequent fetching of the feed might violate the terms of service. At the very least, it isn't very efficient or polite. So here's another solution — I'm now fetching the feed like this:

wget "http://del.icio.us/html/bsag/?count=10&extended=body
&tags=yes&tagsep=|&rssbutton=yes"

This should all be on one line. I run this command via cron every 6 hours, and then just include the local file delicious.html in the page.

comments powered by Disqus