# HG changeset patch # User Tom Fredrik "BFG" Klaussen # Date 1348969172 -7200 # Node ID 647b72603b7da469d75b8742acba06322eb4f8a0 # Parent 394b5df43d1ae5b1976a3e117346e49b440f629a Script to autogenerate a sitemap. diff -r 394b5df43d1a -r 647b72603b7d sitemap.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sitemap.php Sun Sep 30 03:39:32 2012 +0200 @@ -0,0 +1,113 @@ +'; +print "\n"; +?> + +1), $info); + $headers = array(); + $str = explode("\n", $response); + foreach($str as $kv) { + $p = strpos($kv, ":"); + if ($p) { + $key = substr($kv, 0, $p); + $value = trim(substr($kv, $p + 1)); + $headers[$key] = $value; + } + } + return $headers; +} + +function opttostring($opts) +{ + $str = ''; + foreach (array_keys($opts) as $key) { + $value = $opts[$key]; + if ($str) { + $str .= "&${key}=${value}"; + } + else { + $str = "?${key}=${value}"; + } + } + return $str; +} + + +$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 ($acceptedLanguages->length > 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); + + print "\n"; + print "${location}\n"; + print "${lastmod}\n"; + print "\n"; + } + } + } + } + closedir($handle); + } +} + +?> + \ No newline at end of file