/** * get's callend then online user does a pageview * * @param array $params */ public function onlineUserPageViewLogged($params) { if ($this->settings['enabled'] == true && $this->settings['online_visitors_tracking'] == true) { $onlineOptions = erLhcoreClassModelChatConfig::fetch('xmppservice_options')->data; if (isset($onlineOptions['track_online']) && $onlineOptions['track_online'] == true) { if (($xmppAccount = erLhcoreClassModelXMPPAccount::findOne(array('filter' => array('type' => erLhcoreClassModelXMPPAccount::USER_TYPE_VISITOR, 'user_id' => $params['ou']->id)))) !== false) { if ($this->settings['handler'] == 'rpc' && is_object($params['tpl']) && $this->settings['online_visitors_tracking'] == true) { /** * In the future then websockets will support attatch method this could be used * */ /* $xmppAccount->attach_data = erLhcoreClassExtensionXmppserviceHandler::prebindSession(array( 'username' => $xmppAccount->username, 'password' => $xmppAccount->password, 'host' => $this->settings['prebind_host'] . $xmppAccount->username_plain, )); */ $params['tpl']->set('xmppAccount', $xmppAccount); } // Forward this information to NodeJS server erLhcoreClassExtensionXmppserviceHandler::onlineUserPageViewLogged(array('xmpp_account' => $xmppAccount, 'ou' => $params['ou'], 'host_login' => $this->settings['host_login'], 'node_api_server' => $this->settings['node_api_server'], 'handler' => $this->settings['handler'], 'xmpp_host' => $this->settings['xmpp_host'], 'rpc_server' => $this->settings['rpc_server'], 'rpc_username' => $this->settings['rpc_username'], 'rpc_password' => $this->settings['rpc_password'], 'rpc_account_host' => $this->settings['rpc_account_host'])); } } } }
<?php if (erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['enabled'] == false) { erLhcoreClassModule::redirect('/'); exit; } $tpl = erLhcoreClassTemplate::getInstance('lhxmppservice/editoperator.tpl.php'); $xmppaccount = erLhcoreClassModelXMPPAccount::fetch($Params['user_parameters']['id']); if (ezcInputForm::hasPostData()) { if (isset($_POST['Cancel_action'])) { erLhcoreClassModule::redirect('xmppservice/operators'); exit; } $Errors = erLhcoreClassXMPPServiceAccountValidator::validateXMPPAccount($xmppaccount); if (count($Errors) == 0) { try { erLhcoreClassXMPPServiceAccountValidator::publishXMPPAccount($xmppaccount); erLhcoreClassModule::redirect('xmppservice/operators'); exit; } catch (Exception $e) { $tpl->set('errors', array($e->getMessage())); } } else { $tpl->set('errors', $Errors); } } $tpl->setArray(array('xmppaccount' => $xmppaccount)); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('xmppservice/operators'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/module', 'XMPP Accounts')), array('title' => erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/editoperator', 'Edit operator')));
<?php if (erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice')->settings['enabled'] == false) { erLhcoreClassModule::redirect('/'); exit; } $tpl = erLhcoreClassTemplate::getInstance('lhxmppservice/operators.tpl.php'); if (isset($_GET['doSearch'])) { $filterParams = erLhcoreClassSearchHandler::getParams(array('customfilterfile' => 'extension/xmppservice/classes/filter.php', 'format_filter' => true, 'use_override' => true, 'uparams' => $Params['user_parameters_unordered'])); $filterParams['is_search'] = true; } else { $filterParams = erLhcoreClassSearchHandler::getParams(array('customfilterfile' => 'extension/xmppservice/classes/filter.php', 'format_filter' => true, 'uparams' => $Params['user_parameters_unordered'])); $filterParams['is_search'] = false; } $append = erLhcoreClassSearchHandler::getURLAppendFromInput($filterParams['input_form']); $pages = new lhPaginator(); $pages->items_total = erLhcoreClassModelXMPPAccount::getCount($filterParams['filter']); $pages->translationContext = 'chat/activechats'; $pages->serverURL = erLhcoreClassDesign::baseurl('xmppservice/operators') . $append; $pages->paginate(); $tpl->set('pages', $pages); if ($pages->items_total > 0) { $items = erLhcoreClassModelXMPPAccount::getList(array_merge(array('limit' => $pages->items_per_page, 'offset' => $pages->low), $filterParams['filter'])); $tpl->set('items', $items); } $filterParams['input_form']->form_action = erLhcoreClassDesign::baseurl('xmppservice/operators'); $tpl->set('input', $filterParams['input_form']); $tpl->set('inputAppend', $append); $Result['content'] = $tpl->fetch(); $Result['path'] = array(array('url' => erLhcoreClassDesign::baseurl('xmppservice/index'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/module', 'XMPP Service')), array('url' => erLhcoreClassDesign::baseurl('xmppservice/operators'), 'title' => erTranslationClassLhTranslation::getInstance()->getTranslation('xmppservice/module', 'XMPP Accounts')));
/** * 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; } }