Use MIBEW_ENCODING constant

Replace $mibew_encoding global variable with MIBEW_ENCODING constant
This commit is contained in:
Dmitriy Simushev 2014-01-15 13:57:29 +00:00
parent 56c163f6a9
commit 70699aeecd
11 changed files with 36 additions and 56 deletions

View File

@ -491,13 +491,10 @@ function setup_chatview_for_user(Thread $thread) {
/** /**
* Prepare some data for chat for operator * Prepare some data for chat for operator
* *
* @global string $mibew_encoding Current Mibew encoding
* @param Thread $thread thread object * @param Thread $thread thread object
* @return array Array of chat view data * @return array Array of chat view data
*/ */
function setup_chatview_for_operator(Thread $thread, $operator) { function setup_chatview_for_operator(Thread $thread, $operator) {
global $mibew_encoding;
$data = setup_chatview($thread); $data = setup_chatview($thread);
// Load JavaScript plugins and JavaScripts, CSS files required by them // Load JavaScript plugins and JavaScripts, CSS files required by them
@ -564,7 +561,7 @@ function setup_chatview_for_operator(Thread $thread, $operator) {
: cutstring($answer['vcvalue'], 97, '...')) : cutstring($answer['vcvalue'], 97, '...'))
), ),
'full' => myiconv( 'full' => myiconv(
$mibew_encoding, MIBEW_ENCODING,
getoutputenc(), getoutputenc(),
$answer['vcvalue'] $answer['vcvalue']
) )
@ -599,13 +596,12 @@ function ban_for_addr($addr)
function visitor_from_request() function visitor_from_request()
{ {
global $mibew_encoding;
$defaultName = getstring("chat.default.username"); $defaultName = getstring("chat.default.username");
$userName = $defaultName; $userName = $defaultName;
if (isset($_COOKIE[USERNAME_COOKIE_NAME])) { if (isset($_COOKIE[USERNAME_COOKIE_NAME])) {
$data = base64_decode(strtr($_COOKIE[USERNAME_COOKIE_NAME], '-_,', '+/=')); $data = base64_decode(strtr($_COOKIE[USERNAME_COOKIE_NAME], '-_,', '+/='));
if (strlen($data) > 0) { if (strlen($data) > 0) {
$userName = myiconv("utf-8", $mibew_encoding, $data); $userName = myiconv("utf-8", MIBEW_ENCODING, $data);
} }
} }

View File

@ -364,8 +364,6 @@ class ThreadProcessor extends ClientSideProcessor {
* @throws \Mibew\RequestProcessor\ThreadProcessorException * @throws \Mibew\RequestProcessor\ThreadProcessorException
*/ */
protected function apiRename($args) { protected function apiRename($args) {
global $mibew_encoding;
// Check rename possibility // Check rename possibility
if( Settings::get('usercanchangename') != "1" ) { if( Settings::get('usercanchangename') != "1" ) {
throw new ThreadProcessorException( throw new ThreadProcessorException(
@ -383,7 +381,7 @@ class ThreadProcessor extends ClientSideProcessor {
//Rename user //Rename user
$thread->renameUser($args['name']); $thread->renameUser($args['name']);
// Update user name in cookies // Update user name in cookies
$data = strtr(base64_encode(myiconv($mibew_encoding,"utf-8",$args['name'])), '+/=', '-_,'); $data = strtr(base64_encode(myiconv(MIBEW_ENCODING,"utf-8",$args['name'])), '+/=', '-_,');
setcookie(USERNAME_COOKIE_NAME, $data, time()+60*60*24*365); setcookie(USERNAME_COOKIE_NAME, $data, time()+60*60*24*365);
} }

View File

@ -483,8 +483,6 @@ class UsersProcessor extends ClientSideProcessor {
/** /**
* Return updated operators list. API function * Return updated operators list. API function
* *
* @global string $mibew_encoding Encoding for the current locale
*
* @param array $args Associative array of arguments. It must contains * @param array $args Associative array of arguments. It must contains
* following keys: * following keys:
* - 'agentId': Id of the agent related to users window * - 'agentId': Id of the agent related to users window
@ -493,8 +491,6 @@ class UsersProcessor extends ClientSideProcessor {
* - 'operators': array of online operators * - 'operators': array of online operators
*/ */
protected function apiUpdateOperators($args) { protected function apiUpdateOperators($args) {
global $mibew_encoding;
// Check access and get operators info // Check access and get operators info
$operator = self::checkOperator($args['agentId']); $operator = self::checkOperator($args['agentId']);
@ -524,7 +520,7 @@ class UsersProcessor extends ClientSideProcessor {
'id' => (int)$item['operatorid'], 'id' => (int)$item['operatorid'],
// Convert name to UTF-8 // Convert name to UTF-8
'name' => myiconv( 'name' => myiconv(
$mibew_encoding, MIBEW_ENCODING,
"utf-8", "utf-8",
htmlspecialchars($item['vclocalename']) htmlspecialchars($item['vclocalename'])
), ),

View File

@ -730,7 +730,6 @@ Class Thread {
* Load messages from database corresponding to the thread those ID's more * Load messages from database corresponding to the thread those ID's more
* than $lastid * than $lastid
* *
* @global $mibew_encoding
* @param boolean $is_user Boolean TRUE if messages loads for user * @param boolean $is_user Boolean TRUE if messages loads for user
* and boolean FALSE if they loads for operator. * and boolean FALSE if they loads for operator.
* @param int $lastid ID of the last loaded message. * @param int $lastid ID of the last loaded message.
@ -747,8 +746,6 @@ Class Thread {
* @see Thread::postMessage() * @see Thread::postMessage()
*/ */
public function getMessages($is_user, &$last_id) { public function getMessages($is_user, &$last_id) {
global $mibew_encoding;
$db = Database::getInstance(); $db = Database::getInstance();
// Load messages // Load messages
@ -769,7 +766,7 @@ Class Thread {
foreach ($messages as $key => $msg) { foreach ($messages as $key => $msg) {
// Change sender name encoding // Change sender name encoding
$messages[$key]['name'] = myiconv( $messages[$key]['name'] = myiconv(
$mibew_encoding, MIBEW_ENCODING,
"utf-8", "utf-8",
$msg['name'] $msg['name']
); );
@ -785,7 +782,7 @@ Class Thread {
// Change message body encoding // Change message body encoding
$messages[$key]['message'] = myiconv( $messages[$key]['message'] = myiconv(
$mibew_encoding, MIBEW_ENCODING,
"utf-8", "utf-8",
$msg['message'] $msg['message']
); );

View File

@ -48,7 +48,11 @@ $default_cron_key = md5(
/** /**
* Name for cookie to track visitor * Name for cookie to track visitor
*/ */
define('VISITOR_COOKIE_NAME', 'MIBEW_VisitorID'); define('VISITOR_COOKIE_NAME', 'MIBEW_VisitorID');
/**
* Internal system encoding
*/
define('MIBEW_ENCODING', $mibew_encoding);
?> ?>

View File

@ -190,9 +190,6 @@ function load_messages($locale) {
/** /**
* Read and parse locale file. * Read and parse locale file.
* *
* @global string $mibew_encoding Internal Mibew encoding. Defined in
* libs/config.php.
*
* @param string $path Locale file path * @param string $path Locale file path
* @return array Associative array with following keys: * @return array Associative array with following keys:
* - 'encoding': string, one of service field from locale file, determines * - 'encoding': string, one of service field from locale file, determines
@ -210,10 +207,8 @@ function load_messages($locale) {
* value in libs/config.php). * value in libs/config.php).
*/ */
function read_locale_file($path) { function read_locale_file($path) {
global $mibew_encoding;
// Set default values // Set default values
$current_encoding = $mibew_encoding; $current_encoding = MIBEW_ENCODING;
$output_encoding = null; $output_encoding = null;
$messages = array(); $messages = array();
@ -234,12 +229,12 @@ function read_locale_file($path) {
$current_encoding = trim($value); $current_encoding = trim($value);
} else if ($key == 'output_encoding') { } else if ($key == 'output_encoding') {
$output_encoding = trim($value); $output_encoding = trim($value);
} else if ($current_encoding == $mibew_encoding) { } else if ($current_encoding == MIBEW_ENCODING) {
$messages[$key] = str_replace("\\n", "\n", trim($value)); $messages[$key] = str_replace("\\n", "\n", trim($value));
} else { } else {
$messages[$key] = myiconv( $messages[$key] = myiconv(
$current_encoding, $current_encoding,
$mibew_encoding, MIBEW_ENCODING,
str_replace("\\n", "\n", trim($value)) str_replace("\\n", "\n", trim($value))
); );
} }
@ -256,10 +251,10 @@ function read_locale_file($path) {
function getoutputenc() function getoutputenc()
{ {
global $current_locale, $output_encoding, $mibew_encoding, $messages; global $current_locale, $output_encoding, $messages;
if (!isset($messages[$current_locale])) if (!isset($messages[$current_locale]))
load_messages($current_locale); load_messages($current_locale);
return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : $mibew_encoding; return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : MIBEW_ENCODING;
} }
function getstring_($text, $locale) function getstring_($text, $locale)
@ -286,14 +281,13 @@ function getstring($text)
function getlocal($text) function getlocal($text)
{ {
global $current_locale, $mibew_encoding; global $current_locale;
return myiconv($mibew_encoding, getoutputenc(), getstring_($text, $current_locale)); return myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, $current_locale));
} }
function getlocal_($text, $locale) function getlocal_($text, $locale)
{ {
global $mibew_encoding; return myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, $locale));
return myiconv($mibew_encoding, getoutputenc(), getstring_($text, $locale));
} }
function getstring2_($text, $params, $locale) function getstring2_($text, $params, $locale)
@ -313,8 +307,8 @@ function getstring2($text, $params)
function getlocal2($text, $params) function getlocal2($text, $params)
{ {
global $current_locale, $mibew_encoding; global $current_locale;
$string = myiconv($mibew_encoding, getoutputenc(), getstring_($text, $current_locale)); $string = myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, $current_locale));
for ($i = 0; $i < count($params); $i++) { for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string); $string = str_replace("{" . $i . "}", $params[$i], $string);
} }
@ -324,8 +318,8 @@ function getlocal2($text, $params)
/* prepares for Javascript string */ /* prepares for Javascript string */
function getlocalforJS($text, $params) function getlocalforJS($text, $params)
{ {
global $current_locale, $mibew_encoding; global $current_locale;
$string = myiconv($mibew_encoding, getoutputenc(), getstring_($text, $current_locale)); $string = myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, $current_locale));
$string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string)); $string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
for ($i = 0; $i < count($params); $i++) { for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string); $string = str_replace("{" . $i . "}", $params[$i], $string);

View File

@ -24,9 +24,8 @@ require_once(MIBEW_FS_ROOT.'/libs/common/locale.php');
/* ajax server actions use utf-8 */ /* ajax server actions use utf-8 */
function getrawparam($name) function getrawparam($name)
{ {
global $mibew_encoding;
if (isset($_POST[$name])) { if (isset($_POST[$name])) {
$value = myiconv("utf-8", $mibew_encoding, $_POST[$name]); $value = myiconv("utf-8", MIBEW_ENCODING, $_POST[$name]);
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$value = stripslashes($value); $value = stripslashes($value);
} }
@ -38,9 +37,8 @@ function getrawparam($name)
/* form processors use current Output encoding */ /* form processors use current Output encoding */
function getparam($name) function getparam($name)
{ {
global $mibew_encoding;
if (isset($_POST[$name])) { if (isset($_POST[$name])) {
$value = myiconv(getoutputenc(), $mibew_encoding, $_POST[$name]); $value = myiconv(getoutputenc(), MIBEW_ENCODING, $_POST[$name]);
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$value = stripslashes($value); $value = stripslashes($value);
} }
@ -51,11 +49,10 @@ function getparam($name)
function getgetparam($name, $default = '') function getgetparam($name, $default = '')
{ {
global $mibew_encoding;
if (!isset($_GET[$name]) || !$_GET[$name]) { if (!isset($_GET[$name]) || !$_GET[$name]) {
return $default; return $default;
} }
$value = myiconv("utf-8", $mibew_encoding, unicode_urldecode($_GET[$name])); $value = myiconv("utf-8", MIBEW_ENCODING, unicode_urldecode($_GET[$name]));
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
$value = stripslashes($value); $value = stripslashes($value);
} }

View File

@ -65,8 +65,7 @@ function start_js_output(){
function topage($text) function topage($text)
{ {
global $mibew_encoding; return myiconv(MIBEW_ENCODING, getoutputenc(), $text);
return myiconv($mibew_encoding, getoutputenc(), $text);
} }
/** /**

View File

@ -17,20 +17,20 @@
function mibew_mail($toaddr, $reply_to, $subject, $body) function mibew_mail($toaddr, $reply_to, $subject, $body)
{ {
global $mibew_encoding, $mibew_mailbox, $mail_encoding, $current_locale; global $mibew_mailbox, $mail_encoding, $current_locale;
$headers = "From: $mibew_mailbox\r\n" $headers = "From: $mibew_mailbox\r\n"
. "Reply-To: " . myiconv($mibew_encoding, $mail_encoding, $reply_to) . "\r\n" . "Reply-To: " . myiconv(MIBEW_ENCODING, $mail_encoding, $reply_to) . "\r\n"
. "Content-Type: text/plain; charset=$mail_encoding\r\n" . "Content-Type: text/plain; charset=$mail_encoding\r\n"
. 'X-Mailer: PHP/' . phpversion(); . 'X-Mailer: PHP/' . phpversion();
$real_subject = "=?" . $mail_encoding . "?B?" . base64_encode(myiconv($mibew_encoding, $mail_encoding, $subject)) . "?="; $real_subject = "=?" . $mail_encoding . "?B?" . base64_encode(myiconv(MIBEW_ENCODING, $mail_encoding, $subject)) . "?=";
$body = preg_replace("/\n/", "\r\n", $body); $body = preg_replace("/\n/", "\r\n", $body);
$old_from = ini_get('sendmail_from'); $old_from = ini_get('sendmail_from');
@ini_set('sendmail_from', $mibew_mailbox); @ini_set('sendmail_from', $mibew_mailbox);
@mail($toaddr, $real_subject, wordwrap(myiconv($mibew_encoding, $mail_encoding, $body), 70), $headers); @mail($toaddr, $real_subject, wordwrap(myiconv(MIBEW_ENCODING, $mail_encoding, $body), 70), $headers);
if (isset($old_from)) { if (isset($old_from)) {
@ini_set('sendmail_from', $old_from); @ini_set('sendmail_from', $old_from);
} }

View File

@ -34,7 +34,7 @@ force_password($operator);
setlocale(LC_TIME, getstring("time.locale")); setlocale(LC_TIME, getstring("time.locale"));
$page = array(); $page = array();
$query = isset($_GET['q']) ? myiconv(getoutputenc(), $mibew_encoding, $_GET['q']) : false; $query = isset($_GET['q']) ? myiconv(getoutputenc(), MIBEW_ENCODING, $_GET['q']) : false;
$searchType = verifyparam('type', '/^(all|message|operator|visitor)$/', 'all'); $searchType = verifyparam('type', '/^(all|message|operator|visitor)$/', 'all');
$searchInSystemMessages = (verifyparam('insystemmessages', '/^on$/', 'off') == 'on') || !$query; $searchInSystemMessages = (verifyparam('insystemmessages', '/^on$/', 'off') == 'on') || !$query;

View File

@ -57,10 +57,9 @@ function load_idlist($name)
function save_message($locale, $key, $value) function save_message($locale, $key, $value)
{ {
global $mibew_encoding;
$result = ""; $result = "";
$added = false; $added = false;
$current_encoding = $mibew_encoding; $current_encoding = MIBEW_ENCODING;
$fp = fopen(MIBEW_FS_ROOT."/locales/$locale/properties", "r"); $fp = fopen(MIBEW_FS_ROOT."/locales/$locale/properties", "r");
if ($fp === FALSE) { if ($fp === FALSE) {
die("unable to open properties for locale $locale"); die("unable to open properties for locale $locale");
@ -72,7 +71,7 @@ function save_message($locale, $key, $value)
if ($keyval[0] == 'encoding') { if ($keyval[0] == 'encoding') {
$current_encoding = trim($keyval[1]); $current_encoding = trim($keyval[1]);
} else if (!$added && $keyval[0] == $key) { } else if (!$added && $keyval[0] == $key) {
$line = "$key=" . myiconv($mibew_encoding, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n"; $line = "$key=" . myiconv(MIBEW_ENCODING, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n";
$added = true; $added = true;
} }
} }
@ -80,7 +79,7 @@ function save_message($locale, $key, $value)
} }
fclose($fp); fclose($fp);
if (!$added) { if (!$added) {
$result .= "$key=" . myiconv($mibew_encoding, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n"; $result .= "$key=" . myiconv(MIBEW_ENCODING, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n";
} }
$fp = @fopen(MIBEW_FS_ROOT."/locales/$locale/properties", "w"); $fp = @fopen(MIBEW_FS_ROOT."/locales/$locale/properties", "w");
if ($fp !== FALSE) { if ($fp !== FALSE) {
@ -100,7 +99,7 @@ function save_message($locale, $key, $value)
$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr; $remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
fwrite($fp, "# " . date(DATE_RFC822) . " by $remoteHost using $userbrowser\n"); fwrite($fp, "# " . date(DATE_RFC822) . " by $remoteHost using $userbrowser\n");
fwrite($fp, "$key=" . myiconv($mibew_encoding, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n"); fwrite($fp, "$key=" . myiconv(MIBEW_ENCODING, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n");
fclose($fp); fclose($fp);
} }
} }