<?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($license_rdf) && !empty($license_rdf)) print("\t<link rel=\"license\" type=\"application/rdf+xml\" href=\"" . $license_rdf . "\" />\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, $full) { unset($title, $body, $summary, $author, $language, $category, $updated, $license_rdf); 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"); if (isset($license_rdf) && !empty($license_rdf)) print("\t\t<link rel=\"license\" type=\"application/rdf+xml\" href=\"" . $license_rdf . "\" />\n"); $summary = extract_description($body); if (!empty($summary)) print("\t\t<summary>" . $summary . "</summary>\n"); if ($full) print("\t\t<content type=\"xhtml\"><div xmlns=\"http://www.w3.org/1999/xhtml\">" . $body . "</div></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, $full=false) { if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (!is_dir($file)) { if ($file[0] != "." && ereg(".php$", $file)) create_entry($dir, $file, $full); } else { if ($file[0] != ".") create_entries_from_dir($dir . "/" . $file, $full); } } closedir($handle); } } function atom_footer() { print("</feed>\n"); } ?>