From e87734ce728b9f821dc919ef088861aaac540668 Mon Sep 17 00:00:00 2001 From: Shish Date: Mon, 3 Aug 2009 18:25:51 +0100 Subject: [PATCH] sitemap extension from Sein Kraft --- contrib/sitemap/main.php | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 contrib/sitemap/main.php diff --git a/contrib/sitemap/main.php b/contrib/sitemap/main.php new file mode 100644 index 00000000..bdd350ab --- /dev/null +++ b/contrib/sitemap/main.php @@ -0,0 +1,54 @@ + + * License: GPLv2 + * Description: Adds sitemap.xml on request. + * Documentation: + */ + +class XMLSitemap extends SimpleExtension { + public function onPageRequest($event) { + if($event->page_matches("sitemap.xml")) { + $images = Image::find_images(0, 50, array()); + $this->do_xml($images); + } + } + + private function do_xml($images) { + global $page; + $page->set_mode("data"); + $page->set_type("application/xml"); + + $data = ""; + foreach($images as $image) { + $link = make_http(make_link("post/view/{$image->id}")); + $posted = date("Y-m-d", $image->posted_timestamp); + + $data .= " + + $link + $posted + monthly + 0.8 + + "; + } + + $base_href = make_http(make_link("post/list")); + + $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> + + + $base_href + 2009-01-01 + monthly + 1 + + $data + + "; + $page->set_data($xml); + } +} +?>