You are here

function advanced_forum_preprocess_comment in Advanced Forum 5

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

Preprocesses template variables for the comment template.

File

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

Code

function advanced_forum_preprocess_comment(&$variables) {
  if (advanced_forum_treat_as_forum_post('comment', $variables)) {

    // Use our combined node/comment template file
    // D5 won't find templates in subdirectories so we need to give it that
    $forum_style = advanced_forum_get_current_style();
    $variables['template_files'][] = "{$forum_style}/advf-forum-post";

    // Thread is being shown in the forum (not on the front page or in a view)
    $variables['is_forum'] = TRUE;

    // This is a comment, not the node.
    $variables['top_post'] = FALSE;

    // We need some information from the parent node so load it here
    $node = node_load($variables['comment']->nid);
    $variables['node'] = $node;

    // Title
    if (variable_get('comment_subject_field', 1) == 0) {

      // if comment titles are disabled, don't display it.
      $variables['title'] = '';
    }
    else {

      // Assign the subject to the title variable for consistancy with nodes.
      $variables['title'] = check_plain($variables['comment']->subject);
    }

    // Just use the date for the submitted on.
    $variables['submitted'] = format_date($variables['comment']->timestamp);

    // Assign the comment to the content variable for consistancy with nodes.
    $variables['content'] = $variables['comment']->comment;

    // User information
    $account_id = $variables['comment']->uid;
    if ($account_id == 0) {

      // Anonymous user. Make a fake user object for theme_username
      $variables['account']->name = $variables['comment']->name;
      $variables['account']->homepage = $variables['comment']->homepage;
    }
    else {

      // Load up the real user object
      $variables['account'] = user_load(array(
        'uid' => $variables['comment']->uid,
      ));
    }

    // Create the author pane
    $variables['author_pane'] = theme('author_pane', $variables['account'], advanced_forum_path_to_images(), "{$forum_style}/advf-author-pane");

    // Because the $links array isn't available here, we recreate it
    if (arg(1) != 'reply') {
      $links = module_invoke_all('link', 'comment', $variables['comment']);
      foreach (module_implements('link_alter') as $module) {
        $function = $module . '_link_alter';
        $function($node, $links);
      }
      unset($links['comment_parent']);

      // Iconify common links (optional to avoid translation issues)
      _advanced_forum_buttonify_links($links);

      // Remake the links with our changes
      $variables['links'] = theme('links', $links, array(
        'class' => 'links forum-links',
      ));
      $variables['links_array'] = $links;
    }

    // Comment number with link
    if (!isset($post_number)) {
      static $post_number = 0;
    }
    _advanced_forum_topic_nid($variables['node']->nid);
    $post_per_page = _comment_get_display_setting('comments_per_page', $variables['node']);
    $page_number = $_GET['page'];
    if (!$page_number) {
      $page_number = 0;
    }
    $post_number++;
    $fragment = 'comment-' . $variables['comment']->cid;
    $query = $page_number ? 'page=' . $page_number : NULL;
    $linktext = '#' . ($page_number * $post_per_page + $post_number);
    $linkpath = 'node/' . _advanced_forum_topic_nid();
    $variables['comment_link'] = l($linktext, $linkpath, NULL, $query, $fragment);

    // Link to page created by Comment Page module, if it exists
    if (!empty($variables['comment']->page_url) && !(arg(0) == 'comment' && arg(1) == $variables['comment']->cid)) {
      $variables['page_link'] = l('(permalink)', $variables['comment']->page_url);
    }
  }
}