/** * @see EventListener::execute() */ public function execute($eventObj, $className, $eventName) { if (MODULE_USERS_ONLINE == 1) { if ($eventObj->frame->getUser()->isOnline()) { $data = array('userID' => $eventObj->frame->getUser()->userID, 'requestURI' => $eventObj->frame->getUser()->requestURI, 'requestMethod' => $eventObj->frame->getUser()->requestMethod); $location = new UsersOnlineLocation(); $location->cacheLocation($data); $userLocation = $location->getLocation($data); if (!empty($userLocation)) { $eventObj->generalInformation[] = array('icon' => StyleManager::getStyle()->getIconPath('onlineM.png'), 'title' => WCF::getLanguage()->get('wcf.user.profile.currentLocation'), 'value' => $userLocation); } // show ip address and user agent if (WCF::getUser()->getPermission('admin.general.canViewIpAddress')) { if ($eventObj->frame->getUser()->ipAddress) { $eventObj->generalInformation[] = array('icon' => StyleManager::getStyle()->getIconPath('ipAddressM.png'), 'title' => WCF::getLanguage()->get('wcf.usersOnline.ipAddress'), 'value' => StringUtil::encodeHTML($eventObj->frame->getUser()->ipAddress)); } if ($eventObj->frame->getUser()->userAgent) { $icon = UsersOnlineUtil::getUserAgentIcon($eventObj->frame->getUser()->userAgent); $eventObj->generalInformation[] = array('icon' => $icon ? StyleManager::getStyle()->getIconPath('browsers/' . $icon . 'M.png') : '', 'title' => WCF::getLanguage()->get('wcf.usersOnline.userAgent'), 'value' => StringUtil::encodeHTML($eventObj->frame->getUser()->userAgent)); } } } } }
/** * Caches location information. * * @param array $user */ public function cacheLocation($user) { // get cache if (self::$locations == null) { self::$locations = WCF::getCache()->get('pageLocations-' . PACKAGE_ID); } $this->getCurrentLocation($user); foreach (self::$locations as $location) { if (!empty($location['classPath'])) { if (preg_match('~' . $location['locationPattern'] . '~i', $user['requestURI'], $match)) { $locationObj = $this->getLocationObject($location); $locationObj->cache($location, $user['requestURI'], $user['requestMethod'], $match); break; } } } return $user; }
/** * @see UsersOnline::getUsersOnline() */ public function getUsersOnline() { $this->enableUserAgentIcons = WCF::getUser()->getPermission('admin.general.canViewIpAddress'); parent::getUsersOnline(); $location = new UsersOnlineLocation(); // cache location data $location->cacheLocations($this->users); if (USERS_ONLINE_SHOW_GUESTS) { $location->cacheLocations($this->guests); } if (USERS_ONLINE_SHOW_ROBOTS) { $location->cacheLocations($this->spiders); } // get location data $location->getLocations($this->users); if (USERS_ONLINE_SHOW_GUESTS) { $location->getLocations($this->guests); } if (USERS_ONLINE_SHOW_ROBOTS) { $location->getLocations($this->spiders); } }