You are here

function advanced_forum_process_forum in Advanced Forum 6.2

Same name and namespace in other branches
  1. 7.2 includes/advanced_forum_preprocess_forum_list.inc \advanced_forum_process_forum()

Prepare an individual forum for display.

1 call to advanced_forum_process_forum()
_advanced_forum_preprocess_forum_list in includes/advanced_forum_preprocess_forum_list.inc
@file Holds the contents of a preprocess function moved into its own file to ease memory requirements and having too much code in one file.

File

includes/advanced_forum_preprocess_forum_list.inc, line 260
Holds the contents of a preprocess function moved into its own file to ease memory requirements and having too much code in one file.

Code

function advanced_forum_process_forum($forum) {

  // Create a variable to check if the item is a container in the template.
  $forum->is_container = FALSE;

  // Create the link to the forum.
  $forum->link = url("forum/{$forum->tid}");

  // Sanitise the name and description so they can be safely printed.
  // We don't do this for subforum names because that is sent through l()
  // in the theme function which runs it through check_plain().
  $forum->name = empty($forum->parents[0]) ? check_plain($forum->name) : $forum->name;
  $forum->description = !empty($forum->description) ? filter_xss_admin($forum->description) : '';

  // Initialize these variables to avoid notices later since not all forums
  // have new content or even any content at all.
  $forum->total_topics = 0;
  $forum->child_total_topics = 0;
  $forum->new_topics = 0;
  $forum->new_topics_text = '';
  $forum->new_topics_link = '';
  $forum->child_new_topics = 0;
  $forum->total_posts = 0;
  $forum->child_total_posts = 0;
  $forum->new_posts = 0;
  $forum->new_posts_text = '';
  $forum->new_posts_link = '';
  $forum->child_new_posts = 0;

  // Rename these to make them more descriptive.
  if (isset($forum->num_topics)) {
    $forum->total_topics = $forum->num_topics;
    unset($forum->num_topics);
  }
  if (isset($forum->num_posts)) {
    $forum->total_posts = $forum->num_posts;
    unset($forum->num_posts);
  }

  // If the viewer is authenticated, check for new topics and posts.
  global $user;
  if ($user->uid) {

    // New topics.
    $forum->new_topics = _forum_topics_unread($forum->tid, $user->uid);
    if ($forum->new_topics) {
      $forum->new_topics_text = format_plural($forum->new_topics, '1 new', '@count new');
      $forum->new_topics_link = url("forum/{$forum->tid}", array(
        'fragment' => 'new',
      ));
    }

    // New posts are optional because the query is slow.
    if (variable_get('advanced_forum_get_new_comments', 0)) {
      $forum->new_posts = advanced_forum_unread_replies_in_forum($forum->tid, $user->uid) + $forum->new_topics;
      if ($forum->new_posts) {
        $forum->new_posts_text = format_plural($forum->new_posts, '1 new', '@count new');
        $forum->new_posts_path = "forum/{$forum->tid}";
        $forum->new_posts_link = url("forum/{$forum->tid}", array(
          'fragment' => 'new',
        ));
      }
    }
  }

  // Process the "last post" object into a printable string.
  // Trying to copy the string back into the variable directly caused odd bugs
  // so we move it to a temp variable then unset the original.
  // Before doing so, however, we make a copy in case another module implementing
  // hook_TYPE_alter() needs access to the raw data.
  $forum->last_post_obj = $forum->last_post;
  $last_post = empty($forum->last_post) ? '' : $forum->last_post;
  unset($forum->last_post);
  $forum->last_post = theme('forum_submitted', $last_post);

  // Add in the taxonomy image, if any
  if (function_exists('taxonomy_image_display') && variable_get('advanced_forum_use_taxonomy_image', TRUE)) {
    $forum->forum_image = taxonomy_image_display($forum->tid, NULL, variable_get('advanced_forum_use_taxonomy_image_preset', ''));
  }
  drupal_alter('advanced_forum', $forum);
  return $forum;
}