<?php
defined('IN_YUNYECMS') or exit('No direct script access allowed');
core::load_fun("content");
class creathtml {
	private $mod;
	private $ctrl;
	private $act;
	private $langlist; //要生成的语言列表
	private $db; //要生成的语言列表
    function __construct() {
		global $db;
		$this->db=$db;
		$this->group='app';
		$this->mod='content';
		$this->ctrl='index';
		$this->act='index';
    }
	
	//设置语言信息
	 public  function setlang($langinfo){
		if($langinfo) $this->langlist=$langinfo;
	 }
	
     public  function creathome($lang_to_creat){
			global $lang,$cfg,$seo,$thispageurl;
			$ret=false;
		    $thispageurl=ROOT.'index.html';
	        $langid=$lang_to_creat['id'];
	   		if($lang_to_creat){
					$init_cfg=$this->init_cfg($cfg,$langid);
					$lang=$init_cfg['lang'];
					$seo=$init_cfg['seo'];
					$landir=$lang_to_creat['landir'];
					if(empty($landir)){
						 $retarr['home_outstr']='生成首页—'.$lang_to_creat['title'].' 失败<br/>';
						 $retarr['status']=	false;
						 $retarr['desc']=	"{$var['title']}语言版目录不存在！";
						 return $retarr;
					}
					if($lang_to_creat['isdefault']){
						 $htmlfilepath=YUNYECMS_ROOT.'index.html';
					}else{
						 $htmlfilepath=YUNYECMS_ROOT.$landir.DIRECTORY_SEPARATOR.'index.html';
					}
					ob_start();
					ob_implicit_flush(0);
					include tpl('index');		
					$content=ob_get_clean();	
					$retwhite=fwritetext($htmlfilepath,$content);
					if($retwhite){
						$ret=true;
					}
				 if($ret){
						  $retarr['home_outstr']=	'生成首页—'.$lang_to_creat['title'].' 成功<br/>';
						  $retarr['status']=	true;
				  }else{
						  $retarr['home_outstr']='生成首页—'.$lang_to_creat['title'].' 失败<br/>';
						  $retarr['status']=	false;
				  }
		          return $retarr;
		  }else{
				 $retarr['home_outstr']='生成首页—'.$lang_to_creat['title'].' 失败<br/>';
				 $retarr['status']=	false;
			     return $retarr;
		 }
	 }
	
