Commit 33930b56 authored by Dries's avatar Dries
Browse files

- added submission.module

parent da8aaa76
<?
$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_history($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, '". check_input(substr($comment, 0, 29)) ." ...', '". check_input($comment) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."', '1')");
watchdog("comment", "moderation: added comment with subject '$subject'");
}
// Update user's history record:
user_set_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_history($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_history($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->article($submission, "[ <A HREF=\"module.php?mod=submission\"><FONT COLOR=\"$theme->link\">back</FONT></A> ]");
$theme->box("Moderate story", $output);
$theme->footer();
}
}
function submission_page() {
global $comment, $id, $op, $user, $vote;
if ($user->id) {
user_rehash();
switch($op) {
case "view":
submission_display_item($id);
break;
case "Vote";
submission_vote($id, $vote, $comment);
// fall through
default:
submission_page_main();
break;
}
}
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment