[1+1=2]

OneAndOneIs2

« Another minor changeNormal service... »

Wed, Jun 17, 2009

[Icon][Icon]Minor blogroll update

• Post categories: Omni, FOSS, Technology

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)

8 comments

Hari
Comment from: Hari [Member] · http://harishankar.org/blog/
Hey, I wasn't even born in 31/12/69

:P
18/06/09 @ 04:13
oneandoneis2
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
Can you prove it? :P

It appears that PHP's strtotime function doesn't understand "IST" as a timezone. Any chance you can emigrate? :o)

Until you do, I just str_replaced your timezone and that should fix the problem! :o)
18/06/09 @ 15:32
Hari
Comment from: Hari [Member] · http://harishankar.org/blog/
Well I can send you a copy of my birth certificate, if you like :-p

IST is Indian Standard Time. It's an accepted and standard international time zone. PHP developers should learn geography first. :-P
18/06/09 @ 15:35
Hari
Comment from: Hari [Member] · http://harishankar.org/blog/
It's an accepted and standard international time zone. PHP developers should learn geography first. :-P

I read that again and I think there is potential for misunderstanding. So here's what I meant by that: the people who created PHP; it's not directed at you or anybody else who writes PHP scripts.
18/06/09 @ 16:42
oneandoneis2
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
Hey, I knew it wasn't *my* fault - all the other feeds worked fine, so I knew it was either PHP's fault or yours ;o)

No worries!
18/06/09 @ 22:02
Hari
Comment from: Hari [Member] · http://harishankar.org/blog/
Well, I checked the RSS specifications and it seems IST is not one of the recognized time zones.

Well, all I can say is SCREW them and SCREW their ancestors. If they don't recognize IST as a standard time zone, I don't care about complying with their *****ing standards. I'll publish an invalid feed sooner than give up my timezone or National identity.
19/06/09 @ 05:11
oneandoneis2
Comment from: oneandoneis2 [Member] · http://geekblog.oneandoneis2.org/
I've glanced at the spec too - looks like they go right back to ARPA for their time/date spec. Ah, the nostalgia!

In this case, tho, surely it's PHP rather than RSS that's caused the bug? It was PHP's strtotime function's inability to understand IST as a zone that was the problem.

Maybe submit it as a bug report? It's a valid zone that their function doesn't understand, seems like a valid problem to me, and one that should be easy enough to fix for the next version.
19/06/09 @ 10:28
Hari
Comment from: Hari [Member] · http://harishankar.org/blog/
Dominic, I think so too. I believe that most RSS readers can accept date/time in any format.

PHP might be lagging behind in this aspect.

Also you know about these tech specification committees. They usually lag way behind the actual developments.
19/06/09 @ 11:51

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
 

[Links][icon] My links

[Icon][Icon] Hmm.. new look for twitter? I hope it gets less "Ick! Change! Put it back!" nonsense than Facebook..
08/02/12

[Icon][Icon] Facebook Syndication Error
09/02/12

[Icon][Icon] I last listened to:
Johann Pachelbel - Canon in D major

[Icon][Icon] Most recent photo:
Submersible houseboat

[Icon][Icon]About Me

[Icon][Icon]About this blog

[Icon][Icon]My LQ profile

[Icon][Icon]My /. profile

[Icon][Icon]My Wishlist

[Icon]MyCommerce

[FSF Associate Member]


February 2012
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29        

Search

User tools

XML Feeds

eXTReMe Tracker

Valid XHTML 1.0 Transitional

Valid CSS!

[Valid RSS feed]

multiblog