www.gusucode.com > ShopEx481 & PHPWind 整合版码程序 > bbs/require/bbscode.php

    <?php
!function_exists('readover') && exit('Forbidden');
function convert($message,$allow,$type="post"){
	global $code_num,$code_htm,$phpcode_htm,$foruminfo,$db_picpath,$imgpath,$stylepath,$db_attachname,$attachpath,$admincheck,$tpc_author,$tpc_buy,$db_cvtimes,$forumset,$tpc_tag;
	
	$code_num = 0;
	$code_htm = array();
	if(strpos($message,"[code]") !== false && strpos($message,"[/code]") !== false){
		$message=preg_replace("/\[code\](.+?)\[\/code\]/eis","phpcode('\\1')",$message,$db_cvtimes);
	}
	if(strpos($message,"[payto]") !== false && strpos($message,"[/payto]") !== false){
		require_once(R_P.'require/paytofunc.php');
		$message=preg_replace("/\[payto\](.+?)\[\/payto\]/eis","payto('\\1')",$message);
	}
	$message = preg_replace('/\[list=([aA1]?)\](.+?)\[\/list\]/is', "<ol type=\"\\1\" style=\"margin:0 0 0 25px\">\\2</ol>", $message);
	
	$searcharray = array('[u]','[/u]','[b]','[/b]','[i]','[/i]','[list]','[li]','[/li]','[/list]','[sub]', '[/sub]','[sup]','[/sup]','[strike]','[/strike]','[blockquote]','[/blockquote]','[hr]','[/backcolor]', '[/color]','[/font]','[/size]','[/align]'
	);
	$replacearray = array('<u>','</u>','<b>','</b>','<i>','</i>','<ul style="margin:0 0 0 15px">','<li>', '</li>','</ul>','<sub>','</sub>','<sup>','</sup>','<strike>','</strike>','<blockquote>','</blockquote>', '<hr />','</span>','</span>','</span>','</font>','</div>'
	);
	$message = str_replace($searcharray,$replacearray,$message);

	$message = str_replace("p_w_upload",$db_attachname,$message);//此处位置不可调换
	$message = str_replace("p_w_picpath",$db_picpath,$message);//此处位置不可调换

	$searcharray = array(
		"/\[font=([^\[\(&]+?)\]/is",
		"/\[color=([#0-9a-z]{1,10})\]/is",
		"/\[backcolor=([#0-9a-z]{1,10})\]/is",
		"/\[email=([^\[]*)\]([^\[]*)\[\/email\]/is",
	    "/\[email\]([^\[]*)\[\/email\]/is",
		"/\[size=(\d+)\]/eis",
		"/\[align=(left|center|right|justify)\]/is",
		"/\[glow=(\d+)\,([0-9a-zA-Z]+?)\,(\d+)\](.+?)\[\/glow\]/is"
	);
	$replacearray = array(
		"<span style=\"font-family:\\1 \">",
		"<span style=\"color:\\1 \">",
		"<span style=\"background-color:\\1 \">",
		"<a href=\"mailto:\\1 \">\\2</a>",
		"<a href=\"mailto:\\1 \">\\1</a>",
		"size('\\1','$allow[size]')",
		"<div align=\"\\1\">",
		"<div style=\"width:\\1px;filter:glow(color=\\2,strength=\\3);\">\\4</div>"
	);
	$message = preg_replace($searcharray,$replacearray,$message);

	if($allow['pic']){
		$message = preg_replace("/\[img\](.+?)\[\/img\]/eis", "cvpic('\\1','','$allow[picwidth]','$allow[picheight]')",$message,$db_cvtimes);
    } else{
		$message = preg_replace("/\[img\](.+?)\[\/img\]/eis","nopic('\\1')",$message,$db_cvtimes);
	}

	if(strpos($message,'[/URL]')!==false || strpos($message,'[/url]')!==false){
		$searcharray = array(
			"/\[url=(https?|ftp|gopher|news|telnet|mms|rtsp|thunder)([^\[\s]+?)\](.+?)\[\/url\]/eis",			
			"/\[url\]www\.([^\[]+?)\[\/url\]/eis",
			"/\[url\](https?|ftp|gopher|news|telnet|mms|rtsp|thunder)([^\[]+?)\[\/url\]/eis"
		);
		$replacearray = array(
			"cvurl('\\1','\\2','\\3')",
			"cvurl('\\1')",
			"cvurl('\\1','\\2')"
		);
		$message = preg_replace($searcharray,$replacearray,$message);
	}

	$searcharray = array(
		"/\[fly\]([^\[]*)\[\/fly\]/is",
		"/\[move\]([^\[]*)\[\/move\]/is"
	);
	$replacearray = array(
		"<marquee width=90% behavior=alternate scrollamount=3>\\1</marquee>",
		"<marquee scrollamount=3>\\1</marquee>"
	);
	$message = preg_replace($searcharray,$replacearray,$message);

	if($type=="post"){
		if($foruminfo['allowhide'] && strpos($message,"[post]")!==false && strpos($message,"[/post]")!==false){
			$message=preg_replace("/\[post\](.+?)\[\/post\]/eis","post('\\1')",$message);
		}
		if($forumset['allowencode'] && strpos($message,"[hide=")!==false && strpos($message,"[/hide]")!==false){
			$message=preg_replace("/\[hide=(.+?)\](.+?)\[\/hide\]/eis","hiden('\\1','\\2')",$message);
		}
		if($foruminfo['allowsell'] && strpos($message,"[sell")!==false && strpos($message,"[/sell]")!==false){
			$message=preg_replace("/\[sell=(.+?)\](.+?)\[\/sell\]/eis","sell('\\1','\\2')",$message);
		}
	}
	if(strpos($message,"[quote]") !== false && strpos($message,"[/quote]") !== false){
		$message = preg_replace("/\[quote\](.+?)\[\/quote\]/eis","qoute('\\1')",$message);
	}
	if(is_array($code_htm)){
		krsort($code_htm);
		foreach($code_htm as $codehtm){
			foreach($codehtm as $key=>$value){
				$message=str_replace("<\twind_code_$key\t>",$value,$message);
			}
		}
	}
	if($allow['flash']){
		$message = preg_replace("/\[flash=(\d+?)\,(\d+?)(\,(0|1))?\](.+?)\[\/flash\]/eis", "wplayer('\\5','\\1','\\2','\\4','flash')",$message,$db_cvtimes);
	} else{
		$message = preg_replace("/\[flash=(\d+?)\,(\d+?)(\,(0|1))?\](.+?)\[\/flash\]/is","<img src='$imgpath/$stylepath/file/music.gif' align='absbottom'> <a target='_blank' href='\\5 '>flash: \\5</a>",$message,$db_cvtimes);
	}
	if($type=="post"){
		$t = 0;
		while(strpos($message,"[table") !== false && strpos($message,"[/table]") !== false){
			$message = preg_replace('/\[table(=(\d{1,3}(%|px)?))?\](.*?)\[\/table\]/eis', "tablefun('\\2','\\3','\\4')",$message);
			if(++$t>4) break;
		}
		if($allow['mpeg']){
			$message = preg_replace(
				array(
					"/\[wmv=(0|1)\](.+?)\[\/wmv\]/eis",
					"/\[wmv(=([0-9]{1,3})\,([0-9]{1,3})\,(0|1))?\](.+?)\[\/wmv\]/eis",
					"/\[rm(=([0-9]{1,3})\,([0-9]{1,3})\,(0|1))?\](.+?)\[\/rm\]/eis"
				),
				array(
					"wplayer('\\2','314','53','\\1','wmv')",
					"wplayer('\\5','\\2','\\3','\\4','wmv')",
					"wplayer('\\5','\\2','\\3','\\4','rm')"
				),$message,$db_cvtimes
			);
		} else{
			$message = preg_replace(
				array(
					"/\[wmv=[01]{1}\](.+?)\[\/wmv\]/is",
					"/\[wmv(?:=[0-9]{1,3}\,[0-9]{1,3}\,[01]{1})?\](.+?)\[\/wmv\]/is",
					"/\[rm(?:=[0-9]{1,3}\,[0-9]{1,3}\,[01]{1})\](.+?)\[\/rm\]/is"
				),
				"<img src=\"$imgpath/$stylepath/file/music.gif\" align=\"absbottom\"> <a target=\"_blank\" href=\"\\1 \">\\1</a>",$message,$db_cvtimes
			);
		}
		if($allow['iframe']){
			$message = preg_replace("/\[iframe\](.+?)\[\/iframe\]/is","<IFRAME SRC=\\1 FRAMEBORDER=0 ALLOWTRANSPARENCY=true SCROLLING=YES WIDTH=97% HEIGHT=340></IFRAME>",$message,$db_cvtimes);
		} else{
			$message = preg_replace("/\[iframe\](.+?)\[\/iframe\]/is","Iframe Close: <a target=_blank href='\\1 '>\\1</a>",$message,$db_cvtimes);
		}
		$tpc_tag && $message = relatetag($message,$tpc_tag);
		strpos($message,'[s:')!==false && $message = showface($message);
	}
	if(is_array($phpcode_htm)){
		foreach($phpcode_htm as $key=>$value){
			$message=str_replace("<\twind_phpcode_$key\t>",$value,$message);
		}
	}
	return $message;
}
function copyctrl(){
	$lenth=10;
	mt_srand((double)microtime() * 1000000);
	for($i=0;$i<$lenth;$i++){
		$randval.=chr(mt_rand(0,126));
	}
	$randval=str_replace('<','&lt;',$randval);
	return "<span style=\"display:none\"> $randval </span>&nbsp;<br />";
}
function attachment($message){
	global $db_cvtimes;
	return preg_replace("/\[attachment=([0-9]+)\]/eis","upload('\\1')",$message,$db_cvtimes);
}
function upload($aid){
	global $attachments,$aids;

	if($attachments[$aid]){
		$aids[]=$aid;
		return $attachments[$aid];
	} else{
		return "[attachment=$aid]";
	}
}
function tablefun($width,$unit,$text){
	global $tdcolor,$td_htm,$td_num;
	if($width){
		$unit !='%' && $unit = 'px';
		$width = $unit == 'px' ? ($width < 600 ? (int)$width : 600).'px' : ($width < 98 ? (int)$width : 98).'%';
	} else{
		$width = '98%';
	}
	$text = preg_replace(
		array(
			'/(\[\/td\]\s*)?\[\/tr\]/is',
			'/\[(tr|\/td)\]\s*\[td(=(\d{1,2}),(\d{1,2})(,(\d{1,3}%?))?)?\]/eis',
			'/\[tr\]/is',
		),
		array('</td></tr>',"tdfun('\\1','\\3','\\4','\\6')",'<tr class="tr3"><td>'),
		str_replace('\\"','"',$text)
	);
	return "<table style=\"border:1px solid $tdcolor;width:$width\">$text</table>";
}
function tdfun($t,$col,$row,$width){
	return ($t == 'tr' ? '<tr class="tr3">' : '</td>').(($col && $row) ? "<td colspan=\"$col\" rowspan=\"$row\" width=\"$width\">" : "<td>");
}
function size($size,$allowsize){
	$allowsize && $size > $allowsize && $size = $allowsize;
	return "<font size=\"$size\">";
}
function cvurl($http,$url='',$name=''){
	global $code_num,$code_htm;
	$code_num++;
	if(!$url){
		$url="<a href=\"http://www.$http\" target=\"_blank\">www.$http</a>";
	} elseif(!$name){
		$url="<a href=\"$http$url\" target=\"_blank\">$http$url</a>";
	} else{
		$url="<a href=\"$http$url\" target=\"_blank\">".str_replace('\\"','"',$name)."</a>";
	}
	$code_htm[0][$code_num]=$url;
	return "<\twind_code_$code_num\t>";
}

