@@ -21,159 +21,159 @@ |
||
21 | 21 | |
22 | 22 | class PageEditComment extends InternalPageBase |
23 | 23 | { |
24 | - /** |
|
25 | - * Main function for this page, when no specific actions are called. |
|
26 | - * @throws ApplicationLogicException |
|
27 | - * @throws Exception |
|
28 | - */ |
|
29 | - protected function main() |
|
30 | - { |
|
31 | - $commentId = WebRequest::getInt('id'); |
|
32 | - if ($commentId === null) { |
|
33 | - throw new ApplicationLogicException('Comment ID not specified'); |
|
34 | - } |
|
35 | - |
|
36 | - $database = $this->getDatabase(); |
|
37 | - |
|
38 | - /** @var Comment|false $comment */ |
|
39 | - $comment = Comment::getById($commentId, $database); |
|
40 | - if ($comment === false) { |
|
41 | - throw new ApplicationLogicException('Comment not found'); |
|
42 | - } |
|
43 | - |
|
44 | - $currentUser = User::getCurrent($database); |
|
45 | - |
|
46 | - $this->checkCommentAccess($comment, $currentUser); |
|
47 | - |
|
48 | - /** @var Request|false $request */ |
|
49 | - $request = Request::getById($comment->getRequest(), $database); |
|
50 | - |
|
51 | - if ($request === false) { |
|
52 | - throw new ApplicationLogicException('Request was not found.'); |
|
53 | - } |
|
54 | - |
|
55 | - $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
|
56 | - |
|
57 | - if (WebRequest::wasPosted()) { |
|
58 | - $this->validateCSRFToken(); |
|
59 | - $newComment = WebRequest::postString('newcomment'); |
|
60 | - $visibility = WebRequest::postString('visibility'); |
|
61 | - $doUnflag = WebRequest::postBoolean('unflag'); |
|
62 | - |
|
63 | - if ($newComment === null || $newComment === '') { |
|
64 | - throw new ApplicationLogicException('Comment cannot be empty!'); |
|
65 | - } |
|
66 | - |
|
67 | - $commentDataUnchanged = $newComment === $comment->getComment() |
|
68 | - && ($comment->getVisibility() === 'requester' || $comment->getVisibility() === $visibility); |
|
69 | - $flagStatusUnchanged = (!$canUnflag || $comment->getFlagged() && !$doUnflag); |
|
70 | - |
|
71 | - if ($commentDataUnchanged && $flagStatusUnchanged) { |
|
72 | - // No change was made; redirect back. |
|
73 | - $this->redirectBack($comment->getRequest()); |
|
74 | - |
|
75 | - return; |
|
76 | - } |
|
77 | - |
|
78 | - // optimistically lock from the load of the edit comment form |
|
79 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
80 | - |
|
81 | - // comment data has changed, update the object |
|
82 | - if (!$commentDataUnchanged) { |
|
83 | - $this->updateCommentData($comment, $visibility, $newComment); |
|
84 | - } |
|
85 | - |
|
86 | - if ($doUnflag && $canUnflag) { |
|
87 | - $comment->setFlagged(false); |
|
88 | - } |
|
89 | - |
|
90 | - $comment->setUpdateVersion($updateVersion); |
|
91 | - $comment->save(); |
|
92 | - |
|
93 | - if (!$commentDataUnchanged) { |
|
94 | - Logger::editComment($database, $comment, $request); |
|
95 | - $this->getNotificationHelper()->commentEdited($comment, $request); |
|
96 | - } |
|
97 | - |
|
98 | - if ($doUnflag && $canUnflag) { |
|
99 | - Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
100 | - } |
|
101 | - |
|
102 | - SessionAlert::success('Comment has been saved successfully'); |
|
103 | - $this->redirectBack($comment->getRequest()); |
|
104 | - } |
|
105 | - else { |
|
106 | - $this->assignCSRFToken(); |
|
107 | - $this->assign('comment', $comment); |
|
108 | - $this->assign('request', $request); |
|
109 | - $this->assign('user', User::getById($comment->getUser(), $database)); |
|
110 | - $this->assign('canUnflag', $canUnflag); |
|
111 | - $this->setTemplate('edit-comment.tpl'); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @throws AccessDeniedException |
|
117 | - */ |
|
118 | - private function checkCommentAccess(Comment $comment, User $currentUser): void |
|
119 | - { |
|
120 | - if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) { |
|
121 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
122 | - } |
|
123 | - |
|
124 | - $restrictedVisibility = $comment->getFlagged() |
|
125 | - || $comment->getVisibility() === 'admin' |
|
126 | - || $comment->getVisibility() === 'checkuser'; |
|
127 | - |
|
128 | - if ($restrictedVisibility && !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
129 | - // Restricted visibility comments can only be seen if the user has a request reserved. |
|
130 | - /** @var Request $request */ |
|
131 | - $request = Request::getById($comment->getRequest(), $comment->getDatabase()); |
|
132 | - |
|
133 | - if ($request->getReserved() !== $currentUser->getId()) { |
|
134 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - if ($comment->getVisibility() === 'admin' |
|
139 | - && !$this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData') |
|
140 | - && $comment->getUser() !== $currentUser->getId()) { |
|
141 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
142 | - } |
|
143 | - |
|
144 | - if ($comment->getVisibility() === 'checkuser' |
|
145 | - && !$this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData') |
|
146 | - && $comment->getUser() !== $currentUser->getId()) { |
|
147 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @throws ApplicationLogicException |
|
153 | - */ |
|
154 | - private function updateCommentData(Comment $comment, ?string $visibility, string $newComment): void |
|
155 | - { |
|
156 | - if ($comment->getVisibility() !== 'requester') { |
|
157 | - if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
158 | - throw new ApplicationLogicException('Comment visibility is not valid'); |
|
159 | - } |
|
160 | - |
|
161 | - $comment->setVisibility($visibility); |
|
162 | - } |
|
163 | - |
|
164 | - $comment->setComment($newComment); |
|
165 | - $comment->touchEdited(); |
|
166 | - } |
|
167 | - |
|
168 | - private function redirectBack(int $requestId): void |
|
169 | - { |
|
170 | - $source = WebRequest::getString('from'); |
|
171 | - |
|
172 | - if ($source == 'flagged') { |
|
173 | - $this->redirect('flaggedComments'); |
|
174 | - } |
|
175 | - else { |
|
176 | - $this->redirect('viewRequest', null, array('id' => $requestId)); |
|
177 | - } |
|
178 | - } |
|
24 | + /** |
|
25 | + * Main function for this page, when no specific actions are called. |
|
26 | + * @throws ApplicationLogicException |
|
27 | + * @throws Exception |
|
28 | + */ |
|
29 | + protected function main() |
|
30 | + { |
|
31 | + $commentId = WebRequest::getInt('id'); |
|
32 | + if ($commentId === null) { |
|
33 | + throw new ApplicationLogicException('Comment ID not specified'); |
|
34 | + } |
|
35 | + |
|
36 | + $database = $this->getDatabase(); |
|
37 | + |
|
38 | + /** @var Comment|false $comment */ |
|
39 | + $comment = Comment::getById($commentId, $database); |
|
40 | + if ($comment === false) { |
|
41 | + throw new ApplicationLogicException('Comment not found'); |
|
42 | + } |
|
43 | + |
|
44 | + $currentUser = User::getCurrent($database); |
|
45 | + |
|
46 | + $this->checkCommentAccess($comment, $currentUser); |
|
47 | + |
|
48 | + /** @var Request|false $request */ |
|
49 | + $request = Request::getById($comment->getRequest(), $database); |
|
50 | + |
|
51 | + if ($request === false) { |
|
52 | + throw new ApplicationLogicException('Request was not found.'); |
|
53 | + } |
|
54 | + |
|
55 | + $canUnflag = $this->barrierTest('unflag', $currentUser, PageFlagComment::class); |
|
56 | + |
|
57 | + if (WebRequest::wasPosted()) { |
|
58 | + $this->validateCSRFToken(); |
|
59 | + $newComment = WebRequest::postString('newcomment'); |
|
60 | + $visibility = WebRequest::postString('visibility'); |
|
61 | + $doUnflag = WebRequest::postBoolean('unflag'); |
|
62 | + |
|
63 | + if ($newComment === null || $newComment === '') { |
|
64 | + throw new ApplicationLogicException('Comment cannot be empty!'); |
|
65 | + } |
|
66 | + |
|
67 | + $commentDataUnchanged = $newComment === $comment->getComment() |
|
68 | + && ($comment->getVisibility() === 'requester' || $comment->getVisibility() === $visibility); |
|
69 | + $flagStatusUnchanged = (!$canUnflag || $comment->getFlagged() && !$doUnflag); |
|
70 | + |
|
71 | + if ($commentDataUnchanged && $flagStatusUnchanged) { |
|
72 | + // No change was made; redirect back. |
|
73 | + $this->redirectBack($comment->getRequest()); |
|
74 | + |
|
75 | + return; |
|
76 | + } |
|
77 | + |
|
78 | + // optimistically lock from the load of the edit comment form |
|
79 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
80 | + |
|
81 | + // comment data has changed, update the object |
|
82 | + if (!$commentDataUnchanged) { |
|
83 | + $this->updateCommentData($comment, $visibility, $newComment); |
|
84 | + } |
|
85 | + |
|
86 | + if ($doUnflag && $canUnflag) { |
|
87 | + $comment->setFlagged(false); |
|
88 | + } |
|
89 | + |
|
90 | + $comment->setUpdateVersion($updateVersion); |
|
91 | + $comment->save(); |
|
92 | + |
|
93 | + if (!$commentDataUnchanged) { |
|
94 | + Logger::editComment($database, $comment, $request); |
|
95 | + $this->getNotificationHelper()->commentEdited($comment, $request); |
|
96 | + } |
|
97 | + |
|
98 | + if ($doUnflag && $canUnflag) { |
|
99 | + Logger::unflaggedComment($database, $comment, $request->getDomain()); |
|
100 | + } |
|
101 | + |
|
102 | + SessionAlert::success('Comment has been saved successfully'); |
|
103 | + $this->redirectBack($comment->getRequest()); |
|
104 | + } |
|
105 | + else { |
|
106 | + $this->assignCSRFToken(); |
|
107 | + $this->assign('comment', $comment); |
|
108 | + $this->assign('request', $request); |
|
109 | + $this->assign('user', User::getById($comment->getUser(), $database)); |
|
110 | + $this->assign('canUnflag', $canUnflag); |
|
111 | + $this->setTemplate('edit-comment.tpl'); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @throws AccessDeniedException |
|
117 | + */ |
|
118 | + private function checkCommentAccess(Comment $comment, User $currentUser): void |
|
119 | + { |
|
120 | + if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) { |
|
121 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
122 | + } |
|
123 | + |
|
124 | + $restrictedVisibility = $comment->getFlagged() |
|
125 | + || $comment->getVisibility() === 'admin' |
|
126 | + || $comment->getVisibility() === 'checkuser'; |
|
127 | + |
|
128 | + if ($restrictedVisibility && !$this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')) { |
|
129 | + // Restricted visibility comments can only be seen if the user has a request reserved. |
|
130 | + /** @var Request $request */ |
|
131 | + $request = Request::getById($comment->getRequest(), $comment->getDatabase()); |
|
132 | + |
|
133 | + if ($request->getReserved() !== $currentUser->getId()) { |
|
134 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + if ($comment->getVisibility() === 'admin' |
|
139 | + && !$this->barrierTest('seeRestrictedComments', $currentUser, 'RequestData') |
|
140 | + && $comment->getUser() !== $currentUser->getId()) { |
|
141 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
142 | + } |
|
143 | + |
|
144 | + if ($comment->getVisibility() === 'checkuser' |
|
145 | + && !$this->barrierTest('seeCheckuserComments', $currentUser, 'RequestData') |
|
146 | + && $comment->getUser() !== $currentUser->getId()) { |
|
147 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @throws ApplicationLogicException |
|
153 | + */ |
|
154 | + private function updateCommentData(Comment $comment, ?string $visibility, string $newComment): void |
|
155 | + { |
|
156 | + if ($comment->getVisibility() !== 'requester') { |
|
157 | + if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
158 | + throw new ApplicationLogicException('Comment visibility is not valid'); |
|
159 | + } |
|
160 | + |
|
161 | + $comment->setVisibility($visibility); |
|
162 | + } |
|
163 | + |
|
164 | + $comment->setComment($newComment); |
|
165 | + $comment->touchEdited(); |
|
166 | + } |
|
167 | + |
|
168 | + private function redirectBack(int $requestId): void |
|
169 | + { |
|
170 | + $source = WebRequest::getString('from'); |
|
171 | + |
|
172 | + if ($source == 'flagged') { |
|
173 | + $this->redirect('flaggedComments'); |
|
174 | + } |
|
175 | + else { |
|
176 | + $this->redirect('viewRequest', null, array('id' => $requestId)); |
|
177 | + } |
|
178 | + } |
|
179 | 179 | } |
@@ -101,8 +101,7 @@ discard block |
||
101 | 101 | |
102 | 102 | SessionAlert::success('Comment has been saved successfully'); |
103 | 103 | $this->redirectBack($comment->getRequest()); |
104 | - } |
|
105 | - else { |
|
104 | + } else { |
|
106 | 105 | $this->assignCSRFToken(); |
107 | 106 | $this->assign('comment', $comment); |
108 | 107 | $this->assign('request', $request); |
@@ -171,8 +170,7 @@ discard block |
||
171 | 170 | |
172 | 171 | if ($source == 'flagged') { |
173 | 172 | $this->redirect('flaggedComments'); |
174 | - } |
|
175 | - else { |
|
173 | + } else { |
|
176 | 174 | $this->redirect('viewRequest', null, array('id' => $requestId)); |
177 | 175 | } |
178 | 176 | } |
@@ -13,11 +13,11 @@ discard block |
||
13 | 13 | |
14 | 14 | class StatsFastCloses extends InternalPageBase |
15 | 15 | { |
16 | - public function main() |
|
17 | - { |
|
18 | - $this->setHtmlTitle('Fast Closes :: Statistics'); |
|
16 | + public function main() |
|
17 | + { |
|
18 | + $this->setHtmlTitle('Fast Closes :: Statistics'); |
|
19 | 19 | |
20 | - $query = <<<SQL |
|
20 | + $query = <<<SQL |
|
21 | 21 | WITH closedescs AS ( |
22 | 22 | SELECT closes, mail_desc FROM closes |
23 | 23 | UNION ALL |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | ORDER BY TIMEDIFF(log_closed.timestamp, log_reserved.timestamp) ASC |
48 | 48 | ; |
49 | 49 | SQL; |
50 | - $database = $this->getDatabase(); |
|
51 | - $statement = $database->query($query); |
|
52 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
53 | - $this->assign('dataTable', $data); |
|
54 | - $this->assign('statsPageTitle', 'Requests closed less than 30 seconds after reservation in the past 3 months'); |
|
55 | - $this->setTemplate('statistics/fast-closes.tpl'); |
|
56 | - } |
|
50 | + $database = $this->getDatabase(); |
|
51 | + $statement = $database->query($query); |
|
52 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
53 | + $this->assign('dataTable', $data); |
|
54 | + $this->assign('statsPageTitle', 'Requests closed less than 30 seconds after reservation in the past 3 months'); |
|
55 | + $this->setTemplate('statistics/fast-closes.tpl'); |
|
56 | + } |
|
57 | 57 | } |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | |
16 | 16 | class StatsTemplateStats extends InternalPageBase |
17 | 17 | { |
18 | - public function main() |
|
19 | - { |
|
20 | - $this->setHtmlTitle('Template Stats :: Statistics'); |
|
18 | + public function main() |
|
19 | + { |
|
20 | + $this->setHtmlTitle('Template Stats :: Statistics'); |
|
21 | 21 | |
22 | - $query = <<<SQL |
|
22 | + $query = <<<SQL |
|
23 | 23 | SELECT |
24 | 24 | t.id AS templateid, |
25 | 25 | t.usercode AS usercode, |
@@ -49,17 +49,17 @@ discard block |
||
49 | 49 | ) allUsers ON allUsers.welcome_template = t.id |
50 | 50 | ORDER BY t.id |
51 | 51 | SQL; |
52 | - $database = $this->getDatabase(); |
|
53 | - $statement = $database->prepare($query); |
|
54 | - $statement->execute([ |
|
55 | - ':domain1' => WebRequest::getSessionDomain(), |
|
56 | - ':domain2' => WebRequest::getSessionDomain(), |
|
57 | - ':preference1' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
58 | - ':preference2' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
59 | - ]); |
|
60 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
61 | - $this->assign('dataTable', $data); |
|
62 | - $this->assign('statsPageTitle', 'Template Stats'); |
|
63 | - $this->setTemplate('statistics/welcome-template-usage.tpl'); |
|
64 | - } |
|
52 | + $database = $this->getDatabase(); |
|
53 | + $statement = $database->prepare($query); |
|
54 | + $statement->execute([ |
|
55 | + ':domain1' => WebRequest::getSessionDomain(), |
|
56 | + ':domain2' => WebRequest::getSessionDomain(), |
|
57 | + ':preference1' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
58 | + ':preference2' => PreferenceManager::PREF_WELCOMETEMPLATE, |
|
59 | + ]); |
|
60 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
61 | + $this->assign('dataTable', $data); |
|
62 | + $this->assign('statsPageTitle', 'Template Stats'); |
|
63 | + $this->setTemplate('statistics/welcome-template-usage.tpl'); |
|
64 | + } |
|
65 | 65 | } |
@@ -14,12 +14,12 @@ discard block |
||
14 | 14 | |
15 | 15 | class StatsTopCreators extends InternalPageBase |
16 | 16 | { |
17 | - public function main() |
|
18 | - { |
|
19 | - $this->setHtmlTitle('Top Creators :: Statistics'); |
|
17 | + public function main() |
|
18 | + { |
|
19 | + $this->setHtmlTitle('Top Creators :: Statistics'); |
|
20 | 20 | |
21 | - // Retrieve all-time stats |
|
22 | - $queryAllTime = <<<SQL |
|
21 | + // Retrieve all-time stats |
|
22 | + $queryAllTime = <<<SQL |
|
23 | 23 | SELECT |
24 | 24 | /* StatsTopCreators::execute()/queryAllTime */ |
25 | 25 | COUNT(*) count, |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | ORDER BY COUNT(*) DESC; |
37 | 37 | SQL; |
38 | 38 | |
39 | - // Retrieve all-time stats for active users only |
|
40 | - $queryAllTimeActive = <<<SQL |
|
39 | + // Retrieve all-time stats for active users only |
|
40 | + $queryAllTimeActive = <<<SQL |
|
41 | 41 | SELECT |
42 | 42 | /* StatsTopCreators::execute()/queryAllTimeActive */ |
43 | 43 | COUNT(*) count, |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | ORDER BY COUNT(*) DESC; |
55 | 55 | SQL; |
56 | 56 | |
57 | - // Retrieve today's stats (so far) |
|
58 | - $queryToday = <<<SQL |
|
57 | + // Retrieve today's stats (so far) |
|
58 | + $queryToday = <<<SQL |
|
59 | 59 | SELECT |
60 | 60 | /* StatsTopCreators::execute()/top5out */ |
61 | 61 | COUNT(*) count, |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | ORDER BY COUNT(*) DESC; |
72 | 72 | SQL; |
73 | 73 | |
74 | - // Retrieve Yesterday's stats |
|
75 | - $queryYesterday = <<<SQL |
|
74 | + // Retrieve Yesterday's stats |
|
75 | + $queryYesterday = <<<SQL |
|
76 | 76 | SELECT |
77 | 77 | /* StatsTopCreators::execute()/top5yout */ |
78 | 78 | COUNT(*) count, |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | ORDER BY COUNT(*) DESC; |
89 | 89 | SQL; |
90 | 90 | |
91 | - // Retrieve last 7 days |
|
92 | - $queryLast7Days = <<<SQL |
|
91 | + // Retrieve last 7 days |
|
92 | + $queryLast7Days = <<<SQL |
|
93 | 93 | SELECT |
94 | 94 | /* StatsTopCreators::execute()/top5wout */ |
95 | 95 | COUNT(*) count, |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | ORDER BY COUNT(*) DESC; |
106 | 106 | SQL; |
107 | 107 | |
108 | - // Retrieve last month's stats |
|
109 | - $queryLast28Days = <<<SQL |
|
108 | + // Retrieve last month's stats |
|
109 | + $queryLast28Days = <<<SQL |
|
110 | 110 | SELECT |
111 | 111 | /* StatsTopCreators::execute()/top5mout */ |
112 | 112 | COUNT(*) count, |
@@ -122,25 +122,25 @@ discard block |
||
122 | 122 | ORDER BY COUNT(*) DESC; |
123 | 123 | SQL; |
124 | 124 | |
125 | - // Put it all together |
|
126 | - $queries = array( |
|
127 | - 'queryAllTime' => $queryAllTime, |
|
128 | - 'queryAllTimeActive' => $queryAllTimeActive, |
|
129 | - 'queryToday' => $queryToday, |
|
130 | - 'queryYesterday' => $queryYesterday, |
|
131 | - 'queryLast7Days' => $queryLast7Days, |
|
132 | - 'queryLast28Days' => $queryLast28Days, |
|
133 | - ); |
|
125 | + // Put it all together |
|
126 | + $queries = array( |
|
127 | + 'queryAllTime' => $queryAllTime, |
|
128 | + 'queryAllTimeActive' => $queryAllTimeActive, |
|
129 | + 'queryToday' => $queryToday, |
|
130 | + 'queryYesterday' => $queryYesterday, |
|
131 | + 'queryLast7Days' => $queryLast7Days, |
|
132 | + 'queryLast28Days' => $queryLast28Days, |
|
133 | + ); |
|
134 | 134 | |
135 | - $database = $this->getDatabase(); |
|
136 | - foreach ($queries as $name => $sql) { |
|
137 | - $statement = $database->prepare($sql); |
|
138 | - $statement->execute([":created" => EmailTemplate::ACTION_CREATED]); |
|
139 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
140 | - $this->assign($name, $data); |
|
141 | - } |
|
135 | + $database = $this->getDatabase(); |
|
136 | + foreach ($queries as $name => $sql) { |
|
137 | + $statement = $database->prepare($sql); |
|
138 | + $statement->execute([":created" => EmailTemplate::ACTION_CREATED]); |
|
139 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
140 | + $this->assign($name, $data); |
|
141 | + } |
|
142 | 142 | |
143 | - $this->assign('statsPageTitle', 'Top Account Creators'); |
|
144 | - $this->setTemplate('statistics/top-creators.tpl'); |
|
145 | - } |
|
143 | + $this->assign('statsPageTitle', 'Top Account Creators'); |
|
144 | + $this->setTemplate('statistics/top-creators.tpl'); |
|
145 | + } |
|
146 | 146 | } |
@@ -129,8 +129,7 @@ discard block |
||
129 | 129 | |
130 | 130 | if ($logCount === 0) { |
131 | 131 | $this->assign('accountlog', array()); |
132 | - } |
|
133 | - else { |
|
132 | + } else { |
|
134 | 133 | list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
135 | 134 | |
136 | 135 | $this->assign("accountlog", $logData); |
@@ -151,8 +150,7 @@ discard block |
||
151 | 150 | if ($user->getForceIdentified() === null) { |
152 | 151 | $idVerifier = new IdentificationVerifier($this->getHttpHelper(), $this->getSiteConfiguration(), $this->getDatabase()); |
153 | 152 | $this->assign('identificationStatus', $idVerifier->isUserIdentified($user->getOnWikiName()) ? 'detected' : 'missing'); |
154 | - } |
|
155 | - else { |
|
153 | + } else { |
|
156 | 154 | $this->assign('identificationStatus', $user->getForceIdentified() == 1 ? 'forced-on' : 'forced-off'); |
157 | 155 | } |
158 | 156 |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | |
25 | 25 | class StatsUsers extends InternalPageBase |
26 | 26 | { |
27 | - public function main() |
|
28 | - { |
|
29 | - $this->setHtmlTitle('Users :: Statistics'); |
|
27 | + public function main() |
|
28 | + { |
|
29 | + $this->setHtmlTitle('Users :: Statistics'); |
|
30 | 30 | |
31 | - $database = $this->getDatabase(); |
|
31 | + $database = $this->getDatabase(); |
|
32 | 32 | |
33 | - $query = <<<SQL |
|
33 | + $query = <<<SQL |
|
34 | 34 | SELECT |
35 | 35 | u.id |
36 | 36 | , u.username |
@@ -46,34 +46,34 @@ discard block |
||
46 | 46 | WHERE u.status = 'Active' |
47 | 47 | SQL; |
48 | 48 | |
49 | - $users = $database->query($query)->fetchAll(PDO::FETCH_ASSOC); |
|
50 | - $this->assign('users', $users); |
|
49 | + $users = $database->query($query)->fetchAll(PDO::FETCH_ASSOC); |
|
50 | + $this->assign('users', $users); |
|
51 | 51 | |
52 | - $this->assign('statsPageTitle', 'Account Creation Tool users'); |
|
53 | - $this->setTemplate("statistics/users.tpl"); |
|
54 | - } |
|
52 | + $this->assign('statsPageTitle', 'Account Creation Tool users'); |
|
53 | + $this->setTemplate("statistics/users.tpl"); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Entry point for the detail action. |
|
58 | - * |
|
59 | - * @throws ApplicationLogicException |
|
60 | - */ |
|
61 | - protected function detail() |
|
62 | - { |
|
63 | - $userId = WebRequest::getInt('user'); |
|
64 | - if ($userId === null) { |
|
65 | - throw new ApplicationLogicException("User not found"); |
|
66 | - } |
|
56 | + /** |
|
57 | + * Entry point for the detail action. |
|
58 | + * |
|
59 | + * @throws ApplicationLogicException |
|
60 | + */ |
|
61 | + protected function detail() |
|
62 | + { |
|
63 | + $userId = WebRequest::getInt('user'); |
|
64 | + if ($userId === null) { |
|
65 | + throw new ApplicationLogicException("User not found"); |
|
66 | + } |
|
67 | 67 | |
68 | - $database = $this->getDatabase(); |
|
68 | + $database = $this->getDatabase(); |
|
69 | 69 | |
70 | - $user = User::getById($userId, $database); |
|
71 | - if ($user == false) { |
|
72 | - throw new ApplicationLogicException('User not found'); |
|
73 | - } |
|
70 | + $user = User::getById($userId, $database); |
|
71 | + if ($user == false) { |
|
72 | + throw new ApplicationLogicException('User not found'); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - $activitySummary = $database->prepare(<<<SQL |
|
76 | + $activitySummary = $database->prepare(<<<SQL |
|
77 | 77 | SELECT COALESCE(closes.mail_desc, log.action) AS action, COUNT(*) AS count |
78 | 78 | FROM log |
79 | 79 | INNER JOIN user ON log.user = user.id |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | WHERE user.username = :username |
82 | 82 | GROUP BY action; |
83 | 83 | SQL |
84 | - ); |
|
85 | - $activitySummary->execute(array(":username" => $user->getUsername())); |
|
86 | - $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); |
|
84 | + ); |
|
85 | + $activitySummary->execute(array(":username" => $user->getUsername())); |
|
86 | + $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); |
|
87 | 87 | |
88 | - $this->assign("user", $user); |
|
89 | - $this->assign("activity", $activitySummaryData); |
|
88 | + $this->assign("user", $user); |
|
89 | + $this->assign("activity", $activitySummaryData); |
|
90 | 90 | |
91 | - $usersCreatedQuery = $database->prepare(<<<SQL |
|
91 | + $usersCreatedQuery = $database->prepare(<<<SQL |
|
92 | 92 | SELECT log.timestamp time, request.name name, request.id id |
93 | 93 | FROM log |
94 | 94 | INNER JOIN request ON (request.id = log.objectid AND log.objecttype = 'Request') |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | AND (emailtemplate.defaultaction = :created OR log.action = 'Closed custom-y') |
100 | 100 | ORDER BY log.timestamp; |
101 | 101 | SQL |
102 | - ); |
|
103 | - $usersCreatedQuery->execute(array(":username" => $user->getUsername(), ':created' => EmailTemplate::ACTION_CREATED)); |
|
104 | - $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
|
105 | - $this->assign("created", $usersCreated); |
|
102 | + ); |
|
103 | + $usersCreatedQuery->execute(array(":username" => $user->getUsername(), ':created' => EmailTemplate::ACTION_CREATED)); |
|
104 | + $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
|
105 | + $this->assign("created", $usersCreated); |
|
106 | 106 | |
107 | - $usersNotCreatedQuery = $database->prepare(<<<SQL |
|
107 | + $usersNotCreatedQuery = $database->prepare(<<<SQL |
|
108 | 108 | SELECT log.timestamp time, request.name name, request.id id |
109 | 109 | FROM log |
110 | 110 | JOIN request ON request.id = log.objectid AND log.objecttype = 'Request' |
@@ -115,60 +115,60 @@ discard block |
||
115 | 115 | AND (emailtemplate.defaultaction = :created OR log.action = 'Closed custom-n' OR log.action = 'Closed 0') |
116 | 116 | ORDER BY log.timestamp; |
117 | 117 | SQL |
118 | - ); |
|
119 | - $usersNotCreatedQuery->execute(array(":username" => $user->getUsername(), ':created' => EmailTemplate::ACTION_NOT_CREATED)); |
|
120 | - $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
|
121 | - $this->assign("notcreated", $usersNotCreated); |
|
122 | - |
|
123 | - /** @var Log[] $logs */ |
|
124 | - $logs = LogSearchHelper::get($database, Domain::getCurrent($database)->getId()) |
|
125 | - ->byObjectType('User') |
|
126 | - ->byObjectId($user->getId()) |
|
127 | - ->getRecordCount($logCount) |
|
128 | - ->fetch(); |
|
129 | - |
|
130 | - if ($logCount === 0) { |
|
131 | - $this->assign('accountlog', array()); |
|
132 | - } |
|
133 | - else { |
|
134 | - list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
135 | - |
|
136 | - $this->assign("accountlog", $logData); |
|
137 | - $this->assign("users", $users); |
|
138 | - } |
|
139 | - |
|
140 | - $currentUser = User::getCurrent($database); |
|
141 | - $this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class)); |
|
142 | - $this->assign('canDecline', $this->barrierTest('decline', $currentUser, PageUserManagement::class)); |
|
143 | - $this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class)); |
|
144 | - $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser, PageUserManagement::class)); |
|
145 | - $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser, PageUserManagement::class)); |
|
146 | - $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser, PageUserManagement::class)); |
|
147 | - |
|
148 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
149 | - $this->assign('oauth', $oauth); |
|
150 | - |
|
151 | - if ($user->getForceIdentified() === null) { |
|
152 | - $idVerifier = new IdentificationVerifier($this->getHttpHelper(), $this->getSiteConfiguration(), $this->getDatabase()); |
|
153 | - $this->assign('identificationStatus', $idVerifier->isUserIdentified($user->getOnWikiName()) ? 'detected' : 'missing'); |
|
154 | - } |
|
155 | - else { |
|
156 | - $this->assign('identificationStatus', $user->getForceIdentified() == 1 ? 'forced-on' : 'forced-off'); |
|
157 | - } |
|
158 | - |
|
159 | - if ($oauth->isFullyLinked()) { |
|
160 | - $this->assign('identity', $oauth->getIdentity(true)); |
|
161 | - $this->assign('identityExpired', $oauth->identityExpired()); |
|
162 | - } |
|
163 | - |
|
164 | - $this->assign('statsPageTitle', 'Account Creation Tool users'); |
|
165 | - |
|
166 | - // FIXME: domains! |
|
167 | - /** @var Domain $domain */ |
|
168 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
169 | - $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
|
170 | - |
|
171 | - $this->setHtmlTitle('{$user->getUsername()|escape} :: Users :: Statistics'); |
|
172 | - $this->setTemplate("statistics/userdetail.tpl"); |
|
173 | - } |
|
118 | + ); |
|
119 | + $usersNotCreatedQuery->execute(array(":username" => $user->getUsername(), ':created' => EmailTemplate::ACTION_NOT_CREATED)); |
|
120 | + $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
|
121 | + $this->assign("notcreated", $usersNotCreated); |
|
122 | + |
|
123 | + /** @var Log[] $logs */ |
|
124 | + $logs = LogSearchHelper::get($database, Domain::getCurrent($database)->getId()) |
|
125 | + ->byObjectType('User') |
|
126 | + ->byObjectId($user->getId()) |
|
127 | + ->getRecordCount($logCount) |
|
128 | + ->fetch(); |
|
129 | + |
|
130 | + if ($logCount === 0) { |
|
131 | + $this->assign('accountlog', array()); |
|
132 | + } |
|
133 | + else { |
|
134 | + list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
|
135 | + |
|
136 | + $this->assign("accountlog", $logData); |
|
137 | + $this->assign("users", $users); |
|
138 | + } |
|
139 | + |
|
140 | + $currentUser = User::getCurrent($database); |
|
141 | + $this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class)); |
|
142 | + $this->assign('canDecline', $this->barrierTest('decline', $currentUser, PageUserManagement::class)); |
|
143 | + $this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class)); |
|
144 | + $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser, PageUserManagement::class)); |
|
145 | + $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser, PageUserManagement::class)); |
|
146 | + $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser, PageUserManagement::class)); |
|
147 | + |
|
148 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
149 | + $this->assign('oauth', $oauth); |
|
150 | + |
|
151 | + if ($user->getForceIdentified() === null) { |
|
152 | + $idVerifier = new IdentificationVerifier($this->getHttpHelper(), $this->getSiteConfiguration(), $this->getDatabase()); |
|
153 | + $this->assign('identificationStatus', $idVerifier->isUserIdentified($user->getOnWikiName()) ? 'detected' : 'missing'); |
|
154 | + } |
|
155 | + else { |
|
156 | + $this->assign('identificationStatus', $user->getForceIdentified() == 1 ? 'forced-on' : 'forced-off'); |
|
157 | + } |
|
158 | + |
|
159 | + if ($oauth->isFullyLinked()) { |
|
160 | + $this->assign('identity', $oauth->getIdentity(true)); |
|
161 | + $this->assign('identityExpired', $oauth->identityExpired()); |
|
162 | + } |
|
163 | + |
|
164 | + $this->assign('statsPageTitle', 'Account Creation Tool users'); |
|
165 | + |
|
166 | + // FIXME: domains! |
|
167 | + /** @var Domain $domain */ |
|
168 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
169 | + $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
|
170 | + |
|
171 | + $this->setHtmlTitle('{$user->getUsername()|escape} :: Users :: Statistics'); |
|
172 | + $this->setTemplate("statistics/userdetail.tpl"); |
|
173 | + } |
|
174 | 174 | } |
@@ -13,11 +13,11 @@ discard block |
||
13 | 13 | |
14 | 14 | class StatsMonthlyStats extends InternalPageBase |
15 | 15 | { |
16 | - public function main() |
|
17 | - { |
|
18 | - $this->setHtmlTitle('Monthly Stats :: Statistics'); |
|
16 | + public function main() |
|
17 | + { |
|
18 | + $this->setHtmlTitle('Monthly Stats :: Statistics'); |
|
19 | 19 | |
20 | - $query = <<<SQL |
|
20 | + $query = <<<SQL |
|
21 | 21 | WITH activemonths AS ( |
22 | 22 | -- Pull all values from two generated sequences (values 2008 to 2050, and values 1 to 12) to generate dates. |
23 | 23 | -- Filter the resulting set down to months between the earliest and latest log entries. |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | ORDER BY sortkey ASC; |
156 | 156 | SQL; |
157 | 157 | |
158 | - $database = $this->getDatabase(); |
|
159 | - $statement = $database->query($query); |
|
160 | - $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
158 | + $database = $this->getDatabase(); |
|
159 | + $statement = $database->query($query); |
|
160 | + $data = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
161 | 161 | |
162 | - $this->assign('dataTable', $data); |
|
163 | - $this->assign('statsPageTitle', 'Monthly Statistics'); |
|
164 | - $this->setTemplate('statistics/monthly-stats.tpl'); |
|
165 | - } |
|
162 | + $this->assign('dataTable', $data); |
|
163 | + $this->assign('statsPageTitle', 'Monthly Statistics'); |
|
164 | + $this->setTemplate('statistics/monthly-stats.tpl'); |
|
165 | + } |
|
166 | 166 | } |
@@ -21,107 +21,107 @@ |
||
21 | 21 | */ |
22 | 22 | class IpLocationProvider implements ILocationProvider |
23 | 23 | { |
24 | - /** @var string */ |
|
25 | - private $apiKey; |
|
26 | - /** @var PdoDatabase */ |
|
27 | - private $database; |
|
28 | - /** @var HttpHelper */ |
|
29 | - private $httpHelper; |
|
30 | - |
|
31 | - /** |
|
32 | - * IpLocationProvider constructor. |
|
33 | - * |
|
34 | - * @param PdoDatabase $database |
|
35 | - * @param string $apiKey |
|
36 | - * @param HttpHelper $httpHelper |
|
37 | - */ |
|
38 | - public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper) |
|
39 | - { |
|
40 | - $this->database = $database; |
|
41 | - $this->apiKey = $apiKey; |
|
42 | - $this->httpHelper = $httpHelper; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param string $address |
|
47 | - * |
|
48 | - * @return array|null |
|
49 | - * @throws Exception |
|
50 | - * @throws OptimisticLockFailedException |
|
51 | - */ |
|
52 | - public function getIpLocation($address) |
|
53 | - { |
|
54 | - $address = trim($address); |
|
55 | - |
|
56 | - // lets look in our database first. |
|
57 | - $location = GeoLocation::getByAddress($address, $this->database, true); |
|
58 | - |
|
59 | - if ($location != null) { |
|
60 | - // touch cache timer |
|
61 | - $location->save(); |
|
62 | - |
|
63 | - return $location->getData(); |
|
64 | - } |
|
65 | - |
|
66 | - // OK, it's not there, let's do an IP2Location lookup. |
|
67 | - $result = $this->getResult($address); |
|
68 | - |
|
69 | - if ($result != null) { |
|
70 | - $location = new GeoLocation(); |
|
71 | - $location->setDatabase($this->database); |
|
72 | - $location->setAddress($address); |
|
73 | - $location->setData($result); |
|
74 | - $location->save(); |
|
75 | - |
|
76 | - return $result; |
|
77 | - } |
|
78 | - |
|
79 | - return null; |
|
80 | - } |
|
81 | - |
|
82 | - // adapted from http://www.ipinfodb.com/ip_location_api.php |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string $ip |
|
86 | - * |
|
87 | - * @return array|null |
|
88 | - */ |
|
89 | - private function getResult($ip) |
|
90 | - { |
|
91 | - try { |
|
92 | - if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
93 | - $xml = $this->httpHelper->get($this->getApiBase(), array( |
|
94 | - 'key' => $this->apiKey, |
|
95 | - 'ip' => $ip, |
|
96 | - 'format' => 'xml', |
|
97 | - )); |
|
98 | - |
|
99 | - $response = @new SimpleXMLElement($xml); |
|
100 | - |
|
101 | - $result = array(); |
|
102 | - |
|
103 | - foreach ($response as $field => $value) { |
|
104 | - $result[(string)$field] = (string)$value; |
|
105 | - } |
|
106 | - |
|
107 | - return $result; |
|
108 | - } |
|
109 | - } |
|
110 | - catch (Exception $ex) { |
|
111 | - return null; |
|
112 | - |
|
113 | - // LOGME: do something smart here, or wherever we use this value. |
|
114 | - // This is just a temp hack to squash errors on the UI for now. |
|
115 | - } |
|
116 | - |
|
117 | - return null; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - protected function getApiBase() |
|
124 | - { |
|
125 | - return "https://api.ipinfodb.com/v3/ip-city/"; |
|
126 | - } |
|
24 | + /** @var string */ |
|
25 | + private $apiKey; |
|
26 | + /** @var PdoDatabase */ |
|
27 | + private $database; |
|
28 | + /** @var HttpHelper */ |
|
29 | + private $httpHelper; |
|
30 | + |
|
31 | + /** |
|
32 | + * IpLocationProvider constructor. |
|
33 | + * |
|
34 | + * @param PdoDatabase $database |
|
35 | + * @param string $apiKey |
|
36 | + * @param HttpHelper $httpHelper |
|
37 | + */ |
|
38 | + public function __construct(PdoDatabase $database, $apiKey, HttpHelper $httpHelper) |
|
39 | + { |
|
40 | + $this->database = $database; |
|
41 | + $this->apiKey = $apiKey; |
|
42 | + $this->httpHelper = $httpHelper; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param string $address |
|
47 | + * |
|
48 | + * @return array|null |
|
49 | + * @throws Exception |
|
50 | + * @throws OptimisticLockFailedException |
|
51 | + */ |
|
52 | + public function getIpLocation($address) |
|
53 | + { |
|
54 | + $address = trim($address); |
|
55 | + |
|
56 | + // lets look in our database first. |
|
57 | + $location = GeoLocation::getByAddress($address, $this->database, true); |
|
58 | + |
|
59 | + if ($location != null) { |
|
60 | + // touch cache timer |
|
61 | + $location->save(); |
|
62 | + |
|
63 | + return $location->getData(); |
|
64 | + } |
|
65 | + |
|
66 | + // OK, it's not there, let's do an IP2Location lookup. |
|
67 | + $result = $this->getResult($address); |
|
68 | + |
|
69 | + if ($result != null) { |
|
70 | + $location = new GeoLocation(); |
|
71 | + $location->setDatabase($this->database); |
|
72 | + $location->setAddress($address); |
|
73 | + $location->setData($result); |
|
74 | + $location->save(); |
|
75 | + |
|
76 | + return $result; |
|
77 | + } |
|
78 | + |
|
79 | + return null; |
|
80 | + } |
|
81 | + |
|
82 | + // adapted from http://www.ipinfodb.com/ip_location_api.php |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string $ip |
|
86 | + * |
|
87 | + * @return array|null |
|
88 | + */ |
|
89 | + private function getResult($ip) |
|
90 | + { |
|
91 | + try { |
|
92 | + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
|
93 | + $xml = $this->httpHelper->get($this->getApiBase(), array( |
|
94 | + 'key' => $this->apiKey, |
|
95 | + 'ip' => $ip, |
|
96 | + 'format' => 'xml', |
|
97 | + )); |
|
98 | + |
|
99 | + $response = @new SimpleXMLElement($xml); |
|
100 | + |
|
101 | + $result = array(); |
|
102 | + |
|
103 | + foreach ($response as $field => $value) { |
|
104 | + $result[(string)$field] = (string)$value; |
|
105 | + } |
|
106 | + |
|
107 | + return $result; |
|
108 | + } |
|
109 | + } |
|
110 | + catch (Exception $ex) { |
|
111 | + return null; |
|
112 | + |
|
113 | + // LOGME: do something smart here, or wherever we use this value. |
|
114 | + // This is just a temp hack to squash errors on the UI for now. |
|
115 | + } |
|
116 | + |
|
117 | + return null; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + protected function getApiBase() |
|
124 | + { |
|
125 | + return "https://api.ipinfodb.com/v3/ip-city/"; |
|
126 | + } |
|
127 | 127 | } |
@@ -25,619 +25,619 @@ |
||
25 | 25 | */ |
26 | 26 | class WebRequest |
27 | 27 | { |
28 | - /** |
|
29 | - * @var IGlobalStateProvider Provides access to the global state. |
|
30 | - */ |
|
31 | - private static $globalStateProvider; |
|
32 | - |
|
33 | - /** |
|
34 | - * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - public static function wasPosted() |
|
38 | - { |
|
39 | - return self::method() === 'POST'; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Gets the HTTP Method used |
|
44 | - * @return string|null |
|
45 | - */ |
|
46 | - public static function method() |
|
47 | - { |
|
48 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
49 | - |
|
50 | - if (isset($server['REQUEST_METHOD'])) { |
|
51 | - return $server['REQUEST_METHOD']; |
|
52 | - } |
|
53 | - |
|
54 | - return null; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public static function isHttps() |
|
62 | - { |
|
63 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
64 | - |
|
65 | - if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
66 | - if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
67 | - // Client <=> Proxy is encrypted |
|
68 | - return true; |
|
69 | - } |
|
70 | - else { |
|
71 | - // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
72 | - return false; |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - if (isset($server['HTTPS'])) { |
|
77 | - if ($server['HTTPS'] === 'off') { |
|
78 | - // ISAPI on IIS breaks the spec. :( |
|
79 | - return false; |
|
80 | - } |
|
81 | - |
|
82 | - if ($server['HTTPS'] !== '') { |
|
83 | - // Set to a non-empty value |
|
84 | - return true; |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - return false; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Gets the path info |
|
93 | - * |
|
94 | - * @return array Array of path info segments |
|
95 | - */ |
|
96 | - public static function pathInfo() |
|
97 | - { |
|
98 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
99 | - if (!isset($server['PATH_INFO'])) { |
|
100 | - return array(); |
|
101 | - } |
|
102 | - |
|
103 | - $exploded = explode('/', $server['PATH_INFO']); |
|
104 | - |
|
105 | - // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
106 | - // with a / |
|
107 | - return array_values(array_filter($exploded)); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Gets the remote address of the web request |
|
112 | - * @return null|string |
|
113 | - */ |
|
114 | - public static function remoteAddress() |
|
115 | - { |
|
116 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
117 | - |
|
118 | - if (isset($server['REMOTE_ADDR'])) { |
|
119 | - return $server['REMOTE_ADDR']; |
|
120 | - } |
|
121 | - |
|
122 | - return null; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Gets the remote address of the web request |
|
127 | - * @return null|string |
|
128 | - */ |
|
129 | - public static function httpHost() |
|
130 | - { |
|
131 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
132 | - |
|
133 | - if (isset($server['HTTP_HOST'])) { |
|
134 | - return $server['HTTP_HOST']; |
|
135 | - } |
|
136 | - |
|
137 | - return null; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Gets the XFF header contents for the web request |
|
142 | - * @return null|string |
|
143 | - */ |
|
144 | - public static function forwardedAddress() |
|
145 | - { |
|
146 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
147 | - |
|
148 | - if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
149 | - return $server['HTTP_X_FORWARDED_FOR']; |
|
150 | - } |
|
151 | - |
|
152 | - return null; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Sets the global state provider. |
|
157 | - * |
|
158 | - * Almost guaranteed this is not the method you want in production code. |
|
159 | - * |
|
160 | - * @param IGlobalStateProvider $globalState |
|
161 | - */ |
|
162 | - public static function setGlobalStateProvider($globalState) |
|
163 | - { |
|
164 | - self::$globalStateProvider = $globalState; |
|
165 | - } |
|
166 | - |
|
167 | - #region POST variables |
|
168 | - |
|
169 | - /** |
|
170 | - * @param string $key |
|
171 | - * |
|
172 | - * @return null|string |
|
173 | - */ |
|
174 | - public static function postString($key) |
|
175 | - { |
|
176 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
177 | - if (!array_key_exists($key, $post)) { |
|
178 | - return null; |
|
179 | - } |
|
180 | - |
|
181 | - if ($post[$key] === "") { |
|
182 | - return null; |
|
183 | - } |
|
184 | - |
|
185 | - return (string)$post[$key]; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @param string $key |
|
190 | - * |
|
191 | - * @return null|string |
|
192 | - */ |
|
193 | - public static function postEmail($key) |
|
194 | - { |
|
195 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
196 | - if (!array_key_exists($key, $post)) { |
|
197 | - return null; |
|
198 | - } |
|
199 | - |
|
200 | - $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
201 | - |
|
202 | - if ($filteredValue === false) { |
|
203 | - return null; |
|
204 | - } |
|
205 | - |
|
206 | - return (string)$filteredValue; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @param string $key |
|
211 | - * |
|
212 | - * @return int|null |
|
213 | - */ |
|
214 | - public static function postInt($key) |
|
215 | - { |
|
216 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
217 | - if (!array_key_exists($key, $post)) { |
|
218 | - return null; |
|
219 | - } |
|
220 | - |
|
221 | - $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
222 | - |
|
223 | - if ($filteredValue === null) { |
|
224 | - return null; |
|
225 | - } |
|
226 | - |
|
227 | - return (int)$filteredValue; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @param string $key |
|
232 | - * |
|
233 | - * @return bool |
|
234 | - */ |
|
235 | - public static function postBoolean($key) |
|
236 | - { |
|
237 | - $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
238 | - if (!array_key_exists($key, $get)) { |
|
239 | - return false; |
|
240 | - } |
|
241 | - |
|
242 | - // presence of parameter only |
|
243 | - if ($get[$key] === "") { |
|
244 | - return true; |
|
245 | - } |
|
246 | - |
|
247 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
248 | - return false; |
|
249 | - } |
|
250 | - |
|
251 | - return true; |
|
252 | - } |
|
253 | - |
|
254 | - #endregion |
|
255 | - |
|
256 | - #region GET variables |
|
257 | - |
|
258 | - /** |
|
259 | - * @param string $key |
|
260 | - * |
|
261 | - * @return bool |
|
262 | - */ |
|
263 | - public static function getBoolean($key) |
|
264 | - { |
|
265 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
266 | - if (!array_key_exists($key, $get)) { |
|
267 | - return false; |
|
268 | - } |
|
269 | - |
|
270 | - // presence of parameter only |
|
271 | - if ($get[$key] === "") { |
|
272 | - return true; |
|
273 | - } |
|
274 | - |
|
275 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
276 | - return false; |
|
277 | - } |
|
278 | - |
|
279 | - return true; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * @param string $key |
|
284 | - * |
|
285 | - * @return int|null |
|
286 | - */ |
|
287 | - public static function getInt($key) |
|
288 | - { |
|
289 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
290 | - if (!array_key_exists($key, $get)) { |
|
291 | - return null; |
|
292 | - } |
|
293 | - |
|
294 | - $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
295 | - |
|
296 | - if ($filteredValue === null) { |
|
297 | - return null; |
|
298 | - } |
|
299 | - |
|
300 | - return (int)$filteredValue; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * @param string $key |
|
305 | - * |
|
306 | - * @return null|string |
|
307 | - */ |
|
308 | - public static function getString($key) |
|
309 | - { |
|
310 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
311 | - if (!array_key_exists($key, $get)) { |
|
312 | - return null; |
|
313 | - } |
|
314 | - |
|
315 | - if ($get[$key] === "") { |
|
316 | - return null; |
|
317 | - } |
|
318 | - |
|
319 | - return (string)$get[$key]; |
|
320 | - } |
|
321 | - |
|
322 | - #endregion |
|
323 | - |
|
324 | - /** |
|
325 | - * Sets the logged-in user to the specified user. |
|
326 | - * |
|
327 | - * @param User $user |
|
328 | - */ |
|
329 | - public static function setLoggedInUser(User $user) |
|
330 | - { |
|
331 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
332 | - |
|
333 | - $session['userID'] = $user->getId(); |
|
334 | - unset($session['partialLogin']); |
|
335 | - } |
|
336 | - |
|
337 | - public static function setActiveDomain(Domain $domain) |
|
338 | - { |
|
339 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
340 | - |
|
341 | - $session['domainID'] = $domain->getId(); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Sets the post-login redirect |
|
346 | - * |
|
347 | - * @param string|null $uri The URI to redirect to |
|
348 | - */ |
|
349 | - public static function setPostLoginRedirect($uri = null) |
|
350 | - { |
|
351 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
352 | - |
|
353 | - if ($uri === null) { |
|
354 | - $uri = self::requestUri(); |
|
355 | - } |
|
356 | - |
|
357 | - $session['returnTo'] = $uri; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * @return string|null |
|
362 | - */ |
|
363 | - public static function requestUri() |
|
364 | - { |
|
365 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
366 | - |
|
367 | - if (isset($server['REQUEST_URI'])) { |
|
368 | - return $server['REQUEST_URI']; |
|
369 | - } |
|
370 | - |
|
371 | - return null; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Clears the post-login redirect |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public static function clearPostLoginRedirect() |
|
379 | - { |
|
380 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
381 | - if (array_key_exists('returnTo', $session)) { |
|
382 | - $path = $session['returnTo']; |
|
383 | - unset($session['returnTo']); |
|
384 | - |
|
385 | - return $path; |
|
386 | - } |
|
387 | - |
|
388 | - return null; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * @return string|null |
|
393 | - */ |
|
394 | - public static function serverName() |
|
395 | - { |
|
396 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
397 | - |
|
398 | - if (isset($server['SERVER_NAME'])) { |
|
399 | - return $server['SERVER_NAME']; |
|
400 | - } |
|
401 | - |
|
402 | - return null; |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * You probably only want to deal with this through SessionAlert. |
|
407 | - * @return void |
|
408 | - */ |
|
409 | - public static function clearSessionAlertData() |
|
410 | - { |
|
411 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
412 | - if (array_key_exists('alerts', $session)) { |
|
413 | - unset($session['alerts']); |
|
414 | - } |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * You probably only want to deal with this through SessionAlert. |
|
419 | - * |
|
420 | - * @return string[] |
|
421 | - */ |
|
422 | - public static function getSessionAlertData() |
|
423 | - { |
|
424 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
425 | - if (array_key_exists('alerts', $session)) { |
|
426 | - return $session['alerts']; |
|
427 | - } |
|
428 | - |
|
429 | - return array(); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * You probably only want to deal with this through SessionAlert. |
|
434 | - * |
|
435 | - * @param string[] $data |
|
436 | - */ |
|
437 | - public static function setSessionAlertData($data) |
|
438 | - { |
|
439 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
440 | - $session['alerts'] = $data; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * You probably only want to deal with this through TokenManager. |
|
445 | - * |
|
446 | - * @return string[] |
|
447 | - */ |
|
448 | - public static function getSessionTokenData() |
|
449 | - { |
|
450 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
451 | - if (array_key_exists('tokens', $session)) { |
|
452 | - return $session['tokens']; |
|
453 | - } |
|
454 | - |
|
455 | - return array(); |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * You probably only want to deal with this through TokenManager. |
|
460 | - * |
|
461 | - * @param string[] $data |
|
462 | - */ |
|
463 | - public static function setSessionTokenData($data) |
|
464 | - { |
|
465 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
466 | - $session['tokens'] = $data; |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * @param string $key |
|
471 | - * |
|
472 | - * @return mixed |
|
473 | - */ |
|
474 | - public static function getSessionContext($key) |
|
475 | - { |
|
476 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
477 | - |
|
478 | - if (!isset($session['context'])) { |
|
479 | - $session['context'] = array(); |
|
480 | - } |
|
481 | - |
|
482 | - if (!isset($session['context'][$key])) { |
|
483 | - return null; |
|
484 | - } |
|
485 | - |
|
486 | - return $session['context'][$key]; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * @param string $key |
|
491 | - * @param mixed $data |
|
492 | - */ |
|
493 | - public static function setSessionContext($key, $data) |
|
494 | - { |
|
495 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
496 | - |
|
497 | - if (!isset($session['context'])) { |
|
498 | - $session['context'] = array(); |
|
499 | - } |
|
500 | - |
|
501 | - $session['context'][$key] = $data; |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * @return int|null |
|
506 | - */ |
|
507 | - public static function getSessionUserId() |
|
508 | - { |
|
509 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
510 | - |
|
511 | - return isset($session['userID']) ? (int)$session['userID'] : null; |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * @return int|null |
|
516 | - */ |
|
517 | - public static function getSessionDomain() |
|
518 | - { |
|
519 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
520 | - |
|
521 | - return isset($session['domainID']) ? (int)$session['domainID'] : null; |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * @param User $user |
|
526 | - */ |
|
527 | - public static function setOAuthPartialLogin(User $user) |
|
528 | - { |
|
529 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
530 | - $session['oauthPartialLogin'] = $user->getId(); |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * @return int|null |
|
535 | - */ |
|
536 | - public static function getOAuthPartialLogin() |
|
537 | - { |
|
538 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
539 | - |
|
540 | - return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
541 | - } |
|
542 | - |
|
543 | - public static function setAuthPartialLogin($userId, $stage) |
|
544 | - { |
|
545 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
546 | - $session['authPartialLoginId'] = $userId; |
|
547 | - $session['authPartialLoginStage'] = $stage; |
|
548 | - } |
|
549 | - |
|
550 | - public static function getAuthPartialLogin() |
|
551 | - { |
|
552 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
553 | - |
|
554 | - $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
555 | - $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
556 | - |
|
557 | - return array($userId, $stage); |
|
558 | - } |
|
559 | - |
|
560 | - public static function clearAuthPartialLogin() |
|
561 | - { |
|
562 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
563 | - unset($session['authPartialLoginId']); |
|
564 | - unset($session['authPartialLoginStage']); |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * @return null|string |
|
569 | - */ |
|
570 | - public static function userAgent() |
|
571 | - { |
|
572 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
573 | - |
|
574 | - if (isset($server['HTTP_USER_AGENT'])) { |
|
575 | - return $server['HTTP_USER_AGENT']; |
|
576 | - } |
|
577 | - |
|
578 | - return null; |
|
579 | - } |
|
580 | - |
|
581 | - /** |
|
582 | - * @return null|string |
|
583 | - */ |
|
584 | - public static function scriptName() |
|
585 | - { |
|
586 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
587 | - |
|
588 | - if (isset($server['SCRIPT_NAME'])) { |
|
589 | - return $server['SCRIPT_NAME']; |
|
590 | - } |
|
591 | - |
|
592 | - return null; |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * @return null|string |
|
597 | - */ |
|
598 | - public static function origin() |
|
599 | - { |
|
600 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
601 | - |
|
602 | - if (isset($server['HTTP_ORIGIN'])) { |
|
603 | - return $server['HTTP_ORIGIN']; |
|
604 | - } |
|
605 | - |
|
606 | - return null; |
|
607 | - } |
|
608 | - |
|
609 | - public static function httpHeader(string $headerName): ?string { |
|
610 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
611 | - |
|
612 | - $headerKey = strtoupper("HTTP_" . str_replace('-', '_', $headerName)); |
|
613 | - |
|
614 | - if (isset($server[$headerKey])) { |
|
615 | - return $server[$headerKey]; |
|
616 | - } |
|
617 | - |
|
618 | - return null; |
|
619 | - } |
|
620 | - |
|
621 | - public static function testSiteNoticeCookieValue($expectedHash) |
|
622 | - { |
|
623 | - $cookie = &self::$globalStateProvider->getCookieSuperGlobal(); |
|
624 | - |
|
625 | - if (isset($cookie['sitenotice'])) { |
|
626 | - return $cookie['sitenotice'] === $expectedHash; |
|
627 | - } |
|
628 | - |
|
629 | - return false; |
|
630 | - } |
|
631 | - |
|
632 | - public static function requestListDefaultSort() |
|
633 | - { |
|
634 | - $cookie = &self::$globalStateProvider->getCookieSuperGlobal(); |
|
635 | - |
|
636 | - if (isset($cookie['request_table_sort'])) { |
|
637 | - return explode('/', $cookie['request_table_sort'], 2); |
|
638 | - } |
|
639 | - else { |
|
640 | - return ['id', 'asc']; |
|
641 | - } |
|
642 | - } |
|
28 | + /** |
|
29 | + * @var IGlobalStateProvider Provides access to the global state. |
|
30 | + */ |
|
31 | + private static $globalStateProvider; |
|
32 | + |
|
33 | + /** |
|
34 | + * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + public static function wasPosted() |
|
38 | + { |
|
39 | + return self::method() === 'POST'; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Gets the HTTP Method used |
|
44 | + * @return string|null |
|
45 | + */ |
|
46 | + public static function method() |
|
47 | + { |
|
48 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
49 | + |
|
50 | + if (isset($server['REQUEST_METHOD'])) { |
|
51 | + return $server['REQUEST_METHOD']; |
|
52 | + } |
|
53 | + |
|
54 | + return null; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public static function isHttps() |
|
62 | + { |
|
63 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
64 | + |
|
65 | + if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
66 | + if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
67 | + // Client <=> Proxy is encrypted |
|
68 | + return true; |
|
69 | + } |
|
70 | + else { |
|
71 | + // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
72 | + return false; |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + if (isset($server['HTTPS'])) { |
|
77 | + if ($server['HTTPS'] === 'off') { |
|
78 | + // ISAPI on IIS breaks the spec. :( |
|
79 | + return false; |
|
80 | + } |
|
81 | + |
|
82 | + if ($server['HTTPS'] !== '') { |
|
83 | + // Set to a non-empty value |
|
84 | + return true; |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + return false; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Gets the path info |
|
93 | + * |
|
94 | + * @return array Array of path info segments |
|
95 | + */ |
|
96 | + public static function pathInfo() |
|
97 | + { |
|
98 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
99 | + if (!isset($server['PATH_INFO'])) { |
|
100 | + return array(); |
|
101 | + } |
|
102 | + |
|
103 | + $exploded = explode('/', $server['PATH_INFO']); |
|
104 | + |
|
105 | + // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
106 | + // with a / |
|
107 | + return array_values(array_filter($exploded)); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Gets the remote address of the web request |
|
112 | + * @return null|string |
|
113 | + */ |
|
114 | + public static function remoteAddress() |
|
115 | + { |
|
116 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
117 | + |
|
118 | + if (isset($server['REMOTE_ADDR'])) { |
|
119 | + return $server['REMOTE_ADDR']; |
|
120 | + } |
|
121 | + |
|
122 | + return null; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Gets the remote address of the web request |
|
127 | + * @return null|string |
|
128 | + */ |
|
129 | + public static function httpHost() |
|
130 | + { |
|
131 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
132 | + |
|
133 | + if (isset($server['HTTP_HOST'])) { |
|
134 | + return $server['HTTP_HOST']; |
|
135 | + } |
|
136 | + |
|
137 | + return null; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Gets the XFF header contents for the web request |
|
142 | + * @return null|string |
|
143 | + */ |
|
144 | + public static function forwardedAddress() |
|
145 | + { |
|
146 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
147 | + |
|
148 | + if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
149 | + return $server['HTTP_X_FORWARDED_FOR']; |
|
150 | + } |
|
151 | + |
|
152 | + return null; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Sets the global state provider. |
|
157 | + * |
|
158 | + * Almost guaranteed this is not the method you want in production code. |
|
159 | + * |
|
160 | + * @param IGlobalStateProvider $globalState |
|
161 | + */ |
|
162 | + public static function setGlobalStateProvider($globalState) |
|
163 | + { |
|
164 | + self::$globalStateProvider = $globalState; |
|
165 | + } |
|
166 | + |
|
167 | + #region POST variables |
|
168 | + |
|
169 | + /** |
|
170 | + * @param string $key |
|
171 | + * |
|
172 | + * @return null|string |
|
173 | + */ |
|
174 | + public static function postString($key) |
|
175 | + { |
|
176 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
177 | + if (!array_key_exists($key, $post)) { |
|
178 | + return null; |
|
179 | + } |
|
180 | + |
|
181 | + if ($post[$key] === "") { |
|
182 | + return null; |
|
183 | + } |
|
184 | + |
|
185 | + return (string)$post[$key]; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @param string $key |
|
190 | + * |
|
191 | + * @return null|string |
|
192 | + */ |
|
193 | + public static function postEmail($key) |
|
194 | + { |
|
195 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
196 | + if (!array_key_exists($key, $post)) { |
|
197 | + return null; |
|
198 | + } |
|
199 | + |
|
200 | + $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
201 | + |
|
202 | + if ($filteredValue === false) { |
|
203 | + return null; |
|
204 | + } |
|
205 | + |
|
206 | + return (string)$filteredValue; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @param string $key |
|
211 | + * |
|
212 | + * @return int|null |
|
213 | + */ |
|
214 | + public static function postInt($key) |
|
215 | + { |
|
216 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
217 | + if (!array_key_exists($key, $post)) { |
|
218 | + return null; |
|
219 | + } |
|
220 | + |
|
221 | + $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
222 | + |
|
223 | + if ($filteredValue === null) { |
|
224 | + return null; |
|
225 | + } |
|
226 | + |
|
227 | + return (int)$filteredValue; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @param string $key |
|
232 | + * |
|
233 | + * @return bool |
|
234 | + */ |
|
235 | + public static function postBoolean($key) |
|
236 | + { |
|
237 | + $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
238 | + if (!array_key_exists($key, $get)) { |
|
239 | + return false; |
|
240 | + } |
|
241 | + |
|
242 | + // presence of parameter only |
|
243 | + if ($get[$key] === "") { |
|
244 | + return true; |
|
245 | + } |
|
246 | + |
|
247 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
248 | + return false; |
|
249 | + } |
|
250 | + |
|
251 | + return true; |
|
252 | + } |
|
253 | + |
|
254 | + #endregion |
|
255 | + |
|
256 | + #region GET variables |
|
257 | + |
|
258 | + /** |
|
259 | + * @param string $key |
|
260 | + * |
|
261 | + * @return bool |
|
262 | + */ |
|
263 | + public static function getBoolean($key) |
|
264 | + { |
|
265 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
266 | + if (!array_key_exists($key, $get)) { |
|
267 | + return false; |
|
268 | + } |
|
269 | + |
|
270 | + // presence of parameter only |
|
271 | + if ($get[$key] === "") { |
|
272 | + return true; |
|
273 | + } |
|
274 | + |
|
275 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
276 | + return false; |
|
277 | + } |
|
278 | + |
|
279 | + return true; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * @param string $key |
|
284 | + * |
|
285 | + * @return int|null |
|
286 | + */ |
|
287 | + public static function getInt($key) |
|
288 | + { |
|
289 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
290 | + if (!array_key_exists($key, $get)) { |
|
291 | + return null; |
|
292 | + } |
|
293 | + |
|
294 | + $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
295 | + |
|
296 | + if ($filteredValue === null) { |
|
297 | + return null; |
|
298 | + } |
|
299 | + |
|
300 | + return (int)$filteredValue; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * @param string $key |
|
305 | + * |
|
306 | + * @return null|string |
|
307 | + */ |
|
308 | + public static function getString($key) |
|
309 | + { |
|
310 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
311 | + if (!array_key_exists($key, $get)) { |
|
312 | + return null; |
|
313 | + } |
|
314 | + |
|
315 | + if ($get[$key] === "") { |
|
316 | + return null; |
|
317 | + } |
|
318 | + |
|
319 | + return (string)$get[$key]; |
|
320 | + } |
|
321 | + |
|
322 | + #endregion |
|
323 | + |
|
324 | + /** |
|
325 | + * Sets the logged-in user to the specified user. |
|
326 | + * |
|
327 | + * @param User $user |
|
328 | + */ |
|
329 | + public static function setLoggedInUser(User $user) |
|
330 | + { |
|
331 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
332 | + |
|
333 | + $session['userID'] = $user->getId(); |
|
334 | + unset($session['partialLogin']); |
|
335 | + } |
|
336 | + |
|
337 | + public static function setActiveDomain(Domain $domain) |
|
338 | + { |
|
339 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
340 | + |
|
341 | + $session['domainID'] = $domain->getId(); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Sets the post-login redirect |
|
346 | + * |
|
347 | + * @param string|null $uri The URI to redirect to |
|
348 | + */ |
|
349 | + public static function setPostLoginRedirect($uri = null) |
|
350 | + { |
|
351 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
352 | + |
|
353 | + if ($uri === null) { |
|
354 | + $uri = self::requestUri(); |
|
355 | + } |
|
356 | + |
|
357 | + $session['returnTo'] = $uri; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * @return string|null |
|
362 | + */ |
|
363 | + public static function requestUri() |
|
364 | + { |
|
365 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
366 | + |
|
367 | + if (isset($server['REQUEST_URI'])) { |
|
368 | + return $server['REQUEST_URI']; |
|
369 | + } |
|
370 | + |
|
371 | + return null; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Clears the post-login redirect |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public static function clearPostLoginRedirect() |
|
379 | + { |
|
380 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
381 | + if (array_key_exists('returnTo', $session)) { |
|
382 | + $path = $session['returnTo']; |
|
383 | + unset($session['returnTo']); |
|
384 | + |
|
385 | + return $path; |
|
386 | + } |
|
387 | + |
|
388 | + return null; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * @return string|null |
|
393 | + */ |
|
394 | + public static function serverName() |
|
395 | + { |
|
396 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
397 | + |
|
398 | + if (isset($server['SERVER_NAME'])) { |
|
399 | + return $server['SERVER_NAME']; |
|
400 | + } |
|
401 | + |
|
402 | + return null; |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * You probably only want to deal with this through SessionAlert. |
|
407 | + * @return void |
|
408 | + */ |
|
409 | + public static function clearSessionAlertData() |
|
410 | + { |
|
411 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
412 | + if (array_key_exists('alerts', $session)) { |
|
413 | + unset($session['alerts']); |
|
414 | + } |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * You probably only want to deal with this through SessionAlert. |
|
419 | + * |
|
420 | + * @return string[] |
|
421 | + */ |
|
422 | + public static function getSessionAlertData() |
|
423 | + { |
|
424 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
425 | + if (array_key_exists('alerts', $session)) { |
|
426 | + return $session['alerts']; |
|
427 | + } |
|
428 | + |
|
429 | + return array(); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * You probably only want to deal with this through SessionAlert. |
|
434 | + * |
|
435 | + * @param string[] $data |
|
436 | + */ |
|
437 | + public static function setSessionAlertData($data) |
|
438 | + { |
|
439 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
440 | + $session['alerts'] = $data; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * You probably only want to deal with this through TokenManager. |
|
445 | + * |
|
446 | + * @return string[] |
|
447 | + */ |
|
448 | + public static function getSessionTokenData() |
|
449 | + { |
|
450 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
451 | + if (array_key_exists('tokens', $session)) { |
|
452 | + return $session['tokens']; |
|
453 | + } |
|
454 | + |
|
455 | + return array(); |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * You probably only want to deal with this through TokenManager. |
|
460 | + * |
|
461 | + * @param string[] $data |
|
462 | + */ |
|
463 | + public static function setSessionTokenData($data) |
|
464 | + { |
|
465 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
466 | + $session['tokens'] = $data; |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * @param string $key |
|
471 | + * |
|
472 | + * @return mixed |
|
473 | + */ |
|
474 | + public static function getSessionContext($key) |
|
475 | + { |
|
476 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
477 | + |
|
478 | + if (!isset($session['context'])) { |
|
479 | + $session['context'] = array(); |
|
480 | + } |
|
481 | + |
|
482 | + if (!isset($session['context'][$key])) { |
|
483 | + return null; |
|
484 | + } |
|
485 | + |
|
486 | + return $session['context'][$key]; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * @param string $key |
|
491 | + * @param mixed $data |
|
492 | + */ |
|
493 | + public static function setSessionContext($key, $data) |
|
494 | + { |
|
495 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
496 | + |
|
497 | + if (!isset($session['context'])) { |
|
498 | + $session['context'] = array(); |
|
499 | + } |
|
500 | + |
|
501 | + $session['context'][$key] = $data; |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * @return int|null |
|
506 | + */ |
|
507 | + public static function getSessionUserId() |
|
508 | + { |
|
509 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
510 | + |
|
511 | + return isset($session['userID']) ? (int)$session['userID'] : null; |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * @return int|null |
|
516 | + */ |
|
517 | + public static function getSessionDomain() |
|
518 | + { |
|
519 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
520 | + |
|
521 | + return isset($session['domainID']) ? (int)$session['domainID'] : null; |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * @param User $user |
|
526 | + */ |
|
527 | + public static function setOAuthPartialLogin(User $user) |
|
528 | + { |
|
529 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
530 | + $session['oauthPartialLogin'] = $user->getId(); |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * @return int|null |
|
535 | + */ |
|
536 | + public static function getOAuthPartialLogin() |
|
537 | + { |
|
538 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
539 | + |
|
540 | + return isset($session['oauthPartialLogin']) ? (int)$session['oauthPartialLogin'] : null; |
|
541 | + } |
|
542 | + |
|
543 | + public static function setAuthPartialLogin($userId, $stage) |
|
544 | + { |
|
545 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
546 | + $session['authPartialLoginId'] = $userId; |
|
547 | + $session['authPartialLoginStage'] = $stage; |
|
548 | + } |
|
549 | + |
|
550 | + public static function getAuthPartialLogin() |
|
551 | + { |
|
552 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
553 | + |
|
554 | + $userId = isset($session['authPartialLoginId']) ? (int)$session['authPartialLoginId'] : null; |
|
555 | + $stage = isset($session['authPartialLoginStage']) ? (int)$session['authPartialLoginStage'] : null; |
|
556 | + |
|
557 | + return array($userId, $stage); |
|
558 | + } |
|
559 | + |
|
560 | + public static function clearAuthPartialLogin() |
|
561 | + { |
|
562 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
563 | + unset($session['authPartialLoginId']); |
|
564 | + unset($session['authPartialLoginStage']); |
|
565 | + } |
|
566 | + |
|
567 | + /** |
|
568 | + * @return null|string |
|
569 | + */ |
|
570 | + public static function userAgent() |
|
571 | + { |
|
572 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
573 | + |
|
574 | + if (isset($server['HTTP_USER_AGENT'])) { |
|
575 | + return $server['HTTP_USER_AGENT']; |
|
576 | + } |
|
577 | + |
|
578 | + return null; |
|
579 | + } |
|
580 | + |
|
581 | + /** |
|
582 | + * @return null|string |
|
583 | + */ |
|
584 | + public static function scriptName() |
|
585 | + { |
|
586 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
587 | + |
|
588 | + if (isset($server['SCRIPT_NAME'])) { |
|
589 | + return $server['SCRIPT_NAME']; |
|
590 | + } |
|
591 | + |
|
592 | + return null; |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * @return null|string |
|
597 | + */ |
|
598 | + public static function origin() |
|
599 | + { |
|
600 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
601 | + |
|
602 | + if (isset($server['HTTP_ORIGIN'])) { |
|
603 | + return $server['HTTP_ORIGIN']; |
|
604 | + } |
|
605 | + |
|
606 | + return null; |
|
607 | + } |
|
608 | + |
|
609 | + public static function httpHeader(string $headerName): ?string { |
|
610 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
611 | + |
|
612 | + $headerKey = strtoupper("HTTP_" . str_replace('-', '_', $headerName)); |
|
613 | + |
|
614 | + if (isset($server[$headerKey])) { |
|
615 | + return $server[$headerKey]; |
|
616 | + } |
|
617 | + |
|
618 | + return null; |
|
619 | + } |
|
620 | + |
|
621 | + public static function testSiteNoticeCookieValue($expectedHash) |
|
622 | + { |
|
623 | + $cookie = &self::$globalStateProvider->getCookieSuperGlobal(); |
|
624 | + |
|
625 | + if (isset($cookie['sitenotice'])) { |
|
626 | + return $cookie['sitenotice'] === $expectedHash; |
|
627 | + } |
|
628 | + |
|
629 | + return false; |
|
630 | + } |
|
631 | + |
|
632 | + public static function requestListDefaultSort() |
|
633 | + { |
|
634 | + $cookie = &self::$globalStateProvider->getCookieSuperGlobal(); |
|
635 | + |
|
636 | + if (isset($cookie['request_table_sort'])) { |
|
637 | + return explode('/', $cookie['request_table_sort'], 2); |
|
638 | + } |
|
639 | + else { |
|
640 | + return ['id', 'asc']; |
|
641 | + } |
|
642 | + } |
|
643 | 643 | } |
@@ -66,8 +66,7 @@ discard block |
||
66 | 66 | if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
67 | 67 | // Client <=> Proxy is encrypted |
68 | 68 | return true; |
69 | - } |
|
70 | - else { |
|
69 | + } else { |
|
71 | 70 | // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
72 | 71 | return false; |
73 | 72 | } |
@@ -635,8 +634,7 @@ discard block |
||
635 | 634 | |
636 | 635 | if (isset($cookie['request_table_sort'])) { |
637 | 636 | return explode('/', $cookie['request_table_sort'], 2); |
638 | - } |
|
639 | - else { |
|
637 | + } else { |
|
640 | 638 | return ['id', 'asc']; |
641 | 639 | } |
642 | 640 | } |
@@ -10,8 +10,8 @@ |
||
10 | 10 | |
11 | 11 | class RequestStatus |
12 | 12 | { |
13 | - const HOSPITAL = 'Hospital'; |
|
14 | - const JOBQUEUE = 'JobQueue'; |
|
15 | - const CLOSED = 'Closed'; |
|
16 | - const OPEN = 'Open'; |
|
13 | + const HOSPITAL = 'Hospital'; |
|
14 | + const JOBQUEUE = 'JobQueue'; |
|
15 | + const CLOSED = 'Closed'; |
|
16 | + const OPEN = 'Open'; |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |