queue.module 5.99 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
2
// $Id$
Dries's avatar
 
Dries committed
3

Dries's avatar
 
Dries committed
4
function queue_conf_options() {
Dries's avatar
 
Dries committed
5
  $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"));
Dries's avatar
 
Dries committed
6
  $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;
Dries's avatar
 
Dries committed
7 8
}

Dries's avatar
 
Dries committed
9
function queue_perm() {
Dries's avatar
 
Dries committed
10 11 12 13 14 15 16 17 18
  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();
Dries's avatar
 
Dries committed
19 20
}

Dries's avatar
 
Dries committed
21 22 23 24 25
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));
}

Dries's avatar
 
Dries committed
26
function queue_count() {
Dries's avatar
 
Dries committed
27
  global $status;
Dries's avatar
 
Dries committed
28
  $result = db_query("SELECT COUNT(nid) FROM node WHERE status = '$status[queued]'");
Dries's avatar
 
Dries committed
29 30 31
  return ($result) ? db_result($result, 0) : 0;
}

Dries's avatar
 
Dries committed
32
function queue_score($id) {
Dries's avatar
 
Dries committed
33
  $result = db_query("SELECT score FROM node WHERE nid = '$id'");
Dries's avatar
 
Dries committed
34 35 36
  return ($result) ? db_result($result, 0) : 0;
}

Dries's avatar
 
Dries committed
37
function queue_vote($id, $vote) {
Dries's avatar
 
Dries committed
38
  global $status, $user;
Dries's avatar
 
Dries committed
39

40
  if ($node = node_get_object(array(nid => $id))) {
Dries's avatar
 
Dries committed
41

Dries's avatar
 
Dries committed
42
    if (!field_get($node->users, $user->uid)) {
Dries's avatar
 
Dries committed
43 44

      // Update submission's score- and votes-field:
Dries's avatar
 
Dries committed
45
      db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->uid, $vote) ."' WHERE nid = $id");
Dries's avatar
 
Dries committed
46

Dries's avatar
 
Dries committed
47 48 49
      $node = node_get_object(array(nid => $id, type => $node->type));

      if (variable_get($node->type ."_post", 4) <= $node->score) {
Dries's avatar
 
Dries committed
50
        node_save(array(nid => $id, status => $status[posted], timestamp => time()), array(status, timestamp));
Dries's avatar
 
Dries committed
51
        watchdog("special", "node: posted '$node->title' - moderation");
Dries's avatar
 
Dries committed
52
      }
Dries's avatar
 
Dries committed
53
      else if (variable_get($node->type ."_dump", -2) >= $node->score) {
Dries's avatar
 
Dries committed
54
        node_save(array(nid => $id, status => $status[dumped], timestamp => time()), array(status, timestamp));
Dries's avatar
 
Dries committed
55
        watchdog("special", "node: dumped '$node->title' - moderation");
Dries's avatar
 
Dries committed
56
      }
Dries's avatar
 
Dries committed
57
      else if (variable_get($node->type ."_expire", 8) <= $node->votes) {
Dries's avatar
 
Dries committed
58
        node_save(array(nid => $id, status => $status[expired], timestamp => time()), array(status, timestamp));
Dries's avatar
 
Dries committed
59
        watchdog("special", "node: expired '$node->title' - moderation");
Dries's avatar
 
Dries committed
60 61 62 63 64
      }
    }
  }
}

Dries's avatar
 
Dries committed
65
function queue_overview() {
Dries's avatar
 
Dries committed
66
  global $status, $theme, $user;
Dries's avatar
 
Dries committed
67

Dries's avatar
 
Dries committed
68
  $result = db_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid WHERE n.status = '$status[queued]'");
Dries's avatar
 
Dries committed
69 70

  $content .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n";
Dries's avatar
 
Dries committed
71
  $content .= " <TR><TH>". t("Subject") ."</TH><TH>". t("Author") ."</TH><TH>". t("Type") ."</TH><TH>". t("Score") ."</TH></TR>\n";
Dries's avatar
 
Dries committed
72
  while ($node = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
73
    if ($user->uid == $node->uid || field_get($node->users, $user->uid)) $content .= " <TR><TD><A HREF=\"module.php?mod=queue&op=view&id=$node->nid\">". check_output($node->title) ."</A></TD><TD ALIGN=\"center\">". format_name($node) ."</TD><TD ALIGN=\"center\">". check_output($node->type) ."</TD><TD ALIGN=\"center\">". queue_score($node->nid) ."</TD></TR>\n";
Dries's avatar
 
Dries committed
74
    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_name($node) ."</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";
Dries's avatar
 
Dries committed
75 76 77 78 79 80 81 82
  }
  $content .= "</TABLE>\n";

  $theme->header();
  $theme->box(t("Moderation queue"), $content);
  $theme->footer();
}

Dries's avatar
 
Dries committed
83
function queue_node($id) {
Dries's avatar
 
Dries committed
84 85
  global $theme, $user;

Dries's avatar
 
Dries committed
86

87
  $node = node_get_object(array(nid => $id));
Dries's avatar
 
Dries committed
88

Dries's avatar
 
Dries committed
89
  if ($user->uid == $node->uid || field_get($node->users, $user->uid)) {
Dries's avatar
 
Dries committed
90
    drupal_goto("node.php?id=$node->nid");
Dries's avatar
 
Dries committed
91 92
  }
  else {
Dries's avatar
 
Dries committed
93 94 95
    $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.

96
    if ($n = node_get_object(array("nid" => $node->pid))) {
Dries's avatar
 
Dries committed
97 98 99 100 101
      $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>";
Dries's avatar
 
Dries committed
102 103
    }

Dries's avatar
 
Dries committed
104
    // moderation form:
Dries's avatar
 
Dries committed
105 106
    $output .= "<FORM ACTION=\"module.php?mod=queue\" METHOD=\"post\">\n";
    foreach ($queue_votes as $key=>$value) $options .= "  <OPTION VALUE=\"$value\">$key</OPTION>\n";
Dries's avatar
 
Dries committed
107 108 109 110 111 112
    $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();
Dries's avatar
 
Dries committed
113
    node_view($node);
Dries's avatar
 
Dries committed
114 115 116 117 118
    $theme->box(t("Moderate"), $output);
    $theme->footer();
  }
}

Dries's avatar
 
Dries committed
119
function queue_page() {
Dries's avatar
 
Dries committed
120
  global $user, $id, $op, $theme, $vote;
Dries's avatar
 
Dries committed
121

Dries's avatar
 
Dries committed
122
  if ($user->uid && user_access("access submission queue")) {
Dries's avatar
 
Dries committed
123 124
    switch($op) {
      case "Vote";
Dries's avatar
 
Dries committed
125
        queue_vote(check_input($id), check_input($vote));
Dries's avatar
 
Dries committed
126 127
        // fall through:
      case "view":
Dries's avatar
 
Dries committed
128
        queue_node(check_input($id));
Dries's avatar
 
Dries committed
129 130
        break;
      default:
Dries's avatar
 
Dries committed
131
        queue_overview();
Dries's avatar
 
Dries committed
132 133 134
        break;
    }
  }
Dries's avatar
 
Dries committed
135 136
  else {
    $theme->header();
Dries's avatar
 
Dries committed
137
    $theme->box(t("Moderation queue"), message_access());
Dries's avatar
 
Dries committed
138 139
    $theme->footer();
  }
Dries's avatar
 
Dries committed
140
}
141

Dries's avatar
 
Dries committed
142
?>