<?php
if (defined('ISDVBBS') === false OR defined('ROOT_PATH') === false) {
	header('HTTP/1.0 404 Not Found');
	exit;
}
!defined('TIME_NOW') AND define('TIME_NOW', time());
//require_once CACHE_PATH.'space/space_config.php';
require_once INC_PATH.'dv_code.php';

function &getTitleNote(&$str, $start=0, $length=150)
{
	$titlenote = '';
	$content = trim($str);
	if ('' === $content) {
		return $titlenote;
	}
	static $filter;
	if (!isset($filter)) {
		$htmlfilter = new HtmlFilter();
	}
	if ($length > 500) {
		$length = 500;
	}
	if ($length <= 0) {
		$length = 150;
	}
	$titlenote =& $htmlfilter->SubString($content, $start, $length);
	if ('' !== $titlenote) {
		$titlenote = preg_replace(array('#<(\w+?)>\s*</\1>#i', '#(<br */?><br */?>)+#i', '#(<p><br */?></p>)+#i', '#(<p></p>)+#i', '#(<div></div>)+#i'), '', $titlenote);
	}
	return $titlenote;
}//end function getTitleNote
function checkText($_argString)
{
	if ($space_name === '' OR preg_match('#=|%|\?|&|;|,|\'|'.chr(34).'|'.chr(9).'|\$|\|#i',$space_name) === 1 OR preg_match('#^(?:\s|||'.chr(32).')+$#i',$space_name) === 1) {
		return false;
	} else{
		return true;
	}
}

function &CheckAlipay()
{
	$_strSeller = trim($GLOBALS['alipay_seller']);
	$_strSubject = trim($GLOBALS['alipay_subject']);
	$_strMessage = trim($GLOBALS['postcontent']);
	$_strPrice = trim($GLOBALS['alipay_price']);
	if ($_strSeller === '@' OR $_strSeller === '' OR $_strSubject === '' OR !is_numeric($_strPrice) OR $_strMessage === '') {
		return '';
	}
	$_strTransport = trim($GLOBALS['ialipay_transport']);
	$_strMail = trim($GLOBALS['alipay_mail']);
	$_strExpress = trim($GLOBALS['alipay_express']);
	$_strDemo = trim($GLOBALS['alipay_demo']);
	$_strWW = trim($GLOBALS['alipay_ww']);
	$_strQQ = trim($GLOBALS['alipay_qq']);
	$_strReturnVal = "[payto](seller){$_strSeller}(/seller)(subject){$_strSubject}(/subject)(body){$_strMessage}(/body)(price){$_strPrice}(/price)(transport){$_strTransport}(/transport)";
	if ($_strMail !== '' AND is_numeric($_strMail)) {
		$_strReturnVal .= "(ordinary_fee){$_strMail}(/ordinary_fee)";
	}
	if ($_strExpress !== '' AND is_numeric($_strExpress)) {
		$_strReturnVal .= "(express_fee){$_strExpress}(/express_fee)";
	}
	if ($_strDemo !== '' AND strtolower($_strDemo) !== 'http://') {
		$_strReturnVal .= "(demo){$_strDemo}(/demo)";
	}
	if ($_strWW !== '') {
		$_strReturnVal .= "(ww){$_strWW}(/ww)";
	}
	if ($_strQQ !== '') {
		$_strReturnVal .= "(qq){$_strQQ}(/qq)";
	}
	$_strReturnVal .= '[/payto]';
	return $_strReturnVal;
}

function SysDeleteFile($_argPostID)
{
	global $dv,$db,$spaceSystemUpSetting;
	if (!is_numeric($_argPostID) ) return false;
	$_filePath = $spaceSystemUpSetting[19];
	if ($_query =$db->query("SELECT id,filename,previewimage,filesize,spaceuserid FROM {$dv}space_upfile WHERE postid='{$_argPostID}'")) {
		while ($_result = $db->fetch_array($_query)) {
			$_destFile = $_filePath.$_result['filename'];
			if (!file_exists($_destFile)) {
				$_destFile = $_result['filename'];
			}
			if (file_exists($_destFile) ) @unlink($_destFile);
			if (file_exists($_result['previewimage']) ) @unlink($_result['previewimage']);
			
			if ($_result['filesize'] > 0) {//返还文件空间
				$_intFileSize = number_format(((float)$_result['filesize']/1024)/1024,4);
				$db->query("UPDATE {$dv}space_user SET spacesize=spacesize+'{$_intFileSize}' WHERE userid='{$_result['spaceuserid']}' AND spacesize<>-1");
			}
			//删除附件表记录
			$db->query("DELETE FROM {$dv}space_upfile WHERE id='{$_result['id']}'");
		}
	}
}

function &spaceFomatPostCode(&$strCode)//编辑格式化数据
{
	global $spaceUserCat;
	if (empty($strCode)) {
		return $strCode;
	}
	$spacekeyword =& $spaceUserCat['spacekeyword'];
	if (!empty($spacekeyword) AND is_array($spacekeyword)) {
		$target = '';
		foreach ($spacekeyword AS $val ) {
			if ($val['newwindows'] == 1) {
				$target = ' target="_blank" ';
			} else {
				$target = '';
			}
			$link = "<a href=\"{$val['linkurl']}\" title=\"{$val['linktitle']}\" class=\"spacekeyword\" {$target}>{$val['nkeyword']}</a>";
			$strCode = str_replace($link, $val['keyword'], $strCode);
		}
	}
	return $strCode;
}

