loadLanguage(array('public_sitemap'));
$menu = $PMDR->get('CustomLinks');
$PMDR->setAdd('page_title',$PMDR->getLanguage('public_sitemap'));
$PMDR->setAddArray('breadcrumb',array('link'=>BASE_URL.'/sitemap.php','text'=>$PMDR->getLanguage('public_sitemap')));
$PMDR->loadCSS('');
$PMDR->loadJavascript('');
$PMDR->loadJavascript('');
$PMDR->loadJavascript('');
if(!isset($_GET['id']) OR !isset($_GET['letter']) OR !isset($_GET['type'])) {
if(!$content = $PMDR->get('Cache')->get('categories_sitemap', 1800)) {
$categories = $db->GetAll("SELECT id, title, level, hidden, count_total, left_, right_, friendly_url_path FROM ".T_CATEGORIES." WHERE id!=1 ORDER BY left_");
$categories_count = count($categories);
// Loop through categories to get rid of hidden and count = 0
for($x=0; $x < $categories_count; $x++) {
if($categories[$x]['hidden'] OR ($PMDR->getConfig('cat_empty_hidden') AND $categories[$x]['count_total'] == 0)) {
for($y=$x+1; $y < $categories_count; $y++) {
if($categories[$y]['level'] <= $categories[$x]['level']) {
break;
} else {
unset($categories[$y]);
}
}
unset($categories[$x]);
$x = $y-1;
}
}
$closing_tags = array();
$content = '
- '.$PMDR->getLanguage('public_sitemap_categories');
if(count($categories)) {
$content .= '
';
foreach($categories as $category_key=>$category) {
$child = ($PMDR->get('Categories')->isLeaf($category)) ? 0 : 1;
foreach($closing_tags as $level=>$tag) {
if($level >= $category['level']) {
$content .= array_pop($closing_tags);
}
}
if($child == 1) {
$closing_tags[$category['level']] = '
';
} else {
$closing_tags[$category['level']] = '';
}
$content .= '- '.$PMDR->get('Cleaner')->clean_output($category['title']).'';
$content .= ($child == 1) ? '
' : '';
}
while($tag = array_pop($closing_tags)) {
$content .= $tag;
}
$content .= '
';
}
$content .= '
';
$PMDR->get('Cache')->write('categories_sitemap',$content);
}
if(!$content2 = $PMDR->get('Cache')->get('locations_sitemap', 1800)) {
$locations = $db->GetAll("SELECT id, title, level, hidden, count_total, left_, right_, friendly_url_path FROM ".T_LOCATIONS." WHERE id!=1 ORDER BY left_");
$locations_count = count($locations);
// Loop through locations to get rid of hidden and count = 0
for($x=0; $x < $locations_count; $x++) {
if($locations[$x]['hidden'] OR ($PMDR->getConfig('loc_empty_hidden') AND $locations[$x]['count_total'] == 0)) {
for($y=$x+1; $y < $locations_count; $y++) {
if($locations[$y]['level'] <= $locations[$x]['level']) {
break;
} else {
unset($locations[$y]);
}
}
unset($locations[$x]);
$x = $y-1;
}
}
$closing_tags = array();
$content2 = '- '.$PMDR->getLanguage('public_sitemap_locations');
if(count($locations)) {
$content2 .= '
';
foreach($locations as $location_key=>$location) {
$child = ($PMDR->get('Locations')->isLeaf($location)) ? 0 : 1;
foreach($closing_tags as $level=>$tag) {
if($level >= $location['level']) {
$content2 .= array_pop($closing_tags);
}
}
if($child == 1) {
$closing_tags[$location['level']] = '
';
} else {
$closing_tags[$location['level']] = '';
}
$content2 .= '- '.$PMDR->get('Cleaner')->clean_output($location['title']).'';
$content2 .= ($child == 1) ? '
' : '';
}
while($tag = array_pop($closing_tags)) {
$content2 .= $tag;
}
$content2 .= '
';
}
$content2 .= '
';
$PMDR->get('Cache')->write('locations_sitemap',$content2);
}
} else {
if($_GET['type'] == 'locations') {
$datasource = $PMDR->get('Locations');
$content = '- '.$PMDR->getLanguage('public_sitemap_locations');
} else {
$datasource = $PMDR->get('Categories');
$content = '
- '.$PMDR->getLanguage('public_sitemap_categories');
}
if($_GET['letter'] == "0-9") {
$sitemap_cats = $datasource->getChildren(intval($_GET['id']),1,"AND title REGEXP '^[[:digit:]].*$'");
} else {
$sitemap_cats = $datasource->getChildren(intval($_GET['id']),1,"AND title LIKE '".$PMDR->get('Cleaner')->clean_db($_GET['letter'])."%'");
}
$closing_tags = array();
if(count($sitemap_cats)) {
$content .= '
';
foreach($sitemap_cats as $category) {
$child = ($datasource->isLeaf($category)) ? 0 : 1;
foreach($closing_tags as $level=>$tag) {
if($level >= $category['level']) {
$content .= array_pop($closing_tags);
}
}
if($child == 1) {
$closing_tags[$category['level']] = '
';
} else {
$closing_tags[$category['level']] = '
';
}
$content .= '- '.$PMDR->get('Cleaner')->clean_output($category['title']).'';
$content .= ($child == 1) ? '
' : '';
}
foreach($closing_tags as $tag) {
$content .= $tag;
}
$content .= '
';
}
$content .= '
';
}
$template_content = $PMDR->getNew('Template',PMDROOT.TEMPLATE_PATH.'sitemap.tpl');
$template_content->set('sitemap_categories',$content);
$template_content->set('sitemap_locations',$content2);
$template_content->set('links',$menu->getMenuHTML(0,0,1));
include(PMDROOT.'/includes/template_setup.php');
?>