summaryrefslogtreecommitdiff
path: root/modules/book.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2004-10-08 11:17:59 +0000
committerDries Buytaert <dries@buytaert.net>2004-10-08 11:17:59 +0000
commitaf1eb3b9dba1959adc1b5a704b3e749adf7b2105 (patch)
tree45684328568dd0f84174b61ff14d5d94718ef52c /modules/book.module
parent5f5b02af92cda804a938e71854fadaec9210fc46 (diff)
downloadbrdo-af1eb3b9dba1959adc1b5a704b3e749adf7b2105.tar.gz
brdo-af1eb3b9dba1959adc1b5a704b3e749adf7b2105.tar.bz2
- Reintroduced the book outline feature: non-book pages now have an outline-tab on their node page, given you have permission to maintain books. Using the outline-tab, nodes can be added to a book's hierarchy. Also added some context sensitive help and fixed some quotes.
Diffstat (limited to 'modules/book.module')
-rw-r--r--modules/book.module109
1 files changed, 60 insertions, 49 deletions
diff --git a/modules/book.module b/modules/book.module
index a9ce5c758..9184262f5 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -94,6 +94,7 @@ function book_menu($may_cache) {
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'),
@@ -103,6 +104,19 @@ function book_menu($may_cache) {
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
}
+ else {
+ // To avoid SQL overhead, check whether we are on a node page and whether the
+ // user is allowed to maintain books.
+ if (arg(0) == 'node' && is_numeric(arg(1)) && user_access('maintain books')) {
+ // Only add the outline-tab for non-book pages:
+ $result = db_query('SELECT n.nid FROM {node} n '. node_access_join_sql() .' WHERE '. node_access_where_sql() ." AND n.nid = %d AND n.type != 'book'", arg(1));
+ if (db_num_rows($result) > 0) {
+ $items[] = array('path' => 'node/'. arg(1) .'/outline', 'title' => t('outline'),
+ 'callback' => 'book_outline', 'access' => user_access('maintain books'),
+ 'type' => MENU_LOCAL_TASK, 'weight' => 2);
+ }
+ }
+ }
return $items;
}
@@ -228,62 +242,55 @@ function book_form(&$node) {
}
/**
- * Implementation of hook_node_link().
+ * Implementation of function book_outline()
+ * Handles all book outline operations.
*/
-function book_node_link($node = 0) {
- global $user;
+function book_outline() {
$op = $_POST['op'];
$edit = $_POST['edit'];
+ $node = node_load(array('nid' => arg(1)));
- if ($node->type != 'book') {
-
- if ($edit['nid']) {
- $node = node_load(array('nid' => $edit['nid']));
- }
-
- if ($op == t('Add to book outline')) {
- db_query('INSERT INTO {book} (nid, parent, weight) VALUES (%d, %d, %d)', $node->nid, $edit['parent'], $edit['weight']);
- drupal_set_message(t('Added the node to the book.'));
- }
-
- if ($op == t('Update book outline')) {
- db_query('UPDATE {book} SET parent = %d, weight = %d WHERE nid = %d', $edit['parent'], $edit['weight'], $node->nid);
- drupal_set_message(t('Updated the book outline.'));
- }
-
- if ($op == t('Remove from book outline')) {
- db_query('DELETE FROM {book} WHERE nid = %d', $node->nid);
- drupal_set_message(t('Removed the post from the book.'));
- }
-
- $output .= '<h3>'. t('Edit book outline for node "%booktitle"', array('%booktitle' => '<em>'. $node->title .'</em>')) .'</h3>';
-
- if ($edit['nid']) {
- $page = db_fetch_object(db_query('SELECT * FROM {book} WHERE nid = %d', $node->nid));
-
- $output .= form_select(t('Parent'), 'parent', $page->parent, book_toc($node->nid), t('The parent subject or category the page belongs in.'));
- $output .= form_weight(t('Weight'), 'weight', $node->weight, 15, t('The heavier pages will sink and the lighter pages will be positioned nearer the top.'));
-
- if ($page->nid) {
- $output .= form_submit(t('Update book outline'));
- $output .= form_submit(t('Remove from book outline'));
- }
- else {
- $output .= form_submit(t('Add to book outline'));
- }
+ if ($node->nid) {
+ switch ($op) {
+ case t('Add to book outline'):
+ db_query('INSERT INTO {book} (nid, parent, weight) VALUES (%d, %d, %d)', $node->nid, $edit['parent'], $edit['weight']);
+ drupal_set_message(t('Added the post to the book.'));
+ drupal_goto("node/$node->nid");
+ break;
+
+ case t('Update book outline'):
+ db_query('UPDATE {book} SET parent = %d, weight = %d WHERE nid = %d', $edit['parent'], $edit['weight'], $node->nid);
+ drupal_set_message(t('Updated the book outline.'));
+ drupal_goto("node/$node->nid");
+ break;
+
+ case t('Remove from book outline'):
+ db_query('DELETE FROM {book} WHERE nid = %d', $node->nid);
+ drupal_set_message(t('Removed the post from the book.'));
+ drupal_goto("node/$node->nid");
+ break;
+
+ default:
+ $page = db_fetch_object(db_query('SELECT * FROM {book} WHERE nid = %d', $node->nid));
+
+ $output = form_select(t('Parent'), 'parent', $page->parent, book_toc($node->nid), t('The parent page in the book.'));
+ $output .= form_weight(t('Weight'), 'weight', $page->weight, 15, t('The heavier pages will sink and the lighter pages will be positioned nearer the top.'));
+
+ if ($page->nid) {
+ $output .= form_submit(t('Update book outline'));
+ $output .= form_submit(t('Remove from book outline'));
+ }
+ else {
+ $output .= form_submit(t('Add to book outline'));
+ }
+ print theme('page', form($output), $node->title);
}
- else {
- $output .= form_submit(t('Edit book outline'));
- }
-
- $output .= form_hidden('nid', $node->nid);
-
- return form($output, 'post', url('admin/node/book'));
}
}
+
/**
* Return the the most recent revision that matches the specified conditions.
*/
@@ -786,13 +793,13 @@ function book_help($section) {
<p>The book organises content into a nested hierarchical structure. It is particularly good for manuals, Frequently Asked Questions (FAQs) and the like, allowing you to have chapters, sections, etc.</p>
<p>A book is simply a collection of nodes that have been linked together. These nodes are usually of type <em>book page</em>, but you can insert nodes of any type into a book outline. Every node in the book has a <em>parent</em> node which \"contains\" it. This is how book.module establishes its hierarchy. At any given level in the hierarchy, a book can contain many nodes. All these sibling nodes are sorted according to the <em>weight</em> that you give them.</p>
<p>A book page is a special node type that allows you to embed PHP within the body of the page. This capability is only offered to administrators, since malicious users could abuse this power. In addition, book pages contain a <em>log message</em> field which helps your users understand the motivation behind an edit of a book page. Each edited version of a book page is stored as a new revision of a node. This capability makes it easy to revert to an old version of a page, should that be desirable.</p>
- <p>Like other node types, book submissions and edits may be subject to moderation, depending on your configuration. Similarly, books use <a href=\"%permissions\">permissions</a> to determine who may read and write to them. Only administrators are allowed to create new books, which are really just nodes whose parent is <em>&lt;top-level&gt;</em>. To include an existing node in your book, click on the \"administer\"-link in that node. At the bottom of this administration page, click on the <em>edit book outline</em> button. This enables you to place the node wherever you'd like within the book hierarchy. To add a new node into your book, use the <a href=\"%create\">create content &raquo; book page</a> link.</p>
+ <p>Like other node types, book submissions and edits may be subject to moderation, depending on your configuration. Similarly, books use <a href=\"%permissions\">permissions</a> to determine who may read and write to them. Only administrators are allowed to create new books, which are really just nodes whose parent is <em>&lt;top-level&gt;</em>. To include an existing node in your book, click on the \"outline\"-tab on the node's page. This enables you to place the node wherever you'd like within the book hierarchy. To add a new node into your book, use the <a href=\"%create\">create content &raquo; book page</a> link.</p>
<p>Administrators may review the hierarchy of their books by clicking on the <a href=\"%collaborative-book\">collaborative book</a> link in the adminstration pages. There, nodes may be edited, reorganized, removed from book, and deleted. This behavior may change in the future. When a parent node is deleted, it may leave behind child nodes. These nodes are now <em>orphans</em>. Administrators should periodically <a href=\"%orphans-book\">review their books for orphans</a> and reaffiliate those pages as desired. Finally, administrators may also <a href=\"%export-book\">export their books</a> to a single, flat HTML page which is suitable for printing.</p>
<h3>Maintaining a FAQ using a collaborative book</h3>
<p>Collaborative books let you easily set up a Frequently Asked Questions (FAQ) section on your web site. The main benefit is that you don't have to write all the questions/answers by yourself - let the community do it for you!</p>
<p>In order to set up the FAQ, you have to create a new book which will hold all your content. To do so, click on the <a href=\"%create\">create content &raquo; book page</a> link. Give it a thoughtful title, and body. A title like \"Estonia Travel - FAQ\" is nice. You may always edit these fields later. You will probably want to designate <em>&lt;top-level&gt;</em> as the parent of this page. Leave the <em>log message</em> and <em>type</em> fields blank for now. After you have submitted this book page, you are ready to begin filling up your book with questions that are frequently asked.</p>
<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\">create content &raquo; 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/configure/permission"), "%create" => url("node/add/book"), "%collaborative-book" => url("admin/node/book"), "%orphans-book" => url("admin/node/book/orphan"), "%export-book" => url("book/print")));
+ <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\">create content &raquo; 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/configure/permission'), "%create" => url('node/add/book'), '%collaborative-book' => url('admin/node/book'), '%orphans-book' => url('admin/node/book/orphan'), '%export-book' => url('book/print')));
case 'admin/modules#description':
return t('Allows users to collaboratively author a book.');
case 'admin/node/book':
@@ -802,10 +809,14 @@ function book_help($section) {
case 'node/add#book':
return t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it.");
}
+
+ if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'outline') {
+ return t('The outline feature allowes you to include post in the <a href="%book">book hierarchy</a>.', array('%book' => url('book')));
+ }
}
function book_help_page() {
print theme('page', book_help('admin/help#book'));
}
-?> \ No newline at end of file
+?>