Commit f8a435b2 authored by rjsmelo's avatar rjsmelo

[ENH] Enable tiki to serve the sitemap from the root folder

parent fd3c0903
......@@ -67,7 +67,9 @@ class Generator
$perms->setGroups(['Anonymous']); // ensure that permissions are processed as Anonymous
$user = null;
$sitemap = new Sitemap(rtrim($baseUrl, '/'));
$baseUrl = rtrim($baseUrl, '/');
$sitemap = new Sitemap($baseUrl);
$sitemap->setPath($this->basePath . self::RELATIVE_PATH);
$sitemap->setFilename(self::BASE_FILE_NAME);
......@@ -118,4 +120,14 @@ class Generator
return $path;
}
/**
* Return the sitemap file name
*
* @return string
*/
public function getSitemapFilename()
{
return self::BASE_FILE_NAME . '-index.xml';
}
}
......@@ -22,7 +22,7 @@ if (isset($_REQUEST['rebuild'])) {
}
$smarty->assign('title', tr('Sitemap'));
$smarty->assign('url', $base_url . $sitemap->getSitemapPath());
$smarty->assign('url', $base_url . 'tiki-sitemap.php?file=' . $sitemap->getSitemapFilename());
$smarty->assign('sitemapAvailable', file_exists($sitemap->getSitemapPath(false)));
$smarty->assign('mid', 'tiki-admin_sitemap.tpl');
$smarty->display('tiki.tpl');
<?php
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
use Tiki\Sitemap\Generator;
require_once 'tiki-setup.php';
if ($prefs['sitemap_enable'] == 'y') {
$siteMapFile = ! empty($_REQUEST['file']) ? (string)$_REQUEST['file'] : Generator::BASE_FILE_NAME . '-index.xml';
$path = Generator::RELATIVE_PATH;
// filter valid file names
if (! preg_match('/^' . Generator::BASE_FILE_NAME . '(?:|-index?|-[0-9]+).xml$/', $siteMapFile, $matches)
|| ! file_exists($path . $siteMapFile)) {
die(tra('Sitemap file not available'));
}
if ($siteMapFile === Generator::BASE_FILE_NAME . '-index.xml') {
$xml = new DOMDocument('1.0', 'UTF-8');
$xml->load($path . $siteMapFile);
$root = $xml->documentElement;
$siteMap = $root->getElementsByTagName('sitemap');
foreach ($siteMap as $item) {
$loc = $item->getElementsByTagName('loc');
if (strpos($loc->item(0)->nodeValue, $path) !== false) {
$loc->item(0)->nodeValue = str_replace($path, 'tiki-sitemap.php?file=', $loc->item(0)->nodeValue);
}
}
echo $xml->saveXML();
} else {
$file = file_get_contents($path . $_REQUEST['file']);
echo $file;
}
} else {
$smarty->assign(
'msg',
tra(
'Required features: sitemap_enable. If you do not have permission to activate these features, ask the site administrator.'
)
);
$smarty->display('error.tpl');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment