[TikiWiki-commits] [Git][tikiwiki/tiki][28.x] [BP][ENH] improve sitemaps

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

Elifeleti Mukisa Dan pushed to branch 28.x at Tiki Wiki CMS Groupware / Tiki


Commits:
1d03f61e by Elifeleti Mukisa Dan at 2026-02-04T11:27:45+00:00
[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

- - - - -


1 changed file:

- tiki-sitemap.php


Changes:

=====================================
tiki-sitemap.php
=====================================
@@ -8,57 +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)
-    ) {
-        $smarty->assign(
-            'msg',
-            tra(
-                'The sitemap file is not available. Please check <a href="tiki-admin_sitemap.php" class="alert-link"> sitemap administration </a> to build it.'
-            )
-        );
-        header('HTTP/1.1 404 Not Found');
-        $smarty->display('error.tpl');
-        die();
-    }
-
-    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 (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);
-                }
+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/1d03f61e263c57bd45d09e364fb2dad2e1d99ba5

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/1d03f61e263c57bd45d09e364fb2dad2e1d99ba5
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.