From c95df4cf50035e5018974ff9daca0bb2b2e4ae1a Mon Sep 17 00:00:00 2001 From: svanschu Date: Mon, 13 Nov 2017 23:32:09 +0100 Subject: [PATCH] #29 use change frequency as max age --- .../views/xml/tmpl/default.php | 2 +- .../views/xml/view.html.php | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/components/com_schuweb_sitemap/views/xml/tmpl/default.php b/components/com_schuweb_sitemap/views/xml/tmpl/default.php index 15a7a4b..06d7766 100644 --- a/components/com_schuweb_sitemap/views/xml/tmpl/default.php +++ b/components/com_schuweb_sitemap/views/xml/tmpl/default.php @@ -24,7 +24,7 @@ } if ($params->get('cacheControlUseChangeFrequency', 1) == 1) { -//TODO + $cacheControl += 'max-age=' + $this->changeFreq; } else { if ($maxAge = $params->getInt('cacheControlMaxAge', 0) > 0) { $cacheControl += 'max-age=' + $maxAge; diff --git a/components/com_schuweb_sitemap/views/xml/view.html.php b/components/com_schuweb_sitemap/views/xml/view.html.php index 5d78002..7a7109a 100644 --- a/components/com_schuweb_sitemap/views/xml/view.html.php +++ b/components/com_schuweb_sitemap/views/xml/view.html.php @@ -63,6 +63,39 @@ function display($tpl = null) $this->sitemapItems = $this->get('SitemapItems'); $this->extensions = $this->get('Extensions'); + $freq = 31536000; + foreach ($this->items as $item) { + foreach ($item as $iitem) { + foreach ($iitem->items as $iitems) { + switch ($iitems->changefreq) { + case "never": + case "yearly": + if ($freq > 31536000) + $freq = 31536000; + break; + case "monthly": + if ($freq > 18144000) + $freq = 18144000; + break; + case "weekly": + if ($freq > 604800) + $freq = 604800; + break; + case "daily": //60 Sekunden x 60 Minuten x 24 Stunden + if ($freq > 86400) + $freq = 86400; + break; + case "hourly": + if ($freq > 3600) + $freq = 3600; + break; + } + } + } + } + + $this->changeFreq = $freq; + // Check for errors. if (count($errors = $this->get('Errors'))) { $app->enqueueMessage(implode("\n", $errors), 'warning');