From 32ff43a48c4cfae2c794dafda852fff0dc7a589b Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 31 Mar 2001 19:10:53 +0000 Subject: - simplified book.module so that it is easier to maintain (yet a bit less sexy) - the entire module is only 258 lines. --- modules/book.module | 49 ++++++++++++++++++++---------------------------- modules/book/book.module | 49 ++++++++++++++++++++---------------------------- 2 files changed, 40 insertions(+), 58 deletions(-) (limited to 'modules') diff --git a/modules/book.module b/modules/book.module index 1b975695b..6a094870a 100644 --- a/modules/book.module +++ b/modules/book.module @@ -44,7 +44,7 @@ function theme_book($node) { $output .= "

". check_output($node->body, 1) ."

"; } - $theme->box(t("Handbook"), $output ."". book_overview($node->nid) ."". book_navigation($node)); + $theme->box(t("Handbook"), $output ."". book_tree($node->nid) ."". book_navigation($node)); } function book_view($node, $page = 1) { @@ -75,12 +75,13 @@ function book_search() { print search_data($keys, $mod); } -function book_toc($parent = 0, $offset = 0, $toc = array()) { +function book_toc($parent = 0, $offset = "", $toc = array()) { global $status; $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); while ($node = db_fetch_object($result)) { - $toc[$node->nid] = ($offset ? $offset : "") ."". ++$number .". $node->title"; - $toc = book_toc($node->nid, ($offset ? $offset : "") ."$number.", $toc); + $toc[$node->nid] = "$offset $node->title"; + if ($node->pid) $toc = book_toc($node->pid, "$offset-", $toc); + $toc = book_toc($node->nid, "$offset-", $toc); } return $toc; } @@ -163,33 +164,23 @@ function book_delete($id) { return ($node = node_del("nid", $id) ? "book page has been deleted" : "failed to delete book page: change status to 'dumped' first"); } -function book_overview($parent = "", $offset = "") { +function book_tree($parent = "") { global $PHP_SELF, $status; - $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND (n.status = '$status[posted]' OR n.status = '$status[expired]') AND b.parent = '$parent' ORDER BY b.weight"); - - $output .= "
"; + $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); - $nodes = array(); + $output .= "
"; + $output .= ""; return $output; } -function book_history() { +function book_list() { global $status; $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status != '$status[expired]' ORDER BY n.timestamp DESC"); @@ -206,7 +197,7 @@ function book_history() { function book_admin() { global $op, $id, $edit, $user; - print "add new page | history | search book | overview
\n"; + print "add new page | search book | list overview | tree overview
\n"; switch ($op) { case "add": @@ -214,10 +205,10 @@ function book_admin() { break; case "delete": print book_delete($id); - print book_overview(); + print book_tree(); break; - case "history": - print book_history(); + case "list": + print book_list(); break; case "edit": print book_form(node_get_array(nid, $id)); @@ -231,10 +222,10 @@ function book_admin() { break; case t("Submit"): book_save($edit); - print book_overview(); + print book_tree(); break; default: - print book_overview(); + print book_tree(); } } diff --git a/modules/book/book.module b/modules/book/book.module index 1b975695b..6a094870a 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -44,7 +44,7 @@ function theme_book($node) { $output .= "

". check_output($node->body, 1) ."

"; } - $theme->box(t("Handbook"), $output ."". book_overview($node->nid) ."". book_navigation($node)); + $theme->box(t("Handbook"), $output ."". book_tree($node->nid) ."". book_navigation($node)); } function book_view($node, $page = 1) { @@ -75,12 +75,13 @@ function book_search() { print search_data($keys, $mod); } -function book_toc($parent = 0, $offset = 0, $toc = array()) { +function book_toc($parent = 0, $offset = "", $toc = array()) { global $status; $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); while ($node = db_fetch_object($result)) { - $toc[$node->nid] = ($offset ? $offset : "") ."". ++$number .". $node->title"; - $toc = book_toc($node->nid, ($offset ? $offset : "") ."$number.", $toc); + $toc[$node->nid] = "$offset $node->title"; + if ($node->pid) $toc = book_toc($node->pid, "$offset-", $toc); + $toc = book_toc($node->nid, "$offset-", $toc); } return $toc; } @@ -163,33 +164,23 @@ function book_delete($id) { return ($node = node_del("nid", $id) ? "book page has been deleted" : "failed to delete book page: change status to 'dumped' first"); } -function book_overview($parent = "", $offset = "") { +function book_tree($parent = "") { global $PHP_SELF, $status; - $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND (n.status = '$status[posted]' OR n.status = '$status[expired]') AND b.parent = '$parent' ORDER BY b.weight"); - - $output .= "
"; + $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); - $nodes = array(); + $output .= "
"; + $output .= ""; return $output; } -function book_history() { +function book_list() { global $status; $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE n.type = 'book' AND n.status != '$status[expired]' ORDER BY n.timestamp DESC"); @@ -206,7 +197,7 @@ function book_history() { function book_admin() { global $op, $id, $edit, $user; - print "add new page | history | search book | overview
\n"; + print "add new page | search book | list overview | tree overview
\n"; switch ($op) { case "add": @@ -214,10 +205,10 @@ function book_admin() { break; case "delete": print book_delete($id); - print book_overview(); + print book_tree(); break; - case "history": - print book_history(); + case "list": + print book_list(); break; case "edit": print book_form(node_get_array(nid, $id)); @@ -231,10 +222,10 @@ function book_admin() { break; case t("Submit"): book_save($edit); - print book_overview(); + print book_tree(); break; default: - print book_overview(); + print book_tree(); } } -- cgit v1.2.3