Tuesday, April 15, 2008

RSS feed links as error messages

Things have been pretty quiet here of late work wise, so I decided that I was bored with writing error messages for our internal tools. The person who uses the tools 99% of the time had expressed the opinion that error messages such as: There was an error, try again later; are boring, and she prefers the ones I write when I'm mad: It didn't work. BUMMER!.

With this in mind, and knowing her love for a certain blog that talks about celebrities in an unflattering light.. I thought wouldn't it be fun to incorporate links to the blog, with headlines, in the messages. This will aid me in two ways. Firstly she will have something to do while I fix the error. Secondly it will make her like me more, thereby improving communication between our parts of the sites. OK.. maybe the second one isn't the real reason..

I searched for a while trying to find a super simple way of grabbing what I needed. Honestly I don't remember it being this hard last time, but I settled on an example, and some tools from Bobulous.
I'm using the xml regex functions from Bobulous, as well as the make_safe function (good idea, and similar to one I already have).
The resultant code looks like this:

$xml = file_get_contents('http://dlisted.com/rss.xml');
$news_items = element_set('item', $xml);
foreach($news_items as $item) {
$title = value_in('title', $item);
$url = value_in('link', $item);
$item_array[] = array(
'title' => $title,
'url' => $url);
}

if (sizeof($item_array) > 0) {
$count = 0;
$html="";
foreach ($item_array as $item) {
//I removed the link from the next line.. blogger was not pleased
$html .=make_safe($item['title']);
$html .= ', ';
// Limit the output to three news items.
if (++$count == 3) {
break;
}
}
$html .= '<br>';
$funniest_error=$html;
}

Now wherever I want to leave a nice lil title/link for the users, I'll include this page, and put $funniest_error wherever I want the list of 3 links to appear!

Fun!

0 comments: