Revision: 1443
Author: magike.net
Date: Tue Jun  8 23:40:36 2010
Log: fix issue 459
调整嵌套comment的回调函数参数
如果是使用自定义回调函数,则需要调整原来的$before和$after参数没有了,现在的 
函数原型调整为threadedComments($this, $singleCommentOptions)
http://code.google.com/p/typecho/source/detail?r=1443

Modified:
  /trunk/var/Widget/Comments/Archive.php
  /trunk/var/Widget/Comments/Edit.php
  /trunk/var/Widget/Options/Discussion.php

=======================================
--- /trunk/var/Widget/Comments/Archive.php      Tue Mar 16 19:15:44 2010
+++ /trunk/var/Widget/Comments/Archive.php      Tue Jun  8 23:40:36 2010
@@ -99,15 +99,13 @@
       * 评论回调函数
       *
       * @access private
-     * @param string $before 在评论之前输出
-     * @param string $after 在评论之后输出
       * @param string $singleCommentOptions 单个评论自定义选项
       * @return void
       */
-    private function threadedCommentsCallback($before, $after,  
$singleCommentOptions)
+    private function threadedCommentsCallback($singleCommentOptions)
      {
          if ($this->_customThreadedCommentsCallback) {
-            return threadedComments($this, $before, $after,  
$singleCommentOptions);
+            return threadedComments($this, $singleCommentOptions);
          }

          $commentClass = '';
@@ -117,7 +115,7 @@
              } else {
                  $commentClass .= ' comment-by-user';
              }
-        }
+        }

          $commentLevelClass = $this->_levels > 0 ? ' comment-child' : '  
comment-parent';
  ?>
@@ -145,7 +143,7 @@
      <?php $this->content(); ?>
      <?php if ($this->children) { ?>
      <div class="comment-children">
-        <?php $this->threadedComments($before, $after,  
$singleCommentOptions); ?>
+        <?php $this->threadedComments($singleCommentOptions); ?>
      </div>
      <?php } ?>
      <div class="comment-reply">
@@ -285,13 +283,41 @@
          $select->order('table.comments.coid',  
$this->options->commentsOrder);
          $this->db->fetchAll($select, array($this, 'push'));

+        $commentsLevel = array();
+        $commentFilpMap = array();  // 反向查询表
+
          if ($threadedSelect) {
              $threadedSelect->where('table.comments.parent <> ? AND  
table.comments.coid > ?', 0, $this->_splitCommentId)
              ->order('table.comments.coid', $this->options->commentsOrder);
              $threadedComments = $this->db->fetchAll($threadedSelect,  
array($this, 'filter'));

              foreach ($threadedComments as $comment) {
-                 
$this->_threadedComments[$comment['parent']][$comment['coid']] = $comment;
+                /** fix issue 459 */
+                $commentFilpMap[$comment['coid']] = $comment['parent'];
+
+                $commentsLevel[$comment['coid']] =  
isset($commentsLevel[$comment['parent']]) ?  
$commentsLevel[$comment['parent']] + 1 : 1;
+                if ($commentsLevel[$comment['coid']] <  
$this->options->commentsMaxNestingLevels) {
+                    /** 计算顺序 */
+                    $comment['order'] =  
isset($this->_threadedComments[$comment['parent']])
+                        ?  
count($this->_threadedComments[$comment['parent']]) + 1 : 1;
+
+                     
$this->_threadedComments[$comment['parent']][$comment['coid']] = $comment;
+                } else {
+                    $grandParent =  
isset($commentFilpMap[$comment['parent']]) ?  
$commentFilpMap[$comment['parent']] : 0;     // 上上层节点
+
+                    /** 更新父节点 */
+                    $comment['parent'] = $grandParent;
+
+                    /** 计算顺序 */
+                    $comment['order'] =  
isset($this->_threadedComments[$grandParent])
+                        ? count($this->_threadedComments[$grandParent]) +  
1 : 1;
+
+                    /** 直接挂接到上一层节点 */
+                     
$this->_threadedComments[$grandParent][$comment['coid']] = $comment;
+
+                    /** 更新反向查询表 */
+                    $commentFilpMap[$comment['coid']] = $grandParent;
+                }
              }
          }
      }
@@ -356,7 +382,7 @@
       * @param Typecho_Config $singleCommentOptions 单个评论自定义选项
       * @return void
       */
