summaryrefslogtreecommitdiff
path: root/modules/queue.module
blob: 2ea116f8c85ab7192c09ccbe58a3a8dc796dab01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?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->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 = $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.name, u.uid FROM node n LEFT JOIN users u ON n.author = u.uid 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->uid == $node->author || 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";
    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";
  }
  $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->uid == $node->author || field_get($node->users, $user->uid)) {
    drupal_goto("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->uid && 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();
  }
}

?>