# HG changeset patch # User Tom Fredrik "BFG" Klaussen # Date 1350603382 -7200 # Node ID f2d52fed708c6bde3a190057f745b279c3c1af35 # Parent ba11b1c1b8814b413505bed6626142b4a4fd1788 Split retrieval and production of urls. Support for stylesheets in sitemap. diff -r ba11b1c1b881 -r f2d52fed708c Sitemap.inc --- 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 = ''; $out .= "\n"; + $out .= ''; + $out .= "\n"; $out .= '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 .= "\n"; - $out .= "${location}\n"; - $out .= "${lastmod}\n"; - $out .= "\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 .= "\n"; + $out .= "${location}\n"; + $out .= "${lastmod}\n"; + $out .= "\n"; + } + } + $out .= ''; $res = new PageContent($out);