<?php
/**
#	Project: PHPDISK File Storage Solution
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: extend.func.php 2 2011-05-27 02:59:23Z along $
#
#	Copyright (C) 2008-2011 PHPDisk Team. All Rights Reserved.
#
*/
!defined('IN_PHPDISK') && exit('[PHPDisk] Access Denied');

function show_gallery(){
	global $db,$tpf,$settings;
	$settings['gallery_type'] = $settings['gallery_type'] ? $settings['gallery_type'] : 1;
	$q = $db->query("select * from {$tpf}gallery order by show_order asc, gal_id asc");
	$gals = array();
	while($rs = $db->fetch_array($q)){
		$gals[] = $rs;
	}
	$db->free($q);
	unset($rs);

	if(count($gals)){
		foreach($gals as $k => $v){
			$pics .= $v['gal_path'].'|';
			$links .= $v['go_url'].'|';
			$texts .= $v['gal_title'].'|';
		}
	}
	if($settings['gallery_type'] ==2){
		$rtn = "<br />
<SCRIPT type=\"text/javascript\">
var picsarr = new Array();
var linksarr = new Array();
var textsarr = new Array();
var swf_width = {$settings['gallery_size_width']};
var swf_height = {$settings['gallery_size_height']};
var pics = '';
var links = '';
var texts = '';";

		if(count($gals)){
			foreach($gals as $k => $v){
				$rtn .= 'picsarr['.($k+1).'] = "'.$v['gal_path'].'";'.LF;
				$rtn .= 'linksarr['.($k+1).'] = "'.$v['go_url'].'";'.LF;
				$rtn .= 'textsarr['.($k+1).'] = "'.$v['gal_title'].'";'.LF;
			}
		}
		unset($gals);

		$rtn .= "
for(i=1;i<picsarr.length;i++){
	if(pics==\"\") pics = picsarr[i]; else pics += \"|\"+picsarr[i];
}
for(i=1;i<linksarr.length;i++){
	if(links==\"\") links = linksarr[i]; else links += \"|\"+linksarr[i];
}
for(i=1;i<textsarr.length;i++){
	if(texts==\"\") texts = textsarr[i]; else texts += \"|\"+textsarr[i];
}
document.write('<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" ');
document.write('codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" ');
document.write('width=\"'+ swf_width +'\" height=\"'+ swf_height +'\">');
document.write('<param name=\"movie\" value=\"images/flash/gallery_{$settings['gallery_type']}.swf\"><param name=\"quality\" value=\"high\">');
document.write('<param name=\"menu\" value=\"false\"><param name=wmode value=\"opaque\">');
document.write('<param name=\"FlashVars\" value=\"TitleBgPosition=1&bcastr_file='+pics+'&bcastr_link='+links+'&bcastr_title='+texts+'\">');
document.write('<embed src=\"images/flash/gallery_{$settings['gallery_type']}.swf\" wmode=\"opaque\" ');
document.write('FlashVars=\"TitleBgPosition=1&bcastr_file='+pics+'&bcastr_link='+links+'&bcastr_title='+texts+'& ');
document.write('menu=\"false\" quality=\"high\" width=\"'+ swf_width +'\" height=\"'+ swf_height +'\" type=\"application/x-shockwave-flash\" ');
document.write('pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />');
document.write('</object>');
</SCRIPT>
<div class=\"clear\"></div>
<br />
";
	}else{

		$rtn .= "<br />
<script type=\"text/javascript\">
var focus_width = {$settings['gallery_size_width']};
var focus_height = {$settings['gallery_size_height']};
var text_height = 18;
var swf_height = focus_height+text_height;
var pics = clearText(\"{$pics}\");
var links = clearText(\"{$links}\");
var texts = clearText(\"{$texts}\");
document.write('<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabjavascript:void(0)version=6,0,0,0\" width=\"'+ focus_width +'\" height=\"'+ swf_height +'\" align=\"left\"  hspace=\"0\">');
document.write('<param name=\"allowScriptAccess\" value=\"sameDomain\"><param name=\"movie\" value=\"images/flash/gallery_{$settings['gallery_type']}.swf\"><param name=\"quality\" value=\"high\"><param name=\"bgcolor\" value=\"#F0F0F0\">');
document.write('<param name=\"menu\" value=\"false\"><param name=wmode value=\"opaque\">');
document.write('<param name=\"FlashVars\" value=\"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'\">');
document.write('<embed src=\"images/flash/gallery_{$settings['gallery_type']}.swf\" wmode=\"opaque\" FlashVars=\"pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'\" menu=\"false\" bgcolor=\"#F0F0F0\" quality=\"high\" width=\"'+ focus_width +'\" height=\"'+ swf_height +'\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />');
document.write('</object>');
function clearText(str) {
	return str.substr(0, str.length - 1);
}
</script>
<div class=\"clear\"></div>
<br />";
		return $rtn;
	}
}
function show_announces(){
	global $db,$tpf,$settings;
	if($settings['show_announce_detail']){
		$rtn = '';
		$q = $db->query("select * from {$tpf}announces where is_hidden=0 order by show_order asc,annid desc");
		while($rs = $db->fetch_array($q)){
			$rtn .= '<div class="announce">'.LF;
			$rtn .= '	<h2 onclick="rtn_display_status(\'an_ctn_'.$rs['annid'].'\');" style="cursor:pointer"><img src="images/ann_icon.gif" align="absmiddle"> '.$rs['subject'].'</h2>'.LF;
			$rtn .= '	<div class="content" id="an_ctn_'.$rs['annid'].'"> '.$rs['content'].' </div>'.LF;
			$rtn .= '</div>'.LF;
			$rtn .= $rs['is_expand'] ? '' : '<script>getId(\'an_ctn_'.$rs['annid'].'\').style.display="none";</script>'.LF;
		}
		$db->free($q);
		unset($rs);
	}else{
		$q = $db->query("select * from {$tpf}announces where is_hidden=0 order by show_order asc,annid desc");
		while($rs = $db->fetch_array($q)){
			$anns[] = '<img src="images/ann_icon.gif" align="absmiddle"> <a href="'.urr("announce","aid=".$rs['annid']).'" onclick="return hs.htmlExpand(this,{headingText:\\\''.$rs['subject'].'\\\',objectType:\\\'iframe\\\',width:650});" class="f14">'.$rs['subject'].' <span class="txtgray f10">('.date("Y-m-d",$rs['in_time']).')</span></a>';
		}
		$db->free($q);
		unset($rs);
		$rtn = '<div style="padding:8px 0;">';
		$rtn .= '<script language="javascript">';
		$rtn .= 'var anns_arr = new Array();  ';
		for($i=0;$i<count($anns);$i++){
			$rtn .= 'anns_arr['.$i.'] = \''.$anns[$i].'\';';
		}
		$rtn .= '</script>';
		$rtn .= '<script language="javascript" type="text/javascript" src="includes/js/ann_js.js"></script>';
		$rtn .= '</div>';
	}
	return $rtn;
}
function show_tag(){
	global $db,$tpf,$L,$settings;
	$q = $db->query("select * from {$tpf}tags where is_hidden=0 and tag_count>0 order by tag_count desc,tag_id desc limit 30");
	$hot_tags = array();
	while($rs = $db->fetch_array($q)){
		$rs['a_view_tag'] = urr("tag","tag=".rawurlencode($rs['tag_name'])."");
		$rs['tag_count'] = $rs['tag_count'] ? "({$rs['tag_count']})" : '';
		$hot_tags[] = $rs;
	}
	$db->free($q);
	unset($rs);

	if($hot_tags){
		$str = '<div class="tag_list">';
		$str .= '<div class="t_tit">'.$L['hot_tag_title'].'</div>';
		$str .= '<ul><li>';

		foreach($hot_tags as $v){
			$str .= '<a href="'.$v['a_view_tag'].'">'.$v['tag_name'].'<span class="txtgray">'.$v['tag_count'].'</span></a>';
		}
		unset($hot_tags);

		$str .= '</li></ul>';
		$str .= '<br />';
		$str .= '</div><br />';
	}else{
		$str = '';
	}
	return $str;

}
function show_index_file(){
	global $db,$tpf,$settings,$L;
	$q = $db->query("select file_id,file_key,file_name,file_extension,file_time from {$tpf}files where (is_public=1 or in_share=1) and in_recycle=0 and report_status=0 and userid>0 order by file_id desc limit 10");
	$last_file = array();
	while($rs = $db->fetch_array($q)){
		$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
		$rs['file_name'] = cutstr($rs['file_name'].$tmp_ext,25);
		$rs['a_viewfile'] = urr("viewfile","file_id={$rs['file_id']}");
		$rs['file_time'] = is_today($rs['file_time']) ? '<span class="txtred" style="float:right">'.date('m/d',$rs['file_time']).'</span>' : '<span class="txtgray" style="float:right">'.date('m/d',$rs['file_time']).'</span>';
		$last_file[] = $rs;
	}
	$db->free($q);
	unset($rs);

	$q = $db->query("select file_id,file_key,file_name,file_extension,file_time from {$tpf}files where (is_public=1 or in_share=1) and in_recycle=0 and report_status=0 and userid>0 order by file_views desc limit 10");
	$hot_file = array();
	while($rs = $db->fetch_array($q)){
		$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
		$rs['file_name'] = cutstr($rs['file_name'].$tmp_ext,25);
		$rs['a_viewfile'] = urr("viewfile","file_id={$rs['file_id']}");
		$rs['file_time'] = is_today($rs['file_time']) ? '<span class="txtred" style="float:right">'.date('m/d',$rs['file_time']).'</span>' : '<span class="txtgray" style="float:right">'.date('m/d',$rs['file_time']).'</span>';
		$hot_file[] = $rs;
	}
	$db->free($q);
	unset($rs);

	$rtn = '<div class="fl_box">';
	$rtn .= '<div class="tit2">'.$L['last_file'].'</div>';
	$rtn .= '<ul>';
	if(count($last_file)){
		foreach($last_file as $v){
			$rtn .= '<li>'.$v['file_time'].file_icon($v['file_extension']).' <a href="'.$v['a_viewfile'].'" target="_blank">'.$v['file_name'].'</a></li>';
		}
		unset($last_file);
	}
	$rtn .= '</ul>';
	$rtn .= '</div>';
	$rtn .= '<div class="fl_box">';
	$rtn .= '<div class="tit2">'.$L['hot_file'].'</div>';
	$rtn .= '<ul>';
	if(count($hot_file)){
		foreach($hot_file as $v){
			$rtn .= '<li>'.$v['file_time'].file_icon($v['file_extension']).' <a href="'.$v['a_viewfile'].'" target="_blank">'.$v['file_name'].'</a></li>';
		}
		unset($hot_file);
	}
	$rtn .= '</ul>';
	$rtn .= '</div>';
	$rtn .= '<div class="clear"></div>';
	return $rtn;
}

function show_links(){
	global $db,$tpf,$L;
	$str = '<br>';
	$str .= '<div class="f_link">';
	$str .= '<div class="tit"><img src="images/link_icon.gif" align="absmiddle" border="0" /> '.$L['site_link'].'</div>';
	$str .= '<div class="ctn">';
	$q = $db->query("select * from {$tpf}links where is_hidden=0 order by logo desc,show_order asc,linkid desc");
	while($rs = $db->fetch_array($q)){
		$rs['has_logo'] = $rs['logo'] ? 1 : 0;
		if($rs['logo']){
			$str .= '<a href="'.$rs['url'].'" target="_blank"><img src="'.$rs['logo'].'" align="absbottom" border="0" alt="'.$rs['title'].'"></a>&nbsp;';
		}else{
			$str .= '<a href="'.$rs['url'].'" target="_blank">'.$rs['title'].'</a>&nbsp;';

		}
	}
	$db->free($q);
	unset($rs);
	$str .= '</div>';
	$str .= '</div>';
	return $str;
}
function show_adv_data($pos){
	$adv_content = _get_adv($pos);

	$rtn = '';
	switch($pos){
		case 'adv_bottom':
			if(count($adv_content)){
				foreach($adv_content as $v){
					$rtn .= '<div align="center">'.$v['adv_str'].'</div>';
				}
				unset($adv_content);
			}
			break;

		default:
			if(count($adv_content)){
				foreach($adv_content as $v){
					$rtn .= $v['adv_str'];
				}
				unset($adv_content);
			}
	}
	echo $rtn;
}
function _get_adv($adv_position){
	global $tpf,$db,$timestamp;
	$scope = substr(substr(strrchr($_SERVER['PHP_SELF'],'/'),1),0,-4);
	$echo_data = false;
	$q = $db->query("select * from {$tpf}advertisements where adv_position='$adv_position' and is_hidden=0 order by show_order asc,advid desc");
	$adv_arr = array();
	while($rs = $db->fetch_array($q)){
		$adv_type = $rs['adv_type'];
		$param = unserialize($rs['params']);
		$code = $rs['code'];
		$starttime = $rs['starttime'];
		$endtime = $rs['endtime'];

		if(strpos($param['adv_scope'],',')){
			$a2 = explode(',',$param['adv_scope']);
			if(in_array('all',$a2)){
				$echo_data = true;
			}elseif(in_array($scope,$a2)){
				$echo_data = true;
			}
		}else{
			if(!$param['adv_scope'] || $param['adv_scope'] =='all'){
				$echo_data = true;
			}elseif($param['adv_scope'] ==$scope){
				$echo_data = true;
			}
		}
		if($echo_data){
			if($starttime && $timestamp<$starttime){
				$rs['adv_str'] = '';
			}elseif($endtime && $timestamp>$endtime){
				$rs['adv_str'] = '';
			}else{
				switch($adv_type){
					case 'adv_text':
						$size = $param['adv_txt_size'] ? 'font-size:'.$param['adv_txt_size'].';' : 'font-size:12px;';
						$color = $param['adv_txt_color'] ? 'color:'.$param['adv_txt_color'].';' : '';

						$rs['adv_str'] = '<div style="padding:8px 0;"><a href="'.$param['adv_txt_url'].'" target="_blank" style="'.$size.$color.'">'.$param['adv_txt_title'].'</a></div>';
						break;
					case 'adv_code':
						$rs['adv_str'] = html_entity_decode($code);
						break;
					case 'adv_flash':
						$rs['adv_str'] = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'.$param['adv_flash_width'].'" height="'.$param['adv_flash_height'].'">
						  <param name="movie" value="'.$param['adv_flash_src'].'" />
						  <param name="quality" value="high" />
						  <param name="allowScriptAccess" value="always" />
						  <param name="wmode" value="transparent">
							 <embed src="'.$param['adv_flash_src'].'"
							  quality="high"
							  type="application/x-shockwave-flash"
							  WMODE="transparent"
							  width="'.$param['adv_flash_width'].'"
							  height="'.$param['adv_flash_height'].'"
							  pluginspage="http://www.macromedia.com/go/getflashplayer"
							  allowScriptAccess="always" />
						</object>';
						break;
					default:
						$rs['adv_str'] = '<a href="'.$param['adv_img_url'].'" target="_blank">';
						$rs['adv_str'] .= '<img src="'.$param['adv_img_src'].'" ';
						$rs['adv_str'] .= $param['adv_img_width'] ? ' width="'.$param['adv_img_width'].'" ' : '';
						$rs['adv_str'] .= $param['adv_img_height'] ? ' height="'.$param['adv_img_height'].'" ' : '';
						$rs['adv_str'] .= ' align="absmiddle" border="0" alt="'.$param['adv_img_alt'].'" />';
						$rs['adv_str'] .= '</a>';
				}
			}
		}
		$adv_arr[] = $rs;
	}
	$db->free($q);
	unset($rs);

	return $adv_arr;
}
function show_navigation($pos){
	global $db,$tpf;
	if($pos=='top'){
		$q = $db->query("select * from {$tpf}navigations where position='top' order by show_order asc, navid desc");
		while($rs = $db->fetch_array($q)){
			$str .= "<a href=\"{$rs['href']}\" target=\"{$rs['target']}\" title=\"{$rs['title']}\">{$rs['text']}</a> |";
		}
		$db->free($q);
		unset($rs);
		
	}elseif($pos =='bottom'){
		$q = $db->query("select * from {$tpf}navigations where position='bottom' order by show_order asc, navid desc");
		while($rs = $db->fetch_array($q)){
			$str .= "<a href=\"{$rs['href']}\" target=\"{$rs['target']}\" title=\"{$rs['title']}\">{$rs['text']}</a>&nbsp;";
		}
		$db->free($q);
		unset($rs);
	}
	return $str;
}
function show_hotfile(){
	global $db,$tpf,$settings;
	$hot_file = array();
	if($settings['show_hot_file_right']){
		$q = $db->query("select file_id,file_key,file_name,file_views,file_extension,file_size,file_time from {$tpf}files where in_share=1 order by file_views desc limit 10");
		while($rs = $db->fetch_array($q)){
			$tmp_ext = $rs['file_extension'] ? '.'.$rs['file_extension'] : "";
			$rs['file_name_all'] = $rs['file_name'].$tmp_ext;
			$rs['file_name'] = cutstr($rs['file_name'].$tmp_ext,18);
			$rs['file_size'] = get_size($rs['file_size']);
			$rs['file_time'] = custom_time("Y-m-d",$rs['file_time']);
			$rs['file_views'] = $rs['file_views'] ? "({$rs['file_views']})" : "";
			$rs['a_viewfile'] = urr("viewfile","file_id={$rs['file_id']}");
			$hot_file[] = $rs;
		}
		$db->free($q);
		unset($rs);
	}
	return $hot_file;
}
function my_disk_info($pd_uid){
	global $db,$tpf,$settings;
	$rs = $db->fetch_one_array("select wealth,credit,rank,exp from {$tpf}users where userid='$pd_uid' limit 1");
	if($rs){
		$myinfo['credit'] = (int)$rs['credit'];
		$myinfo['wealth'] = (int)$rs['wealth'];
		$myinfo['rank'] = (int)$rs['rank'];
		$myinfo['exp'] = (int)$rs['exp'];
		$myinfo['this_exp'] = ($myinfo['rank']+1)*$settings['exp_const'];
		$myinfo['lv_tips'] = ($myinfo['rank']+1)*$settings['exp_const']-$myinfo['exp'];
		$myinfo['exp_fill'] = @round(100*($myinfo['exp']/(($myinfo['rank']+1)*$settings['exp_const'])));
	}
	unset($rs);
	return $myinfo;
}
?>