phoboslab

Posts tagged with “Blogging”

Fixing Favatars

Ever since this blog went online I used Favatars to make it more easy to recognize authors of comments. I think this worked out really well for my site, as many visitors have their own websites and favicons. However, despite Paul James pointing out that Cool URIs don't change, I had more and more 404s when I viewed my site. All of these resulted from favicons that weren't there anymore.

To fix this, I wrote a small PHP5 class that attempts to download the favicon from the commentators website. This class is very conservative - it stops a download if it's bigger than 50 kb, has a short timeout, only allows PNG, GIF, JPEG and ICO extensions and silently returns if there's any error. Here's how you can use it:

// Create a new Favatars object and tell it to save 
// all favicons to files/favatars/
$favatars = new Favatars( 'files/favatars/' );

// The get method attempts to find a favicon for the given
// URL and returns the local path of the downloaded favicon, 
// or an empty string if none could be found.
$comment['favatar'] = $favatars->get( $comment['website'] );

Read on to view the source of this class.

Read complete post »

PHP, Blogging / 2008.07.05 - 21:49 / Comments (0)