public function logout($user) { $serviceUserOnline = new Model_User_Online(); // 将用户从在线列表移出 $serviceUserOnline->delUser($user['id']); // 用户登出 User_Session::delLoginSession(); User_Session::delLoginCookie(); User_Session::delUserIdCookie(); $notice = array('msg' => '您已成功登出!', 'type' => 'information'); User_Session::setNotice($notice); }
/** * Action: sign out */ public function action_out() { // Remove from online list Model_User_Online::factory(Session::instance()->id())->delete(); // Logout visitor Visitor::instance()->logout(); Request::back(); }
/** * Update current online user. * * @static * @param Model_User $user */ public static function update($user) { $session_id = Session::instance()->id(); $online = Model_User_Online::factory($session_id); if (!$online->loaded() && $session_id) { $online->id = $session_id; } $online->user_id = $user ? $user->id : null; $online->last_activity = time(); try { $online->save(); } catch (Validation_Exception $e) { } catch (Database_Exception $e) { // Might happen if no session id set } }
/** * Create new shouts view. */ public function __construct() { parent::__construct(); $this->_guest_count = Model_User_Online::get_guest_count(); $users = Model_User_Online::find_online_users(); $this->title = __('Online'); // Build user lists $friends = (bool) self::$_user ? self::$_user->find_friends() : array(); foreach ($users as $user_id) { $user = Model_User::find_user_light($user_id); if (in_array($user_id, $friends)) { $this->_friends[mb_strtoupper($user['username'])] = HTML::user($user); } else { $this->_users[mb_strtoupper($user['username'])] = HTML::user($user); } } }
<?php defined('SYSPATH') or die('No direct access allowed.'); /** * Online users * * @package Anqh * @author Antti Qvickström * @copyright (c) 2010 Antti Qvickström * @license http://www.opensource.org/licenses/mit-license.php MIT license */ $guests = Model_User_Online::get_guest_count(); $online = Model_User_Online::find_online_users(); $counts = array(); if ($count = count($online)) { $counts[] = __($count == 1 ? ':members member' : ':members members', array(':members' => $count)); } if ($guests) { $counts[] = __($guests == 1 ? ':guests guest' : ':guests guests', array(':guests' => $guests)); } echo '<div class="totals">' . __(':users users online', array(':users' => '<var title="' . implode(', ', $counts) . '">' . (count($online) + $guests) . '</var>')) . '</div>'; echo View::factory('generic/users', array('viewer' => $viewer, 'users' => $online));
/** * Construct controller. */ public function before() { if ($this->request->is_ajax()) { $this->_request_type = self::REQUEST_AJAX; $this->ajax = true; } else { if (!$this->request->is_initial()) { $this->_request_type = self::REQUEST_INTERNAL; $this->internal = true; } } // Update history? $this->history = $this->history && !$this->ajax; // Initialize session $this->session = Session::instance(); // Load current user, null if none if (self::$user === false) { $visitor = Visitor::instance(); Controller::$user = $visitor->get_user(); // If still no user, try auto login if (!Controller::$user && $visitor->auto_login()) { Controller::$user = $visitor->get_user(); } unset($visitor); } // Update current online user for initial and ajax requests if ($this->_request_type !== self::REQUEST_INTERNAL) { Model_User_Online::update(self::$user); } // Open outside links to a new tab/window HTML::$windowed_urls = true; // Load template if ($this->auto_render) { $this->page_id = $this->page_id ? $this->page_id : $this->request->controller(); // Figure out what format the client wants $accept_types = Request::accept_type(); if (isset($accept_types['*/*'])) { // All formats accepted $accept_types = $this->_accept_formats; } else { // Only some formats accepted $accept_types = Arr::extract($accept_types, array_keys($this->_accept_formats)); if (!($accept_types = array_filter($accept_types))) { throw new HTTP_Exception_415('Unsupported accept type'); } } $this->_response_format = key($accept_types); } }