summaryrefslogtreecommitdiff
path: root/includes/atom.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/atom.php')
-rw-r--r--includes/atom.php101
1 files changed, 101 insertions, 0 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");
+}
+
+?>