=== modified file 'modules/blog/blog.module' --- modules/blog/blog.module 2008-12-31 12:02:21 +0000 +++ modules/blog/blog.module 2009-03-08 05:31:23 +0000 @@ -74,7 +74,7 @@ */ function blog_form($node, $form_state) { global $nid; - $type = node_get_types('type', $node); + $type = node_get_type($node); $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => !empty($node->title) ? $node->title : NULL, '#weight' => -5); $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count); === modified file 'modules/blogapi/blogapi.module' --- modules/blogapi/blogapi.module 2009-02-26 07:30:26 +0000 +++ modules/blogapi/blogapi.module 2009-03-08 05:28:06 +0000 @@ -719,7 +719,7 @@ * Add some settings to the admin_settings form. */ function blogapi_admin_settings() { - $node_types = array_map('check_plain', node_get_types('names')); + $node_types = array_map('check_plain', node_get_names()); $defaults = isset($node_types['blog']) ? array('blog' => 1) : array(); $form['blogapi_node_types'] = array( '#type' => 'checkboxes', === modified file 'modules/book/book.admin.inc' --- modules/book/book.admin.inc 2009-02-05 19:29:31 +0000 +++ modules/book/book.admin.inc 2009-03-08 05:28:06 +0000 @@ -35,7 +35,7 @@ * @ingroup forms */ function book_admin_settings() { - $types = node_get_types('names'); + $types = node_get_names(); $form['book_allowed_types'] = array( '#type' => 'checkboxes', '#title' => t('Allowed book outline types'), === modified file 'modules/forum/forum.module' --- modules/forum/forum.module 2009-02-26 07:30:26 +0000 +++ modules/forum/forum.module 2009-03-08 05:32:35 +0000 @@ -539,7 +539,7 @@ * Implementation of hook_form(). */ function forum_form(&$node, $form_state) { - $type = node_get_types('type', $node); + $type = node_get_type($node); $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#default_value' => !empty($node->title) ? $node->title : '', '#required' => TRUE, '#weight' => -5); if (!empty($node->nid)) { @@ -747,7 +747,7 @@ if (node_access('create', $type)) { // Fetch the "General" name of the content type; // Push the link with title and url to the array. - $forum_types[$type] = array('title' => t('Post new @node_type', array('@node_type' => node_get_types('name', $type))), 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $variables['tid']); + $forum_types[$type] = array('title' => t('Post new @node_type', array('@node_type' => node_get_name($type))), 'href' => 'node/add/' . str_replace('_', '-', $type) . '/' . $variables['tid']); } } === modified file 'modules/node/content_types.inc' --- modules/node/content_types.inc 2009-01-26 14:08:40 +0000 +++ modules/node/content_types.inc 2009-03-08 05:33:03 +0000 @@ -11,12 +11,13 @@ */ function node_overview_types() { $types = node_get_types(); - $names = node_get_types('names'); + $names = node_get_names(); $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => '2')); $rows = array(); foreach ($names as $key => $name) { $type = $types[$key]; + if (node_hook($type, 'form')) { $type_url_str = str_replace('_', '-', $type->type); $row = array(theme('node_admin_overview', $name, $type)); @@ -233,7 +234,7 @@ // Work out what the type was before the user submitted this form $old_type = trim($form_state['values']['old_type']); - $types = node_get_types('names'); + $types = node_get_names(); if (!$form_state['values']['locked']) { if (isset($types[$type->type]) && $type->type != $old_type) { === modified file 'modules/node/node.admin.inc' --- modules/node/node.admin.inc 2009-02-26 07:30:26 +0000 +++ modules/node/node.admin.inc 2009-03-08 05:33:47 +0000 @@ -150,7 +150,7 @@ ); } - $filters['type'] = array('title' => t('type'), 'options' => node_get_types('names')); + $filters['type'] = array('title' => t('type'), 'options' => node_get_names()); // The taxonomy filter if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) { @@ -514,7 +514,7 @@ $nodes[$node->nid] = ''; $options = empty($node->language) ? array() : array('language' => $languages[$node->language]); $form['title'][$node->nid] = array('#markup' => l($node->title, 'node/' . $node->nid, $options) . ' ' . theme('mark', node_mark($node->nid, $node->changed))); - $form['name'][$node->nid] = array('#markup' => check_plain(node_get_types('name', $node))); + $form['name'][$node->nid] = array('#markup' => check_plain(node_get_name($node))); $form['username'][$node->nid] = array('#markup' => theme('username', $node)); $form['status'][$node->nid] = array('#markup' => ($node->status ? t('published') : t('not published'))); $form['changed'][$node->nid] = array('#markup' => format_date($node->changed, 'small')); === modified file 'modules/node/node.module' --- modules/node/node.module 2009-02-26 07:30:26 +0000 +++ modules/node/node.module 2009-03-08 05:43:44 +0000 @@ -80,12 +80,12 @@ return '

' . t('The revisions let you track differences between multiple versions of a post.') . '

'; case 'node/%/edit': $node = node_load($arg[1]); - $type = node_get_types('type', $node->type); + $type = node_get_type($node); return (!empty($type->help) ? '

' . filter_xss_admin($type->help) . '

' : ''); } if ($arg[0] == 'node' && $arg[1] == 'add' && $arg[2]) { - $type = node_get_types('type', str_replace('-', '_', $arg[2])); + $type = node_get_type(str_replace('-', '_', $arg[2])); return (!empty($type->help) ? '

' . filter_xss_admin($type->help) . '

' : ''); } } @@ -470,6 +470,67 @@ } /** + * Builds a list of all the available node types. + * + * @param $reset + * Whether or not to reset the node list (defaults to FALSE). + * @return + * A list of node types, as an array. + */ +function node_get_types($reset = FALSE) { + return _node_get_types('types', null, $reset); +} + +/** + * Returns false if the node type does not exist. Otherwise returns the node's type. + * + *@param $node + * A node object, array, or string that indicates the node type to return. + * Leave at default value (NULL) to return a list of all node types. + * @return + * A single node type, as a string. Returns FALSE if the node name is not found. + */ +function node_get_type($node) { + return _node_get_types('type', $node); +} + +/** + * Returns a list of available node names. + * + * @return + * A list of node names, as an array. + */ +function node_get_names() { + return _node_get_types('names'); +} + +/** + * Returns false if the node name does not exist. Otherwise returns the node's name. + * + * @param $node + * A node object, array, or string that indicates the node type to return. + * + * @return + * A single node name, as a string. Returns FALSE if the node name is not found. + */ +function node_get_name($node) { + return _node_get_types('name', $node); +} + + /** + * Returns false if the module does not exist. Otherwise returns the module's name. + * + * @param $node + * A node object, array, or string that indicates the node type to return. + * + * @return + * A module name, as a string. Returns FALSE if the module is not found. + */ +function node_get_module($node) { + return _node_get_types('module', $node); +} + +/** * Builds a list of available node types, and returns all of part of this list * in the specified format. * @@ -488,7 +549,7 @@ * Either an array of all available node types, or a single node type, in a * variable format. Returns FALSE if the node type is not found. */ -function node_get_types($op = 'types', $node = NULL, $reset = FALSE) { +function _node_get_types($op = 'types', $node = NULL, $reset = FALSE) { static $_node_types, $_node_names; if ($reset || !isset($_node_types)) { @@ -604,7 +665,7 @@ * The machine-readable name of the node type to be deleted. */ function node_type_delete($type) { - $info = node_get_types('type', $type); + $info = node_get_type($type); db_query("DELETE FROM {node_type} WHERE type = '%s'", $type); module_invoke_all('node_type', 'delete', $info); } @@ -730,7 +791,7 @@ * TRUE iff the $hook exists in the node type of $node. */ function node_hook(&$node, $hook) { - $base = node_get_types('base', $node); + $base = node_get_type($node); return module_hook($base, $hook); } @@ -748,7 +809,7 @@ */ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { if (node_hook($node, $hook)) { - $base = node_get_types('base', $node); + $base = node_get_mode($node); $function = $base . '_' . $hook; return ($function($node, $a2, $a3, $a4)); } @@ -970,7 +1031,7 @@ function node_validate($node, $form = array()) { // Convert the node to an object, if necessary. $node = (object)$node; - $type = node_get_types('type', $node); + $type = node_get_type($node); // Make sure the body has the minimum number of words. // TODO : use a better word counting algorithm that will work in other languages @@ -1186,7 +1247,7 @@ search_wipe($node->nid, 'node'); } watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title)); - drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_types('name', $node), '%title' => $node->title))); + drupal_set_message(t('@type %title has been deleted.', array('@type' => node_get_name($node), '%title' => $node->title))); } } @@ -1507,7 +1568,7 @@ $results[] = array( 'link' => url('node/' . $item->sid, array('absolute' => TRUE)), - 'type' => check_plain(node_get_types('name', $node)), + 'type' => check_plain(node_get_name($node)), 'title' => $node->title, 'user' => theme('username', $node), 'date' => $node->changed, @@ -1744,7 +1805,7 @@ 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); - foreach (node_get_types('types', NULL, TRUE) as $type) { + foreach (node_get_types(TRUE) as $type) { $type_url_str = str_replace('_', '-', $type->type); $items['node/add/' . $type_url_str] = array( 'title' => $type->name, @@ -2169,7 +2230,7 @@ } // Node types: - $types = array_map('check_plain', node_get_types('names')); + $types = array_map('check_plain', node_get_names()); $form['advanced']['type'] = array( '#type' => 'checkboxes', '#title' => t('Only of the type(s)'), @@ -2326,7 +2387,7 @@ // Can't use node_invoke('access', $node), because the access hook takes the // $op parameter before the $node parameter. - $base = node_get_types('base', $node); + $base = node_get_module($node); $access = module_invoke($base, 'access', $op, $node, $account); if (!is_null($access)) { return $access; @@ -2777,7 +2838,9 @@ * Implementation of hook_form(). */ function node_content_form($node, $form_state) { - $type = node_get_types('type', $node); + + $type = node_get_type($node); + $form = array(); if ($type->has_title) { @@ -2956,7 +3019,7 @@ */ function node_publish_action(&$node, $context = array()) { $node->status = 1; - watchdog('action', 'Set @type %title to published.', array('@type' => node_get_types('name', $node), '%title' => $node->title)); + watchdog('action', 'Set @type %title to published.', array('@type' => node_get_name($node), '%title' => $node->title)); } /** @@ -2965,7 +3028,7 @@ */ function node_unpublish_action(&$node, $context = array()) { $node->status = 0; - watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_types('name', $node), '%title' => $node->title)); + watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_name($node), '%title' => $node->title)); } /** @@ -2974,7 +3037,7 @@ */ function node_make_sticky_action(&$node, $context = array()) { $node->sticky = 1; - watchdog('action', 'Set @type %title to sticky.', array('@type' => node_get_types('name', $node), '%title' => $node->title)); + watchdog('action', 'Set @type %title to sticky.', array('@type' => node_get_name($node), '%title' => $node->title)); } /** @@ -2983,7 +3046,7 @@ */ function node_make_unsticky_action(&$node, $context = array()) { $node->sticky = 0; - watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_get_types('name', $node), '%title' => $node->title)); + watchdog('action', 'Set @type %title to unsticky.', array('@type' => node_get_name($node), '%title' => $node->title)); } /** @@ -3020,7 +3083,7 @@ function node_assign_owner_action(&$node, $context) { $node->uid = $context['owner_uid']; $owner_name = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $context['owner_uid'])); - watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_get_types('type', $node), '%title' => $node->title, '%name' => $owner_name)); + watchdog('action', 'Changed owner of @type %title to uid %name.', array('@type' => node_get_type($node), '%title' => $node->title, '%name' => $owner_name)); } function node_assign_owner_action_form($context) { === modified file 'modules/node/node.pages.inc' --- modules/node/node.pages.inc 2009-02-13 02:22:09 +0000 +++ modules/node/node.pages.inc 2009-03-08 05:38:30 +0000 @@ -440,7 +440,7 @@ node_save($node); $node_link = l(t('view'), 'node/' . $node->nid); $watchdog_args = array('@type' => $node->type, '%title' => $node->title); - $t_args = array('@type' => node_get_types('name', $node), '%title' => $node->title); + $t_args = array('@type' => node_get_name($node), '%title' => $node->title); if ($insert) { watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link); @@ -572,7 +572,7 @@ node_save($node_revision); watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid)); - drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_get_types('name', $node_revision), '%title' => $node_revision->title, '%revision-date' => format_date($node_revision->revision_timestamp)))); + drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_get_name($node_revision), '%title' => $node_revision->title, '%revision-date' => format_date($node_revision->revision_timestamp)))); $form_state['redirect'] = 'node/' . $node_revision->nid . '/revisions'; } @@ -586,7 +586,7 @@ db_query("DELETE FROM {node_revision} WHERE nid = %d AND vid = %d", $node_revision->nid, $node_revision->vid); node_invoke_nodeapi($node_revision, 'delete_revision'); watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid)); - drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_get_types('name', $node_revision), '%title' => $node_revision->title))); + drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_get_name($node_revision), '%title' => $node_revision->title))); $form_state['redirect'] = 'node/' . $node_revision->nid; if (db_result(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = %d', $node_revision->nid)) > 1) { $form_state['redirect'] .= '/revisions'; === modified file 'modules/poll/poll.module' --- modules/poll/poll.module 2009-02-18 14:28:21 +0000 +++ modules/poll/poll.module 2009-03-08 05:28:06 +0000 @@ -194,7 +194,7 @@ $admin = user_access('administer nodes') || user_access('edit any poll content') || (user_access('edit own poll content') && $user->uid == $node->uid); - $type = node_get_types('type', $node); + $type = node_get_type($node); $form = array( '#cache' => TRUE, === modified file 'modules/system/system.module' --- modules/system/system.module 2009-02-22 17:55:28 +0000 +++ modules/system/system.module 2009-03-08 05:39:48 +0000 @@ -2067,7 +2067,7 @@ $variables += array( '%uid' => $node->uid, '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)), - '%node_type' => node_get_types('name', $node), + '%node_type' => node_get_name($node), '%title' => $node->title, '%teaser' => $node->teaser, '%body' => $node->body, @@ -2141,7 +2141,7 @@ $variables = array_merge($variables, array( '%uid' => $node->uid, '%node_url' => url('node/' . $node->nid, array('absolute' => TRUE)), - '%node_type' => check_plain(node_get_types('name', $node)), + '%node_type' => check_plain(node_get_name($node)), '%title' => filter_xss($node->title), '%teaser' => filter_xss($node->teaser), '%body' => filter_xss($node->body), === modified file 'modules/taxonomy/taxonomy.admin.inc' --- modules/taxonomy/taxonomy.admin.inc 2009-02-24 16:48:18 +0000 +++ modules/taxonomy/taxonomy.admin.inc 2009-03-08 05:28:07 +0000 @@ -19,7 +19,7 @@ foreach ($vocabularies as $vocabulary) { $types = array(); foreach ($vocabulary->nodes as $type) { - $node_type = node_get_types('name', $type); + $node_type = node_get_name($type); $types[] = $node_type ? check_plain($node_type) : check_plain($type); } $form[$vocabulary->vid]['#vocabulary'] = $vocabulary; @@ -145,7 +145,7 @@ '#type' => 'checkboxes', '#title' => t('Content types'), '#default_value' => $edit['nodes'], - '#options' => array_map('check_plain', node_get_types('names')), + '#options' => array_map('check_plain', node_get_names()), '#description' => t('Select content types to categorize using this vocabulary.'), ); $form['settings'] = array( === modified file 'modules/tracker/tracker.pages.inc' --- modules/tracker/tracker.pages.inc 2009-02-26 07:30:26 +0000 +++ modules/tracker/tracker.pages.inc 2009-03-08 05:41:15 +0000 @@ -50,7 +50,7 @@ } $rows[] = array( - check_plain(node_get_types('name', $node->type)), + check_plain(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),