<?php
class CreateAction extends BaseAction{
	//构造函数
    public function _initialize(){
	    parent::_initialize();
		$this->assign($this->Lable_Style());
		$this->assign("waitSecond",C('url_time'));
    }
	//组合需要生成的资讯列表并缓存
    public function newslist(){
		$this->list_cache_array(2);
	}
	//生成资讯列表从缓存任务列表
    public function newslist_create(){
		$this->list_create_array(2);
	}
	//组合需要生成的招聘列表并缓存
    public function zhaopinlist(){
		$this->list_cache_array(10);
	}
	//生成招聘列表从缓存任务列表
    public function zhaopinlist_create(){
		$this->list_create_array(10);
	}
	//组合需要生成的产品列表并缓存
    public function chanpinlist(){
		$this->list_cache_array(1);
	}
	//生成产品列表从缓存任务列表
    public function chanpinlist_create(){
		$this->list_create_array(1);
	}
	//缓存产品/资讯列表列表路径为数组
	public function list_cache_array($sid=1){
		$jump = intval($_REQUEST['jump']);
		$this->check(C('url_html_list'),getsidname($sid).'列表页','?s=Admin-Create-Index-jump-'.$jump);
		$array_list = F('_GxlcmsQY/list');
		$array_listids = explode(',',$_REQUEST['ids_list_'.$sid]);
		$k = 0;
		foreach($array_listids as $key=>$value){
			$list = list_search($array_list,'list_id='.$value);
			if($list[0]["list_limit"]){
				$totalpages = ceil(getcount($value)/$list[0]["list_limit"]);
			}else{
				$totalpages = 1;
			}
			for($page = 1; $page <= $totalpages; $page++){
				$array[$k]['id'] = $value;
				$array[$k]['page'] = $page;
				$k++;
			}
		}
		F('_create/list',$array);
		if($sid == 1){
			$this->chanpinlist_create();
		}elseif($sid == 10){
			$this->zhaopinlist_create();
		}else{
			$this->newslist_create();
		}
	}
	//生成产品/资讯列表列表从缓存数组(分页生成)
    public function list_create_array($sid){
		$List = F('_GxlcmsQY/list');
		$Url = F('_create/list');
		$key = intval($_REQUEST['key']);
		$jump = intval($_REQUEST['jump']);
		if($sid==1){
			$nextcreate = '?s=Admin-Create-Chanpinlist_create-jump-'.$jump.'-key-'.$key;
			$sidname = '产品';
		}elseif($sid==10){
			$nextcreate = '?s=Admin-Create-zhaopinlist_create-jump-'.$jump.'-key-'.$key;
			$sidname = '招聘';
		}else{
			$nextcreate = '?s=Admin-Create-Newslist_create-jump-'.$jump.'-key-'.$key;
			$sidname = '新闻';
		}
		//断点生成(写入缓存)
		F('_create/nextcreate',$nextcreate);
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体">';
		echo'<li>总共需要生成<font color=blue>'.count($Url).'</font>个'.$sidname.'列表页，每页生成'.C('url_number').'个。</li>';
		for($i=1;$i<=C('url_number');$i++){
			if(!$Url[$key]){
				break;
			}
			//变量赋值
			C('jumpurl',ff_list_url(getsidname($sid),array('id'=>$Url[$key]['id'],'p'=>'{!page!}'),9999));
			C('currentpage',$Url[$key]['page']);
			$channel = list_search($List,'list_id='.$Url[$key]['id']);
			if($sid == 1){
				$channel = $this->Lable_Chanpin_List(array('id'=>$Url[$key]['id'],'page'=>$Url[$key]['page'],'order'=>'addtime'),$channel[0]);
			}elseif($sid == 10){
				$channel = $this->Lable_zhaopin_List(array('id'=>$Url[$key]['id'],'page'=>$Url[$key]['page'],'order'=>'addtime'),$channel[0]);
			}else{
				$channel = $this->Lable_News_List(array('id'=>$Url[$key]['id'],'page'=>$Url[$key]['page'],'order'=>'addtime'),$channel[0]);
			}
			$this->assign($channel);
			//目录路径并生成
			$listdir = str_replace('{!page!}',$Url[$key]['page'],ff_list_url_dir(getsidname($sid),$Url[$key]['id'],$Url[$key]['page']));
			$this->buildHtml($listdir,'./','Home:'.$channel['list_skin']);	
			//预览路径
			$showurl = C('sitepath').$listdir.C('html_file_suffix');
			echo'<li>第<font color=red>'.($key+1).'</font>个生成完毕　<a href="'.$showurl.'" target="_blank">'.$showurl.'</a></li>';
			ob_flush();flush();
			$key++;
		}
		echo'</ul>';
		if($key < count($Url)){
			if($sid==1){
				$nextcreate = '?s=Admin-Create-Chanpinlist_create-jump-'.$jump.'-key-'.$key;
			}if($sid==10){
				$nextcreate = '?s=Admin-Create-zhaopinlist_create-jump-'.$jump.'-key-'.$key;
			}else{
				$nextcreate = '?s=Admin-Create-Newslist_create-jump-'.$jump.'-key-'.$key;
			}		
			$this->jump($nextcreate,'让服务器休息一会，生成任务等待中...');
		}
		F('_create/list',NULL);
		if($jump){
			$this->jump('?s=Admin-Create-Index-jump-'.$jump,'列表页已经全部生成，下次将生成网站首页。');
		}
		F('_create/nextcreate',NULL);
		$this->jump('?s=Admin-Create-Show','恭喜您，列表页已经全部生成！');
	}
	//读取资讯内容按分类
	public function newsclass(){
		$jump = intval($_REQUEST['jump']);
		$ids = trim($_REQUEST['ids_2']);
		$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
		//检测是否需要生成
		$this->check(C('url_html'),'资讯内容页','?s=Admin-Create-Newslist-ids_2-'.$ids.'-jump-'.$jump);
		//断点生成(写入缓存)
		F('_create/nextcreate','?s=Admin-Create-Chanpinclass-ids_2-'.$ids.'-jump-'.$jump.'-page-'.$page);
		//查询数据开始	
		$rs = D("News");
		$where['news_status'] = array('eq',1);
		$where['news_cid'] = array('in',$ids);
		$count = $rs->where($where)->count('news_id');
		$totalpages = ceil($count/C('url_number'));
		$array = $rs->where($where)->order('news_addtime desc')->limit(C('url_number'))->page($page)->relation('Tag')->select();
		if (empty($array)) {
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
			$this->error('当前分类没有数据，暂不需要生成！');
		}
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体">';
		echo'<li>总共需要生成<font color=blue>'.$count.'</font>个资讯内容页，需要分<font color=blue>'.$totalpages.'</font>次来执行，正在执行第<font color=red>'.$page.'</font>次</li>';
		foreach($array as $key=>$value){
			$this->news_read_create($value);
		}
		echo'</ul>';
		//组合回跳URL路径与执行跳转
		$jumpurl = '?s=Admin-Create-Show';
		if($page < $totalpages){
			$jumpurl = '?s=Admin-Create-Newsclass-ids_2-'.$ids.'-jump-'.$jump.'-page-'.($page+1);
		}else{
			if($jump){
				$jumpurl = '?s=Admin-Create-Newslist-ids_list_2-'.$ids.'-jump-'.$jump;
			}
		}
		if($page < $totalpages){
			$this->jump($jumpurl,'稍等一会，准备生成下一次资讯内容页...');
		}	
		F('_create/nextcreate',NULL);
		$this->jump($jumpurl,'恭喜您，资讯内容页全部生成完毕。');
	}
	//读取资讯内容按时间
	public function newsday(){
		$jump = intval($_REQUEST['jump']);
		$this->check(C('url_html'),'资讯内容页');
		//查询数据开始
		$rs = D("News");
		$mday = intval($_REQUEST['mday_2']);
		$min = intval($_REQUEST['min']);
		$where['news_status'] = array('eq',1);
		$where['news_cid'] = array('gt',0);
		if($min){//生成多少分钟内的产品
			$where['news_addtime'] = array('gt',time()-$min*60);
		}else{
			$where['news_addtime'] = array('gt',getxtime($mday));
		}
		//
		$count = $rs->where($where)->count('news_id');
		$totalpages = ceil($count/C('url_number'));
		$page = !empty($_GET['page'])?intval($_GET['page']):1;
		$array = $rs->where($where)->order('news_addtime desc')->limit(C('url_number'))->page($page)->relation('Tag')->select();
		if (empty($array )) {
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
			$this->error('今日没有数据更新,暂不需要生成！');
		}
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体">';
		echo'<li>总共需要生成<font color=blue>'.$count.'</font>个资讯内容页，需要分<font color=blue>'.$totalpages.'</font>次来执行，正在执行第<font color=red>'.$page.'</font>次</li>';
		foreach($array as $key=>$value){
			$this->news_read_create($value);
		}
		echo'</ul>';
		//组合回跳URL路径与执行跳转
		$jumpurl = '?s=Admin-Create-Show';
		if ($page < $totalpages) {
			$jumpurl = '?s=Admin-Create-Newsday-jump-'.$jump.'-mday_2-'.$mday.'-min-'.$mid.'-page-'.($page+1);
		}else{
			if($jump){
				$listarr = F('_GxlcmsQY/list');
				foreach($listarr as $key=>$value){
					$keynew = $value['list_sid'];
					$list[$keynew][$key] = $value['list_id'];
				}
				$ids = implode(',',$list[1]);
				$jumpurl = '?s=Admin-Create-Newslist-jump-1-ids_list_2-'.$ids;			
			}
		}
		if ($page < $totalpages) {
			$this->jump($jumpurl,'第('.$page.')页已经生成完毕，正在准备下一个。');
		}
		F('_create/nextcreate',NULL);
		$this->jump($jumpurl,'恭喜您，生成完毕。');
	}
	//读取资讯内容按ID
	public function newsid(){
		$where = array();
		$rs = D("News");
		$where['news_id'] = array('in',$_REQUEST["id"]);
		$where['news_status'] = 1;
		$where['news_cid'] = array('gt',0);
		$array = $rs->where($where)->relation('Tag')->select();
		foreach($array as $value){
			$this->news_read_create($value);
		}
	}		
	//生成资讯内容页
    public function news_read_create($array){
		$arrays = $this->Lable_News_Read($array);
		$this->assign($arrays['show']);
		$this->assign($arrays['read']);
		$newsdir = ff_data_url_dir('news',$arrays['read']['news_id'],$arrays['read']['news_cid'],$arrays['read']['news_name'],1);
		$this->buildHtml($newsdir,'./',$arrays['read']['news_skin_detail']);
		$newsurl = C('site_path').$newsdir.C('html_file_suffix');
		echo '<li>'.$arrays['read']['news_id'].' <a href="'.$newsurl.'" target="_blank">'.$newsurl.'</a> 生成完毕</li>';
		ob_flush();flush();
    }
	public function zhaopinclass(){
		$jump = intval($_REQUEST['jump']);
		$ids = trim($_REQUEST['ids_2']);
		$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
		//检测是否需要生成
		$this->check(C('url_html'),'招聘内容页','?s=Admin-Create-Zhaopinlist-ids_2-'.$ids.'-jump-'.$jump);
		//断点生成(写入缓存)
		F('_create/nextcreate','?s=Admin-Create-Chanpinclass-ids_2-'.$ids.'-jump-'.$jump.'-page-'.$page);
		//查询数据开始	
		$rs = D("Zhaopin");
		$where['zhaopin_status'] = array('eq',1);
		$where['zhaopin_cid'] = array('in',$ids);
		$count = $rs->where($where)->count('zhaopin_id');
		$totalpages = ceil($count/C('url_number'));
		$array = $rs->where($where)->order('zhaopin_addtime desc')->limit(C('url_number'))->page($page)->relation('Tag')->select();
		if (empty($array)) {
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
			$this->error('当前分类没有数据，暂不需要生成！');
		}
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体">';
		echo'<li>总共需要生成<font color=blue>'.$count.'</font>个招聘内容页，需要分<font color=blue>'.$totalpages.'</font>次来执行，正在执行第<font color=red>'.$page.'</font>次</li>';
		foreach($array as $key=>$value){
			$this->zhaopin_read_create($value);
		}
		echo'</ul>';
		//组合回跳URL路径与执行跳转
		$jumpurl = '?s=Admin-Create-Show';
		if($page < $totalpages){
			$jumpurl = '?s=Admin-Create-Zhaopinclass-ids_2-'.$ids.'-jump-'.$jump.'-page-'.($page+1);
		}else{
			if($jump){
				$jumpurl = '?s=Admin-Create-Zhaopinlist-ids_list_2-'.$ids.'-jump-'.$jump;
			}
		}
		if($page < $totalpages){
			$this->jump($jumpurl,'稍等一会，准备生成下一次招聘内容页...');
		}	
		F('_create/nextcreate',NULL);
		$this->jump($jumpurl,'恭喜您，招聘内容页全部生成完毕。');
	}
	//读取招聘内容按时间
	public function zhaopinday(){
		$jump = intval($_REQUEST['jump']);
		$this->check(C('url_html'),'招聘内容页');
		//查询数据开始
		$rs = D("Zhaopin");
		$mday = intval($_REQUEST['mday_2']);
		$min = intval($_REQUEST['min']);
		$where['zhaopin_status'] = array('eq',1);
		$where['zhaopin_cid'] = array('gt',0);
		if($min){//生成多少分钟内的产品
			$where['zhaopin_addtime'] = array('gt',time()-$min*60);
		}else{
			$where['zhaopin_addtime'] = array('gt',getxtime($mday));
		}
		//
		$count = $rs->where($where)->count('zhaopin_id');
		$totalpages = ceil($count/C('url_number'));
		$page = !empty($_GET['page'])?intval($_GET['page']):1;
		$array = $rs->where($where)->order('zhaopin_addtime desc')->limit(C('url_number'))->page($page)->relation('Tag')->select();
		if (empty($array )) {
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
			$this->error('今日没有数据更新,暂不需要生成！');
		}
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体">';
		echo'<li>总共需要生成<font color=blue>'.$count.'</font>个招聘内容页，需要分<font color=blue>'.$totalpages.'</font>次来执行，正在执行第<font color=red>'.$page.'</font>次</li>';
		foreach($array as $key=>$value){
			$this->zhaopin_read_create($value);
		}
		echo'</ul>';
		//组合回跳URL路径与执行跳转
		$jumpurl = '?s=Admin-Create-Show';
		if ($page < $totalpages) {
			$jumpurl = '?s=Admin-Create-Zhaopinday-jump-'.$jump.'-mday_2-'.$mday.'-min-'.$mid.'-page-'.($page+1);
		}else{
			if($jump){
				$listarr = F('_GxlcmsQY/list');
				foreach($listarr as $key=>$value){
					$keynew = $value['list_sid'];
					$list[$keynew][$key] = $value['list_id'];
				}
				$ids = implode(',',$list[1]);
				$jumpurl = '?s=Admin-Create-Zhaopinlist-jump-1-ids_list_2-'.$ids;			
			}
		}
		if ($page < $totalpages) {
			$this->jump($jumpurl,'第('.$page.')页已经生成完毕，正在准备下一个。');
		}
		F('_create/nextcreate',NULL);
		$this->jump($jumpurl,'恭喜您，生成完毕。');
	}
	//读取招聘内容按ID
	public function zhaopinid(){
		$where = array();
		$rs = D("Zhaopin");
		$where['zhaopin_id'] = array('in',$_REQUEST["id"]);
		$where['zhaopin_status'] = 1;
		$where['zhaopin_cid'] = array('gt',0);
		$array = $rs->where($where)->relation('Tag')->select();
		foreach($array as $value){
			$this->zhaopin_read_create($value);
		}
	}		
	//生成招聘内容页
    public function zhaopin_read_create($array){
		$arrays = $this->Lable_Zhaopin_Read($array);
		$this->assign($arrays['show']);
		$this->assign($arrays['read']);
		$zhaopindir = ff_data_url_dir('zhaopin',$arrays['read']['zhaopin_id'],$arrays['read']['zhaopin_cid'],$arrays['read']['zhaopin_name'],1);
		$this->buildHtml($zhaopindir,'./',$arrays['read']['zhaopin_skin_detail']);
		$zhaopinurl = C('site_path').$zhaopindir.C('html_file_suffix');
		echo '<li>'.$arrays['read']['zhaopin_id'].' <a href="'.$zhaopinurl.'" target="_blank">'.$zhaopinurl.'</a> 生成完毕</li>';
		ob_flush();flush();
    }
	//读取产品内容按分类
	public function chanpinclass(){
		$jump = intval($_REQUEST['jump']);
		$ids = trim($_REQUEST['ids_1']);
		$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
		$this->check(C('url_html'),'产品内容页','?s=Admin-Create-Chanpinlist-ids_1-'.$ids.'-jump-'.$jump);
		//断点生成(写入缓存)
		F('_create/nextcreate','?s=Admin-Create-Chanpinclass-ids_1-'.$ids.'-jump-'.$jump.'-page-'.$page);	
		$rs = D("Chanpin");
		$where['chanpin_status'] = array('eq',1);
		$where['chanpin_cid'] = array('in',$ids);
		$count = $rs->where($where)->count('chanpin_id');
		$totalpages = ceil($count/C('url_number'));
		$array = $rs->where($where)->order('chanpin_addtime desc')->limit(C('url_number'))->page($page)->relation('Tag')->select();
		if (empty($array)) {
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
			$this->error('当前分类没有数据，暂不需要生成！');
		}	
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体"><li>总共需要生成<font color=blue>'.$count.'</font>个产品内容页，需要分<font color=blue>'.$totalpages.'</font>次来执行，正在执行第<font color=blue>'.$page.'</font>次</li>';
		foreach($array as $key=>$value){
			$this->chanpin_read_create($value);
		}
		echo'</ul>';
		//组合回跳URL路径与执行跳转
		$jumpurl = '?s=Admin-Create-Show';
		if($page < $totalpages){
			$jumpurl = '?s=Admin-Create-Chanpinclass-ids_1-'.$ids.'-jump-'.$jump.'-page-'.($page+1);
		}else{
			if($jump){
				$jumpurl = '?s=Admin-Create-Chanpinlist-ids_list_1-'.$ids.'-jump-'.$jump;
			}
		}
		if($page < $totalpages){
			$this->jump($jumpurl,'稍等一会，准备生成下一次产品内容页...');
		}
		F('_create/nextcreate',NULL);
		$this->jump($jumpurl,'恭喜您，产品内容页全部生成完毕。');
	}
	//读取产品内容按时间
	public function chanpinday(){
		$jump = intval($_REQUEST['jump']);
		$this->check(C('url_html'),'产品内容页');
		$rs = D("Chanpin");
		$mday = intval($_REQUEST['mday_1']);
		$min = intval($_REQUEST['min']);
		$where['chanpin_status'] = array('eq',1);
		$where['chanpin_cid'] = array('gt',0);
		//
		if($min){//生成多少分钟内的产品
			$where['chanpin_addtime'] = array('gt',time()-$min*60);
		}else{
			$where['chanpin_addtime'] = array('gt',getxtime($mday));
		}
		//
		$count = $rs->where($where)->count('chanpin_id');
		$totalpages = ceil($count/C('url_number'));
		$page = !empty($_GET['page'])?intval($_GET['page']):1;
		$array = $rs->where($where)->order('chanpin_addtime desc')->limit(C('url_number'))->page($page)->relation('Tag')->select();
		if (empty($array )) {
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
			$this->error('今日没有数据更新,暂不需要生成！');
		}
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体"><li>总共需要生成<font color=blue>'.$count.'</font>个产品内容页，需要分<font color=blue>'.$totalpages.'</font>次来执行，正在执行第<font color=blue>'.$page.'</font>次</li>';
		foreach($array as $key=>$value){
			$this->chanpin_read_create($value);
		}
		echo'</ul>';
		if ($page < $totalpages) {
			$jumpurl = '?s=Admin-Create-Chanpinday-jump-'.$jump.'-mday_1-'.$mday.'-min-'.$mid.'-page-'.($page+1);
		}else{
			if($jump){
				$listarr = F('_GxlcmsQY/list');
				foreach($listarr as $key=>$value){
					$keynew = $value['list_sid'];
					$list[$keynew][$key] = $value['list_id'];
				}
				$ids = implode(',',$list[1]);
				$jumpurl = '?s=Admin-Create-Chanpinlist-jump-1-ids_list_1-'.$ids;			
			}else{
				$jumpurl = '?s=Admin-Create-Show';
			}
		}
		if ($page < $totalpages) {
			$this->jump($jumpurl,'第('.$page.')页已经生成完毕，正在准备下一个。');
		}
		F('_create/nextcreate',NULL);
		$this->jump($jumpurl,'恭喜您，生成完毕。');
	}
	//读取产品内容按ID
	public function chanpinid(){
		$where = array();
		$rs = D("Chanpin");
		$where['chanpin_id'] = array('in',$_REQUEST["id"]);
		$where['chanpin_cid'] = array('gt',0);
		$where['chanpin_status'] = 1;
		$array = $rs->where($where)->relation('Tag')->select();
		foreach($array as $value){
			$this->chanpin_read_create($value);
		}
	}
	//生成产品内容页
    public function chanpin_read_create($array){
		$arrays = $this->Lable_Chanpin_Read($array);
		$this->assign($arrays['show']);
		$this->assign($arrays['read']);
		//生成内容页
		$videodir = ff_data_url_dir('chanpin',$arrays['read']['chanpin_id'],$arrays['read']['chanpin_cid'],$arrays['read']['chanpin_name'],1);
		$this->buildHtml($videodir,'./',$arrays['read']['chanpin_skin_detail']);
		echo('<li><a href="'.C('site_path').$videodir.C('html_file_suffix').'" target="_blank">'.$arrays['read']['chanpin_id'].'</a> detail ok</li>');
		//生成播放页
		if(C('url_html')){
			$this->chanpin_play_create($arrays);
		}
		ob_flush();
		flush();
    }
	//生成播放页
	public function chanpin_play_create($arrays){
		//合集在一个页面
		if(C('url_html_play')==1){
			$this->assign($arrays['show']);
			$arrays['read'] = $this->Lable_Chanpin_Play($arrays['read'],array('id'=>$arrays['read']['chanpin_id'],'sid'=>0,'pid'=>1));
			$this->assign($arrays['read']);
			$playdir = ff_play_url_dir($arrays['read']['chanpin_id'],0,1,$arrays['read']['chanpin_cid'],$arrays['read']['chanpin_name']);
			$this->buildHtml($playdir,'./',$arrays['read']['chanpin_skin_play']);
			echo('<li>'.$arrays['read']['chanpin_id'].' play ok</li>');
		}elseif(C('url_html_play')==2){
			echo('<li>'.$arrays['read']['chanpin_id'].' play ');
			//生成播放地址js(只需要一次)
			$player_dir = ff_play_url_dir($arrays['read']['chanpin_id'],0,1,$arrays['read']['chanpin_cid'],$arrays['read']['chanpin_name']);
			write_file('./'.$player_dir.'.js',$arrays['read']['chanpin_player']);
			//播放页模板通用变量解析
			$this->assign($arrays['show']);
			//第一个分集生成完后
			foreach($arrays['read']['chanpin_playlist'] as $sid=>$son){
				$arr_sid = explode('-',$sid);
				$arr_play = array();
				foreach($son["son"] as $pid=>$value){
					//路径替换与生成
					$player_dir_ji = preg_replace('/play-([0-9]+)-([0-9]+)-([0-9]+)/i','play-$1-'.$arr_sid[1].'-'.($pid+1).'',$player_dir);
					$this->assign($this->Lable_Chanpin_Play($arrays['read'],array('id'=>$arrays['read']['chanpin_id'],'sid'=>$arr_sid[1],'pid'=>$pid+1),true));
					$this->buildHtml($player_dir_ji,'./',$arrays['read']['chanpin_skin_play']);
					//echo($arr_sid[1].'-'.($pid+1).' ');
				}
				echo('ok </li>');
			}			
		}
	}
	//一键生成全站地图
    public function maps(){
		$this->check(C('url_html'),'网站地图');
		$this->google(true);
		$this->baidu(true);
		$this->rss(true);
		$this->assign("jumpUrl",'?s=Admin-Create-Show');
		$this->success('恭喜您，所有地图生成完毕！');	
	}
	//生成Baidu地图
    public function baidu($id){
		$baiduall = !empty($_REQUEST['baiduall'])?intval($_REQUEST['baiduall']):10000;
		$baidu = !empty($_REQUEST['baidu'])?intval($_REQUEST['baidu']):2000;
		$page = ceil(intval($baiduall)/intval($baidu));
		for($i=1;$i<=$page;$i++){
			$this->map_create('baidu',$baidu,$i);
		}
		if (empty($id)) {
			$this->assign("waitSecond",5);
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
        	$this->success('Baidu Sitemap地图生成成功！<br />请通过<a href="http://sitemap.baidu.com" target="_blank">百度站长平台</a>提交！');			
		}			    
    }
	//生成Google地图
    public function google($id){
		$googleall = !empty($_REQUEST['googleall'])?intval($_REQUEST['googleall']):5000;
		$google = !empty($_REQUEST['google'])?intval($_REQUEST['google']):1000;
		$page = ceil(intval($googleall)/intval($google));
		for($i=1;$i<=$page;$i++){
			$this->map_create('google',$google,$i);
		}
		if (empty($id)) {
			$this->assign("waitSecond",5);
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
        	$this->success('Google Sitemap地图生成成功！<br />请通过<a href="http://www.google.com/webmasters/tools" target="_blank">谷歌站长工具</a>提交！');
		}
    }
	//生成Rss订阅
    public function rss($id){
		$rss = !empty($_REQUEST['rss'])?intval($_REQUEST['rss']):50;
		$this->map_create('rss',$rss,1);
		if (empty($id)) {
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
        	$this->success('Rss订阅文件生成成功！');
		}
    }
	//生成地图共用模块
    public function map_create($mapname,$limit,$page){
		$suffix = C('html_file_suffix');
		$listmap = $this->Lable_Maps($mapname,$limit,$page);
		if($listmap){
			$this->assign('list_map',$listmap);		
			C('html_file_suffix','.xml');
			if ($page == 1){
				$this->buildHtml($mapname,'./'.C('url_map'),'./Public/maps/'.$mapname.'.html');
			}else{
				$this->buildHtml($mapname.'-'.$page,'./'.C('url_map'),'./Public/maps/'.$mapname.'.html');
			}
			C('html_file_suffix',$suffix);
		}
    }
    //生成网站首页
    public function index(){
		$jump = intval($_GET['jump']);
		$this->check(C('url_html'),'网站首页');
		F('_create/nextcreate',NULL);
	    $this->assign($this->Lable_Index());
		$this->buildHtml("index",'./','Home:gxl_index');
		if ($jump) {
			$this->assign("jumpUrl",'?s=Admin-Create-Mytpl-jump-'.$jump);
			$this->success('首页生成完毕，准备生成自定义模板！');
		}else{
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
			$this->success('首页生成完毕。');		
		}
    }
    //生成自定义模板
    public function mytpl(){
		$suffix = C('html_file_suffix');
		$jump = intval($_GET['jump']);
		$this->check(C('url_html'),'自定义模板');
		import("ORG.Io.Dir");
		$dir = new Dir(TEMPLATE_PATH.'/Home');
		$list_dir = $dir->toArray();
		$array_tpl = array();
		foreach($list_dir as $key=>$value){
			if(ereg("my_(.*)\.html",$value['filename'])){
				C('html_file_suffix',$suffix);
				$this->buildHtml(str_replace(array('my_','.html'),'',$value['filename']),'./'.C('url_mytpl'),'Home:'.str_replace('.html','',$value['filename']));
			}
		}
		if ($jump) {
			$this->assign("jumpUrl",'?s=Admin-Create-Maps-jump-'.$jump);
			$this->success('自定义模板生成完毕，准备生成网站地图！');
		}else{
			$this->assign("jumpUrl",'?s=Admin-Create-Show');
			$this->success('恭喜您，自定义模板生成成功！');			
		}		
    }
	//生成专题列表
    public function speciallist(){
		//检测是否需要生成
		$this->check(C('url_html'),'专题列表页','?s=Admin-Create-Show');
		//查询数据开始	
		$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
		$limit = gettplnum('ff_mysql_special\(\'(.*)\'\)','gxl_speciallist');
		$rs = D("Special");
		$where['special_status'] = array('eq',1);
		$count = $rs->where($where)->count('special_id');
		$totalpages = ceil($count/$limit);
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体">';
		echo'<li>共有专题<font color=red>'.$count.'</font>篇，专题列表需要生成<font color=blue>'.$totalpages.'</font>页。</li>';
		for($i=1;$i<=$totalpages;$i++){
			//变量赋值
			C('jumpurl',ff_special_url(9999));
			C('currentpage',$i);
			$channel = $this->Lable_Special_List(array('page'=>$i));
			//生成文件		
			$htmldir = str_replace('{!page!}',$i,ff_special_url_dir($i));
			$htmlurl = C('sitepath').$htmldir.C('html_file_suffix');
			$this->buildHtml($htmldir,'./','Home:'.$channel['special_skin']);	
			echo'<li>第<font color=blue>'.$i.'</font>页生成完毕　<a href="'.$htmlurl.'" target="_blank">'.$htmlurl.'</a></li>';
			ob_flush();flush();			
		}
		echo'</ul>';
		exit();
		$this->jump('?s=Admin-Create-Show','恭喜您，专题列表页已经全部生成！');
	}
	//生成专题内容分页处理
    public function specialclass(){
		//检测是否需要生成
		$this->check(C('url_html'),'专题内容页','?s=Admin-Create-Show');
		//查询数据开始	
		$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
		$rs = D("Special");
		$where['special_status'] = array('eq',1);
		$count = $rs->where($where)->count('special_id');
		$totalpages = ceil($count/C('url_number'));
		$array = $rs->field('special_id')->where($where)->order('special_addtime desc')->limit(C('url_number'))->page($page)->select();
		if (empty($array)) {
			$this->assign("jumpUrl",'?s=Admin-Create-Show');$this->error('没有数据，不需要生成！');
		}
		echo'<ul id="show" style="font-size:12px;list-style:none;margin:0px;padding:0px;font-family:宋体">';
		echo'<li>总共需要生成<font color=blue>'.$count.'</font>个专题内容页，需要分<font color=blue>'.$totalpages.'</font>次来执行，正在执行第<font color=red>'.$page.'</font>次</li>';
		foreach($array as $key=>$value){
			$this->create_red_special($value['special_id']);
		}
		echo'</ul>';
		//组合回跳URL路径与执行跳转
		$jumpurl = '?s=Admin-Create-Show';
		if($page < $totalpages){
			$jumpurl = '?s=Admin-Create-Specialclass-page-'.($page+1);
			$this->jump($jumpurl,'稍等一会，准备生成下一次专题内容页...');
		}
		$this->jump($jumpurl,'恭喜您，专题内容页全部生成完毕。');		
	}
	//生成专题内容页
    public function create_red_special($specialid){
		$where = array();
		$where['special_id'] = $specialid;
		$where['special_status'] = array('eq',1);
		$rs = D("Special");
		$array_special = $rs->where($where)->find();
		if($array_special){
			$arrays = $this->Lable_Special_Read($array_special);
			$this->assign($arrays['read']);
			$this->assign('list_chanpin',$arrays['list_chanpin']);
			$this->assign('list_zhaopin',$arrays['list_zhaopin']);
			$this->assign('list_news',$arrays['list_news']);
			//
			$htmldir = ff_data_url_dir('special',$arrays['read']['special_id'],0,$arrays['read']['special_name'],1);
			$htmlurl = C('site_path').$htmldir.C('html_file_suffix');
			$this->buildHtml($htmldir,'./',$arrays['read']['special_skin']);
			echo '<li>'.$arrays['read']['special_id'].' <a href="'.$htmlurl.'" target="_blank">'.$htmlurl.'</a> 生成完毕</li>';
		}
	}	
	//显示生成
    public function show(){
		$array['url_html'] = C('url_html');
		if(C('url_html_list')){
			$array['url_html_list'] = C('url_html_list');
		}else{
			$array['url_html_list'] = 0;
		}
		$listarr = F('_GxlcmsQY/list');
		foreach($listarr as $key=>$value){
			$keynew = $value['list_sid'];
			$list[$keynew][$key] = $value['list_id'];
		}
		$this->assign($array);
		$this->assign('jumpurl',F('_create/nextcreate'));
		$this->assign('list_chanpin_all',implode(',',$list[1]));
		$this->assign('list_news_all',implode(',',$list[2]));
		$this->assign('list_zhaopin_all',implode(',',$list[10]));
	    $this->assign('list_chanpin',F('_GxlcmsQY/listchanpin'));
		$this->assign('list_zhaopin',F('_GxlcmsQY/listzhaopin'));
		$this->assign('list_news',F('_GxlcmsQY/listnews'));
        $this->display('./Public/system/html_show.html');
    }
	//判断生成条件
    public function check($html_status,$html_err,$jumpurl='?s=Admin-Create-Show'){	
	    if (!$html_status) {
		    $this->assign("jumpUrl",$jumpurl);
		    $this->error('"'.$html_err.'"模块动态运行，不需要生成静态网页！');
		}
	}
	//生成跳转
	public function jump($jumpurl,$html){
		echo '</div><script>if(document.getElementById("show")){document.getElementById("show").style.display="none";}</script>';
		$this->assign("waitSecond",C('url_time'));
		$this->assign("jumpUrl",$jumpurl);
		$this->success($html);
	}	
}
?>