Passed
Push — dependabot/npm_and_yarn/sass-1... ( dd05dd )
by
unknown
05:21
created
includes/Pages/Registration/PageRegisterStandard.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -10,19 +10,19 @@
 block discarded – undo
10 10
 
11 11
 class PageRegisterStandard extends PageRegisterBase
12 12
 {
13
-    /**
14
-     * @return string
15
-     */
16
-    protected function getRegistrationTemplate()
17
-    {
18
-        return "registration/register.tpl";
19
-    }
13
+	/**
14
+	 * @return string
15
+	 */
16
+	protected function getRegistrationTemplate()
17
+	{
18
+		return "registration/register.tpl";
19
+	}
20 20
 
21
-    /**
22
-     * @return string
23
-     */
24
-    protected function getDefaultRole()
25
-    {
26
-        return 'user';
27
-    }
21
+	/**
22
+	 * @return string
23
+	 */
24
+	protected function getDefaultRole()
25
+	{
26
+		return 'user';
27
+	}
28 28
 }
Please login to merge, or discard this patch.
includes/Pages/PageSiteNotice.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -15,37 +15,37 @@
 block discarded – undo
15 15
 
16 16
 class PageSiteNotice extends InternalPageBase
17 17
 {
18
-    /**
19
-     * Main function for this page, when no specific actions are called.
20
-     * @return void
21
-     */
22
-    protected function main()
23
-    {
24
-        $this->setHtmlTitle('Site Notice');
25
-
26
-        $database = $this->getDatabase();
27
-
28
-        /** @var SiteNotice $siteNoticeMessage */
29
-        $siteNoticeMessage = SiteNotice::getById(1, $database);
30
-
31
-        // Dual-mode
32
-        if (WebRequest::wasPosted()) {
33
-            $this->validateCSRFToken();
34
-
35
-            $siteNoticeMessage->setContent(WebRequest::postString('mailtext'));
36
-            $siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion'));
37
-            $siteNoticeMessage->save();
38
-
39
-            Logger::siteNoticeEdited($database, $siteNoticeMessage);
40
-            $this->getNotificationHelper()->siteNoticeEdited();
41
-
42
-            $this->redirect();
43
-        }
44
-        else {
45
-            $this->assignCSRFToken();
46
-
47
-            $this->setTemplate('site-notice/edit-form.tpl');
48
-            $this->assign('message', $siteNoticeMessage);
49
-        }
50
-    }
18
+	/**
19
+	 * Main function for this page, when no specific actions are called.
20
+	 * @return void
21
+	 */
22
+	protected function main()
23
+	{
24
+		$this->setHtmlTitle('Site Notice');
25
+
26
+		$database = $this->getDatabase();
27
+
28
+		/** @var SiteNotice $siteNoticeMessage */
29
+		$siteNoticeMessage = SiteNotice::getById(1, $database);
30
+
31
+		// Dual-mode
32
+		if (WebRequest::wasPosted()) {
33
+			$this->validateCSRFToken();
34
+
35
+			$siteNoticeMessage->setContent(WebRequest::postString('mailtext'));
36
+			$siteNoticeMessage->setUpdateVersion(WebRequest::postInt('updateversion'));
37
+			$siteNoticeMessage->save();
38
+
39
+			Logger::siteNoticeEdited($database, $siteNoticeMessage);
40
+			$this->getNotificationHelper()->siteNoticeEdited();
41
+
42
+			$this->redirect();
43
+		}
44
+		else {
45
+			$this->assignCSRFToken();
46
+
47
+			$this->setTemplate('site-notice/edit-form.tpl');
48
+			$this->assign('message', $siteNoticeMessage);
49
+		}
50
+	}
51 51
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,7 @@
 block discarded – undo
40 40
             $this->getNotificationHelper()->siteNoticeEdited();
41 41
 
42 42
             $this->redirect();
43
-        }
44
-        else {
43
+        } else {
45 44
             $this->assignCSRFToken();
46 45
 
47 46
             $this->setTemplate('site-notice/edit-form.tpl');
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsReservedRequests.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
 
14 14
 class StatsReservedRequests extends InternalPageBase
15 15
 {
16
-    public function main()
17
-    {
18
-        $this->setHtmlTitle('Reserved Requests :: Statistics');
16
+	public function main()
17
+	{
18
+		$this->setHtmlTitle('Reserved Requests :: Statistics');
19 19
 
20
-        $query = <<<sql
20
+		$query = <<<sql
21 21
 SELECT
22 22
     p.id AS requestid,
23 23
     p.name AS name,
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
 WHERE reserved != 0;
30 30
 sql;
31 31
 
32
-        $database = $this->getDatabase();
33
-        $statement = $database->query($query);
34
-        $data = $statement->fetchAll(PDO::FETCH_ASSOC);
35
-        $this->assign('dataTable', $data);
36
-        $this->assign('statsPageTitle', 'All currently reserved requests');
37
-        $this->setTemplate('statistics/reserved-requests.tpl');
38
-    }
32
+		$database = $this->getDatabase();
33
+		$statement = $database->query($query);
34
+		$data = $statement->fetchAll(PDO::FETCH_ASSOC);
35
+		$this->assign('dataTable', $data);
36
+		$this->assign('statsPageTitle', 'All currently reserved requests');
37
+		$this->setTemplate('statistics/reserved-requests.tpl');
38
+	}
39 39
 }
Please login to merge, or discard this patch.
includes/Pages/Request/PageConfirmEmail.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,8 +48,7 @@
 block discarded – undo
48 48
 
49 49
         if ($request->getEmailConfirm() === $si) {
50 50
             $request->setEmailConfirm('Confirmed');
51
-        }
52
-        else {
51
+        } else {
53 52
             throw new ApplicationLogicException('The confirmation value does not appear to match the expected value');
54 53
         }
55 54
 
Please login to merge, or discard this patch.
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -19,70 +19,70 @@
 block discarded – undo
19 19
 
20 20
 class PageConfirmEmail extends PublicInterfacePageBase
21 21
 {
22
-    /**
23
-     * Main function for this page, when no specific actions are called.
24
-     * @throws ApplicationLogicException
25
-     * @throws Exception
26
-     */
27
-    protected function main()
28
-    {
29
-        $id = WebRequest::getInt('id');
30
-        $si = WebRequest::getString('si');
31
-
32
-        if ($id === null || $si === null) {
33
-            throw new ApplicationLogicException('Link incomplete - please double check the link you received.');
34
-        }
35
-
36
-        /** @var Request|false $request */
37
-        $request = Request::getById($id, $this->getDatabase());
38
-
39
-        if ($request === false) {
40
-            throw new ApplicationLogicException('Request not found');
41
-        }
42
-
43
-        if ($request->getEmailConfirm() === 'Confirmed') {
44
-            // request has already been confirmed. Bomb out silently.
45
-            $this->redirect('requestSubmitted');
46
-
47
-            return;
48
-        }
49
-
50
-        if ($request->getEmailConfirm() === $si) {
51
-            $request->setEmailConfirm('Confirmed');
52
-        }
53
-        else {
54
-            throw new ApplicationLogicException('The confirmation value does not appear to match the expected value');
55
-        }
56
-
57
-        try {
58
-            $request->save();
59
-        }
60
-        catch (OptimisticLockFailedException $ex) {
61
-            // Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting
62
-            // to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they
63
-            // double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the
64
-            // case.
65
-
66
-            $request = Request::getById($id, $this->getDatabase());
67
-            if ($request->getEmailConfirm() === 'Confirmed') {
68
-                // we've already done the sanity checks above
69
-
70
-                $this->redirect('requestSubmitted');
71
-
72
-                // skip the log and notification
73
-                return;
74
-            }
75
-
76
-            // something really weird happened. Another race condition?
77
-            throw $ex;
78
-        }
79
-
80
-        Logger::emailConfirmed($this->getDatabase(), $request);
81
-
82
-        if ($request->getStatus() != RequestStatus::CLOSED) {
83
-            $this->getNotificationHelper()->requestReceived($request);
84
-        }
85
-
86
-        $this->redirect('requestSubmitted');
87
-    }
22
+	/**
23
+	 * Main function for this page, when no specific actions are called.
24
+	 * @throws ApplicationLogicException
25
+	 * @throws Exception
26
+	 */
27
+	protected function main()
28
+	{
29
+		$id = WebRequest::getInt('id');
30
+		$si = WebRequest::getString('si');
31
+
32
+		if ($id === null || $si === null) {
33
+			throw new ApplicationLogicException('Link incomplete - please double check the link you received.');
34
+		}
35
+
36
+		/** @var Request|false $request */
37
+		$request = Request::getById($id, $this->getDatabase());
38
+
39
+		if ($request === false) {
40
+			throw new ApplicationLogicException('Request not found');
41
+		}
42
+
43
+		if ($request->getEmailConfirm() === 'Confirmed') {
44
+			// request has already been confirmed. Bomb out silently.
45
+			$this->redirect('requestSubmitted');
46
+
47
+			return;
48
+		}
49
+
50
+		if ($request->getEmailConfirm() === $si) {
51
+			$request->setEmailConfirm('Confirmed');
52
+		}
53
+		else {
54
+			throw new ApplicationLogicException('The confirmation value does not appear to match the expected value');
55
+		}
56
+
57
+		try {
58
+			$request->save();
59
+		}
60
+		catch (OptimisticLockFailedException $ex) {
61
+			// Okay. Someone's edited this in the time between us loading this page and doing the checks, and us getting
62
+			// to saving the page. We *do not* want to show an optimistic lock failure, the most likely problem is they
63
+			// double-loaded this page (see #255). Let's confirm this, and bomb out with a success message if it's the
64
+			// case.
65
+
66
+			$request = Request::getById($id, $this->getDatabase());
67
+			if ($request->getEmailConfirm() === 'Confirmed') {
68
+				// we've already done the sanity checks above
69
+
70
+				$this->redirect('requestSubmitted');
71
+
72
+				// skip the log and notification
73
+				return;
74
+			}
75
+
76
+			// something really weird happened. Another race condition?
77
+			throw $ex;
78
+		}
79
+
80
+		Logger::emailConfirmed($this->getDatabase(), $request);
81
+
82
+		if ($request->getStatus() != RequestStatus::CLOSED) {
83
+			$this->getNotificationHelper()->requestReceived($request);
84
+		}
85
+
86
+		$this->redirect('requestSubmitted');
87
+	}
88 88
 }
89 89
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/PageTeam.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,8 +29,7 @@
 block discarded – undo
29 29
         foreach ($teamData as $name => $item) {
30 30
             if (count($item['Role']) == 0) {
31 31
                 $inactive[$name] = $item;
32
-            }
33
-            else {
32
+            } else {
34 33
                 $active[$name] = $item;
35 34
             }
36 35
         }
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -12,44 +12,44 @@
 block discarded – undo
12 12
 
13 13
 class PageTeam extends InternalPageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no specific actions are called.
17
-     * @return void
18
-     */
19
-    protected function main()
20
-    {
21
-        $path = $this->getSiteConfiguration()->getFilePath() . '/team.json';
22
-        $json = file_get_contents($path);
23
-
24
-        $teamData = json_decode($json, true);
25
-
26
-        $active = array();
27
-        $inactive = array();
28
-
29
-        foreach ($teamData as $name => $item) {
30
-            if (count($item['Role']) == 0) {
31
-                $inactive[$name] = $item;
32
-            }
33
-            else {
34
-                $active[$name] = $item;
35
-            }
36
-        }
37
-
38
-        $this->assign('developer', $this->assocArrayShuffle($active));
39
-        $this->assign('inactiveDeveloper', $this->assocArrayShuffle($inactive));
40
-        $this->setTemplate('team/team.tpl');
41
-    }
42
-
43
-    private function assocArrayShuffle($array)
44
-    {
45
-        $arrayKeys = array_keys($array);
46
-        shuffle($arrayKeys);
47
-
48
-        $sorted = [];
49
-        foreach ($arrayKeys as $k) {
50
-            $sorted[$k] = $array[$k];
51
-        }
52
-
53
-        return $sorted;
54
-    }
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$path = $this->getSiteConfiguration()->getFilePath() . '/team.json';
22
+		$json = file_get_contents($path);
23
+
24
+		$teamData = json_decode($json, true);
25
+
26
+		$active = array();
27
+		$inactive = array();
28
+
29
+		foreach ($teamData as $name => $item) {
30
+			if (count($item['Role']) == 0) {
31
+				$inactive[$name] = $item;
32
+			}
33
+			else {
34
+				$active[$name] = $item;
35
+			}
36
+		}
37
+
38
+		$this->assign('developer', $this->assocArrayShuffle($active));
39
+		$this->assign('inactiveDeveloper', $this->assocArrayShuffle($inactive));
40
+		$this->setTemplate('team/team.tpl');
41
+	}
42
+
43
+	private function assocArrayShuffle($array)
44
+	{
45
+		$arrayKeys = array_keys($array);
46
+		shuffle($arrayKeys);
47
+
48
+		$sorted = [];
49
+		foreach ($arrayKeys as $k) {
50
+			$sorted[$k] = $array[$k];
51
+		}
52
+
53
+		return $sorted;
54
+	}
55 55
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageSendToUser.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -17,43 +17,43 @@
 block discarded – undo
