diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/default.css | 70 | ||||
-rw-r--r-- | includes/footer.php | 39 | ||||
-rw-r--r-- | includes/header.php | 48 | ||||
-rw-r--r-- | includes/rss.php | 93 | ||||
-rw-r--r-- | includes/tarball.php | 41 |
5 files changed, 291 insertions, 0 deletions
diff --git a/includes/default.css b/includes/default.css new file mode 100644 index 0000000..a98ab34 --- /dev/null +++ b/includes/default.css @@ -0,0 +1,70 @@ +/* + * 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/>. + */ + +body +{ + font-family: sans-serif; + max-width: 75%; + margin: auto; +} + +h1 +{ + text-align: center; + font-size: 1.6em; +} + +h2 +{ + font-size: 1.2em; + font-weight: normal; + border-bottom: thin solid black; +} + +h3 +{ + font-size: 1.1em; + font-weight: normal; +} + +a { text-decoration: none; } + +a:hover { color: #5555dd; } + +p a:hover { text-decoration: underline; } + +div#footer +{ + border-top: thin solid black; + margin: 6ex auto 1ex; + font-size: xx-small; +} + +div#copyright +{ + border: thin solid #777; + background-color: #ddd; + color: black; + padding: 0.4ex 1em; + margin: auto 2%; +} + +div#copyright p +{ + margin-top: 0.2ex; + margin-bottom: 0.2ex; +} diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..056c6b1 --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,39 @@ +<?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/>. + */ + +$moddate = filemtime($_SERVER['DOCUMENT_ROOT'] . "/text/" . $_SERVER['PHP_SELF']); +$moddate = date("d/m/Y", $moddate); + +?> + +<div id="footer"> + + <div id="moddate"> + <p>Last updated: <?php print($moddate) ?></p> + </div> + + <div id="copyright"> + <p>The text on this website is licensed under the <a href="http://creativecommons.org/licenses/by-sa/3.0/" rel="license">Creative Commons Attribution-Share Alike 3.0 License</a>.</p> + <p>The code running this website is released under the <a href="http://www.fsf.org/licensing/licenses/agpl.html" rel="license">GNU Affero General Public License</a>. <a href="/download-source.php">Download the source code</a>.</p> + </div> + +</div> + +</body> + +</html> diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..b9c59fc --- /dev/null +++ b/includes/header.php @@ -0,0 +1,48 @@ +<?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("Vary: Accept"); +if (stristr($_SERVER["HTTP_ACCEPT"], "application/xhtml+xml")) + header("Content-Type: application/xhtml+xml; charset=utf-8"); +else + header("Content-Type: text/html; charset=utf-8"); + +function xhtml_header($title) +{ + $newtitle = str_replace("&", "&", stripslashes($title)); + + print(' +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <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="icon" href="/graphics/candles.ico" /> +</head> + +<body> + +<h1>' . $newtitle . '</h1>'); + +} +?> 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"); +} + +?> diff --git a/includes/tarball.php b/includes/tarball.php new file mode 100644 index 0000000..737aefa --- /dev/null +++ b/includes/tarball.php @@ -0,0 +1,41 @@ +<?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/>. + */ + +function return_tarball($name, $contents) +{ + require("Archive/Tar.php"); + + $mimetype = "application/x-tar"; + $extension = "tar.bz2"; + + $timestamp = strftime('%F'); + + /* Use output buffering (ob_start and ob_end_flush) to ensure that the + * tarball data sent to stdout doesn't interfere with the headers. */ + ob_start(); + header('Content-Type: ' . $mimetype); + header('Content-Disposition: attachment; filename="' . $name . '-' . $timestamp . '.' . $extension . '"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_end_flush(); + + $tarball = new Archive_Tar("php://stdout", "bz2"); + + $tarball->create($contents); +} |