Commit 2de4c1c6 authored by Dries's avatar Dries

- Node API improvements by Moshe:

  "implemented pieces of kjartan's original nodeAPI patch. the mingling
  of other modules into node.module logic decreases (a good thing). for
  example, the string "taxonomy" now appears nowhere in node.module

  - moved the saving of taxonomy terms when submitting a node out of
  node.module and into taxonomy.module

  - moved the deletion of comments while deleting a node out of
  node.module and into comment.module

  - improved usability of node forms by including node type in the title
  of the box and page"
parent 86ddee8d
......@@ -1466,7 +1466,10 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
$node->comment = variable_get("comment_$node->type", 2);
}
break;
case "delete":
db_query("DELETE FROM comments WHERE nid = '$node->nid'");
break;
}
}
?>
?>
\ No newline at end of file
......@@ -1466,7 +1466,10 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
$node->comment = variable_get("comment_$node->type", 2);
}
break;
case "delete":
db_query("DELETE FROM comments WHERE nid = '$node->nid'");
break;
}
}
?>
?>
\ No newline at end of file
......@@ -1180,7 +1180,7 @@ function node_preview($node, $error = NULL) {
}
/*
** Exctract a teaser:
** Extract a teaser:
*/
$node->teaser = node_teaser($node->body);
......@@ -1197,7 +1197,7 @@ function node_preview($node, $error = NULL) {
}
/*
** Display a prenode of the node:
** Display a preview of the node:
*/
if ($view->teaser && $view->teaser != $view->body) {
......@@ -1245,17 +1245,8 @@ function node_submit($node) {
if (node_access("update", $node)) {
$nid = node_save($node);
/*
** Update terms of the node
*/
if (function_exists("taxonomy_node_save")) {
taxonomy_node_save($nid, $node->taxonomy);
}
watchdog("special", "$node->type: updated '$node->title'", l("view post", "node/view/$node->nid"));
$output = t("The node has been updated.");
$output = t("The %name has been updated.", array ("%name" => module_invoke($node->type, "node", "name")));
}
}
else {
......@@ -1275,15 +1266,6 @@ function node_submit($node) {
throttle("node", variable_get("max_node_rate", 900));
$nid = node_save($node);
/*
** Insert terms of the node
*/
if (function_exists("taxonomy_node_save")) {
taxonomy_node_save($nid, $node->taxonomy);
}
watchdog("special", "$node->type: added '$node->title'", l("view post", "node/view/$nid"));
$output = t("Thanks for your submission.");
}
......@@ -1326,17 +1308,10 @@ function node_delete($edit) {
if ($edit["confirm"]) {
/*
** Delete the specified node and its comments:
** Delete the specified node:
*/
db_query("DELETE FROM node WHERE nid = '$node->nid'");
db_query("DELETE FROM comments WHERE nid = '$node->nid'");
/*
** Delete any taxonomy terms
*/
module_invoke("taxonomy", "node_delete", $node->nid);
/*
** Call the node specific callback (if any):
......@@ -1381,26 +1356,26 @@ function node_page() {
}
theme("header");
$name = module_invoke(arg(2), "node", "name");
switch ($op) {
case "add":
theme("box", t("Create new post"), node_add(arg(2)));
theme("box", t("Create new $name"), node_add(arg(2)));
break;
case "edit":
theme("box", t("Edit post"), node_edit(arg(2)));
theme("box", t("Edit $name"), node_edit(arg(2)));
break;
case "view":
print node_show(arg(2), arg(3));
break;
case t("Preview"):
$edit = node_validate($edit, $error);
theme("box", t("Preview post"), node_preview($edit, $error));
theme("box", t("Preview $name"), node_preview($edit, $error));
break;
case t("Submit"):
theme("box", t("Submit post"), node_submit($edit));
theme("box", t("Submit $name"), node_submit($edit));
break;
case t("Delete"):
theme("box", t("Delete post"), node_delete($edit));
theme("box", t("Delete $name"), node_delete($edit));
break;
default:
$result = pager_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", variable_get("default_nodes_main", 10));
......
......@@ -1180,7 +1180,7 @@ function node_preview($node, $error = NULL) {
}
/*
** Exctract a teaser:
** Extract a teaser:
*/
$node->teaser = node_teaser($node->body);
......@@ -1197,7 +1197,7 @@ function node_preview($node, $error = NULL) {
}
/*
** Display a prenode of the node:
** Display a preview of the node:
*/
if ($view->teaser && $view->teaser != $view->body) {
......@@ -1245,17 +1245,8 @@ function node_submit($node) {
if (node_access("update", $node)) {
$nid = node_save($node);
/*
** Update terms of the node
*/
if (function_exists("taxonomy_node_save")) {
taxonomy_node_save($nid, $node->taxonomy);
}
watchdog("special", "$node->type: updated '$node->title'", l("view post", "node/view/$node->nid"));
$output = t("The node has been updated.");
$output = t("The %name has been updated.", array ("%name" => module_invoke($node->type, "node", "name")));
}
}
else {
......@@ -1275,15 +1266,6 @@ function node_submit($node) {
throttle("node", variable_get("max_node_rate", 900));
$nid = node_save($node);
/*
** Insert terms of the node
*/
if (function_exists("taxonomy_node_save")) {
taxonomy_node_save($nid, $node->taxonomy);
}
watchdog("special", "$node->type: added '$node->title'", l("view post", "node/view/$nid"));
$output = t("Thanks for your submission.");
}
......@@ -1326,17 +1308,10 @@ function node_delete($edit) {
if ($edit["confirm"]) {
/*
** Delete the specified node and its comments:
** Delete the specified node:
*/
db_query("DELETE FROM node WHERE nid = '$node->nid'");
db_query("DELETE FROM comments WHERE nid = '$node->nid'");
/*
** Delete any taxonomy terms
*/
module_invoke("taxonomy", "node_delete", $node->nid);
/*
** Call the node specific callback (if any):
......@@ -1381,26 +1356,26 @@ function node_page() {
}
theme("header");
$name = module_invoke(arg(2), "node", "name");
switch ($op) {
case "add":
theme("box", t("Create new post"), node_add(arg(2)));
theme("box", t("Create new $name"), node_add(arg(2)));
break;
case "edit":
theme("box", t("Edit post"), node_edit(arg(2)));
theme("box", t("Edit $name"), node_edit(arg(2)));
break;
case "view":
print node_show(arg(2), arg(3));
break;
case t("Preview"):
$edit = node_validate($edit, $error);
theme("box", t("Preview post"), node_preview($edit, $error));
theme("box", t("Preview $name"), node_preview($edit, $error));
break;
case t("Submit"):
theme("box", t("Submit post"), node_submit($edit));
theme("box", t("Submit $name"), node_submit($edit));
break;
case t("Delete"):
theme("box", t("Delete post"), node_delete($edit));
theme("box", t("Delete $name"), node_delete($edit));
break;
default:
$result = pager_query("SELECT nid, type FROM node WHERE promote = '1' AND status = '1' ORDER BY static DESC, created DESC", variable_get("default_nodes_main", 10));
......
......@@ -36,6 +36,15 @@ function taxonomy_link($type, $node = NULL) {
menu("admin/taxonomy/help", "help", "taxonomy_admin", NULL, 9);
}
else if ($type == "taxonomy terms" && $node != NULL) {
if ($node->taxonomy) {
foreach ($node->taxonomy as $tid) {
$term = taxonomy_get_term($tid);
$links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array("title" => $term->description) : array());
}
}
else {
/*
** Themes can print taxonomy links with:
**
......@@ -44,12 +53,12 @@ function taxonomy_link($type, $node = NULL) {
** }
*/
$links = array();
$links = array();
foreach (taxonomy_node_get_terms($node->nid) as $term) {
$links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array("title" => $term->description) : array());
}
foreach (taxonomy_node_get_terms($node->nid) as $term) {
$links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array("title" => $term->description) : array());
}
return $links;
}
}
......@@ -676,6 +685,21 @@ function taxonomy_render_nodes($result) {
print pager_display_default(NULL, variable_get("default_nodes_main", 10), 0);
}
function taxonomy_nodeapi($node, $op, $arg = 0) {
switch ($op) {
case "insert":
taxonomy_node_save($node->nid, $node->taxonomy);
break;
case "update":
taxonomy_node_save($node->nid, $node->taxonomy);
break;
case "delete":
taxonomy_node_delete($node->nid);
break;
}
}
function taxonomy_page() {
......
......@@ -36,6 +36,15 @@ function taxonomy_link($type, $node = NULL) {
menu("admin/taxonomy/help", "help", "taxonomy_admin", NULL, 9);
}
else if ($type == "taxonomy terms" && $node != NULL) {
if ($node->taxonomy) {
foreach ($node->taxonomy as $tid) {
$term = taxonomy_get_term($tid);
$links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array("title" => $term->description) : array());
}
}
else {
/*
** Themes can print taxonomy links with:
**
......@@ -44,12 +53,12 @@ function taxonomy_link($type, $node = NULL) {
** }
*/
$links = array();
$links = array();
foreach (taxonomy_node_get_terms($node->nid) as $term) {
$links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array("title" => $term->description) : array());
}
foreach (taxonomy_node_get_terms($node->nid) as $term) {
$links[] = l($term->name, "taxonomy/page/or/$term->tid", $term->description ? array("title" => $term->description) : array());
}
return $links;
}
}
......@@ -676,6 +685,21 @@ function taxonomy_render_nodes($result) {
print pager_display_default(NULL, variable_get("default_nodes_main", 10), 0);
}
function taxonomy_nodeapi($node, $op, $arg = 0) {
switch ($op) {
case "insert":
taxonomy_node_save($node->nid, $node->taxonomy);
break;
case "update":
taxonomy_node_save($node->nid, $node->taxonomy);
break;
case "delete":
taxonomy_node_delete($node->nid);
break;
}
}
function taxonomy_page() {
......
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