function nopic($url){
	global $code_num,$code_htm,$imgpath,$stylepath;
	$code_num++;
	$code_htm[-1][$code_num]="<img src=\"$imgpath/$stylepath/file/img.gif\" align=\"absbottom\" border=\"0\"> <a target=\"_blank\" href=\"$url \">img: $url</a>";
	return "<\twind_code_$code_num\t>";
}

function cvpic($url,$type='',$picwidth='',$picheight='',$ifthumb=''){
	global $db_bbsurl,$db_picpath,$attachpath,$db_ftpweb,$code_num,$code_htm;
	$code_num++;
	$lower_url = strtolower($url);
	substr($lower_url,0,4)!='http' && $url = "$db_bbsurl/$url";
	if (strpos($lower_url,'login')!==false && (strpos($lower_url,'action=quit')!==false || strpos($lower_url,'action-quit')!==false)) {
		$url = preg_replace('/login/i','log in',$url);
	}
	$url = str_replace(array("&#39;","'"),'',$url);
	$turl = $url;
	$wopen = 0;
	$alt = '';
	if ($ifthumb) {
		if ($db_ftpweb && !strpos($url,$attachpath)!==false) {
			$picurlpath = $db_ftpweb;
		} else{
			$picurlpath = $attachpath;
		}
		if (strpos($url,$picurlpath)!==false) {
			$wopen = 1;
			$alt = 'alt="Click Here To EnLarge"';
			$turl = str_replace($picurlpath,"$picurlpath/thumb",$url);
		}
	}
	if ($picwidth || $picheight) {
		$wopen = !$wopen ? "if(this.width>=$picwidth)" : '';
		$onload = 'onload="';
		$picwidth  && $onload .= "if(this.width>'$picwidth')this.width='$picwidth';";
		$picheight && $onload .= "if(this.height>'$picheight')this.height='$picheight';";
		$onload .= '"';
		$code = "<img src=\"$turl\" border=\"0\" onclick=\"$wopen window.open('$url');\" $onload $alt>";
	} else{
		$wopen = !$wopen ? "if(this.width>screen.width-461)" : '';
		$code = "<img src=\"$turl\" border=\"0\" onclick=\"$wopen window.open('$url');\" $alt>";
	}
	$code_htm[-1][$code_num]=$code;
	if ($type) {
		return $code;
	} else {
		return "<\twind_code_$code_num\t>";
	}
}

