summaryrefslogtreecommitdiff
path: root/modules/submission.module
blob: 66da6b251cecf58fd827765914447a5d60fab366 (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
<?

$module = array("menu" => "submission_menu",
                "page" => "submission_page");

include_once "includes/common.inc";

function submission_menu() {
  return array("<A HREF=\"module.php?mod=submission\">". t("submission queue") ."</A> (<FONT COLOR=\"red\">". submission_count() ."</FONT>)");
}

function submission_count() {
  $result = db_query("SELECT COUNT(id) FROM stories WHERE status = 1");
  return ($result) ? db_result($result, 0) : 0;
}

function submission_score($id) {
  $result = db_query("SELECT score FROM stories WHERE id = '$id'");
  return ($result) ? db_result($result, 0) : 0;
}

function submission_vote($id, $vote, $comment) {
  global $user;

  if (!user_get($user, "history", "s$id")) {
    // Update submission's score- and votes-field:
    db_query("UPDATE stories SET score = score $vote, votes = votes + 1 WHERE id = $id");

    // Update the comments (if required):
    if ($comment) {
      db_query("INSERT INTO comments (lid, link, author, subject, comment, hostname, timestamp, score) VALUES($id, 'story', $user->id, '". substr($comment, 0, 29) ." ...', '$comment', '". getenv("REMOTE_ADDR") ."', '". time() ."', '1')");
      watchdog("comment", "moderation: added comment with subject '$subject'");
    }

    // Update user's history record:
    $user = user_set($user, "history", "s$id", $vote);

    // Update story table (if required):
    $result = db_query("SELECT * FROM stories WHERE id = $id");
    if ($submission = db_fetch_object($result)) {
      if (section_post_threshold($submission->section) <= $submission->score) {
        db_query("UPDATE stories SET status = 2, timestamp = '". time() ."' WHERE id = $id");
        watchdog("message", "posted story '$submission->subject'");
      }
      else if (section_dump_threshold($submission->section) >= $submission->score) {
        db_query("UPDATE stories SET status = 0, timestamp = '". time() ."' WHERE id = $id");
        watchdog("message", "dumped story '$submission->subject'");
      }
      else if (section_timout_threshold($submission->section) <= $submission->votes) {
        db_query("UPDATE stories SET status = 0, timestamp = '". time() ."' WHERE id = $id");
        watchdog("message", "expired story '$submission->subject'");
      }
    }
  }
}

function submission_page_main() {
  global $theme, $user;

  // Perform query:
  $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.status = 1 ORDER BY s.id");

  $content .= "<P>". t("Anyone who happens by, and has some news or some thoughts they'd like to share, can submit new content for consideration.  After someone has submitted something, their story is added to a queue.  All registered users can access this list of pending stories, that is, stories that have been submitted, but do not yet appear on the public front page.  Those registered users can vote whether they think the story should be posted or not.  When enough people vote to post a story, the story is pushed over the threshold and up it goes on the public page.  On the other hand, when too many people voted to drop a story, the story will get trashed."). "</P>";
  $content .= "<P>". t("Basically, this means that you, the community, are truly the editors of this site as you have the final decision on the content of this site.  It's you judging the overall quality of a story.  But remember, vote on whether the story is interesting, not on whether you agree with it or not.  If the story goes up, you can disagree all you want, but don't vote `no' because you think the ideas expressed are wrong.  Instead, vote `no' when you think the story is plain boring.") ."</P>";
  $content .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n";
  $content .= " <TR BGCOLOR=\"$bgcolor1\"><TH>". t("Subject") ."</TH><TH>". t("Section") ."</TH><TH>". t("Date") ."</TH><TH>". t("Author") ."</TH><TH>". t("Score") ."</TH></TR>\n";
  while ($submission = db_fetch_object($result)) {
    if ($user->id == $submission->author || user_get($user, "history", "s$submission->id")) $content .= " <TR><TD WIDTH=\"100%\"><A HREF=\"module.php?mod=submission&op=view&id=$submission->id\">". check_output($submission->subject) ."</A></TD><TD>$submission->section</TD><TD ALIGN=\"center\">". date("Y-m-d", $submission->timestamp) ."<BR>". date("H:m:s", $submission->timestamp) ."</TD><TD ALIGN=\"center\">". format_username($submission->userid) ."</TD><TD ALIGN=\"center\">". submission_score($submission->id) ."</TD></TR>\n";
    else $content .= " <TR><TD WIDTH=\"100%\"><A HREF=\"module.php?mod=submission&op=view&id=$submission->id\">". check_output($submission->subject) ."</A></TD><TD>$submission->section</TD><TD ALIGN=\"center\">". date("Y-m-d", $submission->timestamp) ."<BR>". date("H:m:s", $submission->timestamp) ."</TD><TD ALIGN=\"center\">". format_username($submission->userid) ."</TD><TD ALIGN=\"center\"><A HREF=\"module.php?mod=submission&op=view&id=$submission->id\">". t("vote") ."</A></TD></TR>\n";
  }
  $content .= "</TABLE>\n";

  $theme->header();
  $theme->box(t("Open submission queue - Pending stories"), $content);
  $theme->footer();
}

function submission_display_item($id) {
  global $theme, $user, $submission_votes;

  $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = $id");
  $submission = db_fetch_object($result);

  if ($user->id == $submission->author || user_get($user, "history", "s$submission->id")) {
    header("Location: story.php?id=$submission->id");
  }
  else {
    $output .= "<FORM ACTION=\"module.php?mod=submission\" METHOD=\"post\">\n";
    $output .= "<P>\n";
    $output .= " <B>Vote:</B><BR>\n";
    $output .= " <SELECT NAME=\"vote\">\n";
    foreach ($submission_votes as $key=>$value) $output .= "  <OPTION VALUE=\"$value\">$key</OPTION>\n";
    $output .= " </SELECT>\n";
    $output .= "</P>\n";
    $output .= "<P>\n";
    $output .= " <B>Comment:</B><BR>\n";
    $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"7\" NAME=\"comment\"></TEXTAREA>\n";
    $output .= "</P>\n";
    $output .= "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$submission->id\">\n";
    $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Vote\">\n";
    $output .= "</FORM>\n";

    $theme->header();
    $theme->story($submission, "[ <A HREF=\"module.php?mod=submission\"><FONT COLOR=\"$theme->link\">back</FONT></A> ]");
    $theme->box(t("Moderate story"), $output);
    $theme->footer();
  }
}

function submission_page() {
  global $comment, $id, $op, $user, $vote;

  if ($user->id) {
    $user = user_load($user->userid);

    switch($op) {
      case "view":
        submission_display_item(check_input($id));
        break;
      case "Vote";
        submission_vote(check_input($id), check_input($vote), check_input($comment));
        // fall through
      default:
        submission_page_main();
        break;
    }
  }
}

?>