<?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
*/
	$mod_template="top_news.tpl";
	if (LabCMS::i()->is_cached($mod_template, 60*10, 0)) return;

	//значения по умолчанию
	if (empty(LabConfig::$mcfg['top_news'])) LabConfig::$mcfg['top_news']=3;
    
	$result=Db::i()->select("SELECT news_date, news_title, news_text, news_id FROM ?_news WHERE news_date<=NOW() ORDER BY news_date DESC LIMIT ?d", LabConfig::$mcfg['top_news']);
	$news=array();
	foreach($result as $news_row)
	{
		$anonce=0;
		//если присутствует тег [more]
		if ($anonce=mb_stristr($news_row['news_text'], '[more]', true))
		{
			$news_row['news_text']=$anonce;
			$anonce=1;
		}
		elseif(!empty(LabConfig::$mcfg['news_anonce_length']))
		{
			$text_wo_tags=strip_tags($news_row['news_text']);
			if (strlen($text_wo_tags)>LabConfig::$mcfg['news_anonce_length'])
			{
				$news_row['news_text']=breakword($news_row['news_text'], LabConfig::$mcfg['news_anonce_length']);
				$anonce=1;
			}
		}
		$news[]=array('news_id'=>$news_row['news_id'],
						'news_date'=>$news_row['news_date'], 
						'news_title'=>$news_row['news_title'], 
						'news_text'=>$news_row['news_text'],
						'anonce'=>$anonce);
	}
Tpl::i()->assign('top_news', $news);
