Add 'msgjs:' and 'pagejs:' prefixies to template engine

This commit is contained in:
Dmitriy Simushev 2013-02-26 11:31:24 +00:00
parent 33f30bd1c6
commit a4d12d7b65
2 changed files with 51 additions and 44 deletions

View File

@ -65,18 +65,25 @@ function expand_var($matches)
} }
} }
} else if ($prefix == 'msg:' || $prefix == 'url:') { } else if ($prefix == 'msg:' || $prefix == 'msgjs:' || $prefix == 'url:') {
$message = '';
if (strpos($var, ",") !== false) { if (strpos($var, ",") !== false) {
$pos = strpos($var, ","); $pos = strpos($var, ",");
$param = substr($var, $pos + 1); $param = substr($var, $pos + 1);
$var = substr($var, 0, $pos); $var = substr($var, 0, $pos);
return getlocal2($var, array($page[$param])); $message = getlocal2($var, array($page[$param]));
} else {
$message = getlocal($var);
} }
return getlocal($var); if ($prefix == 'msgjs:') {
return json_encode($message);
}
return $message;
} else if ($prefix == 'form:') { } else if ($prefix == 'form:') {
return form_value($var); return form_value($var);
} else if ($prefix == 'page:') { } else if ($prefix == 'page:' || $prefix == 'pagejs:') {
return isset($page[$var]) ? $page[$var] : ""; $message = isset($page[$var]) ? $page[$var] : "";
return ($prefix == 'pagejs:') ? json_encode($message) : $message;
} else if ($prefix == 'if:' || $prefix == 'else:' || $prefix == 'endif:' || $prefix == 'ifnot:') { } else if ($prefix == 'if:' || $prefix == 'else:' || $prefix == 'endif:' || $prefix == 'ifnot:') {
return "<!-- wrong $prefix:$var -->"; return "<!-- wrong $prefix:$var -->";
} }

View File

