summaryrefslogtreecommitdiff
path: root/includes/rss.php
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2009-08-23 02:41:10 +0100
committerNick White <git@njw.me.uk>2009-08-23 02:41:10 +0100
commit823ab006aaa504aaaa9be5e9b5c27cbdf3df28cc (patch)
treee0c907ec2afa1ecf57ffa72e77bc211b5699b9e6 /includes/rss.php
downloadnjw-website-source-823ab006aaa504aaaa9be5e9b5c27cbdf3df28cc.tar.bz2
njw-website-source-823ab006aaa504aaaa9be5e9b5c27cbdf3df28cc.zip
Initial commit of website code
Diffstat (limited to 'includes/rss.php')
-rw-r--r--includes/rss.php93
1 files changed, 93 insertions, 0 deletions
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 @@
+<?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");
+}
+
+?>