drupal/modules/queue.module

142 lines
6.0 KiB
Plaintext

<?php
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;
}
function queue_perm() {
return array("access submission queue");
}
function queue_link($type) {
if ($type == "menu" && user_access("access submission queue")) {
$links[] = "<a href=\"module.php?mod=queue\">". t("submission queue") ."</a> (<FONT COLOR=\"red\">". queue_count() ."</FONT>)";
}
return $links ? $links : array();
}
function queue_cron() {
global $status;
db_query("UPDATE node SET status = '$status[dumped]' WHERE status = '$status[queued]' AND ". time() ." - timestamp > ". variable_get("queue_clear", 604800));
}
function queue_count() {
global $status;
$result = db_query("SELECT COUNT(nid) FROM node WHERE status = '$status[queued]'");
return ($result) ? db_result($result, 0) : 0;
}
function queue_score($id) {
$result = db_query("SELECT score FROM node WHERE nid = '$id'");
return ($result) ? db_result($result, 0) : 0;
}
function queue_vote($id, $vote) {
global $status, $user;
if ($node = node_get_object(array(nid => $id))) {
if (!field_get($node->users, $user->userid)) {
// Update submission's score- and votes-field:
db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->userid, $vote) ."' WHERE nid = $id");
$node = node_get_object(array(nid => $id, type => $node->type));
if (variable_get($node->type ."_post", 4) <= $node->score) {
node_save(array(nid => $id, status => $status[posted], timestamp => time()), array(status, timestamp));
watchdog("special", "node: posted '$node->title' - moderation");
}
else if (variable_get($node->type ."_dump", -2) >= $node->score) {
node_save(array(nid => $id, status => $status[dumped], timestamp => time()), array(status, timestamp));
watchdog("special", "node: dumped '$node->title' - moderation");
}
else if (variable_get($node->type ."_expire", 8) <= $node->votes) {
node_save(array(nid => $id, status => $status[expired], timestamp => time()), array(status, timestamp));
watchdog("special", "node: expired '$node->title' - moderation");
}
}
}
}
function queue_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><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 || field_get($node->users, $user->userid)) $content .= " <TR><TD><A HREF=\"module.php?mod=queue&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\">". queue_score($node->nid) ."</TD></TR>\n";
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_username($node->userid) ."</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>\n";
}
$content .= "</TABLE>\n";
$theme->header();
$theme->box(t("Moderation queue"), $content);
$theme->footer();
}
function queue_node($id) {
global $theme, $user;
$node = node_get_object(array(nid => $id));
if ($user->id == $node->author || field_get($node->users, $user->userid)) {
header("Location: node.php?id=$node->nid");
}
else {
$queue_votes = array("neutral (+0)" => "+ 0", "post it (+1)" => "+ 1", "dump it (-1)" => "- 1");
// 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.
if ($n = node_get_object(array("nid" => $node->pid))) {
$output .= " ". t("The above node is a proposed update of 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 submission is given below:") ."<P><I>". check_output($node->log, 1) ."</I></P>";
}
// moderation form:
$output .= "<FORM ACTION=\"module.php?mod=queue\" METHOD=\"post\">\n";
foreach ($queue_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);
$theme->box(t("Moderate"), $output);
$theme->footer();
}
}
function queue_page() {
global $user, $id, $op, $theme, $vote;
if ($user->id && user_access("access submission queue")) {
switch($op) {
case "Vote";
queue_vote(check_input($id), check_input($vote));
// fall through:
case "view":
queue_node(check_input($id));
break;
default:
queue_overview();
break;
}
}
else {
$theme->header();
$theme->box(t("Moderation queue"), message_access());
$theme->footer();
}
}
?>