Index: modules/book/book.module =================================================================== RCS file: /cvs/drupal/drupal/modules/book/book.module,v retrieving revision 1.403 diff -u -p -r1.403 book.module --- modules/book/book.module 30 Nov 2006 02:04:31 -0000 1.403 +++ modules/book/book.module 30 Nov 2006 05:41:47 -0000 @@ -63,7 +63,7 @@ function book_link($type, $node = NULL, if ($type == 'node' && isset($node->parent)) { if (!$teaser) { - if (book_access('create', $node) && $node->status == 1) { + if (book_access('create', $node)) { $links['book_add_child'] = array( 'title' => t('Add child page'), 'href' => "node/add/book/parent/$node->nid" @@ -355,7 +355,10 @@ function book_location($node, $nodes = a * is not part of a book hierarchy or there are no siblings. */ function book_location_down($node, $nodes = array()) { - $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.vid = b.vid WHERE n.status = 1 AND b.parent = %d ORDER BY b.weight DESC, n.title DESC'), $node->nid)); + + $status = user_access('administer nodes') ? '' : 'AND n.status = 1'; + + $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.vid = b.vid WHERE b.parent = %d '. $status .' ORDER BY b.weight DESC, n.title DESC'), $node->nid)); if ($last_direct_child) { $nodes[] = $last_direct_child; $nodes = book_location_down($last_direct_child, $nodes); @@ -372,8 +375,10 @@ function book_prev($node) { return NULL; } + $status = user_access('administer nodes') ? '' : 'AND n.status = 1'; + // Previous on the same level: - $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 (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)); + $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 (b.weight < %d OR (b.weight = %d AND n.title < '%s')) $status ORDER BY b.weight DESC, n.title DESC"), $node->parent, $node->weight, $node->weight, $node->title)); if ($direct_above) { // Get last leaf of $above. $path = book_location_down($direct_above); @@ -382,7 +387,7 @@ function book_prev($node) { } else { // Direct parent: - $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'), $node->parent)); + $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 '. $status), $node->parent)); return $prev; } } @@ -391,8 +396,9 @@ function book_prev($node) { * Fetches the node object of the next page of the book. */ function book_next($node) { + $status = user_access('administer nodes') ? '' : 'AND n.status = 1'; // get first direct child - $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 ORDER BY b.weight ASC, n.title ASC'), $node->nid)); + $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 '. $status .' ORDER BY b.weight ASC, n.title ASC'), $node->nid)); if ($child) { return $child; } @@ -402,7 +408,7 @@ function book_next($node) { $path[] = $node; while (($leaf = array_pop($path)) && count($path)) { - $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 (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)); + $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 (b.weight > %d OR (b.weight = %d AND n.title > '%s')) $status ORDER BY b.weight ASC, n.title ASC"), $leaf->parent, $leaf->weight, $leaf->weight, $leaf->title)); if ($next) { return $next; } @@ -532,7 +538,10 @@ function book_toc_recurse($nid, $indent, * Returns an array of titles and nid entries of book pages in table of contents order. */ function book_toc($exclude = 0) { - $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')); + + $where = user_access('administer nodes') ? '' : 'WHERE n.status = 1'; + + $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 .' ORDER BY b.weight, n.title')); $children = array(); while ($node = db_fetch_object($result)) { @@ -592,7 +601,8 @@ function book_tree_recurse($nid, $depth, * as a tree. */ function book_tree($parent = 0, $depth = 3, $unfold = array()) { - $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')); + $where = user_access('administer nodes') ? '' : 'WHERE n.status = 1'; + $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 .' ORDER BY b.weight, n.title')); while ($node = db_fetch_object($result)) { $list = isset($children[$node->parent]) ? $children[$node->parent] : array(); @@ -609,7 +619,8 @@ function book_tree($parent = 0, $depth = * Menu callback; prints a listing of all books. */ function book_render() { - $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 ORDER BY b.weight, n.title')); + $status = user_access('administer nodes') ? '' : 'AND n.status = 1'; + $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 '. $status .' ORDER BY b.weight, n.title')); $books = array(); while ($node = db_fetch_object($result)) {