[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [BP][ENH] improve sitemaps
"Elifeleti Mukisa Dan \(@Danelif\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <69837b959ec67_3b1844bc911b8@gitlab-sidekiq-low-urgency-cpu-bound-v2-55cfcc57bd-l8pc5.mail> |
Elifeleti Mukisa Dan pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki Commits: da7a03a3 by Elifeleti Mukisa Dan at 2026-02-04T16:55:11+00:00 [BP][ENH] improve sitemaps --- * [BP][ENH] improve sitemaps --- * [ENH] improve sitemaps --- * [ENH] improve sitemaps --- * [ENH] improve sitemaps (cherry picked from commit 208a827bb873c9efbf44d0253083ed1f44e1b067) 107df6bf ENH: improve sitemaps 0489d67d FIX: coding standards for sitemap file. Co-authored-by: Mohamed Elbahja <728613-melbahja-KJX8L1YACloTKYOLMXNBR4JObQgbnkHQ@public.gmane.org> See merge request tikiwiki/tiki!9487 (cherry picked from commit 70620c9b85533448a15e0293c9394af0b443cdf8) 7f1f421b [ENH] improve sitemaps Co-authored-by: Elifeleti Mukisa Dan <[email protected]> See merge request tikiwiki/tiki!9490 See merge request tikiwiki/tiki!9493 See merge request tikiwiki/tiki!9501 - - - - - 1 changed file: - tiki-sitemap.php Changes: ===================================== tiki-sitemap.php ===================================== @@ -8,46 +8,42 @@ 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::getRelativePath(); - // filter valid file names - if ( - ! preg_match('/^.*\.(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) { - if ($prefs['feature_sefurl'] === 'y') { - $loc->item(0)->nodeValue = str_replace($path, '', $loc->item(0)->nodeValue); - } else { - $loc->item(0)->nodeValue = str_replace($path, 'tiki-sitemap.php?file=', $loc->item(0)->nodeValue); - } +if ($prefs['sitemap_enable'] !== 'y') { + Feedback::errorAndDie(tra('Required features: sitemap_enable. If you do not have permission to activate these features, ask the site administrator.'), \Laminas\Http\Response::STATUS_CODE_401); +} + +$siteMapFile = ! empty($_REQUEST['file']) ? (string)$_REQUEST['file'] : Generator::BASE_FILE_NAME . '-index.xml'; +$siteMapPath = realpath(Generator::getRelativePath() . $siteMapFile); + +// filter valid file names +if ( + ! preg_match('/^.*\.(xml)$/', $siteMapFile, $matches) + || dirname($siteMapPath) !== realpath(Generator::getRelativePath()) + || ! file_exists($siteMapPath) +) { + Feedback::errorAndDie(tra('The sitemap file is not available. Please check <a href="tiki-admin_sitemap.php" class="alert-link"> sitemap administration </a> to build it.'), \Laminas\Http\Response::STATUS_CODE_404); +} + +header('Content-Type: application/xml; charset=utf-8'); + +if ($siteMapFile === Generator::BASE_FILE_NAME . '-index.xml') { + $xml = new DOMDocument('1.0', 'UTF-8'); + $xml->load($siteMapPath); + $root = $xml->documentElement; + $siteMap = $root->getElementsByTagName('sitemap'); + + foreach ($siteMap as $item) { + $loc = $item->getElementsByTagName('loc'); + if (str_contains($loc->item(0)->nodeValue, $path)) { + if ($prefs['feature_sefurl'] === 'y') { + $loc->item(0)->nodeValue = str_replace($path, '', $loc->item(0)->nodeValue); + } else { + $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; } + echo $xml->saveXML(); } 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'); + echo file_get_contents($siteMapPath); } View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/da7a03a38636875241899230426b390845d11d73 -- View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/da7a03a38636875241899230426b390845d11d73 You're receiving this email because of your account on gitlab.com. _______________________________________________ TikiWiki-cvs mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs