From 56c163f6a9b4b705675754dca46beb750259f085 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 15 Jan 2014 13:35:28 +0000 Subject: [PATCH] Remove $default_locale and $home_locale globals --- .../RequestProcessor/ThreadProcessor.php | 5 ++--- src/mibew/libs/classes/Mibew/Settings.php | 5 ++--- src/mibew/libs/classes/Mibew/Thread.php | 10 ++------- src/mibew/libs/common/locale.php | 22 +++++++++++++------ src/mibew/libs/groups.php | 9 ++++---- src/mibew/libs/operator.php | 5 ++--- src/mibew/operator/translate.php | 2 +- src/mibew/widget.php | 2 +- 8 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php b/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php index deb4b787..7fc3d947 100644 --- a/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php +++ b/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php @@ -532,7 +532,6 @@ class ThreadProcessor extends ClientSideProcessor { * Process submitted leave message form. * * Send message to operator email and create special meil thread. - * @global string $home_locale Code of the home locale * @global string $current_locale Code of the current locale * @param array $args Associative array of arguments. It must contains * following keys: @@ -550,7 +549,7 @@ class ThreadProcessor extends ClientSideProcessor { * exception if captcha or email is wrong. */ protected function apiProcessLeaveMessage($args) { - global $home_locale, $current_locale; + global $current_locale; // Check captcha if(Settings::get('enablecaptcha') == '1' && can_show_captcha()) { @@ -600,7 +599,7 @@ class ThreadProcessor extends ClientSideProcessor { // Get message locale $message_locale = Settings::get('left_messages_locale'); if(!locale_exists($message_locale)) { - $message_locale = $home_locale; + $message_locale = HOME_LOCALE; } // Create thread diff --git a/src/mibew/libs/classes/Mibew/Settings.php b/src/mibew/libs/classes/Mibew/Settings.php index 517683a0..1bc712e2 100644 --- a/src/mibew/libs/classes/Mibew/Settings.php +++ b/src/mibew/libs/classes/Mibew/Settings.php @@ -53,12 +53,11 @@ Class Settings { /** * Settings class constructor. Set default values and load setting from database. - * @global $home_locale Specifies home locale. Defined in libs/config.php * @global $default_cron_key Default value for cron security key. Defined * in libs/common/constants.php */ protected function __construct() { - global $home_locale, $default_cron_key; + global $default_cron_key; // Set default values $this->settings = array( 'dbversion' => 0, @@ -78,7 +77,7 @@ Class Settings { 'thread_lifetime' => 600, 'email' => '', /* inbox for left messages */ - 'left_messages_locale' => $home_locale, + 'left_messages_locale' => HOME_LOCALE, 'sendmessagekey' => 'center', 'enableban' => '0', diff --git a/src/mibew/libs/classes/Mibew/Thread.php b/src/mibew/libs/classes/Mibew/Thread.php index 48455329..aeb5d59e 100644 --- a/src/mibew/libs/classes/Mibew/Thread.php +++ b/src/mibew/libs/classes/Mibew/Thread.php @@ -692,13 +692,10 @@ Class Thread { * Check if thread is reassigned for another operator * * Updates thread info, send events messages and avatar message to user - * @global string $home_locale * @param array $operator Operator for test */ public function checkForReassign($operator) { - global $home_locale; - - $operator_name = ($this->locale == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname']; + $operator_name = ($this->locale == HOME_LOCALE) ? $operator['vclocalename'] : $operator['vccommonname']; if ($this->state == self::STATE_WAITING && ($this->nextAgent == $operator['operatorid'] || $this->agentId == $operator['operatorid'])) { @@ -982,16 +979,13 @@ Class Thread { /** * Assign operator to thread * - * @global string $home_locale * @param array $operator Operator who try to take thread * @return boolean Boolean TRUE on success or FALSE on failure */ public function take($operator) { - global $home_locale; - $take_thread = false; $message = ''; - $operator_name = ($this->locale == $home_locale) ? $operator['vclocalename'] : $operator['vccommonname']; + $operator_name = ($this->locale == HOME_LOCALE) ? $operator['vclocalename'] : $operator['vccommonname']; if ($this->state == self::STATE_QUEUE || $this->state == self::STATE_WAITING || $this->state == self::STATE_LOADING) { // User waiting diff --git a/src/mibew/libs/common/locale.php b/src/mibew/libs/common/locale.php index df4bc70f..a39f1137 100644 --- a/src/mibew/libs/common/locale.php +++ b/src/mibew/libs/common/locale.php @@ -27,9 +27,19 @@ require_once(MIBEW_FS_ROOT.'/libs/common/verification.php'); */ define('LOCALE_COOKIE_NAME', 'mibew_locale'); -// test and set default locales -$default_locale = locale_pattern_check($default_locale) && locale_exists($default_locale) ? $default_locale : 'en'; -$home_locale = locale_pattern_check($home_locale) && locale_exists($home_locale) ? $default_locale : 'en'; +// Test and set default locales + +/** + * Verified value of the $default_locale configuration parameter (see + * "libs/default_config.php" for details) + */ +define('DEFAULT_LOCALE', locale_pattern_check($default_locale) && locale_exists($default_locale) ? $default_locale : 'en'); + +/** + * Verified value of the $home_locale configuration parameter (see + * "libs/default_config.php" for details) + */ +define('HOME_LOCALE', locale_pattern_check($home_locale) && locale_exists($home_locale) ? $home_locale : 'en'); function myiconv($in_enc, $out_enc, $string) { @@ -80,8 +90,6 @@ function get_available_locales() function get_user_locale() { - global $default_locale; - if (isset($_COOKIE[LOCALE_COOKIE_NAME])) { $requested_lang = $_COOKIE[LOCALE_COOKIE_NAME]; if (locale_pattern_check($requested_lang) && locale_exists($requested_lang)) @@ -99,8 +107,8 @@ function get_user_locale() } } - if (locale_pattern_check($default_locale) && locale_exists($default_locale)) - return $default_locale; + if (locale_pattern_check(DEFAULT_LOCALE) && locale_exists(DEFAULT_LOCALE)) + return DEFAULT_LOCALE; return 'en'; } diff --git a/src/mibew/libs/groups.php b/src/mibew/libs/groups.php index 04829ed0..e72d3b43 100644 --- a/src/mibew/libs/groups.php +++ b/src/mibew/libs/groups.php @@ -32,8 +32,8 @@ function group_by_id($id) function get_group_name($group) { - global $home_locale, $current_locale; - if ($home_locale == $current_locale || !isset($group['vccommonname']) || !$group['vccommonname']) + global $current_locale; + if (HOME_LOCALE == $current_locale || !isset($group['vccommonname']) || !$group['vccommonname']) return $group['vclocalname']; else return $group['vccommonname']; @@ -146,7 +146,6 @@ function group_is_online($group) { /** * Return local or common group description depending on current locale. * - * @global string $home_locale Code of the home locale * @global string $current_locale Code of the current locale * @param array $group Associative group array. Should contain following keys: * - 'vccommondescription': string, contain common description of the group; @@ -154,8 +153,8 @@ function group_is_online($group) { * @return string Group description */ function get_group_description($group) { - global $home_locale, $current_locale; - if ($home_locale == $current_locale + global $current_locale; + if (HOME_LOCALE == $current_locale || !isset($group['vccommondescription']) || !$group['vccommondescription']) { return $group['vclocaldescription']; diff --git a/src/mibew/libs/operator.php b/src/mibew/libs/operator.php index 8a11d620..c5e6d6d2 100644 --- a/src/mibew/libs/operator.php +++ b/src/mibew/libs/operator.php @@ -454,15 +454,14 @@ function is_operator_online($operatorid) /** * Returns name of the operator. Choose between vclocalname and vccommonname * - * @global string $home_locale Code of the operator's home locale * @global string $current_locale Code of the current locale * @param array $operator Operator's array * @return string Operator's name */ function get_operator_name($operator) { - global $home_locale, $current_locale; - if ($home_locale == $current_locale) + global $current_locale; + if (HOME_LOCALE == $current_locale) return $operator['vclocalename']; else return $operator['vccommonname']; diff --git a/src/mibew/operator/translate.php b/src/mibew/operator/translate.php index 58fafa09..321065a9 100644 --- a/src/mibew/operator/translate.php +++ b/src/mibew/operator/translate.php @@ -125,7 +125,7 @@ $operator = check_login(); force_password($operator); csrfchecktoken(); -$source = verifyparam("source", "/^[\w-]{2,5}$/", $default_locale); +$source = verifyparam("source", "/^[\w-]{2,5}$/", DEFAULT_LOCALE); $target = verifyparam("target", "/^[\w-]{2,5}$/", $current_locale); $stringid = verifyparam("key", "/^[_\.\w]+$/", ""); diff --git a/src/mibew/widget.php b/src/mibew/widget.php index 0aefef22..681748a0 100644 --- a/src/mibew/widget.php +++ b/src/mibew/widget.php @@ -89,7 +89,7 @@ if (Settings::get('enabletracking') == '1') { // Get operator info $operator = operator_by_id($thread->agentId); $locale = isset($_GET['locale']) ? $_GET['locale'] : ''; - $operator_name = ($locale == $home_locale) + $operator_name = ($locale == HOME_LOCALE) ? $operator['vclocalename'] : $operator['vccommonname'];