Mercurial > SimpleWebPresenter
changeset 98:f2d52fed708c
Split retrieval and production of urls.
Support for stylesheets in sitemap.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 19 Oct 2012 01:36:22 +0200 |
| parents | ba11b1c1b881 |
| children | d98e315308cd |
| files | Sitemap.inc |
| diffstat | 1 files changed, 41 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/Sitemap.inc Thu Oct 18 22:39:21 2012 +0200 +++ b/Sitemap.inc Fri Oct 19 01:36:22 2012 +0200 @@ -9,6 +9,20 @@ $cache->includeOnce('common-functions.inc', $baseDir); /// @endcond +function cmp_length_lex($a, $b) +{ + if ($a == $b) { + return 0; + } + $la = strlen($a); + $lb = strlen($b); + if ($la == $lb) { + return ($la < $lb) ? -1 : 1; + } + return ($a < $b) ? -1 : 1; +} + + /** * Functionality for generating a sitemap */ @@ -43,6 +57,8 @@ /// The final output variable $out = '<?xml version="1.0" encoding="UTF-8"?>'; $out .= "\n"; + $out .= '<?xml-stylesheet type="text/xsl" href="/css/gss.xsl"?>'; + $out .= "\n"; $out .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" @@ -57,6 +73,8 @@ $acceptedLanguages = $this->options->getAcceptedLanguages(); + $urls = array(); + foreach($this->options->getAcceptedLanguages() as $lang) { if ($handle = opendir(basePath() . "/${lang}")) { while (false !== ($entry = readdir($handle))) { @@ -85,23 +103,7 @@ $location = "${base}${optstring}/"; - $headers = Http::getHeaders($location, 5); - - $location = htmlentities($location); - - $lastmod = $headers["Last-Modified"]; - - $n = StatusCodes::codeFromHeader($headers['']); - - if ($n == StatusCodes::HTTP_OK) { - $lastmod = strtotime($lastmod); - $lastmod = date(DateTime::W3C, $lastmod); - - $out .= "<url>\n"; - $out .= "<loc>${location}</loc>\n"; - $out .= "<lastmod>${lastmod}</lastmod>\n"; - $out .= "</url>\n"; - } + array_push($urls, $location); } } } @@ -110,6 +112,28 @@ } } + usort($urls, cmp_length_lex); + + foreach($urls as $location) { + $headers = Http::getHeaders($location, 5); + + $location = htmlentities($location); + + $lastmod = $headers["Last-Modified"]; + + $n = StatusCodes::codeFromHeader($headers['']); + + if ($n == StatusCodes::HTTP_OK) { + $lastmod = strtotime($lastmod); + $lastmod = date(DateTime::W3C, $lastmod); + + $out .= "<url>\n"; + $out .= "<loc>${location}</loc>\n"; + $out .= "<lastmod>${lastmod}</lastmod>\n"; + $out .= "</url>\n"; + } + } + $out .= '</urlset>'; $res = new PageContent($out);