   public  function creat_category($cat_to_creat,$langid){
			global $lang,$cfg,$seo;
			$ret=false;
	        $column_outstr='';    
	   		if($this->langlist){
			if(!is_array($this->langlist)){
			    return array('code'=>401,'status'=>false,'desc'=>'语言版信息错误！');
			 }
							$init_cfg=$this->init_cfg($cfg,$langid);
							$lang=$init_cfg['lang'];
							$seo=$init_cfg['seo'];
							$landir=$langid['landir'];
				            foreach($cat_to_creat[$langid] as $catitem){
								$cat=$this->db->find("select * from `#yunyecms_category` where id='{$catitem}'");
								if(empty($cat['catdir'])){
			   messagebox("栏目{$cat['title']}还没有设置生成目录，请先设置生成目录再进行操作！",url_addons('index'),"info");
								}
								$rootcat=getbyid(getppid($catitem));
								$rootcatid=$rootcat["id"];
								$catid=$catitem;
			                    $curmodel=getmodel($cat["modelid"]);
								if($cat['dismode']==1){
		                          $tplfile=gettpl($cat['tplhome'],$rootcat['tplhome'],$curmodel['tplhome']);
								}elseif($curmodel['modeltype']==1){
		                          $tplfile=gettpl($cat['tpllist'],$rootcat['tpllist'],$curmodel['tpllist']);
								}elseif($curmodel['modeltype']==2||$curmodel['modeltype']==3){
		                          $tplfile=gettpl($cat['tplcontent'],$rootcat['tplcontent'],$curmodel['tplcontent']);
								}else{
		                          $tplfile=gettpl($cat['tpllist'],$rootcat['tpllist'],$curmodel['tpllist']);
								}
								$tablename="m_".$curmodel['tablename'];
								//单页面信息处理
								   if($curmodel['modeltype']==2){
										$retarr=$this->create_singlepage_html($column_outstr,$cat,$init_cfg,$rootcat,$curmodel,$tplfile);
									    $ret=$retarr['ret'];
									    $column_outstr=$retarr['column_outstr'];
								    }elseif($curmodel['modeltype']==1){
										$pagesize=empty($rootcat["pages"])?20:$rootcat["pages"];
										$sqlquery="select * from `#yunyecms_{$tablename}`  ";
										$where=" where status=1  ";
										$sqlcnt=" select count(*) from `#yunyecms_{$tablename}` ";
										$order=" order by `addtime` desc ";
										$catid=usafestr($catid);
											  if(!empty($catid)){
												   $subcat=get_cat_child($catid);
												   $catidstr=implode(',', $subcat);
												   $where=$where." and catid in($catidstr)";
											  }
										$sqlcnt=$sqlcnt." ".$where;
										$count = $this->db->GetCount($sqlcnt);
										 if($count>0){
											$totalPages = ceil($count/$pagesize);
										 }elseif($count==0){
											$totalPages = 1;
										 }     
									        //总页数
											for($curpage=1;$curpage<=$totalPages;$curpage++){
										  	  $retarr=$this->create_list_html($column_outstr,$cat,$init_cfg,$rootcat,$tplfile,$count,$sqlquery,$where,$order,$curpage,$pagesize);
											  $ret=$retarr['ret'];
											  $column_outstr=$retarr['column_outstr'];
						                    }
									   
								   }else{
									  $retarr=$this->create_form_html($column_outstr,$cat,$init_cfg,$rootcat,$curmodel,$tplfile);
									  $ret=$retarr['ret'];
									  $column_outstr=$retarr['column_outstr'];
								   }
							}
				  if($ret){
					  return array('status'=>true,'outstr'=>$column_outstr);
				  }else{
					  return array('status'=>false,'outstr'=>'');
				  }
		       }else{
					 return array('status'=>false,'outstr'=>'');
		      }
	   }
	
	
    private function create_list_html($column_outstr,$cat,$init_cfg,$rootcat,$tplfile,$count,$sqlquery,$where,$order,$curpage,$pagesize){
			$ret=false;
	        global $cfg,$thispageurl;
			$lang=$init_cfg['lang'];
			$seo=$init_cfg['seo'];
			$landir=$lang['landir'];
			$rootcatid=$rootcat["id"];
			$catid=$cat['id'];
		    $seo['title']=empty($cat["title"])?$seo["title"]:$cat["title"].'-'.$seo['title'];
			$seotitle_pre=empty($cat["title"])?'':$cat["title"].',';	
			$seo["keywords"]=(empty($cat["keywords"])?$seotitle_pre:$cat["keywords"].',').$seo["keywords"];
			$seo["description"]=(empty($cat["description"])?$seotitle_pre:strip_tags($cat["description"])).$seo["description"];	
            if($catid!=$rootcat['id']){
				                    $catdirpath=$rootcat['catdir'].DIRECTORY_SEPARATOR.$cat['catdir'];
									$rootcatpath=$rootcat['catdir'].'/'.$cat['catdir'];
								    }else{
				                    $catdirpath=$cat['catdir'];
									$rootcatpath=$cat['catdir'];
			                       }
								   if($lang['isdefault']){
									 $htmldir=YUNYECMS_ROOT.$catdirpath;
									 $urlpath=ROOT.$rootcatpath;
									}else{	
									 $htmldir=YUNYECMS_ROOT.$landir.DIRECTORY_SEPARATOR.$catdirpath;	
									 $urlpath=ROOT.$landir.'/'.$rootcatpath;	
									}												
								if(!is_dir($htmldir)) @mkdir($htmldir, 0777, true);
		                        if($curpage==1){
								$htmlfilepath=$htmldir.DIRECTORY_SEPARATOR.'index.html';
								$thispageurl=ROOT.$rootcatpath.'/index.html';
								}else{
								$htmlfilepath=$htmldir.DIRECTORY_SEPARATOR.'index_'.$curpage.'.html';
								$thispageurl=ROOT.$rootcatpath.'/index_'.$curpage.'.html';
								}
			                   $pagesize=empty($rootcat["pages"])?20:$rootcat["pages"];
										  	  $pagearr=$this->db->htmlpagelist($count,$sqlquery,$where,$order,$curpage,$pagesize,$urlpath);
											  if($pagearr["count"]!=0){
												 $list=$pagearr["query"];
												 if(isset($list)){
													 foreach($list as $kl=>$vl){
														    if(strlen(RD)>0&&stripos($list[$kl]["pic"],RD)===FALSE){
																$list[$kl]["pic"]=RD.$list[$kl]["pic"];
															}
															 $list[$kl]["downurl"]=url("download",array("catid"=>$vl["catid"],"id"=>$vl['id']));
															 $list[$kl]["url"]=!empty($vl['exlink'])?$vl['exlink']:geturl($vl['catid'],$vl['id']);
															 if(!empty($vl['content']))$list[$kl]["content"]=uhtmlspecialchars_decode($vl["content"]);
														     $modelarr=$this->db->find("select modelid  from `#yunyecms_category` where `id`= {$vl['catid']}");
														     if($modelarr){
															 $list[$kl]["modelid"]=$modelarr["modelid"];
														   }
													   }
													}	
												 $page=$pagearr["page"];
											 }
								ob_start();
								ob_implicit_flush(0);
								include tpl($tplfile);		
								$content=ob_get_clean();
								$retwhite=fwritetext($htmlfilepath,$content);
							     if($retwhite){
									$ret=true;
								  }
		              if($ret){
							  $column_outstr[]=$cat['title'];
							  $retarr['column_outstr']=	$column_outstr;
							  $retarr['ret']=	true;
					  }else{
							  $column_outstr[]=$cat['title'];
							  $retarr['column_outstr']=	$column_outstr;
						      $retarr['ret']=	false;
					  }
		            return $retarr;
	       }
		
	
    private function create_singlepage_html($column_outstr,$cat,$init_cfg,$rootcat,$curmodel,$tplfile){
		    $ret=false;
	        global $cfg,$thispageurl;
			$lang=$init_cfg['lang'];
			$seo=$init_cfg['seo'];
			$landir=$lang['landir'];
			$rootcatid=$rootcat["id"];
			$catid=$cat['id'];
		    $seo['title']=empty($cat["title"])?$seo["title"]:$cat["title"].'-'.$seo['title'];
		    $seotitle_pre=empty($cat["title"])?'':$cat["title"].',';	
		    $seo["keywords"]=(empty($cat["keywords"])?$seotitle_pre:$cat["keywords"].',').$seo["keywords"];
		    $seo["description"]=(empty($cat["description"])?$seotitle_pre:strip_tags($cat["description"])).$seo["description"];
			$modelfields=$this->db->select("select * from `#yunyecms_modelfields`  where modelid={$curmodel['modelid']}  and issys=0 ");
	  		$tablename="m_".$curmodel['tablename'];
			$row=$this->db->find("select * from `#yunyecms_{$tablename}`  where id={$catid}");
				foreach($modelfields as $key=>$var){
				 $ofdname=$var['fdname'];
				 $row[$ofdname]=uhtmlspecialchars_decode($row[$ofdname]);
				}
				 $row['pic']=dopic($row['pic']);
				 $row['content']=doimgs($row['content']);
		
			     if($catid!=$rootcat['id']){
					$catdirpath=$rootcat['catdir'].DIRECTORY_SEPARATOR.$cat['catdir'];
					$rootcatpath=$rootcat['catdir'].'/'.$cat['catdir'];
					}else{
					$catdirpath=$cat['catdir'];
					$rootcatpath=$cat['catdir'];
				   }
				   if($lang['isdefault']){
					 $htmldir=YUNYECMS_ROOT.$catdirpath;
					}else{	
					 $htmldir=YUNYECMS_ROOT.$landir.DIRECTORY_SEPARATOR.$catdirpath;	
					}		
				if(!is_dir($htmldir)) @mkdir($htmldir, 0777, true);
				$htmlfilepath=$htmldir.DIRECTORY_SEPARATOR.'index.html';;
				$thispageurl=ROOT.$rootcatpath.'/index.html';
		
				ob_start();
				ob_implicit_flush(0);
				include tpl($tplfile);		
				$content=ob_get_clean();
				$retwhite=fwritetext($htmlfilepath,$content);
			    if($retwhite){
						$column_outstr[]=$cat['title'];
						$retarr['column_outstr']=	$column_outstr;
						$retarr['ret']=	true;	
				  }else{
						 $column_outstr[]=$cat['title'];
						$retarr['column_outstr']=	$column_outstr;
						$retarr['ret']=	false;	
				 }
			return $retarr;
	}	
	
