diff options
Diffstat (limited to 'modules/book.module')
-rw-r--r-- | modules/book.module | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/modules/book.module b/modules/book.module index 0365e9833..b8d3f9c81 100644 --- a/modules/book.module +++ b/modules/book.module @@ -10,7 +10,19 @@ class Book { } function book_perm() { - return array("edit book"); + return array("administer book"); +} + +function book_link($type) { + if ($type == "admin" && user_access("administer book")) { + $links[] = "<a href=\"admin.php?mod=book\">". t("collaborative book") ."</a>"; + } + + if ($type == "page" && user_access("access content")) { + $links[] = "<a href=\"module.php?mod=book\">". t("collaborative book") ."</a>"; + } + + return $links ? $links : array(); } function book_status() { @@ -70,10 +82,10 @@ function book_view($node, $main = 0) { } function book_search($keys) { - global $status, $user; + global $status; $result = db_query("SELECT n.*, u.userid FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid LEFT JOIN users u ON n.author = u.id WHERE n.type = 'book' AND n.status = '$status[posted]' AND (n.title LIKE '%". check_input($keys) ."%' OR b.body LIKE '%". check_input($keys) ."%') ORDER BY n.timestamp DESC LIMIT 20"); while ($node = db_fetch_object($result)) { - $find[$i++] = array("title" => check_output($node->title), "link" => (user_access($user, "add and edit nodes") ? "admin.php?mod=node&type=book&op=edit&id=$node->nid" : "node.php?id=$node->nid"), "user" => $node->userid, "date" => $node->timestamp); + $find[$i++] = array("title" => check_output($node->title), "link" => (user_access("administer nodes") ? "admin.php?mod=node&type=book&op=edit&id=$node->nid" : "node.php?id=$node->nid"), "user" => $node->userid, "date" => $node->timestamp); } return $find; } @@ -90,13 +102,13 @@ function book_parent_query($parent) { } function book_toc($parent = "", $indent = "", $toc = array()) { - global $status, $user; + global $status; // select all child nodes: $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 ". book_parent_query($parent) ." ORDER BY b.weight"); // add root node: - if (user_access($user, "add and edit nodes")) { + if (user_access("administer nodes")) { $toc[0] = "<root>"; } @@ -125,7 +137,7 @@ function book_form($edit = array()) { $form .= form_textarea(t("Content"), "body", $edit[body], 70, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", ""))); $form .= form_textarea(t("Log message"), "log", $edit[log], 70, 5, t("An explanation of the additions or updates being made to help the group understand your motivations.")); - if (user_access($user, "add and edit nodes")) { + if (user_access("administer nodes")) { $form .= form_select(t("Weight"), "weight", $edit[weight], array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top.")); } @@ -155,7 +167,7 @@ function book_save($edit) { if (!$edit[nid]) { node_save($edit, array(author => $user->id, body, comment => variable_get("book_comment", 0), log, moderate => variable_get("book_moderate", ""), parent, pid, promote => variable_get("book_promote", 0), score => 0, status => variable_get("book_status", $status[queued]), timestamp => time(), title, type => "book", votes => 0, weight)); } - else if (user_access($user, "add and edit nodes")) { + else if (user_access("administer nodes")) { node_save($edit, array(body, log, parent, title, type => "book", weight)); } } @@ -207,8 +219,7 @@ function book_tree($parent = "", $depth = 0) { } function book_admin() { - global $user; - if (user_access($user, "edit book")) { + if (user_access("administer book")) { print book_tree(); } else { @@ -217,9 +228,9 @@ function book_admin() { } function book_page() { - global $user, $status, $theme; + global $status, $theme; - if (user_access($user, "view content")) { + if (user_access("access content")) { $result = db_query("SELECT n.*, b.* FROM node n LEFT JOIN book b ON n.nid = b.nid AND n.lid = b.lid WHERE b.parent = 0 AND n.status = $status[posted] ORDER BY b.weight"); while ($node = db_fetch_object($result)) { |