From 1f79863053350f1a7d6cb654ac615123bc3b5133 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 25 Mar 2001 10:57:01 +0000 Subject: - large commit of everything else that has been queued in my backlog: it's not 100% stable yet --- modules/book.module | 133 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 45 deletions(-) (limited to 'modules/book.module') diff --git a/modules/book.module b/modules/book.module index 7101e0f72..66bedfec9 100644 --- a/modules/book.module +++ b/modules/book.module @@ -2,8 +2,21 @@ $module = array("find" => "book_find", "page" => "book_page", + "user" => "book_user", "admin" => "book_admin"); +class Book { + function Book($nid, $userid, $title, $body, $parent, $weight, $timestamp) { + $this->nid = $nid; + $this->userid = $userid; + $this->title = $title; + $this->body = $body; + $this->parent = $parent; + $this->weight = $weight; + $this->timestamp = $timestamp; + } +} + function book_navigation($node) { if ($node->nid) { $next = db_fetch_object(db_query("SELECT n.nid, n.title FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE b.parent = '$node->parent' AND b.weight > $node->weight ORDER BY b.weight ASC")); @@ -17,49 +30,39 @@ function book_navigation($node) { $output .= "\n"; return $output; - } -function book_update($node) { - return ($node->nid ? "nid\">". t("update") ."" : t("update")); -} - -function theme_book($node, $small = 0) { +function theme_book($node) { global $theme; - if ($small) { - print "nid\">". check_output($node->title) .""; + if ($node->title) { + $output .= "\n"; + $output .= " \n"; + $output .= "
". check_output($node->title) ."". ($node->body ? "
Last updated by ". format_username($node->userid) ." on ". format_date($node->timestamp) ." " : "") ."
". node_info($node) ."
\n"; } - else { - if ($node->title && $node->body) { - $output .= "\n"; - $output .= " \n"; - $output .= "
". check_output($node->title) ."
Last updated by ". format_username($node->userid) ." on ". format_date($node->timestamp) ."
". node_info($node) ."
\n"; - $output .= "

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

"; - } - - $theme->box(t("Documentation book"), $output ."". book_overview($node->nid) ."". book_navigation($node)); + if ($node->body) { + $output .= "

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

"; } -} -function book_view($node) { - global $op; + $theme->box(t("Documentation book"), $output ."". book_overview($node->nid) ."". book_navigation($node)); +} - if ($op == "view") { - theme_book($node); - } - else { +function book_view($node, $page = 1) { + if ($page) { global $theme; $theme->header(); theme_book($node); $theme->footer(); } + else { + theme_book($node); + } } function book_find($keys) { - global $user; + global $status, $user; $find = array(); - $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = 2 AND n.title LIKE '%". check_input($keys) ."%' ORDER BY n.timestamp DESC LIMIT 20"); + $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = '$status[posted]' AND n.title LIKE '%". check_input($keys) ."%' ORDER BY n.timestamp DESC LIMIT 20"); while ($node = db_fetch_object($result)) { array_push($find, array("title" => check_output($node->title), "link" => (user_access($user, "book") ? "admin.php?mod=book&op=edit&id=$node->nid" : "node.php?id=$node->nid"), "user" => $node->userid, "date" => $node->timestamp)); } @@ -73,19 +76,28 @@ function book_search() { } function book_form($edit = array()) { - global $allowed_html, $PHP_SELF, $theme, $user; + global $allowed_html, $PHP_SELF, $REQUEST_URI, $status, $theme, $user; - $output .= "
\n"; + $output .= "\n"; $output .= "". t("Author") .":
\n"; + $output .= "\n"; $output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."

\n"; - $output .= "". t("Category") .":
\n"; - $result = db_query("SELECT nid, title FROM nodes WHERE type = 'book'"); - while ($node = db_fetch_object($result)) $options .= ""; - if (user_access($user, "book")) $options .= ""; - $output .= "
\n"; - $output .= "". t("The parent subject or category the book belongs in.") ."

\n"; + if ($edit[pid]) { + $node = node_get_object("nid", $edit[pid]); + $output .= "". t("Parent") .":
\n"; + $output .= "id\">". check_output($node->title) ."

\n"; + $output .= "". t("The parent subject or category the new page belongs in.") ."

