<?php /* * Copyright (C) 2009 Nick White * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 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("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); print("<rss version=\"2.0\">\n"); /* get variables to use for channel metadata */ include($_SERVER['DOCUMENT_ROOT'] . $metadatafile); print("<channel>\n"); print("\t<title>" . $title . "</title>\n"); print("\t<link>" . "http://" . $_SERVER['HTTP_HOST'] . "</link>\n"); $description = extract_description($body); print("\t<description>" . $description . "</description>\n"); print("\t<pubDate>" . date("r") . "</pubDate>\n"); if (isset($copyright) && !empty($copyright)) print("\t<copyright>" . $copyright . "</copyright>\n"); if (empty($language) || !isset($language)) $language = "en"; print("\t<language>" . $language . "</language>\n"); } function create_item($dir, $file, $full=0) { unset($title, $body, $description, $language, $category, $pubdate); print("\t<item>\n"); include($_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/" . $file); print("\t\t<title>" . $title . "</title>\n"); print("\t\t<link>" . "http://" . $_SERVER['SERVER_NAME'] . "/" . $dir . "/" . $file . "</link>\n"); print("\t\t<guid>" . "http://" . $_SERVER['SERVER_NAME'] . "/" . $dir . "/" . $file . "</guid>\n"); $pubdate = filemtime($dir . "/" . $file); $pubdate = date("r", $pubdate); print("\t\t<pubDate>" . $pubdate . "</pubDate>\n"); $category = ereg_replace("^text", "", $dir); /* dir after text */ if (!empty($category)) print("\t\t<category>" . $category . "</category>\n"); if ($full) print("\t\t<description>" . strip_tags($body) . "</description>\n"); else print("\t\t<description>" . extract_description($body) . "</description>\n"); print("\t</item>\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("</channel>\n"); print("</rss>\n"); } ?>