2016-01-08 00:43:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class pluginSitemap extends Plugin {
|
|
|
|
|
|
|
|
private function createXML()
|
|
|
|
{
|
|
|
|
global $Site;
|
|
|
|
global $dbPages;
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
|
|
|
|
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
|
|
|
|
|
|
|
|
$xml .= '<url>';
|
|
|
|
$xml .= '<loc>'.$Site->url().'</loc>';
|
|
|
|
$xml .= '</url>';
|
|
|
|
|
|
|
|
// Get keys of pages
|
2017-06-04 22:08:20 +02:00
|
|
|
$keys = $dbPages->db;
|
|
|
|
unset($keys['error']);
|
|
|
|
$keys = array_keys($keys);
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
foreach($keys as $pageKey) {
|
|
|
|
// Create the page object from the page key
|
|
|
|
$page = buildPage($pageKey);
|
2017-06-04 22:08:20 +02:00
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
$xml .= '<url>';
|
|
|
|
$xml .= '<loc>'.$page->permalink().'</loc>';
|
|
|
|
$xml .= '<lastmod>'.$page->dateRaw(SITEMAP_DATE_FORMAT).'</lastmod>';
|
|
|
|
$xml .= '<changefreq>daily</changefreq>';
|
|
|
|
$xml .= '</url>';
|
2016-01-08 00:43:09 +01:00
|
|
|
}
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
$xml .= '</urlset>';
|
2016-01-08 00:43:09 +01:00
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// New DOM document
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
$doc->formatOutput = true;
|
|
|
|
$doc->loadXML($xml);
|
|
|
|
$doc->save($this->workspace().'sitemap.xml');
|
2016-01-08 00:43:09 +01:00
|
|
|
}
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
public function install($position=0)
|
2016-01-08 00:43:09 +01:00
|
|
|
{
|
|
|
|
parent::install($position);
|
|
|
|
$this->createXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function afterPageCreate()
|
|
|
|
{
|
|
|
|
$this->createXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function afterPageModify()
|
|
|
|
{
|
|
|
|
$this->createXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function afterPageDelete()
|
|
|
|
{
|
|
|
|
$this->createXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function beforeRulesLoad()
|
|
|
|
{
|
|
|
|
global $Url;
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
if($Url->uri()===HTML_PATH_ROOT.'sitemap.xml') {
|
2016-01-08 00:43:09 +01:00
|
|
|
// Send XML header
|
|
|
|
header('Content-type: text/xml');
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Workaround for a bug https://bugs.php.net/bug.php?id=62577
|
2016-10-01 21:12:40 +02:00
|
|
|
libxml_disable_entity_loader(false);
|
2017-06-04 21:08:31 +02:00
|
|
|
|
|
|
|
// Load XML
|
|
|
|
$doc->load($this->workspace().'sitemap.xml');
|
|
|
|
|
2016-10-01 21:12:40 +02:00
|
|
|
libxml_disable_entity_loader(true);
|
2016-01-08 00:43:09 +01:00
|
|
|
|
|
|
|
// Print the XML
|
|
|
|
echo $doc->saveXML();
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
// Terminate the run successfully
|
|
|
|
exit(0);
|
2016-01-08 00:43:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-04 21:08:31 +02:00
|
|
|
}
|