drupal/modules/queue.module

260 lines
9.3 KiB
Plaintext
Raw Normal View History

<?php
// $Id$
function queue_system($field){
$output = "";
if ($field == "description") {$output = queue_help("admin/system/modules"); }
else if ($field == "admin_help") {$output = queue_help("admin/system/modules/queue"); };
return $output;
}
function queue_help($section) {
$output = "";
switch ($section) {
case 'admin/system/modules':
$output = "Enables content to be moderated by the community.";
break;
case 'admin/system/modules/queue':
$output = "The queue provides a way for your users to vote on submitted content. This is called <b>moderation</b>. Users can moderate a post up (give it a point), or down (subtract a point). The settings below give you control over how many points are required for the status of a post to be automatically changed. See individual items for details.";
break;
}
return t($output);
}
2001-11-12 22:17:52 +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("When a post gets this number of moderation points, it is <b>promoted to the front page</b> automatically."));
$output .= form_select(t("Dump threshold"), "queue_threshold_dump", variable_get("queue_threshold_dump", -2), $threshold_dump, t("When a post drops below this number of points, its status is changed to <b>unpublished</b>."));
$output .= form_select(t("Expiration threshold"), "queue_threshold_expire", variable_get("queue_threshold_expire", 8), $threshold_expire, t("When a post gets this number of points, its status is changed to <b>unpublished</b>."));
$output .= form_item(t("Show comments"), form_checkbox(t("Enabled"), "queue_show_comments", 1, variable_get("queue_show_comments", 1)), t("Tick the box to show comments below the moderation form."));
2001-11-12 22:17:52 +00:00
return $output;
}
function queue_perm() {
return array("access submission queue");
}
function queue_link($type) {
if ($type == "system") {
if (user_access("access submission queue")) {
menu("queue", t("view submissions"), NULL, NULL, 1);
}
}
return $links ? $links : array();
}
function queue_count() {
$result = db_query("SELECT COUNT(nid) FROM {node} WHERE moderate = 1");
return ($result) ? db_result($result, 0) : 0;
}
function queue_score($id) {
$result = db_query("SELECT score FROM {node} WHERE nid = %d", $id);
return ($result) ? db_result($result, 0) : 0;
}
function queue_vote($node, $vote) {
global $user;
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'");
// Reload the updated node from the database:
$node = node_load(array("nid" => $node->nid));
2001-11-12 22:17:52 +00:00
if (variable_get("queue_threshold_post", 3) <= $node->score) {
$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 22:17:52 +00:00
else if (variable_get("queue_threshold_dump", -2) >= $node->score) {
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)");
}
else {
$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 22:17:52 +00:00
else if (variable_get("queue_threshold_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->moderate = 0;
$node->status = 0;
node_save($node);
watchdog("special", "moderation: expired '$node->title'");
}
}
}
}
function queue_overview() {
global $user;
$result = db_query("SELECT n.*, u.name, u.uid FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.moderate = 1");
$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)) {
$output .= " <tr><td>". l($node->title, "queue/$node->nid") ."</td><td style=\"text-align: center;\">". format_name($node) ."</td><td style=\"text-align: center;\">". module_invoke($node->type, "node", "name") ."</td><td style=\"text-align: center;\">". queue_score($node->nid) ."</td></tr>";
}
else {
$output .= " <tr><td>". l($node->title, "queue/$node->nid") ."</td><td style=\"text-align: center;\">". format_name($node) ."</td><td style=\"text-align: center;\">". module_invoke($node->type, "node", "name") ."</td><td style=\"text-align: center;\">". l(t("vote"), "queue/$node->nid") ."</td></tr>";
}
if ($node->teaser) {
$output .= " <tr><td colspan=\"4\"><div style=\"margin-left: 40px; margin-bottom: 20px;\">". check_output($node->teaser) ."</div></td></tr>";
}
}
$output .= "</table>";
theme("header");
theme("box", t("Moderation queue"), $output);
theme("footer");
}
function queue_view($nid) {
global $user;
$op = $_POST["op"];
$edit = $_POST["edit"];
2001-05-13 17:47:17 +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));
if ($user->uid != $node->uid && !field_get($node->users, $user->uid)) {
if ($op == t("Vote") && $votes[$edit["vote"]]) {
/*
** If it is a valid vote, record it.
*/
queue_vote($node, $edit["vote"]);
$output = t("Your vote has been recorded.");
}
else {
/*
** Display some explanation or voting guidelines:
*/
$output .= "<p>". t("When new content is submitted it goes into the submission queue. Registered users with the appropriate permission can access this queue and vote whether they think the content should be approved or not. When enough people vote to approve the content it is displayed on the front page. On the other hand, if enough people vote to drop it, the content will disappear.") ."</p>";
/*
** Display a voting form:
*/
$output .= form_select(t("Your vote"), "vote", "", $votes);
$output .= form_hidden("id", $node->nid);
$output .= form_submit(t("Vote"));
$output = form($output);
}
}
theme("header");
node_view($node);
if ($output) {
theme("box", t("Moderate"), $output);
}
if ($node->comment && variable_get("queue_show_comments", 1)) {
module_invoke("comment", "render", $node);
}
theme("footer");
}
function queue_page() {
global $user, $vote;
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)) {
2003-06-06 21:09:55 +00:00
queue_view(arg(1));
}
else {
queue_overview();
}
}
else {
theme("header");
theme("box", t("Moderation queue"), message_access());
theme("footer");
}
}
function queue_block($op = "list", $delta = 0) {
2003-07-17 22:48:15 +00:00
global $user;
if ($op == "list") {
$blocks[0]["info"] = t("Moderation results");
return $blocks;
}
else {
2003-07-17 22:48:15 +00:00
if (user_access("access submission queue") && (arg(0) == "queue") || arg(0) == "node") {
if ($user->uid) {
2003-07-17 22:48:15 +00:00
if (arg(0) == "queue") {
$id = arg(1);
}
else {
$id = arg(2);
}
$node = node_load(array("nid" => $id));
2003-07-17 22:48:15 +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 />";
}
}
2003-07-17 22:48:15 +00:00
$block["subject"] = t("Moderation results");
$block["content"] = $output ? $output : t("This node has not yet been moderated.");
}
}
}
return $block;
}
}
function queue_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case "fields":
return array("score", "users", "votes");
case "validate":
if ($node->nid && $node->moderate) {
// Reset votes when node is updated:
$node->score = 0;
$node->users = "";
$node->votes = 0;
}
break;
}
}
- Bugfix: renamed the SQL field 'types' to 'nodes' because 'types' is a reserved keyword in MySQL 4. This fixes critical bug #1618. Patch by Marco. ==> This fix requires to run update.php! - Bugfix: made sessions work without warnings when register_globals is turned off. The solution is to use $_SESSION instead of session_register(). This fixes critical bug #1797. Patch by Marco. - Bugfix: sometimes error messages where being discarded when previewing a node. Patch by Craig Courtney. - Bugfix: fixed charset problems. This fixes critical bug #1549. Patch '0023.charset.patch' by Al. - Code improvements: removed some dead code from the comment module. Patch by Marco. - Documentation improvements: polished the node module help texts and form descriptions. Patch '0019.node.module.help.patch' by Al. - CSS improvements all over the map! Patch '0021.more.css.patch' by Al. - GUI improvements: improved the position of Druplicon in the admin menu. Patch '0020.admin.logo.patch' by Al. - GUI improvements: new logos for theme Marvin and theme UnConeD. Logos by Kristjan Jansen. - GUI improvements: small changes to the output emitted by the profile module. Suggestions by Steven Wittens. - GUI improvements: small fixes to Xtemplate. Patch '0022.xtemplate.css.patch' by Al. TODO: - Some modules such as the buddy list module and the annotation module in the contributions repository are also using session_register(). They should be updated. We should setup a task on Drupal. - There is code emitting '<div align="right">' which doesn't validate. - Does our XML feeds validate with the charset changes? - The forum module's SQL doesn't work properly on PostgreSQL.
2003-06-04 18:24:39 +00:00
?>