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

 class CsdjUser extends CI_Model
 {
    function __construct (){
	       parent:: __construct ();
           $this->db->cache_off();
           if($this->session->userdata('cs_id')){
                //改变在线秒数
                $this->db->query("update ".CS_SqlPrefix."user set cs_logms='".time()."' where cs_zx=1 and cs_id='".intval($this->session->userdata('cs_id'))."'");

                $us=$this->db->query("SELECT cs_logo,cs_vip,cs_endtime FROM ".CS_SqlPrefix."user where cs_id='".$this->session->userdata('cs_id')."'")->row();
				//删除到期VIP
				$viptime=strtotime($us->cs_endtime);
                if($us->cs_vip>0 && $viptime<time()){
                      $this->db->query("update ".CS_SqlPrefix."user set cs_vip=0,cs_endtime='00-00-00 00:00:00' where cs_id='".intval($this->session->userdata('cs_id'))."'");
                }

                //判断强行上传头像
                if(strpos(@$_SERVER['REQUEST_URI'],'user/edit') === FALSE && User_Logo==1 && empty($us->cs_logo)){
                     if(strpos(@$_SERVER['REQUEST_URI'],'user/ulog') === FALSE && strpos(@$_SERVER['REQUEST_URI'],'/user') !== FALSE){
                        die("<script language='javascript'>alert('请先上传你的会员头像!');top.location='".Web_Path."index.php/user/edit/logo';</script>");
                     }
                }
           }
    }

    //检测登入
    function User_Login($cid=0,$key='') {
		  if(!empty($key)){
			  $str  = explode("-cscms-",sys_auth($key,'D'));
              $id   = intval($str[0]);
              $name = $str[1];
              $pass = $str[2];
		  }else{
              $id   = intval($this->session->userdata('cs_id'));
              $name = $this->session->userdata('cs_name');
              $pass = $this->session->userdata('cs_pass');
		  }
          $login= TRUE;

          if($id==0||empty($name)||empty($pass)){
              if($cid==0){
                    die("<script language='javascript'>window.parent.location='".site_url('user/login')."';</script>");
              }else{
                    $login=FALSE; 
              }  
          }else{
		$row=$this->db->query("SELECT CS_Pass FROM ".CS_SqlPrefix."user where cs_id='".$id."'")->row();
		if(!$row){
                    if($cid==0){
                           die("<script language='javascript'>window.parent.location='".site_url('user/login')."';</script>");
                    }else{
                           $login=FALSE; 
                    }
                }else{
		    if(md5($row->CS_Pass)!=$pass){
                          if($cid==0){
                                 die("<script language='javascript'>window.parent.location='".site_url('user/login')."';</script>");
                          }else{
                                 $login=FALSE; 
                          }
                    }
                }
          }
          return $login;
    }

        //主标签替换
	function getuser($Mark_Text,$row)
	{
          if(empty($row)){

		return $Mark_Text;
          }else{
                $CS_Wypay=( ! defined('CS_Wypay'))?'0':CS_Wypay;
		$Mark_Text=str_replace("[user:musicup]",User_DjMode,$Mark_Text); //上传歌曲方法,1站内,2官方网盘,3威盘,0关闭
		$Mark_Text=str_replace("[user:alipayfun]",CS_Alipay,$Mark_Text); //支付宝开关
		$Mark_Text=str_replace("[user:tenpayfun]",CS_Tenpay,$Mark_Text); //财富通开关
		$Mark_Text=str_replace("[user:wypayfun]",$CS_Wypay,$Mark_Text); //网银在线开关
		$Mark_Text=str_replace("[user:rmbtocion]",Cion_RmbToCion,$Mark_Text);
		$Mark_Text=str_replace("[user:id]",$row[0]->CS_ID,$Mark_Text);
		$Mark_Text=str_replace("[user:link]",$this->CsdjSkins->userlink('index',$row[0]->CS_ID,$row[0]->CS_Name),$Mark_Text);
		$Mark_Text=str_replace("[user:name]",$row[0]->CS_Name,$Mark_Text);
		$Mark_Text=str_replace("[user:nichen]",$row[0]->CS_Nichen,$Mark_Text);
		$Mark_Text=str_replace("[user:hits]",$row[0]->CS_Hits,$Mark_Text);
		$Mark_Text=str_replace("[user:sex]",$row[0]->CS_Sex,$Mark_Text);
		$Mark_Text=str_replace("[user:qg]",$row[0]->CS_Qg,$Mark_Text);
$Mark_Text=str_replace("[user:zy]",$row[0]->CS_Zy,$Mark_Text);
$Mark_Text=str_replace("[user:gq]",$row[0]->CS_Gq,$Mark_Text);
$Mark_Text=str_replace("[user:gqbfq]",$row[0]->CS_Gqbfq,$Mark_Text);
		$Mark_Text=str_replace("[user:picd]",$this->CsdjSkins->piclink('logo',$row[0]->CS_Logo,'big'),$Mark_Text);
		$Mark_Text=str_replace("[user:pic]",$this->CsdjSkins->piclink('logo',$row[0]->CS_Logo),$Mark_Text);
		$Mark_Text=str_replace("[user:yhits]",$row[0]->CS_Yhits,$Mark_Text);
		$Mark_Text=str_replace("[user:zhits]",$row[0]->CS_Zhits,$Mark_Text);
		$Mark_Text=str_replace("[user:rhits]",$row[0]->CS_Rhits,$Mark_Text);
		$Mark_Text=str_replace("[user:zanhits]",$row[0]->CS_Zanhits,$Mark_Text);
		$Mark_Text=str_replace("[user:qq]",$row[0]->CS_QQ,$Mark_Text);
				//会员认证开始
		$Mark_Text=str_replace("[user:sfzh]",$row[0]->CS_Sfzh,$Mark_Text);
		$Mark_Text=str_replace("[user:sflogo]",$this->CsdjSkins->piclink('bgpic',$row[0]->CS_Sflogo),$Mark_Text);
		$Mark_Text=str_replace("[user:sfdz]",$row[0]->CS_Sfdz,$Mark_Text);
		$Mark_Text=str_replace("[user:sfzt]",$row[0]->CS_Sfzt,$Mark_Text);
		//会员认证结束
//伤飞云信
		$Mark_Text=str_replace("[user:shouji]",$row[0]->CS_Sfzh,$Mark_Text);
		$Mark_Text=str_replace("[user:shoujiid]",$row[0]->CS_Sfzhr,$Mark_Text);
		//伤飞云信
                if(empty($row[0]->CS_Qianm)){
		    $Mark_Text=str_replace("[user:qianm]",'暂时没有签名...',$Mark_Text);
                }else{
		    $Mark_Text=str_replace("[user:qianm]",$row[0]->CS_Qianm,$Mark_Text);
                }
		$Mark_Text=str_replace("[user:email]",$row[0]->CS_Email,$Mark_Text);
		$Mark_Text=str_replace("[user:vipid]",$row[0]->CS_Vip,$Mark_Text);
		$Mark_Text=str_replace("[user:rzid]",$row[0]->CS_RZID,$Mark_Text);
		$Mark_Text=str_replace("[user:tid]",$row[0]->CS_TID,$Mark_Text);
		$Mark_Text=str_replace("[user:vip]",$this->CsdjSkins->userlevel($row[0]->CS_Vip),$Mark_Text);
		$Mark_Text=str_replace("[user:cion]",$row[0]->CS_Cion,$Mark_Text);
		$Mark_Text=str_replace("[user:qdts]",$row[0]->CS_Qdts,$Mark_Text);
		$Mark_Text=str_replace("[user:mbid]",$row[0]->CS_Mbid,$Mark_Text);
		$Mark_Text=str_replace("[user:toppic]",$this->CsdjSkins->piclink('toppic',$row[0]->CS_Toppic),$Mark_Text);
		$Mark_Text=str_replace("[user:bgpic]",$this->CsdjSkins->piclink('bgpic',$row[0]->CS_Bgpic),$Mark_Text);
		$Mark_Text=str_replace("[user:level]",$row[0]->CS_Level,$Mark_Text);
		$Mark_Text=str_replace("[user:rmb]",$row[0]->CS_RMB,$Mark_Text);
		$Mark_Text=str_replace("[user:city]",$row[0]->CS_City,$Mark_Text);
		$Mark_Text=str_replace("[user:jinyan]",$row[0]->CS_Jinyan,$Mark_Text);
		$Mark_Text=str_replace("[user:loghits]",$row[0]->CS_LogNum,$Mark_Text);
		$Mark_Text=str_replace("[user:logip]",$row[0]->CS_LogIP,$Mark_Text);
		$Mark_Text=str_replace("[user:logtime]",$this->CsdjSkins->datetime($row[0]->CS_LogTime),$Mark_Text);
		$Mark_Text=str_replace("[user:addtime]",$this->CsdjSkins->datetime($row[0]->CS_AddTime),$Mark_Text);
		$Mark_Text=str_replace("[user:vipkstime]",$this->CsdjSkins->GetDate($row[0]->CS_VipTime),$Mark_Text);
		$Mark_Text=str_replace("[user:vipjstime]",$this->CsdjSkins->GetDate($row[0]->CS_EndTime),$Mark_Text);

                //分割城市地区
                $Arr=explode('-',$row[0]->CS_City);
		$Mark_Text=str_replace("[user:sheng]",@$Arr[0],$Mark_Text);
		$Mark_Text=str_replace("[user:shi]",@$Arr[1],$Mark_Text);
		$Mark_Text=str_replace("[user:qu]",@$Arr[2],$Mark_Text);

                //--------------------------------相关连接解析---------------------------------------//
		$Mark_Text=str_replace("[user:editlink]",site_url('user/edit/'),$Mark_Text);
		$Mark_Text=str_replace("[user:editlogolink]",site_url('user/edit/logo'),$Mark_Text);
		$Mark_Text=str_replace("[user:editpasslink]",site_url('user/edit/pass'),$Mark_Text);
		$Mark_Text=str_replace("[user:editweblink]",site_url('user/edit/web'),$Mark_Text);
		$Mark_Text=str_replace("[user:msglink]",site_url('user/msg/'),$Mark_Text);
		$Mark_Text=str_replace("[user:msgaddlink]",site_url('user/msg/add/'),$Mark_Text);
		$Mark_Text=str_replace("[user:msgdellink]",site_url('user/msg/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:gbooklink]",site_url('user/gbook/'),$Mark_Text);
		$Mark_Text=str_replace("[user:gbookaddlink]",site_url('user/gbook/add/'),$Mark_Text);
		$Mark_Text=str_replace("[user:gbookdellink]",site_url('user/gbook/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:piclink]",site_url('user/pic/'),$Mark_Text);
		$Mark_Text=str_replace("[user:picaddlink]",site_url('user/pic/add/'),$Mark_Text);
		$Mark_Text=str_replace("[user:picdellink]",site_url('user/pic/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:bloglink]",site_url('user/blog/'),$Mark_Text);
		$Mark_Text=str_replace("[user:blogaddlink]",site_url('user/blog/add/'),$Mark_Text);
		$Mark_Text=str_replace("[user:blogdellink]",site_url('user/blog/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:topiclink]",site_url('user/topic/'),$Mark_Text);
		$Mark_Text=str_replace("[user:topicaddlink]",site_url('user/topic/add/'),$Mark_Text);
		$Mark_Text=str_replace("[user:topicdellink]",site_url('user/topic/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:musiclink]",site_url('user/music/'),$Mark_Text);
		$Mark_Text=str_replace("[user:musicaddlink]",site_url('user/music/add/'),$Mark_Text);
		$Mark_Text=str_replace("[user:musicdellink]",site_url('user/music/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:vodlink]",site_url('user/vod/'),$Mark_Text);
		$Mark_Text=str_replace("[user:vodaddlink]",site_url('user/vod/add/'),$Mark_Text);
		$Mark_Text=str_replace("[user:voddellink]",site_url('user/vod/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:newslink]",site_url('user/news/'),$Mark_Text);
		$Mark_Text=str_replace("[user:newsaddlink]",site_url('user/news/add/'),$Mark_Text);
		$Mark_Text=str_replace("[user:newsdellink]",site_url('user/news/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:fklink]",site_url('user/funco/'),$Mark_Text);
		$Mark_Text=str_replace("[user:hylink]",site_url('user/friend/'),$Mark_Text);
		$Mark_Text=str_replace("[user:hydellink]",site_url('user/friend/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:fslink]",site_url('user/fans/'),$Mark_Text);
		$Mark_Text=str_replace("[user:fsdellink]",site_url('user/fans/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:paylink]",site_url('user/pay'),$Mark_Text);
		$Mark_Text=str_replace("[user:viplink]",site_url('user/pay/vip'),$Mark_Text);
		$Mark_Text=str_replace("[user:paylistlink]",site_url('user/pay/lists'),$Mark_Text);
		$Mark_Text=str_replace("[user:favlink]",site_url('user/fav/'),$Mark_Text);
		$Mark_Text=str_replace("[user:favdellink]",site_url('user/fav/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:downlink]",site_url('user/down/'),$Mark_Text);
		$Mark_Text=str_replace("[user:downdellink]",site_url('user/down/del/'),$Mark_Text);
		$Mark_Text=str_replace("[user:logout]",site_url('user/logout/'),$Mark_Text);
		$Mark_Text=str_replace("[user:index]",site_url('user/space'),$Mark_Text);

                //--------------------------------相关统计解析---------------------------------------//
		$Mark_Text=str_replace("[user:hycount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'friend'),$Mark_Text);
		$Mark_Text=str_replace("[user:fscount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'fans'),$Mark_Text);
		$Mark_Text=str_replace("[user:favcount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'fav'),$Mark_Text);
		$Mark_Text=str_replace("[user:musiccount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'dance'),$Mark_Text);
		$Mark_Text=str_replace("[user:piccount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'pic'),$Mark_Text);
		$Mark_Text=str_replace("[user:vodcount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'vod'),$Mark_Text);
		$Mark_Text=str_replace("[user:newscount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'news'),$Mark_Text);
		$Mark_Text=str_replace("[user:msgcount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'xiaoxi'),$Mark_Text);
		$Mark_Text=str_replace("[user:gbookcount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'gbook'),$Mark_Text);
		$Mark_Text=str_replace("[user:msgnewscount]",$this->CsdjSkins->getusercount($row[0]->CS_Name,'xiaoxi','news'),$Mark_Text);
		

                if($row[0]->CS_RZID==1){
		     $Mark_Text=str_replace("[user:renzheng]","已认证",$Mark_Text);
                }else{
		     $Mark_Text=str_replace("[user:renzheng]","未认证",$Mark_Text);
                }
                if($row[0]->CS_Sex==0){
		     $Mark_Text=str_replace("[user:sex]","先生",$Mark_Text);
                }else{
		     $Mark_Text=str_replace("[user:sex]","女士",$Mark_Text);
                }
		return $Mark_Text;
          }
	}

	function vodcaiji($spurl)
	{
          if(!empty($spurl) && substr($spurl,0,7)=='http://'){
              $url=str_replace('http://','',$spurl);
              $uall=explode("/",$url);
              preg_match('/[\w][\w-]*\.(?:com\.cn|com|cn|co|net|org|gov|cc|so|name|dj|biz|tv)(\/|$)/isU', $url, $domain);
              $cjurl=rtrim($domain[0], '/');

              if($cjurl=='ku6.com'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl);
                    if(empty($neir)){
                        return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr("snyu_page_params='vid=",'&category=',$neir);
                    }
              }elseif($cjurl=='56.com'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl,'utf-8');
                    if(empty($neir)){
                        return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr(',"EnId":"','"}',$neir);
                    }
              }elseif($cjurl=='youku.com'){
				    preg_match('/http:\/\/v.youku.com\/v_show\/id_\s*([0-9a-zA-Z]+).html/',$spurl,$vid);
                    if(empty($vid) || empty($vid[1])){
                        return 'no';
                    }else{
                        $swfurl=$vid[1];
                    }
              }elseif($cjurl=='tudou.com'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl);
                    if(empty($neir)){
                       return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr(',lid = ',' ',$neir);
                    }
              }elseif($cjurl=='sohu.com'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl);
                    if(empty($neir)){
                        return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr('var vid="','";',$neir);
                    }
              }elseif($cjurl=='sina.com.cn'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl,'utf-8');
                    if(empty($neir)){
                        return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr("vid:'","',",$neir);
                    }
              }elseif($cjurl=='qq.com'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl,'utf-8');
                    if(empty($neir)){
                        return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr('vid:"','",',$neir);
                    }
              }elseif($cjurl=='pps.tv'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl);
                    if(empty($neir)){
                        return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr('"url_key":"','",',$neir);
                    }
              }elseif($cjurl=='letv.com'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl,'utf-8');
                    if(empty($neir)){
                        return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr('vid:',',',$neir);
                    }
              }elseif($cjurl=='yinyuetai.com'){
                    $neir=$this->CsdjAdmin->HtmlAll($spurl,'utf-8');
                    if(empty($neir)){
                        return 'no';
                    }else{
                        $swfurl=$this->CsdjAdmin->str_substr('<meta property="og:url" content="http://www.yinyuetai.com/video/','"/>',$neir);
                    }
              }else{
                    return 'no';
              }
          }
          if(empty($swfurl)){
               return 'no';
          }else{
               return $swfurl;
          }
        }
 }