17 17
 
18 18
 class PageSendToUser extends RequestActionBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     * @throws ApplicationLogicException
23
-     * @throws Exception
24
-     */
25
-    protected function main()
26
-    {
27
-        $this->checkPosted();
28
-        $database = $this->getDatabase();
29
-        $request = $this->getRequest($database);
30
-
31
-        if ($request->getReserved() !== User::getCurrent($database)->getId()) {
32
-            throw new ApplicationLogicException('You don\'t have this request reserved!');
33
-        }
34
-
35
-        $username = WebRequest::postString('user');
36
-        if ($username === null) {
37
-            throw new ApplicationLogicException('User must be specified');
38
-        }
39
-
40
-        $user = User::getByUsername($username, $database);
41
-        if ($user === false) {
42
-            throw new ApplicationLogicException('User not found');
43
-        }
44
-
45
-        if (!$user->isActive()) {
46
-            throw new ApplicationLogicException('User is currently not active on the tool');
47
-        }
48
-
49
-        $request->setReserved($user->getId());
50
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
51
-        $request->save();
52
-
53
-        Logger::sendReservation($database, $request, $user);
54
-        $this->getNotificationHelper()->requestReservationSent($request, $user);
55
-        SessionAlert::success("Reservation sent successfully");
56
-
57
-        $this->redirect('viewRequest', null, array('id' => $request->getId()));
58
-    }
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 * @throws ApplicationLogicException
23
+	 * @throws Exception
24
+	 */
25
+	protected function main()
26
+	{
27
+		$this->checkPosted();
28
+		$database = $this->getDatabase();
29
+		$request = $this->getRequest($database);
30
+
31
+		if ($request->getReserved() !== User::getCurrent($database)->getId()) {
32
+			throw new ApplicationLogicException('You don\'t have this request reserved!');
33
+		}
34
+
35
+		$username = WebRequest::postString('user');
36
+		if ($username === null) {
37
+			throw new ApplicationLogicException('User must be specified');
38
+		}
39
+
40
+		$user = User::getByUsername($username, $database);
41
+		if ($user === false) {
42
+			throw new ApplicationLogicException('User not found');
43
+		}
44
+
45
+		if (!$user->isActive()) {
46
+			throw new ApplicationLogicException('User is currently not active on the tool');
47
+		}
48
+
49
+		$request->setReserved($user->getId());
50
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
51
+		$request->save();
52
+
53
+		Logger::sendReservation($database, $request, $user);
54
+		$this->getNotificationHelper()->requestReservationSent($request, $user);
55
+		SessionAlert::success("Reservation sent successfully");
56
+
57
+		$this->redirect('viewRequest', null, array('id' => $request->getId()));
58
+	}
59 59
 }
