[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] improve sitemaps

"Elifeleti Mukisa Dan \(@Danelif\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6983193147120_3b25458888377d@gitlab-sidekiq-low-urgency-cpu-bound-v2-65d8676567-k5jt5.mail>

Elifeleti Mukisa Dan pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
70620c9b by Elifeleti Mukisa Dan at 2026-02-04T09:52:55+00:00
[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

- - - - -


1 changed file:

- tiki-sitemap.php


Changes:

=====================================
tiki-sitemap.php
=====================================
@@ -8,43 +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)
-    ) {
-        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 ($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);
+}
 
-    if ($siteMapFile === Generator::BASE_FILE_NAME . '-index.xml') {
-        $xml = new DOMDocument('1.0', 'UTF-8');
+$siteMapFile = ! empty($_REQUEST['file']) ? (string)$_REQUEST['file'] : Generator::BASE_FILE_NAME . '-index.xml';
+$siteMapPath = realpath(Generator::getRelativePath() . $siteMapFile);
 
-        $xml->load($path . $siteMapFile);
-        $root = $xml->documentElement;
-        $siteMap = $root->getElementsByTagName('sitemap');
+// 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);
+}
 
-        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);
-                }
+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 {
-    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);
+    echo file_get_contents($siteMapPath);
 }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/70620c9b85533448a15e0293c9394af0b443cdf8

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/70620c9b85533448a15e0293c9394af0b443cdf8
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.