--- modules/book/book.module 2007-02-13 23:00:00.000000000 +0100 +++ modules/book/book.module 2008-06-23 12:03:36.718750000 +0200 @@ -58,17 +58,17 @@ * Implementation of hook_link(). */ function book_link($type, $node = NULL, $teaser = FALSE) { $links = array(); if ($type == 'node' && isset($node->parent)) { if (!$teaser) { - if (book_access('create', $node) && $node->status == 1) { + if (book_access('create', $node)) { //Roi Danton: View unpublished nodes $links['book_add_child'] = array( 'title' => t('Add child page'), 'href' => "node/add/book/parent/$node->nid" ); } if (user_access('see printer-friendly version')) { $links['book_printer'] = array( 'title' => t('Printer-friendly version'), @@ -226,33 +226,35 @@ $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE, ); $form['body_filter']['format'] = filter_form($node->format); - if (user_access('administer nodes')) { + /*Roi Danton: normal user must be able to set weight + if (user_access('administer nodes')) { */ $form['weight'] = array('#type' => 'weight', '#title' => t('Weight'), '#default_value' => $node->weight, '#delta' => 15, '#weight' => 5, '#description' => t('Pages at a given level are ordered first by weight and then by title.'), ); + /*Roi Danton: normal user must be able to set weight } else { // If a regular user updates a book page, we preserve the node weight; otherwise // we use 0 as the default for new pages $form['weight'] = array( '#type' => 'value', '#value' => isset($node->weight) ? $node->weight : 0, ); - } + } */ return $form; } /** * Implementation of function book_outline() * Handles all book outline operations. */ @@ -350,64 +352,68 @@ * A book node object where the path starts. * * @return * An array of book node objects representing the path nodes from the * given node. Returns an empty array if the node does not exist or * 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('view unpublished nodes') ? '' : 'AND n.status = 1'; //Roi Danton: View unpublished nodes + $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)); //Roi Danton: View unpublished nodes if ($last_direct_child) { $nodes[] = $last_direct_child; $nodes = book_location_down($last_direct_child, $nodes); } return $nodes; } /** * Fetches the node object of the previous page of the book. */ function book_prev($node) { // If the parent is zero, we are at the start of a book so there is no previous. if ($node->parent == 0) { return NULL; } + $status = user_access('view unpublished nodes') ? '' : 'AND n.status = 1'; //Roi Danton: View unpublished nodes + // 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)); //Roi Danton: View unpublished nodes if ($direct_above) { // Get last leaf of $above. $path = book_location_down($direct_above); return $path ? (count($path) > 0 ? array_pop($path) : NULL) : $direct_above; } 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)); //Roi Danton: View unpublished nodes return $prev; } } /** * Fetches the node object of the next page of the book. */ function book_next($node) { + $status = user_access('view unpublished nodes') ? '' : 'AND n.status = 1'; //Roi Danton: View unpublished nodes // 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)); //Roi Danton: View unpublished nodes if ($child) { return $child; } // No direct child: get next for this level or any parent in this book. $path = book_location($node); // Path to top-level node including this one. $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)); //Roi Danton: View unpublished nodes if ($next) { return $next; } } } /** * Returns the content of a given node. If $teaser if TRUE, returns @@ -438,17 +444,17 @@ $node->breadcrumb = array(); // Overwrite the trail with a book trail. foreach ($path as $level) { $node->breadcrumb[] = array('path' => 'node/'. $level->nid, 'title' => $level->title); } $node->breadcrumb[] = array('path' => 'node/'. $node->nid); $node->content['book_navigation'] = array( '#value' => theme('book_navigation', $node), - '#weight' => 100, + '#weight' => 2, //Roi Danton: weight changed, so cck fields could be below navigation ); if ($page) { menu_set_location($node->breadcrumb); } } } break; @@ -527,17 +533,18 @@ return $toc; } /** * 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('view unpublished nodes') ? '' : 'WHERE n.status = 1'; //Roi Danton: View unpublished nodes + $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')); //Roi Danton: View unpublished nodes $children = array(); while ($node = db_fetch_object($result)) { if (!$children[$node->parent]) { $children[$node->parent] = array(); } $children[$node->parent][] = $node; } @@ -587,34 +594,36 @@ return $output; } /** * Returns an HTML nested list (wrapped in a menu-class div) representing the book nodes * 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('view unpublished nodes') ? '' : 'WHERE n.status = 1'; //Roi Danton: View unpublished nodes + $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')); //Roi Danton: View unpublished nodes while ($node = db_fetch_object($result)) { $list = isset($children[$node->parent]) ? $children[$node->parent] : array(); $list[] = $node; $children[$node->parent] = $list; } if ($tree = book_tree_recurse($parent, $depth, $children, $unfold)) { return ''; } } /** * 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('view unpublished nodes') ? '' : 'AND n.status = 1'; //Roi Danton: View unpublished nodes + $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')); //Roi Danton: View unpublished nodes $books = array(); while ($node = db_fetch_object($result)) { $books[] = l($node->title, 'node/'. $node->nid); } return theme('item_list', $books); }