diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-04-19 19:59:48 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-04-19 19:59:48 +0000 |
commit | 3f1979aa3cfa2d50789e88bd0a857dec6babb44b (patch) | |
tree | 00a5170b8db220163950343292e0e7f966c80549 | |
parent | a6e6dfb9219ebea34331ad46c9c43d53f7c3ca6f (diff) | |
download | brdo-3f1979aa3cfa2d50789e88bd0a857dec6babb44b.tar.gz brdo-3f1979aa3cfa2d50789e88bd0a857dec6babb44b.tar.bz2 |
- Addition: made it so that comments can be enabled/disabled on
a node per node basis, rather then on a category per category
basis. The default settings for each individual category can
be changed though.
Example: it can be setup so that - by default - all stories
posted to the category "article" will have comments enabled
but stories submitted to "announcement" not.
Different configuration schemes can easily be added later.
Requires a SQL update, see 2.00-to-x.xx.sql/database.mysql.
- Addition: made submit.php only use categories that users can
actually submit new content to.
-rw-r--r-- | database/database.mysql | 9 | ||||
-rw-r--r-- | includes/comment.inc | 5 | ||||
-rw-r--r-- | includes/node.inc | 6 | ||||
-rw-r--r-- | includes/structure.inc | 6 | ||||
-rw-r--r-- | modules/book.module | 2 | ||||
-rw-r--r-- | modules/book/book.module | 2 | ||||
-rw-r--r-- | modules/node.module | 9 | ||||
-rw-r--r-- | modules/node/node.module | 9 | ||||
-rw-r--r-- | modules/story.module | 2 | ||||
-rw-r--r-- | modules/story/story.module | 2 | ||||
-rw-r--r-- | modules/structure.module | 9 | ||||
-rw-r--r-- | submit.php | 4 |
12 files changed, 42 insertions, 23 deletions
diff --git a/database/database.mysql b/database/database.mysql index c3d577758..0e80148c1 100644 --- a/database/database.mysql +++ b/database/database.mysql @@ -195,8 +195,10 @@ CREATE TABLE modules ( DROP TABLE IF EXISTS node; CREATE TABLE node ( nid int(10) unsigned DEFAULT '0' NOT NULL auto_increment, - lid int(10) DEFAULT '0' NOT NULL, - pid int(10) DEFAULT '0' NOT NULL, + lid int(10) unsigned DEFAULT '0' NOT NULL, + pid int(10) unsigned DEFAULT '0' NOT NULL, + cid int(10) unsigned DEFAULT '0' NOT NULL, + tid int(10) unsigned DEFAULT '0' NOT NULL, log text NOT NULL, type varchar(16) DEFAULT '' NOT NULL, title varchar(128) DEFAULT '' NOT NULL, @@ -204,9 +206,8 @@ CREATE TABLE node ( votes int(11) DEFAULT '0' NOT NULL, author int(6) DEFAULT '0' NOT NULL, status int(4) DEFAULT '1' NOT NULL, + comment int(2) DEFAULT '1' NOT NULL, timestamp int(11) DEFAULT '0' NOT NULL, - cid int(10) unsigned DEFAULT '0' NOT NULL, - tid int(10) unsigned DEFAULT '0' NOT NULL, KEY type (lid,type), KEY author (author), KEY title (title,type), diff --git a/includes/comment.inc b/includes/comment.inc index 0d1003530..6d6290f1e 100644 --- a/includes/comment.inc +++ b/includes/comment.inc @@ -145,6 +145,11 @@ 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 9a8b9f020..733c38da0 100644 --- a/includes/node.inc +++ b/includes/node.inc @@ -6,7 +6,7 @@ $rstatus = array(0 => dumped, 1 => expired, 2 => queued, 3 => posted); function _node_get($field, $value) { $result = db_query("SELECT lid, type FROM node WHERE $field = '$value'"); if ($node = db_fetch_object($result)) { - return db_query("SELECT n.*, l.*, c.name AS category, c.comment, t.name AS topic, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id LEFT JOIN category c ON n.cid = c.cid LEFT JOIN topic t ON n.tid = t.tid WHERE n.$field = '$value' ORDER BY n.timestamp DESC"); + return db_query("SELECT n.*, l.*, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id WHERE n.$field = '$value' ORDER BY n.timestamp DESC"); } } @@ -39,7 +39,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, timestamp); + $rows = array(nid, pid, lid, cid, tid, log, type, title, score, votes, author, status, comment, timestamp); if ($node[nid] > 0) { $n = node_get_object("nid", $node[nid]); @@ -74,7 +74,7 @@ function node_save($node) { 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, timestamp => time()), $node); + $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); // prepare queries: $f1 = array(); diff --git a/includes/structure.inc b/includes/structure.inc index 6d6655a3e..94c14ad6d 100644 --- a/includes/structure.inc +++ b/includes/structure.inc @@ -47,6 +47,12 @@ function category_expire_threshold($cid) { return $category->threshold; } +// return default comment status of category $cid: +function category_comment($cid) { + $category = category_get_object("cid", $cid); + return $category->comment; +} + // return linked string with name of category $cid: function category_name($cid) { $category = category_get_object("cid", $cid); diff --git a/modules/book.module b/modules/book.module index 8fe3aea9f..355366e3e 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")), array(userid => $edit[userid]))); + node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "book", comment => category_comment($edit[cid]))), array(userid => $edit[userid]))); } function book_tree($parent = "", $depth = 0) { diff --git a/modules/book/book.module b/modules/book/book.module index 8fe3aea9f..355366e3e 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")), array(userid => $edit[userid]))); + node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "book", comment => category_comment($edit[cid]))), array(userid => $edit[userid]))); } function book_tree($parent = "", $depth = 0) { diff --git a/modules/node.module b/modules/node.module index 7d0a5b3a5..58b77fd99 100644 --- a/modules/node.module +++ b/modules/node.module @@ -27,6 +27,7 @@ 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>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"; @@ -42,12 +43,14 @@ 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) $statuz .= " <OPTION VALUE=\"". $status[$value] ."\"". (($node->status == $status[$value]) ? " 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"; $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]\">$statuz</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>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"; @@ -96,7 +99,7 @@ function node_admin() { print node_listing(node_query()); break; case "Save node": - print status(node_save($edit)); + node_save($edit); print node_admin_view($id); break; case "View node": diff --git a/modules/node/node.module b/modules/node/node.module index 7d0a5b3a5..58b77fd99 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -27,6 +27,7 @@ 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>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"; @@ -42,12 +43,14 @@ 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) $statuz .= " <OPTION VALUE=\"". $status[$value] ."\"". (($node->status == $status[$value]) ? " 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"; $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]\">$statuz</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>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"; @@ -96,7 +99,7 @@ function node_admin() { print node_listing(node_query()); break; case "Save node": - print status(node_save($edit)); + node_save($edit); print node_admin_view($id); break; case "View node": diff --git a/modules/story.module b/modules/story.module index 484574d35..88550443a 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")), array(userid => $edit[userid]))); + node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story", comment => category_comment($edit[cid]))), array(userid => $edit[userid]))); } function story_block() { diff --git a/modules/story/story.module b/modules/story/story.module index 484574d35..88550443a 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")), array(userid => $edit[userid]))); + node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story", comment => category_comment($edit[cid]))), array(userid => $edit[userid]))); } function story_block() { diff --git a/modules/structure.module b/modules/structure.module index 6e921ec0d..5fa361bd9 100644 --- a/modules/structure.module +++ b/modules/structure.module @@ -2,7 +2,6 @@ $module = array("admin" => "structure_admin"); -$cstatus = array("disabled", "enabled"); $mstatus = array("post new submissions", "moderate new submissions"); function content_types($name, $module) { @@ -11,7 +10,7 @@ function content_types($name, $module) { } function category_form($edit = array()) { - global $types, $cstatus, $mstatus; + global $types, $mstatus; $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); @@ -31,7 +30,7 @@ function category_form($edit = array()) { $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 ($cstatus as $key=>$value) $options2 .= "<OPTION VALUE=\"$key\"". ($edit[comment] == $key ? " SELECTED" : "") .">". check_select($value) ."</OPTION>"; + foreach (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"; @@ -65,14 +64,14 @@ function category_form($edit = array()) { } function category_overview() { - global $cstatus, $mstatus; + 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"; while ($category = db_fetch_object($result)) { - $output .= " <TR><TD>". check_output($category->name) ."</TD><TD>". check_output($category->type) ."</TD><TD>". check_output($cstatus[$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>". 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 .= "</TABLE>\n"; return $output; diff --git a/submit.php b/submit.php index b2e4231ff..89e9b9769 100644 --- a/submit.php +++ b/submit.php @@ -15,7 +15,9 @@ if ($user->id) { $output .= "<FORM ACTION=\"submit.php\" METHOD=\"get\">\n"; $output .= "<B>". t("Category") .":</B><BR>\n"; - while ($category = db_fetch_object($result)) $options .= "<OPTION VALUE=\"$category->type\">$category->name</OPTION>"; + while ($category = db_fetch_object($result)) { + if (module_hook($category->type, "user")) $options .= "<OPTION VALUE=\"$category->type\">$category->name</OPTION>"; + } $output .= "<SELECT NAME=\"mod\">$options</SELECT><P>\n"; $output .= "<INPUT NAME=\"op\" TYPE=\"submit\" VALUE=\"". t("Next step") ."\">\n"; |