本文整理汇总了PHP中erTranslationClassLhTranslation::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP erTranslationClassLhTranslation::getInstance方法的具体用法?PHP erTranslationClassLhTranslation::getInstance怎么用?PHP erTranslationClassLhTranslation::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类erTranslationClassLhTranslation
的用法示例。
在下文中一共展示了erTranslationClassLhTranslation::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateRequest
public static function validateRequest()
{
$headers = self::getHeaders();
if (isset($headers['Authorization'])) {
$dataAuthorisation = explode(' ', $headers['Authorization']);
$apiData = explode(':', base64_decode($dataAuthorisation[1]));
if (count($apiData) != 2) {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('lhrestapi/validation', 'Authorization failed!'));
}
$apiKey = erLhAbstractModelRestAPIKey::findOne(array('enable_sql_cache' => true, 'filter' => array('active' => 1, 'api_key' => $apiData[1])));
if (!$apiKey instanceof erLhAbstractModelRestAPIKey) {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('lhrestapi/validation', 'Authorization failed!'));
}
if ($apiKey->user->username != $apiData[0]) {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('lhrestapi/validation', 'Authorization failed!'));
}
// API Key
self::$apiKey = $apiKey;
if (isset($_GET['update_activity'])) {
$db = ezcDbInstance::get();
$stmt = $db->prepare('UPDATE lh_userdep SET last_activity = :last_activity WHERE user_id = :user_id');
$stmt->bindValue(':last_activity', time(), PDO::PARAM_INT);
$stmt->bindValue(':user_id', self::$apiKey->user->id, PDO::PARAM_INT);
$stmt->execute();
}
} else {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('lhrestapi/validation', 'Authorization header is missing!'));
}
}
示例2: translate
public static function translate($access_token, $word, $from, $to)
{
$url = 'http://api.microsofttranslator.com/V2/Http.svc/Translate?text=' . urlencode($word) . '&from=' . $from . '&to=' . $to;
if (empty($word)) {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Missing text to translate'));
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization:bearer ' . $access_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$rsp = curl_exec($ch);
if (strpos($rsp, '<string') === false) {
throw new Exception($rsp);
}
$errors = array();
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('translate.after_bing_translate', array('word' => &$word, 'errors' => &$errors));
if (!empty($errors)) {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Could not translate') . ' - ' . implode('; ', $errors));
}
preg_match_all('/<string (.*?)>(.*?)<\\/string>/s', $rsp, $matches);
return htmlspecialchars_decode($matches[2][0]);
}
示例3: getModuleTranslations
public function getModuleTranslations()
{
/**
* Get's executed before permissions check. It can redirect to frontpage throw permission exception etc
* */
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('feature.can_use_proactive', array());
return array('can_use' => $can_use, 'permission_delete' => array('module' => 'lhchat', 'function' => 'administrateinvitations'), 'permission' => array('module' => 'lhchat', 'function' => 'administrateinvitations'), 'name' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/proactivechatinvitation', 'Pro active chat invitations'));
}
示例4: getModuleTranslations
public function getModuleTranslations()
{
/**
* Get's executed before permissions check. It can redirect to frontpage throw permission exception etc
* */
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('feature.can_use_forms', array());
return array('path' => array('url' => erLhcoreClassDesign::baseurl('form/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('browseoffer/index', 'Form')), 'permission_delete' => array('module' => 'lhform', 'function' => 'delete_fm'), 'permission' => array('module' => 'lhform', 'function' => 'manage_fm'), 'name' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation', 'Forms list'));
}
示例5: getModuleTranslations
public function getModuleTranslations()
{
$metaData = array('permission_delete' => array('module' => 'lhchat', 'function' => 'administrateresponder'), 'permission' => array('module' => 'lhchat', 'function' => 'administrateresponder'), 'name' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/proactivechatinvitation', 'Auto responder'));
/**
* Get's executed before permissions check. It can redirect to frontpage throw permission exception etc
* */
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('feature.can_use_autoresponder', array('object_meta_data' => &$metaData));
return $metaData;
}
示例6: getModuleTranslations
public function getModuleTranslations()
{
$metaData = array('path' => array('url' => erLhcoreClassDesign::baseurl('restapi/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('theme/index', 'Rest API')), 'permission_delete' => array('module' => 'lhrestapi', 'function' => 'use_admin'), 'permission' => array('module' => 'lhrestapi', 'function' => 'use_admin'), 'name' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/product', 'API Key'));
/**
* Get's executed before permissions check. It can redirect to frontpage throw permission exception etc
* */
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('feature.can_use_product', array('object_meta_data' => &$metaData));
return $metaData;
}
示例7: translate
public static function translate($apiKey, $word, $from, $to)
{
$url = "https://www.googleapis.com/language/translate/v2?key={$apiKey}&q=" . urlencode($word) . "&source={$from}&target={$to}";
$rsp = self::executeRequest($url);
$data = json_decode($rsp, true);
if (isset($data['data']['translations'][0]['translatedText'])) {
return htmlspecialchars_decode($data['data']['translations'][0]['translatedText']);
}
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Could not translate') . ' - ' . $rsp);
}
示例8: validateAdminTheme
public static function validateAdminTheme(erLhAbstractModelAdminTheme &$clickform)
{
$definition = array('Name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'header_content' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'header_css' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'static_content_name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_content_hash' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_js_content_name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_js_content_hash' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_css_content_name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'static_css_content_hash' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY));
$form = new ezcInputForm(INPUT_POST, $definition);
$Errors = array();
$currentUser = erLhcoreClassUser::instance();
if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token'])) {
$Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('icclicktocallform/form', 'Invalid CSRF token!');
}
if (!$form->hasValidData('Name') || $form->Name == '') {
$Errors['Name'] = erTranslationClassLhTranslation::getInstance()->getTranslation('icclicktocallform/form', 'Please enter a name');
} else {
$clickform->name = $form->Name;
}
if ($form->hasValidData('header_content')) {
$clickform->header_content = $form->header_content;
}
if ($form->hasValidData('header_css')) {
$clickform->header_css = $form->header_css;
}
$resourcesArray = array('static_content', 'static_js_content', 'static_css_content');
$supportedExtensions = array('zip', 'doc', 'docx', 'ttf', 'pdf', 'xls', 'ico', 'gif', 'xlsx', 'jpg', 'jpeg', 'png', 'bmp', 'rar', '7z', 'css', 'js', 'eot', 'woff', 'woff2', 'svg');
// Validate resources
foreach ($resourcesArray as $resource) {
if ($form->hasValidData($resource . '_hash') && !empty($form->{$resource . '_hash'})) {
$customFields = $currentStaticResources = $clickform->{$resource . '_array'};
foreach ($form->{$resource . '_hash'} as $key => $customFieldType) {
if (!erLhcoreClassSearchHandler::isFile($resource . '_file_' . $key, $supportedExtensions) && !isset($currentStaticResources[$key]['file'])) {
$Errors[$resource . '_file_' . $key] = erTranslationClassLhTranslation::getInstance()->getTranslation('icclicktocallform/form', 'File not chosen for') . (isset($form->{$resource . '_name'}[$key]) ? ' - ' . htmlspecialchars($form->{$resource . '_name'}[$key]) : '');
}
}
// If there is no errors upload files
if (empty($Errors)) {
foreach ($form->{$resource . '_hash'} as $key => $customFieldType) {
$customFields[$key]['name'] = $form->{$resource . '_name'}[$key];
$customFields[$key]['hash'] = $key;
if (erLhcoreClassSearchHandler::isFile($resource . '_file_' . $key, $supportedExtensions)) {
// Check there is already uploaded file and remove it
$clickform->removeResource($resource, $key);
// Store new file if required
$dir = 'var/storageadmintheme/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/' . $clickform->id . '/';
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('admintheme.filedir', array('dir' => &$dir, 'storage_id' => $clickform->id));
erLhcoreClassFileUpload::mkdirRecursive($dir);
$customFields[$key]['file'] = erLhcoreClassSearchHandler::moveUploadedFile($resource . '_file_' . $key, $dir . '/', '.');
$customFields[$key]['file_dir'] = $dir;
}
}
$clickform->{$resource} = json_encode($customFields, JSON_HEX_APOS);
}
} else {
$clickform->{$resource} = '';
}
}
return $Errors;
}
示例9: validateSurvey
public static function validateSurvey(erLhAbstractModelSurveyItem &$surveyItem, erLhAbstractModelSurvey $survey)
{
$definition = array('StarsValue' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1, 'max_range' => $survey->max_stars)));
$form = new ezcInputForm(INPUT_POST, $definition);
$Errors = array();
if (!$form->hasValidData('StarsValue')) {
$Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Please choose a star');
} else {
$surveyItem->stars = $form->StarsValue;
}
return $Errors;
}
示例10: validateSurvey
public static function validateSurvey(erLhAbstractModelSurveyItem &$surveyItem, erLhAbstractModelSurvey $survey)
{
include erLhcoreClassDesign::designtpl('lhsurvey/forms/fields_names.tpl.php');
$definition = array();
for ($i = 0; $i < 16; $i++) {
foreach ($sortOptions as $keyOption => $sortOption) {
if ($survey->{$keyOption . '_pos'} == $i && $survey->{$keyOption . '_enabled'}) {
if ($sortOption['type'] == 'stars') {
$definition[$sortOption['field'] . 'Evaluate'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1, 'max_range' => $survey->{$sortOption}['field']));
} elseif ($sortOption['type'] == 'question') {
$definition[$sortOption['field'] . 'Question'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw');
} elseif ($sortOption['type'] == 'question_options') {
$definition[$sortOption['field'] . 'EvaluateOption'] = new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1));
}
}
}
}
$form = new ezcInputForm(INPUT_POST, $definition);
$Errors = array();
for ($i = 0; $i < 16; $i++) {
foreach ($sortOptions as $keyOption => $sortOption) {
if ($survey->{$keyOption . '_pos'} == $i && $survey->{$keyOption . '_enabled'}) {
if ($sortOption['type'] == 'stars') {
if (!$form->hasValidData($sortOption['field'] . 'Evaluate')) {
if ($survey->{$keyOption . '_req'} == 1) {
$Errors[] = '"' . htmlspecialchars(trim($survey->{$keyOption . '_title'})) . '" : ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'is required');
}
} else {
$surveyItem->{$sortOption['field']} = $form->{$sortOption['field'] . 'Evaluate'};
}
} elseif ($sortOption['type'] == 'question') {
if (!$form->hasValidData($sortOption['field'] . 'Question') || $form->{$sortOption['field'] . 'Question'} == '' && $survey->{$keyOption . '_req'} == 1) {
// @todo Make possible to choose field type in the future
$Errors[] = '"' . htmlspecialchars(trim($survey->{$keyOption})) . '" : ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'is required');
} else {
$surveyItem->{$sortOption['field']} = $form->{$sortOption['field'] . 'Question'};
}
} elseif ($sortOption['type'] == 'question_options') {
if (!$form->hasValidData($sortOption['field'] . 'EvaluateOption')) {
if ($survey->{$keyOption . '_req'} == 1) {
$Errors[] = '"' . htmlspecialchars(trim($survey->{$sortOption['field']})) . '" : ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'is required');
}
} else {
$surveyItem->{$sortOption['field']} = $form->{$sortOption['field'] . 'EvaluateOption'};
}
}
}
}
}
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('survey.validate', array('survey' => &$survey, 'survey_item' => &$surveyItem, 'errors' => &$Errors));
return $Errors;
}
示例11: chatListExportXLS
public static function chatListExportXLS($chats)
{
include 'lib/core/lhform/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->getStyle('A1:AW1')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->setTitle('Report');
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "ID");
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Visitor Name'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'E-mail'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Phone'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Country'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'City'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'IP'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Operator'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Department'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Date'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Mail send'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Referrer'));
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('chat/chatexport', 'Link'));
$attributes = array('id', 'nick', 'email', 'phone', 'country_name', 'city', 'ip', 'user', 'department');
$i = 2;
foreach ($chats as $item) {
foreach ($attributes as $key => $attr) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, (string) $item->{$attr});
}
$key++;
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, date(erLhcoreClassModule::$dateFormat, $item->time));
$key++;
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, $item->mail_send == 1 ? 'Yes' : 'No');
$key++;
if ($item->session_referrer != '') {
$referer = parse_url($item->session_referrer);
if (isset($referer['host'])) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, $referer['host']);
}
}
$key++;
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, "URL");
$objPHPExcel->getActiveSheet()->getCellByColumnAndRow($key, $i)->getHyperlink()->setUrl(erLhcoreClassXMP::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('user/login') . '/(r)/' . rawurlencode(base64_encode('chat/single/' . $item->id)));
$i++;
}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
// We'll be outputting an excel file
header('Content-type: application/vnd.ms-excel');
// It will be called file.xls
header('Content-Disposition: attachment; filename="report.xlsx"');
// Write file to the browser
$objWriter->save('php://output');
}
示例12: fillDataByChat
public function fillDataByChat($chat)
{
$this->getConfig();
$messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5000, 'sort' => 'id DESC', 'filter' => array('chat_id' => $chat->id))));
$messagesContent = '';
foreach ($messages as $msg) {
if ($msg->user_id == -1) {
$messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncadmin', 'System assistant') . ': ' . htmlspecialchars($msg->msg) . "\n";
} else {
$messagesContent .= date(erLhcoreClassModule::$dateDateHourFormat, $msg->time) . ' ' . ($msg->user_id == 0 ? htmlspecialchars($chat->nick) : htmlspecialchars($msg->name_support)) . ': ' . htmlspecialchars($msg->msg) . "\n";
}
}
$data = array('name' => $chat->nick, 'email' => $chat->email, 'subject' => str_replace(array('{referrer}', '{nick}', '{email}', '{country_code}', '{country_name}', '{city}', '{user_tz_identifier}'), array($chat->referrer, $chat->nick, $chat->email, $chat->country_code, $chat->country_name, $chat->city, $chat->user_tz_identifier), $this->configData['subject']), 'message' => str_replace(array('{time_created_front}', '{additional_data}', '{id}', '{url}', '{referrer}', '{messages}', '{remarks}', '{nick}', '{email}', '{country_code}', '{country_name}', '{city}', '{user_tz_identifier}'), array(date(erLhcoreClassModule::$dateDateHourFormat, $chat->time), $chat->additional_data, $chat->id, (erLhcoreClassSystem::$httpsMode == true ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('user/login') . '/(r)/' . rawurlencode(base64_encode('chat/single/' . $chat->id)), $chat->referrer, $messagesContent, $chat->remarks, $chat->nick, $chat->email, $chat->country_code, $chat->country_name, $chat->city, $chat->user_tz_identifier), $this->configData['message']), 'ip' => $chat->ip);
return $data;
}
示例13: translate
public static function translate($apiKey, $word, $from, $to)
{
$url = "https://www.googleapis.com/language/translate/v2?key={$apiKey}&q=" . urlencode($word) . "&source={$from}&target={$to}";
$rsp = self::executeRequest($url);
$data = json_decode($rsp, true);
if (isset($data['data']['translations'][0]['translatedText'])) {
$errors = array();
erLhcoreClassChatEventDispatcher::getInstance()->dispatch('translate.after_google_translate', array('word' => &$word, 'errors' => &$errors));
if (!empty($errors)) {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Could not translate') . ' - ' . implode('; ', $errors));
}
return htmlspecialchars_decode($data['data']['translations'][0]['translatedText']);
}
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Could not translate') . ' - ' . $rsp);
}
示例14: setChatLanguages
/**
* Set's chat language
*
* Detects chats languages, operator and visitor and translates recent chat messages
*
* @param erLhcoreClassModelChat $chat
*
* @param string $visitorLanguage | Optional
*
* @param string $operatorLanguage | Optional
*
* @return void || Exception
* */
public static function setChatLanguages(erLhcoreClassModelChat $chat, $visitorLanguage, $operatorLanguage)
{
$originalLanguages = array('chat_locale' => $chat->chat_locale, 'chat_locale_to' => $chat->chat_locale_to);
$supportedLanguages = self::getSupportedLanguages(true);
$db = ezcDbInstance::get();
$data = array();
if (key_exists($visitorLanguage, $supportedLanguages)) {
$chat->chat_locale = $data['chat_locale'] = $visitorLanguage;
} else {
// We take few first messages from visitor and try to detect language
$stmt = $db->prepare('SELECT msg FROM lh_msg WHERE chat_id = :chat_id AND user_id = 0 ORDER BY id ASC LIMIT 3 OFFSET 0');
$stmt->bindValue(':chat_id', $chat->id);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_COLUMN);
foreach ($rows as &$row) {
$row = preg_replace('#\\[translation\\](.*?)\\[/translation\\]#is', '', $row);
}
$msgText = substr(implode("\n", $rows), 0, 500);
$languageCode = self::detectLanguage($msgText);
$chat->chat_locale = $data['chat_locale'] = $languageCode;
}
if (key_exists($operatorLanguage, $supportedLanguages)) {
$chat->chat_locale_to = $data['chat_locale_to'] = $operatorLanguage;
} else {
// We need to detect opetator language, basically we just take back office language and try to find a match
$languageCode = substr(erLhcoreClassSystem::instance()->Language, 0, 2);
if (key_exists($languageCode, $supportedLanguages)) {
$chat->chat_locale_to = $data['chat_locale_to'] = $languageCode;
} else {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'We could not detect operator language'));
}
}
if ($chat->chat_locale == $chat->chat_locale_to) {
throw new Exception(erTranslationClassLhTranslation::getInstance()->getTranslation('chat/translation', 'Detected operator and visitor languages matches, please choose languages manually'));
}
// Because chat data can be already be changed we modify just required fields
$stmt = $db->prepare('UPDATE lh_chat SET chat_locale_to = :chat_locale_to, chat_locale =:chat_locale WHERE id = :chat_id');
$stmt->bindValue(':chat_id', $chat->id, PDO::PARAM_INT);
$stmt->bindValue(':chat_locale_to', $data['chat_locale_to'], PDO::PARAM_STR);
$stmt->bindValue(':chat_locale', $data['chat_locale'], PDO::PARAM_STR);
$stmt->execute();
// We have to translate only if our languages are different
if ($originalLanguages['chat_locale'] != $chat->chat_locale || $originalLanguages['chat_locale_to'] != $chat->chat_locale_to) {
// And now we can translate all chat messages
self::translateChatMessages($chat);
}
return $data;
}
示例15: changeStatus
public static function changeStatus($params)
{
$changeStatus = $params['status'];
$chat = $params['chat'];
$userData = $params['user'];
$allowCloseRemote = $params['allow_close_remote'];
if ($changeStatus == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT) {
if ($chat->status != erLhcoreClassModelChat::STATUS_ACTIVE_CHAT) {
$chat->status = erLhcoreClassModelChat::STATUS_ACTIVE_CHAT;
$chat->wait_time = time() - $chat->time;
}
if ($chat->user_id == 0) {
$chat->user_id = $userData->id;
}
$chat->updateThis();
} elseif ($changeStatus == erLhcoreClassModelChat::STATUS_PENDING_CHAT) {
$chat->status = erLhcoreClassModelChat::STATUS_PENDING_CHAT;
$chat->support_informed = 0;
$chat->has_unread_messages = 1;
$chat->updateThis();
} elseif ($changeStatus == erLhcoreClassModelChat::STATUS_CLOSED_CHAT && $chat->user_id == $userData->id || $allowCloseRemote == true) {
if ($chat->status != erLhcoreClassModelChat::STATUS_CLOSED_CHAT) {
$chat->status = erLhcoreClassModelChat::STATUS_CLOSED_CHAT;
$chat->chat_duration = erLhcoreClassChat::getChatDurationToUpdateChatID($chat->id);
$msg = new erLhcoreClassModelmsg();
$msg->msg = (string) $userData . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/closechatadmin', 'has closed the chat!');
$msg->chat_id = $chat->id;
$msg->user_id = -1;
$chat->last_user_msg_time = $msg->time = time();
erLhcoreClassChat::getSession()->save($msg);
$chat->updateThis();
CSCacheAPC::getMem()->removeFromArray('lhc_open_chats', $chat->id);
// Execute callback for close chat
erLhcoreClassChat::closeChatCallback($chat, $userData);
}
} elseif ($changeStatus == erLhcoreClassModelChat::STATUS_CHATBOX_CHAT) {
$chat->status = erLhcoreClassModelChat::STATUS_CHATBOX_CHAT;
erLhcoreClassChat::getSession()->update($chat);
} elseif ($changeStatus == erLhcoreClassModelChat::STATUS_OPERATORS_CHAT) {
$chat->status = erLhcoreClassModelChat::STATUS_OPERATORS_CHAT;
erLhcoreClassChat::getSession()->update($chat);
}
erLhcoreClassChat::updateActiveChats($chat->user_id);
if ($chat->department !== false) {
erLhcoreClassChat::updateDepartmentStats($chat->department);
}
}