summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-07-17 20:57:43 +0000
committerDries Buytaert <dries@buytaert.net>2005-07-17 20:57:43 +0000
commit2895357de0af2ea92bc758b20f4e305902e7b02f (patch)
tree0a7bb76a39496368386762dff42c64f8b2eb9182
parent28c72cd89d66ad4d8c2a5d19a620a8d3914e356d (diff)
downloadbrdo-2895357de0af2ea92bc758b20f4e305902e7b02f.tar.gz
brdo-2895357de0af2ea92bc758b20f4e305902e7b02f.tar.bz2
- Modified patch #25031 by chx: modified node_list() so one has both the module and its type.
TODO: update migration page in handbook.
-rw-r--r--modules/blogapi.module4
-rw-r--r--modules/blogapi/blogapi.module4
-rw-r--r--modules/node.module62
-rw-r--r--modules/node/node.module62
-rw-r--r--modules/system.module2
-rw-r--r--modules/system/system.module2
-rw-r--r--modules/taxonomy.module2
-rw-r--r--modules/taxonomy/taxonomy.module2
8 files changed, 62 insertions, 78 deletions
diff --git a/modules/blogapi.module b/modules/blogapi.module
index 1a4e8f6b7..df376580f 100644
--- a/modules/blogapi.module
+++ b/modules/blogapi.module
@@ -535,7 +535,7 @@ 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) {
+ foreach (node_list() as $type => $module) {
$node_types[$type] = node_invoke($type, 'node_name');
if (in_array($type, array('blog'))) {
$defaults[] = $type;
@@ -707,7 +707,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) {
+ foreach (node_list() as $type => $module) {
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 1a4e8f6b7..df376580f 100644
--- a/modules/blogapi/blogapi.module
+++ b/modules/blogapi/blogapi.module
@@ -535,7 +535,7 @@ 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) {
+ foreach (node_list() as $type => $module) {
$node_types[$type] = node_invoke($type, 'node_name');
if (in_array($type, array('blog'))) {
$defaults[] = $type;
@@ -707,7 +707,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) {
+ foreach (node_list() as $type => $module) {
if (node_access('create', $type) && in_array($type, $available_types)) {
$types[] = $type;
}
diff --git a/modules/node.module b/modules/node.module
index 3a8903901..c292d92c5 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -32,7 +32,7 @@ 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) {
+ foreach (node_list() as $type => $module) {
$output .= '<h3>'. t('Node type: %module', array('%module' => node_invoke($type, 'node_name'))). '</h3>';
$output .= implode("\n", module_invoke_all('help', 'node/add#'. $type));
}
@@ -212,49 +212,41 @@ function node_teaser($body, $format = NULL) {
*/
function node_get_module_name($node) {
if (is_array($node)) {
- if ($pos = strpos($node['type'], '-')) {
- return substr($node['type'], 0, $pos);
- }
- else {
- return $node['type'];
- }
+ $type = $node['type'];
}
else if (is_object($node)) {
- if ($pos = strpos($node->type, '-')) {
- return substr($node->type, 0, $pos);
- }
- else {
- return $node->type;
- }
+ $type = $node->type;
}
else if (is_string($node)) {
- if ($pos = strpos($node, '-')) {
- return substr($node, 0, $pos);
- }
- else {
- return $node;
- }
+ $type = $node;
}
+
+ $modules = node_list();
+
+ return $modules[$type];
}
/**
* Get a list of all the defined node types.
*
* @return
- * A list of all node types.
+ * An associate array of consisting of (node type, modulename) pairs for all node types.
*/
function node_list() {
- $types = array();
- 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;
+ 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;
}
- }
- else {
- $types[] = $module;
}
}
}
@@ -781,7 +773,7 @@ function node_admin_nodes() {
/*
** Filters
*/
- $node_types = drupal_map_assoc(node_list());
+ $node_types = drupal_map_assoc(array_keys(node_list()));
foreach ($node_types as $k => $v) {
$node_types[$k] = node_invoke($v, 'node_name');
}
@@ -955,7 +947,7 @@ function node_types_configure($type = NULL) {
$header = array(t('Type'), t('Operations'));
$rows = array();
- foreach (node_list() as $type) {
+ foreach (node_list() as $type => $module) {
$rows[] = array(node_invoke($type, 'node_name'), l(t('configure'), 'admin/settings/content-types/'. $type));
}
@@ -1388,7 +1380,7 @@ function node_add($type) {
$edit = $_POST['edit'];
// If a node type has been specified, validate its existence.
- if (in_array($type, node_list()) && node_access('create', $type)) {
+ if (array_key_exists($type, node_list()) && node_access('create', $type)) {
// Initialize settings:
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);
@@ -1404,7 +1396,7 @@ function node_add($type) {
}
else {
// If no (valid) node type has been provided, display a node type overview.
- foreach (node_list() as $type) {
+ foreach (node_list() as $type => $module) {
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 .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>';
@@ -1984,4 +1976,4 @@ function node_db_rewrite_sql($query, $primary_table, $primary_field) {
* @} End of "defgroup node_access".
*/
-?> \ No newline at end of file
+?>
diff --git a/modules/node/node.module b/modules/node/node.module
index 3a8903901..c292d92c5 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -32,7 +32,7 @@ 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) {
+ foreach (node_list() as $type => $module) {
$output .= '<h3>'. t('Node type: %module', array('%module' => node_invoke($type, 'node_name'))). '</h3>';
$output .= implode("\n", module_invoke_all('help', 'node/add#'. $type));
}
@@ -212,49 +212,41 @@ function node_teaser($body, $format = NULL) {
*/
function node_get_module_name($node) {
if (is_array($node)) {
- if ($pos = strpos($node['type'], '-')) {
- return substr($node['type'], 0, $pos);
- }
- else {
- return $node['type'];
- }
+ $type = $node['type'];
}
else if (is_object($node)) {
- if ($pos = strpos($node->type, '-')) {
- return substr($node->type, 0, $pos);
- }
- else {
- return $node->type;
- }
+ $type = $node->type;
}
else if (is_string($node)) {
- if ($pos = strpos($node, '-')) {
- return substr($node, 0, $pos);
- }
- else {
- return $node;
- }
+ $type = $node;
}
+
+ $modules = node_list();
+
+ return $modules[$type];
}
/**
* Get a list of all the defined node types.
*
* @return
- * A list of all node types.
+ * An associate array of consisting of (node type, modulename) pairs for all node types.
*/
function node_list() {
- $types = array();
- 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;
+ 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;
}
- }
- else {
- $types[] = $module;
}
}
}
@@ -781,7 +773,7 @@ function node_admin_nodes() {
/*
** Filters
*/
- $node_types = drupal_map_assoc(node_list());
+ $node_types = drupal_map_assoc(array_keys(node_list()));
foreach ($node_types as $k => $v) {
$node_types[$k] = node_invoke($v, 'node_name');
}
@@ -955,7 +947,7 @@ function node_types_configure($type = NULL) {
$header = array(t('Type'), t('Operations'));
$rows = array();
- foreach (node_list() as $type) {
+ foreach (node_list() as $type => $module) {
$rows[] = array(node_invoke($type, 'node_name'), l(t('configure'), 'admin/settings/content-types/'. $type));
}
@@ -1388,7 +1380,7 @@ function node_add($type) {
$edit = $_POST['edit'];
// If a node type has been specified, validate its existence.
- if (in_array($type, node_list()) && node_access('create', $type)) {
+ if (array_key_exists($type, node_list()) && node_access('create', $type)) {
// Initialize settings:
$node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type);
@@ -1404,7 +1396,7 @@ function node_add($type) {
}
else {
// If no (valid) node type has been provided, display a node type overview.
- foreach (node_list() as $type) {
+ foreach (node_list() as $type => $module) {
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 .= '<dd>'. implode("\n", module_invoke_all('help', 'node/add#'. $type)) .'</dd>';
@@ -1984,4 +1976,4 @@ function node_db_rewrite_sql($query, $primary_table, $primary_field) {
* @} End of "defgroup node_access".
*/
-?> \ No newline at end of file
+?>
diff --git a/modules/system.module b/modules/system.module
index ca7c1f8a4..3f0fe7cad 100644
--- a/modules/system.module
+++ b/modules/system.module
@@ -716,7 +716,7 @@ function system_theme_settings($key = '') {
$node_list = module_invoke('node', 'list');
if ($node_list) {
$group = '';
- foreach (node_list() as $type) {
+ 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"]);
}
$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 ca7c1f8a4..3f0fe7cad 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -716,7 +716,7 @@ function system_theme_settings($key = '') {
$node_list = module_invoke('node', 'list');
if ($node_list) {
$group = '';
- foreach (node_list() as $type) {
+ 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"]);
}
$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 17ad65295..cb60413ba 100644
--- a/modules/taxonomy.module
+++ b/modules/taxonomy.module
@@ -109,7 +109,7 @@ function taxonomy_menu($may_cache) {
}
function taxonomy_form_vocabulary($edit = array()) {
- foreach (node_list() as $type) {
+ foreach (node_list() as $type => $module) {
$node_type = node_invoke($type, 'node_name');
$nodes[$type] = $node_type ? $node_type : $type;
}
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 17ad65295..cb60413ba 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -109,7 +109,7 @@ function taxonomy_menu($may_cache) {
}
function taxonomy_form_vocabulary($edit = array()) {
- foreach (node_list() as $type) {
+ foreach (node_list() as $type => $module) {
$node_type = node_invoke($type, 'node_name');
$nodes[$type] = $node_type ? $node_type : $type;
}