URL: http://www.rssFeedFolder.com/
This script is a modification of the RSS Feed Folder script available at http://www.rssFeedFolder.com/ . The original script created an RSS feed based on the latest changed files by html title and meta description tags. My modification removes the html components of the original script, instead aiming to generate an RSS feed with the latest files (recursive) in the specified directory.
The updated script achieves this by looping recursively through all directories that it finds within the specified path and listing out the file names and modification times (filemtime) as it goes. Once it has an array of all filenames with their modification times, it reverse sorts this list and does an array_slice on the first $rssMaxItems to be displayed. Finally, the script echos all the items in RSS format.
<?php ########################################################################### ### ### RSS FEED FOLDER ### http://www.rssFeedFolder.com ### ### v1.1 ### Nov 7th 2010 ### Author: Karl Horky ### Purpose: Display list of files in given directory, starting from latest ### ### v1.0 ### June 3rd 2009 ### ########################################################################### ########################################################################### ### ### Edit these next few lines to customize your feed ### ########################################################################### $rssTitle = "RSS Feed Title"; $rssDescription = "RSS feed created using tools from http://www.rssFeedFolder.com"; $rssLink = "http://www.rssFeedFolder.com/"; $rssLanguage = "en"; $rssCopyright = "rssFeedFolder.com"; $rssTtl = "1000"; //$rssLogo = "http://www.rssFeedFolder.com/images/rssFeedFolderLogo.gif"; // Example directory to list items from $rssFolder = "Music"; // Make $strDocRoot point at the parent of your example directory ("Music" above) ########################################################################### ### The name of the folder to build the feed from is an optional parameter ### e.g. http://www.yourdomain.com/cgi-bin/rss.cgi?feed=news ### http://www.yourdomain.com/cgi-bin/rss.cgi?feed=overstock ### The $rssFolder setting is used if you just call ### http://www.yourdomain.com/cgi-bin/rss.cgi ########################################################################### $feed = $_GET['feed']; if ( $feed == "" ) { $feed = $rssFolder; } ########################################################################### ### Determine website config details to locate and create the feed links. ########################################################################### $strTimeZone = "GMT"; $strHost = $_SERVER['SERVER_NAME']; $strScript = $_SERVER['SCRIPT_NAME']; $rssDate = rfcDate($rawDate); ########################################################################### ### Start the Feed ########################################################################### "; echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\"> "; echo " <channel> "; ########################################################################### ### Feed owner details ########################################################################### echo " <title>$rssTitle</title> "; echo " <description>$rssDescription</description> "; echo " <link>$rssLink</link> "; echo " <language>$rssLanguage</language> "; echo " <copyright>$rssCopyright</copyright> "; echo " <pubDate>$rssDate</pubDate> "; echo " <lastBuildDate>$rssDate</lastBuildDate> "; echo " <generator>rssFeedFolder.com</generator> "; echo " <ttl>$rssTtl</ttl> "; echo " <atom:link href=\"http://${strHost}${strScript}\" rel=\"self\" type=\"application/rss+xml\" /> "; ########################################################################### ### The items in the feed ########################################################################### $cArticles = 0; // Loop recursively through all directories in specified path and list all files function getFiles($strDocRoot, $path, &$files) { } else { getFiles($strDocRoot, $node, $files); } } } getFiles($strDocRoot, "$strDocRoot$feed", $files); //foreach ( glob("$strDocRoot/$feed/*") as $strFile ) foreach ($newestFiles as $strFile => $filemtimeFile) { $cArticles++; ################################################################### ### Published Date is the modification date of the feed item ################################################################### ################################################################### ### Print the item info ################################################################### $strArticle = ""; $strArticle .= " <item> "; $strArticle .= " <title><![CDATA[$strFile]]></title> "; $strArticle .= " <pubDate>$strPubDate</pubDate> "; $strArticle .= " </item> "; echo $strArticle; } echo " </channel> "; echo "</rss> "; ########################################################################### ### Translate UNIX date format into the format required by RSS ### which is: Tue, 04 Dec 2007 15:22:43 CST ########################################################################### function rfcDate( $date ) { $ret = ""; ################################################################### ### Tue Dec 4 15:22:43 CST 2007 => Tue, 04 Dec 2007 15:22:43 CST ################################################################### if ( $matches ) { $ret = sprintf("%s, %2.2d %s %d %s %s", $matches[0], $matches[2], $matches[1], $matches[5], $matches[3], $matches[4]); $strTimeZone = $matches[4]; } ################################################################### ### Tue Dec 4 15:22:43 2007 => Tue, 04 Dec 2007 15:22:43 CST ################################################################### else { if ( $matches ) { $ret = sprintf("%s, %2.2d %s %d %s %s", $matches[0], $matches[2], $matches[1], $matches[4], $matches[3], $strTimeZone); } } return $ret; } ?>
You need to login to post a comment.