  private function create_form_html($column_outstr,$cat,$init_cfg,$rootcat,$curmodel,$tplfile){
		    $ret=false;
	        global $cfg,$thispageurl;
			$lang=$init_cfg['lang'];
			$seo=$init_cfg['seo'];
			$landir=$lang['landir'];
			$rootcatid=$rootcat["id"];
			$catid=$cat['id'];
		    $seo['title']=empty($cat["title"])?$seo["title"]:$cat["title"].'-'.$seo['title'];
		    $seotitle_pre=empty($cat["title"])?'':$cat["title"].',';	
		    $seo["keywords"]=(empty($cat["keywords"])?$seotitle_pre:$cat["keywords"].',').$seo["keywords"];
		    $seo["description"]=(empty($cat["description"])?$seotitle_pre:strip_tags($cat["description"])).$seo["description"];
			$modelfields=$this->db->select("select * from `#yunyecms_modelfields`  where modelid={$curmodel['modelid']}  and issys=0 ");
	  		$tablename="m_".$curmodel['tablename'];
			$row=$this->db->find("select * from `#yunyecms_{$tablename}`  where id={$catid}");
				foreach($modelfields as $key=>$var){
				 $ofdname=$var['fdname'];
				 $row[$ofdname]=uhtmlspecialchars_decode($row[$ofdname]);
				}
				 $row['pic']=dopic($row['pic']);
				 $row['content']=doimgs($row['content']);
				if($catid!=$rootcat['id']){
					$catdirpath=$rootcat['catdir'].DIRECTORY_SEPARATOR.$cat['catdir'];
					$rootcatpath=$rootcat['catdir'].'/'.$cat['catdir'];
					}else{
					$catdirpath=$cat['catdir'];
					$rootcatpath=$cat['catdir'];
				   }
				   if($lang['isdefault']){
					 $htmldir=YUNYECMS_ROOT.$catdirpath;
					}else{	
					 $htmldir=YUNYECMS_ROOT.$landir.DIRECTORY_SEPARATOR.$catdirpath;	
					}		
				if(!is_dir($htmldir)) @mkdir($htmldir, 0777, true);
				$htmlfilepath=$htmldir.DIRECTORY_SEPARATOR.'index.html';;
				$thispageurl=ROOT.$rootcatpath.'/index.html';
				ob_start();
				ob_implicit_flush(0);
				include tpl($tplfile);		
				$content=ob_get_clean();
				$retwhite=fwritetext($htmlfilepath,$content);
			    if($retwhite){
						$column_outstr[]=$cat['title'];
						$retarr['column_outstr']=	$column_outstr;
						$retarr['ret']=	true;	
				  }else{
						$column_outstr[]=$cat['title'];
						$retarr['column_outstr']=	$column_outstr;
						$retarr['ret']=	false;	
				 }
			return $retarr;
	}	
	
