分类:
2008-05-17 17:25:15
插件演示地址:Discuz!论坛实现高亮:
插件添加步骤如下:
修改include/discuzcode.func.php
查找
[php]function codedisp($code) {
global $discuzcodes;
$discuzcodes['pcodecount']++;
$code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "", $code)));
$discuzcodes['codehtml'][$discuzcodes['pcodecount']] = tpl_codedisp($discuzcodes, $code);
$discuzcodes['codecount']++;
return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
}[/php]
在下面添加:
CODE:
function phpcodedisp($code) {
global $discuzcodes;
$discuzcodes['pcodecount']++;
$code = phphighlite(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "", $code)));
$discuzcodes['codehtml'][$discuzcodes['pcodecount']] = "
{$code}
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, '?');
$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) {
$message = preg_replace("/\s*\[php\](.+?)\[\/php\]\s*/ies", "phpcodedisp('\\1')", $message);
}[/php]修改include/javascript/editor.js
查找
CODE:
insertText(text, strlen(opentag), strlen(closetag), in_array(tagname, ['code', 'quote', 'free', 'hide']) ? true : false);
修改为
CODE:
insertText(text, strlen(opentag), strlen(closetag), in_array(tagname, ['code', 'quote', 'free', 'hide', 'php']) ? true : false);
继续修改include/javascript/editor.js
查找
CODE:
if(in_array(cmd, ['quote', 'code', 'free', 'hide'])) {
修改为
CODE:
if(in_array(cmd, ['quote', 'code', 'free', 'hide', 'php'])) {
6.修改templates/default/post_bbinsert.htm
查找
CODE: