From 13e12813fd5d157081e1d87198f29c589e8a96fe Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 17 Sep 2009 23:18:03 +0100 Subject: Switched to providing atom feeds --- includes/atom.php | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ includes/header.php | 3 +- 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 includes/atom.php 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 @@ +. + */ + +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("\n"); + print("\n"); + + /* get variables to use for channel metadata */ + include($_SERVER['DOCUMENT_ROOT'] . $metadatafile); + + print("\t" . "http://" . $_SERVER['HTTP_HOST'] . "/\n"); + print("\t" . $title . "\n"); + print("\t" . date("c") . "\n"); /* check format is rfc3339 */ + print("\t" . $author . "\n"); + print("\t\n"); + + if (isset($copyright) && !empty($copyright)) + print("\t" . $copyright . "\n"); + $description = extract_description($body); + if (!empty($description)) + print("\t" . $description . "\n"); +} + +function create_entry($dir, $file) +{ + unset($title, $body, $summary, $author, $language, $category, $updated); + include($_SERVER['DOCUMENT_ROOT'] . "/" . $dir . "/" . $file); + + print("\t\n"); + + print("\t\t" . "http://" . $_SERVER['HTTP_HOST'] . "/" . $dir . "/" . $file . "\n"); + print("\t\t" . $title . "\n"); + $updated = filemtime($dir . "/" . $file); + $updated = date("c", $updated); + print("\t\t" . $updated . "\n"); + + if (isset($author) && !empty($author)) + print("\t\t" . $author . "\n"); + print("\t\t\n"); + + $summary = extract_description($body); + if (!empty($summary)) + print("\t\t" . $summary . "\n"); + + print("\t\t" . strip_tags($body) . "\n"); + + $category = ereg_replace("^text", "", $dir); /* dir after text */ + if (!empty($category)) + print("\t\t\n"); + + print("\t\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("\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) ' . $newtitle . ' - - + -- cgit v1.2.3