2001-03-24 16:31:17 +00:00
<?php
2001-10-20 18:57:09 +00:00
// $Id$
2001-03-24 16:31:17 +00:00
2002-06-01 21:57:29 +00:00
function queue_system($field){
2002-06-08 16:17:29 +00:00
$system["description"] = t("Enables content to be moderated by the community.");
2003-05-29 09:15:00 +00:00
$system["admin_help"] = t("** REWRITE **These are the settings for the moderation system. When the moderation value of a node is the same as or greater than the <b>Post threshold</b> then the node will be promoted to the front page. If the moderation value of a node falls below the <b>Dump threshold</b> then the node will be changed to an \"unpublished/private\" node. If the number of votes a node has recieved is the same as or higher than the <b>Expiration threshold</b>, and the node has not been promoted to the front page or dumped, then the node will be changed to an \"unpublished/private\" node. In all of three cases the moderation of the node will be marked as \"Approved\".<br /> If \"Show comments\" is enabled then the comments on this node will be shown in the moderation form.");
2002-06-01 21:57:29 +00:00
return $system[$field];
}
2001-11-12 22:17:52 +00:00
2003-02-11 20:01:17 +00:00
function queue_settings() {
2001-11-12 22:17:52 +00:00
$threshold_post = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15, 20 => 20, 25 => 25, 30 => 30, 35 => 35, 40 => 40, 45 => 45, 50 => 50, 60 => 60, 70 => 70, 80 => 80, 90 => 90, 100 => 100);
$threshold_dump = array(-1 => -1, -2 => -2, -3 => -3, -4 => -4, -5 => -5, -6 => -6, -7 => -7, -8 => -8, -9 => -9, -10 => -10, -11 => -11, -12 => -12, -13 => -13, -14 => -14, -15 => -15, -20 => -20, -25 => -25, -30 => -30);
$threshold_expire = array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 11 => 11, 12 => 12, 13 => 13, 14 => 14, 15 => 15, 20 => 20, 25 => 25, 30 => 30, 35 => 35, 40 => 40, 45 => 45, 50 => 50, 60 => 60, 70 => 70, 80 => 80, 90 => 90, 100 => 100);
$output .= form_select(t("Post threshold"), "queue_threshold_post", variable_get("queue_threshold_post", 4), $threshold_post, t("If new submissions are subject to moderation, select a post threshold."));
$output .= form_select(t("Dump threshold"), "queue_threshold_dump", variable_get("queue_threshold_dump", -2), $threshold_dump, t("If new submissions are subject to moderation, select a dump threshold."));
2002-04-22 09:05:36 +00:00
$output .= form_select(t("Expiration threshold"), "queue_threshold_expire", variable_get("queue_threshold_expire", 8), $threshold_expire, t("If new submissions are subject to moderation, select an expiration threshold."));
$output .= form_select(t("Show comments"), "queue_show_comments", variable_get("queue_show_comments", 1), array(0 => "Disabled", 1 => "Enabled"), t("If enabled comments will be shown below the moderation form."));
2001-11-12 22:17:52 +00:00
2001-11-12 20:15:08 +00:00
return $output;
2001-05-24 15:31:17 +00:00
}
2001-06-20 20:00:40 +00:00
function queue_perm() {
2001-06-29 22:08:57 +00:00
return array("access submission queue");
}
function queue_link($type) {
2002-01-30 18:15:02 +00:00
if ($type == "menu.view" && user_access("access submission queue")) {
2003-06-04 18:24:39 +00:00
$links[] = l(t("view submissions"), "queue", array("title" => t("Moderate the content in the submission queue."))) ." (<span class=\"queue-user-numeral\">". queue_count() ."</span>)";
2001-06-29 22:08:57 +00:00
}
return $links ? $links : array();
2001-06-20 20:00:40 +00:00
}
2001-05-02 20:52:19 +00:00
function queue_count() {
2001-11-01 11:00:51 +00:00
$result = db_query("SELECT COUNT(nid) FROM node WHERE moderate = 1");
2001-03-24 16:31:17 +00:00
return ($result) ? db_result($result, 0) : 0;
}
2001-05-02 20:52:19 +00:00
function queue_score($id) {
2003-05-07 21:00:36 +00:00
$result = db_query("SELECT score FROM node WHERE nid = %d", $id);
2001-03-24 16:31:17 +00:00
return ($result) ? db_result($result, 0) : 0;
}
2001-11-12 20:15:08 +00:00
function queue_vote($node, $vote) {
2001-11-01 11:00:51 +00:00
global $user;
2001-03-24 16:31:17 +00:00
2001-11-12 20:15:08 +00:00
if (!field_get($node->users, $user->uid)) {
// Update submission's score- and votes-field:
2001-11-12 22:17:52 +00:00
db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->uid, $vote) ."' WHERE nid = '$node->nid'");
2001-05-16 20:54:37 +00:00
2001-11-12 20:15:08 +00:00
// Reload the updated node from the database:
$node = node_load(array("nid" => $node->nid));
2001-03-24 16:31:17 +00:00
2001-11-12 22:17:52 +00:00
if (variable_get("queue_threshold_post", 3) <= $node->score) {
2003-03-07 22:11:44 +00:00
$node->moderate = 0;
$node->promote = 1;
node_save($node);
2001-11-23 19:26:49 +00:00
watchdog("special", "moderation: approved '$node->title'");
2001-11-12 20:15:08 +00:00
}
2001-11-12 22:17:52 +00:00
else if (variable_get("queue_threshold_dump", -2) >= $node->score) {
2001-11-12 20:15:08 +00:00
if ($node->revisions) {
node_revision_rollback($node, end(node_revision_list($node)));
2001-11-23 19:26:49 +00:00
watchdog("special", "moderation: declined '$node->title' (rollback)");
2001-03-24 16:31:17 +00:00
}
2001-11-12 20:15:08 +00:00
else {
2003-03-07 22:11:44 +00:00
$node->moderate = 0;
$node->status = 0;
node_save($node);
2001-11-23 19:26:49 +00:00
watchdog("special", "moderation: declined '$node->title'");
2001-11-12 20:15:08 +00:00
}
}
2001-11-12 22:17:52 +00:00
else if (variable_get("queue_threshold_expire", 6) <= $node->votes) {
2001-11-12 20:15:08 +00:00
if ($node->revisions) {
node_revision_rollback($node, end(node_revision_list($node)));
watchdog("special", "moderation: expired '$node->title' (rollback)");
2001-03-24 16:31:17 +00:00
}
2001-11-12 20:15:08 +00:00
else {
2003-03-07 22:11:44 +00:00
$node->moderate = 0;
$node->status = 0;
node_save($node);
2001-11-12 20:15:08 +00:00
watchdog("special", "moderation: expired '$node->title'");
2001-03-24 16:31:17 +00:00
}
}
}
}
2001-05-02 20:52:19 +00:00
function queue_overview() {
2003-02-15 11:39:56 +00:00
global $user;
2001-03-24 16:31:17 +00:00
2001-11-01 11:00:51 +00:00
$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");
2001-03-24 16:31:17 +00:00
2001-11-12 20:15:08 +00:00
$output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\">";
2002-01-27 14:58:45 +00:00
$output .= " <tr><th>". t("Subject") ."</th><th>". t("Author") ."</th><th>". t("Type") ."</th><th>". t("Score") ."</th></tr>";
2001-03-24 16:31:17 +00:00
while ($node = db_fetch_object($result)) {
2001-11-12 20:15:08 +00:00
if ($user->uid == $node->uid || field_get($node->users, $user->uid)) {
2003-01-06 19:51:01 +00:00
$output .= " <tr><td>". l($node->title, "queue/$node->nid") ."</td><td align=\"center\">". format_name($node) ."</td><td align=\"center\">". module_invoke($node->type, "node", "name") ."</td><td align=\"center\">". queue_score($node->nid) ."</td></tr>";
2001-11-12 20:15:08 +00:00
}
else {
2003-01-06 19:51:01 +00:00
$output .= " <tr><td>". l($node->title, "queue/$node->nid") ."</td><td align=\"center\">". format_name($node) ."</td><td align=\"center\">". module_invoke($node->type, "node", "name") ."</td><td align=\"center\">". l(t("vote"), "queue/$node->nid") ."</td></tr>";
2001-11-17 22:22:18 +00:00
}
if ($node->teaser) {
2002-12-31 12:34:07 +00:00
$output .= " <tr><td colspan=\"4\"><div style=\"margin-left: 40px; margin-bottom: 20px;\">". check_output($node->teaser) ."</div></td></tr>";
2001-11-12 20:15:08 +00:00
}
2001-03-24 16:31:17 +00:00
}
2001-11-12 20:15:08 +00:00
$output .= "</table>";
2001-03-24 16:31:17 +00:00
2003-02-15 11:39:56 +00:00
theme("header");
theme("box", t("Moderation queue"), $output);
theme("footer");
2001-03-24 16:31:17 +00:00
}
2001-11-12 20:15:08 +00:00
function queue_view($nid) {
2003-05-13 18:36:38 +00:00
global $user;
$op = $_POST["op"];
$edit = $_POST["edit"];
2001-05-13 17:47:17 +00:00
2001-11-12 20:15:08 +00:00
/*
** 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));
2001-03-24 16:31:17 +00:00
2002-03-20 20:04:23 +00:00
if ($user->uid != $node->uid && !field_get($node->users, $user->uid)) {
if ($op == t("Vote") && $votes[$edit["vote"]]) {
2002-04-05 18:11:42 +00:00
/*
** If it is a valid vote, record it.
*/
2002-04-14 20:46:41 +00:00
2002-04-05 18:11:42 +00:00
queue_vote($node, $edit["vote"]);
2002-04-14 20:46:41 +00:00
2002-04-05 18:11:42 +00:00
$output = t("Your vote has been recorded.");
}
else {
/*
** Display some explanation or voting guidelines:
*/
2002-04-14 20:46:41 +00:00
2002-04-05 18:11:42 +00:00
$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>";
2002-04-14 20:46:41 +00:00
2002-04-05 18:11:42 +00:00
/*
** Display a voting form:
*/
2002-04-14 20:46:41 +00:00
2002-04-05 18:11:42 +00:00
$output .= form_select(t("Your vote"), "vote", "", $votes);
$output .= form_hidden("id", $node->nid);
$output .= form_submit(t("Vote"));
2002-04-14 20:46:41 +00:00
2002-04-05 18:11:42 +00:00
$output = form($output);
2002-04-14 20:46:41 +00:00
}
2002-04-05 18:11:42 +00:00
}
2001-11-12 20:15:08 +00:00
2003-02-15 11:39:56 +00:00
theme("header");
2001-11-12 20:15:08 +00:00
node_view($node);
2002-03-20 20:04:23 +00:00
if ($output) {
2003-02-15 11:39:56 +00:00
theme("box", t("Moderate"), $output);
2002-03-20 20:04:23 +00:00
}
if ($node->comment && variable_get("queue_show_comments", 1)) {
2002-12-10 20:35:20 +00:00
module_invoke("comment", "render", $node);
2002-03-20 20:04:23 +00:00
}
2003-02-15 11:39:56 +00:00
theme("footer");
2001-03-24 16:31:17 +00:00
}
2001-05-02 20:52:19 +00:00
function queue_page() {
2003-02-15 11:39:56 +00:00
global $user, $vote;
2001-03-24 16:31:17 +00:00
2001-09-16 11:33:14 +00:00
if ($user->uid && user_access("access submission queue")) {
2003-01-06 19:51:01 +00:00
if (arg(1)) {
queue_view(check_input(arg(1)));
2001-11-12 20:15:08 +00:00
}
else {
queue_overview();
2001-03-24 16:31:17 +00:00
}
}
2001-05-15 18:38:57 +00:00
else {
2003-02-15 11:39:56 +00:00
theme("header");
theme("box", t("Moderation queue"), message_access());
theme("footer");
2001-05-15 18:38:57 +00:00
}
2001-03-24 16:31:17 +00:00
}
2001-11-01 11:00:51 +00:00
2002-10-28 19:36:37 +00:00
function queue_block($op = "list", $delta = 0) {
if ($op == "list") {
$blocks[0]["info"] = t("Moderation results");
return $blocks;
}
else {
2003-01-11 10:46:11 +00:00
if (user_access("access submission queue") && (substr_count(request_uri(), url("queue")) || substr_count(request_uri(), url("node")))) {
2002-10-28 19:36:37 +00:00
global $user, $id;
if ($user->uid) {
$node = node_load(array("nid" => $id));
2002-01-27 14:58:45 +00:00
}
2002-10-28 19:36:37 +00:00
if (($user->uid == $node->uid || field_get($node->users, $user->uid)) && $node->moderate == 1) {
foreach (explode(",", $node->users) as $vote) {
if ($vote) {
$data = explode("=", $vote);
$account = user_load(array("uid" => $data[0]));
$output .= format_name($account) ." voted '$data[1]'.<br />";
}
}
2002-01-27 14:58:45 +00:00
2002-11-27 18:43:49 +00:00
$block["subject"] = t("Moderation results");
$block["content"] = $output ? $output : t("This node has not been moderated yet.");
2002-10-28 19:36:37 +00:00
}
}
2003-01-06 19:51:01 +00:00
elseif ((user_access("access submission queue") || user_access("administer blocks")) && (substr_count(request_uri(), url("user")) || substr_count(request_uri(), url("admin")))) {
2002-11-27 18:43:49 +00:00
$block["subject"] = t("Moderation results");
2002-01-21 17:31:13 +00:00
}
2002-10-28 19:36:37 +00:00
return $block;
}
2002-01-21 17:31:13 +00:00
}
2003-02-16 14:57:35 +00:00
function queue_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
2003-03-07 22:11:44 +00:00
case "fields":
2003-03-09 17:19:50 +00:00
return array("score", "users", "votes");
2003-03-07 22:11:44 +00:00
case "validate":
if ($node->nid && $node->moderate) {
// Reset votes when node is updated:
$node->score = 0;
$node->users = "";
$node->votes = 0;
2003-02-16 14:57:35 +00:00
}
break;
}
}
2003-06-04 18:24:39 +00:00
?>