<?php
	header("Content-type: application/xml");
	
	require_once "config.php";
	require_once "inc/init.php";
	// Конект к БД
	dbconnect($db_host, $db_user, $db_pass, $db_name);
	dbquery("SET NAMES utf8");
	dbquery("SET CHARACTER SET utf8");
	
	$domain = "luberteh.ru";
	
	$trees = raItems(setQuery('tree',"p_id=0 AND (publ='on' OR onbody='on' OR link='news') AND id>1",'ord,id'));
	echo '<?xml version="1.0" encoding="UTF-8"?>';
echo "\n<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\">
<url>
  <loc>http://{$domain}/</loc>
  <changefreq>monthly</changefreq>
  <priority>0.8</priority>
</url>\n";
foreach($trees as $t){
	
	if($t['link'] == 'news'){
		echo "<url>
  <loc>http://{$domain}/{$t['link']}".($t['module'] != '' ? "/" : ".htm")."</loc>
  <changefreq>weekly</changefreq>
  <priority>0.7</priority>
</url>\n";
		$news = raItems(setQuery('news',"1=1",'id DESC LIMIT 100'));
		foreach($news as $s){
echo "<url>
  <loc>http://{$domain}/{$t['link']}/{$s['link']}.htm</loc>
  <changefreq>daily</changefreq>
  <priority>0.8</priority>
</url>\n";
		}
		
	}else{
if($t['link'] != '')
echo "<url>
  <loc>http://{$domain}/{$t['link']}.htm</loc>
  <changefreq>weekly</changefreq>
  <priority>0.7</priority>
</url>\n";
	$trees2 = raItems(setQuery('tree',"p_id={$t['id']} AND (publ='on' OR onbody='on')",'ord,id'));
foreach($trees2 as $t2){
if($t2['link'] != '')
echo "<url>
  <loc>http://{$domain}/{$t2['link']}.htm</loc>
  <changefreq>weekly</changefreq>
  <priority>0.9</priority>
</url>\n";
		$trees3 = raItems(setQuery('tree',"p_id={$t2['id']} AND (publ='on' OR onbody='on')",'ord,id'));
foreach($trees3 as $t3){
if($t3['link'] != '')
echo "<url>
  <loc>http://{$domain}/{$t3['link']}.htm</loc>
  <changefreq>weekly</changefreq>
  <priority>0.8</priority>
</url>\n";
	}
}
	}
	
}
echo '</urlset>';
?>