* License: GPLv2
* Description: Adds sitemap.xml on request.
* Documentation:
*/
class XMLSitemap extends Extension {
public function onPageRequest(PageRequestEvent $event) {
if($event->page_matches("sitemap.xml")) {
$images = Image::find_images(0, 50, array());
$this->do_xml($images);
}
}
private function do_xml(/*array(Image)*/ $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);
}
}
?>