00001 <?php
00002 error_reporting(E_ALL);
00003
00005 $SITE_NAME = 'My Website';
00007 $CONTENT_DIR = 'content';
00009 $SITE_URL = '';
00011 $SITE_DESC = 'Site Updates';
00013 $SCRIPT_PREFIX = '/index.php/page:';
00015 $COMMENT_PREFIX = '';
00016
00017 @include 'moonmoth-cfg.php';
00018
00019 function page_list($dir) {
00020 $cwd = getcwd();
00021 if (!@chdir($dir)) return array();
00022 $files = glob('*.html');
00023 chdir($cwd);
00024
00025 $pages = array();
00026 foreach ($files as $filename) {
00027 $pages[substr($filename, 0, -5)] =
00028 filemtime($dir . DIRECTORY_SEPARATOR . $filename);
00029 }
00030
00031 return $pages;
00032 }
00033
00034 function sitemap($location = array()) {
00035 global $CONTENT_DIR;
00036
00037 $page_dir = implode(
00038 DIRECTORY_SEPARATOR,
00039 array_merge(array($CONTENT_DIR), $location));
00040 $pages = page_list($page_dir);
00041
00042 $allpages = array();
00043 foreach ($pages as $page => $timestamp) {
00044 $new_location = array_merge($location, array($page));
00045 $path = implode(':', $new_location);
00046 $allpages[$path] = $timestamp;
00047 $allpages += sitemap($new_location);
00048 }
00049 return $allpages;
00050 }
00051
00052 $pages = sitemap();
00053 arsort($pages);
00054 $pages = array_slice($pages, 0, 15);
00055
00056 if (empty($SITE_URL)) {
00057 $SITE_URL = 'http://'
00058 . $_SERVER['SERVER_NAME']
00059 . dirname($_SERVER['SCRIPT_NAME']);
00060 }
00061
00062 header('Content-type: application/rss+xml');
00063
00064 print '<?xml version="1.0" encoding="utf-8"?>' . "\n";
00065 ?>
00066 <rss version="2.0">
00067 <channel>
00068 <title><?php print $SITE_NAME; ?></title>
00069 <link><?php print $SITE_URL; ?></link>
00070 <description><?php print $SITE_DESC; ?></description>
00071
00072 <?php foreach ($pages as $title => $timestamp): ?>
00073 <item>
00074 <title><?php print $title; ?></title>
00075 <pubDate><?php print date('D, F d Y H:i:s T', $timestamp); ?></pubDate>
00076 <link><?php print $SITE_URL . $SCRIPT_PREFIX . $title; ?></link>
00077 <?php
00078 $filename = $CONTENT_DIR . DIRECTORY_SEPARATOR .
00079 str_replace(':', DIRECTORY_SEPARATOR, $title) . ".html";
00080 ?>
00081 <?php if (is_file($filename) && is_readable($filename)): ?>
00082 <description>
00083 <?php print htmlspecialchars(
00084 strip_tags(
00085 file_get_contents($filename),
00086 '<p><a><strong><em><ul><li><img>')); ?>
00087 </description>
00088 <?php endif; ?>
00089 <?php if (!empty($COMMENT_PREFIX)): ?>
00090 <comments><?php print $SITE_URL . $COMMENT_PREFIX . $title; ?></comments>
00091 <?php endif; ?>
00092 </item>
00093 <?php endforeach; ?>
00094 </channel>
00095 </rss>