Convert Spaces -> Tabs
This commit is contained in:
parent
e37c5cb9d0
commit
3cd8c33ed1
1 changed files with 155 additions and 136 deletions
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Name: XML Sitemap
|
* Name: XML Sitemap
|
||||||
* Author: Sein Kraft <mail@seinkraft.info>
|
* Author: Sein Kraft <mail@seinkraft.info>
|
||||||
|
@ -9,30 +10,31 @@
|
||||||
* Documentation:
|
* Documentation:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class XMLSitemap extends Extension {
|
class XMLSitemap extends Extension
|
||||||
|
{
|
||||||
private $sitemap_queue = "";
|
private $sitemap_queue = "";
|
||||||
private $sitemap_filepath = ""; // set onPageRequest
|
private $sitemap_filepath = ""; // set onPageRequest
|
||||||
|
|
||||||
public function onPageRequest(PageRequestEvent $event) {
|
public function onPageRequest(PageRequestEvent $event)
|
||||||
if($event->page_matches("sitemap.xml"))
|
|
||||||
{
|
{
|
||||||
|
if ($event->page_matches("sitemap.xml")) {
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
$this->sitemap_filepath = $_SERVER['DOCUMENT_ROOT']."/data/cache/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()) {
|
||||||
{
|
|
||||||
// determine which type of sitemap to generate
|
// determine which type of sitemap to generate
|
||||||
if ($config->get_bool("sitemap_generatefull",false))
|
if ($config->get_bool("sitemap_generatefull", false)) {
|
||||||
$this->handle_full_sitemap(); // default false until cache fixed
|
$this->handle_full_sitemap(); // default false until cache fixed
|
||||||
else
|
} else {
|
||||||
$this->handle_smaller_sitemap();
|
$this->handle_smaller_sitemap();
|
||||||
}
|
}
|
||||||
else $this->display_existing_sitemap();
|
} else $this->display_existing_sitemap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSetupBuilding(SetupBuildingEvent $event) {
|
public function onSetupBuilding(SetupBuildingEvent $event)
|
||||||
|
{
|
||||||
$sb = new SetupBlock("Sitemap");
|
$sb = new SetupBlock("Sitemap");
|
||||||
|
|
||||||
$sb->add_bool_option("sitemap_generatefull", "Generate full sitemap");
|
$sb->add_bool_option("sitemap_generatefull", "Generate full sitemap");
|
||||||
|
@ -48,9 +50,11 @@ class XMLSitemap extends Extension {
|
||||||
/* --- Add latest images to sitemap with higher priority --- */
|
/* --- Add latest images to sitemap with higher priority --- */
|
||||||
$latestimages = Image::find_images(0, 50, array());
|
$latestimages = Image::find_images(0, 50, array());
|
||||||
$latestimages_urllist = array();
|
$latestimages_urllist = array();
|
||||||
foreach($latestimages as $arrayid => $image)
|
foreach ($latestimages as $arrayid => $image) {
|
||||||
// create url from image id's
|
// create url from image id's
|
||||||
$latestimages_urllist[$arrayid] = "post/view/$image->id";
|
$latestimages_urllist[$arrayid] = "post/view/$image->id";
|
||||||
|
}
|
||||||
|
|
||||||
$this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp));
|
$this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp));
|
||||||
|
|
||||||
/* --- Display page --- */
|
/* --- Display page --- */
|
||||||
|
@ -70,7 +74,7 @@ class XMLSitemap extends Extension {
|
||||||
|
|
||||||
/* --- 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'];
|
||||||
$popular_tags[$arrayid] = "post/list/$tag/";
|
$popular_tags[$arrayid] = "post/list/$tag/";
|
||||||
}
|
}
|
||||||
|
@ -79,14 +83,15 @@ class XMLSitemap extends Extension {
|
||||||
/* --- Add latest images to sitemap with higher priority --- */
|
/* --- Add latest images to sitemap with higher priority --- */
|
||||||
$latestimages = Image::find_images(0, 50, array());
|
$latestimages = Image::find_images(0, 50, array());
|
||||||
$latestimages_urllist = array();
|
$latestimages_urllist = array();
|
||||||
foreach($latestimages as $arrayid => $image)
|
foreach ($latestimages as $arrayid => $image) {
|
||||||
// create url from image id's
|
// create url from image id's
|
||||||
$latestimages_urllist[$arrayid] = "post/view/$image->id";
|
$latestimages_urllist[$arrayid] = "post/view/$image->id";
|
||||||
|
}
|
||||||
$this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp));
|
$this->add_sitemap_queue($latestimages_urllist, "monthly", "0.8", date("Y-m-d", $image->posted_timestamp));
|
||||||
|
|
||||||
/* --- Add other tags --- */
|
/* --- Add other tags --- */
|
||||||
$other_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 21,10000000");
|
$other_tags = $database->get_all("SELECT tag, count FROM tags ORDER BY `count` DESC LIMIT 21,10000000");
|
||||||
foreach($other_tags as $arrayid => $tag) {
|
foreach ($other_tags as $arrayid => $tag) {
|
||||||
$tag = $tag['tag'];
|
$tag = $tag['tag'];
|
||||||
// create url from tags (tagme ignored)
|
// create url from tags (tagme ignored)
|
||||||
if ($tag != "tagme")
|
if ($tag != "tagme")
|
||||||
|
@ -96,9 +101,10 @@ class XMLSitemap extends Extension {
|
||||||
|
|
||||||
/* --- Add all other images to sitemap with lower priority --- */
|
/* --- Add all other images to sitemap with lower priority --- */
|
||||||
$otherimages = Image::find_images(51, 10000000, array());
|
$otherimages = Image::find_images(51, 10000000, array());
|
||||||
foreach($otherimages as $arrayid => $image)
|
foreach ($otherimages as $arrayid => $image) {
|
||||||
// create url from image id's
|
// create url from image id's
|
||||||
$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));
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,9 +113,18 @@ class XMLSitemap extends Extension {
|
||||||
$this->generate_display_sitemap();
|
$this->generate_display_sitemap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds an array of urls to the sitemap with the given information
|
/**
|
||||||
private function add_sitemap_queue(/*array(urls)*/ $urls, $changefreq="monthly", $priority="0.5", $date="2013-02-01") {
|
* Adds an array of urls to the sitemap with the given information.
|
||||||
foreach($urls as $url) {
|
*
|
||||||
|
* @param array $urls
|
||||||
|
* @param string $changefreq
|
||||||
|
* @param string $priority
|
||||||
|
* @param string $date
|
||||||
|
*/
|
||||||
|
private function add_sitemap_queue( /*array(urls)*/ $urls, $changefreq = "monthly",
|
||||||
|
$priority = "0.5", $date = "2013-02-01")
|
||||||
|
{
|
||||||
|
foreach ($urls as $url) {
|
||||||
$link = make_http(make_link("$url"));
|
$link = make_http(make_link("$url"));
|
||||||
$this->sitemap_queue .= "
|
$this->sitemap_queue .= "
|
||||||
<url>
|
<url>
|
||||||
|
@ -126,7 +141,7 @@ class XMLSitemap extends Extension {
|
||||||
{
|
{
|
||||||
global $page;
|
global $page;
|
||||||
|
|
||||||
$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>";
|
||||||
|
@ -145,12 +160,16 @@ class XMLSitemap extends Extension {
|
||||||
$last_generated_time = filemtime($this->sitemap_filepath);
|
$last_generated_time = filemtime($this->sitemap_filepath);
|
||||||
|
|
||||||
// if file doesn't exist, return true
|
// if file doesn't exist, return true
|
||||||
if ($last_generated_time == false) return true;
|
if ($last_generated_time == false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// if it's been a day since last sitemap creation, return true
|
// if it's been a day since last sitemap creation, return true
|
||||||
if ($last_generated_time + $sitemap_generation_interval < time())
|
if ($last_generated_time + $sitemap_generation_interval < time()) {
|
||||||
return true;
|
return true;
|
||||||
else return false;
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function display_existing_sitemap()
|
private function display_existing_sitemap()
|
||||||
|
|
Reference in a new issue