| « Another minor change | Normal service... » |
Wed, Jun 17, 2009
![[Icon]](rsc/img/chain_link.gif)
There was a brief email thread on the MagpieRSS mailing list about including the date. I thought that was a good idea, so I did a minor bit of PHP editing so that my blogroll will now show the date of the most recent post as well as the title & link.
As ever, feedback welcome. The new code used to generate the blogroll is included below for anybody who's interested:
<?php
// Turn off error displays - we'll handle this ourselves later
ini_set('display_errors', 0);
require_once('../magpierss/rss_fetch.inc');
// Tell MagpieRSS where to find the RSS feed
$rss = fetch_rss('[RSS feed]');
// Put in a link to the blog with its favicon
echo "<img style=\"border: 0px solid ; width: 16px; height: 16px;\" alt='icon'
src=\"[Favicon]\" />
<a href=\"[Blog URL]\">
[Blog name]</a><br />";
// Now to process the actual RSS feed. If the feed is valid, grab the most recent item
if ( $rss) {
$short_items = array_slice($rss->items,0,1);
// To be polite, only update every half-hour (1800 secs)
define('magpie_cache_age', 1800);
// Tell Magpie to use UTF-8 encoding
define('magpie_output_encoding', 'utf-8');
define('magpie_input_encoding', 'utf-8');
define('magpie_detect_encoding', 'false');
foreach ($short_items as $item) {
$title = $item['title'];
$href = $item['link'];
$pubdate = date('d/m/y',strtotime($item['pubdate']));
$longdesc = $item['description'];
$desc = trim(strip_tags($longdesc));
$title = trim(strip_tags($title));
// Keep things a reasonable length: 60 character headings and 300 characters from the articles
if (strlen($desc) >= 300)
{
$desc = substr($desc,0,299)."...";
}
if (strlen($title) >= 60)
{ $title = substr($title,0,59)."..."; }
// Insert a "Link" icon that will link (duh) to the most recent post:
echo "<a href=\"$href\"><img alt='[Link]' title=\"";
// To prevent double-quote issues, use htmlentities (Thanks Cosmin!)
echo htmlentities($desc);
echo "\" src=\"[Link icon]\" /></a>
<font size=\"1\">$pubdate - $title</font><br />";
}
}
// In case of an error fetching the RSS feed, 'fess up
else {
echo "<font color=red><font size=\"1\">Unable to fetch RSS</font></font><br />";
}
?>
...seems like a LOT of code for two lousy lines of text in a sidebar, doesn't it? :o)
It's an accepted and standard international time zone. PHP developers should learn geography first. :-P
![[Links]](http://geekblog.oneandoneis2.org/skins/112/rsc/img/chain_link.gif)
Hmm.. new look for twitter? I hope it gets less "Ick! Change! Put it back!" nonsense than Facebook..
08/02/12
Facebook Syndication Error
09/02/12
![]()
I last listened to:
Johann Pachelbel - Canon in D major
Most recent photo:
Submersible houseboat