Index: includes/locale.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/locale.inc,v retrieving revision 1.129 diff -u -r1.129 locale.inc --- includes/locale.inc 22 May 2007 07:42:36 -0000 1.129 +++ includes/locale.inc 26 May 2007 13:26:00 -0000 @@ -736,7 +736,7 @@ $languages = language_list(); unset($languages['en']); - $result = db_query('SELECT DISTINCT s.source, t.translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid); + $result = db_query('SELECT DISTINCT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.lid = %d', $lid); $form = array(); $form['translations'] = array('#tree' => TRUE); while ($translation = db_fetch_object($result)) { @@ -1776,8 +1776,9 @@ // We have at least one criterion to match if ($query = _locale_translate_seek_query()) { - $join = "SELECT s.source, s.location, s.lid, s.textgroup, t.translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid "; - + //$join = "SELECT s.source, s.location, s.lid, s.textgroup, t.translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid "; + $join = "SELECT s.source, s.location, s.lid, s.textgroup, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid "; + $arguments = array(); // Compute LIKE section switch ($query['translation']) { Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.165 diff -u -r1.165 bootstrap.inc --- includes/bootstrap.inc 8 May 2007 16:36:55 -0000 1.165 +++ includes/bootstrap.inc 26 May 2007 13:25:59 -0000 @@ -1,5 +1,5 @@ data; } else { - $result = db_query('SELECT * FROM {variable}'); + // Special language initialization + if ($variable_language && function_exists('language_variable_init')) { + $variables = language_variable_init($variable_language); + } + $result = db_query("SELECT * FROM {variable} WHERE language = '%s'", $variable_language); while ($variable = db_fetch_object($result)) { $variables[$variable->name] = unserialize($variable->value); } - cache_set('variables', $variables); + cache_set('variables:'. $variable_language, $variables); } foreach ($conf as $name => $value) { @@ -423,51 +432,105 @@ * The name of the variable to return. * @param $default * The default value to use if this variable has never been set. + * @param $variable_language + * The language code to get the value for. Defaults to the code of the + * language used on the page, but then falls back to the global variable + * if a language specific is not found. Set it to empty to explicitly + * ask for a global variable. * @return * The value of the variable. */ -function variable_get($name, $default) { - global $conf; - +function variable_get($name, $default, $variable_language = -1) { + global $conf, $language; + // Before variable_init, $language is empty. + if (!empty($language)) { + // -1 is not possible as a language code, but it's the default, + // and we override that with the current language. + if ($variable_language == -1) { + $variable_language = $language->language; + } elseif (!isset($conf[$variable_language])) { + $conf[$variable_language] = variable_init(array(), $variable_language); + } + if (isset($conf[$variable_language][$name])) { + return $conf[$variable_language][$name]; + } + } return isset($conf[$name]) ? $conf[$name] : $default; } /** + * Return a persistent variable default. + * + * This function doesn't return language dependent variables so it is + * intended to be used for default values in settings forms. + * + * @param $name + * The name of the variable to return. + * @param $default + * The default value to use if this variable has never been set. + * If a localizable string, should be the English value, not localized + * @param $localize + * Optional flag, wether the variable needs localization or not + * @return + * The value of the variable. + */ +function variable_get_default($name, $default, $localize = FALSE) { + global $conf; + $language = language_default(); + return isset($conf[$name]) ? $conf[$name] : ($localize ? t($default, 0, $language->language) : $default); +} + +/** * Set a persistent variable. * * @param $name * The name of the variable to set. + * @param $variable_language + * Language code to save with the value. Leave empty if the value + * is a global variable. * @param $value * The value to set. This can be any PHP data type; these functions take care * of serialization as necessary. */ -function variable_set($name, $value) { +function variable_set($name, $value, $variable_language = '') { global $conf; - db_lock_table('variable'); - db_query("DELETE FROM {variable} WHERE name = '%s'", $name); - db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value)); - db_unlock_tables(); + $serialized_value = serialize($value); + db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'", $serialized_value, $name); + if (!db_affected_rows()) { + @db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $serialized_value); + } - cache_clear_all('variables', 'cache'); + cache_clear_all('variables:'. $variable_language, 'cache'); + if ($variable_language) { + $conf[$variable_language][$name] = $value; + } else { $conf[$name] = $value; } +} /** * Unset a persistent variable. * * @param $name * The name of the variable to undefine. + * @param $variable_language + * Language code of the variable to undefine. Leave empty + * if the value is a global variable. */ -function variable_del($name) { +function variable_del($name, $variable_language = '') { global $conf; - db_query("DELETE FROM {variable} WHERE name = '%s'", $name); + db_query("DELETE FROM {variable} WHERE name = '%s' AND language = '%s'", $name, $variable_language); cache_clear_all('variables', 'cache'); + if ($variable_language) { + unset($conf[$name][$variable_language]); + } else { unset($conf[$name]); } +} /** @@ -703,7 +766,7 @@ 'user' => $user, 'request_uri' => $base_root . request_uri(), 'referer' => referer_uri(), - 'ip' => $_SERVER['REMOTE_ADDR'], + 'ip' => ip_address(), 'timestamp' => time(), ); @@ -819,7 +882,7 @@ function drupal_anonymous_user($session = '') { $user = new stdClass(); $user->uid = 0; - $user->hostname = $_SERVER['REMOTE_ADDR']; + $user->hostname = ip_address(); $user->roles = array(); $user->roles[DRUPAL_ANONYMOUS_RID] = 'anonymous user'; $user->session = $session; @@ -881,9 +944,9 @@ case DRUPAL_BOOTSTRAP_ACCESS: // Deny access to hosts which were banned - t() is not yet available. - if (drupal_is_denied('host', $_SERVER['REMOTE_ADDR'])) { + if (drupal_is_denied('host', ip_address())) { header('HTTP/1.1 403 Forbidden'); - print 'Sorry, '. $_SERVER['REMOTE_ADDR'] .' has been banned.'; + print 'Sorry, '. ip_address() .' has been banned.'; exit(); } break; @@ -999,7 +1062,7 @@ * Choose a language for the current page, based on site and user preferences. */ function drupal_init_language() { - global $language, $user; + global $language, $conf; // Ensure the language is correctly returned, even without multilanguage support. // Useful for eg. XML/HTML 'lang' attributes. @@ -1009,6 +1072,9 @@ else { include_once './includes/language.inc'; $language = language_initialize(); + // We already loaded the variables without language, + // now load the language dependent ones, after we have the language selected. + $conf[$language->language] = variable_init(array(), $language->language); } } @@ -1056,3 +1122,31 @@ function language_default() { return variable_get('language_default', (object) array('language' => 'en', 'name' => 'English', 'native' => 'English', 'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '', 'domain' => '', 'prefix' => '', 'weight' => 0)); } + +/** + * If Drupal is behind a reverse proxy, we use the X-Forwarded-For header + * instead of $_SERVER['REMOTE_ADDR'], which would be the IP address + * of the proxy server, and not the client's. + * + * @return + * IP address of client machine, adjusted for reverse proxy. + */ +function ip_address() { + static $remote_ip; + + if ($remote_ip) { + // We have been here before, so just return the one we processed before + return $remote_ip; + } + else { + $remote_ip = $_SERVER['REMOTE_ADDR']; + if (variable_get('reverse_proxy', FALSE) && array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { + $ip_array = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + // If there are several arguments, the leftmost one is the farthest client + $remote_ip = $ip_array[0]; + } + } + // Store the satnized version in the static variable + $remote_ip = check_plain($remote_ip); + return $remote_ip; +} Index: includes/language.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/language.inc,v retrieving revision 1.4 diff -u -r1.4 language.inc --- includes/language.inc 18 Apr 2007 21:56:18 -0000 1.4 +++ includes/language.inc 26 May 2007 13:25:59 -0000 @@ -134,3 +134,20 @@ } } } + +/** + * Returns translated variables for a given language + */ +function language_variable_init($langcode) { + $default = language_default(); + $variables = array(); + // No translations for default language + if ($default->language != $langcode) { + // Load text translations for variables + $result = db_query("SELECT s.location, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid WHERE s.textgroup = 'variable' AND t.language = '%s'", $langcode); + while ($data = db_fetch_object($result)) { + $variables[$data->location] = $data->translation; + } + } + return $variables; +} \ No newline at end of file Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.174 diff -u -r1.174 locale.module --- modules/locale/locale.module 22 May 2007 07:42:37 -0000 1.174 +++ modules/locale/locale.module 26 May 2007 13:26:01 -0000 @@ -262,10 +262,194 @@ ); } } + // Rewrite forms for multilingual variables. + if ($variables = _locale_forms($form_id)) { + if ($replaced = locale_form_replace($variables, $form)) { + $form['locale_replaced'] = array('#type' => 'value', '#value' => $replaced); + // Add locale submit callback the first and pass replaced variables as additional arguments + $form['#submit'] = array_merge(array('locale_form_replace_submit'), $form['#submit']); + } + } + } +} + +/** + * Form callback. Saves multilingual variables + */ +function locale_form_replace_submit(&$form_values, $form, $form_status) { + $op = isset($form_values['op']) ? $form_values['op'] : ''; + $Language_default = language_default(); + if ($op == t('Reset to defaults')) { + return; + } + foreach ($form_values['locale_replaced'] as $field => $method) { + if (isset($form_values[$field])) { + switch ($method) { + case 'text': + locale_form_handler_text('submit', $field, $form_values); + break; + default: + locale_form_handler_spawn('submit', $field, $form_values); + } + } + } + unset($form_values['locale_replaced']); +} + +/** + * Replace multilingual variables in forms with an array of values for every language + * + * This is a recursive function that will go through the whole form tree + * + * @param $variables + * List of variables to be replaced with tree structure, like in the form + * @param $form + * Form object + * + * @return + * List of replaced variables + */ +function locale_form_replace(&$variables, &$form) { + $replaced = array(); + foreach ($variables as $field => $value) { + if (is_array($value) && isset($form[$field])) { + // Recursive call on subform elements + $replaced += locale_form_replace($value, $form[$field]); + } elseif(is_string($value) && isset($form[$field])) { + switch ($value) { + case 'text': + $replaced += locale_form_handler_text('alter', $field, $form); + break; + default: + $replaced += locale_form_handler_spawn('alter', $field, $form); + } + } } + return $replaced; } /** + * Form handler for variables stored in textgroup interface. + */ +function locale_form_handler_text($op, $variable, &$form = NULL) { + + switch ($op) { + case 'alter': + // Replace value with default language + $language_default = language_default(); + if (isset($form[$variable]['#value'])) { + // This is just a form value + $form[$variable]['#value'] = variable_get($variable, $form[$variable]['#value'], $language_default->language); + } else { + // Regular form field + if (isset($form[$variable]['#default_value'])) { + $form[$variable]['#default_value'] = variable_get($variable, $form[$variable]['#default_value'], $language_default->language); + } + $form[$variable]['#description'] .='
'. t('This is a translatable setting. The value here is for the default language.'); + } + return array($variable => 'text'); + + case 'submit': // We save the value through the textgroups interface + drupal_set_message("DEBUG: Saving multilingual text variable $variable"); + // The value will be saved as default for this variable + $value = $form[$variable]; + if ($source = db_fetch_object(db_query("SELECT * FROM {locales_source} WHERE location = '%s' AND textgroup = '%s'", $variable, 'variable'))) { + // Update entry only if source string changed. + if ($source->source != $form[$variable]) { + db_query("UPDATE {locales_source} SET source = '%s' WHERE location = '%s' AND textgroup = '%s'", $value, $variable, 'variable'); + } + } else { + // Create new entry. + db_query("INSERT INTO {locales_source} (source, location, textgroup) VALUES('%s', '%s', '%s')", $value, $variable, 'variable'); + } + } +} + +function locale_form_handler_spawn($op, $variable, &$form) { + $language_default = language_default(); + + // Get and compute localizable variables + $locale_variables = variable_get('locale_variables', array()); + $query = !empty($_GET) ? $_GET : array(); + $localize = isset($query[$variable]) ? $query[$variable] : in_array($variable, $locale_variables); + + switch ($op) { + case 'alter': + // If it's not a field, may be a value, forget about this variable and return + if (!isset($form[$variable]['#type']) || $form[$variable]['#type'] == 'value') { + return array(); + } + + if ($localize) { + $field = $form[$variable]; + $form[$variable]['#type'] = 'fieldset'; + $form[$variable]['#tree'] = TRUE; + $form[$variable]['#collapsible'] = TRUE; + $query[$variable] = 0; + $change_link = l(t('change this setting'), $_GET['q'], array('query' => $query)); + $form[$variable]['#description'] .= '
'.t('This is a localizable setting so it can take a value for each language. You can !change_link', array('!change_link' => $change_link)); + unset($form['#default_value']); + unset($field['#description']); + // Variable default + foreach (locale_language_list() as $lang => $language) { + $form[$variable][$lang] = $field; + // The default value may be tricky, we look for a global default, if not + $form[$variable][$lang]['#default_value'] = variable_get($variable, $field['#default_value'], $lang); + $form[$variable][$lang]['#title'] = $language; + } + // Mark variable in default language + $form[$variable][$language_default->language]['#description'] = t('This will be the default value.'); + } else { + $query[$variable] = 1; + $change_link = l(t('make this setting localizable'), $_GET['q'], array('query' => $query)); + $form[$variable]['#description'] .= '
'.t('You can !change_link so it can take a value for each language.', array('!change_link' => $change_link)); + } + return array($variable => 'spawn'); + + case 'submit': // We save the value for each language and set only the default in form_values + $form_values = &$form; + if ($localize) { + drupal_set_message("DEBUG: Saving multilingual variable $variable"); + foreach ($form_values[$variable] as $lang => $value) { + if (is_array($value) && isset($form_values['array_filter'])) { + $value = array_keys(array_filter($value)); + } + variable_set($variable, $value, $lang); + } + // Set default value for this variable so it will be saved the regular way + $form_values[$variable] = $form_values[$variable][$language_default->language]; + } + // Check for changed status of variable and add/remove from locale list + if (isset($query[$variable])) { + if ($query[$variable] && !in_array($variable, $locale_variables)) { + variable_set('locale_variables', array_merge($locale_variables, array($variable))); + } + if (!$query[$variable] && in_array($variable, $locale_variables)) { + variable_set('locale_variables', array_diff($locale_variables, array($variable))); + } + } + } +} + +/** + * Returns an array with variables to be replaced for multilingual values + * + * The form of the array is + * array( + * // For a simple form without tree structure + * 'form_id_1' => array('variable1', 'variable2'...), + * // For a form with tree structure + * 'form_id_2' => array('fieldset1' => array('variable1', 'variable2')) + * ) + */ +function _locale_forms($form_id) { + static $forms; + if (empty($forms)) { + $forms = module_invoke_all('locale', 'forms'); + } + return array_key_exists($form_id, $forms) ? $forms[$form_id] : NULL; +} +/** * Implementation of hook_theme() */ function locale_theme() { Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.482 diff -u -r1.482 system.module --- modules/system/system.module 25 May 2007 15:04:42 -0000 1.482 +++ modules/system/system.module 26 May 2007 13:26:04 -0000 @@ -429,7 +429,7 @@ '#options' => $options, '#title' => t('Administration theme'), '#description' => t('Choose which theme the administration pages should display in. If you choose "System default" the administration pages will use the same theme as the rest of the site.'), - '#default_value' => variable_get('admin_theme', '0'), + '#default_value' => variable_get_default('admin_theme', '0'), ); $form['#submit'][] = 'system_admin_theme_submit'; @@ -439,7 +439,7 @@ function system_admin_theme_submit($form_values, $form, &$form_state) { // If we're changing themes, make sure the theme has its blocks initialized. - if ($form_values['admin_theme'] != variable_get('admin_theme', '0')) { + if ($form_values['admin_theme'] != variable_get_default('admin_theme', '0')) { $result = db_query("SELECT status FROM {blocks} WHERE theme = '%s'", $form_values['admin_theme']); if (!db_num_rows($result)) { system_initialize_theme_blocks($form_values['admin_theme']); @@ -483,7 +483,7 @@ foreach ($enabled as $info) { // For the default theme, revert to an empty string so the user's theme updates when the site theme is changed. - $info->key = $info->name == variable_get('theme_default', 'garland') ? '' : $info->name; + $info->key = $info->name == variable_get_default('theme_default', 'garland') ? '' : $info->name; $screenshot = NULL; $theme_key = $info->name; @@ -498,7 +498,7 @@ $screenshot = $screenshot ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot'); $form['themes'][$info->key]['screenshot'] = array('#value' => $screenshot); - $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'garland') ? '
'. t('(site default theme)') .'' : '')); + $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name, '#value' => dirname($info->filename) . ($info->name == variable_get_default('theme_default', 'garland') ? '
'. t('(site default theme)') .'' : '')); $options[$info->key] = ''; } @@ -531,7 +531,7 @@ $zones = array(); foreach ($zonelist as $offset) { $zone = $offset * 3600; - $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') .' O', $zone); + $zones[$zone] = format_date($timestamp, 'custom', variable_get_default('date_format_long', 'l, F j, Y - H:i') .' O', $zone); } return $zones; } @@ -540,49 +540,49 @@ $form['site_name'] = array( '#type' => 'textfield', '#title' => t('Name'), - '#default_value' => variable_get('site_name', 'Drupal'), + '#default_value' => variable_get_default('site_name', 'Drupal'), '#description' => t('The name of this website.'), '#required' => TRUE ); $form['site_mail'] = array( '#type' => 'textfield', '#title' => t('E-mail address'), - '#default_value' => variable_get('site_mail', ini_get('sendmail_from')), + '#default_value' => variable_get_default('site_mail', ini_get('sendmail_from')), '#description' => t('A valid e-mail address to be used as the "From" address by the auto-mailer during registration, new password requests, notifications, etc. To lessen the likelihood of e-mail being marked as spam, this e-mail address should use the same domain as the website.'), '#required' => TRUE, ); $form['site_slogan'] = array( '#type' => 'textfield', '#title' => t('Slogan'), - '#default_value' => variable_get('site_slogan', ''), + '#default_value' => variable_get_default('site_slogan', ''), '#description' => t('The slogan of this website. Some themes display a slogan when available.') ); $form['site_mission'] = array( '#type' => 'textarea', '#title' => t('Mission'), - '#default_value' => variable_get('site_mission', ''), + '#default_value' => variable_get_default('site_mission', ''), '#description' => t('Your site\'s mission statement or focus.') ); $form['site_footer'] = array( '#type' => 'textarea', '#title' => t('Footer message'), - '#default_value' => variable_get('site_footer', ''), + '#default_value' => variable_get_default('site_footer', ''), '#description' => t('This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages.') ); $form['anonymous'] = array( '#type' => 'textfield', '#title' => t('Anonymous user'), - '#default_value' => variable_get('anonymous', t('Anonymous')), + '#default_value' => variable_get_default('anonymous', 'Anonymous', TRUE), '#description' => t('The name used to indicate anonymous users.') ); $form['site_frontpage'] = array( '#type' => 'textfield', '#title' => t('Default front page'), - '#default_value' => variable_get('site_frontpage', 'node'), + '#default_value' => variable_get_default('site_frontpage', 'node'), '#size' => 40, '#description' => t('The home page displays content from this relative URL. If unsure, specify "node".'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') + '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get_default('clean_url', 0) ? '' : '?q=') ); return system_settings_form($form); @@ -592,12 +592,12 @@ $form['clean_url'] = array( '#type' => 'radios', '#title' => t('Clean URLs'), - '#default_value' => variable_get('clean_url', 0), + '#default_value' => variable_get_default('clean_url', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('This option makes Drupal emit "clean" URLs (i.e. without ?q= in the URL).'), ); - if (!variable_get('clean_url', 0)) { + if (!variable_get_default('clean_url', 0)) { if (strpos(request_uri(), '?q=') !== FALSE) { drupal_add_js(array('cleanURL' => array('success' => t('Your server has been successfully tested to support this feature.'), 'failure' => t('Your system configuration does not currently support this feature. The handbook page on Clean URLs has additional troubleshooting information.'), 'testing' => t('Testing clean URLs...'))), 'setting'); drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module'); @@ -628,23 +628,23 @@ $form['site_403'] = array( '#type' => 'textfield', '#title' => t('Default 403 (access denied) page'), - '#default_value' => variable_get('site_403', ''), + '#default_value' => variable_get_default('site_403', ''), '#size' => 40, '#description' => t('This page is displayed when the requested document is denied to the current user. If unsure, specify nothing.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') + '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get_default('clean_url', 0) ? '' : '?q=') ); $form['site_404'] = array( '#type' => 'textfield', '#title' => t('Default 404 (not found) page'), - '#default_value' => variable_get('site_404', ''), + '#default_value' => variable_get_default('site_404', ''), '#size' => 40, '#description' => t('This page is displayed when no other content matches the requested document. If unsure, specify nothing.'), - '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q=') + '#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get_default('clean_url', 0) ? '' : '?q=') ); $form['error_level'] = array( - '#type' => 'select', '#title' => t('Error reporting'), '#default_value' => variable_get('error_level', 1), + '#type' => 'select', '#title' => t('Error reporting'), '#default_value' => variable_get_default('error_level', 1), '#options' => array(t('Write errors to the log'), t('Write errors to the log and to the screen')), '#description' => t('Where Drupal, PHP and SQL errors are logged. On a production server it is recommended that errors are only written to the error log. On a test server it can be helpful to write logs to the screen.') ); @@ -674,7 +674,7 @@ $form['page_cache']['cache'] = array( '#type' => 'radios', '#title' => t('Caching mode'), - '#default_value' => variable_get('cache', CACHE_DISABLED), + '#default_value' => variable_get_default('cache', CACHE_DISABLED), '#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Normal (recommended, no side effects)'), CACHE_AGGRESSIVE => t('Aggressive (experts only, possible side effects)')), '#description' => $description ); @@ -684,7 +684,7 @@ $form['page_cache']['cache_lifetime'] = array( '#type' => 'select', '#title' => t('Minimum cache lifetime'), - '#default_value' => variable_get('cache_lifetime', 0), + '#default_value' => variable_get_default('cache_lifetime', 0), '#options' => $period, '#description' => t('On high-traffic sites it can become necessary to enforce a minimum cache lifetime. The minimum cache lifetime is the minimum amount of time that will go by before the cache is emptied and recreated. A larger minimum cache lifetime offers better performance, but users will not see new content for a longer period of time.') ); @@ -696,11 +696,11 @@ ); $directory = file_directory_path(); - $is_writable = is_dir($directory) && is_writable($directory) && (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC); + $is_writable = is_dir($directory) && is_writable($directory) && (variable_get_default('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC); $form['bandwidth_optimizations']['preprocess_css'] = array( '#type' => 'radios', '#title' => t('Aggregate and compress CSS files'), - '#default_value' => variable_get('preprocess_css', FALSE) && $is_writable, + '#default_value' => variable_get_default('preprocess_css', FALSE) && $is_writable, '#disabled' => !$is_writable, '#options' => array(t('Disabled'), t('Enabled')), '#description' => t("Some Drupal modules include their own CSS files. When these modules are enabled, each module's CSS file adds an additional HTTP request to the page, which can increase the load time of each page. These HTTP requests can also slightly increase server load. It is recommended to only turn this option on when your site is in production, as it can interfere with theme development. This option is disabled if you have not set up your files directory, or if your download method is set to private."), @@ -748,7 +748,7 @@ $form['file_downloads'] = array( '#type' => 'radios', '#title' => t('Download method'), - '#default_value' => variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC), + '#default_value' => variable_get_default('file_downloads', FILE_DOWNLOADS_PUBLIC), '#options' => array(FILE_DOWNLOADS_PUBLIC => t('Public - files are available using HTTP directly.'), FILE_DOWNLOADS_PRIVATE => t('Private - files are transferred by Drupal.')), '#description' => t('If you want any sort of access control on the downloading of files, this needs to be set to private. You can change this at any time, however all download URLs will change and there may be unexpected problems so it is not recommended.') ); @@ -762,7 +762,7 @@ $form['image_toolkit'] = array( '#type' => 'radios', '#title' => t('Select an image processing toolkit'), - '#default_value' => variable_get('image_toolkit', image_get_toolkit()), + '#default_value' => variable_get_default('image_toolkit', image_get_toolkit()), '#options' => $toolkits_available ); } @@ -778,14 +778,14 @@ $form['feed_default_items'] = array( '#type' => 'select', '#title' => t('Number of items per feed'), - '#default_value' => variable_get('feed_default_items', 10), + '#default_value' => variable_get_default('feed_default_items', 10), '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)), '#description' => t('The default number of items to include in a feed.') ); $form['feed_item_length'] = array( '#type' => 'select', '#title' => t('Display of XML feed items'), - '#default_value' => variable_get('feed_item_length', 'teaser'), + '#default_value' => variable_get_default('feed_item_length', 'teaser'), '#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')), '#description' => t('Global setting for the length of XML feed items that are output by default.') ); @@ -837,7 +837,7 @@ $form['locale']['date_default_timezone'] = array( '#type' => 'select', '#title' => t('Default time zone'), - '#default_value' => variable_get('date_default_timezone', 0), + '#default_value' => variable_get_default('date_default_timezone', 0), '#options' => $zones, '#description' => t('Select the default site time zone.') ); @@ -845,7 +845,7 @@ $form['locale']['configurable_timezones'] = array( '#type' => 'radios', '#title' => t('User-configurable time zones'), - '#default_value' => variable_get('configurable_timezones', 1), + '#default_value' => variable_get_default('configurable_timezones', 1), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('When enabled, users can set their own time zone and dates will be displayed accordingly.') ); @@ -853,7 +853,7 @@ $form['locale']['date_first_day'] = array( '#type' => 'select', '#title' => t('First day of week'), - '#default_value' => variable_get('date_first_day', 0), + '#default_value' => variable_get_default('date_first_day', 0), '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')), '#description' => t('The first day of the week for calendar views.') ); @@ -863,7 +863,7 @@ '#title' => t('Formatting'), ); - $date_format_short = variable_get('date_format_short', $date_short[1]); + $date_format_short = variable_get_default('date_format_short', $date_short[1]); $form['date_formats']['date_format_short'] = array( '#prefix' => '
', '#suffix' => '
', @@ -875,7 +875,7 @@ '#description' => t('The short format of date display.'), ); - $default_short_custom = variable_get('date_format_short_custom', (isset($date_short_choices[$date_format_short]) ? $date_format_short : '')); + $default_short_custom = variable_get_default('date_format_short_custom', (isset($date_short_choices[$date_format_short]) ? $date_format_short : '')); $form['date_formats']['date_format_short_custom'] = array( '#prefix' => '
', '#suffix' => '
', @@ -886,7 +886,7 @@ '#description' => t('A user-defined short date format. See the PHP manual for available options. This format is currently set to display as %date.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_short_custom))), ); - $date_format_medium = variable_get('date_format_medium', $date_medium[1]); + $date_format_medium = variable_get_default('date_format_medium', $date_medium[1]); $form['date_formats']['date_format_medium'] = array( '#prefix' => '
', '#suffix' => '
', @@ -898,7 +898,7 @@ '#description' => t('The medium sized date display.'), ); - $default_medium_custom = variable_get('date_format_medium_custom', (isset($date_medium_choices[$date_format_medium]) ? $date_format_medium : '')); + $default_medium_custom = variable_get_default('date_format_medium_custom', (isset($date_medium_choices[$date_format_medium]) ? $date_format_medium : '')); $form['date_formats']['date_format_medium_custom'] = array( '#prefix' => '
', '#suffix' => '
', @@ -909,7 +909,7 @@ '#description' => t('A user-defined medium date format. See the PHP manual for available options. This format is currently set to display as %date.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_medium_custom))), ); - $date_format_long = variable_get('date_format_long', $date_long[0]); + $date_format_long = variable_get_default('date_format_long', $date_long[0]); $form['date_formats']['date_format_long'] = array( '#prefix' => '
', '#suffix' => '
', @@ -921,7 +921,7 @@ '#description' => t('Longer date format used for detailed display.') ); - $default_long_custom = variable_get('date_format_long_custom', (isset($date_long_choices[$date_format_long]) ? $date_format_long : '')); + $default_long_custom = variable_get_default('date_format_long_custom', (isset($date_long_choices[$date_format_long]) ? $date_format_long : '')); $form['date_formats']['date_format_long_custom'] = array( '#prefix' => '
', '#suffix' => '
', @@ -965,15 +965,16 @@ $form['site_offline'] = array( '#type' => 'radios', '#title' => t('Site status'), - '#default_value' => variable_get('site_offline', 0), + '#default_value' => variable_get_default('site_offline', 0), '#options' => array(t('Online'), t('Off-line')), '#description' => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Off-line", only users with the "administer site configuration" permission will be able to access your site to perform maintenance; all other visitors will see the site off-line message configured below. Authorized users can log in during "Off-line" mode directly via the user login page.', array('@user-login' => url('user'))), ); - + // This variable should be localized to default language + $default = language_default(); $form['site_offline_message'] = array( '#type' => 'textarea', '#title' => t('Site off-line message'), - '#default_value' => variable_get('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')))), + '#default_value' => variable_get_default('site_offline_message', t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')), $default->language)), '#description' => t('Message to show visitors when the site is in off-line mode.') ); @@ -1218,6 +1219,25 @@ } /** + * Implementation of hook_locale(). + */ +function system_locale($op) { + switch ($op) { + case 'groups': + return array('variable' => t('Site settings')); + case 'forms': + return array( + 'system_site_information_settings' => array( + 'site_name' => 'text', + 'site_slogan' => 'text', + 'site_mission' => 'text', + 'site_footer' => 'text', + 'anonymous' => 'spawn', + 'site_frontpage' => 'spawn'), + ); + } +} +/** * Add default buttons to a form and set its prefix */ function system_settings_form($form) {