website rev 799
get-feed.php: clean up, improve speed (get 4 last entry and break), show up hour
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Mar 30 17:27:20 2011 +0200 (2011-03-30) |
parents | a8dd792c6e46 |
children | b71d2e7bc0c4 |
files | libs/get-feed.php |
line diff
1.1 --- a/libs/get-feed.php Wed Mar 30 16:17:23 2011 +0200 1.2 +++ b/libs/get-feed.php Wed Mar 30 17:27:20 2011 +0200 1.3 @@ -4,25 +4,19 @@ 1.4 function get_rss_feed($feed_url) { 1.5 $content = file_get_contents($feed_url); 1.6 $x = new SimpleXmlElement($content); 1.7 + $entries = 4; 1.8 + $count = 0; 1.9 // We look for last item, channel may not have a PubDate* 1.10 $up = ($x->channel->item->pubDate); 1.11 - echo "<span>Updated: " . substr("$up", 5, 12) . "</span>\n"; 1.12 + echo "<span>Updated: " . substr("$up", 5, 17) . "</span>\n"; 1.13 echo "</p>\n<div>\n<ul>\n"; 1.14 foreach($x->channel->item as $entry) { 1.15 - echo " <li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>\n"; 1.16 - } 1.17 - echo "</ul>\n"; 1.18 -} 1.19 - 1.20 -// Read Atom Feed 1.21 -function get_atom_feed($feed_url) { 1.22 - $content = file_get_contents($feed_url); 1.23 - $x = new SimpleXmlElement($content); 1.24 - $up = ($x->updated); 1.25 - echo "<span>Updated: " . substr("$up", 0, 10) . "</span>\n"; 1.26 - echo "</p>\n<div>\n<ul>\n"; 1.27 - foreach($x->entry as $entry) { 1.28 - echo " <li><a href='$entry->id' title='$entry->title'>" . $entry->title . "</a></li>\n"; 1.29 + $count = $count + 1; 1.30 + echo " <li><a href='$entry->link' title='$entry->title'>" . 1.31 + $entry->title . "</a></li>\n"; 1.32 + if ($count == $entries) { 1.33 + break; 1.34 + } 1.35 } 1.36 echo "</ul>\n"; 1.37 }