diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-11-12 20:15:08 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-11-12 20:15:08 +0000 |
commit | 6642f2987e1b176465e82ce1623327471c2c99a2 (patch) | |
tree | 82360ed9f7cb9eb95891c819473b400cb471fab8 | |
parent | 1291d8dcb406442972c543502377779f2c8fecc1 (diff) | |
download | brdo-6642f2987e1b176465e82ce1623327471c2c99a2.tar.gz brdo-6642f2987e1b176465e82ce1623327471c2c99a2.tar.bz2 |
- node modules:
+ made some improvements to the node access checks
- queue module:
+ form()-ified the queue module and added some extra information
or guidelines
+ added a few missing translations
+ ...
-rw-r--r-- | modules/blog.module | 2 | ||||
-rw-r--r-- | modules/blog/blog.module | 2 | ||||
-rw-r--r-- | modules/forum.module | 2 | ||||
-rw-r--r-- | modules/forum/forum.module | 2 | ||||
-rw-r--r-- | modules/page.module | 2 | ||||
-rw-r--r-- | modules/page/page.module | 2 | ||||
-rw-r--r-- | modules/queue.module | 147 | ||||
-rw-r--r-- | modules/story.module | 2 | ||||
-rw-r--r-- | modules/story/story.module | 2 |
9 files changed, 90 insertions, 73 deletions
diff --git a/modules/blog.module b/modules/blog.module index a79f0abf8..b9d0a4f86 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -22,7 +22,7 @@ function blog_access($op, $node) { global $user; if ($op == "view") { - return ($node->nid && $node->status && !$node->moderate); + return $node->status; } if ($op == "create") { diff --git a/modules/blog/blog.module b/modules/blog/blog.module index a79f0abf8..b9d0a4f86 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -22,7 +22,7 @@ function blog_access($op, $node) { global $user; if ($op == "view") { - return ($node->nid && $node->status && !$node->moderate); + return $node->status; } if ($op == "create") { diff --git a/modules/forum.module b/modules/forum.module index 354b5ad37..3721658ec 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -10,7 +10,7 @@ function forum_node($field) { function forum_access($op, $node) { if ($op == "view") { - return ($node->nid && $node->status && !$node->moderate); + return $node->status; } } diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 354b5ad37..3721658ec 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -10,7 +10,7 @@ function forum_node($field) { function forum_access($op, $node) { if ($op == "view") { - return ($node->nid && $node->status && !$node->moderate); + return $node->status; } } diff --git a/modules/page.module b/modules/page.module index 6e33db148..4341f0f78 100644 --- a/modules/page.module +++ b/modules/page.module @@ -12,7 +12,7 @@ function page_node($field) { function page_access($op, $node) { if ($op == "view") { - return ($node->nid && $node->status && !$node->moderate); + return $node->status; } } diff --git a/modules/page/page.module b/modules/page/page.module index 6e33db148..4341f0f78 100644 --- a/modules/page/page.module +++ b/modules/page/page.module @@ -12,7 +12,7 @@ function page_node($field) { function page_access($op, $node) { if ($op == "view") { - return ($node->nid && $node->status && !$node->moderate); + return $node->status; } } diff --git a/modules/queue.module b/modules/queue.module index aa70ef656..ce2e67567 100644 --- a/modules/queue.module +++ b/modules/queue.module @@ -3,7 +3,8 @@ function queue_conf_options() { $period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200), 1000000000 => t("Never")); - $output .= form_select(t("Discard entries older than"), "queue_clear", variable_get("queue_clear", 604800), $period, t("The time nodes should be kept in the submission queue. Older entries will be automatically discarded. Requires crontab.")); return $output; + $output .= form_select(t("Discard entries older than"), "queue_clear", variable_get("queue_clear", 604800), $period, t("The time nodes should be kept in the submission queue. Older entries will be automatically discarded. Requires crontab.")); + return $output; } function queue_perm() { @@ -19,8 +20,7 @@ function queue_link($type) { } function queue_cron() { - // TODO: use 'created' or 'changed' ? - // db_query("UPDATE node SET status = 0 WHERE moderate = 1 AND ". time() ." - timestamp > ". variable_get("queue_clear", 604800)); + db_query("UPDATE node SET status = 0 WHERE moderate = 1 AND ". time() ." - timestamp > ". variable_get("queue_clear", 604800)); } function queue_count() { @@ -33,41 +33,39 @@ function queue_score($id) { return ($result) ? db_result($result, 0) : 0; } -function queue_vote($id, $vote) { +function queue_vote($node, $vote) { global $user; - if ($node = node_load(array(nid => $id))) { + if (!field_get($node->users, $user->uid)) { - if (!field_get($node->users, $user->uid)) { + // Update submission's score- and votes-field: + db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->uid, $vote) ."' WHERE nid = $node->nid"); - // Update submission's score- and votes-field: - db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->uid, $vote) ."' WHERE nid = $id"); + // Reload the updated node from the database: + $node = node_load(array("nid" => $node->nid)); - $node = node_load(array(nid => $id, type => $node->type)); - - if (variable_get($node->type ."_post", 3) <= $node->score) { - node_save($node, array("nid", "status" => 1, "moderate" => 0)); - watchdog("special", "moderation: posted '$node->title'"); + if (variable_get($node->type ."_post", 3) <= $node->score) { + node_save($node, array("nid", "status" => 1, "moderate" => 0)); + watchdog("special", "moderation: posted '$node->title'"); + } + else if (variable_get($node->type ."_dump", -2) >= $node->score) { + if ($node->revisions) { + node_revision_rollback($node, end(node_revision_list($node))); + watchdog("special", "moderation: dumped '$node->title' (rollback)"); } - else if (variable_get($node->type ."_dump", -2) >= $node->score) { - if ($node->revisions) { - node_revision_rollback($node, end(node_revision_list($node))); - watchdog("special", "moderation: dumped '$node->title' (rollback)"); - } - else { - node_save($node, array("nid", "status" => 0, "moderate" => 0)); - watchdog("special", "moderation: dumped '$node->title'"); - } + else { + node_save($node, array("nid", "status" => 0, "moderate" => 0)); + watchdog("special", "moderation: dumped '$node->title'"); + } + } + else if (variable_get($node->type ."_expire", 6) <= $node->votes) { + if ($node->revisions) { + node_revision_rollback($node, end(node_revision_list($node))); + watchdog("special", "moderation: expired '$node->title' (rollback)"); } - else if (variable_get($node->type ."_expire", 6) <= $node->votes) { - if ($node->revisions) { - node_revision_rollback($node, end(node_revision_list($node))); - watchdog("special", "moderation: expired '$node->title' (rollback)"); - } - else { - node_save($node, array("nid", "status" => 0, "moderate" => 0)); - watchdog("special", "moderation: expired '$node->title'"); - } + else { + node_save($node, array("nid", "status" => 0, "moderate" => 0)); + watchdog("special", "moderation: expired '$node->title'"); } } } @@ -78,65 +76,84 @@ function queue_overview() { $result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.moderate = 1"); - $content .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\">"; - $content .= " <tr><th>". t("Subject") ."</th><th>". t("Author") ."</th><th>". t("Type") ."</TH><TH>". t("Score") ."</th></tr>"; + $output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\">"; + $output .= " <tr><th>". t("Subject") ."</th><th>". t("Author") ."</th><th>". t("Type") ."</TH><TH>". t("Score") ."</th></tr>"; while ($node = db_fetch_object($result)) { - if ($user->uid == $node->uid || field_get($node->users, $user->uid)) $content .= " <tr><td><a href=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</a></td><td align=\"center\">". format_name($node) ."</td><td align=\"center\">". check_output($node->type) ."</td><td align=\"center\">". queue_score($node->nid) ."</td></tr>"; - else $content .= " <tr><td><a href=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</a></td><td align=\"center\">". format_name($node) ."</td><td align=\"center\">". check_output($node->type) ."</td><td align=\"center\"><a href=\"module.php?mod=queue&op=view&id=$node->nid\">". t("vote") ."</a></td></tr>"; + if ($user->uid == $node->uid || field_get($node->users, $user->uid)) { + $output .= " <tr><td><a href=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</a></td><td align=\"center\">". format_name($node) ."</td><td align=\"center\">". check_output($node->type) ."</td><td align=\"center\">". queue_score($node->nid) ."</td></tr>"; + } + else { + $output .= " <tr><td><a href=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</a></td><td align=\"center\">". format_name($node) ."</td><td align=\"center\">". check_output($node->type) ."</td><td align=\"center\"><a href=\"module.php?mod=queue&op=view&id=$node->nid\">". t("vote") ."</a></td></tr>"; + } } - $content .= "</table>"; + $output .= "</table>"; $theme->header(); - $theme->box(t("Moderation queue"), $content); + $theme->box(t("Moderation queue"), $output); $theme->footer(); } -function queue_view($id) { - global $theme, $user; +function queue_view($nid) { + global $op, $edit, $theme, $user; - $node = node_load(array(nid => $id)); + /* + ** An associative array with the possible voting options: + */ + + $votes = array("+ 0" => t("neutral (+0)"), "+ 1" => t("post it (+1)"), "- 1" => t("dump it (-1)")); + + /* + ** Load the node from the database: + */ + + $node = node_load(array("nid" => $nid, "moderate" => 1)); if ($user->uid == $node->uid || field_get($node->users, $user->uid)) { drupal_goto("node.php?id=$node->nid"); } + + if ($op == t("Vote") && $votes[$edit["vote"]]) { + /* + ** If it is a valid vote, record it. + */ + + queue_vote($node, $edit["vote"]); + + $output = t("Thanks for your vote."); + } else { + /* + ** Display some explanation or voting guidelines: + */ + + $output .= "<p>". t("When new content get submitted it goes to the submission queue. Most, if not all, registered users can access this queue and can vote whether they think the content should be approved or not. When enough people vote to approve the content, it is pushed over the threshold and up it goes. On the other hand, when too many people voted to drop some content, the content will get trashed.") ."</p>"; /* - ** The keys of this associative array are displayed in each submission's - ** selection box whereas the corresponding values represent the - ** mathematical calculation to be performed to update a comment's value. + ** Display a voting form: */ - $queue_votes = array("neutral (+0)" => "+ 0", "post it (+1)" => "+ 1", "dump it (-1)" => "- 1"); - // moderation form: - $output .= "<form action=\"module.php?mod=queue\" method=\"post\">"; - foreach ($queue_votes as $key=>$value) $options .= " <option value=\"$value\">$key</option>"; - $output .= " <select name=\"vote\">$options</select>"; - $output .= " <input type=\"hidden\" name=\"id\" value=\"$node->nid\">"; - $output .= " <input type=\"submit\" name=\"op\" value=\"Vote\">"; - $output .= "</form>"; + $output .= form_select(t("Your vote"), "vote", "", $votes); + $output .= form_hidden("id", $node->nid); + $output .= form_submit(t("Vote")); - $theme->header(); - node_view($node); - $theme->box(t("Moderate"), $output); - $theme->footer(); + $output = form($output); } + + $theme->header(); + node_view($node); + $theme->box(t("Moderate"), $output); + $theme->footer(); } function queue_page() { global $user, $id, $op, $theme, $vote; if ($user->uid && user_access("access submission queue")) { - switch($op) { - case "Vote"; - queue_vote(check_input($id), check_input($vote)); - // fall through: - case "view": - queue_view(check_input($id)); - break; - default: - queue_overview(); - break; + if ($op) { + queue_view(check_input($id)); + } + else { + queue_overview(); } } else { diff --git a/modules/story.module b/modules/story.module index b2b004be3..3ce31c7cd 100644 --- a/modules/story.module +++ b/modules/story.module @@ -17,7 +17,7 @@ function story_node($field) { function story_access($op, $node) { if ($op == "view") { - return ($node->nid && $node->status && !$node->moderate); + return $node->status; } if ($op == "create") { diff --git a/modules/story/story.module b/modules/story/story.module index b2b004be3..3ce31c7cd 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -17,7 +17,7 @@ function story_node($field) { function story_access($op, $node) { if ($op == "view") { - return ($node->nid && $node->status && !$node->moderate); + return $node->status; } if ($op == "create") { |