Sidebar stars

Cool thing #1: Using rvw!, del.icio.us, RSS and Magpie to create a links sidebar with rating stars (see the side of HubLog's front page for an example).

Magpie code:


$rss = fetch_rss( 'http://del.icio.us/rss/USERNAME' );
$items = array_slice($rss->items, 0, 10);
echo "document.write(\"<ul>";
foreach ($items as $item) {
    $href = $item['link'];
    $title = str_replace ("\n", "", $item['title']);
    $subject_array = split(" ", $item['dc']['subject']);
    $star_url = "";
    foreach ($subject_array as $tag){
        if (preg_match("/rating\:([0-9]+)%/", $tag, $matches)){
            $twice_actual_rating = $matches[1]/10;
            $rating_round_half = round($twice_actual_rating, 0)/2;
            $remainder = fmod($rating_round_half, 1);
            $rating = $rating_round_half - $remainder;
            $half_star = ($remainder == 0.5) * 5;
            $star_url = "http://g-images.amazon.com/images/G/01/detail/stars-$rating-$half_star.gif";
            $star = "<img src=$star_url>";
        }
    }
    echo "<li><a href=$href>$title</a>$star</li>";
}
echo "</ul>\")";