Mercurial > SimpleWebPresenter
view sitemap.php @ 59:0e157721bbad
Change the way we parse input files, preparing for more reasonable
caching strategy.
| author | Tom Fredrik "BFG" Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 11 Oct 2012 16:40:03 +0200 |
| parents | 2e6ba7259281 |
| children | b7efe2ecbc11 |
line wrap: on
line source
<? /** * @file * Generates a sitemap */ $out = '<?xml version="1.0" encoding="UTF-8"?>'; $out .= "\n"; $out .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> '; include_once 'CacheTimeCheck.inc'; $baseDir = dirname(__FILE__); $cache = CacheTimeCheck::instance(__FILE__); $cache->includeOnce('common-functions.inc', $baseDir); $cache = CacheTimeCheck::instance(__FILE__); $cache->includeOnce('Options.inc', dirname(__FILE__)); $master = new DOMDocument(); $master->load("master.xml"); $options = new Options($master); $base = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; $base = substr($base, 0, strrpos($base, '/')); $acceptedLanguages = $options->getAcceptedLanguages(); foreach($options->getAcceptedLanguages() as $lang) { if ($handle = opendir("${lang}")) { while (false !== ($entry = readdir($handle))) { if (endsWith($entry, '.xml')) { $fentry = "${lang}/${entry}"; $doc = new DOMDocument(); if (file_exists($fentry)) { $doc->load($fentry); $opts = array(); if (count($acceptedLanguages) > 1) { $opts['lang'] = $lang; } $toplevel = $doc->getElementsByTagName("toplevel"); if($toplevel->length) { $name = substr($entry, 0, -4); if ($name != $options->getInputDefault('name')) { $opts['name'] = $name; } $optstring = opttostring($opts); $location = "${base}/${optstring}"; $headers = getHeaders($location); $location = htmlentities($location); $lastmod = $headers["Last-Modified"]; $lastmod = strtotime($lastmod); $lastmod = date(DateTime::W3C, $lastmod); $out .= "<url>\n"; $out .= "<loc>${location}</loc>\n"; $out .= "<lastmod>${lastmod}</lastmod>\n"; $out .= "</url>\n"; } } } } closedir($handle); } } $out .= '</urlset>'; header('Content-type: application/xml'); print $out; ?>
