Elaborate del.icio.us sidebar

by Carson Reynolds

I’ve been feeling a bit guilty about abusing del.icio.us wth the simple sidebar scheme I detailed a little earlier. So here is a much more complex way of getting a sidebar on your blog. This is a self-contained PHP caching sidebartender. To use it, copy and paste it into the relevant blog template code. Change $user to be your del.icio.us user name. Assuming, of course, that you have PHP configured and that you can write a file called sidebar.html in the same directory as the page, it should work like a charm.

// This script writes a del.icio.us sidebar.html cache file
// and updates it after 5 minutes have elapsed.
// I added this code to the MT Main Index inside
// <div class="side"> ... </div> on my blog.

$opts = "?count=10&tags=no&bullet=&rssbutton=no";
$url = "http://del.icio.us/html/";
$cachefile = "sidebar.html"; // name of cache file
$cachetime = 5 * 60; // 5 minutes

// if cache is valid, just use it instead of hitting del.icio.us
if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile)))
} else {
  // otherwise update the cache

  //read from del.icio.us
  readfile($url . $user . $opts);

  $fp = fopen($cachefile, 'w');
  fwrite($fp, ob_get_contents());