<?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, 'posts'.$forum_info['theme_id'])) return;

	$posts=Db::i()->select("SELECT fp.post_id, IF (u.user_id>0, login, fp.user_name) as user_name, fp.msg, UNIX_TIMESTAMP(putdate) as `date`
						FROM ?_forum_posts fp 
						LEFT JOIN ?_users u ON fp.user_id=u.user_id
						WHERE fp.theme_id=?
						ORDER BY fp.post_id DESC
						LIMIT 50", $forum_info['theme_id']);
	
	$url=getServerName();
	
	$posts=array_reverse($posts);
	
	$rss=array('title'=>$forum_info['subject_html'].' - '.LabConfig::get('site_name'),
						'link'=>$url.LabCMS::i()->url($forum_info['theme_id'], 'theme'),
						'description'=>"Тема в форуме ".LabConfig::get('site_name'));
						
	foreach($posts as $key=>$post)
	{
		$post['msg_html']=getbb($post['msg']);
		
		$rss['feed'][]=array('title'=>htmlspecialchars($post['user_name']),
							'description'=>$post['msg_html'],
							'link'=>$url.LabCMS::i()->url(array($post['theme_id'], 999), 'theme').'#p'.$post_id,
							'pubDate'=>$post['date']);
	}

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