tension 2008-2-6 11:03
为discuz 6.0 加上html代码运行框
[attach]4335[/attach]
[b]效果演示[/b]
[url]http://bbs.pickbar.com/thread-828-1-1.html[/url]
[url]http://www.pickbar.com/bbs/thread-44-1-2.html[/url]
[url]http://www.resday.com/bbs/thread-827-1-1.html[/url]
[b]修改过程[/b]
[color=Red]修改./include/discuzcode.func.php文件[/color]
找到:[code]'codehtml' => '',[/code]在其后添加:[code]'phtmlcount' => -1,
'htmlcount' => 0,
'htmlhtml' => '',[/code]找到:[code]function codedisp($code) {[/code]在其前添加:[code]function htmldisp($code) {
global $discuzcodes;
$discuzcodes['phtmlcount']++;
$code = htmlspecialchars(str_replace('\\"', '"', preg_replace("/^[\n\r]*(.+?)[\n\r]*$/is", "\\1", $code)));
$discuzcodes['htmlhtml'][$discuzcodes['phtmlcount']] = "
<DIV class=smalltxt style=\"MARGIN-TOP: 1em; MARGIN-BOTTOM: 1em\"><TEXTAREA name=\"run$discuzcodes[htmlcount]\" rows=12 cols=95>$code</TEXTAREA>
<INPUT onclick=runCode(run$discuzcodes[htmlcount]) type=button value=运行代码> <INPUT onclick=copycode(run$discuzcodes[htmlcount]) type=button value=复制代码> <INPUT onclick=saveCode(run$discuzcodes[htmlcount]) type=button value=另存代码> 提示:您可以先修改部分代码再运行</DIV>";
$discuzcodes['htmlcount']++;
return "[\tDISCUZ_html_$discuzcodes[phtmlcount]\t]";
}[/code]找到:[code]if(!$htmlon && !$allowhtml) {[/code]在其前添加:[code]if($parsetype != 1 && !$bbcodeoff && $allowbbcode) {
$message = preg_replace("/\s*\[html\](.+?)\[\/html\]\s*/ies", "htmldisp('\\1')", $message);
}[/code]找到:[code]return $htmlon || $allowhtml ? $message : nl2br(str_replace(array("\t", ' ', ' '), array(' ', ' ', ' '), $message));[/code]替换为:[code]$message= $htmlon || $allowhtml ? $message : nl2br(str_replace(array("\t", ' ', ' '), array(' ', ' ', ' '), $message));
for($i = 0; $i <= $discuzcodes['phtmlcount']; $i++) {
$message = str_replace("[ DISCUZ_html_$i ]", $discuzcodes['htmlhtml'][$i], $message);
}
return $message;[/code]上面这个要注意了,请看图示:
[attach]4336[/attach]
[color=DarkOrange]很多朋友改了不成功都是这里出了问题[/color]
[color=Red]修改./templates/default/viewthread.html文件[/color]
找到:[code]<!--{if !$iscircle || !empty($frombbs)}-->{template footer}<!--{else}-->[/code]在其前添加:[code]<!--{if $discuzcodes['htmlcount']}-->
<script>
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();
}
</script>
<!--{/if}-->[/code][color=Red]修改./include/javascript/editor.js文件[/color]
查找[code]in_array(tagname, ['code', 'quote', 'free', 'hide']) [/code]替换为[code]in_array(tagname, ['code', 'quote', 'html','free', 'hide']) [/code]查找[code]if(in_array(cmd, ['quote', 'code', 'free', 'hide'])) {[/code]替换为[code]if(in_array(cmd, ['quote', 'code','html', 'free', 'hide'])) {[/code][color=Red]修改./templates/default/post_editor.html文件[/color] (如果你使用模板不是默认模板请确认当前模板是否有post_editor.html文件,然后进行修改)
找到:[code]<!--{if $forum['allowbbcode'] && $allowcusbbcode}-->
<!--{loop $_DCACHE['bbcodes_display'] $tag $bbcode}-->
<td><a id="{$editorid}_cmd_custom{$bbcode[params]}_$tag"><img src="images/common/$bbcode[icon]" title="$bbcode[explanation]" alt="$tag" /></a></td>
<!--{/loop}-->
<!--{/if}-->[/code]在其后添加:[code]<td><div class="editor_buttonnormal" id="{$editorid}_cmd_wrap0_code" onclick="discuzcode('html')" onMouseOver="buttonContext(this, 'mouseover')" onMouseOut="buttonContext(this, 'mouseout')"><img src="images/common/bb_html.gif" width="21" height="20" title="插入代码运行框" alt="插入代码运行框" /></div></td>[/code]