Same name and namespace in other branches
  1. 7.x modules/forum/forum.module \template_preprocess_forum_topic_list()

Preprocess variables to format the topic listing.

$variables contains the following data:

  • $tid
  • $topics
  • $sortby
  • $forum_per_page

See also

forum-topic-list.tpl.php

theme_forum_topic_list()

File

modules/forum/forum.module, line 804
Enable threaded discussions about general topics.

Code

function template_preprocess_forum_topic_list(&$variables) {
  global $forum_topic_list_header;

  // Create the tablesorting header.
  $ts = tablesort_init($forum_topic_list_header);
  $header = '';
  foreach ($forum_topic_list_header as $cell) {
    $cell = tablesort_header($cell, $forum_topic_list_header, $ts);
    $header .= _theme_table_cell($cell, TRUE);
  }
  $variables['header'] = $header;
  if (!empty($variables['topics'])) {
    $row = 0;
    foreach ($variables['topics'] as $id => $topic) {
      $variables['topics'][$id]->icon = theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky);
      $variables['topics'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even';
      $row++;

      // We keep the actual tid in forum table, if it's different from the
      // current tid then it means the topic appears in two forums, one of
      // them is a shadow copy.
      if ($topic->forum_tid != $variables['tid']) {
        $variables['topics'][$id]->moved = TRUE;
        $variables['topics'][$id]->title = check_plain($topic->title);
        $variables['topics'][$id]->message = l(t('This topic has been moved'), "forum/{$topic->forum_tid}");
      }
      else {
        $variables['topics'][$id]->moved = FALSE;
        $variables['topics'][$id]->title = l($topic->title, "node/{$topic->nid}");
        $variables['topics'][$id]->message = '';
      }
      $variables['topics'][$id]->created = theme('forum_submitted', $topic);
      $variables['topics'][$id]->last_reply = theme('forum_submitted', isset($topic->last_reply) ? $topic->last_reply : NULL);
      $variables['topics'][$id]->new_text = '';
      $variables['topics'][$id]->new_url = '';
      if ($topic->new_replies) {
        $variables['topics'][$id]->new_text = format_plural($topic->new_replies, '1 new', '@count new');
        $variables['topics'][$id]->new_url = url("node/{$topic->nid}", array(
          'query' => comment_new_page_count($topic->num_comments, $topic->new_replies, $topic),
          'fragment' => 'new',
        ));
      }
    }
  }
  else {

    // Make this safe for the template
    $variables['topics'] = array();
  }

  // Give meaning to $tid for themers. $tid actually stands for term id.
  $variables['topic_id'] = $variables['tid'];
  unset($variables['tid']);
  $variables['pager'] = theme('pager', NULL, $variables['forum_per_page'], 0);
}