From d59c86bd1a8b7e25378c29b5e95b4b39ec7c760f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 30 Apr 2013 01:43:43 +0200 Subject: [PATCH] I18nHandler now provides reset() disableAssignValueVariables() and enableAssignValueVariables() have been removed in favor of reset(). --- .../form/AbstractCategoryAddForm.class.php | 4 +- .../lib/acp/form/CronjobAddForm.class.php | 1 + .../acp/form/PageMenuItemAddForm.class.php | 3 +- .../files/lib/acp/form/StyleAddForm.class.php | 2 + .../lib/acp/form/UserGroupAddForm.class.php | 2 + .../lib/acp/form/UserOptionAddForm.class.php | 2 + .../form/UserOptionCategoryAddForm.class.php | 3 +- .../lib/system/language/I18nHandler.class.php | 91 ++++++++----------- 8 files changed, 50 insertions(+), 58 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php b/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php index 94ba45a2b3..df99bc6aab 100644 --- a/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/AbstractCategoryAddForm.class.php @@ -286,8 +286,8 @@ abstract class AbstractCategoryAddForm extends AbstractForm { $this->saved(); - // disable assignment of i18n values - I18nHandler::getInstance()->disableAssignValueVariables(); + // reset i18n values + I18nHandler::getInstance()->reset(); // show success message WCF::getTPL()->assign('success', true); diff --git a/wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php b/wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php index 758a6d8081..13139d6816 100755 --- a/wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/CronjobAddForm.class.php @@ -182,6 +182,7 @@ class CronjobAddForm extends AbstractForm { // reset values $this->className = $this->description = ''; $this->startMinute = $this->startHour = $this->startDom = $this->startMonth = $this->startDow = '*'; + I18nHandler::getInstance()->reset(); // show success. WCF::getTPL()->assign(array( diff --git a/wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php b/wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php index 0c71259361..9a4d7cbf06 100644 --- a/wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/PageMenuItemAddForm.class.php @@ -239,8 +239,7 @@ class PageMenuItemAddForm extends AbstractForm { $this->menuItemController = $this->menuItemLink = $this->pageMenuItem = $this->parentMenuItem = ''; $this->showOrder = 0; - // disable assignment of value variables - I18nHandler::getInstance()->disableAssignValueVariables(); + I18nHandler::getInstance()->reset(); // reload parent menu items if ($menuItem->menuPosition == 'header' && $menuItem->parentMenuItem == '') { diff --git a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php index 9a14217efc..658c8da97a 100644 --- a/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/StyleAddForm.class.php @@ -505,6 +505,8 @@ class StyleAddForm extends AbstractForm { $this->imagePath = 'images/'; $this->templateGroupID = 0; + I18nHandler::getInstance()->reset(); + // reload variables $this->readStyleVariables(); diff --git a/wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php index abb59a9eb4..8d8db44aff 100755 --- a/wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserGroupAddForm.class.php @@ -157,6 +157,8 @@ class UserGroupAddForm extends AbstractOptionListForm { // reset values $this->groupName = ''; $this->optionValues = array(); + + I18nHandler::getInstance()->reset(); } /** diff --git a/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php index 229c32543e..db0ae7a381 100644 --- a/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php @@ -255,6 +255,8 @@ class UserOptionAddForm extends AbstractForm { $this->editable = 3; $this->visible = 15; + I18nHandler::getInstance()->reset(); + // show success WCF::getTPL()->assign('success', true); } diff --git a/wcfsetup/install/files/lib/acp/form/UserOptionCategoryAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserOptionCategoryAddForm.class.php index a7163c443d..67e81fbe15 100644 --- a/wcfsetup/install/files/lib/acp/form/UserOptionCategoryAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserOptionCategoryAddForm.class.php @@ -99,7 +99,8 @@ class UserOptionCategoryAddForm extends AbstractForm { // reset values $this->categoryName = ''; $this->showOrder = 0; - I18nHandler::getInstance()->disableAssignValueVariables(); + + I18nHandler::getInstance()->reset(); // show success WCF::getTPL()->assign(array( diff --git a/wcfsetup/install/files/lib/system/language/I18nHandler.class.php b/wcfsetup/install/files/lib/system/language/I18nHandler.class.php index 9a612c849d..c17f80fe9f 100644 --- a/wcfsetup/install/files/lib/system/language/I18nHandler.class.php +++ b/wcfsetup/install/files/lib/system/language/I18nHandler.class.php @@ -19,12 +19,6 @@ use wcf\util\StringUtil; * @category Community Framework */ class I18nHandler extends SingletonFactory { - /** - * indicates if value variables are assigned in assignVariables() - * @var boolean - */ - protected $assignValueVariablesDisabled = false; - /** * list of available languages * @var array @@ -374,51 +368,49 @@ class I18nHandler extends SingletonFactory { $value = ''; $i18nValues = array(); - if (!$this->assignValueVariablesDisabled) { - // use POST values instead of querying database - if ($useRequestData) { - if ($this->isPlainValue($elementID)) { - $value = $this->getValue($elementID); - } - else { - if ($this->hasI18nValues($elementID)) { - $i18nValues = $this->i18nValues[$elementID]; - // encoding the entries for javascript - foreach ($i18nValues as $languageID => $value) { - $i18nValues[$languageID] = StringUtil::encodeJS(StringUtil::unifyNewlines($value)); - } - } - else { - $i18nValues = array(); - } - } + // use POST values instead of querying database + if ($useRequestData) { + if ($this->isPlainValue($elementID)) { + $value = $this->getValue($elementID); } else { - $isI18n = Regex::compile('^'.$this->elementOptions[$elementID]['pattern'].'$')->match($this->elementOptions[$elementID]['value']); - if (!$isI18n) { - // check if it's a regular language variable - $isI18n = Regex::compile('^([a-zA-Z0-9-_]+\.)+[a-zA-Z0-9-_]+$')->match($this->elementOptions[$elementID]['value']); - } - - if ($isI18n) { - // use i18n values from language items - $sql = "SELECT languageID, languageItemValue - FROM wcf".WCF_N."_language_item - WHERE languageItem = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array( - $this->elementOptions[$elementID]['value'] - )); - while ($row = $statement->fetchArray()) { - $i18nValues[$row['languageID']] = StringUtil::encodeJS(StringUtil::unifyNewlines($row['languageItemValue'])); + if ($this->hasI18nValues($elementID)) { + $i18nValues = $this->i18nValues[$elementID]; + // encoding the entries for javascript + foreach ($i18nValues as $languageID => $value) { + $i18nValues[$languageID] = StringUtil::encodeJS(StringUtil::unifyNewlines($value)); } } else { - // use data provided by setOptions() - $value = $this->elementOptions[$elementID]['value']; + $i18nValues = array(); } } } + else { + $isI18n = Regex::compile('^'.$this->elementOptions[$elementID]['pattern'].'$')->match($this->elementOptions[$elementID]['value']); + if (!$isI18n) { + // check if it's a regular language variable + $isI18n = Regex::compile('^([a-zA-Z0-9-_]+\.)+[a-zA-Z0-9-_]+$')->match($this->elementOptions[$elementID]['value']); + } + + if ($isI18n) { + // use i18n values from language items + $sql = "SELECT languageID, languageItemValue + FROM wcf".WCF_N."_language_item + WHERE languageItem = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $this->elementOptions[$elementID]['value'] + )); + while ($row = $statement->fetchArray()) { + $i18nValues[$row['languageID']] = StringUtil::encodeJS(StringUtil::unifyNewlines($row['languageItemValue'])); + } + } + else { + // use data provided by setOptions() + $value = $this->elementOptions[$elementID]['value']; + } + } $elementValues[$elementID] = $value; $elementValuesI18n[$elementID] = $i18nValues; @@ -432,17 +424,10 @@ class I18nHandler extends SingletonFactory { } /** - * Disables assignment of value variables in assignVariables(). - */ - public function disableAssignValueVariables() { - $this->assignValueVariablesDisabled = true; - } - - /** - * Enables assignment of value variables in assignVariables(). + * Resets internally stored data after creating a new object through a form. */ - public function enableAssignValueVariables() { - $this->assignValueVariablesDisabled = false; + public function reset() { + $this->i18nValues = $this->plainValues = array(); } /** -- 2.20.1