<?
header( 'Content-type: text/html; charset=windows-1251' );
include '../sfb.php';
if ($user_status != 'admin') {
    exit();
}

if (isset($_POST['ok']) == 'ok') {
    $count = 0;
    //создаем файл
    $files = '../sitemap.xml';
    $fp = fopen($files, 'w');
    
    if (!file_exists($files)) {
        echo 'Ошибка при открытии файла';
    } else {
$add = '<?xml version="1.0" encoding="UTF-8"?>
<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">';
$add .= "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/</loc>
    <changefreq>daily</changefreq>
    <priority>1.00</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/'; echo "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/home</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/home'; echo "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/news</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/news'; echo "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/forum</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/forum'; echo "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/payments</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/payments'; echo "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/tos</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/tos'; echo "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/payments</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/payments'; echo "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/policy</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/policy'; echo "\r";
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/contact</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/contact'; echo "\r";
$sql = mysql_query("SELECT id FROM tb_forum_topic");
while ($row = mysql_fetch_array($sql)) {
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/posts/'.$row['id'].'</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/posts/'.$row['id'].''; echo "\r";
}
$sql = mysql_query("SELECT id FROM catalog_id WHERE idcount > 0");
while ($row = mysql_fetch_array($sql)) {
$add .= "\r";
$count++;
$add .= '<url>
    <loc>http://'.$_SERVER['HTTP_HOST'].'/cat/'.$row['id'].'</loc>
    <changefreq>daily</changefreq>
    <priority>0.80</priority>
</url>';
echo 'http://'.$_SERVER['HTTP_HOST'].'/cat/'.$row['id'].''; echo "\r";
}
echo '----------------------------------------------'."\r";
echo 'Все сгенерировано ссылок - '.$count."\r";
echo '----------------------------------------------';
$add .= "\r";
$add .= '</urlset>';
    fwrite($fp, $add);
    fclose ($fp);
    }
}
?>