diff --git a/src/.htaccess b/src/.htaccess index 51cb326..470f73e 100644 --- a/src/.htaccess +++ b/src/.htaccess @@ -8,7 +8,4 @@ RewriteRule ^Themes/[^/]+/Assets/.+$ - [L] # Allow access to the robots.txt file RewriteRule ^robots\.txt$ - [L] -# Allow access to the sitemap.xml file -RewriteRule ^sitemap\.xml$ - [L] - RewriteRule ^(.+)$ index.php [L,QSA] diff --git a/src/Plugins/Sitemap/SitemapPlugin.php b/src/Plugins/Sitemap/SitemapPlugin.php new file mode 100644 index 0000000..028c351 --- /dev/null +++ b/src/Plugins/Sitemap/SitemapPlugin.php @@ -0,0 +1,54 @@ +formatOutput = true; + + $root = $doc->createElement('urlset'); + $root->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'); + $doc->appendChild($root); + + $urls = array(); + foreach ($pages as $key => $value) { + $urls[$key]['url'] = $value['functionalPagePath']; + $urls[$key]['lastchange'] = date('Y-m-d', filemtime($value['fullPagePath'])); + } + + foreach ($urls as $url) { + $element = $doc->createElement('url'); + + $loc = $doc->createElement('loc', $protocol . '://' . AntTools::repairURL($baseURL . $url['url'])); + $element->appendChild($loc); + + $lastmod = $doc->createElement('lastmod', $url['lastchange']); + $element->appendChild($lastmod); + + $root->appendChild($element); + } + + header('Content-Type: application/xml'); + echo $doc->saveXML(); + exit; + } else { + die("AntCMS is unable to generate a sitemap without having the DOM extension loadded in PHP."); + } + } + public function getName() + { + return 'Sitemap'; + } +} diff --git a/src/index.php b/src/index.php index 13536e0..a4ae094 100644 --- a/src/index.php +++ b/src/index.php @@ -54,6 +54,11 @@ if ($segments[0] === 'themes' && $segments[2] === 'assets') { exit; } +if($segments[0] == 'sitemap.xml'){ + $segments[0] = 'plugin'; + $segments[1] = 'sitemap'; +} + if ($segments[0] === 'plugin') { $pluginName = $segments[1]; $pluginLoader = new AntPluginLoader();