? precck.patch ? sites/localhost Index: modules/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node.module,v retrieving revision 1.650 diff -u -p -r1.650 node.module --- modules/node.module 18 May 2006 14:58:57 -0000 1.650 +++ modules/node.module 20 May 2006 22:42:06 -0000 @@ -195,16 +195,29 @@ function node_teaser($body, $format = NU return truncate_utf8($body, $size); } -function _node_names($op = '', $node = NULL) { - static $node_names = array(); - static $node_list = array(); - - if (empty($node_names)) { - $node_names = module_invoke_all('node_info'); - foreach ($node_names as $type => $value) { - $node_list[$type] = $value['name']; +function _node_types($op = '', $node = NULL, $reset = FALSE) { + static $node_types, $node_labels; + + if ($reset || !isset($node_types)) { + if ($cached = cache_get('node_types')) { + $node_types = unserialize($cached->data); + $cached = cache_get('node_labels'); + $node_labels = unserialize($cached->data); + } + else { + $node_types = array(); + $type_result = db_query('SELECT * FROM {node_type} nt ORDER BY nt.name ASC'); + while ($type = db_fetch_object($type_result)) { + $type->fields = module_invoke('field', 'load_type', $type->name_name); + $node_types[$type->name] = $type; + $node_labels[$type->name] = $type->label; + } + + cache_set('node_types', serialize($node_types), CACHE_PERMANENT); + cache_set('node_labels', serialize($node_labels), CACHE_PERMANENT); } } + if ($node) { if (is_array($node)) { $type = $node['type']; @@ -215,17 +228,21 @@ function _node_names($op = '', $node = N elseif (is_string($node)) { $type = $node; } - if (!isset($node_names[$type])) { + if (!isset($node_types[$type])) { return FALSE; } } switch ($op) { + case 'types': + return $node_types; + case 'type': + return $node_types[$node]; case 'base': - return $node_names[$type]['base']; + return $node_types[$type]->base; case 'list': - return $node_list; - case 'name': - return $node_list[$type]; + return $node_labels; + case 'label': + return $node_labels[$type]; } } @@ -238,7 +255,7 @@ function _node_names($op = '', $node = N * The basename for hook_load, hook_nodeapi etc. */ function node_get_base($node) { - return _node_names('base', $node); + return _node_types('base', $node); } /** @@ -249,8 +266,8 @@ function node_get_base($node) { * @return * The human readable name of the node type. */ -function node_get_name($node) { - return _node_names('name', $node); +function node_get_label($node) { + return _node_types('label', $node); } /** @@ -259,12 +276,48 @@ function node_get_name($node) { * @param $node * Either a node object, a node array, or a string containing the node type. * @return - * An array consisting ('#type' => name) pairs. + * An array consisting (machine readable node name => node type object) pairs. */ function node_get_types() { - return _node_names('list'); + return _node_types('types'); +} + +/** + * Return a node type object. + * + * @param $node + * Either a node object, a node array, or a string containing the node type. + * @return + * A node type object. + */ +function node_get_type($node) { + return _node_types('type', $node); +} + +/** + * 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 array consisting (machine readable node name => human readable node name) pairs. + */ +function node_get_list() { + return _node_types('list'); +} + +/** + * Clear the cache of node_types; called in several places when content + * information is changed. + */ +function node_clear_type_cache() { + cache_clear_all('node_types'); + + _content_types(TRUE); + module_invoke('field', 'clear_type_cache'); } + /** * Determine whether a node hook exists. * @@ -726,7 +779,7 @@ function node_search($op = 'search', $ke $extra = node_invoke_nodeapi($node, 'search result'); $results[] = array('link' => url('node/'. $item->sid), - 'type' => node_get_name($node), + 'type' => node_get_label($node), 'title' => $node->title, 'user' => theme('username', $node), 'date' => $node->changed, @@ -897,7 +950,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_get_name(arg(3)))), + 'title' => t("'%name' content type", array('%name' => node_get_label(arg(3)))), 'type' => MENU_CALLBACK); } } @@ -935,7 +988,7 @@ function node_filters() { 'moderate-1' => t('in moderation'), 'moderate-0' => t('not in moderation'), 'promote-1' => t('promoted'), 'promote-0' => t('not promoted'), 'sticky-1' => t('sticky'), 'sticky-0' => t('not sticky'))); - $filters['type'] = array('title' => t('type'), 'options' => node_get_types()); + $filters['type'] = array('title' => t('type'), 'options' => node_get_list()); // The taxonomy filter if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) { $filters['category'] = array('title' => t('category'), 'options' => $taxonomy); @@ -1150,7 +1203,7 @@ function node_admin_nodes() { while ($node = db_fetch_object($result)) { $nodes[$node->nid] = ''; $form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed))); - $form['name'][$node->nid] = array('#value' => node_get_name($node)); + $form['name'][$node->nid] = array('#value' => node_get_label($node)); $form['username'][$node->nid] = array('#value' => theme('username', $node)); $form['status'][$node->nid] = array('#value' => ($node->status ? t('published') : t('not published'))); $form['operations'][$node->nid] = array('#value' => l(t('edit'), 'node/'. $node->nid .'/edit', array(), $destination)); @@ -1231,35 +1284,109 @@ function node_multiple_delete_confirm_su */ function node_types_configure($type = NULL) { if (isset($type)) { - $node = new stdClass(); - $node->type = $type; - $form['submission'] = array('#type' => 'fieldset', '#title' =>t('Submission form') ); + $form['submission'] = array('#type' => 'fieldset', '#title' => t('Submission form'), '#collapsible' => TRUE, '#collapsed' => TRUE); $form['submission'][$type . '_help'] = array( '#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => variable_get($type .'_help', ''), - '#description' => 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))) + '#description' => 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_label($type))) ); $form['submission']['minimum_'. $type .'_size'] = array( '#type' => 'select', '#title' => t('Minimum number of words'), '#default_value' => variable_get('minimum_'. $type .'_size', 0), '#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), - '#description' => 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))) + '#description' => 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_label($type))) + ); + $form['workflow'] = array('#type' => 'fieldset', '#title' =>t('Workflow'), '#collapsible' => TRUE, '#collapsed' => TRUE); + $form['workflow'][$type] = array('#type' => 'checkboxes', + '#title' => t('Default options'), + '#default_value' => variable_get('node_options_'. $type, array('status', 'promote')), + '#options' => array( + 'status' => t('Published'), + 'moderate' => t('In moderation queue'), + 'promote' => t('Promoted to front page'), + 'sticky' => t('Sticky at top of lists'), + 'revision' => t('Create new revision'), + ), + '#description' => t('Users with the administer nodes permission will be able to override these options.'), + ); + + $form['texts'] = array('#type' => 'fieldset', '#title' =>t('text'), '#collapsible' => TRUE, '#collapsed' => TRUE); + + $type = node_get_type($type); + $form['texts']['label'] = array( + '#title' => t('Label'), + '#type' => 'textfield', + '#default_value' => $type->label, + '#description' => t('The human-readable name of this content type.'), + '#required' => TRUE, + ); + $form['texts']['description'] = array( + '#title' => t('Description'), + '#type' => 'textarea', + '#default_value' => $type->description, + '#rows' => 10, + '#description' => t('A brief description of the content type.'), + ); + $form['texts']['help'] = array( + '#title' => t('Help text'), + '#type' => 'textarea', + '#default_value' => $type->help, + '#rows' => 10, + '#description' => t('Instructions to present to the user when adding new content of this type.'), + ); + $form['texts']['title_label'] = array( + '#title' => t('Title field label'), + '#type' => 'textfield', + '#default_value' => $type->title_label, + '#description' => t('The label for the title field.'), + ); + $form['texts']['body_label'] = array( + '#title' => t('Body field label'), + '#type' => 'textfield', + '#default_value' => $type->body_label, + '#description' => t('The label for the body field.'), + ); + $form['texts']['name'] = array( + '#type' => 'value', + '#value' => $type->name, ); - $form['workflow'] = array('#type' => 'fieldset', '#title' =>t('Workflow')); - $form['type'] = array('#type' => 'value', '#value' => $type); $form['array_filter'] = array('#type' => 'value', '#value' => TRUE); - return system_settings_form($type .'_node_settings', $form); + $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') ); + $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') ); + return drupal_get_form($type->name .'_node_type_configure', $form, 'node_type_configure'); } else { $header = array(t('Type'), t('Operations')); $rows = array(); - foreach (node_get_types() as $type => $name) { - $rows[] = array($name, l(t('configure'), 'admin/settings/content-types/'. $type)); + + foreach (node_get_types() as $label => $type) { + $base = 'admin/settings/content-types/'. $type->name; + $row = array(); + $row[] = $type->label; + $row[] = truncate_utf8(filter_xss_admin($type->description), 60); + $row[] = l(t('configure'), $base); + if (module_exist('fields')) { + $row[] = l('fields', $base .'/fields'); + $row[] = l(t('duplicate'), $base .'/duplicate'); + } + if ($type->base == 'content') { + $row[] = l(t('delete'), $base .'/delete'); + } + $rows[] = $row; + } return theme('table', $header, $rows); } } +function node_type_configure_submit($form_id, $form_values) { + db_query("UPDATE {node_type} SET label = '%s', description = '%s', help = '%s', title_label = '%s', body_label = '%s' WHERE type_name = '%s'", $form_values['texts']['label'], $form_values['texts']['description'], $form_values['texts']['help'], $form_values['texts']['title_label'], $form_values['texts']['body_label'], $form_values['texts']['type_name']); + node_clear_type_cache(); + + unset($form_values['text']); + system_settings_form_submit($form_id, $form_values); +} + /** * Generate an overview table of older revisions of a node. */ @@ -1538,7 +1665,7 @@ function node_validate($node, $form = ar // 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_get_name($node)))); + 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_label($node)))); } if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) { @@ -1732,21 +1859,22 @@ function theme_node_form($form) { function node_add($type) { global $user; + $types = node_get_types(); // If a node type has been specified, validate its existence. - if (array_key_exists($type, node_get_types()) && node_access('create', $type)) { + if (isset($types[$type]) && node_access('create', $type)) { // Initialize settings: $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type); $output = node_form($node); - drupal_set_title(t('Submit %name', array('%name' => node_get_name($node)))); + drupal_set_title(t('Submit %name', array('%name' => $types[$type]->label))); } else { // If no (valid) node type has been provided, display a node type overview. - foreach (node_get_types() as $type => $name) { - if (module_invoke(node_get_base($type), 'access', 'create', $type)) { - $out = '