Commit dd329e1d authored by Kjartan's avatar Kjartan

- Added function node_invoke_all($hook, &$node, $op, $arg = 0).

- Added a _nodeapi hook that in time will replace the _node hook. Trying
  to make as few changes to existing code as possible until the new api
  is stabilized.
- Modified node_form() to add administration options from other modules
  using the _nodeapi hook.
- Modified node_save() to fetch which fields should be saved to the node
  table from the _nodeapi hook.
- Moved comment and queue options from node_form() and node_save() to
  the modules _nodeapi hooks.
parent b29f1bff
......@@ -1490,4 +1490,16 @@ function comment_update_index() {
return array("last_update" => "comment_cron_last", "node_type" => "comment", "select" => "SELECT c.cid as lno, c.subject as text1, c.comment as text2 FROM comments c WHERE c.status = 0 AND timestamp > ". variable_get("comment_cron_last", 1));
}
?>
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 "fields":
return array("comment");
}
}
?>
\ No newline at end of file
......@@ -1490,4 +1490,16 @@ function comment_update_index() {
return array("last_update" => "comment_cron_last", "node_type" => "comment", "select" => "SELECT c.cid as lno, c.subject as text1, c.comment as text2 FROM comments c WHERE c.status = 0 AND timestamp > ". variable_get("comment_cron_last", 1));
}
?>
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 "fields":
return array("comment");
}
}
?>
\ No newline at end of file
......@@ -131,6 +131,20 @@ function node_invoke($node, $name, $arg = 0) {
}
}
function node_invoke_all($hook, &$node, $op, $arg = 0) {
$return = array();
foreach (module_list() as $name) {
if (module_hook($name, $hook)) {
$function = $name ."_". $hook;
$result = $function($node, $op, $arg);
if (isset($result)) {
$return = array_merge($return, $result);
}
}
}
return $return;
}
function node_load($conditions) {
/*
......@@ -171,7 +185,7 @@ function node_load($conditions) {
function node_save($node, $filter) {
$fields = array("nid", "uid", "type", "title", "teaser", "body", "revisions", "score", "status", "comment", "promote", "static", "moderate", "created", "changed", "users", "votes");
$fields = node_invoke_all("nodeapi", $node, "fields");
foreach ($filter as $key => $value) {
/*
......@@ -900,13 +914,9 @@ function node_form($edit, $error = NULL) {
$output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]);
$output .= "<br />";
$output .= form_select(t("Set public/published"), "status", $edit->status, array(t("Disabled"), t("Enabled")));
$output .= form_select(t("Moderation status"), "moderate", $edit->moderate, array(t("Approved"), t("Awaiting approval")));
$output .= form_select(t("Promote to front page"), "promote", $edit->promote, array(t("Disabled"), t("Enabled")));
$output .= form_select(t("Static on front page"), "static", $edit->static, array(t("Disabled"), t("Enabled")));
// TODO: move this to the comment.module
if (module_exist("comment")) {
$output .= form_select(t("Allow user comments"), "comment", $edit->comment, array(t("Disabled"), t("Read only"), t("Read-write")));
}
$output .= implode("", node_invoke_all("nodeapi", $edit, "form", "admin"));
$output .= form_select(t("Create new revision"), "revision", $edit->revision, array(t("Disabled"), t("Enabled")));
}
......@@ -1299,4 +1309,11 @@ function node_update_index() {
"select" => "SELECT n.nid as lno, n.title as text1, n.body as text2 FROM node n WHERE n.status = 1 AND moderate = 0 and (created > " . variable_get("node_cron_last", 1) . " or changed > " . variable_get("node_cron_last", 1) . ")");
}
?>
function node_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case "fields":
return array("nid", "uid", "type", "title", "teaser", "body", "revisions", "score", "status", "promote", "static", "created", "changed", "users", "votes");
}
}
?>
\ No newline at end of file
......@@ -131,6 +131,20 @@ function node_invoke($node, $name, $arg = 0) {
}
}
function node_invoke_all($hook, &$node, $op, $arg = 0) {
$return = array();
foreach (module_list() as $name) {
if (module_hook($name, $hook)) {
$function = $name ."_". $hook;
$result = $function($node, $op, $arg);
if (isset($result)) {
$return = array_merge($return, $result);
}
}
}
return $return;
}
function node_load($conditions) {
/*
......@@ -171,7 +185,7 @@ function node_load($conditions) {
function node_save($node, $filter) {
$fields = array("nid", "uid", "type", "title", "teaser", "body", "revisions", "score", "status", "comment", "promote", "static", "moderate", "created", "changed", "users", "votes");
$fields = node_invoke_all("nodeapi", $node, "fields");
foreach ($filter as $key => $value) {
/*
......@@ -900,13 +914,9 @@ function node_form($edit, $error = NULL) {
$output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]);
$output .= "<br />";
$output .= form_select(t("Set public/published"), "status", $edit->status, array(t("Disabled"), t("Enabled")));
$output .= form_select(t("Moderation status"), "moderate", $edit->moderate, array(t("Approved"), t("Awaiting approval")));
$output .= form_select(t("Promote to front page"), "promote", $edit->promote, array(t("Disabled"), t("Enabled")));
$output .= form_select(t("Static on front page"), "static", $edit->static, array(t("Disabled"), t("Enabled")));
// TODO: move this to the comment.module
if (module_exist("comment")) {
$output .= form_select(t("Allow user comments"), "comment", $edit->comment, array(t("Disabled"), t("Read only"), t("Read-write")));
}
$output .= implode("", node_invoke_all("nodeapi", $edit, "form", "admin"));
$output .= form_select(t("Create new revision"), "revision", $edit->revision, array(t("Disabled"), t("Enabled")));
}
......@@ -1299,4 +1309,11 @@ function node_update_index() {
"select" => "SELECT n.nid as lno, n.title as text1, n.body as text2 FROM node n WHERE n.status = 1 AND moderate = 0 and (created > " . variable_get("node_cron_last", 1) . " or changed > " . variable_get("node_cron_last", 1) . ")");
}
?>
function node_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case "fields":
return array("nid", "uid", "type", "title", "teaser", "body", "revisions", "score", "status", "promote", "static", "created", "changed", "users", "votes");
}
}
?>
\ No newline at end of file
......@@ -210,4 +210,15 @@ function queue_block($op = "list", $delta = 0) {
}
}
?>
function queue_nodeapi(&$node, $op, $arg = 0) {
switch ($op) {
case "form":
if ($arg == "admin" && user_access("administer moderation")) {
return form_select(t("Moderation status"), "moderate", $node->moderate, array(t("Approved"), t("Awaiting approval")));
}
break;
case "fields":
return array("moderate");
}
}
?>
\ No newline at end of file
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