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!')); } }
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]); }
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')); }
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')); }
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; }
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; }
public function getModuleTranslations() { $metaData = array('path' => array('url' => erLhcoreClassDesign::baseurl('browseoffer/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('browseoffer/index', 'Browse offers')), 'permission_delete' => array('module' => 'lhbrowseoffer', 'function' => 'manage_bo'), 'permission' => array('module' => 'lhbrowseoffer', 'function' => 'manage_bo'), 'name' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/browserofferinvitation', 'Browser offer invitations')); /** * Get's executed before permissions check. It can redirect to frontpage throw permission exception etc * */ erLhcoreClassChatEventDispatcher::getInstance()->dispatch('feature.can_use_browse_offers', array('object_meta_data' => &$metaData)); return $metaData; }
public function getModuleTranslations() { $metaData = array('permission_delete' => array('module' => 'lhsurvey', 'function' => 'manage_survey'), 'permission' => array('module' => 'lhsurvey', 'function' => 'manage_survey'), 'name' => erTranslationClassLhTranslation::getInstance()->getTranslation('abstract/survey', 'Survey')); /** * Get's executed before permissions check. It can redirect to frontpage throw permission exception etc * */ erLhcoreClassChatEventDispatcher::getInstance()->dispatch('feature.can_use_survey', array('object_meta_data' => &$metaData)); return $metaData; }
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); }
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; }
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; }
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; }
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'); }
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; }
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); }
/** * 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; }
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); } }
public static function validateXMPPAccount(erLhcoreClassModelXMPPAccount &$xmppAccount) { $definition = array('username' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'password' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'user_id' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'int', array('min_range' => 1)), 'sendmessage' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean')); $form = new ezcInputForm(INPUT_POST, $definition); $Errors = array(); // Username is available only for new accounts if ($xmppAccount->id == 0) { if (!$form->hasValidData('username') || $form->username == '') { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please enter a username'); } else { if (strpos($form->username, 'visitor') === false) { if (preg_match('/[^a-z_0-9]/i', $form->username)) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Not allowed characters detected'); } elseif ($form->username != 'admin') { $subdomain = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['subdomain']; $xmppAccount->username = $form->username . ($subdomain != '' ? '.' . $subdomain : '') . '@' . erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['xmpp_host']; } else { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Admin is reserved username and can not be used'); } } else { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Username cannot start with visitor keyword'); } } } if ($xmppAccount->id == 0) { if (!$form->hasValidData('password') || $form->password == '') { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please enter a password'); } else { $xmppAccount->password = $form->password; } } else { if ($form->hasValidData('password') && $form->password != '') { $xmppAccount->password = $form->password; } } if ($form->hasValidData('user_id')) { $xmppAccount->user_id = $form->user_id; } else { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/operatorvalidator', 'Please choose opeator id!'); } if ($form->hasValidData('sendmessage') && $form->sendmessage == true) { $xmppAccount->sendmessage = 1; } else { $xmppAccount->sendmessage = 0; } return $Errors; }
/** * Arguments * array('chat' => & $chat) * */ public function sevabot($params) { $settings = (include 'extension/sevabot/settings/settings.ini.php'); // Format message content $chat = $params['chat']; $messages = array_reverse(erLhcoreClassModelmsg::getList(array('limit' => 5, '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"; } } $cfgSite = erConfigClassLhConfig::getInstance(); $secretHash = $cfgSite->getSetting('site', 'secrethash'); $chatDataItems = $settings['chat']; if (isset($settings['chat_dep'][$chat->dep_id]) && !empty($settings['chat_dep'][$chat->dep_id])) { $chatDataItems = array_merge($chatDataItems, $settings['chat_dep'][$chat->dep_id]); } // Global notifications foreach ($chatDataItems as $chatData) { $veryfyEmail = sha1(sha1($chatData['email'] . $secretHash) . $secretHash); $msgParsed = str_replace(array('{messages}', '{url_accept}', '{chat_id}', '{user_name}'), array($messagesContent, erLhcoreClassXMP::getBaseHost() . $_SERVER['HTTP_HOST'] . erLhcoreClassDesign::baseurl('chat/accept') . '/' . erLhcoreClassModelChatAccept::generateAcceptLink($chat) . '/' . $veryfyEmail . '/' . $chatData['email'], $chat->id, $chat->user_name), $settings['msg']); $md5 = md5($chatData['chat_id'] . $msgParsed . $settings['sevabot_secret']); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $settings['url']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, array('md5' => $md5, 'msg' => $msgParsed, 'chat' => $chatData['chat_id'])); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Some hostings produces wargning... $content = curl_exec($ch); if ($content != 'OK') { erLhcoreClassLog::write(print_r($content, true)); } } }
public static function validateFaq(&$faq) { $definition = array('answer' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'question' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'URL' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'Email' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'validate_email'), 'Identifier' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw'), 'ActiveFAQ' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'boolean')); $form = new ezcInputForm(INPUT_POST, $definition); $Errors = array(); if (!$form->hasValidData('answer') || $form->answer == '') { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('faq/view', 'Please enter answer!'); } else { $faq->answer = $form->answer; } if ($form->hasValidData('Identifier') && $form->Identifier != '') { if (mb_strlen($form->Identifier) <= 10) { $faq->identifier = $form->Identifier; } else { $faq->identifier = $form->Identifier; $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('faq/view', 'Identifier has to be shorter than 10 characters!'); } } else { $faq->identifier = ''; } if ($form->hasValidData('Email')) { $faq->email = $form->Email; } else { $faq->email = ''; } if (!$form->hasValidData('question') || $form->question == '') { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('faq/view', 'Please enter question!'); } else { $faq->question = $form->question; } if ($form->hasValidData('URL')) { $faq->url = $form->URL; } else { $faq->url = ''; } if ($form->hasValidData('ActiveFAQ') && $form->ActiveFAQ == true) { $faq->active = 1; } else { $faq->active = 0; } return $Errors; }
<label><input type="checkbox" id="DisableMiminize" value="on"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode', 'Disable minimize icon'); ?> </label> <label><input type="checkbox" id="ShowContent" value="on"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode', 'Show chatbox content instead of widget, users will be able only minimize, not close it.'); ?> </label> <label><input type="checkbox" id="ShowContentMinimized" value="on"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode', 'Show chatbox content minimized first time if content is shown.'); ?> </label> <p class="explain"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode', 'Copy the code from the text area to the footer, before the closing </body> tag'); ?> </p> <textarea style="width:100%;height:180px;font-size:12px;" id="HMLTContent" ></textarea> <script type="text/javascript"> var default_site_access = '<?php echo erConfigClassLhConfig::getInstance()->getSetting('site', 'default_site_access'); ?> /'; function generateEmbedCode(){ var siteAccess = $('#LocaleID').val() == default_site_access ? '' : $('#LocaleID').val(); var id_position = '/(position)/'+$('#PositionID').val(); var textStatus = $('#id_status_text').val(); var top = '/(top)/'+($('#id_top_text').val() == '' ? 300 : $('#id_top_text').val());
</div> <hr> </div> <?php } ?> <?php if ($closedTabEnabled == true) { ?> <div ng-show="closed_chats.list.length > 0"> <h5><a href="<?php echo erLhcoreClassDesign::baseurl('chat/closedchats'); ?> "><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('pagelayout/pagelayout', 'Closed chats'); ?> </a></h5> <div id="right-closed-chats"> <?php include erLhcoreClassDesign::designtpl('lhchat/lists/angular_closed_list.tpl.php'); ?> </div> </div> <?php } ?> </div> <?php }
<h2><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('questionary/previewanswer', 'Preview the answer'); ?> </h2> <p><?php echo erLhcoreClassBBCode::make_clickable(htmlspecialchars($answer->answer)); ?> </p> <br>
<?php $faq = new erLhcoreClassModelFaq(); $response = erLhcoreClassChatEventDispatcher::getInstance()->dispatch('faq.new', array('faq' => $faq)); $tpl = erLhcoreClassTemplate::getInstance('lhfaq/new.tpl.php'); if (isset($_POST['Save'])) { if (!isset($_POST['csfr_token']) || !$currentUser->validateCSFRToken($_POST['csfr_token'])) { erLhcoreClassModule::redirect(); exit; } $Errors = erLhcoreClassFaq::validateFaq($faq); if (count($Errors) == 0) { $faq->saveThis(); erLhcoreClassChatEventDispatcher::getInstance()->dispatch('faq.created', array('faq' => &$faq)); erLhcoreClassModule::redirect('faq/list'); exit; } else { $tpl->set('errors', $Errors); } } if (isset($_POST['Cancel'])) { erLhcoreClassModule::redirect('faq/list'); exit; } $tpl->set('faq', $faq); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('faq/list'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('faq/list', 'FAQ')), array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('faq/new', 'New question')));
?> btop-reset btrad-reset mb0<?php } ?> " placeholder="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Type your message here and hit enter to send...'); ?> " id="id_Question" name="Question"><?php echo htmlspecialchars($input_data->question); ?> </textarea> <?php if ($hasExtraField === true) { ?> <div class="btn-group" role="group" aria-label="..."> <input type="submit" name="askQuestionAction" id="idaskQuestionAction" value="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Send'); ?> " class="btn btn-default btn-sm"/> <?php } ?> <?php include erLhcoreClassDesign::designtpl('lhchat/part/readoperatormessage_button_multiinclude.tpl.php'); if ($hasExtraField === true) { ?> </div> <?php }
public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new erTranslationClassLhTranslation(); } return self::$instance; }
$chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $Params['user_parameters']['chat_id']); if (erLhcoreClassChat::hasAccessToRead($chat)) { $browse = erLhcoreClassCoBrowse::getBrowseInstance($chat); } } if ($browse instanceof erLhcoreClassModelCoBrowse) { if ($browse->modifications != '') { $changes = json_decode($browse->modifications); $changes[] = array('url' => $browse->url); $changes[] = array('lmsg' => $browse->mtime > 0 ? $browse->mtime_front : ''); $changes[] = array('finished' => array('status' => !$browse->is_sharing, 'text' => $browse->is_sharing == 0 ? erTranslationClassLhTranslation::getInstance()->getTranslation('cobrowse/browse', 'Screen sharing session has finished') : erTranslationClassLhTranslation::getInstance()->getTranslation('cobrowse/browse', 'Screen is shared'))); if ($browse->finished == 1) { $changes[] = array('clear' => true); } array_unshift($changes, array('base' => $browse->url)); echo json_encode($changes); $browse->modifications = ''; $browse->saveThis(); } else { $changes = array(); $changes[] = array('lmsg' => $browse->mtime > 0 ? $browse->mtime_front : ''); $changes[] = array('finished' => array('status' => !$browse->is_sharing, 'text' => $browse->is_sharing == 0 ? erTranslationClassLhTranslation::getInstance()->getTranslation('cobrowse/browse', 'Screen sharing session has finished') : erTranslationClassLhTranslation::getInstance()->getTranslation('cobrowse/browse', 'Screen is shared'))); if ($browse->finished == 1) { $changes[] = array('clear' => true); } array_unshift($changes, array('base' => $browse->url)); echo json_encode($changes); } } } exit;
<li><a href="<?php echo erLhcoreClassDesign::baseurl('chat/list'); ?> "><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('system/configuration', 'Chats list'); ?> </a></li>
" /> </div> <div class="form-group"> <label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('faq/faqwidget', 'Question'); ?> :*</label> <textarea class="form-control" rows="3" name="question"><?php echo htmlspecialchars($item_new->question); ?> </textarea> </div> <input type="submit" class="btn btn-default btn-sm" name="sendAction" value="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('faq/faqwidget', 'Send your question'); ?> "/> <br/> <br/> <input type="hidden" value="<?php echo htmlspecialchars($referer); ?> " name="url" /> <input type="hidden" value="1" name="send"/> </form> </div> </div>
public static function exportXLS($items) { include 'lib/core/lhform/PHPExcel.php'; $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp; $cacheSettings = array('memoryCacheSize ' => '64MB'); PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->getStyle('A1:AW1')->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->setTitle('Report'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('survey/collected', 'Chats')); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('survey/collected', 'Department name')); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('survey/collected', 'Operator')); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, 1, erTranslationClassLhTranslation::getInstance()->getTranslation('survey/collected', 'Stars')); $attributes = array('virtual_chats_number', 'department_name', 'user', 'average_stars'); $i = 2; foreach ($items as $item) { foreach ($attributes as $key => $attr) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($key, $i, (string) $item->{$attr}); } $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'); }