	//刷新内容页
   public  function creat_content($cat_to_creat,$langid){
			global $lang,$cfg,$seo,$thispageurl,$htmlinfo;
			$ret=false;
	        $content_outstr='';   
	   		if($this->langlist){
			if(!is_array($this->langlist)){
			    return array('code'=>401,'status'=>false,'desc'=>'语言版信息错误！');
			 }
			                $infosum=0;	
							$init_cfg=$this->init_cfg($cfg,$langid);
							$lang=$init_cfg['lang'];
							$seo=$init_cfg['seo'];
							$landir=$lang['landir'];
							$infosum=$infosum+count($cat_to_creat[$langid]);
				            foreach($cat_to_creat[$langid] as $catitem){
								$catid=$catitem['catid'];
								$cat=$this->db->find("select * from `#yunyecms_category` where id='{$catid}'");
								if(empty($cat['catdir'])){
			   messagebox("栏目{$cat['title']}还没有设置生成目录，请先设置生成目录再进行操作！",url_addons('index'),"info");
								}
								$id=$catitem['id'];
								$rootcat=getbyid(getppid($catid));
								$rootcatid=$rootcat["id"];
			                    $curmodel=getmodel($cat["modelid"]);
							    $tplfile=gettpl($cat['tplcontent'],$rootcat['tplcontent'],$curmodel['tplcontent']);
								$tablename="m_".$curmodel['tablename'];
								$modelfields_all=$this->db->select("select * from `#yunyecms_modelfields`  where modelid='{$cat["modelid"]}'  and issys=0 ");
		                        $row=$this->db->find("select * from `#yunyecms_{$tablename}`  where id='{$id}'");
		$token="<script language=\"javascript\" src=\"".ROOT."index.php?m=api&c=index&a=get_member_token\"></script>";
									$prevsql='';
									$nextsql='';
									if($catid!=''){
									$prevsql=" addtime>=".$row['addtime']." and id<>".$id."   and catid=".$catid."";
									$nextsql=" addtime<=".$row['addtime']."  and id<>".$id."   and catid=".$catid."";
										}else{
									$prevsql=" addtime>=".$row['addtime']." and id<>".$id."  ";
									$nextsql=" addtime<=".$row['addtime']."  and id<>".$id."  ";	
											}
									$prev=$this->db->find("select * from `#yunyecms_{$tablename}`  where {$prevsql} order by addtime asc limit 0,1");
									if($prev){
										$prev["url"]=url("show",array("catid"=>$prev["catid"],"id"=>$prev["id"]));
									}		 
									$next=$this->db->find("select * from `#yunyecms_{$tablename}`  where {$nextsql}  order by addtime desc limit 0,1");
									if($next){
										$next["url"]=url("show",array("catid"=>$next["catid"],"id"=>$next["id"]));
									}
									$row['time']=udate($row['addtime']);
									foreach($modelfields_all as $key=>$vfd){
										 $fdname=$vfd['fdname'];
										 $formctrl=$vfd['formctrl'];
										  if(isset($row[$fdname])){
											  if($formctrl=="editor"){
												$row[$fdname]=doimgs($row[$fdname]);
												$row[$fdname]=remove_style($row[$fdname]);
											   }else{
											    $row[$fdname]=uhtmlspecialchars_decode($row[$fdname]);
											   }
										  }
									   }
							$row["downurl"]=url("download",array("catid"=>$row["catid"],"id"=>$id));
							if(!empty($row["morepic"])){
							   $row["morepic"]=unserialize($row["morepic"]);
								foreach($row["morepic"] as $k=>$vpic){
									 $row['morepic'][$k]=dopic($vpic);
								}	
							}				 
							 $row['pic']=dopic( $row['pic']);
		$row['jshits']="<script language=\"javascript\" src=\"".ROOT."index.php?m=api&c=index&a=get_content_hits&id={$id}&catid={$catid}\"></script>";
								$seo["description"]=(empty($row["seodesc"])? strcut(trim(strip_tags($row["content"])),200):$row["seodesc"].','.$cat["description"]);		 
								$seo['title']=(empty($row["seotitle"])?$row["title"]:$row["seotitle"]).'-'.$cat["title"].'-'.$seo['title'];
								$seo["keywords"]=(empty($row["seokeywords"])?$row["title"]:$row["seokeywords"]).','.$seo["keywords"];
								$tplfile=gettpl($cat['tplcontent'],$rootcat['tplcontent'],$curmodel['tplcontent'],$row['template'],2);
				
				if($catid!=$rootcat['id']){
					$catdirpath=$rootcat['catdir'].DIRECTORY_SEPARATOR.$cat['catdir'];
					$rootcatpath=$rootcat['catdir'].'/'.$cat['catdir'];
					}else{
					$catdirpath=$cat['catdir'];
					$rootcatpath=$cat['catdir'];
				   }
				   if($lang['isdefault']){
					 $htmldir=YUNYECMS_ROOT.$catdirpath;
					}else{	
					 $htmldir=YUNYECMS_ROOT.$landir.DIRECTORY_SEPARATOR.$catdirpath;	
					}		
				if(!is_dir($htmldir)) @mkdir($htmldir, 0777, true);
				$htmlfilepath=$htmldir.DIRECTORY_SEPARATOR.$id.'.html';
				$thispageurl=ROOT.$rootcatpath.'/'.$id.'.html';
				$htmlinfo['id']=$id;			
				$htmlinfo['langid']=$langid;			
				$htmlinfo['tablename']=$tablename;			
				ob_start();
				ob_implicit_flush(0);
				include tpl($tplfile);		
				$content=ob_get_clean();
				$retwhite=fwritetext($htmlfilepath,$content);
							if($retwhite){
										$ret['status']=	true;	
										$ret['cat_title']= $cat['title'];	
										$ret['cat_id']= $cat['id'];	
								}else{
										$ret['status']=	false;	
										$ret['cat_title']= $cat['title'];	
										$ret['cat_id']= $cat['id'];	
							   }
						  }
				 $ret['infosum']= $infosum;	
				 return $ret;
		        }else{
					 return false;
		      }
	   }	
	
