Home  >  Article  >  Backend Development  >  Powered by discuz! PHP code highlighting plugin for Discuz!5 (Dancer in the Dark update)

Powered by discuz! PHP code highlighting plugin for Discuz!5 (Dancer in the Dark update)

WBOY
WBOYOriginal
2016-07-29 08:36:121109browse

discuz!5.0论坛显示风格的php代码高亮显示插件,
把php代码进行语法着色,喜欢PHP的同志可以轻松的看代码啦。
同时添加了html代码运行功能。
此插件是在以前某位同志发布的Discuz!4的php代码高亮显示基础之上修改完成。
另外,本人的php学习进入了停滞状态,
希望有人能帮助我走出php的学习困境
My QQ:5642382  我的QQ群:2577162
功能:发贴时使用[php]php代码[/php]标记来高亮显示php代码,
      使用[runcode]Html代码[/runcode]标记来运行HTML代码(在客户端运行非服务器)。
插件添加步骤如下:
1.修改include/common.js
  查找
function copycode(obj) {
        var rng = document.body.createTextRange();
        rng.moveToElementText(obj);
        rng.scrollIntoView();
        rng.select();
        rng.execCommand("Copy");
        rng.collapse(false);
}
在这个函数结束的下面添加:
[Copy to clipboard] [ - ]CODE:
function runCode(obj) { 
        var winname = window.open('', "_blank", ''); 
        winname.document.open('text/html', 'replace'); 
        winname.document.writeln(obj.value); 
        winname.document.close(); 

function saveCode(obj) { 
        var winname = window.open('', '_blank', 'top=10000'); 
        winname.document.open('text/html', 'replace'); 
        winname.document.writeln(obj.value); 
        winname.document.execCommand('saveas','','code.htm'); 
        winname.close(); 

2.修改include/discuzcode.func.php
  查找
[Copy to clipboard] [ - ]CODE:
        $discuzcodes['codecount']++;
        return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";
}
(注:也可以用Editplus直接查找到代码的第110行来进行下面的添加)
在下面继续添加:
/------- 添加 [runcode] Html代码 [/runcode] 来运行Html代码
function runcodedisp($code) { 
        global $discuzcodes; 
        $discuzcodes['pcodecount']++; 
        $code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code))); 
        $discuzcodes['codehtml'][$discuzcodes['pcodecount']] = "


/g,''); delpost.runcode$discuzcodes[codecount] .value = ffcod; 提示:您可以先修改部分代码再运行
& lt; br & gt; ";
$ discuzcodes ['codecount'] ++;
Return" [tdiscuz_code_ $ discuzcodes [pcodecount] t] "
// --------------- Add [php] php code [/php] to highlight php code and perform php syntax coloring
function phpcodedisp($code) {
            global $discuzcodes;  
          $discuzcodes['pcodecount']++;  
          $code = phphighlite(str_replace("\" ", """, $code));
$discuzcodes['codehtml'][$discuzcodes['pcodecount']] = "

"; code) {
       if(!strpos($code,"             $code = '<'.'?'.trim($code).' ?'.'>';                                                                                           ;
          $oldlevel = error_reporting(0) ;
          Highlight_string($code);                                                   use using {
                                                                                                                                                                                                                        Out               Out       Out     Out ’ Out ’ Out ’ Out Out Out           off off off 到到到账速度到;
             $closingpos = strrpos($buffer, '?'); .substr($buffer, $closingpos+5);
                                                                                                                                                                      substr ( $buffer);
return $buffer;
}
//------- End
3. Continue to modify include/discuzcode.func.php
Find
$message = preg_replace("/s*[code]( .+?)[/code]s*/ies", "codedisp('\1')", $message);
Continue to add below it:
[Copy to clipboard] [ - ]CODE:
//- ------ runcode
$message = preg_replace("/s*[runcode](.+?)[/runcode]s*/ies", "runcodedisp('\1')", $message);
//------- php
$message = preg_replace("/s*[php](.+?)[/php]s*/ies", "phpcodedisp('\1')", $message );
[This post was last edited by yzxicq0 on 2006-9-4 17:11 ]

The above introduces the PHP code highlighting plug-in for Discuz! 5 powered by discuz! (Dancer in the Dark update), including the content of powered by discuz!. I hope it will be helpful to friends who are interested in PHP tutorials.