Commit cccb132c authored by Dries's avatar Dries

- Addition: added a "promote" field to the node table, which
  makes "promoting nodes" to the main page possible.  Stories
  and reviews could be promoted by default, but - on accasion
  a good book entry could be manually promoted too.  Thus all
  existing content types can be shown on the main page, not
  just stories.

  Requires a SQL update, see 2.00-to-x.xx.sql!

- Addition: implemented "auto-post new submissions" feature
  to disable or by-pass the moderation queue in addition to
  "moderate new submissions".

  TODO: admin moderation versus registered user moderation.

- Addition: added category and topic support to page.module.
parent 3f1979aa
......@@ -145,11 +145,6 @@ function comment_post($pid, $id, $subject, $comment) {
}
}
function comment_status($index = -1) {
$status = array("disabled", "enabled");
return $index < 0 ? $status : $status[$index];
}
function comment_score($comment) {
$value = ($comment->votes) ? ($comment->score / $comment->votes) : (($comment->score) ? $comment->score : 0);
return ((strpos($value, ".")) ? substr($value ."00", 0, 4) : $value .".00");
......
......@@ -10,6 +10,21 @@ function _node_get($field, $value) {
}
}
function node_comment_status($index = -1) {
$status = array("disabled", "enabled");
return $index < 0 ? $status : $status[$index];
}
function node_promote_status($index = -1) {
$status = array("disabled", "enabled");
return $index < 0 ? $status : $status[$index];
}
function node_submission_status($index = -1) {
$status = array("auto-post new submissions", "moderate new submissions");
return $index < 0 ? $status : $status[$index];
}
function node_get_object($field, $value) {
return db_fetch_object(_node_get($field, $value));
}
......@@ -39,7 +54,7 @@ function node_get_comments($nid) {
function node_save($node) {
global $user, $status;
$rows = array(nid, pid, lid, cid, tid, log, type, title, score, votes, author, status, comment, timestamp);
$rows = array(nid, pid, lid, cid, tid, log, type, title, score, votes, author, status, comment, promote, timestamp);
if ($node[nid] > 0) {
$n = node_get_object("nid", $node[nid]);
......@@ -71,10 +86,11 @@ function node_save($node) {
watchdog("warning", "node: duplicate '$node[title]'");
}
else {
// verify submission rate:
throttle("post node", variable_get(max_node_rate, 900));
// setup default values:
$node = array_merge(array(title => "?", author => $user->id, type => "?", pid => 0, cid => 0, tid => 0, log => "node created", status => $status[queued], score => 0, votes => 0, comment => 1, timestamp => time()), $node);
$node = array_merge(array(title => "?", author => $user->id, type => "?", pid => 0, cid => 0, tid => 0, log => "node created", status => (category_submission($node[cid]) ? $status[queued] : $status[posted]) , score => 0, votes => 0, comment => category_comment($node[cid]), promote => category_promote($node[cid]), timestamp => time()), $node);
// prepare queries:
$f1 = array();
......
......@@ -50,7 +50,19 @@ function category_expire_threshold($cid) {
// return default comment status of category $cid:
function category_comment($cid) {
$category = category_get_object("cid", $cid);
return $category->comment;
return $category->comment ? $category->comment : 0;
}
// return default promote status of category $cid:
function category_promote($cid) {
$category = category_get_object("cid", $cid);
return $category->promote ? $category->promote : 0;
}
// return default submission status of category $cid:
function category_submission($cid) {
$category = category_get_object("cid", $cid);
return $category->submission ? $category->submission : 0;
}
// return linked string with name of category $cid:
......
......@@ -4,7 +4,7 @@
if (variable_get(dev_timing, 0)) timer_start();
$result = db_query("SELECT nid FROM node WHERE type = 'story' AND status = '$status[posted]' AND timestamp <= ". ($date > 0 ? $date : time()) ." ". ($category ? "AND cid = '$category'" : "") ." ". ($topic ? "AND tid = '$topic'" : "") ." ORDER BY timestamp DESC LIMIT ". ($user->nodes ? $user->nodes : 10));
$result = db_query("SELECT nid FROM node WHERE promote = '1' AND status = '$status[posted]' AND timestamp <= ". ($date > 0 ? $date : time()) ." ". ($category ? "AND cid = '$category'" : "") ." ". ($topic ? "AND tid = '$topic'" : "") ." ORDER BY timestamp DESC LIMIT ". ($user->nodes ? $user->nodes : 10));
$theme->header();
while ($node = db_fetch_object($result)) {
......
......@@ -157,7 +157,7 @@ function book_form($edit = array()) {
}
function book_save($edit) {
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "book", comment => category_comment($edit[cid]))), array(userid => $edit[userid])));
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "book")), array(userid => $edit[userid])));
}
function book_tree($parent = "", $depth = 0) {
......
......@@ -157,7 +157,7 @@ function book_form($edit = array()) {
}
function book_save($edit) {
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "book", comment => category_comment($edit[cid]))), array(userid => $edit[userid])));
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "book")), array(userid => $edit[userid])));
}
function book_tree($parent = "", $depth = 0) {
......
......@@ -27,7 +27,8 @@ function node_admin_view($id) {
$output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
$output .= "<B>Author:</B><BR>". format_username($node->userid) ."<P>\n";
$output .= "<B>Status:</B><BR>". $rstatus[$node->status] ."<P>\n";
$output .= "<B>Comment:</B><BR>". comment_status($node->comment) ."<P>\n";
$output .= "<B>Comment:</B><BR>". node_comment_status($node->comment) ."<P>\n";
$output .= "<B>Promote:</B><BR>". node_promote_status($node->promote) ."<P>\n";
$output .= "<B>Date:</B><BR>". format_date($node->timestamp) ."<P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Edit node\">\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Delete node\">\n";
......@@ -44,13 +45,15 @@ function node_admin_edit($id) {
foreach (array($node->userid => $node->author, $user->userid => $user->id) as $value=>$key) $author .= " <OPTION VALUE=\"$key\"". (($node->author == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (array(format_date($node->timestamp) ." (original)" => $node->timestamp, format_date(time()) ." (current)" => time()) as $value=>$key) $timestamp .= " <OPTION VALUE=\"$key\"". (($node->timestamp == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (node_status($node) as $value) $display .= " <OPTION VALUE=\"". $status[$value] ."\"". (($node->status == $status[$value]) ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (comment_status() as $key=>$value) $comment .= " <OPTION VALUE=\"$key\"". ($node->comment == $key ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (node_comment_status() as $key=>$value) $comment .= " <OPTION VALUE=\"$key\"". ($node->comment == $key ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (node_promote_status() as $key=>$value) $promote .= " <OPTION VALUE=\"$key\"". ($node->promote == $key ? " SELECTED" : "") .">$value</OPTION>\n";
$output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
$output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
$output .= "<B>Author:</B><BR><SELECT NAME=\"edit[author]\">$author</SELECT><P>\n";
$output .= "<B>Status:</B><BR><SELECT NAME=\"edit[status]\">$display</SELECT><P>\n";
$output .= "<B>Comment:</B><BR><SELECT NAME=\"edit[comment]\">$comment</SELECT><P>\n";
$output .= "<B>Promote:</B><BR><SELECT NAME=\"edit[promote]\">$promote</SELECT><P>\n";
$output .= "<B>Date:</B><BR><SELECT NAME=\"edit[timestamp]\">$timestamp</SELECT><P>\n";
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$node->nid\">\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"View node\">\n";
......
......@@ -27,7 +27,8 @@ function node_admin_view($id) {
$output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
$output .= "<B>Author:</B><BR>". format_username($node->userid) ."<P>\n";
$output .= "<B>Status:</B><BR>". $rstatus[$node->status] ."<P>\n";
$output .= "<B>Comment:</B><BR>". comment_status($node->comment) ."<P>\n";
$output .= "<B>Comment:</B><BR>". node_comment_status($node->comment) ."<P>\n";
$output .= "<B>Promote:</B><BR>". node_promote_status($node->promote) ."<P>\n";
$output .= "<B>Date:</B><BR>". format_date($node->timestamp) ."<P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Edit node\">\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Delete node\">\n";
......@@ -44,13 +45,15 @@ function node_admin_edit($id) {
foreach (array($node->userid => $node->author, $user->userid => $user->id) as $value=>$key) $author .= " <OPTION VALUE=\"$key\"". (($node->author == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (array(format_date($node->timestamp) ." (original)" => $node->timestamp, format_date(time()) ." (current)" => time()) as $value=>$key) $timestamp .= " <OPTION VALUE=\"$key\"". (($node->timestamp == $key) ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (node_status($node) as $value) $display .= " <OPTION VALUE=\"". $status[$value] ."\"". (($node->status == $status[$value]) ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (comment_status() as $key=>$value) $comment .= " <OPTION VALUE=\"$key\"". ($node->comment == $key ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (node_comment_status() as $key=>$value) $comment .= " <OPTION VALUE=\"$key\"". ($node->comment == $key ? " SELECTED" : "") .">$value</OPTION>\n";
foreach (node_promote_status() as $key=>$value) $promote .= " <OPTION VALUE=\"$key\"". ($node->promote == $key ? " SELECTED" : "") .">$value</OPTION>\n";
$output .= "<FORM ACTION=\"admin.php?mod=node&id=$node->nid\" METHOD=\"post\">\n";
$output .= "<B>Title:</B><BR>". check_output($node->title) ."<P>\n";
$output .= "<B>Author:</B><BR><SELECT NAME=\"edit[author]\">$author</SELECT><P>\n";
$output .= "<B>Status:</B><BR><SELECT NAME=\"edit[status]\">$display</SELECT><P>\n";
$output .= "<B>Comment:</B><BR><SELECT NAME=\"edit[comment]\">$comment</SELECT><P>\n";
$output .= "<B>Promote:</B><BR><SELECT NAME=\"edit[promote]\">$promote</SELECT><P>\n";
$output .= "<B>Date:</B><BR><SELECT NAME=\"edit[timestamp]\">$timestamp</SELECT><P>\n";
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$node->nid\">\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"View node\">\n";
......
......@@ -36,9 +36,11 @@ function page_form($edit = array()) {
$output .= "<FORM ACTION=\"admin.php?mod=page\" METHOD=\"post\">\n";
$output .= "<B>Name:</B><BR>\n";
$output .= "<B>Subject:</B><BR>\n";
$output .= "<INPUT NAME=\"edit[title]\" SIZE=\"55\" VALUE=\"". check_textfield($edit[title]) ."\"><P>\n";
$output .= structure_form("page", $edit);
$output .= "<B>Body:</B><BR>\n";
$output .= "<TEXTAREA NAME=\"edit[body]\" COLS=\"55\" ROWS=\"10\" WRAP=\"virtual\">". check_textarea($edit[body]) ."</TEXTAREA><P>\n";
......
......@@ -36,9 +36,11 @@ function page_form($edit = array()) {
$output .= "<FORM ACTION=\"admin.php?mod=page\" METHOD=\"post\">\n";
$output .= "<B>Name:</B><BR>\n";
$output .= "<B>Subject:</B><BR>\n";
$output .= "<INPUT NAME=\"edit[title]\" SIZE=\"55\" VALUE=\"". check_textfield($edit[title]) ."\"><P>\n";
$output .= structure_form("page", $edit);
$output .= "<B>Body:</B><BR>\n";
$output .= "<TEXTAREA NAME=\"edit[body]\" COLS=\"55\" ROWS=\"10\" WRAP=\"virtual\">". check_textarea($edit[body]) ."</TEXTAREA><P>\n";
......
......@@ -106,7 +106,7 @@ function story_form($edit = array()) {
}
function story_save($edit) {
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story", comment => category_comment($edit[cid]))), array(userid => $edit[userid])));
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story")), array(userid => $edit[userid])));
}
function story_block() {
......
......@@ -106,7 +106,7 @@ function story_form($edit = array()) {
}
function story_save($edit) {
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story", comment => category_comment($edit[cid]))), array(userid => $edit[userid])));
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story")), array(userid => $edit[userid])));
}
function story_block() {
......
......@@ -2,15 +2,13 @@
$module = array("admin" => "structure_admin");
$mstatus = array("post new submissions", "moderate new submissions");
function content_types($name, $module) {
global $types;
if ($module[type]) $types[$name] = $name;
}
function category_form($edit = array()) {
global $types, $mstatus;
global $types;
$threshold_post = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100);
$threshold_dump = array(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -20, -25, -30);
......@@ -29,25 +27,26 @@ function category_form($edit = array()) {
$output .= "<SELECT NAME=\"edit[type]\">$options1</SELECT><BR>\n";
$output .= "<SMALL><I>The content type to bind or associate this category with.</I></SMALL><P>\n";
$output .= "<B>Comment settings:</B><BR>\n";
foreach (comment_status() as $key=>$value) $options2 .= "<OPTION VALUE=\"$key\"". ($edit[comment] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<B>Comment:</B><BR>\n";
foreach (node_comment_status() as $key=>$value) $options2 .= "<OPTION VALUE=\"$key\"". ($edit[comment] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[comment]\">$options2</SELECT><BR>\n";
$output .= "<SMALL><I>Allow or dissallow users to post comments in this category.</I></SMALL><P>\n";
$output .= "<B>Submission settings:</B><BR>\n";
foreach ($mstatus as $key=>$value) $options3 .= "<OPTION VALUE=\"$key\"". ($edit[submission] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[submission]\">$options3</SELECT><BR>\n";
$output .= "<SMALL><I>What to do with new submissions in this category.</I></SMALL><P>\n";
$output .= "<B>Post, dump and expiration threshold:</B><BR>\n";
foreach ($threshold_post as $value) $options4 .= "<OPTION VALUE=\"$value\"". ($edit[post] == $value ? " SELECTED" : "") .">". format_plural($value, "point", "points") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[post]\">$options4</SELECT>\n";
foreach ($threshold_dump as $value) $options5 .= "<OPTION VALUE=\"$value\"". ($edit[dump] == $value ? " SELECTED" : "") .">". format_plural($value, "point", "points") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[dump]\">$options5</SELECT>\n";
foreach ($threshold_expire as $value) $options6 .= "<OPTION VALUE=\"$value\"". ($edit[expire] == $value ? " SELECTED" : "") .">". format_plural($value, "vote", "votes") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[expire]\">$options6</SELECT><BR>\n";
$output .= "<SMALL><I>Specify the post, dump and expiration threshold for moderation purpose.</I></SMALL><P>\n";
$output .= "<SMALL><I>By default, allow or dissallow users to post comments in this category.</I></SMALL><P>\n";
$output .= "<B>Promote:</B><BR>\n";
foreach (node_promote_status() as $key=>$value) $options3 .= "<OPTION VALUE=\"$key\"". ($edit[promote] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[promote]\">$options3</SELECT><BR>\n";
$output .= "<SMALL><I>By default, promote new submissions in this category to the front page.</I></SMALL><P>\n";
$output .= "<B>Submission:</B><BR>\n";
foreach (node_submission_status() as $key=>$value) $options4 .= "<OPTION VALUE=\"$key\"". ($edit[submission] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>";
$output .= "<SELECT NAME=\"edit[submission]\">$options4</SELECT><BR>\n";
foreach ($threshold_post as $value) $options5 .= "<OPTION VALUE=\"$value\"". ($edit[post] == $value ? " SELECTED" : "") .">". format_plural($value, "point", "points") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[post]\">$options5</SELECT>\n";
foreach ($threshold_dump as $value) $options6 .= "<OPTION VALUE=\"$value\"". ($edit[dump] == $value ? " SELECTED" : "") .">". format_plural($value, "point", "points") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[dump]\">$options6</SELECT>\n";
foreach ($threshold_expire as $value) $options7 .= "<OPTION VALUE=\"$value\"". ($edit[expire] == $value ? " SELECTED" : "") .">". format_plural($value, "vote", "votes") ."</OPTION>";
$output .= "<SELECT NAME=\"edit[expire]\">$options7</SELECT><BR>\n";
$output .= "<SMALL><I>What to do with new submissions in this category?<BR>Specify the post, dump and expiration threshold for moderation purpose.</I></SMALL><P>\n";
if ($edit[cid]) {
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[cid]\" VALUE=\"$edit[cid]\">\n";
......@@ -64,14 +63,12 @@ function category_form($edit = array()) {
}
function category_overview() {
global $mstatus;
$result = db_query("SELECT * FROM category ORDER BY name");
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR><TH>name</TH><TH>type</TH><TH>comments</TH><TH>submissions</TH><TH>operations</TH></TR>\n";
$output .= " <TR><TH>name</TH><TH>type</TH><TH>comment</TH><TH>promote</TH><TH>submissions</TH><TH>operations</TH></TR>\n";
while ($category = db_fetch_object($result)) {
$output .= " <TR><TD>". check_output($category->name) ."</TD><TD>". check_output($category->type) ."</TD><TD>". comment_status($category->comment) ."</TD><TD>". check_output($mstatus[$category->submission]) ."". ($category->submission ? "<BR><SMALL>post: $category->post, dump: $category->dump, expire: $category->expire</SMALL>" : "") ."</TD><TD><A HREF=\"admin.php?mod=structure&type=category&op=edit&id=$category->cid\">edit category</A></TD></TR>\n";
$output .= " <TR><TD>". check_output($category->name) ."</TD><TD>". check_output($category->type) ."</TD><TD>". node_comment_status($category->comment) ."</TD><TD>". node_promote_status($category->promote) ."</TD><TD>". node_submission_status($category->submission) ."". ($category->submission ? "<BR><SMALL>post: $category->post, dump: $category->dump, expire: $category->expire</SMALL>" : "") ."</TD><TD><A HREF=\"admin.php?mod=structure&type=category&op=edit&id=$category->cid\">edit category</A></TD></TR>\n";
}
$output .= "</TABLE>\n";
return $output;
......
# 19/04/2001:
ALTER TABLE node ADD comment int(2) DEFAULT '1' NOT NULL;
ALTER TABLE node ADD promote int(2) DEFAULT '1' NOT NULL;
ALTER TABLE category ADD promote int(2) unsigned DEFAULT '0' NOT NULL;
CREATE TABLE cvs (
user varchar(32) DEFAULT '' NOT NULL,
......
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