<?php
/**
 * @Cscms 3.5 open source management system
 * @copyright 2009-2013 chshcms.com. All rights reserved.
 * @Author:Cheng Jie
 * @Dtime:2015-02-8
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class CsdjVod extends CI_Model
{
    function __construct (){
	       parent:: __construct ();
    }

    //主页
    public function index($data='') {
           $this->load->get_templates();
		   $template=$this->load->view('vod-index.html',$data,true);
		   $Mark_Text=str_replace("{cscms:title}","视频首页 - ".Web_Name,$template);
           $Mark_Text=$this->CsdjSkins->skins($Mark_Text,$data,true);
		   if (defined('IS_ADMIN')) {
		       $Mark_Text=str_replace(SELF,"index.php",$Mark_Text);
		   }
		   return $Mark_Text;
    }

    //列表
    public function lists($fid,$id,$page,$row,$aliasname='') {
		   $data='';$data_content='';


           if(empty($row[0]->CS_Template)){
                 $CS_Template='vod-list.html';
		   }else{
                 $CS_Template=$row[0]->CS_Template;
           }

           $this->load->get_templates();
		   $template=$this->load->view($CS_Template,$data,true);

           //SEO标题
           if (empty($row[0]->CS_Title)){
               		$seo_title=$row[0]->CS_Name." - ".Web_Name;
           }else{
               		$seo_title=$row[0]->CS_Title;
           }
           //SEO关键词
           if (empty($row[0]->CS_Keywords)){
               		$seo_keywords=$row[0]->CS_Name.",".$row[0]->CS_Name."视听,".$row[0]->CS_Name."下载";
           }else{
              		$seo_keywords=$row[0]->CS_Keywords;
           }
           //SEO描述
           if (empty($row[0]->CS_Description)){
               		$seo_description=$row[0]->CS_Name." 是由".Web_Name."提供视听和下载。";
           }else{
               		$seo_description=$row[0]->CS_Description;
           }
		   $Mark_Text=$this->CsdjSkins->TopandBottom($template);
		   $Mark_Text=str_replace("{cscms:title}",$seo_title,$Mark_Text);
		   $Mark_Text=str_replace("{cscms:keywords}",$seo_keywords,$Mark_Text);
		   $Mark_Text=str_replace("{cscms:description}",$seo_description,$Mark_Text);
		   $Mark_Text=str_replace("[vod:sort]",$fid,$Mark_Text);
		   $Mark_Text=str_replace("[vod:classid]",$row[0]->CS_ID,$Mark_Text);

		   //预先除了分页
		   $pagenum=$this->CsdjSkins->GetPageNum($Mark_Text);
		   preg_match_all('/{cscms:vod(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/cscms:vod}/',$Mark_Text,$page_arr);//判断是否有分页标识
		   if(!empty($page_arr) && !empty($page_arr[2])){

			   $sqlstr=$this->CsdjSkins->Mark_Sql('vod',$page_arr[1][0],$id,$fid);
			   $Arr=$this->CsdjSkins->SpanPage($sqlstr,$page_arr[2][0],$pagenum,'lists','vod',$fid,$row[0]->CS_ID,1,$page,$aliasname);//sql,每页显示条数
			   $result=$this->CsdjDB->db->query($Arr[2]);
			   $recount=$result->num_rows();
			   if($recount==0){
				   $data_content="<div align=center><strong><font style=font-size:12px;>该分类暂无视频！</font></strong></div>";
			   }else{
				   if($result){
					   $sorti=1;
					   foreach ($result->result() as $row2) {
						   $datatmp=$this->CsdjSkins->DataVod($page_arr[0][0],$page_arr[3][0],$row2,$sorti);
						   $sorti=$sorti+1;
						   $data_content.=$datatmp;
					   }
				   }
			   }// end if recount
			   $Mark_Text=$this->CsdjSkins->Page_Mark($Mark_Text,$Arr);	
			   $Mark_Text=str_replace($page_arr[0][0],$data_content,$Mark_Text);
			   unset($Arr);
		   }
		   unset($page_arr);
		   $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$id);
		   $Mark_Text=str_replace("[vod:classlink]",$this->CsdjSkins->LinkUrl('lists','vod','id',$row[0]->CS_ID),$Mark_Text);
		   $Mark_Text=str_replace("[vod:classhlink]",$this->CsdjSkins->LinkUrl('lists','vod','hits',$row[0]->CS_ID),$Mark_Text);
		   $Mark_Text=str_replace("[vod:classtlink]",$this->CsdjSkins->LinkUrl('lists','vod','reco',$row[0]->CS_ID),$Mark_Text);
		   $Mark_Text=str_replace("[vod:classylink]",$this->CsdjSkins->LinkUrl('lists','vod','yue',$row[0]->CS_ID),$Mark_Text);
		   $Mark_Text=str_replace("[vod:classzlink]",$this->CsdjSkins->LinkUrl('lists','vod','zhou',$row[0]->CS_ID),$Mark_Text);
		   $Mark_Text=str_replace("[vod:classrlink]",$this->CsdjSkins->LinkUrl('lists','vod','ri',$row[0]->CS_ID),$Mark_Text);
		   $Mark_Text=str_replace("[vod:classdlink]",$this->CsdjSkins->LinkUrl('lists','vod','ding',$row[0]->CS_ID),$Mark_Text);
		   $Mark_Text=str_replace("[vod:classname]",$row[0]->CS_Name,$Mark_Text);
           $Mark_Text=$this->CsdjSkins->skins($Mark_Text,$data,true);
		   if (defined('IS_ADMIN')) {
		       $Mark_Text=str_replace(SELF,"index.php",$Mark_Text);
		   }
		   return $Mark_Text;
    }

    //内容页
    public function show($fid,$id,$row) {
		   $data='';$data_content='';

           if(empty($row[0]->CS_Template2)){
                 $CS_Template='vod-show.html';
           }else{
                 $CS_Template=$row[0]->CS_Template2;
           }

           $this->load->get_templates();
		   $template=$this->load->view($CS_Template,$data,true);

           //SEO标题
           if (empty($row[0]->CS_Title)){
               		$seo_title=$row[0]->CS_Name." - ".Web_Name;
           }else{
               		$seo_title=$row[0]->CS_Title;
           }
           //SEO关键词
           if (empty($row[0]->CS_Keywords)){
               		$seo_keywords=$row[0]->CS_Name.",".$row[0]->CS_Name."介绍";
           }else{
              		$seo_keywords=$row[0]->CS_Keywords;
           }
           //SEO描述
           if (empty($row[0]->CS_Description)){
               		$seo_description=$row[0]->CS_Name." 是由".Web_Name."提供观看和下载。";
           }else{
               		$seo_description=$row[0]->CS_Description;
           }

		   $Mark_Text=str_replace("{cscms:title}",$seo_title,$template);
		   $Mark_Text=str_replace("{cscms:keywords}",$seo_keywords,$Mark_Text);
		   $Mark_Text=str_replace("{cscms:description}",$seo_description,$Mark_Text);

		   $Mark_Text=$this->CsdjSkins->Vod_Playlist($Mark_Text,$id,$row[0]->CS_Laiy,$row[0]->CS_PlayUrl);
		   $Mark_Text=$this->CsdjSkins->Common_Mark($Mark_Text,$row[0]->CS_CID);

		   //上下部开始
		   if (stripos($Mark_Text, '[dance:slink]')) {
		        $sqlu="Select CS_ID,CS_Name,CS_CID from ".CS_SqlPrefix."dance where CS_YID=0 order by cs_id>=$id, cs_id desc limit 1";
		        $rowu=$this->CsdjDB->get_all($sqlu);
		        if($rowu){
		            $Mark_Text=str_replace('[dance:sid]',$rowu[0]->CS_ID,$Mark_Text);
		            $Mark_Text=str_replace('[dance:sname]',$rowu[0]->CS_Name,$Mark_Text);
		            $Mark_Text=str_replace('[dance:slink]',$this->CsdjSkins->LinkUrl('play','dance','id',$rowu[0]->CS_CID,$rowu[0]->CS_ID),$Mark_Text);
		        }else{
		            $Mark_Text=str_replace('[dance:sid]','0',$Mark_Text);
		            $Mark_Text=str_replace('[dance:sname]','没有了',$Mark_Text);
		            $Mark_Text=str_replace('[dance:slink]','#',$Mark_Text);
		        }
		   }

		   if (stripos($Mark_Text, '[dance:xlink]')) {
		        $sqld="Select CS_ID,CS_Name,CS_CID from ".CS_SqlPrefix."dance where CS_YID=0 order by cs_id<=$id, cs_id asc limit 1";
		        $rowd=$this->CsdjDB->get_all($sqld);
		        if($rowd){
		            $Mark_Text=str_replace('[dance:xid]',$rowd[0]->CS_ID,$Mark_Text);
		            $Mark_Text=str_replace('[dance:xname]',$rowd[0]->CS_Name,$Mark_Text);
		            $Mark_Text=str_replace('[dance:xlink]',$this->CsdjSkins->LinkUrl('play','dance','id',$rowd[0]->CS_CID,$rowd[0]->CS_ID),$Mark_Text);
		        }else{
		            $Mark_Text=str_replace('[dance:xid]','0',$Mark_Text);
		            $Mark_Text=str_replace('[dance:xname]','没有了',$Mark_Text);
		            $Mark_Text=str_replace('[dance:xlink]','#',$Mark_Text);
		        }
		   }


           if(Pl_Modes==0){
			   $comment="<script language='javascript' src='".Web_Path."csdj/js/plajax.js'></script><script>var cs_sid='topic';var cs_did='".$id."';var cs_path='".Web_Path."';getpllist('1','".$id."','vod');</script><div id='cscms_pl'><div style='padding:5px;text-align:center;'><img src='".Web_Path."csdj/images/load.gif'/>&nbsp;&nbsp;评论载入中，请稍候.....</div></div>";
		   }elseif(Pl_Modes==2){
			   $comment="<div style='padding:5px;text-align:center;'>&nbsp;&nbsp;评论已经被站长关闭!</div>";
		   }else{
			   $comment="<div id=\"uyan_frame\"></div><script type=\"text/javascript\" id=\"UYScript\" src=\"http://v1.uyan.cc/js/iframe.js?UYUserId=0\" async=\"\"></script>";
		   }
           //静态模式,动态人气
           if(Web_Mode==3){
			    $Mark_Text=str_replace('[vod:hits]',"<script src=".site_url('vod/hits/dt/hits/'.$id)."></script>",$Mark_Text);
           }
		   $Mark_Text=str_replace("[vod:pl]",$comment,$Mark_Text);
		   $Mark_Text=$this->CsdjSkins->DataVod($Mark_Text,$Mark_Text,$row[0],1);
           $Mark_Text=$this->CsdjSkins->skins($Mark_Text,$data,true);
		   if (defined('IS_ADMIN')) {
		       $Mark_Text=str_replace(SELF,"index.php",$Mark_Text);
		   }
		   return $Mark_Text;
	}
}

