Sorry! yes i am talking about foreach.
<?php namespace ProcessWire;
class MarkupSitemapXMLmin extends WireData implements Module
{
private $multilang;
/**
* Provide information about this module to ProcessWire
*
*/
public static function getModuleInfo()
{
return array(
'title' => 'Markup Sitemap XMLmin',
'summary' => 'Generates an XML sitemap at yoursite.com/sitemap.xml for use with Google Webmaster Tools etc.',
'href' => 'http://processwire.com/talk/index.php/topic,867.0.html',
'version' => 126,
'permanent' => false,
'autoload' => true,
'singular' => true,
);
}
/**
* Add the hook
*
*/
public function init()
{
$urlParams = '';
$this->multilang = false;
// Intercept a request for an URL ending in sitemap.xml and output
if (isset($_SERVER['REQUEST_URI']) && strlen($_SERVER['REQUEST_URI']) - strlen('/sitemap.xml' . $urlParams) === strrpos($_SERVER['REQUEST_URI'], '/sitemap.xml' . $urlParams)) {
$this->addHookBefore("ProcessPageView::pageNotFound", $this, "renderSitemap");
}
}
public function renderSitemap(HookEvent $event)
{
$this->pageselector = '';
$startPage = str_ireplace(trim(wire('config')->urls->root, '/'), '', $this->sanitizer->path(dirname($_SERVER['REQUEST_URI'])));
// make sure that page used as root for sitemap actually exists
if ($this->pages->get($startPage) instanceof NullPage) return;
// support for LanguageLocalizedURL language module
if (wire("modules")->isInstalled("LanguageSupport")) {
$this->multilang = true;
}
// Check for the cached sitemap, else generate and cache a fresh sitemap
$startpagestr = $this->sanitizer->pageName($startPage);
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
$output .= $this->sitemapListPage($this->wire('pages')->get($startPage));
$output .= "\n</urlset>";
header("Content-Type: text/xml", true, 200);
echo $output;
exit();
}
private function renderSitemapEntry($url, $modified)
{
return "<url>\n"
. "<loc>{$url}</loc>\n"
. "<lastmod>{$modified}</lastmod>\n"
. "</url>\n";
}
public function sitemapListPage($page)
{
$entry = "";
if ($page->viewable()
&& ($page->sitemap_ignore == 0 || $page->path == '/')
) { // $page->path part added so that it ignores hiding the homepage, else you wouldn't have ANY pages returned
$modified = date('Y-m-d', $page->modified);
if (!$this->multilang) {
$entry .= $this->renderSitemapEntry($page->httpUrl, $modified);
} else {
foreach ($page->getLanguages() as $lang) {
$entry .= $this->renderSitemapEntry($page->localHttpUrl($lang), $modified);
}
}
}
// Fix #12 by FlipZoomMedia | David Karich
$children = $page->children($this->pageselector);
if (count($children)) {
foreach ($children as $child) {
$entry .= $this->sitemapListPage($child);
}
}
return $entry;
}
}