www.gusucode.com > 08CMS空白站群系统 3.3 繁体 UTF-8 > upload/include/parse/attachment.php

    <?php
!defined('M_COM') && exit('No Permission');
function singlebox(&$tag,&$sarr){
	//单模式的内容还是字串,即url#plid,而多模式的内容因为是从多集列表中传送过来,已经是需要的内容数组了
	global $players;
	$temparr = $sarr;
	$tclass = $tag['tclass'];
	if(!empty($tag['tmode'])){//file的设定是不同的
		$temps = explode('#',$temparr[$tag['tname']]);
		$temparr['url'] = view_atmurl($temps[0]);
		$temparr['player'] = empty($temps[1]) ? 0 : $temps[1];
		unset($temps);
	}
	if(empty($temparr['url'])) return '';
	if($tclass == 'file'){
		$result = $tag['template'];
	}elseif(in_array($tclass,array('flash','media'))){
		load_cache('players');
		$plid = empty($temparr['player']) ? 0 : $temparr['player'];
		if(!$plid){
			$ext = strtolower(mextension($temparr['url']));
			foreach($players as $k => $player){
				if($player['available'] && $player['ptype'] == $tclass && in_array($ext,array_filter(explode(',',$player['exts'])))){
					$plid = $k;
					break;
				}
			}
		}
		if(!$plid) return '';
		$player = read_cache('player',$plid);
		$temparr['width'] = empty($tag['width']) ? '100%' : $tag['width'];
		$temparr['height'] = empty($tag['height']) ? '100%' : $tag['height'];
		$result = $player['template'];
	}
	nreplace($result,'b',$temparr);
	unset($temparr,$player);
	return $result;
}
function imagebox(&$tag,&$sarr){
	$temp = @explode('#',$sarr[$tag['tname']]);
	$sarr['url'] = view_atmurl($temp[0]);
	if(empty($sarr['url']) && empty($tag['emptyurl'])) return '';
	if(!empty($sarr['url'])){
		$sarr['url_s'] = view_thumburl($temp[0]);
		$wh = imagewh($sarr['url'],!empty($temp[1]) ? $temp[1] : 0,!empty($temp[2]) ? $temp[2] : 0,empty($tag['maxwidth']) ? 0 : $tag['maxwidth'],empty($tag['maxheight']) ? 0 : $tag['maxheight'],empty($tag['expand']) ? 0 : 1);
		$sarr['width'] = $wh['width'];
		$sarr['height'] = $wh['height'];
	}
	if(empty($sarr['url']) && !empty($tag['emptyurl'])){
		$sarr['url'] = $sarr['url_s'] = view_atmurl($tag['emptyurl']);
		$sarr['width'] = $tag['maxwidth'];
		$sarr['height'] = $tag['maxheight'];
	}
	$result = $tag['template'];
	nreplace($result,'b',$sarr);
	return $result;
}
function follow_url(&$tag,$sarr=array()){
	global $cms_abs;
	if(empty($sarr['aid'])) return;
	$result = $cms_abs.(empty($tag['type']) ? 'down' : $tag['type']).'.php?aid='.$sarr['aid'];
	if(empty($tag['tmode'])){
		if(!isset($sarr['fid'])) return '';
		$result .= '&tname='.$sarr['tname'].'&fid='.$sarr['fid'];
	}else{
		if(empty($tag['tname'])) return '';
		$result .= '&tname='.$tag['tname'].'&tmode=1';
	}
	return $result;
}
function imagewh($imageurl,$width=0,$height=0,$maxwidth=0,$maxheight=0,$expand = 0){
	if(!$width) $width = !$maxwidth ? '100' : $maxwidth;
	if(!$height) $height = !$maxheight ? '100' : $maxheight;
	$maxwidth = !$maxwidth ? $width : $maxwidth;
	$maxheight = !$maxheight ? $height : $maxheight;
	$wh['width'] = $width;
	$wh['height'] = $height;
	if(($wh['width'] >= $maxwidth || $wh['height'] >= $maxheight) || ($wh['width'] < $maxwidth && $wh['height'] < $maxheight && $expand)) {
		$x_ratio = $maxwidth / $wh['width'];
		$y_ratio = $maxheight / $wh['height'];
		if(($x_ratio * $wh['height']) < $maxheight) {
			$wh['height'] = @ceil($x_ratio * $wh['height']);
			$wh['width'] = $maxwidth;
		} else {
			$wh['width'] = @ceil($y_ratio * $wh['width']);
			$wh['height'] = $maxheight;
		}
	}
	return $wh;
}

?>