diff options
-rw-r--r-- | modules/book.module | 21 | ||||
-rw-r--r-- | modules/book/book.module | 21 |
2 files changed, 24 insertions, 18 deletions
diff --git a/modules/book.module b/modules/book.module index b21138a16..5c5eb1b79 100644 --- a/modules/book.module +++ b/modules/book.module @@ -304,7 +304,7 @@ function book_prev($node) { if ($direct_above) { // get last leaf of $above $path = book_location_down($direct_above); - return $path ? array_pop($path) : $direct_above; + return $path ? (count($path) > 1 ? array_pop($path) : NULL) : $direct_above; } else { // direct parent @@ -320,10 +320,10 @@ function book_next($node) { return $child; } - // no direct child: get next for this level or any parent + // no direct child: get next for this level or any parent in this book array_push($path = book_location($node), $node); // path to root node including this one - // loop through nodes to root, starting with this node - while ($leaf = array_pop($path)) { + // loop through nodes to book root, starting with this node + while (($leaf = array_pop($path)) && count($path)) { $next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') 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)); if ($next) { return $next; @@ -398,9 +398,12 @@ function book_view($node, $main = 0) { $output .= "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">"; if ($node->title) { - foreach (book_location($node) as $level) { - $location .= "$indent ". l($level->title, "node/view/$level->nid") ."<br />"; - $indent .= "-"; + // build the tree from bottom to top to have the book index in $level for navigation later + $path = array_reverse(book_location($node)); + $i = count($path); + foreach ($path as $level) { + $indent = str_repeat("-", --$i); + $location = "$indent ". l($level->title, "node/view/$level->nid") ."<br />". $location; } $output .= " <tr><td colspan=\"3\">$location</td></tr>"; @@ -421,8 +424,8 @@ function book_view($node, $main = 0) { } $output .= " <tr><td colspan=\"3\"><hr /></td></tr>"; - $output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? l(t("previous"), "node/view/$prev->nid", array("title" => t("View the previous page in this book."))) : t("previous")) ."</td><td align=\"center\" width=\"34%\">". l(t("index"), "book", array("title" => t("View this book's table of contents."))) ."</td><td align=\"right\" width=\"33%\">". ($next ? l(t("next"), "node/view/$next->nid", array("title" => t("View the next page in this book."))) : t("next")) ."</td></tr>"; - $output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? "<small>$prev->title</small>" : " ") ."</td><td align=\"center\" width=\"34%\">". ($node->parent ? l(t("up"), "node/view/$node->parent", array("title" => t("View this page's parent section."))) : t("up")) ."</td><td align=\"right\" width=\"33%\">". ($next ? "<small>$next->title</small>" : " ") ."</td></tr>"; + $output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? l(t("previous"), "node/view/$prev->nid", array("title" => t("View the previous page in this book."))) : " ") ."</td><td align=\"center\" width=\"34%\">". ($node->parent ? l(t("up"), "node/view/$node->parent", array("title" => t("View this page's parent section."))) : " ") ."</td><td align=\"right\" width=\"33%\">". ($next ? l(t("next"), "node/view/$next->nid", array("title" => t("View the next page in this book."))) : " ") ."</td></tr>"; + $output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? "<small>$prev->title</small>" : " ") ."</td><td align=\"center\" width=\"34%\">". ($node->parent && $node->parent != $level->nid ? l(t("index"), "node/view/$level->nid", array("title" => t("View this book's table of contents."))) : " ") ."</td><td align=\"right\" width=\"33%\">". ($next ? "<small>$next->title</small>" : " ") ."</td></tr>"; $output .= " <tr><td colspan=\"3\"><hr /></td></tr>"; $output .= " <tr><td colspan=\"3\" align=\"right\"><div style=\"margin: 10 10 10 10;\">". theme("links", link_node($node, $main)) ."</div></td></tr>"; $output .= "</table>"; diff --git a/modules/book/book.module b/modules/book/book.module index b21138a16..5c5eb1b79 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -304,7 +304,7 @@ function book_prev($node) { if ($direct_above) { // get last leaf of $above $path = book_location_down($direct_above); - return $path ? array_pop($path) : $direct_above; + return $path ? (count($path) > 1 ? array_pop($path) : NULL) : $direct_above; } else { // direct parent @@ -320,10 +320,10 @@ function book_next($node) { return $child; } - // no direct child: get next for this level or any parent + // no direct child: get next for this level or any parent in this book array_push($path = book_location($node), $node); // path to root node including this one - // loop through nodes to root, starting with this node - while ($leaf = array_pop($path)) { + // loop through nodes to book root, starting with this node + while (($leaf = array_pop($path)) && count($path)) { $next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = %d AND n.status = 1 AND (n.moderate = 0 OR n.revisions != '') 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)); if ($next) { return $next; @@ -398,9 +398,12 @@ function book_view($node, $main = 0) { $output .= "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\">"; if ($node->title) { - foreach (book_location($node) as $level) { - $location .= "$indent ". l($level->title, "node/view/$level->nid") ."<br />"; - $indent .= "-"; + // build the tree from bottom to top to have the book index in $level for navigation later + $path = array_reverse(book_location($node)); + $i = count($path); + foreach ($path as $level) { + $indent = str_repeat("-", --$i); + $location = "$indent ". l($level->title, "node/view/$level->nid") ."<br />". $location; } $output .= " <tr><td colspan=\"3\">$location</td></tr>"; @@ -421,8 +424,8 @@ function book_view($node, $main = 0) { } $output .= " <tr><td colspan=\"3\"><hr /></td></tr>"; - $output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? l(t("previous"), "node/view/$prev->nid", array("title" => t("View the previous page in this book."))) : t("previous")) ."</td><td align=\"center\" width=\"34%\">". l(t("index"), "book", array("title" => t("View this book's table of contents."))) ."</td><td align=\"right\" width=\"33%\">". ($next ? l(t("next"), "node/view/$next->nid", array("title" => t("View the next page in this book."))) : t("next")) ."</td></tr>"; - $output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? "<small>$prev->title</small>" : " ") ."</td><td align=\"center\" width=\"34%\">". ($node->parent ? l(t("up"), "node/view/$node->parent", array("title" => t("View this page's parent section."))) : t("up")) ."</td><td align=\"right\" width=\"33%\">". ($next ? "<small>$next->title</small>" : " ") ."</td></tr>"; + $output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? l(t("previous"), "node/view/$prev->nid", array("title" => t("View the previous page in this book."))) : " ") ."</td><td align=\"center\" width=\"34%\">". ($node->parent ? l(t("up"), "node/view/$node->parent", array("title" => t("View this page's parent section."))) : " ") ."</td><td align=\"right\" width=\"33%\">". ($next ? l(t("next"), "node/view/$next->nid", array("title" => t("View the next page in this book."))) : " ") ."</td></tr>"; + $output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? "<small>$prev->title</small>" : " ") ."</td><td align=\"center\" width=\"34%\">". ($node->parent && $node->parent != $level->nid ? l(t("index"), "node/view/$level->nid", array("title" => t("View this book's table of contents."))) : " ") ."</td><td align=\"right\" width=\"33%\">". ($next ? "<small>$next->title</small>" : " ") ."</td></tr>"; $output .= " <tr><td colspan=\"3\"><hr /></td></tr>"; $output .= " <tr><td colspan=\"3\" align=\"right\"><div style=\"margin: 10 10 10 10;\">". theme("links", link_node($node, $main)) ."</div></td></tr>"; $output .= "</table>"; |