diff options
Diffstat (limited to 'modules/book/book.module')
-rw-r--r-- | modules/book/book.module | 82 |
1 files changed, 51 insertions, 31 deletions
diff --git a/modules/book/book.module b/modules/book/book.module index bf55805b0..c7d754fb0 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -69,33 +69,53 @@ function book_link($type, $node = 0, $main = 0) { if ($type == 'node' && $node->type == 'book') { if (book_access('update', $node)) { - $links[] = l(t('edit this page'), "node/edit/$node->nid", array('title' => t('Suggest an update for this book page.'))); + $links[] = l(t('edit this page'), "node/$node->nid/edit", array('title' => t('Suggest an update for this book page.'))); } if (!$main) { $links[] = l(t('printer-friendly version'), "book/print/$node->nid", array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))); } } - if ($type == 'system') { - menu('node/add/book', t('book page'), user_access('maintain books') ? MENU_FALLTHROUGH : MENU_DENIED, 0); - - menu('admin/node/book', t('books'), user_access('administer nodes') ? 'book_admin' : MENU_DENIED, 4); - menu('admin/node/book/orphan', t('orphan pages'), user_access('administer nodes') ? 'book_admin_orphan' : MENU_DENIED, 8); - menu('admin/node/book/help', t('help'), user_access('administer nodes') ? 'book_help_page' : MENU_DENIED, 9); - - $result = db_query('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title'); - while ($book = db_fetch_object($result)) { - menu("admin/node/book/$book->nid", t('"%title" book', array('%title' => $book->title)), MENU_FALLTHROUGH); - } - menu('book', t('books'), user_access('access content') ? 'book_render' : MENU_DENIED, 0, MENU_HIDE); - menu('book/view', t('view'), user_access('access content') ? 'book_view_page' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); - menu('book/print', t('printer-friendly version'), user_access('access content') ? 'book_print' : MENU_DENIED, 0, MENU_HIDE, MENU_LOCKED); - } - return $links; } /** + * Implementation of hook_menu(). + */ +function book_menu() { + $items = array(); + + $items[] = array('path' => 'node/add/book', 'title' => t('book page'), + 'access' => user_access('maintain books')); + $items[] = array('path' => 'admin/node/book', 'title' => t('books'), + 'callback' => 'book_admin', + 'access' => user_access('administer nodes'), + 'weight' => 4); + $items[] = array('path' => 'admin/node/book/orphan', 'title' => t('orphan pages'), + 'callback' => 'book_admin_orphan', + 'access' => user_access('administer nodes'), + 'weight' => 8); + $result = db_query('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = 0 ORDER BY b.weight, n.title'); + while ($book = db_fetch_object($result)) { + $items[] = array('path' => 'admin/node/book/'. $book->nid, 'title' => t('"%title" book', array('%title' => $book->title))); + } + $items[] = array('path' => 'book', 'title' => t('books'), + 'callback' => 'book_render', + 'access' => user_access('access content'), + 'type' => MENU_SUGGESTED_ITEM); + $items[] = array('path' => 'book/view', 'title' => t('view'), + 'callback' => 'book_view_page', + 'access' => user_access('access content'), + 'type' => MENU_CALLBACK); + $items[] = array('path' => 'book/print', 'title' => t('printer-friendly version'), + 'callback' => 'book_print', + 'access' => user_access('access content'), + 'type' => MENU_CALLBACK); + + return $items; +} + +/** * Implementation of hook_block(). * * Displays the book table of contents in a block when a node is being @@ -402,7 +422,7 @@ function book_next($node) { /** * Implementation of hook_content(). */ -function book_content($node, $main = 0) { +function book_content($node, $teaser = FALSE) { $op = $_POST['op']; /* @@ -436,7 +456,7 @@ function book_content($node, $main = 0) { ob_end_clean(); } else { - $node = node_prepare($node, $main); + $node = node_prepare($node, $teaser); } return $node; @@ -448,13 +468,13 @@ function book_content($node, $main = 0) { * If not displayed on the main page, we render the node as a page in the * book with extra links to the previous and next pages. */ -function book_view($node, $main = 0, $page = 0) { - $node = book_content($node, $main); +function book_view($node, $teaser = FALSE, $page = FALSE) { + $node = book_content($node, $teaser); $output = ''; - if ($main) { - $output .= theme('node', $node, $main, $page); + if ($teaser) { + $output .= theme('node', $node, $teaser, $page); } else { if ($node->moderate) { @@ -464,10 +484,10 @@ function book_view($node, $main = 0, $page = 0) { if ($page) { $node = book_navigation($node); // Print the breadcrumb - drupal_set_breadcrumb($node->breadcrumb); + menu_set_location($node->breadcrumb); } // Print the node - $output .= theme('node', $node, $main, $page); + $output .= theme('node', $node, $teaser, $page); } return $output; @@ -511,7 +531,7 @@ function book_show($node, $cid) { /* ** View the node */ - drupal_set_breadcrumb($node->breadcrumb); + menu_set_location($node->breadcrumb); $output .= theme('node', $node, 0, 1); } else { @@ -549,11 +569,11 @@ function book_navigation($node) { ** Construct the breadcrumb: */ - $node->breadcrumb = ''; // Overwrite the trail with a book trail. - $node->breadcrumb[] = l(t('Home'), ''); + $node->breadcrumb = array(); // Overwrite the trail with a book trail. foreach ($path as $level) { - $node->breadcrumb[] = l($level->title, "book/view/$level->nid"); + $node->breadcrumb[] = array('path' => 'book/view/'. $level->nid, 'title' => $level->title); } + $node->breadcrumb[] = array('path' => 'book/view/'. $node->nid); if ($node->nid) { $output .= '<div class="book">'; @@ -778,7 +798,7 @@ function book_print_recurse($parent = '', $depth = 1) { } function book_admin_view_line($node, $depth = 0) { - return array("<div style=\"padding-left: ". (25 * $depth) ."px;\">". form_textfield(NULL, "$node->nid][title", $node->title, 64, 255) ."</div>", form_weight(NULL, "$node->nid][weight", $node->weight), l(t("view node"), "node/view/$node->nid"), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid")); + return array("<div style=\"padding-left: ". (25 * $depth) ."px;\">". form_textfield(NULL, "$node->nid][title", $node->title, 64, 255) ."</div>", form_weight(NULL, "$node->nid][weight", $node->weight), l(t("view node"), "node/$node->nid"), l(t("edit node"), "node/$node->nid/edit"), l(t("delete node"), "admin/node/delete/$node->nid")); } function book_admin_view_book($nid, $depth = 1) { @@ -913,7 +933,7 @@ function book_help($section = "admin/help#book") { <p>Whenever you come across a post which you want to include in your FAQ, click on the <em>administer</em> link. Then click on the <em>edit book outline</em> button at the bottom of the page. Then place the relevant post wherever is most appropriate in your book by selecting a <em>parent</em>. Books are quite flexible. They can have sections like <em>Flying to Estonia</em>, <em>Eating in Estonia</em> and so on. As you get more experienced with the book module, you can reorganize posts in your book so that it stays organized.</p> <p>Notes:</p><ul><li>Any comments attached to those relevant posts which you designate as book pages will also be transported into your book. This is a great feature, since much wisdom is shared via comments. Remember that all future comments and edits will automatically be reflected in your book.</li><li>You may wish to edit the title of posts when adding them to your FAQ. This is done on the same page as the <em>Edit book outline</em> button. Clear titles improve navigability enormously.</li><li>Book pages may come from any content type (blog, story, page, etc.). If you are creating a post solely for inclusion in your book, then use the <a href=\"%create\">submit content » book page</a> link.</li><li>If you don't see the <em>administer</em> link, then you probably have insufficient <a href=\"%permissions\">permissions</a>.</li><li>If you want to get really fancy, note that books are one of the few content types which allow raw PHP in their <em>body</em>. So you've got lots of geeky possibilities there.</li></ul>", array("%permissions" => url("admin/user/permission"), "%create" => url("node/add/book"), "%collaborative-book" => url("admin/node/book"), "%orphans-book" => url("admin/node/book/orphan"), "%export-book" => url("book/print"))); break; - case 'admin/system/modules#description': + case 'admin/modules#description': $output = t("Allows users to collaboratively author a book."); break; case 'admin/node/book': |