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

PHP
利用discuz实现PHP大文件上传应用实例代码
php 遍历显示文件夹下所有目录、所有文件的函数,没有分页的代码
php在字符串中查找另一个字符串
php下HTTP Response中的Chunked编码实现方法
PHP实现定时生成HTML网站首页实例代码
PHP下一个非常全面获取图象信息的函数
PHP strtr() 函数使用说明
php 删除无限级目录与文件代码共享
php AJAX实例根据邮编自动完成地址信息
php miniBB中文乱码问题解决方法
cmd下运行php脚本
PHP 遍历XP文件夹下所有文件
php 移除数组重复元素的一点说明
discuz论坛 用户登录 后台程序代码
Optimizer与Debugger兼容性问题的解决方法
Zend Studio 无法启动的问题解决方法
php 页面执行时间计算代码
php smarty的预保留变量总结
php获取网页内容方法总结
php读取msn上的用户信息类

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 385 ::
收藏到网摘: 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();}

打包文件下载