<?php
/*
=====================================================
 Модуль создал: REZER (http://rezer.net)
=====================================================
 Файл: category.php
=====================================================
 Данный код защищен авторскими правами
=====================================================
 Назначение: вывод категории
=====================================================
*/

if( !defined( "DATALIFEENGINE" ) ) die( "Hacking attempt!" );

//--------------------------------------------------=-=-=-=-=
//	Настройка параметров
//--------------------------------------------------=-=-=-=-=

$maxBoardRss = intval( $Board->Config['max_rss'] ); // Максимум объявлений
$ThreadCatForSql = implode( ",", $Board->SqlThreadCat( $Board->RequestCat ) ); // Запрос для категории
$mainRss = $ThreadCatForSql ? false : true;
if( !$ThreadCatForSql ) $Board->RequestCat = "main";

//--------------------------------------------------=-=-=-=-=
//	Генерация объявлений категории и её подкатегорий
//--------------------------------------------------=-=-=-=-=

$template_list = $Board->OpenCache( "rss/", "cashe_{$Board->RequestCat}.tmp" );
if( !$template_list )
	{
		$ThreadCatForSql = $ThreadCatForSql ? "AND category IN ({$ThreadCatForSql})" : "";
		$result = $db->query( "SELECT * FROM ".PREFIX."_board_post WHERE approve='1' {$ThreadCatForSql} ORDER BY `date` DESC LIMIT 0,{$maxBoardRss}" );
		if( $db->num_rows( $result ) > 0 )
			{
				while( $row = $db->get_row( $result ) )
					{
						$id = $row['id'];
						$author = stripslashes( $row['author'] );
						$author_id = stripslashes( $row['author_id'] );
						$date = date( "r", strtotime( $row['date'] ) );
						$description = stripslashes( $row['text'] );
						$title = htmlspecialchars( stripslashes( $row['title'] ) );
						$alt_name = stripslashes( $row['alt_name'] );
						$price = intval( $row['price'] );
						$currency = intval( $row['currency'] );
						$board_type = intval( $row['board_type'] );
						$country = intval( $row['country'] );
						$city = intval( $row['city'] );
						$category = intval( $row['category'] );
						$link = "http://".$_SERVER['HTTP_HOST'].$Board->ReturnLinkPost( $id, $alt_name, $category );
				
				
$template_list .= <<<HTML
		<item>
			<title>{$title}</title>
			<guid isPermaLink="true">{$link}</guid>
			<link>{$link}</link>
			<comments>{$link}#comments</comments>
			<description><![CDATA[{$description}]]></description>
			<dc:creator>{$author}</dc:creator>
			<pubDate>{$date}</pubDate>
		</item>\n
HTML;
				
					}
			}
		
		$Board->CreateCache( "rss/", "cashe_{$Board->RequestCat}.tmp", $template_list );
	}

if( $mainRss === true )
	{
		$title = stripslashes( $config['home_title'] )." - ".stripslashes( $Board->Config['main_title'] );
	}
		else
	{
		$title = array();
		$SpeedBarCat = $Board->SpeedBarCat( $Board->RequestCat );
		for( $i = count( $SpeedBarCat ); $i > 0; $i-- ) $title[] = $SpeedBarCat[ ( $i - 1 ) ]['title'];
		$title = stripslashes( $config['home_title'] )." - ".implode( "/", $title );
	}

$link = "http://".$_SERVER['HTTP_HOST']."/".$Board->ReturnLinkCategory( $Board->RequestCat );
				
$template = <<<HTML
<?xml version="1.0" encoding="$config[charset]"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<generator>Dle Board (http://rezer.net/)</generator>
		<copyright>(C) 2012</copyright>
		<webMaster>rzermak@yandex.ru (REZER)</webMaster>
		<language>ru</language>
		<title>{$title}</title>
		<link>{$link}</link>
$template_list
	</channel>
</rss>
HTML;

echo $template;
die();

?>