119 lines
4.6 KiB
Plaintext
119 lines
4.6 KiB
Plaintext
<?php
|
|
|
|
$module = array("menu" => "moderation_menu",
|
|
"page" => "moderation_page");
|
|
|
|
include_once "includes/common.inc";
|
|
include_once "includes/node.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() {
|
|
global $status;
|
|
$result = db_query("SELECT COUNT(nid) FROM node WHERE status = '$status[queued]'");
|
|
return ($result) ? db_result($result, 0) : 0;
|
|
}
|
|
|
|
function moderation_score($id) {
|
|
$result = db_query("SELECT score FROM node WHERE nid = '$id'");
|
|
return ($result) ? db_result($result, 0) : 0;
|
|
}
|
|
|
|
function moderation_vote($id, $vote) {
|
|
global $status, $user;
|
|
|
|
if (!user_get($user, "history", "n$id")) {
|
|
// Update submission's score- and votes-field:
|
|
db_query("UPDATE node SET score = score $vote, votes = votes + 1 WHERE nid = $id");
|
|
|
|
// Update user's history record:
|
|
$user = user_set($user, "history", "n$id", $vote);
|
|
|
|
if ($node = node_get_object(nid, $id)) {
|
|
if (node_post_threshold($node) <= $node->score) {
|
|
node_save(array(nid => $id, pid => $node->pid, type => $node->type, status => $status[posted]));
|
|
watchdog("message", "posted node '$node->title'");
|
|
}
|
|
else if (node_dump_threshold($node) >= $node->score) {
|
|
node_save(array(nid => $id, pid => $node->pid, type => $node->type, status => $status[dumped]));
|
|
watchdog("message", "dumped node '$node->title'");
|
|
}
|
|
else if (node_timout_threshold($node) <= $node->votes) {
|
|
node_save(array(nid => $id, pid => $node->pid, type => $node->type, status => $status[expired]));
|
|
watchdog("message", "expired node '$node->title'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function moderation_overview() {
|
|
global $status, $theme, $user;
|
|
|
|
$result = db_query("SELECT n.*, u.userid FROM node n LEFT JOIN users u ON n.author = u.id WHERE n.status = '$status[queued]'");
|
|
|
|
$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 {
|
|
if ($node->pid && $n = node_get_object("nid", $node->pid)) {
|
|
if ($node->pid) $output .= " ". t("The above node is a suggested update for an existing node:") ." \"<A HREF=\"node.php?id=$n->nid\">". check_output($n->title) ."</A>\".";
|
|
if ($node->log) $output .= " ". t("The log message to accompany this update is given below:") ."<P><I>". check_output($node->log, 1) ."</I></P>";
|
|
}
|
|
|
|
// 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, 0);
|
|
$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;
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|