插件演示地址:Discuz!论坛实现PHP代码高亮:http://www.phpq.net/bbs/thread-5-1-1.html www~phperz~com
插件添加步骤如下: php程序员站
修改include/discuzcode.func.php php程序员站
查找 [php]function codedisp($code) { global $discuzcodes; $discuzcodes['pcodecount']++; $code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code))); $discuzcodes['codehtml'][$discuzcodes['pcodecount']] = tpl_codedisp($discuzcodes, $code); $discuzcodes['codecount']++; return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]"; }[/php] php程序员站
在下面添加: CODE: www.phperz.com
function phpcodedisp($code) { global $discuzcodes; $discuzcodes['pcodecount']++; $code = phphighlite(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code))); $discuzcodes['codehtml'][$discuzcodes['pcodecount']] = "<div class=\"blockcode\"><span class=\"headactions\" onclick=\"copycode($('code{$discuzcodes['codecount']}'));\">复制内容到剪贴板</span><h5>HP代码:</h5><code id=\"code{$discuzcodes['codecount']}\">{$code}</code></div>"; $discuzcodes['codecount']++; return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]"; } php程序员站
function phphighlite($code) { if(!strpos($code,"<?\n") && !strpos($code,'<? ') && substr($code,0,2) != '<?') { $code = '<'.'?'.trim($code).'?'.'>'; $addedtags = 1; } ob_start(); $oldlevel = error_reporting(0); highlight_string($code); error_reporting($oldlevel); $buffer = ob_get_contents(); ob_end_clean(); if ($addedtags) { $openingpos = strpos($buffer, '?'); phperz~com $closingpos = strrpos($buffer, '?'); $buffer = substr($buffer, $openingpos+1, $closingpos-($openingpos+1)).substr($buffer, $closingpos+5); } $buffer = str_replace('"', "\"", $buffer); $buffer = str_replace(' ', '', $buffer); return $buffer; } 继续修改include/discuzcode.func.php 查找[php]if($parsetype != 1 && !$bbcodeoff && $allowbbcode) { $message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "codedisp('\\1')", $message); }[/php]在其下面添加:[php] if($parsetype != 1 && !$bbcodeoff && $allowbbcode) { php程序员站 $message = preg_replace("/\s*\[php\](.+?)\[\/php\]\s*/ies", "phpcodedisp('\\1')", $message); }[/php]修改include/javascript/editor.js php程序员之家
查找 CODE: phperz~com
insertText(text, strlen(opentag), strlen(closetag), in_array(tagname, ['code', 'quote', 'free', 'hide']) ? true : false); 修改为 CODE: www.phperz.com
insertText(text, strlen(opentag), strlen(closetag), in_array(tagname, ['code', 'quote', 'free', 'hide', 'php']) ? true : false); 继续修改include/javascript/editor.js phperz.com
查找 CODE: www.phperz.com
if(in_array(cmd, ['quote', 'code', 'free', 'hide'])) { 修改为 CODE: phperz.com
if(in_array(cmd, ['quote', 'code', 'free', 'hide', 'php'])) { 6.修改templates/default/post_bbinsert.htm php程序员站
查找 CODE: www~phperz~com
<td><a id="{$editorid}_cmd_code"><img src="images/common/bb_code.gif" title="{lang post_discuzcode_code}" alt="Code" /></a></td> 在下面添加 CODE: phperz.com
<td><a id="{$editorid}_cmd_php"><img src="images/common/bb_php.gif" title="HP代码" alt="php" /></a></td> 然后上传bb_php.gif到 images/common 目录下 php程序员站
|