summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGábor Hojtsy <gabor@hojtsy.hu>2007-08-07 11:43:05 +0000
committerGábor Hojtsy <gabor@hojtsy.hu>2007-08-07 11:43:05 +0000
commit2bfeda7672ae7c3516de004c6117af5f3669f8a4 (patch)
treee8192f786634d0618e43981ef3b3313a4a9bbd9b /modules
parent491b47f0a9df2c7ac39774b83ce60fc601c4af15 (diff)
downloadbrdo-2bfeda7672ae7c3516de004c6117af5f3669f8a4.tar.gz
brdo-2bfeda7672ae7c3516de004c6117af5f3669f8a4.tar.bz2
#164348 by pwolanin: improve book block performance
Diffstat (limited to 'modules')
-rw-r--r--modules/book/book.module38
1 files changed, 26 insertions, 12 deletions
diff --git a/modules/book/book.module b/modules/book/book.module
index a1fa59190..4d81375e6 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -166,27 +166,41 @@ function book_block($op = 'list', $delta = 0, $edit = array()) {
$block[0]['info'] = t('Book navigation');
return $block;
case 'view':
+ if (arg(0) == 'node' && is_numeric(arg(1))) {
+ $node = node_load(arg(1));
+ }
+ $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
$mode = variable_get('book_block_mode', 'all pages');
if ($mode == 'all pages') {
$block['subject'] = t('Book navigation');
$book_menus = array();
+ $pseudo_tree = array(0 => array('below' => FALSE));
foreach (book_get_books() as $book) {
- $book_menus[] = menu_tree_output(menu_tree_page_data($book['menu_name']));
+ if ($book['bid'] == $current_bid) {
+ // If the current page is a node associated with a book, the menu
+ // needs to be retrieved.
+ $book_menus[] = menu_tree_output(menu_tree_all_data($node->book['menu_name'], $node->book));
+ }
+ else {
+ // Since we know we will only display a link to the top node, there
+ // is no reason to run an additional menu tree query for each book.
+ $book['in_active_trail'] = FALSE;
+ $pseudo_tree[0]['link'] = $book;
+ $book_menus[] = menu_tree_output($pseudo_tree);
+ }
}
$block['content'] = theme('book_all_books_block', $book_menus);
}
- elseif (arg(0) == 'node' && is_numeric(arg(1))) {
+ elseif ($current_bid) {
// Only display this block when the user is browsing a book.
- $node = node_load(arg(1));
- if (isset($node->book['bid'])) {
- $title = db_result(db_query(db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.nid = %d'), $node->book['bid']));
- // Only show the block if the user has view access for the top-level node.
- if ($title) {
- $tree = menu_tree_all_data($node->book['menu_name'], $node->book);
- $data = array_shift($tree); // Should only be one element.
- $block['subject'] = theme('book_title_link', $data['link']);
- $block['content'] = ($data['below']) ? menu_tree_output($data['below']) : '';
- }
+ $title = db_result(db_query(db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.nid = %d'), $node->book['bid']));
+ // Only show the block if the user has view access for the top-level node.
+ if ($title) {
+ $tree = menu_tree_all_data($node->book['menu_name'], $node->book);
+ // There should only be one element at the top level.
+ $data = array_shift($tree);
+ $block['subject'] = theme('book_title_link', $data['link']);
+ $block['content'] = ($data['below']) ? menu_tree_output($data['below']) : '';
}
}
return $block;