当前位置: 首页 > 图文教程 > 网络编程 > PHP > Discuz5.5.0代码高亮显示+运行代码框合成插件 下载

PHP
PHP 开发环境的选择、建立及使用(5)
PHP 开发环境的选择、建立及使用(6)
PHP 开发环境的选择、建立及使用(7)
PHP 开发环境的选择、建立及使用(8)
PHP 开发环境的选择、建立及使用(9)
Win2003下APACHE PHP5 MYSQL4 PHPMYADMIN 的简易安装配置
PHP新手上路(八) 文件上传
PHP新手上路(九) 投票系统
PHP新手上路(十) 简易banner动态更替
PHP新手上路(十一) 数据库链接
PHP新手上路(十二)使用PHP来操作Oracle数据库
PHP新手上路(十三)PHP资源
PHP新手上路(十四) 其他杂项
session全教程(一)
session全教程(二)
session全教程(三)
PHP编码规范
第十五节--Zend引擎的发展 -- Classes and Objects in PHP5 [15]
第十四节--命名空间 -- Classes and Objects in PHP5 [14]
第十二节--类的自动加载 -- Classes and Objects in PHP5 [12]

PHP 中的 Discuz5.5.0代码高亮显示+运行代码框合成插件 下载


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 217 ::
收藏到网摘: n/a

主要功能:
1.几乎支持所有程序代码的高亮显示,包括以下语言:Actionscript、ADA、Apache Log、AppleScript、ASM、ASP、AutoIT、Backus-Naur form、Bash、BlitzBasic、C、C for Macs、C#、C++、CAD DCL、CadLisp、CFDG、CFDG、ColdFusion、CSS、Delphi、DIV、DOS、Eiffel、Fortran、Fortran、FreeBasic、GML、Groovy、HTML、Inno、IO、Java、Java 5、Javascript、LaTeX、Lisp、Lua、Microprocessor ASM、mIRC、MySQL、NSIS、Objective C、OCaml、OpenOffice BASIC、Oracle 8 SQL、Pascal、Perl、PHP、PL/SQL、Python、Q(uick)BASIC、robots.txt、Ruby、SAS、Scheme、SDLBasic、Smalltalk、Smarty、SQL、T-SQL、TCL、thinBasic、Uno IDL、VB.NET、Visual BASIC、Visual Fox Pro、Winbatch、X++、XML、Z80 ASM等等。
2.代码运行框,含复制代码、运行代码、另存代码三项功能。
使用方法:
1.如果你想高亮一种语言代码,可以使用下面的格式:
[languge=html]这里是HTML代码[/language]
[languge=xml]这里是XML代码[/language]
[languge=css]这里是CSS代码[/language]
[languge=javascript]这里是Javascript代码[/language]
[languge=asp]这里是ASP代码[/language]
[languge=php]这里是PHP代码[/language]
[languge=java]这里是Java代码[/language]
[languge=cpp]这里是C++代码[/language]
[languge=csharp]这里是C#代码[/language]
[languge=mysql]这里是Mysql代码[/language]
2.如果你只是想一段代码可以运行,则可以使用默认的
复制代码 代码如下:
格式。
安装方法:
1.下载解压压缩包,如果你使用的是默认模板,并且以前没有修改过以下几个文件:
/viewthread.php
/include/discuzcode.func.php
/include/global.func.php
/include/javascript/common.js
那么,您可以直接将其解压缩后的文件上传到网站根目录即可,其他模板可以参照后面的修改方法进行修改。
2.如果您以前修改过其中的一些或所有文件,你可以按照以下的说明,修改你以前修改过的文件,没有修改过的就直接上传覆盖就可以了:
(1)/viewthread.php
找到:
[code]
$post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], $post['htmlon'], $forum['allowsmilies'], $forum['allowbbcode'], ($forum['allowimgcode'] && $showimages ? 1 : 0), $forum['allowhtml'], ($forum['jammer'] && $post['authorid'] != $discuz_uid ? 1 : 0), $pasetype, $post['authorid']);

改为
复制代码 代码如下:

$post['message'] = discuzcode($post['message'], $post['smileyoff'], $post['bbcodeoff'], $post['htmlon'], $forum['allowsmilies'], $forum['allowbbcode'], ($forum['allowimgcode'] && $showimages ? 1 : 0), $forum['allowhtml'], ($forum['jammer'] && $post['authorid'] != $discuz_uid ? 1 : 0), $pasetype, $post['authorid'],$thread['subject']); //-----zouql代码运行开始------ $post['message'] = preg_replace("/\s*id=\"cmsmb_htmlcode\"(.+?)textarea\s*/ies", "cmsmb_no_br('$1')", $post['message']); //----------------------------


(2)/include/discuzcode.func.php
①找到:
复制代码 代码如下:

if(!defined('IN_DISCUZ')) {

前面添加
复制代码 代码如下:

include_once('geshi.php');

②将下面这段代码放在其它函数结束的地方添加,比如:
找到:
复制代码 代码如下:

return ($htmlon || $allowhtml) && $parsetype != 1 ? $message : nl2br(str_replace(array("\t", ' ', ' '), array(' ', ' ', ' '), $message));}

在后面添加:
//分析语言高亮显示
复制代码 代码如下:

