Commit 831ee213 authored by Kjartan's avatar Kjartan

- Renamed "form.admin" to "form admin".

- Added node_admin_settings() to let users set node defaults.
    * Added _nodeapi("conf")
- Modified form_checkbox() to unset options. (Modified the patch from Ax.)
- Removed the _save() hook.
- Fixed a logical flaw in field_get() and field_set() which would break
  moderation.
- Moved some admin menus around and cleaned up some typos.
parent 3aba0fda
...@@ -723,7 +723,7 @@ function form_item($title, $value, $description = 0) { ...@@ -723,7 +723,7 @@ function form_item($title, $value, $description = 0) {
} }
function form_checkbox($title, $name, $value = 1, $checked = 0, $description = 0) { function form_checkbox($title, $name, $value = 1, $checked = 0, $description = 0) {
return form_item(0, "<input type=\"checkbox\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") ." /> $title", $description); return form_hidden($name, 0) . form_item(0, "<input type=\"checkbox\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") ." /> $title", $description);
} }
function form_textfield($title, $name, $value, $size, $maxlength, $description = 0) { function form_textfield($title, $name, $value, $size, $maxlength, $description = 0) {
...@@ -819,7 +819,7 @@ function l($text, $url, $attributes = array(), $query = NULL) { ...@@ -819,7 +819,7 @@ function l($text, $url, $attributes = array(), $query = NULL) {
} }
function field_get($string, $name) { function field_get($string, $name) {
ereg(",$name=([^,]+)", ", $string", $regs); ereg(",?$name=([^,]+)", ", $string", $regs);
return $regs[1]; return $regs[1];
} }
...@@ -839,7 +839,7 @@ function link_page() { ...@@ -839,7 +839,7 @@ function link_page() {
} }
else { else {
$links = module_invoke_all("link", "page"); $links = module_invoke_all("link", "page");
array_unshift($links, "<a href=\"$base_url\" title=\"". t("Return to the main page.") ."\">". t("home") ."</a>"); array_unshift($links, "<a href=\"$base_url/\" title=\"". t("Return to the main page.") ."\">". t("home") ."</a>");
return $links; return $links;
} }
} }
......
...@@ -67,50 +67,6 @@ function blog_user($type, &$edit, &$user) { ...@@ -67,50 +67,6 @@ function blog_user($type, &$edit, &$user) {
} }
} }
function blog_save($op, $node) {
if ($op == "approve") {
return array("promote" => 1);
}
if ($op == "create") {
if (user_access("administer nodes")) {
/*
** When an administrator creates blog entries through the admin
** pages, they will not be changed unless explicitly specified.
*/
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
}
else {
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "promote" => 0, "moderate" => 1, "status" => 1);
}
}
if ($op == "decline") {
return array("promote" => 0);
}
if ($op == "update") {
if (user_access("administer nodes")) {
/*
** When an administrator updates blog entries through the admin
** pages, they will not be changed unless explicitly specified.
*/
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
}
else {
/*
** Updating your own blog entry will demote it (if promoted),
** and will queue it in the moderation queue for promotion.
*/
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "promote" => 0, "moderate" => 1, "score" => 0, "votes" => 0, "users" => 0);
}
}
}
function blog_help() { function blog_help() {
?> ?>
<p>Drupal's blog module allows registered users to maintain an online blog, often referred to as an online journal or diary. They can be filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption. It is made up of individual entries that are timestamped and are typically viewed by day as you would a diary. Blogs often contain links to things you've seen, or agree/disagree with. A typical example of a long term blog can be seen at <a href="http://www.scripting.com/">http://www.scripting.com/</a>.</p> <p>Drupal's blog module allows registered users to maintain an online blog, often referred to as an online journal or diary. They can be filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption. It is made up of individual entries that are timestamped and are typically viewed by day as you would a diary. Blogs often contain links to things you've seen, or agree/disagree with. A typical example of a long term blog can be seen at <a href="http://www.scripting.com/">http://www.scripting.com/</a>.</p>
...@@ -296,4 +252,10 @@ function blog_block($op = "list", $delta = 0) { ...@@ -296,4 +252,10 @@ function blog_block($op = "list", $delta = 0) {
} }
} }
function blog_validate(&$node) {
// Make sure all fields are set properly:
$node->body = filter($node->body);
$node->teaser = filter($node->teaser);
}
?> ?>
...@@ -67,50 +67,6 @@ function blog_user($type, &$edit, &$user) { ...@@ -67,50 +67,6 @@ function blog_user($type, &$edit, &$user) {
} }
} }
function blog_save($op, $node) {
if ($op == "approve") {
return array("promote" => 1);
}
if ($op == "create") {
if (user_access("administer nodes")) {
/*
** When an administrator creates blog entries through the admin
** pages, they will not be changed unless explicitly specified.
*/
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
}
else {
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "promote" => 0, "moderate" => 1, "status" => 1);
}
}
if ($op == "decline") {
return array("promote" => 0);
}
if ($op == "update") {
if (user_access("administer nodes")) {
/*
** When an administrator updates blog entries through the admin
** pages, they will not be changed unless explicitly specified.
*/
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
}
else {
/*
** Updating your own blog entry will demote it (if promoted),
** and will queue it in the moderation queue for promotion.
*/
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "promote" => 0, "moderate" => 1, "score" => 0, "votes" => 0, "users" => 0);
}
}
}
function blog_help() { function blog_help() {
?> ?>
<p>Drupal's blog module allows registered users to maintain an online blog, often referred to as an online journal or diary. They can be filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption. It is made up of individual entries that are timestamped and are typically viewed by day as you would a diary. Blogs often contain links to things you've seen, or agree/disagree with. A typical example of a long term blog can be seen at <a href="http://www.scripting.com/">http://www.scripting.com/</a>.</p> <p>Drupal's blog module allows registered users to maintain an online blog, often referred to as an online journal or diary. They can be filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption. It is made up of individual entries that are timestamped and are typically viewed by day as you would a diary. Blogs often contain links to things you've seen, or agree/disagree with. A typical example of a long term blog can be seen at <a href="http://www.scripting.com/">http://www.scripting.com/</a>.</p>
...@@ -296,4 +252,10 @@ function blog_block($op = "list", $delta = 0) { ...@@ -296,4 +252,10 @@ function blog_block($op = "list", $delta = 0) {
} }
} }
function blog_validate(&$node) {
// Make sure all fields are set properly:
$node->body = filter($node->body);
$node->teaser = filter($node->teaser);
}
?> ?>
...@@ -57,48 +57,6 @@ function book_access($op, $node) { ...@@ -57,48 +57,6 @@ function book_access($op, $node) {
} }
} }
function book_save($op, $node) {
global $user;
if ($op == "approve") {
return array("status" => 1);
}
if ($op == "create") {
if (user_access("administer nodes")) {
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "parent", "weight", "log");
}
else {
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "moderate" => 1, "parent", "promote" => 0, "status" => 1, "weight", "log");
}
}
if ($op == "decline") {
return array("status" => 0);
}
if ($op == "update") {
if (user_access("administer nodes")) {
/*
** If a node administrator updates a book page, we don't create a
** new revision unless we are explicitly instructed to.
*/
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "parent", "weight", "log");
}
else {
/*
** If a regular user updates a book page, we always create a new
** revision. All new revisions have to be approved (moderation)
** and are not promoted by default. See also: book_load().
*/
return array("body" => filter($node->body), "teaser" => filter($node->body), "created" => time(), "format", "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight", "log");
}
}
}
function book_link($type, $node = 0, $main = 0) { function book_link($type, $node = 0, $main = 0) {
if ($type == "page" && user_access("access content")) { if ($type == "page" && user_access("access content")) {
$links[] = l(t("collaborative book"), "book", array("title" => t("Read and contribute to the collaborative books."))); $links[] = l(t("collaborative book"), "book", array("title" => t("Read and contribute to the collaborative books.")));
...@@ -166,20 +124,10 @@ function book_load($node) { ...@@ -166,20 +124,10 @@ function book_load($node) {
} }
function book_insert($node) { function book_insert($node) {
if (!user_access("administer nodes")) {
$node->format = 0;
$node->weight = 0;
}
db_query("INSERT INTO book (nid, format, parent, weight, log) VALUES ('%d', '%d', '%d', '%d', '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log); db_query("INSERT INTO book (nid, format, parent, weight, log) VALUES ('%d', '%d', '%d', '%d', '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log);
} }
function book_update($node) { function book_update($node) {
if (!user_access("administer nodes")) {
$node->format = 0;
$node->weight = 0;
}
db_query("UPDATE book SET format = '%d', parent = '%d', weight = '%d', log = '%s' WHERE nid = '%d'", $node->format, $node->parent, $node->weight, $node->log, $node->nid); db_query("UPDATE book SET format = '%d', parent = '%d', weight = '%d', log = '%s' WHERE nid = '%d'", $node->format, $node->parent, $node->weight, $node->log, $node->nid);
} }
...@@ -187,12 +135,23 @@ function book_delete(&$node) { ...@@ -187,12 +135,23 @@ function book_delete(&$node) {
db_query("DELETE FROM book WHERE nid = '%d'", $node->nid); db_query("DELETE FROM book WHERE nid = '%d'", $node->nid);
} }
function book_validate($node, &$error) { function book_validate(&$node) {
if ($node->format && user_access("create php content")) {
// Make sure user has permissions to create php content: // Do not filter PHP code, do not auto-extract a teaser
$node->format = $node->format && user_access("create php content"); $node->teaser = $node->body;
}
else {
$node->format = 0;
$node->body = filter($node->body);
$node->teaser = filter($node->body);
}
return $node; // Set default values for non administrators:
if (!user_access("administer nodes")) {
$node->format = 0;
$node->weight = 0;
$node->revision = 1;
}
} }
function book_form(&$node, &$help, &$error) { function book_form(&$node, &$help, &$error) {
......
...@@ -57,48 +57,6 @@ function book_access($op, $node) { ...@@ -57,48 +57,6 @@ function book_access($op, $node) {
} }
} }
function book_save($op, $node) {
global $user;
if ($op == "approve") {
return array("status" => 1);
}
if ($op == "create") {
if (user_access("administer nodes")) {
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "parent", "weight", "log");
}
else {
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "moderate" => 1, "parent", "promote" => 0, "status" => 1, "weight", "log");
}
}
if ($op == "decline") {
return array("status" => 0);
}
if ($op == "update") {
if (user_access("administer nodes")) {
/*
** If a node administrator updates a book page, we don't create a
** new revision unless we are explicitly instructed to.
*/
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "parent", "weight", "log");
}
else {
/*
** If a regular user updates a book page, we always create a new
** revision. All new revisions have to be approved (moderation)
** and are not promoted by default. See also: book_load().
*/
return array("body" => filter($node->body), "teaser" => filter($node->body), "created" => time(), "format", "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight", "log");
}
}
}
function book_link($type, $node = 0, $main = 0) { function book_link($type, $node = 0, $main = 0) {
if ($type == "page" && user_access("access content")) { if ($type == "page" && user_access("access content")) {
$links[] = l(t("collaborative book"), "book", array("title" => t("Read and contribute to the collaborative books."))); $links[] = l(t("collaborative book"), "book", array("title" => t("Read and contribute to the collaborative books.")));
...@@ -166,20 +124,10 @@ function book_load($node) { ...@@ -166,20 +124,10 @@ function book_load($node) {
} }
function book_insert($node) { function book_insert($node) {
if (!user_access("administer nodes")) {
$node->format = 0;
$node->weight = 0;
}
db_query("INSERT INTO book (nid, format, parent, weight, log) VALUES ('%d', '%d', '%d', '%d', '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log); db_query("INSERT INTO book (nid, format, parent, weight, log) VALUES ('%d', '%d', '%d', '%d', '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log);
} }
function book_update($node) { function book_update($node) {
if (!user_access("administer nodes")) {
$node->format = 0;
$node->weight = 0;
}
db_query("UPDATE book SET format = '%d', parent = '%d', weight = '%d', log = '%s' WHERE nid = '%d'", $node->format, $node->parent, $node->weight, $node->log, $node->nid); db_query("UPDATE book SET format = '%d', parent = '%d', weight = '%d', log = '%s' WHERE nid = '%d'", $node->format, $node->parent, $node->weight, $node->log, $node->nid);
} }
...@@ -187,12 +135,23 @@ function book_delete(&$node) { ...@@ -187,12 +135,23 @@ function book_delete(&$node) {
db_query("DELETE FROM book WHERE nid = '%d'", $node->nid); db_query("DELETE FROM book WHERE nid = '%d'", $node->nid);
} }
function book_validate($node, &$error) { function book_validate(&$node) {
if ($node->format && user_access("create php content")) {
// Make sure user has permissions to create php content: // Do not filter PHP code, do not auto-extract a teaser
$node->format = $node->format && user_access("create php content"); $node->teaser = $node->body;
}
else {
$node->format = 0;
$node->body = filter($node->body);
$node->teaser = filter($node->body);
}
return $node; // Set default values for non administrators:
if (!user_access("administer nodes")) {
$node->format = 0;
$node->weight = 0;
$node->revision = 1;
}
} }
function book_form(&$node, &$help, &$error) { function book_form(&$node, &$help, &$error) {
......
...@@ -671,7 +671,7 @@ function comment_link($type, $node = 0, $main = 0) { ...@@ -671,7 +671,7 @@ function comment_link($type, $node = 0, $main = 0) {
// comment settings: // comment settings:
if (user_access("administer moderation")) { if (user_access("administer moderation")) {
menu("admin/comment/votes", "comment moderation votes", "comment_admin", $help["settings"], 5); menu("admin/comment/votes", "comment moderation votes", "comment_admin", $help["settings"], 5);
menu("admin/comment/matrix", "ccomment moderation matrix", "comment_admin", $help["settings"], 5); menu("admin/comment/matrix", "comment moderation matrix", "comment_admin", $help["settings"], 5);
menu("admin/comment/filters", "comment moderation thresholds", "comment_admin", $help["settings"], 5); menu("admin/comment/filters", "comment moderation thresholds", "comment_admin", $help["settings"], 5);
menu("admin/comment/roles", "initial comment scores", "comment_admin", $help["settings"], 5); menu("admin/comment/roles", "initial comment scores", "comment_admin", $help["settings"], 5);
} }
...@@ -1491,13 +1491,21 @@ function comment_update_index() { ...@@ -1491,13 +1491,21 @@ function comment_update_index() {
function comment_nodeapi(&$node, $op, $arg = 0) { function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) { switch ($op) {
case "form": case "conf":
if ($arg == "admin" && user_access("administer comments")) { $output[t("Comment")] = form_select("", "comment_$node->type", variable_get("comment_$node->type", 2), array("Disabled", "Read only", "Read/Write"));
return form_select(t("Allow user comments"), "comment", $node->comment, array(t("Disabled"), t("Read only"), t("Read-write"))); return $output;
}
break;
case "fields": case "fields":
return array("comment"); return array("comment");
case "form admin":
if (user_access("administer comments")) {
return form_select(t("Allow user comments"), "comment", isset($node->comment) ? $node->comment : variable_get("comment_$node->type", 2), array(t("Disabled"), t("Read only"), t("Read-write")));
}
break;
case "validate":
if (!user_access("administer nodes")) {
unset($node->comment);
}
break;
} }
} }
......
...@@ -671,7 +671,7 @@ function comment_link($type, $node = 0, $main = 0) { ...@@ -671,7 +671,7 @@ function comment_link($type, $node = 0, $main = 0) {
// comment settings: // comment settings:
if (user_access("administer moderation")) { if (user_access("administer moderation")) {
menu("admin/comment/votes", "comment moderation votes", "comment_admin", $help["settings"], 5); menu("admin/comment/votes", "comment moderation votes", "comment_admin", $help["settings"], 5);
menu("admin/comment/matrix", "ccomment moderation matrix", "comment_admin", $help["settings"], 5); menu("admin/comment/matrix", "comment moderation matrix", "comment_admin", $help["settings"], 5);
menu("admin/comment/filters", "comment moderation thresholds", "comment_admin", $help["settings"], 5); menu("admin/comment/filters", "comment moderation thresholds", "comment_admin", $help["settings"], 5);
menu("admin/comment/roles", "initial comment scores", "comment_admin", $help["settings"], 5); menu("admin/comment/roles", "initial comment scores", "comment_admin", $help["settings"], 5);
} }
...@@ -1491,13 +1491,21 @@ function comment_update_index() { ...@@ -1491,13 +1491,21 @@ function comment_update_index() {
function comment_nodeapi(&$node, $op, $arg = 0) { function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) { switch ($op) {
case "form": case "conf":
if ($arg == "admin" && user_access("administer comments")) { $output[t("Comment")] = form_select("", "comment_$node->type", variable_get("comment_$node->type", 2), array("Disabled", "Read only", "Read/Write"));
return form_select(t("Allow user comments"), "comment", $node->comment, array(t("Disabled"), t("Read only"), t("Read-write"))); return $output;
}
break;
case "fields": case "fields":
return array("comment"); return array("comment");
case "form admin":
if (user_access("administer comments")) {
return form_select(t("Allow user comments"), "comment", isset($node->comment) ? $node->comment : variable_get("comment_$node->type", 2), array(t("Disabled"), t("Read only"), t("Read-write")));
}
break;
case "validate":
if (!user_access("administer nodes")) {
unset($node->comment);
}
break;
} }
} }
......
...@@ -69,24 +69,6 @@ function forum_taxonomy($op, $type, $object) { ...@@ -69,24 +69,6 @@ function forum_taxonomy($op, $type, $object) {
} }
} }
function forum_save($op, $node) {
if ($op == "approve") {
return array("status" => 1);
}
if ($op == "create") {
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "moderate" => 0, "status" => 1, "tid", "icon_num", "shadow" => 0);
}
if ($op == "decline") {
return array("status" => 0);
}
if ($op == "update") {
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "tid", "icon_num", "shadow");
}
}
function forum_load($node) { function forum_load($node) {
$forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = '%d'", $node->nid)); $forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = '%d'", $node->nid));
...@@ -185,13 +167,20 @@ function forum_view($node, $main = 0) { ...@@ -185,13 +167,20 @@ function forum_view($node, $main = 0) {
theme("node", $node, $main); theme("node", $node, $main);
} }
function forum_validate($node) { function forum_validate(&$node) {
// we use the validate hook to remember the old taxonomy terms // Make sure all fields are set properly:
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid)); $node->body = filter($node->body);
if (!in_array($node->tid[0], $node->taxonomy)) { $node->teaser = filter($node->teaser);
$node->taxonomy[] = $node->tid[0]; $node->icon = $node->icon ? $node->icon : "";
$node->shadow = $node->shadow ? $node->shadow : 0;
$node->tid = $node->tid ? $node->tid : 0;
// We use the validate hook to remember the old taxonomy terms:
if ($node->tid) {
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
if (!in_array($node->tid[0], $node->taxonomy)) {
$node->taxonomy[] = $node->tid[0];
}
} }
return $node;
} }
function forum_form(&$node, &$help, &$error) { function forum_form(&$node, &$help, &$error) {
......
...@@ -69,24 +69,6 @@ function forum_taxonomy($op, $type, $object) { ...@@ -69,24 +69,6 @@ function forum_taxonomy($op, $type, $object) {
} }
} }
function forum_save($op, $node) {
if ($op == "approve") {
return array("status" => 1);
}
if ($op == "create") {
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "moderate" => 0, "status" => 1, "tid", "icon_num", "shadow" => 0);
}
if ($op == "decline") {
return array("status" => 0);
}
if ($op == "update") {
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "tid", "icon_num", "shadow");
}
}
function forum_load($node) { function forum_load($node) {
$forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = '%d'", $node->nid)); $forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = '%d'", $node->nid));
...@@ -185,13 +167,20 @@ function forum_view($node, $main = 0) { ...@@ -185,13 +167,20 @@ function forum_view($node, $main = 0) {
theme("node", $node, $main); theme("node", $node, $main);
} }
function forum_validate($node) { function forum_validate(&$node) {
// we use the validate hook to remember the old taxonomy terms // Make sure all fields are set properly:
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid)); $node->body = filter($node->body);
if (!in_array($node->tid[0], $node->taxonomy)) { $node->teaser = filter($node->teaser);
$node->taxonomy[] = $node->tid[0]; $node->icon = $node->icon ? $node->icon : "";
$node->shadow = $node->shadow ? $node->shadow : 0;
$node->tid = $node->tid ? $node->tid : 0;
// We use the validate hook to remember the old taxonomy terms:
if ($node->tid) {
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
if (!in_array($node->tid[0], $node->taxonomy)) {
$node->taxonomy[] = $node->tid[0];
}
} }
return $node;
} }
function forum_form(&$node, &$help, &$error) { function forum_form(&$node, &$help, &$error) {
......