function book_block in Drupal 4
Same name and namespace in other branches
- 5 modules/book/book.module \book_block()
- 6 modules/book/book.module \book_block()
Implementation of hook_block().
Displays the book table of contents in a block when the current page is a single-node view of a book node.
File
- modules/
book.module, line 141 - Allows users to collaboratively author a book.
Code
function book_block($op = 'list', $delta = 0) {
$block = array();
if ($op == 'list') {
$block[0]['info'] = t('Book navigation');
return $block;
}
else {
if ($op == 'view') {
// Only display this block when the user is browsing a book:
if (arg(0) == 'node' && is_numeric(arg(1))) {
$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'), arg(1));
if (db_num_rows($result) > 0) {
$node = db_fetch_object($result);
$path = book_location($node);
$path[] = $node;
$expand = array();
foreach ($path as $key => $node) {
$expand[] = $node->nid;
}
$block['subject'] = check_plain($path[0]->title);
$block['content'] = book_tree($expand[0], 5, $expand);
}
}
return $block;
}
}
}