| 这个运行代码框给需要的技术类网站使用,如果你用的比较少还是不要安装了 =========================================
 新增加2个实现此功能的方案
 后台添加discuz!自定义代码增加“运行代码框”功能 https://www.discuz.1314study.com/thread-16376-1-1.html
 通用的,让网页支持“运行代码框”的操作设置!https://www.discuz.1314study.com/thread-16377-1-1.html
 =========================================
 贴内效果
 运行代码框forDZ x2.0(附:手改方法)
 演示地址http://www.173orz.com/t49-1-1.html
 编辑器效果
 
   贴内效果
 
 
   
 
 附件中的文件已经修改好了,如果你的dx2.0程序下面涉及的文件没有做过修改的话,可以直接覆盖使用!(最新官方0629补丁)
 
 PS:如果你的风格使用的不是官方的默认风格,请务必按说明同时修改你的风格下的common/common.css、common/editor.css、forum/post_editor_body.htm这3个文件。
 下面是修改方法,需要修改程序的多个文件,请自行备份以防修改失误后能及时恢复!
 涉及修改文件列表:
 
 
 
 
 
 source/function/function_discuzcode.phpstatic/js/seditor.js
 static/js/editor.js
 static/js/forum.js
 template/default/common/common.css
 template/default/common/editor.css
 template/default/forum/post_editor_body.htm
手改方法看這裡吧
 
 附件中的文件已经修改好了,如果你的dx2.0程序下面涉及的文件没有做过修改的话,可以直接覆盖使用!
 
 附件下载:
 PS:如果你的风格使用的不是官方的默认风格,请务必按说明同时修改你的风格下的common/common.css、common/editor.css、forum/post_editor_body.htm这3个文件。
 
 下面是修改方法,需要修改程序的多个文件,请自行备份以防修改失误后能及时恢复!
 涉及修改文件列表:
 
 
 source/function/function_discuzcode.phpstatic/js/seditor.js
 static/js/editor.js
 static/js/forum.js
 template/default/common/common.css
 template/default/common/editor.css
 template/default/forum/post_editor_body.htm
source/function/function_discuzcode.php 查找
 下面添加
 复制代码/*运行代码star*/
'phtmlcount' => -1,
'htmlcount' => 0,
'htmlhtml' => '',
/*运行代码end*/
继续查找
 复制代码return tpl_hide_credits_hidden($creditsrequire);
}
}
下面添加
 复制代码/*运行代码star*/
