From 7b5caf0e8dc544bbe8d62b4189fef6784304a65f Mon Sep 17 00:00:00 2001 From: "Fedor A. Fetisov" Date: Tue, 29 Oct 2013 01:04:43 +0400 Subject: [PATCH] Define constants for all cookies' names --- src/mibew/libs/chat.php | 21 +++++++++++++-------- src/mibew/libs/classes/thread_processor.php | 8 +++----- src/mibew/libs/common/constants.php | 3 ++- src/mibew/libs/common/locale.php | 15 +++++++++------ src/mibew/libs/getcode.php | 3 +-- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/mibew/libs/chat.php b/src/mibew/libs/chat.php index efaee20a..6ab12c5f 100644 --- a/src/mibew/libs/chat.php +++ b/src/mibew/libs/chat.php @@ -25,8 +25,13 @@ require_once(dirname(__FILE__).'/classes/request_processor.php'); require_once(dirname(__FILE__).'/classes/client_side_processor.php'); require_once(dirname(__FILE__).'/classes/thread_processor.php'); -$namecookie = "MIBEW_Data"; -$usercookie = "MIBEW_UserID"; + +/** + * Names for chat-related cookies + */ + +define('USERID_COOKIE_NAME', 'MIBEW_UserID'); +define('USERNAME_COOKIE_NAME', 'MIBEW_Data'); function message_to_text($msg) { @@ -582,11 +587,11 @@ function ban_for_addr($addr) function visitor_from_request() { - global $namecookie, $mibew_encoding, $usercookie; + global $mibew_encoding; $defaultName = getstring("chat.default.username"); $userName = $defaultName; - if (isset($_COOKIE[$namecookie])) { - $data = base64_decode(strtr($_COOKIE[$namecookie], '-_,', '+/=')); + if (isset($_COOKIE[USERNAME_COOKIE_NAME])) { + $data = base64_decode(strtr($_COOKIE[USERNAME_COOKIE_NAME], '-_,', '+/=')); if (strlen($data) > 0) { $userName = myiconv("utf-8", $mibew_encoding, $data); } @@ -596,11 +601,11 @@ function visitor_from_request() $userName = getgetparam('name', $userName); } - if (isset($_COOKIE[$usercookie])) { - $userId = $_COOKIE[$usercookie]; + if (isset($_COOKIE[USERID_COOKIE_NAME])) { + $userId = $_COOKIE[USERID_COOKIE_NAME]; } else { $userId = uniqid('', TRUE); - setcookie($usercookie, $userId, time() + 60 * 60 * 24 * 365); + setcookie(USERID_COOKIE_NAME, $userId, time() + 60 * 60 * 24 * 365); } return array('id' => $userId, 'name' => $userName); } diff --git a/src/mibew/libs/classes/thread_processor.php b/src/mibew/libs/classes/thread_processor.php index 0490a6e2..7783160e 100644 --- a/src/mibew/libs/classes/thread_processor.php +++ b/src/mibew/libs/classes/thread_processor.php @@ -355,7 +355,7 @@ class ThreadProcessor extends ClientSideProcessor { * @throws ThreadProcessorException */ protected function apiRename($args) { - global $namecookie, $mibew_encoding; + global $mibew_encoding; // Check rename possibility if( Settings::get('usercanchangename') != "1" ) { @@ -375,7 +375,7 @@ class ThreadProcessor extends ClientSideProcessor { $thread->renameUser($args['name']); // Update user name in cookies $data = strtr(base64_encode(myiconv($mibew_encoding,"utf-8",$args['name'])), '+/=', '-_,'); - setcookie($namecookie, $data, time()+60*60*24*365); + setcookie(USERNAME_COOKIE_NAME, $data, time()+60*60*24*365); } /** @@ -413,7 +413,6 @@ class ThreadProcessor extends ClientSideProcessor { /** * Process submitted prechat survey. * - * @global string $namecookie Name of cookie that store visitor name * @param array $args Associative array of arguments. It must contains * following keys: * - 'threadId': for this function this param equals to null; @@ -429,7 +428,6 @@ class ThreadProcessor extends ClientSideProcessor { * - 'options': options array for next module. */ protected function apiProcessSurvey($args) { - global $namecookie; $visitor = visitor_from_request(); @@ -459,7 +457,7 @@ class ThreadProcessor extends ClientSideProcessor { '+/=', '-_,' ); - setcookie($namecookie, $data, time()+60*60*24*365); + setcookie(USERNAME_COOKIE_NAME, $data, time()+60*60*24*365); $visitor['name'] = $newname; } } diff --git a/src/mibew/libs/common/constants.php b/src/mibew/libs/common/constants.php index 5eb6b2e1..df2b496c 100644 --- a/src/mibew/libs/common/constants.php +++ b/src/mibew/libs/common/constants.php @@ -48,6 +48,7 @@ $default_cron_key = md5( /** * Name for cookie to track visitor */ -$visitorcookie = "MIBEW_VisitorID"; + +define('VISITOR_COOKIE_NAME', 'MIBEW_VisitorID'); ?> \ No newline at end of file diff --git a/src/mibew/libs/common/locale.php b/src/mibew/libs/common/locale.php index ea94fc83..5e67eb4d 100644 --- a/src/mibew/libs/common/locale.php +++ b/src/mibew/libs/common/locale.php @@ -18,7 +18,10 @@ require_once(dirname(__FILE__).'/converter.php'); require_once(dirname(__FILE__).'/verification.php'); -$locale_cookie_name = 'mibew_locale'; +/** + * Name for the cookie to store locale code in use + */ +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'; @@ -73,10 +76,10 @@ function get_available_locales() function get_user_locale() { - global $default_locale, $locale_cookie_name; + global $default_locale; - if (isset($_COOKIE['mibew_locale'])) { - $requested_lang = $_COOKIE['mibew_locale']; + if (isset($_COOKIE[LOCALE_COOKIE_NAME])) { + $requested_lang = $_COOKIE[LOCALE_COOKIE_NAME]; if (locale_pattern_check($requested_lang) && locale_exists($requested_lang)) return $requested_lang; } @@ -100,7 +103,7 @@ function get_user_locale() function get_locale() { - global $mibewroot, $locale_cookie_name; + global $mibewroot; $locale = verifyparam("locale", "/./", ""); @@ -114,7 +117,7 @@ function get_locale() $locale = get_user_locale(); } - setcookie($locale_cookie_name, $locale, time() + 60 * 60 * 24 * 1000, "$mibewroot/"); + setcookie(LOCALE_COOKIE_NAME, $locale, time() + 60 * 60 * 24 * 1000, "$mibewroot/"); return $locale; } diff --git a/src/mibew/libs/getcode.php b/src/mibew/libs/getcode.php index 2eb496e3..422e428c 100644 --- a/src/mibew/libs/getcode.php +++ b/src/mibew/libs/getcode.php @@ -17,7 +17,6 @@ function generate_button($title, $locale, $style, $invitationstyle, $group, $inner, $showhost, $forcesecure, $modsecurity, $operator_code) { - global $visitorcookie; $app_location = get_app_location($showhost, $forcesecure); $link = $app_location . "/client.php"; if ($locale) @@ -67,7 +66,7 @@ function generate_button($title, $locale, $style, $invitationstyle, $group, $inn $widget_data['locale'] = $locale; // Name of the cookie to track user. Use if third-party cookie blocked - $widget_data['visitorCookieName'] = $visitorcookie; + $widget_data['visitorCookieName'] = VISITOR_COOKIE_NAME; // Build additional button code $temp = preg_replace('/^(