让 Discuz7.2在bbcode off下也解析 ‘最后编辑’标签

DZ在编辑帖子之后会在帖子内容之前附加上字符串

[i=s]本帖最后由 waiting 于 2011-11-3 17:10 编辑[/i]

 

 当浏览帖子时如果 bbcodeoff == false则解析为如下的HTML代码:

<i class="pstatus">本帖最后由 waiting 于 2011-11-3 17:10 编辑</i>

 

 不过当bbcodeoff == true则不解析而原样输出。

 

编辑 include/discuzcode.func.php 文件让DZ在不解析bbcode时依旧能且仅能解析‘最后编辑’的标签:

 

大约在135行,找到

if(!$bbcodeoff && $allowbbcode) {
...
}
      

 这个段落,整段替换如下:

 

	if($allowbbcode) {
		if (!$bbcodeoff) {  // <------- 单独判断,小节内代码不变
			if(strpos($msglower, '[/url]') !== FALSE) {
				$message = preg_replace("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.|mailto:)([^\s\[\"']+?))?\](.+?)\[\/url\]/ies", "parseurl('\\1', '\\5')", $message);
			}
			if(strpos($msglower, '[/email]') !== FALSE) {
				$message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "parseemail('\\1', '\\4')", $message);
			}
			$message = str_replace(array(
				'[/color]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[s]', '[/s]', '[hr]', '[/p]',
				'[i=s]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
				'[list=A]', '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
			), array(
				'</font>', '</font>', '</font>', '</p>', '<strong>', '</strong>', '<strike>', '</strike>', '<hr class="solidline" />', '</p>', '<i class="pstatus">', '<i>',
				'</i>', '<u>', '</u>', '<ul>', '<ul type="1" class="litype_1">', '<ul type="a" class="litype_2">',
				'<ul type="A" class="litype_3">', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>'
			), preg_replace(array(
				"/\[color=([#\w]+?)\]/i",
				"/\[size=(\d+?)\]/i",
				"/\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]/i",
				"/\[font=([^\[\<]+?)\]/i",
				"/\[align=(left|center|right)\]/i",
				"/\[p=(\d{1,2}), (\d{1,2}), (left|center|right)\]/i",
				"/\[float=(left|right)\]/i"

			), array(
				"<font color=\"\\1\">",
				"<font size=\"\\1\">",
				"<font style=\"font-size: \\1\">",
				"<font face=\"\\1 \">",
				"<p align=\"\\1\">",
				"<p style=\"line-height: \\1px; text-indent: \\2em; text-align: \\3;\">",
				"<span style=\"float: \\1;\">"
			), $message));
			$nest = 0;
			while(strpos($msglower, '[table') !== FALSE && strpos($msglower, '[/table]') !== FALSE){
				$message = preg_replace("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/ies", "parsetable('\\1', '\\2', '\\3')", $message);
				if(++$nest > 4) break;
			}

			if($parsetype != 1) {
				if(strpos($msglower, '[/quote]') !== FALSE) {
					$message = preg_replace("/\s?\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s?/is", tpl_quote(), $message);
				}
				if(strpos($msglower, '[/free]') !== FALSE) {
					$message = preg_replace("/\s*\[free\][\n\r]*(.+?)[\n\r]*\[\/free\]\s*/is", tpl_free(), $message);
				}
			}
			if(strpos($msglower, '[/media]') !== FALSE) {
				$message = preg_replace("/\[media=([\w,]+)\]\s*([^\[\<\r\n]+?)\s*\[\/media\]/ies", $allowmediacode ? "parsemedia('\\1', '\\2')" : "bbcodeurl('\\2', '<a href=\"%s\" target=\"_blank\">%s</a>')", $message);
			}
			if($allowmediacode && strpos($msglower, '[/audio]') !== FALSE) {
				$message = preg_replace("/\[audio\]\s*([^\[\<\r\n]+?)\s*\[\/audio\]/ies", "parseaudio('\\1')", $message);
			}
			if($allowmediacode && strpos($msglower, '[/flash]') !== FALSE) {
				$message = preg_replace("/\[flash\]\s*([^\[\<\r\n]+?)\s*\[\/flash\]/is", "<script type=\"text/javascript\" reload=\"1\">document.write(AC_FL_RunContent('width', '550', 'height', '400', 'allowNetworking', 'internal', 'allowScriptAccess', 'never', 'src', '\\1', 'quality', 'high', 'bgcolor', '#ffffff', 'wmode', 'transparent', 'allowfullscreen', 'true'));</script>", $message);
			}
			if($parsetype != 1 && $allowbbcode == 2 && $GLOBALS['_DCACHE']['bbcodes']) {
				$message = preg_replace($GLOBALS['_DCACHE']['bbcodes']['searcharray'], $GLOBALS['_DCACHE']['bbcodes']['replacearray'], $message);
			}
			if($parsetype != 1 && strpos($msglower, '[/hide]') !== FALSE) {
				if(strpos($msglower, '[hide]') !== FALSE) {
					if($GLOBALS['authorreplyexist'] === '') {
						$GLOBALS['authorreplyexist'] = !$GLOBALS['forum']['ismoderator'] ? $db->result_first("SELECT pid FROM {$tablepre}posts WHERE tid='$tid' AND ".($discuz_uid ? "authorid='$discuz_uid'" : "authorid=0 AND useip='$GLOBALS[onlineip]'")." LIMIT 1") : TRUE;
					}
					if($GLOBALS['authorreplyexist']) {
						$message = preg_replace("/\[hide\]\s*(.+?)\s*\[\/hide\]/is", tpl_hide_reply(), $message);
					} else {
						$message = preg_replace("/\[hide\](.+?)\[\/hide\]/is", tpl_hide_reply_hidden(), $message);
						$message .= '<script type="text/javascript">replyreload += \',\' + '.$pid.';</script>';
					}
				}
				if(strpos($msglower, '[hide=') !== FALSE) {
					$message = preg_replace("/\[hide=(\d+)\]\s*(.+?)\s*\[\/hide\]/ies", "creditshide(\\1,'\\2', $pid)", $message);
				}
			}
		}
		// 添加开始
             elseif ($bbcodeoff && substr($message, 0, 5) === '[i=s]') {		// allow parse '[i=s]last modified by [/i]' even if bbcodeoff
				$message = preg_replace( "/\[i=s\](.*)\[\/i\]/", "<i class=\"pstatus\">\\1</i>", $message );
		} // 添加结束
	}
 

 

 

 

你可能感兴趣的:(discuz)