function &spaceFormatCode(&$strCode)//提交格式化数据
{
	global $spaceUserCat;
	if (empty($strCode)) {
		return $strCode;
	}
	$spacekeyword =& $spaceUserCat['spacekeyword'];
	if (!empty($spacekeyword) AND is_array($spacekeyword)) {
		$target = '';
		foreach ($spacekeyword AS $val ) {
			if ($val['newwindows'] == 1) {
				$target = ' target="_blank" ';
			} else {
				$target = '';
			}
			$link = "<a href=\"{$val['linkurl']}\" title=\"{$val['linktitle']}\" class=\"spacekeyword\" {$target}>{$val['nkeyword']}</a>";
			$strCode = str_replace($val['keyword'], $link, $strCode);
		}
	}
	$strCode = preg_replace(
			 array(
				 '/<(\w*) class\s*=\s*([^>|\s]*)([^>]*)>/i'
				,'/<(\w*) style\s*=\s*([^>|\s]*)([^>]*)>/i'
				, '/<(\w[^>|\s]*)([^>]*)(on(finish|mouse|Exit|error|click|key|load|change|focus|blur))(.[^>]*)>/i'
				,'/<(\w[^>|\s]*)([^>]*)(&#|window\.|javascript:|js:|about:|file:|Document\.|vbs:|cookie| name| id)(.[^>]*)>/i'
			 )
			,array('<$1$3>', '<$1$3>', '<$1$2>', '<$1$2>')
			,$strCode
	);
	return $strCode;
}

