diff --git a/includes/core-overrides.inc b/includes/core-overrides.inc index 2c2c1b8..f701333 100644 --- a/includes/core-overrides.inc +++ b/includes/core-overrides.inc @@ -191,38 +191,40 @@ function advanced_forum_forum_load($tid = NULL) { $forum->num_posts = 0; } - // Query "Last Post" information for this forum. - $query = db_select('node', 'n'); - $query->join('forum_index', 'f', 'n.nid = f.nid AND f.tid = :tid', array(':tid' => $forum->tid)); - $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid'); - $query->join('users', 'u', 'ncs.last_comment_uid = u.uid'); - $query->addExpression('CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u.name END', 'last_comment_name'); - - $topics = $query - ->fields('ncs', array('last_comment_timestamp', 'last_comment_uid')) - ->fields('n', array('nid', 'title', 'type')) - ->condition('n.status', 1) - ->orderBy('last_comment_timestamp', 'DESC') - ->range(0, $post_count) - ->addTag('node_access') - ->execute(); - - while ($topic = $topics->fetchObject()) { - // Merge in the "Last Post" information. - $last_post = new stdClass(); - if (!empty($topic->last_comment_timestamp)) { - $last_post->nid = $topic->nid; - $last_post->node_title = $topic->title; - $last_post->type = $topic->type; - $last_post->created = $topic->last_comment_timestamp; - $last_post->name = $topic->last_comment_name; - $last_post->uid = $topic->last_comment_uid; - } - if ($post_count > 1) { - $forum->last_post[] = $last_post; - } - else { - $forum->last_post = $last_post; + if (variable_get('advanced_forum_show_latest_comment', 1)) { + // Query "Last Post" information for this forum. + $query = db_select('node', 'n'); + $query->join('forum_index', 'f', 'n.nid = f.nid AND f.tid = :tid', array(':tid' => $forum->tid)); + $query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid'); + $query->join('users', 'u', 'ncs.last_comment_uid = u.uid'); + $query->addExpression('CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u.name END', 'last_comment_name'); + + $topics = $query + ->fields('ncs', array('last_comment_timestamp', 'last_comment_uid')) + ->fields('n', array('nid', 'title', 'type')) + ->condition('n.status', 1) + ->orderBy('last_comment_timestamp', 'DESC') + ->range(0, $post_count) + ->addTag('node_access') + ->execute(); + + while ($topic = $topics->fetchObject()) { + // Merge in the "Last Post" information. + $last_post = new stdClass(); + if (!empty($topic->last_comment_timestamp)) { + $last_post->nid = $topic->nid; + $last_post->node_title = $topic->title; + $last_post->type = $topic->type; + $last_post->created = $topic->last_comment_timestamp; + $last_post->name = $topic->last_comment_name; + $last_post->uid = $topic->last_comment_uid; + } + if ($post_count > 1) { + $forum->last_post[] = $last_post; + } + else { + $forum->last_post = $last_post; + } } } diff --git a/includes/settings.inc b/includes/settings.inc index e8f1c1e..61de153 100644 --- a/includes/settings.inc +++ b/includes/settings.inc @@ -205,6 +205,14 @@ function advanced_forum_settings_page() { ); } + // Show Latest Topic + $form['advanced_forum_lists']['advanced_forum_show_latest_comment'] = array( + '#type' => 'checkbox', + '#title' => t('Show the lastest topic or comment status.'), + '#default_value' => variable_get('advanced_forum_show_latest_comment', 1), + '#description' => t('Allows you to toggle the the latest activity. If checked this can hit performance.'), + ); + // Retrieve new comments on forum listing $form['advanced_forum_lists']['advanced_forum_get_new_comments'] = array( '#type' => 'checkbox',