From 6275348098baa21523f31d8c228cd7fa0dd64b2d Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 24 Mar 2001 16:36:13 +0000 Subject: - the "faq module" and the "documentation module" are going to be bundled into a much more powerful and easier to maintain "book module": each "page" in the big "drop.org/drupal book" is a node and everyone with a user account can suggest new pages or updates of existing pages. --- modules/book.module | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 modules/book.module (limited to 'modules/book.module') diff --git a/modules/book.module b/modules/book.module new file mode 100644 index 000000000..7101e0f72 --- /dev/null +++ b/modules/book.module @@ -0,0 +1,189 @@ + "book_find", + "page" => "book_page", + "admin" => "book_admin"); + +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")); + $prev = 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 DESC")); + } + + $output .= "
"; + $output .= "\n"; + $output .= " \n"; + $output .= " \n"; + $output .= "
". ($prev ? "nid\">". t("previous") ."" : t("previous")) ."index". ($next ? "nid\">". t("next") ."" : t("next")) ."
". ($prev ? "". check_output($prev->title) ."" : "") ."". ($node->parent ? "parent\">". t("up") ."" : t("up")) ."". ($next ? "". check_output($next->title) ."" : "") ."
\n"; + + return $output; + +} + +function book_update($node) { + return ($node->nid ? "nid\">". t("update") ."" : t("update")); +} + +function theme_book($node, $small = 0) { + global $theme; + + if ($small) { + print "nid\">". check_output($node->title) .""; + } + 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)); + } +} + +function book_view($node) { + global $op; + + if ($op == "view") { + theme_book($node); + } + else { + global $theme; + $theme->header(); + theme_book($node); + $theme->footer(); + } +} + +function book_find($keys) { + global $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"); + 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)); + } + return $find; +} + +function book_search() { + global $keys, $mod; + print search_form($keys); + print search_data($keys, $mod); +} + +function book_form($edit = array()) { + global $allowed_html, $PHP_SELF, $theme, $user; + + $output .= "
\n"; + + $output .= "". t("Author") .":
\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"; + + $output .= "". t("Subject") .":
\n"; + $output .= "

\n"; + + $output .= "". t("Content") .":
\n"; + $output .= "
\n"; + $output .= "". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".

\n"; + + if (user_access($user, "book")) { + $status = array(2 => "posted", 1 => "queued", 0 => "dumped"); + + $output .= "". t("Weight") .":
\n"; + for ($count = 0; $count < 25; $count++) $weight .= ""; + $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"; + } + + if (!$edit) { + $output .= "\n"; + } + else if (!$edit[title]) { + $output .= "". t("Warning: you did not supply a title.") ."

\n"; + $output .= "\n"; + } + else { + $output .= "\n"; + $output .= "\n"; + } + + $output .= "\n"; + $output .= "

\n"; + + return $output; +} + +function book_save($edit) { + node_save(array_merge($edit, array(type => "book"))); +} + +function book_delete($id) { + node_del_object("nid", $id); +} + +function book_overview($parent = "", $offset = "") { + global $PHP_SELF; + + $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"); + + $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)"; + $output .= book_overview($node->nid, "$offset$number."); + } + $output .= "

"; + return $output; +} + +function book_admin() { + global $op, $id, $edit; + + print "add new entry | search documenation | overview
\n"; + + switch ($op) { + case "add": + print book_form(); + break; + case "delete": + print book_delete($id); + print book_overview(); + break; + case "edit": + print book_form(node_get_array(nid, $id)); + break; + case "search": + book_search(); + break; + case t("Preview"): + print book_form($edit); + break; + case t("Submit"): + book_save($edit); + print book_overview(); + break; + default: + print book_overview(); + } +} + +function book_page($id = 0) { + global $theme; + book_view(node_get_object("nid", $nid)); +} + +?> -- cgit v1.2.3