diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-11-03 18:38:30 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-11-03 18:38:30 +0000 |
commit | a2e6910902bfb1263e1b6363e2c29ede68f89918 (patch) | |
tree | baa89d2d8bcd814f73d5108466024bd13ea7159d | |
parent | 4d8b485fad960ea6551111e58f8c59df053b4456 (diff) | |
download | brdo-a2e6910902bfb1263e1b6363e2c29ede68f89918.tar.gz brdo-a2e6910902bfb1263e1b6363e2c29ede68f89918.tar.bz2 |
- Made the node forms support "help texts": it is not possible to configure
Drupal to display submission guidelines, or any other kind of explanation
such as "NO TEST POSTS", for example.
- Added node versioning: it is possible to create revisions, to view old
revisions and to roll-back to older revisions. You'll need to apply a
SQL update.
I'm going to work on the book module now, so I might be changing a few
things to enable collaborative, moderated revisions - but feel free to
send some first feedback, if you like.
- Added some configuration options which can be used to set the minimum
number of words a blog/story should consist of. Hopefully this will
be usefull to stop the (almost empty) test blogs.
- Various improvements:
+ Fine-tuned new node permission system.
+ Fine-tuned the functions in node.inc.
+ Fine-tuned some forms.
+ XHTML-ified some code.
-rw-r--r-- | includes/comment.inc | 6 | ||||
-rw-r--r-- | includes/common.inc | 6 | ||||
-rw-r--r-- | includes/node.inc | 70 | ||||
-rw-r--r-- | modules/blog.module | 52 | ||||
-rw-r--r-- | modules/blog/blog.module | 52 | ||||
-rw-r--r-- | modules/book.module | 9 | ||||
-rw-r--r-- | modules/book/book.module | 9 | ||||
-rw-r--r-- | modules/forum.module | 17 | ||||
-rw-r--r-- | modules/forum/forum.module | 17 | ||||
-rw-r--r-- | modules/node.module | 225 | ||||
-rw-r--r-- | modules/node/node.module | 225 | ||||
-rw-r--r-- | modules/page.module | 22 | ||||
-rw-r--r-- | modules/page/page.module | 22 | ||||
-rw-r--r-- | modules/story.module | 50 | ||||
-rw-r--r-- | modules/story/story.module | 50 | ||||
-rw-r--r-- | node.php | 10 | ||||
-rw-r--r-- | updates/3.00-to-x.xx.mysql | 7 |
17 files changed, 598 insertions, 251 deletions
diff --git a/includes/comment.inc b/includes/comment.inc index ce0f20404..5d5a3e98c 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -1,12 +1,6 @@ <?php // $Id$ -// Security check: -if (strstr($id, " ") || strstr($pid, " ") || strstr($lid, " ") || strstr($mode, " ") || strstr($order, " ") || strstr($threshold, " ")) { - watchdog("error", "comment: attempt to provide malicious input through URI"); - exit(); -} - $cmodes = array(1 => "List - min", 2 => "List - max", 3 => "Threaded - min", 4 => "Threaded - max"); $corder = array(1 => "Date - new", 2 => "Date - old", 3 => "Rate - high", 4 => "Rate - low"); diff --git a/includes/common.inc b/includes/common.inc index 04c9b8a42..4f8dcaca7 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -279,7 +279,11 @@ function form($form, $method = "post", $action = 0, $options = 0) { } function form_item($title, $value, $description = 0) { - return ($description) ? "<b>$title:</b><br />$value<br /><small><i>$description</i></small><p />\n" : "<b>$title:</b><br />$value<p />\n"; + return ($title ? "<b>$title:</b><br />" : "") . $value . ($description ? "<br /><small><i>$description</i></small>" : "") ."<p />\n"; +} + +function form_checkbox($title, $name, $value, $description = 0) { + return form_item(0, "<input type=\"checkbox\" name=\"edit[$name]\" ". ($value ? " checked=\"checked\"" : "") ." /> $title", $description); } function form_textfield($title, $name, $value, $size, $maxlength, $description = 0) { diff --git a/includes/node.inc b/includes/node.inc index 01f5c17a0..ca914a490 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -84,15 +84,33 @@ function node_array($node) { function node_load($conditions) { - // prepare query: + /* + ** Turn the conditions into a query: + */ + foreach ($conditions as $key => $value) { $cond[] = "n.". check_query($key) ." = '". check_query($value) ."'"; } - // retrieve the node: + /* + ** Retrieve the node: + */ + $node = db_fetch_object(db_query("SELECT n.*, u.uid, u.name FROM node n LEFT JOIN users u ON u.uid = n.uid LEFT JOIN comments c ON c.lid = n.nid WHERE ". implode(" AND ", $cond))); - // call the node specific callback (if any): + /* + ** Unserialize the revisions field: + */ + + if ($node->revisions) { + $node->revisions = unserialize($node->revisions); + } + + /* + ** Call the node specific callback (if any) and piggy-back to + ** results to the node: + */ + if ($extra = module_invoke($node->type, "load", $node)) { foreach ($extra as $key => $value) { $node->$key = $value; @@ -105,7 +123,7 @@ function node_load($conditions) { function node_save($node, $filter) { - $fields = array("nid", "uid", "type", "title", "teaser", "body", "status", "comment", "promote", "moderate", "created", "changed"); + $fields = array("nid", "uid", "type", "title", "teaser", "body", "revisions", "status", "comment", "promote", "moderate", "created", "changed"); foreach ($filter as $key => $value) { /* @@ -115,16 +133,31 @@ function node_save($node, $filter) { */ if (is_numeric($key)) { - $edit->$value = $node->$value; + if (isset($node->$value)) { + // The above check is mandatory. + $edit->$value = check_query($node->$value); + } } else { - $edit->$key = $value; + if (isset($value)) { + // The above check is mandatory. + $edit->$key = check_query($value); + } } } $node = $edit; + /* + ** Serialize the revisions field: + */ + + if ($node->revisions) { + $node->revisions = serialize($node->revisions); + } + if (empty($node->nid)) { + /* ** Verify a user's submission rate and avoid duplicate nodes being ** inserted: @@ -143,8 +176,8 @@ function node_save($node, $filter) { // prepare the query: foreach ($node as $key => $value) { if (in_array($key, $fields)) { - $k[] = check_query($key); - $v[] = "'". check_query($value) ."'"; + $k[] = $key; + $v[] = "'$value'"; } } @@ -168,12 +201,12 @@ function node_save($node, $filter) { // prepare the query: foreach ($node as $key => $value) { if (in_array($key, $fields)) { - $q[] = check_query($key) ." = '". check_query($value) ."'"; + $q[] = "$key = '$value'"; } } // update the node in the database: - db_query("UPDATE node SET ". implode(", ", $q) ." WHERE nid = '". check_query($node->nid) ."'"); + db_query("UPDATE node SET ". implode(", ", $q) ." WHERE nid = '$node->nid'"); // call the node specific callback (if any): module_invoke($node->type, "update", $node); @@ -189,23 +222,6 @@ function node_save($node, $filter) { } -function node_delete($node) { - - if (is_array($node)) { - $node = node_object($node); - } - - // delete the node and its comments: - db_query("DELETE FROM node WHERE nid = '$node->nid'"); - db_query("DELETE FROM comments WHERE lid = '$node->nid'"); - db_query("DELETE FROM moderate WHERE nid = '$node->nid'"); - - // call the node specific callback (if any): - module_invoke($node->type, "delete", &$node); - - watchdog("special", "node: deleted '$node->title'"); -} - function node_view($node, $main = 0) { global $theme; diff --git a/modules/blog.module b/modules/blog.module index 397fb56cf..d4bded863 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -1,6 +1,14 @@ <?php // $Id$ +function blog_conf_options() { + $output .= form_textarea("Explanation or submission guidelines", "blog_help", variable_get("blog_help", ""), 55, 4, "This text will be displayed at the top of the blog submission form. Useful for helping or instructing your users."); + $output .= form_select(t("Minimum number of words in a node"), "minimum_blog_size", variable_get("minimum_node_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a personal blog entry should consist of. This can be useful to rule out submissions that do not meet the site's standards, such as short test post.")); + + return $output; + +} + function blog_node($field) { global $user; @@ -13,7 +21,7 @@ function blog_access($op, $node) { global $user; if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } if ($op == "create") { @@ -21,11 +29,11 @@ function blog_access($op, $node) { } if ($op == "update") { - return user_access("administer nodes") || ($user->uid == $node->uid); + return ($user->uid == $node->uid); } if ($op == "delete") { - return user_access("administer nodes") || ($user->uid == $node->uid); + return ($user->uid == $node->uid); } } @@ -36,10 +44,6 @@ function blog_help() { <?php } -function blog_perm() { - return array("administer blogs", "access blogs", "post blogs"); -} - function blog_feed_user($uid = 0, $date = 0) { global $user; @@ -122,7 +126,7 @@ function blog_page_user($uid = 0, $date = 0) { $links[] = "<a href=\"module.php?mod=node&op=edit&id=$blog->nid\">". t("edit") ."</a>"; } - if ($user->uid && user_access("post blogs")) { + if ($user->uid) { $links[] = "<a href=\"module.php?mod=node&op=add&type=blog&nid=$blog->nid\">". t("blog it") ."</a>"; } @@ -159,7 +163,7 @@ function blog_page_last() { $links[] = "<a href=\"module.php?mod=node&op=edit&id=$blog->nid\">". t("edit") ."</a>"; } - if ($user->uid && user_access("post blogs")) { + if ($user->uid) { $links[] = "<a href=\"module.php?mod=node&op=add&type=blog&nid=$blog->nid\">". t("blog it") ."</a>"; } @@ -178,15 +182,33 @@ function blog_page_last() { $theme->box(t("User blogs"), $output, "main"); } -function blog_form($node, $error) { +function blog_form($node, $help, $error) { global $nid, $iid; - if ($node->body) { - if (count(explode(" ", $node->body)) < variable_get("minimum_node_size", 0)) { + + if (isset($node->body)) { + + /* + ** Validate the size of the blog: + */ + + if (count(explode(" ", $node->body)) < variable_get("minimum_blog_size", 0)) { $error["body"] = "<div style=\"color: red;\">". t("The body of your blog is too short.") ."</div>"; } } else { + + /* + ** Carry out some explanation or submission guidelines: + */ + + $help = variable_get("blog_help", ""); + + /* + ** If the user clicked a "blog it" link, we load the data from the + ** database and quote it in the blog: + */ + if ($nid && $blog = node_load(array("nid" => $nid))) { $node->body = "<i>". $blog->body ."</i> [<a href=\"module.php?mod=blog&id=$blog->uid&date=$blog->created\">$blog->name</a>]"; } @@ -215,7 +237,7 @@ function blog_save($node) { function blog_page() { global $theme, $id, $op, $date; - if (user_access("access blogs")) { + if (user_access("access content")) { switch ($op) { case "feed": if ($id) { @@ -247,11 +269,11 @@ function blog_page() { function blog_link($type, $node = 0) { global $user; - if ($type == "page" && user_access("access blogs")) { + if ($type == "page" && user_access("access content")) { $links[] = "<a href=\"module.php?mod=blog\">". t("user blogs") ."</a>"; } - if ($type == "menu" && user_access("post blogs")) { + if ($type == "menu") { $links[] = "<a href=\"module.php?mod=node&op=add&type=blog\">". t("add blog entry") ."</a>"; $links[] = "<a href=\"module.php?mod=blog&op=view&id=$user->uid\">". t("view your blog") ."</a>"; } diff --git a/modules/blog/blog.module b/modules/blog/blog.module index 397fb56cf..d4bded863 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -1,6 +1,14 @@ <?php // $Id$ +function blog_conf_options() { + $output .= form_textarea("Explanation or submission guidelines", "blog_help", variable_get("blog_help", ""), 55, 4, "This text will be displayed at the top of the blog submission form. Useful for helping or instructing your users."); + $output .= form_select(t("Minimum number of words in a node"), "minimum_blog_size", variable_get("minimum_node_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a personal blog entry should consist of. This can be useful to rule out submissions that do not meet the site's standards, such as short test post.")); + + return $output; + +} + function blog_node($field) { global $user; @@ -13,7 +21,7 @@ function blog_access($op, $node) { global $user; if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } if ($op == "create") { @@ -21,11 +29,11 @@ function blog_access($op, $node) { } if ($op == "update") { - return user_access("administer nodes") || ($user->uid == $node->uid); + return ($user->uid == $node->uid); } if ($op == "delete") { - return user_access("administer nodes") || ($user->uid == $node->uid); + return ($user->uid == $node->uid); } } @@ -36,10 +44,6 @@ function blog_help() { <?php } -function blog_perm() { - return array("administer blogs", "access blogs", "post blogs"); -} - function blog_feed_user($uid = 0, $date = 0) { global $user; @@ -122,7 +126,7 @@ function blog_page_user($uid = 0, $date = 0) { $links[] = "<a href=\"module.php?mod=node&op=edit&id=$blog->nid\">". t("edit") ."</a>"; } - if ($user->uid && user_access("post blogs")) { + if ($user->uid) { $links[] = "<a href=\"module.php?mod=node&op=add&type=blog&nid=$blog->nid\">". t("blog it") ."</a>"; } @@ -159,7 +163,7 @@ function blog_page_last() { $links[] = "<a href=\"module.php?mod=node&op=edit&id=$blog->nid\">". t("edit") ."</a>"; } - if ($user->uid && user_access("post blogs")) { + if ($user->uid) { $links[] = "<a href=\"module.php?mod=node&op=add&type=blog&nid=$blog->nid\">". t("blog it") ."</a>"; } @@ -178,15 +182,33 @@ function blog_page_last() { $theme->box(t("User blogs"), $output, "main"); } -function blog_form($node, $error) { +function blog_form($node, $help, $error) { global $nid, $iid; - if ($node->body) { - if (count(explode(" ", $node->body)) < variable_get("minimum_node_size", 0)) { + + if (isset($node->body)) { + + /* + ** Validate the size of the blog: + */ + + if (count(explode(" ", $node->body)) < variable_get("minimum_blog_size", 0)) { $error["body"] = "<div style=\"color: red;\">". t("The body of your blog is too short.") ."</div>"; } } else { + + /* + ** Carry out some explanation or submission guidelines: + */ + + $help = variable_get("blog_help", ""); + + /* + ** If the user clicked a "blog it" link, we load the data from the + ** database and quote it in the blog: + */ + if ($nid && $blog = node_load(array("nid" => $nid))) { $node->body = "<i>". $blog->body ."</i> [<a href=\"module.php?mod=blog&id=$blog->uid&date=$blog->created\">$blog->name</a>]"; } @@ -215,7 +237,7 @@ function blog_save($node) { function blog_page() { global $theme, $id, $op, $date; - if (user_access("access blogs")) { + if (user_access("access content")) { switch ($op) { case "feed": if ($id) { @@ -247,11 +269,11 @@ function blog_page() { function blog_link($type, $node = 0) { global $user; - if ($type == "page" && user_access("access blogs")) { + if ($type == "page" && user_access("access content")) { $links[] = "<a href=\"module.php?mod=blog\">". t("user blogs") ."</a>"; } - if ($type == "menu" && user_access("post blogs")) { + if ($type == "menu") { $links[] = "<a href=\"module.php?mod=node&op=add&type=blog\">". t("add blog entry") ."</a>"; $links[] = "<a href=\"module.php?mod=blog&op=view&id=$user->uid\">". t("view your blog") ."</a>"; } diff --git a/modules/book.module b/modules/book.module index 3b88c3376..03a239ae2 100644 --- a/modules/book.module +++ b/modules/book.module @@ -10,10 +10,9 @@ function book_node($field) { } function book_access($op, $node) { - global $user; if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } if ($op == "create") { @@ -24,10 +23,6 @@ function book_access($op, $node) { return 1; } - if ($op == "delete") { - return user_access("adminster nodes"); - } - } function book_link($type) { @@ -155,7 +150,7 @@ function book_toc($parent = "", $indent = "", $toc = array()) { return $toc; } -function book_form($node, $error) { +function book_form($node, $help, $error) { global $user; $output .= form_select(t("Parent"), "parent", $node->parent, book_toc(), t("The parent subject or category the page belongs in.")); diff --git a/modules/book/book.module b/modules/book/book.module index 3b88c3376..03a239ae2 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -10,10 +10,9 @@ function book_node($field) { } function book_access($op, $node) { - global $user; if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } if ($op == "create") { @@ -24,10 +23,6 @@ function book_access($op, $node) { return 1; } - if ($op == "delete") { - return user_access("adminster nodes"); - } - } function book_link($type) { @@ -155,7 +150,7 @@ function book_toc($parent = "", $indent = "", $toc = array()) { return $toc; } -function book_form($node, $error) { +function book_form($node, $help, $error) { global $user; $output .= form_select(t("Parent"), "parent", $node->parent, book_toc(), t("The parent subject or category the page belongs in.")); diff --git a/modules/forum.module b/modules/forum.module index 1eec66753..e826fb95e 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -8,12 +8,9 @@ function forum_node($field) { } function forum_access($op, $node) { - if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } - - return user_access("adminster nodes"); } function forum_link($type) { @@ -30,15 +27,13 @@ function forum_view($node) { $theme->box(t("Discussion forum"), $output); } -function forum_form($node, $error) { - +function forum_form($node, $help, $error) { $output .= form_textarea("Body", "body", $node->body, 60, 10); return $output; } function forum_save() { - if ($node->nid) { return array(); } @@ -63,13 +58,13 @@ function forum_page() { if (user_access("access content")) { $result = db_query("SELECT nid FROM node WHERE type = 'forum' ORDER BY title"); - $output .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n"; - $output .= " <TR><TH>". t("Forum") ."</TH><TH>". t("Comments") ."</TH><TH>". t("Last comment") ."</TH></TR>"; + $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\">"; + $output .= " <tr><th>". t("Forum") ."</th><th>". t("Comments") ."</th><th>". t("Last comment") ."</th></tr>"; while ($node = db_fetch_object($result)) { $node = node_load(array("nid" => $node->nid)); - $output .= " <TR><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A><BR><SMALL>". check_output($node->body, 1) ."</SMALL></TD><TD ALIGN=\"center\">". forum_num_comments($node->nid) ."</TD><TD ALIGN=\"center\">". forum_last_comment($node->nid) ."</TD></TR>"; + $output .= " <tr><td><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a><br /><small>". check_output($node->body, 1) ."</small></td><td align=\"center\">". forum_num_comments($node->nid) ."</td><td align=\"center\">". forum_last_comment($node->nid) ."</td></tr>"; } - $output .= "</TABLE>\n"; + $output .= "</table>"; $theme->header(); $theme->box(t("Discussion forum"), $output); diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 1eec66753..e826fb95e 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -8,12 +8,9 @@ function forum_node($field) { } function forum_access($op, $node) { - if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } - - return user_access("adminster nodes"); } function forum_link($type) { @@ -30,15 +27,13 @@ function forum_view($node) { $theme->box(t("Discussion forum"), $output); } -function forum_form($node, $error) { - +function forum_form($node, $help, $error) { $output .= form_textarea("Body", "body", $node->body, 60, 10); return $output; } function forum_save() { - if ($node->nid) { return array(); } @@ -63,13 +58,13 @@ function forum_page() { if (user_access("access content")) { $result = db_query("SELECT nid FROM node WHERE type = 'forum' ORDER BY title"); - $output .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n"; - $output .= " <TR><TH>". t("Forum") ."</TH><TH>". t("Comments") ."</TH><TH>". t("Last comment") ."</TH></TR>"; + $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\">"; + $output .= " <tr><th>". t("Forum") ."</th><th>". t("Comments") ."</th><th>". t("Last comment") ."</th></tr>"; while ($node = db_fetch_object($result)) { $node = node_load(array("nid" => $node->nid)); - $output .= " <TR><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A><BR><SMALL>". check_output($node->body, 1) ."</SMALL></TD><TD ALIGN=\"center\">". forum_num_comments($node->nid) ."</TD><TD ALIGN=\"center\">". forum_last_comment($node->nid) ."</TD></TR>"; + $output .= " <tr><td><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a><br /><small>". check_output($node->body, 1) ."</small></td><td align=\"center\">". forum_num_comments($node->nid) ."</td><td align=\"center\">". forum_last_comment($node->nid) ."</td></tr>"; } - $output .= "</TABLE>\n"; + $output .= "</table>"; $theme->header(); $theme->box(t("Discussion forum"), $output); diff --git a/modules/node.module b/modules/node.module index c82eaf44a..4186230cd 100644 --- a/modules/node.module +++ b/modules/node.module @@ -16,25 +16,31 @@ function node_help() { function node_access($op, $node = 0) { - /* - ** Convert the node to an object if necessary: - */ - - if (is_array($node)) { - $node = node_object($node); + if (user_access("administer nodes")) { + return 1; } + else { - /* - ** Construct a function: - */ + /* + ** Convert the node to an object if necessary: + */ - $function = $node->type ."_access"; + if (is_array($node)) { + $node = node_object($node); + } - if (function_exists($function)) { - return $function($op, $node); - } - else { - return 0; + /* + ** Construct a function: + */ + + $function = $node->type ."_access"; + + if (function_exists($function)) { + return $function($op, $node); + } + else { + return 0; + } } } @@ -56,7 +62,6 @@ function node_search($keys) { function node_conf_options() { $output .= form_select(t("Default number of nodes to display"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of nodes to display on the main page.")); - $output .= form_select(t("Minimum number of words in a node"), "minimum_node_size", variable_get("minimum_node_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a node should have. This can be useful to stop test post.")); return $output; } @@ -129,7 +134,9 @@ function node_admin_settings($edit = array()) { ** Save the configuration options: */ - foreach ($edit as $name => $value) variable_set($name, $value); + foreach ($edit as $name => $value) { + variable_set($name, $value); + } } if ($op == t("Reset to defaults")) { @@ -137,10 +144,21 @@ function node_admin_settings($edit = array()) { ** Reset the configuration options to their default value: */ - foreach ($edit as $name=>$value) variable_del($name); + foreach ($edit as $name=>$value) { + variable_del($name); + } } + $output .= "<h3>". t("Global node settings") ."</h3>"; $output .= node_conf_options(); + + foreach (module_list() as $name) { + if (module_hook($name, "conf_options") && module_hook($name, "node")) { + $output .= "<h3>". t(ucfirst(module_invoke($name, "node", "name")) ." settings") ."</h3>"; + $output .= module_invoke($name, "conf_options"); + } + } + $output .= form_submit(t("Save configuration")); $output .= form_submit(t("Reset to defaults")); @@ -150,7 +168,7 @@ function node_admin_settings($edit = array()) { function node_admin_edit($node) { if (is_numeric($node)) { - $node = node_array(node_load(array("nid" => $node))); + $node = node_load(array("nid" => $node)); } /* @@ -162,6 +180,20 @@ function node_admin_edit($node) { $output .= node_form($node); /* + ** Edit revisions: + */ + + if ($node->revisions) { + $output .= "<h3>". t("Edit revisions") ."</h3>"; + $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; + $output .= " <tr><th>older revisions</th><th colspan=\"3\">operations</th></tr>"; + foreach ($node->revisions as $key => $revision) { + $output .= " <tr><td>". sprintf(t("revision #%d by %s on %s"), $key, format_name(user_load(array("uid" => $revision["uid"]))), format_date($revision["timestamp"])) ."</td><td><a href=\"node.php?id=$node->nid&revision=$key\">". t("view revision") ."</a></td><td><a href=\"admin.php?mod=node&op=rollback+revision&id=$node->nid&revision=$key\">". t("rollback revision") ."</a></td><td><a href=\"admin.php?mod=node&op=delete+revision&id=$node->nid&revision=$key\">". t("delete revision") ."</a></td></tr>"; + } + $output .= "</table>"; + } + + /* ** Edit comments: */ @@ -169,9 +201,12 @@ function node_admin_edit($node) { $result = db_query("SELECT c.cid, c.subject, u.uid, u.name FROM comments c LEFT JOIN users u ON u.uid = c.uid WHERE lid = '". $node["nid"] ."' ORDER BY c.timestamp"); + $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; + $output .= " <tr><th>title</th><th>author</th><th colspan=\"3\">operations</th></tr>"; while ($comment = db_fetch_object($result)) { - $output .= "<a href=\"admin.php?mod=comment&op=edit&id=$comment->cid\">$comment->subject</a> by ". format_name($comment) ."<br />"; + $output .= "<tr><td><a href=\"node.php?id=$node->nid&cid=$comment->cid#$comment->cid\">$comment->subject</a></td><td>". format_name($comment) ."</td><td><a href=\"node.php?id=$node->nid&cid=$comment->cid#$comment->cid\">". t("view comment") ."</a></td><td><a href=\"admin.php?mod=comment&op=edit&id=$comment->cid\">". t("edit comment") ."</a></td><td><a href=\"admin.php?mod=comment&op=delete&id=$comment->cid\">". t("delete comment") ."</a></td></tr>"; } + $output .= "</table>"; return $output; @@ -200,8 +235,74 @@ function node_admin_nodes() { return $output; } +function node_revision_create($node) { + global $user; + + if ($node->nid && $node->revision) { + $no = node_load(array("nid" => $node->nid)); + $node->revisions = $no->revisions; + unset($no->revisions); + $node->revisions[] = array("uid" => $user->uid, "timestamp" => time(), "node" => $no); + } + + return $node; +} + +function node_revision_rollback($nid, $revision) { + global $user; + + /* + ** Load the original/current node: + */ + + $node = node_load(array("nid" => $nid)); + + /* + ** Extract the specified revision: + */ + + $rev = $node->revisions[$revision]["node"]; + + /* + ** Inherit all the past revisions: + */ + + $rev->revisions = $node->revisions; + + /* + ** Save the original/current node: + */ + + $rev->revisions[] = array("uid" => $user->uid, "timestamp" => time(), "node" => $node); + + /* + ** Remove the specified revision: + */ + + unset($rev->revisions[$revision]); + + /* + ** Save the node: + */ + + foreach ($node as $key => $value) { + $filter[] = $key; + } + + node_save($rev, $filter); + + watchdog("message", "node: rolled-back '$node->title'"); +} + +function node_revision_delete($nid, $revision) { + $node = node_load(array("nid" => $nid)); + + unset($node->revisions[$revision]); + node_save($node, array("nid", "revisions")); +} + function node_admin() { - global $op, $id, $edit; + global $op, $id, $revision, $edit; if (user_access("administer nodes")) { @@ -231,6 +332,12 @@ function node_admin() { case "edit": print node_admin_edit($id); break; + case "rollback revision": + print node_revision_rollback($id, $revision); + break; + case "delete revision": + print node_revision_delete($id, $revision); + break; case t("Preview"): print node_preview($edit); break; @@ -239,7 +346,7 @@ function node_admin() { print node_admin_nodes(); break; case t("Delete"): - print node_remove($edit); + print node_delete($edit); break; default: print node_admin_nodes(); @@ -285,7 +392,7 @@ function node_feed() { } -function node_validate($node, $error) { +function node_validate($node, $error = array()) { global $user; @@ -299,7 +406,7 @@ function node_validate($node, $error) { ** Validate the title field: */ - if (($node->nid || $node->body) && !$node->title) { + if (isset($node->title) && $node->title == "") { $error["title"] = "<div style=\"color: red;\">". t("You have to specify a valid title.") ."</div>"; } @@ -356,13 +463,35 @@ function node_validate($node, $error) { return $node; } + function node_form($edit) { + /* + ** Validate the node: + */ + $edit = node_validate($edit, &$error); + /* + ** Get the node specific bits: + */ + + $function = $edit->type ."_form"; + if (function_exists($function)) { + $form .= $function(&$edit, &$help, &$error); + } + $output .= "<div style=\"margin-right: 40px; float: left;\">"; /* + ** Add the help text: + */ + + if ($help) { + $output .= "<p>$help</p>"; + } + + /* ** Add the default fields: */ @@ -377,13 +506,10 @@ function node_form($edit) { } /* - ** Add the node specific parts: + ** Add the node specific fields: */ - $function = $edit->type ."_form"; - if (function_exists($function)) { - $output .= $function($edit, &$error); - } + $output .= $form; /* ** Add the hidden fields: @@ -428,9 +554,10 @@ function node_form($edit) { $output .= form_textfield(t("Authored by"), "name", $edit->name, 20, 25, $error["name"]); $output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]); $output .= "<br />"; - $output .= form_select(t("Current status"), "status", $edit->status, array("Disabled", "Enabled")); - $output .= form_select(t("User comments"), "comment", $edit->comment, array("Disabled", "Enabled")); - $output .= form_select(t("Node location"), "promote", $edit->promote, array("Default", "Front page")); + $output .= form_select(t("Set public/published"), "status", $edit->status, array("Disabled", "Enabled")); + $output .= form_select(t("Allow users comments"), "comment", $edit->comment, array("Disabled", "Enabled")); + $output .= form_select(t("Promote to front page"), "promote", $edit->promote, array("Disabled", "Enabled")); + $output .= form_select(t("Create new revision"), "revision", $edit->revision, array("Disabled", "Enabled")); $output .= "</div>"; } @@ -515,6 +642,14 @@ function node_submit($node) { $node = node_validate($node); + /* + ** Create a new revision when required: + */ + + if ($node->revision) { + $node = node_revision_create($node); + } + if ($node->nid) { /* @@ -530,7 +665,7 @@ function node_submit($node) { */ if (user_access("administer nodes")) { - $fields = array("nid", "uid", "body", "comment", "promote", "moderate", "status", "teaser", "title", "created", "type" => $node->type); + $fields = array("nid", "uid", "body", "comment", "created", "promote", "moderate", "revisions", "status", "teaser", "title", "type" => $node->type); } else { $fields = array("nid", "uid" => $user->uid, "body", "teaser", "title", "type" => $node->type); @@ -580,18 +715,32 @@ function node_submit($node) { return $output; } -function node_remove($edit) { +function node_delete($edit) { $node = node_load(array("nid" => $edit["nid"])); if (node_access("delete", $node)) { + if ($edit["confirm"]) { - node_delete($node); + /* + ** Delete the specified node and its comments: + */ + + db_query("DELETE FROM node WHERE nid = '$node->nid'"); + db_query("DELETE FROM comments WHERE lid = '$node->nid'"); + + /* + ** Call the node specific callback (if any): + */ + + module_invoke($node->type, "delete", &$node); + + watchdog("special", "node: deleted '$node->title'"); $output = t("The node has been deleted."); } else { - $output .= form_item(t("Confirm removal of"), check_output($node->title)); + $output .= form_item(t("Confirm deletion"), check_output($node->title)); $output .= form_hidden("nid", $node->nid); $output .= form_hidden("confirm", 1); $output .= form_submit(t("Delete")); @@ -630,10 +779,10 @@ function node_page() { $theme->box(t("Node"), node_submit($edit)); break; case t("Delete"): - print node_remove($edit); + print node_delete($edit); break; default: - $result = db_query("SELECT nid, type FROM node WHERE ". ($meta ? "attributes LIKE '%". check_input($meta) ."%' AND " : "") ." promote = '1' AND status = '1' AND created <= '". ($date > 0 ? check_input($date) : time()) ."' ORDER BY created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get(default_nodes_main, 10))); + $result = db_query("SELECT nid, type FROM node WHERE ". ($meta ? "attributes LIKE '%". check_input($meta) ."%' AND " : "") ." promote = '1' AND status = '1' AND created <= '". ($date > 0 ? check_input($date) : time()) ."' ORDER BY created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); while ($node = db_fetch_object($result)) { node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1); } diff --git a/modules/node/node.module b/modules/node/node.module index c82eaf44a..4186230cd 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -16,25 +16,31 @@ function node_help() { function node_access($op, $node = 0) { - /* - ** Convert the node to an object if necessary: - */ - - if (is_array($node)) { - $node = node_object($node); + if (user_access("administer nodes")) { + return 1; } + else { - /* - ** Construct a function: - */ + /* + ** Convert the node to an object if necessary: + */ - $function = $node->type ."_access"; + if (is_array($node)) { + $node = node_object($node); + } - if (function_exists($function)) { - return $function($op, $node); - } - else { - return 0; + /* + ** Construct a function: + */ + + $function = $node->type ."_access"; + + if (function_exists($function)) { + return $function($op, $node); + } + else { + return 0; + } } } @@ -56,7 +62,6 @@ function node_search($keys) { function node_conf_options() { $output .= form_select(t("Default number of nodes to display"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of nodes to display on the main page.")); - $output .= form_select(t("Minimum number of words in a node"), "minimum_node_size", variable_get("minimum_node_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a node should have. This can be useful to stop test post.")); return $output; } @@ -129,7 +134,9 @@ function node_admin_settings($edit = array()) { ** Save the configuration options: */ - foreach ($edit as $name => $value) variable_set($name, $value); + foreach ($edit as $name => $value) { + variable_set($name, $value); + } } if ($op == t("Reset to defaults")) { @@ -137,10 +144,21 @@ function node_admin_settings($edit = array()) { ** Reset the configuration options to their default value: */ - foreach ($edit as $name=>$value) variable_del($name); + foreach ($edit as $name=>$value) { + variable_del($name); + } } + $output .= "<h3>". t("Global node settings") ."</h3>"; $output .= node_conf_options(); + + foreach (module_list() as $name) { + if (module_hook($name, "conf_options") && module_hook($name, "node")) { + $output .= "<h3>". t(ucfirst(module_invoke($name, "node", "name")) ." settings") ."</h3>"; + $output .= module_invoke($name, "conf_options"); + } + } + $output .= form_submit(t("Save configuration")); $output .= form_submit(t("Reset to defaults")); @@ -150,7 +168,7 @@ function node_admin_settings($edit = array()) { function node_admin_edit($node) { if (is_numeric($node)) { - $node = node_array(node_load(array("nid" => $node))); + $node = node_load(array("nid" => $node)); } /* @@ -162,6 +180,20 @@ function node_admin_edit($node) { $output .= node_form($node); /* + ** Edit revisions: + */ + + if ($node->revisions) { + $output .= "<h3>". t("Edit revisions") ."</h3>"; + $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; + $output .= " <tr><th>older revisions</th><th colspan=\"3\">operations</th></tr>"; + foreach ($node->revisions as $key => $revision) { + $output .= " <tr><td>". sprintf(t("revision #%d by %s on %s"), $key, format_name(user_load(array("uid" => $revision["uid"]))), format_date($revision["timestamp"])) ."</td><td><a href=\"node.php?id=$node->nid&revision=$key\">". t("view revision") ."</a></td><td><a href=\"admin.php?mod=node&op=rollback+revision&id=$node->nid&revision=$key\">". t("rollback revision") ."</a></td><td><a href=\"admin.php?mod=node&op=delete+revision&id=$node->nid&revision=$key\">". t("delete revision") ."</a></td></tr>"; + } + $output .= "</table>"; + } + + /* ** Edit comments: */ @@ -169,9 +201,12 @@ function node_admin_edit($node) { $result = db_query("SELECT c.cid, c.subject, u.uid, u.name FROM comments c LEFT JOIN users u ON u.uid = c.uid WHERE lid = '". $node["nid"] ."' ORDER BY c.timestamp"); + $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">"; + $output .= " <tr><th>title</th><th>author</th><th colspan=\"3\">operations</th></tr>"; while ($comment = db_fetch_object($result)) { - $output .= "<a href=\"admin.php?mod=comment&op=edit&id=$comment->cid\">$comment->subject</a> by ". format_name($comment) ."<br />"; + $output .= "<tr><td><a href=\"node.php?id=$node->nid&cid=$comment->cid#$comment->cid\">$comment->subject</a></td><td>". format_name($comment) ."</td><td><a href=\"node.php?id=$node->nid&cid=$comment->cid#$comment->cid\">". t("view comment") ."</a></td><td><a href=\"admin.php?mod=comment&op=edit&id=$comment->cid\">". t("edit comment") ."</a></td><td><a href=\"admin.php?mod=comment&op=delete&id=$comment->cid\">". t("delete comment") ."</a></td></tr>"; } + $output .= "</table>"; return $output; @@ -200,8 +235,74 @@ function node_admin_nodes() { return $output; } +function node_revision_create($node) { + global $user; + + if ($node->nid && $node->revision) { + $no = node_load(array("nid" => $node->nid)); + $node->revisions = $no->revisions; + unset($no->revisions); + $node->revisions[] = array("uid" => $user->uid, "timestamp" => time(), "node" => $no); + } + + return $node; +} + +function node_revision_rollback($nid, $revision) { + global $user; + + /* + ** Load the original/current node: + */ + + $node = node_load(array("nid" => $nid)); + + /* + ** Extract the specified revision: + */ + + $rev = $node->revisions[$revision]["node"]; + + /* + ** Inherit all the past revisions: + */ + + $rev->revisions = $node->revisions; + + /* + ** Save the original/current node: + */ + + $rev->revisions[] = array("uid" => $user->uid, "timestamp" => time(), "node" => $node); + + /* + ** Remove the specified revision: + */ + + unset($rev->revisions[$revision]); + + /* + ** Save the node: + */ + + foreach ($node as $key => $value) { + $filter[] = $key; + } + + node_save($rev, $filter); + + watchdog("message", "node: rolled-back '$node->title'"); +} + +function node_revision_delete($nid, $revision) { + $node = node_load(array("nid" => $nid)); + + unset($node->revisions[$revision]); + node_save($node, array("nid", "revisions")); +} + function node_admin() { - global $op, $id, $edit; + global $op, $id, $revision, $edit; if (user_access("administer nodes")) { @@ -231,6 +332,12 @@ function node_admin() { case "edit": print node_admin_edit($id); break; + case "rollback revision": + print node_revision_rollback($id, $revision); + break; + case "delete revision": + print node_revision_delete($id, $revision); + break; case t("Preview"): print node_preview($edit); break; @@ -239,7 +346,7 @@ function node_admin() { print node_admin_nodes(); break; case t("Delete"): - print node_remove($edit); + print node_delete($edit); break; default: print node_admin_nodes(); @@ -285,7 +392,7 @@ function node_feed() { } -function node_validate($node, $error) { +function node_validate($node, $error = array()) { global $user; @@ -299,7 +406,7 @@ function node_validate($node, $error) { ** Validate the title field: */ - if (($node->nid || $node->body) && !$node->title) { + if (isset($node->title) && $node->title == "") { $error["title"] = "<div style=\"color: red;\">". t("You have to specify a valid title.") ."</div>"; } @@ -356,13 +463,35 @@ function node_validate($node, $error) { return $node; } + function node_form($edit) { + /* + ** Validate the node: + */ + $edit = node_validate($edit, &$error); + /* + ** Get the node specific bits: + */ + + $function = $edit->type ."_form"; + if (function_exists($function)) { + $form .= $function(&$edit, &$help, &$error); + } + $output .= "<div style=\"margin-right: 40px; float: left;\">"; /* + ** Add the help text: + */ + + if ($help) { + $output .= "<p>$help</p>"; + } + + /* ** Add the default fields: */ @@ -377,13 +506,10 @@ function node_form($edit) { } /* - ** Add the node specific parts: + ** Add the node specific fields: */ - $function = $edit->type ."_form"; - if (function_exists($function)) { - $output .= $function($edit, &$error); - } + $output .= $form; /* ** Add the hidden fields: @@ -428,9 +554,10 @@ function node_form($edit) { $output .= form_textfield(t("Authored by"), "name", $edit->name, 20, 25, $error["name"]); $output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]); $output .= "<br />"; - $output .= form_select(t("Current status"), "status", $edit->status, array("Disabled", "Enabled")); - $output .= form_select(t("User comments"), "comment", $edit->comment, array("Disabled", "Enabled")); - $output .= form_select(t("Node location"), "promote", $edit->promote, array("Default", "Front page")); + $output .= form_select(t("Set public/published"), "status", $edit->status, array("Disabled", "Enabled")); + $output .= form_select(t("Allow users comments"), "comment", $edit->comment, array("Disabled", "Enabled")); + $output .= form_select(t("Promote to front page"), "promote", $edit->promote, array("Disabled", "Enabled")); + $output .= form_select(t("Create new revision"), "revision", $edit->revision, array("Disabled", "Enabled")); $output .= "</div>"; } @@ -515,6 +642,14 @@ function node_submit($node) { $node = node_validate($node); + /* + ** Create a new revision when required: + */ + + if ($node->revision) { + $node = node_revision_create($node); + } + if ($node->nid) { /* @@ -530,7 +665,7 @@ function node_submit($node) { */ if (user_access("administer nodes")) { - $fields = array("nid", "uid", "body", "comment", "promote", "moderate", "status", "teaser", "title", "created", "type" => $node->type); + $fields = array("nid", "uid", "body", "comment", "created", "promote", "moderate", "revisions", "status", "teaser", "title", "type" => $node->type); } else { $fields = array("nid", "uid" => $user->uid, "body", "teaser", "title", "type" => $node->type); @@ -580,18 +715,32 @@ function node_submit($node) { return $output; } -function node_remove($edit) { +function node_delete($edit) { $node = node_load(array("nid" => $edit["nid"])); if (node_access("delete", $node)) { + if ($edit["confirm"]) { - node_delete($node); + /* + ** Delete the specified node and its comments: + */ + + db_query("DELETE FROM node WHERE nid = '$node->nid'"); + db_query("DELETE FROM comments WHERE lid = '$node->nid'"); + + /* + ** Call the node specific callback (if any): + */ + + module_invoke($node->type, "delete", &$node); + + watchdog("special", "node: deleted '$node->title'"); $output = t("The node has been deleted."); } else { - $output .= form_item(t("Confirm removal of"), check_output($node->title)); + $output .= form_item(t("Confirm deletion"), check_output($node->title)); $output .= form_hidden("nid", $node->nid); $output .= form_hidden("confirm", 1); $output .= form_submit(t("Delete")); @@ -630,10 +779,10 @@ function node_page() { $theme->box(t("Node"), node_submit($edit)); break; case t("Delete"): - print node_remove($edit); + print node_delete($edit); break; default: - $result = db_query("SELECT nid, type FROM node WHERE ". ($meta ? "attributes LIKE '%". check_input($meta) ."%' AND " : "") ." promote = '1' AND status = '1' AND created <= '". ($date > 0 ? check_input($date) : time()) ."' ORDER BY created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get(default_nodes_main, 10))); + $result = db_query("SELECT nid, type FROM node WHERE ". ($meta ? "attributes LIKE '%". check_input($meta) ."%' AND " : "") ." promote = '1' AND status = '1' AND created <= '". ($date > 0 ? check_input($date) : time()) ."' ORDER BY created DESC LIMIT ". ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10))); while ($node = db_fetch_object($result)) { node_view(node_load(array("nid" => $node->nid, "type" => $node->type)), 1); } diff --git a/modules/page.module b/modules/page.module index f2b9e6834..a6f81a100 100644 --- a/modules/page.module +++ b/modules/page.module @@ -10,12 +10,9 @@ function page_node($field) { } function page_access($op, $node) { - if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } - - return user_access("administer nodes"); } function page_insert($node) { @@ -30,9 +27,14 @@ function page_delete($node) { db_query("DELETE FROM page WHERE nid = '$node->nid'"); } +function page_load($node) { + $page = db_fetch_object(db_query("SELECT format, link FROM page WHERE nid = '$node->nid'")); + return $page; +} + function page_link($type) { if ($type == "page") { - $result = db_query("SELECT nid,link FROM page WHERE link != '' ORDER BY link"); + $result = db_query("SELECT nid, link FROM page WHERE link != '' ORDER BY link"); while ($page = db_fetch_object($result)) { $links[] = "<a href=\"node.php?id=$page->nid\">$page->link</a>"; } @@ -41,11 +43,6 @@ function page_link($type) { return $links ? $links : array(); } -function page_load($node) { - $page = db_fetch_object(db_query("SELECT format, link FROM page WHERE nid = '$node->nid'")); - return $page; -} - function page_view($node, $main = 0) { global $format, $theme; @@ -59,10 +56,9 @@ function page_view($node, $main = 0) { default: $theme->box($node->title, check_output($node->body, 1)); } - } -function page_form($node, $error) { +function page_form($node, $help, $error) { global $format, $op; if ($op != t("Preview") && $format[$node->format] == "PHP") { @@ -77,14 +73,12 @@ function page_form($node, $error) { } function page_save() { - if ($node->nid) { return array("format", "link"); } else { return array("format", "link", "promote" => 0, "moderate" => 0, "status" => 1); } - } diff --git a/modules/page/page.module b/modules/page/page.module index f2b9e6834..a6f81a100 100644 --- a/modules/page/page.module +++ b/modules/page/page.module @@ -10,12 +10,9 @@ function page_node($field) { } function page_access($op, $node) { - if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } - - return user_access("administer nodes"); } function page_insert($node) { @@ -30,9 +27,14 @@ function page_delete($node) { db_query("DELETE FROM page WHERE nid = '$node->nid'"); } +function page_load($node) { + $page = db_fetch_object(db_query("SELECT format, link FROM page WHERE nid = '$node->nid'")); + return $page; +} + function page_link($type) { if ($type == "page") { - $result = db_query("SELECT nid,link FROM page WHERE link != '' ORDER BY link"); + $result = db_query("SELECT nid, link FROM page WHERE link != '' ORDER BY link"); while ($page = db_fetch_object($result)) { $links[] = "<a href=\"node.php?id=$page->nid\">$page->link</a>"; } @@ -41,11 +43,6 @@ function page_link($type) { return $links ? $links : array(); } -function page_load($node) { - $page = db_fetch_object(db_query("SELECT format, link FROM page WHERE nid = '$node->nid'")); - return $page; -} - function page_view($node, $main = 0) { global $format, $theme; @@ -59,10 +56,9 @@ function page_view($node, $main = 0) { default: $theme->box($node->title, check_output($node->body, 1)); } - } -function page_form($node, $error) { +function page_form($node, $help, $error) { global $format, $op; if ($op != t("Preview") && $format[$node->format] == "PHP") { @@ -77,14 +73,12 @@ function page_form($node, $error) { } function page_save() { - if ($node->nid) { return array("format", "link"); } else { return array("format", "link", "promote" => 0, "moderate" => 0, "status" => 1); } - } diff --git a/modules/story.module b/modules/story.module index 1829474fb..a611b3346 100644 --- a/modules/story.module +++ b/modules/story.module @@ -1,6 +1,13 @@ <?php // $Id$ +function story_conf_options() { + $output .= form_textarea("Explanation or submission guidelines", "story_help", variable_get("story_help", ""), 55, 4, "This text will be displayed at the top of the story submission form. Useful for helping or instructing your users."); + $output .= form_select(t("Minimum number of words"), "minimum_story_size", variable_get("minimum_node_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a personal story entry should consist of. This can be useful to rule out submissions that do not meet the site's standards, such as short test post.")); + + return $output; +} + function story_node($field) { $info = array("name" => "story"); @@ -8,43 +15,46 @@ function story_node($field) { } function story_access($op, $node) { - if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } if ($op == "create") { return 1; } - - if ($op == "update") { - return user_access("administer nodes"); - } - - if ($op == "delete") { - return user_access("adminster nodes"); - } - } function story_help() { ?> -/* // TODO: update documentation, outdated - <p>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</p> - <p>Posted stories: published stories accessible to all visitors.</p> - <p>Dumped stories: rejected stories that are no longer available to visitors.</p> -*/ + //<p>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</p> + //<p>Posted stories: published stories accessible to all visitors.</p> + //<p>Dumped stories: rejected stories that are no longer available to visitors.</p> <?php } -function story_form($node, $error) { +function story_form($node, $help, $error) { + + if (isset($node->body)) { - if ($node->body) { - if (count(explode(" ", $node->body)) < variable_get("minimum_node_size", 0)) { + /* + ** Validate the size of the story: + */ + + if (count(explode(" ", $node->body)) < variable_get("minimum_story_size", 0)) { $error["body"] = "<div style=\"color: red;\">". t("The body of your story is too short.") ."</div>"; } + + } + else { + + /* + ** Carry out some explanation or submission guidelines: + */ + + $help = variable_get("story_help", ""); + } $output = form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", ""))); @@ -53,14 +63,12 @@ function story_form($node, $error) { } function story_save($node) { - if ($node->nid) { return array(); } else { return array("promote" => 1, "moderate" => 1); } - } ?> diff --git a/modules/story/story.module b/modules/story/story.module index 1829474fb..a611b3346 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -1,6 +1,13 @@ <?php // $Id$ +function story_conf_options() { + $output .= form_textarea("Explanation or submission guidelines", "story_help", variable_get("story_help", ""), 55, 4, "This text will be displayed at the top of the story submission form. Useful for helping or instructing your users."); + $output .= form_select(t("Minimum number of words"), "minimum_story_size", variable_get("minimum_node_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a personal story entry should consist of. This can be useful to rule out submissions that do not meet the site's standards, such as short test post.")); + + return $output; +} + function story_node($field) { $info = array("name" => "story"); @@ -8,43 +15,46 @@ function story_node($field) { } function story_access($op, $node) { - if ($op == "view") { - return $node->nid && $node->status && !$node->moderate; + return ($node->nid && $node->status && !$node->moderate); } if ($op == "create") { return 1; } - - if ($op == "update") { - return user_access("administer nodes"); - } - - if ($op == "delete") { - return user_access("adminster nodes"); - } - } function story_help() { ?> -/* // TODO: update documentation, outdated - <p>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</p> - <p>Posted stories: published stories accessible to all visitors.</p> - <p>Dumped stories: rejected stories that are no longer available to visitors.</p> -*/ + //<p>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</p> + //<p>Posted stories: published stories accessible to all visitors.</p> + //<p>Dumped stories: rejected stories that are no longer available to visitors.</p> <?php } -function story_form($node, $error) { +function story_form($node, $help, $error) { + + if (isset($node->body)) { - if ($node->body) { - if (count(explode(" ", $node->body)) < variable_get("minimum_node_size", 0)) { + /* + ** Validate the size of the story: + */ + + if (count(explode(" ", $node->body)) < variable_get("minimum_story_size", 0)) { $error["body"] = "<div style=\"color: red;\">". t("The body of your story is too short.") ."</div>"; } + + } + else { + + /* + ** Carry out some explanation or submission guidelines: + */ + + $help = variable_get("story_help", ""); + } $output = form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", ""))); @@ -53,14 +63,12 @@ function story_form($node, $error) { } function story_save($node) { - if ($node->nid) { return array(); } else { return array("promote" => 1, "moderate" => 1); } - } ?> @@ -77,7 +77,6 @@ function node_failure() { $number = ($title ? db_num_rows(db_query("SELECT nid FROM node WHERE title = '$title' AND status = 1")) : 1); -// TODO: this is dead code if ($number > 1) { $result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.title = '$title' AND n.status = 1 ORDER BY created DESC"); @@ -93,12 +92,19 @@ if ($number > 1) { } elseif ($number) { $node = ($title ? node_load(array("title" => $title, "status" => 1)) : node_load(array("nid" => ($edit[id] ? $edit[id] : $id)))); + if (node_access("view", $node)) { - node_render($node); + if (isset($revision)) { + node_render($node->revisions[$revision]["node"]); + } + else { + node_render($node); + } } else { node_failure(); } + } else { node_failure(); diff --git a/updates/3.00-to-x.xx.mysql b/updates/3.00-to-x.xx.mysql index 0bc71e41a..cb947c8fa 100644 --- a/updates/3.00-to-x.xx.mysql +++ b/updates/3.00-to-x.xx.mysql @@ -134,14 +134,15 @@ ALTER TABLE node CHANGE moderate moderate int(2) DEFAULT '0' NOT NULL; ALTER TABLE node DROP timestamp_posted; ALTER TABLE node DROP timestamp_queued; ALTER TABLE node DROP timestamp_hidden; - UPDATE node SET status = 1 WHERE status = 3; ALTER TABLE book DROP section; - -# change ALTER TABLE users CHANGE session sid varchar(32) DEFAULT '' NOT NULL; +# 02/11/01: +ALTER TABLE node ADD revisions TEXT DEFAULT '' NOT NULL; + +## work in progress # ALTER TABLE users ADD session TEXT DEFAULT '' NOT NULL; # ALTER TABLE users ADD data TEXT DEFAULT '' NOT NULL; |