<?php
# (c) Беззубов Александр Станиславович (S30N1K)
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/shif.php';
include_once 'sys/inc/adm_check.php';
include_once 'sys/inc/user.php';





//Нужно для даты
define('DATE_FORMAT_RFC822','r');
// Создаем документ
$xml = new DomDocument('1.0','utf-8');



//Заголовки
$urlset = $xml->appendChild($xml->createElement('urlset'));
$urlset->setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance');
$urlset->setAttribute('xsi:schemaLocation','http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd');
$urlset->setAttribute('xmlns','http://www.sitemaps.org/schemas/sitemap/0.9');



$pp[] = 'chat/';
$pp[] = 'forum/';
$pp[] = 'guest/';
$pp[] = 'loads/';
$pp[] = 'lib/';

foreach ($pp as $k => $v) {

	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/'.$v));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));

}





$q=mysql_query("SELECT * FROM `forum_f`  WHERE `adm` = '0' ORDER BY `pos` ASC");
while ($post = mysql_fetch_assoc($q)) {
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/forum/'.$post['id'].'/'));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}


$q=mysql_query("SELECT * FROM `forum_r` ORDER BY `time` DESC");
while ($post = mysql_fetch_assoc($q)) {
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/forum/'.$post['id_forum'].'/'.$post['id'].'/'));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}



$q=mysql_query("SELECT * FROM `forum_t` ORDER BY `time` DESC");
while ($post = mysql_fetch_assoc($q)) {
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/forum/'.$post['id_forum'].'/'.$post['id_razdel'].'/'.$post['id'].'/'));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}




$q=mysql_query("SELECT * FROM `loads_list` ORDER BY `time` DESC");
while ($post = mysql_fetch_assoc($q)) {
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/loads/?d='.$post['path'].'&f='.$post['name']));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}



$q=mysql_query("SELECT * FROM `obmennik_dir` ORDER BY `id` ASC");
while ($post = mysql_fetch_assoc($q)) {
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/obmen'.$post['dir']));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}


$q=mysql_query("SELECT * FROM `obmennik_files` ORDER BY `id` ASC");
while ($post = mysql_fetch_assoc($q)) {
	$dir=mysql_fetch_assoc(mysql_query("SELECT * FROM `obmennik_dir` WHERE `dir` = '$post[id]' LIMIT 1"));
	
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/obmen/'.$dir['dir'].$post['name'].'.'.$post['ras']));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}


$q=mysql_query("SELECT * FROM `gallery` ORDER BY `id` DESC");
while ($post = mysql_fetch_assoc($q)) {
	$ank=get_user($post['id_user']);
	
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/foto/'.$ank['id'].'/'.$post['id'].'/'));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}


$q=mysql_query("SELECT * FROM `gallery_foto` ORDER BY `id` DESC");
while ($post = mysql_fetch_assoc($q)) {
	$dir = mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `id` = '$post[id]' LIMIT 1"));
	$ank = get_user($dir['id_user']);
	
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/foto/'.$ank['id'].'/'.$dir['id'].'/'.$post['id']));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}


$q=mysql_query("SELECT * FROM `lib_dir` ORDER BY `id` ASC");
while ($post = mysql_fetch_assoc($q)) {
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/lib'.$post['dir']));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}

$q=mysql_query("SELECT * FROM `lib_files` ORDER BY `id` ASC");
while ($post = mysql_fetch_assoc($q)) {
	$dir = mysql_fetch_assoc(mysql_query("SELECT * FROM `lib_dir` WHERE `id` = '$post[id]' LIMIT 1"));
	
	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/lib'.$dir['dir'].$post['name'].'.htm'));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	$priority->appendChild($xml->createTextNode('0.5'));
}


$q = mysql_query("SELECT * FROM `user` ORDER BY id DESC");
while ($post = mysql_fetch_assoc($q)) {

	$lastmod_value = date(DATE_FORMAT_RFC822, $post['date_last']);

	$url = $urlset->appendChild($xml->createElement('url'));
	$loc = $url->appendChild($xml->createElement('loc'));
	$lastmod = $url->appendChild($xml->createElement('lastmod'));
	$changefreq = $url->appendChild($xml->createElement('changefreq'));
	$priority = $url->appendChild($xml->createElement('priority'));
	$loc->appendChild($xml->createTextNode('http://' . $_SERVER['HTTP_HOST'] . '/info.php?id='.$post['id']));
	$lastmod->appendChild($xml->createTextNode($lastmod_value));
	$changefreq->appendChild($xml->createTextNode('monthly'));
	//Укажем средний приоритет
	$priority->appendChild($xml->createTextNode('0.5'));
}

 
$xml -> formatOutput = true;
//Записываем файл
$xml->save('sitemap.xml');