Moved sitemap file to /data/cache/sitemap.xml

Sitemap creation time now determined by filemtime instead of via config
This commit is contained in:
DrudexSoftware 2013-02-20 00:31:52 +01:00
parent 4b4d08c854
commit 4c170110e8

View file

@ -17,7 +17,7 @@ class XMLSitemap extends Extension {
{ {
global $config; global $config;
$this->sitemap_filepath = $_SERVER['DOCUMENT_ROOT']."/ext/sitemap/generated_sitemap.xml"; $this->sitemap_filepath = $_SERVER['DOCUMENT_ROOT']."/data/cache/sitemap.xml";
// determine if new sitemap needs to be generated // determine if new sitemap needs to be generated
if ($this->new_sitemap_needed()) if ($this->new_sitemap_needed())
{ {
@ -121,7 +121,7 @@ class XMLSitemap extends Extension {
// sets sitemap with entries in the queue // sets sitemap with entries in the queue
private function generate_display_sitemap() private function generate_display_sitemap()
{ {
global $page, $config; global $page;
$page->set_mode("data"); $page->set_mode("data");
$page->set_type("application/xml"); $page->set_type("application/xml");
@ -131,8 +131,7 @@ class XMLSitemap extends Extension {
$this->sitemap_queue $this->sitemap_queue
</urlset>"; </urlset>";
// sets // Generate new sitemap & display
$config->set_int("sitemap_lastgenerated", time());
file_put_contents($this->sitemap_filepath, $xml); file_put_contents($this->sitemap_filepath, $xml);
$page->set_data($xml); $page->set_data($xml);
} }
@ -140,13 +139,14 @@ class XMLSitemap extends Extension {
// returns true if a new sitemap is needed // returns true if a new sitemap is needed
private function new_sitemap_needed() private function new_sitemap_needed()
{ {
global $config;
$sitemap_generation_interval = 86400; // allow new site map every day $sitemap_generation_interval = 86400; // allow new site map every day
$last_generated_time = $config->get_int("sitemap_lastgenerated",0); $last_generated_time = filemtime($this->sitemap_filepath);
if (!file_exists($this->sitemap_filepath) || // if file doesn't exist, return true
($last_generated_time + $sitemap_generation_interval < time())) if ($last_generated_time == false) return true;
// if it's been a day since last sitemap creation, return true
if ($last_generated_time + $sitemap_generation_interval < time())
return true; return true;
else return false; else return false;
} }