@@ -20,242 +20,242 @@ |
||
| 20 | 20 | |
| 21 | 21 | class PageCloseRequest extends RequestActionBase |
| 22 | 22 | { |
| 23 | - protected function main() |
|
| 24 | - { |
|
| 25 | - $this->processClose(); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Main function for this page, when no specific actions are called. |
|
| 30 | - * @throws ApplicationLogicException |
|
| 31 | - */ |
|
| 32 | - final protected function processClose() |
|
| 33 | - { |
|
| 34 | - $this->checkPosted(); |
|
| 35 | - $database = $this->getDatabase(); |
|
| 36 | - |
|
| 37 | - $currentUser = User::getCurrent($database); |
|
| 38 | - $template = $this->getTemplate($database); |
|
| 39 | - $request = $this->getRequest($database); |
|
| 40 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 41 | - |
|
| 42 | - if ($request->getStatus() === 'Closed') { |
|
| 43 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if ($this->confirmEmailAlreadySent($request, $template)) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) { |
|
| 51 | - return; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if ($this->confirmAccountCreated($request, $template)) { |
|
| 55 | - return; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // I think we're good here... |
|
| 59 | - $request->setStatus('Closed'); |
|
| 60 | - $request->setReserved(null); |
|
| 61 | - |
|
| 62 | - Logger::closeRequest($database, $request, $template->getId(), null); |
|
| 63 | - |
|
| 64 | - $request->save(); |
|
| 65 | - |
|
| 66 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 67 | - // be rolled back. |
|
| 68 | - |
|
| 69 | - $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
| 70 | - SessionAlert::success("Request {$request->getId()} has been closed"); |
|
| 71 | - |
|
| 72 | - $this->sendMail($request, $template->getText(), $currentUser, false); |
|
| 73 | - |
|
| 74 | - $this->redirect(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param PdoDatabase $database |
|
| 79 | - * |
|
| 80 | - * @return EmailTemplate |
|
| 81 | - * @throws ApplicationLogicException |
|
| 82 | - */ |
|
| 83 | - protected function getTemplate(PdoDatabase $database) |
|
| 84 | - { |
|
| 85 | - $templateId = WebRequest::postInt('template'); |
|
| 86 | - if ($templateId === null) { |
|
| 87 | - throw new ApplicationLogicException('No template specified'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** @var EmailTemplate $template */ |
|
| 91 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 92 | - if ($template === false || !$template->getActive()) { |
|
| 93 | - throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return $template; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param Request $request |
|
| 101 | - * @param EmailTemplate $template |
|
| 102 | - * |
|
| 103 | - * @return bool |
|
| 104 | - */ |
|
| 105 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 106 | - { |
|
| 107 | - if ($this->checkEmailAlreadySent($request)) { |
|
| 108 | - $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
| 109 | - |
|
| 110 | - return true; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return false; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - protected function checkEmailAlreadySent(Request $request) |
|
| 117 | - { |
|
| 118 | - if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
| 119 | - return true; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - protected function checkReserveOverride(Request $request, User $currentUser) |
|
| 126 | - { |
|
| 127 | - $reservationId = $request->getReserved(); |
|
| 128 | - |
|
| 129 | - if ($reservationId !== 0 && $reservationId !== null) { |
|
| 130 | - if (!WebRequest::postBoolean('reserveOverride')) { |
|
| 131 | - if ($currentUser->getId() !== $reservationId) { |
|
| 132 | - return true; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - return false; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param Request $request |
|
| 142 | - * @param EmailTemplate $template |
|
| 143 | - * @param User $currentUser |
|
| 144 | - * @param PdoDatabase $database |
|
| 145 | - * |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - protected function confirmReserveOverride( |
|
| 149 | - Request $request, |
|
| 150 | - EmailTemplate $template, |
|
| 151 | - User $currentUser, |
|
| 152 | - PdoDatabase $database |
|
| 153 | - ) { |
|
| 154 | - if ($this->checkReserveOverride($request, $currentUser)) { |
|
| 155 | - $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername()); |
|
| 156 | - $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl'); |
|
| 157 | - |
|
| 158 | - return true; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param Request $request |
|
| 166 | - * @param EmailTemplate $template |
|
| 167 | - * |
|
| 168 | - * @return bool |
|
| 169 | - * @throws \Waca\Exceptions\CurlException |
|
| 170 | - */ |
|
| 171 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 172 | - { |
|
| 173 | - if ($this->checkAccountCreated($request, $template)) { |
|
| 174 | - $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
| 175 | - |
|
| 176 | - return true; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
| 183 | - { |
|
| 184 | - if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
| 185 | - $parameters = array( |
|
| 186 | - 'action' => 'query', |
|
| 187 | - 'list' => 'users', |
|
| 188 | - 'format' => 'php', |
|
| 189 | - 'ususers' => $request->getName(), |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 193 | - $parameters); |
|
| 194 | - |
|
| 195 | - $apiResult = unserialize($content); |
|
| 196 | - $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
| 197 | - |
|
| 198 | - if (!$exists) { |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @param Request $request |
|
| 208 | - * @param string $mailText |
|
| 209 | - * @param User $currentUser |
|
| 210 | - * @param boolean $ccMailingList |
|
| 211 | - */ |
|
| 212 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 213 | - { |
|
| 214 | - $headers = array( |
|
| 215 | - 'X-ACC-Request' => $request->getId(), |
|
| 216 | - 'X-ACC-UserID' => $currentUser->getId(), |
|
| 217 | - ); |
|
| 218 | - |
|
| 219 | - if ($ccMailingList) { |
|
| 220 | - $headers['Cc'] = '[email protected]'; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $helper = $this->getEmailHelper(); |
|
| 224 | - |
|
| 225 | - $emailSig = $currentUser->getEmailSig(); |
|
| 226 | - if ($emailSig !== '' || $emailSig !== null) { |
|
| 227 | - $emailSig = "\n\n" . $emailSig; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
|
| 231 | - $content = $mailText . $emailSig; |
|
| 232 | - |
|
| 233 | - $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
|
| 234 | - |
|
| 235 | - $request->setEmailSent(true); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param Request $request |
|
| 240 | - * @param EmailTemplate $template |
|
| 241 | - * @param string $templateName |
|
| 242 | - * |
|
| 243 | - * @throws Exception |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
| 247 | - { |
|
| 248 | - $this->assignCSRFToken(); |
|
| 249 | - |
|
| 250 | - $this->assign('request', $request->getId()); |
|
| 251 | - $this->assign('template', $template->getId()); |
|
| 252 | - |
|
| 253 | - $this->assign('updateversion', $request->getUpdateVersion()); |
|
| 254 | - |
|
| 255 | - $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
| 256 | - $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
| 257 | - $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
| 258 | - |
|
| 259 | - $this->setTemplate($templateName); |
|
| 260 | - } |
|
| 23 | + protected function main() |
|
| 24 | + { |
|
| 25 | + $this->processClose(); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Main function for this page, when no specific actions are called. |
|
| 30 | + * @throws ApplicationLogicException |
|
| 31 | + */ |
|
| 32 | + final protected function processClose() |
|
| 33 | + { |
|
| 34 | + $this->checkPosted(); |
|
| 35 | + $database = $this->getDatabase(); |
|
| 36 | + |
|
| 37 | + $currentUser = User::getCurrent($database); |
|
| 38 | + $template = $this->getTemplate($database); |
|
| 39 | + $request = $this->getRequest($database); |
|
| 40 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 41 | + |
|
| 42 | + if ($request->getStatus() === 'Closed') { |
|
| 43 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if ($this->confirmEmailAlreadySent($request, $template)) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) { |
|
| 51 | + return; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if ($this->confirmAccountCreated($request, $template)) { |
|
| 55 | + return; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // I think we're good here... |
|
| 59 | + $request->setStatus('Closed'); |
|
| 60 | + $request->setReserved(null); |
|
| 61 | + |
|
| 62 | + Logger::closeRequest($database, $request, $template->getId(), null); |
|
| 63 | + |
|
| 64 | + $request->save(); |
|
| 65 | + |
|
| 66 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 67 | + // be rolled back. |
|
| 68 | + |
|
| 69 | + $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
| 70 | + SessionAlert::success("Request {$request->getId()} has been closed"); |
|
| 71 | + |
|
| 72 | + $this->sendMail($request, $template->getText(), $currentUser, false); |
|
| 73 | + |
|
| 74 | + $this->redirect(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param PdoDatabase $database |
|
| 79 | + * |
|
| 80 | + * @return EmailTemplate |
|
| 81 | + * @throws ApplicationLogicException |
|
| 82 | + */ |
|
| 83 | + protected function getTemplate(PdoDatabase $database) |
|
| 84 | + { |
|
| 85 | + $templateId = WebRequest::postInt('template'); |
|
| 86 | + if ($templateId === null) { |
|
| 87 | + throw new ApplicationLogicException('No template specified'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** @var EmailTemplate $template */ |
|
| 91 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 92 | + if ($template === false || !$template->getActive()) { |
|
| 93 | + throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return $template; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param Request $request |
|
| 101 | + * @param EmailTemplate $template |
|
| 102 | + * |
|
| 103 | + * @return bool |
|
| 104 | + */ |
|
| 105 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 106 | + { |
|
| 107 | + if ($this->checkEmailAlreadySent($request)) { |
|
| 108 | + $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
| 109 | + |
|
| 110 | + return true; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return false; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + protected function checkEmailAlreadySent(Request $request) |
|
| 117 | + { |
|
| 118 | + if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
| 119 | + return true; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + protected function checkReserveOverride(Request $request, User $currentUser) |
|
| 126 | + { |
|
| 127 | + $reservationId = $request->getReserved(); |
|
| 128 | + |
|
| 129 | + if ($reservationId !== 0 && $reservationId !== null) { |
|
| 130 | + if (!WebRequest::postBoolean('reserveOverride')) { |
|
| 131 | + if ($currentUser->getId() !== $reservationId) { |
|
| 132 | + return true; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + return false; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param Request $request |
|
| 142 | + * @param EmailTemplate $template |
|
| 143 | + * @param User $currentUser |
|
| 144 | + * @param PdoDatabase $database |
|
| 145 | + * |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + protected function confirmReserveOverride( |
|
| 149 | + Request $request, |
|
| 150 | + EmailTemplate $template, |
|
| 151 | + User $currentUser, |
|
| 152 | + PdoDatabase $database |
|
| 153 | + ) { |
|
| 154 | + if ($this->checkReserveOverride($request, $currentUser)) { |
|
| 155 | + $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername()); |
|
| 156 | + $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl'); |
|
| 157 | + |
|
| 158 | + return true; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param Request $request |
|
| 166 | + * @param EmailTemplate $template |
|
| 167 | + * |
|
| 168 | + * @return bool |
|
| 169 | + * @throws \Waca\Exceptions\CurlException |
|
| 170 | + */ |
|
| 171 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 172 | + { |
|
| 173 | + if ($this->checkAccountCreated($request, $template)) { |
|
| 174 | + $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
| 175 | + |
|
| 176 | + return true; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
| 183 | + { |
|
| 184 | + if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
| 185 | + $parameters = array( |
|
| 186 | + 'action' => 'query', |
|
| 187 | + 'list' => 'users', |
|
| 188 | + 'format' => 'php', |
|
| 189 | + 'ususers' => $request->getName(), |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 193 | + $parameters); |
|
| 194 | + |
|
| 195 | + $apiResult = unserialize($content); |
|
| 196 | + $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
| 197 | + |
|
| 198 | + if (!$exists) { |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @param Request $request |
|
| 208 | + * @param string $mailText |
|
| 209 | + * @param User $currentUser |
|
| 210 | + * @param boolean $ccMailingList |
|
| 211 | + */ |
|
| 212 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 213 | + { |
|
| 214 | + $headers = array( |
|
| 215 | + 'X-ACC-Request' => $request->getId(), |
|
| 216 | + 'X-ACC-UserID' => $currentUser->getId(), |
|
| 217 | + ); |
|
| 218 | + |
|
| 219 | + if ($ccMailingList) { |
|
| 220 | + $headers['Cc'] = '[email protected]'; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $helper = $this->getEmailHelper(); |
|
| 224 | + |
|
| 225 | + $emailSig = $currentUser->getEmailSig(); |
|
| 226 | + if ($emailSig !== '' || $emailSig !== null) { |
|
| 227 | + $emailSig = "\n\n" . $emailSig; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $subject = "RE: [ACC #{$request->getId()}] English Wikipedia Account Request"; |
|
| 231 | + $content = $mailText . $emailSig; |
|
| 232 | + |
|
| 233 | + $helper->sendMail($request->getEmail(), $subject, $content, $headers); |
|
| 234 | + |
|
| 235 | + $request->setEmailSent(true); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param Request $request |
|
| 240 | + * @param EmailTemplate $template |
|
| 241 | + * @param string $templateName |
|
| 242 | + * |
|
| 243 | + * @throws Exception |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
| 247 | + { |
|
| 248 | + $this->assignCSRFToken(); |
|
| 249 | + |
|
| 250 | + $this->assign('request', $request->getId()); |
|
| 251 | + $this->assign('template', $template->getId()); |
|
| 252 | + |
|
| 253 | + $this->assign('updateversion', $request->getUpdateVersion()); |
|
| 254 | + |
|
| 255 | + $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
| 256 | + $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
| 257 | + $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
| 258 | + |
|
| 259 | + $this->setTemplate($templateName); |
|
| 260 | + } |
|
| 261 | 261 | } |
@@ -17,57 +17,57 @@ |
||
| 17 | 17 | |
| 18 | 18 | class PageDeferRequest extends RequestActionBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Main function for this page, when no specific actions are called. |
|
| 22 | - * @throws ApplicationLogicException |
|
| 23 | - */ |
|
| 24 | - protected function main() |
|
| 25 | - { |
|
| 26 | - $this->checkPosted(); |
|
| 27 | - $database = $this->getDatabase(); |
|
| 28 | - $request = $this->getRequest($database); |
|
| 29 | - $currentUser = User::getCurrent($database); |
|
| 20 | + /** |
|
| 21 | + * Main function for this page, when no specific actions are called. |
|
| 22 | + * @throws ApplicationLogicException |
|
| 23 | + */ |
|
| 24 | + protected function main() |
|
| 25 | + { |
|
| 26 | + $this->checkPosted(); |
|
| 27 | + $database = $this->getDatabase(); |
|
| 28 | + $request = $this->getRequest($database); |
|
| 29 | + $currentUser = User::getCurrent($database); |
|
| 30 | 30 | |
| 31 | - $target = WebRequest::postString('target'); |
|
| 32 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 31 | + $target = WebRequest::postString('target'); |
|
| 32 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 33 | 33 | |
| 34 | - if (!array_key_exists($target, $requestStates)) { |
|
| 35 | - throw new ApplicationLogicException('Defer target not valid'); |
|
| 36 | - } |
|
| 34 | + if (!array_key_exists($target, $requestStates)) { |
|
| 35 | + throw new ApplicationLogicException('Defer target not valid'); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - if ($request->getStatus() == $target) { |
|
| 39 | - SessionAlert::warning('This request is already in the specified queue.'); |
|
| 40 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 38 | + if ($request->getStatus() == $target) { |
|
| 39 | + SessionAlert::warning('This request is already in the specified queue.'); |
|
| 40 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 41 | 41 | |
| 42 | - return; |
|
| 43 | - } |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $closureDate = $request->getClosureDate(); |
|
| 46 | - $date = new DateTime(); |
|
| 47 | - $date->modify("-7 days"); |
|
| 48 | - $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 45 | + $closureDate = $request->getClosureDate(); |
|
| 46 | + $date = new DateTime(); |
|
| 47 | + $date->modify("-7 days"); |
|
| 48 | + $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 52 | - if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 53 | - throw new ApplicationLogicException( |
|
| 54 | - "You are not allowed to re-open a request that has been closed for over a week."); |
|
| 55 | - } |
|
| 56 | - } |
|
| 51 | + if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 52 | + if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 53 | + throw new ApplicationLogicException( |
|
| 54 | + "You are not allowed to re-open a request that has been closed for over a week."); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $request->setReserved(null); |
|
| 59 | - $request->setStatus($target); |
|
| 60 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 61 | - $request->save(); |
|
| 58 | + $request->setReserved(null); |
|
| 59 | + $request->setStatus($target); |
|
| 60 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 61 | + $request->save(); |
|
| 62 | 62 | |
| 63 | - $deto = $requestStates[$target]['deferto']; |
|
| 64 | - $detolog = $requestStates[$target]['defertolog']; |
|
| 63 | + $deto = $requestStates[$target]['deferto']; |
|
| 64 | + $detolog = $requestStates[$target]['defertolog']; |
|
| 65 | 65 | |
| 66 | - Logger::deferRequest($database, $request, $detolog); |
|
| 66 | + Logger::deferRequest($database, $request, $detolog); |
|
| 67 | 67 | |
| 68 | - $this->getNotificationHelper()->requestDeferred($request); |
|
| 69 | - SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
| 68 | + $this->getNotificationHelper()->requestDeferred($request); |
|
| 69 | + SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
| 70 | 70 | |
| 71 | - $this->redirect(); |
|
| 72 | - } |
|
| 71 | + $this->redirect(); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -17,58 +17,58 @@ |
||
| 17 | 17 | |
| 18 | 18 | class PageReservation extends RequestActionBase |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Main function for this page, when no specific actions are called. |
|
| 22 | - * @throws ApplicationLogicException |
|
| 23 | - */ |
|
| 24 | - protected function main() |
|
| 25 | - { |
|
| 26 | - $this->checkPosted(); |
|
| 27 | - $database = $this->getDatabase(); |
|
| 28 | - $request = $this->getRequest($database); |
|
| 20 | + /** |
|
| 21 | + * Main function for this page, when no specific actions are called. |
|
| 22 | + * @throws ApplicationLogicException |
|
| 23 | + */ |
|
| 24 | + protected function main() |
|
| 25 | + { |
|
| 26 | + $this->checkPosted(); |
|
| 27 | + $database = $this->getDatabase(); |
|
| 28 | + $request = $this->getRequest($database); |
|
| 29 | 29 | |
| 30 | - $closureDate = $request->getClosureDate(); |
|
| 30 | + $closureDate = $request->getClosureDate(); |
|
| 31 | 31 | |
| 32 | - $date = new DateTime(); |
|
| 33 | - $date->modify("-7 days"); |
|
| 34 | - $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 32 | + $date = new DateTime(); |
|
| 33 | + $date->modify("-7 days"); |
|
| 34 | + $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 35 | 35 | |
| 36 | - $currentUser = User::getCurrent($database); |
|
| 37 | - if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 38 | - if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 39 | - throw new ApplicationLogicException( |
|
| 40 | - "You are not allowed to reserve a request that has been closed for over a week."); |
|
| 41 | - } |
|
| 42 | - } |
|
| 36 | + $currentUser = User::getCurrent($database); |
|
| 37 | + if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 38 | + if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 39 | + throw new ApplicationLogicException( |
|
| 40 | + "You are not allowed to reserve a request that has been closed for over a week."); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - if ($request->getReserved() !== null && $request->getReserved() != $currentUser->getId()) { |
|
| 45 | - throw new ApplicationLogicException("Request is already reserved!"); |
|
| 46 | - } |
|
| 44 | + if ($request->getReserved() !== null && $request->getReserved() != $currentUser->getId()) { |
|
| 45 | + throw new ApplicationLogicException("Request is already reserved!"); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - if ($request->getReserved() === null) { |
|
| 49 | - // Check the number of requests a user has reserved already |
|
| 50 | - $doubleReserveCountQuery = $database->prepare("SELECT COUNT(*) FROM request WHERE reserved = :userid;"); |
|
| 51 | - $doubleReserveCountQuery->bindValue(":userid", $currentUser->getId()); |
|
| 52 | - $doubleReserveCountQuery->execute(); |
|
| 53 | - $doubleReserveCount = $doubleReserveCountQuery->fetchColumn(); |
|
| 54 | - $doubleReserveCountQuery->closeCursor(); |
|
| 48 | + if ($request->getReserved() === null) { |
|
| 49 | + // Check the number of requests a user has reserved already |
|
| 50 | + $doubleReserveCountQuery = $database->prepare("SELECT COUNT(*) FROM request WHERE reserved = :userid;"); |
|
| 51 | + $doubleReserveCountQuery->bindValue(":userid", $currentUser->getId()); |
|
| 52 | + $doubleReserveCountQuery->execute(); |
|
| 53 | + $doubleReserveCount = $doubleReserveCountQuery->fetchColumn(); |
|
| 54 | + $doubleReserveCountQuery->closeCursor(); |
|
| 55 | 55 | |
| 56 | - // User already has at least one reserved. |
|
| 57 | - if ($doubleReserveCount != 0) { |
|
| 58 | - SessionAlert::warning("You have multiple requests reserved!"); |
|
| 59 | - } |
|
| 56 | + // User already has at least one reserved. |
|
| 57 | + if ($doubleReserveCount != 0) { |
|
| 58 | + SessionAlert::warning("You have multiple requests reserved!"); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $request->setReserved($currentUser->getId()); |
|
| 62 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 63 | - $request->save(); |
|
| 61 | + $request->setReserved($currentUser->getId()); |
|
| 62 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 63 | + $request->save(); |
|
| 64 | 64 | |
| 65 | - Logger::reserve($database, $request); |
|
| 65 | + Logger::reserve($database, $request); |
|
| 66 | 66 | |
| 67 | - $this->getNotificationHelper()->requestReserved($request); |
|
| 67 | + $this->getNotificationHelper()->requestReserved($request); |
|
| 68 | 68 | |
| 69 | - SessionAlert::success("Reserved request {$request->getId()}."); |
|
| 70 | - } |
|
| 69 | + SessionAlert::success("Reserved request {$request->getId()}."); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 73 | - } |
|
| 72 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -15,22 +15,22 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PageDropRequest extends PageCloseRequest |
| 17 | 17 | { |
| 18 | - protected function getTemplate(PdoDatabase $database) |
|
| 19 | - { |
|
| 20 | - return EmailTemplate::getDroppedTemplate(); |
|
| 21 | - } |
|
| 18 | + protected function getTemplate(PdoDatabase $database) |
|
| 19 | + { |
|
| 20 | + return EmailTemplate::getDroppedTemplate(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 24 | - { |
|
| 25 | - return false; |
|
| 26 | - } |
|
| 23 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 24 | + { |
|
| 25 | + return false; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 29 | - { |
|
| 30 | - return false; |
|
| 31 | - } |
|
| 28 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 29 | + { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - protected function sendMail(Request $request, EmailTemplate $template, User $currentUser, $ccMailingList) |
|
| 34 | - { |
|
| 35 | - } |
|
| 33 | + protected function sendMail(Request $request, EmailTemplate $template, User $currentUser, $ccMailingList) |
|
| 34 | + { |
|
| 35 | + } |
|
| 36 | 36 | } |
| 37 | 37 | \ No newline at end of file |
@@ -15,55 +15,55 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Offline |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Determines if the tool is offline |
|
| 20 | - * @return bool |
|
| 21 | - */ |
|
| 22 | - public static function isOffline() |
|
| 23 | - { |
|
| 24 | - global $dontUseDb; |
|
| 18 | + /** |
|
| 19 | + * Determines if the tool is offline |
|
| 20 | + * @return bool |
|
| 21 | + */ |
|
| 22 | + public static function isOffline() |
|
| 23 | + { |
|
| 24 | + global $dontUseDb; |
|
| 25 | 25 | |
| 26 | - return (bool)$dontUseDb; |
|
| 27 | - } |
|
| 26 | + return (bool)$dontUseDb; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Gets the offline message |
|
| 31 | - * |
|
| 32 | - * @param bool $external |
|
| 33 | - * @param null $message |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public static function getOfflineMessage($external, $message = null) |
|
| 38 | - { |
|
| 39 | - global $dontUseDbCulprit, $dontUseDbReason, $baseurl; |
|
| 29 | + /** |
|
| 30 | + * Gets the offline message |
|
| 31 | + * |
|
| 32 | + * @param bool $external |
|
| 33 | + * @param null $message |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public static function getOfflineMessage($external, $message = null) |
|
| 38 | + { |
|
| 39 | + global $dontUseDbCulprit, $dontUseDbReason, $baseurl; |
|
| 40 | 40 | |
| 41 | - $smarty = new Smarty(); |
|
| 42 | - $smarty->assign("baseurl", $baseurl); |
|
| 43 | - $smarty->assign("toolversion", Environment::getToolVersion()); |
|
| 41 | + $smarty = new Smarty(); |
|
| 42 | + $smarty->assign("baseurl", $baseurl); |
|
| 43 | + $smarty->assign("toolversion", Environment::getToolVersion()); |
|
| 44 | 44 | |
| 45 | - if (!headers_sent()) { |
|
| 46 | - header("HTTP/1.1 503 Service Unavailable"); |
|
| 47 | - } |
|
| 45 | + if (!headers_sent()) { |
|
| 46 | + header("HTTP/1.1 503 Service Unavailable"); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - if ($external) { |
|
| 50 | - return $smarty->fetch("offline/external.tpl"); |
|
| 51 | - } |
|
| 52 | - else { |
|
| 53 | - $hideCulprit = true; |
|
| 49 | + if ($external) { |
|
| 50 | + return $smarty->fetch("offline/external.tpl"); |
|
| 51 | + } |
|
| 52 | + else { |
|
| 53 | + $hideCulprit = true; |
|
| 54 | 54 | |
| 55 | - // Use the provided message if possible |
|
| 56 | - if ($message === null) { |
|
| 57 | - $hideCulprit = false; |
|
| 58 | - $message = $dontUseDbReason; |
|
| 59 | - } |
|
| 55 | + // Use the provided message if possible |
|
| 56 | + if ($message === null) { |
|
| 57 | + $hideCulprit = false; |
|
| 58 | + $message = $dontUseDbReason; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $smarty->assign("hideCulprit", $hideCulprit); |
|
| 62 | - $smarty->assign("dontUseDbCulprit", $dontUseDbCulprit); |
|
| 63 | - $smarty->assign("dontUseDbReason", $message); |
|
| 64 | - $smarty->assign("alerts", array()); |
|
| 61 | + $smarty->assign("hideCulprit", $hideCulprit); |
|
| 62 | + $smarty->assign("dontUseDbCulprit", $dontUseDbCulprit); |
|
| 63 | + $smarty->assign("dontUseDbReason", $message); |
|
| 64 | + $smarty->assign("alerts", array()); |
|
| 65 | 65 | |
| 66 | - return $smarty->fetch("offline/internal.tpl"); |
|
| 67 | - } |
|
| 68 | - } |
|
| 66 | + return $smarty->fetch("offline/internal.tpl"); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -48,8 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | if ($external) { |
| 50 | 50 | return $smarty->fetch("offline/external.tpl"); |
| 51 | - } |
|
| 52 | - else { |
|
| 51 | + } else { |
|
| 53 | 52 | $hideCulprit = true; |
| 54 | 53 | |
| 55 | 54 | // Use the provided message if possible |
@@ -55,395 +55,395 @@ |
||
| 55 | 55 | */ |
| 56 | 56 | class RequestRouter implements IRequestRouter |
| 57 | 57 | { |
| 58 | - /** |
|
| 59 | - * This is the core routing table for the application. The basic idea is: |
|
| 60 | - * |
|
| 61 | - * array( |
|
| 62 | - * "foo" => |
|
| 63 | - * array( |
|
| 64 | - * "class" => PageFoo::class, |
|
| 65 | - * "actions" => array("bar", "other") |
|
| 66 | - * ), |
|
| 67 | - * ); |
|
| 68 | - * |
|
| 69 | - * Things to note: |
|
| 70 | - * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
| 71 | - * |
|
| 72 | - * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
| 73 | - * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
| 74 | - * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
| 75 | - * method. |
|
| 76 | - * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
| 77 | - * |
|
| 78 | - * - Query parameters are ignored. |
|
| 79 | - * |
|
| 80 | - * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
| 81 | - * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
| 82 | - * before we start calling random methods through the web UI. |
|
| 83 | - * |
|
| 84 | - * Examples: |
|
| 85 | - * /internal.php => returns instance of PageMain, routed to main() |
|
| 86 | - * /internal.php?query => returns instance of PageMain, routed to main() |
|
| 87 | - * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
| 88 | - * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
| 89 | - * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
| 90 | - * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
| 91 | - * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
| 92 | - * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
| 93 | - * /internal.php/bar => returns instance of Page404, routed to main() |
|
| 94 | - * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
| 95 | - * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
| 96 | - * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
| 97 | - * |
|
| 98 | - * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
| 99 | - * to change the key, then you'll likely have to update a lot of files. |
|
| 100 | - * |
|
| 101 | - * @var array |
|
| 102 | - */ |
|
| 103 | - private $routeMap = array( |
|
| 104 | - |
|
| 105 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 106 | - // Login and registration |
|
| 107 | - 'logout' => |
|
| 108 | - array( |
|
| 109 | - 'class' => PageLogout::class, |
|
| 110 | - 'actions' => array(), |
|
| 111 | - ), |
|
| 112 | - 'login' => |
|
| 113 | - array( |
|
| 114 | - 'class' => PageLogin::class, |
|
| 115 | - 'actions' => array(), |
|
| 116 | - ), |
|
| 117 | - 'forgotPassword' => |
|
| 118 | - array( |
|
| 119 | - 'class' => PageForgotPassword::class, |
|
| 120 | - 'actions' => array('reset'), |
|
| 121 | - ), |
|
| 122 | - 'register' => |
|
| 123 | - array( |
|
| 124 | - 'class' => PageRegisterOption::class, |
|
| 125 | - 'actions' => array(), |
|
| 126 | - ), |
|
| 127 | - 'register/standard' => |
|
| 128 | - array( |
|
| 129 | - 'class' => PageRegisterStandard::class, |
|
| 130 | - 'actions' => array('done'), |
|
| 131 | - ), |
|
| 132 | - |
|
| 133 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 134 | - // Discovery |
|
| 135 | - 'search' => |
|
| 136 | - array( |
|
| 137 | - 'class' => PageSearch::class, |
|
| 138 | - 'actions' => array(), |
|
| 139 | - ), |
|
| 140 | - 'logs' => |
|
| 141 | - array( |
|
| 142 | - 'class' => PageLog::class, |
|
| 143 | - 'actions' => array(), |
|
| 144 | - ), |
|
| 145 | - |
|
| 146 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 147 | - // Administration |
|
| 148 | - 'bans' => |
|
| 149 | - array( |
|
| 150 | - 'class' => PageBan::class, |
|
| 151 | - 'actions' => array('set', 'remove'), |
|
| 152 | - ), |
|
| 153 | - 'userManagement' => |
|
| 154 | - array( |
|
| 155 | - 'class' => PageUserManagement::class, |
|
| 156 | - 'actions' => array( |
|
| 157 | - 'approve', |
|
| 158 | - 'decline', |
|
| 159 | - 'rename', |
|
| 160 | - 'editUser', |
|
| 161 | - 'suspend', |
|
| 162 | - 'editRoles', |
|
| 163 | - ), |
|
| 164 | - ), |
|
| 165 | - 'siteNotice' => |
|
| 166 | - array( |
|
| 167 | - 'class' => PageSiteNotice::class, |
|
| 168 | - 'actions' => array(), |
|
| 169 | - ), |
|
| 170 | - 'emailManagement' => |
|
| 171 | - array( |
|
| 172 | - 'class' => PageEmailManagement::class, |
|
| 173 | - 'actions' => array('create', 'edit', 'view'), |
|
| 174 | - ), |
|
| 175 | - |
|
| 176 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 177 | - // Personal preferences |
|
| 178 | - 'preferences' => |
|
| 179 | - array( |
|
| 180 | - 'class' => PagePreferences::class, |
|
| 181 | - 'actions' => array('changePassword'), |
|
| 182 | - ), |
|
| 183 | - 'oauth' => |
|
| 184 | - array( |
|
| 185 | - 'class' => PageOAuth::class, |
|
| 186 | - 'actions' => array('detach', 'attach'), |
|
| 187 | - ), |
|
| 188 | - |
|
| 189 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 190 | - // Welcomer configuration |
|
| 191 | - 'welcomeTemplates' => |
|
| 192 | - array( |
|
| 193 | - 'class' => PageWelcomeTemplateManagement::class, |
|
| 194 | - 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
| 195 | - ), |
|
| 196 | - |
|
| 197 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 198 | - // Statistics |
|
| 199 | - 'statistics' => |
|
| 200 | - array( |
|
| 201 | - 'class' => StatsMain::class, |
|
| 202 | - 'actions' => array(), |
|
| 203 | - ), |
|
| 204 | - 'statistics/fastCloses' => |
|
| 205 | - array( |
|
| 206 | - 'class' => StatsFastCloses::class, |
|
| 207 | - 'actions' => array(), |
|
| 208 | - ), |
|
| 209 | - 'statistics/inactiveUsers' => |
|
| 210 | - array( |
|
| 211 | - 'class' => StatsInactiveUsers::class, |
|
| 212 | - 'actions' => array(), |
|
| 213 | - ), |
|
| 214 | - 'statistics/monthlyStats' => |
|
| 215 | - array( |
|
| 216 | - 'class' => StatsMonthlyStats::class, |
|
| 217 | - 'actions' => array(), |
|
| 218 | - ), |
|
| 219 | - 'statistics/reservedRequests' => |
|
| 220 | - array( |
|
| 221 | - 'class' => StatsReservedRequests::class, |
|
| 222 | - 'actions' => array(), |
|
| 223 | - ), |
|
| 224 | - 'statistics/templateStats' => |
|
| 225 | - array( |
|
| 226 | - 'class' => StatsTemplateStats::class, |
|
| 227 | - 'actions' => array(), |
|
| 228 | - ), |
|
| 229 | - 'statistics/topCreators' => |
|
| 230 | - array( |
|
| 231 | - 'class' => StatsTopCreators::class, |
|
| 232 | - 'actions' => array(), |
|
| 233 | - ), |
|
| 234 | - 'statistics/users' => |
|
| 235 | - array( |
|
| 236 | - 'class' => StatsUsers::class, |
|
| 237 | - 'actions' => array('detail'), |
|
| 238 | - ), |
|
| 239 | - |
|
| 240 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 241 | - // Zoom page |
|
| 242 | - 'viewRequest' => |
|
| 243 | - array( |
|
| 244 | - 'class' => PageViewRequest::class, |
|
| 245 | - 'actions' => array(), |
|
| 246 | - ), |
|
| 247 | - 'viewRequest/reserve' => |
|
| 248 | - array( |
|
| 249 | - 'class' => PageReservation::class, |
|
| 250 | - 'actions' => array(), |
|
| 251 | - ), |
|
| 252 | - 'viewRequest/breakReserve' => |
|
| 253 | - array( |
|
| 254 | - 'class' => PageBreakReservation::class, |
|
| 255 | - 'actions' => array(), |
|
| 256 | - ), |
|
| 257 | - 'viewRequest/defer' => |
|
| 258 | - array( |
|
| 259 | - 'class' => PageDeferRequest::class, |
|
| 260 | - 'actions' => array(), |
|
| 261 | - ), |
|
| 262 | - 'viewRequest/comment' => |
|
| 263 | - array( |
|
| 264 | - 'class' => PageComment::class, |
|
| 265 | - 'actions' => array(), |
|
| 266 | - ), |
|
| 267 | - 'viewRequest/sendToUser' => |
|
| 268 | - array( |
|
| 269 | - 'class' => PageSendToUser::class, |
|
| 270 | - 'actions' => array(), |
|
| 271 | - ), |
|
| 272 | - 'viewRequest/close' => |
|
| 273 | - array( |
|
| 274 | - 'class' => PageCloseRequest::class, |
|
| 275 | - 'actions' => array(), |
|
| 276 | - ), |
|
| 277 | - 'viewRequest/drop' => |
|
| 278 | - array( |
|
| 279 | - 'class' => PageDropRequest::class, |
|
| 280 | - 'actions' => array(), |
|
| 281 | - ), |
|
| 282 | - 'viewRequest/custom' => |
|
| 283 | - array( |
|
| 284 | - 'class' => PageCustomClose::class, |
|
| 285 | - 'actions' => array(), |
|
| 286 | - ), |
|
| 287 | - 'editComment' => |
|
| 288 | - array( |
|
| 289 | - 'class' => PageEditComment::class, |
|
| 290 | - 'actions' => array(), |
|
| 291 | - ), |
|
| 292 | - |
|
| 293 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 294 | - // Misc stuff |
|
| 295 | - 'team' => |
|
| 296 | - array( |
|
| 297 | - 'class' => PageTeam::class, |
|
| 298 | - 'actions' => array(), |
|
| 299 | - ), |
|
| 300 | - 'requestList' => |
|
| 301 | - array( |
|
| 302 | - 'class' => PageExpandedRequestList::class, |
|
| 303 | - 'actions' => array(), |
|
| 304 | - ), |
|
| 305 | - ); |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @return IRoutedTask |
|
| 309 | - * @throws Exception |
|
| 310 | - */ |
|
| 311 | - final public function route() |
|
| 312 | - { |
|
| 313 | - $pathInfo = WebRequest::pathInfo(); |
|
| 314 | - |
|
| 315 | - list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
| 316 | - |
|
| 317 | - /** @var IRoutedTask $page */ |
|
| 318 | - $page = new $pageClass(); |
|
| 319 | - |
|
| 320 | - // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
| 321 | - // let's use our own. |
|
| 322 | - if (!($page instanceof IRoutedTask)) { |
|
| 323 | - throw new Exception('Expected a page, but this is not a page.'); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it |
|
| 327 | - // inherits PageBase and has been created from the routing map. |
|
| 328 | - $page->setRoute($action); |
|
| 329 | - |
|
| 330 | - return $page; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @param $pathInfo |
|
| 335 | - * |
|
| 336 | - * @return array |
|
| 337 | - */ |
|
| 338 | - protected function getRouteFromPath($pathInfo) |
|
| 339 | - { |
|
| 340 | - if (count($pathInfo) === 0) { |
|
| 341 | - // No pathInfo, so no page to load. Load the main page. |
|
| 342 | - return $this->getDefaultRoute(); |
|
| 343 | - } |
|
| 344 | - elseif (count($pathInfo) === 1) { |
|
| 345 | - // Exactly one path info segment, it's got to be a page. |
|
| 346 | - $classSegment = $pathInfo[0]; |
|
| 347 | - |
|
| 348 | - return $this->routeSinglePathSegment($classSegment); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // OK, we have two or more segments now. |
|
| 352 | - if (count($pathInfo) > 2) { |
|
| 353 | - // Let's handle more than two, and collapse it down into two. |
|
| 354 | - $requestedAction = array_pop($pathInfo); |
|
| 355 | - $classSegment = implode('/', $pathInfo); |
|
| 356 | - } |
|
| 357 | - else { |
|
| 358 | - // Two path info segments. |
|
| 359 | - $classSegment = $pathInfo[0]; |
|
| 360 | - $requestedAction = $pathInfo[1]; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
| 364 | - |
|
| 365 | - if ($routeMap[0] === Page404::class) { |
|
| 366 | - $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - return $routeMap; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @param $classSegment |
|
| 374 | - * |
|
| 375 | - * @return array |
|
| 376 | - */ |
|
| 377 | - final protected function routeSinglePathSegment($classSegment) |
|
| 378 | - { |
|
| 379 | - $routeMap = $this->getRouteMap(); |
|
| 380 | - if (array_key_exists($classSegment, $routeMap)) { |
|
| 381 | - // Route exists, but we don't have an action in path info, so default to main. |
|
| 382 | - $pageClass = $routeMap[$classSegment]['class']; |
|
| 383 | - $action = 'main'; |
|
| 384 | - |
|
| 385 | - return array($pageClass, $action); |
|
| 386 | - } |
|
| 387 | - else { |
|
| 388 | - // Doesn't exist in map. Fall back to 404 |
|
| 389 | - $pageClass = Page404::class; |
|
| 390 | - $action = "main"; |
|
| 391 | - |
|
| 392 | - return array($pageClass, $action); |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * @param $classSegment |
|
| 398 | - * @param $requestedAction |
|
| 399 | - * |
|
| 400 | - * @return array |
|
| 401 | - */ |
|
| 402 | - final protected function routePathSegments($classSegment, $requestedAction) |
|
| 403 | - { |
|
| 404 | - $routeMap = $this->getRouteMap(); |
|
| 405 | - if (array_key_exists($classSegment, $routeMap)) { |
|
| 406 | - // Route exists, but we don't have an action in path info, so default to main. |
|
| 407 | - |
|
| 408 | - if (isset($routeMap[$classSegment]['actions']) |
|
| 409 | - && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
| 410 | - ) { |
|
| 411 | - // Action exists in allowed action list. Allow both the page and the action |
|
| 412 | - $pageClass = $routeMap[$classSegment]['class']; |
|
| 413 | - $action = $requestedAction; |
|
| 414 | - |
|
| 415 | - return array($pageClass, $action); |
|
| 416 | - } |
|
| 417 | - else { |
|
| 418 | - // Valid page, invalid action. 404 our way out. |
|
| 419 | - $pageClass = Page404::class; |
|
| 420 | - $action = 'main'; |
|
| 421 | - |
|
| 422 | - return array($pageClass, $action); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - else { |
|
| 426 | - // Class doesn't exist in map. Fall back to 404 |
|
| 427 | - $pageClass = Page404::class; |
|
| 428 | - $action = 'main'; |
|
| 429 | - |
|
| 430 | - return array($pageClass, $action); |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * @return array |
|
| 436 | - */ |
|
| 437 | - protected function getRouteMap() |
|
| 438 | - { |
|
| 439 | - return $this->routeMap; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @return callable |
|
| 444 | - */ |
|
| 445 | - protected function getDefaultRoute() |
|
| 446 | - { |
|
| 447 | - return array(PageMain::class, "main"); |
|
| 448 | - } |
|
| 58 | + /** |
|
| 59 | + * This is the core routing table for the application. The basic idea is: |
|
| 60 | + * |
|
| 61 | + * array( |
|
| 62 | + * "foo" => |
|
| 63 | + * array( |
|
| 64 | + * "class" => PageFoo::class, |
|
| 65 | + * "actions" => array("bar", "other") |
|
| 66 | + * ), |
|
| 67 | + * ); |
|
| 68 | + * |
|
| 69 | + * Things to note: |
|
| 70 | + * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
| 71 | + * |
|
| 72 | + * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
| 73 | + * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
| 74 | + * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
| 75 | + * method. |
|
| 76 | + * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
| 77 | + * |
|
| 78 | + * - Query parameters are ignored. |
|
| 79 | + * |
|
| 80 | + * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
| 81 | + * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
| 82 | + * before we start calling random methods through the web UI. |
|
| 83 | + * |
|
| 84 | + * Examples: |
|
| 85 | + * /internal.php => returns instance of PageMain, routed to main() |
|
| 86 | + * /internal.php?query => returns instance of PageMain, routed to main() |
|
| 87 | + * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
| 88 | + * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
| 89 | + * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
| 90 | + * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
| 91 | + * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
| 92 | + * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
| 93 | + * /internal.php/bar => returns instance of Page404, routed to main() |
|
| 94 | + * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
| 95 | + * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
| 96 | + * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
| 97 | + * |
|
| 98 | + * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
| 99 | + * to change the key, then you'll likely have to update a lot of files. |
|
| 100 | + * |
|
| 101 | + * @var array |
|
| 102 | + */ |
|
| 103 | + private $routeMap = array( |
|
| 104 | + |
|
| 105 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 106 | + // Login and registration |
|
| 107 | + 'logout' => |
|
| 108 | + array( |
|
| 109 | + 'class' => PageLogout::class, |
|
| 110 | + 'actions' => array(), |
|
| 111 | + ), |
|
| 112 | + 'login' => |
|
| 113 | + array( |
|
| 114 | + 'class' => PageLogin::class, |
|
| 115 | + 'actions' => array(), |
|
| 116 | + ), |
|
| 117 | + 'forgotPassword' => |
|
| 118 | + array( |
|
| 119 | + 'class' => PageForgotPassword::class, |
|
| 120 | + 'actions' => array('reset'), |
|
| 121 | + ), |
|
| 122 | + 'register' => |
|
| 123 | + array( |
|
| 124 | + 'class' => PageRegisterOption::class, |
|
| 125 | + 'actions' => array(), |
|
| 126 | + ), |
|
| 127 | + 'register/standard' => |
|
| 128 | + array( |
|
| 129 | + 'class' => PageRegisterStandard::class, |
|
| 130 | + 'actions' => array('done'), |
|
| 131 | + ), |
|
| 132 | + |
|
| 133 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 134 | + // Discovery |
|
| 135 | + 'search' => |
|
| 136 | + array( |
|
| 137 | + 'class' => PageSearch::class, |
|
| 138 | + 'actions' => array(), |
|
| 139 | + ), |
|
| 140 | + 'logs' => |
|
| 141 | + array( |
|
| 142 | + 'class' => PageLog::class, |
|
| 143 | + 'actions' => array(), |
|
| 144 | + ), |
|
| 145 | + |
|
| 146 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 147 | + // Administration |
|
| 148 | + 'bans' => |
|
| 149 | + array( |
|
| 150 | + 'class' => PageBan::class, |
|
| 151 | + 'actions' => array('set', 'remove'), |
|
| 152 | + ), |
|
| 153 | + 'userManagement' => |
|
| 154 | + array( |
|
| 155 | + 'class' => PageUserManagement::class, |
|
| 156 | + 'actions' => array( |
|
| 157 | + 'approve', |
|
| 158 | + 'decline', |
|
| 159 | + 'rename', |
|
| 160 | + 'editUser', |
|
| 161 | + 'suspend', |
|
| 162 | + 'editRoles', |
|
| 163 | + ), |
|
| 164 | + ), |
|
| 165 | + 'siteNotice' => |
|
| 166 | + array( |
|
| 167 | + 'class' => PageSiteNotice::class, |
|
| 168 | + 'actions' => array(), |
|
| 169 | + ), |
|
| 170 | + 'emailManagement' => |
|
| 171 | + array( |
|
| 172 | + 'class' => PageEmailManagement::class, |
|
| 173 | + 'actions' => array('create', 'edit', 'view'), |
|
| 174 | + ), |
|
| 175 | + |
|
| 176 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 177 | + // Personal preferences |
|
| 178 | + 'preferences' => |
|
| 179 | + array( |
|
| 180 | + 'class' => PagePreferences::class, |
|
| 181 | + 'actions' => array('changePassword'), |
|
| 182 | + ), |
|
| 183 | + 'oauth' => |
|
| 184 | + array( |
|
| 185 | + 'class' => PageOAuth::class, |
|
| 186 | + 'actions' => array('detach', 'attach'), |
|
| 187 | + ), |
|
| 188 | + |
|
| 189 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 190 | + // Welcomer configuration |
|
| 191 | + 'welcomeTemplates' => |
|
| 192 | + array( |
|
| 193 | + 'class' => PageWelcomeTemplateManagement::class, |
|
| 194 | + 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
| 195 | + ), |
|
| 196 | + |
|
| 197 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 198 | + // Statistics |
|
| 199 | + 'statistics' => |
|
| 200 | + array( |
|
| 201 | + 'class' => StatsMain::class, |
|
| 202 | + 'actions' => array(), |
|
| 203 | + ), |
|
| 204 | + 'statistics/fastCloses' => |
|
| 205 | + array( |
|
| 206 | + 'class' => StatsFastCloses::class, |
|
| 207 | + 'actions' => array(), |
|
| 208 | + ), |
|
| 209 | + 'statistics/inactiveUsers' => |
|
| 210 | + array( |
|
| 211 | + 'class' => StatsInactiveUsers::class, |
|
| 212 | + 'actions' => array(), |
|
| 213 | + ), |
|
| 214 | + 'statistics/monthlyStats' => |
|
| 215 | + array( |
|
| 216 | + 'class' => StatsMonthlyStats::class, |
|
| 217 | + 'actions' => array(), |
|
| 218 | + ), |
|
| 219 | + 'statistics/reservedRequests' => |
|
| 220 | + array( |
|
| 221 | + 'class' => StatsReservedRequests::class, |
|
| 222 | + 'actions' => array(), |
|
| 223 | + ), |
|
| 224 | + 'statistics/templateStats' => |
|
| 225 | + array( |
|
| 226 | + 'class' => StatsTemplateStats::class, |
|
| 227 | + 'actions' => array(), |
|
| 228 | + ), |
|
| 229 | + 'statistics/topCreators' => |
|
| 230 | + array( |
|
| 231 | + 'class' => StatsTopCreators::class, |
|
| 232 | + 'actions' => array(), |
|
| 233 | + ), |
|
| 234 | + 'statistics/users' => |
|
| 235 | + array( |
|
| 236 | + 'class' => StatsUsers::class, |
|
| 237 | + 'actions' => array('detail'), |
|
| 238 | + ), |
|
| 239 | + |
|
| 240 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 241 | + // Zoom page |
|
| 242 | + 'viewRequest' => |
|
| 243 | + array( |
|
| 244 | + 'class' => PageViewRequest::class, |
|
| 245 | + 'actions' => array(), |
|
| 246 | + ), |
|
| 247 | + 'viewRequest/reserve' => |
|
| 248 | + array( |
|
| 249 | + 'class' => PageReservation::class, |
|
| 250 | + 'actions' => array(), |
|
| 251 | + ), |
|
| 252 | + 'viewRequest/breakReserve' => |
|
| 253 | + array( |
|
| 254 | + 'class' => PageBreakReservation::class, |
|
| 255 | + 'actions' => array(), |
|
| 256 | + ), |
|
| 257 | + 'viewRequest/defer' => |
|
| 258 | + array( |
|
| 259 | + 'class' => PageDeferRequest::class, |
|
| 260 | + 'actions' => array(), |
|
| 261 | + ), |
|
| 262 | + 'viewRequest/comment' => |
|
| 263 | + array( |
|
| 264 | + 'class' => PageComment::class, |
|
| 265 | + 'actions' => array(), |
|
| 266 | + ), |
|
| 267 | + 'viewRequest/sendToUser' => |
|
| 268 | + array( |
|
| 269 | + 'class' => PageSendToUser::class, |
|
| 270 | + 'actions' => array(), |
|
| 271 | + ), |
|
| 272 | + 'viewRequest/close' => |
|
| 273 | + array( |
|
| 274 | + 'class' => PageCloseRequest::class, |
|
| 275 | + 'actions' => array(), |
|
| 276 | + ), |
|
| 277 | + 'viewRequest/drop' => |
|
| 278 | + array( |
|
| 279 | + 'class' => PageDropRequest::class, |
|
| 280 | + 'actions' => array(), |
|
| 281 | + ), |
|
| 282 | + 'viewRequest/custom' => |
|
| 283 | + array( |
|
| 284 | + 'class' => PageCustomClose::class, |
|
| 285 | + 'actions' => array(), |
|
| 286 | + ), |
|
| 287 | + 'editComment' => |
|
| 288 | + array( |
|
| 289 | + 'class' => PageEditComment::class, |
|
| 290 | + 'actions' => array(), |
|
| 291 | + ), |
|
| 292 | + |
|
| 293 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 294 | + // Misc stuff |
|
| 295 | + 'team' => |
|
| 296 | + array( |
|
| 297 | + 'class' => PageTeam::class, |
|
| 298 | + 'actions' => array(), |
|
| 299 | + ), |
|
| 300 | + 'requestList' => |
|
| 301 | + array( |
|
| 302 | + 'class' => PageExpandedRequestList::class, |
|
| 303 | + 'actions' => array(), |
|
| 304 | + ), |
|
| 305 | + ); |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @return IRoutedTask |
|
| 309 | + * @throws Exception |
|
| 310 | + */ |
|
| 311 | + final public function route() |
|
| 312 | + { |
|
| 313 | + $pathInfo = WebRequest::pathInfo(); |
|
| 314 | + |
|
| 315 | + list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
| 316 | + |
|
| 317 | + /** @var IRoutedTask $page */ |
|
| 318 | + $page = new $pageClass(); |
|
| 319 | + |
|
| 320 | + // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
| 321 | + // let's use our own. |
|
| 322 | + if (!($page instanceof IRoutedTask)) { |
|
| 323 | + throw new Exception('Expected a page, but this is not a page.'); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // OK, I'm happy at this point that we know we're running a page, and we know it's probably what we want if it |
|
| 327 | + // inherits PageBase and has been created from the routing map. |
|
| 328 | + $page->setRoute($action); |
|
| 329 | + |
|
| 330 | + return $page; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @param $pathInfo |
|
| 335 | + * |
|
| 336 | + * @return array |
|
| 337 | + */ |
|
| 338 | + protected function getRouteFromPath($pathInfo) |
|
| 339 | + { |
|
| 340 | + if (count($pathInfo) === 0) { |
|
| 341 | + // No pathInfo, so no page to load. Load the main page. |
|
| 342 | + return $this->getDefaultRoute(); |
|
| 343 | + } |
|
| 344 | + elseif (count($pathInfo) === 1) { |
|
| 345 | + // Exactly one path info segment, it's got to be a page. |
|
| 346 | + $classSegment = $pathInfo[0]; |
|
| 347 | + |
|
| 348 | + return $this->routeSinglePathSegment($classSegment); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // OK, we have two or more segments now. |
|
| 352 | + if (count($pathInfo) > 2) { |
|
| 353 | + // Let's handle more than two, and collapse it down into two. |
|
| 354 | + $requestedAction = array_pop($pathInfo); |
|
| 355 | + $classSegment = implode('/', $pathInfo); |
|
| 356 | + } |
|
| 357 | + else { |
|
| 358 | + // Two path info segments. |
|
| 359 | + $classSegment = $pathInfo[0]; |
|
| 360 | + $requestedAction = $pathInfo[1]; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
| 364 | + |
|
| 365 | + if ($routeMap[0] === Page404::class) { |
|
| 366 | + $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + return $routeMap; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @param $classSegment |
|
| 374 | + * |
|
| 375 | + * @return array |
|
| 376 | + */ |
|
| 377 | + final protected function routeSinglePathSegment($classSegment) |
|
| 378 | + { |
|
| 379 | + $routeMap = $this->getRouteMap(); |
|
| 380 | + if (array_key_exists($classSegment, $routeMap)) { |
|
| 381 | + // Route exists, but we don't have an action in path info, so default to main. |
|
| 382 | + $pageClass = $routeMap[$classSegment]['class']; |
|
| 383 | + $action = 'main'; |
|
| 384 | + |
|
| 385 | + return array($pageClass, $action); |
|
| 386 | + } |
|
| 387 | + else { |
|
| 388 | + // Doesn't exist in map. Fall back to 404 |
|
| 389 | + $pageClass = Page404::class; |
|
| 390 | + $action = "main"; |
|
| 391 | + |
|
| 392 | + return array($pageClass, $action); |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * @param $classSegment |
|
| 398 | + * @param $requestedAction |
|
| 399 | + * |
|
| 400 | + * @return array |
|
| 401 | + */ |
|
| 402 | + final protected function routePathSegments($classSegment, $requestedAction) |
|
| 403 | + { |
|
| 404 | + $routeMap = $this->getRouteMap(); |
|
| 405 | + if (array_key_exists($classSegment, $routeMap)) { |
|
| 406 | + // Route exists, but we don't have an action in path info, so default to main. |
|
| 407 | + |
|
| 408 | + if (isset($routeMap[$classSegment]['actions']) |
|
| 409 | + && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
| 410 | + ) { |
|
| 411 | + // Action exists in allowed action list. Allow both the page and the action |
|
| 412 | + $pageClass = $routeMap[$classSegment]['class']; |
|
| 413 | + $action = $requestedAction; |
|
| 414 | + |
|
| 415 | + return array($pageClass, $action); |
|
| 416 | + } |
|
| 417 | + else { |
|
| 418 | + // Valid page, invalid action. 404 our way out. |
|
| 419 | + $pageClass = Page404::class; |
|
| 420 | + $action = 'main'; |
|
| 421 | + |
|
| 422 | + return array($pageClass, $action); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + else { |
|
| 426 | + // Class doesn't exist in map. Fall back to 404 |
|
| 427 | + $pageClass = Page404::class; |
|
| 428 | + $action = 'main'; |
|
| 429 | + |
|
| 430 | + return array($pageClass, $action); |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * @return array |
|
| 436 | + */ |
|
| 437 | + protected function getRouteMap() |
|
| 438 | + { |
|
| 439 | + return $this->routeMap; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @return callable |
|
| 444 | + */ |
|
| 445 | + protected function getDefaultRoute() |
|
| 446 | + { |
|
| 447 | + return array(PageMain::class, "main"); |
|
| 448 | + } |
|
| 449 | 449 | } |
@@ -340,8 +340,7 @@ discard block |
||
| 340 | 340 | if (count($pathInfo) === 0) { |
| 341 | 341 | // No pathInfo, so no page to load. Load the main page. |
| 342 | 342 | return $this->getDefaultRoute(); |
| 343 | - } |
|
| 344 | - elseif (count($pathInfo) === 1) { |
|
| 343 | + } elseif (count($pathInfo) === 1) { |
|
| 345 | 344 | // Exactly one path info segment, it's got to be a page. |
| 346 | 345 | $classSegment = $pathInfo[0]; |
| 347 | 346 | |
@@ -353,8 +352,7 @@ discard block |
||
| 353 | 352 | // Let's handle more than two, and collapse it down into two. |
| 354 | 353 | $requestedAction = array_pop($pathInfo); |
| 355 | 354 | $classSegment = implode('/', $pathInfo); |
| 356 | - } |
|
| 357 | - else { |
|
| 355 | + } else { |
|
| 358 | 356 | // Two path info segments. |
| 359 | 357 | $classSegment = $pathInfo[0]; |
| 360 | 358 | $requestedAction = $pathInfo[1]; |
@@ -383,8 +381,7 @@ discard block |
||
| 383 | 381 | $action = 'main'; |
| 384 | 382 | |
| 385 | 383 | return array($pageClass, $action); |
| 386 | - } |
|
| 387 | - else { |
|
| 384 | + } else { |
|
| 388 | 385 | // Doesn't exist in map. Fall back to 404 |
| 389 | 386 | $pageClass = Page404::class; |
| 390 | 387 | $action = "main"; |
@@ -413,16 +410,14 @@ discard block |
||
| 413 | 410 | $action = $requestedAction; |
| 414 | 411 | |
| 415 | 412 | return array($pageClass, $action); |
| 416 | - } |
|
| 417 | - else { |
|
| 413 | + } else { |
|
| 418 | 414 | // Valid page, invalid action. 404 our way out. |
| 419 | 415 | $pageClass = Page404::class; |
| 420 | 416 | $action = 'main'; |
| 421 | 417 | |
| 422 | 418 | return array($pageClass, $action); |
| 423 | 419 | } |
| 424 | - } |
|
| 425 | - else { |
|
| 420 | + } else { |
|
| 426 | 421 | // Class doesn't exist in map. Fall back to 404 |
| 427 | 422 | $pageClass = Page404::class; |
| 428 | 423 | $action = 'main'; |
@@ -17,9 +17,9 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class OAuthRequestRouter extends RequestRouter |
| 19 | 19 | { |
| 20 | - protected function getRouteFromPath($pathInfo) |
|
| 21 | - { |
|
| 22 | - // Hardcode the route for this entry point |
|
| 23 | - return array(PageOAuth::class, 'callback'); |
|
| 24 | - } |
|
| 20 | + protected function getRouteFromPath($pathInfo) |
|
| 21 | + { |
|
| 22 | + // Hardcode the route for this entry point |
|
| 23 | + return array(PageOAuth::class, 'callback'); |
|
| 24 | + } |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -18,9 +18,9 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | interface IRequestRouter |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @return IRoutedTask |
|
| 23 | - * @throws Exception |
|
| 24 | - */ |
|
| 25 | - public function route(); |
|
| 21 | + /** |
|
| 22 | + * @return IRoutedTask |
|
| 23 | + * @throws Exception |
|
| 24 | + */ |
|
| 25 | + public function route(); |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -15,42 +15,42 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PublicRequestRouter extends RequestRouter |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Gets the route map to be used by this request router. |
|
| 20 | - * |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - protected function getRouteMap() |
|
| 24 | - { |
|
| 25 | - return array( |
|
| 26 | - // Page showing a message stating the request has been submitted to our internal queues |
|
| 27 | - 'requestSubmitted' => |
|
| 28 | - array( |
|
| 29 | - 'class' => PageRequestSubmitted::class, |
|
| 30 | - 'actions' => array(), |
|
| 31 | - ), |
|
| 32 | - // Page showing a message stating that email confirmation is required to continue |
|
| 33 | - 'emailConfirmationRequired' => |
|
| 34 | - array( |
|
| 35 | - 'class' => PageEmailConfirmationRequired::class, |
|
| 36 | - 'actions' => array(), |
|
| 37 | - ), |
|
| 38 | - // Action page which handles email confirmation |
|
| 39 | - 'confirmEmail' => |
|
| 40 | - array( |
|
| 41 | - 'class' => PageConfirmEmail::class, |
|
| 42 | - 'actions' => array(), |
|
| 43 | - ), |
|
| 44 | - ); |
|
| 45 | - } |
|
| 18 | + /** |
|
| 19 | + * Gets the route map to be used by this request router. |
|
| 20 | + * |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + protected function getRouteMap() |
|
| 24 | + { |
|
| 25 | + return array( |
|
| 26 | + // Page showing a message stating the request has been submitted to our internal queues |
|
| 27 | + 'requestSubmitted' => |
|
| 28 | + array( |
|
| 29 | + 'class' => PageRequestSubmitted::class, |
|
| 30 | + 'actions' => array(), |
|
| 31 | + ), |
|
| 32 | + // Page showing a message stating that email confirmation is required to continue |
|
| 33 | + 'emailConfirmationRequired' => |
|
| 34 | + array( |
|
| 35 | + 'class' => PageEmailConfirmationRequired::class, |
|
| 36 | + 'actions' => array(), |
|
| 37 | + ), |
|
| 38 | + // Action page which handles email confirmation |
|
| 39 | + 'confirmEmail' => |
|
| 40 | + array( |
|
| 41 | + 'class' => PageConfirmEmail::class, |
|
| 42 | + 'actions' => array(), |
|
| 43 | + ), |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Gets the default route if no explicit route is requested. |
|
| 49 | - * |
|
| 50 | - * @return callable |
|
| 51 | - */ |
|
| 52 | - protected function getDefaultRoute() |
|
| 53 | - { |
|
| 54 | - return array(PageRequestAccount::class, 'main'); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Gets the default route if no explicit route is requested. |
|
| 49 | + * |
|
| 50 | + * @return callable |
|
| 51 | + */ |
|
| 52 | + protected function getDefaultRoute() |
|
| 53 | + { |
|
| 54 | + return array(PageRequestAccount::class, 'main'); |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | \ No newline at end of file |