<?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 CsdjSinger extends CI_Model
{
    function __construct (){
	       parent:: __construct ();
    }

    //主页
    public function index($data='') {
           $this->load->get_templates();
		   $template=$this->load->view('singer-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='singer-list.html';
           }else{
                 $CS_Template=$row[0]->CS_Template;
           }

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

           //SEO标题
           $seo_title=$row[0]->CS_Name." - ".Web_Name;
           $seo_keywords=$row[0]->CS_Name.",".$row[0]->CS_Name."视听,".$row[0]->CS_Name."下载";
           $seo_description=$row[0]->CS_Name." 是由".Web_Name."提供视听和下载。";

		   $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("[singer:classid]",$row[0]->CS_ID,$Mark_Text);
		   $Mark_Text=str_replace("[singer:sort]",$fid,$Mark_Text);

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

			   $sqlstr=$this->CsdjSkins->Mark_Sql('singer',$page_arr[1][0],$id,$fid);
			   $Arr=$this->CsdjSkins->SpanPage($sqlstr,$page_arr[2][0],$pagenum,'lists','singer',$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->DataSinger($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("[singer:classname]",$row[0]->CS_Name,$Mark_Text);
		   $Mark_Text=str_replace("[singer:classlink]",$this->CsdjSkins->LinkUrl('lists','singer','id',$row[0]->CS_ID),$Mark_Text);
		   $Mark_Text=str_replace("[singer:classhlink]",$this->CsdjSkins->LinkUrl('lists','singer','hits',$row[0]->CS_ID),$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,$page,$row) {
		   $data='';$data_content='';
           if(empty($row[0]->CS_Template)){
                 $CS_Template='singer-show.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."介绍";
           }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=str_replace("[singer:sort]",$fid,$Mark_Text);
		   $Mark_Text=str_replace("[singer:counts]",$this->CsdjSkins->getsingercount($row[0]->CS_ID),$Mark_Text);

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

               $sqlstr=$this->CsdjSkins->Mark_Sql('dance',$page_arr[1][0],$id,$fid);
			   $Arr=$this->CsdjSkins->SpanPage($sqlstr,$page_arr[2][0],$pagenum,'show','singer',$fid,$id,$id,$page);//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->DataDance($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);

           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."','singer');</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('[singer:hits]',"<script src=".site_url('singer/hits/dt/hits/'.$id)."></script>",$Mark_Text);
           }
           $Mark_Text=$this->CsdjSkins->DataSinger($Mark_Text,$Mark_Text,$row[0],'1'); //全部解析
		   $Mark_Text.="<script src=".site_url('singer/hits/id/'.$id)."></script>";//增加人气
           $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;
	}
}

