You are here

function advanced_forum_post_position in Advanced Forum 6.2

Same name and namespace in other branches
  1. 7.2 advanced_forum.module \advanced_forum_post_position()

Returns the display position of a given reply post ID on a given node.

2 calls to advanced_forum_post_position()
_advanced_forum_preprocess_comment in includes/advanced_forum_preprocess_comment.inc
@file Holds the contents of a preprocess function moved into its own file to ease memory requirements and having too much code in one file.
_advanced_forum_preprocess_node in includes/advanced_forum_preprocess_node.inc
@file Holds the contents of a preprocess function moved into its own file to ease memory requirements and having too much code in one file.

File

./advanced_forum.module, line 1326
Enables the look and feel of other popular forum software.

Code

function advanced_forum_post_position($node_id, $post_id) {
  static $post_order = array();
  if (!isset($post_order[$node_id])) {

    // Initialize the spot for this node's list.
    $post_order[$node_id] = array();

    // Make this work with either core comments or node comments.
    $table = module_exists('nodecomment') ? "node_comments" : "comments";

    // 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";

    // Cycle through the results and fill in the array.
    $result = db_query($query, $node_id);
    while ($post = db_fetch_array($result)) {
      $post_order[$node_id][] = reset($post);
    }
  }

  // Find the position of the passed in post ID.
  $post_position = 0;
  if (is_array($post_order[$node_id])) {
    if (($index = array_search($post_id, $post_order[$node_id])) !== FALSE) {
      $post_position = $index;

      // We need to add 2 because the array starts at 0 and also because the topic
      // node is post #1 on display but is not included in the index.
      $post_position = $post_position + 2;
    }
  }
  return $post_position;
}