1
0
mirror of https://github.com/Mibew/mibew.git synced 2025-03-01 17:44:33 +03:00

Remove getstring* functions

This commit is contained in:
Dmitriy Simushev 2014-06-04 12:20:40 +00:00
parent 24c50487d2
commit 98fe748bef
15 changed files with 54 additions and 71 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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)
);
}

View File

@ -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(

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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.');

View File

@ -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(

View File

@ -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)
)

View File

@ -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);

View File

@ -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'],

View File

@ -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,

View File

@ -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);

View File

@ -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);
}