From cccb132c81e82cc01ca7f014d185c1ecce864377 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Sat, 21 Apr 2001 14:19:20 +0000 Subject: [PATCH] - 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. --- includes/comment.inc | 5 ---- includes/node.inc | 20 ++++++++++++++-- includes/structure.inc | 14 +++++++++++- index.php | 2 +- modules/book.module | 2 +- modules/book/book.module | 2 +- modules/node.module | 7 ++++-- modules/node/node.module | 7 ++++-- modules/page.module | 4 +++- modules/page/page.module | 4 +++- modules/story.module | 2 +- modules/story/story.module | 2 +- modules/structure.module | 47 ++++++++++++++++++-------------------- updates/2.00-to-x.xx.sql | 2 ++ 14 files changed, 76 insertions(+), 44 deletions(-) diff --git a/includes/comment.inc b/includes/comment.inc index 6d6290f1eed2..0d100353063b 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -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"); diff --git a/includes/node.inc b/includes/node.inc index 733c38da084e..aa401cea836b 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -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(); diff --git a/includes/structure.inc b/includes/structure.inc index 94c14ad6dfbe..aabb9d34a1cf 100644 --- a/includes/structure.inc +++ b/includes/structure.inc @@ -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: diff --git a/index.php b/index.php index 51b78e374042..e4bfe258d802 100644 --- a/index.php +++ b/index.php @@ -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)) { diff --git a/modules/book.module b/modules/book.module index 355366e3edb5..8fe3aea9f699 100644 --- a/modules/book.module +++ b/modules/book.module @@ -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) { diff --git a/modules/book/book.module b/modules/book/book.module index 355366e3edb5..8fe3aea9f699 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -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) { diff --git a/modules/node.module b/modules/node.module index 58b77fd994d9..3c377a2a41b4 100644 --- a/modules/node.module +++ b/modules/node.module @@ -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"; diff --git a/modules/node/node.module b/modules/node/node.module index 58b77fd994d9..3c377a2a41b4 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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"; diff --git a/modules/page.module b/modules/page.module index 3886cf04b2f3..9cf760933732 100644 --- a/modules/page.module +++ b/modules/page.module @@ -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"; diff --git a/modules/page/page.module b/modules/page/page.module index 3886cf04b2f3..9cf760933732 100644 --- a/modules/page/page.module +++ b/modules/page/page.module @@ -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"; diff --git a/modules/story.module b/modules/story.module index 88550443a48e..484574d35f8e 100644 --- a/modules/story.module +++ b/modules/story.module @@ -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() { diff --git a/modules/story/story.module b/modules/story/story.module index 88550443a48e..484574d35f8e 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -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() { diff --git a/modules/structure.module b/modules/structure.module index 5fa361bd9b40..8bcc21978257 100644 --- a/modules/structure.module +++ b/modules/structure.module @@ -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; diff --git a/updates/2.00-to-x.xx.sql b/updates/2.00-to-x.xx.sql index 71e697b7a157..18e409eb9721 100644 --- a/updates/2.00-to-x.xx.sql +++ b/updates/2.00-to-x.xx.sql @@ -1,5 +1,7 @@ # 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, -- GitLab