5 use wcf\data\page\PageCache
;
6 use wcf\data\user\online\UserOnline
;
7 use wcf\data\user\online\UsersOnlineList
;
8 use wcf\system\page\handler\IOnlineLocationPageHandler
;
9 use wcf\system\page\PageLocationManager
;
10 use wcf\system\request\LinkHandler
;
12 use wcf\util\HeaderUtil
;
15 * Shows page which lists all users who are online.
18 * @copyright 2001-2019 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
21 * @property UsersOnlineList $objectList
23 class UsersOnlineListPage
extends SortablePage
28 public $neededPermissions = ['user.profile.canViewUsersOnlineList'];
33 public $itemsPerPage = 100;
38 public $defaultSortField = USERS_ONLINE_DEFAULT_SORT_FIELD
;
43 public $defaultSortOrder = USERS_ONLINE_DEFAULT_SORT_ORDER
;
48 public $validSortFields = ['username', 'lastActivityTime', 'requestURI'];
53 public $objectListClassName = UsersOnlineList
::class;
59 public $locations = [];
64 public function readParameters()
66 parent
::readParameters();
68 if (WCF
::getSession()->getPermission('admin.user.canViewIpAddress')) {
69 $this->validSortFields
[] = 'ipAddress';
70 $this->validSortFields
[] = 'userAgent';
74 HeaderUtil
::redirect(LinkHandler
::getInstance()->getLink(
77 'sortField=' . $this->sortField
. '&sortOrder=' . $this->sortOrder
87 protected function initObjectList()
89 parent
::initObjectList();
90 $this->objectList
->readStats();
91 $this->objectList
->checkRecord();
93 if (!USERS_ONLINE_SHOW_ROBOTS
) {
94 $this->objectList
->getConditionBuilder()->add('session.spiderIdentifier IS NULL');
96 if (!USERS_ONLINE_SHOW_GUESTS
) {
97 if (USERS_ONLINE_SHOW_ROBOTS
) {
98 $this->objectList
->getConditionBuilder()->add('(session.userID IS NOT NULL OR session.spiderIdentifier IS NOT NULL)');
100 $this->objectList
->getConditionBuilder()->add('session.userID IS NOT NULL');
104 $this->objectList
->sqlSelects
.= ", CASE WHEN session.userID IS NULL THEN 1 ELSE 0 END AS userIsGuest";
105 $this->objectList
->sqlSelects
.= ", CASE WHEN session.spiderIdentifier IS NOT NULL THEN 1 ELSE 0 END AS userIsRobot";
111 public function readData()
116 if (MODULE_MEMBERS_LIST
) {
117 PageLocationManager
::getInstance()->addParentLocation('com.woltlab.wcf.MembersList');
120 // cache all necessary data for showing locations
121 foreach ($this->objectList
as $userOnline) {
122 $page = PageCache
::getInstance()->getPage($userOnline->pageID
);
123 if ($page !== null && $page->getHandler() !== null && $page->getHandler() instanceof IOnlineLocationPageHandler
) {
124 /** @noinspection PhpUndefinedMethodInspection */
125 $page->getHandler()->prepareOnlineLocation($page, $userOnline);
130 /** @var UserOnline $userOnline */
131 foreach ($this->objectList
as $userOnline) {
132 $userOnline->setLocation();
139 protected function readObjects()
141 if ($this->sqlOrderBy
) {
142 $this->sqlOrderBy
= ($this->sortField
== 'lastActivityTime' ?
'session.' : '') . $this->sqlOrderBy
;
145 $originalSqlOrderBy = $this->sqlOrderBy
;
146 // sort in this order: users -> guests -> robots
147 $this->sqlOrderBy
= "userIsGuest ASC, userIsRobot DESC, " . $this->sqlOrderBy
;
149 parent
::readObjects();
151 // restore original order
152 $this->sqlOrderBy
= $originalSqlOrderBy;