mirror of
https://github.com/Mibew/mibew.git
synced 2025-01-31 21:34:42 +03:00
Do not use $current_locale global variable
Replace $current_locale global var with CURRENT_LOCALE constant
This commit is contained in:
parent
7b83f8ca6f
commit
03797744e2
@ -37,7 +37,7 @@ if($referer && isset($_SESSION['threadid'])) {
|
||||
$image = verifyparam(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "mibew");
|
||||
$lang = verifyparam(isset($_GET['language']) ? "language" : "lang", "/^[\w-]{2,5}$/", "");
|
||||
if(!$lang || !locale_exists($lang)) {
|
||||
$lang = $current_locale;
|
||||
$lang = CURRENT_LOCALE;
|
||||
}
|
||||
|
||||
$groupid = verifyparam( "group", "/^\d{1,8}$/", "");
|
||||
|
@ -631,7 +631,6 @@ function get_remote_host()
|
||||
/**
|
||||
* Start chat thread for user
|
||||
*
|
||||
* @global string $current_locale Current locale code
|
||||
* @param int $group_id Id of group related to thread
|
||||
* @param array $requested_operator Array of requested operator info
|
||||
* @param string $visitor_id Id of the visitor
|
||||
@ -640,8 +639,6 @@ function get_remote_host()
|
||||
* @param string $info User info
|
||||
*/
|
||||
function chat_start_for_user($group_id, $requested_operator, $visitor_id, $visitor_name, $referrer, $info) {
|
||||
global $current_locale;
|
||||
|
||||
// Get user info
|
||||
$remote_host = get_remote_host();
|
||||
$user_browser = $_SERVER['HTTP_USER_AGENT'];
|
||||
@ -690,7 +687,7 @@ function chat_start_for_user($group_id, $requested_operator, $visitor_id, $visit
|
||||
$thread->userName = $visitor_name;
|
||||
$thread->remote = $remote_host;
|
||||
$thread->referer = $referrer;
|
||||
$thread->locale = $current_locale;
|
||||
$thread->locale = CURRENT_LOCALE;
|
||||
$thread->userId = $visitor_id;
|
||||
$thread->userAgent = $user_browser;
|
||||
$thread->save();
|
||||
|
@ -530,7 +530,6 @@ class ThreadProcessor extends ClientSideProcessor {
|
||||
* Process submitted leave message form.
|
||||
*
|
||||
* Send message to operator email and create special meil thread.
|
||||
* @global string $current_locale Code of the current locale
|
||||
* @param array $args Associative array of arguments. It must contains
|
||||
* following keys:
|
||||
* - 'threadId': for this function this param equals to null;
|
||||
@ -547,8 +546,6 @@ class ThreadProcessor extends ClientSideProcessor {
|
||||
* exception if captcha or email is wrong.
|
||||
*/
|
||||
protected function apiProcessLeaveMessage($args) {
|
||||
global $current_locale;
|
||||
|
||||
// Check captcha
|
||||
if(Settings::get('enablecaptcha') == '1' && can_show_captcha()) {
|
||||
$captcha = $args['captcha'];
|
||||
@ -606,7 +603,7 @@ class ThreadProcessor extends ClientSideProcessor {
|
||||
$thread->userName = $name;
|
||||
$thread->remote = $remote_host;
|
||||
$thread->referer = $referrer;
|
||||
$thread->locale = $current_locale;
|
||||
$thread->locale = CURRENT_LOCALE;
|
||||
$thread->userId = $visitor['id'];
|
||||
$thread->userAgent = $user_browser;
|
||||
$thread->state = Thread::STATE_LEFT;
|
||||
|
@ -41,6 +41,11 @@ define('DEFAULT_LOCALE', locale_pattern_check($default_locale) && locale_exists(
|
||||
*/
|
||||
define('HOME_LOCALE', locale_pattern_check($home_locale) && locale_exists($home_locale) ? $home_locale : 'en');
|
||||
|
||||
/**
|
||||
* Code of the current system locale
|
||||
*/
|
||||
define('CURRENT_LOCALE', get_locale());
|
||||
|
||||
function myiconv($in_enc, $out_enc, $string)
|
||||
{
|
||||
global $_utf8win1251, $_win1251utf8;
|
||||
@ -133,7 +138,6 @@ function get_locale()
|
||||
|
||||
function get_locale_links($href)
|
||||
{
|
||||
global $current_locale;
|
||||
$localeLinks = array();
|
||||
$allLocales = get_available_locales();
|
||||
if (count($allLocales) < 2) {
|
||||
@ -251,10 +255,10 @@ function read_locale_file($path) {
|
||||
|
||||
function getoutputenc()
|
||||
{
|
||||
global $current_locale, $output_encoding, $messages;
|
||||
if (!isset($messages[$current_locale]))
|
||||
load_messages($current_locale);
|
||||
return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : MIBEW_ENCODING;
|
||||
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)
|
||||
@ -275,14 +279,12 @@ function getstring_($text, $locale)
|
||||
|
||||
function getstring($text)
|
||||
{
|
||||
global $current_locale;
|
||||
return getstring_($text, $current_locale);
|
||||
return getstring_($text, CURRENT_LOCALE);
|
||||
}
|
||||
|
||||
function getlocal($text)
|
||||
{
|
||||
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)
|
||||
@ -301,14 +303,12 @@ function getstring2_($text, $params, $locale)
|
||||
|
||||
function getstring2($text, $params)
|
||||
{
|
||||
global $current_locale;
|
||||
return getstring2_($text, $params, $current_locale);
|
||||
return getstring2_($text, $params, CURRENT_LOCALE);
|
||||
}
|
||||
|
||||
function getlocal2($text, $params)
|
||||
{
|
||||
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++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
@ -318,8 +318,7 @@ function getlocal2($text, $params)
|
||||
/* prepares for Javascript string */
|
||||
function getlocalforJS($text, $params)
|
||||
{
|
||||
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));
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
@ -327,7 +326,6 @@ function getlocalforJS($text, $params)
|
||||
return $string;
|
||||
}
|
||||
|
||||
$current_locale = get_locale();
|
||||
$messages = array();
|
||||
$output_encoding = array();
|
||||
|
||||
|
@ -32,8 +32,7 @@ function group_by_id($id)
|
||||
|
||||
function get_group_name($group)
|
||||
{
|
||||
global $current_locale;
|
||||
if (HOME_LOCALE == $current_locale || !isset($group['vccommonname']) || !$group['vccommonname'])
|
||||
if (HOME_LOCALE == CURRENT_LOCALE || !isset($group['vccommonname']) || !$group['vccommonname'])
|
||||
return $group['vclocalname'];
|
||||
else
|
||||
return $group['vccommonname'];
|
||||
@ -154,15 +153,13 @@ function group_is_online($group) {
|
||||
/**
|
||||
* Return local or common group description depending on current 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;
|
||||
* - 'vclocaldescription': string, contain local description of the group.
|
||||
* @return string Group description
|
||||
*/
|
||||
function get_group_description($group) {
|
||||
global $current_locale;
|
||||
if (HOME_LOCALE == $current_locale
|
||||
if (HOME_LOCALE == CURRENT_LOCALE
|
||||
|| !isset($group['vccommondescription'])
|
||||
|| !$group['vccommondescription']) {
|
||||
return $group['vclocaldescription'];
|
||||
|
@ -55,15 +55,12 @@ function invitation_state($visitor_id) {
|
||||
/**
|
||||
* Invite visitor by operator
|
||||
*
|
||||
* @global string $current_locale Current locale code
|
||||
* @param int $visitor_id ID of the visitor, who must be invited.
|
||||
* @param array $operator Info for operator who invite the visitor
|
||||
* @return Thread|boolean Thread object related with invitation or boolean
|
||||
* false on failure
|
||||
*/
|
||||
function invitation_invite($visitor_id, $operator) {
|
||||
global $current_locale;
|
||||
|
||||
// Check if visitor already invited
|
||||
$invitation_state = invitation_state($visitor_id);
|
||||
if ($invitation_state['invited']) {
|
||||
@ -97,7 +94,7 @@ function invitation_invite($visitor_id, $operator) {
|
||||
$thread->remote = $visitor_details['remote_host'];
|
||||
$thread->referer = $last_visited_page;
|
||||
// User's locale is unknown, set operator locale to the thread
|
||||
$thread->locale = $current_locale;
|
||||
$thread->locale = CURRENT_LOCALE;
|
||||
$thread->userId = $visitor['userid'];
|
||||
$thread->userAgent = $visitor_details['user_agent'];
|
||||
$thread->state = Thread::STATE_INVITED;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
function mibew_mail($toaddr, $reply_to, $subject, $body)
|
||||
{
|
||||
global $mibew_mailbox, $mail_encoding, $current_locale;
|
||||
global $mibew_mailbox, $mail_encoding;
|
||||
|
||||
$headers = "From: $mibew_mailbox\r\n"
|
||||
. "Reply-To: " . myiconv(MIBEW_ENCODING, $mail_encoding, $reply_to) . "\r\n"
|
||||
|
@ -453,14 +453,12 @@ function is_operator_online($operatorid)
|
||||
/**
|
||||
* Returns name of the operator. Choose between vclocalname and vccommonname
|
||||
*
|
||||
* @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 $current_locale;
|
||||
if (HOME_LOCALE == $current_locale)
|
||||
if (HOME_LOCALE == CURRENT_LOCALE)
|
||||
return $operator['vclocalename'];
|
||||
else
|
||||
return $operator['vccommonname'];
|
||||
|
@ -46,7 +46,7 @@ $page['locales'] = $locales_with_label;
|
||||
|
||||
$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
|
||||
if (!$lang || !in_array($lang, $all_locales)) {
|
||||
$lang = in_array($current_locale, $all_locales) ? $current_locale : $all_locales[0];
|
||||
$lang = in_array(CURRENT_LOCALE, $all_locales) ? CURRENT_LOCALE : $all_locales[0];
|
||||
}
|
||||
|
||||
# groups
|
||||
|
@ -67,7 +67,7 @@ $operator_code = ($code_type == "operator_code");
|
||||
|
||||
$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
|
||||
if (!$lang || !in_array($lang, $image_locales))
|
||||
$lang = in_array($current_locale, $image_locales) ? $current_locale : $image_locales[0];
|
||||
$lang = in_array(CURRENT_LOCALE, $image_locales) ? CURRENT_LOCALE : $image_locales[0];
|
||||
|
||||
$file = MIBEW_FS_ROOT.'/locales/${lang}/button/${image}_on.gif';
|
||||
$size = get_gifimage_size($file);
|
||||
|
@ -125,7 +125,7 @@ force_password($operator);
|
||||
csrfchecktoken();
|
||||
|
||||
$source = verifyparam("source", "/^[\w-]{2,5}$/", DEFAULT_LOCALE);
|
||||
$target = verifyparam("target", "/^[\w-]{2,5}$/", $current_locale);
|
||||
$target = verifyparam("target", "/^[\w-]{2,5}$/", CURRENT_LOCALE);
|
||||
$stringid = verifyparam("key", "/^[_\.\w]+$/", "");
|
||||
|
||||
if (!isset($messages[$source])) {
|
||||
|
@ -16,13 +16,12 @@
|
||||
*/
|
||||
|
||||
function menuloc($id) {
|
||||
global $current_locale;
|
||||
if($current_locale == $id) {
|
||||
if(CURRENT_LOCALE == $id) {
|
||||
echo " class=\"active\"";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function tpl_menu() { global $page, $current_locale;
|
||||
function tpl_menu() { global $page;
|
||||
?>
|
||||
<li>
|
||||
<h2><b><?php echo getlocal("lang.choose") ?></b></h2>
|
||||
|
@ -32,7 +32,7 @@ function menuseparator() {
|
||||
if(($menuItemsCount%3) == 0) { echo "</tr><tr>"; }
|
||||
}
|
||||
|
||||
function tpl_content() { global $page, $current_locale, $menuItemsCount;
|
||||
function tpl_content() { global $page, $menuItemsCount;
|
||||
?>
|
||||
|
||||
<br/>
|
||||
@ -176,7 +176,7 @@ $menuItemsCount = 2;
|
||||
<b><?php echo getlocal("lang.choose") ?></b></h2>
|
||||
<ul class="locales">
|
||||
<?php foreach($page['localeLinks'] as $id => $title) { ?>
|
||||
<li<?php echo $current_locale == $id ? " class=\"active\"" : "" ?> ><a href='?locale=<?php echo $id ?>'><?php echo $title ?></a></li>
|
||||
<li<?php echo CURRENT_LOCALE == $id ? " class=\"active\"" : "" ?> ><a href='?locale=<?php echo $id ?>'><?php echo $title ?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user