Use only UTF-8 encoding

This commit is contained in:
Dmitriy Simushev 2014-05-14 12:16:04 +00:00
parent a93517dcf1
commit 7042f3dd9e
36 changed files with 164 additions and 360 deletions

View File

@ -304,7 +304,7 @@ function show_install_err($text)
function create_table($id, $link)
{
global $dbtables, $dbtables_indexes, $memtables, $dbencoding, $mysqlprefix;
global $dbtables, $dbtables_indexes, $memtables, $mysqlprefix;
if (!isset($dbtables[$id])) {
show_install_err("Unknown table: $id, " . mysql_error($link));
@ -324,7 +324,7 @@ function create_table($id, $link)
}
$query = preg_replace("/,\n$/", "", $query);
$query .= ") charset $dbencoding";
$query .= ") charset utf8";
if (in_array($id, $memtables)) {
$query .= " ENGINE=MEMORY";
} else {

View File

@ -37,7 +37,6 @@ define('MIBEW_WEB_ROOT', $mibewroot);
// Include common functions
require_once(MIBEW_FS_ROOT.'/libs/common/constants.php');
require_once(MIBEW_FS_ROOT.'/libs/common/verification.php');
require_once(MIBEW_FS_ROOT.'/libs/common/converter.php');
require_once(MIBEW_FS_ROOT.'/libs/common/locale.php');
require_once(MIBEW_FS_ROOT.'/libs/common/misc.php');
require_once(MIBEW_FS_ROOT.'/libs/common/response.php');
@ -65,7 +64,7 @@ if ($act == "silentcreateall") {
} else {
mysql_select_db($mysqldb, $link) or show_install_err('Could not select database');
if ($force_charset_in_connection) {
mysql_query("SET character set $dbencoding", $link);
mysql_query("SET character set utf8", $link);
}
if ($act == "ct") {

View File

@ -52,7 +52,6 @@ define('MIBEW_WEB_ROOT', $base_url);
// Include common functions
require_once(MIBEW_FS_ROOT.'/libs/common/constants.php');
require_once(MIBEW_FS_ROOT.'/libs/common/verification.php');
require_once(MIBEW_FS_ROOT.'/libs/common/converter.php');
require_once(MIBEW_FS_ROOT.'/libs/common/locale.php');
require_once(MIBEW_FS_ROOT.'/libs/common/misc.php');
require_once(MIBEW_FS_ROOT.'/libs/common/response.php');
@ -199,11 +198,11 @@ function check_connection()
function check_database($link)
{
global $mysqldb, $force_charset_in_connection, $dbencoding, $page;
global $mysqldb, $force_charset_in_connection, $page;
if (mysql_select_db($mysqldb, $link)) {
$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
if ($force_charset_in_connection) {
mysql_query("SET character set $dbencoding", $link);
mysql_query("SET character set utf8", $link);
}
return true;
} else {

View File

@ -221,10 +221,10 @@ function setup_logo($group = null)
: $top_level_group['vchosturl'];
$data['company'] = array(
'name' => to_page($group_name),
'chatLogoURL' => to_page($logo),
'name' => $group_name,
'chatLogoURL' => $logo,
);
$data['mibewHost'] = to_page($mibew_host);
$data['mibewHost'] = $mibew_host;
return $data;
}
@ -285,12 +285,12 @@ function setup_leavemessage($name, $email, $group_id, $info, $referrer)
}
$data['leaveMessage']['leaveMessageForm'] = array(
'name' => to_page($name),
'email' => to_page($email),
'name' => $name,
'email' => $email,
'groupId' => $group_id,
'groupName' => $group_name,
'info' => to_page($info),
'referrer' => to_page($referrer),
'info' => $info,
'referrer' => $referrer,
'showCaptcha' => (bool) (Settings::get("enablecaptcha") == "1" && can_show_captcha()),
);
@ -331,11 +331,11 @@ function setup_survey($name, $email, $group_id, $info, $referrer)
$data['survey'] = array();
$data['survey']['surveyForm'] = array(
'name' => to_page($name),
'name' => $name,
'groupId' => $group_id,
'email' => to_page($email),
'info' => to_page($info),
'referrer' => to_page($referrer),
'email' => $email,
'info' => $info,
'referrer' => $referrer,
'showEmail' => (bool) (Settings::get("surveyaskmail") == "1"),
'showMessage' => (bool) (Settings::get("surveyaskmessage") == "1"),
'canChangeName' => (bool) (Settings::get('usercanchangename') == "1"),
@ -463,9 +463,9 @@ function setup_chatview(Thread $thread)
'token' => $thread->lastToken
);
$data['page.title'] = to_page(
empty($group['vcchattitle']) ? Settings::get('chattitle') : $group['vcchattitle']
);
$data['page.title'] = empty($group['vcchattitle'])
? Settings::get('chattitle')
: $group['vcchattitle'];
$data['chat']['page'] = array(
'title' => $data['page.title']
);
@ -516,7 +516,7 @@ function setup_chatview_for_user(Thread $thread)
// Set user info
$data['chat']['user'] = array(
'name' => htmlspecialchars(to_page($thread->userName)),
'name' => htmlspecialchars($thread->userName),
'canChangeName' => (bool) (Settings::get('usercanchangename') == "1"),
'defaultName' => (bool) (getstring("chat.default.username") != $thread->userName),
'canPost' => true,
@ -556,13 +556,11 @@ function setup_chatview_for_operator(Thread $thread, $operator)
// Set operator info
$data['chat']['user'] = array(
'name' => htmlspecialchars(
to_page(
get_user_name(
$thread->userName,
$thread->remote,
$thread->userId
)
)
),
'canPost' => (bool) ($thread->agentId == $operator['operatorid']),
'isAgent' => true,
@ -607,13 +605,9 @@ function setup_chatview_for_operator(Thread $thread, $operator)
foreach ($canned_messages as $answer) {
$predefined_answers[] = array(
'short' => htmlspecialchars(
to_page($answer['vctitle'] ? $answer['vctitle'] : cut_string($answer['vcvalue'], 97, '...'))
$answer['vctitle'] ? $answer['vctitle'] : cut_string($answer['vcvalue'], 97, '...')
),
'full' => myiconv(
MIBEW_ENCODING,
getoutputenc(),
$answer['vcvalue']
)
'full' => $answer['vcvalue'],
);
}
$data['chat']['messageForm']['predefinedAnswers'] = $predefined_answers;
@ -661,7 +655,7 @@ function visitor_from_request()
if (isset($_COOKIE[USERNAME_COOKIE_NAME])) {
$data = base64_decode(strtr($_COOKIE[USERNAME_COOKIE_NAME], '-_,', '+/='));
if (strlen($data) > 0) {
$user_name = myiconv("utf-8", MIBEW_ENCODING, $data);
$user_name = $data;
}
}

View File

@ -38,9 +38,7 @@ class HistoryController extends AbstractController
$page = array();
$operator = $request->attributes->get('_operator');
$query = $request->query->has('q')
? myiconv(getoutputenc(), MIBEW_ENCODING, $request->query->get('q'))
: false;
$query = $request->query->get('q', false);
$search_type = $request->query->get('type');
if (!in_array($search_type, array('all', 'message', 'operator', 'visitor'))) {
@ -135,12 +133,12 @@ class HistoryController extends AbstractController
$page['pagination.items'][] = array(
'threadId' => $thread->id,
'userName' => to_page($thread->userName),
'userAddress' => get_user_addr(to_page($thread->remote)),
'agentName' => to_page($thread->agentName),
'messageCount' => to_page($thread->messageCount),
'userName' => $thread->userName,
'userAddress' => get_user_addr($thread->remote),
'agentName' => $thread->agentName,
'messageCount' => $thread->messageCount,
'groupName' => ($group_name_set
? to_page($group_name[$thread->groupId])
? $group_name[$thread->groupId]
: false),
'chatTime' => $thread->modified - $thread->created,
'chatCreated' => $thread->created,
@ -151,7 +149,7 @@ class HistoryController extends AbstractController
$page['pagination.items'] = false;
}
$page['formq'] = to_page($query);
$page['formq'] = $query;
} else {
$page['pagination'] = false;
$page['pagination.items'] = false;
@ -187,13 +185,13 @@ class HistoryController extends AbstractController
$group = group_by_id($thread->groupId);
$thread_info = array(
'userName' => to_page($thread->userName),
'userAddress' => get_user_addr(to_page($thread->remote)),
'userAgentVersion' => get_user_agent_version(to_page($thread->userAgent)),
'agentName' => to_page($thread->agentName),
'userName' => $thread->userName,
'userAddress' => get_user_addr($thread->remote),
'userAgentVersion' => get_user_agent_version($thread->userAgent),
'agentName' => $thread->agentName,
'chatTime' => ($thread->modified - $thread->created),
'chatStarted' => $thread->created,
'groupName' => to_page(get_group_name($group)),
'groupName' => get_group_name($group),
);
$page['threadInfo'] = $thread_info;
@ -256,10 +254,10 @@ class HistoryController extends AbstractController
foreach ($page['pagination.items'] as $key => $item) {
$thread = Thread::createFromDbInfo($item);
$page['pagination.items'][$key] = array(
'threadId' => to_page($thread->id),
'userName' => to_page($thread->userName),
'userAddress' => get_user_addr(to_page($thread->remote)),
'agentName' => to_page($thread->agentName),
'threadId' => $thread->id,
'userName' => $thread->userName,
'userAddress' => get_user_addr($thread->remote),
'agentName' => $thread->agentName,
'chatTime' => ($thread->modified - $thread->created),
'chatCreated' => $thread->created,
);

View File

@ -384,7 +384,7 @@ class ThreadProcessor extends ClientSideProcessor
//Rename user
$thread->renameUser($args['name']);
// Update user name in cookies
$data = strtr(base64_encode(myiconv(MIBEW_ENCODING, "utf-8", $args['name'])), '+/=', '-_,');
$data = strtr(base64_encode($args['name']), '+/=', '-_,');
setcookie(USERNAME_COOKIE_NAME, $data, time() + 60 * 60 * 24 * 365);
}
@ -464,11 +464,7 @@ class ThreadProcessor extends ClientSideProcessor
if (Settings::get('usercanchangename') == "1" && !empty($args['name'])) {
$newname = $args['name'];
if ($newname != $visitor['name']) {
$data = strtr(
base64_encode(myiconv(MIBEW_ENCODING, "utf-8", $newname)),
'+/=',
'-_,'
);
$data = strtr(base64_encode($newname), '+/=', '-_,');
setcookie(USERNAME_COOKIE_NAME, $data, time() + 60 * 60 * 24 * 365);
$visitor['name'] = $newname;
}

View File

@ -521,12 +521,7 @@ class UsersProcessor extends ClientSideProcessor
$result_list[] = array(
'id' => (int) $item['operatorid'],
// Convert name to UTF-8
'name' => myiconv(
MIBEW_ENCODING,
"utf-8",
htmlspecialchars($item['vclocalename'])
),
'name' => htmlspecialchars($item['vclocalename']),
'away' => (bool) operator_is_away($item)
);
}

View File

@ -778,13 +778,6 @@ class Thread
);
foreach ($messages as $key => $msg) {
// Change sender name encoding
$messages[$key]['name'] = myiconv(
MIBEW_ENCODING,
"utf-8",
$msg['name']
);
// Process data attached to the message
if (!empty($messages[$key]['data'])) {
$messages[$key]['data'] = unserialize(
@ -794,13 +787,6 @@ class Thread
$messages[$key]['data'] = array();
}
// Change message body encoding
$messages[$key]['message'] = myiconv(
MIBEW_ENCODING,
"utf-8",
$msg['message']
);
// Get last message ID
if ($msg['id'] > $last_id) {
$last_id = $msg['id'];

View File

@ -50,11 +50,6 @@ define('DEFAULT_CRON_KEY', md5(
*/
define('VISITOR_COOKIE_NAME', 'MIBEW_VisitorID');
/**
* Internal system encoding
*/
define('MIBEW_ENCODING', $mibew_encoding);
/**
* Names for chat-related cookies
*/

View File

@ -1,49 +0,0 @@
<?php
/*
* Copyright 2005-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
$_utf8win1251 = array(
"\xD0\x90" => "\xC0", "\xD0\x91" => "\xC1", "\xD0\x92" => "\xC2", "\xD0\x93" => "\xC3", "\xD0\x94" => "\xC4",
"\xD0\x95" => "\xC5", "\xD0\x81" => "\xA8", "\xD0\x96" => "\xC6", "\xD0\x97" => "\xC7", "\xD0\x98" => "\xC8",
"\xD0\x99" => "\xC9", "\xD0\x9A" => "\xCA", "\xD0\x9B" => "\xCB", "\xD0\x9C" => "\xCC", "\xD0\x9D" => "\xCD",
"\xD0\x9E" => "\xCE", "\xD0\x9F" => "\xCF", "\xD0\xA0" => "\xD0", "\xD0\xA1" => "\xD1", "\xD0\xA2" => "\xD2",
"\xD0\xA3" => "\xD3", "\xD0\xA4" => "\xD4", "\xD0\xA5" => "\xD5", "\xD0\xA6" => "\xD6", "\xD0\xA7" => "\xD7",
"\xD0\xA8" => "\xD8", "\xD0\xA9" => "\xD9", "\xD0\xAA" => "\xDA", "\xD0\xAB" => "\xDB", "\xD0\xAC" => "\xDC",
"\xD0\xAD" => "\xDD", "\xD0\xAE" => "\xDE", "\xD0\xAF" => "\xDF", "\xD0\x87" => "\xAF", "\xD0\x86" => "\xB2",
"\xD0\x84" => "\xAA", "\xD0\x8E" => "\xA1", "\xD0\xB0" => "\xE0", "\xD0\xB1" => "\xE1", "\xD0\xB2" => "\xE2",
"\xD0\xB3" => "\xE3", "\xD0\xB4" => "\xE4", "\xD0\xB5" => "\xE5", "\xD1\x91" => "\xB8", "\xD0\xB6" => "\xE6",
"\xD0\xB7" => "\xE7", "\xD0\xB8" => "\xE8", "\xD0\xB9" => "\xE9", "\xD0\xBA" => "\xEA", "\xD0\xBB" => "\xEB",
"\xD0\xBC" => "\xEC", "\xD0\xBD" => "\xED", "\xD0\xBE" => "\xEE", "\xD0\xBF" => "\xEF", "\xD1\x80" => "\xF0",
"\xD1\x81" => "\xF1", "\xD1\x82" => "\xF2", "\xD1\x83" => "\xF3", "\xD1\x84" => "\xF4", "\xD1\x85" => "\xF5",
"\xD1\x86" => "\xF6", "\xD1\x87" => "\xF7", "\xD1\x88" => "\xF8", "\xD1\x89" => "\xF9", "\xD1\x8A" => "\xFA",
"\xD1\x8B" => "\xFB", "\xD1\x8C" => "\xFC", "\xD1\x8D" => "\xFD", "\xD1\x8E" => "\xFE", "\xD1\x8F" => "\xFF",
"\xD1\x96" => "\xB3", "\xD1\x97" => "\xBF", "\xD1\x94" => "\xBA", "\xD1\x9E" => "\xA2");
$_win1251utf8 = array(
"\xC0" => "\xD0\x90", "\xC1" => "\xD0\x91", "\xC2" => "\xD0\x92", "\xC3" => "\xD0\x93", "\xC4" => "\xD0\x94",
"\xC5" => "\xD0\x95", "\xA8" => "\xD0\x81", "\xC6" => "\xD0\x96", "\xC7" => "\xD0\x97", "\xC8" => "\xD0\x98",
"\xC9" => "\xD0\x99", "\xCA" => "\xD0\x9A", "\xCB" => "\xD0\x9B", "\xCC" => "\xD0\x9C", "\xCD" => "\xD0\x9D",
"\xCE" => "\xD0\x9E", "\xCF" => "\xD0\x9F", "\xD0" => "\xD0\xA0", "\xD1" => "\xD0\xA1", "\xD2" => "\xD0\xA2",
"\xD3" => "\xD0\xA3", "\xD4" => "\xD0\xA4", "\xD5" => "\xD0\xA5", "\xD6" => "\xD0\xA6", "\xD7" => "\xD0\xA7",
"\xD8" => "\xD0\xA8", "\xD9" => "\xD0\xA9", "\xDA" => "\xD0\xAA", "\xDB" => "\xD0\xAB", "\xDC" => "\xD0\xAC",
"\xDD" => "\xD0\xAD", "\xDE" => "\xD0\xAE", "\xDF" => "\xD0\xAF", "\xAF" => "\xD0\x87", "\xB2" => "\xD0\x86",
"\xAA" => "\xD0\x84", "\xA1" => "\xD0\x8E", "\xE0" => "\xD0\xB0", "\xE1" => "\xD0\xB1", "\xE2" => "\xD0\xB2",
"\xE3" => "\xD0\xB3", "\xE4" => "\xD0\xB4", "\xE5" => "\xD0\xB5", "\xB8" => "\xD1\x91", "\xE6" => "\xD0\xB6",
"\xE7" => "\xD0\xB7", "\xE8" => "\xD0\xB8", "\xE9" => "\xD0\xB9", "\xEA" => "\xD0\xBA", "\xEB" => "\xD0\xBB",
"\xEC" => "\xD0\xBC", "\xED" => "\xD0\xBD", "\xEE" => "\xD0\xBE", "\xEF" => "\xD0\xBF", "\xF0" => "\xD1\x80",
"\xF1" => "\xD1\x81", "\xF2" => "\xD1\x82", "\xF3" => "\xD1\x83", "\xF4" => "\xD1\x84", "\xF5" => "\xD1\x85",
"\xF6" => "\xD1\x86", "\xF7" => "\xD1\x87", "\xF8" => "\xD1\x88", "\xF9" => "\xD1\x89", "\xFA" => "\xD1\x8A",
"\xFB" => "\xD1\x8B", "\xFC" => "\xD1\x8C", "\xFD" => "\xD1\x8D", "\xFE" => "\xD1\x8E", "\xFF" => "\xD1\x8F",
"\xB3" => "\xD1\x96", "\xBF" => "\xD1\x97", "\xBA" => "\xD1\x94", "\xA2" => "\xD1\x9E");

View File

@ -48,28 +48,6 @@ define(
*/
define('CURRENT_LOCALE', get_locale());
function myiconv($in_enc, $out_enc, $string)
{
global $_utf8win1251, $_win1251utf8;
if ($in_enc == $out_enc) {
return $string;
}
if (function_exists('iconv')) {
$converted = @iconv($in_enc, $out_enc, $string);
if ($converted !== false) {
return $converted;
}
}
if ($in_enc == "cp1251" && $out_enc == "utf-8") {
return strtr($string, $_win1251utf8);
}
if ($in_enc == "utf-8" && $out_enc == "cp1251") {
return strtr($string, $_utf8win1251);
}
return $string; // do not know how to convert
}
function locale_exists($locale)
{
return file_exists(MIBEW_FS_ROOT . "/locales/$locale/properties");
@ -173,22 +151,17 @@ function get_locale_links($href)
* Load localized messages id some service locale info.
*
* @global array $messages Localized messages array
* @global array $output_encoding Array of mapping locales to output encodings
*
* @param string $locale Name of a locale whose messages should be loaded.
*/
function load_messages($locale)
{
global $messages, $output_encoding;
global $messages;
// Load core localization
$locale_file = MIBEW_FS_ROOT . "/locales/{$locale}/properties";
$locale_data = read_locale_file($locale_file);
if (!is_null($locale_data['output_encoding'])) {
$output_encoding[$locale] = $locale_data['output_encoding'];
}
$messages[$locale] = $locale_data['messages'];
// Plugins are unavailable on system installation
@ -224,25 +197,13 @@ function load_messages($locale)
*
* @param string $path Locale file path
* @return array Associative array with following keys:
* - 'encoding': string, one of service field from locale file, determines
* encoding of strings in the locale file. If there is no 'encoding' field in
* the locale file, this variable will be equal to $mibew_encoding.
*
* - 'output_encoding': string, one of service field from locale file,
* determines in what encoding document should be output for this locale.
* If there is no 'output_encoding' field in the locale file, this variable
* will bew equal to NULL.
*
* - 'messages': associative array of localized strings. The keys of the array
* are localization keys and the values of the array are localized strings.
* All localized strings have internal Mibew encoding(see $mibew_encoding
* value in libs/config.php).
* All localized strings are encoded in UTF-8.
*/
function read_locale_file($path)
{
// Set default values
$current_encoding = MIBEW_ENCODING;
$output_encoding = null;
$messages = array();
$fp = fopen($path, "r");
@ -256,44 +217,16 @@ function read_locale_file($path)
if (count($line_parts) == 2) {
$key = $line_parts[0];
$value = $line_parts[1];
// Check if key is service field and treat it as
// localized string otherwise
if ($key == 'encoding') {
$current_encoding = trim($value);
} elseif ($key == 'output_encoding') {
$output_encoding = trim($value);
} elseif ($current_encoding == MIBEW_ENCODING) {
$messages[$key] = str_replace("\\n", "\n", trim($value));
} else {
$messages[$key] = myiconv(
$current_encoding,
MIBEW_ENCODING,
str_replace("\\n", "\n", trim($value))
);
}
}
}
fclose($fp);
return array(
'encoding' => $current_encoding,
'output_encoding' => $output_encoding,
'messages' => $messages
);
}
function getoutputenc()
{
global $output_encoding, $messages;
if (!isset($messages[CURRENT_LOCALE])) {
load_messages(CURRENT_LOCALE);
}
return isset($output_encoding[CURRENT_LOCALE])
? $output_encoding[CURRENT_LOCALE]
: MIBEW_ENCODING;
}
function getstring_($text, $locale, $raw = false)
{
global $messages;
@ -326,11 +259,7 @@ function getlocal($text, $raw = false)
function getlocal_($text, $locale, $raw = false)
{
$string = myiconv(
MIBEW_ENCODING,
getoutputenc(),
getstring_($text, $locale, true)
);
$string = getstring_($text, $locale, true);
return $raw ? $string : sanitize_string($string, 'low', 'moderate');
}
@ -352,11 +281,7 @@ function getstring2($text, $params, $raw = false)
function getlocal2($text, $params, $raw = false)
{
$string = myiconv(
MIBEW_ENCODING,
getoutputenc(),
getstring_($text, CURRENT_LOCALE, true)
);
$string = getstring_($text, CURRENT_LOCALE, true);
for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string);
@ -368,7 +293,7 @@ function getlocal2($text, $params, $raw = false)
/* prepares for Javascript string */
function get_local_for_js($text, $params)
{
$string = myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, CURRENT_LOCALE));
$string = getstring_($text, CURRENT_LOCALE);
$string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
for ($i = 0; $i < count($params); $i++) {
$string = str_replace("{" . $i . "}", $params[$i], $string);
@ -398,7 +323,6 @@ function save_message($locale, $key, $value)
{
$result = "";
$added = false;
$current_encoding = MIBEW_ENCODING;
$fp = fopen(MIBEW_FS_ROOT . "/locales/$locale/properties", "r");
if ($fp === false) {
die("unable to open properties for locale $locale");
@ -407,15 +331,10 @@ function save_message($locale, $key, $value)
$line = fgets($fp, 4096);
$key_val = preg_split("/=/", $line, 2);
if (isset($key_val[1])) {
if ($key_val[0] == 'encoding') {
$current_encoding = trim($key_val[1]);
} elseif (!$added && $key_val[0] == $key) {
if (!$added && $key_val[0] == $key) {
$line = "$key="
. myiconv(
MIBEW_ENCODING,
$current_encoding,
str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
) . "\n";
. str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
. "\n";
$added = true;
}
}
@ -424,11 +343,8 @@ function save_message($locale, $key, $value)
fclose($fp);
if (!$added) {
$result .= "$key="
. myiconv(
MIBEW_ENCODING,
$current_encoding,
str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
) . "\n";
. str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
. "\n";
}
$fp = @fopen(MIBEW_FS_ROOT . "/locales/$locale/properties", "w");
if ($fp !== false) {
@ -451,11 +367,7 @@ function save_message($locale, $key, $value)
fwrite(
$fp,
("$key="
. myiconv(
MIBEW_ENCODING,
$current_encoding,
str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
)
. str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
. "\n")
);
fclose($fp);
@ -463,4 +375,3 @@ function save_message($locale, $key, $value)
}
$messages = array();
$output_encoding = array();

View File

@ -22,7 +22,7 @@ use Mibew\Settings;
function get_raw_param($name)
{
if (isset($_POST[$name])) {
$value = myiconv("utf-8", MIBEW_ENCODING, $_POST[$name]);
$value = $_POST[$name];
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
@ -36,7 +36,7 @@ function get_raw_param($name)
function get_param($name)
{
if (isset($_POST[$name])) {
$value = myiconv(getoutputenc(), MIBEW_ENCODING, $_POST[$name]);
$value = $_POST[$name];
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
@ -51,7 +51,7 @@ function get_get_param($name, $default = '')
if (!isset($_GET[$name]) || !$_GET[$name]) {
return $default;
}
$value = myiconv("utf-8", MIBEW_ENCODING, unicode_urldecode($_GET[$name]));
$value = unicode_urldecode($_GET[$name]);
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}

View File

@ -77,11 +77,6 @@ function start_js_output()
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
}
function to_page($text)
{
return myiconv(MIBEW_ENCODING, getoutputenc(), $text);
}
/**
* Load additional CSS files, required by plugins, and build HTML code to
* include them

View File

@ -27,11 +27,6 @@
*/
$mibewroot = "/mibew";
/*
* Internal encoding
*/
$mibew_encoding = "utf-8";
/*
* MySQL Database parameters
*/
@ -41,7 +36,6 @@ $mysqllogin = "";
$mysqlpass = "";
$mysqlprefix = "";
$dbencoding = "utf8";
$force_charset_in_connection = true;
$use_persistent_connection = false;
@ -50,7 +44,6 @@ $use_persistent_connection = false;
* Mailbox
*/
$mibew_mailbox = "mibew@yourdomain.com";
$mail_encoding = "utf-8";
/*
* Locales

View File

@ -53,7 +53,6 @@ require_once(MIBEW_FS_ROOT . '/vendor/autoload.php');
// Include common libs
require_once(MIBEW_FS_ROOT . '/libs/common/configurations.php');
require_once(MIBEW_FS_ROOT . '/libs/common/verification.php');
require_once(MIBEW_FS_ROOT . '/libs/common/converter.php');
require_once(MIBEW_FS_ROOT . '/libs/common/locale.php');
require_once(MIBEW_FS_ROOT . '/libs/common/csrf.php');
require_once(MIBEW_FS_ROOT . '/libs/common/datetime.php');
@ -83,7 +82,7 @@ session_start();
$mysqldb,
$mysqlprefix,
$force_charset_in_connection,
$dbencoding
'utf8'
);
if (function_exists("date_default_timezone_set")) {

View File

@ -302,7 +302,7 @@ function setup_invitation_view(Thread $thread)
);
$data['invitation']['user'] = array(
'name' => htmlspecialchars(to_page($thread->userName)),
'name' => htmlspecialchars($thread->userName),
'canChangeName' => false,
'isAgent' => false,
);

View File

@ -15,25 +15,16 @@
* limitations under the License.
*/
/**
* Send an email
*
* @param string $to_addr Comma separated list recipient emails
* @param string $reply_to Comma separated list replies emails
* @param string $subject subject of email
* @param string $body text of email.
*/
function mibew_mail($to_addr, $reply_to, $subject, $body)
{
global $mibew_mailbox, $mail_encoding;
global $mibew_mailbox;
$headers = "From: $mibew_mailbox\r\n"
. "Reply-To: " . myiconv(MIBEW_ENCODING, $mail_encoding, $reply_to) . "\r\n"
. "Content-Type: text/plain; charset=$mail_encoding\r\n"
. "Reply-To: " . $reply_to . "\r\n"
. "Content-Type: text/plain; charset=utf-8\r\n"
. 'X-Mailer: PHP/' . phpversion();
$real_subject = "=?" . $mail_encoding . "?B?"
. base64_encode(myiconv(MIBEW_ENCODING, $mail_encoding, $subject)) . "?=";
$real_subject = "=?utf-8?B?" . base64_encode($subject) . "?=";
$body = preg_replace("/\n/", "\r\n", $body);
@ -42,7 +33,7 @@ function mibew_mail($to_addr, $reply_to, $subject, $body)
@mail(
$to_addr,
$real_subject,
wordwrap(myiconv(MIBEW_ENCODING, $mail_encoding, $body), 70),
wordwrap($body, 70),
$headers
);
if (isset($old_from)) {

View File

@ -701,8 +701,8 @@ function setup_redirect_links($threadid, $operator, $token)
: getlocal("char.redirect.operator.away_suff"))
: "";
$agent_list .= "<li><a href=\"" . add_params(MIBEW_WEB_ROOT . "/operator/redirect.php", $params)
. "\" title=\"" . to_page(get_operator_name($agent)) . "\">"
. to_page(get_operator_name($agent))
. "\" title=\"" . get_operator_name($agent) . "\">"
. get_operator_name($agent)
. "</a> $status</li>";
}
$result['redirectToAgent'] = $agent_list;
@ -716,8 +716,8 @@ function setup_redirect_links($threadid, $operator, $token)
? getlocal("char.redirect.operator.online_suff")
: (group_is_away($group) ? getlocal("char.redirect.operator.away_suff") : "");
$group_list .= "<li><a href=\"" . add_params(MIBEW_WEB_ROOT . "/operator/redirect.php", $params)
. "\" title=\"" . to_page(get_group_name($group)) . "\">"
. to_page(get_group_name($group))
. "\" title=\"" . get_group_name($group) . "\">"
. get_group_name($group)
. "</a> $status</li>";
}
}
@ -771,7 +771,7 @@ function prepare_menu($operator, $has_right = true)
$result = array();
$result['showMenu'] = true;
$result['operator'] = to_page(get_operator_name($operator));
$result['operator'] = get_operator_name($operator);
$result['goOnlineLink'] = getlocal2(
"menu.goonline",
array(MIBEW_WEB_ROOT . "/operator/users?nomenu")

View File

@ -77,8 +77,8 @@ if (!isset($_GET['token'])) {
if ($force_take == false) {
$page = array(
'user' => to_page($thread->userName),
'agent' => to_page($thread->agentName),
'user' => $thread->userName,
'agent' => $thread->agentName,
'link' => $_SERVER['PHP_SELF'] . "?thread=$thread_id&force=true",
'title' => getlocal("confirm.take.head"),
);

View File

@ -83,7 +83,7 @@ if (!$op) {
header("Location: " . MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . intval($op_id));
exit;
} else {
$page['avatar'] = to_page($op['vcavatar']);
$page['avatar'] = $op['vcavatar'];
}
} else {
if (isset($_GET['delete']) && $_GET['delete'] == "true" && $can_modify) {
@ -91,10 +91,10 @@ if (!$op) {
header("Location: " . MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . intval($op_id));
exit;
}
$page['avatar'] = to_page($op['vcavatar']);
$page['avatar'] = $op['vcavatar'];
}
$page['currentop'] = $op ? to_page(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : getlocal("not_found");
$page['currentop'] = $op ? get_operator_name($op) . " (" . $op['vclogin'] . ")" : getlocal("not_found");
$page['canmodify'] = $can_modify ? "1" : "";
$page['title'] = getlocal("page_avatar.title");
$page['menuid'] = ($operator['operatorid'] == $op_id) ? "profile" : "operators";

View File

@ -88,10 +88,10 @@ if (isset($_POST['address'])) {
$page['saved'] = true;
$page['address'] = $address;
} else {
$page['banId'] = to_page($ban_id);
$page['formaddress'] = to_page($address);
$page['formdays'] = to_page($days);
$page['formcomment'] = to_page($comment);
$page['banId'] = $ban_id;
$page['formaddress'] = $address;
$page['formdays'] = $days;
$page['formcomment'] = $comment;
$page['threadid'] = $thread_id;
}
} elseif (isset($_GET['id'])) {
@ -108,10 +108,10 @@ if (isset($_POST['address'])) {
);
if ($ban) {
$page['banId'] = to_page($ban['banid']);
$page['formaddress'] = to_page($ban['address']);
$page['formdays'] = to_page(round($ban['days'] / 86400));
$page['formcomment'] = to_page($ban['comment']);
$page['banId'] = $ban['banid'];
$page['formaddress'] = $ban['address'];
$page['formdays'] = round($ban['days'] / 86400);
$page['formcomment'] = $ban['comment'];
} else {
$page['errors'][] = "Wrong id";
}
@ -119,9 +119,9 @@ if (isset($_POST['address'])) {
$thread_id = verify_param('thread', "/^\d{1,9}$/");
$thread = Thread::load($thread_id);
if ($thread) {
$page['thread'] = htmlspecialchars(to_page($thread->userName));
$page['thread'] = htmlspecialchars($thread->userName);
$page['threadid'] = $thread_id;
$page['formaddress'] = to_page($thread->remote);
$page['formaddress'] = $thread->remote;
$page['formdays'] = 15;
}
}

View File

@ -54,7 +54,7 @@ $blocked_list = $db->query(
);
foreach ($blocked_list as &$item) {
$item['comment'] = to_page($item['comment']);
$item['comment'] = $item['comment'];
}
unset($item);

View File

@ -89,8 +89,8 @@ if (isset($_GET['act']) && $_GET['act'] == 'delete') {
$canned_messages = load_canned_messages($lang, $group_id);
foreach ($canned_messages as &$message) {
$message['vctitle'] = to_page($message['vctitle']);
$message['vcvalue'] = to_page($message['vcvalue']);
$message['vctitle'] = $message['vctitle'];
$message['vcvalue'] = $message['vcvalue'];
}
unset($message);

View File

@ -75,8 +75,8 @@ if (isset($_POST['message']) && isset($_POST['title'])) {
$page['saved'] = false;
$page['key'] = $string_id;
$page['formtitle'] = to_page($title);
$page['formmessage'] = to_page($message);
$page['formtitle'] = $title;
$page['formmessage'] = $message;
$page['title'] = empty($string_id) ? getlocal("cannednew.title") : getlocal("cannededit.title");
$page = array_merge($page, prepare_menu($operator, false));

View File

@ -109,18 +109,18 @@ if (isset($_POST['name'])) {
exit;
}
} else {
$page['formname'] = to_page($name);
$page['formdescription'] = to_page($description);
$page['formcommonname'] = to_page($common_name);
$page['formcommondescription'] = to_page($common_description);
$page['formemail'] = to_page($email);
$page['formweight'] = to_page($weight);
$page['formparentgroup'] = to_page($parent_group);
$page['grid'] = to_page($group_id);
$page['formtitle'] = to_page($title);
$page['formchattitle'] = to_page($chat_title);
$page['formhosturl'] = to_page($host_url);
$page['formlogo'] = to_page($logo);
$page['formname'] = $name;
$page['formdescription'] = $description;
$page['formcommonname'] = $common_name;
$page['formcommondescription'] = $common_description;
$page['formemail'] = $email;
$page['formweight'] = $weight;
$page['formparentgroup'] = $parent_group;
$page['grid'] = $group_id;
$page['formtitle'] = $title;
$page['formchattitle'] = $chat_title;
$page['formhosturl'] = $host_url;
$page['formlogo'] = $logo;
}
} elseif (isset($_GET['gid'])) {
$group_id = verify_param('gid', "/^\d{1,9}$/");
@ -128,20 +128,20 @@ if (isset($_POST['name'])) {
if (!$group) {
$page['errors'][] = getlocal("page.group.no_such");
$page['grid'] = to_page($group_id);
$page['grid'] = $group_id;
} else {
$page['formname'] = to_page($group['vclocalname']);
$page['formdescription'] = to_page($group['vclocaldescription']);
$page['formcommonname'] = to_page($group['vccommonname']);
$page['formcommondescription'] = to_page($group['vccommondescription']);
$page['formemail'] = to_page($group['vcemail']);
$page['formweight'] = to_page($group['iweight']);
$page['formparentgroup'] = to_page($group['parent']);
$page['grid'] = to_page($group['groupid']);
$page['formtitle'] = to_page($group['vctitle']);
$page['formchattitle'] = to_page($group['vcchattitle']);
$page['formhosturl'] = to_page($group['vchosturl']);
$page['formlogo'] = to_page($group['vclogo']);
$page['formname'] = $group['vclocalname'];
$page['formdescription'] = $group['vclocaldescription'];
$page['formcommonname'] = $group['vccommonname'];
$page['formcommondescription'] = $group['vccommondescription'];
$page['formemail'] = $group['vcemail'];
$page['formweight'] = $group['iweight'];
$page['formparentgroup'] = $group['parent'];
$page['grid'] = $group['groupid'];
$page['formtitle'] = $group['vctitle'];
$page['formchattitle'] = $group['vcchattitle'];
$page['formhosturl'] = $group['vchosturl'];
$page['formlogo'] = $group['vclogo'];
}
}

View File

@ -50,7 +50,7 @@ if (!$group) {
}
$page['formop'] = array();
$page['currentgroup'] = $group ? to_page(htmlspecialchars($group['vclocalname'])) : "";
$page['currentgroup'] = $group ? htmlspecialchars($group['vclocalname']) : "";
$checked_operators = array();
foreach (get_group_members($group_id) as $rel) {
@ -59,8 +59,8 @@ foreach (get_group_members($group_id) as $rel) {
$page['operators'] = array();
foreach ($operators as $op) {
$op['vclocalename'] = to_page($op['vclocalename']);
$op['vclogin'] = to_page($op['vclogin']);
$op['vclocalename'] = $op['vclocalename'];
$op['vclogin'] = $op['vclogin'];
$op['checked'] = in_array($op['operatorid'], $checked_operators);
$page['operators'][] = $op;

View File

@ -57,12 +57,12 @@ $sort['desc'] = (verify_param("sortdirection", "/^(desc|asc)$/", "desc") == "des
// Load and prepare groups
$groups = get_sorted_groups($sort);
foreach ($groups as &$group) {
$group['vclocalname'] = to_page($group['vclocalname']);
$group['vclocaldescription'] = to_page($group['vclocaldescription']);
$group['vclocalname'] = $group['vclocalname'];
$group['vclocaldescription'] = $group['vclocaldescription'];
$group['isOnline'] = group_is_online($group);
$group['isAway'] = group_is_away($group);
$group['lastTimeOnline'] = time() - ($group['ilastseen'] ? $group['ilastseen'] : time());
$group['inumofagents'] = to_page($group['inumofagents']);
$group['inumofagents'] = $group['inumofagents'];
}
unset($group);

View File

@ -123,12 +123,12 @@ if ((isset($_POST['login']) || !is_capable(CAN_ADMINISTRATE, $operator)) && isse
exit;
}
} else {
$page['formlogin'] = to_page($login);
$page['formname'] = to_page($local_name);
$page['formemail'] = to_page($email);
$page['formcommonname'] = to_page($common_name);
$page['formcode'] = to_page($code);
$page['opid'] = to_page($op_id);
$page['formlogin'] = $login;
$page['formname'] = $local_name;
$page['formemail'] = $email;
$page['formcommonname'] = $common_name;
$page['formcode'] = $code;
$page['opid'] = $op_id;
}
} elseif (isset($_GET['op'])) {
$op_id = verify_param('op', "/^\d{1,9}$/");
@ -136,19 +136,19 @@ if ((isset($_POST['login']) || !is_capable(CAN_ADMINISTRATE, $operator)) && isse
if (!$op) {
$page['errors'][] = getlocal("no_such_operator");
$page['opid'] = to_page($op_id);
$page['opid'] = $op_id;
} else {
//show an error if the admin password hasn't been set yet.
if (check_password_hash($operator['vclogin'], '', $operator['vcpassword']) && !isset($_GET['stored'])) {
$page['errors'][] = getlocal("my_settings.error.no_password");
}
$page['formlogin'] = to_page($op['vclogin']);
$page['formname'] = to_page($op['vclocalename']);
$page['formemail'] = to_page($op['vcemail']);
$page['formcommonname'] = to_page($op['vccommonname']);
$page['formcode'] = to_page($op['code']);
$page['opid'] = to_page($op['operatorid']);
$page['formlogin'] = $op['vclogin'];
$page['formname'] = $op['vclocalename'];
$page['formemail'] = $op['vcemail'];
$page['formcommonname'] = $op['vccommonname'];
$page['formcode'] = $op['code'];
$page['opid'] = $op['operatorid'];
}
}

View File

@ -108,9 +108,9 @@ $operators_list = get_operators_list($list_options);
// Prepare operator to render in template
foreach ($operators_list as &$item) {
$item['vclogin'] = to_page($item['vclogin']);
$item['vclocalename'] = to_page($item['vclocalename']);
$item['vccommonname'] = to_page($item['vccommonname']);
$item['vclogin'] = $item['vclogin'];
$item['vclocalename'] = $item['vclocalename'];
$item['vccommonname'] = $item['vccommonname'];
$item['isAvailable'] = operator_is_available($item);
$item['isAway'] = operator_is_away($item);
$item['lastTimeOnline'] = time() - $item['time'];

View File

@ -63,7 +63,7 @@ if (!$op) {
}
$page['currentop'] = $op
? to_page(get_operator_name($op)) . " (" . $op['vclogin'] . ")"
? get_operator_name($op) . " (" . $op['vclogin'] . ")"
: getlocal("not_found");
$page['canmodify'] = $can_modify ? "1" : "";
@ -76,8 +76,8 @@ if ($op) {
$page['groups'] = array();
foreach ($groups as $group) {
$group['vclocalname'] = to_page($group['vclocalname']);
$group['vclocaldescription'] = to_page($group['vclocaldescription']);
$group['vclocalname'] = $group['vclocalname'];
$group['vclocaldescription'] = $group['vclocaldescription'];
$group['checked'] = in_array($group['groupid'], $checked_groups);
$page['groups'][] = $group;

View File

@ -62,7 +62,9 @@ if (!$op) {
}
}
$page['currentop'] = $op ? to_page(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : getlocal("not_found");
$page['currentop'] = $op
? get_operator_name($op) . " (" . $op['vclogin'] . ")"
: getlocal("not_found");
$checked_permissions = array();
if ($op) {

View File

@ -47,7 +47,7 @@ if (isset($_GET['nextGroup'])) {
if ($next_group) {
$page['message'] = getlocal2(
"chat.redirected.group.content",
array(to_page(get_group_name($next_group)))
array(get_group_name($next_group))
);
if ($thread->state == Thread::STATE_CHATTING) {
$thread->state = Thread::STATE_WAITING;
@ -79,7 +79,7 @@ if (isset($_GET['nextGroup'])) {
if ($next_operator) {
$page['message'] = getlocal2(
"chat.redirected.content",
array(to_page(get_operator_name($next_operator)))
array(get_operator_name($next_operator))
);
if ($thread->state == Thread::STATE_CHATTING) {
$thread->state = Thread::STATE_WAITING;

View File

@ -85,7 +85,7 @@ if (isset($_POST['loginoremail'])) {
}
}
$page['formloginoremail'] = to_page($login_or_email);
$page['formloginoremail'] = $login_or_email;
$page['localeLinks'] = get_locale_links(MIBEW_WEB_ROOT . "/operator/restore.php");
$page['isdone'] = false;

View File

@ -141,17 +141,17 @@ if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
}
}
$page['formemail'] = to_page($params['email']);
$page['formtitle'] = to_page($params['title']);
$page['formlogo'] = to_page($params['logo']);
$page['formhosturl'] = to_page($params['hosturl']);
$page['formgeolink'] = to_page($params['geolink']);
$page['formgeolinkparams'] = to_page($params['geolinkparams']);
$page['formusernamepattern'] = to_page($params['usernamepattern']);
$page['formemail'] = $params['email'];
$page['formtitle'] = $params['title'];
$page['formlogo'] = $params['logo'];
$page['formhosturl'] = $params['hosturl'];
$page['formgeolink'] = $params['geolink'];
$page['formgeolinkparams'] = $params['geolinkparams'];
$page['formusernamepattern'] = $params['usernamepattern'];
$page['formpagestyle'] = $styles_params['page_style'];
$page['availablePageStyles'] = $page_style_list;
$page['formchatstyle'] = $styles_params['chat_style'];
$page['formchattitle'] = to_page($params['chattitle']);
$page['formchattitle'] = $params['chattitle'];
$page['formsendmessagekey'] = $params['sendmessagekey'];
$page['availableChatStyles'] = $chat_style_list;
$page['stored'] = isset($_GET['stored']);

View File

@ -29,7 +29,7 @@ force_password($operator);
setlocale(LC_TIME, getstring("time.locale"));
$page = array();
$page['operator'] = to_page(get_operator_name($operator));
$page['operator'] = get_operator_name($operator);
$page['availableDays'] = range(1, 31);
$page['availableMonth'] = get_month_selection(time() - 400 * 24 * 60 * 60, time() + 50 * 24 * 60 * 60);
$page['showresults'] = false;
@ -164,7 +164,7 @@ if ($statistics_type == 'bydate') {
// cannot do it in a template.
// TODO: Remove this block when "to_page" function will be removed.
foreach ($page['reportByAgent'] as &$row) {
$row['name'] = to_page($row['name']);
$row['name'] = $row['name'];
}
unset($row);

View File

@ -41,8 +41,8 @@ $lang2 = $messages[$target];
$page = array(
'lang1' => $source,
'lang2' => $target,
'title1' => to_page(isset($lang1["localeid"]) ? $lang1["localeid"] : $source),
'title2' => to_page(isset($lang2["localeid"]) ? $lang2["localeid"] : $target),
'title1' => (isset($lang1["localeid"]) ? $lang1["localeid"] : $source),
'title2' => (isset($lang2["localeid"]) ? $lang2["localeid"] : $target),
'errors' => array(),
);
@ -115,9 +115,9 @@ foreach ($all_keys as $key) {
'id' => $key,
'l1' => $t_source,
'l2' => $value,
'idToPage' => to_page($key),
'l1ToPage' => to_page($t_source),
'l2ToPage' => to_page($value),
'idToPage' => $key,
'l1ToPage' => $t_source,
'l2ToPage' => $value,
);
}
}