Commit 3f1979aa authored by Dries's avatar Dries

- 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.
parent a6e6dfb9
......@@ -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),
......
......@@ -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");
......
......@@ -6,7 +6,7 @@
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();
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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) {
......
......@@ -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":
......
......@@ -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":
......
......@@ -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() {
......
......@@ -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() {
......
......@@ -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;
......
......@@ -15,7 +15,9 @@
$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";
......
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