function &spaceUbbCode(&$strCode, $imgaddjscode = true)//显示标记转换
{
	global $lang, $spaceSystemSetting, $spaceSystemUpSetting;
	if (empty($strCode)) {
		return $strCode;
	}
	$arrPattern = array('/\r\n|\n/i', '/(<s+cript(.[^>]*)>)/i', '/<\/s+cript>/i', '/<\/p>\x0a+<p>/i', '/([^\x0d])\x0a/i', '/\x0d\x0a([^\x0d]*)/i', '/(<body(.[^>]*)>)/i', '/(<\!(.[^>]*)>)/i', '/(<\!)/i', '/(-->)/i', '/(javascript:)/i', '/<((asp|\!|%))/i', '/	/i', '/  /i', '/<(\w+)(&nbsp;)+([^>]*)>/i');
	$arrRepl = array('<br/>', '&lt;&#83cript$2&gt;', '&lt;/&#83cript&gt;', '<p></p>', '$1<br>', '<p>$1</p>', '<body>', '&lt;$2&gt;', '&lt;!', '--&gt;', '<i>javascript</i>:', '&lt;$1', '&nbsp;', '&nbsp;&nbsp;', '<$1 $3>');
//Start JavaScript过滤
	$arrPattern[] = '/(\<script(?:.*?)\>)|(\<\/script(?:.*?)\>)/ie';
	$arrRepl[] = 'htmlspecialchars("$1")';
//End JavaScript过滤
	$strlower = strtolower($strCode);
//Start [flash][/flash]
	if (strpos($strlower, '[/flash]') !== false) {
		$arrPattern[] = '/\[FLASH\]/i';
		$arrRepl[] = chr(1).'FLASH'.chr(2);
		$arrPattern[] = '/\[\/FLASH\]/i';
		$arrRepl[] = chr(1).'/FLASH'.chr(2);
		$arrPattern[] = '/\x01FLASH\x02(.[^\x01]*)\x01\/FLASH\x02/i';
		$arrRepl[] = '<a href="$1" target="_blank"><img src="images/filetype/swf.gif" border="0" title="'.$lang['space.ubbcode.str1'].'" />['.$lang['space.ubbcode.str2'].']</a><br /><object codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="500" height="400"><param name="movie" value="$1" /><param name="quality" VALUE="high" /><embed src="$1" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="500" height="400"><!--$1--></embed></object>';
		$arrPattern[] = '/\x02/i';
		$arrRepl[] = ']';
		$arrPattern[] = '/\x01/i';
		$arrRepl[] = '[';

		$arrPattern[] = '/\[FLASH=(.[^\[]*)\]/i';
		$arrRepl[] = chr(1).'FLASH=$1'.chr(2);
		$arrPattern[] = '/\[\/FLASH\]/i';
		$arrRepl[] = chr(1).'/FLASH'.chr(2);
		$arrPattern[] = '/\x01FLASH=*([0-9]*),*([0-9]*)\x02(.[^\x01]*)\x01\/FLASH\x02/i';
		$arrRepl[] = '<a href="$3" target="_blank"><img src="images/filetype/swf.gif" border="0" title="点击开新窗口欣赏该FLASH动画！"/>[全屏欣赏]</a><br /><object codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="$1" height="$2"><param name="movie" value="$3" /><param name="quality" value="high" /><embed src="$3" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="$1" height="$2">$3</embed></object>';
		$arrPattern[] = '/\x02/i';
		$arrRepl[] = ']';
		$arrPattern[] = '/\x01/i';
		$arrRepl[] = '[';
	}
//End [flash][/flash]
//Start [qt][/qt]
	if (strpos($strlower, '[/qt]') !== false) {
		$arrPattern[] = '/\[QT=(.[^\[]*)\]/i';
		$arrRepl[] = chr(1).'QT=$1'.chr(2);
		$arrPattern[] = '/\[\/QT\]/i';
		$arrRepl[] = chr(1).'/QT'.chr(2);
		$arrPattern[] = '/\x01QT=*([0-9]*),*([0-9]*)\x02(.[^\x01]*)\x01\/QT\x02/i';
		$arrRepl[] = '<embed src="$3" width="$1" height="$2" autoplay="true" loop="false" controller="true" playeveryframe="false" cache="false" scale="TOFIT" bgcolor="#000000" kioskmode="false" targetcache="false" pluginspage="http://www.apple.com/quicktime/"></embed>';
		$arrPattern[] = '/\x02/i';
		$arrRepl[] = ']';
		$arrPattern[] = '/\x01/i';
		$arrRepl[] = '[';
	}
//End [qt][/qt]
//Start [mp][/mp]
	if (strpos($strlower, '[/mp]') !== false) {
		$arrPattern[] = '/\[MP=(.[^\[]*)\]/i';
		$arrRepl[] = chr(1).'MP=$1'.chr(2);
		$arrPattern[] = '/\[\/MP\]/i';
		$arrRepl[] = chr(1).'/MP'.chr(2);
		$arrPattern[] = '/\x01MP=*([0-9]*),*([0-9]*),*([0|1|true|false]*)\x02(.[^\x01]*)\x01\/MP\x02/i';
		$arrRepl[] = '<object align="middle" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" class="OBJECT" id="MediaPlayer" width="$1" height="$2"><param name="AUTOSTART" VALUE="$3" /><param name="ShowStatusBar" value="-1" /><param name="Filename" value="$4" /><embed type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" flename="mp" src="$4" width="$1" height="$2"></embed></object>';
		$arrPattern[] = '/\x02/i';
		$arrRepl[] = ']';
		$arrPattern[] = '/\x01/i';
		$arrRepl[] = '[';
	}
//End [mp][/mp]
//Start [rm][/rm]
	if (strpos($strlower, '[/rm]') !== false) {
		$arrPattern[] = '/\[RM=(.[^\[]*)\]/i';
		$arrRepl[] = chr(1).'RM=$1'.chr(2);
		$arrPattern[] = '/\[\/RM\]/i';
		$arrRepl[] = chr(1).'/RM'.chr(2);
		$arrPattern[] = '/\x01RM=*([0-9]*),*([0-9]*),*([0|1|true|false]*)\x02(.[^\x01]*)\x01\/RM\x02/i';
		$arrRepl[] = '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" class="OBJECT" id="RAOCX" width="$1" height="$2"><param NAME="SRC" VALUE="$4" /><param NAME="CONSOLE" VALUE="$4" /><param NAME="CONTROLS" VALUE="imagewindow" /><param NAME="AUTOSTART" VALUE="$3" /></object><br/><object classid="CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA" height="32" id="video" width="$1"><param NAME="SRC" VALUE="$4" /><param NAME="AUTOSTART" VALUE="$3" /><param NAME="CONTROLS" VALUE="controlpanel" /><param NAME="CONSOLE" VALUE="$4" /></object>';
		$arrPattern[] = '/\x02/i';
		$arrRepl[] = ']';
		$arrPattern[] = '/\x01/i';
		$arrRepl[] = '[';
	}
//End [rm][/rm]
//Start [upload][/upload]
	if (strpos($strlower, '[/upload]') !== false) {
		global $fsetting;
		if (empty($fsetting)) {
			require_once CACHE_PATH.'forum_setting.php';
			$fsetting =& $_DCACHE['settings'];
		}
		$filepath = basename($fsetting['forumuploadname']).'/'.basename($spaceSystemUpSetting[19]).'/';
		$arrPattern[] = '/\[UPLOAD=(gif|jpg|jpeg|bmp|png|swf|swi)\]/i';
		$arrRepl[] = chr(1).'UPLOAD=$1'.chr(2);
		$arrPattern[] = '/\[\/UPLOAD\]/i';
		$arrRepl[] = chr(1).'/UPLOAD'.chr(2);
		$arrPattern[] = '/\x01UPLOAD=(gif|jpg|jpeg|bmp|png)\x02\x01\/UPLOAD\x02/i';
		$arrRepl[] = '';
		$arrPattern[] = '/\x01UPLOAD=(gif|jpg|jpeg|bmp|png)\x02(.[^\x01]*)\x01\/UPLOAD\x02/i';
		$arrRepl[] = '<br /><img src="images/filetype/$1.gif" border="0" /><br /><a href="'.$filepath.'$2" target="_blank"><img src="'.$filepath.'$2" border="0" alt="'.$lang['space.ubbcode.str3'].'" /></a>';
		$arrPattern[] = '/\x01UPLOAD=(swf|swi)\x02(.[^\x01]*)\x01\/UPLOAD\x02/i';
		$arrRepl[] = '<br /><img src="images/filetype/swf.gif" border="0" /><a href="'.$filepath.'$2" target="_blank">'.$lang['space.ubbcode.str4'].'</a>：<br /><embed src="'.$filepath.'$2" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="500" height="300"></embed>';
		$arrPattern[] = '/\x02/i';
		$arrRepl[] = ']';
		$arrPattern[] = '/\x01/i';
		$arrRepl[] = '[';
		$arrPattern[] = '/\[UPLOAD=(.[^\[]*)\]/i';
		$arrRepl[] = chr(1).'UPLOAD=$1'.chr(2);
		$arrPattern[] = '/\[\/UPLOAD\]/i';
		$arrRepl[] = chr(1).'/UPLOAD'.chr(2);
		$arrPattern[] = '/\x01UPLOAD=(.[^\x01]*)\x02\x01\/UPLOAD\x02/i';
		$arrRepl[] = '';
		$arrPattern[] = '/\x01UPLOAD=(.[^\x01]*)\x02(viewfile\.php.[^\x01]*)\x01\/UPLOAD\x02/i';
		$arrRepl[] = '<br /><img src="images/filetype/$1.gif" border="0" /> <a href="$2" target="_blank">'.$lang['space.ubbcode.str5'].'</a>';
		$arrPattern[] = '/\x01UPLOAD=(.[^\x01]*)\x02(.[^\x01]*)\x01\/UPLOAD\x02/i';
		$arrRepl[] = '<br /><img src="images/filetype/$1.gif" border="0" /><a href="$2" target="_blank">'.$lang['space.ubbcode.str5'].'</a><br /><img src="$2" border="0" />';
		$arrPattern[] = '/\x02/i';
		$arrRepl[] = ']';
		$arrPattern[] = '/\x01/i';
		$arrRepl[] = '[';
	}
//End [upload][/upload]
//Start [payto][/payto]
	if (strpos($strlower, '[/payto]') !== false) {
		$arrPattern[] = '/\[payto](.+?)\[\/payto]/eis';
		$arrRepl[] = '_InnerPaytoCodeProcess("$1","$0")';
	}
//End [payto][/payto]
//Start [code][/code]
	if (strpos($strlower, '[/code]') !== false) {
		$arrPattern[] = '/\[code\]/i';
		$arrRepl[] = chr(1).'code'.chr(2);
		$arrPattern[] = '/\[\/code\]/i';
		$arrRepl[] = chr(1).'/code'.chr(2);
		$arrPattern[] = '/\x01code\x02\x01\/code\x02/i';
		$arrRepl[] = '';
		$arrPattern[] = '/\x01code\x02(.[^\x01]*)\x01\/code\x02/i';
		$arrRepl[] = '<u>'.$lang['space.ubbcode.str0'].'</u><br/><div class="htmlcode">$1</div>';
		$arrPattern[] = '/\x02/i';
		$arrRepl[] = ']';
		$arrPattern[] = '/\x01/i';
		$arrRepl[] = '[';
	}
//End [code][/code]
	if (true === $imgaddjscode AND 1 == $spaceSystemSetting[11]) {
		$arrPattern[] = '#<img(.*?)(?:>|/>)#i';
		$arrRepl[] = '<img$1 onmousewheel="return bbimg(this)" onload="javascript:if(this.width>screen.width-500)this.style.width=screen.width-500;" />';
	}
	$returnval = preg_replace($arrPattern, $arrRepl, $strCode);
	return $returnval;
}
function &_imgaddjscode(&$data)
{
	$returnval = preg_replace('#<img(.*?)(?:>|/>)#i', '<img$1 onmousewheel="return bbimg(this)" onload="javascript:if(this.width>screen.width-500)this.style.width=screen.width-500;" />', $data);
	return $returnval;
}//end function _jscodeaddtoimg
function _InnerPaytoCodeProcess($match_1,$match_0)
{
	if( preg_match('/\(seller\)([^\n]+?)\(\/seller\)/i',$match_1,$sellerMatches) === 1 ){
		unset($sellerMatches[0]);
		if( preg_match('/\(subject\)([^\n]+?)\(\/subject\)/i',$match_1,$subjectMatches) === 1 ){
			unset($subjectMatches[0]);
			if( preg_match('/\(body\)(.*?)\(\/body\)/is',$match_1,$bodyMatches) === 1 ){
				unset($bodyMatches[0]);
				if( preg_match('/\(price\)([\d\.]+?)\(\/price\)/i',$match_1,$priceMatches) === 1 ){
					unset($priceMatches[0]);
					if( preg_match('/\(transport\)([1-3])\(\/transport\)/i',$match_1,$transportMatches) === 1 ){
						unset($transportMatches[0]);
						$isChecked = true;
						$arrTmp = array( '卖家承担运费' ,'买家承担运费' ,'虚拟物品不需邮递' );
						$strUrlTmp = '';
						$strMsgTmp = '';
						$iTmp = intval($transportMatches[1]);
						if( $iTmp === 2 ){
							if( preg_match('/\(express_fee\)([\d\.]+?)\(\/express_fee\)/i',$match_1,$express_feeMatches) === 1 ){
								unset($express_feeMatches[0]);
								$strUrlTmp .= '&transport='.$iTmp.'&express_fee='.doubleval($express_feeMatches[1]);
								$strMsgTmp .= '<b>邮递信息</b>：'.$arrTmp[$iTmp-1].'，快递 '.doubleval($express_feeMatches[1]).' 元<br/><br/>';
							} elseif( preg_match('/\(ordinary_fee\)([\d\.]+?)\(\/ordinary_fee\)/i',$match_1,$ordinary_feeMatches) === 1 ){
								unset($ordinary_feeMatches[0]);
								$strUrlTmp .= '&transport='.$iTmp.'&ordinary_fee='.doubleval($ordinary_feeMatches[1]);
								$strMsgTmp .= '<b>邮递信息</b>：'.$arrTmp[$iTmp-1].'，平邮 '.doubleval($ordinary_feeMatches[1]).' 元<br/><br/>';
							} else{
								return $match_0;
							}
						} else{
							$strUrlTmp .= '&transport='.$iTmp;
							$strMsgTmp .= '<b>邮递信息</b>：'.$arrTmp[$iTmp-1].'<br/><br/>';
						}
						$isChecked = false;
						if( preg_match('/\(ww\)([^\n]+?)\(\/ww\)/i',$match_1,$wwMatches) === 1 ){
							unset($wwMatches[0]);
							$strUtf8Tmp = EncodeUtf8($wwMatches[1]);
							$strMsgTmp .= '<b>联系方法</b>：<a target="_blank" href="http://amos1.taobao.com/msg.ww?v=2&uid='.$strUtf8Tmp.'&s=1"><img border="0" src="http://amos1.taobao.com/online.ww?v=2&uid='.$strUtf8Tmp.'"&s=1"/></a>';
							$isChecked = true;
						}
						if( preg_match('/\(qq\)(\d+?)\(\/qq\)/i',$match_1,$qqMatches) === 1 ){
							unset($qqMatches[0]);
							if( $isChecked === true ){
								$strMsgTmp .= '&nbsp;&nbsp;<a target="_blank" href="http://wpa.qq.com/msgrd?V=1&Uin='.$qqMatches[1].'&Site=Dvbbs.Net&Menu=yes"><img border="0" SRC="http://wpa.qq.com/pa?p=1:'.$qqMatches[1].':10" alt="联系我"></a><br/><br/>';
							} else{
								$strMsgTmp .= '<b>联系方法</b>：<a target="_blank" href="http://wpa.qq.com/msgrd?V=1&Uin='.$qqMatches[1].'&Site=Dvbbs.Net&Menu=yes"><img border="0" SRC="http://wpa.qq.com/pa?p=1:'.$qqMatches[1].':10" alt="联系我"></a><br/><br/>';
							}
						} elseif( $isChecked === true ){
							$strMsgTmp .= '<br/><br/>';
						}
						if( preg_match('/\(demo\)([^\n]+?)\(\/demo\)/i',$match_1,$demoMatches) === 1 ){
							unset($demoMatches[0]);
							$strUrlTmp .= '&url='.urlencode($demoMatches[1]);
							$strMsgTmp .= '<b>演示地址</b>：'.$demoMatches[1].'<br/><br/>';
						}
						return '<br/><b>商品名称</b>：'.$subjectMatches[1].'<br/><br/><b>商品说明</b>：'.$bodyMatches[1].'<br/><br/><b>商品价格</b>：'.$priceMatches[1].' 元<br/><br/>'.$strMsgTmp.'<a href="http://pay.dvbbs.net/payto.asp?seller='.urlencode($sellerMatches[1]).'&subject='.urlencode($subjectMatches[1]).'&body='.urlencode($bodyMatches[1]).'&price='.urlencode($priceMatches[1]).$strUrlTmp.'&partner=2088002048522272&type=1&readonly=true" target="_blank"><img src="images/alipay/alipay_7.gif" border="0" alt="通过支付宝交易，买卖都放心，免手续费、安全、快捷！"></a>&nbsp;&nbsp;<a href="http://server.dvbbs.net/dvbbs/alipay/b.htm" target="_blank"><font color="blue">查看交易帮助，买卖放心</font></a><br/>';
					}
				}
			}
		}
	}
	return $match_0;
}//end funciton _InnerPaytoCodeProcess

