require("config.php");
connect_to_mysql();
//
// CONFIGURATION BEGINS HERE
//
// false = write to file, true = dynamic
define('GENERATE_DYNAMIC_SITEMAP', true);
// This only matters if you're writing to the file
define('STATIC_SITEMAP_FILENAME', 'sitemap.xml');
$dbprefix='fluxbb';
//
// CONFIGURATION ENDS HERE
//
$ttt=microtime();
$ttt=((double)strstr($ttt, ' ')+(double)substr($ttt,0,strpos($ttt,' ')));
ob_start();
if (GENERATE_DYNAMIC_SITEMAP)
$generator = new DynamicSitemapGenerator();
else
$generator = new StaticSitemapGenerator();
$generator->addUrl('http://mtk.com.ua/', time(), null, '1.0');
$generator->addUrl('http://mtk.com.ua/company/', time(), null, '0.75');
$generator->addUrl('http://mtk.com.ua/contacts/', time(), null, '0.75');
$generator->addUrl('http://mtk.com.ua/catalog/', time(), null, '0.75');
$generator->addUrl('http://mtk.com.ua/price/', time(), null, '0.75');
$generator->addUrl('http://mtk.com.ua/search/', time(), null, '0.75');
$generator->addUrl('http://mtk.com.ua/viasat/', time(), null, '0.75');
// ÊÀÒÀËÎÃ
$q = @mysql_query("SELECT * FROM cat_type GROUP BY type ORDER BY type");
while( $r=@mysql_fetch_object($q)) {
$generator->addUrl('http://mtk.com.ua/catalog/'.$r->type.'/', time(), null, '0.5');
// echo "type/>$r->name, ";
}
// ÒÎÂÀÐÛ
$q = @mysql_query("SELECT * FROM cat_data ORDER BY id");
while( $r=@mysql_fetch_object($q)) {
$generator->addUrl('http://mtk.com.ua/catalog/items/'.$r->id.'/', time(), null, '0.5');
// echo "id/>$r->cat_name, ";
}
$generator->addUrl('http://mtk.com.ua/delivery/', time(), null, '0.5');
$generator->addUrl('http://mtk.com.ua/English/', time(), null, '0.5');
// $generator->addUrl('http://mtk.com.ua/files/', time(), null, '0.5');
// $generator->addUrl('http://mtk.com.ua/hardware/', time(), null, '0.5');
$generator->addUrl('http://mtk.com.ua/map/', time(), null, '0.75');
// ÍÎÂÎÑÒÈ
$q = @mysql_query("SELECT id, postdate FROM inews ORDER BY id ASC");
while( $r=@mysql_fetch_object($q)) {
$postdate=$r->postdate;
$generator->addUrl('http://mtk.com.ua/news/'.$r->id.'/', $postdate, null, '0.5');
}
$q = @mysql_query("SELECT count(*) as num FROM inews");
if ($r=@mysql_fetch_object($q)) {
$pages=ceil($r->num/$res_pp);
for ($i=2; $i<$pages; $i++) {
$generator->addUrl('http://mtk.com.ua/news/?pg='.$i, $postdate, null, '0.5');
}
}
$generator->addUrl('http://mtk.com.ua/news/', $postdate, null, '0.75');
// TEX.ÎÒÄÅË
$q = @mysql_query("SELECT id, postdate FROM technical ORDER BY id ASC");
while( $r=@mysql_fetch_object($q)) {
$postdate=$r->postdate;
$generator->addUrl('http://mtk.com.ua/technical/'.$r->id.'/', $postdate, null, '0.5');
}
$q = @mysql_query("SELECT count(*) as num FROM technical");
if ($r=@mysql_fetch_object($q)) {
$pages=ceil($r->num/$res_pp);
for ($i=2; $i<$pages; $i++) {
$generator->addUrl('http://mtk.com.ua/technical/page/'.$i.'/', $postdate, null, '0.5');
}
}
$generator->addUrl('http://mtk.com.ua/technical/', $postdate, null, '0.75');
// ÑÒÀÒÜÈ
$q = @mysql_query("SELECT id, postdate FROM articles ORDER BY id ASC");
while( $r=@mysql_fetch_object($q)) {
$postdate=$r->postdate;
$generator->addUrl('http://mtk.com.ua/articles/'.$r->id.'/', $postdate, null, '0.5');
}
$q = @mysql_query("SELECT count(*) as num FROM articles");
if ($r=@mysql_fetch_object($q)) {
$pages=ceil($r->num/$res_pp);
for ($i=2; $i<$pages; $i++) {
$generator->addUrl('http://mtk.com.ua/articles/?pg='.$i, $postdate, null, '0.5');
}
}
$generator->addUrl('http://mtk.com.ua/articles/', $postdate, null, '0.75');
// ÎÁÚßÂËÅÍÈß
$q = @mysql_query("SELECT hd_id, hd_posted FROM hardware ORDER BY hd_id ASC");
while( $r=@mysql_fetch_object($q)) {
$postdate=strtotime($r->hd_posted);
$generator->addUrl('http://mtk.com.ua/hardware/'.$r->hd_id.'/', $postdate, null, '0.5');
}
$q = @mysql_query("SELECT count(*) as num FROM hardware");
if ($r=@mysql_fetch_object($q)) {
$pages=ceil($r->num/$res_pp);
for ($i=2; $i<$pages; $i++) {
$generator->addUrl('http://mtk.com.ua/hardware/page/'.$i.'/', $postdate, null, '0.5');
}
}
$generator->addUrl('http://mtk.com.ua/hardware/', $postdate, null, '0.75');
// ÔÀÉËÛ
$generator->addUrl('http://mtk.com.ua/files/', filemtime("files/"), null, '0.5');
$list=get_leaf_dirs("files");
for ($i=0; $iaddUrl('http://mtk.com.ua/files/?dir='.encode($fname).'/', filemtime($list[$i]), null, '0.5');
}
// FORUM
$result = @mysql_query('SELECT f.id as forum_id, last_post, num_topics FROM '.$dbprefix.'forums AS f LEFT JOIN '.$dbprefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY f.id DESC');
// or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
while ($cur_forum = mysql_fetch_assoc($result))
{
$generator->addUrl('http://mtk.com.ua/forum/viewforum.php?id=' . $cur_forum['forum_id'], $cur_forum['last_post'], null, '0.5');
$num_pages = ceil($cur_forum['num_topics'] / 10);
// Add page number for subsequent pages
for ($i = 2; $i <= $num_pages; ++$i)
{
$generator->addUrl('http://mtk.com.ua/forum/viewforum.php?id=' . $cur_forum['forum_id'] . '&p=' . $i, $cur_forum['last_post'], null, '0.5');
}
}
// Output the data for the topics
$result = @mysql_query('SELECT t.id as topic_id, last_post, sticky, num_replies FROM '.$dbprefix.'topics AS t LEFT JOIN '.$dbprefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL ORDER BY last_post DESC');
// or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
while ($cur_topic = mysql_fetch_assoc($result))
{
$priority = ($cur_topic['sticky'] == '1') ? '1.0' : '0.75';
$generator->addUrl('http://mtk.com.ua/forum/viewtopic.php?id=' . $cur_topic['topic_id'], $cur_topic['last_post'], null, $priority);
// We add one because the first post is not counted as a reply but needs to be
// taken into account for display
$num_pages = ceil(($cur_topic['num_replies'] + 1) / 10);
for ($i = 2; $i <= $num_pages; ++$i)
{
$generator->addUrl('http://mtk.com.ua/forum/viewtopic.php?id=' . $cur_topic['topic_id'] . '&p=' . $i, $cur_topic['last_post'], null, $priority);
}
}
$generator->addUrl('http://mtk.com.ua/forum/', time(), null, '0.75');
$generator->completeSitemap();
$sitemap = ob_get_clean();
// $sitemap .= '';
echo $sitemap;
// $ddd=microtime();
// $ddd=((double)strstr($ddd, ' ')+(double)substr($ddd,0,strpos($ddd,' ')));
// echo "";
// exit;
##################################################
abstract class SitemapGenerator
{
protected function beginSitemap()
{
global $pun_config;
$output = '' . "\n";
$output .= '' . "\n";
$output .= '' . "\n";
$this->addToSitemap($output);
}
public function completeSitemap()
{
$this->addToSitemap('' . "\n");
}
public function addUrl($loc, $lastmod = null, $changefreq = null, $priority = 0.5)
{
$output = "\t" . '' . "\n";
$output .= "\t\t" . '' . htmlspecialchars($loc, ENT_QUOTES) . '' . "\n";
if ($lastmod != null)
$output .= "\t\t" . '' . gmdate('Y-m-d\TH:i:s+00:00', $lastmod) . '' . "\n";
if ($changefreq != null)
$output .= "\t\t" . '' . $changefreq . '' . "\n";
$output .= "\t\t" . '' . $priority . '' . "\n";
$output .= "\t" . '' . "\n";
$this->addToSitemap($output);
}
protected abstract function addToSitemap($xml);
}
class StaticSitemapGenerator extends SitemapGenerator
{
private static $file;
public function __construct()
{
$this->file = fopen(STATIC_SITEMAP_FILENAME, 'w');
$this->beginSitemap();
}
protected function addToSitemap($xml)
{
fwrite($this->file, $xml);
}
public function completeSitemap()
{
parent::completeSitemap();
fclose($this->file);
echo 'Done';
}
}
class DynamicSitemapGenerator extends SitemapGenerator
{
public function __construct()
{
header('Content-type: application/xml');
$this->beginSitemap();
}
protected function addToSitemap($xml)
{
echo $xml;
}
}
####################################################################
function get_leaf_dirs($dir)
{
$array = array();
$d = @dir($dir);
if($d)
{
while (false !== ($entry = $d->read()))
{
if($entry!='.' && $entry!='..')
{
$entry = $dir.'/'.$entry;
if(is_dir($entry))
{
$subdirs = get_leaf_dirs($entry);
if ($subdirs)
$array = array_merge($array, $subdirs);
else
$array[] = $entry;
}
}
}
$d->close();
}
return $array;
}
function echo_memory_usage() {
$return='';
$mem_usage = memory_get_usage(true);
if ($mem_usage < 1024)
$return= $mem_usage." bytes";
elseif ($mem_usage < 1048576)
$return= round($mem_usage/1024,2)." kilobytes";
else
$return= round($mem_usage/1048576,2)." megabytes";
return $return;
}
function encode($buf) {
return iconv("Windows-1251", "UTF-8", $buf);
}
?>