You are here

function advanced_forum_preprocess_comment in Advanced Forum 6

Same name and namespace in other branches
  1. 5 advanced_forum.module \advanced_forum_preprocess_comment()
  2. 6.2 includes/theme.inc \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 468
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)) {
    if (arg(1) == 'reply') {

      // Use the preview version
      $variables['template_files'][] = "advf-forum-preview-post";
    }
    else {

      // Use our combined node/comment template file
      $variables['template_files'][] = 'advf-forum-post';
    }

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

    // 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;
      $variables['account']->mail = $variables['comment']->mail;
    }
    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', variable_get('advanced_forum_user_picture_preset', ''), $variables['comment'], TRUE);
    if (arg(1) != 'reply') {

      // Because the $links array isn't available here, we recreate it
      $node = node_load($variables['comment']->nid);
      $links = module_invoke_all('link', 'comment', $variables['comment']);
      drupal_alter('link', $links, $node, $variables['comment']);
      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;
    }

    // Since we have to load the node anyway for our links trick, make it avail
    $variables['node'] = $node;

    // Title
    if (variable_get('comment_subject_field_' . $node->type, 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);
    }

    // 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 = !empty($_GET['page']) ? $_GET['page'] : 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, array(
      'query' => $query,
      'fragment' => $fragment,
    ));

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

    // Load the signature.
    if (module_exists('signature_forum')) {

      // If Signature For Forums is installed, use that
      $variables['signature'] = signature_forum_get_signature($variables['comment']);
    }
    elseif (variable_get('user_signatures', 0)) {
      if ($variables['account']->signature) {

        // Otherwise load Drupal's built in one, if enabled.
        $variables['signature'] = check_markup($variables['account']->signature, $variables['account']->signature_format);
      }
    }

    // Initialize to avoid notices.
    $variables['classes'] = empty($variables['classes']) ? '' : $variables['classes'];
    $variables['comment_classes'] = empty($variables['comment_classes']) ? '' : $variables['comment_classes'];
  }
}