function phpcode($code){
	global $phpcode_htm,$codeid;
	$code = str_replace(array("[attachment=",'\\"'),array("&#91;attachment=",'"'),$code);
	$codeid ++;
	$phpcode_htm[$codeid]="<h6 class=\"quote\"><a href=\"javascript:\"  onclick=\"CopyCode(document.getElementById('code$codeid'));\">Copy code</a></h6><blockquote class=\"blockquote\" id=\"code$codeid\">".preg_replace("/^(\<br \/\>)?(.*)/is","\\2",$code)."</blockquote>";

	return "<\twind_phpcode_$codeid\t>";
}

function qoute($code){
	global $code_num,$code_htm,$i_table;
	$code_num++;
	$code_htm[6][$code_num]="<h6 class=\"quote\">Quote:</h6><blockquote class=\"blockquote\">".str_replace('\\"','"',$code)."</blockquote>";
	return "<\twind_code_$code_num\t>";
}
function ifpost($tid){
	global $SYSTEM,$admincheck,$tpc_author,$winduid,$windid,$db,$tpc_ifview;
	if($tpc_ifview==''){
		if($admincheck==1 || $SYSTEM['viewhide'] || $tpc_author==$windid){
			$tpc_ifview = 1;
		} else{
			$pw_posts = GetPtable($GLOBALS['ptable']);
			$rs = $db->get_one("SELECT count(*) AS count FROM $pw_posts WHERE tid='$tid' AND authorid='$winduid'");
			$tpc_ifview = $rs['count']>0 ? 1 : 2;
		}
	}
	return $tpc_ifview;
}
function post($code){
	global $code_num,$tid,$code_htm,$lang,$tpc_att;
	require_once GetLang('bbscode');
	$code_num++;
	if(ifpost($tid) == 1){
		$code_htm[3][$code_num]="<h6 class=\"quote\"><span class=\"s3 f12 fn\">$lang[bbcode_hide1]</span></h6><blockquote class=\"blockquote\">".str_replace('\\"','"',$code)."</blockquote>";
	} else{
		$code_htm[3][$code_num]="<blockquote class=\"blockquote\">$lang[bbcode_hide2]</blockquote>";
		$tpc_att = 0;
	}
	return "<\twind_code_$code_num\t>";
}
function hiden($rvrc,$code){
	global $hidecode1,$hidecode2,$hidecode3,$db,$groupid,$tpc_att,$userrvrc,$code_num,$code_htm,$lang;
	require_once GetLang('bbscode');
	$code_num++;
	if($groupid!='guest'){
		global $admincheck,$userrvrc,$userpath,$windid,$tpc_author,$SYSTEM;
		$rvrc=intval(trim(stripslashes($rvrc)));
		if($windid!=$tpc_author && $userrvrc<$rvrc && $admincheck!=1 && !$SYSTEM['viewhide']){
			$code="<blockquote class=\"blockquote\">{$lang[bbcode_encode1]}{$rvrc}</blockquote>";
			$tpc_att = 0;
		} else{
			$code="<h6 class=\"quote\"><span class=\"s3 f12 fn\">{$lang[bbcode_encode2]}</span></h6><blockquote class=\"blockquote\">".str_replace('\\"','"',$code)."</blockquote>";
		}
	} else{
		$tpc_att = 0;
		$code="<blockquote class=\"blockquote\">".$lang['bbcode_encode3']."</blockquote>";
	}
	$code_htm[4][$code_num]=$code;
	return "<\twind_code_$code_num\t>";
}
function sell($cost,$code){
	global $SYSTEM,$admincheck,$windid,$tpc_author,$tpc_buy,$tpc_pid,$tpc_att,$fid,$tid,$i_table,$groupid,$code_num,$code_htm,$lang,$db_credits,$db_bbsurl,$db_sellset,$db_currencyname,$_CREDITDB;
	list($db_moneyname,,$db_rvrcname,,$db_creditname,) = explode("\t",$db_credits);
	$sellset = !empty($db_sellset) ? unserialize($db_sellset) : array();
	require_once GetLang('bbscode');
	$code_num++;
	$sellcheck = 0;
	list($creditvalue,$credittype) = explode(',',$cost);
	$creditvalue = (int)$creditvalue;
	if ($creditvalue < 1) {
		$creditvalue = 1;
	} elseif ($sellset['price'] && $creditvalue>$sellset['price']) {
		$creditvalue = $sellset['price'];
	}
	$creditname = isset($_CREDITDB[$credittype]) ? $_CREDITDB[$credittype][0] : (in_array($credittype,array('money','rvrc','credit','currency')) ? ${'db_'.$credittype.'name'} : $db_moneyname);

	$userarray = explode(',',$tpc_buy);
	$count = 0;
	foreach ($userarray as $value) {
		if ($value) {
			$count++;
			$buyers.="<option value=''>".$value."</option>";
		}
	}
	if ($groupid!='guest' && ($SYSTEM['viewhide'] || $admincheck || $tpc_author==$windid || ($userarray && @in_array($windid,$userarray)))) {
		$sellcheck=1;
	}
	$bbcode_sell_info = str_replace(array('$creditvalue','$creditname','$count'), array($creditvalue,$creditname,$count), $lang['bbcode_sell_info']);

	if ($sellcheck==1) {
		$printcode = "<h6 class=\"quote\"><span class=\"s3 f12 fn\">{$bbcode_sell_info}</span> <select name=\"buyers\"><option>{$lang[bbcode_sell_buy]}</option>$buyers</select></h6><blockquote class=\"blockquote\">".str_replace('\\"','"',$code)."</blockquote>";
	} else {
		$buyurl = PwEncodeUrl("job.php?action=buytopic&tid=$tid&pid=$tpc_pid");
		$printcode = "<h6 class=\"quote\"><span class=\"s3\">{$bbcode_sell_info}</span> <select name=\"buyers\"><option value=''>{$lang[bbcode_sell_buy]}</option><option value=>-----------</option>$buyers</select> <input type=\"button\" value=\"{$lang[bbcode_sell_submit]}\" class=\"btn\" onclick=location.href=\"$buyurl\" style=\"line-height:100%\"></h6><blockquote class=\"blockquote\"> {$lang[bbcode_sell_notice]}</blockquote>";
		$tpc_att = 0;
	}
	$code_htm[5][$code_num]=$printcode;
	return "<\twind_code_$code_num\t>";
}

