1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-12-22 13:45:02 +00:00
Pepperminty-Wiki/modules/page-sitemap.php

69 lines
2.6 KiB
PHP
Raw Normal View History

2020-10-26 18:26:59 +00:00
<?php
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
register_module([
"name" => "Sitemap",
2024-09-06 01:35:46 +00:00
"version" => "0.1.2",
2020-10-26 18:26:59 +00:00
"author" => "Starbeamrainbowlabs",
2021-09-03 01:04:41 +00:00
"description" => "Adds XML sitemap generation. Additional manual setup is required to notify search engines about the sitemap. See the Features FAQ in the documentation (or your wiki's credits page) for more information.",
2020-10-26 18:26:59 +00:00
"id" => "page-sitemap",
"code" => function() {
2024-09-06 01:35:46 +00:00
global $settings, $env;
2020-10-26 18:26:59 +00:00
/**
* @api {get} ?action=sitemap Get an XML sitemap
* @apiName Sitemap
* @apiGroup Page
* @apiPermission Anonymous
*/
/*
* ██████ █████ ██ ██
* ██ ██ ██ ██ ██ ██
* ██████ ███████ ██ ██
* ██ ██ ██ ██ ██ ███ ██
* ██ ██ ██ ██ ███ ███
*/
add_action("sitemap", function() {
global $pageindex, $env;
$full_url_stem = full_url();
// Reference: https://www.sitemaps.org/protocol.html
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument("1.0", "utf-8");
$xml->startElement("urlset");
$xml->writeAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
foreach($pageindex as $pagename => $pagedata) {
$xml->startElement("url");
$xml->writeElement("loc", "$full_url_stem?page=".rawurlencode($pagename));
if(isset($pagedata->lastmodified))
$xml->writeElement("lastmod", date("Y-m-d", $pagedata->lastmodified));
$xml->endElement();
}
$xml->endElement();
$sitemap = $xml->flush();
header("content-type: application/xml");
header("content-disposition: inline");
header("content-length: " . strlen($sitemap));
exit($sitemap);
});
2024-09-06 01:35:46 +00:00
if($env->is_admin) {
add_help_section("947-sitemap", "Sitemap", "<p>$settings->sitename has a sitemap. You can find it here: <a href='?action=sitemap'>sitemap</a>.</p>
<p>In order for crawlers to discover this sitemap however, you must update your <code>robots.txt</code> file for the domain $settings->sitename is hosted on to add a line like so:</p>
<pre><code>Sitemap: http://example.com/path/to/index.php?action=sitemap</code></pre>
<p>....replacing the relevant parts of the URL as appropriate. Note that more than one <code>Sitemap:</code> directive is allowed in a single <code>robots.txt</code> file.</p>");
}
2020-10-26 18:26:59 +00:00
}
]);
?>