=== removed file 'modules/page.module' --- modules/page.module +++ /dev/null @@ -1,100 +0,0 @@ -'. t('The page module allows users to create static pages, which are the most basic type of content. Pages are commonly collected in books via the book module. Users should create a page if the information on the page is static. An example would be an "about" page. ') .'
'; - $output .= ''. t('When a page is created, a user can set authoring information, configure publishing options, whether readers will be able to post comments. They can also select the content type of the page (e.g., full HTML, filtered HTML). ') .'
'; - $output .= ''. t('As an administrator, you can set the publishing default for a page (in its workflow): you can specify whether a page is by default published, sent to moderation, promoted to the front page, sticky at the top of lists, and whether revisions are enabled by default. You can set the permissions that different user roles have to view, create, and edit pages.') .'
'; - $output .= ''. t('If the location module is enabled, then location specific information can be added. If the trackback module is enabled trackbacks can be configured.') .'
'; - $output .= t('You can
-'. t('For more information please read the configuration and customization handbook Page page.', array('%page' => 'http://drupal.org/handbook/modules/page/')) .'
'; - return $output; - case 'admin/modules#description': - return t('Enables the creation of pages that can be added to the navigation system.'); - case 'node/add#page': - return t('If you want to add a static page, like a contact page or an about page, use a page.'); - } -} - -/** - * Implementation of hook_perm(). - */ -function page_perm() { - return array('create pages', 'edit own pages'); -} - -/** - * Implementation of hook_node_info(). - */ -function page_node_info() { - return array('page' => array('name' => t('page'), 'base' => 'page')); -} - -/** - * Implementation of hook_access(). - */ -function page_access($op, $node) { - global $user; - - if ($op == 'create') { - return user_access('create pages'); - } - - if ($op == 'update' || $op == 'delete') { - if (user_access('edit own pages') && ($user->uid == $node->uid)) { - return TRUE; - } - } -} - -/** - * Implementation of hook_menu(). - */ -function page_menu($may_cache) { - $items = array(); - - if ($may_cache) { - $items[] = array('path' => 'node/add/page', 'title' => t('page'), - 'access' => user_access('create pages')); - } - - return $items; -} - -/** - * Implementation of hook_form(). - */ -function page_form(&$node) { - - $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); - - $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format); - - $form['log'] = array( - '#type' => 'textarea', '#title' => t('Log message'), '#default_value' => $node->log, '#weight' => 5, - '#description' => t('An explanation of the additions or updates being made to help other authors understand your motivations.') - ); - - return $form; -} - - === removed file 'modules/story.module' --- modules/story.module +++ /dev/null @@ -1,86 +0,0 @@ -'. t('The story module is used to create a content post type called stories. Stories are articles in their simplest form: they have a title, a teaser and a body. Stories are typically used to post news articles or as a group blog. ') .''; - $output .= ''. t('The story administration interface allows for complex configuration. It provides a submission form, workflow, default view permission, default edit permission, permissions for permission, and attachments. Trackbacks can also be enabled.') .'
'; - $output .= t('You can
-'. t('For more information please read the configuration and customization handbook Story page.', array('%story' => 'http://drupal.org/handbook/modules/story/')) .'
'; - return $output; - case 'admin/modules#description': - return t('Allows users to submit stories, articles or similar content.'); - case 'node/add#story': - return t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.'); - } -} - -/** - * Implementation of hook_node_info(). - */ -function story_node_info() { - return array('story' => array('name' => t('story'), 'base' => 'story')); -} - -/** - * Implementation of hook_perm(). - */ -function story_perm() { - return array('create stories', 'edit own stories'); -} - -/** - * Implementation of hook_access(). - */ -function story_access($op, $node) { - global $user; - - if ($op == 'create') { - return user_access('create stories'); - } - - if ($op == 'update' || $op == 'delete') { - if (user_access('edit own stories') && ($user->uid == $node->uid)) { - return TRUE; - } - } -} - -/** - * Implementation of hook_menu(). - */ -function story_menu($may_cache) { - $items = array(); - - if ($may_cache) { - $items[] = array('path' => 'node/add/story', 'title' => t('story'), - 'access' => user_access('create stories')); - } - - return $items; -} - -/** - * Implementation of hook_form(). - */ -function story_form(&$node) { - $form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5); - $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Body'), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE); - $form['body_filter']['format'] = filter_form($node->format); - return $form; -} - === added file 'modules/content.module' --- /dev/null +++ modules/content.module @@ -0,0 +1,565 @@ +base == 'content') { + $name = check_plain($type->name); + $perms[] = "create $name content"; + $perms[] = "edit own $name content"; + $perms[] = "edit $name content"; + } + } + return $perms; +} + +/** + * Implementation of hook_menu(). + */ +function content_menu($may_cache) { + $items = array(); + + if ($may_cache) { + $items[] = array( + 'path' => 'admin/types', + 'title' => t('content types'), + 'callback' => 'content_types_page', + 'access' => user_access('administer nodes'), + ); + $items[] = array( + 'path' => 'admin/types/list', + 'title' => t('list'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, + ); + $items[] = array( + 'path' => 'admin/types/add', + 'title' => t('add content type'), + 'callback' => 'content_type_form', + 'type' => MENU_LOCAL_TASK, + ); + } + else { + if (arg(0) == 'admin' && arg(1) == 'types' && arg(2)) { + + $type_name = arg(2); + $type = node_get_type($type_name); + + if ($type) { + $type->name = check_plain($type->name); + $items[] = array( + 'path' => 'admin/types/'. $type_name, + 'title' => t($type->name), + 'callback' => 'content_type_form', + 'callback arguments' => array($type), + 'type' => MENU_CALLBACK, + ); + $items[] = array( + 'path' => 'admin/types/'. $type_name .'/delete', + 'title' => t('delete'), + 'callback' => 'content_type_delete', + 'callback arguments' => array($type), + 'type' => MENU_CALLBACK, + ); + $items[] = array( + 'path' => 'admin/types/'. $type_name .'/disable', + 'title' => t('disable'), + 'callback' => 'content_type_disable', + 'callback arguments' => array($type), + 'type' => MENU_CALLBACK, + ); + $items[] = array( + 'path' => 'admin/types/'. $type_name .'/reset', + 'title' => t('reset'), + 'callback' => 'content_type_reset', + 'callback arguments' => array($type), + 'type' => MENU_CALLBACK, + ); + } + } + } + + return $items; +} + +/** + * Implementation of hook_node_info(). + */ +function content_node_info() { + return array( + 'content-page' => array( + 'name' => t('page'), + 'base' => 'content', + 'description' => t('If you want to add a static page, like a contact page or an about page, use a page.'), + 'status' => NODE_TYPE_NORMAL | NODE_TYPE_MODIFIABLE_TYPE_FIELD + ), + 'content-story' => array( + 'name' => t('story'), + 'base' => 'content', + 'description' => t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.'), + 'status' => NODE_TYPE_NORMAL | NODE_TYPE_MODIFIABLE_TYPE_FIELD + ) + ); +} + +/** + * Implementation of hook_access(). + */ +function content_access($op, $node) { + global $user; + $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type); + + if ($op == 'create') { + return user_access('create '. $type .' content'); + } + + if ($op == 'update' || $op == 'delete') { + if (user_access('edit '. $type .' content') || (user_access('edit own '. $type .' content') && ($user->uid == $node->uid))) { + return TRUE; + } + } +} + +/** + * Implementation of hook_form(). + * + * Each field defines its own component of the content entry form, via its + * chosen widget. + */ +function content_form($node) { + $type = node_get_type($node); + + if (!empty($type->title_label)) { + $form['title'] = array( + '#type' => 'textfield', + '#title' => check_plain(t($type->title_label)), + '#required' => TRUE, + '#default_value' => $node->title, + '#weight' => -5, + ); + } + + if (!empty($type->body_label)) { + $form['body_filter']['body'] = array( + '#type' => 'textarea', + '#title' => check_plain(t($type->body_label)), + '#default_value' => $node->body, + '#rows' => 20, + '#required' => TRUE); + $form['body_filter']['format'] = filter_form($node->format); + } + + return $form; +} + +/** + * Menu callback; display the node type administration page. + */ +function content_types_page($type = NULL, $op = NULL) { + if (isset($type)) { + $type = node_get_type($type); + if (isset($type)) { + return content_type_form($type); + } + } + + return content_overview_types(); +} + +/** + * Displays the content type admin overview page. + */ +function content_overview_types() { + $types = node_get_types(); + $header = array(t('Name'), t('Type'), t('Description'), array('data' => t('Operations'), 'colspan' => '3')); + $rows = array(); + + foreach ($types as $type) { + $name = check_plain($type->name); + // Populate the operations field. + $operations = array(); + + if (!($type->status & NODE_TYPE_MODIFIABLE_BY_ADMIN)) { + $operations[] = array('data' => t('locked'), 'colspan' => '3', 'align' => 'center'); + } + else { + if (($type->status & NODE_TYPE_MODIFIABLE_BY_ADMIN) && ($type->status & NODE_TYPE_ENABLED)) { + // Set the edit column. + $operations[] = array('data' => l(t('edit'), 'admin/types/'. $type->type)); + } + else { + $operations[] = array('data' => ''); + } + + if ($type->status & NODE_TYPE_MODIFIABLE_BY_ADMIN) { + // Set the disable column. + if ($type->status & NODE_TYPE_ENABLED) { + $operations[] = array('data' => l(t('disable'), 'admin/types/'. $type->type .'/disable')); + } + else { + $operations[] = array('data' => l(t('enable'), 'admin/types/'. $type->type)); + } + } + else { + $operations[] = array('data' => ''); + } + + // Set the reset column. + if ($type->status & NODE_TYPE_CREATED_BY_ADMIN) { + $operations[] = array('data' => l(t('delete'), 'admin/types/'. $type->type .'/delete')); + } + else if ($type->status & NODE_TYPE_MODIFIED_BY_ADMIN) { + $operations[] = array('data' => l(t('reset'), 'admin/types/'. $type->type .'/reset')); + } + else { + $operations[] = array('data' => ''); + } + } + + // Call out disabled items. + if ($type->status & NODE_TYPE_ENABLED) { + $class = 'item-enabled'; + } + else { + $name .= ' ('. t('disabled') .')'; + $class = 'item-disabled'; + } + + $row = array(array('data' => $name, 'class' => $class), array('data' => check_plain($type->type), 'class' => $class), array('data' => check_plain($type->description), 'class' => $class)); + foreach ($operations as $operation) { + $operation['class'] = $class; + $row[] = $operation; + } + $rows[] = $row; + } + + if (empty($rows)) { + $rows[] = array('data' => t('No content types available.'), 'colspan' => '6', 'class' => 'message'); + } + + return theme('table', $header, $rows); +} + +/** + * Generates the node type editing form. + */ +function content_type_form($type = NULL) { + if (!isset($type->type)) { + $type = new stdClass(); + $type->type = $type->name = $type->description = $type->help = ''; + $type->min_word_count = 0; + $type->has_title = TRUE; + $type->has_body = TRUE; + $type->title_label = t('Title'); + $type->body_label = t('Body'); + $type->status = NODE_TYPE_CUSTOM; + } + elseif ($type->status & NODE_TYPE_MODIFIABLE_TYPE_FIELD) { + // Chop off the non-user-defined prefix from the content type string. + $type->type = drupal_substr($type->type, drupal_strlen(CONTENT_TYPE_PREFIX)); + } + + $form['identity'] = array( + '#type' => 'fieldset', + '#title' => t('Identification'), + ); + $form['identity']['name'] = array( + '#title' => t('Name'), + '#type' => 'textfield', + '#default_value' => $type->name, + '#description' => t('The human-readable name of this content type. The name must be unique to this content type.'), + '#required' => TRUE, + ); + + if ($type->status & NODE_TYPE_MODIFIABLE_TYPE_FIELD) { + $form['identity']['type'] = array( + '#title' => t('Type'), + '#type' => 'textfield', + '#default_value' => $type->type, + '#maxlength' => (32 - drupal_strlen(CONTENT_TYPE_PREFIX)), + '#description' => t('The machine-readable name of this content type. The text that you enter here will be prefixed by %content when used by the system. Only lowercase letters, numbers, and underscores are allowed. The name must be unique to this content type. Leave blank to have this automatically generated, based on the content type name.', array('%content' => theme('placeholder', CONTENT_TYPE_PREFIX))), + ); + } + else { + $form['identity']['type'] = array( + '#type' => 'value', + '#value' => $type->type, + ); + $form['identity']['type_display'] = array( + '#title' => t('Type'), + '#type' => 'item', + '#value' => theme('placeholder', $type->type), + '#description' => t('The machine-readable name of this content type. This field cannot be modified for system-defined content types.'), + ); + } + + $form['submission'] = array( + '#type' => 'fieldset', + '#title' =>t('Submission form'), + ); + if ($type->has_title) { + $form['submission']['title_label'] = array( + '#title' => t('Title field label'), + '#type' => 'textfield', + '#default_value' => $type->title_label, + '#description' => t('The label for the title field of this content type.'), + '#required' => TRUE, + ); + } + if ($type->has_body) { + $form['submission']['body_label'] = array( + '#title' => t('Body field label'), + '#type' => 'textfield', + '#default_value' => $type->body_label, + '#description' => t('The label for the body field of this content type.'), + '#required' => TRUE, + ); + } + $form['submission']['description'] = array( + '#title' => t('Description'), + '#type' => 'textarea', + '#default_value' => $type->description, + '#description' => t('A brief description of this content type. This text will be displayed as part of the list on the %create-content page. It will also be displayed as one of the table columns on the content type administration page.', array('%create-content' => theme('placeholder', t('create content')))), + ); + $form['submission']['help'] = array( + '#type' => 'textarea', + '#title' => t('Explanation or submission guidelines'), + '#default_value' => $type->help, + '#description' => t('This text will be displayed at the top of the submission form for this content type. It is useful for helping or instructing your users.') + ); + $form['submission']['min_word_count'] = array( + '#type' => 'select', + '#title' => t('Minimum number of words'), + '#default_value' => $type->min_word_count, + '#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)), + '#description' => t('The minimum number of words for the body field to be considered valid for this content type. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.') + ); + $form['workflow'] = array( + '#type' => 'fieldset', + '#title' =>t('Workflow'), + ); + + if (!empty($type->type) && ($type->status & NODE_TYPE_MODIFIABLE_TYPE_FIELD)) { + $form['old_type'] = array( + '#type' => 'value', + '#value' => $type->type, + ); + } + $form['orig_type'] = array( + '#type' => 'value', + '#value' => $type->orig_type, + ); + $form['status'] = array( + '#type' => 'value', + '#value' => $type->status, + ); + + $form['submit'] = array( + '#value' => t('Save content type'), + '#type' => 'submit', + ); + + return drupal_get_form('content_type_form', $form); +} + +/** + * Implementation of hook_form_validate(). + */ +function content_type_form_validate($form_id, $form_values) { + if (!empty($form_values['type']) && !preg_match('/^[a-z0-9_]+$/', $form_values['type'])) { + form_set_error('type', t('The machine-readable name of this content type may only consist of lowercase letters, numbers, and underscores.')); + } + + $type = new stdClass(); + $type->type = trim($form_values['type']); + $type->name = trim($form_values['name']); + + // Work out what the type was before the user submitted this form + $old_type = NULL; + if (($form_values['status'] & NODE_TYPE_MODIFIABLE_TYPE_FIELD) || ($form_values['status'] & NODE_TYPE_MODIFIABLE_BY_ADMIN)) { + $old_type = trim($form_values['old_type']); + if (empty($old_type)) { + $old_type = $type->type; + } + } + $types = node_get_types(); + + if ($form_values['status'] & NODE_TYPE_MODIFIABLE_TYPE_FIELD) { + $type_new = $type->type; + $old_type = CONTENT_TYPE_PREFIX . $old_type; + _content_type_set_name_and_type($type); + + if (isset($types[$type->type]) && $type->type != $old_type) { + form_set_error('type', t('The machine-readable name %type is already taken.', array('%type' => theme('placeholder', $type_new)))); + } + } + + if ($form_values['status'] & NODE_TYPE_MODIFIABLE_BY_ADMIN) { + foreach ($types as $info) { + if ($info->name == $type->name && $info->type != $old_type) { + form_set_error('name', t('The human-readable name %name is already taken.', array('%name' => theme('placeholder', $type->name)))); + break; + } + } + } +} + +/** + * Implementation of hook_form_submit(). + */ +function content_type_form_submit($form_id, $form_values) { + $type = new stdClass(); + + $type->type = trim($form_values['type']); + $type->name = trim($form_values['name']); + if ($form_values['status'] & NODE_TYPE_MODIFIABLE_TYPE_FIELD) { + _content_type_set_name_and_type($type); + } + $type->orig_type = trim($form_values['orig_type']); + + $type->description = $form_values['description']; + $type->help = $form_values['help']; + $type->min_word_count = $form_values['min_word_count']; + $type->title_label = $form_values['title_label']; + $type->body_label = $form_values['body_label']; + + $type->base = drupal_substr(CONTENT_TYPE_PREFIX, 0, (drupal_strlen(CONTENT_TYPE_PREFIX) - 1)); + $type->has_title = $type->has_body = TRUE; + $type->status = $form_values['status'] | NODE_TYPE_MODIFIED_BY_ADMIN; + $type->status |= NODE_TYPE_ENABLED; + + if (isset($form_values['old_type'])) { + $type->old_type = CONTENT_TYPE_PREFIX . $form_values['old_type']; + + if ($type->old_type != $type->type) { + $update_count = node_type_update_nodes($type->old_type, $type->type); + + if ($update_count) { + $t_args = array('%update_count' => theme('placeholder', $update_count), '%old_type' => theme('placeholder', $type->old_type), '%type' => theme('placeholder', $type->type)); + drupal_set_message(t('Changed the content type of %update_count posts from %old_type to %type.', $t_args)); + cache_clear_all('filter:', TRUE); + } + } + } + else { + $type->old_type = $type->type; + } + + $status = node_type_save($type); + + $t_args = array('%name' => theme('placeholder', $type->name)); + if ($status == SAVED_UPDATED) { + drupal_set_message(t('The content type %name has been updated.', $t_args)); + } + elseif ($status == SAVED_NEW) { + drupal_set_message(t('The content type %name has been added.', $t_args)); + watchdog('content', t('Added content type %name.', $t_args), WATCHDOG_NOTICE, l(t('view'), 'admin/types')); + } + + node_types_rebuild(); + menu_rebuild(); + + return 'admin/types'; +} + +/** + * Menu callback; hide a menu item. + */ +function content_type_disable($type) { + $type->status &= ~NODE_TYPE_ENABLED; + $type->status |= NODE_TYPE_MODIFIED_BY_ADMIN; + + node_type_save($type); + drupal_set_message(t('The content type %name has been disabled.', array('%name' => theme('placeholder', $type->name)))); + + node_types_rebuild(); + menu_rebuild(); + + drupal_goto('admin/types'); +} + +/** + * Menu callback; reset a single modified content type. + */ +function content_type_reset($type) { + $form['type'] = array('#type' => 'value', '#value' => $type->type); +return confirm_form('content_type_reset_form', $form, t('Are you sure you want to reset the content type %type to its default values?', array('%type' => theme('placeholder', $type->name))), 'admin/types', t('Any customizations will be lost. This action cannot be undone.'), t('Reset')); +} + +/** + * Process content type reset form submissions. + */ +function content_type_reset_form_submit($form_id, $form_values) { + node_type_delete($form_values['type']); + drupal_set_message(t('The content type was reset to its default settings.')); + node_types_rebuild(); + menu_rebuild(); + + return 'admin/types'; +} + +/** + * Menu callback; delete a single content type. + */ +function content_type_delete($type) { + $form['type'] = array('#type' => 'value', '#value' => $type->type); + $form['name'] = array('#type' => 'value', '#value' => $type->name); + + $message = t('Are you sure you want to delete the content type %type?', array('%type' => theme('placeholder', $type->name))); + + return confirm_form('content_type_delete_form', $form, $message, 'admin/types', t('This action cannot be undone.'), t('Delete')); +} + +/** + * Process content type delete form submissions. + */ +function content_type_delete_form_submit($form_id, $form_values) { + node_type_delete($form_values['type']); + + $t_args = array('%name' => theme('placeholder', $form_values['name'])); + drupal_set_message(t('The content type %name has been deleted.', $t_args)); + watchdog('menu', t('Deleted content type %name.', $t_args), WATCHDOG_NOTICE); + + node_types_rebuild(); + menu_rebuild(); + + return 'admin/types'; +} + +/** + * Sets the machine-readable content type name, where it is user-defined, based + * on the inputted human-readable and machine-readable names of the content + * type. + */ +function _content_type_set_name_and_type(&$type) { + if (empty($type->type)) { + $type->type = $type->name; + $type->type = drupal_strtolower($type->type); + $type->type = str_replace(array(' ', '-'), '_', $type->type); + $type->type = preg_replace('/[^a-z0-9_]/', '', $type->type); + $type->type = drupal_substr($type->type, 0, 32); + } + + $type->type = CONTENT_TYPE_PREFIX . $type->type; + $type->type = drupal_substr($type->type, 0, 32); +} + Index: database/database.4.0.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.4.0.mysql,v retrieving revision 1.6 diff -u -r1.6 database.4.0.mysql --- database/database.4.0.mysql 2 Jul 2006 19:53:39 -0000 1.6 +++ database/database.4.0.mysql 4 Jul 2006 15:51:02 -0000 @@ -460,6 +460,26 @@ ); -- +-- Table structure for table 'node_type' +-- + +CREATE TABLE node_type ( + type varchar(255) NOT NULL, + name varchar(255) NOT NULL default '', + base varchar(255) NOT NULL, + description mediumtext NOT NULL, + help mediumtext NOT NULL, + has_title tinyint(3) unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body tinyint(3) unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + min_word_count smallint(4) unsigned NOT NULL, + status smallint(4) unsigned NOT NULL, + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) +); + +-- -- Table structure for table 'profile_fields' -- Index: database/database.4.1.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.4.1.mysql,v retrieving revision 1.6 diff -u -r1.6 database.4.1.mysql --- database/database.4.1.mysql 2 Jul 2006 19:53:39 -0000 1.6 +++ database/database.4.1.mysql 4 Jul 2006 15:51:02 -0000 @@ -491,6 +491,27 @@ DEFAULT CHARACTER SET utf8; -- +-- Table structure for table 'node_type' +-- + +CREATE TABLE node_type ( + type varchar(255) NOT NULL default '', + name varchar(255) NOT NULL, + base varchar(255) NOT NULL, + has_title tinyint(3) unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body tinyint(3) unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + description mediumtext NOT NULL, + help mediumtext NOT NULL, + min_word_count smallint(4) unsigned NOT NULL, + status smallint(4) unsigned NOT NULL, + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) +) +DEFAULT CHARACTER SET utf8; + +-- -- Table structure for table 'profile_fields' -- Index: database/database.pgsql =================================================================== RCS file: /cvs/drupal/drupal/database/database.pgsql,v retrieving revision 1.178 diff -u -r1.178 database.pgsql --- database/database.pgsql 29 May 2006 16:04:41 -0000 1.178 +++ database/database.pgsql 4 Jul 2006 15:51:02 -0000 @@ -468,6 +468,26 @@ CREATE SEQUENCE node_revisions_vid_seq INCREMENT 1 START 1; -- +-- Table structure for table 'node_type' +-- + +CREATE TABLE node_type ( + type varchar(255) NOT NULL default '', + name varchar(255) NOT NULL, + base varchar(255) NOT NULL, + description text NOT NULL, + help text NOT NULL, + has_title integer unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body integer unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + min_word_count integer unsigned NOT NULL, + status integer unsigned NOT NULL, + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) +); + +-- -- Table structure for table 'url_alias' -- Index: database/updates.inc =================================================================== RCS file: /cvs/drupal/drupal/database/updates.inc,v retrieving revision 1.239 diff -u -r1.239 updates.inc --- database/updates.inc 2 Jul 2006 19:53:39 -0000 1.239 +++ database/updates.inc 4 Jul 2006 15:51:03 -0000 @@ -2102,3 +2102,57 @@ } return $ret; } + +function system_update_188() { + // Add ability to create dynamic node types like the CCK module + $ret = array(); + + switch ($GLOBALS['db_type']) { + case 'mysqli': + case 'mysql': + // Create node_type table + $ret[] = update_sql("CREATE TABLE {node_type} ( + type varchar(255) NOT NULL, + name varchar(255) NOT NULL, + base varchar(255) NOT NULL, + description mediumtext NOT NULL, + help mediumtext NOT NULL, + has_title tinyint(3) unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body tinyint(3) unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + min_word_count smallint(4) unsigned NOT NULL, + status smallint(4) unsigned NOT NULL, + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) + ) /*!40100 DEFAULT CHARACTER SET utf8 */;"); + break; + + case 'pgsql': + $ret[] = update_sql("CREATE TABLE {node_type} ( + type varchar(255) NOT NULL, + name varchar(255) NOT NULL, + base varchar(255) NOT NULL, + description text NOT NULL, + help text NOT NULL, + has_title integer unsigned NOT NULL, + title_label varchar(255) NOT NULL default '', + has_body integer unsigned NOT NULL, + body_label varchar(255) NOT NULL default '', + min_word_count integer unsigned NOT NULL, + status integer unsigned NOT NULL, + orig_type varchar(255) NOT NULL default '', + PRIMARY KEY (type) + );"); + break; + } + + $type_map = array('content-page' => 'page', 'content-story' => 'story'); + foreach ($type_map as $new_type => $old_type) { + db_query("UPDATE {node} SET type = '%s' WHERE type = '%s'", $new_type, $old_type); + } + + node_types_rebuild(); + + return $ret; +} Index: misc/drupal.css =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.css,v retrieving revision 1.151 diff -u -r1.151 drupal.css --- misc/drupal.css 30 Jun 2006 00:13:32 -0000 1.151 +++ misc/drupal.css 4 Jul 2006 15:51:03 -0000 @@ -72,9 +72,6 @@ li a.active { color: #000; } -td.menu-disabled { - background: #ccc; -} /* ** Other common styles @@ -128,6 +125,9 @@ padding: 0; list-style: disc; } +td.item-disabled { + background: #ccc; +} .form-item { margin-top: 1em; margin-bottom: 1em; Index: modules/book.module =================================================================== RCS file: /cvs/drupal/drupal/modules/book.module,v retrieving revision 1.372 diff -u -r1.372 book.module --- modules/book.module 4 Jul 2006 08:59:04 -0000 1.372 +++ modules/book.module 4 Jul 2006 15:51:03 -0000 @@ -10,7 +10,13 @@ * Implementation of hook_node_info(). */ function book_node_info() { - return array('book' => array('name' => t('book page'), 'base' => 'book')); + return array( + 'book' => array( + 'name' => t('book page'), + 'base' => 'book', + 'description' => t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it."), + ) + ); } /** @@ -84,10 +90,6 @@ if ($may_cache) { $items[] = array( - 'path' => 'node/add/book', - 'title' => t('book page'), - 'access' => user_access('create book pages')); - $items[] = array( 'path' => 'admin/node/book', 'title' => t('books'), 'callback' => 'book_admin', @@ -1014,8 +1016,6 @@ return t('The book module offers a means to organize content, authored by many users, in an online manual, outline or FAQ.
'); case 'admin/node/book/orphan': return t('Pages in a book are like a tree. As pages are edited, reorganized and removed, child pages might be left with no link to the rest of the book. Such pages are referred to as "orphan pages". On this page, administrators can review their books for orphans and reattach those pages as desired.
'); - case 'node/add#book': - return t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it."); } if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'outline') { Index: modules/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment.module,v retrieving revision 1.462 diff -u -r1.462 comment.module --- modules/comment.module 4 Jul 2006 08:59:05 -0000 1.462 +++ modules/comment.module 4 Jul 2006 15:51:03 -0000 @@ -258,10 +258,12 @@ } function comment_form_alter($form_id, &$form) { - if (isset($form['type'])) { - if ($form['type']['#value'] .'_node_settings' == $form_id) { - $form['workflow']['comment_'. $form['type']['#value']] = array('#type' => 'radios', '#title' => t('Default comment setting'), '#default_value' => variable_get('comment_'. $form['type']['#value'], COMMENT_NODE_READ_WRITE), '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')), '#description' => t('Users with the administer comments permission will be able to override this setting.')); + if (isset($form['identity']['type'])) { + if ($form_id == 'content_type_form') { + $form['workflow']['comment'] = array('#type' => 'radios', '#title' => t('Default comment setting'), '#default_value' => variable_get('comment_'. $form['identity']['type']['#value'], COMMENT_NODE_READ_WRITE), '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')), '#description' => t('Users with the administer comments permission will be able to override this setting.')); } + } + elseif (isset($form['type'])) { if ($form['type']['#value'] .'_node_form' == $form_id) { $node = $form['#node']; if (user_access('administer comments')) { Index: modules/menu.module =================================================================== RCS file: /cvs/drupal/drupal/modules/menu.module,v retrieving revision 1.75 diff -u -r1.75 menu.module --- modules/menu.module 22 Jun 2006 09:50:57 -0000 1.75 +++ modules/menu.module 4 Jul 2006 15:51:04 -0000 @@ -682,7 +682,7 @@ } else { $title .= ' ('. t('disabled') .')'; - $class = 'menu-disabled'; + $class = 'item-disabled'; } if ($item['type'] & (MENU_MODIFIABLE_BY_ADMIN | MENU_VISIBLE_IN_TREE)) { Index: modules/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node.module,v retrieving revision 1.653 diff -u -r1.653 node.module --- modules/node.module 4 Jul 2006 08:59:05 -0000 1.653 +++ modules/node.module 4 Jul 2006 15:51:04 -0000 @@ -8,6 +8,32 @@ define('NODE_NEW_LIMIT', time() - 30 * 24 * 60 * 60); +define('NODE_TYPE_ENABLED', 0x0001); +define('NODE_TYPE_MODIFIABLE_BY_ADMIN', 0x0002); +define('NODE_TYPE_MODIFIED_BY_ADMIN', 0x0004); +define('NODE_TYPE_CREATED_BY_ADMIN', 0x0008); +define('NODE_TYPE_MODIFIABLE_TYPE_FIELD', 0x0010); + +/** + * Normal node types are defined by modules, and can be disabled (but not + * edited) by the administrator. Use this for most node types that are + * non-user-defined, and that are designed to be used for creating content. It + * is the default value if no node type status is specified. + */ +define('NODE_TYPE_NORMAL', NODE_TYPE_ENABLED | NODE_TYPE_MODIFIABLE_BY_ADMIN); + +/** + * Suggested node types are just like normal node types, except that they are + * disabled by default. + */ +define('NODE_TYPE_SUGGESTED', NODE_TYPE_MODIFIABLE_BY_ADMIN); + +/** + * Custom node types are those defined by the administrator. Reserved for + * internal use; do not return from hook_node_info() implementations. + */ +define('NODE_TYPE_CUSTOM', NODE_TYPE_ENABLED | NODE_TYPE_CREATED_BY_ADMIN | NODE_TYPE_MODIFIABLE_BY_ADMIN | NODE_TYPE_MODIFIABLE_TYPE_FIELD); + /** * Implementation of hook_help(). */ @@ -48,7 +74,8 @@ } if (arg(0) == 'node' && arg(1) == 'add' && $type = arg(2)) { - return filter_xss_admin(variable_get($type .'_help', '')); + $type = node_get_type(arg(2)); + return filter_xss_admin($type->help); } } @@ -195,16 +222,41 @@ 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']; +/** + * Builds a list of available node types, and returns all of part of this list + * in the specified format. + * + * @param $op + * The format in which to return the list. When this is set to 'type', + * 'base', or 'name', only the specified node type is returned. When set to + * 'types' or 'names', all node types are returned. + * @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. + * @param $reset + * Whether or not to reset this function's internal cache (defaults to + * FALSE). + * + * @return + * Either an array of all available node types, or a single node type, in a + * variable format. + */ +function _node_types($op = '', $node = NULL, $reset = FALSE) { + global $_node_types, $_node_names; + + if ($reset || !isset($_node_types)) { + if ($cached = cache_get('node_types')) { + $_node_types = unserialize($cached->data); + $cached = cache_get('node_names'); + $_node_names = unserialize($cached->data); + } + else { + _node_types_build(); + cache_set('node_types', serialize($_node_types), CACHE_PERMANENT); + cache_set('node_names', serialize($_node_names), CACHE_PERMANENT); } } + if ($node) { if (is_array($node)) { $type = $node['type']; @@ -215,21 +267,182 @@ 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[$type]; case 'base': - return $node_names[$type]['base']; - case 'list': - return $node_list; + return $_node_types[$type]->base; + case 'names': + return $_node_names; case 'name': - return $node_list[$type]; + return $_node_names[$type]; + } +} + +/** + * Resets the database cache of node types, and saves all new or non-modified + * module-defined node types to the database. + */ +function node_types_rebuild() { + cache_clear_all('node_types'); + + _node_types_build(); + + $node_types = _node_types('types'); + + foreach ($node_types as $type => $info) { + if (!empty($info->is_new)) { + node_type_save($info); + } + } + + _node_types_build(); +} + +/** + * Saves a node type to the database. + * + * @param $info + * The node type to save, as an object. + * + * @return + * Status flag indicating outcome of the operation. + */ +function node_type_save($info) { + $is_existing = FALSE; + $existing_type = !empty($info->old_type) ? $info->old_type : $info->type; + $is_existing = db_num_rows(db_query("SELECT * FROM {node_type} WHERE type = '%s'", $existing_type)); + + if ($is_existing) { + db_query("UPDATE {node_type} SET type = '%s', name = '%s', base = '%s', has_title = %d, title_label = '%s', has_body = %d, body_label = '%s', description = '%s', help = '%s', min_word_count = %d, status = %d WHERE type = '%s'", $info->type, $info->name, $info->base, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->status, $existing_type); + return SAVED_UPDATED; + } + else { + db_query("INSERT INTO {node_type} (type, name, base, has_title, title_label, has_body, body_label, description, help, min_word_count, status, orig_type) VALUES ('%s', '%s', '%s', %d, '%s', %d, '%s', '%s', '%s', %d, %d, '%s')", $info->type, $info->name, $info->base, $info->has_title, $info->title_label, $info->has_body, $info->body_label, $info->description, $info->help, $info->min_word_count, $info->status, $info->orig_type); + return SAVED_NEW; + } +} + +/** + * Deletes a node type from the database. + * + * @param $type + * The node type to delete, as a string. + */ +function node_type_delete($type) { + db_query("DELETE FROM {node_type} WHERE type = '%s'", $type); +} + +/** + * Updates all nodes of one type to be of another type. + * + * @param $orig_type + * The current node type of the nodes. + * @param $type + * The new node type of the nodes. + * + * @return + * The number of nodes whose node type field was modified. + */ +function node_type_update_nodes($old_type, $type) { + return db_num_rows(db_query("UPDATE {node} SET type = '%s' WHERE type = '%s'", $type, $old_type)); +} + +/** + * Builds the list of available node types, by querying hook_node_info() in all + * modules, and by looking for node types in the database. + * + */ +function _node_types_build() { + global $_node_types, $_node_names; + + $_node_types = array(); + $_node_names = array(); + + $info_array = module_invoke_all('node_info'); + foreach ($info_array as $type => $info) { + $info['type'] = $type; + $_node_types[$type] = _node_type_set_defaults($info); + $_node_names[$type] = $info['name']; + } + + $type_result = db_query(db_rewrite_sql('SELECT nt.type, nt.* FROM {node_type} nt ORDER BY nt.type ASC', 'nt', 'type')); + while ($type_object = db_fetch_object($type_result)) { + if (module_exist('field')) { + $type_object->fields = field_load_type($type_object->type); + } + if (!isset($_node_types[$type_object->type]) || ($type_object->status & NODE_TYPE_MODIFIED_BY_ADMIN)) { + $_node_types[$type_object->type] = $type_object; + $_node_names[$type_object->type] = $type_object->name; + + if ($type_object->type != $type_object->orig_type) { + unset($_node_types[$type_object->orig_type]); + unset($_node_names[$type_object->orig_type]); + } + } } } /** + * Set default values for a node type defined through hook_node_info(). + */ +function _node_type_set_defaults($info) { + if (!isset($info['has_title'])) { + $info['has_title'] = 1; + } + if ($info['has_title'] && !isset($info['title_label'])) { + $info['title_label'] = t('Title'); + } + + if (!isset($info['has_body'])) { + $info['has_body'] = 1; + } + if ($info['has_body'] && !isset($info['body_label'])) { + $info['body_label'] = t('Body'); + } + + if (!isset($info['status'])) { + $info['status'] = NODE_TYPE_NORMAL; + } + + $info['orig_type'] = $info['type']; + $info['is_new'] = TRUE; + + return (object) $info; +} + +/** + * 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 of (node type internal name => node type object) + * pairs. + */ +function node_get_types() { + 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); +} + +/** * Determine the basename for hook_load etc. * * @param $node @@ -238,31 +451,32 @@ * The basename for hook_load, hook_nodeapi etc. */ function node_get_base($node) { - return _node_names('base', $node); + return _node_types('base', $node); } /** - * Determine the human readable name for a given type. + * Return the human-readable names of available node types. * * @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. + * An array consisting of (internal node type name => human readable node + * type name) pairs. */ -function node_get_name($node) { - return _node_names('name', $node); +function node_get_names() { + return _node_types('names'); } /** - * Return the list of available node types. + * 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 - * An array consisting ('#type' => name) pairs. + * The human readable name of the node type. */ -function node_get_types() { - return _node_names('list'); +function node_get_name($node, $check_plain = TRUE) { + return _node_types('name', $node); } /** @@ -587,7 +801,7 @@ * Implementation of hook_perm(). */ function node_perm() { - return array('administer nodes', 'access content', 'view revisions', 'revert revisions'); + return array('administer content types', 'administer nodes', 'access content', 'view revisions', 'revert revisions'); } /** @@ -866,6 +1080,17 @@ 'callback' => 'node_feed', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); + + foreach (node_get_types() as $type) { + if ($type->status & NODE_TYPE_ENABLED) { + $name = check_plain($type->name); + $items[] = array( + 'path' => 'node/add/'. $type->type, + 'title' => t($name), + 'access' => module_invoke($type->base, 'access', 'create', $type->type), + ); + } + } } else { if (arg(0) == 'node' && is_numeric(arg(1))) { @@ -935,7 +1160,7 @@ '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_names()); // The taxonomy filter if ($taxonomy = module_invoke('taxonomy', 'form_all', 1)) { $filters['category'] = array('title' => t('category'), 'options' => $taxonomy); @@ -1252,7 +1477,7 @@ $header = array(t('Type'), t('Operations')); $rows = array(); - foreach (node_get_types() as $type => $name) { + foreach (node_get_names() as $type => $name) { $rows[] = array($name, l(t('configure'), 'admin/settings/content-types/'. $type)); } @@ -1732,21 +1957,23 @@ 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' => check_plain($types[$type]->name)))); } 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 = '