Commit df750672 authored by Dries's avatar Dries

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.
parent 9a57a207
......@@ -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>" : "&nbsp;") ."</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>" : "&nbsp;") ."</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."))) : "&nbsp;") ."</td><td align=\"center\" width=\"34%\">". ($node->parent ? l(t("up"), "node/view/$node->parent", array("title" => t("View this page's parent section."))) : "&nbsp;") ."</td><td align=\"right\" width=\"33%\">". ($next ? l(t("next"), "node/view/$next->nid", array("title" => t("View the next page in this book."))) : "&nbsp;") ."</td></tr>";
$output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? "<small>$prev->title</small>" : "&nbsp;") ."</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."))) : "&nbsp;") ."</td><td align=\"right\" width=\"33%\">". ($next ? "<small>$next->title</small>" : "&nbsp;") ."</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>";
......
......@@ -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>" : "&nbsp;") ."</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>" : "&nbsp;") ."</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."))) : "&nbsp;") ."</td><td align=\"center\" width=\"34%\">". ($node->parent ? l(t("up"), "node/view/$node->parent", array("title" => t("View this page's parent section."))) : "&nbsp;") ."</td><td align=\"right\" width=\"33%\">". ($next ? l(t("next"), "node/view/$next->nid", array("title" => t("View the next page in this book."))) : "&nbsp;") ."</td></tr>";
$output .= " <tr><td align=\"left\" width=\"33%\">". ($prev ? "<small>$prev->title</small>" : "&nbsp;") ."</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."))) : "&nbsp;") ."</td><td align=\"right\" width=\"33%\">". ($next ? "<small>$next->title</small>" : "&nbsp;") ."</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>";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment