diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-11-20 22:51:06 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-11-20 22:51:06 +0000 |
commit | 2c3409f03d5dc27a24a53187b5ecf02d4543fac6 (patch) | |
tree | 892336b5cf5f6f6a47ff1944b9b8d14b4de12029 | |
parent | c35019601ed1d1453f527c5ebb8d5664d5a2a2ef (diff) | |
download | brdo-2c3409f03d5dc27a24a53187b5ecf02d4543fac6.tar.gz brdo-2c3409f03d5dc27a24a53187b5ecf02d4543fac6.tar.bz2 |
- Revised and documented the "change author"-logic used in the node forms
of node administrators. Fixed a bug: it was not possible to change the
name to "anoymous user" (or vice versa).
-rw-r--r-- | modules/node.module | 49 | ||||
-rw-r--r-- | modules/node/node.module | 49 |
2 files changed, 66 insertions, 32 deletions
diff --git a/modules/node.module b/modules/node.module index b310b30e9..e61229844 100644 --- a/modules/node.module +++ b/modules/node.module @@ -107,7 +107,7 @@ function node_filter_line($text) { $text = eregi_replace("<br />", "\n", $text); /* - ** Replace "\r\n" by "\n": + ** Replace "\r\n" by "\n": */ $text = ereg_replace("\r\n", "\n", $text); @@ -119,7 +119,7 @@ function node_filter_line($text) { while (strpos($text, "\n\n\n")) { $text = ereg_replace("\n\n\n", "\n\n", $text); } - + return trim($text); } @@ -480,7 +480,7 @@ function node_validate($node, $error = array()) { ** Validate the title field: */ - if (isset($node->title) && $node->title == "") { + if (isset($node->title) && !$node->title) { $error["title"] = "<div style=\"color: red;\">". t("You have to specify a valid title.") ."</div>"; } @@ -490,10 +490,6 @@ function node_validate($node, $error = array()) { ** Setup default values if required: */ - if (!$node->name) { - $node->name = $user->name; - } - if (!$node->created) { $node->created = time(); } @@ -506,7 +502,15 @@ function node_validate($node, $error = array()) { ** Validate the "authored by"-field: */ - if ($account = user_load(array("name" => $node->name))) { + if (empty($node->name)) { + /* + ** The use of empty() is mandatory in the context of usernames + ** as the empty string denotes the anonymous user. In case we + ** are dealing with an anomymous user we set the user ID to 0. + */ + $node->uid = 0; + } + else if ($account = user_load(array("name" => $node->name))) { $node->uid = $account->uid; } else { @@ -555,7 +559,6 @@ function node_form($edit) { $form .= $function(&$edit, &$help, &$error); } - /* ** Add the help text: */ @@ -596,7 +599,11 @@ function node_form($edit) { $output .= form_hidden("nid", $edit->nid); } - if ($edit->uid) { + if (isset($edit->uid)) { + /* + ** The use of isset() is mandatory in the context of user IDs as uid + ** 0 denotes the anonymous user. + */ $output .= form_hidden("uid", $edit->uid); } @@ -625,7 +632,7 @@ function node_form($edit) { */ if (user_access("administer nodes")) { - $output .= "</td><td valign=\"top\">"; + $output .= "</td><td align=\"left\" valign=\"top\">"; $output .= form_textfield(t("Authored by"), "name", $edit->name, 20, 25, $error["name"]); $output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]); @@ -647,11 +654,13 @@ function node_add($type) { global $user; if ($type) { - $output = node_form(array("uid" => $user->uid, "type" => $type)); + $output = node_form(array("uid" => $user->uid, "name" => $user->name, "type" => $type)); } else { - $links = array(); + /* + ** Compile a list with the different node types and their explanation: + */ foreach (module_list() as $name) { if (module_hook($name, "node") && node_access("create", array("type" => $name))) { @@ -690,9 +699,17 @@ function node_preview($edit) { ** Load the user's name when needed: */ - if ($edit["name"]) { - $user = user_load(array("name" => $edit["name"])); - $edit["uid"] = $user->uid; + if (isset($edit["name"])) { + /* + ** The use of isset() is mandatory in the context of user IDs as uid + ** 0 denotes the anonymous user. + */ + if ($user = user_load(array("name" => $edit["name"]))) { + $edit["uid"] = $user->uid; + } + else { + $edit["uid"] = 0; // anonymous user + } } else if ($edit["uid"]) { $user = user_load(array("uid" => $edit["uid"])); diff --git a/modules/node/node.module b/modules/node/node.module index b310b30e9..e61229844 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -107,7 +107,7 @@ function node_filter_line($text) { $text = eregi_replace("<br />", "\n", $text); /* - ** Replace "\r\n" by "\n": + ** Replace "\r\n" by "\n": */ $text = ereg_replace("\r\n", "\n", $text); @@ -119,7 +119,7 @@ function node_filter_line($text) { while (strpos($text, "\n\n\n")) { $text = ereg_replace("\n\n\n", "\n\n", $text); } - + return trim($text); } @@ -480,7 +480,7 @@ function node_validate($node, $error = array()) { ** Validate the title field: */ - if (isset($node->title) && $node->title == "") { + if (isset($node->title) && !$node->title) { $error["title"] = "<div style=\"color: red;\">". t("You have to specify a valid title.") ."</div>"; } @@ -490,10 +490,6 @@ function node_validate($node, $error = array()) { ** Setup default values if required: */ - if (!$node->name) { - $node->name = $user->name; - } - if (!$node->created) { $node->created = time(); } @@ -506,7 +502,15 @@ function node_validate($node, $error = array()) { ** Validate the "authored by"-field: */ - if ($account = user_load(array("name" => $node->name))) { + if (empty($node->name)) { + /* + ** The use of empty() is mandatory in the context of usernames + ** as the empty string denotes the anonymous user. In case we + ** are dealing with an anomymous user we set the user ID to 0. + */ + $node->uid = 0; + } + else if ($account = user_load(array("name" => $node->name))) { $node->uid = $account->uid; } else { @@ -555,7 +559,6 @@ function node_form($edit) { $form .= $function(&$edit, &$help, &$error); } - /* ** Add the help text: */ @@ -596,7 +599,11 @@ function node_form($edit) { $output .= form_hidden("nid", $edit->nid); } - if ($edit->uid) { + if (isset($edit->uid)) { + /* + ** The use of isset() is mandatory in the context of user IDs as uid + ** 0 denotes the anonymous user. + */ $output .= form_hidden("uid", $edit->uid); } @@ -625,7 +632,7 @@ function node_form($edit) { */ if (user_access("administer nodes")) { - $output .= "</td><td valign=\"top\">"; + $output .= "</td><td align=\"left\" valign=\"top\">"; $output .= form_textfield(t("Authored by"), "name", $edit->name, 20, 25, $error["name"]); $output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]); @@ -647,11 +654,13 @@ function node_add($type) { global $user; if ($type) { - $output = node_form(array("uid" => $user->uid, "type" => $type)); + $output = node_form(array("uid" => $user->uid, "name" => $user->name, "type" => $type)); } else { - $links = array(); + /* + ** Compile a list with the different node types and their explanation: + */ foreach (module_list() as $name) { if (module_hook($name, "node") && node_access("create", array("type" => $name))) { @@ -690,9 +699,17 @@ function node_preview($edit) { ** Load the user's name when needed: */ - if ($edit["name"]) { - $user = user_load(array("name" => $edit["name"])); - $edit["uid"] = $user->uid; + if (isset($edit["name"])) { + /* + ** The use of isset() is mandatory in the context of user IDs as uid + ** 0 denotes the anonymous user. + */ + if ($user = user_load(array("name" => $edit["name"]))) { + $edit["uid"] = $user->uid; + } + else { + $edit["uid"] = 0; // anonymous user + } } else if ($edit["uid"]) { $user = user_load(array("uid" => $edit["uid"])); |