Please login to merge, or discard this patch.
includes/Offline.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,8 +48,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -17,57 +17,57 @@
 block discarded – undo
17 17
  */
18 18
 class Offline
19 19
 {
20
-    /**
21
-     * Determines if the tool is offline
22
-     * @return bool
23
-     */
24
-    public static function isOffline(SiteConfiguration $configuration): bool
25
-    {
26
-        return (bool)$configuration->getOffline()['offline'];
27
-    }
20
+	/**
21
+	 * Determines if the tool is offline
22
+	 * @return bool
23
+	 */
24
+	public static function isOffline(SiteConfiguration $configuration): bool
25
+	{
26
+		return (bool)$configuration->getOffline()['offline'];
27
+	}
28 28
 
29
-    /**
30
-     * Gets the offline message
31
-     *
32
-     * @throws SmartyException
33
-     */
34
-    public static function getOfflineMessage(bool $external, SiteConfiguration $configuration, ?string $message = null): string
35
-    {
36
-        $baseurl = $configuration->getBaseUrl();
37
-        $culprit = $configuration->getOffline()['culprit'];
38
-        $reason = $configuration->getOffline()['reason'];
29
+	/**
30
+	 * Gets the offline message
31
+	 *
32
+	 * @throws SmartyException
33
+	 */
34
+	public static function getOfflineMessage(bool $external, SiteConfiguration $configuration, ?string $message = null): string
35
+	{
36
+		$baseurl = $configuration->getBaseUrl();
37
+		$culprit = $configuration->getOffline()['culprit'];
38
+		$reason = $configuration->getOffline()['reason'];
39 39
 
40
-        $smarty = new Smarty();
41
-        $smarty->assign("baseurl", $baseurl);
42
-        $smarty->assign("resourceCacheEpoch", 0);
43
-        $smarty->assign("alerts", []);
44
-        $smarty->assign("toolversion", Environment::getToolVersion());
40
+		$smarty = new Smarty();
41
+		$smarty->assign("baseurl", $baseurl);
42
+		$smarty->assign("resourceCacheEpoch", 0);
43
+		$smarty->assign("alerts", []);
44
+		$smarty->assign("toolversion", Environment::getToolVersion());
45 45
 
46
-        if (!headers_sent()) {
47
-            header("HTTP/1.1 503 Service Unavailable");
48
-        }
46
+		if (!headers_sent()) {
47
+			header("HTTP/1.1 503 Service Unavailable");
48
+		}
49 49
 
50
-        if ($external) {
51
-            return $smarty->fetch("offline/external.tpl");
52
-        }
53
-        else {
54
-            $hideCulprit = true;
50
+		if ($external) {
51
+			return $smarty->fetch("offline/external.tpl");
52
+		}
53
+		else {
54
+			$hideCulprit = true;
55 55
 
56
-            // Use the provided message if possible
57
-            if ($message === null) {
58
-                $hideCulprit = false;
59
-                $message = $reason;
60
-            }
56
+			// Use the provided message if possible
57
+			if ($message === null) {
58
+				$hideCulprit = false;
59
+				$message = $reason;
60
+			}
61 61
 
62
-            $smarty->assign("hideCulprit", $hideCulprit);
63
-            $smarty->assign("dontUseDbCulprit", $culprit);
64
-            $smarty->assign("dontUseDbReason", $message);
65
-            $smarty->assign("alerts", []);
66
-            $smarty->assign('currentUser', User::getCommunity());
67
-            $smarty->assign('skin', 'main');
68
-            $smarty->assign('currentDomain', null);
62
+			$smarty->assign("hideCulprit", $hideCulprit);
63
+			$smarty->assign("dontUseDbCulprit", $culprit);
64
+			$smarty->assign("dontUseDbReason", $message);
65
+			$smarty->assign("alerts", []);
66
+			$smarty->assign('currentUser', User::getCommunity());
67
+			$smarty->assign('skin', 'main');
68
+			$smarty->assign('currentDomain', null);
69 69
 
70
-            return $smarty->fetch("offline/internal.tpl");
71
-        }
72
-    }
70
+			return $smarty->fetch("offline/internal.tpl");
71
+		}
72
+	}
73 73
 }
Please login to merge, or discard this patch.
includes/Router/RequestRouter.php 2 patches
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -340,8 +340,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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';
Please login to merge, or discard this patch.
Indentation   +483 added lines, -483 removed lines patch added patch discarded remove patch
@@ -73,487 +73,487 @@
 block discarded – undo
73 73
  */
74 74
 class RequestRouter implements IRequestRouter
75 75
 {
76
-    /**
77
-     * This is the core routing table for the application. The basic idea is:
78
-     *
79
-     *      array(
80
-     *          "foo" =>
81
-     *              array(
82
-     *                  "class"   => PageFoo::class,
83
-     *                  "actions" => array("bar", "other")
84
-     *              ),
85
-     * );
86
-     *
87
-     * Things to note:
88
-     *     - If no page is requested, we go to PageMain. PageMain can't have actions defined.
89
-     *
90
-     *     - If a page is defined and requested, but no action is requested, go to that page's main() method
91
-     *     - If a page is defined and requested, and an action is defined and requested, go to that action's method.
92
-     *     - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main()
93
-     *       method.
94
-     *     - If a page is NOT defined and requested, go to Page404 and it's main() method.
95
-     *
96
-     *     - Query parameters are ignored.
97
-     *
98
-     * The key point here is request routing with validation that this is allowed, before we start hitting the
99
-     * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested
100
-     * before we start calling random methods through the web UI.
101
-     *
102
-     * Examples:
103
-     * /internal.php                => returns instance of PageMain, routed to main()
104
-     * /internal.php?query          => returns instance of PageMain, routed to main()
105
-     * /internal.php/foo            => returns instance of PageFoo, routed to main()
106
-     * /internal.php/foo?query      => returns instance of PageFoo, routed to main()
107
-     * /internal.php/foo/bar        => returns instance of PageFoo, routed to bar()
108
-     * /internal.php/foo/bar?query  => returns instance of PageFoo, routed to bar()
109
-     * /internal.php/foo/baz        => returns instance of Page404, routed to main()
110
-     * /internal.php/foo/baz?query  => returns instance of Page404, routed to main()
111
-     * /internal.php/bar            => returns instance of Page404, routed to main()
112
-     * /internal.php/bar?query      => returns instance of Page404, routed to main()
113
-     * /internal.php/bar/baz        => returns instance of Page404, routed to main()
114
-     * /internal.php/bar/baz?query  => returns instance of Page404, routed to main()
115
-     *
116
-     * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need
117
-     * to change the key, then you'll likely have to update a lot of files.
118
-     *
119
-     * @var array
120
-     */
121
-    private $routeMap = array(
122
-
123
-        //////////////////////////////////////////////////////////////////////////////////////////////////
124
-        // Login and registration
125
-        'logout'                      =>
126
-            array(
127
-                'class'   => PageLogout::class,
128
-                'actions' => array(),
129
-            ),
130
-        'login'                       =>
131
-            array(
132
-                'class'   => PagePasswordLogin::class,
133
-                'actions' => array(),
134
-            ),
135
-        'login/otp'                   =>
136
-            array(
137
-                'class'   => PageOtpLogin::class,
138
-                'actions' => array(),
139
-            ),
140
-        'forgotPassword'              =>
141
-            array(
142
-                'class'   => PageForgotPassword::class,
143
-                'actions' => array('reset'),
144
-            ),
145
-        'register'                    =>
146
-            array(
147
-                'class'   => PageRegisterOption::class,
148
-                'actions' => array(),
149
-            ),
150
-        'register/standard'           =>
151
-            array(
152
-                'class'   => PageRegisterStandard::class,
153
-                'actions' => array('done'),
154
-            ),
155
-        'domainSwitch'                =>
156
-            array(
157
-                'class'   => PageDomainSwitch::class,
158
-                'actions' => array(),
159
-            ),
160
-        'login/reactivate'            =>
161
-            array(
162
-                'class'   => PageUserReactivate::class,
163
-                'actions' => array(),
164
-            ),
165
-
166
-        //////////////////////////////////////////////////////////////////////////////////////////////////
167
-        // Discovery
168
-        'search'                      =>
169
-            array(
170
-                'class'   => PageSearch::class,
171
-                'actions' => array(),
172
-            ),
173
-        'logs'                        =>
174
-            array(
175
-                'class'   => PageLog::class,
176
-                'actions' => array(),
177
-            ),
178
-
179
-        //////////////////////////////////////////////////////////////////////////////////////////////////
180
-        // Administration
181
-        'bans'                        =>
182
-            array(
183
-                'class'   => PageBan::class,
184
-                'actions' => array('set', 'remove', 'show', 'replace'),
185
-            ),
186
-        'userManagement'              =>
187
-            array(
188
-                'class'   => PageUserManagement::class,
189
-                'actions' => array(
190
-                    'approve',
191
-                    'deactivate',
192
-                    'rename',
193
-                    'editUser',
194
-                    'editRoles',
195
-                ),
196
-            ),
197
-        'siteNotice'                  =>
198
-            array(
199
-                'class'   => PageSiteNotice::class,
200
-                'actions' => array(),
201
-            ),
202
-        'emailManagement'             =>
203
-            array(
204
-                'class'   => PageEmailManagement::class,
205
-                'actions' => array('create', 'edit', 'view'),
206
-            ),
207
-        'queueManagement'             =>
208
-            array(
209
-                'class'   => PageQueueManagement::class,
210
-                'actions' => array('create', 'edit'),
211
-            ),
212
-        'requestFormManagement'       =>
213
-            array(
214
-                'class'   => PageRequestFormManagement::class,
215
-                'actions' => array('create', 'edit', 'view', 'preview'),
216
-            ),
217
-        'jobQueue'                    =>
218
-            array(
219
-                'class'   => PageJobQueue::class,
220
-                'actions' => array('acknowledge', 'requeue', 'view', 'all', 'cancel'),
221
-            ),
222
-        'domainManagement'            =>
223
-            array(
224
-                'class'   => PageDomainManagement::class,
225
-                'actions' => array('create', 'edit'),
226
-            ),
227
-        'flaggedComments'             =>
228
-            array(
229
-                'class'   => PageListFlaggedComments::class,
230
-                'actions' => array(),
231
-            ),
232
-
233
-        //////////////////////////////////////////////////////////////////////////////////////////////////
234
-        // Personal preferences
235
-        'preferences'                 =>
236
-            array(
237
-                'class'   => PagePreferences::class,
238
-                'actions' => array(
239
-                    'refreshOAuth'
240
-                ),
241
-            ),
242
-        'changePassword'              =>
243
-            array(
244
-                'class'   => PageChangePassword::class,
245
-                'actions' => array(),
246
-            ),
247
-        'multiFactor'                 =>
248
-            array(
249
-                'class'   => PageMultiFactor::class,
250
-                'actions' => array(
251
-                    'scratch',
252
-                    'enableYubikeyOtp',
253
-                    'disableYubikeyOtp',
254
-                    'enableTotp',
255
-                    'disableTotp',
256
-                ),
257
-            ),
258
-        'oauth'                       =>
259
-            array(
260
-                'class'   => PageOAuth::class,
261
-                'actions' => array('detach', 'attach'),
262
-            ),
263
-        'oauth/callback'              =>
264
-            array(
265
-                'class'   => PageOAuthCallback::class,
266
-                'actions' => array('authorise', 'create'),
267
-            ),
268
-
269
-        //////////////////////////////////////////////////////////////////////////////////////////////////
270
-        // Welcomer configuration
271
-        'welcomeTemplates'            =>
272
-            array(
273
-                'class'   => PageWelcomeTemplateManagement::class,
274
-                'actions' => array('select', 'edit', 'delete', 'add', 'view'),
275
-            ),
276
-
277
-        //////////////////////////////////////////////////////////////////////////////////////////////////
278
-        // Statistics
279
-        'statistics'                  =>
280
-            array(
281
-                'class'   => StatsMain::class,
282
-                'actions' => array(),
283
-            ),
284
-        'statistics/fastCloses'       =>
285
-            array(
286
-                'class'   => StatsFastCloses::class,
287
-                'actions' => array(),
288
-            ),
289
-        'statistics/inactiveUsers'    =>
290
-            array(
291
-                'class'   => StatsInactiveUsers::class,
292
-                'actions' => array(),
293
-            ),
294
-        'statistics/monthlyStats'     =>
295
-            array(
296
-                'class'   => StatsMonthlyStats::class,
297
-                'actions' => array(),
298
-            ),
299
-        'statistics/reservedRequests' =>
300
-            array(
301
-                'class'   => StatsReservedRequests::class,
302
-                'actions' => array(),
303
-            ),
304
-        'statistics/templateStats'    =>
305
-            array(
306
-                'class'   => StatsTemplateStats::class,
307
-                'actions' => array(),
308
-            ),
309
-        'statistics/topCreators'      =>
310
-            array(
311
-                'class'   => StatsTopCreators::class,
312
-                'actions' => array(),
313
-            ),
314
-        'statistics/users'            =>
315
-            array(
316
-                'class'   => StatsUsers::class,
317
-                'actions' => array('detail'),
318
-            ),
319
-
320
-        //////////////////////////////////////////////////////////////////////////////////////////////////
321
-        // Zoom page
322
-        'viewRequest'                 =>
323
-            array(
324
-                'class'   => PageViewRequest::class,
325
-                'actions' => array(),
326
-            ),
327
-        'viewRequest/confirm'         =>
328
-            array(
329
-                'class'   => PageManuallyConfirm::class,
330
-                'actions' => array(),
331
-            ),
332
-        'viewRequest/reserve'         =>
333
-            array(
334
-                'class'   => PageReservation::class,
335
-                'actions' => array(),
336
-            ),
337
-        'viewRequest/breakReserve'    =>
338
-            array(
339
-                'class'   => PageBreakReservation::class,
340
-                'actions' => array(),
341
-            ),
342
-        'viewRequest/defer'           =>
343
-            array(
344
-                'class'   => PageDeferRequest::class,
345
-                'actions' => array(),
346
-            ),
347
-        'viewRequest/comment'         =>
348
-            array(
349
-                'class'   => PageComment::class,
350
-                'actions' => array(),
351
-            ),
352
-        'viewRequest/sendToUser'      =>
353
-            array(
354
-                'class'   => PageSendToUser::class,
355
-                'actions' => array(),
356
-            ),
357
-        'viewRequest/close'           =>
358
-            array(
359
-                'class'   => PageCloseRequest::class,
360
-                'actions' => array(),
361
-            ),
362
-        'viewRequest/create'          =>
363
-            array(
364
-                'class'   => PageCreateRequest::class,
365
-                'actions' => array(),
366
-            ),
367
-        'viewRequest/drop'            =>
368
-            array(
369
-                'class'   => PageDropRequest::class,
370
-                'actions' => array(),
371
-            ),
372
-        'viewRequest/custom'          =>
373
-            array(
374
-                'class'   => PageCustomClose::class,
375
-                'actions' => array(),
376
-            ),
377
-        'editComment'                 =>
378
-            array(
379
-                'class'   => PageEditComment::class,
380
-                'actions' => array(),
381
-            ),
382
-        'flagComment'                 =>
383
-            array(
384
-                'class'   => PageFlagComment::class,
385
-                'actions' => array(),
386
-            ),
387
-
388
-        //////////////////////////////////////////////////////////////////////////////////////////////////
389
-        // Misc stuff
390
-        'team'                        =>
391
-            array(
392
-                'class'   => PageTeam::class,
393
-                'actions' => array(),
394
-            ),
395
-        'requestList'                 =>
396
-            array(
397
-                'class'   => PageExpandedRequestList::class,
398
-                'actions' => array(),
399
-            ),
400
-        'xffdemo'                     =>
401
-            array(
402
-                'class'   => PageXffDemo::class,
403
-                'actions' => array(),
404
-            ),
405
-        'errorLog'                    =>
406
-            array(
407
-                'class'   => PageErrorLogViewer::class,
408
-                'actions' => array('remove', 'view'),
409
-            ),
410
-        'privacy'                     =>
411
-            array(
412
-                'class'   => PagePrivacy::class,
413
-                'actions' => array(),
414
-            ),
415
-    );
416
-
417
-    /**
418
-     * @return IRoutedTask
419
-     * @throws Exception
420
-     */
421
-    final public function route()
422
-    {
423
-        $pathInfo = WebRequest::pathInfo();
424
-
425
-        list($pageClass, $action) = $this->getRouteFromPath($pathInfo);
426
-
427
-        /** @var IRoutedTask $page */
428
-        $page = new $pageClass();
429
-
430
-        // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so
431
-        // let's use our own.
432
-        if (!($page instanceof IRoutedTask)) {
433
-            throw new Exception('Expected a page, but this is not a page.');
434
-        }
435
-
436
-        // 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
437
-        // inherits PageBase and has been created from the routing map.
438
-        $page->setRoute($action);
439
-
440
-        return $page;
441
-    }
442
-
443
-    /**
444
-     * @param $pathInfo
445
-     *
446
-     * @return array
447
-     */
448
-    public function getRouteFromPath($pathInfo)
449
-    {
450
-        if (count($pathInfo) === 0) {
451
-            // No pathInfo, so no page to load. Load the main page.
452
-            return $this->getDefaultRoute();
453
-        }
454
-        elseif (count($pathInfo) === 1) {
455
-            // Exactly one path info segment, it's got to be a page.
456
-            $classSegment = $pathInfo[0];
457
-
458
-            return $this->routeSinglePathSegment($classSegment);
459
-        }
460
-
461
-        // OK, we have two or more segments now.
462
-        if (count($pathInfo) > 2) {
463
-            // Let's handle more than two, and collapse it down into two.
464
-            $requestedAction = array_pop($pathInfo);
465
-            $classSegment = implode('/', $pathInfo);
466
-        }
467
-        else {
468
-            // Two path info segments.
469
-            $classSegment = $pathInfo[0];
470
-            $requestedAction = $pathInfo[1];
471
-        }
472
-
473
-        $routeMap = $this->routePathSegments($classSegment, $requestedAction);
474
-
475
-        if ($routeMap[0] === Page404::class) {
476
-            $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction);
477
-        }
478
-
479
-        return $routeMap;
480
-    }
481
-
482
-    /**
483
-     * @param $classSegment
484
-     *
485
-     * @return array
486
-     */
487
-    final protected function routeSinglePathSegment($classSegment)
488
-    {
489
-        $routeMap = $this->getRouteMap();
490
-        if (array_key_exists($classSegment, $routeMap)) {
491
-            // Route exists, but we don't have an action in path info, so default to main.
492
-            $pageClass = $routeMap[$classSegment]['class'];
493
-            $action = 'main';
494
-
495
-            return array($pageClass, $action);
496
-        }
497
-        else {
498
-            // Doesn't exist in map. Fall back to 404
499
-            $pageClass = Page404::class;
500
-            $action = "main";
501
-
502
-            return array($pageClass, $action);
503
-        }
504
-    }
505
-
506
-    /**
507
-     * @param $classSegment
508
-     * @param $requestedAction
509
-     *
510
-     * @return array
511
-     */
512
-    final protected function routePathSegments($classSegment, $requestedAction)
513
-    {
514
-        $routeMap = $this->getRouteMap();
515
-        if (array_key_exists($classSegment, $routeMap)) {
516
-            // Route exists, but we don't have an action in path info, so default to main.
517
-
518
-            if (isset($routeMap[$classSegment]['actions'])
519
-                && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false
520
-            ) {
521
-                // Action exists in allowed action list. Allow both the page and the action
522
-                $pageClass = $routeMap[$classSegment]['class'];
523
-                $action = $requestedAction;
524
-
525
-                return array($pageClass, $action);
526
-            }
527
-            else {
528
-                // Valid page, invalid action. 404 our way out.
529
-                $pageClass = Page404::class;
530
-                $action = 'main';
531
-
532
-                return array($pageClass, $action);
533
-            }
534
-        }
535
-        else {
536
-            // Class doesn't exist in map. Fall back to 404
537
-            $pageClass = Page404::class;
538
-            $action = 'main';
539
-
540
-            return array($pageClass, $action);
541
-        }
542
-    }
543
-
544
-    /**
545
-     * @return array
546
-     */
547
-    protected function getRouteMap()
548
-    {
549
-        return $this->routeMap;
550
-    }
551
-
552
-    /**
553
-     * @return array
554
-     */
555
-    protected function getDefaultRoute()
556
-    {
557
-        return array(PageMain::class, "main");
558
-    }
76
+	/**
77
+	 * This is the core routing table for the application. The basic idea is:
78
+	 *
79
+	 *      array(
80
+	 *          "foo" =>
81
+	 *              array(
82
+	 *                  "class"   => PageFoo::class,
83
+	 *                  "actions" => array("bar", "other")
84
+	 *              ),
85
+	 * );
86
+	 *
87
+	 * Things to note:
88
+	 *     - If no page is requested, we go to PageMain. PageMain can't have actions defined.
89
+	 *
90
+	 *     - If a page is defined and requested, but no action is requested, go to that page's main() method
91
+	 *     - If a page is defined and requested, and an action is defined and requested, go to that action's method.
92
+	 *     - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main()
93
+	 *       method.
94
+	 *     - If a page is NOT defined and requested, go to Page404 and it's main() method.
95
+	 *
96
+	 *     - Query parameters are ignored.
97
+	 *
98
+	 * The key point here is request routing with validation that this is allowed, before we start hitting the
99
+	 * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested
100
+	 * before we start calling random methods through the web UI.
101
+	 *
102
+	 * Examples:
103
+	 * /internal.php                => returns instance of PageMain, routed to main()
104
+	 * /internal.php?query          => returns instance of PageMain, routed to main()
105
+	 * /internal.php/foo            => returns instance of PageFoo, routed to main()
106
+	 * /internal.php/foo?query      => returns instance of PageFoo, routed to main()
107
+	 * /internal.php/foo/bar        => returns instance of PageFoo, routed to bar()
108
+	 * /internal.php/foo/bar?query  => returns instance of PageFoo, routed to bar()
109
+	 * /internal.php/foo/baz        => returns instance of Page404, routed to main()
110
+	 * /internal.php/foo/baz?query  => returns instance of Page404, routed to main()
111
+	 * /internal.php/bar            => returns instance of Page404, routed to main()
112
+	 * /internal.php/bar?query      => returns instance of Page404, routed to main()
113
+	 * /internal.php/bar/baz        => returns instance of Page404, routed to main()
114
+	 * /internal.php/bar/baz?query  => returns instance of Page404, routed to main()
115
+	 *
116
+	 * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need
117
+	 * to change the key, then you'll likely have to update a lot of files.
118
+	 *
119
+	 * @var array
120
+	 */
121
+	private $routeMap = array(
122
+
123
+		//////////////////////////////////////////////////////////////////////////////////////////////////
124
+		// Login and registration
125
+		'logout'                      =>
126
+			array(
127
+				'class'   => PageLogout::class,
128
+				'actions' => array(),
129
+			),
130
+		'login'                       =>
131
+			array(
132
+				'class'   => PagePasswordLogin::class,
133
+				'actions' => array(),
134
+			),
135
+		'login/otp'                   =>
136
+			array(
137
+				'class'   => PageOtpLogin::class,
138
+				'actions' => array(),
139
+			),
140
+		'forgotPassword'              =>
141
+			array(
142
+				'class'   => PageForgotPassword::class,
143
+				'actions' => array('reset'),
144
+			),
145
+		'register'                    =>
146
+			array(
147
+				'class'   => PageRegisterOption::class,
148
+				'actions' => array(),
149
+			),
150
+		'register/standard'           =>
151
+			array(
152
+				'class'   => PageRegisterStandard::class,
153
+				'actions' => array('done'),
154
+			),
155
+		'domainSwitch'                =>
156
+			array(
157
+				'class'   => PageDomainSwitch::class,
158
+				'actions' => array(),
159
+			),
160
+		'login/reactivate'            =>
161
+			array(
162
+				'class'   => PageUserReactivate::class,
163
+				'actions' => array(),
164
+			),
165
+
166
+		//////////////////////////////////////////////////////////////////////////////////////////////////
167
+		// Discovery
168
+		'search'                      =>
169
+			array(
170
+				'class'   => PageSearch::class,
171
+				'actions' => array(),
172
+			),
173
+		'logs'                        =>
174
+			array(
175
+				'class'   => PageLog::class,
176
+				'actions' => array(),
177
+			),
178
+
179
+		//////////////////////////////////////////////////////////////////////////////////////////////////
180
+		// Administration
181
+		'bans'                        =>
182
+			array(
183
+				'class'   => PageBan::class,
184
+				'actions' => array('set', 'remove', 'show', 'replace'),
185
+			),
186
+		'userManagement'              =>
187
+			array(
188
+				'class'   => PageUserManagement::class,
189
+				'actions' => array(
190
+					'approve',
191
+					'deactivate',
192
+					'rename',
193
+					'editUser',
194
+					'editRoles',
195
+				),
196
+			),
197
+		'siteNotice'                  =>
198
+			array(
199
+				'class'   => PageSiteNotice::class,
200
+				'actions' => array(),
201
+			),
202
+		'emailManagement'             =>
203
+			array(
204
+				'class'   => PageEmailManagement::class,
205
+				'actions' => array('create', 'edit', 'view'),
206
+			),
207
+		'queueManagement'             =>
208
+			array(
209
+				'class'   => PageQueueManagement::class,
210
+				'actions' => array('create', 'edit'),
211
+			),
212
+		'requestFormManagement'       =>
213
+			array(
214
+				'class'   => PageRequestFormManagement::class,
215
+				'actions' => array('create', 'edit', 'view', 'preview'),
216
+			),
217
+		'jobQueue'                    =>
218
+			array(
219
+				'class'   => PageJobQueue::class,
220
+				'actions' => array('acknowledge', 'requeue', 'view', 'all', 'cancel'),
221
+			),
222
+		'domainManagement'            =>
223
+			array(
224
+				'class'   => PageDomainManagement::class,
225
+				'actions' => array('create', 'edit'),
226
+			),
227
+		'flaggedComments'             =>
228
+			array(
229
+				'class'   => PageListFlaggedComments::class,
230
+				'actions' => array(),
231
+			),
232
+
233
+		//////////////////////////////////////////////////////////////////////////////////////////////////
234
+		// Personal preferences
235
+		'preferences'                 =>
236
+			array(
237
+				'class'   => PagePreferences::class,
238
+				'actions' => array(
239
+					'refreshOAuth'
240
+				),
241
+			),
242
+		'changePassword'              =>
243
+			array(
244
+				'class'   => PageChangePassword::class,
245
+				'actions' => array(),
246
+			),
247
+		'multiFactor'                 =>
248
+			array(
249
+				'class'   => PageMultiFactor::class,
250
+				'actions' => array(
251
+					'scratch',
252
+					'enableYubikeyOtp',
253
+					'disableYubikeyOtp',
254
+					'enableTotp',
255
+					'disableTotp',
256
+				),
257
+			),
258
+		'oauth'                       =>
259
+			array(
260
+				'class'   => PageOAuth::class,
261
+				'actions' => array('detach', 'attach'),
262
+			),
263
+		'oauth/callback'              =>
264
+			array(
265
+				'class'   => PageOAuthCallback::class,
266
+				'actions' => array('authorise', 'create'),
267
+			),
268
+
269
+		//////////////////////////////////////////////////////////////////////////////////////////////////
270
+		// Welcomer configuration
271
+		'welcomeTemplates'            =>
272
+			array(
273
+				'class'   => PageWelcomeTemplateManagement::class,
274
+				'actions' => array('select', 'edit', 'delete', 'add', 'view'),
275
+			),
276
+
277
+		//////////////////////////////////////////////////////////////////////////////////////////////////
278
+		// Statistics
279
+		'statistics'                  =>
280
+			array(
281
+				'class'   => StatsMain::class,
282
+				'actions' => array(),
283
+			),
284
+		'statistics/fastCloses'       =>
285
+			array(
286
+				'class'   => StatsFastCloses::class,
287
+				'actions' => array(),
288
+			),
289
+		'statistics/inactiveUsers'    =>
290
+			array(
291
+				'class'   => StatsInactiveUsers::class,
292
+				'actions' => array(),
293
+			),
294
+		'statistics/monthlyStats'     =>
295
+			array(
296
+				'class'   => StatsMonthlyStats::class,
297
+				'actions' => array(),
298
+			),
299
+		'statistics/reservedRequests' =>
300
+			array(
301
+				'class'   => StatsReservedRequests::class,
302
+				'actions' => array(),
303
+			),
304
+		'statistics/templateStats'    =>
305
+			array(
306
+				'class'   => StatsTemplateStats::class,
307
+				'actions' => array(),
308
+			),
309
+		'statistics/topCreators'      =>
310
+			array(
311
+				'class'   => StatsTopCreators::class,
312
+				'actions' => array(),
313
+			),
314
+		'statistics/users'            =>
315
+			array(
316
+				'class'   => StatsUsers::class,
317
+				'actions' => array('detail'),
318
+			),
319
+
320
+		//////////////////////////////////////////////////////////////////////////////////////////////////
321
+		// Zoom page
322
+		'viewRequest'                 =>
323
+			array(
324
+				'class'   => PageViewRequest::class,
325
+				'actions' => array(),
326
+			),
327
+		'viewRequest/confirm'         =>
328
+			array(
329
+				'class'   => PageManuallyConfirm::class,
330
+				'actions' => array(),
331
+			),
332
+		'viewRequest/reserve'         =>
333
+			array(
334
+				'class'   => PageReservation::class,
335
+				'actions' => array(),
336
+			),
337
+		'viewRequest/breakReserve'    =>
338
+			array(
339
+				'class'   => PageBreakReservation::class,
340
+				'actions' => array(),
341
+			),
342
+		'viewRequest/defer'           =>
343
+			array(
344
+				'class'   => PageDeferRequest::class,
345
+				'actions' => array(),
346
+			),
347
+		'viewRequest/comment'         =>
348
+			array(
349
+				'class'   => PageComment::class,
350
+				'actions' => array(),
351
+			),
352
+		'viewRequest/sendToUser'      =>
353
+			array(
354
+				'class'   => PageSendToUser::class,
355
+				'actions' => array(),
356
+			),
357
+		'viewRequest/close'           =>
358
+			array(
359
+				'class'   => PageCloseRequest::class,
360
+				'actions' => array(),
361
+			),
362
+		'viewRequest/create'          =>
363
+			array(
364
+				'class'   => PageCreateRequest::class,
365
+				'actions' => array(),
366
+			),
367
+		'viewRequest/drop'            =>
368
+			array(
369
+				'class'   => PageDropRequest::class,
370
+				'actions' => array(),
371
+			),
372
+		'viewRequest/custom'          =>
373
+			array(
374
+				'class'   => PageCustomClose::class,
375
+				'actions' => array(),
376
+			),
377
+		'editComment'                 =>
378
+			array(
379
+				'class'   => PageEditComment::class,
380
+				'actions' => array(),
381
+			),
382
+		'flagComment'                 =>
383
+			array(
384
+				'class'   => PageFlagComment::class,
385
+				'actions' => array(),
386
+			),
387
+
388
+		//////////////////////////////////////////////////////////////////////////////////////////////////
389
+		// Misc stuff
390
+		'team'                        =>
391
+			array(
392
+				'class'   => PageTeam::class,
393
+				'actions' => array(),
394
+			),
395
+		'requestList'                 =>
396
+			array(
397
+				'class'   => PageExpandedRequestList::class,
398
+				'actions' => array(),
399
+			),
400
+		'xffdemo'                     =>
401
+			array(
402
+				'class'   => PageXffDemo::class,
403
+				'actions' => array(),
404
+			),
405
+		'errorLog'                    =>
406
+			array(
407
+				'class'   => PageErrorLogViewer::class,
408
+				'actions' => array('remove', 'view'),
409
+			),
410
+		'privacy'                     =>
411
+			array(
412
+				'class'   => PagePrivacy::class,
413
+				'actions' => array(),
414
+			),
415
+	);
416
+
417
+	/**
418
+	 * @return IRoutedTask
419
+	 * @throws Exception
420
+	 */
421
+	final public function route()
422
+	{
423
+		$pathInfo = WebRequest::pathInfo();
424
+
425
+		list($pageClass, $action) = $this->getRouteFromPath($pathInfo);
426
+
427
+		/** @var IRoutedTask $page */
428
+		$page = new $pageClass();
429
+
430
+		// Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so
431
+		// let's use our own.
432
+		if (!($page instanceof IRoutedTask)) {
433
+			throw new Exception('Expected a page, but this is not a page.');
434
+		}
435
+
436
+		// 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
437
+		// inherits PageBase and has been created from the routing map.
438
+		$page->setRoute($action);
439
+
440
+		return $page;
441
+	}
442
+
443
+	/**
444
+	 * @param $pathInfo
445
+	 *
446
+	 * @return array
447
+	 */
448
+	public function getRouteFromPath($pathInfo)
449
+	{
450
+		if (count($pathInfo) === 0) {
451
+			// No pathInfo, so no page to load. Load the main page.
452
+			return $this->getDefaultRoute();
453
+		}
454
+		elseif (count($pathInfo) === 1) {
455
+			// Exactly one path info segment, it's got to be a page.
456
+			$classSegment = $pathInfo[0];
457
+
458
+			return $this->routeSinglePathSegment($classSegment);
459
+		}
460
+
461
+		// OK, we have two or more segments now.
462
+		if (count($pathInfo) > 2) {
463
+			// Let's handle more than two, and collapse it down into two.
464
+			$requestedAction = array_pop($pathInfo);
465
+			$classSegment = implode('/', $pathInfo);
466
+		}
467
+		else {
468
+			// Two path info segments.
469
+			$classSegment = $pathInfo[0];
470
+			$requestedAction = $pathInfo[1];
471
+		}
472
+
473
+		$routeMap = $this->routePathSegments($classSegment, $requestedAction);
474
+
475
+		if ($routeMap[0] === Page404::class) {
476
+			$routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction);
477
+		}
478
+
479
+		return $routeMap;
480
+	}
481
+
482
+	/**
483
+	 * @param $classSegment
484
+	 *
485
+	 * @return array
486
+	 */
487
+	final protected function routeSinglePathSegment($classSegment)
488
+	{
489
+		$routeMap = $this->getRouteMap();
490
+		if (array_key_exists($classSegment, $routeMap)) {
491
+			// Route exists, but we don't have an action in path info, so default to main.
492
+			$pageClass = $routeMap[$classSegment]['class'];
493
+			$action = 'main';
494
+
495
+			return array($pageClass, $action);
496
+		}
497
+		else {
498
+			// Doesn't exist in map. Fall back to 404
499
+			$pageClass = Page404::class;
500
+			$action = "main";
501
+
502
+			return array($pageClass, $action);
503
+		}
504
+	}
505
+
506
+	/**
507
+	 * @param $classSegment
508
+	 * @param $requestedAction
509
+	 *
510
+	 * @return array
511
+	 */
512
+	final protected function routePathSegments($classSegment, $requestedAction)
513
+	{
514
+		$routeMap = $this->getRouteMap();
515
+		if (array_key_exists($classSegment, $routeMap)) {
516
+			// Route exists, but we don't have an action in path info, so default to main.
517
+
518
+			if (isset($routeMap[$classSegment]['actions'])
519
+				&& array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false
520
+			) {
521
+				// Action exists in allowed action list. Allow both the page and the action
522
+				$pageClass = $routeMap[$classSegment]['class'];
523
+				$action = $requestedAction;
524
+
525
+				return array($pageClass, $action);
526
+			}
527
+			else {
528
+				// Valid page, invalid action. 404 our way out.
529
+				$pageClass = Page404::class;
530
+				$action = 'main';
531
+
532
+				return array($pageClass, $action);
533
+			}
534
+		}
535
+		else {
536
+			// Class doesn't exist in map. Fall back to 404
537
+			$pageClass = Page404::class;
538
+			$action = 'main';
539
+
540
+			return array($pageClass, $action);
541
+		}
542
+	}
543
+
544
+	/**
545
+	 * @return array
546
+	 */
547
+	protected function getRouteMap()
548
+	{
549
+		return $this->routeMap;
550
+	}
551
+
552
+	/**
553
+	 * @return array
554
+	 */
555
+	protected function getDefaultRoute()
556
+	{
557
+		return array(PageMain::class, "main");
558
+	}
559 559
 }
Please login to merge, or discard this patch.
includes/Router/IRequestRouter.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,9 +18,9 @@
 block discarded – undo
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
Please login to merge, or discard this patch.