You are here

function advanced_forum_preprocess_forum_submitted in Advanced Forum 7.2

Same name and namespace in other branches
  1. 5 advanced_forum.module \advanced_forum_preprocess_forum_submitted()
  2. 6.2 includes/theme.inc \advanced_forum_preprocess_forum_submitted()
  3. 6 advanced_forum.module \advanced_forum_preprocess_forum_submitted()

Preprocesses template variables for the submitted by/in template.

File

includes/theme.inc, line 215
Holds theme functions and template preprocesses. Other style related functions are in style.inc

Code

function advanced_forum_preprocess_forum_submitted(&$variables) {
  advanced_forum_add_template_suggestions("submitted", $variables);

  // Avoid E_ALL warning.
  $variables['topic_link'] = '';
  if (isset($variables['topic']->node_title)) {
    $nid = $variables['topic']->nid;

    // Make a fake node object to avoid the node load.
    $node = new stdClass();
    $node->nid = $nid;
    $node->type = $variables['topic']->type;

    // Find the page of the first unread comment, if any.
    $comment_count = db_query('SELECT COUNT(cid) FROM {comment} WHERE nid = :nid', array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $new_replies = advanced_forum_reply_num_new($nid);
    $query = advanced_forum_page_first_new($comment_count, $new_replies, $node);

    // Format the node title with a link.
    $title_length = variable_get('advanced_forum_topic_title_length', 15);
    if ($title_length == 0) {
      $short_topic_title = $variables['topic']->node_title;
    }
    else {
      $short_topic_title = truncate_utf8($variables['topic']->node_title, $title_length, TRUE, TRUE);
    }
    $variables['short_topic_title'] = $short_topic_title;
    $fragment = $new_replies ? 'new' : NULL;
    $variables['topic_link_fragment'] = $fragment;
    $variables['topic_link_query'] = $query;
    $variables['topic_link'] = l($short_topic_title, "node/{$nid}", array(
      'query' => $query,
      'fragment' => $fragment,
    ));
  }
  if (isset($variables['topic']->created)) {
    $timestamp = $variables['topic']->created;
    $interval = REQUEST_TIME - $timestamp;
    $variables['time'] = format_interval($interval);

    // For items posted more than $cutoff hours ago, offer an actual date.
    $cutoff = variable_get('advanced_forum_time_ago_cutoff', 48) * 60 * 60;
    if ($interval > $cutoff) {
      $variables['date_posted'] = format_date($timestamp, 'short');
    }
    else {
      unset($variables['date_posted']);
    }
  }
}