forum.pages.inc 1.76 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * User page callbacks for the Forum module.
6 7 8
 */

/**
9 10 11 12 13 14 15 16 17 18
 * Page callback: Prints a forum listing.
 *
 * @param $forum_term
 *   A tree of all forums for a given taxonomy term ID. Defaults to NULL. See
 *   the return object of forum_forum_load() for a complete definition.
 *
 * @return
 *   A string containing HTML representing the themed forum listing.
 *
 * @see forum_menu()
19
 */
20
function forum_page($forum_term = NULL) {
21
  $config = config('forum.settings');
22 23
  $vocabulary = entity_load('taxonomy_vocabulary', $config->get('vocabulary'));

24 25 26
  if (!isset($forum_term)) {
    // On the main page, display all the top-level forums.
    $forum_term = forum_forum_load(0);
27 28 29 30
    // Set the page title to forum's vocabulary name.
    drupal_set_title($vocabulary->label());
  }

31
  if ($forum_term->id() && array_search($forum_term->id(), $config->get('containers')) === FALSE) {
32 33 34 35 36 37 38
    // Add RSS feed for forums.
    drupal_add_feed('taxonomy/term/' . $forum_term->id() . '/feed', 'RSS - ' . $forum_term->label());
  }

  if (empty($forum_term->forums) && empty($forum_term->parents)) {
    // Root of empty forum.
    drupal_set_title(t('No forums defined'));
39 40
  }

41
  $forum_per_page = $config->get('topics.page_limit');
42
  $sort_by = $config->get('topics.order');
43

44
  if (empty($forum_term->container)) {
45
    $topics = forum_get_topics($forum_term->id(), $sort_by, $forum_per_page);
46 47 48
  }
  else {
    $topics = '';
49 50
  }

51 52 53 54 55
  $build = array(
    '#theme' => 'forums',
    '#forums' => $forum_term->forums,
    '#topics' => $topics,
    '#parents' => $forum_term->parents,
56
    '#tid' => $forum_term->id(),
57
    '#sortby' => $sort_by,
58 59
    '#forums_per_page' => $forum_per_page,
  );
60
  $build['#attached']['css'][] = drupal_get_path('module', 'forum') . '/css/forum.module.css';
61
  return $build;
62
}