\n"; + } + else { + $output .= "". t("Parent") .":
\n"; + $result = db_query("SELECT nid, title FROM nodes WHERE type = 'book' AND status = '$status[posted]'"); + while ($node = db_fetch_object($result)) $options2 .= ""; + if (user_access($user, "book")) $options2 .= ""; + $output .= "
\n"; + $output .= "". t("The parent subject or category the new page belongs in.") ."

\n"; + } $output .= "". t("Subject") .":
\n"; $output .= "

\n"; @@ -94,17 +106,23 @@ function book_form($edit = array()) { $output .= "
\n"; $output .= "". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".

\n"; + if ($edit[pid]) { + $output .= "". t("Log message") .":
\n"; + $output .= "
\n"; + $output .= "". t("A brief explanation of your update.") ."

\n"; + } + if (user_access($user, "book")) { - $status = array(2 => "posted", 1 => "queued", 0 => "dumped"); + $status = array_intersect($status, array(0, 2, 3)); $output .= "". t("Weight") .":
\n"; - for ($count = 0; $count < 25; $count++) $weight .= ""; - $output .= "
\n"; + for ($count = 0; $count < 25; $count++) $options3 .= ""; + $output .= "
\n"; $output .= "". t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top.") ."

\n"; $output .= "". t("Status") .":
\n"; - foreach ($status as $key=>$value) $status .= ""; - $output .= "

\n"; + foreach ($status as $value=>$key) $options4 .= ""; + $output .= "

\n"; } if (!$edit) { @@ -119,14 +137,17 @@ function book_form($edit = array()) { $output .= "\n"; } + $output .= "\n"; $output .= "\n"; + $output .= "

\n"; return $output; } function book_save($edit) { - node_save(array_merge($edit, array(type => "book"))); + $node = ($edit[nid] ? node_get_object("nid", $edit[nid]) : node_get_object("title", $edit[title])); + node_save(array_diff(array_merge($edit, array(nid => $node->nid, type => "book")), array(userid => $edit[userid]))); } function book_delete($id) { @@ -134,16 +155,16 @@ function book_delete($id) { } function book_overview($parent = "", $offset = "") { - global $PHP_SELF; + global $PHP_SELF, $status; - $result = db_query("SELECT n.*, b.* FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE n.type = 'book' AND b.parent = '$parent' ORDER BY b.weight"); + $result = db_query("SELECT n.*, b.* FROM nodes n LEFT JOIN book b ON n.nid = b.node WHERE n.type = 'book' AND n.status = '$status[posted]' AND b.parent = '$parent' ORDER BY b.weight"); $output .= "
"; while ($node = db_fetch_object($result)) { $number++; if ($offset) $output .= "
$offset$number. nid\">". check_output($node->title) ."\n"; else $output .= "

$number. nid\">". check_output($node->title) ."\n"; - if ($PHP_SELF == "/admin.php") $output .= " (nid\">edit | nid\">delete)"; + if ($PHP_SELF == "/admin.php") $output .= " (weight: $node->weight, status: $node->status) (nid\">edit, nid\">delete)"; $output .= book_overview($node->nid, "$offset$number."); } $output .= "

"; @@ -151,9 +172,9 @@ function book_overview($parent = "", $offset = "") { } function book_admin() { - global $op, $id, $edit; + global $op, $id, $edit, $user; - print "add new entry | search documenation | overview
\n"; + print "add new page | search book | overview
\n"; switch ($op) { case "add": @@ -170,6 +191,7 @@ function book_admin() { book_search(); break; case t("Preview"): + book_view(new Book(($edit[nid] ? $edit[nid] : -1), ($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0); print book_form($edit); break; case t("Submit"): @@ -186,4 +208,25 @@ function book_page($id = 0) { book_view(node_get_object("nid", $nid)); } +function book_user() { + global $edit, $id, $op, $theme, $user; + + switch($op) { + case "update": + $node = node_get_object("nid", $id); + $theme->box("Update a book page", book_form(array(nid => -1, pid => $id, title => $node->title, body => $node->body, parent => $node->parent))); + break; + case t("Preview"): + book_view(new Book(($edit[nid] ? $edit[nid] : -1), $user->userid, $edit[title], $edit[body], $edit[parent], $edit[weight], ($edit[timestamp] ? $edit[timestamp] : time())), 0); + $theme->box("Submit a book page", book_form($edit)); + break; + case t("Submit"): + book_save($edit); + $theme->box(t("Submit a book page"), t("Thank you for your submission.")); + break; + default: + $theme->box("Submit a book page", book_form()); + } +} + ?> -- cgit v1.2.3