@@ -20,47 +20,47 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class CountAction extends ApiPageBase implements IApiAction |
22 | 22 | { |
23 | - /** |
|
24 | - * The target user |
|
25 | - * @var User $user |
|
26 | - */ |
|
27 | - private $user; |
|
23 | + /** |
|
24 | + * The target user |
|
25 | + * @var User $user |
|
26 | + */ |
|
27 | + private $user; |
|
28 | 28 | |
29 | - public function executeApiAction(DOMElement $apiDocument) |
|
30 | - { |
|
31 | - $username = WebRequest::getString('user'); |
|
32 | - if ($username === null) { |
|
33 | - throw new ApiException("Please specify a username"); |
|
34 | - } |
|
29 | + public function executeApiAction(DOMElement $apiDocument) |
|
30 | + { |
|
31 | + $username = WebRequest::getString('user'); |
|
32 | + if ($username === null) { |
|
33 | + throw new ApiException("Please specify a username"); |
|
34 | + } |
|
35 | 35 | |
36 | - $userElement = $this->document->createElement("user"); |
|
37 | - $userElement->setAttribute("name", $username); |
|
38 | - $apiDocument->appendChild($userElement); |
|
36 | + $userElement = $this->document->createElement("user"); |
|
37 | + $userElement->setAttribute("name", $username); |
|
38 | + $apiDocument->appendChild($userElement); |
|
39 | 39 | |
40 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
40 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
41 | 41 | |
42 | - if ($user === false) { |
|
43 | - $userElement->setAttribute("missing", "true"); |
|
42 | + if ($user === false) { |
|
43 | + $userElement->setAttribute("missing", "true"); |
|
44 | 44 | |
45 | - return $apiDocument; |
|
46 | - } |
|
45 | + return $apiDocument; |
|
46 | + } |
|
47 | 47 | |
48 | - $this->user = $user; |
|
48 | + $this->user = $user; |
|
49 | 49 | |
50 | - $userElement->setAttribute("level", $this->user->getStatus()); |
|
51 | - $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
50 | + $userElement->setAttribute("level", $this->user->getStatus()); |
|
51 | + $userElement->setAttribute("created", $this->getAccountsCreated()); |
|
52 | 52 | |
53 | - $userElement->setAttribute("today", $this->getToday()); |
|
53 | + $userElement->setAttribute("today", $this->getToday()); |
|
54 | 54 | |
55 | - // Let the IRC bot handle the result of this. |
|
56 | - $this->fetchAdminData($userElement); |
|
55 | + // Let the IRC bot handle the result of this. |
|
56 | + $this->fetchAdminData($userElement); |
|
57 | 57 | |
58 | - return $apiDocument; |
|
59 | - } |
|
58 | + return $apiDocument; |
|
59 | + } |
|
60 | 60 | |
61 | - private function getAccountsCreated() |
|
62 | - { |
|
63 | - $query = <<<QUERY |
|
61 | + private function getAccountsCreated() |
|
62 | + { |
|
63 | + $query = <<<QUERY |
|
64 | 64 | SELECT COUNT(*) AS count |
65 | 65 | FROM log |
66 | 66 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
@@ -71,17 +71,17 @@ discard block |
||
71 | 71 | AND user.username = :username; |
72 | 72 | QUERY; |
73 | 73 | |
74 | - $statement = $this->getDatabase()->prepare($query); |
|
75 | - $statement->execute(array(":username" => $this->user->getUsername())); |
|
76 | - $result = $statement->fetchColumn(); |
|
77 | - $statement->closeCursor(); |
|
74 | + $statement = $this->getDatabase()->prepare($query); |
|
75 | + $statement->execute(array(":username" => $this->user->getUsername())); |
|
76 | + $result = $statement->fetchColumn(); |
|
77 | + $statement->closeCursor(); |
|
78 | 78 | |
79 | - return $result; |
|
80 | - } |
|
79 | + return $result; |
|
80 | + } |
|
81 | 81 | |
82 | - private function getToday() |
|
83 | - { |
|
84 | - $query = <<<QUERY |
|
82 | + private function getToday() |
|
83 | + { |
|
84 | + $query = <<<QUERY |
|
85 | 85 | SELECT |
86 | 86 | COUNT(*) AS count |
87 | 87 | FROM log |
@@ -93,99 +93,99 @@ discard block |
||
93 | 93 | AND user.username = :username; |
94 | 94 | QUERY; |
95 | 95 | |
96 | - $statement = $this->getDatabase()->prepare($query); |
|
97 | - $statement->bindValue(":username", $this->user->getUsername()); |
|
98 | - $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
99 | - $statement->execute(); |
|
100 | - $today = $statement->fetchColumn(); |
|
101 | - $statement->closeCursor(); |
|
102 | - |
|
103 | - return $today; |
|
104 | - } |
|
105 | - |
|
106 | - private function fetchAdminData(DOMElement $userElement) |
|
107 | - { |
|
108 | - $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
109 | - |
|
110 | - $statement = $this->getDatabase()->prepare($query); |
|
111 | - $statement->bindValue(":userid", $this->user->getId()); |
|
112 | - $statement->bindValue(":action", "Suspended"); |
|
113 | - $statement->execute(); |
|
114 | - $sus = $statement->fetchColumn(); |
|
115 | - $userElement->setAttribute("suspended", $sus); |
|
116 | - $statement->closeCursor(); |
|
117 | - |
|
118 | - $statement->bindValue(":action", "Promoted"); |
|
119 | - $statement->execute(); |
|
120 | - $pro = $statement->fetchColumn(); |
|
121 | - $userElement->setAttribute("promoted", $pro); |
|
122 | - $statement->closeCursor(); |
|
123 | - |
|
124 | - $statement->bindValue(":action", "Approved"); |
|
125 | - $statement->execute(); |
|
126 | - $app = $statement->fetchColumn(); |
|
127 | - $userElement->setAttribute("approved", $app); |
|
128 | - $statement->closeCursor(); |
|
129 | - |
|
130 | - $statement->bindValue(":action", "Demoted"); |
|
131 | - $statement->execute(); |
|
132 | - $dem = $statement->fetchColumn(); |
|
133 | - $userElement->setAttribute("demoted", $dem); |
|
134 | - $statement->closeCursor(); |
|
135 | - |
|
136 | - $statement->bindValue(":action", "Declined"); |
|
137 | - $statement->execute(); |
|
138 | - $dec = $statement->fetchColumn(); |
|
139 | - $userElement->setAttribute("declined", $dec); |
|
140 | - $statement->closeCursor(); |
|
141 | - |
|
142 | - $statement->bindValue(":action", "Renamed"); |
|
143 | - $statement->execute(); |
|
144 | - $rnc = $statement->fetchColumn(); |
|
145 | - $userElement->setAttribute("renamed", $rnc); |
|
146 | - $statement->closeCursor(); |
|
147 | - |
|
148 | - $statement->bindValue(":action", "Edited"); |
|
149 | - $statement->execute(); |
|
150 | - $mec = $statement->fetchColumn(); |
|
151 | - $userElement->setAttribute("edited", $mec); |
|
152 | - $statement->closeCursor(); |
|
153 | - |
|
154 | - $statement->bindValue(":action", "Prefchange"); |
|
155 | - $statement->execute(); |
|
156 | - $pcc = $statement->fetchColumn(); |
|
157 | - $userElement->setAttribute("prefchange", $pcc); |
|
158 | - $statement->closeCursor(); |
|
159 | - |
|
160 | - // Combine all three actions affecting Welcome templates into one count. |
|
161 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
96 | + $statement = $this->getDatabase()->prepare($query); |
|
97 | + $statement->bindValue(":username", $this->user->getUsername()); |
|
98 | + $statement->bindValue(":date", date('Y-m-d') . "%"); |
|
99 | + $statement->execute(); |
|
100 | + $today = $statement->fetchColumn(); |
|
101 | + $statement->closeCursor(); |
|
102 | + |
|
103 | + return $today; |
|
104 | + } |
|
105 | + |
|
106 | + private function fetchAdminData(DOMElement $userElement) |
|
107 | + { |
|
108 | + $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;"; |
|
109 | + |
|
110 | + $statement = $this->getDatabase()->prepare($query); |
|
111 | + $statement->bindValue(":userid", $this->user->getId()); |
|
112 | + $statement->bindValue(":action", "Suspended"); |
|
113 | + $statement->execute(); |
|
114 | + $sus = $statement->fetchColumn(); |
|
115 | + $userElement->setAttribute("suspended", $sus); |
|
116 | + $statement->closeCursor(); |
|
117 | + |
|
118 | + $statement->bindValue(":action", "Promoted"); |
|
119 | + $statement->execute(); |
|
120 | + $pro = $statement->fetchColumn(); |
|
121 | + $userElement->setAttribute("promoted", $pro); |
|
122 | + $statement->closeCursor(); |
|
123 | + |
|
124 | + $statement->bindValue(":action", "Approved"); |
|
125 | + $statement->execute(); |
|
126 | + $app = $statement->fetchColumn(); |
|
127 | + $userElement->setAttribute("approved", $app); |
|
128 | + $statement->closeCursor(); |
|
129 | + |
|
130 | + $statement->bindValue(":action", "Demoted"); |
|
131 | + $statement->execute(); |
|
132 | + $dem = $statement->fetchColumn(); |
|
133 | + $userElement->setAttribute("demoted", $dem); |
|
134 | + $statement->closeCursor(); |
|
135 | + |
|
136 | + $statement->bindValue(":action", "Declined"); |
|
137 | + $statement->execute(); |
|
138 | + $dec = $statement->fetchColumn(); |
|
139 | + $userElement->setAttribute("declined", $dec); |
|
140 | + $statement->closeCursor(); |
|
141 | + |
|
142 | + $statement->bindValue(":action", "Renamed"); |
|
143 | + $statement->execute(); |
|
144 | + $rnc = $statement->fetchColumn(); |
|
145 | + $userElement->setAttribute("renamed", $rnc); |
|
146 | + $statement->closeCursor(); |
|
147 | + |
|
148 | + $statement->bindValue(":action", "Edited"); |
|
149 | + $statement->execute(); |
|
150 | + $mec = $statement->fetchColumn(); |
|
151 | + $userElement->setAttribute("edited", $mec); |
|
152 | + $statement->closeCursor(); |
|
153 | + |
|
154 | + $statement->bindValue(":action", "Prefchange"); |
|
155 | + $statement->execute(); |
|
156 | + $pcc = $statement->fetchColumn(); |
|
157 | + $userElement->setAttribute("prefchange", $pcc); |
|
158 | + $statement->closeCursor(); |
|
159 | + |
|
160 | + // Combine all three actions affecting Welcome templates into one count. |
|
161 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
162 | 162 | SELECT |
163 | 163 | COUNT(*) AS count |
164 | 164 | FROM log |
165 | 165 | WHERE log.user = :userid |
166 | 166 | AND log.action IN ('CreatedTemplate', 'EditedTemplate', 'DeletedTemplate'); |
167 | 167 | SQL |
168 | - ); |
|
168 | + ); |
|
169 | 169 | |
170 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
171 | - $combinedquery->execute(); |
|
172 | - $dtc = $combinedquery->fetchColumn(); |
|
173 | - $userElement->setAttribute("welctempchange", $dtc); |
|
174 | - $combinedquery->closeCursor(); |
|
170 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
171 | + $combinedquery->execute(); |
|
172 | + $dtc = $combinedquery->fetchColumn(); |
|
173 | + $userElement->setAttribute("welctempchange", $dtc); |
|
174 | + $combinedquery->closeCursor(); |
|
175 | 175 | |
176 | - // Combine both actions affecting Email templates into one count. |
|
177 | - $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
176 | + // Combine both actions affecting Email templates into one count. |
|
177 | + $combinedquery = $this->getDatabase()->prepare(<<<SQL |
|
178 | 178 | SELECT COUNT(*) AS count |
179 | 179 | FROM log |
180 | 180 | WHERE log.user = :userid |
181 | 181 | AND log.action IN ('CreatedEmail', 'EditedEmail'); |
182 | 182 | SQL |
183 | - ); |
|
184 | - |
|
185 | - $combinedquery->bindValue(":userid", $this->user->getId()); |
|
186 | - $combinedquery->execute(); |
|
187 | - $cec = $combinedquery->fetchColumn(); |
|
188 | - $userElement->setAttribute("emailtempchange", $cec); |
|
189 | - $combinedquery->closeCursor(); |
|
190 | - } |
|
183 | + ); |
|
184 | + |
|
185 | + $combinedquery->bindValue(":userid", $this->user->getId()); |
|
186 | + $combinedquery->execute(); |
|
187 | + $cec = $combinedquery->fetchColumn(); |
|
188 | + $userElement->setAttribute("emailtempchange", $cec); |
|
189 | + $combinedquery->closeCursor(); |
|
190 | + } |
|
191 | 191 | } |
@@ -18,34 +18,34 @@ |
||
18 | 18 | */ |
19 | 19 | class HelpAction extends ApiPageBase implements IApiAction |
20 | 20 | { |
21 | - public function executeApiAction(DOMElement $apiDocument) |
|
22 | - { |
|
23 | - $helpElement = $this->getHelpElement(); |
|
24 | - $apiDocument->appendChild($helpElement); |
|
25 | - |
|
26 | - return $apiDocument; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Gets the help information |
|
31 | - * @return DOMElement |
|
32 | - */ |
|
33 | - protected function getHelpElement() |
|
34 | - { |
|
35 | - $helpInfo = "Help info goes here!"; |
|
36 | - |
|
37 | - $help = $this->document->createElement("help"); |
|
38 | - $helptext = $this->document->createElement("info", $helpInfo); |
|
39 | - $helpactions = $this->document->createElement("actions"); |
|
40 | - |
|
41 | - foreach (ApiRequestRouter::getActionList() as $action) { |
|
42 | - $actionElement = $this->document->createElement("action", $action); |
|
43 | - $helpactions->appendChild($actionElement); |
|
44 | - } |
|
45 | - |
|
46 | - $help->appendChild($helptext); |
|
47 | - $help->appendChild($helpactions); |
|
48 | - |
|
49 | - return $help; |
|
50 | - } |
|
21 | + public function executeApiAction(DOMElement $apiDocument) |
|
22 | + { |
|
23 | + $helpElement = $this->getHelpElement(); |
|
24 | + $apiDocument->appendChild($helpElement); |
|
25 | + |
|
26 | + return $apiDocument; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Gets the help information |
|
31 | + * @return DOMElement |
|
32 | + */ |
|
33 | + protected function getHelpElement() |
|
34 | + { |
|
35 | + $helpInfo = "Help info goes here!"; |
|
36 | + |
|
37 | + $help = $this->document->createElement("help"); |
|
38 | + $helptext = $this->document->createElement("info", $helpInfo); |
|
39 | + $helpactions = $this->document->createElement("actions"); |
|
40 | + |
|
41 | + foreach (ApiRequestRouter::getActionList() as $action) { |
|
42 | + $actionElement = $this->document->createElement("action", $action); |
|
43 | + $helpactions->appendChild($actionElement); |
|
44 | + } |
|
45 | + |
|
46 | + $help->appendChild($helptext); |
|
47 | + $help->appendChild($helpactions); |
|
48 | + |
|
49 | + return $help; |
|
50 | + } |
|
51 | 51 | } |
@@ -23,65 +23,65 @@ |
||
23 | 23 | */ |
24 | 24 | class MonitorAction extends ApiPageBase implements IApiAction |
25 | 25 | { |
26 | - /** |
|
27 | - * @param DOMElement $apiDocument |
|
28 | - * |
|
29 | - * @return DOMElement |
|
30 | - */ |
|
31 | - public function executeApiAction(DOMElement $apiDocument) |
|
32 | - { |
|
33 | - $now = new DateTime(); |
|
26 | + /** |
|
27 | + * @param DOMElement $apiDocument |
|
28 | + * |
|
29 | + * @return DOMElement |
|
30 | + */ |
|
31 | + public function executeApiAction(DOMElement $apiDocument) |
|
32 | + { |
|
33 | + $now = new DateTime(); |
|
34 | 34 | |
35 | - $old = $this->getOldest(); |
|
36 | - $oldest = new DateTime($old); |
|
35 | + $old = $this->getOldest(); |
|
36 | + $oldest = new DateTime($old); |
|
37 | 37 | |
38 | - $new = $this->getNewest(); |
|
39 | - $newest = new DateTime($new); |
|
38 | + $new = $this->getNewest(); |
|
39 | + $newest = new DateTime($new); |
|
40 | 40 | |
41 | - $monitoringElement = $this->document->createElement("data"); |
|
42 | - $monitoringElement->setAttribute("date", $now->format('c')); |
|
43 | - $monitoringElement->setAttribute("oldest", $old === null ? null : $oldest->format('c')); |
|
44 | - $monitoringElement->setAttribute("newest", $new === null ? null : $newest->format('c')); |
|
45 | - $apiDocument->appendChild($monitoringElement); |
|
41 | + $monitoringElement = $this->document->createElement("data"); |
|
42 | + $monitoringElement->setAttribute("date", $now->format('c')); |
|
43 | + $monitoringElement->setAttribute("oldest", $old === null ? null : $oldest->format('c')); |
|
44 | + $monitoringElement->setAttribute("newest", $new === null ? null : $newest->format('c')); |
|
45 | + $apiDocument->appendChild($monitoringElement); |
|
46 | 46 | |
47 | - return $apiDocument; |
|
48 | - } |
|
47 | + return $apiDocument; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return string|null |
|
52 | - */ |
|
53 | - private function getOldest() |
|
54 | - { |
|
55 | - $statement = $this->getDatabase() |
|
56 | - ->prepare("SELECT min(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
57 | - $successful = $statement->execute(array( |
|
58 | - ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
59 | - ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
60 | - )); |
|
50 | + /** |
|
51 | + * @return string|null |
|
52 | + */ |
|
53 | + private function getOldest() |
|
54 | + { |
|
55 | + $statement = $this->getDatabase() |
|
56 | + ->prepare("SELECT min(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
57 | + $successful = $statement->execute(array( |
|
58 | + ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
59 | + ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
60 | + )); |
|
61 | 61 | |
62 | - if (!$successful) { |
|
63 | - return null; |
|
64 | - } |
|
62 | + if (!$successful) { |
|
63 | + return null; |
|
64 | + } |
|
65 | 65 | |
66 | - $result = $statement->fetchColumn(); |
|
66 | + $result = $statement->fetchColumn(); |
|
67 | 67 | |
68 | - return $result; |
|
69 | - } |
|
68 | + return $result; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - private function getNewest() |
|
75 | - { |
|
76 | - $statement = $this->getDatabase() |
|
77 | - ->prepare("SELECT max(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
78 | - $statement->execute(array( |
|
79 | - ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
80 | - ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
81 | - )); |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + private function getNewest() |
|
75 | + { |
|
76 | + $statement = $this->getDatabase() |
|
77 | + ->prepare("SELECT max(date) FROM request WHERE email != :email AND ip != :ip;"); |
|
78 | + $statement->execute(array( |
|
79 | + ':email' => $this->getSiteConfiguration()->getDataClearEmail(), |
|
80 | + ':ip' => $this->getSiteConfiguration()->getDataClearIp(), |
|
81 | + )); |
|
82 | 82 | |
83 | - $result = $statement->fetchColumn(0); |
|
83 | + $result = $statement->fetchColumn(0); |
|
84 | 84 | |
85 | - return $result; |
|
86 | - } |
|
85 | + return $result; |
|
86 | + } |
|
87 | 87 | } |
@@ -19,55 +19,55 @@ |
||
19 | 19 | */ |
20 | 20 | class StatsAction extends ApiPageBase implements IApiAction |
21 | 21 | { |
22 | - /** |
|
23 | - * The target user |
|
24 | - * @var User $user |
|
25 | - */ |
|
26 | - private $user; |
|
22 | + /** |
|
23 | + * The target user |
|
24 | + * @var User $user |
|
25 | + */ |
|
26 | + private $user; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Summary of execute |
|
30 | - * |
|
31 | - * @param \DOMElement $apiDocument |
|
32 | - * |
|
33 | - * @return \DOMElement |
|
34 | - * @throws ApiException |
|
35 | - * @throws \Exception |
|
36 | - */ |
|
37 | - public function executeApiAction(\DOMElement $apiDocument) |
|
38 | - { |
|
39 | - $username = WebRequest::getString('user'); |
|
40 | - $wikiusername = WebRequest::getString('wikiuser'); |
|
28 | + /** |
|
29 | + * Summary of execute |
|
30 | + * |
|
31 | + * @param \DOMElement $apiDocument |
|
32 | + * |
|
33 | + * @return \DOMElement |
|
34 | + * @throws ApiException |
|
35 | + * @throws \Exception |
|
36 | + */ |
|
37 | + public function executeApiAction(\DOMElement $apiDocument) |
|
38 | + { |
|
39 | + $username = WebRequest::getString('user'); |
|
40 | + $wikiusername = WebRequest::getString('wikiuser'); |
|
41 | 41 | |
42 | - if ($username === null && $wikiusername === null) { |
|
43 | - throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
44 | - } |
|
42 | + if ($username === null && $wikiusername === null) { |
|
43 | + throw new ApiException("Please specify a username using either user or wikiuser parameters."); |
|
44 | + } |
|
45 | 45 | |
46 | - $userElement = $this->document->createElement("user"); |
|
47 | - $apiDocument->appendChild($userElement); |
|
46 | + $userElement = $this->document->createElement("user"); |
|
47 | + $apiDocument->appendChild($userElement); |
|
48 | 48 | |
49 | - if ($username !== null) { |
|
50 | - $user = User::getByUsername($username, $this->getDatabase()); |
|
51 | - } |
|
52 | - else { |
|
53 | - $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
54 | - } |
|
49 | + if ($username !== null) { |
|
50 | + $user = User::getByUsername($username, $this->getDatabase()); |
|
51 | + } |
|
52 | + else { |
|
53 | + $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
|
54 | + } |
|
55 | 55 | |
56 | - if ($user === false) { |
|
57 | - $userElement->setAttribute("missing", "true"); |
|
56 | + if ($user === false) { |
|
57 | + $userElement->setAttribute("missing", "true"); |
|
58 | 58 | |
59 | - return $apiDocument; |
|
60 | - } |
|
59 | + return $apiDocument; |
|
60 | + } |
|
61 | 61 | |
62 | - $this->user = $user; |
|
62 | + $this->user = $user; |
|
63 | 63 | |
64 | - $userElement->setAttribute("username", $this->user->getUsername()); |
|
65 | - $userElement->setAttribute("status", $this->user->getStatus()); |
|
66 | - $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
67 | - $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
68 | - $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
69 | - $userElement->setAttribute("oauth", $this->user->isOAuthLinked() ? "true" : "false"); |
|
64 | + $userElement->setAttribute("username", $this->user->getUsername()); |
|
65 | + $userElement->setAttribute("status", $this->user->getStatus()); |
|
66 | + $userElement->setAttribute("lastactive", $this->user->getLastActive()); |
|
67 | + $userElement->setAttribute("welcome_template", $this->user->getWelcomeTemplate()); |
|
68 | + $userElement->setAttribute("onwikiname", $this->user->getOnWikiName()); |
|
69 | + $userElement->setAttribute("oauth", $this->user->isOAuthLinked() ? "true" : "false"); |
|
70 | 70 | |
71 | - return $apiDocument; |
|
72 | - } |
|
71 | + return $apiDocument; |
|
72 | + } |
|
73 | 73 | } |
@@ -48,8 +48,7 @@ |
||
48 | 48 | |
49 | 49 | if ($username !== null) { |
50 | 50 | $user = User::getByUsername($username, $this->getDatabase()); |
51 | - } |
|
52 | - else { |
|
51 | + } else { |
|
53 | 52 | $user = User::getByOnWikiUsername($wikiusername, $this->getDatabase()); |
54 | 53 | } |
55 | 54 |
@@ -17,17 +17,17 @@ |
||
17 | 17 | */ |
18 | 18 | interface IApiAction extends IRoutedTask |
19 | 19 | { |
20 | - /** |
|
21 | - * Method that runs API action |
|
22 | - * |
|
23 | - * @param DOMElement $apiDocument |
|
24 | - * |
|
25 | - * @return DOMElement The modified API document |
|
26 | - */ |
|
27 | - public function executeApiAction(DOMElement $apiDocument); |
|
20 | + /** |
|
21 | + * Method that runs API action |
|
22 | + * |
|
23 | + * @param DOMElement $apiDocument |
|
24 | + * |
|
25 | + * @return DOMElement The modified API document |
|
26 | + */ |
|
27 | + public function executeApiAction(DOMElement $apiDocument); |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return string the XML, or false if an error occurred. |
|
31 | - */ |
|
32 | - public function runApiPage(); |
|
29 | + /** |
|
30 | + * @return string the XML, or false if an error occurred. |
|
31 | + */ |
|
32 | + public function runApiPage(); |
|
33 | 33 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | */ |
16 | 16 | class ApiException extends Exception |
17 | 17 | { |
18 | - /** |
|
19 | - * @param string $message |
|
20 | - */ |
|
21 | - public function __construct($message) |
|
22 | - { |
|
23 | - $this->message = $message; |
|
24 | - } |
|
18 | + /** |
|
19 | + * @param string $message |
|
20 | + */ |
|
21 | + public function __construct($message) |
|
22 | + { |
|
23 | + $this->message = $message; |
|
24 | + } |
|
25 | 25 | } |
@@ -15,72 +15,72 @@ |
||
15 | 15 | |
16 | 16 | class ConsoleStart extends ApplicationBase |
17 | 17 | { |
18 | - /** |
|
19 | - * @var ConsoleTaskBase |
|
20 | - */ |
|
21 | - private $consoleTask; |
|
18 | + /** |
|
19 | + * @var ConsoleTaskBase |
|
20 | + */ |
|
21 | + private $consoleTask; |
|
22 | 22 | |
23 | - /** |
|
24 | - * ConsoleStart constructor. |
|
25 | - * |
|
26 | - * @param SiteConfiguration $configuration |
|
27 | - * @param ConsoleTaskBase $consoleTask |
|
28 | - */ |
|
29 | - public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask) |
|
30 | - { |
|
31 | - parent::__construct($configuration); |
|
32 | - $this->consoleTask = $consoleTask; |
|
33 | - } |
|
23 | + /** |
|
24 | + * ConsoleStart constructor. |
|
25 | + * |
|
26 | + * @param SiteConfiguration $configuration |
|
27 | + * @param ConsoleTaskBase $consoleTask |
|
28 | + */ |
|
29 | + public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask) |
|
30 | + { |
|
31 | + parent::__construct($configuration); |
|
32 | + $this->consoleTask = $consoleTask; |
|
33 | + } |
|
34 | 34 | |
35 | - protected function setupEnvironment() |
|
36 | - { |
|
37 | - // initialise super-global providers |
|
38 | - WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider()); |
|
35 | + protected function setupEnvironment() |
|
36 | + { |
|
37 | + // initialise super-global providers |
|
38 | + WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider()); |
|
39 | 39 | |
40 | - if (WebRequest::method() !== null) { |
|
41 | - throw new EnvironmentException('This is a console task, which cannot be executed via the web.'); |
|
42 | - } |
|
40 | + if (WebRequest::method() !== null) { |
|
41 | + throw new EnvironmentException('This is a console task, which cannot be executed via the web.'); |
|
42 | + } |
|
43 | 43 | |
44 | - return parent::setupEnvironment(); |
|
45 | - } |
|
44 | + return parent::setupEnvironment(); |
|
45 | + } |
|
46 | 46 | |
47 | - protected function cleanupEnvironment() |
|
48 | - { |
|
49 | - } |
|
47 | + protected function cleanupEnvironment() |
|
48 | + { |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Main application logic |
|
53 | - */ |
|
54 | - protected function main() |
|
55 | - { |
|
56 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
51 | + /** |
|
52 | + * Main application logic |
|
53 | + */ |
|
54 | + protected function main() |
|
55 | + { |
|
56 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
57 | 57 | |
58 | - if ($this->getConfiguration()->getIrcNotificationsEnabled()) { |
|
59 | - $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
60 | - } |
|
61 | - else { |
|
62 | - // pass through null |
|
63 | - $notificationsDatabase = null; |
|
64 | - } |
|
58 | + if ($this->getConfiguration()->getIrcNotificationsEnabled()) { |
|
59 | + $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
60 | + } |
|
61 | + else { |
|
62 | + // pass through null |
|
63 | + $notificationsDatabase = null; |
|
64 | + } |
|
65 | 65 | |
66 | - $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase); |
|
66 | + $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase); |
|
67 | 67 | |
68 | - // initialise a database transaction |
|
69 | - if (!$database->beginTransaction()) { |
|
70 | - throw new Exception('Failed to start transaction on primary database.'); |
|
71 | - } |
|
68 | + // initialise a database transaction |
|
69 | + if (!$database->beginTransaction()) { |
|
70 | + throw new Exception('Failed to start transaction on primary database.'); |
|
71 | + } |
|
72 | 72 | |
73 | - try { |
|
74 | - // run the task |
|
75 | - $this->consoleTask->execute(); |
|
73 | + try { |
|
74 | + // run the task |
|
75 | + $this->consoleTask->execute(); |
|
76 | 76 | |
77 | - $database->commit(); |
|
78 | - } |
|
79 | - finally { |
|
80 | - // Catch any hanging on transactions |
|
81 | - if ($database->hasActiveTransaction()) { |
|
82 | - $database->rollBack(); |
|
83 | - } |
|
84 | - } |
|
85 | - } |
|
77 | + $database->commit(); |
|
78 | + } |
|
79 | + finally { |
|
80 | + // Catch any hanging on transactions |
|
81 | + if ($database->hasActiveTransaction()) { |
|
82 | + $database->rollBack(); |
|
83 | + } |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
87 | 87 | \ No newline at end of file |
@@ -57,8 +57,7 @@ |
||
57 | 57 | |
58 | 58 | if ($this->getConfiguration()->getIrcNotificationsEnabled()) { |
59 | 59 | $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
60 | - } |
|
61 | - else { |
|
60 | + } else { |
|
62 | 61 | // pass through null |
63 | 62 | $notificationsDatabase = null; |
64 | 63 | } |
@@ -10,77 +10,77 @@ |
||
10 | 10 | |
11 | 11 | class StringFunctions |
12 | 12 | { |
13 | - /** |
|
14 | - * Formats a string to be used as a username. |
|
15 | - * |
|
16 | - * @param $username |
|
17 | - * |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function formatAsUsername($username) |
|
21 | - { |
|
22 | - // trim whitespace from the ends |
|
23 | - $uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username); |
|
13 | + /** |
|
14 | + * Formats a string to be used as a username. |
|
15 | + * |
|
16 | + * @param $username |
|
17 | + * |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function formatAsUsername($username) |
|
21 | + { |
|
22 | + // trim whitespace from the ends |
|
23 | + $uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username); |
|
24 | 24 | |
25 | - // convert first char to uppercase |
|
26 | - $uname = $this->ucfirst($uname); |
|
25 | + // convert first char to uppercase |
|
26 | + $uname = $this->ucfirst($uname); |
|
27 | 27 | |
28 | - // replace spaces with underscores |
|
29 | - $uname = mb_ereg_replace("[ ]+", "_", $uname); |
|
28 | + // replace spaces with underscores |
|
29 | + $uname = mb_ereg_replace("[ ]+", "_", $uname); |
|
30 | 30 | |
31 | - // trim underscores from the end |
|
32 | - $uname = mb_ereg_replace("[_]+$", "", $uname); |
|
31 | + // trim underscores from the end |
|
32 | + $uname = mb_ereg_replace("[_]+$", "", $uname); |
|
33 | 33 | |
34 | - return $uname; |
|
35 | - } |
|
34 | + return $uname; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Formats a string to be used as an email (specifically strips whitespace |
|
39 | - * from the beginning/end of the Email, as well as immediately before/after |
|
40 | - * the @ in the Email). |
|
41 | - * |
|
42 | - * @param $email |
|
43 | - * |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public static function formatAsEmail($email) |
|
47 | - { |
|
48 | - // trim whitespace from the ends |
|
49 | - $newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email); |
|
37 | + /** |
|
38 | + * Formats a string to be used as an email (specifically strips whitespace |
|
39 | + * from the beginning/end of the Email, as well as immediately before/after |
|
40 | + * the @ in the Email). |
|
41 | + * |
|
42 | + * @param $email |
|
43 | + * |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public static function formatAsEmail($email) |
|
47 | + { |
|
48 | + // trim whitespace from the ends |
|
49 | + $newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email); |
|
50 | 50 | |
51 | - // trim whitespace from around the email address |
|
52 | - $newemail = mb_ereg_replace("[ \t]+@", "@", $newemail); |
|
53 | - $newemail = mb_ereg_replace("@[ \t]+", "@", $newemail); |
|
51 | + // trim whitespace from around the email address |
|
52 | + $newemail = mb_ereg_replace("[ \t]+@", "@", $newemail); |
|
53 | + $newemail = mb_ereg_replace("@[ \t]+", "@", $newemail); |
|
54 | 54 | |
55 | - return $newemail; |
|
56 | - } |
|
55 | + return $newemail; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Returns true if a string is a multibyte string |
|
60 | - * |
|
61 | - * @param string $string |
|
62 | - * |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - public function isMultibyte($string) |
|
66 | - { |
|
67 | - return strlen($string) !== mb_strlen($string); |
|
68 | - } |
|
58 | + /** |
|
59 | + * Returns true if a string is a multibyte string |
|
60 | + * |
|
61 | + * @param string $string |
|
62 | + * |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + public function isMultibyte($string) |
|
66 | + { |
|
67 | + return strlen($string) !== mb_strlen($string); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Make a string's first character uppercase |
|
72 | - * |
|
73 | - * @param string $string |
|
74 | - * |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function ucfirst($string) |
|
78 | - { |
|
79 | - if (ord($string) < 128) { |
|
80 | - return ucfirst($string); |
|
81 | - } |
|
82 | - else { |
|
83 | - return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
84 | - } |
|
85 | - } |
|
70 | + /** |
|
71 | + * Make a string's first character uppercase |
|
72 | + * |
|
73 | + * @param string $string |
|
74 | + * |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function ucfirst($string) |
|
78 | + { |
|
79 | + if (ord($string) < 128) { |
|
80 | + return ucfirst($string); |
|
81 | + } |
|
82 | + else { |
|
83 | + return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
@@ -78,8 +78,7 @@ |
||
78 | 78 | { |
79 | 79 | if (ord($string) < 128) { |
80 | 80 | return ucfirst($string); |
81 | - } |
|
82 | - else { |
|
81 | + } else { |
|
83 | 82 | return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
84 | 83 | } |
85 | 84 | } |
@@ -22,521 +22,521 @@ |
||
22 | 22 | */ |
23 | 23 | class WebRequest |
24 | 24 | { |
25 | - /** |
|
26 | - * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | - */ |
|
28 | - private static $globalStateProvider; |
|
29 | - |
|
30 | - /** |
|
31 | - * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | - * @return bool |
|
33 | - */ |
|
34 | - public static function wasPosted() |
|
35 | - { |
|
36 | - return self::method() === 'POST'; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets the HTTP Method used |
|
41 | - * @return string|null |
|
42 | - */ |
|
43 | - public static function method() |
|
44 | - { |
|
45 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | - |
|
47 | - if (isset($server['REQUEST_METHOD'])) { |
|
48 | - return $server['REQUEST_METHOD']; |
|
49 | - } |
|
50 | - |
|
51 | - return null; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public static function isHttps() |
|
59 | - { |
|
60 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | - |
|
62 | - if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | - if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | - // Client <=> Proxy is encrypted |
|
65 | - return true; |
|
66 | - } |
|
67 | - else { |
|
68 | - // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | - return false; |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($server['HTTPS'])) { |
|
74 | - if ($server['HTTPS'] === 'off') { |
|
75 | - // ISAPI on IIS breaks the spec. :( |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - if ($server['HTTPS'] !== '') { |
|
80 | - // Set to a non-empty value |
|
81 | - return true; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - return false; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Gets the path info |
|
90 | - * |
|
91 | - * @return array Array of path info segments |
|
92 | - */ |
|
93 | - public static function pathInfo() |
|
94 | - { |
|
95 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | - if (!isset($server['PATH_INFO'])) { |
|
97 | - return array(); |
|
98 | - } |
|
99 | - |
|
100 | - $exploded = explode('/', $server['PATH_INFO']); |
|
101 | - |
|
102 | - // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | - // with a / |
|
104 | - return array_values(array_filter($exploded)); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Gets the remote address of the web request |
|
109 | - * @return null|string |
|
110 | - */ |
|
111 | - public static function remoteAddress() |
|
112 | - { |
|
113 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | - |
|
115 | - if (isset($server['REMOTE_ADDR'])) { |
|
116 | - return $server['REMOTE_ADDR']; |
|
117 | - } |
|
118 | - |
|
119 | - return null; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Gets the XFF header contents for the web request |
|
124 | - * @return null|string |
|
125 | - */ |
|
126 | - public static function forwardedAddress() |
|
127 | - { |
|
128 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | - |
|
130 | - if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
131 | - return $server['HTTP_X_FORWARDED_FOR']; |
|
132 | - } |
|
133 | - |
|
134 | - return null; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Sets the global state provider. |
|
139 | - * |
|
140 | - * Almost guaranteed this is not the method you want in production code. |
|
141 | - * |
|
142 | - * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
143 | - */ |
|
144 | - public static function setGlobalStateProvider($globalState) |
|
145 | - { |
|
146 | - self::$globalStateProvider = $globalState; |
|
147 | - } |
|
148 | - |
|
149 | - #region POST variables |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $key |
|
153 | - * |
|
154 | - * @return null|string |
|
155 | - */ |
|
156 | - public static function postString($key) |
|
157 | - { |
|
158 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
159 | - if (!array_key_exists($key, $post)) { |
|
160 | - return null; |
|
161 | - } |
|
162 | - |
|
163 | - if ($post[$key] === "") { |
|
164 | - return null; |
|
165 | - } |
|
166 | - |
|
167 | - return (string)$post[$key]; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $key |
|
172 | - * |
|
173 | - * @return null|string |
|
174 | - */ |
|
175 | - public static function postEmail($key) |
|
176 | - { |
|
177 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
178 | - if (!array_key_exists($key, $post)) { |
|
179 | - return null; |
|
180 | - } |
|
181 | - |
|
182 | - $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
183 | - |
|
184 | - if ($filteredValue === false) { |
|
185 | - return null; |
|
186 | - } |
|
187 | - |
|
188 | - return (string)$filteredValue; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param string $key |
|
193 | - * |
|
194 | - * @return int|null |
|
195 | - */ |
|
196 | - public static function postInt($key) |
|
197 | - { |
|
198 | - $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
199 | - if (!array_key_exists($key, $post)) { |
|
200 | - return null; |
|
201 | - } |
|
202 | - |
|
203 | - $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
204 | - |
|
205 | - if ($filteredValue === null) { |
|
206 | - return null; |
|
207 | - } |
|
208 | - |
|
209 | - return (int)$filteredValue; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param string $key |
|
214 | - * |
|
215 | - * @return bool |
|
216 | - */ |
|
217 | - public static function postBoolean($key) |
|
218 | - { |
|
219 | - $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
220 | - if (!array_key_exists($key, $get)) { |
|
221 | - return false; |
|
222 | - } |
|
223 | - |
|
224 | - // presence of parameter only |
|
225 | - if ($get[$key] === "") { |
|
226 | - return true; |
|
227 | - } |
|
228 | - |
|
229 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
230 | - return false; |
|
231 | - } |
|
232 | - |
|
233 | - return true; |
|
234 | - } |
|
235 | - |
|
236 | - #endregion |
|
237 | - |
|
238 | - #region GET variables |
|
239 | - |
|
240 | - /** |
|
241 | - * @param string $key |
|
242 | - * |
|
243 | - * @return bool |
|
244 | - */ |
|
245 | - public static function getBoolean($key) |
|
246 | - { |
|
247 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
248 | - if (!array_key_exists($key, $get)) { |
|
249 | - return false; |
|
250 | - } |
|
251 | - |
|
252 | - // presence of parameter only |
|
253 | - if ($get[$key] === "") { |
|
254 | - return true; |
|
255 | - } |
|
256 | - |
|
257 | - if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
258 | - return false; |
|
259 | - } |
|
260 | - |
|
261 | - return true; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @param string $key |
|
266 | - * |
|
267 | - * @return int|null |
|
268 | - */ |
|
269 | - public static function getInt($key) |
|
270 | - { |
|
271 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
272 | - if (!array_key_exists($key, $get)) { |
|
273 | - return null; |
|
274 | - } |
|
275 | - |
|
276 | - $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
277 | - |
|
278 | - if ($filteredValue === null) { |
|
279 | - return null; |
|
280 | - } |
|
281 | - |
|
282 | - return (int)$filteredValue; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * @param string $key |
|
287 | - * |
|
288 | - * @return null|string |
|
289 | - */ |
|
290 | - public static function getString($key) |
|
291 | - { |
|
292 | - $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
293 | - if (!array_key_exists($key, $get)) { |
|
294 | - return null; |
|
295 | - } |
|
296 | - |
|
297 | - if ($get[$key] === "") { |
|
298 | - return null; |
|
299 | - } |
|
300 | - |
|
301 | - return (string)$get[$key]; |
|
302 | - } |
|
303 | - |
|
304 | - #endregion |
|
305 | - |
|
306 | - /** |
|
307 | - * Sets the logged-in user to the specified user. |
|
308 | - * |
|
309 | - * @param User $user |
|
310 | - */ |
|
311 | - public static function setLoggedInUser(User $user) |
|
312 | - { |
|
313 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
314 | - |
|
315 | - $session['userID'] = $user->getId(); |
|
316 | - unset($session['partialLogin']); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Sets the post-login redirect |
|
321 | - */ |
|
322 | - public static function setPostLoginRedirect() |
|
323 | - { |
|
324 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
325 | - $session['returnTo'] = self::requestUri(); |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * @return string|null |
|
330 | - */ |
|
331 | - public static function requestUri() |
|
332 | - { |
|
333 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
334 | - |
|
335 | - if (isset($server['REQUEST_URI'])) { |
|
336 | - return $server['REQUEST_URI']; |
|
337 | - } |
|
338 | - |
|
339 | - return null; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Clears the post-login redirect |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public static function clearPostLoginRedirect() |
|
347 | - { |
|
348 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
349 | - if (array_key_exists('returnTo', $session)) { |
|
350 | - $path = $session['returnTo']; |
|
351 | - unset($session['returnTo']); |
|
352 | - |
|
353 | - return $path; |
|
354 | - } |
|
355 | - |
|
356 | - return null; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * @return string|null |
|
361 | - */ |
|
362 | - public static function serverName() |
|
363 | - { |
|
364 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
365 | - |
|
366 | - if (isset($server['SERVER_NAME'])) { |
|
367 | - return $server['SERVER_NAME']; |
|
368 | - } |
|
369 | - |
|
370 | - return null; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * You probably only want to deal with this through SessionAlert. |
|
375 | - * @return void |
|
376 | - */ |
|
377 | - public static function clearSessionAlertData() |
|
378 | - { |
|
379 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
380 | - if (array_key_exists('alerts', $session)) { |
|
381 | - unset($session['alerts']); |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * You probably only want to deal with this through SessionAlert. |
|
387 | - * |
|
388 | - * @return string[] |
|
389 | - */ |
|
390 | - public static function getSessionAlertData() |
|
391 | - { |
|
392 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
393 | - if (array_key_exists('alerts', $session)) { |
|
394 | - return $session['alerts']; |
|
395 | - } |
|
396 | - |
|
397 | - return array(); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * You probably only want to deal with this through SessionAlert. |
|
402 | - * |
|
403 | - * @param string[] $data |
|
404 | - */ |
|
405 | - public static function setSessionAlertData($data) |
|
406 | - { |
|
407 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
408 | - $session['alerts'] = $data; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * You probably only want to deal with this through TokenManager. |
|
413 | - * |
|
414 | - * @return string[] |
|
415 | - */ |
|
416 | - public static function getSessionTokenData() |
|
417 | - { |
|
418 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
419 | - if (array_key_exists('tokens', $session)) { |
|
420 | - return $session['tokens']; |
|
421 | - } |
|
422 | - |
|
423 | - return array(); |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * You probably only want to deal with this through TokenManager. |
|
428 | - * |
|
429 | - * @param string[] $data |
|
430 | - */ |
|
431 | - public static function setSessionTokenData($data) |
|
432 | - { |
|
433 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
434 | - $session['tokens'] = $data; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * @param string $key |
|
439 | - * |
|
440 | - * @return mixed |
|
441 | - */ |
|
442 | - public static function getSessionContext($key) |
|
443 | - { |
|
444 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
445 | - |
|
446 | - if (!isset($session['context'])) { |
|
447 | - $session['context'] = array(); |
|
448 | - } |
|
449 | - |
|
450 | - if (!isset($session['context'][$key])) { |
|
451 | - return null; |
|
452 | - } |
|
453 | - |
|
454 | - return $session['context'][$key]; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * @param string $key |
|
459 | - * @param mixed $data |
|
460 | - */ |
|
461 | - public static function setSessionContext($key, $data) |
|
462 | - { |
|
463 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
464 | - |
|
465 | - if (!isset($session['context'])) { |
|
466 | - $session['context'] = array(); |
|
467 | - } |
|
468 | - |
|
469 | - $session['context'][$key] = $data; |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * @return int|null |
|
474 | - */ |
|
475 | - public static function getSessionUserId() |
|
476 | - { |
|
477 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
478 | - |
|
479 | - return isset($session['userID']) ? (int)$session['userID'] : null; |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * @param User $user |
|
484 | - */ |
|
485 | - public static function setPartialLogin(User $user) |
|
486 | - { |
|
487 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
488 | - $session['partialLogin'] = $user->getId(); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * @return int|null |
|
493 | - */ |
|
494 | - public static function getPartialLogin() |
|
495 | - { |
|
496 | - $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
497 | - |
|
498 | - return isset($session['partialLogin']) ? (int)$session['partialLogin'] : null; |
|
499 | - } |
|
500 | - |
|
501 | - /** |
|
502 | - * @return null|string |
|
503 | - */ |
|
504 | - public static function userAgent() |
|
505 | - { |
|
506 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
507 | - |
|
508 | - if (isset($server['HTTP_USER_AGENT'])) { |
|
509 | - return $server['HTTP_USER_AGENT']; |
|
510 | - } |
|
511 | - |
|
512 | - return null; |
|
513 | - } |
|
514 | - |
|
515 | - /** |
|
516 | - * @return null|string |
|
517 | - */ |
|
518 | - public static function scriptName() |
|
519 | - { |
|
520 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
521 | - |
|
522 | - if (isset($server['SCRIPT_NAME'])) { |
|
523 | - return $server['SCRIPT_NAME']; |
|
524 | - } |
|
525 | - |
|
526 | - return null; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * @return null|string |
|
531 | - */ |
|
532 | - public static function origin() |
|
533 | - { |
|
534 | - $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
535 | - |
|
536 | - if (isset($server['HTTP_ORIGIN'])) { |
|
537 | - return $server['HTTP_ORIGIN']; |
|
538 | - } |
|
539 | - |
|
540 | - return null; |
|
541 | - } |
|
25 | + /** |
|
26 | + * @var \Waca\Providers\GlobalState\IGlobalStateProvider Provides access to the global state. |
|
27 | + */ |
|
28 | + private static $globalStateProvider; |
|
29 | + |
|
30 | + /** |
|
31 | + * Returns a boolean value if the request was submitted with the HTTP POST method. |
|
32 | + * @return bool |
|
33 | + */ |
|
34 | + public static function wasPosted() |
|
35 | + { |
|
36 | + return self::method() === 'POST'; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets the HTTP Method used |
|
41 | + * @return string|null |
|
42 | + */ |
|
43 | + public static function method() |
|
44 | + { |
|
45 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
46 | + |
|
47 | + if (isset($server['REQUEST_METHOD'])) { |
|
48 | + return $server['REQUEST_METHOD']; |
|
49 | + } |
|
50 | + |
|
51 | + return null; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Gets a boolean value stating whether the request was served over HTTPS or not. |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public static function isHttps() |
|
59 | + { |
|
60 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
61 | + |
|
62 | + if (isset($server['HTTP_X_FORWARDED_PROTO'])) { |
|
63 | + if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
64 | + // Client <=> Proxy is encrypted |
|
65 | + return true; |
|
66 | + } |
|
67 | + else { |
|
68 | + // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
|
69 | + return false; |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($server['HTTPS'])) { |
|
74 | + if ($server['HTTPS'] === 'off') { |
|
75 | + // ISAPI on IIS breaks the spec. :( |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + if ($server['HTTPS'] !== '') { |
|
80 | + // Set to a non-empty value |
|
81 | + return true; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + return false; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Gets the path info |
|
90 | + * |
|
91 | + * @return array Array of path info segments |
|
92 | + */ |
|
93 | + public static function pathInfo() |
|
94 | + { |
|
95 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
96 | + if (!isset($server['PATH_INFO'])) { |
|
97 | + return array(); |
|
98 | + } |
|
99 | + |
|
100 | + $exploded = explode('/', $server['PATH_INFO']); |
|
101 | + |
|
102 | + // filter out empty values, and reindex from zero. Notably, the first element is always zero, since it starts |
|
103 | + // with a / |
|
104 | + return array_values(array_filter($exploded)); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Gets the remote address of the web request |
|
109 | + * @return null|string |
|
110 | + */ |
|
111 | + public static function remoteAddress() |
|
112 | + { |
|
113 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
114 | + |
|
115 | + if (isset($server['REMOTE_ADDR'])) { |
|
116 | + return $server['REMOTE_ADDR']; |
|
117 | + } |
|
118 | + |
|
119 | + return null; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Gets the XFF header contents for the web request |
|
124 | + * @return null|string |
|
125 | + */ |
|
126 | + public static function forwardedAddress() |
|
127 | + { |
|
128 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
129 | + |
|
130 | + if (isset($server['HTTP_X_FORWARDED_FOR'])) { |
|
131 | + return $server['HTTP_X_FORWARDED_FOR']; |
|
132 | + } |
|
133 | + |
|
134 | + return null; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Sets the global state provider. |
|
139 | + * |
|
140 | + * Almost guaranteed this is not the method you want in production code. |
|
141 | + * |
|
142 | + * @param \Waca\Providers\GlobalState\IGlobalStateProvider $globalState |
|
143 | + */ |
|
144 | + public static function setGlobalStateProvider($globalState) |
|
145 | + { |
|
146 | + self::$globalStateProvider = $globalState; |
|
147 | + } |
|
148 | + |
|
149 | + #region POST variables |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $key |
|
153 | + * |
|
154 | + * @return null|string |
|
155 | + */ |
|
156 | + public static function postString($key) |
|
157 | + { |
|
158 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
159 | + if (!array_key_exists($key, $post)) { |
|
160 | + return null; |
|
161 | + } |
|
162 | + |
|
163 | + if ($post[$key] === "") { |
|
164 | + return null; |
|
165 | + } |
|
166 | + |
|
167 | + return (string)$post[$key]; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $key |
|
172 | + * |
|
173 | + * @return null|string |
|
174 | + */ |
|
175 | + public static function postEmail($key) |
|
176 | + { |
|
177 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
178 | + if (!array_key_exists($key, $post)) { |
|
179 | + return null; |
|
180 | + } |
|
181 | + |
|
182 | + $filteredValue = filter_var($post[$key], FILTER_SANITIZE_EMAIL); |
|
183 | + |
|
184 | + if ($filteredValue === false) { |
|
185 | + return null; |
|
186 | + } |
|
187 | + |
|
188 | + return (string)$filteredValue; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param string $key |
|
193 | + * |
|
194 | + * @return int|null |
|
195 | + */ |
|
196 | + public static function postInt($key) |
|
197 | + { |
|
198 | + $post = &self::$globalStateProvider->getPostSuperGlobal(); |
|
199 | + if (!array_key_exists($key, $post)) { |
|
200 | + return null; |
|
201 | + } |
|
202 | + |
|
203 | + $filteredValue = filter_var($post[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
204 | + |
|
205 | + if ($filteredValue === null) { |
|
206 | + return null; |
|
207 | + } |
|
208 | + |
|
209 | + return (int)$filteredValue; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param string $key |
|
214 | + * |
|
215 | + * @return bool |
|
216 | + */ |
|
217 | + public static function postBoolean($key) |
|
218 | + { |
|
219 | + $get = &self::$globalStateProvider->getPostSuperGlobal(); |
|
220 | + if (!array_key_exists($key, $get)) { |
|
221 | + return false; |
|
222 | + } |
|
223 | + |
|
224 | + // presence of parameter only |
|
225 | + if ($get[$key] === "") { |
|
226 | + return true; |
|
227 | + } |
|
228 | + |
|
229 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
230 | + return false; |
|
231 | + } |
|
232 | + |
|
233 | + return true; |
|
234 | + } |
|
235 | + |
|
236 | + #endregion |
|
237 | + |
|
238 | + #region GET variables |
|
239 | + |
|
240 | + /** |
|
241 | + * @param string $key |
|
242 | + * |
|
243 | + * @return bool |
|
244 | + */ |
|
245 | + public static function getBoolean($key) |
|
246 | + { |
|
247 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
248 | + if (!array_key_exists($key, $get)) { |
|
249 | + return false; |
|
250 | + } |
|
251 | + |
|
252 | + // presence of parameter only |
|
253 | + if ($get[$key] === "") { |
|
254 | + return true; |
|
255 | + } |
|
256 | + |
|
257 | + if (in_array($get[$key], array(false, 'no', 'off', 0, 'false'), true)) { |
|
258 | + return false; |
|
259 | + } |
|
260 | + |
|
261 | + return true; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @param string $key |
|
266 | + * |
|
267 | + * @return int|null |
|
268 | + */ |
|
269 | + public static function getInt($key) |
|
270 | + { |
|
271 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
272 | + if (!array_key_exists($key, $get)) { |
|
273 | + return null; |
|
274 | + } |
|
275 | + |
|
276 | + $filteredValue = filter_var($get[$key], FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
|
277 | + |
|
278 | + if ($filteredValue === null) { |
|
279 | + return null; |
|
280 | + } |
|
281 | + |
|
282 | + return (int)$filteredValue; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * @param string $key |
|
287 | + * |
|
288 | + * @return null|string |
|
289 | + */ |
|
290 | + public static function getString($key) |
|
291 | + { |
|
292 | + $get = &self::$globalStateProvider->getGetSuperGlobal(); |
|
293 | + if (!array_key_exists($key, $get)) { |
|
294 | + return null; |
|
295 | + } |
|
296 | + |
|
297 | + if ($get[$key] === "") { |
|
298 | + return null; |
|
299 | + } |
|
300 | + |
|
301 | + return (string)$get[$key]; |
|
302 | + } |
|
303 | + |
|
304 | + #endregion |
|
305 | + |
|
306 | + /** |
|
307 | + * Sets the logged-in user to the specified user. |
|
308 | + * |
|
309 | + * @param User $user |
|
310 | + */ |
|
311 | + public static function setLoggedInUser(User $user) |
|
312 | + { |
|
313 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
314 | + |
|
315 | + $session['userID'] = $user->getId(); |
|
316 | + unset($session['partialLogin']); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Sets the post-login redirect |
|
321 | + */ |
|
322 | + public static function setPostLoginRedirect() |
|
323 | + { |
|
324 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
325 | + $session['returnTo'] = self::requestUri(); |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * @return string|null |
|
330 | + */ |
|
331 | + public static function requestUri() |
|
332 | + { |
|
333 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
334 | + |
|
335 | + if (isset($server['REQUEST_URI'])) { |
|
336 | + return $server['REQUEST_URI']; |
|
337 | + } |
|
338 | + |
|
339 | + return null; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Clears the post-login redirect |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public static function clearPostLoginRedirect() |
|
347 | + { |
|
348 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
349 | + if (array_key_exists('returnTo', $session)) { |
|
350 | + $path = $session['returnTo']; |
|
351 | + unset($session['returnTo']); |
|
352 | + |
|
353 | + return $path; |
|
354 | + } |
|
355 | + |
|
356 | + return null; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * @return string|null |
|
361 | + */ |
|
362 | + public static function serverName() |
|
363 | + { |
|
364 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
365 | + |
|
366 | + if (isset($server['SERVER_NAME'])) { |
|
367 | + return $server['SERVER_NAME']; |
|
368 | + } |
|
369 | + |
|
370 | + return null; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * You probably only want to deal with this through SessionAlert. |
|
375 | + * @return void |
|
376 | + */ |
|
377 | + public static function clearSessionAlertData() |
|
378 | + { |
|
379 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
380 | + if (array_key_exists('alerts', $session)) { |
|
381 | + unset($session['alerts']); |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * You probably only want to deal with this through SessionAlert. |
|
387 | + * |
|
388 | + * @return string[] |
|
389 | + */ |
|
390 | + public static function getSessionAlertData() |
|
391 | + { |
|
392 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
393 | + if (array_key_exists('alerts', $session)) { |
|
394 | + return $session['alerts']; |
|
395 | + } |
|
396 | + |
|
397 | + return array(); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * You probably only want to deal with this through SessionAlert. |
|
402 | + * |
|
403 | + * @param string[] $data |
|
404 | + */ |
|
405 | + public static function setSessionAlertData($data) |
|
406 | + { |
|
407 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
408 | + $session['alerts'] = $data; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * You probably only want to deal with this through TokenManager. |
|
413 | + * |
|
414 | + * @return string[] |
|
415 | + */ |
|
416 | + public static function getSessionTokenData() |
|
417 | + { |
|
418 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
419 | + if (array_key_exists('tokens', $session)) { |
|
420 | + return $session['tokens']; |
|
421 | + } |
|
422 | + |
|
423 | + return array(); |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * You probably only want to deal with this through TokenManager. |
|
428 | + * |
|
429 | + * @param string[] $data |
|
430 | + */ |
|
431 | + public static function setSessionTokenData($data) |
|
432 | + { |
|
433 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
434 | + $session['tokens'] = $data; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * @param string $key |
|
439 | + * |
|
440 | + * @return mixed |
|
441 | + */ |
|
442 | + public static function getSessionContext($key) |
|
443 | + { |
|
444 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
445 | + |
|
446 | + if (!isset($session['context'])) { |
|
447 | + $session['context'] = array(); |
|
448 | + } |
|
449 | + |
|
450 | + if (!isset($session['context'][$key])) { |
|
451 | + return null; |
|
452 | + } |
|
453 | + |
|
454 | + return $session['context'][$key]; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * @param string $key |
|
459 | + * @param mixed $data |
|
460 | + */ |
|
461 | + public static function setSessionContext($key, $data) |
|
462 | + { |
|
463 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
464 | + |
|
465 | + if (!isset($session['context'])) { |
|
466 | + $session['context'] = array(); |
|
467 | + } |
|
468 | + |
|
469 | + $session['context'][$key] = $data; |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * @return int|null |
|
474 | + */ |
|
475 | + public static function getSessionUserId() |
|
476 | + { |
|
477 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
478 | + |
|
479 | + return isset($session['userID']) ? (int)$session['userID'] : null; |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * @param User $user |
|
484 | + */ |
|
485 | + public static function setPartialLogin(User $user) |
|
486 | + { |
|
487 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
488 | + $session['partialLogin'] = $user->getId(); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * @return int|null |
|
493 | + */ |
|
494 | + public static function getPartialLogin() |
|
495 | + { |
|
496 | + $session = &self::$globalStateProvider->getSessionSuperGlobal(); |
|
497 | + |
|
498 | + return isset($session['partialLogin']) ? (int)$session['partialLogin'] : null; |
|
499 | + } |
|
500 | + |
|
501 | + /** |
|
502 | + * @return null|string |
|
503 | + */ |
|
504 | + public static function userAgent() |
|
505 | + { |
|
506 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
507 | + |
|
508 | + if (isset($server['HTTP_USER_AGENT'])) { |
|
509 | + return $server['HTTP_USER_AGENT']; |
|
510 | + } |
|
511 | + |
|
512 | + return null; |
|
513 | + } |
|
514 | + |
|
515 | + /** |
|
516 | + * @return null|string |
|
517 | + */ |
|
518 | + public static function scriptName() |
|
519 | + { |
|
520 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
521 | + |
|
522 | + if (isset($server['SCRIPT_NAME'])) { |
|
523 | + return $server['SCRIPT_NAME']; |
|
524 | + } |
|
525 | + |
|
526 | + return null; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * @return null|string |
|
531 | + */ |
|
532 | + public static function origin() |
|
533 | + { |
|
534 | + $server = &self::$globalStateProvider->getServerSuperGlobal(); |
|
535 | + |
|
536 | + if (isset($server['HTTP_ORIGIN'])) { |
|
537 | + return $server['HTTP_ORIGIN']; |
|
538 | + } |
|
539 | + |
|
540 | + return null; |
|
541 | + } |
|
542 | 542 | } |
543 | 543 | \ No newline at end of file |
@@ -63,8 +63,7 @@ |
||
63 | 63 | if ($server['HTTP_X_FORWARDED_PROTO'] === 'https') { |
64 | 64 | // Client <=> Proxy is encrypted |
65 | 65 | return true; |
66 | - } |
|
67 | - else { |
|
66 | + } else { |
|
68 | 67 | // Proxy <=> Server link unknown, Client <=> Proxy is not encrypted. |
69 | 68 | return false; |
70 | 69 | } |