elelement for link and for publish date Modified by Alan Levine 04.dec.2003 - fixed problem with incorrect parsing of item published dates from RSS 2.0 feeds Modified by Alan Levine 15.dec.2003 - changed redirection for bad RSS URLs to nosource.php (so it could generate the correct feedback for use on other web sites) Usage: see http://jade.mcli.dist.maricopa.edu/feed/ Local customization can be achieved via declarations of CSS for div.rssbox (style for bounding box) class.rss_title (style for title of feed) class.rss_item, class.rss_item a (style for linked entry) class.rss_date (style for date display) This makes use of the Onyx RSS parser from http://www.readinged.com/onyx/rss/ */ // utility to remove return characters from strings that might // pollute JavaScript commands function strip_returns ($text) { return ereg_replace("(\r\n|\n|\r)", " ", $text); } // POSTED VARS // retrieve from posted vars, just in case PHP globals are off $xml_src = $_GET['src']; // flag to show channel info, values = no/yes/title; default = yes if ($_GET['chan']) { $channel_option = $_GET['chan']; } else { $channel_option = 'yes'; } // variable to limit number of displayed items; default = 0 (show all) if ($_GET['num']) { $num_option = $_GET['num']; } else { $num_option = 0; } // flag to show item description, values = no/yes; default = no if ($_GET['desc']) { $desc_option = $_GET['desc']; } else { $desc_option = 'no'; } // flag to show date of posts, values = no/yes; default = no if ($_GET['date']) { $date_option = $_GET['date']; } else { $date_option = 'no'; } // ERROR TRAP // trap for missing src param, divert to an error page if (!$xml_src) header("Location:nosource.php"); // INCLUDES // path to location of onyx-rss code files include('onyx-rss.php'); // VARIABLES // relative or full path to cache directory (must be writable permissions CHMOD 777) $cachePath = './cached/'; // output spec for item date string if used // see http://www.php.net/manual/en/function.date.php $date_format = "F d, Y h:i:s a"; // START OUTPUT // headers to tell browser this is a JS file header("Content-type: application/x-javascript"); // create unique cache file name based on URL of feed $url_parts = parse_url($xml_src); $xfile = $url_parts["host"] . $url_parts["path"] . $url_parts["query"]; $xfile = preg_replace("/(\/|=|&)/", "-", $xfile); // Use Onyx RSS $rss = new ONYX_RSS(); // set local local cache (must by CMHMOD 777) $rss->setCachePath($cachePath); //use object mode $rss->setFetchMode(ONYX_FETCH_OBJECT); // set cache based on XML file / path name // The default cache time is 3 hours (180 minutes) // This can be over-rided by adding a third paramater // parse(feed_url, cachefile, cache_exipires_minutes) $rss->parse($xml_src, "$xfile.cache"); // get channel data $channel = $rss->getData(ONYX_META); // begin javascript output string for channel info $str = "document.write('
');\n"; if ($channel_option == 'yes') { // output channel title and description $str.= "document.write('

link\">" . addslashes(strip_returns($channel->title)) . "
" . addslashes(strip_returns($channel->description)) . "

');\n"; } elseif ($channel_option == 'title') { // output title only $str.= "document.write('

link\">" . addslashes(strip_returns($channel->title)) . "

');\n"; } // begin item listing $str.= "document.write('
');\n"; $str .= "document.close();"; // return results echo $str; ?>