diff options
Diffstat (limited to 'modules/moderation.module')
-rw-r--r-- | modules/moderation.module | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/modules/moderation.module b/modules/moderation.module new file mode 100644 index 000000000..3d0b0f4c8 --- /dev/null +++ b/modules/moderation.module @@ -0,0 +1,112 @@ +<?php + +$module = array("menu" => "moderation_menu", + "page" => "moderation_page"); + +include_once "includes/common.inc"; + +function moderation_menu() { + return array("<A HREF=\"module.php?mod=moderation\">". t("moderation queue") ."</A> (<FONT COLOR=\"red\">". moderation_count() ."</FONT>)"); +} + +function moderation_count() { + $result = db_query("SELECT COUNT(nid) FROM nodes WHERE status = 1"); + return ($result) ? db_result($result, 0) : 0; +} + +function moderation_score($id) { + $result = db_query("SELECT score FROM nodes WHERE nid = '$id'"); + return ($result) ? db_result($result, 0) : 0; +} + +function moderation_vote($id, $vote) { + global $user; + + if (!user_get($user, "history", "n$id")) { + // Update submission's score- and votes-field: + db_query("UPDATE nodes SET score = score $vote, votes = votes + 1 WHERE nid = $id"); + + // Update user's history record: + $user = user_set($user, "history", "n$id", $vote); + + $result = db_query("SELECT * FROM nodes WHERE nid = $id"); + if ($node = db_fetch_object($result)) { + if (node_post_threshold($node) <= $node->score) { + db_query("UPDATE nodes SET status = 2, timestamp = '". time() ."' WHERE nid = $id"); + watchdog("message", "posted node '$node->subject'"); + } + else if (node_dump_threshold($node) >= $node->score) { + db_query("UPDATE nodes SET status = 0, timestamp = '". time() ."' WHERE nid = $id"); + watchdog("message", "dumped node '$node->subject'"); + } + else if (node_timout_threshold($node) <= $node->votes) { + db_query("UPDATE nodes SET status = 0, timestamp = '". time() ."' WHERE nid = $id"); + watchdog("message", "expired node '$node->subject'"); + } + } + } +} + +function moderation_overview() { + global $theme, $user; + + $result = db_query("SELECT n.*, u.userid FROM nodes n LEFT JOIN users u ON n.author = u.id WHERE n.status = 1"); + + $content .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n"; + $content .= " <TR BGCOLOR=\"$bgcolor1\"><TH>". t("Subject") ."</TH><TH>". t("Author") ."</TH><TH>". t("Type") ."</TH><TH>". t("Score") ."</TH></TR>\n"; + while ($node = db_fetch_object($result)) { + if ($user->id == $node->author || user_get($user, "history", "n$node->nid")) $content .= " <TR><TD><A HREF=\"module.php?mod=moderation&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\">". moderation_score($node->nid) ."</TD></TR>\n"; + else $content .= " <TR><TD><A HREF=\"module.php?mod=moderation&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_username($node->userid) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\"><A HREF=\"module.php?mod=moderation&op=view&id=$node->nid\">". t("vote") ."</A></TD></TR>\n"; + } + $content .= "</TABLE>\n"; + + $theme->header(); + $theme->box(t("Moderation queue"), $content); + $theme->footer(); +} + +function moderation_node($id) { + global $theme, $user, $moderation_votes; + + $node = node_get_object(nid, $id); + + if ($user->id == $node->author || user_get($user, "history", "n$node->nid")) { + header("Location: node.php?id=$node->nid"); + } + else { + // moderation form: + $output .= "<FORM ACTION=\"module.php?mod=moderation\" METHOD=\"post\">\n"; + foreach ($moderation_votes as $key=>$value) $options .= " <OPTION VALUE=\"$value\">$key</OPTION>\n"; + $output .= "<SELECT NAME=\"vote\">$options</SELECT>\n"; + $output .= "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$node->nid\">\n"; + $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Vote\">\n"; + $output .= "</FORM>\n"; + + $theme->header(); + node_view($node, 1); + $theme->box(t("Moderate"), $output); + $theme->footer(); + } +} + +function moderation_page() { + global $id, $op, $user, $vote; + + if ($user->id) { + $user = user_load($user->userid); + + switch($op) { + case "Vote"; + moderation_vote(check_input($id), check_input($vote)); + // fall through: + case "view": + moderation_node(check_input($id)); + break; + default: + moderation_overview(); + break; + } + } +} + +?> |