summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2009-09-17 23:18:03 +0100
committerNick White <git@njw.me.uk>2009-09-17 23:18:03 +0100
commit13e12813fd5d157081e1d87198f29c589e8a96fe (patch)
tree89442d332b025dfc4ea642355f9d423906c0c9c9
parent22c52b1b71cd4fbeb8bf51df1afe1c7cecaa3da4 (diff)
downloadnjw-website-source-13e12813fd5d157081e1d87198f29c589e8a96fe.tar.bz2
njw-website-source-13e12813fd5d157081e1d87198f29c589e8a96fe.zip
Switched to providing atom feeds
-rw-r--r--includes/atom.php101
-rw-r--r--includes/header.php3
2 files changed, 102 insertions, 2 deletions
diff --git a/includes/atom.php b/includes/atom.php
new file mode 100644
index 0000000..b9673f4
--- /dev/null
+++ b/includes/atom.php
@@ -0,0 +1,101 @@
+<?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/atom+xml");
+
+function extract_description($body)
+{
+ $body = explode("\n", $body);
+ $description = strip_tags($body[0]); /* use first line of body */
+ return $description;
+}
+
+function atom_header($metadatafile)
+{
+ print("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
+ print("<feed xmlns=\"http://www.w3.org/2005/Atom\">\n");
+
+ /* get variables to use for channel metadata */
+ include($_SERVER['DOCUMENT_ROOT'] . $metadatafile);
+
+ print("\t<id>" . "http://" . $_SERVER['HTTP_HOST'] . "/</id>\n");
+ print("\t<title>" . $title . "</title>\n");
+ print("\t<updated>" . date("c") . "</updated>\n"); /* check format is rfc3339 */
+ print("\t<author><name>" . $author . "</name></author>\n");
+ print("\t<link rel=\"self\" href=\"http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\" />\n");
+
+ if (isset($copyright) && !empty($copyright))
+ print("\t<rights>" . $copyright . "</rights>\n");
+ $description = extract_description($body);
+ if (!empty($description))
+ print("\t<description>" . $description . "</description>\n");
+}
+
+function create_entry($dir, $file)
+{
+ unset($title, $body, $summary, $author, $language, $category, $updated);
+ include($_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/" . $file);
+
+ print("\t<entry>\n");
+
+ print("\t\t<id>" . "http://" . $_SERVER['HTTP_HOST'] . "/" . $dir . "/" . $file . "</id>\n");
+ print("\t\t<title>" . $title . "</title>\n");
+ $updated = filemtime($dir . "/" . $file);
+ $updated = date("c", $updated);
+ print("\t\t<updated>" . $updated . "</updated>\n");
+
+ if (isset($author) && !empty($author))
+ print("\t\t<author><name>" . $author . "</name></author>\n");
+ print("\t\t<link rel=\"alternate\" href=\"" . "http://" . $_SERVER['HTTP_HOST'] . "/" . $dir . "/" . $file . "\" />\n");
+
+ $summary = extract_description($body);
+ if (!empty($summary))
+ print("\t\t<summary>" . $summary . "</summary>\n");
+
+ print("\t\t<content>" . strip_tags($body) . "</content>\n");
+
+ $category = ereg_replace("^text", "", $dir); /* dir after text */
+ if (!empty($category))
+ print("\t\t<category term=\"" . $category . "\" />\n");
+
+ print("\t</entry>\n");
+}
+
+function create_entries_from_dir($dir)
+{
+ if ($handle = opendir($dir)) {
+ while (false !== ($file = readdir($handle))) {
+ if (!is_dir($file)) {
+ if ($file[0] != "." && ereg(".php$", $file))
+ create_entry($dir, $file);
+ }
+ else {
+ if ($file[0] != ".")
+ create_entries_from_dir($dir . "/" . $file);
+ }
+ }
+ closedir($handle);
+ }
+}
+
+function atom_footer()
+{
+ print("</feed>\n");
+}
+
+?>
diff --git a/includes/header.php b/includes/header.php
index b9c59fc..ffddd5f 100644
--- a/includes/header.php
+++ b/includes/header.php
@@ -35,8 +35,7 @@ function xhtml_header($title)
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>' . $newtitle . '</title>
<link rel="stylesheet" type="text/css" href="/includes/default.css" />
- <link rel="alternate" type="application/rss+xml" href="/rss.php" title="RSS text excerpts" />
- <link rel="alternate" type="application/rss+xml" href="/rss-full.php" title="RSS complete text" />
+ <link rel="alternate" type="application/atom+xml" href="/atom.php" title="Full feed" />
<link rel="icon" href="/graphics/candles.ico" />
</head>