2001-03-24 16:36:13 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2001-03-24 16:36:13 +00:00
2004-08-21 06:42:38 +00:00
/**
* @file
* Allows users to collaboratively author a book.
*/
2004-05-09 19:28:43 +00:00
/**
2005-08-29 19:58:49 +00:00
* Implementation of hook_node_info().
2004-05-09 19:28:43 +00:00
*/
2005-08-29 19:58:49 +00:00
function book_node_info() {
- Patch #29785 by Chx: multiple node types were broken so we refactored
part of the node system! If you have a module that implements node
types, you'll have to udpate its CVS HEAD version.
We replaced _node_name() and _node_types() by _node(). The new _node()
hook let's you define one or more node types, including their names.
The implementation of the _node() hook needs to:
return array($type1 => array('name' => $name1, 'base' => $base1),
$type2 => array('name' => $name2, 'base' => $base2));
where $type is the node type, $name is the human readable name of the type
and $base is used instead of <hook> for <hook>_load, <hook>_view, etc.
For example, the story module's node hook looks like this:
function story_node() {
return array('story' => array('name' => t('story'), 'base' => 'story'));
}
The page module's node hook module like:
function page_node() {
return array('page' => array('name' => t('page'), 'base' => 'page'));
}
However, more complex node modules like the project module and the
flexinode module can use the 'base' parameter to specify a different base.
The project module implements two node types, proejcts and issues, so it
can do:
function project_node() {
return array(
array('project_project' => array('name' => t('project'), 'base' => 'project'),
array('project_issue' => array('name' => t('issue'), 'base' => 'project_issue'));
}
In the flexinode module's case there can only one base ...
This hook will simplify the CCK, and will make it easy (or easier) to merge
the story and page module.
In addition, node_list() became node_get_types(). In addition, we created
the following functions: node_get_name($type) and node_get_base($type).
2005-08-28 15:29:34 +00:00
return array('book' => array('name' => t('book page'), 'base' => 'book'));
2001-11-01 17:04:20 +00:00
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_perm().
*/
2002-12-10 20:35:20 +00:00
function book_perm() {
2005-10-08 14:48:33 +00:00
return array('create book pages', 'maintain books', 'edit own book pages', 'export books', 'see printer-friendly version');
2002-12-10 20:35:20 +00:00
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_access().
*/
2001-11-01 17:04:20 +00:00
function book_access($op, $node) {
2001-11-04 23:30:39 +00:00
global $user;
2001-11-01 17:04:20 +00:00
2004-05-09 19:28:43 +00:00
if ($op == 'create') {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Only registered users can create book pages. Given the nature
// of the book module this is considered to be a good/safe idea.
2004-11-04 22:31:46 +00:00
return user_access('create book pages');
2001-11-01 17:04:20 +00:00
}
2004-05-09 19:28:43 +00:00
if ($op == 'update') {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Only registered users can update book pages. Given the nature
// of the book module this is considered to be a good/safe idea.
// One can only update a book page if there are no suggested updates
2004-12-22 20:47:47 +00:00
// of that page waiting for approval. That is, only updates that
// don't overwrite the current or pending information are allowed.
The Input formats - filter patch has landed. I still need to make update instructions for modules and update the hook docs.
Here's an overview of the changes:
1) Multiple Input formats: they are complete filter configurations (what filters to use, in what order and with which settings). Input formats are admin-definable, and usage of them is role-dependant. For example, you can set it up so that regular users can only use limited HTML, while admins can free HTML without any tag limitations.
The input format can be chosen per content item (nodes, comments, blocks, ...) when you add/edit them. If only a single format is available, there is no choice, and nothing changes with before.
The default install (and the upgrade) contains a basic set of formats which should satisfy the average user's needs.
2) Filters have toggles
Because now you might want to enable a filter only on some input formats, an explicit toggle is provided by the filter system. Modules do not need to worry about it and filters that still have their own on/off switch should get rid of it.
3) Multiple filters per module
This was necessary to accomodate the next change, and it's also a logical extension of the filter system.
4) Embedded PHP is now a filter
Thanks to the multiple input formats, I was able to move the 'embedded PHP' feature from block.module, page.module and book.module into a simple filter which executes PHP code. This filter is part of filter.module, and by default there is an input format 'PHP', restricted to the administrator only, which contains this filter.
This change means that block.module now passes custom block contents through the filter system.
As well as from reducing code duplication and avoiding two type selectors for page/book nodes, you can now combine PHP code with other filters.
5) User-supplied PHP code now requires <?php ?> tags.
This is required for teasers to work with PHP code. Because PHP evaluation is now just another step in the filter process, we can't do this. Also, because teasers are generated before filtering, this would result in errors when the teaser generation would cut off a piece of PHP code.
Also, regular PHP syntax explicitly includes the <?php ?> tags for PHP files, so it makes sense to use the same convention for embedded PHP in Drupal.
6) Filter caching was added.
Benchmarking shows that even for a simple setup (basic html filtering + legacy URL rewriting), filtercache can offer speedups. Unlike the old filtercache, this uses the normal cache table.
7) Filtertips were moved from help into a hook_filter_tips(). This was required to accomodate the fact that there are multiple filters per module, and that filter settings are format dependant. Shoehorning filter tips into _help was ugly and silly. The display of the filter tips is done through the input format selector, so filter_tips_short() no longer exists.
8) A more intelligent linebreak convertor was added, which doesn't stop working if you use block-level tags and which adds <p> tags.
2004-08-10 18:34:29 +00:00
2005-02-06 09:37:10 +00:00
if ((user_access('maintain books') && !$node->moderate) || ($node->uid == $user->uid && user_access('edit own book pages'))) {
return TRUE;
}
else {
// do nothing. node-access() will determine further access
}
2001-11-04 15:57:43 +00:00
}
2001-11-01 17:04:20 +00:00
}
2004-04-21 13:56:38 +00:00
/**
* Implementation of hook_link().
*/
2001-12-02 21:11:18 +00:00
function book_link($type, $node = 0, $main = 0) {
2003-04-21 14:55:03 +00:00
$links = array();
2005-04-13 18:50:57 +00:00
if ($type == 'node' && isset($node->parent)) {
2003-05-13 19:05:02 +00:00
if (!$main) {
2004-11-15 12:49:59 +00:00
if (book_access('create', $node)) {
$links[] = l(t('add child page'), "node/add/book/parent/$node->nid");
}
2005-10-08 14:48:33 +00:00
if (user_access('see printer-friendly version')) {
$links[] = l(t('printer-friendly version'), 'book/export/html/'. $node->nid, array('title' => t('Show a printer-friendly version of this book page and its sub-pages.')));
}
if (user_access('export books')) {
$links[] = l(t('export DocBook XML'), 'book/export/docbook/'. $node->nid, array('title' => t('Export this book page and its sub-pages as DocBook XML.')));
$links[] = l(t('export OPML'), 'book/export/opml/'. $node->nid, array('title' => t('Export this book page and its sub-pages as OPML.')));
}
2003-05-13 19:05:02 +00:00
}
2001-12-02 21:05:31 +00:00
}
2003-04-21 14:55:03 +00:00
return $links;
2001-03-25 10:57:01 +00:00
}
2004-06-18 15:04:37 +00:00
/**
* Implementation of hook_menu().
*/
2004-09-16 07:17:56 +00:00
function book_menu($may_cache) {
2004-06-18 15:04:37 +00:00
$items = array();
2004-09-16 07:17:56 +00:00
if ($may_cache) {
2005-06-07 19:20:20 +00:00
$items[] = array(
'path' => 'book',
'title' => t('books'),
'access' => user_access('access content'),
'type' => MENU_NORMAL_ITEM,
'weight' => 5);
$items[] = array(
'path' => 'node/add/book',
'title' => t('book page'),
2004-11-04 22:31:46 +00:00
'access' => user_access('create book pages'));
2005-06-07 19:20:20 +00:00
$items[] = array(
'path' => 'admin/node/book',
'title' => t('books'),
2004-09-16 07:17:56 +00:00
'callback' => 'book_admin',
'access' => user_access('administer nodes'),
2005-07-29 03:49:16 +00:00
'type' => MENU_LOCAL_TASK,
'weight' => -1);
$items[] = array(
'path' => 'admin/node/book/list',
'title' => t('list'),
'type' => MENU_DEFAULT_LOCAL_TASK);
2005-06-07 19:20:20 +00:00
$items[] = array(
'path' => 'admin/node/book/orphan',
'title' => t('orphan pages'),
2004-09-16 07:17:56 +00:00
'callback' => 'book_admin_orphan',
2005-07-29 03:49:16 +00:00
'type' => MENU_LOCAL_TASK,
2004-09-16 07:17:56 +00:00
'weight' => 8);
$items[] = array('path' => 'book', 'title' => t('books'),
'callback' => 'book_render',
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
2005-06-05 10:52:04 +00:00
$items[] = array(
2005-06-07 19:20:20 +00:00
'path' => 'book/export',
'callback' => 'book_export',
2005-10-08 14:48:33 +00:00
'access' => (user_access('export books') || user_access('see printer-friendly version')) && user_access('access content'),
2004-09-16 07:17:56 +00:00
'type' => MENU_CALLBACK);
2004-06-18 15:04:37 +00:00
}
2004-10-08 11:17:59 +00:00
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:
2005-01-29 22:02:37 +00:00
$result = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n WHERE n.nid = %d AND n.type != 'book'"), arg(1));
2004-10-08 11:17:59 +00:00
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);
}
}
}
2004-06-18 15:04:37 +00:00
return $items;
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_block().
*
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
* Displays the book table of contents in a block when the current page is a
* single-node view of a book node.
2004-05-09 19:28:43 +00:00
*/
2004-01-14 19:26:41 +00:00
function book_block($op = 'list', $delta = 0) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$block = array();
2004-01-14 19:26:41 +00:00
if ($op == 'list') {
$block[0]['info'] = t('Book navigation');
2004-10-31 07:34:47 +00:00
return $block;
2004-01-14 19:26:41 +00:00
}
2004-10-31 07:34:47 +00:00
else if ($op == 'view') {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Only display this block when the user is browsing a book:
if (arg(0) == 'node' && is_numeric(arg(1))) {
2005-08-30 15:22:29 +00:00
$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));
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
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;
}
2005-03-31 09:25:33 +00:00
$block['subject'] = check_plain($path[0]->title);
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$block['content'] = book_tree($expand[0], 5, $expand);
}
}
2004-01-14 19:26:41 +00:00
2004-10-31 07:34:47 +00:00
return $block;
}
2004-01-14 19:26:41 +00:00
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_load().
*/
2001-11-01 11:00:51 +00:00
function book_load($node) {
2002-04-20 11:52:50 +00:00
global $user;
2001-11-24 15:10:36 +00:00
2005-08-30 15:22:29 +00:00
$book = db_fetch_object(db_query('SELECT parent, weight FROM {book} WHERE vid = %d', $node->vid));
2001-11-24 15:10:36 +00:00
2004-08-18 20:46:28 +00:00
if (arg(2) == 'edit' && !user_access('administer nodes')) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// If a user is about to update a book page, we overload some
// fields to reflect the changes.
2001-11-25 15:58:08 +00:00
if ($user->uid) {
$book->uid = $user->uid;
$book->name = $user->name;
}
else {
$book->uid = 0;
2004-05-09 19:28:43 +00:00
$book->name = '';
2001-11-25 15:58:08 +00:00
}
2001-12-06 17:33:05 +00:00
}
2001-11-24 15:10:36 +00:00
2001-11-01 11:00:51 +00:00
return $book;
2001-06-29 22:08:57 +00:00
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_insert().
*/
2001-11-01 11:00:51 +00:00
function book_insert($node) {
2005-08-30 15:22:29 +00:00
db_query("INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)", $node->nid, $node->vid, $node->parent, $node->weight);
2001-11-01 11:00:51 +00:00
}
2001-06-29 22:08:57 +00:00
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_update().
*/
2001-11-01 11:00:51 +00:00
function book_update($node) {
2005-08-30 15:22:29 +00:00
if ($node->revision) {
2005-09-06 18:55:41 +00:00
db_query("INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)", $node->nid, $node->vid, $node->parent, $node->weight);
2005-08-30 15:22:29 +00:00
}
else {
db_query("UPDATE {book} SET parent = %d, weight = %d WHERE vid = %d", $node->parent, $node->weight, $node->vid);
}
2001-11-01 11:00:51 +00:00
}
2001-06-29 22:08:57 +00:00
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_delete().
*/
2001-11-26 18:27:34 +00:00
function book_delete(&$node) {
2004-05-09 19:28:43 +00:00
db_query('DELETE FROM {book} WHERE nid = %d', $node->nid);
2001-06-20 20:00:40 +00:00
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_validate().
*/
2003-03-07 22:11:44 +00:00
function book_validate(&$node) {
2004-05-09 19:28:43 +00:00
// Set default values for non-administrators.
if (!user_access('administer nodes')) {
2003-03-07 22:11:44 +00:00
$node->weight = 0;
$node->revision = 1;
}
2005-09-23 08:47:13 +00:00
node_validate_title($node);
2002-11-18 22:19:17 +00:00
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_form().
*/
2004-07-04 16:50:02 +00:00
function book_form(&$node) {
2005-10-07 06:11:12 +00:00
$form['parent'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'select', '#title' => t('Parent'), '#default_value' => ($node->parent ? $node->parent : arg(4)), '#options' => book_toc($node->nid), '#weight' => -15,
'#description' => t('The parent that this page belongs in. Note that pages whose parent is <top-level> are regarded as independent, top-level books.')
2005-10-07 06:11:12 +00:00
);
2001-12-06 17:33:05 +00:00
2005-10-11 19:44:35 +00:00
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#size' => 60, '#maxlength' => 128, '#required' => TRUE, '#default_value' => $node->title);
2005-10-07 06:11:12 +00:00
$form['body'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#required' => TRUE
2005-10-07 06:11:12 +00:00
);
$form = array_merge($form, filter_form($node->format));
2005-08-30 15:22:29 +00:00
2005-10-07 06:11:12 +00:00
$form['log'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'textarea', '#title' => t('Log message'), '#default_value' => $node->log, '#rows' => 5, '#weight' => 19,
'#description' => t('An explanation of the additions or updates being made to help other authors understand your motivations.')
2005-10-07 06:11:12 +00:00
);
2001-11-04 15:57:43 +00:00
2004-05-09 19:28:43 +00:00
if (user_access('administer nodes')) {
2005-10-07 06:11:12 +00:00
$form['weight'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'weight', '#title' => t('Weight'), '#default_value' => $node->weight, '#delta' => 15, '#weight' => -14,
'#description' => t('Pages at a given level are ordered first by weight and then by title.')
2005-10-07 06:11:12 +00:00
);
2001-11-04 15:57:43 +00:00
}
else {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// If a regular user updates a book page, we create a new revision
// authored by that user:
2005-10-11 19:44:35 +00:00
$form['revision'] = array('#type' => 'hidden', '#value' => 1);
2001-11-04 15:57:43 +00:00
}
2005-10-07 06:11:12 +00:00
return $form;
2001-11-04 15:57:43 +00:00
}
2004-05-09 19:28:43 +00:00
/**
2004-10-08 11:17:59 +00:00
* Implementation of function book_outline()
* Handles all book outline operations.
2004-05-09 19:28:43 +00:00
*/
2004-10-08 11:17:59 +00:00
function book_outline() {
2003-05-13 18:36:38 +00:00
2004-05-09 19:28:43 +00:00
$op = $_POST['op'];
$edit = $_POST['edit'];
2005-07-17 18:29:32 +00:00
$node = node_load(arg(1));
2001-12-06 17:33:05 +00:00
2004-10-08 11:17:59 +00:00
if ($node->nid) {
switch ($op) {
case t('Add to book outline'):
2005-08-30 15:22:29 +00:00
db_query('INSERT INTO {book} (nid, vid, parent, weight) VALUES (%d, %d, %d, %d)', $node->nid, $node->vid, $edit['parent'], $edit['weight']);
db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $edit['log'], $node->vid);
2005-05-05 22:22:46 +00:00
drupal_set_message(t('The post has been added to the book.'));
2004-10-08 11:17:59 +00:00
drupal_goto("node/$node->nid");
break;
case t('Update book outline'):
2005-08-30 15:22:29 +00:00
db_query('UPDATE {book} SET parent = %d, weight = %d WHERE vid = %d', $edit['parent'], $edit['weight'], $node->vid);
db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $edit['log'], $node->vid);
2005-05-05 22:22:46 +00:00
drupal_set_message(t('The book outline has been updated.'));
2004-10-08 11:17:59 +00:00
drupal_goto("node/$node->nid");
break;
case t('Remove from book outline'):
db_query('DELETE FROM {book} WHERE nid = %d', $node->nid);
2005-05-05 22:22:46 +00:00
drupal_set_message(t('The post has been removed from the book.'));
2004-10-08 11:17:59 +00:00
drupal_goto("node/$node->nid");
break;
default:
2005-08-30 15:22:29 +00:00
$page = db_fetch_object(db_query('SELECT * FROM {book} WHERE vid = %d', $node->vid));
2005-10-07 06:51:43 +00:00
2005-10-07 06:11:12 +00:00
$form['parent'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'select', '#title' => t('Parent'), '#default_value' => $page->parent,
'#options' => book_toc($node->nid), '#description' => t('The parent page in the book.')
2005-10-07 06:11:12 +00:00
);
2005-10-07 06:51:43 +00:00
2005-10-07 06:11:12 +00:00
$form['weight'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'weight', '#title' => t('Weight'), '#default_value' => $page->weight, '#delta' => 15,
'#description' => t('Pages at a given level are ordered first by weight and then by title.')
2005-10-07 06:11:12 +00:00
);
2005-10-07 06:51:43 +00:00
2005-10-07 06:11:12 +00:00
$form['log'] = array(
2005-10-11 19:44:35 +00:00
'#type' => 'textarea', '#title' => t('Log message'), '#cols' => 60, '#rows' => 5,
'#default_value' => $node->log, '#description' => t('An explanation to help other authors understand your motivations to put this post into the book.')
2005-10-07 06:11:12 +00:00
);
2004-10-08 11:17:59 +00:00
if ($page->nid) {
2005-10-11 19:44:35 +00:00
$form['update'] = array('#type' => 'submit', '#value' => t('Update book outline'));
$form['remove'] = array('#type' => 'submit', '#value' => t('Remove from book outline'));
2004-10-08 11:17:59 +00:00
}
else {
2005-10-11 19:44:35 +00:00
$form['add'] = array('#type' => 'submit', '#value' => t('Add to book outline'));
2004-10-08 11:17:59 +00:00
}
2001-12-06 17:33:05 +00:00
2005-03-31 09:25:33 +00:00
drupal_set_title(check_plain($node->title));
2005-10-07 06:11:12 +00:00
return drupal_get_form('book_outline', $form);
2001-12-06 17:33:05 +00:00
}
}
}
2004-05-09 19:28:43 +00:00
/**
* Return the path (call stack) to a certain book page.
*/
2001-04-04 12:54:10 +00:00
function book_location($node, $nodes = array()) {
2005-08-30 15:22:29 +00:00
$parent = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d'), $node->parent));
2001-04-04 12:54:10 +00:00
if ($parent->title) {
$nodes = book_location($parent, $nodes);
array_push($nodes, $parent);
}
return $nodes;
}
2005-06-05 10:52:04 +00:00
/**
* Accumulates the nodes up to the root of the book from the given node in the $nodes array.
*/
2003-03-10 20:18:38 +00:00
function book_location_down($node, $nodes = array()) {
2005-07-29 07:13:25 +00:00
$last_direct_child = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = %d ORDER BY b.weight DESC, n.title DESC'), $node->nid));
2003-03-10 20:18:38 +00:00
if ($last_direct_child) {
array_push($nodes, $last_direct_child);
$nodes = book_location_down($last_direct_child, $nodes);
}
return $nodes;
}
2004-05-09 19:28:43 +00:00
/**
2005-06-05 10:52:04 +00:00
* Fetches the node object of the previous page of the book.
2004-05-09 19:28:43 +00:00
*/
2003-03-10 20:18:38 +00:00
function book_prev($node) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// If the parent is zero, we are at the start of a book so there is no previous.
2003-05-18 16:43:56 +00:00
if ($node->parent == 0) {
return NULL;
}
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Previous on the same level:
2005-08-30 15:22:29 +00:00
$direct_above = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = %d AND n.status = 1 AND n.moderate = 0 AND (b.weight < %d OR (b.weight = %d AND n.title < '%s')) ORDER BY b.weight DESC, n.title DESC"), $node->parent, $node->weight, $node->weight, $node->title));
2003-03-10 20:18:38 +00:00
if ($direct_above) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Get last leaf of $above.
2003-03-10 20:18:38 +00:00
$path = book_location_down($direct_above);
2003-05-18 16:43:56 +00:00
return $path ? (count($path) > 0 ? array_pop($path) : NULL) : $direct_above;
2003-03-10 20:18:38 +00:00
}
else {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Direct parent:
2005-08-30 15:22:29 +00:00
$prev = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.nid = %d AND n.status = 1 AND n.moderate = 0'), $node->parent));
2003-03-10 20:18:38 +00:00
return $prev;
}
}
2004-05-09 19:28:43 +00:00
/**
2005-06-05 10:52:04 +00:00
* Fetches the node object of the next page of the book.
2004-05-09 19:28:43 +00:00
*/
2003-03-10 20:18:38 +00:00
function book_next($node) {
// get first direct child
2005-08-30 15:22:29 +00:00
$child = db_fetch_object(db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = %d AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight ASC, n.title ASC'), $node->nid));
2003-03-10 20:18:38 +00:00
if ($child) {
return $child;
}
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// No direct child: get next for this level or any parent in this book.
array_push($path = book_location($node), $node); // Path to top-level node including this one.
2004-04-24 16:31:54 +00:00
Patch by Ax:
- the index link ("View this book's table of contents.") which pointed
to http://drupal/book instead of to ... this book's table of contents.
- it doesn't print "previous", "next", "up", "index" if there are no
"previous", "next", "up", "index"
- it doesn't print "index" if "up" /is/ the "index"
- it swaps the order of "up" and "index", ie. "up" is in the row above
"index", between "previous" and "next" now. this is more logical and the
way all tree-browsing apps (python doc, info, ...) do it.
2003-03-13 20:09:47 +00:00
while (($leaf = array_pop($path)) && count($path)) {
2005-08-30 15:22:29 +00:00
$next = db_fetch_object(db_query(db_rewrite_sql("SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = %d AND n.status = 1 AND n.moderate = 0 AND (b.weight > %d OR (b.weight = %d AND n.title > '%s')) ORDER BY b.weight ASC, n.title ASC"), $leaf->parent, $leaf->weight, $leaf->weight, $leaf->title));
2003-03-10 20:18:38 +00:00
if ($next) {
return $next;
}
}
}
2005-06-05 10:52:04 +00:00
/**
* Returns the content of a given node. If $teaser if true, returns
* the teaser rather than full content. Displays the most recently
* approved revision of a node (if any) unless we have to display this
* page in the context of the moderation queue.
*/
2004-06-18 15:04:37 +00:00
function book_content($node, $teaser = FALSE) {
2004-05-09 19:28:43 +00:00
$op = $_POST['op'];
2001-12-06 17:33:05 +00:00
The Input formats - filter patch has landed. I still need to make update instructions for modules and update the hook docs.
Here's an overview of the changes:
1) Multiple Input formats: they are complete filter configurations (what filters to use, in what order and with which settings). Input formats are admin-definable, and usage of them is role-dependant. For example, you can set it up so that regular users can only use limited HTML, while admins can free HTML without any tag limitations.
The input format can be chosen per content item (nodes, comments, blocks, ...) when you add/edit them. If only a single format is available, there is no choice, and nothing changes with before.
The default install (and the upgrade) contains a basic set of formats which should satisfy the average user's needs.
2) Filters have toggles
Because now you might want to enable a filter only on some input formats, an explicit toggle is provided by the filter system. Modules do not need to worry about it and filters that still have their own on/off switch should get rid of it.
3) Multiple filters per module
This was necessary to accomodate the next change, and it's also a logical extension of the filter system.
4) Embedded PHP is now a filter
Thanks to the multiple input formats, I was able to move the 'embedded PHP' feature from block.module, page.module and book.module into a simple filter which executes PHP code. This filter is part of filter.module, and by default there is an input format 'PHP', restricted to the administrator only, which contains this filter.
This change means that block.module now passes custom block contents through the filter system.
As well as from reducing code duplication and avoiding two type selectors for page/book nodes, you can now combine PHP code with other filters.
5) User-supplied PHP code now requires <?php ?> tags.
This is required for teasers to work with PHP code. Because PHP evaluation is now just another step in the filter process, we can't do this. Also, because teasers are generated before filtering, this would result in errors when the teaser generation would cut off a piece of PHP code.
Also, regular PHP syntax explicitly includes the <?php ?> tags for PHP files, so it makes sense to use the same convention for embedded PHP in Drupal.
6) Filter caching was added.
Benchmarking shows that even for a simple setup (basic html filtering + legacy URL rewriting), filtercache can offer speedups. Unlike the old filtercache, this uses the normal cache table.
7) Filtertips were moved from help into a hook_filter_tips(). This was required to accomodate the fact that there are multiple filters per module, and that filter settings are format dependant. Shoehorning filter tips into _help was ugly and silly. The display of the filter tips is done through the input format selector, so filter_tips_short() no longer exists.
8) A more intelligent linebreak convertor was added, which doesn't stop working if you use block-level tags and which adds <p> tags.
2004-08-10 18:34:29 +00:00
// Extract the page body.
$node = node_prepare($node, $teaser);
2001-12-06 17:33:05 +00:00
2003-09-20 15:11:41 +00:00
return $node;
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_view().
*
* 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.
*/
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
function book_view(&$node, $teaser = FALSE, $page = FALSE) {
2004-06-18 15:04:37 +00:00
$node = book_content($node, $teaser);
2003-09-15 15:58:20 +00:00
}
2004-05-09 19:28:43 +00:00
/**
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
* Implementation of hook_nodeapi().
*
* Appends book navigation to all nodes in the book.
2004-05-09 19:28:43 +00:00
*/
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
function book_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'view':
if (!$teaser) {
2005-08-30 15:22:29 +00:00
$book = db_fetch_array(db_query('SELECT * FROM {book} WHERE vid = %d', $node->vid));
2003-09-20 15:11:41 +00:00
if ($book) {
2005-02-06 09:37:10 +00:00
if ($node->moderate && user_access('administer nodes')) {
2005-05-05 22:22:46 +00:00
drupal_set_message(t("The post has been submitted for moderation and won't be accessible until it has been approved."));
2005-02-06 09:37:10 +00:00
}
2003-09-20 15:11:41 +00:00
foreach ($book as $key => $value) {
$node->$key = $value;
}
2005-03-22 18:34:20 +00:00
$node = theme('book_navigation', $node);
2004-07-31 16:23:01 +00:00
if ($page) {
menu_set_location($node->breadcrumb);
}
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
}
2003-09-20 15:11:41 +00:00
}
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
break;
2003-11-25 19:26:21 +00:00
}
2003-09-15 15:58:20 +00:00
}
2001-12-06 17:33:05 +00:00
2004-05-09 19:28:43 +00:00
/**
* Prepares both the custom breadcrumb trail and the forward/backward
* navigation for a node presented as a book page.
2005-03-22 18:34:20 +00:00
*
* @ingroup themeable
2004-05-09 19:28:43 +00:00
*/
2005-03-22 18:34:20 +00:00
function theme_book_navigation($node) {
2004-01-17 23:34:11 +00:00
$path = book_location($node);
2001-04-04 12:54:10 +00:00
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Construct the breadcrumb:
2004-01-17 23:34:11 +00:00
2004-06-18 15:04:37 +00:00
$node->breadcrumb = array(); // Overwrite the trail with a book trail.
2004-01-17 23:34:11 +00:00
foreach ($path as $level) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$node->breadcrumb[] = array('path' => 'node/'. $level->nid, 'title' => $level->title);
2004-01-17 23:34:11 +00:00
}
2004-07-06 07:33:59 +00:00
$node->breadcrumb[] = array('path' => 'node/'. $node->nid);
2003-09-20 15:11:41 +00:00
2004-01-17 23:34:11 +00:00
if ($node->nid) {
2004-05-09 19:28:43 +00:00
$output .= '<div class="book">';
2004-01-17 23:34:11 +00:00
if ($tree = book_tree($node->nid)) {
2004-08-16 17:54:24 +00:00
$output .= '<div class="tree">'. $tree .'</div>';
2003-09-15 15:58:20 +00:00
}
2003-09-20 15:11:41 +00:00
2004-01-17 23:34:11 +00:00
if ($prev = book_prev($node)) {
2004-05-09 19:28:43 +00:00
$links .= '<div class="prev">';
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$links .= l(t('previous'), 'node/'. $prev->nid, array('title' => t('View the previous page.')));
2004-05-09 19:28:43 +00:00
$links .= '</div>';
2005-03-31 09:25:33 +00:00
$titles .= '<div class="prev">'. check_plain($prev->title) .'</div>';
2004-01-17 23:34:11 +00:00
}
else {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$links .= '<div class="prev"> </div>'; // Make an empty div to fill the space.
2004-01-17 23:34:11 +00:00
}
if ($next = book_next($node)) {
2004-05-09 19:28:43 +00:00
$links .= '<div class="next">';
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$links .= l(t('next'), 'node/'. $next->nid, array('title' => t('View the next page.')));
2004-05-09 19:28:43 +00:00
$links .= '</div>';
2005-03-31 09:25:33 +00:00
$titles .= '<div class="next">'. check_plain($next->title) .'</div>';
2004-01-17 23:34:11 +00:00
}
else {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$links .= '<div class="next"> </div>'; // Make an empty div to fill the space.
2004-01-17 23:34:11 +00:00
}
if ($node->parent) {
2004-05-09 19:28:43 +00:00
$links .= '<div class="up">';
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$links .= l(t('up'), 'node/'. $node->parent, array('title' => t('View this page\'s parent section.')));
2004-05-09 19:28:43 +00:00
$links .= '</div>';
2004-01-17 23:34:11 +00:00
}
2004-01-14 19:26:41 +00:00
2004-05-09 19:28:43 +00:00
$output .= '<div class="nav">';
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$output .= ' <div class="links">'. $links .'</div>';
$output .= ' <div class="titles">'. $titles .'</div>';
2004-05-09 19:28:43 +00:00
$output .= '</div>';
$output .= '</div>';
2004-01-17 23:34:11 +00:00
}
2004-01-14 19:26:41 +00:00
2004-01-17 23:34:11 +00:00
$node->body = $node->body.$output;
2004-01-14 19:26:41 +00:00
2003-09-15 15:58:20 +00:00
return $node;
2003-09-20 15:11:41 +00:00
}
2001-03-24 16:36:13 +00:00
2005-06-05 10:52:04 +00:00
/**
* This is a helper function for book_toc().
*/
2004-08-10 14:16:01 +00:00
function book_toc_recurse($nid, $indent, $toc, $children, $exclude) {
2001-12-17 19:45:47 +00:00
if ($children[$nid]) {
foreach ($children[$nid] as $foo => $node) {
2004-08-10 14:16:01 +00:00
if (!$exclude || $exclude != $node->nid) {
$toc[$node->nid] = $indent .' '. $node->title;
$toc = book_toc_recurse($node->nid, $indent .'--', $toc, $children, $exclude);
}
2001-12-17 19:45:47 +00:00
}
}
return $toc;
}
2005-06-05 10:52:04 +00:00
/**
* Returns an array of titles and nid entries of book pages in table of contents order.
*/
2004-08-10 14:32:09 +00:00
function book_toc($exclude = 0) {
2005-08-30 15:22:29 +00:00
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 ORDER BY b.weight, n.title'));
2001-11-04 15:57:43 +00:00
2001-12-17 19:45:47 +00:00
while ($node = db_fetch_object($result)) {
2003-11-23 12:13:08 +00:00
if (!$children[$node->parent]) {
$children[$node->parent] = array();
}
array_push($children[$node->parent], $node);
2001-12-17 19:45:47 +00:00
}
2001-11-04 15:57:43 +00:00
2004-08-24 03:22:26 +00:00
$toc = array();
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// If the user is an administrator, add the top-level book page;
// only administrators can start new books.
2004-05-09 19:28:43 +00:00
if (user_access('administer nodes')) {
$toc[0] = '<'. t('top-level') .'>';
2001-05-07 18:44:40 +00:00
}
2004-08-24 03:22:26 +00:00
$toc = book_toc_recurse(0, '', $toc, $children, $exclude);
2001-05-06 19:51:14 +00:00
2001-03-25 16:42:52 +00:00
return $toc;
}
2005-06-05 10:52:04 +00:00
/**
* This is a helper function for book_tree()
*/
2004-01-14 19:26:41 +00:00
function book_tree_recurse($nid, $depth, $children, $unfold = array()) {
2002-01-01 11:26:29 +00:00
if ($depth > 0) {
2001-12-30 16:16:38 +00:00
if ($children[$nid]) {
foreach ($children[$nid] as $foo => $node) {
2004-01-14 19:26:41 +00:00
if (in_array($node->nid, $unfold)) {
if ($tree = book_tree_recurse($node->nid, $depth - 1, $children, $unfold)) {
$output .= '<li class="expanded">';
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$output .= l($node->title, 'node/'. $node->nid);
$output .= '<ul>'. $tree .'</ul>';
2004-01-14 19:26:41 +00:00
$output .= '</li>';
}
else {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$output .= '<li class="leaf">'. l($node->title, 'node/'. $node->nid) .'</li>';
2004-01-14 19:26:41 +00:00
}
}
else {
if ($tree = book_tree_recurse($node->nid, 1, $children)) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$output .= '<li class="collapsed">'. l($node->title, 'node/'. $node->nid) .'</li>';
2004-01-14 19:26:41 +00:00
}
else {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$output .= '<li class="leaf">'. l($node->title, 'node/'. $node->nid) .'</li>';
2004-01-14 19:26:41 +00:00
}
2002-01-01 11:26:29 +00:00
}
2001-12-27 15:20:20 +00:00
}
}
2001-12-30 16:16:38 +00:00
}
return $output;
}
2005-06-05 10:52:04 +00:00
/**
* Returns an HTML nested list (wrapped in a menu-class div) representing the book nodes
* as a tree.
*/
2004-01-14 19:26:41 +00:00
function book_tree($parent = 0, $depth = 3, $unfold = array()) {
2005-08-30 15:22:29 +00:00
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title'));
2001-11-04 23:30:39 +00:00
2001-12-30 16:16:38 +00:00
while ($node = db_fetch_object($result)) {
$list = $children[$node->parent] ? $children[$node->parent] : array();
array_push($list, $node);
$children[$node->parent] = $list;
2001-05-06 19:51:14 +00:00
}
2002-01-01 11:26:29 +00:00
2004-01-14 19:26:41 +00:00
if ($tree = book_tree_recurse($parent, $depth, $children, $unfold)) {
2005-04-24 08:23:33 +00:00
return '<div class="menu"><ul>'. $tree .'</ul></div>';
2004-01-14 19:26:41 +00:00
}
2001-05-06 19:51:14 +00:00
}
2004-05-09 19:28:43 +00:00
/**
2004-05-17 22:00:06 +00:00
* Menu callback; prints a listing of all books.
2004-05-09 19:28:43 +00:00
*/
2001-07-15 17:32:33 +00:00
function book_render() {
2005-08-30 15:22:29 +00:00
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = 0 AND n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title'));
2001-11-04 23:30:39 +00:00
2005-06-07 08:30:16 +00:00
$books = array();
while ($node = db_fetch_object($result)) {
$books[] = l($node->title, 'node/'. $node->nid);
}
return theme('item_list', $books);
2001-07-15 17:32:33 +00:00
}
2004-05-09 19:28:43 +00:00
/**
2005-06-07 19:20:20 +00:00
* Menu callback; Generates various representation of a book page with
* all descendants and prints the requested representation to output.
*
* Notes: For HTML output, the given node is /embedded to its absolute
* depth in a top level section/. For example, a child node with
* depth 2 in the hierarchy is contained in (otherwise empty) <div>
* elements corresponding to depth 0 and depth 1. This is intended to
* support WYSIWYG output - e.g., level 3 sections always look like
* level 3 sections, no matter their depth relative to the node
* selected to be exported as printer-friendly HTML.
*
* DocBook XML and OPML outputs do not attempt to embed a node to its
* absolute level in the parent book.
* For DocBook output, the exported node will be a document fragment
* unless the node is a level 0 node (book), specifically
* <ul>
* <li>a <chapter> for level 1 elements, </li>
* <li>a <section> for levels 2 and deeper.</li>
* </ul>
*
* For OPML output, the exported node will be the top level element
* in the OPML outline.
*
* @param type
* - a string encoding the type of output requested.
* The following types are supported:
* 1) HTML (printer friendly output)
* 2) DocBook XML
* 3) OPML (Outline Processor Markup Language) outlines
* @param nid
* - an integer representing the node id (nid) of the node to export
*
2004-05-09 19:28:43 +00:00
*/
2005-10-06 09:17:17 +00:00
function book_export($type = 'html', $nid = FALSE) {
2003-06-12 17:24:06 +00:00
global $base_url;
2005-07-25 20:40:35 +00:00
$type = drupal_strtolower($type);
2005-10-06 09:17:17 +00:00
$node = node_load($nid);
if ($node) {
2005-09-29 21:56:12 +00:00
$depth = _book_get_depth($nid);
switch ($type) {
case 'docbook':
2005-10-08 14:48:33 +00:00
if (user_access('export books')) {
$xml = "<?xml version='1.0'?>\n";
$xml .= "<!DOCTYPE book PUBLIC \"-//OASIS//DTD Docbook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">\n";
$xml .= book_recurse($nid, $depth, 'book_node_visitor_xml_pre', 'book_node_visitor_xml_post');
drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $xml;
}
else {
drupal_access_denied();
}
2005-09-29 21:56:12 +00:00
break;
case 'html':
2005-10-08 14:48:33 +00:00
if (user_access('see printer-friendly version')) {
for ($i = 1; $i < $depth; $i++) {
$output .= "<div class=\"section-$i\">\n";
}
$output .= book_recurse($nid, $depth, 'book_node_visitor_html_pre', 'book_node_visitor_html_post');
for ($i = 1; $i < $depth; $i++) {
$output .= "</div>\n";
}
$html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">';
$html .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
$html .= '<base href="'. $base_url .'/" />' . "\n";
$html .= "<style type=\"text/css\">\n@import url(misc/print.css);\n</style>\n";
$html .= "</head>\n<body>\n". $output . "\n</body>\n</html>\n";
print $html;
2005-09-29 21:56:12 +00:00
}
2005-10-08 14:48:33 +00:00
else {
drupal_access_denied();
2005-09-29 21:56:12 +00:00
}
break;
case 'opml':
2005-10-08 14:48:33 +00:00
if (user_access('export books')) {
$output .= book_recurse($nid, $depth, 'book_node_visitor_opml_pre', 'book_node_visitor_opml_post');
$opml = "<?xml version='1.0'?>\n";
$opml .= "<opml version='1.0'>\n";
$opml .= "<head>\n<title>". check_plain($node->title) ."</title>\n";
$opml .= "</head>\n<body>\n". $output . "\n</body>\n</opml>\n";
drupal_set_header('Content-Type: text/xml; charset=utf-8');
print $opml;
}
else {
drupal_access_denied();
}
2005-09-29 21:56:12 +00:00
break;
default:
drupal_not_found();
}
}
else {
drupal_not_found();
2005-06-07 19:20:20 +00:00
}
2005-06-05 10:52:04 +00:00
}
2001-08-11 14:54:39 +00:00
2005-06-05 10:52:04 +00:00
/**
2005-06-07 19:20:20 +00:00
* Given a node, this function returns the depth of the node in its hierarchy.
* A root node has depth 1, and children of a node of depth n have depth (n+1).
*
* @param node
* - the node whose depth to compute.
* @return
* - the depth of the given node in its hierarchy. Returns 0 if the node
* does not exist or is not part of a book hierarchy.
2005-06-05 10:52:04 +00:00
*/
2005-06-07 19:20:20 +00:00
function _book_get_depth($nid) {
$depth = 0;
if ($nid) {
while ($nid) {
$result = db_query(db_rewrite_sql('SELECT b.parent FROM {book} b WHERE b.nid = %d'), $nid);
$obj = db_fetch_object($result);
$parent = $obj->parent;
if ($nid == $parent->parent) {
$nid = 0;
}
else {
$nid = $parent;
}
$depth++;
}
return $depth;
}
else {
return 0;
}
2001-08-11 14:54:39 +00:00
}
2005-06-05 10:52:04 +00:00
/**
* Traverses the book tree. Applies the $visit_pre() callback to each
* node, is called recursively for each child of the node (in weight,
* title order). Finally appends the output of the $visit_post()
* callback to the output before returning the generated output.
*
* @param nid
* - the node id (nid) of the root node of the book hierarchy.
* @param depth
* - the depth of the given node in the book hierarchy.
* @param visit_pre
* - a function callback to be called upon visiting a node in the tree
* @param visit_post
* - a function callback to be called after visiting a node in the tree,
* but before recursively visiting children.
* @return
* - the output generated in visiting each node
*/
function book_recurse($nid = 0, $depth = 1, $visit_pre, $visit_post) {
2005-08-30 15:22:29 +00:00
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $nid);
2001-11-04 23:30:39 +00:00
while ($page = db_fetch_object($result)) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Load the node:
2005-07-17 18:29:32 +00:00
$node = node_load($page->nid);
2001-11-04 23:30:39 +00:00
2001-11-25 09:55:00 +00:00
if ($node) {
2005-06-05 10:52:04 +00:00
if (function_exists($visit_pre)) {
$output .= call_user_func($visit_pre, $node, $depth, $nid);
2003-09-20 15:11:41 +00:00
}
2005-06-07 19:20:20 +00:00
else {
$output .= book_node_visitor_html_pre($node, $depth, $nid);
2001-11-25 09:55:00 +00:00
}
2001-11-04 23:30:39 +00:00
2005-08-30 15:22:29 +00:00
$children = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND b.parent = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $node->nid);
2005-06-05 10:52:04 +00:00
while ($childpage = db_fetch_object($children)) {
2005-07-17 18:29:32 +00:00
$childnode = node_load($childpage->nid);
2005-06-05 10:52:04 +00:00
if ($childnode->nid != $node->nid) {
$output .= book_recurse($childnode->nid, $depth+1, $visit_pre, $visit_post);
}
}
if (function_exists($visit_post)) {
2005-06-07 19:20:20 +00:00
$output .= call_user_func($visit_post, $node, $depth);
2005-06-05 10:52:04 +00:00
}
else { # default
2005-06-07 19:20:20 +00:00
$output .= book_node_visitor_html_post($node, $depth);
2005-06-05 10:52:04 +00:00
}
2001-11-25 09:55:00 +00:00
}
2001-04-11 19:44:24 +00:00
}
2001-06-24 19:12:30 +00:00
2001-04-11 19:44:24 +00:00
return $output;
}
2001-11-01 11:00:51 +00:00
2005-06-05 10:52:04 +00:00
/**
* Generates printer-friendly HTML for a node. This function
* is a 'pre-node' visitor function for book_recurse().
*
* @param $node
* - the node to generate output for.
* @param $depth
* - the depth of the given node in the hierarchy. This
* is used only for generating output.
* @param $nid
* - the node id (nid) of the given node. This
* is used only for generating output.
* @return
* - the HTML generated for the given node.
*/
2005-06-07 19:20:20 +00:00
function book_node_visitor_html_pre($node, $depth, $nid) {
2005-06-05 10:52:04 +00:00
// Output the content:
if (node_hook($node, 'content')) {
$node = node_invoke($node, 'content');
}
// Allow modules to change $node->body before viewing.
2005-06-07 19:20:20 +00:00
node_invoke_nodeapi($node, 'print', $node->body, false);
2005-06-05 10:52:04 +00:00
2005-06-07 19:20:20 +00:00
$output .= "<div id=\"node-". $node->nid ."\" class=\"section-$depth\">\n";
$output .= "<h1 class=\"book-heading\">". check_plain($node->title) ."</h1>\n";
2005-06-05 10:52:04 +00:00
if ($node->body) {
$output .= $node->body;
}
return $output;
}
/**
* Finishes up generation of printer-friendly HTML after visiting a
* node. This function is a 'post-node' visitor function for
* book_recurse().
*/
2005-06-07 19:20:20 +00:00
function book_node_visitor_html_post($node, $depth) {
2005-06-05 10:52:04 +00:00
return "</div>\n";
}
/**
* Generates XML for a given node. This function is a 'pre-node'
2005-06-07 19:20:20 +00:00
* visitor function for book_recurse(). The generated XML is valid
* DocBook, but each node's HTML content is wrapped in a CDATA
* section, and put inside a <literallayout> element. The node body
* has an md5-hash applied; the value of this is stored as node
* metadata to allow importing code to determine if contents have
* changed. The weight of a node is also stored as metadata to
* allow the node to be properly re-imported.
2005-06-05 10:52:04 +00:00
*
* @param $node
* - the node to generate output for.
* @param $depth
* - the depth of the given node in the hierarchy. This
* is currently not used.
* @param $nid
* - the node id (nid) of the given node. This
2005-06-07 19:20:20 +00:00
* is used only for generating output (e.g., id attribute)
2005-06-05 10:52:04 +00:00
* @return
* - the generated XML for the given node.
*/
function book_node_visitor_xml_pre($node, $depth, $nid) {
// Output the content:
if (node_hook($node, 'content')) {
$node = node_invoke($node, 'content');
}
// Allow modules to change $node->body before viewing.
2005-06-07 19:20:20 +00:00
node_invoke_nodeapi($node, 'export_xml', $node->body, false);
$releaseinfo = "<releaseinfo>\n";
$releaseinfo .= "md5-hash:" . md5($node->body) . "\n";
$releaseinfo .= "weight:". $node->weight . "\n";
$releaseinfo .= "depth:". $depth . "\n";
$releaseinfo .= "</releaseinfo>\n";
$title = "<title>". check_plain($node->title) ."</title>\n";
2005-06-05 10:52:04 +00:00
// wrap the node body in a CDATA declaration
2005-06-07 19:20:20 +00:00
$content = "<literallayout>";
$content .= "<![CDATA[";
2005-06-05 10:52:04 +00:00
if ($node->body) {
2005-06-07 19:20:20 +00:00
$content .= $node->body;
}
$content .= "]]>";
$content .= "</literallayout>\n";
if ($depth == 1) {
$output .= "<book>\n";
$output .= $title;
$output .= "<bookinfo>\n$releaseinfo</bookinfo>\n";
$output .= "<preface>\n";
$output .= "<title>Preface</title>\n";
$output .= $content;
$output .= "</preface>\n";
}
else if ($depth == 2) {
$output .= "<chapter id=\"node-".$node->nid ."\">\n";
$output .= "<chapterinfo>\n$releaseinfo</chapterinfo>\n";
$output .= $title;
$output .= $content;
}
else {
$output .= "<section id=\"node-".$node->nid ."\">\n";
$output .= "<sectioninfo>\n$releaseinfo</sectioninfo>\n";
$output .= $title;
$output .= $content;
2005-06-05 10:52:04 +00:00
}
2005-06-07 19:20:20 +00:00
2005-06-05 10:52:04 +00:00
return $output;
}
/**
2005-06-07 19:20:20 +00:00
* Completes the XML generation for the node. This function is a
* 'post-node' visitor function for book_recurse().
*/
function book_node_visitor_xml_post($node, $depth) {
if ($depth == 1) {
return "</book>\n";
}
else if ($depth == 2) {
return "</chapter>\n";
}
else {
return "</section>\n";
}
}
/**
* Generates OPML for a node. This function is a 'pre-node' visitor
* function for book_recurse().
*
* @param $node
* - the node to generate output for.
* @param $depth
* - the depth of the given node in the hierarchy. This is used only
* for generating output.
* @param $nid
* - the node id (nid) of the given node. This is used only for
* generating output.
* @return
* - the OPML generated for the given node.
*/
function book_node_visitor_opml_pre($node, $depth, $nid) {
// Output the content:
if (node_hook($node, 'content')) {
$node = node_invoke($node, 'content');
}
$output .= "<outline type=\"id:node-". $node->nid ."\"\n";
$text = check_plain($node->title);
$output .= "text=\"$text\">\n";
return $output;
}
/**
* Finishes up generation of OPML after visiting a node. This function
* is a 'post-node' visitor function for book_recurse().
2005-06-05 10:52:04 +00:00
*/
2005-06-07 19:20:20 +00:00
function book_node_visitor_opml_post($node, $depth) {
return "</outline>\n";
2005-06-05 10:52:04 +00:00
}
/**
* Creates a row for the 'admin' view of a book. Each row represents a page in the book, in the tree representing the book
*/
2005-05-05 09:36:51 +00:00
function book_admin_edit_line($node, $depth = 0) {
2005-10-11 19:44:35 +00:00
$form['#tree'] = TRUE;
$form[$node->nid]['title'] = array('#type' => 'textfield', '#default_value' => $node->title, '#size' => 60, '#maxlength' => 255);
$form[$node->nid]['weight'] = array('#type' => 'weight', '#default_value' => $node->weight, '#delta' => 15);
$form['depth'] = array('#value' => $depth);
$form['nid'] = array('#value' => $node->nid);
2005-10-07 06:11:12 +00:00
return drupal_get_form('book_admin_edit_line', $form);
}
function theme_book_admin_edit_line($form) {
2005-10-11 19:44:35 +00:00
$nid = $form['nid']['#value'];
2005-10-07 06:11:12 +00:00
return array(
2005-10-11 19:44:35 +00:00
'<div style="padding-left: '. (25 * $form['depth']['#value']) .'px;">'. form_render($form[$nid]['title']) .'</div>', form_render($form[$nid]['weight']), l(t('view'), 'node/'. $nid), l(t('edit'), 'node/'. $nid .'/edit'), l(t('delete'), 'node/'.$nid.'/delete')
2005-10-07 06:11:12 +00:00
);
2001-12-01 15:20:48 +00:00
}
2005-05-05 09:36:51 +00:00
function book_admin_edit_book($nid, $depth = 1) {
2005-08-30 15:22:29 +00:00
$result = db_query(db_rewrite_sql('SELECT n.nid, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = %d ORDER BY b.weight, n.title'), $nid);
2001-11-18 12:30:08 +00:00
2005-06-05 10:52:04 +00:00
$rows = array();
2001-11-18 12:30:08 +00:00
while ($node = db_fetch_object($result)) {
2005-07-17 18:29:32 +00:00
$node = node_load($node->nid);
2005-05-05 09:36:51 +00:00
$rows[] = book_admin_edit_line($node, $depth);
$rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1));
2001-11-18 12:30:08 +00:00
}
2003-01-12 09:57:20 +00:00
return $rows;
2001-11-18 12:30:08 +00:00
}
2004-05-09 19:28:43 +00:00
/**
* Display an administrative view of the hierarchy of a book.
*/
2005-05-05 09:36:51 +00:00
function book_admin_edit($nid, $depth = 0) {
2005-07-17 18:29:32 +00:00
$node = node_load($nid);
2005-05-05 09:36:51 +00:00
if ($node->nid) {
2005-10-07 06:11:12 +00:00
drupal_set_title(check_plain($node->title));
2004-11-15 11:16:39 +00:00
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
2005-05-05 09:36:51 +00:00
$rows[] = book_admin_edit_line($node);
$rows = array_merge($rows, book_admin_edit_book($nid));
2003-01-12 09:57:20 +00:00
2005-10-11 19:44:35 +00:00
$form['save'] = array('#type' => 'submit', '#value' => t('Save book pages'));
2002-11-10 10:36:22 +00:00
2005-10-07 06:11:12 +00:00
return theme('table', $header, $rows) . $form;
2003-05-13 21:34:39 +00:00
}
2005-05-05 09:36:51 +00:00
else {
drupal_not_found();
}
2002-11-10 10:36:22 +00:00
}
2005-06-05 10:52:04 +00:00
/**
* Saves the changes to a book made by an administrator in the book admin view.
*/
2002-11-10 10:36:22 +00:00
function book_admin_save($nid, $edit = array()) {
2003-05-13 21:34:39 +00:00
if ($nid) {
2005-07-17 18:29:32 +00:00
$book = node_load($nid);
2002-11-10 10:36:22 +00:00
2003-05-13 21:34:39 +00:00
foreach ($edit as $nid => $value) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Check to see whether the title needs updating:
2005-08-30 15:22:29 +00:00
$node = db_fetch_object(db_query('SELECT title, vid FROM {node} WHERE nid = %d', $nid));
if ($node->title != $value['title']) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
db_query("UPDATE {node} SET title = '%s' WHERE nid = %d", $value['title'], $nid);
2005-08-30 15:22:29 +00:00
db_query("UPDATE {book} SET title = '%s' WHERE vid = %d", $value['title'], $node->vid);
2003-05-13 21:34:39 +00:00
}
2002-11-10 10:36:22 +00:00
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
// Check to see whether the weight needs updating:
2005-08-30 15:22:29 +00:00
$node = db_fetch_object(db_query('SELECT b.vid, b.weight FROM {book} b INNER JOIN {node} n ON n.vid = b.vid WHERE n.nid = %d', $nid));
if ($node->weight != $value['weight']) {
db_query('UPDATE {book} SET weight = %d WHERE vid = %d', $value['weight'], $node->vid);
2003-05-13 21:34:39 +00:00
}
2002-11-10 10:36:22 +00:00
}
2005-05-05 22:22:46 +00:00
$message = t('The book %title has been updated.', array('%title' => theme('placeholder', $book->title)));
2005-01-09 09:22:40 +00:00
watchdog('content', $message);
2002-11-10 10:36:22 +00:00
2003-05-13 21:34:39 +00:00
return $message;
}
2001-11-18 12:30:08 +00:00
}
2004-05-09 19:28:43 +00:00
/**
2004-05-17 22:00:06 +00:00
* Menu callback; displays a listing of all orphaned book pages.
2004-05-09 19:28:43 +00:00
*/
2001-11-18 12:30:08 +00:00
function book_admin_orphan() {
2005-08-30 15:22:29 +00:00
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.status, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid'));
2001-11-18 12:30:08 +00:00
while ($page = db_fetch_object($result)) {
$pages[$page->nid] = $page;
}
2002-10-30 08:02:52 +00:00
if ($pages) {
2004-07-25 14:22:16 +00:00
$output .= '<h3>'. t('Orphan pages') .'</h3>';
2004-11-15 11:16:39 +00:00
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
2002-10-30 08:02:52 +00:00
foreach ($pages as $nid => $node) {
if ($node->parent && empty($pages[$node->parent])) {
2005-05-05 09:36:51 +00:00
$rows[] = book_admin_edit_line($node, $depth);
$rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1));
2002-10-30 08:02:52 +00:00
}
2001-11-18 12:30:08 +00:00
}
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$output .= theme('table', $header, $rows);
2001-11-18 12:30:08 +00:00
}
2005-04-24 16:34:36 +00:00
return $output;
2001-11-18 12:30:08 +00:00
}
2004-05-09 19:28:43 +00:00
/**
2004-05-17 22:00:06 +00:00
* Menu callback; displays the book administration page.
2004-05-09 19:28:43 +00:00
*/
2004-05-17 22:00:06 +00:00
function book_admin($nid = 0) {
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
$op = $_POST['op'];
$edit = $_POST['edit'];
2001-11-18 12:30:08 +00:00
2005-05-05 09:36:51 +00:00
if ($op == t('Save book pages')) {
drupal_set_message(book_admin_save($nid, $edit));
2001-11-18 12:30:08 +00:00
}
2005-05-05 09:36:51 +00:00
if ($nid) {
return book_admin_edit($nid);
}
else {
return book_admin_overview();
}
}
2005-06-05 10:52:04 +00:00
/**
* Returns an administrative overview of all books.
*/
2005-05-05 09:36:51 +00:00
function book_admin_overview() {
2005-08-30 15:22:29 +00:00
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = 0 ORDER BY b.weight, n.title'));
2005-05-05 09:36:51 +00:00
while ($book = db_fetch_object($result)) {
$rows[] = array(l($book->title, "node/$book->nid"), l(t('outline'), "admin/node/book/$book->nid"));
}
$headers = array(t('Book'), t('Operations'));
return theme('table', $headers, $rows);
2001-11-18 12:30:08 +00:00
}
2004-05-09 19:28:43 +00:00
/**
* Implementation of hook_help().
*/
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
function book_help($section) {
2003-08-05 18:33:39 +00:00
switch ($section) {
2003-10-09 18:53:22 +00:00
case 'admin/help#book':
2005-06-07 19:20:20 +00:00
return t(
"<p>The \"book\" content type is suited for creating structured, multi-page hypertexts such as site resource guides, manuals, and Frequently Asked Questions (FAQs). It permits a document to have chapters, sections, subsections, etc. Authors with suitable permissions can add pages to a collaborative book, placing them into the existing document by adding them to a table of contents menu. </p>
<p>Books have additional ''previous'', ''up'', and ''next'' navigation elements at the bottom of each page for moving through the text. Additional navigation may be provided by enabling the \"book navigation block\" on the
<a href = \"%book-block\" title = \"block administration\">block administration page</a>.
</p>
<p>Users can select the \"printer-friendly version\" link visible at the bottom of a book page to generate a printer-friendly display of the page and all of its subsections. They can choose to <em>export</em> the page and its subsections as DocBook XML (for offline editing, or production of print or other electronic publication formats) by selecting the \"export DocBook XML\" link. DocBook export currently treats node content as preformatted text. Selecting the \"export OPML\" link will generate an outline document (titles only) in OPML format, readable by many outline editing tools. Note: it may be neccessary to shift-click on the link to save the results to a file on the local computer.</p>
<p>Administrators can view a book outline, from which is it possible to change the titles of sections, and their <i>weight</i> (thus reordering sections). From this outline, it is also possible to edit and/or delete book pages. Many content types besides pages (for example, blog entries, stories, and polls) can be added to a collaborative book by choosing the \"outline\" tab when viewing the post.</p>
<p>You can:</p><ul><li>create new book pages:
<a href=\"%create\">create content » book page</a>
</li>
<li>administer books (choose a book from the list and select \"outline\"):
<a href=\"%collaborative-book\">administer » content » books</a>
</li>
<li>set workflow and other global book settings:
<a href=\"%workflow\" title = \"book page content type\">administer » content » [configure] » [content types] » book page</a>
</li>
<li>enable the book navigation block:
<a href = \"%book-block\" title = \"administer block\">administer » block</a>
</li>
<li>control who can create, edit, and maintain book pages by setting access permissions:
<a href = \"%permissions\" title = \"access permissions\">administer » access control</a>
</li></ul>
<p>For more information, visit the <a href = \"%book-module-help\" title = \"book module online help\">online documentation</a>.
",
array(
'%create' => url('node/add/book'),
'%collaborative-book' => url('admin/node/book'),
'%workflow' => url('admin/node/configure/types/book'),
'%book-block' => url('admin/block'),
'%permissions' => url('admin/access/permissions'),
'%book-module-help' => url('http://drupal.org/handbook/modules/book')
)
);
2004-06-18 15:04:37 +00:00
case 'admin/modules#description':
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
return t('Allows users to collaboratively author a book.');
2003-08-05 18:33:39 +00:00
case 'admin/node/book':
2004-11-23 22:20:41 +00:00
return t('<p>The book module offers a mean to organize content, authored by many users, in an online manual, outline or FAQ.</p>');
2003-08-05 18:33:39 +00:00
case 'admin/node/book/orphan':
2004-11-23 22:20:41 +00:00
return t('<p>Pages in a book are like a tree. As pages are edited, reorganized and removed, child pages might be left with no link to the rest of the book. Such pages are referred to as "orphan pages". On this page, administrators can review their books for orphans and reattach those pages as desired.</p>');
2004-01-27 18:47:07 +00:00
case 'node/add#book':
- Patch #5347 by JonBob:
Here's a new patch that unifies the node/52 and book/view/52 paths for nodes. It involves a small change to hook_view(), which is discussed first:
Currently hook_view() expects node modules to return a themed node. However, each module does this the same way; they modify $node as necessary, then call theme('node', $node) and return the result. We can refactor this so that the calling function node_view() calls theme('node') instead. By doing this, it becomes possible for hook_nodeapi('view') to be called after hook_view() where the node contents are filtered, and before theme('node') where the body is enclosed in other HTML. This way the book module can insert its navigation into the body right before the theming.
Advantages of this refactoring:
- I can use it for book.module to remove the extra viewing path.
- The function of hook_nodeapi('view') becomes more like hook_view(), as neither will expect a return value.
- We more closely follow the flow of other nodeapi calls, which usually directly follow their corresponding specific node type hooks (instead of preceding them).
- The attachment.module people could use it to append their attachments in a list after the node.
- Gabor could use it instead of his filter perversion for his "articles in a series" module.
- A little less code in each view hook.
- The content hook is no longer needed, so that means even less code.
Disadvantages:
- Any modules written to use nodeapi('view') could be affected (but these would all be post-4.4 modules).
- Implementations of hook_view() would need to be updated (but return values would be ignored, so most would work without updates anyway).
Now the patch takes advantage of this API shift to inject its navigation at the end of all book nodes, regardless of the viewing path. In fact, since the paths become identical, I've removed the book/view handler entirely. We should probably provide an .htaccess rewrite for this (one is still needed for node/view/nn anyway). At the same time, there is a check in book_block() that shows the block appropriately on these pages.
2004-07-30 13:37:26 +00:00
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.");
2003-08-05 18:33:39 +00:00
}
2004-10-08 11:17:59 +00:00
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'outline') {
2004-10-14 05:34:12 +00:00
return t('The outline feature allows you to include posts in the <a href="%book">book hierarchy</a>.', array('%book' => url('book')));
2004-10-08 11:17:59 +00:00
}
2002-04-14 19:34:04 +00:00
}
2003-11-20 21:51:23 +00:00
2005-08-25 21:14:17 +00:00