? .buildpath ? .project ? .settings ? 520736-25-forum-menu-load-crazyness.patch ? 520736-forum-menu-load-crazyness.patch ? 86299-unset-current-password-101.patch ? sites Index: modules/forum/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v retrieving revision 1.558 diff -u -p -r1.558 forum.module --- modules/forum/forum.module 8 Mar 2010 15:40:25 -0000 1.558 +++ modules/forum/forum.module 10 Mar 2010 18:09:13 -0000 @@ -91,6 +91,14 @@ function forum_menu() { $items['forum'] = array( 'title' => 'Forums', 'page callback' => 'forum_page', + 'page arguments' => array(), + 'access arguments' => array('access content'), + 'file' => 'forum.pages.inc', + ); + $items['forum/%forum_forum'] = array( + 'title' => 'Forums', + 'page callback' => 'forum_page', + 'page arguments' => array(1), 'access arguments' => array('access content'), 'file' => 'forum.pages.inc', ); @@ -163,9 +171,8 @@ function forum_menu_local_tasks_alter(&$ // Add action link to 'node/add/forum' on 'forum' page. if ($root_path == 'forum') { $tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0] : 0); - $forums = forum_get_forums($tid); - $parents = taxonomy_get_parents_all($tid); - if ($forums || $parents) { + $forum_term = forum_forum_load($tid); + if ($forum_term) { $vid = variable_get('forum_nav_vocabulary', 0); $vocabulary = taxonomy_vocabulary_load($vid); @@ -178,7 +185,7 @@ function forum_menu_local_tasks_alter(&$ '#theme' => 'menu_local_action', '#link' => array( 'title' => t('Add new @node_type', array('@node_type' => node_type_get_name($type))), - 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $tid, + 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $forum_term->tid, ), ); } @@ -704,17 +711,49 @@ function forum_url_outbound_alter(&$path * @param $tid * Taxonomy ID of the vocabulary that holds the forum list. * @return - * Array of object containing the forum information. + * Array of object containing the forum information, with the following keys: + * - tid (String) + * - vid (String) + * - name (String) + * - description (String) + * - format (String) + * - weight (String) + * - vocabulary_machine_name (String) + * - rdf_mapping (Array) + * - parents (Array) + * - forums (Array) */ -function forum_get_forums($tid = 0) { +function forum_forum_load($tid) { $cache = &drupal_static(__FUNCTION__, array()); if (isset($cache[$tid])) { return $cache[$tid]; } - $forums = array(); $vid = variable_get('forum_nav_vocabulary', 0); + + // Load and validate the parent term. + if ($tid) { + $forum_term = taxonomy_term_load($tid); + if (!$forum_term || ($forum_term->vid != $vid)) { + return $cache[$tid] = FALSE; + } + } + else if ($tid === 0) { + $forum_term = (object) array( + 'tid' => 0, + ); + } + + if (!$forum_term->tid || in_array($forum_term->tid, variable_get('forum_containers', array()))) { + $forum_term->container = 1; + } + + // Load parent terms. + $forum_term->parents = taxonomy_get_parents_all($forum_term->tid); + + // Load the tree below. + $forums = array(); $_forums = taxonomy_get_tree($vid, $tid); if (count($_forums)) { @@ -773,9 +812,9 @@ function forum_get_forums($tid = 0) { $forums[$forum->tid] = $forum; } - $cache[$tid] = $forums; + $forum_term->forums = $forums; - return $forums; + return $cache[$tid] = $forum_term;; } /** Index: modules/forum/forum.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.pages.inc,v retrieving revision 1.3 diff -u -p -r1.3 forum.pages.inc --- modules/forum/forum.pages.inc 9 Oct 2009 00:59:59 -0000 1.3 +++ modules/forum/forum.pages.inc 10 Mar 2010 18:09:13 -0000 @@ -9,16 +9,21 @@ /** * Menu callback; prints a forum listing. */ -function forum_page($tid = 0) { - $topics = ''; +function forum_page($forum_term = NULL) { + if (!isset($forum_term)) { + // On the main page, display all the top-level forums. + $forum_term = forum_forum_load(0); + } + $forum_per_page = variable_get('forum_per_page', 25); $sortby = variable_get('forum_order', 1); - $forums = forum_get_forums($tid); - $parents = taxonomy_get_parents_all($tid); - if ($tid && !in_array($tid, variable_get('forum_containers', array()))) { - $topics = forum_get_topics($tid, $sortby, $forum_per_page); + if (empty($forum_term->container)) { + $topics = forum_get_topics($forum_term->tid, $sortby, $forum_per_page); + } + else { + $topics = ''; } - return theme('forums', array('forums' => $forums, 'topics' => $topics, 'parents' => $parents, 'tid' => $tid, 'sortby' => $sortby, 'forums_per_page' => $forum_per_page)); + return theme('forums', array('forums' => $forum_term->forums, 'topics' => $topics, 'parents' => $forum_term->parents, 'tid' => $forum_term->tid, 'sortby' => $sortby, 'forums_per_page' => $forum_per_page)); } Index: modules/forum/forum.test =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.test,v retrieving revision 1.48 diff -u -p -r1.48 forum.test --- modules/forum/forum.test 10 Mar 2010 17:59:00 -0000 1.48 +++ modules/forum/forum.test 10 Mar 2010 18:09:13 -0000 @@ -230,7 +230,7 @@ class ForumTestCase extends DrupalWebTes // Assert that the forum no longer exists. $this->drupalGet('forum/' . $tid); - $this->assertRaw(t('No forums defined'), 'The forum was not found'); + $this->assertResponse(404, 'The forum was not found'); } /**