Commit d9cb4522 authored by Dries's avatar Dries

- Book module improvements.  This commit changes the behavior of the "view"
  hook.  See mailing list for details; search for a mail with the subject:
  '[IMPORTANT] behavior of "view" hook changed'.  Modified patch from Nick.
parent 7e60456c
......@@ -41,8 +41,8 @@ function image($name) {
return "misc/$name";
}
function path($path) {
print "<div class=\"path\">". implode($path, " &raquo; ") ."</div>";
function breadcrumb($trail) {
print "<div class=\"breadcrumb\">". implode($trail, " &raquo; ") ."</div>";
}
function node($node, $main) {
......
......@@ -34,34 +34,30 @@ th {
.book {
margin-bottom: 2em;
}
.book hr {
clear: both;
border: 0;
height: 1px;
background-color: #888;
color: #888;
}
.book .title {
font-weight: bold;
font-size: 1.3em;
margin-bottom:1em;
}
.book .last-updated {
font-size: 0.8em;
margin-top: 0.25em;
.book .tree {
margin-bottom: 2em;
}
.book .body {
margin: 1em 0 1em 0;
.book .name {
padding-top:1em;
font-weight: bold;
font-size: 1em;
}
.book .links {
clear: both;
.book .nav {
border-top: 1px solid #888;
padding-top: 0.5em;
padding-top:0.5em;
padding-bottom: 2em;
border-bottom: 1px solid #888;
clear:both;
}
.book .nav .links {
margin-top: 2em;
clear: both;
}
.book .nav {
margin: 1em 0;
.book .nav .titles {
clear: both;
}
.book .nav .prev {
......@@ -77,9 +73,6 @@ th {
.book .nav .up {
text-align: center;
}
.book .nav .titles {
clear: both;
}
.calendar .row-week td a {
display: block;
}
......
......@@ -128,7 +128,7 @@ function blog_page_user($uid) {
$trail[] = l(t("Home"), NULL);
$trail[] = l(t("Blogs"), "blog");
$trail[] = t("%name's blog", array("%name" => $account->name));
theme("path", $trail, $trail);
theme("breadcrumb", $trail);
$result = pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
......@@ -144,7 +144,7 @@ function blog_page_last() {
// Breadcrumb navigation:
$trail[] = l(t("Home"), NULL);
$trail[] = t("Blogs");
theme("path", $trail, $trail);
theme("breadcrumb", $trail);
$result = pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
......@@ -232,13 +232,14 @@ function blog_page() {
function blog_view($node, $main = 0) {
if ($main == 0) {
// Breadcrumb navigation:
$trail[] = l(t("Home"), NULL);
$trail[] = l(t("%name's blog", array("%name" => $node->name)), "blog/$node->uid");
theme("path", $trail, $trail);
$node->trail[] = l(t("Home"), NULL);
$node->trail[] = l(t("%name's blog", array("%name" => $node->name)), "blog/$node->uid");
}
theme("node", $node, $main);
$node->teaser = check_output($node->teaser);
$node->body = check_output($node->body);
return $node;
}
function blog_link($type, $node = 0, $main) {
......
......@@ -128,7 +128,7 @@ function blog_page_user($uid) {
$trail[] = l(t("Home"), NULL);
$trail[] = l(t("Blogs"), "blog");
$trail[] = t("%name's blog", array("%name" => $account->name));
theme("path", $trail, $trail);
theme("breadcrumb", $trail);
$result = pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
......@@ -144,7 +144,7 @@ function blog_page_last() {
// Breadcrumb navigation:
$trail[] = l(t("Home"), NULL);
$trail[] = t("Blogs");
theme("path", $trail, $trail);
theme("breadcrumb", $trail);
$result = pager_query("SELECT nid FROM {node} WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", variable_get("default_nodes_main", 10));
......@@ -232,13 +232,14 @@ function blog_page() {
function blog_view($node, $main = 0) {
if ($main == 0) {
// Breadcrumb navigation:
$trail[] = l(t("Home"), NULL);
$trail[] = l(t("%name's blog", array("%name" => $node->name)), "blog/$node->uid");
theme("path", $trail, $trail);
$node->trail[] = l(t("Home"), NULL);
$node->trail[] = l(t("%name's blog", array("%name" => $node->name)), "blog/$node->uid");
}
theme("node", $node, $main);
$node->teaser = check_output($node->teaser);
$node->body = check_output($node->body);
return $node;
}
function blog_link($type, $node = 0, $main) {
......
......@@ -367,7 +367,7 @@ function book_body($node) {
return $output;
}
function book_view($node, $main = 0) {
function book_view($node, $main = 0, $return = 0) {
/*
** Always display the most recently approved revision of a node
......@@ -397,67 +397,121 @@ function book_view($node, $main = 0) {
*/
if ($main) {
theme("node", $node, $main);
return $node;
}
else {
// build the tree from bottom to top to have the book index in $level for navigation later
$path = book_location($node);
$node->trail[] = l(t("Home"), "");
$node->trail[] = l(t("Books"), "book");
foreach ($path as $level) {
$node->trail[] = l($level->title, "book/view/$level->nid");
}
if ($node->moderate) {
$node->body = $node->body . "<div class=\"log\"><div class=\"title\">". t("Log") .":</div>$node->log</div>";
}
if (!$return) { // Add the navigation when we have a node/view and the output is for theme("node")
$node = book_navigation($node);
}
return $node;
}
}
function book_show($node, $cid) {
$node = node_view($node,0,1);
/*
** Add the book navigation
*/
$book = db_fetch_object(db_query("SELECT * FROM {book} WHERE nid = %d", $node->nid));
if ($book) {
foreach ($book as $key => $value) {
$node->$key = $value;
}
$node = book_navigation($node);
}
/*
** make $node->type a book. This is for the links.
*/
$node->type = "book";
/*
** View the node
*/
if (node_access("view", $node)) {
theme("breadcrumb", $node->trail);
theme("node",$node, 0);
if (function_exists("comment_render") && $node->comment) {
comment_render($node, $cid);
}
/*
** Construct the "next" and "previous" links:
** Update the history table, stating that this user viewed this node.
*/
node_tag_new($node->nid);
}
}
if ($node->nid) {
$prev = book_prev($node);
$next = book_next($node);
}
function book_navigation($node) {
// build the tree from bottom to top to have the book index in $level for navigation later
$path = book_location($node);
$trail[] = l(t("Home"), "");
$trail[] = l(t("Books"), "book");
foreach ($path as $level) {
$trail[] = l($level->title, "node/view/$level->nid");
}
theme("path", $trail);
$output .= "<div class=\"book\">";
$output .= "<div class=\"body\">$node->body</div>";
if ($node->type != "book") {
$node->trail = ""; // Overwrite the trail with a book trail.
$node->trail[] = l(t("Home"), "");
$node->trail[] = l(t("Books"), "book");
foreach ($path as $level) {
$node->trail[] = l($level->title, "book/view/$level->nid");
}
}
/*
** Construct the "next" and "previous" links:
*/
if ($node->moderate) {
$output .= "<div class=\"log\"><div class=\"title\">". t("Log") .":</div>$node->log</div>";
if ($node->nid) {
$prev = book_prev($node);
$next = book_next($node);
}
if ($node->nid) {
$output .= "<div class=\"book\">";
$output .= "<div class=\"tree\">". book_tree($node->nid) ."</div>";
if ($prev) {
$links .= "<div class=\"prev\">";
$links .= l(t("previous"), "node/view/$prev->nid", array("title" => t("View the previous page in this book.")));
$links .= l(t("previous"), "book/view/$prev->nid", array("title" => t("View the previous page in this book.")));
$links .= "</div>";
$titles .= "<div class=\"prev\">$prev->title</div>";
}
if ($next) {
$links .= "<div class=\"next\">";
$links .= l(t("next"), "node/view/$next->nid", array("title" => t("View the next page in this book.")));
$links .= l(t("next"), "book/view/$next->nid", array("title" => t("View the next page in this book.")));
$links .= "</div>";
$titles .= "<div class=\"next\">$next->title</div>";
}
else {
$links .= "<div class=\"next\">&nbsp;</div>"; // make an empty div to fill the space
}
if ($node->parent) {
$links .= "<div class=\"up\">";
$links .= l(t("up"), "node/view/$node->parent", array("title" => t("View this page's parent section.")));
if ($node->parent != $level->nid) {
$links .= " | ";
$links .= l(t("index"), "node/view/$level->nid", array("title" => t("View this book's table of contents.")));
}
$links .= l(t("up"), "book/view/$node->parent", array("title" => t("View this page's parent section.")));
$links .= "</div>";
}
$output .= "<div class=\"nav\">";
$output .= "<div class=\"links\">$links</div>";
$output .= "<div class=\"titles\">$titles</div>";
$output .= "</div>";
$output .= "</div>";
}
$output .= "</div>";
$node->body = $output;
theme("node", $node, 0);
$node->body = $node->body.$output;
return $node;
}
}
function book_toc_recurse($nid, $indent, $toc, $children) {
......@@ -506,7 +560,7 @@ function book_tree_recurse($nid, $depth, $children) {
if ($children[$nid]) {
foreach ($children[$nid] as $foo => $node) {
$output .= "<li>";
$output .= l($node->title, "node/view/$node->nid");
$output .= l($node->title, "book/view/$node->nid");
if ($tree = book_tree_recurse($node->nid, $depth - 1, $children)) {
$output .= "<ul>$tree</ul>";
}
......@@ -552,7 +606,7 @@ function book_render() {
if ($node) {
// output the content:
$output .= "<div class=\"book\">";
$output .= "<div class=\"title\">". l($node->title, "node/view/$node->nid") ."</div>";
$output .= "<div class=\"title\">". l($node->title, "book/view/$node->nid") ."</div>";
$output .= "<div class=\"body\">". book_body($node) ."</div>";
$output .= "</div>";
}
......@@ -565,9 +619,14 @@ function book_render() {
function book_page() {
if (user_access("access content")) {
switch (arg(1)) {
case "view":
$node = node_load(array("nid" => arg(2)), 1);
theme("header");
book_show($node, arg(3));
theme("footer");
break;
case "print":
print book_print(arg(2), $depth = 1);
break;
......@@ -596,11 +655,11 @@ function book_print($id = "", $depth = 1) {
}
if ($node) {
$node = node_view($node, 0, 1);
// output the content:
$output .= "<h1 id=\"$node->nid\" name=\"$node->nid\" class=\"book-h$depth\">$node->title</h1>";
if ($node->body) {
$output .= book_body($node);
$output .= $node->body;
}
}
}
......@@ -630,9 +689,9 @@ function book_print_recurse($parent = "", $depth = 1) {
if ($node) {
// output the content:
$output .= "<h1 id=\"$node->nid\" name=\"$node->nid\" class=\"book-h$depth\">$node->title</h1>";
$node = node_view($node, 0, 1);
if ($node->body) {
$output .= "<ul>". book_body($node) ."</ul>";
$output .= "<ul>". $node->body ."</ul>";
}
$output .= book_print_recurse($node->nid, $depth + 1);
......
......@@ -367,7 +367,7 @@ function book_body($node) {
return $output;
}
function book_view($node, $main = 0) {
function book_view($node, $main = 0, $return = 0) {
/*
** Always display the most recently approved revision of a node
......@@ -397,67 +397,121 @@ function book_view($node, $main = 0) {
*/
if ($main) {
theme("node", $node, $main);
return $node;
}
else {
// build the tree from bottom to top to have the book index in $level for navigation later
$path = book_location($node);
$node->trail[] = l(t("Home"), "");
$node->trail[] = l(t("Books"), "book");
foreach ($path as $level) {
$node->trail[] = l($level->title, "book/view/$level->nid");
}
if ($node->moderate) {
$node->body = $node->body . "<div class=\"log\"><div class=\"title\">". t("Log") .":</div>$node->log</div>";
}
if (!$return) { // Add the navigation when we have a node/view and the output is for theme("node")
$node = book_navigation($node);
}
return $node;
}
}
function book_show($node, $cid) {
$node = node_view($node,0,1);
/*
** Add the book navigation
*/
$book = db_fetch_object(db_query("SELECT * FROM {book} WHERE nid = %d", $node->nid));
if ($book) {
foreach ($book as $key => $value) {
$node->$key = $value;
}
$node = book_navigation($node);
}
/*
** make $node->type a book. This is for the links.
*/
$node->type = "book";
/*
** View the node
*/
if (node_access("view", $node)) {
theme("breadcrumb", $node->trail);
theme("node",$node, 0);
if (function_exists("comment_render") && $node->comment) {
comment_render($node, $cid);
}
/*
** Construct the "next" and "previous" links:
** Update the history table, stating that this user viewed this node.
*/
node_tag_new($node->nid);
}
}
if ($node->nid) {
$prev = book_prev($node);
$next = book_next($node);
}
function book_navigation($node) {
// build the tree from bottom to top to have the book index in $level for navigation later
$path = book_location($node);
$trail[] = l(t("Home"), "");
$trail[] = l(t("Books"), "book");
foreach ($path as $level) {
$trail[] = l($level->title, "node/view/$level->nid");
}
theme("path", $trail);
$output .= "<div class=\"book\">";
$output .= "<div class=\"body\">$node->body</div>";
if ($node->type != "book") {
$node->trail = ""; // Overwrite the trail with a book trail.
$node->trail[] = l(t("Home"), "");
$node->trail[] = l(t("Books"), "book");
foreach ($path as $level) {
$node->trail[] = l($level->title, "book/view/$level->nid");
}
}
/*
** Construct the "next" and "previous" links:
*/
if ($node->moderate) {
$output .= "<div class=\"log\"><div class=\"title\">". t("Log") .":</div>$node->log</div>";
if ($node->nid) {
$prev = book_prev($node);
$next = book_next($node);
}
if ($node->nid) {
$output .= "<div class=\"book\">";
$output .= "<div class=\"tree\">". book_tree($node->nid) ."</div>";
if ($prev) {
$links .= "<div class=\"prev\">";
$links .= l(t("previous"), "node/view/$prev->nid", array("title" => t("View the previous page in this book.")));
$links .= l(t("previous"), "book/view/$prev->nid", array("title" => t("View the previous page in this book.")));
$links .= "</div>";
$titles .= "<div class=\"prev\">$prev->title</div>";
}
if ($next) {
$links .= "<div class=\"next\">";
$links .= l(t("next"), "node/view/$next->nid", array("title" => t("View the next page in this book.")));
$links .= l(t("next"), "book/view/$next->nid", array("title" => t("View the next page in this book.")));
$links .= "</div>";
$titles .= "<div class=\"next\">$next->title</div>";
}
else {
$links .= "<div class=\"next\">&nbsp;</div>"; // make an empty div to fill the space
}
if ($node->parent) {
$links .= "<div class=\"up\">";
$links .= l(t("up"), "node/view/$node->parent", array("title" => t("View this page's parent section.")));
if ($node->parent != $level->nid) {
$links .= " | ";
$links .= l(t("index"), "node/view/$level->nid", array("title" => t("View this book's table of contents.")));
}
$links .= l(t("up"), "book/view/$node->parent", array("title" => t("View this page's parent section.")));
$links .= "</div>";
}
$output .= "<div class=\"nav\">";
$output .= "<div class=\"links\">$links</div>";
$output .= "<div class=\"titles\">$titles</div>";
$output .= "</div>";
$output .= "</div>";
}
$output .= "</div>";
$node->body = $output;
theme("node", $node, 0);
$node->body = $node->body.$output;
return $node;
}
}
function book_toc_recurse($nid, $indent, $toc, $children) {
......@@ -506,7 +560,7 @@ function book_tree_recurse($nid, $depth, $children) {
if ($children[$nid]) {
foreach ($children[$nid] as $foo => $node) {
$output .= "<li>";
$output .= l($node->title, "node/view/$node->nid");
$output .= l($node->title, "book/view/$node->nid");
if ($tree = book_tree_recurse($node->nid, $depth - 1, $children)) {
$output .= "<ul>$tree</ul>";
}
......@@ -552,7 +606,7 @@ function book_render() {
if ($node) {
// output the content:
$output .= "<div class=\"book\">";
$output .= "<div class=\"title\">". l($node->title, "node/view/$node->nid") ."</div>";
$output .= "<div class=\"title\">". l($node->title, "book/view/$node->nid") ."</div>";
$output .= "<div class=\"body\">". book_body($node) ."</div>";
$output .= "</div>";
}
......@@ -565,9 +619,14 @@ function book_render() {
function book_page() {
if (user_access("access content")) {
switch (arg(1)) {
case "view":
$node = node_load(array("nid" => arg(2)), 1);
theme("header");
book_show($node, arg(3));
theme("footer");
break;
case "print":
print book_print(arg(2), $depth = 1);
break;
......@@ -596,11 +655,11 @@ function book_print($id = "", $depth = 1) {
}
if ($node) {
$node = node_view($node, 0, 1);
// output the content:
$output .= "<h1 id=\"$node->nid\" name=\"$node->nid\" class=\"book-h$depth\">$node->title</h1>";
if ($node->body) {
$output .= book_body($node);
$output .= $node->body;
}
}
}
......@@ -630,9 +689,9 @@ function book_print_recurse($parent = "", $depth = 1) {
if ($node) {
// output the content:
$output .= "<h1 id=\"$node->nid\" name=\"$node->nid\" class=\"book-h$depth\">$node->title</h1>";
$node = node_view($node, 0, 1);
if ($node->body) {
$output .= "<ul>". book_body($node) ."</ul>";
$output .= "<ul>". $node->body ."</ul>";
}
$output .= book_print_recurse($node->nid, $depth + 1);
......
......@@ -141,6 +141,17 @@ function comment_access($op, $comment) {
}
}
function comment_referer_save() {
$_SESSION["comment_referer"] = arg(0)."/".arg(1)."/".arg(2);
}
/*
** Restores the referer from a persistent variable:
*/
function comment_referer_load() {
return $_SESSION["comment_referer"];
}
function comment_form($edit) {
global $user;
......@@ -196,7 +207,8 @@ function comment_reply($pid, $nid) {
comment_view($comment);
}
else if (user_access("access content")) {
node_view(node_load(array("nid" => $nid)));
$node = node_view(node_load(array("nid" => $nid)),0,1);
theme("box", $node->title, $node->body);
$pid = 0;
}
......@@ -247,7 +259,8 @@ function comment_preview($edit) {
comment_view($comment);
}
else {
node_view(node_load(array("nid" => $edit["nid"])));
$node = node_view(node_load(array("nid" => $edit["nid"])), 0, 1);
theme("box", $node->title, $node->body);
$edit["pid"] = 0;
}
}
......@@ -464,7 +477,7 @@ function comment_links($comment, $return = 1) {
*/
if ($return) {
$links[] = l(t("parent"), "node/view/$comment->nid#$comment->cid");
$links[] = l(t("parent"), comment_referer_load()."#$comment->cid");
}
/*
......@@ -740,6 +753,11 @@ function comment_render($node, $cid = 0) {
theme("box", t("Post new comment"), comment_form(array("nid" => $nid)));
}
/*
** Save were we come from so we can go back after a reply
*/
comment_referer_save();
}
}
......@@ -837,7 +855,7 @@ function comment_page() {
case t("Moderate comments"):
case t("Moderate comment"):
comment_moderate($edit);
drupal_goto(url("node/view/". $edit["nid"]));
drupal_goto(url(comment_referer_load()));
break;
case "reply":
theme("header");
......@@ -857,7 +875,7 @@ function comment_page() {
theme("footer");
}
else {
drupal_goto(url("node/view/". $edit["nid"]));
drupal_goto(url(comment_referer_load()));
}
break;
case t("Save settings"):
......@@ -867,7 +885,8 @@ function comment_page() {
$comments_per_page = $_POST["comments_per_page"];
comment_save_settings(check_query($mode), check_query($order), check_query($threshold), check_query($comments_per_page));
drupal_goto(url("node/view/". $edit["nid"], "mode=$mode&order=$order&threshold=$threshold&comments_per_page=$comments_per_page"));
//drupal_goto(url(comment_referer_load(), "mode=$mode&order=$order&threshold=$threshold&comments_per_page=$comments_per_page"));
drupal_goto(url(comment_referer_load()));
break;
}
}
......@@ -1326,7 +1345,7 @@ function comment($comment, $links = 0) {
}
function comment_folded($comment) {
print "<div class=\"comment-folded\"><span class=\"subject\">". l($comment->subject, "node/view/$comment->nid/$comment->cid#$comment->cid") ."</span> <span class=\"credit\">". t("by") . " " . format_name($comment) ."</span></div>";
print "<div class=\"comment-folded\"><span class=\"subject\">". l($comment->subject, comment_referer_load()."/$comment->cid#$comment->cid") ."</span> <span class=\"credit\">". t("by") . " " . format_name($comment) ."</span></div>";
}
function comment_flat_collapsed($comment, $threshold) {
......
......@@ -141,6 +141,17 @@ function comment_access($op, $comment) {
}
}