Commit 1c6fff91 authored by rjsmelo's avatar rjsmelo

[ENH] Move sitemap to storage/public, improve feedback to user, move all static values to constants

parent 04e45446
......@@ -25,6 +25,16 @@ class Generator
*/
const BASE_CLASS = '\\Tiki\\Sitemap\\AbstractType';
/**
* The base of the sitemap file name
*/
const BASE_FILE_NAME = 'sitemap';
/**
* The relative path where the sitemap will be stored
*/
const RELATIVE_PATH = 'storage/public/';
protected $basePath;
public function __construct($basePath = null)
......@@ -53,8 +63,8 @@ class Generator
$perms->setGroups(['Anonymous']); // ensure that permissions are processed as Anonymous
$sitemap = new Sitemap($baseUrl);
$sitemap->setPath($this->basePath . 'temp/public/');
$sitemap->setFilename('sitemap');
$sitemap->setPath($this->basePath . self::RELATIVE_PATH);
$sitemap->setFilename(self::BASE_FILE_NAME);
// Add the website root
$sitemap->addItem('/', '1.0', 'daily', date('Y-m-d'));
......@@ -63,7 +73,7 @@ class Generator
$directoryFiles = new \GlobIterator(__DIR__ . '/Type/*.php');
/** @var \SplFileInfo $file */
foreach ($directoryFiles as $file) {
if ($file->getFilename() === 'index.php'){
if ($file->getFilename() === 'index.php') {
continue; // file to prevent directory browsing
}
......@@ -83,8 +93,25 @@ class Generator
}
}
$sitemap->createSitemapIndex($baseUrl . '/public/', date('Y-m-d'));
$sitemap->createSitemapIndex($baseUrl . self::RELATIVE_PATH, date('Y-m-d'));
$perms->setGroups($oldGroups); // restore the group configuration for permissions
}
/**
* Return the path to the sitemap
*
* @param bool $relative if it should return only the relative path (default true)
* @return string
*/
public function getSitemapPath($relative = true)
{
$path = self::RELATIVE_PATH . self::BASE_FILE_NAME . '-index.xml';
if (! $relative) {
$path = $this->basePath . $path;
}
return $path;
}
}
\ No newline at end of file
......@@ -4,16 +4,24 @@
{button href="tiki-admin_sitemap.php?rebuild=1" _icon_name="sitemap" class="btn btn-default" _text="{tr}Rebuild sitemap{/tr}"}
<br />
<h2>{tr}Submit the Sitemap{/tr}</h2>
<br/><h2>{tr}Submit the Sitemap{/tr}</h2>
{remarksbox type="info" title="{tr}Submit the Sitemap{/tr}" close="n"}
{if $sitemapAvailable}
<div class="alert alert-info">
{tr}You can submit the sitemap for processing in all major search engines using the following URL:{/tr}
<br><br>
<a href="{$url}" target="_blank">{$xml}</a>
</div>
<br>
<br>
<a href="{$url}" target="_blank">{$url}</a>
{else}
<div class="alert alert-info">
{tr}The URL that you will need to use for submitting the sitemap will be available after you rebuild the sitemap.{/tr}
</div>
{/if}
{/remarksbox}
{remarksbox type="info" title="{tr}Automate Sitemap generation{/tr}" close="n"}
<p>
{tr}You can automate the sitemap generation by using the scheduler functionality:
<a href="https://doc.tiki.org/Scheduler">https://doc.tiki.org/Scheduler</a>
{/tr}
</p>
<p>
{tr}Or you can use directly the command line:{/tr} <code>php console.php sitemap:generate {$base_host}</code>
</p>
{/remarksbox}
......@@ -12,21 +12,18 @@ global $base_host, $prefs, $tikipath;
$access->check_permission('tiki_p_admin');
$access->check_feature('sitemap_enable');
$sitemap = new Tiki\Sitemap\Generator();
if (isset($_REQUEST['rebuild'])) {
$sitemap = new Tiki\Sitemap\Generator();
$sitemap->generate($base_host);
Feedback::success(tr('New sitemap created!'), 'session');
$access->redirect('tiki-admin_sitemap.php');
}
$xml = $base_host . '/temp/public/sitemap.xml';
$url = 'temp/public/sitemap.xml';
$smarty->assign('title', tr('Sitemap'));
$smarty->assign('xml', $xml);
$smarty->assign('url', $url);
$smarty->assign('sitemapAvailable', file_exists($tikipath . 'temp/public/sitemap.xml'));
$smarty->assign('url', $base_host . '/' . $sitemap->getSitemapPath());
$smarty->assign('sitemapAvailable', file_exists($sitemap->getSitemapPath(false)));
$smarty->assign('mid', 'tiki-admin_sitemap.tpl');
$smarty->display('tiki.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