From a8b52a1e09fd646ab1ac12fb10675ae92d8c140a Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 22 Dec 2010 01:38:37 -0700 Subject: [PATCH] Add on-demand loading of nlsconfig data. Move nlsconfig manipulation code inside of this new object. Cache nlsconfig info about the current language - only need to load nls.php config file now if manipulating an entire config entry. --- framework/Core/lib/Horde.php | 12 +- framework/Core/lib/Horde/Config.php | 2 +- .../lib/Horde/Core/Ajax/Imple/SpellChecker.php | 4 +- framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php | 4 +- framework/Core/lib/Horde/Core/Ui/Language.php | 2 +- framework/Core/lib/Horde/Help.php | 4 +- framework/Core/lib/Horde/Menu.php | 2 +- framework/Core/lib/Horde/Registry.php | 52 ++++----- framework/Core/lib/Horde/Registry/Nlsconfig.php | 129 +++++++++++++++++++++ framework/Core/lib/Horde/Themes/Css.php | 2 +- framework/Core/package.xml | 2 + horde/config/prefs.php.dist | 2 +- horde/lib/Prefs/Ui.php | 6 +- horde/login.php | 2 +- horde/services/help/index.php | 2 +- horde/services/sidebar.php | 2 +- imp/compose.php | 5 +- imp/config/prefs.php.dist | 11 +- imp/lib/Prefs/Ui.php | 7 -- imp/mailbox.php | 2 +- imp/message.php | 2 +- nag/lib/Task.php | 4 +- turba/data.php | 7 +- 23 files changed, 186 insertions(+), 81 deletions(-) create mode 100644 framework/Core/lib/Horde/Registry/Nlsconfig.php diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 84a8634d2..86945d034 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -1590,10 +1590,7 @@ HTML; */ static public function stripAccessKey($label) { - $multibyte = isset($GLOBALS['registry']->nlsconfig['multibyte'][$GLOBALS['registry']->getLanguageCharset()]); - return preg_replace('/_([A-Za-z])/', - $multibyte && preg_match('/[\x80-\xff]/', $label) ? '' : '\1', - $label); + return preg_replace('/_([A-Za-z])/', $GLOBALS['registry']->nlsconfig->curr_multibyte && preg_match('/[\x80-\xff]/', $label) ? '' : '\1', $label); } /** @@ -1613,11 +1610,12 @@ HTML; return $stripped_label; } - if (isset($GLOBALS['registry']->nlsconfig['multibyte'][$GLOBALS['registry']->getLanguageCharset()])) { + if ($GLOBALS['registry']->nlsconfig->curr_multibyte) { /* Prefix parenthesis with the UTF-8 representation of the LRO * (Left-to-Right-Override) Unicode codepoint U+202D. */ - return $stripped_label . "\xe2\x80\xad" . '(' - . strtoupper($accessKey) . '' . ')'; + return $stripped_label . "\xe2\x80\xad" . + '(' . strtoupper($accessKey) . + '' . ')'; } return str_replace('_' . $accessKey, '' . $accessKey . '', $label); diff --git a/framework/Core/lib/Horde/Config.php b/framework/Core/lib/Horde/Config.php index b540d7564..f3c24991a 100644 --- a/framework/Core/lib/Horde/Config.php +++ b/framework/Core/lib/Horde/Config.php @@ -1600,7 +1600,7 @@ class Horde_Config return $apps; case 'list-horde-languages': - return array_map(create_function('$val', 'return preg_replace(array("/&#x([0-9a-f]{4});/ie", "/(&[^;]+;)/e"), array("Horde_String::convertCharset(pack(\"H*\", \"$1\"), \"ucs-2\", \"UTF-8\")", "Horde_String::convertCharset(html_entity_decode(\"$1\", ENT_COMPAT, \"iso-8859-1\"), \"iso-8859-1\", \"UTF-8\")"), $val);'), $GLOBALS['registry']->nlsconfig['languages']); + return array_map(create_function('$val', 'return preg_replace(array("/&#x([0-9a-f]{4});/ie", "/(&[^;]+;)/e"), array("Horde_String::convertCharset(pack(\"H*\", \"$1\"), \"ucs-2\", \"UTF-8\")", "Horde_String::convertCharset(html_entity_decode(\"$1\", ENT_COMPAT, \"iso-8859-1\"), \"iso-8859-1\", \"UTF-8\")"), $val);'), $GLOBALS['registry']->nlsconfig->languages); case 'list-blocks': $collection = Horde_Block_Collection::singleton(); diff --git a/framework/Core/lib/Horde/Core/Ajax/Imple/SpellChecker.php b/framework/Core/lib/Horde/Core/Ajax/Imple/SpellChecker.php index b72ccbfd5..fb4a5ba45 100644 --- a/framework/Core/lib/Horde/Core/Ajax/Imple/SpellChecker.php +++ b/framework/Core/lib/Horde/Core/Ajax/Imple/SpellChecker.php @@ -41,12 +41,12 @@ class Horde_Core_Ajax_Imple_SpellChecker extends Horde_Core_Ajax_Imple } if (empty($params['locales'])) { - $key_list = array_keys($GLOBALS['registry']->nlsconfig['spelling']); + $key_list = array_keys($GLOBALS['registry']->nlsconfig->spelling); asort($key_list, SORT_LOCALE_STRING); $params['locales'] = array(); foreach ($key_list as $lcode) { - $params['locales'][] = array('l' => $GLOBALS['registry']->nlsconfig['languages'][$lcode], 'v' => $lcode); + $params['locales'][] = array('l' => $GLOBALS['registry']->nlsconfig->languages[$lcode], 'v' => $lcode); } } diff --git a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php index 74ac01432..1c783712a 100644 --- a/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php +++ b/framework/Core/lib/Horde/Core/Prefs/Ui/Widgets.php @@ -89,8 +89,8 @@ class Horde_Core_Prefs_Ui_Widgets )); } - $t->set('addimg', Horde::img(isset($GLOBALS['registry']->nlsconfig['rtl'][$GLOBALS['language']]) ? 'lhand.png' : 'rhand.png', Horde_Core_Translation::t("Add source"))); - $t->set('removeimg', Horde::img(isset($GLOBALS['registry']->nlsconfig['rtl'][$GLOBALS['language']]) ? 'rhand.png' : 'lhand.png', Horde_Core_Translation::t("Remove source"))); + $t->set('addimg', Horde::img($GLOBALS['registry']->nlsconfig->curr_rtl ? 'lhand.png' : 'rhand.png', Horde_Core_Translation::t("Add source"))); + $t->set('removeimg', Horde::img($GLOBALS['registry']->nlsconfig->curr_rtl ? 'rhand.png' : 'lhand.png', Horde_Core_Translation::t("Remove source"))); if (empty($data['no_up'])) { $t->set('upimg', Horde::img('nav/up.png', Horde_Core_Translation::t("Move up"))); diff --git a/framework/Core/lib/Horde/Core/Ui/Language.php b/framework/Core/lib/Horde/Core/Ui/Language.php index b7c0dae4c..9597c8251 100644 --- a/framework/Core/lib/Horde/Core/Ui/Language.php +++ b/framework/Core/lib/Horde/Core/Ui/Language.php @@ -35,7 +35,7 @@ class Horde_Core_Ui_Language { Horde::url($registry->get('webroot', 'horde') . '/services/language.php', false, -1)); $html .= ''; $html .= ' widget containing the available languages. */ if (!$is_auth && !$prefs->isLocked('language')) { $langs = array(); - foreach ($registry->nlsconfig['languages'] as $key => $val) { + foreach ($registry->nlsconfig->languages as $key => $val) { $langs[] = array( 'sel' => ($key == $GLOBALS['language']), 'val' => $key, diff --git a/horde/services/help/index.php b/horde/services/help/index.php index ad7f7e3f5..194c3d3b9 100644 --- a/horde/services/help/index.php +++ b/horde/services/help/index.php @@ -13,7 +13,7 @@ Horde_Registry::appInit('horde', array('authentication' => 'none')); $vars = Horde_Variables::getDefaultVariables(); -$rtl = isset($registry->nlsconfig['rtl'][$language]); +$rtl = $registry->nlsconfig->curr_rtl; $title = _("Help"); $show = isset($vars->show) ? Horde_String::lower($vars->show) diff --git a/horde/services/sidebar.php b/horde/services/sidebar.php index 6d7680143..15bfbdc8a 100644 --- a/horde/services/sidebar.php +++ b/horde/services/sidebar.php @@ -31,7 +31,7 @@ if (!Horde_Util::getFormData('ajaxui') && $ajax_url = Horde::getServiceLink('ajax', 'horde'); $ajax_url->pathInfo = 'sidebarUpdate'; - $rtl = intval(isset($registry->nlsconfig['rtl'][$language])); + $rtl = intval($registry->nlsconfig->curr_rtl); $show_sidebar = !isset($_COOKIE['horde_sidebar_expanded']) || $_COOKIE['horde_sidebar_expanded']; $width = intval($prefs->getValue('sidebar_width')); diff --git a/imp/compose.php b/imp/compose.php index c3f674c2d..a1ba198cf 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -822,8 +822,9 @@ if ($redirect) { $t->set('charset_label', Horde::label('charset', _("C_harset"))); $t->set('charset_tabindex', ++$tabindex); $charset_array = array(); - asort($registry->nlsconfig['encodings']); - foreach (array_merge(array('' => _("Default")), $registry->nlsconfig['encodings']) as $encoding => $label) { + $enc_list = $registry->nslconfig->encodings; + asort($enc_list); + foreach (array_merge(array('' => _("Default")), $enc_list) as $encoding => $label) { $charset_array[] = array( 'label' => $label, 'selected' => (strcasecmp($encoding, $charset) === 0), diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index bb4d5cf2f..6f08dd465 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -823,15 +823,16 @@ $_prefs['mail_hdr'] = array( ); // default message character set + $_prefs['default_msg_charset'] = array( - 'value' => isset($GLOBALS['registry']->nlsconfig['emails'][$GLOBALS['language']]) - ? $GLOBALS['registry']->nlsconfig['emails'][$GLOBALS['language']] - : (isset($GLOBALS['registry']->nlsconfig['charsets'][$GLOBALS['language']]) - ? $GLOBALS['registry']->nlsconfig['charsets'][$GLOBALS['language']] + 'value' => $GLOBALS['registry']->getEmailCharset() + ? $GLOBALS['registry']->getEmailCharset() + : ($GLOBALS['registry']->getLanguageCharset() + ? $GLOBALS['registry']->getLanguageCharset() : ''), 'type' => 'enum', 'enum' => array_merge( - array('' => _("Default (US-ASCII)")), $GLOBALS['registry']->nlsconfig['encodings'] + array('' => _("Default (US-ASCII)")), $GLOBALS['registry']->nlsconfig->encodings_sort ), 'desc' => _("The default charset for messages with no charset information:"), 'help' => 'prefs-default_msg_charset' diff --git a/imp/lib/Prefs/Ui.php b/imp/lib/Prefs/Ui.php index 9b17a5af2..49748b023 100644 --- a/imp/lib/Prefs/Ui.php +++ b/imp/lib/Prefs/Ui.php @@ -128,13 +128,6 @@ class IMP_Prefs_Ui $ui->nobuttons = true; } break; - - case 'viewing': - /* Sort encodings. */ - if (!$prefs->isLocked('default_msg_charset')) { - asort($registry->nlsconfig['encodings']); - } - break; } /* Hide appropriate prefGroups. */ diff --git a/imp/mailbox.php b/imp/mailbox.php index 8064450e5..4dd4cd3fe 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -268,7 +268,7 @@ if ($readonly) { /* Generate paging links. */ if ($pageOb['pagecount']) { - $rtl = !empty($registry->nlsconfig['rtl'][$language]); + $rtl = $registry->nlsconfig->curr_rtl; if ($pageOb['page'] == 1) { $pages_first = Horde::img($rtl ? 'nav/last-grey.png' : 'nav/first-grey.png'); $pages_prev = Horde::img($rtl ? 'nav/right-grey.png' : 'nav/left-grey.png'); diff --git a/imp/message.php b/imp/message.php index 4c0fcfc27..3975c4409 100644 --- a/imp/message.php +++ b/imp/message.php @@ -482,7 +482,7 @@ if (!$use_pop) { $n_template->set('back_to', Horde::widget($mailbox_url, sprintf(_("Back to %s"), $h_page_label), 'widget', '', '', sprintf(_("Bac_k to %s"), $h_page_label), true)); -$rtl = !empty($registry->nlsconfig['rtl'][$language]); +$rtl = $registry->nlsconfig->curr_rtl; if (Horde_Util::nonInputVar('prev_url')) { $n_template->set('prev', Horde::link($prev_url, _("Previous Message"))); $n_template->set('prev_img', Horde::img($rtl ? 'nav/right.png' : 'nav/left.png', $rtl ? '>' : '<')); diff --git a/nag/lib/Task.php b/nag/lib/Task.php index 96b888cb7..bdbc3b961 100644 --- a/nag/lib/Task.php +++ b/nag/lib/Task.php @@ -552,9 +552,9 @@ class Nag_Task { } if ($this->indent) { if ($this->lastChild) { - $html .= Horde::img(empty($GLOBALS['registry']->nlsconfig['rtl'][$GLOBALS['language']]) ? 'tree/joinbottom.png' : 'tree/rev-joinbottom.png', '\\'); + $html .= Horde::img($GLOBALS['registry']->nlsconfig->curr_rtl ? 'tree/joinbottom.png' : 'tree/rev-joinbottom.png', '\\'); } else { - $html .= Horde::img(empty($GLOBALS['registry']->nlsconfig['rtl'][$GLOBALS['language']]) ? 'tree/join.png' : 'tree/rev-join.png', '+'); + $html .= Horde::img($GLOBALS['registry']->nlsconfig->curr_rtl ? 'tree/join.png' : 'tree/rev-join.png', '+'); } } diff --git a/turba/data.php b/turba/data.php index a8cc04e04..7810402d1 100644 --- a/turba/data.php +++ b/turba/data.php @@ -542,11 +542,8 @@ if ($next_step == Horde_Data::IMPORT_FILE) { } /* Build the charset options. */ - $charsets = $registry->nlsconfig['encodings']; - asort($charsets); - $all_charsets = $registry->nlsconfig['charsets']; - natcasesort($all_charsets); - foreach ($all_charsets as $charset) { + $charsets = $registry->nlsconfig->encodings_sort; + foreach ($registry->nlsconfig->charsets as $charset) { if (!isset($charsets[$charset])) { $charsets[$charset] = $charset; } -- 2.11.0