--- modules/book/book.module.orig 2009-02-25 12:47:37.000000000 +0100 +++ modules/book/book.module 2010-05-17 00:01:10.000000000 +0200 @@ -214,6 +214,37 @@ function book_block($op = 'list', $delta // There should only be one element at the top level. $data = array_shift($tree); $block['subject'] = theme('book_title_link', $data['link']); + /* With many pages on the same depth one level below the index page for the book + the bookmenu becomes very long. This code was added to create a "context sensitive" + menu when browsing a book: an x number of pages above the current one and the same number + of pages below the current one is shown in the book menu. + At the index page and the first (x + 1) pages only the first (2*x + 1) pages are shown. */ + if (isset($data['below'])) { + $no_shown_above_below = 10; + $totaal = count($data['below']); + if ($totaal > (2 * $no_shown_above_below + 1)) { + $nummer_in_array = 0; + $on_index_page = 1; + // we need to know where we are in the menu array + foreach($data['below'] as $key => $subdata) { + $nummer_in_array++; + if ($subdata['link']['in_active_trail'] == 1) { + $on_index_page--; + break; // active page found + } + } // end foreach($data['below'] as $key => $subdata) + if (($nummer_in_array < ($no_shown_above_below + 1) && $on_index_page == 0) | $on_index_page == 1) { + // early page or on index page + $data['below'] = array_slice($data['below'], 0, (2 * $no_shown_above_below + 1)); + } elseif ($totaal - $nummer_in_array < $no_shown_above_below && $on_index_page == 0) { + // close to the end of the number of pages + $data['below'] = array_slice($data['below'], ($totaal - (2 * $no_shown_above_below + 1)), (2 * $no_shown_above_below + 1)); + } else { + $data['below'] = array_slice($data['below'], ($nummer_in_array - $no_shown_above_below - 1), (2 * $no_shown_above_below + 1)); + } + } // end if ($totaal > (2 * $no_shown_above_below + 1)) + } // end if (isset($data['below'])) + $block['content'] = ($data['below']) ? menu_tree_output($data['below']) : ''; } }