<?='<?xml version="1.0" encoding="windows-1251"?>'?>
<rss version="2.0">
  <channel>
    <title>ChessPro.ru - профессионально о шахматах</title>
    <link>http://www.chesspro.ru</link>
    <description>Шахматы. Профессиональные обзоры. Самое интересное в лучшей форме. Трансляции с шахматных турниров с комментариями ведущих гроссмейстеров</description>
    <image>
        <url>http://www.chesspro.ru/_images/small_logo.gif</url><link>http://www.chesspro.ru</link><title>ChessPro лента</title>
    </image>
    <lastBuildDate><?=date('r');?></lastBuildDate>

<?php
include '_images/gal/includes/db.php';
include '_images/gal/includes/settings.inc';

$items = array();


//статьи
$sqlstr  = 'SELECT t1.Name, t1.Title, t1.Title_main, t1.Description, UNIX_TIMESTAMP(t1.Date) AS dat, t2.Name AS RubricName, t2.Title AS RubricTitle
	FROM Article AS t1
	INNER JOIN Rubric AS t2 USING(RubricID)
WHERE t1.Visible = "yes" ORDER BY Date DESC
';
$result = mysql_query($sqlstr);
while($row = mysql_fetch_array($result))
{
	if($row['Title_main'] == '')
	{
		$title = $row['Title'];
	}
	else
	{
      if(strpos($row['Title_main'], '.'))
		  $title = trim(substr($row['Title_main'], strpos($row['Title_main'], '.') + 1));
      else
         $title = trim($row['Title_main']);
	}
	$date = date('r', $row['dat']);
        $items[$row['dat']][] = array(
            'title' => $title,
            'url' => "http://chesspro.ru/{$row['RubricName']}/{$row['Name']}",
            'description' => $row['Description'],
            'rubric_title' => $row['RubricTitle'],
            'date' => $date
        );

}

//новости
$sqlstr = 'select id, head, descr, unix_timestamp(date) as udate from news_main where type = 1';
$result = mysql_query($sqlstr);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $href = "http://chesspro.ru/".NEWS_PATH."/{$row['id']}.html";
    foreach ($tags_vars as $tag => $data) {
        $sqlstr = 'select count(*) from tags where material_id = ' . $row['id'] . ' and material_type = "news" and tag = "' . $tag . '"';
        $result2 = mysql_query($sqlstr);
        $cnt = mysql_result($result2, 0);
        if ($cnt) {
            $href = "http://chesspro.ru/{$data['url']}/data/{$row['id']}.html";
        }
    }

    $items[$row['udate']][] = array(
        'title' => $row['head'],
        'url' => $href,
        'description' => $row['descr'],
        'rubric_title' => 'Новости',
        'date' => date('r', $row['udate'])
    );
}
//галереи
$sqlstr = 'SELECT t2.id, t1.name, unix_timestamp(date) as udate FROM gallary AS t1
                INNER JOIN foto AS t2 ON t2.gallary_id = t1.id
        WHERE visible = "yes" GROUP BY t1.id ORDER BY t1.date DESC';
        $result2 = mysql_query($sqlstr);
while($row = mysql_fetch_array($result2, MYSQL_ASSOC)) {
    $href = 'http://chesspro.ru/_images/gal/gallery.html?f=' . $row['id'];
    $items[$row['udate']][] = array(
        'title' => $row['name'],
        'url' => $href,
        'description' => '',
        'rubric_title' => 'Галереи',
        'date' => date('r', $row['udate'])
    );
}

//турниры
$sqlstr = 'select id, head, descr, unix_timestamp(date) as udate, translit from news_main where type = 2 and translit <> ""';
$result = mysql_query($sqlstr);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

    $href = 'http://chesspro.ru/tournaments/' . $row['translit'];

    $items[$row['udate']][] = array(
        'title' => htmlspecialchars($row['head']),
        'url' => $href,
        'description' => '',
        'rubric_title' => 'Турниры',
        'date' => date('r', $row['udate'])
    );
}

//Информер
$sqlstr = 'select title, anonce, href, createtime from informer ';
$result = mysql_query($sqlstr);
while ($row = mysql_fetch_assoc($result)) {
  $items[$row['createtime']][] = array(
      'title' => trim(htmlspecialchars(strip_tags($row['title']))),
      'url' => "http://chesspro.ru{$row['href']}",
      'description' => trim(htmlspecialchars(strip_tags($row['anonce']))),
      'rubric_title' => 'Чесспро онлайн',
      'date' => date('r', $row['createtime'])
  );
}


krsort($items);
foreach ($items as $item) {
    foreach ($item as $it) {
        echo "<item>
            <title>{$it['title']}</title>
            <link>{$it['url']}</link>
            <description>{$it['description']}</description>
            <category>{$it['rubric_title']}</category>
            <pubDate>{$it['date']}</pubDate>
            <guid>{$it['url']}</guid>
         </item>

         ";
    }
}

?>


</channel>
</rss>