function paste_language($language,$text) { $text = str_replace(" ", " ", $text); $text = str_replace(">", ">", $text); $text = str_replace("<", "<", $text); $text = str_replace("&", "&", $text); $text = str_replace(""", '"', $text); $text =& new geshi($text,$language); // Enable line numbers. We want fancy line numbers, and we want every 5th line number to be fancy $text->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5); $text->set_overall_style('font:12px Verdana, Courier, monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #fff;', true); $text->set_line_style('font:12px Verdana, Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true); $text->set_code_style('font:12px Verdana, Courier, monospace; color: #000020;', 'color: #000020;'); $text->set_link_styles(GESHI_LINK, 'color: #000060;'); $text->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;'); $text->set_header_content('54geek.com © 2007. 代码语言:'.$language); $text->set_header_content_style('font-family: Arial,Verdana,sans-serif; color: #808080; font-size: 12px; background-color: #f0f0ff; border-bottom: 1px dotted #d0d0d0; padding: 2px;'); $text->set_footer_content('Parsed in <TIME> seconds, using GeSHi <VERSION>'); $text->set_footer_content_style('font-family: Arial,Verdana,sans-serif; color: #808080; font-size: 12px; background-color: #f0f0ff; border-top: 1px dotted #d0d0d0; padding: 2px;'); //echo "$text->parse_code()"; //return preg_replace("#<br />#", "", $text->parse_code()); return $text->parse_code(); }


③找到
复制代码 代码如下:

function discuzcode($message, $smileyoff, $bbcodeoff, $htmlon = 0, $allowsmilies = 1, $allowbbcode = 1, $allowimgcode = 1, $allowhtml = 0, $jammer = 0, $parsetype = '0', $authorid = '0') {

改为
复制代码 代码如下:

function discuzcode($message, $smileyoff, $bbcodeoff, $htmlon = 0, $allowsmilies = 1, $allowbbcode = 1, $allowimgcode = 1, $allowhtml = 0, $jammer = 0, $parsetype = '0', $authorid = '0', $title='') {

④找到:
复制代码 代码如下:

if($parsetype != 1 && !$bbcodeoff && $allowbbcode) { $message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "codedisp('\\1')", $message); }

改为
复制代码 代码如下:

if($parsetype != 1 && !$bbcodeoff && $allowbbcode) { $message = preg_replace("/\s*\[code\](.+?)\[\/code\]\s*/ies", "code_htmldisp('\\1','$title')", $message); //$message = preg_replace("/\s*\[html\](.+?)\[\/html\]\s*/ies", "code_htmldisp('\\1')", $message); }

⑤找到下面函数后:
复制代码 代码如下:

function codedisp($code) { global $discuzcodes; $discuzcodes['pcodecount']++; $code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code))); $discuzcodes['codehtml'][$discuzcodes['pcodecount']] = " [Copy to clipboard]CODE<img src=\"images/smilies/shy.gif\" smilieid=\"8\" border=\"0\" alt=\"\" />code"; $discuzcodes['codecount']++; return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";}

后面再加一个函数:
复制代码 代码如下:

function code_htmldisp($code,$mytitle='') { global $discuzcodes; $mytitle .= '-code'; $discuzcodes['pcodecount']++; $discuzcodes['codecount']++; $code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code))); $discuzcodes['codehtml'][$discuzcodes['pcodecount']] = "<div class=\"smalltxt\" style=\"margin:10px 0\"><textarea name=\"runcode$discuzcodes[codecount]\" rows=\"12\" cols=\"95\" id=\"cmsmb_htmlcode\">$code</textarea><br><input type=\"button\" value=\"运行代码\" onclick=\"runCode(runcode$discuzcodes[codecount])\"> <input type=\"button\" value=\"复制代码\" onclick=\"copycode(runcode$discuzcodes[codecount])\"> <input type=\"button\" value=\"另存代码\" onclick=\"saveCode(runcode$discuzcodes[codecount],'$mytitle$discuzcodes[codecount]')\"> 提示:您可以先修改部分代码再运行</div>"; return "[\tDISCUZ_CODE_$discuzcodes[pcodecount]\t]";}

⑥查找
复制代码 代码如下:

if(!in_array($parsetype, array(1, 2)) && preg_match("/\[hide=?\d*\].+?\[\/hide\]/is", $message)) {

在前面添加:
复制代码 代码如下:

$message = preg_replace("/\s*\[language=(.+?)\](.+?)\[\/language\]\s*/ies", "paste_language('\\1','\\2')", $message);

(3)/include/global.func.php
在顶部
复制代码 代码如下:

if(!defined('IN_DISCUZ')) { exit('Access Denied');}

后加入:
复制代码 代码如下:

//-----zouql代码运行开始------function cmsmb_no_br($str) { $cmsmb_ori = array('<br />', ' '); $cmsmb_new = array('', ' '); $str1 = str_replace($cmsmb_ori, $cmsmb_new, $str); $str1 = $str1."textarea"; return $str1;}//-------------------------------


(4)/include/javascript/common.js
在最后加入下面三个函数即可:
复制代码 代码如下:

function runCode(obj) { var winname = window.open('', "_blank", ''); winname.document.open('text/html', 'replace'); winname.opener = null // 防止代码对论坛页面修改 winname.document.write(obj.value); winname.document.close();}function copycode(obj) { var rng = document.body.createTextRange(); rng.moveToElementText(obj); rng.scrollIntoView(); rng.select(); rng.execCommand("Copy"); rng.collapse(false);}function saveCode(obj,name) { var myname = name + '.htm'; var winname = window.open('', '_blank', 'top=10000'); winname.document.open('text/html', 'replace'); winname.document.write(obj.value); winname.document.execCommand('saveas','',myname); winname.close();}

打包文件下载