Permalink
Browse files

Fixed sitemap generation

  • Loading branch information...
ilmich committed Oct 10, 2011
1 parent df129e8 commit 6858b95edfd0f9cbb09f937d56d3783da71ee357
Showing with 15 additions and 7 deletions.
  1. +15 −7 sitemap.php
View
@@ -8,18 +8,26 @@
//generate url for all pages
$pages = glob(getDataDir().'pages/*.metadata.php');
- foreach ($pages as $page) {
+ foreach ($pages as $page) {
$id = basename($page,'.metadata.php'); //recover id from filename
+ if (strpos($id, '_') == 0) { continue; }
$stats = stat(getDataDir().'pages/'.$id.'.php'); //recover stat from file
- $urls['url'] = array('url' => array('loc' => getWebRoot().'page.php?page='.$id,
- 'lastmod' => Date::dater($stats['mtime'],"Y-m-d"))
+ $urls[] = array('loc' => getWebRoot().'page.php?page='.$id,
+ 'lastmod' => Date::dater($stats['mtime'],"Y-m-d")
); //generate url
- }
-
+ }
+
//raise event in order to add url from external component
EventManager::getInstance()->getEvent('sitemapEvent')->raise($urls);
- $xml = ArrayUtils::toXml($urls,'urlset');
+ $xml = '<?xml version="1.0" encoding="utf-8"?>'.PHP_EOL.'<urlset>'.PHP_EOL;
+ foreach ($urls as $url) {
+ $xml .= ' <url>'.PHP_EOL;
+ $xml .= ' <loc>'.$url['loc'].'</loc>'.PHP_EOL;
+ $xml .= ' <lastmod>'.$url['lastmod'].'</lastmod>'.PHP_EOL;
+ $xml .= ' </url>'.PHP_EOL;
+ }
+ $xml .= '</urlset>';
$res->setBody($xml);
- $res->send();
+ $res->send();

0 comments on commit 6858b95

Please sign in to comment.