diff --git a/includes/theme.inc b/includes/theme.inc index 0715585bf3909f8fe9eaad198b1f1b567e5af135..5046fc19ff958ec541a37d93abf4d584cdadb70e 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -232,7 +232,7 @@ function theme_get_settings($key = NULL) { ); if (module_exist('node')) { - foreach (node_list() as $type) { + foreach (node_get_types() as $type) { $defaults['toggle_node_info_' . $type] = 1; } } diff --git a/modules/blog.module b/modules/blog.module index 4327c34dbc67d60f28cd208b53a8a232db81581d..3dbe76083a5d03a0b0fb6286be81bd3b9944b9c0 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -7,10 +7,10 @@ */ /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function blog_node_name($node) { - return t('personal blog entry'); +function blog_node() { + return array('blog' => array('name' => t('personal blog entry'), 'base' => 'blog')); } /** diff --git a/modules/blog/blog.module b/modules/blog/blog.module index 4327c34dbc67d60f28cd208b53a8a232db81581d..3dbe76083a5d03a0b0fb6286be81bd3b9944b9c0 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -7,10 +7,10 @@ */ /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function blog_node_name($node) { - return t('personal blog entry'); +function blog_node() { + return array('blog' => array('name' => t('personal blog entry'), 'base' => 'blog')); } /** diff --git a/modules/blogapi.module b/modules/blogapi.module index 636f776716b15d286e93c407d4a6c39dee379a14..f42036d0e20d95edcf6f144b78c51c944c62c1e8 100644 --- a/modules/blogapi.module +++ b/modules/blogapi.module @@ -544,12 +544,8 @@ function blogapi_blogger_title(&$contents) { function blogapi_settings() { $output = form_select(t('XML-RPC Engine'), 'blogapi_engine', variable_get('blogapi_engine', 0), array(0 => 'Blogger', 1 => 'MetaWeblog', 2 => 'Movabletype'), t('RSD or Really-Simple-Discovery is a mechanism which allows external blogger tools to discover the APIs they can use to interact with Drupal. Here you can set the preferred method for blogger tools to interact with your site. The common XML-RPC engines are Blogger, MetaWeblog and Movabletype. If you are not sure which is the correct setting, choose Blogger.')); - foreach (node_list() as $type => $module) { - $node_types[$type] = node_invoke($type, 'node_name'); - if (in_array($type, array('blog'))) { - $defaults[] = $type; - } - } + $node_types = node_get_types(); + $defaults = isset($node_types['blog']) ? array('blog') : array(); $output .= form_checkboxes(t('Blog types'), "blogapi_node_types", variable_get('blogapi_node_types', $defaults), $node_types, t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).'), 0, 1); return $output; } @@ -716,7 +712,7 @@ function _blogapi_blogid($id) { function _blogapi_get_node_types() { $available_types = variable_get('blogapi_node_types', array('blog')); $types = array(); - foreach (node_list() as $type => $module) { + foreach (node_get_types() as $type => $name) { if (node_access('create', $type) && in_array($type, $available_types)) { $types[] = $type; } diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module index 636f776716b15d286e93c407d4a6c39dee379a14..f42036d0e20d95edcf6f144b78c51c944c62c1e8 100644 --- a/modules/blogapi/blogapi.module +++ b/modules/blogapi/blogapi.module @@ -544,12 +544,8 @@ function blogapi_blogger_title(&$contents) { function blogapi_settings() { $output = form_select(t('XML-RPC Engine'), 'blogapi_engine', variable_get('blogapi_engine', 0), array(0 => 'Blogger', 1 => 'MetaWeblog', 2 => 'Movabletype'), t('RSD or Really-Simple-Discovery is a mechanism which allows external blogger tools to discover the APIs they can use to interact with Drupal. Here you can set the preferred method for blogger tools to interact with your site. The common XML-RPC engines are Blogger, MetaWeblog and Movabletype. If you are not sure which is the correct setting, choose Blogger.')); - foreach (node_list() as $type => $module) { - $node_types[$type] = node_invoke($type, 'node_name'); - if (in_array($type, array('blog'))) { - $defaults[] = $type; - } - } + $node_types = node_get_types(); + $defaults = isset($node_types['blog']) ? array('blog') : array(); $output .= form_checkboxes(t('Blog types'), "blogapi_node_types", variable_get('blogapi_node_types', $defaults), $node_types, t('Select the content types for which you wish to enable posting via blogapi. Each type will appear as a different "blog" in the client application (if supported).'), 0, 1); return $output; } @@ -716,7 +712,7 @@ function _blogapi_blogid($id) { function _blogapi_get_node_types() { $available_types = variable_get('blogapi_node_types', array('blog')); $types = array(); - foreach (node_list() as $type => $module) { + foreach (node_get_types() as $type => $name) { if (node_access('create', $type) && in_array($type, $available_types)) { $types[] = $type; } diff --git a/modules/book.module b/modules/book.module index 72b165795ece57bd4c0e6d5cd190dc83e7a0833a..f65af1a58fb74973db4467ec4a90f802300c7214 100644 --- a/modules/book.module +++ b/modules/book.module @@ -7,10 +7,10 @@ */ /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function book_node_name($node) { - return t('book page'); +function book_node() { + return array('book' => array('name' => t('book page'), 'base' => 'book')); } /** diff --git a/modules/book/book.module b/modules/book/book.module index 72b165795ece57bd4c0e6d5cd190dc83e7a0833a..f65af1a58fb74973db4467ec4a90f802300c7214 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -7,10 +7,10 @@ */ /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function book_node_name($node) { - return t('book page'); +function book_node() { + return array('book' => array('name' => t('book page'), 'base' => 'book')); } /** diff --git a/modules/forum.module b/modules/forum.module index e46b34d60e6663d240acbe37f85b45b7462b8520..3fd910da0dcf62c644381a04ff70c1563911afa7 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -27,10 +27,10 @@ function forum_help($section) { } /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function forum_node_name($node) { - return t('forum topic'); +function forum_node() { + return array('forum' => array('name' => t('forum topic'), 'base' => 'forum')); } /** diff --git a/modules/forum/forum.module b/modules/forum/forum.module index e46b34d60e6663d240acbe37f85b45b7462b8520..3fd910da0dcf62c644381a04ff70c1563911afa7 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -27,10 +27,10 @@ function forum_help($section) { } /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function forum_node_name($node) { - return t('forum topic'); +function forum_node() { + return array('forum' => array('name' => t('forum topic'), 'base' => 'forum')); } /** diff --git a/modules/node.module b/modules/node.module index 36c6fb16e8bae2dc8b9e2e4bcf20ac9115f2458c..4a2f1a6557a32f902ed6396bf972dbb192457e27 100644 --- a/modules/node.module +++ b/modules/node.module @@ -32,8 +32,8 @@ function node_help($section) { <dt>Published</dt><dd>When using Drupal's moderation system a node remains unpublished -- unavailable to non-moderators -- until it is marked Published.</dd></dl> <p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/node/configure/settings"))); - foreach (node_list() as $type => $module) { - $output .= '<h3>'. t('Node type: %module', array('%module' => node_invoke($type, 'node_name'))). '</h3>'; + foreach (node_get_types() as $type => $name) { + $output .= '<h3>'. t('Node type: %name', array('%name' => $name)). '</h3>'; $output .= implode("\n", module_invoke_all('help', 'node/add#'. $type)); } @@ -202,55 +202,73 @@ function node_teaser($body, $format = NULL) { return truncate_utf8($body, $size); } +function _node_names($op = '', $node = NULL) { + static $node_names, $node_list; + + if (!isset($node_names)) { + $node_names = module_invoke_all('node'); + foreach ($node_names as $type => $value) { + $node_list[$type] = $value['name']; + } + } + if ($node) { + if (is_array($node)) { + $type = $node['type']; + } + elseif (is_object($node)) { + $type = $node->type; + } + elseif (is_string($node)) { + $type = $node; + } + if (!isset($node_names[$type])) { + return FALSE; + } + } + switch ($op) { + case 'base': + return $node_names[$type]['base']; + case 'list': + return $node_list; + case 'name': + return $node_list[$type]; + } +} + /** - * Determine the module that defines the node type of the given node. + * Determine the basename for hook_load etc. * - * @param &$node + * @param $node * Either a node object, a node array, or a string containing the node type. * @return - * A string containing the name of the defining module. + * The basename for hook_load, hook_nodeapi etc. */ -function node_get_module_name($node) { - if (is_array($node)) { - $type = $node['type']; - } - else if (is_object($node)) { - $type = $node->type; - } - else if (is_string($node)) { - $type = $node; - } - - $modules = node_list(); +function node_get_base($node) { + return _node_names('base', $node); +} - return $modules[$type]; +/** + * Determine the human readable name for a given type. + * + * @param $node + * Either a node object, a node array, or a string containing the node type. + * @return + * The human readable name of the node type. + */ +function node_get_name($node) { + return _node_names('name', $node); } /** - * Get a list of all the defined node types. + * Return the list of available node types. * + * @param $node + * Either a node object, a node array, or a string containing the node type. * @return - * An associate array of consisting of (node type, module name) pairs for all node types. + * An array consisting (type => name) pairs. */ -function node_list() { - static $types = array(); - - if (empty($types)) { - foreach (module_list() as $module) { - if (module_hook($module, 'node_name')) { - $module_types = module_invoke($module, 'node_types'); - if (is_array($module_types)) { - foreach ($module_types as $type) { - $types[$type] = $module; - } - } - else { - $types[$module] = $module; - } - } - } - } - return $types; +function node_get_types() { + return _node_names('list'); } /** @@ -264,9 +282,7 @@ function node_list() { * TRUE iff the $hook exists in the node type of $node. */ function node_hook(&$node, $hook) { - $function = node_get_module_name($node) ."_$hook"; - - return function_exists($function); + return module_hook(node_get_base($node), $hook); } /** @@ -282,9 +298,8 @@ function node_hook(&$node, $hook) { * The returned value of the invoked hook. */ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { - $function = node_get_module_name($node) ."_$hook"; - - if (function_exists($function)) { + if (node_hook($node, $hook)) { + $function = node_get_base($node) ."_$hook"; return ($function($node, $a2, $a3, $a4)); } } @@ -303,16 +318,14 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { */ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { $return = array(); - foreach (module_list() as $name) { + foreach (module_implements('nodeapi') as $name) { $function = $name .'_nodeapi'; - if (function_exists($function)) { - $result = $function($node, $op, $a3, $a4); - if (is_array($result)) { - $return = array_merge($return, $result); - } - else if (isset($result)) { - $return[] = $result; - } + $result = $function($node, $op, $a3, $a4); + if (is_array($result)) { + $return = array_merge($return, $result); + } + else if (isset($result)) { + $return[] = $result; } } return $return; @@ -575,7 +588,7 @@ function node_search($op = 'search', $keys = null) { $extra = node_invoke_nodeapi($node, 'search result'); $results[] = array('link' => url('node/'. $item), - 'type' => node_invoke($node, 'node_name'), + 'type' => node_get_name($node), 'title' => $node->title, 'user' => theme('username', $node), 'date' => $node->changed, @@ -700,7 +713,7 @@ function node_menu($may_cache) { } else if (arg(0) == 'admin' && arg(1) == 'settings' && arg(2) == 'content-types' && is_string(arg(3))) { $items[] = array('path' => 'admin/settings/content-types/'. arg(3), - 'title' => t("'%name' content type", array('%name' => node_invoke(arg(3), 'node_name'))), + 'title' => t("'%name' content type", array('%name' => node_get_name(arg(3)))), 'type' => MENU_CALLBACK); } } @@ -784,10 +797,6 @@ function node_admin_nodes() { /* ** Filters */ - $node_types = drupal_map_assoc(array_keys(node_list())); - foreach ($node_types as $k => $v) { - $node_types[$k] = node_invoke($v, 'node_name'); - } // Regular filters $filters = array( 'status' => array('title' => t('status'), @@ -796,7 +805,7 @@ function node_admin_nodes() { 'promote-1' => t('promoted'), 'promote-0' => t('not promoted'), 'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky'))), 'type' => array('title' => t('type'), 'where' => "n.type = '%s'", - 'options' => $node_types)); + 'options' => node_get_types())); // Merge all vocabularies into one for retrieving $value below if ($taxonomy = module_invoke('taxonomy', 'form_all')) { $terms = array(); @@ -912,7 +921,7 @@ function node_admin_nodes() { while ($node = db_fetch_object($result)) { $rows[] = array(form_checkbox(NULL, 'nodes]['. $node->nid, 1, 0), l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)), - node_invoke($node, 'node_name'), + node_get_name($node), theme('username', $node), ($node->status ? t('published') : t('not published')), l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination)); @@ -947,8 +956,8 @@ function node_types_configure($type = NULL) { $node = new stdClass(); $node->type = $type; - $group = form_textarea(t('Explanation or submission guidelines'), $type .'_help', variable_get($type .'_help', ''), 60, 5, t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_invoke($type, 'node_name')))); - $group .= form_select(t('Minimum number of words'), 'minimum_'. $type .'_size', variable_get('minimum_'. $type .'_size', 0), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_invoke($type, 'node_name')))); + $group = form_textarea(t('Explanation or submission guidelines'), $type .'_help', variable_get($type .'_help', ''), 60, 5, t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_get_name($type)))); + $group .= form_select(t('Minimum number of words'), 'minimum_'. $type .'_size', variable_get('minimum_'. $type .'_size', 0), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_get_name($type)))); $output = form_group(t('Submission form'), $group); $output .= form_group(t('Workflow'), implode('', node_invoke_nodeapi($node, 'settings'))); @@ -958,8 +967,8 @@ function node_types_configure($type = NULL) { $header = array(t('Type'), t('Operations')); $rows = array(); - foreach (node_list() as $type => $module) { - $rows[] = array(node_invoke($type, 'node_name'), l(t('configure'), 'admin/settings/content-types/'. $type)); + foreach (node_get_types() as $type => $name) { + $rows[] = array($name, l(t('configure'), 'admin/settings/content-types/'. $type)); } return theme('table', $header, $rows); @@ -1190,7 +1199,7 @@ function node_validate($node) { // Make sure the body has the minimum number of words. // todo use a better word counting algorithm that will work in other languages if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_'. $node->type .'_size', 0)) { - form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_invoke($node->type, 'node_name')))); + form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_get_name($node)))); } // Auto-generate the teaser, but only if it hasn't been set (e.g. by a @@ -1279,7 +1288,7 @@ function node_form($edit) { // Get the node-specific bits. // We can't use node_invoke() because $param must be passed by reference. - $function = node_get_module_name($edit) .'_form'; + $function = node_get_base($edit) .'_form'; $param = array(); if (function_exists($function)) { $form .= $function($edit, $param); @@ -1391,7 +1400,7 @@ function node_add($type) { $edit = $_POST['edit']; // If a node type has been specified, validate its existence. - if (array_key_exists($type, node_list()) && node_access('create', $type)) { + if (array_key_exists($type, node_get_types()) && node_access('create', $type)) { // Initialize settings: $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type); @@ -1403,15 +1412,15 @@ function node_add($type) { } } $output = node_form($node); - drupal_set_title(t('Submit %name', array('%name' => node_invoke($node, 'node_name')))); + drupal_set_title(t('Submit %name', array('%name' => node_get_name($node)))); } else { // If no (valid) node type has been provided, display a node type overview. - foreach (node_list() as $type => $module) { + foreach (node_get_types() as $type => $name) { if (node_access('create', $type)) { - $out = '<dt>'. l(node_invoke($type, 'node_name'), "node/add/$type", array('title' => t('Add a new %s.', array('%s' => node_invoke($type, 'node_name'))))) .'</dt>'; + $out = '<dt>'. l($name, "node/add/$type", array('title' => t('Add a new %s.', array('%s' => $name)))) .'</dt>'; $out .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>'; - $item[node_invoke($type, 'node_name')] = $out; + $item[$name] = $out; } } @@ -1485,8 +1494,7 @@ function node_preview($node) { $output .= node_form($node); - $name = node_invoke($node, 'node_name'); - drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => $name)), 'node/add/'. $node->type))); + drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => node_get_name($node))), 'node/add/'. $node->type))); return $output; } @@ -1543,7 +1551,7 @@ function node_submit(&$node) { if (node_access('update', $node)) { $node->nid = node_save($node); watchdog('content', t('%type: updated %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); - $msg = t('The %post was updated.', array ('%post' => node_invoke($node, 'node_name'))); + $msg = t('The %post was updated.', array ('%post' => node_get_name($node))); } } else { @@ -1552,7 +1560,7 @@ function node_submit(&$node) { if (node_access('create', $node)) { $node->nid = node_save($node); watchdog('content', t('%type: added %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); - $msg = t('Your %post was created.', array ('%post' => node_invoke($node, 'node_name'))); + $msg = t('Your %post was created.', array ('%post' => node_get_name($node))); } } @@ -1865,7 +1873,7 @@ function node_access($op, $node = NULL, $uid = NULL) { // Can't use node_invoke(), because the access hook takes the $op parameter // before the $node parameter. - $access = module_invoke(node_get_module_name($node), 'access', $op, $node); + $access = module_invoke(node_get_base($node), 'access', $op, $node); if (!is_null($access)) { return $access; } diff --git a/modules/node/node.module b/modules/node/node.module index 36c6fb16e8bae2dc8b9e2e4bcf20ac9115f2458c..4a2f1a6557a32f902ed6396bf972dbb192457e27 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -32,8 +32,8 @@ function node_help($section) { <dt>Published</dt><dd>When using Drupal's moderation system a node remains unpublished -- unavailable to non-moderators -- until it is marked Published.</dd></dl> <p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/node/configure/settings"))); - foreach (node_list() as $type => $module) { - $output .= '<h3>'. t('Node type: %module', array('%module' => node_invoke($type, 'node_name'))). '</h3>'; + foreach (node_get_types() as $type => $name) { + $output .= '<h3>'. t('Node type: %name', array('%name' => $name)). '</h3>'; $output .= implode("\n", module_invoke_all('help', 'node/add#'. $type)); } @@ -202,55 +202,73 @@ function node_teaser($body, $format = NULL) { return truncate_utf8($body, $size); } +function _node_names($op = '', $node = NULL) { + static $node_names, $node_list; + + if (!isset($node_names)) { + $node_names = module_invoke_all('node'); + foreach ($node_names as $type => $value) { + $node_list[$type] = $value['name']; + } + } + if ($node) { + if (is_array($node)) { + $type = $node['type']; + } + elseif (is_object($node)) { + $type = $node->type; + } + elseif (is_string($node)) { + $type = $node; + } + if (!isset($node_names[$type])) { + return FALSE; + } + } + switch ($op) { + case 'base': + return $node_names[$type]['base']; + case 'list': + return $node_list; + case 'name': + return $node_list[$type]; + } +} + /** - * Determine the module that defines the node type of the given node. + * Determine the basename for hook_load etc. * - * @param &$node + * @param $node * Either a node object, a node array, or a string containing the node type. * @return - * A string containing the name of the defining module. + * The basename for hook_load, hook_nodeapi etc. */ -function node_get_module_name($node) { - if (is_array($node)) { - $type = $node['type']; - } - else if (is_object($node)) { - $type = $node->type; - } - else if (is_string($node)) { - $type = $node; - } - - $modules = node_list(); +function node_get_base($node) { + return _node_names('base', $node); +} - return $modules[$type]; +/** + * Determine the human readable name for a given type. + * + * @param $node + * Either a node object, a node array, or a string containing the node type. + * @return + * The human readable name of the node type. + */ +function node_get_name($node) { + return _node_names('name', $node); } /** - * Get a list of all the defined node types. + * Return the list of available node types. * + * @param $node + * Either a node object, a node array, or a string containing the node type. * @return - * An associate array of consisting of (node type, module name) pairs for all node types. + * An array consisting (type => name) pairs. */ -function node_list() { - static $types = array(); - - if (empty($types)) { - foreach (module_list() as $module) { - if (module_hook($module, 'node_name')) { - $module_types = module_invoke($module, 'node_types'); - if (is_array($module_types)) { - foreach ($module_types as $type) { - $types[$type] = $module; - } - } - else { - $types[$module] = $module; - } - } - } - } - return $types; +function node_get_types() { + return _node_names('list'); } /** @@ -264,9 +282,7 @@ function node_list() { * TRUE iff the $hook exists in the node type of $node. */ function node_hook(&$node, $hook) { - $function = node_get_module_name($node) ."_$hook"; - - return function_exists($function); + return module_hook(node_get_base($node), $hook); } /** @@ -282,9 +298,8 @@ function node_hook(&$node, $hook) { * The returned value of the invoked hook. */ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { - $function = node_get_module_name($node) ."_$hook"; - - if (function_exists($function)) { + if (node_hook($node, $hook)) { + $function = node_get_base($node) ."_$hook"; return ($function($node, $a2, $a3, $a4)); } } @@ -303,16 +318,14 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { */ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { $return = array(); - foreach (module_list() as $name) { + foreach (module_implements('nodeapi') as $name) { $function = $name .'_nodeapi'; - if (function_exists($function)) { - $result = $function($node, $op, $a3, $a4); - if (is_array($result)) { - $return = array_merge($return, $result); - } - else if (isset($result)) { - $return[] = $result; - } + $result = $function($node, $op, $a3, $a4); + if (is_array($result)) { + $return = array_merge($return, $result); + } + else if (isset($result)) { + $return[] = $result; } } return $return; @@ -575,7 +588,7 @@ function node_search($op = 'search', $keys = null) { $extra = node_invoke_nodeapi($node, 'search result'); $results[] = array('link' => url('node/'. $item), - 'type' => node_invoke($node, 'node_name'), + 'type' => node_get_name($node), 'title' => $node->title, 'user' => theme('username', $node), 'date' => $node->changed, @@ -700,7 +713,7 @@ function node_menu($may_cache) { } else if (arg(0) == 'admin' && arg(1) == 'settings' && arg(2) == 'content-types' && is_string(arg(3))) { $items[] = array('path' => 'admin/settings/content-types/'. arg(3), - 'title' => t("'%name' content type", array('%name' => node_invoke(arg(3), 'node_name'))), + 'title' => t("'%name' content type", array('%name' => node_get_name(arg(3)))), 'type' => MENU_CALLBACK); } } @@ -784,10 +797,6 @@ function node_admin_nodes() { /* ** Filters */ - $node_types = drupal_map_assoc(array_keys(node_list())); - foreach ($node_types as $k => $v) { - $node_types[$k] = node_invoke($v, 'node_name'); - } // Regular filters $filters = array( 'status' => array('title' => t('status'), @@ -796,7 +805,7 @@ function node_admin_nodes() { 'promote-1' => t('promoted'), 'promote-0' => t('not promoted'), 'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky'))), 'type' => array('title' => t('type'), 'where' => "n.type = '%s'", - 'options' => $node_types)); + 'options' => node_get_types())); // Merge all vocabularies into one for retrieving $value below if ($taxonomy = module_invoke('taxonomy', 'form_all')) { $terms = array(); @@ -912,7 +921,7 @@ function node_admin_nodes() { while ($node = db_fetch_object($result)) { $rows[] = array(form_checkbox(NULL, 'nodes]['. $node->nid, 1, 0), l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)), - node_invoke($node, 'node_name'), + node_get_name($node), theme('username', $node), ($node->status ? t('published') : t('not published')), l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination)); @@ -947,8 +956,8 @@ function node_types_configure($type = NULL) { $node = new stdClass(); $node->type = $type; - $group = form_textarea(t('Explanation or submission guidelines'), $type .'_help', variable_get($type .'_help', ''), 60, 5, t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_invoke($type, 'node_name')))); - $group .= form_select(t('Minimum number of words'), 'minimum_'. $type .'_size', variable_get('minimum_'. $type .'_size', 0), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_invoke($type, 'node_name')))); + $group = form_textarea(t('Explanation or submission guidelines'), $type .'_help', variable_get($type .'_help', ''), 60, 5, t('This text will be displayed at the top of the %type submission form. It is useful for helping or instructing your users.', array('%type' => node_get_name($type)))); + $group .= form_select(t('Minimum number of words'), 'minimum_'. $type .'_size', variable_get('minimum_'. $type .'_size', 0), drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), t('The minimum number of words a %type must be to be considered valid. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.', array('%type' => node_get_name($type)))); $output = form_group(t('Submission form'), $group); $output .= form_group(t('Workflow'), implode('', node_invoke_nodeapi($node, 'settings'))); @@ -958,8 +967,8 @@ function node_types_configure($type = NULL) { $header = array(t('Type'), t('Operations')); $rows = array(); - foreach (node_list() as $type => $module) { - $rows[] = array(node_invoke($type, 'node_name'), l(t('configure'), 'admin/settings/content-types/'. $type)); + foreach (node_get_types() as $type => $name) { + $rows[] = array($name, l(t('configure'), 'admin/settings/content-types/'. $type)); } return theme('table', $header, $rows); @@ -1190,7 +1199,7 @@ function node_validate($node) { // Make sure the body has the minimum number of words. // todo use a better word counting algorithm that will work in other languages if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_'. $node->type .'_size', 0)) { - form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_invoke($node->type, 'node_name')))); + form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array('%words' => variable_get('minimum_'. $node->type .'_size', 0), '%type' => node_get_name($node)))); } // Auto-generate the teaser, but only if it hasn't been set (e.g. by a @@ -1279,7 +1288,7 @@ function node_form($edit) { // Get the node-specific bits. // We can't use node_invoke() because $param must be passed by reference. - $function = node_get_module_name($edit) .'_form'; + $function = node_get_base($edit) .'_form'; $param = array(); if (function_exists($function)) { $form .= $function($edit, $param); @@ -1391,7 +1400,7 @@ function node_add($type) { $edit = $_POST['edit']; // If a node type has been specified, validate its existence. - if (array_key_exists($type, node_list()) && node_access('create', $type)) { + if (array_key_exists($type, node_get_types()) && node_access('create', $type)) { // Initialize settings: $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type); @@ -1403,15 +1412,15 @@ function node_add($type) { } } $output = node_form($node); - drupal_set_title(t('Submit %name', array('%name' => node_invoke($node, 'node_name')))); + drupal_set_title(t('Submit %name', array('%name' => node_get_name($node)))); } else { // If no (valid) node type has been provided, display a node type overview. - foreach (node_list() as $type => $module) { + foreach (node_get_types() as $type => $name) { if (node_access('create', $type)) { - $out = '<dt>'. l(node_invoke($type, 'node_name'), "node/add/$type", array('title' => t('Add a new %s.', array('%s' => node_invoke($type, 'node_name'))))) .'</dt>'; + $out = '<dt>'. l($name, "node/add/$type", array('title' => t('Add a new %s.', array('%s' => $name)))) .'</dt>'; $out .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>'; - $item[node_invoke($type, 'node_name')] = $out; + $item[$name] = $out; } } @@ -1485,8 +1494,7 @@ function node_preview($node) { $output .= node_form($node); - $name = node_invoke($node, 'node_name'); - drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => $name)), 'node/add/'. $node->type))); + drupal_set_breadcrumb(array(l(t('Home'), NULL), l(t('create content'), 'node/add'), l(t('Submit %name', array('%name' => node_get_name($node))), 'node/add/'. $node->type))); return $output; } @@ -1543,7 +1551,7 @@ function node_submit(&$node) { if (node_access('update', $node)) { $node->nid = node_save($node); watchdog('content', t('%type: updated %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); - $msg = t('The %post was updated.', array ('%post' => node_invoke($node, 'node_name'))); + $msg = t('The %post was updated.', array ('%post' => node_get_name($node))); } } else { @@ -1552,7 +1560,7 @@ function node_submit(&$node) { if (node_access('create', $node)) { $node->nid = node_save($node); watchdog('content', t('%type: added %title.', array('%type' => theme('placeholder', t($node->type)), '%title' => theme('placeholder', $node->title))), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); - $msg = t('Your %post was created.', array ('%post' => node_invoke($node, 'node_name'))); + $msg = t('Your %post was created.', array ('%post' => node_get_name($node))); } } @@ -1865,7 +1873,7 @@ function node_access($op, $node = NULL, $uid = NULL) { // Can't use node_invoke(), because the access hook takes the $op parameter // before the $node parameter. - $access = module_invoke(node_get_module_name($node), 'access', $op, $node); + $access = module_invoke(node_get_base($node), 'access', $op, $node); if (!is_null($access)) { return $access; } diff --git a/modules/page.module b/modules/page.module index 51b34f6d550e852614dd12dafbe6bad61fb498fd..ca9c06c0ffd61cf1933043d188ab88981b252a7f 100644 --- a/modules/page.module +++ b/modules/page.module @@ -26,10 +26,10 @@ function page_perm() { } /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function page_node_name($node) { - return t('page'); +function page_node() { + return array('page' => array('name' => t('page'), 'base' => 'page')); } /** diff --git a/modules/page/page.module b/modules/page/page.module index 51b34f6d550e852614dd12dafbe6bad61fb498fd..ca9c06c0ffd61cf1933043d188ab88981b252a7f 100644 --- a/modules/page/page.module +++ b/modules/page/page.module @@ -26,10 +26,10 @@ function page_perm() { } /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function page_node_name($node) { - return t('page'); +function page_node() { + return array('page' => array('name' => t('page'), 'base' => 'page')); } /** diff --git a/modules/poll.module b/modules/poll.module index f5877c77091f41657d1acc5e6bb28eddfaa674c8..4973dcf9455d407fe57cce17700242e27493de1f 100644 --- a/modules/poll.module +++ b/modules/poll.module @@ -258,10 +258,10 @@ function poll_load($node) { } /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function poll_node_name($node) { - return t("poll"); +function poll_node() { + return array('poll' => array('name' => t("poll"), 'base' => 'poll')); } function poll_page() { diff --git a/modules/poll/poll.module b/modules/poll/poll.module index f5877c77091f41657d1acc5e6bb28eddfaa674c8..4973dcf9455d407fe57cce17700242e27493de1f 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -258,10 +258,10 @@ function poll_load($node) { } /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function poll_node_name($node) { - return t("poll"); +function poll_node() { + return array('poll' => array('name' => t("poll"), 'base' => 'poll')); } function poll_page() { diff --git a/modules/story.module b/modules/story.module index e1a51650944b883e9aff0b2fc33ef6dfbace119d..b4ee244c4b3bfef261724555f33689244ccb15c4 100644 --- a/modules/story.module +++ b/modules/story.module @@ -19,10 +19,10 @@ function story_help($section) { } /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function story_node_name($node) { - return t('story'); +function story_node() { + return array('story' => array('name' => t('story'), 'base' => 'story')); } /** diff --git a/modules/story/story.module b/modules/story/story.module index e1a51650944b883e9aff0b2fc33ef6dfbace119d..b4ee244c4b3bfef261724555f33689244ccb15c4 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -19,10 +19,10 @@ function story_help($section) { } /** - * Implementation of hook_node_name(). + * Implementation of hook_node(). */ -function story_node_name($node) { - return t('story'); +function story_node() { + return array('story' => array('name' => t('story'), 'base' => 'story')); } /** diff --git a/modules/system.module b/modules/system.module index b664f1f415b79d5c1768dea32d1758b69292030c..f62459f696b04dec9b038bb8d10c12c59b537fc0 100644 --- a/modules/system.module +++ b/modules/system.module @@ -790,11 +790,11 @@ function system_theme_settings($key = '') { } // Toggle node display. - $node_list = module_invoke('node', 'list'); - if ($node_list) { + $node_type = module_invoke('node', 'get_types'); + if ($node_types) { $group = ''; - foreach ($node_list as $type => $module) { - $group .= form_checkbox(node_invoke($type, 'node_name'), "$var][toggle_node_info_$type", 1, $settings["toggle_node_info_$type"]); + foreach ($node_types as $type => $name) { + $group .= form_checkbox($name, "$var][toggle_node_info_$type", 1, $settings["toggle_node_info_$type"]); } $form .= form_group(t('Display post information on'), $group, t('Enable or disable the "submitted by Username on date" text when displaying posts of the above type')); } diff --git a/modules/system/system.module b/modules/system/system.module index b664f1f415b79d5c1768dea32d1758b69292030c..f62459f696b04dec9b038bb8d10c12c59b537fc0 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -790,11 +790,11 @@ function system_theme_settings($key = '') { } // Toggle node display. - $node_list = module_invoke('node', 'list'); - if ($node_list) { + $node_type = module_invoke('node', 'get_types'); + if ($node_types) { $group = ''; - foreach ($node_list as $type => $module) { - $group .= form_checkbox(node_invoke($type, 'node_name'), "$var][toggle_node_info_$type", 1, $settings["toggle_node_info_$type"]); + foreach ($node_types as $type => $name) { + $group .= form_checkbox($name, "$var][toggle_node_info_$type", 1, $settings["toggle_node_info_$type"]); } $form .= form_group(t('Display post information on'), $group, t('Enable or disable the "submitted by Username on date" text when displaying posts of the above type')); } diff --git a/modules/taxonomy.module b/modules/taxonomy.module index 1dbde4f816dace75fe27386c23d165c401f638eb..4bbfbe36c0c12f81cdc9e6955e86455cdd517304 100644 --- a/modules/taxonomy.module +++ b/modules/taxonomy.module @@ -107,17 +107,12 @@ function taxonomy_menu($may_cache) { } function taxonomy_form_vocabulary($edit = array()) { - foreach (node_list() as $type => $module) { - $node_type = node_invoke($type, 'node_name'); - $nodes[$type] = $node_type ? $node_type : $type; - } - $form .= form_textfield(t('Vocabulary name'), 'name', $edit['name'], 60, 64, t('The name for this vocabulary. Example: "Topic".'), NULL, TRUE); // Prepend extra vocabulary form elements. $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'vocabulary', $edit)); $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('Description of the vocabulary; can be used by modules.')); $form .= form_textfield(t('Help text'), 'help', $edit['help'], 60, 255, t('Instructions to present to the user when choosing a term.')); - $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], $nodes, t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE); + $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], node_get_types(), t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE); $form .= form_radios(t('Hierarchy'), 'hierarchy', $edit['hierarchy'], array(t('Disabled'), t('Single'), t('Multiple')), t('Allows <a href="%help-url">a tree-like hierarchy</a> between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy')))); $form .= form_checkbox(t('Related terms'), 'relations', 1, $edit['relations'], t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms')))); $form .= form_checkbox(t('Free tagging'), 'tags', 1, $edit['tags'], t('Content is categorized by typing terms instead of choosing from a list.')); @@ -374,7 +369,7 @@ function taxonomy_overview() { foreach ($vocabularies as $vocabulary) { $types = array(); foreach ($vocabulary->nodes as $type) { - $node_type = node_invoke($type, 'node_name'); + $node_type = node_get_name($type); $types[] = $node_type ? $node_type : $type; } $rows[] = array(check_plain($vocabulary->name), implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('edit terms'), "admin/taxonomy/$vocabulary->vid")); diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 1dbde4f816dace75fe27386c23d165c401f638eb..4bbfbe36c0c12f81cdc9e6955e86455cdd517304 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -107,17 +107,12 @@ function taxonomy_menu($may_cache) { } function taxonomy_form_vocabulary($edit = array()) { - foreach (node_list() as $type => $module) { - $node_type = node_invoke($type, 'node_name'); - $nodes[$type] = $node_type ? $node_type : $type; - } - $form .= form_textfield(t('Vocabulary name'), 'name', $edit['name'], 60, 64, t('The name for this vocabulary. Example: "Topic".'), NULL, TRUE); // Prepend extra vocabulary form elements. $form .= implode('', module_invoke_all('taxonomy', 'form pre', 'vocabulary', $edit)); $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('Description of the vocabulary; can be used by modules.')); $form .= form_textfield(t('Help text'), 'help', $edit['help'], 60, 255, t('Instructions to present to the user when choosing a term.')); - $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], $nodes, t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE); + $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], node_get_types(), t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE); $form .= form_radios(t('Hierarchy'), 'hierarchy', $edit['hierarchy'], array(t('Disabled'), t('Single'), t('Multiple')), t('Allows <a href="%help-url">a tree-like hierarchy</a> between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy')))); $form .= form_checkbox(t('Related terms'), 'relations', 1, $edit['relations'], t('Allows <a href="%help-url">related terms</a> in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms')))); $form .= form_checkbox(t('Free tagging'), 'tags', 1, $edit['tags'], t('Content is categorized by typing terms instead of choosing from a list.')); @@ -374,7 +369,7 @@ function taxonomy_overview() { foreach ($vocabularies as $vocabulary) { $types = array(); foreach ($vocabulary->nodes as $type) { - $node_type = node_invoke($type, 'node_name'); + $node_type = node_get_name($type); $types[] = $node_type ? $node_type : $type; } $rows[] = array(check_plain($vocabulary->name), implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('edit terms'), "admin/taxonomy/$vocabulary->vid")); diff --git a/modules/tracker.module b/modules/tracker.module index 8b1dee05b547d8e22303debaaade67346e971a90..d4112f511a46774a5da48b1a1a5e7df3fc8fbe12 100644 --- a/modules/tracker.module +++ b/modules/tracker.module @@ -100,7 +100,7 @@ function tracker_page($uid = 0) { } $rows[] = array( - node_invoke($node->type, 'node_name'), + node_get_name($node->type), l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), theme('username', $node), array('class' => 'replies', 'data' => $comments), diff --git a/modules/tracker/tracker.module b/modules/tracker/tracker.module index 8b1dee05b547d8e22303debaaade67346e971a90..d4112f511a46774a5da48b1a1a5e7df3fc8fbe12 100644 --- a/modules/tracker/tracker.module +++ b/modules/tracker/tracker.module @@ -100,7 +100,7 @@ function tracker_page($uid = 0) { } $rows[] = array( - node_invoke($node->type, 'node_name'), + node_get_name($node->type), l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)), theme('username', $node), array('class' => 'replies', 'data' => $comments),