diff --git a/advanced_forum.module b/advanced_forum.module index 2afda36..5d14988 100644 --- a/advanced_forum.module +++ b/advanced_forum.module @@ -1323,9 +1323,12 @@ function advanced_forum_unread_replies_in_forum($tid, $uid) { /** * Returns the display position of a given reply post ID on a given node. */ -function advanced_forum_post_position($node_id, $post_id) { +function advanced_forum_post_position($node, $comment) { static $post_order = array(); + $node_id = $node->nid; + $post_id = $comment->pid; + if (!isset($post_order[$node_id])) { // Initialize the spot for this node's list. $post_order[$node_id] = array(); @@ -1333,10 +1336,18 @@ function advanced_forum_post_position($node_id, $post_id) { // Make this work with either core comments or node comments. $table = (module_exists('nodecomment')) ? "node_comments" : "comments"; + $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED); + if ($mode === COMMENT_MODE_FLAT) { + $orderby = 'c.cid ASC'; + } + else { + $orderby = 'SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1)) ASC'; + } + // Get the list of CIDs from the database in order of oldest first. // We are going to make that assumption for now for simplicity but may // revisit in the future if there are requests for newest first. - $query = "SELECT c.cid FROM {" . $table . "} c WHERE c.nid = %d ORDER BY c.cid ASC"; + $query = "SELECT c.cid FROM {" . $table . "} c WHERE c.nid = %d ORDER BY ". $orderby; // Cycle through the results and fill in the array. $result = db_query($query, $node_id); diff --git a/includes/advanced_forum_preprocess_comment.inc b/includes/advanced_forum_preprocess_comment.inc index b912040..fe063ee 100644 --- a/includes/advanced_forum_preprocess_comment.inc +++ b/includes/advanced_forum_preprocess_comment.inc @@ -106,7 +106,7 @@ function _advanced_forum_preprocess_comment(&$variables) { $variables['in_reply_to'] = ""; if ($comment->pid > 0) { // Find the display position of the parent post;. - $post_position = advanced_forum_post_position($node->nid, $comment->pid); + $post_position = advanced_forum_post_position($node, $comment); // This extra if test is a sanity check in case the comment being replied // to no longer exists. @@ -173,4 +173,4 @@ function _advanced_forum_preprocess_comment(&$variables) { /* Post edited */ $variables['post_edited'] = (isset($comment->comment_edited)) ? $comment->comment_edited : ""; -} \ No newline at end of file +}