<?php
class searchAction extends security_normal {
	
	function action(){
		if($this->_getParam('page')){
			$page=$this->_getParam('page');
		}else{
			$page=1;
		}

		$keywords='';
		if($this->_getParam('keywords')){
			$keywords=urldecode($this->_getParam('keywords'));
		}elseif($_POST['keywords']){
			$keywords=$_POST['keywords'];
		}
		$keywords=preg_replace("/(\s+)/",' ',$keywords);
		$keywords=str_replace(' ','++',$keywords);

		if($keywords){
			$kws=explode('++',$keywords);
			$subsql='';
			foreach($kws as $kw){
				if($subsql!=''){
					$subsql.=' OR ';
				}
				$subsql.='title LIKE \'%'.$kw.'%\' OR content LIKE \'%'.$kw.'%\' OR summary LIKE \'%'.$kw.'%\' OR tags LIKE \'%'.$kw.'%\'';
			}

			//查找文章
			$article=new model_Article();
			$article->setSubsection('WHERE isvisible=0 AND ('.$subsql.') ORDER BY createdat DESC');
			$article->setPagenum($page);
			$article->setPages(20);
			$ArticleRS=$article->Pager();
			$pager=MicePager($article->TotalPages(),$article->Totals(),$article->Page(),5,MICE_URL.'index.php/search/keywords/'.urlencode($keywords).'/page/');
		}

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign('ArticleRS',$ArticleRS);
		$smarty->assign('pager',$pager);
		$smarty->assign('keywords',$keywords);

		$filename = new getTPLFileName(__CLASS__);
		$tpl=$filename->TPLFileName;
		$smarty->display($tpl);
	}	
}
?>