- Patch #6612 by JonBob: extended the node API with new hooks.

4.5.x
Dries Buytaert 2004-04-28 20:23:30 +00:00
parent 3117258552
commit 2ca7eb7152
2 changed files with 44 additions and 42 deletions

View File

@ -312,12 +312,12 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
}
}
function node_invoke_nodeapi(&$node, $op, $arg = 0) {
function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$return = array();
foreach (module_list() as $name) {
$function = $name .'_nodeapi';
if (function_exists($function)) {
$result = $function($node, $op, $arg);
$result = $function($node, $op, $a3, $a4);
if (isset($result)) {
$return = array_merge($return, $result);
}
@ -362,6 +362,12 @@ function node_load($conditions, $revision = -1) {
}
}
if ($extra = node_invoke_nodeapi($node, 'load')) {
foreach ($extra as $key => $value) {
$node->$key = $value;
}
}
/*
** Return the desired revision
*/
@ -477,6 +483,9 @@ function node_view($node, $main = 0, $page = 0) {
$node->body = str_replace('<!--break-->', '', $node->body);
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', $main, $page);
/*
** The 'view' hook can be implemented to overwrite the default function
** to display nodes.
@ -780,24 +789,6 @@ function node_admin_settings($edit) {
$output .= theme('table', $header, $rows);
/* This is an idea for the future.
foreach (node_list() as $type) {
$node->type = $type;
// Create theme('table', ) data:
$header = array_keys(node_invoke_nodeapi($node, 'settings'));
$cols = array();
foreach (node_invoke_nodeapi($node, 'settings') as $setting) {
$cols[] = array('data' => $setting, 'align' => 'center', 'width' => 75);
}
$output .= '<h2>'. node_invoke($node, 'node_name') .'</h2>';
$output .= theme('table', $header, array($cols));
$output .= '<br /><br />';
}
}
*/
$output .= form_submit(t('Save configuration'));
$output .= form_submit(t('Reset to defaults'));
@ -1188,7 +1179,7 @@ function node_form($edit, $error = NULL) {
$output .= form_group(t('Options'), $options);
$output .= "</div>\n";
$extras .= implode("</div><div class=\"extra\">", node_invoke_nodeapi($edit, 'form admin'));
$extras .= implode("</div><div class=\"extra\">", node_invoke_nodeapi($edit, 'form admin', $error));
$output .= $extras ? "<div class=\"extra\">$extras</div></div>" : "</div>";
}
@ -1247,6 +1238,16 @@ function node_form($edit, $error = NULL) {
$output .= "</div></div>";
$extra = node_invoke_nodeapi($edit, "form param");
foreach ($extra as $key => $value) {
if (is_array($value)) {
$param[$key] = array_merge($param[$key], $value);
}
else {
$param[$key] = $value;
}
}
return form($output, ($param['method'] ? $param['method'] : 'post'), $param['action'], array_merge($param['options'], array('id' => 'node-form')));
}

View File

@ -312,12 +312,12 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
}
}
function node_invoke_nodeapi(&$node, $op, $arg = 0) {
function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$return = array();
foreach (module_list() as $name) {
$function = $name .'_nodeapi';
if (function_exists($function)) {
$result = $function($node, $op, $arg);
$result = $function($node, $op, $a3, $a4);
if (isset($result)) {
$return = array_merge($return, $result);
}
@ -362,6 +362,12 @@ function node_load($conditions, $revision = -1) {
}
}
if ($extra = node_invoke_nodeapi($node, 'load')) {
foreach ($extra as $key => $value) {
$node->$key = $value;
}
}
/*
** Return the desired revision
*/
@ -477,6 +483,9 @@ function node_view($node, $main = 0, $page = 0) {
$node->body = str_replace('<!--break-->', '', $node->body);
// Allow modules to change $node->body before viewing.
node_invoke_nodeapi($node, 'view', $main, $page);
/*
** The 'view' hook can be implemented to overwrite the default function
** to display nodes.
@ -780,24 +789,6 @@ function node_admin_settings($edit) {
$output .= theme('table', $header, $rows);
/* This is an idea for the future.
foreach (node_list() as $type) {
$node->type = $type;
// Create theme('table', ) data:
$header = array_keys(node_invoke_nodeapi($node, 'settings'));
$cols = array();
foreach (node_invoke_nodeapi($node, 'settings') as $setting) {
$cols[] = array('data' => $setting, 'align' => 'center', 'width' => 75);
}
$output .= '<h2>'. node_invoke($node, 'node_name') .'</h2>';
$output .= theme('table', $header, array($cols));
$output .= '<br /><br />';
}
}
*/
$output .= form_submit(t('Save configuration'));
$output .= form_submit(t('Reset to defaults'));
@ -1188,7 +1179,7 @@ function node_form($edit, $error = NULL) {
$output .= form_group(t('Options'), $options);
$output .= "</div>\n";
$extras .= implode("</div><div class=\"extra\">", node_invoke_nodeapi($edit, 'form admin'));
$extras .= implode("</div><div class=\"extra\">", node_invoke_nodeapi($edit, 'form admin', $error));
$output .= $extras ? "<div class=\"extra\">$extras</div></div>" : "</div>";
}
@ -1247,6 +1238,16 @@ function node_form($edit, $error = NULL) {
$output .= "</div></div>";
$extra = node_invoke_nodeapi($edit, "form param");
foreach ($extra as $key => $value) {
if (is_array($value)) {
$param[$key] = array_merge($param[$key], $value);
}
else {
$param[$key] = $value;
}
}
return form($output, ($param['method'] ? $param['method'] : 'post'), $param['action'], array_merge($param['options'], array('id' => 'node-form')));
}