function shield($code){
	global $lang,$groupid;
	require_once GetLang('bbscode');
	$lang[$code] && $code = $lang[$code];
	return "<span style=\"color:black;background-color:#ffff66\">$code</span>";
}
function wplayer($wmvurl,$width='',$height='',$auto='',$type='wmv'){
	global $lang,$player_id;
	$player_id = $player_id + 1;
	require_once GetLang('bbscode');
	!$width && $width = 314;
	!$height && $height = 256;
    return ($player_id==1 ? "<script src=\"js/player.js\"></script>" : '')."<div id=\"player_$player_id\"><a onclick=\"player('player_$player_id','$wmvurl','$width','$height','$type');\" class=\"abtn f12\">".$lang['player_'.$type]."</a></div>".($auto == '1' ? "<script language=\"JavaScript\">player('player_'+$player_id,'$wmvurl','$width','$height','$type');</script>" : '');
}
function showface($message){
	global $face,$db_cvtimes;
	include_once(D_P.'data/bbscache/postcache.php');
	$message = preg_replace("/\[s:(.+?)\]/eis","postcache('\\1')",$message,$db_cvtimes);
	return $message;
}
function postcache($key){
	global $face,$imgpath,$tpc_author;
	!$face[$key] && $face[$key] = current($face);
	if($face[$key][2]){
		return "<br /><img src=$imgpath/post/smile/{$face[$key][0]} /><br />[<font color=red><b>$tpc_author</b></font>] {$face[$key][2]}<br />";
	} else{
		return "<img src=\"$imgpath/post/smile/{$face[$key][0]}\" />";
	}
}
function wordsfb($message,$update='N'){
	global $wordsfb,$replace,$pwcode;
	include_once(D_P."data/bbscache/wordsfb.php");
	$replacedb = $wordsfb + $replace;
	$msg = $message;
	if($replacedb){
		foreach($replacedb as $key => $value){
			$msg = preg_replace("/$key/i",$value,$msg);
		}
	}
	$pwcode && $msg = preg_replace($pwcode['searcharray'],$pwcode['replacearray'],$msg);
	if(is_numeric($update) && ($update>0 || $msg == $message)){
		global $db,$tpc_pid,$tid,$pw_tmsgs,$pw_posts,$db_wordsfb,$fbpid;
		$ifwordsfb = $msg == $message ? $db_wordsfb : 0;
		if(is_numeric($tpc_pid)){
			$fbpid[$ifwordsfb] .= $fbpid[$ifwordsfb] ? ','.$tpc_pid : $tpc_pid;
		} elseif($tpc_pid == 'tpc'){
			$db->update("UPDATE $pw_tmsgs SET ifwordsfb='$ifwordsfb' WHERE tid='$tid'");
		}
	}
	return $msg;
}
function leaveword($code,$pid){
	global $lang,$admincheck,$imgpath,$tid;
	require_once GetLang('bbscode');
	return "<div id=\"lwd_$pid\"><h6 class=\"quote\">".($admincheck ? "<span class=\"fr\" style=\"cursor:pointer\" onclick=\"read.obj=getObj('lwd_$pid');ajax.send('pw_ajax.php?action=leaveword','step=3&tid=$tid&pid=$pid',worded);\"><img src=\"$imgpath/close.gif\" /></span>" : '')."<span class=\"s3 f12 fn\">{$lang[post_reply]}</span></h6><blockquote class=\"blockquote\">".str_replace("\n","<br />",$code)."</blockquote></div>";
}
function relatetag($message,$tags){
	$tags = explode(' ',$tags);
	foreach($tags as $key=>$tag){
		$message = preg_replace("/(?<=[\s\"\]>()]|[\x7f-\xff]|^)(".preg_quote($tag, '/').")([.,:;-?!()\s\"<\[]|[\x7f-\xff]|$)/siUe","tagfont('\\1','\\2')",$message,1);
	}
	return $message;
}
function tagfont($tag,$code){
	static $rlt_id = 0;
	$rlt_id++;
	return "<span onclick=\"sendmsg('pw_ajax.php','action=relatetag&tagname=$tag',this.id)\" style=\"cursor:pointer;border-bottom: 1px solid #FA891B;\" id=\"rlt_$rlt_id\">$tag</span>$code";
}
?>