); TOOD: - Smart link extraction (feedburner or not) - Pass *all* options through an array (or make an object ?) - Title/Desc/Link override - Some filters : Slashdot ads, Slashdot XXX writes "blah, blah" - From where comes date_timestamp in magpie ? $rss_2_date = $item['pubdate']; $rss_1_date = $item['dc']['date']; $atom_date = $item['issued']; ChangeLog: * Datetime is no longer on the slashdot feed (?!), using dc-date and (buggy, hacked) parse_w3cdtf : "$seconds = str_replace(':','',$seconds);" at least to be moved here with a regex http://www.cadenhead.org/workbench/news/1620/get-dates-aggregator#a1806 IN FACT IT SEEMS TO BE A MAGPIE BUG WITH PHP 5.1.1 * 0.2 released - Fixed a really stupid bug - Added some error handling * 0.1 released */ require_once('magpierss/rss_fetch.inc'); require_once('feedcreator.class.php'); function rss_extender($url,$cachefile,$outfile,$maxitems,$maxdays=0) { // STAGE 0 * quick checks if ( !is_writable($cachefile) ) die("Cache file is not writable"); if ( !is_writable($outfile) ) die("Output file is not writable"); // STAGE 1 * read rss from url $rss = fetch_rss($url); if ( !$rss ) die('Feed fetch error'); // STAGE 2 * load data from file $data = unserialize( file_get_contents($cachefile) ); // invalid data file? create empty array if ( !is_array($data) ) $data = array(); // STAGE 3 * sync data : insert, sort, clean foreach ($rss->items as $item) { $timestamp = parse_w3cdtf($item['dc']['date']); $data[$timestamp] = $item; } // latest on top krsort($data); // keep the $maxitems latest items $data = array_slice($data,0,$maxitems,true); // delete $maxdays days old items if ($maxdays != 0) { $datelow = time() - ($maxdays * 24 * 3600); // delete if the key is too old foreach (array_keys($data) as $key) { if ($key < $datelow) unset($data[$key]); } } // STAGE 4 * write data to cache file file_put_contents ( $cachefile, serialize($data) ); // STAGE 5 * construct rss $outrss=new UniversalFeedCreator(); $outrss->title = $rss->channel['title']; $outrss->link = $rss->channel['link']; $outrss->description = $rss->channel['description']; foreach ($data as $item) { $outitem = new FeedItem(); $outitem->title = $item['title']; $outitem->link = $item['feedburner']['origlink']; $outitem->description = $item['description']; $outitem->date = $item['dc']['date']; $outrss->addItem($outitem); } // STAGE 6 * writing rss echo $outrss->saveFeed("RSS2.0", $outfile, false); // DEBUG if (0) { echo count($data); echo '
'; print_r($rss); print_r($data); // echo serialize($data); echo ''; } } ?>