function spacepostform($argOpts=array())
{
	global $dv,$db,$userinfo,$_tStr,$_tStr_1,$lang,$s,$t,$_sTypeID,$m,$keyword,$_tpl_skinPath,$_tpl_spaceName,$spaceConfig_Syschatcat_parent;
	global $_tpl_spaceUrl,$spaceUserCat,$spaceSystemSetting,$spaceConfig_Syscat,$spaceSetting,$spaceConfig_syschatcat;
	static $_blnLangLoaded = false;
	if ($_blnLangLoaded === false) {
		$lang = load_lang($lang,'spacepostform');
		$_blnLangLoaded = true;
	}
	if (!isset($argOpts['Show_Upload'])) {//是否显示上传
		$argOpts['Show_Upload'] = 0;
	}
	if (!isset($argOpts['IsTopic'])) {
		$argOpts['IsTopic'] = 0;
	}
	if (!isset($argOpts['EditMode'])) {
		$argOpts['EditMode'] = 'Default';
	}
	if (!isset($argOpts['RootID'])) {
		$argOpts['RootID'] = 0;
	}
	if (!isset($argOpts['PostID'])) {
		$argOpts['PostID'] = 0;
	}
	if (!isset($argOpts['PostUserName'])) {
		$argOpts['PostUserName'] = '';
	}
	if (!isset($argOpts['CatID'])) {
		$argOpts['CatID'] = -1;
	}
	if (!isset($argOpts['sCatID'])) {
		$argOpts['sCatID'] = -1;
	}
	if (!isset($argOpts['sType'])) {
		$argOpts['sType'] = -1;//0=文章,1=收藏,2=链接,3=交易,4=相册
	}
	if (!isset($argOpts['PostUserID'])) {
		$argOpts['PostUserID'] = 0;
	}
	if (!isset($argOpts['Title'])) {
		$argOpts['Title'] = '';
	}
	if (!isset($argOpts['Content'])) {
		$argOpts['Content'] = '';
	}
	if (!isset($argOpts['JoinTime']) OR !isDate($argOpts['JoinTime']) OR !is_numeric($argOpts['JoinTime'])) {
		//$argOpts['JoinTime'] = date('Y-m-d');
		$argOpts['JoinTime'] = TIME_NOW + date('Z') - getUserTimeZoneOffset();
	}
	if (!isset($argOpts['IsLock'])) {
		$argOpts['IsLock'] = 0;
	}
	if (!isset($argOpts['IsBest'])) {
		$argOpts['IsBest'] = 0;
	}
	if (!isset($argOpts['Weather'])) {
		$argOpts['Weather'] = 0;
	}
	if (!isset($argOpts['MaxLen'])) {
		$argOpts['MaxLen'] = 250;
	}
	if (!isset($argOpts['PostTitleNote'])) {
		$argOpts['PostTitleNote'] = '';
	}
	$jscode = '';
	foreach ($lang['spaceStype'] AS $index => $stypeval) {
		if (!empty($spaceUserCat['result_set']) AND is_array($spaceUserCat['result_set'])) {
			$strtmp1 = '[';
			$strtmp2 = '[';
			$comma1 = '';
			$comma2 = '';
			foreach ($spaceUserCat['result_set'] AS $val) {
				if ($val['utype'] != $index ) continue;
				$strtmp1 .= "{$comma1}'{$val['ucatid']}'";
				$strtmp2 .= "{$comma2}'{$val['ucattitle']}'";
				$comma1 = ',';
				$comma2 = ',';
			}
			$strtmp1 .= ']';
			$strtmp2 .= ']';
			$jscode .= "\r\n\tspaceCat_ID[{$index}]={$strtmp1};\r\n\tspaceCat_Title[{$index}]={$strtmp2};\r\n";
		}
		if (!empty($spaceConfig_Syschatcat_parent[$index]) AND is_array($spaceConfig_Syschatcat_parent[$index])) {
			$strtmp1 = '[';
			$strtmp2 = '[';
			$comma1 = '';
			$comma2 = '';
			foreach ($spaceConfig_Syschatcat_parent[$index] AS $val) {
				if ($val['stype'] != $index ) continue;
				$strtmp1 .= "{$comma1}'{$val['scatid']}'";
				$strtmp2 .= "{$comma2}'{$val['scattitle']}'";
				$comma1 = ',';
				$comma2 = ',';
			}
			$strtmp1 .= ']';
			$strtmp2 .= ']';
			$jscode .= "\r\n\tspaceSCat_ID[{$index}]={$strtmp1};\r\n\tspaceSCat_Title[{$index}]={$strtmp2};\r\n";
		}
	}
	print <<<EOT
<script language="JavaScript">
	var spaceCat_ID = new Array();
	var spaceCat_Title = new Array();
	var spaceSCat_ID = new Array();
	var spaceSCat_Title = new Array();
	{$jscode}
</script>
EOT;
	$_tpl_PostUserName = htmlspecialchars($argOpts['PostUserName']);
	$_tpl_action = strtolower($argOpts['Action']);
	print <<<EOT
<script language="javascript" src="space/script/dv_main.js" type="text/javascript"></script>
<script language="javascript" src="space/script/dv_form.js" type="text/javascript"></script>
<script language="javascript" src="space/script/sel_calendar.js" type="text/javascript"></script>
<script type="text/javascript" src="space/edit_plus/fckeditor/fckeditor.js"></script>
<style type="text/css">
.DHtml_PostForm { width: 99%; vertical-align: top; text-align: center; padding: 0px; margin: 10px auto 0px auto; }
.DHtml_PostForm table { margin: 0px; padding: 0px; }
.DHtml_PostForm table tr { background-color: #F1F1F1; }
.DHtml_PostForm table td { text-align: left; }
</style>
<div class="DHtml_PostForm">
	<script type="text/JavaScript">
	<!--
	function OnSpaceFormSubmit(form)
	{
		if (!CheckPostForm(form)) {
			return false;
		}
		try {
			(window.frames['postcontent___Frame']) && (document.getElementById('postcontent').value = OSWEBXHTML.GetXHTML(window.frames['postcontent___Frame'].document.body));
		}//end try
		catch (e) {
			alert(e.description);
			return false;
		}//end catch
		return true;
	}//end function OnSpaceFormSubmit
	//-->
	</script>
<table border="0" width="100%" align="center" cellpadding="4" cellspacing="1" bgcolor="#999999">
<form method="post" action="{$_tpl_action}" name="PostForm" onSubmit="return OnSpaceFormSubmit(this);">
<input type="hidden" name="__upload_subdir" />
<input type="hidden" name="__upfileinfo" />
	<tr>
		<td height="20" colspan="2" class="reply_t1">{$lang['tpl.str1']}</td>
	</tr>
	<tr>
		<td width="20%" class="reply_t2">{$lang['tpl.str2']}</td>
		<td width="80%" class="reply_t3"><input type="text" name="postusername" value="{$_tpl_PostUserName}"/>
EOT;
	if ($spaceSetting[8] != 0) {
		print <<<EOT
		<!--{$isalipay}-->
			&nbsp;<a href="javascript:Dvbbs_foralipay('postcontent');"><img src="space/images/alipay/icon_alipay.gif" border="0" alt="{$lang['tpl.str3']}"></a>
EOT;
	}
	print <<<EOT
		</td>
	</tr>
EOT;
	if (( $argOpts['IsTopic'] == 1 AND $spaceSystemSetting[4] == 1 ) OR ( $argOpts['IsTopic'] != 1 AND $spaceSystemSetting[5] == 1 )) {
		$cercodehtml=get_cercode();
		print <<<EOT
	<!--{$getcode}-->
	<tr>
		<td class="reply_t2">{$lang['tpl.str4']}</td>
		<td class="reply_t3"><input type="text" name="getcode" maxlength="4" size="4" onfocus="setObjSize(document.getElementById('cercode'),100,24)" />&nbsp;<script language="javascript">document.write('<'+'script language="javascript" src="./dv_getcode.js.php?w=0&h=0&d='+Date()+'"></script'+'>');</script>
点击左边输入框获取验证码，请确认你的浏览器开启Flash和Javascript</td>
	</tr>
EOT;
	}
	if (!empty($userinfo['cachespacetopic']) AND $argOpts['Title'] == '') {
		$_tpl_Title = $userinfo['cachespacetopic'];
	} else{
		$_tpl_Title = htmlspecialchars($argOpts['Title']);
	}
	$_tpl_PostDate = gmdate('Y-m-d', $argOpts['JoinTime'] + getUserTimeZoneOffset());
	print <<<EOT
	<tr>
		<td class="reply_t2">{$lang['tpl.str6']}</td>
		<td class="reply_t3">
		<input type="text" name="title" size="50" onkeyup="javascript:Dv_Form.CheckLength(this,250);" value="{$_tpl_Title}"/>
		{$lang['tpl.str7']}<INPUT TYPE="text" name="ddatetime" value="{$_tpl_PostDate}" onfocus="show_cele_date(ddatetime,'','',ddatetime)"/>
		</td>
	</tr>
EOT;
	if ($argOpts['IsTopic'] == 1) {
		print <<<EOT
	<!--{$TopicFunction1}-->
	<tr>
		<td class="reply_t2">{$lang['tpl.str8']}</td>
		<td class="reply_t3">
		<input type="hidden" name="stype" value="{$argOpts['sType']}" />
		<Select Name="stype1" Size="1" disabled onchange="OchangeSel_sCat('scatid',this.options[this.selectedIndex].value);OchangeSel_Cat('catid',this.options[this.selectedIndex].value);">
EOT;
		foreach ($lang['spaceStype'] AS $index => $val) {
			print '<option value="'.$index.'" '.($argOpts['sType'] == $index ? ' selected ' : '').'>'.$val.'</option>';
		}
		print <<<EOT
		</Select>
		<select name="scatid" size="1">
		<option value="-1">{$lang['tpl.str14']}</Option>
EOT;
		$_arrTmp =& $spaceConfig_Syschatcat_parent[$argOpts['sType']];
		if ($_arrTmp !== false) {
			foreach ($_arrTmp as $_val) {
				if ($argOpts['sCatID'] == $_val['scatid']) {
					$_strSelected = ' selected="selected" ';
				} else{
					$_strSelected = '';
				}
				print <<<EOT
		<!--{$sCatList}-->
			<option value="{$_val['scatid']}" {$_strSelected}>{$_val['scattitle']}</option>
EOT;
			}
		}
		print <<<EOT
		</Select>
		<Select Name="catid" ID="catid" Size="1">
		<Option value="-1">{$lang['tpl.str15']}</Option>
		</Select>
		</td>
	</tr>
EOT;
	}
	if ($spaceSetting[8] != 0 AND $argOpts['sType'] == 3 AND $GLOBALS['action'] != 'edit') {
		if ($GLOBALS['spaceUserID'] > 0) {
			$_tpl_paytomail = $userinfo['useremail'];
		} else{
			$_tpl_paytomail = '';
		}
		print <<<EOT
	<!--{$Show_Payto}-->
	<tr>
		<td width="20%" class="reply_t2">{$lang['tpl.str16']}</td>
		<td width="80%" class="reply_t3"><input type="text" name="alipay_seller" size="20" value="{$_tpl_paytomail}"/>
		{$lang['tpl.str17']}</td>
	</tr>
	<tr>
		<td width="20%" class="reply_t2">{$lang['tpl.str18']}<BR/><a href="http://server.dvbbs.net/dvbbs/alipay/s.htm" target="_blank"><font color="blue">{$lang['tpl.str19']}</font></a>&nbsp;&nbsp;</td>
		<td width="80%" class="reply_t3"><input type="text" name="alipay_subject" size="30"/>
		{$lang['tpl.str56']}<input type="text" name="alipay_price" size="10" value="0"/> {$lang['tpl.str20']}
		</td>
	</tr>
	<tr>
		<td width="20%" class="reply_t2">{$lang['tpl.str21']}</td>
		<td width="80%" class="reply_t3">
			<input type=radio ID="ialipay_transport" name="ialipay_transport" value="3" onclick="document.getElementById('alipay_mail').disabled=true; document.getElementById('alipay_express').disabled=true;alipay_transport.value=3;"> {$lang['tpl.str22']}
			<input type=radio ID="ialipay_transport" name="ialipay_transport" checked value="1" onclick="document.getElementById('alipay_mail').disabled=true; document.getElementById('alipay_express').disabled=true;alipay_transport.value=1;"> {$lang['tpl.str23']}
			<input type=radio ID="ialipay_transport" name="ialipay_transport" value="2" onclick="document.getElementById('alipay_mail').disabled=false; document.getElementById('alipay_express').disabled=false;alipay_transport.value=2;"> {$lang['tpl.str24']}<BR>
			<input type="hidden" value="1" ID="alipay_transport">
			{$lang['tpl.str25']}<input type=text ID="alipay_mail" name="alipay_mail" style="width:45px" size=25 disabled> {$lang['tpl.str20']} &nbsp;&nbsp;
			{$lang['tpl.str26']}<input type=text ID="alipay_express" name="alipay_express" style="width:45px" size=25 disabled> {$lang['tpl.str27']}</td>
	</tr>
	<tr>
		<td width="20%" class="reply_t2">{$lang['tpl.str28']}</td>
		<td width="80%" class="reply_t3"><input type="text" name="alipay_demo" size="30" value="http://"/>
		{$lang['tpl.str29']}</td>
	</tr>
	<tr>
		<td width="20%" class="reply_t2">{$lang['tpl.str30']}</td>
		<td width="80%" class="reply_t3">{$lang['tpl.str31']}<input type="text" name="alipay_ww" size="10"/>{$lang['tpl.str32']}<input type="text" name="alipay_qq" size="9"/>
		{$lang['tpl.str33']}</td>
	</tr>
EOT;
	}
	if ('5' != $argOpts['sType']) {
		print <<<EOT
	<!--{$Show_Upload}-->
	<tr>
		<td class="reply_t2">{$lang['tpl.str34']}<input type="hidden" name="upfilerename" value=""/></td>
		<td class="reply_t3">
		<iframe name="UPLOADFRAME" frameborder="0" width="100%" height="24" scrolling="no" src="spaceupload.php?mode=UploadForm"></iframe></td>
	</tr>
EOT;
	}
	if (!empty($userinfo['cachespacebody']) AND $argOpts['Content'] == '') {
		$_tpl_Content = $userinfo['cachespacebody'];
	} else{
		$_tpl_Content = htmlspecialchars($argOpts['Content']);
	}
	if ($argOpts['sType'] == 2) {
		print <<<EOT
	<!--{$Show_PostContent}-->
	<tr>
		<td class="reply_t2">{$lang['tpl.str35']}</td>
		<td class="reply_t3"><input type="text" name="postcontent" value="{$_tpl_Content}" size="60"/></td>
	</tr>
EOT;
	} else{
		$_tpl_Editmode = $argOpts['EditMode'];
		print <<<EOT
	<!--{$Show_PostContent}-->
	<tr>
		<td class="reply_t2">{$lang['tpl.str36']}</td>
		<td class="reply_t3">
		<textarea rows="4" name="postcontent" id="postcontent">{$_tpl_Content}</textarea>		
		{$lang['tpl.str37']}<a href="javascript:onclick=PlayUbb('postcontent','FLASH');" alt="{$lang['tpl.str38']}">[FLASH]</a>
		<a href="javascript:onclick=PlayUbb('postcontent','RM');" alt="{$lang['tpl.str39']}">[RM]</a>
		<a href="javascript:onclick=PlayUbb('postcontent','MP');" alt="{$lang['tpl.str40']}">[MP]</a>
		<a href="javascript:onclick=PlayUbb('postcontent','QT');" alt="">[QT]</a>
		<a href="javascript:onclick=put_ubb('postcontent','CODE');" alt="{$lang['tpl.str41']}">[CODE]</a>
		</td>
	</tr>
	<script language="JavaScript">
	<!--
		window.onload = function()
	{
		var oFCKeditor = new FCKeditor( 'postcontent','100%','350px','{$_tpl_Editmode}' ) ;
		oFCKeditor.BasePath	= "space/edit_plus/fckeditor/" ;
		oFCKeditor.Config['SkinPath'] = "skins/office2003/"
		oFCKeditor.ReplaceTextarea() ;
	}
	//-->
	</script>
EOT;
	}
	if ($argOpts['IsTopic'] == 1) {
		$_tpl_Weather = $argOpts['Weather'];
		print <<<EOT
	<!--{$TopicFunction2}-->
EOT;
		if ($argOpts['sType'] == 2) {
			$_tpl_PostTitleNote = htmlspecialchars($argOpts['PostTitleNote']);
			print <<<EOT
<!--{$TitleNote}-->
	<tr>
		<td  class="reply_t2">{$lang['tpl.str42']}</td>
		<td  class="reply_t3">
		<input type="text" name="posttitlenote" value="{$_tpl_PostTitleNote}" size="60" onkeyup="javascript:Dv_Form.CheckLength(this,250);"/>
		</td>
	</tr>
EOT;
		} else{
			$_tpl_maxlen = $argOpts['MaxLen'];
			if (empty($_tpl_PostTitleNote)) {
				$_tpl_PostTitleNote = htmlspecialchars($argOpts['PostTitleNote']);
			}
			print <<<EOT
<!--{$TitleNote}-->
	<tr>
		<td  class="reply_t2">{$lang['tpl.str43']}</td>
		<td  class="reply_t3">[<a href="javascript:onclick=GetNode('postcontent','posttitlenote',{$_tpl_maxlen});" alt="{$lang['tpl.str44']}">{$lang['tpl.str45']}</a>]<br/>
		<textarea style="width:95%;height:50px;" name="posttitlenote" id="PostTitleNote">{$_tpl_PostTitleNote}</textarea>
		</td>
	</tr>
EOT;
		}
		$_tpl_stype = $argOpts['sType'];
		$_tpl_sCat_Val = $argOpts['sCatID'];
		$_tpl_Cat_Val = $argOpts['CatID'];
		$_tpl_Lock = $argOpts['IsLock'];
		$_tpl_Best = $argOpts['IsBest'];
print <<<EOT
<SCRIPT language="JavaScript">
	Dv_Form.Set_Select("stype","{$_tpl_stype}");
	Dv_Form.Set_Select("lock","{$_tpl_Lock}");
	Dv_Form.Set_Select("best","{$_tpl_Best}");
	Dv_Form.Weather_Select("weather","{$_tpl_Weather}","WeatherSrc","space/images/weather/");

	OchangeSel_sCat("scatid","{$_tpl_stype}","{$_tpl_sCat_Val}");
	OchangeSel_Cat("catid","{$_tpl_stype}","{$_tpl_Cat_Val}");
</SCRIPT>
EOT;
	}
	if ($argOpts['IsTopic'] == 1) {
		$_tpl_SearchKey = htmlspecialchars($argOpts['SearchKey']);
		print <<<EOT
	<!--{$TopicFunction3}-->
	<tr>
		<td class="reply_t2">{$lang['tpl.str46']}</td>
		<td class="reply_t3"><input type="text" name="searchkey" size="50" onkeyup="javascript:Dv_Form.CheckLength(this,250);" value="{$_tpl_SearchKey}"/>{$lang['tpl.str47']}
		</td>
	</tr>
	<tr>
		<td class="reply_t2">{$lang['tpl.str48']}</td>
		<td class="reply_t3">
		<select Name="lock" Size="1">
		<Option value="0">{$lang['tpl.str49']}</Option>
		<Option value="1">{$lang['tpl.str50']}</Option>
		<Option value="2">{$lang['tpl.str51']}</Option>
		<Option value="3">{$lang['tpl.str52']}</Option>
		</select>
		<select Name="best" Size="1">
		<Option value="0">{$lang['tpl.str53']}</Option>
		<Option value="1">{$lang['tpl.str54']}</Option>
		</select>
		<select Name="weather" Size="1" onchange="Chang(this.value,'WeatherSrc','space/images/weather/')">
EOT;
		$_arrWeatherA = explode('|',$spaceSystemSetting[13]);
		$_arrWeatherB = explode('|',$spaceSystemSetting[14]);
		foreach ($_arrWeatherA as $_index => $_val) {
			print <<<EOT
		<!--{$WeatherList}-->
			<Option value="{$_arrWeatherB[$_index]}|{$_index}">{$_val}</Option>
EOT;
		}
		print <<<EOT
		</Select>
		<img id="WeatherSrc" src="space/images/weather/sun.gif" border="0">
		</td>
	</tr>
EOT;
	}
	$_tpl_RootID = $argOpts['RootID'];
	$_tpl_PostID = $argOpts['PostID'];
print <<<EOT
	<tr>
		<td colspan="2" class="reply_t1" align="center" height="25px">
		<input type="hidden" name="rootid" value="{$_tpl_RootID}"/>
		<input type="hidden" name="postid" value="{$_tpl_PostID}"/>
		<input type="submit" name="submit" value="{$lang['tpl.str55']}"/>
		</td>
	</tr>
</form>
</table>
</div>
<br/>
<script language="JavaScript">
<!--
function Chang(picurl,V,S)
	{
		picurl=picurl.split("|");
		picurl=picurl[0];
		var pic=S+picurl
		if (picurl!=''){
		document.getElementById(V).src=pic;
		}
	}
//-->
</script>
EOT;
}
?>