-    public function threadedComments($before = '', $after = '',  
$singleCommentOptions = NULL)
+    public function threadedComments($singleCommentOptions = NULL)
      {
          $children = $this->children;
          if ($children) {
@@ -366,16 +392,16 @@
              $this->sequence ++;

              //在子评论之前输出
-            echo $before;
+            $singleCommentOptions->before;

              foreach ($children as $child) {
                  $this->row = $child;
-                $this->threadedCommentsCallback($before, $after,  
$singleCommentOptions);
+                $this->threadedCommentsCallback($singleCommentOptions);
                  $this->row = $tmp;
              }

              //在子评论之后输出
-            echo $after;
+            $singleCommentOptions->after;

              $this->sequence --;
              $this->_levels --;
@@ -386,17 +412,17 @@
       * 列出评论
       *
       * @access private
-     * @param string $before 在评论之前输出
-     * @param string $after 在评论之后输出
       * @param mixed $singleCommentOptions 单个评论自定义选项
       * @return void
       */
-    public function listComments($before = '<ol class="comment-list">',  
$after = '</ol>', $singleCommentOptions = NULL)
+    public function listComments($singleCommentOptions = NULL)
      {
          if ($this->have()) {
              //初始化一些变量
              $parsedSingleCommentOptions =  
Typecho_Config::factory($singleCommentOptions);
              $parsedSingleCommentOptions->setDefault(array(
+                'before'        =>  '<ol class="comment-list">',
+                'after'         =>  '</ol>',
                  'beforeAuthor'  =>  '',
                  'afterAuthor'   =>  '',
                  'beforeDate'    =>  '',
@@ -407,13 +433,13 @@
                  'defaultAvatar' =>  NULL
              ));

-            echo $before;
+            echo $parsedSingleCommentOptions->before;

              while ($this->next()) {
-                $this->threadedCommentsCallback($before, $after,  
$parsedSingleCommentOptions);
+                 
$this->threadedCommentsCallback($parsedSingleCommentOptions);
              }

-            echo $after;
+            echo $parsedSingleCommentOptions->after;
          }
      }

@@ -428,8 +454,7 @@
          $args = func_get_args();
          $num = func_num_args();

-        $sequence = $this->_levels <= 0 ? $this->sequence :
-        array_search($this->coid, $this->_threadedComments[$this->parent])  
+ 1;
+        $sequence = $this->_levels <= 0 ? $this->sequence : $this->order;

          $split = $sequence % $num;
          echo $args[(0 == $split ? $num : $split) -1];
=======================================
--- /trunk/var/Widget/Comments/Edit.php Sat May 29 21:46:49 2010
+++ /trunk/var/Widget/Comments/Edit.php Tue Jun  8 23:40:36 2010
@@ -320,7 +320,7 @@
                  'mail'      =>  $this->user->mail,
                  'url'       =>  $this->user->url,
                  'parent'    =>  $coid,
-                'text'      =>   
$this->request->filter(array($this->widget('Widget_Feedback'), 
'filterText'))->text,
+                'text'      =>  $this->request->text,
                  'status'    =>  'approved'
              );

=======================================
--- /trunk/var/Widget/Options/Discussion.php    Wed Apr 21 05:35:28 2010
+++ /trunk/var/Widget/Options/Discussion.php    Tue Jun  8 23:40:36 2010
@@ -181,7 +181,7 @@
          $settings['commentsThreaded'] =  
$this->isEnableByCheckbox($settings['commentsShow'], 'commentsThreaded');

          $settings['commentsPageSize'] =  
intval($settings['commentsPageSize']);
-        $settings['commentsMaxNestingLevels'] =  
intval($settings['commentsMaxNestingLevels']);
+        $settings['commentsMaxNestingLevels'] = max(2,  
intval($settings['commentsMaxNestingLevels']));
          $settings['commentsPageDisplay'] = ('first' ==  
$settings['commentsPageDisplay']) ? 'first' : 'last';
          $settings['commentsOrder'] = ('DESC' ==  
$settings['commentsOrder']) ? 'DESC' : 'ASC';
          $settings['commentsAvatarRating'] =  
in_array($settings['commentsAvatarRating'], array('G', 'PG', 'R', 'X'))
_______________________________________________
announce mailing list
[email protected]
http://lists.typecho.org/mailman/listinfo/announce

回复