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) {
}
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) {
......@@ -819,7 +819,7 @@ function l($text, $url, $attributes = array(), $query = NULL) {
}
function field_get($string, $name) {
ereg(",$name=([^,]+)", ", $string", $regs);
ereg(",?$name=([^,]+)", ", $string", $regs);
return $regs[1];
}
......@@ -839,7 +839,7 @@ function link_page() {
}
else {
$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;
}
}
......
......@@ -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() {
?>
<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) {
}
}
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) {
}
}
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() {
?>
<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) {
}
}
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) {
}
}
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) {
if ($type == "page" && user_access("access content")) {
$links[] = l(t("collaborative book"), "book", array("title" => t("Read and contribute to the collaborative books.")));
......@@ -166,20 +124,10 @@ function book_load($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);
}
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);
}
......@@ -187,12 +135,23 @@ function book_delete(&$node) {
db_query("DELETE FROM book WHERE nid = '%d'", $node->nid);
}
function book_validate($node, &$error) {
// Make sure user has permissions to create php content:
$node->format = $node->format && user_access("create php content");
function book_validate(&$node) {
if ($node->format && user_access("create php content")) {
// Do not filter PHP code, do not auto-extract a teaser
$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) {
......
......@@ -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) {
if ($type == "page" && user_access("access content")) {
$links[] = l(t("collaborative book"), "book", array("title" => t("Read and contribute to the collaborative books.")));
......@@ -166,20 +124,10 @@ function book_load($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);
}
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);
}
......@@ -187,12 +135,23 @@ function book_delete(&$node) {
db_query("DELETE FROM book WHERE nid = '%d'", $node->nid);
}
function book_validate($node, &$error) {
// Make sure user has permissions to create php content:
$node->format = $node->format && user_access("create php content");
function book_validate(&$node) {
if ($node->format && user_access("create php content")) {
// Do not filter PHP code, do not auto-extract a teaser
$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) {
......
......@@ -671,7 +671,7 @@ function comment_link($type, $node = 0, $main = 0) {
// comment settings:
if (user_access("administer moderation")) {
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/roles", "initial comment scores", "comment_admin", $help["settings"], 5);
}
......@@ -1491,13 +1491,21 @@ function comment_update_index() {
function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case "form":
if ($arg == "admin" && user_access("administer comments")) {
return form_select(t("Allow user comments"), "comment", $node->comment, array(t("Disabled"), t("Read only"), t("Read-write")));
}
break;
case "conf":
$output[t("Comment")] = form_select("", "comment_$node->type", variable_get("comment_$node->type", 2), array("Disabled", "Read only", "Read/Write"));
return $output;
case "fields":
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) {
// comment settings:
if (user_access("administer moderation")) {
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/roles", "initial comment scores", "comment_admin", $help["settings"], 5);
}
......@@ -1491,13 +1491,21 @@ function comment_update_index() {
function comment_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case "form":
if ($arg == "admin" && user_access("administer comments")) {
return form_select(t("Allow user comments"), "comment", $node->comment, array(t("Disabled"), t("Read only"), t("Read-write")));
}
break;
case "conf":
$output[t("Comment")] = form_select("", "comment_$node->type", variable_get("comment_$node->type", 2), array("Disabled", "Read only", "Read/Write"));
return $output;
case "fields":
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) {
}
}
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) {
$forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = '%d'", $node->nid));
......@@ -185,13 +167,20 @@ function forum_view($node, $main = 0) {
theme("node", $node, $main);
}
function forum_validate($node) {
// we use the validate hook to remember the old taxonomy terms
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
if (!in_array($node->tid[0], $node->taxonomy)) {
$node->taxonomy[] = $node->tid[0];
function forum_validate(&$node) {
// Make sure all fields are set properly:
$node->body = filter($node->body);
$node->teaser = filter($node->teaser);
$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) {
......
......@@ -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) {
$forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = '%d'", $node->nid));
......@@ -185,13 +167,20 @@ function forum_view($node, $main = 0) {
theme("node", $node, $main);
}
function forum_validate($node) {
// we use the validate hook to remember the old taxonomy terms
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
if (!in_array($node->tid[0], $node->taxonomy)) {
$node->taxonomy[] = $node->tid[0];
function forum_validate(&$node) {
// Make sure all fields are set properly:
$node->body = filter($node->body);
$node->teaser = filter($node->teaser);
$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) {
......
......@@ -115,15 +115,15 @@ function node_teaser($body) {
return substr($body, 0, $size);
}
function node_invoke($node, $name, $arg = 0) {
function node_invoke(&$node, $hook, $arg = 0) {
if (is_array($node)) {
$function = $node["type"] ."_$name";
$function = $node["type"] ."_$hook";
}
else if (is_object($node)) {
$function = $node->type ."_$name";
$function = $node->type ."_$hook";
}
else if (is_string($node)) {
$function = $node ."_$name";
$function = $node ."_$hook";
}
if (function_exists($function)) {
......@@ -131,10 +131,10 @@ function node_invoke($node, $name, $arg = 0) {
}
}
function node_invoke_all($hook, &$node, $op, $arg = 0) {
function node_invoke_all(&$node, $hook, $op, $arg = 0) {
$return = array();
foreach (module_list() as $name) {
if (module_hook($name, $hook)) {
if ((module_hook($name, "node") || module_hook($name, "nodeapi")) && module_hook($name, $hook)) {
$function = $name ."_". $hook;
$result = $function($node, $op, $arg);
if (isset($result)) {
......@@ -183,32 +183,12 @@ function node_load($conditions) {
return $node;
}
function node_save($node, $filter) {
function node_save($node) {
$fields = node_invoke_all("nodeapi", $node, "fields");
foreach ($filter as $key => $value) {
/*
** Only save those fields specified by the filter. If the filter
** does not specify a default value, use the value of the $node's
** corresponding field instead.
*/
if (is_numeric($key)) {
if (isset($node->$value)) {
// The above check is mandatory.
$edit->$value = $node->$value;
}
}
else {
if (isset($value)) {
// The above check is mandatory.
$edit->$key = $value;
}
}
}
$node = $edit;
/*
** Fetch fields to save to node table:
*/
$fields = node_invoke_all($node, "nodeapi", "fields");
/*
** Serialize the revisions field:
......@@ -247,7 +227,8 @@ function node_save($node, $filter) {
db_query("INSERT INTO node (". implode(", ", $k) .") VALUES (". implode(", ", $v) .")");
// Call the node specific callback (if any):
module_invoke($node->type, "insert", $node);
node_invoke($node, "insert");
node_invoke_all($node, "nodeapi", "insert");
}
else {
......@@ -269,8 +250,8 @@ function node_save($node, $filter) {
db_query("UPDATE node SET ". implode(", ", $q) ." WHERE nid = '$node->nid'");
// Call the node specific callback (if any):
module_invoke($node->type, "update", $node);
node_invoke($node, "update");
node_invoke_all($node, "nodeapi", "update");
}
/*
......@@ -471,10 +452,10 @@ function node_link($type, $node = 0, $main = 0) {
menu("admin/node", "node management", "node_admin");
menu("admin/node/nodes", "post overview");
menu("admin/node/nodes/0", "new or updated posts", "node_admin", NULL, 0);
menu("admin/node/nodes/1", "approval queue", "node_admin", NULL, 1);
menu("admin/node/search", "search posts", "node_admin", $help["search"], 8);
menu("admin/node/help", "help", "node_help", NULL, 9);
menu("admin/node/edit", "edit node", "node_admin", NULL, 0, 1);
menu("admin/node/settings", "content settings", "node_admin", NULL, 8);
}
return $links ? $links : array();
......@@ -540,6 +521,57 @@ function node_admin_nodes() {
return table($header, $rows);
}
/*
**
*/