diff --git a/src/compute_resources.pl b/src/compute_resources.pl index e7e3584a..baff7033 100755 --- a/src/compute_resources.pl +++ b/src/compute_resources.pl @@ -146,7 +146,7 @@ sub process_php($) { while( $content =~ s/<\?(?!xml)(.*?)\?>//s ) { my $inner = $1; - while($inner =~ s/(getlocal|getstring|no_field)2?_?\((.*?)[,\)]//s) { + while($inner =~ s/(getlocal|no_field)2?_?\((.*?)[,\)]//s) { my $firstarg = $2; if( $firstarg =~ /^["']([\w\.]+)['"]$/) { usemsg($1); diff --git a/src/mibew/install/index.php b/src/mibew/install/index.php index 77582e64..75051396 100644 --- a/src/mibew/install/index.php +++ b/src/mibew/install/index.php @@ -310,7 +310,7 @@ function add_canned_messages($link){ $result = array(); foreach (get_available_locales() as $locale) { if (! in_array($locale, $existlocales)) { - foreach (explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) { + foreach (explode("\n", getlocal_('chat.predefined_answers', $locale)) as $answer) { $result[] = array('locale' => $locale, 'vctitle' => cut_string($answer, 97, '...'), 'vcvalue' => $answer); } } diff --git a/src/mibew/libs/chat.php b/src/mibew/libs/chat.php index 7ffc4f3c..6e90a6ef 100644 --- a/src/mibew/libs/chat.php +++ b/src/mibew/libs/chat.php @@ -518,7 +518,7 @@ function setup_chatview_for_user(Thread $thread) $data['chat']['user'] = array( 'name' => htmlspecialchars($thread->userName), 'canChangeName' => (bool) (Settings::get('usercanchangename') == "1"), - 'defaultName' => (bool) (getstring("chat.default.username") != $thread->userName), + 'defaultName' => (bool) (getlocal("chat.default.username") != $thread->userName), 'canPost' => true, 'isAgent' => false, ); @@ -641,7 +641,7 @@ function ban_for_addr($addr) */ function visitor_from_request() { - $default_name = getstring("chat.default.username"); + $default_name = getlocal("chat.default.username"); $user_name = $default_name; if (isset($_COOKIE[USERNAME_COOKIE_NAME])) { $data = base64_decode(strtr($_COOKIE[USERNAME_COOKIE_NAME], '-_,', '+/=')); @@ -766,7 +766,7 @@ function chat_start_for_user( $operator_name = get_operator_name($operator); $thread->postMessage( Thread::KIND_FOR_AGENT, - getstring2( + getlocal2( 'chat.visitor.invitation.accepted', array($operator_name), true @@ -776,20 +776,20 @@ function chat_start_for_user( if ($referrer) { $thread->postMessage( Thread::KIND_FOR_AGENT, - getstring2('chat.came.from', array($referrer), true) + getlocal2('chat.came.from', array($referrer), true) ); } if ($requested_operator && !$requested_operator_online) { $thread->postMessage( Thread::KIND_INFO, - getstring2( + getlocal2( 'chat.requested_operator.offline', array(get_operator_name($requested_operator)), true ) ); } else { - $thread->postMessage(Thread::KIND_INFO, getstring('chat.wait', true)); + $thread->postMessage(Thread::KIND_INFO, getlocal('chat.wait', true)); } } @@ -797,7 +797,7 @@ function chat_start_for_user( if ($info) { $thread->postMessage( Thread::KIND_FOR_AGENT, - getstring2('chat.visitor.info', array($info), true) + getlocal2('chat.visitor.info', array($info), true) ); } diff --git a/src/mibew/libs/classes/Mibew/Controller/BanController.php b/src/mibew/libs/classes/Mibew/Controller/BanController.php index 2b8d0052..3a9fd1fe 100644 --- a/src/mibew/libs/classes/Mibew/Controller/BanController.php +++ b/src/mibew/libs/classes/Mibew/Controller/BanController.php @@ -37,7 +37,7 @@ class BanController extends AbstractController public function indexAction(Request $request) { set_csrf_token(); - setlocale(LC_TIME, getstring('time.locale')); + setlocale(LC_TIME, getlocal('time.locale')); $operator = $this->getOperator(); $page = array( diff --git a/src/mibew/libs/classes/Mibew/Controller/ButtonController.php b/src/mibew/libs/classes/Mibew/Controller/ButtonController.php index a8310276..03c5fb6e 100644 --- a/src/mibew/libs/classes/Mibew/Controller/ButtonController.php +++ b/src/mibew/libs/classes/Mibew/Controller/ButtonController.php @@ -40,7 +40,7 @@ class ButtonController extends AbstractController if ($referer && isset($_SESSION['threadid'])) { $thread = Thread::load($_SESSION['threadid']); if ($thread && $thread->state != Thread::STATE_CLOSED) { - $msg = getstring2_( + $msg = getlocal2_( "chat.client.visited.page", array($referer), $thread->locale, diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/MailController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/MailController.php index 5d2b61f1..f17b2113 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/MailController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/MailController.php @@ -110,8 +110,8 @@ class MailController extends AbstractController $history .= message_to_text($msg); } - $subject = getstring('mail.user.history.subject', true); - $body = getstring2( + $subject = getlocal('mail.user.history.subject', true); + $body = getlocal2( 'mail.user.history.body', array($thread->userName, $history, diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php index 852f6258..f83e700b 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/RedirectController.php @@ -167,7 +167,7 @@ class RedirectController extends AbstractController // Send notification message $thread->postMessage( Thread::KIND_EVENTS, - getstring2_( + getlocal2_( 'chat.status.operator.redirect', array(get_operator_name($this->getOperator())), $thread->locale, @@ -221,7 +221,7 @@ class RedirectController extends AbstractController // Send notification message $thread->postMessage( Thread::KIND_EVENTS, - getstring2_( + getlocal2_( 'chat.status.operator.redirect', array(get_operator_name($this->getOperator())), $thread->locale, diff --git a/src/mibew/libs/classes/Mibew/Controller/HistoryController.php b/src/mibew/libs/classes/Mibew/Controller/HistoryController.php index 4d8fcbd1..2c878ae4 100644 --- a/src/mibew/libs/classes/Mibew/Controller/HistoryController.php +++ b/src/mibew/libs/classes/Mibew/Controller/HistoryController.php @@ -36,7 +36,7 @@ class HistoryController extends AbstractController */ public function indexAction(Request $request) { - setlocale(LC_TIME, getstring("time.locale")); + setlocale(LC_TIME, getlocal("time.locale")); $page = array(); $operator = $this->getOperator(); @@ -177,7 +177,7 @@ class HistoryController extends AbstractController */ public function threadAction(Request $request) { - setlocale(LC_TIME, getstring("time.locale")); + setlocale(LC_TIME, getlocal("time.locale")); $operator = $this->getOperator(); $page = array(); @@ -216,7 +216,7 @@ class HistoryController extends AbstractController */ public function userAction(Request $request) { - setlocale(LC_TIME, getstring("time.locale")); + setlocale(LC_TIME, getlocal("time.locale")); $operator = $this->getOperator(); $user_id = $request->attributes->get('user_id', ''); @@ -280,7 +280,7 @@ class HistoryController extends AbstractController */ public function userTrackAction(Request $request) { - setlocale(LC_TIME, getstring('time.locale')); + setlocale(LC_TIME, getlocal('time.locale')); if (Settings::get('enabletracking') == '0') { throw new BadRequestException('Tracking is disabled.'); diff --git a/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php b/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php index 69ab9223..9df6b29d 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php @@ -35,7 +35,7 @@ class ManagementController extends AbstractController public function indexAction(Request $request) { set_csrf_token(); - setlocale(LC_TIME, getstring('time.locale')); + setlocale(LC_TIME, getlocal('time.locale')); $operator = $this->getOperator(); $page = array( diff --git a/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php b/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php index 6d93069b..d03e483c 100644 --- a/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php +++ b/src/mibew/libs/classes/Mibew/Controller/PasswordRecoveryController.php @@ -93,8 +93,8 @@ class PasswordRecoveryController extends AbstractController mibew_mail( $email, $email, - getstring('restore.mailsubj'), - getstring2( + getlocal('restore.mailsubj'), + getlocal2( 'restore.mailtext', array(get_operator_name($to_restore), $href) ) diff --git a/src/mibew/libs/classes/Mibew/Controller/StatisticsController.php b/src/mibew/libs/classes/Mibew/Controller/StatisticsController.php index 3af3e4be..0bf3d3f1 100644 --- a/src/mibew/libs/classes/Mibew/Controller/StatisticsController.php +++ b/src/mibew/libs/classes/Mibew/Controller/StatisticsController.php @@ -41,7 +41,7 @@ class StatisticsController extends AbstractController { $operator = $this->getOperator(); $statistics_type = $request->attributes->get('type'); - setlocale(LC_TIME, getstring("time.locale")); + setlocale(LC_TIME, getlocal("time.locale")); $page = array(); $page['operator'] = get_operator_name($operator); diff --git a/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php b/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php index 044a2bc3..717aebe5 100644 --- a/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php +++ b/src/mibew/libs/classes/Mibew/RequestProcessor/ThreadProcessor.php @@ -503,7 +503,7 @@ class ThreadProcessor extends ClientSideProcessor if ($email) { $thread->postMessage( Thread::KIND_FOR_AGENT, - getstring2('chat.visitor.email', array($email), true) + getlocal2('chat.visitor.email', array($email), true) ); } @@ -617,19 +617,19 @@ class ThreadProcessor extends ClientSideProcessor if ($referrer) { $thread->postMessage( Thread::KIND_FOR_AGENT, - getstring2('chat.came.from', array($referrer), true) + getlocal2('chat.came.from', array($referrer), true) ); } if ($email) { $thread->postMessage( Thread::KIND_FOR_AGENT, - getstring2('chat.visitor.email', array($email), true) + getlocal2('chat.visitor.email', array($email), true) ); } if ($info) { $thread->postMessage( Thread::KIND_FOR_AGENT, - getstring2('chat.visitor.info', array($info), true) + getlocal2('chat.visitor.info', array($info), true) ); } $thread->postMessage(Thread::KIND_USER, $message, array('name' => $name)); @@ -644,12 +644,12 @@ class ThreadProcessor extends ClientSideProcessor // Send email if ($inbox_mail) { // Prepare message to send by email - $subject = getstring2_( + $subject = getlocal2_( "leavemail.subject", array($args['name']), $message_locale ); - $body = getstring2_( + $body = getlocal2_( "leavemail.body", array( $args['name'], diff --git a/src/mibew/libs/classes/Mibew/Thread.php b/src/mibew/libs/classes/Mibew/Thread.php index fb53350c..85b66286 100644 --- a/src/mibew/libs/classes/Mibew/Thread.php +++ b/src/mibew/libs/classes/Mibew/Thread.php @@ -364,7 +364,7 @@ class Thread // Send message $thread->postMessage( self::KIND_EVENTS, - getstring_("chat.status.user.reopenedthread", $thread->locale, true) + getlocal_("chat.status.user.reopenedthread", $thread->locale, true) ); return $thread; @@ -600,7 +600,7 @@ class Thread // Check if user chatting at the moment if ($this->state == self::STATE_CHATTING) { // Send message to user - $message_to_post = getstring_( + $message_to_post = getlocal_( "chat.status.operator.dead", $this->locale, true @@ -625,7 +625,7 @@ class Thread $this->lastPingUser = 0; // And send a message to operator - $message_to_post = getstring_( + $message_to_post = getlocal_( "chat.status.user.dead", $this->locale, true @@ -707,14 +707,14 @@ class Thread // Prepare message if ($this->nextAgent == $operator['operatorid']) { - $message_to_post = getstring2_( + $message_to_post = getlocal2_( "chat.status.operator.changed", array($operator_name, $this->agentName), $this->locale, true ); } else { - $message_to_post = getstring2_( + $message_to_post = getlocal2_( "chat.status.operator.returned", array($operator_name), $this->locale, @@ -854,7 +854,7 @@ class Thread if ($is_user) { $this->postMessage( self::KIND_EVENTS, - getstring2_( + getlocal2_( "chat.status.user.left", array($this->userName), $this->locale, @@ -865,7 +865,7 @@ class Thread if ($this->state == self::STATE_INVITED) { $this->postMessage( self::KIND_FOR_AGENT, - getstring_( + getlocal_( "chat.visitor.invitation.canceled", $this->locale, true @@ -874,7 +874,7 @@ class Thread } else { $this->postMessage( self::KIND_EVENTS, - getstring2_( + getlocal2_( "chat.status.operator.left", array($this->agentName), $this->locale, @@ -932,14 +932,14 @@ class Thread $take_thread = true; if ($this->state == self::STATE_WAITING) { if ($operator['operatorid'] != $this->agentId) { - $message = getstring2_( + $message = getlocal2_( "chat.status.operator.changed", array($operator_name, $this->agentName), $this->locale, true ); } else { - $message = getstring2_( + $message = getlocal2_( "chat.status.operator.returned", array($operator_name), $this->locale, @@ -947,7 +947,7 @@ class Thread ); } } else { - $message = getstring2_( + $message = getlocal2_( "chat.status.operator.joined", array($operator_name), $this->locale, @@ -958,7 +958,7 @@ class Thread // User chatting if ($operator['operatorid'] != $this->agentId) { $take_thread = true; - $message = getstring2_( + $message = getlocal2_( "chat.status.operator.changed", array($operator_name, $this->agentName), $this->locale, @@ -1009,7 +1009,7 @@ class Thread $this->save(); // Send message about renaming - $message = getstring2_( + $message = getlocal2_( "chat.status.user.changedname", array($old_name, $new_name), $this->locale, diff --git a/src/mibew/libs/common/locale.php b/src/mibew/libs/common/locale.php index e1559d49..1b3824bb 100644 --- a/src/mibew/libs/common/locale.php +++ b/src/mibew/libs/common/locale.php @@ -232,7 +232,12 @@ function read_locale_file($path) ); } -function getstring_($text, $locale, $raw = false) +function getlocal($text, $raw = false) +{ + return getlocal_($text, CURRENT_LOCALE, $raw); +} + +function getlocal_($text, $locale, $raw = false) { $localized = load_messages($locale); if (isset($localized[$text])) { @@ -241,32 +246,15 @@ function getstring_($text, $locale, $raw = false) : sanitize_string($localized[$text], 'low', 'moderate'); } if ($locale != 'en') { - return getstring_($text, 'en', $raw); + return getlocal_($text, 'en', $raw); } return "!" . ($raw ? $text : sanitize_string($text, 'low', 'moderate')); } -function getstring($text, $raw = false) +function getlocal2_($text, $params, $locale, $raw = false) { - return getstring_($text, CURRENT_LOCALE, $raw); -} - -function getlocal($text, $raw = false) -{ - return getlocal_($text, CURRENT_LOCALE, $raw); -} - -function getlocal_($text, $locale, $raw = false) -{ - $string = getstring_($text, $locale, true); - - return $raw ? $string : sanitize_string($string, 'low', 'moderate'); -} - -function getstring2_($text, $params, $locale, $raw = false) -{ - $string = getstring_($text, $locale, true); + $string = getlocal_($text, $locale, true); for ($i = 0; $i < count($params); $i++) { $string = str_replace("{" . $i . "}", $params[$i], $string); } @@ -274,14 +262,9 @@ function getstring2_($text, $params, $locale, $raw = false) return $raw ? $string : sanitize_string($string, 'low', 'moderate'); } -function getstring2($text, $params, $raw = false) -{ - return getstring2_($text, $params, CURRENT_LOCALE, $raw); -} - function getlocal2($text, $params, $raw = false) { - $string = getstring_($text, CURRENT_LOCALE, true); + $string = getlocal_($text, CURRENT_LOCALE, true); for ($i = 0; $i < count($params); $i++) { $string = str_replace("{" . $i . "}", $params[$i], $string); @@ -293,7 +276,7 @@ function getlocal2($text, $params, $raw = false) /* prepares for Javascript string */ function get_local_for_js($text, $params) { - $string = getstring_($text, CURRENT_LOCALE); + $string = getlocal_($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); diff --git a/src/mibew/libs/invitation.php b/src/mibew/libs/invitation.php index 5b7e84d6..8c8d61ee 100644 --- a/src/mibew/libs/invitation.php +++ b/src/mibew/libs/invitation.php @@ -271,7 +271,7 @@ function invitation_close_old() $thread = Thread::createFromDbInfo($thread_info); $thread->postMessage( Thread::KIND_FOR_AGENT, - getstring_('chat.visitor.invitation.ignored', $thread->locale, true) + getlocal_('chat.visitor.invitation.ignored', $thread->locale, true) ); unset($thread); }