diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-01-24 14:48:36 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-01-24 14:48:36 +0000 |
commit | 03752e35a41992c3d61f2591980020c87af257e7 (patch) | |
tree | dd8d9f51a47716785083591d82ca873c201c1057 /modules/book/book.module | |
parent | d407de4cec606623a5946805d2d42b580ccb116b (diff) | |
download | brdo-03752e35a41992c3d61f2591980020c87af257e7.tar.gz brdo-03752e35a41992c3d61f2591980020c87af257e7.tar.bz2 |
- Patch #34755 by chx et al: faster menu system. HEAD is temporary broken and there is no upgrade path yet.
Diffstat (limited to 'modules/book/book.module')
-rw-r--r-- | modules/book/book.module | 109 |
1 files changed, 50 insertions, 59 deletions
diff --git a/modules/book/book.module b/modules/book/book.module index 1d07a5f5b..8216d617a 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -85,65 +85,58 @@ function book_link($type, $node = NULL, $teaser = FALSE) { /** * Implementation of hook_menu(). */ -function book_menu($may_cache) { - $items = array(); - - if ($may_cache) { - $items[] = array( - 'path' => 'admin/content/book', - 'title' => t('Books'), - 'description' => t("Manage site's books and orphaned book pages."), - 'callback' => 'book_admin', - 'access' => user_access('administer nodes')); - $items[] = array( - 'path' => 'admin/content/book/list', - 'title' => t('List'), - 'type' => MENU_DEFAULT_LOCAL_TASK); - $items[] = array( - 'path' => 'admin/content/book/orphan', - 'title' => t('Orphan pages'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('book_admin_orphan'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 8); - $items[] = array( - 'path' => 'book', - 'title' => t('Books'), - 'callback' => 'book_render', - 'access' => user_access('access content'), - 'type' => MENU_SUGGESTED_ITEM); - $items[] = array( - 'path' => 'book/export', - 'callback' => 'book_export', - 'access' => user_access('access content'), - 'type' => MENU_CALLBACK); - } - else { - // Add the CSS for this module - // We put this in !$may_cache so it's only added once per request - drupal_add_css(drupal_get_path('module', 'book') .'/book.css'); - - // To avoid SQL overhead, check whether we are on a node page and whether the - // user is allowed to outline posts in books. - if (arg(0) == 'node' && is_numeric(arg(1)) && user_access('outline posts in books')) { - // Only add the outline-tab for non-book pages: - $result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d AND n.type != 'book'"), arg(1)); - if (db_num_rows($result) > 0) { - $items[] = array( - 'path' => 'node/'. arg(1) .'/outline', - 'title' => t('Outline'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('book_outline', arg(1)), - 'access' => user_access('outline posts in books'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2); - } - } - } +function book_menu() { + $items['admin/content/book'] = array( + 'title' => t('Books'), + 'description' => t("Manage site's books and orphaned book pages."), + 'page callback' => 'book_admin', + 'access arguments' => array('administer nodes'), + ); + $items['admin/content/book/list'] = array( + 'title' => t('List'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + ); + $items['admin/content/book/orphan'] = array( + 'title' => t('Orphan pages'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('book_admin_orphan'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 8, + ); + $items['book'] = array( + 'title' => t('Books'), + 'page callback' => 'book_render', + 'access arguments' => array('access content'), + 'type' => MENU_SUGGESTED_ITEM, + ); + $items['book/export/%/%'] = array( + 'page callback' => 'book_export', + 'page arguments' => array(2, 3), + 'type' => MENU_CALLBACK, + ); + $items['node/%/outline'] = array( + 'title' => t('Outline'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('book_outline', 1), + 'access callback' => '_book_outline_access', + 'access arguments' => array(1), + 'map arguments' => array('node_load', 1), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + ); return $items; } +function _book_outline_access($node) { + // Only add the outline-tab for non-book pages: + return user_access('outline posts in books') && $node && ($node->type != 'book'); +} + +function book_init() { + drupal_add_css(drupal_get_path('module', 'book') .'/book.css'); +} + /** * Implementation of hook_block(). * @@ -256,9 +249,7 @@ function book_form(&$node) { * Implementation of function book_outline() * Handles all book outline operations. */ -function book_outline($nid) { - $node = node_load($nid); - +function book_outline($node) { $form['parent'] = array('#type' => 'select', '#title' => t('Parent'), '#default_value' => $node->parent, @@ -637,7 +628,7 @@ function book_render() { * - an integer representing the node id (nid) of the node to export * */ -function book_export($type = 'html', $nid = 0) { +function book_export($type, $nid) { $type = drupal_strtolower($type); $node_result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), $nid); if (db_num_rows($node_result) > 0) { |