暖冬的源码分享

 找回密码
 立即加入

QQ登录

只需一步,快速开始

搜索
热搜: 巧借
查看: 5791|回复: 0

[bug修正]当$disablepos启用并倒序浏览帖子楼层错乱的问题

[复制链接]
发表于 2013-7-12 17:57:38 | 显示全部楼层 |阅读模式
【注意】
            当前修正方法还没有进行全面的测试,慎用。本人只做一个临时记录,后续问题可能等待适当时间进行处理。
           未测试内容:  特殊主题是否正常;抢楼贴是否正常;其他未知方面...

【修正:】
           2013/07/16 修正修改时导致正序出现问题的Bug。修正代码参见下面的代码。
    将下述代码:
  1. $startLimit = $page > 1 ? ($_G['forum_pagebydesc'] ? $start_limit + 1 : $start_limit - 1) : $start_limit;
  2.                 $gppp = $page > 1 ? $_G['ppp'] : $_G['ppp'] - 1;
复制代码
替换为:
  1. $startLimit = ($page > 1 && $ordertype == 1) ? ($_G['forum_pagebydesc'] ? $start_limit + 1 : $start_limit - 1) : $start_limit;
  2.                 $gppp = ($page == 1 && $ordertype == 1) ? $_G['ppp'] - 1 : $_G['ppp'];
复制代码
即可


当论坛某主题的帖子出现删帖时,我们往往会看到“无效楼层,帖子可能已删除”的提示(也可能进入未审核)。当论坛浏览时检测到这种现象,帖子tid将被记录到一个名为“forum_threaddisablepos”的数据表中,此时如果该帖不是抢楼贴的话 $disablepos 将生效,同时按照 position 获取帖子将被禁止,导致 $maxposition 为 false。
     在这种情况下,当倒序浏览帖子的时候,会发现以下问题:
       1.   楼主贴楼层序号变为 #,而不是楼主;
       2.   第一页有 11 个帖子,最后一页少一个帖子;如果最后一页只有1个帖子的时候,会导致“没有帖子”的错误提示
       3.   如果只有一页的话,最后一个会变成 楼主

上述问题在 x2.5 和 x3 中均有出现。

临时修正方案:
第一步:
找到以下代码,位置大概在文件的 560行上下
  1. if(!$maxposition && empty($postarr)) {

  2.         if(empty($_GET['viewpid'])) {
  3.                
  4.                 if($_G['forum_thread']['special'] == 2) {
  5.                         $postarr = C::t('forum_post')->fetch_all_tradepost_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $tpids, $_G['forum_pagebydesc'], $ordertype, $start_limit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $_G['ppp']));
  6.                 } elseif($_G['forum_thread']['special'] == 5) {
  7.                         $postarr = C::t('forum_post')->fetch_all_debatepost_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $_GET['stand'], $_G['forum_pagebydesc'], $ordertype, $start_limit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $_G['ppp']));
  8.                 } else {
  9.                         $postarr = C::t('forum_post')->fetch_all_common_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $_G['forum_pagebydesc'], $ordertype, $_G['forum_thread']['replies'] + 1, $start_limit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $_G['ppp']));
  10.                 }
  11.         } else {
复制代码
修改为:
  1. if(!$maxposition && empty($postarr)) {

  2.         if(empty($_GET['viewpid'])) {
  3.                 //$startLimit = $page > 1 ? ($_G['forum_pagebydesc'] ? $start_limit + 1 : $start_limit - 1) : $start_limit;
  4.                 //$gppp = $page > 1 ? $_G['ppp'] : $_G['ppp'] - 1;
  5.                 $startLimit = ($page > 1 && $ordertype == 1) ? ($_G['forum_pagebydesc'] ? $start_limit + 1 : $start_limit - 1) : $start_limit;
  6.                 $gppp = ($page == 1 && $ordertype == 1) ? $_G['ppp'] - 1 : $_G['ppp'];
  7.                
  8.                 if($_G['forum_thread']['special'] == 2) {
  9.                         $postarr = C::t('forum_post')->fetch_all_tradepost_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $tpids, $_G['forum_pagebydesc'], $ordertype, $startLimit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $gppp));
  10.                 } elseif($_G['forum_thread']['special'] == 5) {
  11.                         $postarr = C::t('forum_post')->fetch_all_debatepost_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $_GET['stand'], $_G['forum_pagebydesc'], $ordertype, $startLimit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $gppp));
  12.                 } else {
  13.                         $postarr = C::t('forum_post')->fetch_all_common_viewthread_by_tid($_G['tid'], $visibleallflag, $_GET['authorid'], $_G['forum_pagebydesc'], $ordertype, $_G['forum_thread']['replies'] + 1, $startLimit, ($_G['forum_pagebydesc'] ? $_G['forum_ppp2'] : $gppp));
  14.                 }
  15.         } else {
复制代码
此处做了两件事:
1 修正 gpp
2 修正开始查询的位置

修改理由:
第一页因为有楼主帖子存在,所以在倒序获取回复时应该只获取9个,而不是10个,所以 $gppp 为 $_G['ppp'] - 1,之后恢复正常。
第二页开始偏移位置应该往前移动1个,所以-1;而当页数达到总页数的一半以上时,回复获取为ASC,需要将偏移值增加1。

第二处修正为 number 值的修正,代码位置大概在 1060~1080行,需要修改的行在 1070上下,有两处(下面的代码只有一段,包含修改,请对比注释掉的行和新增加的行对比):
  1.         if(!$post['hotrecommended']) {
  2.                 if($_G['forum_pagebydesc']) {
  3.                         if($ordertype != 1) {
  4.                                 $post['number'] = $_G['forum_numpost'] + $_G['forum_ppp2']--;
  5.                         } else {
  6.                                 //$post['number'] = $post['first'] == 1 ? 1 : ($_G['forum_numpost'] - 1) - $_G['forum_ppp2']--;
  7.                                 $post['number'] = $post['first'] == 1 ? 1 : ($_G['forum_numpost']) - $_G['forum_ppp2']--;
  8.                         }
  9.                 } else {
  10.                         if($ordertype != 1) {
  11.                                 $post['number'] = ++$_G['forum_numpost'];
  12.                         } else {
  13.                                 $post['number'] = $post['first'] == 1 ? 1 : --$_G['forum_numpost'];
  14.                                 //$post['number'] = $post['number'] - 1;
  15.                         }
  16.                 }
  17.         }
复制代码
此处的修改目的是,取消所有的楼层 number 减1,因为本身是不需要的。


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

本版积分规则

手机版|小黑屋|享码网 ( 京ICP备12003721号 )

GMT+8, 2024-3-29 15:00

Powered by Discuz! X3.5

Copyright © 2001-2021 Tencent Cloud.

快速回复 返回顶部 返回列表