<?php
defined('IN_YUNYECMS') or exit('No direct script access allowed');
class creathtml {
	private $mod;
	private $ctrl;
	private $act;
	private $langlist; //要生成的语言列表
    function __construct() {
		$this->group='app';
		$this->mod='content';
		$this->ctrl='index';
		$this->act='index';
    }
	
	//设置语言信息
	 public  function setlang($langinfo){
		if($langinfo) $this->langlist=$langinfo;
	 }
	
	
   public  function creathome2(){
			global $lang,$cfg,$seo;
			$ret=false;
	   		if($this->langlist){
			if(!is_array($this->langlist)){
			    return array('code'=>401,'status'=>false,'desc'=>'语言版信息错误！');
			 }else{
				if(count($this->langlist)>1){
					    foreach($this->langlist as $key=>$var){
							$lang=getcurlang($var['id']);
							$lang=dolang($lang,$cfg);
							$seo['title']=$lang["seotitle"];
							$seo['keywords']=$lang["seokey"];
							$seo['description']=$lang["seodesc"];
							define('LAN',empty($lang['landir'])?"cn":$lang['landir']);
							define('CTD',empty($lang['theme'])?"default":$lang['theme']);
							define('TPL',THEME.CTD."/".LAN."/");
							$landir=$var['landir'];
							if(empty($landir)){
								return array('code'=>402,'status'=>false,'desc'=>"{$var['title']}语言版目录不存在！");
							}
							if($var['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;
							}
					 }
				}else{
					ob_start();
					ob_implicit_flush(0);
					include tpl('index');		
					$content=ob_get_clean();	
					$htmlfilepath=YUNYECMS_ROOT.'index.html';
					$ret=fwritetext($htmlfilepath,$content);
				}
				 if($ret){
					 return array('code'=>100,'status'=>true,'desc'=>'成功刷新首页HTML文件！');
				  }else{
					 return array('code'=>403,'status'=>false,'desc'=>'刷新首页HTML文件失败！');
				  }
			 }
		  }else{
			 return array('code'=>400,'status'=>false,'desc'=>'刷新首页HTML文件失败！');
		 }
	 }
	
	
    public  function creathome(){
		//$strurl=$this->group.'/'.$this->mod.'/'.$this->ctrl.'/index';
		//$web_url=getweburl(url($strurl));
		$web_url=gethost().'/index.php';
		$ret=false;
		if($this->langlist){
			if(!is_array($this->langlist)){
			    return array('code'=>401,'status'=>false,'desc'=>'语言版信息错误！');
			}else{
				if(count($this->langlist)>1){
					    foreach($this->langlist as $key=>$var){
						$landir=$var['landir'];
						if(empty($landir)){
							return array('code'=>402,'status'=>false,'desc'=>"{$var['title']}语言版目录不存在！");
						}
						if($var['isdefault']){
							 $htmlfilepath=YUNYECMS_ROOT.'index.html';
							 $requesturl=$web_url;
						}else{
							 $htmlfilepath=YUNYECMS_ROOT.$landir.DIRECTORY_SEPARATOR.'index.html';
							 $requesturl=$web_url.'?lang='.$var['id'];
						}
						$string=curl_post($requesturl);
						$retwhite=fwritetext($htmlfilepath,$string);
						if($retwhite){
							$ret=true;
						}
					 }
				}else{
					$string=curl_post($web_url);
					$htmlfilepath=YUNYECMS_ROOT.'index.html';
					$ret=fwritetext($htmlfilepath,$string);
				}
				 if($ret){
					 return array('code'=>100,'status'=>true,'desc'=>'成功刷新首页HTML文件！');
				  }else{
					 return array('code'=>403,'status'=>false,'desc'=>'语言版信息错误！');
				  }
			}
		}else{
			 return array('code'=>400,'status'=>false,'desc'=>'语言版信息不存在！');
		}
		
	 }
	
	/**
	* 获取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();;
	}	
	
	
	
}