Commit 647a99fd authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Serve sitemaps from download.php and use download url in the index



Adds a 'type' parameter to download.php, which, if equal to 'sitemap',
will serve up a sitemap file from dataroot.  The download.php links
are then used in the generation of the sitemap index.

Change-Id: I8b7af1a6820cf32542f3ae1bdfc8940c309939b0
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 00740557
...@@ -28,16 +28,38 @@ define('INTERNAL', 1); ...@@ -28,16 +28,38 @@ define('INTERNAL', 1);
require('init.php'); require('init.php');
require_once('file.php'); require_once('file.php');
$data = $SESSION->get('downloadfile'); $type = param_alpha('type', null);
if (!$USER->is_logged_in() || empty($data) || empty($data['file'])) { if ($type == 'sitemap') {
throw new NotFoundException(get_string('filenotfound')); if (!get_config('generatesitemap')) {
throw new NotFoundException(get_string('filenotfound'));
}
if ($name = param_alphanumext('name', null)) {
if (!preg_match('/^sitemap_[a-z0-9_]+\.xml(\.gz)?$/', $name, $m)) {
throw new NotFoundException(get_string('filenotfound'));
}
$mimetype = empty($m[1]) ? 'text/xml' : 'application/gzip';
}
else {
$name = 'sitemap_index.xml';
$mimetype = 'text/xml';
}
$path = get_config('dataroot') . 'sitemaps/' . $name;
} }
else {
$data = $SESSION->get('downloadfile');
if (!$USER->is_logged_in() || empty($data) || empty($data['file'])) {
throw new NotFoundException(get_string('filenotfound'));
}
$path = get_config('dataroot') . 'export/' . $USER->get('id') . '/' . $data['file']; $path = get_config('dataroot') . 'export/' . $USER->get('id') . '/' . $data['file'];
$name = $data['name'];
$mimetype = $data['mimetype'];
}
if (!file_exists($path)) { if (!file_exists($path)) {
throw new NotFoundException(get_string('filenotfound')); throw new NotFoundException(get_string('filenotfound'));
} }
serve_file($path, $data['name'], $data['mimetype']); serve_file($path, $name, $mimetype);
...@@ -232,7 +232,7 @@ class Sitemap { ...@@ -232,7 +232,7 @@ class Sitemap {
$sitemapelement = $doc->createElement('sitemap'); $sitemapelement = $doc->createElement('sitemap');
// create and encode the url // create and encode the url
$sitemapurl = sprintf("%ssitemaps/%s", get_config('wwwroot'), basename($sitemap)); $sitemapurl = sprintf("%sdownload.php?type=sitemap&name=%s", get_config('wwwroot'), basename($sitemap));
$sitemapurl = utf8_encode(htmlspecialchars($sitemapurl, ENT_QUOTES, 'UTF-8')); $sitemapurl = utf8_encode(htmlspecialchars($sitemapurl, ENT_QUOTES, 'UTF-8'));
// add it to the <sitemap> node // add it to the <sitemap> node
......
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