/** * Deletes old XMPP accounts based on lactivity field value. * * Deletes only chat and visitors accounts, NOT operators. * Old account is considered if from last login has passed more than 1 day * * Are called in these methods * * @see erLhcoreClassExtensionXmppserviceHandler::newChat() * @see erLhcoreClassExtensionXmppserviceHandler::newOnlineVisitor() */ public static function cleanupOldXMPPAccounts() { $oldAccounts = erLhcoreClassModelXMPPAccount::getList(array('filterin' => array('type' => array(erLhcoreClassModelXMPPAccount::USER_TYPE_CHAT, erLhcoreClassModelXMPPAccount::USER_TYPE_VISITOR)), 'filterlt' => array('lactivity' => time() - 24 * 3600))); foreach ($oldAccounts as $xmppAccount) { $xmppAccount->removeThis(); } }
public function sendMessageToAllDepartmentOperators($params) { if ($this->settings['enabled'] == true) { // Determine what operators should receive this message $db = ezcDbInstance::get(); $stmt = $db->prepare("SELECT user_id FROM lh_userdep WHERE dep_id = 0 OR dep_id = :dep_id AND lh_userdep.last_activity > :last_activity"); $stmt->bindValue(':dep_id', $params['chat']->dep_id, PDO::PARAM_INT); $stmt->bindValue(':last_activity', time() - (int) erLhcoreClassModelChatConfig::fetch('sync_sound_settings')->data['online_timeout'], PDO::PARAM_INT); $stmt->execute(); $usersId = $stmt->fetchAll(PDO::FETCH_COLUMN); if (!empty($usersId)) { $accountsXMPP = erLhcoreClassModelXMPPAccount::getList(array('filter' => array('type' => erLhcoreClassModelXMPPAccount::USER_TYPE_OPERATOR, 'sendmessage' => 1), 'filterin' => array('user_id' => $usersId))); // Change user nick to proper one $rpc = new \GameNet\Jabber\RpcClient(array('server' => $this->settings['rpc_server'], 'host' => $this->settings['xmpp_host'], 'account_host' => $this->settings['rpc_account_host'], 'username' => $this->settings['rpc_username'], 'password' => $this->settings['rpc_password'])); $paramsOnlineUser = erLhcoreClassExtensionXmppserviceHandler::getNickAndStatusByChat($params['chat']); // Nick $rpc->setNick($params['xmpp_account']->username_plain, $paramsOnlineUser['nick'], $paramsOnlineUser['status']); // Send messages foreach ($accountsXMPP as $xmppAccountOpetrator) { if ($params['msg'] === false) { $params['msg'] = new stdClass(); $params['msg']->msg = 'New chat request from visitor. Reply to accept a chat'; } erLhcoreClassExtensionXmppserviceHandler::sendMessageStartChat(array('xmpp_account' => $params['xmpp_account'], 'xmpp_account_operator' => $xmppAccountOpetrator, 'host_login' => $this->settings['host_login'], 'node_api_server' => $this->settings['node_api_server'], 'chat' => $params['chat'], 'msg' => $params['msg'], 'handler' => $this->settings['handler'], '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'], 'xmpp_host' => $this->settings['xmpp_host'])); } } } }
<?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')));