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

PHP
php 远程图片保存到本地的函数类
php 破解防盗链图片函数
快速开发一个PHP扩展图文教程
PHP6 mysql连接方式说明
php 进度条实现代码
php discuz 主题表和回帖表的设计
php 无限级缓存的类的扩展
php adodb操作mysql数据库
php FPDF类库应用实现代码
sourcesafe管理phpproj文件的补充说明(downmoon)
AspNetAjaxPager,Asp.Net通用无刷新Ajax分页控件,支持多样式多数据绑定
php一句话cmdshell新型 (非一句话木马)
php 木马的分析(加密破解)
PHP 数组入门教程小结
php 方便水印和缩略图的图形类
PHP加速 eAccelerator配置和使用指南
PHP 组件化编程技巧
IIS6+PHP5+MySQL5+Zend Optimizer+phpMyAdmin安装配置图文教程 2009年
两个强悍的php 图像处理类1
PHP 数据库 常见问题小结

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


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

打包文件下载