From 823ab006aaa504aaaa9be5e9b5c27cbdf3df28cc Mon Sep 17 00:00:00 2001 From: Nick White Date: Sun, 23 Aug 2009 02:41:10 +0100 Subject: Initial commit of website code --- includes/rss.php | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 includes/rss.php (limited to 'includes/rss.php') diff --git a/includes/rss.php b/includes/rss.php new file mode 100644 index 0000000..d752f26 --- /dev/null +++ b/includes/rss.php @@ -0,0 +1,93 @@ +. + */ + +header("Content-Type: application/rss+xml"); + +function extract_description($body) +{ + $body = explode("\n", $body); + $description = strip_tags($body[0]); /* use first line of body */ + return $description; +} + +function rss_header($metadatafile) +{ + print("\n"); + print("\n"); + + /* get variables to use for channel metadata */ + include($_SERVER['DOCUMENT_ROOT'] . $metadatafile); + + print("\n"); + print("\t" . $title . "\n"); + print("\t" . "http://" . $_SERVER['HTTP_HOST'] . "\n"); + $description = extract_description($body); + print("\t" . $description . "\n"); + print("\t" . date("r") . "\n"); + if (isset($copyright) && !empty($copyright)) + print("\t" . $copyright . "\n"); + if (empty($language) || !isset($language)) + $language = "en"; + print("\t" . $language . "\n"); +} + +function create_item($dir, $file, $full=0) +{ + unset($title, $body, $description, $language, $category, $pubdate); + print("\t\n"); + include($_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/" . $file); + print("\t\t" . $title . "\n"); + print("\t\t" . "http://" . $_SERVER['SERVER_NAME'] . "/" . $dir . "/" . $file . "\n"); + print("\t\t" . "http://" . $_SERVER['SERVER_NAME'] . "/" . $dir . "/" . $file . "\n"); + $pubdate = filemtime($dir . "/" . $file); + $pubdate = date("r", $pubdate); + print("\t\t" . $pubdate . "\n"); + $category = ereg_replace("^text", "", $dir); /* dir after text */ + if (!empty($category)) + print("\t\t" . $category . "\n"); + if ($full) + print("\t\t" . strip_tags($body) . "\n"); + else + print("\t\t" . extract_description($body) . "\n"); + print("\t\n"); +} + +function create_items_from_dir($dir, $full=0) +{ + if ($handle = opendir($dir)) { + while (false !== ($file = readdir($handle))) { + if (!is_dir($file)) { + if ($file[0] != "." && ereg(".php$", $file)) + create_item($dir, $file, $full); + } + else { + if ($file[0] != ".") + create_items_from_dir($dir . "/" . $file, $full); + } + } + closedir($handle); + } +} + +function rss_footer() +{ + print("\n"); + print("\n"); +} + +?> -- cgit v1.2.3