public function __get($var) { switch ($var) { case 'mtime_front': return date('Ymd') == date('Ymd', $this->mtime) ? date(erLhcoreClassModule::$dateHourFormat, $this->mtime) : date(erLhcoreClassModule::$dateDateHourFormat, $this->mtime); break; case 'is_sharing': return $this->finished == 0 && $this->mtime > time() - 3600; break; case 'online_user': $this->online_user = false; if ($this->online_user_id > 0) { try { $this->online_user = erLhcoreClassModelChatOnlineUser::fetch($this->online_user_id); } catch (Exception $e) { $this->online_user = false; } } return $this->online_user; break; case 'chat': $this->chat = erLhcoreClassModelChat::fetch($this->chat_id); return $this->chat; break; default: break; } }
public static function removeCustomer($instance) { $cfg = erConfigClassLhConfig::getInstance(); $secretHash = $cfg->getSetting('site', 'seller_secret_hash'); $hash = sha1($instance->id . date('Ym') . $secretHash); $url = erConfigClassLhConfig::getInstance()->getSetting('site', 'http_mode') . $instance->address . '.' . $cfg->getSetting('site', 'seller_domain') . '/index.php/instance/remove/' . $instance->id . '/' . date('Ym') . '/' . $hash; $response = erLhcoreClassModelChatOnlineUser::executeRequest($url); $responseData = json_decode($response); if (isset($responseData->error) && $responseData->error == false) { self::deleteDatabase($instance->id); return true; } else { throw new Exception('Instance removement failed'); } }
<?php /** * Iterates through all instances and executes callback timeout * At the moment it's a simple foreach. In the future we may need to enahance this part * with some queues etc. * * php cron.php -s site_admin -e instance -c cron/extensions_update * */ $cfg = erConfigClassLhConfig::getInstance(); $db = ezcDbInstance::get(); foreach (erLhcoreClassModelInstance::getList(array('limit' => 1000000, 'filter' => array('status' => erLhcoreClassModelInstance::WORKING))) as $instance) { echo "Executing request to update instance internal structure for extensions - ", $instance->id, "\n"; $secretHash = $cfg->getSetting('site', 'seller_secret_hash'); $hash = sha1($instance->id . 'extensions' . date('Ym') . $secretHash); if ($instance->full_domain == 1) { $url = erConfigClassLhConfig::getInstance()->getSetting('site', 'http_mode') . $instance->address . '/index.php/instance/extensionsstructure/' . $instance->id . '/' . date('Ym') . '/' . $hash; } else { $url = erConfigClassLhConfig::getInstance()->getSetting('site', 'http_mode') . $instance->address . '.' . $cfg->getSetting('site', 'seller_domain') . '/index.php/instance/extensionsstructure/' . $instance->id . '/' . date('Ym') . '/' . $hash; } $response = erLhcoreClassModelChatOnlineUser::executeRequest($url); echo "Response:\n"; print_r($response); echo PHP_EOL; }
<?php if ((string) $Params['user_parameters_unordered']['action'] == 'statusdb' || (string) $Params['user_parameters_unordered']['action'] == 'statusdbdoupdate') { if (!isset($_SERVER['HTTP_X_CSRFTOKEN']) || !$currentUser->validateCSFRToken($_SERVER['HTTP_X_CSRFTOKEN'])) { echo json_encode(array('error' => 'true', 'result' => 'Invalid CSRF Token')); exit; } $tpl = erLhcoreClassTemplate::getInstance('lhsystem/update/statusdb.tpl.php'); $contentData = erLhcoreClassModelChatOnlineUser::executeRequest('https://raw.githubusercontent.com/LiveHelperChat/livehelperchat/master/lhc_web/doc/update_db/structure.json'); if ((string) $Params['user_parameters_unordered']['action'] == 'statusdbdoupdate') { erLhcoreClassUpdate::doTablesUpdate(json_decode($contentData, true)); } $tables = erLhcoreClassUpdate::getTablesStatus(json_decode($contentData, true)); $tpl->set('tables', $tables); echo json_encode(array('result' => $tpl->fetch())); exit; } $tpl = erLhcoreClassTemplate::getInstance('lhsystem/update.tpl.php'); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('system/configuration'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('system/htmlcode', 'System configuration')), array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('system/update', 'Live Helper Chat update information')));
<?php header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); $tpl = erLhcoreClassTemplate::getInstance('lhchat/readoperatormessage.tpl.php'); $tpl->set('referer', ''); $tpl->set('referer_site', ''); $userInstance = erLhcoreClassModelChatOnlineUser::handleRequest(array('message_seen_timeout' => erLhcoreClassModelChatConfig::fetch('message_seen_timeout')->current_value, 'check_message_operator' => true, 'vid' => (string) $Params['user_parameters_unordered']['vid'])); $tpl->set('visitor', $userInstance); $inputData = new stdClass(); $inputData->username = ''; $inputData->question = ''; $inputData->email = ''; if (is_array($Params['user_parameters_unordered']['department']) && count($Params['user_parameters_unordered']['department']) == 1) { erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['department']); $inputData->departament_id = array_shift($Params['user_parameters_unordered']['department']); } else { $inputData->departament_id = 0; } if (is_array($Params['user_parameters_unordered']['department'])) { erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['department']); $inputData->departament_id_array = $Params['user_parameters_unordered']['department']; } $inputData->validate_start_chat = false; $inputData->operator = (int) $Params['user_parameters_unordered']['operator']; $inputData->name_items = array(); $inputData->value_items = array(); $inputData->value_types = array(); $inputData->value_sizes = array(); $inputData->hattr = array(); if ((string) $Params['user_parameters_unordered']['vid'] != '') { $inputData->vid = (string) $Params['user_parameters_unordered']['vid'];
exit; } $activeChats = erLhcoreClassChat::getActiveChats(10); $closedChats = erLhcoreClassChat::getClosedChats(10); $pendingChats = erLhcoreClassChat::getPendingChats(10); $transferedChats = erLhcoreClassTransfer::getTransferChats(); $unreadChats = erLhcoreClassChat::getUnreadMessagesChats(10, 0); erLhcoreClassChat::prefillGetAttributes($activeChats, array('department_name'), array('updateIgnoreColumns', 'department')); erLhcoreClassChat::prefillGetAttributes($closedChats, array('department_name'), array('updateIgnoreColumns', 'department')); erLhcoreClassChat::prefillGetAttributes($pendingChats, array('department_name'), array('updateIgnoreColumns', 'department')); erLhcoreClassChat::prefillGetAttributes($unreadChats, array('department_name'), array('updateIgnoreColumns', 'department')); $onlineUsers = array(); if ($currentUser->hasAccessTo('lhchat', 'use_onlineusers')) { $filter = array('offset' => 0, 'limit' => 50, 'sort' => 'last_visit DESC', 'filtergt' => array('last_visit' => time() - 3600)); $departmentParams = array(); $userDepartments = erLhcoreClassUserDep::parseUserDepartmetnsForFilter($currentUser->getUserID()); if ($userDepartments !== true) { $departmentParams['filterin']['id'] = $userDepartments; if (!$currentUser->hasAccessTo('lhchat', 'sees_all_online_visitors')) { $filter['filterin']['dep_id'] = $userDepartments; } } $onlineUsers = erLhcoreClassModelChatOnlineUser::getList($filter); } $columnsToHide = array('user_closed_ts', 'tslasign', 'reinform_timeout', 'unread_messages_informed', 'wait_timeout', 'wait_timeout_send', 'status_sub', 'timeout_message', 'nc_cb_executed', 'fbst', 'user_id', 'transfer_timeout_ts', 'operator_typing_id', 'transfer_timeout_ac', 'transfer_if_na', 'na_cb_executed', 'status', 'remarks', 'operation', 'operation_admin', 'screenshot_id', 'mail_send', 'online_user_id', 'dep_id', 'last_msg_id', 'hash', 'user_status', 'support_informed', 'support_informed', 'country_code', 'user_typing', 'user_typing_txt', 'lat', 'lon', 'chat_initiator', 'chat_variables', 'chat_duration', 'operator_typing', 'has_unread_messages', 'last_user_msg_time', 'additional_data'); $columnsName = array('id' => 'ID', 'user_tz_identifier' => 'User time zone', 'department_name' => 'Department', 'nick' => 'Nick', 'time' => 'Time', 'referrer' => 'Referrer', 'session_referrer' => 'Original referrer', 'ip' => 'IP', 'country_name' => 'Country', 'email' => 'E-mail', 'priority' => 'Priority', 'name' => 'Department', 'phone' => 'Phone', 'city' => 'City', 'wait_time' => 'Waited'); $onlineuserscolumnsToHide = array('requires_phone', 'lat_check_time', 'dep_id', 'requires_email', 'requires_username', 'invitation_seen_count', 'screenshot_id', 'operation', 'reopen_chat', 'vid', 'user_country_code', 'invitation_assigned', 'current_page', 'chat_id', 'operator_user_id', 'message_seen', 'operator_user_proactive', 'message_seen_ts', 'lat', 'lon', 'invitation_id', 'time_on_site', 'tt_time_on_site', 'invitation_count', 'store_chat'); $onlineuserscolumnsNames = array('last_check_time' => 'Last online check', 'notes' => 'Notes', 'referrer' => 'Referrer', 'page_title' => 'Page title', 'visitor_tz' => 'Visitor time zone', 'online_attr' => 'Attributes', 'id' => 'ID', 'operator_message' => 'Operator message', 'ip' => 'IP', 'identifier' => 'Identifier', 'user_agent' => 'Browser', 'last_visit' => 'Last visit', 'first_visit' => 'First visit', 'total_visits' => 'Total visits', 'user_country_name' => 'Country', 'city' => 'City', 'pages_count' => 'Pages viewed', 'tt_pages_count' => 'Total pages viewed'); echo json_encode(array('active_chats' => array('rows' => $activeChats, 'size' => count($activeChats), 'hidden_columns' => $columnsToHide, 'timestamp_delegate' => array('time'), 'column_names' => $columnsName), 'unread_chats' => array('rows' => $unreadChats, 'size' => count($unreadChats), 'hidden_columns' => $columnsToHide, 'timestamp_delegate' => array('time'), 'column_names' => $columnsName), 'online_users' => array('rows' => $onlineUsers, 'size' => count($onlineUsers), 'hidden_columns' => $onlineuserscolumnsToHide, 'column_names' => $onlineuserscolumnsNames, 'timestamp_delegate' => array('last_check_time', 'last_visit', 'first_visit')), 'closed_chats' => array('rows' => $closedChats, 'size' => count($closedChats), 'hidden_columns' => $columnsToHide, 'timestamp_delegate' => array('time'), 'column_names' => $columnsName), 'pending_chats' => array('rows' => $pendingChats, 'size' => count($pendingChats), 'hidden_columns' => $columnsToHide, 'timestamp_delegate' => array('time'), 'column_names' => $columnsName), 'transfered_chats' => array('rows' => $transferedChats, 'size' => count($transferedChats), 'hidden_columns' => array_merge($columnsToHide, array('transfer_id')), 'timestamp_delegate' => array('time'), 'column_names' => $columnsName))); $currentUser->updateLastVisit(); exit;
<?php $online_user = erLhcoreClassModelChatOnlineUser::fetchByVid($Params['user_parameters']['vid']); if ($online_user !== false && isset($online_user->online_attr_system_array['ishare_enabled']) && $online_user->online_attr_system_array['ishare_enabled'] == 1) { $fileData = erLhcoreClassModelChatConfig::fetch('file_configuration'); $data = (array) $fileData->data; $path = 'var/storage/' . date('Y') . 'y/' . date('m') . '/' . date('d') . '/ou' . $online_user->id . '/'; erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.uploadfile.file_path', array('path' => &$path, 'storage_id' => $online_user->id)); $upload_handler = new erLhcoreClassFileUpload(array('user_id' => 0, 'max_file_size' => $data['fs_max'] * 1024, 'accept_file_types_lhc' => '/\\.(' . $data['ft_us'] . ')$/i', 'online_user' => $online_user, 'download_via_php' => true, 'upload_dir' => $path)); if ($upload_handler->uploadedFile instanceof erLhcoreClassModelChatFile) { erLhcoreClassChatEventDispatcher::getInstance()->dispatch('file.uploadfile.file_store', array('chat_file' => $upload_handler->uploadedFile)); } echo json_encode(array('error' => 'false')); } exit;
<?php $tpl = erLhcoreClassTemplate::getInstance('lhxml/userinfo.tpl.php'); try { $onlineUsers = erLhcoreClassModelChatOnlineUser::fetch((int) $Params['user_parameters']['user_id']); $tpl->set('onlineUsers', $onlineUsers); echo json_encode(array('user' => $tpl->fetch())); } catch (Exception $e) { echo json_encode(array('user' => '-')); } exit;
<?php header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"'); header('Content-type: text/javascript'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time() + 60 * 60 * 8) . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); $ignorable_ip = erLhcoreClassModelChatConfig::fetch('ignorable_ip')->current_value; if ($ignorable_ip == '' || !erLhcoreClassIPDetect::isIgnored(erLhcoreClassIPDetect::getIP(), explode(',', $ignorable_ip))) { if (is_array($Params['user_parameters_unordered']['department'])) { erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['department']); $department = $Params['user_parameters_unordered']['department']; } else { $department = false; } $userInstance = erLhcoreClassModelChatOnlineUser::handleRequest(array('uactiv' => (int) $Params['user_parameters_unordered']['uactiv'], 'wopen' => (int) $Params['user_parameters_unordered']['wopen'], 'tz' => $Params['user_parameters_unordered']['tz'], 'message_seen_timeout' => erLhcoreClassModelChatConfig::fetch('message_seen_timeout')->current_value, 'department' => $department, 'identifier' => (string) $Params['user_parameters_unordered']['identifier'], 'pages_count' => true, 'vid' => (string) $Params['user_parameters_unordered']['vid'])); if (erLhcoreClassModelChatConfig::fetch('track_footprint')->current_value == 1 && isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) { erLhcoreClassModelChatOnlineUserFootprint::addPageView($userInstance); } } exit;
if ($ignorable_ip == '' || !erLhcoreClassIPDetect::isIgnored(erLhcoreClassIPDetect::getIP(), explode(',', $ignorable_ip))) { $tpl = erLhcoreClassTemplate::getInstance('lhchat/chatcheckoperatormessage.tpl.php'); if (is_array($Params['user_parameters_unordered']['department'])) { erLhcoreClassChat::validateFilterIn($Params['user_parameters_unordered']['department']); $department = $Params['user_parameters_unordered']['department']; } else { $department = false; } if (is_array($Params['user_parameters_unordered']['ua'])) { $uarguments = $Params['user_parameters_unordered']['ua']; } else { $uarguments = false; } $proactiveInviteActive = erLhcoreClassModelChatConfig::fetch('pro_active_invite')->current_value; erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.chatcheckoperatormessage', array('proactive_active' => &$proactiveInviteActive)); $userInstance = erLhcoreClassModelChatOnlineUser::handleRequest(array('uactiv' => (int) $Params['user_parameters_unordered']['uactiv'], 'wopen' => (int) $Params['user_parameters_unordered']['wopen'], 'tpl' => &$tpl, 'tz' => $Params['user_parameters_unordered']['tz'], 'message_seen_timeout' => erLhcoreClassModelChatConfig::fetch('message_seen_timeout')->current_value, 'department' => $department, 'identifier' => (string) $Params['user_parameters_unordered']['identifier'], 'pages_count' => (int) $Params['user_parameters_unordered']['count_page'] == 1 ? true : false, 'vid' => (string) $Params['user_parameters_unordered']['vid'], 'check_message_operator' => true, 'pro_active_limitation' => erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value, 'pro_active_invite' => $proactiveInviteActive)); // Exit if not required $statusGeoAdjustment = erLhcoreClassChat::getAdjustment(erLhcoreClassModelChatConfig::fetch('geoadjustment_data')->data_value, '', false, $userInstance); if ($statusGeoAdjustment['status'] == 'offline' || $statusGeoAdjustment['status'] == 'hidden') { echo "lh_inst.stopCheckNewMessage();"; // Stop check for messages and save resources exit; } if ((int) $Params['user_parameters_unordered']['count_page'] == 1 && erLhcoreClassModelChatConfig::fetch('track_footprint')->current_value == 1 && isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER'])) { erLhcoreClassModelChatOnlineUserFootprint::addPageView($userInstance); } if ($userInstance !== false) { if ($userInstance->invitation_id == -1) { $userInstance->invitation_id = 0; $userInstance->invitation_assigned = true; $userInstance->saveThis();
public static function handleRequest($paramsHandle = array()) { if (isset($_SERVER['HTTP_USER_AGENT']) && !self::isBot($_SERVER['HTTP_USER_AGENT'])) { $newVisitor = false; if (isset($paramsHandle['vid']) && !empty($paramsHandle['vid'])) { $items = erLhcoreClassModelChatOnlineUser::getList(array('filter' => array('vid' => $paramsHandle['vid']))); if (!empty($items)) { $item = array_shift($items); // Visit duration les than 30m. Same as google analytics // See: https://support.google.com/analytics/answer/2731565?hl=en if (time() - $item->last_visit <= 30 * 60) { $item->time_on_site += time() - $item->last_visit; $item->tt_time_on_site += time() - $item->last_visit; } else { $item->time_on_site = 0; $item->total_visits++; $item->last_visit = time(); $item->pages_count = 0; // Reset chat_id only if chat is not active or pending if ($item->chat_id > 0) { if ($item->chat === false || !in_array($item->chat->status, array(erLhcoreClassModelChat::STATUS_ACTIVE_CHAT, erLhcoreClassModelChat::STATUS_PENDING_CHAT))) { $item->chat_id = 0; } } if ($item->message_seen == 1 && $item->message_seen_ts < time() - (int) $paramsHandle['message_seen_timeout'] * 3600) { $item->message_seen = 0; $item->message_seen_ts = 0; $item->operator_message = ''; } } $item->identifier = isset($paramsHandle['identifier']) && !empty($paramsHandle['identifier']) ? $paramsHandle['identifier'] : $item->identifier; if (isset($paramsHandle['department']) && is_array($paramsHandle['department']) && count($paramsHandle['department']) == 1) { $item->dep_id = array_shift($paramsHandle['department']); } elseif (isset($paramsHandle['department']) && is_numeric($paramsHandle['department'])) { $item->dep_id = (int) $paramsHandle['department']; } } else { $item = new erLhcoreClassModelChatOnlineUser(); $item->ip = erLhcoreClassIPDetect::getIP(); $item->vid = $paramsHandle['vid']; $item->identifier = isset($paramsHandle['identifier']) && !empty($paramsHandle['identifier']) ? $paramsHandle['identifier'] : ''; $item->referrer = isset($_GET['r']) ? rawurldecode($_GET['r']) : ''; $item->total_visits = 1; if (isset($paramsHandle['department']) && is_array($paramsHandle['department']) && count($paramsHandle['department']) == 1) { $item->dep_id = array_shift($paramsHandle['department']); } elseif (isset($paramsHandle['department']) && is_numeric($paramsHandle['department'])) { $item->dep_id = (int) $paramsHandle['department']; } if (isset($paramsHandle['tz']) && is_numeric($paramsHandle['tz'])) { $timezone_name = timezone_name_from_abbr(null, (int) $paramsHandle['tz'] * 3600, true); if ($timezone_name !== false) { $item->visitor_tz = $timezone_name; } } self::detectLocation($item); // Cleanup database then new user comes self::cleanupOnlineUsers(); $item->store_chat = true; $newVisitor = true; } } else { self::cleanupOnlineUsers(); return false; } if (isset($paramsHandle['pages_count']) && $paramsHandle['pages_count'] == true) { $item->pages_count++; $item->tt_pages_count++; $item->store_chat = true; if (isset($_GET['onattr']) && is_array($_GET['onattr']) && !empty($_GET['onattr'])) { $item->online_attr = json_encode($_GET['onattr']); } if ($item->has_message_from_operator == true) { $item->invitation_seen_count++; } if (isset($paramsHandle['tz']) && is_numeric($paramsHandle['tz']) && $item->visitor_tz == '') { $timezone_name = timezone_name_from_abbr(null, (int) $paramsHandle['tz'] * 3600, true); if ($timezone_name !== false) { $item->visitor_tz = $timezone_name; } } // Hide invitation message after n times if required if ($item->has_message_from_operator == true && $item->invitation !== false && $item->invitation->hide_after_ntimes > 0 && $item->invitation_seen_count > $item->invitation->hide_after_ntimes) { $item->message_seen = 1; $item->message_seen_ts = time(); } } $logPageView = false; // Update variables only if it's not JS to check for operator message if (!isset($paramsHandle['check_message_operator']) || isset($paramsHandle['pages_count']) && $paramsHandle['pages_count'] == true) { $item->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $item->current_page = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $item->page_title = isset($_GET['dt']) ? (string) rawurldecode($_GET['dt']) : ''; $item->last_visit = time(); $item->store_chat = true; $logPageView = true; } if ((!isset($paramsHandle['wopen']) || $paramsHandle['wopen'] == 0) && $item->operator_message == '' && isset($paramsHandle['pro_active_invite']) && $paramsHandle['pro_active_invite'] == 1 && isset($paramsHandle['pro_active_limitation']) && ($paramsHandle['pro_active_limitation'] == -1 || erLhcoreClassChat::getPendingChatsCountPublic($item->dep_id > 0 ? $item->dep_id : false) <= $paramsHandle['pro_active_limitation'])) { //Process pro active chat invitation if this visitor matches any rules erLhAbstractModelProactiveChatInvitation::processProActiveInvitation($item); } $activityChanged = false; if (isset($paramsHandle['uactiv'])) { $activityChanged = $item->user_active != (int) $paramsHandle['uactiv'] && $newVisitor == false; $item->user_active = (int) $paramsHandle['uactiv']; } // Save only then we have to, in general only then page view appears if ($item->store_chat == true) { $item->last_check_time = time(); $item->saveThis(); if ($newVisitor == true) { erLhcoreClassChatEventDispatcher::getInstance()->dispatch('onlineuser.created', array('tpl' => isset($paramsHandle['tpl']) ? $paramsHandle['tpl'] : false, 'ou' => &$item)); } elseif ($logPageView == true) { erLhcoreClassChatEventDispatcher::getInstance()->dispatch('onlineuser.pageview_logged', array('tpl' => isset($paramsHandle['tpl']) ? $paramsHandle['tpl'] : false, 'ou' => &$item)); } if ($activityChanged == true && $item->chat_id > 0) { erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.data_changed_chat', array('chat_id' => $item->chat_id)); } } return $item; } else { // Stop execution on google bot exit; } }
$filledAPIData = true; if ($form->hasValidData('ipinfodbAPIKey') && $form->ipinfodbAPIKey != '') { $data['ipinfodbcom_api_key'] = $form->ipinfodbAPIKey; } else { $filledAPIData = false; $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Please enter the API key!'); } if ($filledAPIData == true) { $responseDetection = erLhcoreClassModelChatOnlineUser::getUserData('ipinfodbcom', erLhcoreClassIPDetect::getServerAddress(), array('api_key' => $data['ipinfodbcom_api_key'])); if ($responseDetection == false || !isset($responseDetection->country_code)) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Setting service provider failed, please check that your service provider allows you to make requests to remote pages and your API key is correct!'); } } } elseif ($form->UseGeoIP == 'php_geoip') { $data['geo_service_identifier'] = 'php_geoip'; $responseDetection = erLhcoreClassModelChatOnlineUser::getUserData('php_geoip', '94.23.200.91'); if ($responseDetection == false || !isset($responseDetection->country_code)) { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Setting service provider failed, please check that you have installed php-GeoIP module and GeoIPCity.dat file is available!'); } } } else { $Errors[] = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/onlineusers', 'Please choose a service provider!'); } } if (count($Errors) == 0) { $geoData->value = serialize($data); $geoData->saveThis(); $tpl->set('updated', 'done'); } else { $tpl->set('errors', $Errors); }
public static function getAdjustment($geo_adjustment, $onlineUserVid = '', $widgetMode = false, $onlineUserDefined = false) { $responseStatus = array('status' => 'normal'); $onlineUser = false; if (isset($geo_adjustment['use_geo_adjustment']) && $geo_adjustment['use_geo_adjustment'] == true) { if ($widgetMode === true && $geo_adjustment['apply_widget'] == 0) { return $responseStatus; } if (is_object($onlineUserDefined)) { $onlineUser = $onlineUserDefined; } elseif (!empty($onlineUserVid)) { $onlineUser = erLhcoreClassModelChatOnlineUser::fetchByVid($onlineUserVid); } if ($onlineUser === false) { $onlineUser = new erLhcoreClassModelChatOnlineUser(); // Just to pass instance $onlineUser->ip = erLhcoreClassIPDetect::getIP(); erLhcoreClassModelChatOnlineUser::detectLocation($onlineUser); } $countriesAvailableFor = array(); if ($geo_adjustment['available_for'] != '') { $countriesAvailableFor = explode(',', $geo_adjustment['available_for']); } if (!in_array($onlineUser->user_country_code, $countriesAvailableFor)) { if ($geo_adjustment['other_countries'] == 'all') { if ($geo_adjustment['other_status'] == 'offline') { $responseStatus = array('status' => 'offline'); } else { $responseStatus = array('status' => 'hidden'); } } else { if ($geo_adjustment['hide_for'] != '') { $countrieshideFor = explode(',', $geo_adjustment['hide_for']); if (in_array($onlineUser->user_country_code, $countrieshideFor)) { if ($geo_adjustment['other_status'] == 'offline') { $responseStatus = array('status' => 'offline'); } else { $responseStatus = array('status' => 'hidden'); } } else { if ($geo_adjustment['rest_status'] == 'offline') { $responseStatus = array('status' => 'offline'); } elseif ($geo_adjustment['rest_status'] == 'normal') { $responseStatus = array('status' => 'normal'); } else { $responseStatus = array('status' => 'hidden'); } } } else { if ($geo_adjustment['rest_status'] == 'offline') { $responseStatus = array('status' => 'offline'); } elseif ($geo_adjustment['rest_status'] == 'normal') { $responseStatus = array('status' => 'normal'); } else { $responseStatus = array('status' => 'hidden'); } } } } // Normal status } return $responseStatus; }
<?php if (is_numeric($Params['user_parameters']['chat_id'])) { /* * If online user mode we have to make different check * */ $browse = false; if ($Params['user_parameters_unordered']['cobrowsemode'] == 'onlineuser') { $onlineUser = erLhcoreClassModelChatOnlineUser::fetch($Params['user_parameters']['chat_id']); $browse = erLhcoreClassCoBrowse::getBrowseInstanceByOnlineUser($onlineUser); } else { $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();
<?php header('content-type: application/json; charset=utf-8'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'); if ($Params['user_parameters_unordered']['hash'] != '' || $Params['user_parameters_unordered']['vid'] != '') { $checkHash = true; $vid = false; if ($Params['user_parameters_unordered']['hash'] != '') { list($chatID, $hash) = explode('_', $Params['user_parameters_unordered']['hash']); } else { if ($Params['user_parameters_unordered']['hash_resume'] != '') { list($chatID, $hash) = explode('_', $Params['user_parameters_unordered']['hash_resume']); } elseif ($Params['user_parameters_unordered']['vid'] != '') { $vid = erLhcoreClassModelChatOnlineUser::fetchByVid($Params['user_parameters_unordered']['vid']); if ($vid !== false) { $chatID = $vid->chat_id; $checkHash = false; } else { echo json_encode(array('stored' => 'false')); exit; } } } try { if ($chatID > 0) { $chat = erLhcoreClassChat::getSession()->load('erLhcoreClassModelChat', $chatID); } else { $chat = false; } if (($checkHash == true && $chat !== false && $chat->hash == $hash || $checkHash == false) && (is_object($vid) || ($chat !== false && $chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT || $chat->status == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT))) {
public static function detectLocation(erLhcoreClassModelChat &$instance) { $geoData = erLhcoreClassModelChatConfig::fetch('geo_data'); $geo_data = (array) $geoData->data; if (isset($geo_data['geo_detection_enabled']) && $geo_data['geo_detection_enabled'] == 1) { $params = array(); if ($geo_data['geo_service_identifier'] == 'mod_geoip2') { $params['country_code'] = $geo_data['mod_geo_ip_country_code']; $params['country_name'] = $geo_data['mod_geo_ip_country_name']; $params['mod_geo_ip_city_name'] = $geo_data['mod_geo_ip_city_name']; $params['mod_geo_ip_latitude'] = $geo_data['mod_geo_ip_latitude']; $params['mod_geo_ip_longitude'] = $geo_data['mod_geo_ip_longitude']; } elseif ($geo_data['geo_service_identifier'] == 'locatorhq') { $params['username'] = $geo_data['locatorhqusername']; $params['api_key'] = $geo_data['locatorhq_api_key']; } elseif ($geo_data['geo_service_identifier'] == 'ipinfodbcom') { $params['api_key'] = $geo_data['ipinfodbcom_api_key']; } elseif ($geo_data['geo_service_identifier'] == 'max_mind') { $params['detection_type'] = $geo_data['max_mind_detection_type']; $params['city_file'] = isset($geo_data['max_mind_city_location']) ? $geo_data['max_mind_city_location'] : ''; } $location = erLhcoreClassModelChatOnlineUser::getUserData($geo_data['geo_service_identifier'], $instance->ip, $params); if ($location !== false) { $instance->country_code = $location->country_code; $instance->country_name = $location->country_name; $instance->lat = $location->lat; $instance->lon = $location->lon; $instance->city = $location->city; } } }
/** * handles messages from operator. * Workflow sounds like that * 1. Check that we can determine an operator * 2. Check to what messages was send, to chat or online visitor * 3. If message is send to online visitor check perphaps visitor has active chat * 4. If active chat found, send a message * 5. If active chat not found send message as proactive invitation * * @param array $params * */ public static function handleMessageFromOperator($params) { try { $parts = explode('.', $params['receiver']); if (isset($parts[1])) { $xmppUserLogin = $params['sender'] . '@' . $params['server']; $xmppUser = erLhcoreClassModelXMPPAccount::findOne(array('filter' => array('username' => $xmppUserLogin))); if ($xmppUser !== false) { // It's message to online visitor if (isset($parts[2]) && $parts[2] == 'chat') { $chat = erLhcoreClassModelChat::fetch($parts[1]); $user = $xmppUser->user; // Messages to chat is only send if chat is not accepted or sender is chat owner if ($chat->user_id == $user->id || $chat->user_id == 0) { self::sendMessageToChat($chat, $xmppUser, $params['body']); } else { $xmppService = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice'); $xmppService->sendMessageToOperatorAsUserByChat(array('xmpp_account_operator' => $xmppUser, 'chat' => $chat, 'msg' => '[[System Assistant]] Chat was already accepted by [' . $chat->user . '], your messages are now ignored')); } } else { $visitorId = $parts[1]; $visitor = erLhcoreClassModelChatOnlineUser::fetch($visitorId); // We do not have any active chat if ($visitor->chat === false || !in_array($visitor->chat->status, array(erLhcoreClassModelChat::STATUS_ACTIVE_CHAT, erLhcoreClassModelChat::STATUS_PENDING_CHAT))) { $visitor->operator_message = $params['body']; $visitor->message_seen = 0; $visitor->invitation_id = -1; $visitor->operator_user_id = $xmppUser->user_id; $visitor->saveThis(); // We have active chat } else { self::sendMessageToChat($visitor->chat, $xmppUser, $params['body']); } } } else { throw new Exception('Could not find a operator'); } } else { throw new Exception('Could not extract visitor ID'); } } catch (Exception $e) { throw $e; } }