开源DIGG软件PBDigg2.0的修改(二):ubb编辑器换行问题的解决方法

PBDIGG 2.0周年版在程序上做了一些小的改动,而模板也因此也有一些改动。不知道是否由于时间紧迫的原因,导致bug出现了很多。下面我们要说的就是2.0周年版在使用ubb编辑器上的一个问题。本着技术分享的原则,下面将文件修改内容写出来。针对新手,提供了程序补丁直接下载。


在整个分析中,花了不少时间,主要是对php程序不熟悉造成的。从模板分析到ubb编辑器,最后到程序文件。Finally , I found the anwser.(提醒:在修改程序以前,请备份相关文件。主要涉及3个文件show.php,include/postedit.inc.php,include/postnew.inc.php
show.php第140行到147行代码
140 $rs['ifconvert'] && $rs['content'] = UBB2HTML($rs['content'], 'content');
141 /*
142 if (!$rs['ishtml'])
143 {
144 $rs['ifconvert'] && $rs['content'] = UBB2HTML($rs['content'], 'content');
145 $rs['content'] = preg_replace('/(?:\r\n|\n\r|\r|\n)/i', '<br />', $rs['content']);
146 }
147 */
我们可以看到,官方将下面一段给注释掉了。查看了之前的2.0版,是使用了此段代码的。通过代码也能大概了解这段代码应该是将content中存在换行符的内容替换为html标签<br />。在这里,我们把140行代码注释掉,或者删除,去掉142行到146行的注释。代码如下:
140 // $rs['ifconvert'] && $rs['content'] = UBB2HTML($rs['content'], 'content');
141
142 if (!$rs['ishtml'])
143 {
144 $rs['ifconvert'] && $rs['content'] = UBB2HTML($rs['content'], 'content');
145 $rs['content'] = preg_replace('/(?:\r\n|\n\r|\r|\n)/i', '<br />', $rs['content']);
146 }
147


/include/postedit.inc.php第47行到57行:
47 if ($allowhtml)
48 {
49 $content = ($customer['adminid'] == '1') ? $content : safeConvert($content);
50 }
51 else
52 {
53 require_once PBDIGG_ROOT.'include/safehtml.php';
54 $safehtml = & new HTML_Safe();
55 $content = addslashes($safehtml->parse(stripslashes($content)));
56 }
57 $ishtml = $convert = 1;
我比较了一下2.0周年版和之前的2.0版本的不同,发现这里引用了一个safehtml.php文件,我想应该是用来过滤危险html代码的吧。但是查看2.0版本和周年版的不同,发现他没有判断到是ubb编辑器的情况,按照2.0版本的判断,做如下修改:
if ($allowhtml)
{
$content = ($customer['adminid'] == '1') ? $content : safeConvert($content);
$ishtml = '1';
}
else
{
if ($pb_editor == '2')
{
require_once PBDIGG_ROOT.'include/safehtml.php';
$safehtml = & new HTML_Safe();
$content = addslashes($safehtml->parse(stripslashes($content)));
$convert = 1;
}
else
{
$content = HConvert($content);
require_once(PBDIGG_ROOT.'include/ubb.func.php');
$convert = ($content == UBB2HTML($content)) ? 0 : 1;
}
}


include/postnew.inc.php 修改相同,只是原文件代码从57行到67行:
57 if ($allowhtml)
58 {
59 $content = ($customer['adminid'] == '1') ? $content : safeConvert($content);
60 }
61 else
62 {
63 require_once PBDIGG_ROOT.'include/safehtml.php';
64 $safehtml = & new HTML_Safe();
65 $content = addslashes($safehtml->parse(stripslashes($content)));
66 }
67 $ishtml = $convert = 1;
修改后的代码:
57 if ($allowhtml)
{
$content = ($customer['adminid'] == '1') ? $content : safeConvert($content);
$ishtml = '1';
}
else
{
if ($pb_editor == '2')
{
require_once PBDIGG_ROOT.'include/safehtml.php';
$safehtml = & new HTML_Safe();
$content = addslashes($safehtml->parse(stripslashes($content)));
$convert = 1;
}
else
{
$content = HConvert($content);
require_once(PBDIGG_ROOT.'include/ubb.func.php');
$convert = ($content == UBB2HTML($content)) ? 0 : 1;
}
}
在多次测试后,没有发现什么功能上的问题。至于安全问题,留给熟悉php的朋友吧。如果出现任何问题,造成的任何损失,本人概不负责。该文仅作技术分享,如需修改,请备份相关资料文件。
下面给出修改以后的文件,方便新手使用。下载后将“ubb编辑器换行补丁”文件夹内的show.php和include文件夹全部上传到您的pbdigg安装文件夹里,覆盖。(请先备份上面说到的3个文件)。
ubb编辑器换行补丁.rar
注意:以前使用ubb编辑器发布的文章,需要重新编辑发布一次。否则文章内容页会出现ubb标签,而不会被转换为html标签。

posted @ 2011-12-25 17:40  忧国忧铭  Views(1736)  Comments(0Edit  收藏  举报