View source
<?php
define('BOOKBLOCK_DEBUG', FALSE);
function bookblock_menu() {
$items['admin/content/book/blocks'] = array(
'title' => 'Book Blocks',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'bookblock_admin_settings',
),
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'bookblock.admin.inc',
);
return $items;
}
function bookblock_block_info() {
$block = array();
$books = book_get_books();
$navigationblocks = variable_get('bookblock_books', array());
if (BOOKBLOCK_DEBUG) {
watchdog('bookblock', '$navigationblocks = ' . implode(',', $navigationblocks));
}
foreach ($navigationblocks as $navigationblock) {
if (isset($books[$navigationblock])) {
$block[$navigationblock]['info'] = t('Book block: @title', array(
'@title' => $books[$navigationblock]['title'],
));
}
}
return $block;
}
function bookblock_block_view($delta = '') {
$block = array();
$expansion = variable_get('bookblock_block_options_' . $delta, TRUE);
$node_info = menu_get_object();
$bid = NULL;
if (isset($node_info->book['bid'])) {
$bid = $node_info->book['bid'];
}
if (!$node_info || $bid != $delta || !$expansion) {
$node_info = db_query('SELECT n.nid, n.uid, n.status, n.type FROM {node} n WHERE n.nid = :nid', array(
':nid' => $delta,
))
->fetchObject();
$node_info->book = bookblock_book_info_load($delta);
}
if (node_access('view', $node_info) && isset($node_info->book)) {
if ($expansion) {
$tree = menu_tree_page_data($node_info->book['menu_name']);
}
else {
$tree = menu_tree_all_data($node_info->book['menu_name'], $node_info->book);
_bookblock_fix_tree($tree);
}
$data = array_shift($tree);
if ($expansion && !$data['below']) {
$tree = menu_tree_all_data($node_info->book['menu_name'], $node_info->book);
$data = array_shift($tree);
}
$block['subject'] = theme('book_title_link', array(
'link' => $data['link'],
));
if ($data['below']) {
$block['content'] = menu_tree_output($data['below']);
}
}
return $block;
}
function bookblock_block_configure($delta) {
$form['bookblock_block_options'] = array(
'#type' => 'checkbox',
'#title' => t('Allow menu to expand'),
'#default_value' => variable_get('bookblock_block_options_' . $delta, TRUE),
'#description' => t("If checked, the menu will expand to show child pages as the user navigates through the book. Otherwise it will only show the first level of links. You may not want the menu to expand in the footer, for example."),
);
return $form;
}
function bookblock_block_save($delta, $edit) {
variable_set('bookblock_block_options_' . $delta, $edit['bookblock_block_options']);
}
function bookblock_help($path, $arg) {
switch ($path) {
case 'admin/content/book/blocks':
$output = '<h4>' . t('Configuration') . '</h4>';
$output .= '<p>' . t('The books you have created on your site will be listed below. Select which ones you would like to create a <em>book navigation block</em> for and they will then be available to you on the <a href="@admin-block">blocks administration page</a>, where you can control on which pages they appear and in which region.', array(
'@admin-block' => url('admin/structure/block'),
)) . '</p>';
$output .= '<p><em>' . t('N.B. Only books with child pages will actually display anything!') . '</em></p>';
return $output;
case 'admin/help#bookblock':
$output = '<h4>' . t('About') . '</h4>';
$output .= '<p>' . t('The core book module provides one <em>book navigation block</em>, which is very useful, but occasionally you may need a book navigation block on specific non-book pages or in an additional region (e.g. in the footer).') . '</p>';
$output .= '<h4>' . t('Configuration') . '</h4>';
$output .= '<p>' . t('The books you have created on your site will be listed. Select which ones you would like to create a <em>book navigation block</em> for and they will then be available to you on the <a href="@admin-block">blocks administration page</a>, where you can control on which pages they appear and in which region.', array(
'@admin-block' => url('admin/structure/block'),
)) . '</p>';
$output .= '<p>' . t('Each <em>book navigation block</em> can also be configured from the blocks administration page (click <em>configure</em> next to the block name). The title can be replaced and you can control whether the menu expands to reveal child pages or not.') . '</p>';
$output .= '<p><em>' . t('N.B. Only books with child pages will actually display anything!') . '</em></p>';
return $output;
}
}
function bookblock_book_info_load($nid) {
if ($book = db_query('SELECT * FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid = :nid', array(
':nid' => $nid,
))
->fetchAssoc()) {
$book['href'] = $book['link_path'];
$book['title'] = $book['link_title'];
$book['options'] = unserialize($book['options']);
return $book;
}
}
function _bookblock_fix_tree(&$tree) {
}