/** * Generates a page with thread history (thread log). * * @param Request $request * @return string Rendered page content */ public function threadAction(Request $request) { $operator = $this->getOperator(); $page = array(); // Load thread info $thread = Thread::load($request->attributes->get('thread_id')); $group = group_by_id($thread->groupId); $thread_info = array('userName' => $thread->userName, 'userAddress' => get_user_addr($thread->remote), 'userAgentVersion' => get_user_agent_version($thread->userAgent), 'agentName' => $thread->agentName, 'chatTime' => $thread->modified - $thread->created, 'chatStarted' => $thread->created, 'groupName' => get_group_name($group)); $page['threadInfo'] = $thread_info; // Build messages list $last_id = -1; $messages = array_map('sanitize_message', $thread->getMessages(false, $last_id)); $page['title'] = getlocal("Chat log"); $page = array_merge($page, prepare_menu($operator, false)); $this->getAssetManager()->attachJs('js/compiled/thread_log_app.js'); $this->getAssetManager()->attachJs(sprintf('jQuery(document).ready(function(){Mibew.Application.start(%s);});', json_encode(array('messages' => $messages))), \Mibew\Asset\AssetManagerInterface::INLINE, 1000); return $this->render('history_thread', $page); }
/** * Return updated visitors list. API function. * * Triggers * {@link \Mibew\EventDispatcher\Events::USERS_UPDATE_VISITORS_LOAD} and * {@link \Mibew\EventDispatcher\Events::USERS_UPDATE_VISITORS_ALTER} * events. * * @param array $args Associative array of arguments. It must contains the * following keys: * - 'agentId': Id of the agent related to users window * * @return array Array of results. It contains the following keys: * - 'visitors': array of visitors on the site */ protected function apiUpdateVisitors($args) { // Check access $this->checkOperator($args['agentId']); // Close old invitations invitation_close_old(); // Remove old visitors track_remove_old_visitors(); // Get instance of event dispatcher $dispatcher = EventDispatcher::getInstance(); // Trigger load event $arguments = array('visitors' => false); $dispatcher->triggerEvent(Events::USERS_UPDATE_VISITORS_LOAD, $arguments); // Check if visiors list loaded by plugins if (!is_array($arguments['visitors'])) { // Load visitors list $db = Database::getInstance(); // Load visitors $query = "SELECT v.visitorid, " . "v.userid, " . "v.username, " . "v.firsttime, " . "v.lasttime, " . "v.entry, " . "v.details, " . "t.invitationstate, " . "t.dtmcreated AS invitationtime, " . "t.agentId AS invitedby, " . "v.invitations, " . "v.chats " . "FROM {sitevisitor} v " . "LEFT OUTER JOIN {thread} t " . "ON t.threadid = v.threadid " . "WHERE v.threadid IS NULL " . "OR (t.istate = :state_invited " . "AND t.invitationstate = :invitation_wait)" . "ORDER BY t.invitationstate, v.lasttime DESC, v.invitations"; $query .= Settings::get('visitors_limit') == '0' ? "" : " LIMIT " . Settings::get('visitors_limit'); $rows = $db->query($query, array(':state_invited' => Thread::STATE_INVITED, ':invitation_wait' => Thread::INVITATION_WAIT), array('return_rows' => Database::RETURN_ALL_ROWS)); $visitors = array(); foreach ($rows as $row) { // Get visitor details $details = track_retrieve_details($row); // Get user agent $user_agent = get_user_agent_version($details['user_agent']); // Get user ip if (preg_match("/(\\d+\\.\\d+\\.\\d+\\.\\d+)/", $details['remote_host'], $matches) != 0) { $user_ip = $matches[1]; } else { $user_ip = false; } // Get invitation info $row['invited'] = $row['invitationstate'] == Thread::INVITATION_WAIT; if ($row['invited']) { $agent_name = get_operator_name(operator_by_id($row['invitedby'])); $invitation_info = array('time' => $row['invitationtime'], 'agentName' => $agent_name); } else { $invitation_info = false; } // Create resulting visitor structure $visitors[] = array('id' => (int) $row['visitorid'], 'userId' => $row['userid'], 'userName' => $row['username'], 'userAgent' => $user_agent, 'userIp' => $user_ip, 'remote' => $details['remote_host'], 'firstTime' => $row['firsttime'], 'lastTime' => $row['lasttime'], 'invitations' => (int) $row['invitations'], 'chats' => (int) $row['chats'], 'invitationInfo' => $invitation_info); } } else { $visitors = $arguments['visitors']; } // Provide ability to alter visitors list $arguments = array('visitors' => $visitors); $dispatcher->triggerEvent(Events::USERS_UPDATE_VISITORS_ALTER, $arguments); // Send results back to the client. "array_values" function should be // used to avoid problems with JSON conversion. If there will be gaps in // keys (the keys are not serial) JSON Object will be produced instead // of an Array. return array('visitors' => array_values($arguments['visitors'])); }