@ -32,43 +32,43 @@
${page:additional_js} ${page:additional_js}
<script type="text/javascript"><!-- <script type="text/javascript"><!--
Mibew.Localization.set({ Mibew.Localization.set({
'chat.close.confirmation': "${msg:chat.close.confirmation}", 'chat.close.confirmation': ${msgjs:chat.close.confirmation},
'typing.remote': "${msg:typing.remote}", 'typing.remote': ${msgjs:typing.remote},
'chat.window.predefined.select_answer': "${msg:chat.window.predefined.select_answer}", 'chat.window.predefined.select_answer': ${msgjs:chat.window.predefined.select_answer},
'chat.window.send_message': "${msg:chat.window.send_message}", 'chat.window.send_message': ${msgjs:chat.window.send_message},
'chat.window.send_message_short_and_shortcut': "${msg:chat.window.send_message_short,send_shortcut}", 'chat.window.send_message_short_and_shortcut': ${msgjs:chat.window.send_message_short,send_shortcut},
'chat.window.close_title': "${msg:chat.window.close_title}", 'chat.window.close_title': ${msgjs:chat.window.close_title},
'chat.window.toolbar.refresh': "${msg:chat.window.toolbar.refresh}", 'chat.window.toolbar.refresh': ${msgjs:chat.window.toolbar.refresh},
'chat.window.toolbar.mail_history': "${msg:chat.window.toolbar.mail_history}", 'chat.window.toolbar.mail_history': ${msgjs:chat.window.toolbar.mail_history},
'chat.window.toolbar.redirect_user': "${msg:chat.window.toolbar.redirect_user}", 'chat.window.toolbar.redirect_user': ${msgjs:chat.window.toolbar.redirect_user},
'page.analysis.userhistory.title': "${msg:page.analysis.userhistory.title}", 'page.analysis.userhistory.title': ${msgjs:page.analysis.userhistory.title},
'chat.client.name': "${msg:chat.client.name}", 'chat.client.name': ${msgjs:chat.client.name},
'chat.client.changename': "${msg:chat.client.changename}", 'chat.client.changename': ${msgjs:chat.client.changename},
'chat.window.toolbar.turn_off_sound': "${msg:chat.window.toolbar.turn_off_sound}", 'chat.window.toolbar.turn_off_sound': ${msgjs:chat.window.toolbar.turn_off_sound},
'chat.window.toolbar.turn_on_sound': "${msg:chat.window.toolbar.turn_on_sound}", 'chat.window.toolbar.turn_on_sound': ${msgjs:chat.window.toolbar.turn_on_sound},
'chat.window.poweredby': "${msg:chat.window.poweredby}", 'chat.window.poweredby': ${msgjs:chat.window.poweredby},
'chat.mailthread.sent.close': "${msg:chat.mailthread.sent.close}", 'chat.mailthread.sent.close': ${msgjs:chat.mailthread.sent.close},
'form.field.department': "${msg:form.field.department}", 'form.field.department': ${msgjs:form.field.department},
'form.field.department.description': "${msg:form.field.department.description}", 'form.field.department.description': ${msgjs:form.field.department.description},
'form.field.email': "${msg:form.field.email}", 'form.field.email': ${msgjs:form.field.email},
'form.field.name': "${msg:form.field.name}", 'form.field.name': ${msgjs:form.field.name},
'form.field.message': "${msg:form.field.message}", 'form.field.message': ${msgjs:form.field.message},
'leavemessage.close': "${msg:leavemessage.close}", 'leavemessage.close': ${msgjs:leavemessage.close},
'leavemessage.descr': "${msg:leavemessage.descr}", 'leavemessage.descr': ${msgjs:leavemessage.descr},
'leavemessage.sent.message': "${msg:leavemessage.sent.message}", 'leavemessage.sent.message': ${msgjs:leavemessage.sent.message},
'leavemessage.error.email.required': '${page:localized.email.required}', 'leavemessage.error.email.required': ${pagejs:localized.email.required},
'leavemessage.error.name.required': '${page:localized.name.required}', 'leavemessage.error.name.required': ${pagejs:localized.name.required},
'leavemessage.error.message.required': '${page:localized.message.required}', 'leavemessage.error.message.required': ${pagejs:localized.message.required},
'leavemessage.error.wrong.email': '${page:localized.wrong.email}', 'leavemessage.error.wrong.email': ${pagejs:localized.wrong.email},
'errors.captcha': '${msg:errors.captcha}', 'errors.captcha': ${msgjs:errors.captcha},
'mailthread.perform': "${msg:mailthread.perform}", 'mailthread.perform': ${msgjs:mailthread.perform},
'presurvey.name': "${msg:presurvey.name}", 'presurvey.name': ${msgjs:presurvey.name},
'presurvey.mail': "${msg:presurvey.mail}", 'presurvey.mail': ${msgjs:presurvey.mail},
'presurvey.question': "${msg:presurvey.question}", 'presurvey.question': ${msgjs:presurvey.question},
'presurvey.submit': "${msg:presurvey.submit}", 'presurvey.submit': ${msgjs:presurvey.submit},
'presurvey.error.wrong_email': "${msg:presurvey.error.wrong_email}", 'presurvey.error.wrong_email': ${msgjs:presurvey.error.wrong_email},
'presurvey.title': "${msg:presurvey.title}", 'presurvey.title': ${msgjs:presurvey.title},
'presurvey.intro': '${msg:presurvey.intro}' 'presurvey.intro': ${msgjs:presurvey.intro}
}); });
//--></script> //--></script>
@ -85,11 +85,11 @@
webimRoot: '${webimroot}', webimRoot: '${webimroot}',
tplRoot: '${tplroot}', tplRoot: '${tplroot}',
company: { company: {
name: '${page:company.name}', name: ${pagejs:company.name},
chatLogoURL: '${page:company.chatLogoURL}' chatLogoURL: '${page:company.chatLogoURL}'
}, },
webimHost: '${page:webimHost}', webimHost: '${page:webimHost}',
title: '${page:page.title}' title: ${pagejs:page.title}
}, },
${if:chatOptions} ${if:chatOptions}
chatOptions: ${page:chatOptions}, chatOptions: ${page:chatOptions},