function htmldisp($code) {
global $_G;
$_G['forum_discuzcode']['phtmlcount']++;
$code = dhtmlspecialchars(str_replace('\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code)));
$_G['forum_discuzcode']['htmlhtml'][$_G['forum_discuzcode']['phtmlcount']] = '<div class="runtxt"><textarea name="run'.$_G['forum_discuzcode'][htmlcount].'" id="run'.$_G['forum_discuzcode'][htmlcount].'" rows=12 cols=110>'.$code.'</textarea><br><input type="button" value="运行代码" onclick=runCode(run'.$_G['forum_discuzcode'][htmlcount].')> <input type="button" value="复制代码" onclick=copycode(run'.$_G['forum_discuzcode'][htmlcount].')> <input type="button" value="另存代码" onclick=saveCode(run'.$_G['forum_discuzcode'][htmlcount].')> <span>提示:您可以先修改部分代码再运行!<font color="red">目前暂时仅支持IE浏览器!</font></span></div><script language=JavaScript>ffcod=document.getElementById("run'.$_G['forum_discuzcode'][htmlcount].'").value;ffcod=ffcod.replace(/<br(.*)\/>/g,"");document.getElementById("run'.$_G['forum_discuzcode'][htmlcount].'").value=ffcod;</script>';
$_G['forum_discuzcode']['htmlcount']++;
return "[\tDISCUZ_HTML_".$_G['forum_discuzcode']['phtmlcount']."\t]";
}
/*运行代码end*/
继续查找
 复制代码$message = preg_replace("/\s?\[code\](.+?)\[\/code\]\s?/ies", "codedisp('\\1')", $message);
}
下面添加
 复制代码/*运行代码star*/
if($parsetype != 1 && !$bbcodeoff && $allowbbcode && (strpos($message, '[/html]') || strpos($message, '[/HTML]')) !== FALSE) {
$message = preg_replace("/\s?\[html\](.+?)\[\/html\]\s?/ies", "htmldisp('\\1')", $message);
}
/*运行代码end*/
继续查找
 复制代码for($i = 0; $i <= $_G['forum_discuzcode']['pcodecount']; $i++) {
$message = str_replace("[\tDISCUZ_CODE_$i\t]", $_G['forum_discuzcode']['codehtml'][$i], $message);
}
下面添加
 复制代码/*运行代码star*/
for($i = 0; $i <= $_G['forum_discuzcode']['phtmlcount']; $i++) {
$message = str_replace("[\tDISCUZ_HTML_$i\t]", $_G['forum_discuzcode']['htmlhtml'][$i], $message);
}
/*运行代码end*/
static/js/seditor.js查找
 复制代码var tagl = {'quote' : '请输入要插入的引用', 'code' : '请输入要插入的代码'};
修改为
 复制代码var tagl = {'quote' : '请输入要插入的引用', 'code' : '请输入要插入的代码', 'html' : '请输入要插入的代码'};
static/js/editor.js查找
 复制代码insertText(text, strlen(opentag), strlen(closetag), in_array(tagname, ['code', 'quote', 'free', 'hide']) ? true : false);
修改为
 复制代码insertText(text, strlen(opentag), strlen(closetag), in_array(tagname, ['code', 'quote', 'html', 'free', 'hide']) ? true : false);
继续查找
 复制代码if(in_array(cmd, ['sml', 'url', 'quote', 'code', 'free', 'hide', 'aud', 'vid', 'fls', 'attach', 'image', 'pasteword']) || cmd == 'tbl' || in_array(cmd, ['fontname', 'fontsize', 'forecolor', 'backcolor']) && !arg) {
修改为
 复制代码if(in_array(cmd, ['sml', 'url', 'quote', 'code', 'html','free', 'hide', 'aud', 'vid', 'fls', 'attach', 'image', 'pasteword']) || cmd == 'tbl' || in_array(cmd, ['fontname', 'fontsize', 'forecolor', 'backcolor']) && !arg) {
继续查找
 复制代码opentag = '<div class="blockcode"><blockquote>';
closetag = '</blockquote></div><br />';
}
下面添加
 继续查找
 复制代码var lang = {'quote' : '请输入要插入的引用', 'code' : '请输入要插入的代码', 'hide' : '请输入要隐藏的信息内容', 'free' : '如果您设置了帖子售价,请输入购买前免费可见的信息内容'};
修改为
 复制代码var lang = {'quote' : '请输入要插入的引用', 'code' : '请输入要插入的代码', 'html' : '请输入要插入的代码', 'hide' : '请输入要隐藏的信息内容', 'free' : '如果您设置了帖子售价,请输入购买前免费可见的信息内容'};
继续查找
 复制代码selection = selection ? selection : '\n';
}
}
这里有2个相同的,在第一个的下面添加
 static/js/forum.js最后添加
 复制代码function copyCode(obj) {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
function runCode(obj)
{
var code=obj.value;
var newwin=window.open('','','');
newwin.opener = null;
newwin.document.write(code);
newwin.document.close();
}
function saveCode(obj) {
var newwin = window.open('', '_blank', 'top=10000');
newwin.document.open('text/html', 'replace');
newwin.document.write(obj.value);
newwin.document.execCommand('saveas','','code.htm');
newwin.close();
}
template/default/common/common.css最后添加
 复制代码.runtxt{background:{COMMONBG};padding:10px;border:1px solid {COMMONBORDER};}
.runtxt textarea{font-family:Courier New,Courier,monospace;border:1px solid #ccc;width:100%;font-size:12px;color:#333}
.runtxt input{ margin-top:5px; border-left:1px solid {INPUTBORDER};border-right:1px solid {INPUTBORDERDARKCOLOR};border-top:1px solid {INPUTBORDER};border-bottom:1px solid {INPUTBORDERDARKCOLOR};background:{INPUTBG};color:{LIGHTLINK};}
.runtxt input{border-color:{INPUTBORDER} {INPUTBORDERDARKCOLOR} {INPUTBORDERDARKCOLOR} {INPUTBORDER};background:{MENUTEXT};}
.runtxt span{font-size:12px;color:#888;} 
template/default/common/editor.css查找
 复制代码#e_code { background-position: -123px -80px; }
.b2r #e_code{ background-position: -120px -20px; }
下面添加
 复制代码.b2r #e_html{ background:url(static/image/editor/html1.gif) no-repeat center center; }
template/default/forum/post_editor_body.htm查找
 复制代码<div class="b2r{if $_G['cache']['bbcodes_display'][$_G['groupid']]} nbr{/if}" id="{$editorid}_adv_6">
<p>
<a id="{$editorid}_code" title="{lang e_code_title}">{lang e_code}</a>
下面添加
 复制代码<a id="{$editorid}_html" title="添加运行的HTML代码">HTML</a>
   图标上传到static/image/editor/里
 
 
 |