<?php
/**
 *	[网盘虚拟附件--免跳转下载(threed_pan.{modulename})] (C)2014-2015 Powered by www.adminbuy.cn
 *	Version: 商业版  By:QQ 9490489
 *	Date: 2014-12-3 21:54
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
class plugin_threed_pan {
	//TODO - Insert your code here 
}

class plugin_threed_pan_forum extends plugin_threed_pan{
	function post_editorctrl_left() {
		global $_G;
		if(!$_G['cache']['plugin']['threed_pan']['thd_tabopen'])return;
		$load_url='plugin.php?id=threed_pan:load';
		$str = '<a id="a_mg_vdisk" style="background:url(source/plugin/threed_pan/template/ico.png) no-repeat scroll 0% 0% transparent;" title="'.lang('plugin/threed_pan', 'downld9').'" href="javascript:;" onClick="showWindow(\'loadbox\', \''.$load_url.'\')">'.lang('plugin/threed_pan', 'downld9').'</a>';
		return $str;
	} 
 function post_top(){
	 global $_G;
	 $pan_forums=unserialize($_G['cache']['plugin']['threed_pan']["thd_forum"]);
	if(in_array($_G['fid'], $pan_forums)) return $_G['cache']['plugin']['threed_pan']['pan_editinfo'];	
 }
	
	function viewthread_posttop_output(){
		global $_G,$postlist,$post;
		$pan_option = $_G['cache']['plugin']['threed_pan'];	
		$pan_forums = unserialize($pan_option["thd_forum"]);
		$pan_user=unserialize($pan_option["thd_user"]);
		$pan_other=$pan_option["thd_other"];
		
		
		foreach($postlist as $id => $post) {
			if( (!in_array($_G['fid'], $pan_forums))||!$post['first']){				
			break;
			}			
			$pan_message=$post['message'];			
			$pan_tab1='<a href="';
			$pan_tab2='" target="_blank">';
			$pan_tab3='</a>';
			if($pan_option["thd_tabopen"]){
				$pan_tab1="[pan=";
				$pan_tab2="]";
				$pan_tab3="[/pan]";
			}
			
		$trmp1_arr=explode($pan_tab1,$pan_message);

		if(count($trmp1_arr)>1){
		
			$n=1;
			include template('threed_pan:attach');
			foreach($trmp1_arr as $key => $trmp1_arrstr){
			
				if($n==1){
					$pan_message=$trmp1_arrstr;
					$n++;
			
					continue;
				}else{
					$tmpmessage.=$pan_tab1.$trmp1_arrstr;
				
				}		
				$n=$n+1;				
				$trmp2_arr=explode($pan_tab3,$trmp1_arrstr);
				
					if(count($trmp2_arr)>1){					
						$trmp3_arr=explode($pan_tab2,$trmp2_arr[0]);
						$pan_srl=$trmp3_arr[0];
						$pan_srltemp=explode("|",$trmp3_arr[1]);
						$pan_srljiage=0;
						if(count($pan_srltemp)>1)$pan_srljiage=intval($pan_srltemp[2]);
						$pan_srlname=$pan_srltemp[0];
						$pan_srlkey=$pan_srltemp[1];
						$pan_type=0;					
						if(substr($pan_srl,0,20)=='http://pan.baidu.com'){					
							$pan_type=1;
						}elseif(substr($pan_srl,0,20)=='http://dl.vmall.com/'){
							$pan_type=2;
							$pan_srl=str_replace('http://dl.vmall.com/','http://dl.vmall.com/mini_Show_5_0_0.html?id=',$pan_srl);
						}elseif(substr($pan_srl,0,16)=='http://yunpan.cn'){
							$pan_type=3;
						}else {
							$pan_type=0;
							}
						
						if($pan_type==0&&$pan_other==0){if($pan_option["thd_tabopen"])$tmpmessage.='<font color="#F00">'.lang('plugin/threed_pan', 'downld6').'</font>'; continue;}	
						$buycount=DB::result_first('SELECT count(1) FROM '.DB::table('threed_pan').' WHERE buy_tid='.$_G[tid].' and buy_uid = '.$_G['uid']);
						$allcount=DB::result_first('SELECT count(1) FROM '.DB::table('threed_pan').' WHERE buy_tid='.$_G[tid]);
										
							if(in_array($_G[groupid], $pan_user)||$post[authorid]==$_G['uid']||$buycount>0||!$pan_srljiage){
								$pan_srl=$pan_type.'|'.$pan_srl.'|'.$_G['tid'];					
								$pan_srl=base64_encode($pan_srl);
								$pan_url='plugin.php?id=threed_pan:downld&url='.$pan_srl.'&name='.$pan_srlname.'&formhash='.FORMHASH;
								$ifbuy=1;										
												
							}else{
								
								$pan_srlgg=($pan_srljiage+3)*91+131;//简单加密
								$pan_url='plugin.php?id=threed_pan:payfor&ac=buy&tid='.$_G['tid'].'&gg='.$pan_srlgg.'&formhash='.FORMHASH;
								$ifbuy=0;
											
							}				
							$replace=show_pan_attach($ifbuy,$pan_url,$pan_srlname,$pan_srlkey,$pan_srljiage,$allcount);
							
							$tmpmessage = str_replace($pan_tab1.$trmp2_arr[0].$pan_tab3,$replace,$tmpmessage);
						
					}
					
				}
				$post['message']=$pan_message.$tmpmessage;
				$postlist[$id] =$post;

			}

		}
		 
	}
}

?>