Caching not working properly for various reasons, removed for now

This commit is contained in:
DrudexSoftware 2013-02-11 08:43:06 +01:00
parent b7b8786f18
commit 59ec209c4a

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Name: XML Sitemap * Name: XML Sitemap
* Author: Sein Kraft <mail@seinkraft.info>, Drudex Software <support@drudexsoftware.com * Author: Sein Kraft <mail@seinkraft.info>
* License: GPLv2 * License: GPLv2
* Description: Adds sitemap.xml on request. * Description: Adds sitemap.xml on request.
* Documentation: * Documentation:
@ -9,41 +9,19 @@
class XMLSitemap extends Extension { class XMLSitemap extends Extension {
private $sitemap_queue = ""; private $sitemap_queue = "";
private $time_structure = "YmdHis";
private $sitemap_creation_interval = 6; // number of hours between sitemap regeneration
public function onInitExt(InitExtEvent $event) {
global $config;
// adds last_sitemap to config
$config->set_default_string("last_sitemap", // set initial date to a year ago
date($this->time_structure, strtotime('-1 year',time())));
}
public function onPageRequest(PageRequestEvent $event) { public function onPageRequest(PageRequestEvent $event) {
global $database, $config; global $database, $config;
if($event->page_matches("sitemap.xml")) if($event->page_matches("sitemap.xml"))
{
// creates default value
$config->set_default_string("last_sitemap", // set initial date to a year ago
date($this->time_structure, strtotime('-1 year',time())));
// remakes sitemap if needed
$lastsitemaptime = date($this->time_structure, $config->get_string("last_sitemap"));
$sitemap_creation_allowed_time = date($this->time_structure, strtotime("+$this->sitemap_creation_interval hours", $lastsitemaptime));
if ($sitemap_creation_allowed_time < time() || // sitemap is allowed to reset
!file_exists($_SERVER["DOCUMENT_ROOT"]."/sitemap.xml")) // or sitemap can be remade
{ {
// add index // add index
$index[0] = $base_href = make_http(make_link("post/list")); $index[0] = $base_href = $config->get_string("front_page");
$this->add_sitemap_queue($index, "weekly", "1"); $this->add_sitemap_queue($index, "weekly", "1");
/* --- Add 20 most used tags --- */ /* --- Add 20 most used tags --- */
$popular_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 0,20"); $popular_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 0,20");
foreach($popular_tags as $arrayid => $tag) { foreach($popular_tags as $arrayid => $tag) {
$tag = $tag['tag']; $tag = $tag['tag'];
// create url from tags (tagme ignored)
if ($tag != "tagme")
$popular_tags[$arrayid] = "post/list/$tag/"; $popular_tags[$arrayid] = "post/list/$tag/";
} }
$this->add_sitemap_queue($popular_tags, "monthly", "0.9" /* not sure how to deal with date here */); $this->add_sitemap_queue($popular_tags, "monthly", "0.9" /* not sure how to deal with date here */);
@ -73,9 +51,6 @@ class XMLSitemap extends Extension {
$otherimages[$arrayid] = "post/view/$image->id"; $otherimages[$arrayid] = "post/view/$image->id";
$this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", $image->posted_timestamp)); $this->add_sitemap_queue($otherimages, "monthly", "0.6", date("Y-m-d", $image->posted_timestamp));
// Creates the sitemap file
$this->create_sitemap();
}
/* --- Display page --- */ /* --- Display page --- */
// when sitemap is ok, display it from the file // when sitemap is ok, display it from the file
@ -104,32 +79,13 @@ class XMLSitemap extends Extension {
$page->set_mode("data"); $page->set_mode("data");
$page->set_type("application/xml"); $page->set_type("application/xml");
// read file
$filename = $_SERVER['DOCUMENT_ROOT']."/sitemap.xml";
$xmlreader = fopen($filename, 'r') or die("can't open file");
$xml = fread($xmlreader, filesize($filename));
fclose($xmlreader);
// sets
$page->set_data($xml);
}
// creates the xml sitemap file from the queue
private function create_sitemap()
{
global $config;
$xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?"."> $xml = "<"."?xml version=\"1.0\" encoding=\"utf-8\"?".">
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"> <urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">
$this->sitemap_queue $this->sitemap_queue
</urlset>"; </urlset>";
$fh = fopen($_SERVER["DOCUMENT_ROOT"]."/sitemap.xml", 'w') or die("can't open file"); // sets
fwrite($fh, $this->sitemap_queue); $page->set_data($xml);
fclose($fh);
file_put_contents($_SERVER['DOCUMENT_ROOT']."/sitemap.xml", $xml);
$config->set_string("last_sitemap", date($this->time_structure, time()));
} }
} }
?> ?>