<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

	LabCMS::i()->setModuleTemplate('string:{$xml}');
	LabVars::$break=true;
	LabVars::$template='blank.tpl';
	
	sendXmlHeaders();
	if (LabCMS::i()->is_cached('string:{$xml}', 10*60, 'themes'.$forum_info['forum_id'])) return;

	$url=getServerName();
	
	$themes=Db::i()->select("SELECT theme_id, author_id, IF(author_id, ua.login, author) as author, subject, total_posts, UNIX_TIMESTAMP(last_post) as last_post
													FROM ?_forum_themes ft
													LEFT JOIN ?_users u ON ft.last_user_id=u.user_id
													LEFT JOIN ?_users ua ON ft.author_id=ua.user_id
													WHERE forum_id=?
													ORDER BY last_post DESC LIMIT 30", $forum_info['forum_id']);
													
	$rss=array('title'=>'Последние темы форума - '.$forum_info['forum_name'].' - '.LabConfig::get('site_name'),
						'link'=>$url.LabCMS::i()->url(),
						'description'=>"Последние темы в форуме ".LabConfig::get('site_name'));
	
	foreach($themes as $key=>$theme)
	{
		$post['subject_html']=getbb($theme['subject'], 'nolinks');
		
		$rss['feed'][]=array('title'=>$post['subject_html'],
							'description'=>"Последний ответ: ".date("d/m/Y H:i",$theme['last_date'])."<br />Всего ответов: ".$theme['total_posts'],
							'link'=>$url.LabCMS::i()->url(array($post['theme_id'], 999), 'theme').'#'.$theme['last_date'],
							'pubDate'=>$post['last_date']);
	}

	$xml=genereteFeed($rss);
	Tpl::i()->assign('xml', $xml);