Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.870 diff -u -p -r1.870 common.inc --- includes/common.inc 28 Feb 2009 07:36:06 -0000 1.870 +++ includes/common.inc 5 Mar 2009 07:01:36 -0000 @@ -25,6 +25,11 @@ define('SAVED_UPDATED', 2); define('SAVED_DELETED', 3); /** + * The machine-readable name of Drupal text fields. + */ +define('DRUPAL_TEXT_FIELD', 'drupal_text_field'); + +/** * The weight of JavaScript libraries, settings or jQuery plugins being * added to the page. */ @@ -3721,6 +3726,160 @@ function drupal_common_theme() { } /** + * Acts like variable_set() for text, but saves the format too. + */ +function drupal_save_text($name, $text, $format) { + // Obtain the stored object name for this variable. + $name = drupal_text_field_object_name($name); + + // Create a template object which stores the text. + $template_object = drupal_text_field_object(); + $template_object->{DRUPAL_TEXT_FIELD}[0]['value'] = $text; + $template_object->{DRUPAL_TEXT_FIELD}[0]['format'] = $format; + + // If this is the first text field being saved, we need to create the + // field. + // TODO: Move this to some module's .install file? + $text_field = field_info_field(DRUPAL_TEXT_FIELD); + if (empty($text_field)) { + $text_field = array(); + $text_field['field_name'] = DRUPAL_TEXT_FIELD; + $text_field['type'] = 'text_long'; + $text_field['cardinality'] = 1; + $text_field['settings']['text_processing'] = TRUE; + field_create_field($text_field); + } + + // If the text field instance doesn't exist yet, we need to add this + // variable as a new fieldable object and create an instance for it. + $instance = field_info_instance(DRUPAL_TEXT_FIELD, $name); + if (empty($instance)) { + // Add the variable to the stored list. + $objects = drupal_text_field_objects(); + $objects[$name] = $name; + variable_set('drupal_text_field_objects', $objects); + // Create and save the instance. This also clears the field cache which + // means the new list of objects saved above will be used. + $instance = array(); + $instance['field_name'] = DRUPAL_TEXT_FIELD; + $instance['bundle'] = $name; + $instance['settings']['text_processing'] = TRUE; + $instance['widget']['type'] = 'text_textarea'; + field_create_instance($instance); + // Save the new variable as a field. + field_attach_insert($name, $template_object); + } + else { + // Update the existing field for this variable. + field_attach_update($name, $template_object); + } +} + +/** + * Acts like variable_del() for text fields. + */ +function drupal_delete_text($name) { + if (drupal_text_field_object_exists($name)) { + // Obtain the stored object name for this variable. + $name = drupal_text_field_object_name($name); + + // Delete the text. + field_attach_delete($name, drupal_text_field_object()); + + // Delete the variable from the stored list. + $objects = drupal_text_field_objects(); + if (isset($objects[$name])) { + unset($objects[$name]); + variable_set('drupal_text_field_objects', $objects); + field_cache_clear(); + } + } +} + +/** + * Acts like variable_get() for text fields. + * + * TODO: Default values? + */ +function drupal_get_raw_text($name) { + return _drupal_load_text_data($name, 'value'); +} + +/** + * Acts like variable_get() for text fields, but returns formatted text + * that is safe for display. + * + * TODO: Default values? + */ +function drupal_get_text($name) { + return _drupal_load_text_data($name, 'safe'); +} + +/** + * Returns the format for a text field. + */ +function drupal_get_text_format($name) { + $format = _drupal_load_text_data($name, 'format'); + return empty($format) ? FILTER_FORMAT_DEFAULT : $format; +} + +/** + * Returns an array of system-wide text field objects. + */ +function drupal_text_field_objects() { + return variable_get('drupal_text_field_objects', array()); +} + +/** + * Determines whether or not a text field object exists. + */ +function drupal_text_field_object_exists($name) { + $name = drupal_text_field_object_name($name); + $objects = drupal_text_field_objects(); + return isset($objects[$name]); +} + +/** + * Creates a template object to attach Drupal text fields to. + */ +function drupal_text_field_object() { + $object = new stdClass(); + $object->id = 1; + return $object; +} + +/** + * Prevent conflicts between Drupal text field object names and other + * fieldable objects on the site. + */ +function drupal_text_field_object_name($name) { + return 'drupal_' . $name; +} + +/** + * Helper function for loading text field data. + */ +function _drupal_load_text_data($name, $key) { + if (drupal_text_field_object_exists($name)) { + // Obtain the stored object name for this variable. + $name = drupal_text_field_object_name($name); + + $object = drupal_text_field_object(); + $object_array = array($object->id => $object); + // TODO: Ugly hack to get install.php working. + if (module_exists('field')) { + field_attach_load($name, $object_array); + if ($key == 'safe') { + field_attach_view($name, $object_array[$object->id]); + } + } + if (isset($object_array[$object->id]->{DRUPAL_TEXT_FIELD}[0][$key])) { + return $object_array[$object->id]->{DRUPAL_TEXT_FIELD}[0][$key]; + } + } +} + +/** * @ingroup schemaapi * @{ */ Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.470 diff -u -p -r1.470 theme.inc --- includes/theme.inc 22 Feb 2009 17:55:29 -0000 1.470 +++ includes/theme.inc 5 Mar 2009 07:01:42 -0000 @@ -961,7 +961,7 @@ function theme_get_setting($setting_name $theme_object = $themes[$theme_key]; if ($settings['mission'] == '') { - $settings['mission'] = variable_get('site_mission', ''); + $settings['mission'] = drupal_get_text('site_mission'); } if (!$settings['toggle_mission']) { @@ -1846,7 +1846,7 @@ function template_preprocess_page(&$vari // Set mission when viewing the frontpage. if (drupal_is_front_page()) { - $mission = filter_xss_admin(theme_get_setting('mission')); + $mission = theme_get_setting('mission'); } // Construct page title Index: modules/field/modules/text/text.info =================================================================== RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.info,v retrieving revision 1.2 diff -u -p -r1.2 text.info --- modules/field/modules/text/text.info 5 Feb 2009 03:42:57 -0000 1.2 +++ modules/field/modules/text/text.info 5 Mar 2009 07:01:42 -0000 @@ -4,3 +4,4 @@ description = Defines simple text field package = Core - fields core = 7.x files[]=text.module +required = TRUE Index: modules/field/modules/text/text.module =================================================================== RCS file: /cvs/drupal/drupal/modules/field/modules/text/text.module,v retrieving revision 1.3 diff -u -p -r1.3 text.module --- modules/field/modules/text/text.module 10 Feb 2009 03:16:15 -0000 1.3 +++ modules/field/modules/text/text.module 5 Mar 2009 07:01:42 -0000 @@ -107,7 +107,7 @@ function text_field_sanitize($obj_type, // TODO D7 : this code is really node-related. if (!empty($instance['settings']['text_processing'])) { $check = is_null($object) || (isset($object->build_mode) && $object->build_mode == NODE_BUILD_PREVIEW); - $text = isset($item['value']) ? check_markup($item['value'], $item['format'], isset($object->language) ? $object->language : $language, $check) : ''; + $text = isset($item['value']) ? check_markup($item['value'], $item['format'], isset($object->language) ? $object->language : $language->language, $check) : ''; } else { $text = check_plain($item['value']); @@ -397,4 +397,4 @@ function theme_text_textfield($element) function theme_text_textarea($element) { return $element['#children']; -} \ No newline at end of file +} Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1027 diff -u -p -r1.1027 node.module --- modules/node/node.module 26 Feb 2009 07:30:27 -0000 1.1027 +++ modules/node/node.module 5 Mar 2009 07:01:44 -0000 @@ -1983,7 +1983,7 @@ function node_feed($nids = FALSE, $chann 'version' => '2.0', 'title' => variable_get('site_name', 'Drupal'), 'link' => $base_url, - 'description' => variable_get('site_mission', ''), + 'description' => drupal_get_text('site_mission'), 'language' => $language->language ); $channel = array_merge($channel_defaults, $channel); Index: modules/system/system.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v retrieving revision 1.129 diff -u -p -r1.129 system.admin.inc --- modules/system/system.admin.inc 26 Feb 2009 07:30:28 -0000 1.129 +++ modules/system/system.admin.inc 5 Mar 2009 07:01:46 -0000 @@ -1199,6 +1199,7 @@ function system_site_information_setting $form['site_mission'] = array( '#type' => 'textarea', '#title' => t('Mission'), + '#text_format' => TRUE, '#default_value' => '', '#description' => t("Your site's mission or focus statement (often prominently displayed on the front page).") ); Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.668 diff -u -p -r1.668 system.module --- modules/system/system.module 22 Feb 2009 17:55:30 -0000 1.668 +++ modules/system/system.module 5 Mar 2009 07:01:47 -0000 @@ -432,6 +432,20 @@ function system_elements() { } /** + * Implementation of hook_fieldable_info(). + */ +function system_fieldable_info() { + $fieldable_types = array(); + foreach (drupal_text_field_objects() as $object_name) { + $fieldable_types[$object_name] = array( + 'name' => $object_name, // TODO: Does this matter? + 'id key' => 'id', + ); + } + return $fieldable_types; +} + +/** * Implementation of hook_menu(). */ function system_menu() { @@ -1323,6 +1337,19 @@ function system_initialize_theme_blocks( } } +function _system_settings_form_process_text_formats($form) { + foreach (element_children($form) as $key) { + // Replace the default text format only when it is enabled and a format + // is not specifically set. + if (isset($form[$key]['#text_format']) && $form[$key]['#text_format'] === TRUE) { + $form[$key]['#text_format'] = drupal_get_text_format($key); + } + // Recurse through child elements. + _system_settings_form_process_text_formats($form[$key]); + } + return $form; +} + function _system_settings_form_automatic_defaults($form) { // Get an array of all non-property keys $keys = element_children($form); @@ -1330,7 +1357,7 @@ function _system_settings_form_automatic foreach ($keys as $key) { // If the property (key) '#default_value' exists, replace it. if (array_key_exists('#default_value', $form[$key])) { - $form[$key]['#default_value'] = variable_get($key, $form[$key]['#default_value']); + $form[$key]['#default_value'] = isset($form[$key]['#text_format']) ? drupal_get_raw_text($key) : variable_get($key, $form[$key]['#default_value']); } else { // Recurse through child elements @@ -1355,6 +1382,9 @@ function system_settings_form($form, $au $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') ); $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') ); + // Fill in the default text format for fields that have one. + $form = _system_settings_form_process_text_formats($form); + if ($automatic_defaults) { $form = _system_settings_form_automatic_defaults($form); } @@ -1381,13 +1411,27 @@ function system_settings_form_submit($fo foreach ($form_state['values'] as $key => $value) { if ($op == t('Reset to defaults')) { - variable_del($key); + // TODO: We need to ignore the '_format' form value or it will get + // passed to variable_del() below. + if (_system_settings_text_format($key, $form_state)) { + drupal_delete_text($key); + } + else { + variable_del($key); + } } else { - if (is_array($value) && isset($form_state['values']['array_filter'])) { - $value = array_keys(array_filter($value)); + // TODO: We need to ignore the '_format' form value or it will get + // passed to variable_set() below. + if (($format = _system_settings_text_format($key, $form_state))) { + drupal_save_text($key, $value, $format); + } + else { + if (is_array($value) && isset($form_state['values']['array_filter'])) { + $value = array_keys(array_filter($value)); + } + variable_set($key, $value); } - variable_set($key, $value); } } if ($op == t('Reset to defaults')) { @@ -1402,6 +1446,16 @@ function system_settings_form_submit($fo } /** + * Returns the text format associated with the given key in a $form_state + * array, if there is one. + */ +function _system_settings_text_format($key, $form_state) { + if (isset($form_state['values'][$key . '_format'])) { + return $form_state['values'][$key . '_format']; + } +} + +/** * Helper function to sort requirements. */ function _system_sort_requirements($a, $b) {