<?php 
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pan extends CI_Controller {

	function __construct(){
		parent::__construct();
	        $this->load->model('CsdjDB');
	        $this->load->model('CsdjAdmin');
	}

        //威盘地址解析
	public function vdisk()
	{
            $id = $this->uri->segment(3);   //ID
            $id =str_replace('.mp3','',$id);

            $url='http://www.vdisk.cn/down/index/'.$id;
            $str=$this->CsdjAdmin->HtmlAll($url,'utf-8');
            $durl=$this->CsdjAdmin->str_substr('="httpfileurl" content="', '"', $str);

            $UA = strtoupper(@$_SERVER['HTTP_USER_AGENT']);
            if(preg_match("/(iPhone|iPad|iPod|Android)/i", $UA)){
                  $durl="http://www.boanniu.com/".$id."/cscms.mp3";
            }
            Header("Location: ".$durl);
	}

        //官方盘地址解析
	public function csdjso()
	{
            $id = $this->uri->segment(3);   //ID
            $id =str_replace('.mp3','',$id);
            $Arr=explode('_',$id);
            $user=$Arr[0];
            $uid=$Arr[1];
            $durl='http://up.chshcms.com/wl/url/'.$user.'/'.$uid.'/yuedisk.mp3';

            $UA = strtoupper(@$_SERVER['HTTP_USER_AGENT']);
            if(preg_match("/(iPhone|iPad|iPod|Android)/i", $UA)){
                  $durl='http://up.chshcms.com/m.php/'.$user.'/'.$uid.'/yuedisk.mp3';
            }
            Header("Location: ".$durl);
	}

        //聚龙盘上传返回
	public function julong_return_url()
	{
                $url=$this->input->get('demourl', TRUE);
		$name=$this->input->get('filename', TRUE);
		$dx=$this->input->get('file_size', TRUE);
		
		$name = substr(iconv('utf-8','gbk',$name),0,-4);

		
       $arr = split('/', $url);
$page = array_pop($arr);
$pagea = str_replace('.mp3', '', $page); 
$pageb = str_replace('http://pan.julongdj.com/', '', $pagea);
$pagec = str_replace('demo-', '', $pageb);
$url_a='http://demo.julongdj.com/demo_play.php?file_id='.$pagec.'';
$json_info=$this->get_url_contents($url_a);

$dj_cc=substr(trim($json_info),13,-2);
if($json_info!='var cb="Error file";'){
$durl='http://demo.julongdj.com/'.$dj_cc.'.mp3';
exit("<script type=\"text/javascript\">

window.parent.document.getElementById('cs_playurl').value= 'http://www.27meng.com/url.php/".$pagec.".mp3';
window.parent.document.getElementById('cs_downurl').value= 'http://www.27meng.com/url.php/".$pagec.".mp3';
window.parent.document.getElementById('cs_dx').value= '".$dx."';
window.parent.document.getElementById('msg_upload').innerHTML='<font color=#0000ff>恭喜您，文件上传成功! 记得点保存！</font>';
                        parent.Dialog.close();
		</script>");
}else{
exit("<script type=\"text/javascript\">
window.parent.document.getElementById('msg_upload').innerHTML='<font color=#0000ff>对不起，文件上传失败! 请重新试下！</font>';
                        parent.Dialog.close();
		</script>");
}

}
    

        //官方网盘上传返回
	public function csdj_return_url()
	{
                $fhurl=$this->input->get('fhurl', TRUE);
                $durl=$this->input->get('downurl', TRUE);
		$name=$this->input->get('name', TRUE);
		$user=$this->input->get('user', TRUE);
		$url = "_csdjso_".$user."_".substr($durl,33);
		$name = substr($name,0,-4);

		exit("<script type=\"text/javascript\">
			opener.document.getElementById('".$fhurl."').value= '".$url."';
                        alert('文件上传成功!');
			window.close();
		</script>");
        }
		function get_url_contents($url,$post='',$type='get'){

                $ch = curl_init();
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
                if($type=='post') {
		    curl_setopt($ch, CURLOPT_POST, 1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
                }else{
		    curl_setopt($ch, CURLOPT_POST, 0);
                }
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
		$result = curl_exec($ch);
                curl_close($ch);

            return $result;
    }
}

