Commit 5598417c authored by Dries's avatar Dries
Browse files

- Some small improvements/fixes to the node system.  Suggested by Marco.
parent 0475d4fb
...@@ -498,7 +498,7 @@ function node_admin_nodes() { ...@@ -498,7 +498,7 @@ function node_admin_nodes() {
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$rows[] = array(l(check_output($node->title), array("id" => $node->nid)), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), la(t("edit node"), array("mod" => "node", "op" => "edit", "id" => $node->nid)), la(t("delete node"), array("mod" => "node", "op" => "delete", "id" => $node->nid))); $rows[] = array(l(check_output($node->title), array("id" => $node->nid)), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), la(t("edit node"), array("mod" => "node", "op" => "edit", "id" => $node->nid)), la(t("delete node"), array("mod" => "node", "op" => "delete", "id" => $node->nid)));
} }
if ($pager = pager_display(NULL, 50, 0, "admin")) { if ($pager = pager_display(NULL, 50, 0, "admin")) {
$rows[] = array(array("data" => $pager, "colspan" => 6)); $rows[] = array(array("data" => $pager, "colspan" => 6));
} }
...@@ -637,7 +637,7 @@ function node_admin() { ...@@ -637,7 +637,7 @@ function node_admin() {
print node_admin_edit($id); print node_admin_edit($id);
break; break;
case t("Preview"): case t("Preview"):
$edit = object2array(node_validate($edit, $error)); $edit = node_validate($edit, $error);
print node_preview($edit); print node_preview($edit);
break; break;
case t("Submit"): case t("Submit"):
...@@ -954,72 +954,75 @@ function node_preview($node, $error = NULL) { ...@@ -954,72 +954,75 @@ function node_preview($node, $error = NULL) {
$node = array2object($node); $node = array2object($node);
/* if (node_access("create", $node) || node_access("update", $node)) {
** Load the user's name when needed:
*/
if (isset($node->name)) {
/* /*
** The use of isset() is mandatory in the context of user IDs as uid ** Load the user's name when needed:
** 0 denotes the anonymous user.
*/ */
if ($user = user_load(array("name" => $node->name))) { if (isset($node->name)) {
$node->uid = $user->uid; /*
** 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" => $node->name))) {
$node->uid = $user->uid;
}
else {
$node->uid = 0; // anonymous user
}
} }
else { else if ($node->uid) {
$node->uid = 0; // anonymous user $user = user_load(array("uid" => $node->uid));
$node->name = $user->name;
} }
}
else if ($node->uid) {
$user = user_load(array("uid" => $node->uid));
$node->name = $user->name;
}
/* /*
** Set the created time when needed: ** Set the created time when needed:
*/ */
if (empty($node->created)) { if (empty($node->created)) {
$node->created = time(); $node->created = time();
} }
/* /*
** Exctract a teaser: ** Exctract a teaser:
*/ */
$node->teaser = node_teaser($node->body); $node->teaser = node_teaser($node->body);
/* /*
** Apply the required filters: ** Apply the required filters:
*/ */
if ($node->nid) { if ($node->nid) {
$view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "update", $node))); $view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "update", $node)));
} }
else { else {
$view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "create", $node))); $view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "create", $node)));
} }
/* /*
** Display a prenode of the node: ** Display a prenode of the node:
*/ */
$view->body = filter($view->body); $view->body = filter($view->body);
$view->teaser = filter($view->teaser); $view->teaser = filter($view->teaser);
if ($view->teaser && $view->teaser != $view->body) { if ($view->teaser && $view->teaser != $view->body) {
print "<h3>". t("Preview trimmed version") ."</h3>"; print "<h3>". t("Preview trimmed version") ."</h3>";
node_view($view, 1); node_view($view, 1);
print "<p><i>". t("The trimmed version of your post shows how your post looks like when promoted to the main page or when exported for syndication. You can insert a delimiter '---' (without the quotes) to fine-tune where your post gets split. However note that delimiter will be ignored when misplaced.") ."</i></p>"; print "<p><i>". t("The trimmed version of your post shows how your post looks like when promoted to the main page or when exported for syndication. You can insert a delimiter '---' (without the quotes) to fine-tune where your post gets split. However note that delimiter will be ignored when misplaced.") ."</i></p>";
print "<h3>". t("Preview full version") ."</h3>"; print "<h3>". t("Preview full version") ."</h3>";
node_view($view, 0); node_view($view, 0);
} }
else { else {
node_view($view, 0); node_view($view, 0);
} }
return node_form($node, $error); return node_form($node, $error);
}
} }
function node_submit($node) { function node_submit($node) {
...@@ -1085,11 +1088,6 @@ function node_submit($node) { ...@@ -1085,11 +1088,6 @@ function node_submit($node) {
watchdog("special", "$node->type: updated '$node->title'"); watchdog("special", "$node->type: updated '$node->title'");
$output = t("The node has been updated."); $output = t("The node has been updated.");
} }
else {
watchdog("warning", "$node->type: not authorized to update node");
$output = t("You are not authorized to update this node.");
}
} }
else { else {
...@@ -1132,10 +1130,6 @@ function node_submit($node) { ...@@ -1132,10 +1130,6 @@ function node_submit($node) {
watchdog("special", "$node->type: added '$node->title'"); watchdog("special", "$node->type: added '$node->title'");
$output = t("Thanks for your submission."); $output = t("Thanks for your submission.");
} }
else {
watchdog("warning", "$node->type: not authorized to create node");
$output = t("You are not authorized to create this node.");
}
} }
/* /*
...@@ -1210,10 +1204,6 @@ function node_delete($edit) { ...@@ -1210,10 +1204,6 @@ function node_delete($edit) {
$output = form($output); $output = form($output);
} }
} }
else {
watchdog("warning", "$node->type: not authorized to remove node");
$output = t("You are not authorized to remove this node.");
}
return $output; return $output;
} }
......
...@@ -498,7 +498,7 @@ function node_admin_nodes() { ...@@ -498,7 +498,7 @@ function node_admin_nodes() {
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$rows[] = array(l(check_output($node->title), array("id" => $node->nid)), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), la(t("edit node"), array("mod" => "node", "op" => "edit", "id" => $node->nid)), la(t("delete node"), array("mod" => "node", "op" => "delete", "id" => $node->nid))); $rows[] = array(l(check_output($node->title), array("id" => $node->nid)), module_invoke($node->type, "node", "name"), format_name($node), ($node->status ? t("published") : t("not published")), la(t("edit node"), array("mod" => "node", "op" => "edit", "id" => $node->nid)), la(t("delete node"), array("mod" => "node", "op" => "delete", "id" => $node->nid)));
} }
if ($pager = pager_display(NULL, 50, 0, "admin")) { if ($pager = pager_display(NULL, 50, 0, "admin")) {
$rows[] = array(array("data" => $pager, "colspan" => 6)); $rows[] = array(array("data" => $pager, "colspan" => 6));
} }
...@@ -637,7 +637,7 @@ function node_admin() { ...@@ -637,7 +637,7 @@ function node_admin() {
print node_admin_edit($id); print node_admin_edit($id);
break; break;
case t("Preview"): case t("Preview"):
$edit = object2array(node_validate($edit, $error)); $edit = node_validate($edit, $error);
print node_preview($edit); print node_preview($edit);
break; break;
case t("Submit"): case t("Submit"):
...@@ -954,72 +954,75 @@ function node_preview($node, $error = NULL) { ...@@ -954,72 +954,75 @@ function node_preview($node, $error = NULL) {
$node = array2object($node); $node = array2object($node);
/* if (node_access("create", $node) || node_access("update", $node)) {
** Load the user's name when needed:
*/
if (isset($node->name)) {
/* /*
** The use of isset() is mandatory in the context of user IDs as uid ** Load the user's name when needed:
** 0 denotes the anonymous user.
*/ */
if ($user = user_load(array("name" => $node->name))) { if (isset($node->name)) {
$node->uid = $user->uid; /*
** 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" => $node->name))) {
$node->uid = $user->uid;
}
else {
$node->uid = 0; // anonymous user
}
} }
else { else if ($node->uid) {
$node->uid = 0; // anonymous user $user = user_load(array("uid" => $node->uid));
$node->name = $user->name;
} }
}
else if ($node->uid) {
$user = user_load(array("uid" => $node->uid));
$node->name = $user->name;
}
/* /*
** Set the created time when needed: ** Set the created time when needed:
*/ */
if (empty($node->created)) { if (empty($node->created)) {
$node->created = time(); $node->created = time();
} }
/* /*
** Exctract a teaser: ** Exctract a teaser:
*/ */
$node->teaser = node_teaser($node->body); $node->teaser = node_teaser($node->body);
/* /*
** Apply the required filters: ** Apply the required filters:
*/ */
if ($node->nid) { if ($node->nid) {
$view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "update", $node))); $view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "update", $node)));
} }
else { else {
$view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "create", $node))); $view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "create", $node)));
} }
/* /*
** Display a prenode of the node: ** Display a prenode of the node:
*/ */
$view->body = filter($view->body); $view->body = filter($view->body);
$view->teaser = filter($view->teaser); $view->teaser = filter($view->teaser);
if ($view->teaser && $view->teaser != $view->body) { if ($view->teaser && $view->teaser != $view->body) {
print "<h3>". t("Preview trimmed version") ."</h3>"; print "<h3>". t("Preview trimmed version") ."</h3>";
node_view($view, 1); node_view($view, 1);
print "<p><i>". t("The trimmed version of your post shows how your post looks like when promoted to the main page or when exported for syndication. You can insert a delimiter '---' (without the quotes) to fine-tune where your post gets split. However note that delimiter will be ignored when misplaced.") ."</i></p>"; print "<p><i>". t("The trimmed version of your post shows how your post looks like when promoted to the main page or when exported for syndication. You can insert a delimiter '---' (without the quotes) to fine-tune where your post gets split. However note that delimiter will be ignored when misplaced.") ."</i></p>";
print "<h3>". t("Preview full version") ."</h3>"; print "<h3>". t("Preview full version") ."</h3>";
node_view($view, 0); node_view($view, 0);
} }
else { else {
node_view($view, 0); node_view($view, 0);
} }
return node_form($node, $error); return node_form($node, $error);
}
} }
function node_submit($node) { function node_submit($node) {
...@@ -1085,11 +1088,6 @@ function node_submit($node) { ...@@ -1085,11 +1088,6 @@ function node_submit($node) {
watchdog("special", "$node->type: updated '$node->title'"); watchdog("special", "$node->type: updated '$node->title'");
$output = t("The node has been updated."); $output = t("The node has been updated.");
} }
else {
watchdog("warning", "$node->type: not authorized to update node");
$output = t("You are not authorized to update this node.");
}
} }
else { else {
...@@ -1132,10 +1130,6 @@ function node_submit($node) { ...@@ -1132,10 +1130,6 @@ function node_submit($node) {
watchdog("special", "$node->type: added '$node->title'"); watchdog("special", "$node->type: added '$node->title'");
$output = t("Thanks for your submission."); $output = t("Thanks for your submission.");
} }
else {
watchdog("warning", "$node->type: not authorized to create node");
$output = t("You are not authorized to create this node.");
}
} }
/* /*
...@@ -1210,10 +1204,6 @@ function node_delete($edit) { ...@@ -1210,10 +1204,6 @@ function node_delete($edit) {
$output = form($output); $output = form($output);
} }
} }
else {
watchdog("warning", "$node->type: not authorized to remove node");
$output = t("You are not authorized to remove this node.");
}
return $output; return $output;
} }
......
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