Commit fbc674f1 authored by Dries's avatar Dries

- Node API code clean-up. Patch by Kjartan.

parent 6e86d70c
...@@ -143,9 +143,6 @@ function path_link($type, $node = NULL) { ...@@ -143,9 +143,6 @@ function path_link($type, $node = NULL) {
} }
function path_nodeapi($node, $op, $arg) { function path_nodeapi($node, $op, $arg) {
global $error;
$edit = $_POST["edit"];
if (user_access("create url aliases") || user_access("administer url aliases")) { if (user_access("create url aliases") || user_access("administer url aliases")) {
switch ($op) { switch ($op) {
...@@ -153,30 +150,28 @@ function path_nodeapi($node, $op, $arg) { ...@@ -153,30 +150,28 @@ function path_nodeapi($node, $op, $arg) {
// is_null provides a mechanism for us to determine if this is the first // is_null provides a mechanism for us to determine if this is the first
// viewing of the form. If it is the first time, load the alias, if it isn't // viewing of the form. If it is the first time, load the alias, if it isn't
// (i.e., user has clicked preview) let them work with their current form alias. // (i.e., user has clicked preview) let them work with their current form alias.
if (is_null($edit["path"])) { if (is_null($node->path)) {
$_POST["edit"]["path"] = drupal_get_path_alias("node/view/$node->nid"); $node->path = drupal_get_path_alias("node/view/$node->nid");
} }
else { else {
if ($_POST["edit"]["path"] && !valid_url($_POST["edit"]["path"])) { $node->path = trim($node->path);
$error["path"] = theme("theme_error", t("The path is invalid.")); if ($node->path && !valid_url($node->path)) {
$error["path"] = t("The path is invalid.");
return $error; return $error;
} }
else if (db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s' AND src != '%s'", $_POST["edit"]["path"], "node/view/$node->nid"))) { else if (db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s' AND src != '%s'", $node->path, "node/view/$node->nid"))) {
$error["path"] = theme("theme_error", t("The path is already in use.")); $error["path"] = t("The path is already in use.");
return $error; return $error;
} }
$edit["path"] = $_POST["edit"]["path"];
} }
break; break;
case "form pre": case "form pre":
return form_textfield(t("Path alias"), "path", $edit["path"], 60, 250, $error["path"] ? $error["path"] : t("Optionally specify an alternative URL by which this node can be accessed. For example, type 'about' when writing an about page. Use a relative path and don't add a trailing slash or the URL alias won't work.")); return form_textfield(t("Path alias"), "path", $node->path, 60, 250, t("Optionally specify an alternative URL by which this node can be accessed. For example, type 'about' when writing an about page. Use a relative path and don't add a trailing slash or the URL alias won't work.") . theme_error($arg["path"]));
break;
case "insert": case "insert":
case "update": case "update":
path_set_alias("node/view/$node->nid", $edit["path"]); path_set_alias("node/view/$node->nid", $node->path);
break; break;
case "delete": case "delete":
......
...@@ -143,9 +143,6 @@ function path_link($type, $node = NULL) { ...@@ -143,9 +143,6 @@ function path_link($type, $node = NULL) {
} }
function path_nodeapi($node, $op, $arg) { function path_nodeapi($node, $op, $arg) {
global $error;
$edit = $_POST["edit"];
if (user_access("create url aliases") || user_access("administer url aliases")) { if (user_access("create url aliases") || user_access("administer url aliases")) {
switch ($op) { switch ($op) {
...@@ -153,30 +150,28 @@ function path_nodeapi($node, $op, $arg) { ...@@ -153,30 +150,28 @@ function path_nodeapi($node, $op, $arg) {
// is_null provides a mechanism for us to determine if this is the first // is_null provides a mechanism for us to determine if this is the first
// viewing of the form. If it is the first time, load the alias, if it isn't // viewing of the form. If it is the first time, load the alias, if it isn't
// (i.e., user has clicked preview) let them work with their current form alias. // (i.e., user has clicked preview) let them work with their current form alias.
if (is_null($edit["path"])) { if (is_null($node->path)) {
$_POST["edit"]["path"] = drupal_get_path_alias("node/view/$node->nid"); $node->path = drupal_get_path_alias("node/view/$node->nid");
} }
else { else {
if ($_POST["edit"]["path"] && !valid_url($_POST["edit"]["path"])) { $node->path = trim($node->path);
$error["path"] = theme("theme_error", t("The path is invalid.")); if ($node->path && !valid_url($node->path)) {
$error["path"] = t("The path is invalid.");
return $error; return $error;
} }
else if (db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s' AND src != '%s'", $_POST["edit"]["path"], "node/view/$node->nid"))) { else if (db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s' AND src != '%s'", $node->path, "node/view/$node->nid"))) {
$error["path"] = theme("theme_error", t("The path is already in use.")); $error["path"] = t("The path is already in use.");
return $error; return $error;
} }
$edit["path"] = $_POST["edit"]["path"];
} }
break; break;
case "form pre": case "form pre":
return form_textfield(t("Path alias"), "path", $edit["path"], 60, 250, $error["path"] ? $error["path"] : t("Optionally specify an alternative URL by which this node can be accessed. For example, type 'about' when writing an about page. Use a relative path and don't add a trailing slash or the URL alias won't work.")); return form_textfield(t("Path alias"), "path", $node->path, 60, 250, t("Optionally specify an alternative URL by which this node can be accessed. For example, type 'about' when writing an about page. Use a relative path and don't add a trailing slash or the URL alias won't work.") . theme_error($arg["path"]));
break;
case "insert": case "insert":
case "update": case "update":
path_set_alias("node/view/$node->nid", $edit["path"]); path_set_alias("node/view/$node->nid", $node->path);
break; break;
case "delete": case "delete":
......
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