	 private function init_cfg($cfg,$langid=false) {
		    if($langid){
		     $lang=getcurlang($langid);
			}else{
		     $lang=getdefaultlang();
			}
			$lang=dolang($lang,$cfg);
		 	$lang['logo']=dopic($lang['logo']);
			$lang['icon']=dopic($lang['icon']);
			$lang['qrcode']=dopic($lang['qrcode']);
			$lang['copyright']=doimgs($lang['copyright']);
		 	define('LAN',empty($lang['landir'])?"cn":$lang['landir']);
			define('CTD',empty($lang['theme'])?"default":$lang['theme']);
			define('TPL',THEME.CTD."/".LAN."/");
			$seo['title']=$lang["seotitle"];
			$seo['keywords']=$lang["seokey"];
			$seo['description']=$lang["seodesc"];
	        $this->init_const();
            return array('lang'=>$lang,'seo'=>$seo);
	   }
	
	
	private function  init_const(){
		define('URL_MODEL',5);
		define('URL_ROUTE',true);
		define('APP_SUB_DOMAIN_DEPLOY',false);
		define('URL_COMPAT',      3);   // 兼容模式
		define('URL_REWRITE',     2);   //REWRITE模式
		define('URL_PATHINFO_DEPR',"/");
		define('URL_HTML_SUFFIX',"html");
		define('URL_DENY_SUFFIX',"ico|png|gif|jpg"); // URL禁止访问的后缀设置
		define('VAR_URL_PARAMS','_URL_'); // PATHINFO URL参数变量
		define('IS_CGI',substr(PHP_SAPI, 0,3)=='cgi' ? 1 : 0 );
		define('IS_WIN',strstr(PHP_OS, 'WIN') ? 1 : 0 );
		define('URL_PATHINFO_FETCH',     'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL,REQUEST_URI,QUERY_STRING');   //用于兼容判断PATH_INFO 参数的SERVER替代变量列表
		// 项目名称
		defined('SITE_ROOT') or define('SITE_ROOT', basename(dirname($_SERVER['SCRIPT_FILENAME'])));	
		if(!defined('_PHP_FILE_')) {
			if(IS_CGI) {
				//CGI/FASTCGI模式下
				$_temp  = explode('.php',$_SERVER['PHP_SELF']);
				define('_PHP_FILE_',    rtrim(str_replace($_SERVER['HTTP_HOST'],'',$_temp[0].'.php'),'/'));
			}else {
				define('_PHP_FILE_',    rtrim($_SERVER['SCRIPT_NAME'],'/'));
			}
		}
		// 当前文件名
		if(!defined('_PHP_FILE_')) {
			if(IS_CGI) {
				//CGI/FASTCGI模式下
				$_temp  = explode('.php',$_SERVER['PHP_SELF']);
				define('_PHP_FILE_',    rtrim(str_replace($_SERVER['HTTP_HOST'],'',$_temp[0].'.php'),'/'));
			}else {
				define('_PHP_FILE_',    rtrim($_SERVER['SCRIPT_NAME'],'/'));
			}
		}
		if(!defined('__ROOT__')) {
			// 网站URL根目录
			if( strtoupper(SITE_ROOT) == strtoupper(basename(dirname(_PHP_FILE_))) ) {
				$_root = dirname(dirname(_PHP_FILE_));
			}else {
				$_root = dirname(_PHP_FILE_);
			}
			define('__ROOT__',   (($_root=='/' || $_root=='\\')?'':$_root));
		}
		define('APP_IN',strip_tags(_PHP_FILE_));
	}
	
	/**
	* 获取html文件
	* @param $tpl 模板名
	*/
	private function gethtml($tpl='index') {
		    global $lang,$cfg,$seo;
			ob_start();
			ob_implicit_flush(0);
			include tpl($tpl);		
		    return ob_get_clean();;
	}
	
	
	
	
	
	
}