diff --git a/flat_book.admin.inc b/flat_book.admin.inc index 31ad691..3f253a7 100644 --- a/flat_book.admin.inc +++ b/flat_book.admin.inc @@ -7,7 +7,7 @@ /** * Form builder for flat_book settings form */ -function flat_book_admin() { +function flat_book_admin_form($form, &$form_state) { $form['flat_book_max_menu_depth'] = array( '#type' => 'textfield', '#title' => t('Maximum book depth'), @@ -27,25 +27,30 @@ function flat_book_admin() { ), '#description' => t('Display the book navigation at the bottom of each page in a flattened book'), ); - $form['#validate'][] = 'flat_book_admin_validate'; - $form['#submit'][] = 'flat_book_admin_submit'; - return system_settings_form($form); + $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); + + $form['#validate'][] = 'flat_book_admin_form_validate'; + $form['#submit'][] = 'flat_book_admin_form_submit'; + return $form; } /** * Validation function for admin form */ -function flat_book_admin_validate($form, $form_state) { +function flat_book_admin_form_validate($form, &$form_state) { if ($form_state['values']['flat_book_max_menu_depth'] < 1 || $form_state['values']['flat_book_max_menu_depth'] > 99 ) { - form_set_error('flat_book_max_menu_depth', 'Please enter a valid integer for the maximum menu depth', FALSE); + form_set_error('flat_book_sitewide_max_depth', 'Please enter a valid integer for the maximum menu depth', NULL); } } /** * Submit handler for admin form */ -function flat_book_admin_submit() { +function flat_book_admin_form_submit($form, &$form_state) { cache_clear_all('flat_book_node_', 'cache', TRUE); cache_clear_all('flat_book_node_admin_', 'cache', TRUE); + variable_set('flat_book_max_menu_depth', $form_state['values']['flat_book_max_menu_depth']); + variable_set('flat_book_display_book_navigation', $form_state['values']['flat_book_display_book_navigation']); + drupal_set_message(t('Changes have been saved.')); } diff --git a/flat_book.info b/flat_book.info index 5c623b1..33d51e5 100644 --- a/flat_book.info +++ b/flat_book.info @@ -1,6 +1,16 @@ - name = "Flat Book" description = "Flattens books below a given menu depth, and provides a 'jump to' menu for easy access" -core = "6.x" +core = 7.x package = "Book" dependencies[] = book +configure = "admin/config/content/flat_book" +files[] = flat_book.admin.inc +files[] = flat_book.install +files[] = flat_book.module + +; Information added by drupal.org packaging script on 2011-06-19 +version = "7.x-1.0-alpha" +core = 7.x +project = "flat_book" +datestamp = "1311608462 " + diff --git a/flat_book.install b/flat_book.install index 0b3116c..eee1353 100644 --- a/flat_book.install +++ b/flat_book.install @@ -6,24 +6,30 @@ */ /** - * Implementation of hook_uninstall(). + * Implements hook_uninstall(). * Delete settings variables, empty cache, and remove custom table. */ function flat_book_uninstall() { - drupal_uninstall_schema('flat_book'); - db_query("DELETE FROM {variable} WHERE name LIKE 'flat_book%%'"); + // TODO The drupal_(un)install_schema functions are called automatically in D7. + // drupal_uninstall_schema('flat_book') + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query("DELETE FROM {variable} WHERE name LIKE 'flat_book%%'") */ + db_delete('variable') + ->condition('name', 'flat_book%%', 'LIKE') + ->execute(); cache_clear_all(); } /** - * Implementation of hook_install(). + * Implements hook_install(). */ function flat_book_install() { - drupal_install_schema('flat_book'); + // TODO The drupal_(un)install_schema functions are called automatically in D7. + // drupal_install_schema('flat_book') } /** - * Implementation of hook_schema() + * Implements hook_schema(). */ function flat_book_schema() { $schema['flat_book_flattened_nodes'] = array( @@ -48,36 +54,3 @@ function flat_book_schema() { return $schema; } -/** - * Update to 6.x-1.2 - * {flat_book_flattened_nodes} table added. - * @see http://drupal.org/node/150220 for why I have duplicated - * the schema. - */ -function flat_book_update_6102() { - $schema['flat_book_flattened_nodes'] = array( - 'description' => 'Stores which nodes have been flattened per book', - 'fields' => array( - 'bid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => 'The {book}.bid of the book which contains the nodes being flattened.', - ), - 'nid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - 'description' => 'The {node}.nid of the book page being flattened.', - ), - ), - 'primary key' => array('nid'), - ); - $ret = array(); - db_create_table($ret, 'flat_book_flattened_nodes', $schema['flat_book_flattened_nodes']); - $max = variable_get('flat_book_max_menu_depth', 3); - variable_set('flat_book_sitewide_max_depth', $max); - variable_del('flat_book_max_menu_depth'); - return $ret; -} diff --git a/flat_book.module b/flat_book.module index 00bd3c4..8760452 100644 --- a/flat_book.module +++ b/flat_book.module @@ -16,7 +16,7 @@ define('FLAT_BOOK_USE_SITEWIDE_DEPTH', -1); define('FLAT_BOOK_FLATTEN_SELECTED', 0); /** - * Implementation of hook_help(). + * Implements hook_help(). */ function flat_book_help($path, $arg) { switch ($path) { @@ -26,7 +26,39 @@ function flat_book_help($path, $arg) { } /** - * Implementation of hook_init(). + * Implements hook_permission(). + */ +/* not used +function flat_book_permission() { + return array( + 'administer flat book' => array( + 'title' => t('Administer flat book'), + ), + ); +} +*/ + +/** +* Implement hook_menu(). +*/ +function flat_book_menu() { + $items = array(); + +$items['admin/config/content/flat_book'] = array( + 'title' => 'Flat Book', + 'description' => 'Configuration for the Flat Book module.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('flat_book_admin_form'), + 'access arguments' => array('administer users'), + 'file' => 'flat_book.admin.inc', + 'type' => MENU_NORMAL_ITEM, +); + + return $items; +} + +/** + * Implements hook_init(). * * If the user requests a page that is deeper than the maximum depth, redirect * to the ancestor that is at (or above) the maximum depth. @@ -38,7 +70,7 @@ function flat_book_init() { $node = menu_get_object(); if (isset($node->book)) { if (($ancestor_nid = _flat_book_find_flattened_ancestor($node->book)) > 0) { - drupal_goto('node/'. $ancestor_nid, NULL, 'booknode-'. $node->nid); + drupal_goto('node/' . $ancestor_nid, array('fragment' => 'booknode-' . $node->nid)); } } } @@ -66,14 +98,14 @@ function _flat_book_find_flattened_ancestor($book) { //If we are below the flatten level, return immediately if ($flatten_level != 0 && $book['depth'] > $flatten_level) { $mlid = $book['p' . $flatten_level]; - $cache[$book['nid']] = db_result(db_query('SELECT nid FROM {book} WHERE mlid = %d', $mlid)); + $cache[$book['nid']] = db_query('SELECT nid FROM {book} WHERE mlid = :mlid', array(':mlid' => $mlid))->fetchField(); return $cache[$book['nid']]; } //Get all branches in this book that are selectively flattened $flattened_nids = array(); - $result = db_query('SELECT nid FROM {flat_book_flattened_nodes} WHERE bid = %d', $book['bid']); - while ($record = db_fetch_object($result)) { + $result = db_query('SELECT nid FROM {flat_book_flattened_nodes} WHERE bid = :bid', array(':bid' => $book['bid'])); + foreach ($result as $record) { //If we are on a flattened page, return immediately if ($book['nid'] == $record->nid) { $cache[$book['nid']] = FLAT_BOOK_FLATTEN_PAGE; @@ -94,7 +126,7 @@ function _flat_book_find_flattened_ancestor($book) { //If we are under a flattened branch, return the nid $result = db_query($query); - while($record = db_fetch_object($result)) { + foreach ($result as $record) { if (in_array($record->nid, $flattened_nids)) { return $record->nid; } @@ -105,7 +137,8 @@ function _flat_book_find_flattened_ancestor($book) { if ($book['depth'] == $flatten_level) { $cache[$book['nid']] = FLAT_BOOK_FLATTEN_PAGE; return FLAT_BOOK_FLATTEN_PAGE; - } else { + } + else { //If none of the above cases is true, this page is not flattened $cache[$book['nid']] = FLAT_BOOK_NOT_FLAT; return FLAT_BOOK_NOT_FLAT; @@ -117,10 +150,10 @@ function _flat_book_find_flattened_ancestor($book) { } /** - * Implementation of hook_form_alter() + * Implements hook_form_alter(). */ function flat_book_form_alter(&$form, $form_state, $form_id) { - switch($form_id) { + switch ($form_id) { case 'book_admin_settings': for ($i = 1; $i <= 8; $i++) { $options[$i] = $i; @@ -149,7 +182,7 @@ function flat_book_form_alter(&$form, $form_state, $form_id) { '#collapsible' => FALSE, '#weight' => 13, ); - $flattened = db_result(db_query('SELECT count(nid) FROM {flat_book_flattened_nodes} WHERE nid = %d', $form['#node']->nid)); + $flattened = db_query('SELECT count(nid) FROM {flat_book_flattened_nodes} WHERE nid = :nid', array(':nid' => $form['#node']->nid))->fetchField(); $form['flat_book']['flatten_branch'] = array( '#type' => 'checkbox', '#title' => t('Flatten this branch'), @@ -162,11 +195,11 @@ function flat_book_form_alter(&$form, $form_state, $form_id) { break; case 'book_admin_edit': $flat_nids = array(); - $result = db_query('SELECT nid FROM {flat_book_flattened_nodes} WHERE bid = %d', $form['#node']->book['bid']); - while($record = db_fetch_object($result)) { + $result = db_query('SELECT nid FROM {flat_book_flattened_nodes} WHERE bid = :bid', array(':bid' => $form['#node']->book['bid'])); + foreach ($result as $record) { $flat_nids[] = $record->nid; } - foreach($form['table'] as &$value) { + foreach ($form['table'] as &$value) { if (is_array($value)) { $default_value = in_array($value['nid']['#value'], $flat_nids); $value['flatten'] = array( @@ -174,7 +207,7 @@ function flat_book_form_alter(&$form, $form_state, $form_id) { '#default_value' => $default_value, ); $value['flatten_depth'] = array( - '#value' => $value['depth']['#value'], + '#markup' => $value['depth']['#value'], ); } } @@ -199,7 +232,7 @@ function flat_book_form_alter(&$form, $form_state, $form_id) { '#weight' => 5, ); $form['flat_book']['link_text'] = array( - '#value' => t('The sitewide flatten depth is @value. You may change it !link, or override it below.', array('@value' => variable_get('flat_book_sitewide_max_depth', 3), '!link' => l(t('here'),'admin/content/book/settings'))), + '#markup' => t('The sitewide flatten depth is @value. You may change it !link, or override it below.', array('@value' => variable_get('flat_book_sitewide_max_depth', 3), '!link' => l(t('here'), 'admin/content/book/settings'))), ); $form['table']['#theme'] = 'flat_book_admin_table'; $form['#submit'][] = '_flat_book_book_admin_edit_submit'; @@ -229,13 +262,19 @@ function _flat_book_set_branch_flatten($bid, $nid, $setting) { 'bid' => $bid, 'nid' => $nid, ); - if (!db_result(db_query('SELECT count(nid) FROM {flat_book_flattened_nodes} WHERE nid = %d', $nid))) { + if (!db_query('SELECT count(nid) FROM {flat_book_flattened_nodes} WHERE nid = :nid', array(':nid' => $nid))->fetchField()) { drupal_write_record('flat_book_flattened_nodes', $record); - } else { + } + else { drupal_write_record('flat_book_flattened_nodes', $record, 'nid'); } - } else { - db_query('DELETE FROM {flat_book_flattened_nodes} WHERE nid = %d', $nid); + } + else { + // TODO Please review the conversion of this statement to the D7 database API syntax. + /* db_query('DELETE FROM {flat_book_flattened_nodes} WHERE nid = %d', $nid) */ + db_delete('flat_book_flattened_nodes') + ->condition('nid', $nid) + ->execute(); } } @@ -244,7 +283,7 @@ function _flat_book_set_branch_flatten($bid, $nid, $setting) { */ function _flat_book_book_admin_edit_submit($form, $form_state) { variable_set('flat_book_bid_' . $form['#node']->book['bid'] . '_depth', $form_state['values']['flatten_depth']); - foreach($form_state['values']['table'] as $value) { + foreach ($form_state['values']['table'] as $value) { _flat_book_set_branch_flatten($form['#node']->book['bid'], $value['nid'], $value['flatten']); } } @@ -261,23 +300,21 @@ function _flat_book_book_outline_form_submit($form, &$form_state) { * Clear the cache associated with the root page of a flattened book */ function _flat_book_update_cache($node) { - $result = db_query('SELECT nid FROM {book} WHERE bid = %d', $node->book['bid']); - while($record = db_fetch_object($result)) { + $result = db_query('SELECT nid FROM {book} WHERE bid = :bid', array(':bid' => $node->book['bid'])); + foreach ($result as $record) { cache_clear_all('flat_book_node_' . $record->nid, 'cache'); cache_clear_all('flat_book_node_admin_' . $record->nid, 'cache'); } } /** - * Implementation of hook_nodeapi(). + * Implements hook_nodeapi(). * * Squishes the node and its children into one page. */ -function flat_book_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { +function flat_book_node_view($node, $view_mode, $langcode) { // If the node is not in a book, this hook doesn't apply. if (isset($node->book)) { - switch ($op) { - case 'view': // We rely on node_build_content() to generate the HTML for this node, // which will invoke all hook_nodeapis for the node (including this one!) // The firstrun variable ensures this hook will only be called once, @@ -292,7 +329,8 @@ function flat_book_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { //Check the cache tables: admin pages are cached seperately due to edit links if ($is_admin) { $content = cache_get('flat_book_node_admin_' . $node->nid); - } else { + } + else { $content = cache_get('flat_book_node_' . $node->nid); } if (!empty($content->data)) { @@ -301,30 +339,40 @@ function flat_book_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { else { //Flatten the subtree and cache the result $tree = book_menu_subtree_data($node->book); - $children = _flat_book_export_traverse($tree, 0, $node, $is_admin); - $content = $node->content['body']['#value'] . $children; - + $content = _flat_book_export_traverse($tree, 0, $node, $is_admin); //Cache the results: admin pages are cached seperately due to edit links if ($is_admin) { cache_set('flat_book_node_admin_' . $node->nid, serialize($content), 'cache'); - } else { + } + else { cache_set('flat_book_node_' . $node->nid, serialize($content), 'cache'); } } } //Replace the node body content with the content we found/created - $node->content['body']['#value'] = $content; + $node->content['children_book_pages']['#markup'] = $content; + $node->content['children_book_pages']['#weight'] = 5; + + $display_book_nav = variable_get('flat_book_display_book_navigation', 0); + if ($display_book_nav == 0 ) { + $node->content['book_navigation']=array(); } } - break; - case 'update': - case 'insert': - case 'delete': + } + } +} + +function flat_book_node_update($node) { _flat_book_update_cache($node); - break; } + +function flat_book_node_insert($node) { + _flat_book_update_cache($node); } + +function flat_book_node_delete($node) { + _flat_book_update_cache($node); } /** @@ -359,14 +407,14 @@ function _flat_book_visit($node, $children, $depth, $root_node, $is_admin) { if ($depth == 0) { return $children; } - $node = node_build_content($node, FALSE, FALSE); + node_build_content($node); $node->content['book_navigation']['#access'] = FALSE; - $node->body = drupal_render($node->content); + $node->rendered = drupal_render($node->content); $edit_link = l(t('edit'), "node/{$node->nid}/edit"); $outline_link = l(t('outline'), "node/{$node->nid}/outline"); - return theme('flat_book_node_export_html', $node, $children, $root_node->depth - $depth, $root_node->nid, $is_admin, $edit_link, $outline_link); + return theme('flat_book_node_export_html', array('node' => $node, 'children' => $children, 'flatten_depth' => $root_node->book['depth'] - $depth, 'root_nid' => $root_node->nid, 'is_admin' => $is_admin, 'edit_link' => $edit_link, 'outline_link' => $outline_link)); } /** @@ -389,7 +437,8 @@ function _flat_book_menu_tree_toc($tree, $depth = 0, $item_list = array()) { $item['data'] = l($subtree['link']['link_title'], "", array( "fragment" => "booknode-{$subtree['link']['nid']}", //We need to specify external or the link will go to '/' - "external" => "TRUE")); + "external" => "TRUE", + )); $item['children'] = _flat_book_menu_tree_toc($subtree['below'], $depth + 1); $item_list[] = $item; } @@ -398,12 +447,12 @@ function _flat_book_menu_tree_toc($tree, $depth = 0, $item_list = array()) { } /** - * Implementation of hook_theme(). + * Implements hook_theme(). */ function flat_book_theme() { return array( 'flat_book_node_export_html' => array( - 'arguments' => array( + 'variables' => array( 'node' => NULL, 'children' => NULL, 'flatten_depth' => NULL, @@ -414,16 +463,35 @@ function flat_book_theme() { ), 'template' => 'flat-book-node-export-html', // Make sure to include the same variables the book theme includes - 'preprocess functions' => array('template_preprocess_book_node_export_html'), + 'preprocess functions' => array('template_preprocess_flat_book_node_export_html'), ), 'flat_book_toc_title' => array(), 'flat_book_admin_table' => array( - 'arguments' => array('form' => NULL), + 'render element' => 'form', ), ); } /** + * Process variables for book-node-export-html.tpl.php. + * + * The $variables array contains the following arguments: + * - $node + * - $children + * + * @see book-node-export-html.tpl.php + */ +function template_preprocess_flat_book_node_export_html(&$variables) { + $variables['depth'] = $variables['node']->book['depth']; + $variables['title'] = check_plain($variables['node']->title); + $variables['content'] = $variables['node']->rendered; + $variables['classes_array'] = array('node-flat-book'); + $variables['attributes_array'] = array(); + $variables['title_attributes_array'] = array(); + $variables['content_attributes_array'] = array(); +} + +/** * Preprocess the book navigation template. * If we are on a flattened page, remove links to children. */ @@ -439,12 +507,16 @@ function flat_book_preprocess_book_navigation(&$variables) { * @ingroup themeable * @see book_admin_table() */ -function theme_flat_book_admin_table($form) { +function theme_flat_book_admin_table(&$variables) { + $form = $variables['form']; drupal_add_tabledrag('book-outline', 'match', 'parent', 'book-plid', 'book-plid', 'book-mlid', TRUE, MENU_MAX_DEPTH - 2); drupal_add_tabledrag('book-outline', 'order', 'sibling', 'book-weight'); - $header = array(t('Title'), t('Depth'), t('Flatten'), t('Weight'), t('Parent'), array('data' => t('Operations'), 'colspan' => '3')); + $header = array(t('Title'), t('Depth'), t('Flatten'), t('Weight'), t('Parent'), array( + 'data' => t('Operations'), + 'colspan' => '3', + )); $rows = array(); $destination = drupal_get_destination(); @@ -454,19 +526,19 @@ function theme_flat_book_admin_table($form) { $href = $form[$key]['href']['#value']; // Add special classes to be used with tabledrag.js. - $form[$key]['plid']['#attributes']['class'] = 'book-plid'; - $form[$key]['mlid']['#attributes']['class'] = 'book-mlid'; - $form[$key]['weight']['#attributes']['class'] = 'book-weight'; + $form[$key]['plid']['#attributes']['class'] = array('book-plid'); + $form[$key]['mlid']['#attributes']['class'] = array('book-mlid'); + $form[$key]['weight']['#attributes']['class'] = array('book-weight'); $data = array( - theme('indentation', $form[$key]['depth']['#value'] - 2) . drupal_render($form[$key]['title']), + theme('indentation', array('size' => $form[$key]['depth']['#value'] - 2)) . drupal_render($form[$key]['title']), drupal_render($form[$key]['flatten_depth']), drupal_render($form[$key]['flatten']), drupal_render($form[$key]['weight']), drupal_render($form[$key]['plid']) . drupal_render($form[$key]['mlid']), l(t('view'), $href), - $access ? l(t('edit'), 'node/'. $nid .'/edit', array('query' => $destination)) : ' ', - $access ? l(t('delete'), 'node/'. $nid .'/delete', array('query' => $destination) ) : ' ', + $access ? l(t('edit'), 'node/' . $nid . '/edit', array('query' => $destination)) : ' ', + $access ? l(t('delete'), 'node/' . $nid . '/delete', array('query' => $destination) ) : ' ', ); $row = array('data' => $data); if (isset($form[$key]['#attributes'])) { @@ -476,11 +548,11 @@ function theme_flat_book_admin_table($form) { $rows[] = $row; } - return theme('table', $header, $rows, array('id' => 'book-outline')); + return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'book-outline'))); } /** - * Implementation of hook_block(). + * Implements hook_block(). * Ideally we would alter the Book Navigation block provided by the book module. * However hook_block_alter does not exist presently. Instead, we provide a * seperate Flat Book Navigation block with the needed functionality. @@ -496,19 +568,26 @@ function theme_flat_book_admin_table($form) { * @see book_block() * from which this is copied. */ -function flat_book_block($op = 'list', $delta = 0, $edit = array()) { - $block = array(); - switch ($op) { - case 'list': - $block[0]['info'] = t('Flat Book navigation'); - $block[0]['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE; - - $block[1]['info'] = t('Jump To:'); - $block[1]['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE; - return $block; - case 'view': - switch($delta) { - case 0: + +/** + * Implements hook_block_info(). + */ +function flat_book_block_info() { + $blocks = array(); + $blocks['fb-nav']['info'] = t('Flat Book navigation'); + $blocks['fb-nav']['cache'] = DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE; + + $blocks['fb-jump']['info'] = t('Jump To:'); + $blocks['fb-jump']['cache'] = DRUPAL_CACHE_PER_PAGE | DRUPAL_CACHE_PER_ROLE; + return $blocks; +} + +/** + * Implements hook_block_view(). + */ +function flat_book_block_view($delta) { + switch ($delta) { + case 'fb-nav': $current_bid = 0; if ($node = menu_get_object()) { $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; @@ -529,40 +608,54 @@ function flat_book_block($op = 'list', $delta = 0, $edit = array()) { // 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; + // Check whether user can access the book link. + $book_node = node_load($book['nid']); + $book['access'] = node_access('view', $book_node); $pseudo_tree[0]['link'] = $book; $book_menus[$book_id] = menu_tree_output($pseudo_tree); } } - $block['content'] = theme('book_all_books_block', $book_menus); + $book_menus['#theme'] = 'book_all_books_block'; + $block['content'] = $book_menus; } elseif ($current_bid) { // Only display this block when the user is browsing a book. - $title = db_result(db_query(db_rewrite_sql('SELECT n.title FROM {node} n WHERE n.nid = %d'), $node->book['bid'])); + $select = db_select('node', 'n') + ->fields('n', array('title')) + ->condition('nid', $node->book['bid']) + ->addTag('node_access'); + $title = $select->execute()->fetchField(); // 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); _flat_book_menu_tree_all_data_alter($tree); // There should only be one element at the top level. $data = array_shift($tree); - $block['subject'] = theme('book_title_link', $data['link']); + $block['subject'] = theme('book_title_link', array('link' => $data['link'])); $block['content'] = ($data['below']) ? menu_tree_output($data['below']) : ''; } } return $block; break; - case 1: + case 'fb-jump': + $block = array(); if ($node = menu_get_object()) { - if (isset($node->book) && _flat_book_find_flattened_ancestor($node->book) == FLAT_BOOK_FLATTENED_PAGE) { - $block['subject'] = theme('flat_book_toc_title', $node); + if (isset($node->book) && _flat_book_find_flattened_ancestor($node->book) == FLAT_BOOK_FLATTEN_PAGE) { + $block['subject'] = theme('flat_book_toc_title', array('node' => $node)); $tree = book_menu_subtree_data($node->book); - $block['content'] = theme_item_list(_flat_book_menu_tree_toc($tree)); + $block['content'] = theme_item_list(array('items' => _flat_book_menu_tree_toc($tree),'title'=>NULL,'type' => 'ul','attributes' => array())); } } return $block; break; } - case 'configure': +} + +/** + * Implements hook_block_configure(). + */ +function flat_book_block_configure($delta) { $options = array( 'all pages' => t('Show block on all pages'), 'book pages' => t('Show block only on book pages'), @@ -575,10 +668,13 @@ function flat_book_block($op = 'list', $delta = 0, $edit = array()) { '#description' => t("If Show block on all pages is selected, the block will contain the automatically generated menus for all of the site's books. If Show block only on book pages is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The Page specific visibility settings or other visibility settings can be used in addition to selectively display this block."), ); return $form; - case 'save': +} + +/** + * Implements hook_block_save(). + */ +function flat_book_block_save($delta, $edit) { variable_set('flat_book_block_mode', $edit['flat_book_block_mode']); - break; - } } /**