Posts Tagged ‘simplepie’

CSS Class Based on Date

Wednesday, August 1st, 2007
Posted in Web Development · Tags: , , ,

I recently saw a tutorial on SimplePie’s site about using relative dates and I modified the function to output a CSS class rather than text. That way you can make newer stories bold, brighter, or bigger and older stories dimmed out or smaller. Use your imagination with CSS. 🙂

Here is the function

//CREATE CSS BASED ON DATE
function create_age_css_class($date_sent)
{
/**
$date_sent should be in the following format: YYYYMMDDHHMMSS
Based on doRelativeDate() By Garrett Murray, http://graveyard.maniacalrage.net/etc/relative/
**/
$in_seconds = strtotime(substr($date_sent,0,8).' '.
substr($date_sent,8,2).':'.
substr($date_sent,10,2).':'.
substr($date_sent,12,2));
$diff = time()-$in_seconds;
if ($diff < 86400)
$css_class = 'age_today';
else if ($diff < 604800)
$css_class = 'age_days';
else if ($diff < 1209600)
$css_class = 'age_week';
else if ($diff < 2630880)
$css_class = 'age_weeks';
else
$css_class = 'age_month';
return $css_class;
}

Here is how I call it

$data .= '<li><a href="'. $item->get_permalink();
//SET CLASS BASED ON DATE/AGE
$data .= ' class="' . create_age_css_class($item->get_date('YmdHis')) . '"';
$data .= '>';

You don’t have to use SimplePie for this function, but it’s what inspired me to modify it.

Now for an screenshot

Here is the HTML I used for that

<ul id="type3">
<li class="age_today">Lorem ipsum dolor sit amet</li>
<li class="age_days">Etiam iaculis nulla iaculis mauris</li>
<li class="age_week">Suspendisse at odio</li>
<li class="age_week">Nullam volutpat aliquam lacus</li>
<li class="age_weeks">Nunc dapibus eros vitae mauris rutrum laoreet</li>
<li class="age_weeks">Suspendisse sed nisl</li>
<li class="age_month">Nulla scelerisque gravida neque</li>
<li class="age_month">Leo imperdiet metus, ut adipiscing nisi lacus et pede</li>
</ul>

And here is the CSS used

<style type="text/css">
body {font-family:Verdana, Arial, Helvetica, sans-serif; color:#000; background-color:#fff;}
ul {list-style:none;}
#type3 .age_days {font-size:150%; color:#555;}
#type3 .age_week {font-size:100%; color:#777;}
#type3 .age_weeks {font-size:80%; color:#999;}
#type3 .age_month {font-size:60%; color:#ccc;}
</style>

Added screenshot and sample CSS

SimplePie and Digg’s RSS Feeds

Thursday, July 26th, 2007
Posted in Web Development · Tags: , ,

Been playing with SimplePie some more and here is some code for dealing with Digg’s RSS feed. I included some stuff in comments that just shows how their namespaces look.


/*
<digg:diggCount>95</digg:diggCount>
<digg:submitter>
<digg:username>kilooneniner</digg:username>
<digg:userimage>http://digg.com/userimages/k/i/l/kilooneniner/medium9515.jpg</digg:userimage>
</digg:submitter>
<digg:category>Political News</digg:category>
<digg:commentCount>9</digg:commentCount>
*/
//DIGG NAMESPACES
$digg_count = $item->get_item_tags('http://digg.com/docs/diggrss/', 'diggCount');
$digg_comments = $item->get_item_tags('http://digg.com/docs/diggrss/', 'commentCount');
$digg_category = $item->get_item_tags('http://digg.com/docs/diggrss/', 'category');
$digg_submitter = $item->get_item_tags('http://digg.com/docs/diggrss/', 'submitter');
$digg_username = $digg_submitter[0]['child']['http://digg.com/docs/diggrss/']['username'];
$digg_userimage = $digg_submitter[0]['child']['http://digg.com/docs/diggrss/']['userimage'];
if (!empty($digg_count[0]['data']))
$data .= '<br /><span class="minor">' . $digg_count[0]['data'] . ' diggs &middot; ' . $digg_comments[0]['data'] . ' comments &middot; ' . $digg_category[0]['data'] . ' &middot; ' . $digg_username[0]['data'] . ' &middot; ' . $digg_userimage[0]['data'] . '</span>';

Using something like the following helps traverse the arrays to figure out how to get the data.

print_r($digg_submitter);//will show array to parse to get stuff

Get Yahoo Weather with SimplePie

Wednesday, July 25th, 2007
Posted in Web Development · Tags: , , ,

SimplePie is a new PHP library made to make parsing RSS feeds easy and fun. Yes I said fun, because its very easy and the docs are well written. RSS is more than just news, it can be images, video and podcasts. Mash up the data however you want, I’ve seen some innovative and unique things done so far. They also offer sample code on making a site like popurls/Original Signal.

Figure I’d share some code I used with SimplePie and a Yahoo Weather RSS feed. I can’t post it all on the homepage as its really long. It does transform and output the data nicely (not any CSS styling but I do calculate the wind direction and some other things). Please note that Yahoo only permits you to use their Weather RSS feed on non-commercial sites.

(more…)

Web Based OSS RSS Feed Aggregators

Thursday, May 24th, 2007
Posted in Web Apps · Tags:

MonkeyChow – based on feedonfeeds, this one is updated quite a bit, you might visit the developer’s blog for current updates

Tiny Tiny RSS – This one is in active development also, it looks very good also, similar to how a offline Feed Aggregator might look, they have a online demo also

FoFRedux (feed on feeds – redux) – based on feedonfeeds, even though they have like 7 developers they haven’t released a new verison in a long time

feed on feeds – pretty much dead, despite the fact the developer stated he was bringing it back

Of course nowdays you can use Magpie, SimplePie to build your own popurls / Original Signal clone or use Pageflakes, Netvibes or Google Reader if you don’t want to build it and host it yourself.