@@ -13,91 +13,91 @@ |
||
| 13 | 13 | |
| 14 | 14 | class TokenManager |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Validates a CSRF token |
|
| 18 | - * |
|
| 19 | - * @param string $data The token data string itself |
|
| 20 | - * @param string|null $context Token context for extra validation |
|
| 21 | - * |
|
| 22 | - * @return bool |
|
| 23 | - */ |
|
| 24 | - public function validateToken($data, $context = null) |
|
| 25 | - { |
|
| 26 | - if (!is_string($data) || strlen($data) === 0) { |
|
| 27 | - // Nothing to validate |
|
| 28 | - return false; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $tokens = WebRequest::getSessionTokenData(); |
|
| 32 | - |
|
| 33 | - // if the token doesn't exist, then it's not valid |
|
| 34 | - if (!array_key_exists($data, $tokens)) { |
|
| 35 | - return false; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** @var Token $token */ |
|
| 39 | - $token = unserialize($tokens[$data]); |
|
| 40 | - |
|
| 41 | - if ($token->getTokenData() !== $data) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - if ($token->getContext() !== $context) { |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ($token->isUsed()) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // mark the token as used, and save it back to the session |
|
| 54 | - $token->markAsUsed(); |
|
| 55 | - $this->storeToken($token); |
|
| 56 | - |
|
| 57 | - return true; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param string|null $context An optional context for extra validation |
|
| 62 | - * |
|
| 63 | - * @return Token |
|
| 64 | - */ |
|
| 65 | - public function getNewToken($context = null) |
|
| 66 | - { |
|
| 67 | - $token = new Token($this->generateTokenData(), $context); |
|
| 68 | - $this->storeToken($token); |
|
| 69 | - |
|
| 70 | - return $token; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Stores a token in the session data |
|
| 75 | - * |
|
| 76 | - * @param Token $token |
|
| 77 | - */ |
|
| 78 | - private function storeToken(Token $token) |
|
| 79 | - { |
|
| 80 | - $tokens = WebRequest::getSessionTokenData(); |
|
| 81 | - $tokens[$token->getTokenData()] = serialize($token); |
|
| 82 | - WebRequest::setSessionTokenData($tokens); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Generates a security token |
|
| 87 | - * |
|
| 88 | - * @return string |
|
| 89 | - * @throws Exception |
|
| 90 | - * |
|
| 91 | - * @category Security-Critical |
|
| 92 | - */ |
|
| 93 | - private function generateTokenData() |
|
| 94 | - { |
|
| 95 | - $genBytes = openssl_random_pseudo_bytes(33); |
|
| 96 | - |
|
| 97 | - if ($genBytes !== false) { |
|
| 98 | - return base64_encode($genBytes); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - throw new Exception('Unable to generate secure token.'); |
|
| 102 | - } |
|
| 16 | + /** |
|
| 17 | + * Validates a CSRF token |
|
| 18 | + * |
|
| 19 | + * @param string $data The token data string itself |
|
| 20 | + * @param string|null $context Token context for extra validation |
|
| 21 | + * |
|
| 22 | + * @return bool |
|
| 23 | + */ |
|
| 24 | + public function validateToken($data, $context = null) |
|
| 25 | + { |
|
| 26 | + if (!is_string($data) || strlen($data) === 0) { |
|
| 27 | + // Nothing to validate |
|
| 28 | + return false; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $tokens = WebRequest::getSessionTokenData(); |
|
| 32 | + |
|
| 33 | + // if the token doesn't exist, then it's not valid |
|
| 34 | + if (!array_key_exists($data, $tokens)) { |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** @var Token $token */ |
|
| 39 | + $token = unserialize($tokens[$data]); |
|
| 40 | + |
|
| 41 | + if ($token->getTokenData() !== $data) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + if ($token->getContext() !== $context) { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ($token->isUsed()) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // mark the token as used, and save it back to the session |
|
| 54 | + $token->markAsUsed(); |
|
| 55 | + $this->storeToken($token); |
|
| 56 | + |
|
| 57 | + return true; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param string|null $context An optional context for extra validation |
|
| 62 | + * |
|
| 63 | + * @return Token |
|
| 64 | + */ |
|
| 65 | + public function getNewToken($context = null) |
|
| 66 | + { |
|
| 67 | + $token = new Token($this->generateTokenData(), $context); |
|
| 68 | + $this->storeToken($token); |
|
| 69 | + |
|
| 70 | + return $token; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Stores a token in the session data |
|
| 75 | + * |
|
| 76 | + * @param Token $token |
|
| 77 | + */ |
|
| 78 | + private function storeToken(Token $token) |
|
| 79 | + { |
|
| 80 | + $tokens = WebRequest::getSessionTokenData(); |
|
| 81 | + $tokens[$token->getTokenData()] = serialize($token); |
|
| 82 | + WebRequest::setSessionTokenData($tokens); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Generates a security token |
|
| 87 | + * |
|
| 88 | + * @return string |
|
| 89 | + * @throws Exception |
|
| 90 | + * |
|
| 91 | + * @category Security-Critical |
|
| 92 | + */ |
|
| 93 | + private function generateTokenData() |
|
| 94 | + { |
|
| 95 | + $genBytes = openssl_random_pseudo_bytes(33); |
|
| 96 | + |
|
| 97 | + if ($genBytes !== false) { |
|
| 98 | + return base64_encode($genBytes); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + throw new Exception('Unable to generate secure token.'); |
|
| 102 | + } |
|
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -10,152 +10,152 @@ |
||
| 10 | 10 | |
| 11 | 11 | final class SecurityConfigurationFactory |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * @var bool |
|
| 15 | - */ |
|
| 16 | - private $forceIdentified; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Security constructor. |
|
| 20 | - * |
|
| 21 | - * @param bool $forceIdentified |
|
| 22 | - */ |
|
| 23 | - public function __construct($forceIdentified) |
|
| 24 | - { |
|
| 25 | - $this->forceIdentified = $forceIdentified; |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Returns a pre-built security configuration for an internal page. |
|
| 30 | - * |
|
| 31 | - * @category Security-Critical |
|
| 32 | - * @return SecurityConfiguration |
|
| 33 | - */ |
|
| 34 | - public function asInternalPage() |
|
| 35 | - { |
|
| 36 | - $config = new SecurityConfiguration(); |
|
| 37 | - $config->setAdmin(SecurityConfiguration::ALLOW) |
|
| 38 | - ->setUser(SecurityConfiguration::ALLOW); |
|
| 39 | - |
|
| 40 | - $config->setRequireIdentified($this->forceIdentified); |
|
| 41 | - |
|
| 42 | - return $config; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Returns a pre-built security configuration for a tool admin only page. |
|
| 47 | - * |
|
| 48 | - * @category Security-Critical |
|
| 49 | - * @return SecurityConfiguration |
|
| 50 | - */ |
|
| 51 | - public function asAdminPage() |
|
| 52 | - { |
|
| 53 | - $config = new SecurityConfiguration(); |
|
| 54 | - $config->setAdmin(SecurityConfiguration::ALLOW); |
|
| 55 | - |
|
| 56 | - $config->setRequireIdentified($this->forceIdentified); |
|
| 57 | - |
|
| 58 | - return $config; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Returns a pre-built security configuration for a page accessible to *ALL* logged in users, including suspended |
|
| 63 | - * and new users. This probably isn't the setting you want. |
|
| 64 | - * |
|
| 65 | - * @category Security-Critical |
|
| 66 | - * @return SecurityConfiguration |
|
| 67 | - */ |
|
| 68 | - public function asAllLoggedInUsersPage() |
|
| 69 | - { |
|
| 70 | - $config = new SecurityConfiguration(); |
|
| 71 | - $config->setAdmin(SecurityConfiguration::ALLOW) |
|
| 72 | - ->setUser(SecurityConfiguration::ALLOW) |
|
| 73 | - ->setDeclined(SecurityConfiguration::ALLOW) |
|
| 74 | - ->setNew(SecurityConfiguration::ALLOW) |
|
| 75 | - ->setSuspended(SecurityConfiguration::ALLOW); |
|
| 76 | - |
|
| 77 | - $config->setRequireIdentified($this->forceIdentified); |
|
| 78 | - |
|
| 79 | - return $config; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @return SecurityConfiguration |
|
| 84 | - * @category Security-Critical |
|
| 85 | - */ |
|
| 86 | - public function asCheckUserData() |
|
| 87 | - { |
|
| 88 | - $config = new SecurityConfiguration(); |
|
| 89 | - $config->setCheckuser(SecurityConfiguration::ALLOW) |
|
| 90 | - ->setCommunity(SecurityConfiguration::DENY) |
|
| 91 | - ->setSuspended(SecurityConfiguration::DENY) |
|
| 92 | - ->setDeclined(SecurityConfiguration::DENY) |
|
| 93 | - ->setNew(SecurityConfiguration::DENY); |
|
| 94 | - |
|
| 95 | - $config->setRequireIdentified($this->forceIdentified); |
|
| 96 | - |
|
| 97 | - return $config; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Returns a pre-built security configuration for a public page. |
|
| 102 | - * |
|
| 103 | - * @category Security-Critical |
|
| 104 | - * @return SecurityConfiguration |
|
| 105 | - */ |
|
| 106 | - public function asPublicPage() |
|
| 107 | - { |
|
| 108 | - $config = new SecurityConfiguration(); |
|
| 109 | - $config->setAdmin(SecurityConfiguration::ALLOW) |
|
| 110 | - ->setUser(SecurityConfiguration::ALLOW) |
|
| 111 | - ->setCheckuser(SecurityConfiguration::ALLOW) |
|
| 112 | - ->setCommunity(SecurityConfiguration::ALLOW) |
|
| 113 | - ->setSuspended(SecurityConfiguration::ALLOW) |
|
| 114 | - ->setDeclined(SecurityConfiguration::ALLOW) |
|
| 115 | - ->setNew(SecurityConfiguration::ALLOW); |
|
| 116 | - |
|
| 117 | - // Public pages shouldn't be inaccessible to logged-in, unidentified users. |
|
| 118 | - // Otherwise, logged in but unidentified users can't even log out. |
|
| 119 | - $config->setRequireIdentified(false); |
|
| 120 | - |
|
| 121 | - return $config; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Special case for zoom page private data. |
|
| 126 | - * |
|
| 127 | - * This will only return true if you are either a checkuser or a tool admin, taking special note of disabled |
|
| 128 | - * accounts which happen to be check users |
|
| 129 | - * |
|
| 130 | - * @return SecurityConfiguration |
|
| 131 | - */ |
|
| 132 | - public function asGeneralPrivateDataAccess() |
|
| 133 | - { |
|
| 134 | - $config = new SecurityConfiguration(); |
|
| 135 | - $config |
|
| 136 | - // Basic configuration, admins and check users allowed |
|
| 137 | - ->setAdmin(SecurityConfiguration::ALLOW) |
|
| 138 | - ->setCheckuser(SecurityConfiguration::ALLOW) |
|
| 139 | - // Deny these, even if they were allowed by the above |
|
| 140 | - ->setCommunity(SecurityConfiguration::DENY) |
|
| 141 | - ->setSuspended(SecurityConfiguration::DENY) |
|
| 142 | - ->setDeclined(SecurityConfiguration::DENY) |
|
| 143 | - ->setNew(SecurityConfiguration::DENY); |
|
| 144 | - |
|
| 145 | - // You must also be identified to access this data |
|
| 146 | - $config->setRequireIdentified($this->forceIdentified); |
|
| 147 | - |
|
| 148 | - return $config; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @category Security-Critical |
|
| 153 | - * @return SecurityConfiguration |
|
| 154 | - */ |
|
| 155 | - public function asNone() |
|
| 156 | - { |
|
| 157 | - $config = new SecurityConfiguration(); |
|
| 158 | - |
|
| 159 | - return $config; |
|
| 160 | - } |
|
| 13 | + /** |
|
| 14 | + * @var bool |
|
| 15 | + */ |
|
| 16 | + private $forceIdentified; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Security constructor. |
|
| 20 | + * |
|
| 21 | + * @param bool $forceIdentified |
|
| 22 | + */ |
|
| 23 | + public function __construct($forceIdentified) |
|
| 24 | + { |
|
| 25 | + $this->forceIdentified = $forceIdentified; |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Returns a pre-built security configuration for an internal page. |
|
| 30 | + * |
|
| 31 | + * @category Security-Critical |
|
| 32 | + * @return SecurityConfiguration |
|
| 33 | + */ |
|
| 34 | + public function asInternalPage() |
|
| 35 | + { |
|
| 36 | + $config = new SecurityConfiguration(); |
|
| 37 | + $config->setAdmin(SecurityConfiguration::ALLOW) |
|
| 38 | + ->setUser(SecurityConfiguration::ALLOW); |
|
| 39 | + |
|
| 40 | + $config->setRequireIdentified($this->forceIdentified); |
|
| 41 | + |
|
| 42 | + return $config; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Returns a pre-built security configuration for a tool admin only page. |
|
| 47 | + * |
|
| 48 | + * @category Security-Critical |
|
| 49 | + * @return SecurityConfiguration |
|
| 50 | + */ |
|
| 51 | + public function asAdminPage() |
|
| 52 | + { |
|
| 53 | + $config = new SecurityConfiguration(); |
|
| 54 | + $config->setAdmin(SecurityConfiguration::ALLOW); |
|
| 55 | + |
|
| 56 | + $config->setRequireIdentified($this->forceIdentified); |
|
| 57 | + |
|
| 58 | + return $config; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Returns a pre-built security configuration for a page accessible to *ALL* logged in users, including suspended |
|
| 63 | + * and new users. This probably isn't the setting you want. |
|
| 64 | + * |
|
| 65 | + * @category Security-Critical |
|
| 66 | + * @return SecurityConfiguration |
|
| 67 | + */ |
|
| 68 | + public function asAllLoggedInUsersPage() |
|
| 69 | + { |
|
| 70 | + $config = new SecurityConfiguration(); |
|
| 71 | + $config->setAdmin(SecurityConfiguration::ALLOW) |
|
| 72 | + ->setUser(SecurityConfiguration::ALLOW) |
|
| 73 | + ->setDeclined(SecurityConfiguration::ALLOW) |
|
| 74 | + ->setNew(SecurityConfiguration::ALLOW) |
|
| 75 | + ->setSuspended(SecurityConfiguration::ALLOW); |
|
| 76 | + |
|
| 77 | + $config->setRequireIdentified($this->forceIdentified); |
|
| 78 | + |
|
| 79 | + return $config; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @return SecurityConfiguration |
|
| 84 | + * @category Security-Critical |
|
| 85 | + */ |
|
| 86 | + public function asCheckUserData() |
|
| 87 | + { |
|
| 88 | + $config = new SecurityConfiguration(); |
|
| 89 | + $config->setCheckuser(SecurityConfiguration::ALLOW) |
|
| 90 | + ->setCommunity(SecurityConfiguration::DENY) |
|
| 91 | + ->setSuspended(SecurityConfiguration::DENY) |
|
| 92 | + ->setDeclined(SecurityConfiguration::DENY) |
|
| 93 | + ->setNew(SecurityConfiguration::DENY); |
|
| 94 | + |
|
| 95 | + $config->setRequireIdentified($this->forceIdentified); |
|
| 96 | + |
|
| 97 | + return $config; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Returns a pre-built security configuration for a public page. |
|
| 102 | + * |
|
| 103 | + * @category Security-Critical |
|
| 104 | + * @return SecurityConfiguration |
|
| 105 | + */ |
|
| 106 | + public function asPublicPage() |
|
| 107 | + { |
|
| 108 | + $config = new SecurityConfiguration(); |
|
| 109 | + $config->setAdmin(SecurityConfiguration::ALLOW) |
|
| 110 | + ->setUser(SecurityConfiguration::ALLOW) |
|
| 111 | + ->setCheckuser(SecurityConfiguration::ALLOW) |
|
| 112 | + ->setCommunity(SecurityConfiguration::ALLOW) |
|
| 113 | + ->setSuspended(SecurityConfiguration::ALLOW) |
|
| 114 | + ->setDeclined(SecurityConfiguration::ALLOW) |
|
| 115 | + ->setNew(SecurityConfiguration::ALLOW); |
|
| 116 | + |
|
| 117 | + // Public pages shouldn't be inaccessible to logged-in, unidentified users. |
|
| 118 | + // Otherwise, logged in but unidentified users can't even log out. |
|
| 119 | + $config->setRequireIdentified(false); |
|
| 120 | + |
|
| 121 | + return $config; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Special case for zoom page private data. |
|
| 126 | + * |
|
| 127 | + * This will only return true if you are either a checkuser or a tool admin, taking special note of disabled |
|
| 128 | + * accounts which happen to be check users |
|
| 129 | + * |
|
| 130 | + * @return SecurityConfiguration |
|
| 131 | + */ |
|
| 132 | + public function asGeneralPrivateDataAccess() |
|
| 133 | + { |
|
| 134 | + $config = new SecurityConfiguration(); |
|
| 135 | + $config |
|
| 136 | + // Basic configuration, admins and check users allowed |
|
| 137 | + ->setAdmin(SecurityConfiguration::ALLOW) |
|
| 138 | + ->setCheckuser(SecurityConfiguration::ALLOW) |
|
| 139 | + // Deny these, even if they were allowed by the above |
|
| 140 | + ->setCommunity(SecurityConfiguration::DENY) |
|
| 141 | + ->setSuspended(SecurityConfiguration::DENY) |
|
| 142 | + ->setDeclined(SecurityConfiguration::DENY) |
|
| 143 | + ->setNew(SecurityConfiguration::DENY); |
|
| 144 | + |
|
| 145 | + // You must also be identified to access this data |
|
| 146 | + $config->setRequireIdentified($this->forceIdentified); |
|
| 147 | + |
|
| 148 | + return $config; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @category Security-Critical |
|
| 153 | + * @return SecurityConfiguration |
|
| 154 | + */ |
|
| 155 | + public function asNone() |
|
| 156 | + { |
|
| 157 | + $config = new SecurityConfiguration(); |
|
| 158 | + |
|
| 159 | + return $config; |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | \ No newline at end of file |
@@ -20,43 +20,43 @@ |
||
| 20 | 20 | |
| 21 | 21 | class ApiRequestRouter implements IRequestRouter |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @return string[] |
|
| 25 | - */ |
|
| 26 | - public static function getActionList() |
|
| 27 | - { |
|
| 28 | - return array("count", "status", "stats", "help", "monitor"); |
|
| 29 | - } |
|
| 23 | + /** |
|
| 24 | + * @return string[] |
|
| 25 | + */ |
|
| 26 | + public static function getActionList() |
|
| 27 | + { |
|
| 28 | + return array("count", "status", "stats", "help", "monitor"); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @return IRoutedTask |
|
| 33 | - * @throws Exception |
|
| 34 | - */ |
|
| 35 | - public function route() |
|
| 36 | - { |
|
| 37 | - $requestAction = WebRequest::getString('action'); |
|
| 31 | + /** |
|
| 32 | + * @return IRoutedTask |
|
| 33 | + * @throws Exception |
|
| 34 | + */ |
|
| 35 | + public function route() |
|
| 36 | + { |
|
| 37 | + $requestAction = WebRequest::getString('action'); |
|
| 38 | 38 | |
| 39 | - switch ($requestAction) { |
|
| 40 | - case "count": |
|
| 41 | - $result = new CountAction(); |
|
| 42 | - break; |
|
| 43 | - case "status": |
|
| 44 | - $result = new StatusAction(); |
|
| 45 | - break; |
|
| 46 | - case "stats": |
|
| 47 | - $result = new StatsAction(); |
|
| 48 | - break; |
|
| 49 | - case "help": |
|
| 50 | - $result = new HelpAction(); |
|
| 51 | - break; |
|
| 52 | - case "monitor": |
|
| 53 | - $result = new MonitorAction(); |
|
| 54 | - break; |
|
| 55 | - default: |
|
| 56 | - $result = new UnknownAction(); |
|
| 57 | - break; |
|
| 58 | - } |
|
| 39 | + switch ($requestAction) { |
|
| 40 | + case "count": |
|
| 41 | + $result = new CountAction(); |
|
| 42 | + break; |
|
| 43 | + case "status": |
|
| 44 | + $result = new StatusAction(); |
|
| 45 | + break; |
|
| 46 | + case "stats": |
|
| 47 | + $result = new StatsAction(); |
|
| 48 | + break; |
|
| 49 | + case "help": |
|
| 50 | + $result = new HelpAction(); |
|
| 51 | + break; |
|
| 52 | + case "monitor": |
|
| 53 | + $result = new MonitorAction(); |
|
| 54 | + break; |
|
| 55 | + default: |
|
| 56 | + $result = new UnknownAction(); |
|
| 57 | + break; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return $result; |
|
| 61 | - } |
|
| 60 | + return $result; |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |
@@ -54,391 +54,391 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | class RequestRouter implements IRequestRouter |
| 56 | 56 | { |
| 57 | - /** |
|
| 58 | - * This is the core routing table for the application. The basic idea is: |
|
| 59 | - * |
|
| 60 | - * array( |
|
| 61 | - * "foo" => |
|
| 62 | - * array( |
|
| 63 | - * "class" => PageFoo::class, |
|
| 64 | - * "actions" => array("bar", "other") |
|
| 65 | - * ), |
|
| 66 | - * ); |
|
| 67 | - * |
|
| 68 | - * Things to note: |
|
| 69 | - * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
| 70 | - * |
|
| 71 | - * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
| 72 | - * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
| 73 | - * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
| 74 | - * method. |
|
| 75 | - * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
| 76 | - * |
|
| 77 | - * - Query parameters are ignored. |
|
| 78 | - * |
|
| 79 | - * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
| 80 | - * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
| 81 | - * before we start calling random methods through the web UI. |
|
| 82 | - * |
|
| 83 | - * Examples: |
|
| 84 | - * /internal.php => returns instance of PageMain, routed to main() |
|
| 85 | - * /internal.php?query => returns instance of PageMain, routed to main() |
|
| 86 | - * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
| 87 | - * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
| 88 | - * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
| 89 | - * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
| 90 | - * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
| 91 | - * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
| 92 | - * /internal.php/bar => returns instance of Page404, routed to main() |
|
| 93 | - * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
| 94 | - * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
| 95 | - * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
| 96 | - * |
|
| 97 | - * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
| 98 | - * to change the key, then you'll likely have to update a lot of files. |
|
| 99 | - * |
|
| 100 | - * @var array |
|
| 101 | - */ |
|
| 102 | - private $routeMap = array( |
|
| 103 | - |
|
| 104 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 105 | - // Login and registration |
|
| 106 | - 'logout' => |
|
| 107 | - array( |
|
| 108 | - 'class' => PageLogout::class, |
|
| 109 | - 'actions' => array(), |
|
| 110 | - ), |
|
| 111 | - 'login' => |
|
| 112 | - array( |
|
| 113 | - 'class' => PageLogin::class, |
|
| 114 | - 'actions' => array(), |
|
| 115 | - ), |
|
| 116 | - 'forgotPassword' => |
|
| 117 | - array( |
|
| 118 | - 'class' => PageForgotPassword::class, |
|
| 119 | - 'actions' => array('reset'), |
|
| 120 | - ), |
|
| 121 | - 'register' => |
|
| 122 | - array( |
|
| 123 | - 'class' => PageRegister::class, |
|
| 124 | - 'actions' => array('done'), |
|
| 125 | - ), |
|
| 126 | - |
|
| 127 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 | - // Discovery |
|
| 129 | - 'search' => |
|
| 130 | - array( |
|
| 131 | - 'class' => PageSearch::class, |
|
| 132 | - 'actions' => array(), |
|
| 133 | - ), |
|
| 134 | - 'logs' => |
|
| 135 | - array( |
|
| 136 | - 'class' => PageLog::class, |
|
| 137 | - 'actions' => array(), |
|
| 138 | - ), |
|
| 139 | - |
|
| 140 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 141 | - // Administration |
|
| 142 | - 'bans' => |
|
| 143 | - array( |
|
| 144 | - 'class' => PageBan::class, |
|
| 145 | - 'actions' => array('set', 'remove'), |
|
| 146 | - ), |
|
| 147 | - 'userManagement' => |
|
| 148 | - array( |
|
| 149 | - 'class' => PageUserManagement::class, |
|
| 150 | - 'actions' => array( |
|
| 151 | - 'approve', |
|
| 152 | - 'decline', |
|
| 153 | - 'rename', |
|
| 154 | - 'editUser', |
|
| 155 | - 'suspend', |
|
| 156 | - 'promote', |
|
| 157 | - 'demote', |
|
| 158 | - ), |
|
| 159 | - ), |
|
| 160 | - 'siteNotice' => |
|
| 161 | - array( |
|
| 162 | - 'class' => PageSiteNotice::class, |
|
| 163 | - 'actions' => array(), |
|
| 164 | - ), |
|
| 165 | - 'emailManagement' => |
|
| 166 | - array( |
|
| 167 | - 'class' => PageEmailManagement::class, |
|
| 168 | - 'actions' => array('create', 'edit', 'view'), |
|
| 169 | - ), |
|
| 170 | - |
|
| 171 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 172 | - // Personal preferences |
|
| 173 | - 'preferences' => |
|
| 174 | - array( |
|
| 175 | - 'class' => PagePreferences::class, |
|
| 176 | - 'actions' => array('changePassword'), |
|
| 177 | - ), |
|
| 178 | - 'oauth' => |
|
| 179 | - array( |
|
| 180 | - 'class' => PageOAuth::class, |
|
| 181 | - 'actions' => array('detach', 'attach'), |
|
| 182 | - ), |
|
| 183 | - |
|
| 184 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 185 | - // Welcomer configuration |
|
| 186 | - 'welcomeTemplates' => |
|
| 187 | - array( |
|
| 188 | - 'class' => PageWelcomeTemplateManagement::class, |
|
| 189 | - 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
| 190 | - ), |
|
| 191 | - |
|
| 192 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 193 | - // Statistics |
|
| 194 | - 'statistics' => |
|
| 195 | - array( |
|
| 196 | - 'class' => StatsMain::class, |
|
| 197 | - 'actions' => array(), |
|
| 198 | - ), |
|
| 199 | - 'statistics/fastCloses' => |
|
| 200 | - array( |
|
| 201 | - 'class' => StatsFastCloses::class, |
|
| 202 | - 'actions' => array(), |
|
| 203 | - ), |
|
| 204 | - 'statistics/inactiveUsers' => |
|
| 205 | - array( |
|
| 206 | - 'class' => StatsInactiveUsers::class, |
|
| 207 | - 'actions' => array(), |
|
| 208 | - ), |
|
| 209 | - 'statistics/monthlyStats' => |
|
| 210 | - array( |
|
| 211 | - 'class' => StatsMonthlyStats::class, |
|
| 212 | - 'actions' => array(), |
|
| 213 | - ), |
|
| 214 | - 'statistics/reservedRequests' => |
|
| 215 | - array( |
|
| 216 | - 'class' => StatsReservedRequests::class, |
|
| 217 | - 'actions' => array(), |
|
| 218 | - ), |
|
| 219 | - 'statistics/templateStats' => |
|
| 220 | - array( |
|
| 221 | - 'class' => StatsTemplateStats::class, |
|
| 222 | - 'actions' => array(), |
|
| 223 | - ), |
|
| 224 | - 'statistics/topCreators' => |
|
| 225 | - array( |
|
| 226 | - 'class' => StatsTopCreators::class, |
|
| 227 | - 'actions' => array(), |
|
| 228 | - ), |
|
| 229 | - 'statistics/users' => |
|
| 230 | - array( |
|
| 231 | - 'class' => StatsUsers::class, |
|
| 232 | - 'actions' => array('detail'), |
|
| 233 | - ), |
|
| 234 | - |
|
| 235 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 236 | - // Zoom page |
|
| 237 | - 'viewRequest' => |
|
| 238 | - array( |
|
| 239 | - 'class' => PageViewRequest::class, |
|
| 240 | - 'actions' => array(), |
|
| 241 | - ), |
|
| 242 | - 'viewRequest/reserve' => |
|
| 243 | - array( |
|
| 244 | - 'class' => PageReservation::class, |
|
| 245 | - 'actions' => array(), |
|
| 246 | - ), |
|
| 247 | - 'viewRequest/breakReserve' => |
|
| 248 | - array( |
|
| 249 | - 'class' => PageBreakReservation::class, |
|
| 250 | - 'actions' => array(), |
|
| 251 | - ), |
|
| 252 | - 'viewRequest/defer' => |
|
| 253 | - array( |
|
| 254 | - 'class' => PageDeferRequest::class, |
|
| 255 | - 'actions' => array(), |
|
| 256 | - ), |
|
| 257 | - 'viewRequest/comment' => |
|
| 258 | - array( |
|
| 259 | - 'class' => PageComment::class, |
|
| 260 | - 'actions' => array(), |
|
| 261 | - ), |
|
| 262 | - 'viewRequest/sendToUser' => |
|
| 263 | - array( |
|
| 264 | - 'class' => PageSendToUser::class, |
|
| 265 | - 'actions' => array(), |
|
| 266 | - ), |
|
| 267 | - 'viewRequest/close' => |
|
| 268 | - array( |
|
| 269 | - 'class' => PageCloseRequest::class, |
|
| 270 | - 'actions' => array(), |
|
| 271 | - ), |
|
| 272 | - 'viewRequest/drop' => |
|
| 273 | - array( |
|
| 274 | - 'class' => PageDropRequest::class, |
|
| 275 | - 'actions' => array(), |
|
| 276 | - ), |
|
| 277 | - 'viewRequest/custom' => |
|
| 278 | - array( |
|
| 279 | - 'class' => PageCustomClose::class, |
|
| 280 | - 'actions' => array(), |
|
| 281 | - ), |
|
| 282 | - 'editComment' => |
|
| 283 | - array( |
|
| 284 | - 'class' => PageEditComment::class, |
|
| 285 | - 'actions' => array(), |
|
| 286 | - ), |
|
| 287 | - |
|
| 288 | - ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 289 | - // Misc stuff |
|
| 290 | - 'team' => |
|
| 291 | - array( |
|
| 292 | - 'class' => PageTeam::class, |
|
| 293 | - 'actions' => array(), |
|
| 294 | - ), |
|
| 295 | - 'requestList' => |
|
| 296 | - array( |
|
| 297 | - 'class' => PageExpandedRequestList::class, |
|
| 298 | - 'actions' => array(), |
|
| 299 | - ), |
|
| 300 | - ); |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @return IRoutedTask |
|
| 304 | - * @throws Exception |
|
| 305 | - */ |
|
| 306 | - final public function route() |
|
| 307 | - { |
|
| 308 | - $pathInfo = WebRequest::pathInfo(); |
|
| 309 | - |
|
| 310 | - list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
| 311 | - |
|
| 312 | - /** @var IRoutedTask $page */ |
|
| 313 | - $page = new $pageClass(); |
|
| 314 | - |
|
| 315 | - // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
| 316 | - // let's use our own. |
|
| 317 | - if (!($page instanceof IRoutedTask)) { |
|
| 318 | - throw new Exception('Expected a page, but this is not a page.'); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - // 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 |
|
| 322 | - // inherits PageBase and has been created from the routing map. |
|
| 323 | - $page->setRoute($action); |
|
| 324 | - |
|
| 325 | - return $page; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @param $pathInfo |
|
| 330 | - * |
|
| 331 | - * @return array |
|
| 332 | - */ |
|
| 333 | - protected function getRouteFromPath($pathInfo) |
|
| 334 | - { |
|
| 335 | - if (count($pathInfo) === 0) { |
|
| 336 | - // No pathInfo, so no page to load. Load the main page. |
|
| 337 | - return $this->getDefaultRoute(); |
|
| 338 | - } |
|
| 339 | - elseif (count($pathInfo) === 1) { |
|
| 340 | - // Exactly one path info segment, it's got to be a page. |
|
| 341 | - $classSegment = $pathInfo[0]; |
|
| 342 | - |
|
| 343 | - return $this->routeSinglePathSegment($classSegment); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // OK, we have two or more segments now. |
|
| 347 | - if (count($pathInfo) > 2) { |
|
| 348 | - // Let's handle more than two, and collapse it down into two. |
|
| 349 | - $requestedAction = array_pop($pathInfo); |
|
| 350 | - $classSegment = implode('/', $pathInfo); |
|
| 351 | - } |
|
| 352 | - else { |
|
| 353 | - // Two path info segments. |
|
| 354 | - $classSegment = $pathInfo[0]; |
|
| 355 | - $requestedAction = $pathInfo[1]; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
| 359 | - |
|
| 360 | - if ($routeMap[0] === Page404::class) { |
|
| 361 | - $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - return $routeMap; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @param $classSegment |
|
| 369 | - * |
|
| 370 | - * @return array |
|
| 371 | - */ |
|
| 372 | - final protected function routeSinglePathSegment($classSegment) |
|
| 373 | - { |
|
| 374 | - $routeMap = $this->getRouteMap(); |
|
| 375 | - if (array_key_exists($classSegment, $routeMap)) { |
|
| 376 | - // Route exists, but we don't have an action in path info, so default to main. |
|
| 377 | - $pageClass = $routeMap[$classSegment]['class']; |
|
| 378 | - $action = 'main'; |
|
| 379 | - |
|
| 380 | - return array($pageClass, $action); |
|
| 381 | - } |
|
| 382 | - else { |
|
| 383 | - // Doesn't exist in map. Fall back to 404 |
|
| 384 | - $pageClass = Page404::class; |
|
| 385 | - $action = "main"; |
|
| 386 | - |
|
| 387 | - return array($pageClass, $action); |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @param $classSegment |
|
| 393 | - * @param $requestedAction |
|
| 394 | - * |
|
| 395 | - * @return array |
|
| 396 | - */ |
|
| 397 | - final protected function routePathSegments($classSegment, $requestedAction) |
|
| 398 | - { |
|
| 399 | - $routeMap = $this->getRouteMap(); |
|
| 400 | - if (array_key_exists($classSegment, $routeMap)) { |
|
| 401 | - // Route exists, but we don't have an action in path info, so default to main. |
|
| 402 | - |
|
| 403 | - if (isset($routeMap[$classSegment]['actions']) |
|
| 404 | - && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
| 405 | - ) { |
|
| 406 | - // Action exists in allowed action list. Allow both the page and the action |
|
| 407 | - $pageClass = $routeMap[$classSegment]['class']; |
|
| 408 | - $action = $requestedAction; |
|
| 409 | - |
|
| 410 | - return array($pageClass, $action); |
|
| 411 | - } |
|
| 412 | - else { |
|
| 413 | - // Valid page, invalid action. 404 our way out. |
|
| 414 | - $pageClass = Page404::class; |
|
| 415 | - $action = 'main'; |
|
| 416 | - |
|
| 417 | - return array($pageClass, $action); |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - else { |
|
| 421 | - // Class doesn't exist in map. Fall back to 404 |
|
| 422 | - $pageClass = Page404::class; |
|
| 423 | - $action = 'main'; |
|
| 424 | - |
|
| 425 | - return array($pageClass, $action); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * @return array |
|
| 431 | - */ |
|
| 432 | - protected function getRouteMap() |
|
| 433 | - { |
|
| 434 | - return $this->routeMap; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * @return callable |
|
| 439 | - */ |
|
| 440 | - protected function getDefaultRoute() |
|
| 441 | - { |
|
| 442 | - return array(PageMain::class, "main"); |
|
| 443 | - } |
|
| 57 | + /** |
|
| 58 | + * This is the core routing table for the application. The basic idea is: |
|
| 59 | + * |
|
| 60 | + * array( |
|
| 61 | + * "foo" => |
|
| 62 | + * array( |
|
| 63 | + * "class" => PageFoo::class, |
|
| 64 | + * "actions" => array("bar", "other") |
|
| 65 | + * ), |
|
| 66 | + * ); |
|
| 67 | + * |
|
| 68 | + * Things to note: |
|
| 69 | + * - If no page is requested, we go to PageMain. PageMain can't have actions defined. |
|
| 70 | + * |
|
| 71 | + * - If a page is defined and requested, but no action is requested, go to that page's main() method |
|
| 72 | + * - If a page is defined and requested, and an action is defined and requested, go to that action's method. |
|
| 73 | + * - If a page is defined and requested, and an action NOT defined and requested, go to Page404 and it's main() |
|
| 74 | + * method. |
|
| 75 | + * - If a page is NOT defined and requested, go to Page404 and it's main() method. |
|
| 76 | + * |
|
| 77 | + * - Query parameters are ignored. |
|
| 78 | + * |
|
| 79 | + * The key point here is request routing with validation that this is allowed, before we start hitting the |
|
| 80 | + * filesystem through the AutoLoader, and opening random files. Also, so that we validate the action requested |
|
| 81 | + * before we start calling random methods through the web UI. |
|
| 82 | + * |
|
| 83 | + * Examples: |
|
| 84 | + * /internal.php => returns instance of PageMain, routed to main() |
|
| 85 | + * /internal.php?query => returns instance of PageMain, routed to main() |
|
| 86 | + * /internal.php/foo => returns instance of PageFoo, routed to main() |
|
| 87 | + * /internal.php/foo?query => returns instance of PageFoo, routed to main() |
|
| 88 | + * /internal.php/foo/bar => returns instance of PageFoo, routed to bar() |
|
| 89 | + * /internal.php/foo/bar?query => returns instance of PageFoo, routed to bar() |
|
| 90 | + * /internal.php/foo/baz => returns instance of Page404, routed to main() |
|
| 91 | + * /internal.php/foo/baz?query => returns instance of Page404, routed to main() |
|
| 92 | + * /internal.php/bar => returns instance of Page404, routed to main() |
|
| 93 | + * /internal.php/bar?query => returns instance of Page404, routed to main() |
|
| 94 | + * /internal.php/bar/baz => returns instance of Page404, routed to main() |
|
| 95 | + * /internal.php/bar/baz?query => returns instance of Page404, routed to main() |
|
| 96 | + * |
|
| 97 | + * Take care when changing this - a lot of places rely on the array key for redirects and other links. If you need |
|
| 98 | + * to change the key, then you'll likely have to update a lot of files. |
|
| 99 | + * |
|
| 100 | + * @var array |
|
| 101 | + */ |
|
| 102 | + private $routeMap = array( |
|
| 103 | + |
|
| 104 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 105 | + // Login and registration |
|
| 106 | + 'logout' => |
|
| 107 | + array( |
|
| 108 | + 'class' => PageLogout::class, |
|
| 109 | + 'actions' => array(), |
|
| 110 | + ), |
|
| 111 | + 'login' => |
|
| 112 | + array( |
|
| 113 | + 'class' => PageLogin::class, |
|
| 114 | + 'actions' => array(), |
|
| 115 | + ), |
|
| 116 | + 'forgotPassword' => |
|
| 117 | + array( |
|
| 118 | + 'class' => PageForgotPassword::class, |
|
| 119 | + 'actions' => array('reset'), |
|
| 120 | + ), |
|
| 121 | + 'register' => |
|
| 122 | + array( |
|
| 123 | + 'class' => PageRegister::class, |
|
| 124 | + 'actions' => array('done'), |
|
| 125 | + ), |
|
| 126 | + |
|
| 127 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 | + // Discovery |
|
| 129 | + 'search' => |
|
| 130 | + array( |
|
| 131 | + 'class' => PageSearch::class, |
|
| 132 | + 'actions' => array(), |
|
| 133 | + ), |
|
| 134 | + 'logs' => |
|
| 135 | + array( |
|
| 136 | + 'class' => PageLog::class, |
|
| 137 | + 'actions' => array(), |
|
| 138 | + ), |
|
| 139 | + |
|
| 140 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 141 | + // Administration |
|
| 142 | + 'bans' => |
|
| 143 | + array( |
|
| 144 | + 'class' => PageBan::class, |
|
| 145 | + 'actions' => array('set', 'remove'), |
|
| 146 | + ), |
|
| 147 | + 'userManagement' => |
|
| 148 | + array( |
|
| 149 | + 'class' => PageUserManagement::class, |
|
| 150 | + 'actions' => array( |
|
| 151 | + 'approve', |
|
| 152 | + 'decline', |
|
| 153 | + 'rename', |
|
| 154 | + 'editUser', |
|
| 155 | + 'suspend', |
|
| 156 | + 'promote', |
|
| 157 | + 'demote', |
|
| 158 | + ), |
|
| 159 | + ), |
|
| 160 | + 'siteNotice' => |
|
| 161 | + array( |
|
| 162 | + 'class' => PageSiteNotice::class, |
|
| 163 | + 'actions' => array(), |
|
| 164 | + ), |
|
| 165 | + 'emailManagement' => |
|
| 166 | + array( |
|
| 167 | + 'class' => PageEmailManagement::class, |
|
| 168 | + 'actions' => array('create', 'edit', 'view'), |
|
| 169 | + ), |
|
| 170 | + |
|
| 171 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 172 | + // Personal preferences |
|
| 173 | + 'preferences' => |
|
| 174 | + array( |
|
| 175 | + 'class' => PagePreferences::class, |
|
| 176 | + 'actions' => array('changePassword'), |
|
| 177 | + ), |
|
| 178 | + 'oauth' => |
|
| 179 | + array( |
|
| 180 | + 'class' => PageOAuth::class, |
|
| 181 | + 'actions' => array('detach', 'attach'), |
|
| 182 | + ), |
|
| 183 | + |
|
| 184 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 185 | + // Welcomer configuration |
|
| 186 | + 'welcomeTemplates' => |
|
| 187 | + array( |
|
| 188 | + 'class' => PageWelcomeTemplateManagement::class, |
|
| 189 | + 'actions' => array('select', 'edit', 'delete', 'add', 'view'), |
|
| 190 | + ), |
|
| 191 | + |
|
| 192 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 193 | + // Statistics |
|
| 194 | + 'statistics' => |
|
| 195 | + array( |
|
| 196 | + 'class' => StatsMain::class, |
|
| 197 | + 'actions' => array(), |
|
| 198 | + ), |
|
| 199 | + 'statistics/fastCloses' => |
|
| 200 | + array( |
|
| 201 | + 'class' => StatsFastCloses::class, |
|
| 202 | + 'actions' => array(), |
|
| 203 | + ), |
|
| 204 | + 'statistics/inactiveUsers' => |
|
| 205 | + array( |
|
| 206 | + 'class' => StatsInactiveUsers::class, |
|
| 207 | + 'actions' => array(), |
|
| 208 | + ), |
|
| 209 | + 'statistics/monthlyStats' => |
|
| 210 | + array( |
|
| 211 | + 'class' => StatsMonthlyStats::class, |
|
| 212 | + 'actions' => array(), |
|
| 213 | + ), |
|
| 214 | + 'statistics/reservedRequests' => |
|
| 215 | + array( |
|
| 216 | + 'class' => StatsReservedRequests::class, |
|
| 217 | + 'actions' => array(), |
|
| 218 | + ), |
|
| 219 | + 'statistics/templateStats' => |
|
| 220 | + array( |
|
| 221 | + 'class' => StatsTemplateStats::class, |
|
| 222 | + 'actions' => array(), |
|
| 223 | + ), |
|
| 224 | + 'statistics/topCreators' => |
|
| 225 | + array( |
|
| 226 | + 'class' => StatsTopCreators::class, |
|
| 227 | + 'actions' => array(), |
|
| 228 | + ), |
|
| 229 | + 'statistics/users' => |
|
| 230 | + array( |
|
| 231 | + 'class' => StatsUsers::class, |
|
| 232 | + 'actions' => array('detail'), |
|
| 233 | + ), |
|
| 234 | + |
|
| 235 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 236 | + // Zoom page |
|
| 237 | + 'viewRequest' => |
|
| 238 | + array( |
|
| 239 | + 'class' => PageViewRequest::class, |
|
| 240 | + 'actions' => array(), |
|
| 241 | + ), |
|
| 242 | + 'viewRequest/reserve' => |
|
| 243 | + array( |
|
| 244 | + 'class' => PageReservation::class, |
|
| 245 | + 'actions' => array(), |
|
| 246 | + ), |
|
| 247 | + 'viewRequest/breakReserve' => |
|
| 248 | + array( |
|
| 249 | + 'class' => PageBreakReservation::class, |
|
| 250 | + 'actions' => array(), |
|
| 251 | + ), |
|
| 252 | + 'viewRequest/defer' => |
|
| 253 | + array( |
|
| 254 | + 'class' => PageDeferRequest::class, |
|
| 255 | + 'actions' => array(), |
|
| 256 | + ), |
|
| 257 | + 'viewRequest/comment' => |
|
| 258 | + array( |
|
| 259 | + 'class' => PageComment::class, |
|
| 260 | + 'actions' => array(), |
|
| 261 | + ), |
|
| 262 | + 'viewRequest/sendToUser' => |
|
| 263 | + array( |
|
| 264 | + 'class' => PageSendToUser::class, |
|
| 265 | + 'actions' => array(), |
|
| 266 | + ), |
|
| 267 | + 'viewRequest/close' => |
|
| 268 | + array( |
|
| 269 | + 'class' => PageCloseRequest::class, |
|
| 270 | + 'actions' => array(), |
|
| 271 | + ), |
|
| 272 | + 'viewRequest/drop' => |
|
| 273 | + array( |
|
| 274 | + 'class' => PageDropRequest::class, |
|
| 275 | + 'actions' => array(), |
|
| 276 | + ), |
|
| 277 | + 'viewRequest/custom' => |
|
| 278 | + array( |
|
| 279 | + 'class' => PageCustomClose::class, |
|
| 280 | + 'actions' => array(), |
|
| 281 | + ), |
|
| 282 | + 'editComment' => |
|
| 283 | + array( |
|
| 284 | + 'class' => PageEditComment::class, |
|
| 285 | + 'actions' => array(), |
|
| 286 | + ), |
|
| 287 | + |
|
| 288 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 289 | + // Misc stuff |
|
| 290 | + 'team' => |
|
| 291 | + array( |
|
| 292 | + 'class' => PageTeam::class, |
|
| 293 | + 'actions' => array(), |
|
| 294 | + ), |
|
| 295 | + 'requestList' => |
|
| 296 | + array( |
|
| 297 | + 'class' => PageExpandedRequestList::class, |
|
| 298 | + 'actions' => array(), |
|
| 299 | + ), |
|
| 300 | + ); |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @return IRoutedTask |
|
| 304 | + * @throws Exception |
|
| 305 | + */ |
|
| 306 | + final public function route() |
|
| 307 | + { |
|
| 308 | + $pathInfo = WebRequest::pathInfo(); |
|
| 309 | + |
|
| 310 | + list($pageClass, $action) = $this->getRouteFromPath($pathInfo); |
|
| 311 | + |
|
| 312 | + /** @var IRoutedTask $page */ |
|
| 313 | + $page = new $pageClass(); |
|
| 314 | + |
|
| 315 | + // Dynamic creation, so we've got to be careful here. We can't use built-in language type protection, so |
|
| 316 | + // let's use our own. |
|
| 317 | + if (!($page instanceof IRoutedTask)) { |
|
| 318 | + throw new Exception('Expected a page, but this is not a page.'); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + // 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 |
|
| 322 | + // inherits PageBase and has been created from the routing map. |
|
| 323 | + $page->setRoute($action); |
|
| 324 | + |
|
| 325 | + return $page; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @param $pathInfo |
|
| 330 | + * |
|
| 331 | + * @return array |
|
| 332 | + */ |
|
| 333 | + protected function getRouteFromPath($pathInfo) |
|
| 334 | + { |
|
| 335 | + if (count($pathInfo) === 0) { |
|
| 336 | + // No pathInfo, so no page to load. Load the main page. |
|
| 337 | + return $this->getDefaultRoute(); |
|
| 338 | + } |
|
| 339 | + elseif (count($pathInfo) === 1) { |
|
| 340 | + // Exactly one path info segment, it's got to be a page. |
|
| 341 | + $classSegment = $pathInfo[0]; |
|
| 342 | + |
|
| 343 | + return $this->routeSinglePathSegment($classSegment); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // OK, we have two or more segments now. |
|
| 347 | + if (count($pathInfo) > 2) { |
|
| 348 | + // Let's handle more than two, and collapse it down into two. |
|
| 349 | + $requestedAction = array_pop($pathInfo); |
|
| 350 | + $classSegment = implode('/', $pathInfo); |
|
| 351 | + } |
|
| 352 | + else { |
|
| 353 | + // Two path info segments. |
|
| 354 | + $classSegment = $pathInfo[0]; |
|
| 355 | + $requestedAction = $pathInfo[1]; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $routeMap = $this->routePathSegments($classSegment, $requestedAction); |
|
| 359 | + |
|
| 360 | + if ($routeMap[0] === Page404::class) { |
|
| 361 | + $routeMap = $this->routeSinglePathSegment($classSegment . '/' . $requestedAction); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + return $routeMap; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @param $classSegment |
|
| 369 | + * |
|
| 370 | + * @return array |
|
| 371 | + */ |
|
| 372 | + final protected function routeSinglePathSegment($classSegment) |
|
| 373 | + { |
|
| 374 | + $routeMap = $this->getRouteMap(); |
|
| 375 | + if (array_key_exists($classSegment, $routeMap)) { |
|
| 376 | + // Route exists, but we don't have an action in path info, so default to main. |
|
| 377 | + $pageClass = $routeMap[$classSegment]['class']; |
|
| 378 | + $action = 'main'; |
|
| 379 | + |
|
| 380 | + return array($pageClass, $action); |
|
| 381 | + } |
|
| 382 | + else { |
|
| 383 | + // Doesn't exist in map. Fall back to 404 |
|
| 384 | + $pageClass = Page404::class; |
|
| 385 | + $action = "main"; |
|
| 386 | + |
|
| 387 | + return array($pageClass, $action); |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @param $classSegment |
|
| 393 | + * @param $requestedAction |
|
| 394 | + * |
|
| 395 | + * @return array |
|
| 396 | + */ |
|
| 397 | + final protected function routePathSegments($classSegment, $requestedAction) |
|
| 398 | + { |
|
| 399 | + $routeMap = $this->getRouteMap(); |
|
| 400 | + if (array_key_exists($classSegment, $routeMap)) { |
|
| 401 | + // Route exists, but we don't have an action in path info, so default to main. |
|
| 402 | + |
|
| 403 | + if (isset($routeMap[$classSegment]['actions']) |
|
| 404 | + && array_search($requestedAction, $routeMap[$classSegment]['actions']) !== false |
|
| 405 | + ) { |
|
| 406 | + // Action exists in allowed action list. Allow both the page and the action |
|
| 407 | + $pageClass = $routeMap[$classSegment]['class']; |
|
| 408 | + $action = $requestedAction; |
|
| 409 | + |
|
| 410 | + return array($pageClass, $action); |
|
| 411 | + } |
|
| 412 | + else { |
|
| 413 | + // Valid page, invalid action. 404 our way out. |
|
| 414 | + $pageClass = Page404::class; |
|
| 415 | + $action = 'main'; |
|
| 416 | + |
|
| 417 | + return array($pageClass, $action); |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + else { |
|
| 421 | + // Class doesn't exist in map. Fall back to 404 |
|
| 422 | + $pageClass = Page404::class; |
|
| 423 | + $action = 'main'; |
|
| 424 | + |
|
| 425 | + return array($pageClass, $action); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * @return array |
|
| 431 | + */ |
|
| 432 | + protected function getRouteMap() |
|
| 433 | + { |
|
| 434 | + return $this->routeMap; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * @return callable |
|
| 439 | + */ |
|
| 440 | + protected function getDefaultRoute() |
|
| 441 | + { |
|
| 442 | + return array(PageMain::class, "main"); |
|
| 443 | + } |
|
| 444 | 444 | } |
| 445 | 445 | \ 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 |
@@ -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 |
@@ -13,36 +13,36 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class AutoLoader |
| 15 | 15 | { |
| 16 | - public static function load($class) |
|
| 17 | - { |
|
| 18 | - // handle namespaces sensibly |
|
| 19 | - if (strpos($class, "Waca") !== false) { |
|
| 20 | - // strip off the initial namespace |
|
| 21 | - $class = str_replace("Waca\\", "", $class); |
|
| 16 | + public static function load($class) |
|
| 17 | + { |
|
| 18 | + // handle namespaces sensibly |
|
| 19 | + if (strpos($class, "Waca") !== false) { |
|
| 20 | + // strip off the initial namespace |
|
| 21 | + $class = str_replace("Waca\\", "", $class); |
|
| 22 | 22 | |
| 23 | - // swap backslashes for forward slashes to map to directory names |
|
| 24 | - $class = str_replace("\\", "/", $class); |
|
| 25 | - } |
|
| 23 | + // swap backslashes for forward slashes to map to directory names |
|
| 24 | + $class = str_replace("\\", "/", $class); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - $paths = array( |
|
| 28 | - __DIR__ . '/' . $class . ".php", |
|
| 29 | - __DIR__ . '/DataObjects/' . $class . ".php", |
|
| 30 | - __DIR__ . '/Providers/' . $class . ".php", |
|
| 31 | - __DIR__ . '/Providers/Interfaces/' . $class . ".php", |
|
| 32 | - __DIR__ . '/Validation/' . $class . ".php", |
|
| 33 | - __DIR__ . '/Helpers/' . $class . ".php", |
|
| 34 | - __DIR__ . '/Helpers/Interfaces/' . $class . ".php", |
|
| 35 | - __DIR__ . '/' . $class . ".php", |
|
| 36 | - ); |
|
| 27 | + $paths = array( |
|
| 28 | + __DIR__ . '/' . $class . ".php", |
|
| 29 | + __DIR__ . '/DataObjects/' . $class . ".php", |
|
| 30 | + __DIR__ . '/Providers/' . $class . ".php", |
|
| 31 | + __DIR__ . '/Providers/Interfaces/' . $class . ".php", |
|
| 32 | + __DIR__ . '/Validation/' . $class . ".php", |
|
| 33 | + __DIR__ . '/Helpers/' . $class . ".php", |
|
| 34 | + __DIR__ . '/Helpers/Interfaces/' . $class . ".php", |
|
| 35 | + __DIR__ . '/' . $class . ".php", |
|
| 36 | + ); |
|
| 37 | 37 | |
| 38 | - foreach ($paths as $file) { |
|
| 39 | - if (file_exists($file)) { |
|
| 40 | - require_once($file); |
|
| 41 | - } |
|
| 38 | + foreach ($paths as $file) { |
|
| 39 | + if (file_exists($file)) { |
|
| 40 | + require_once($file); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if (class_exists($class)) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 43 | + if (class_exists($class)) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -10,77 +10,77 @@ |
||
| 10 | 10 | |
| 11 | 11 | class StringFunctions |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Formats a string to be used as a username. |
|
| 15 | - * |
|
| 16 | - * @param $username |
|
| 17 | - * |
|
| 18 | - * @return string |
|
| 19 | - */ |
|
| 20 | - public function formatAsUsername($username) |
|
| 21 | - { |
|
| 22 | - // trim whitespace from the ends |
|
| 23 | - $uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username); |
|
| 13 | + /** |
|
| 14 | + * Formats a string to be used as a username. |
|
| 15 | + * |
|
| 16 | + * @param $username |
|
| 17 | + * |
|
| 18 | + * @return string |
|
| 19 | + */ |
|
| 20 | + public function formatAsUsername($username) |
|
| 21 | + { |
|
| 22 | + // trim whitespace from the ends |
|
| 23 | + $uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username); |
|
| 24 | 24 | |
| 25 | - // convert first char to uppercase |
|
| 26 | - $uname = $this->ucfirst($uname); |
|
| 25 | + // convert first char to uppercase |
|
| 26 | + $uname = $this->ucfirst($uname); |
|
| 27 | 27 | |
| 28 | - // replace spaces with underscores |
|
| 29 | - $uname = mb_ereg_replace("[ ]+", "_", $uname); |
|
| 28 | + // replace spaces with underscores |
|
| 29 | + $uname = mb_ereg_replace("[ ]+", "_", $uname); |
|
| 30 | 30 | |
| 31 | - // trim underscores from the end |
|
| 32 | - $uname = mb_ereg_replace("[_]+$", "", $uname); |
|
| 31 | + // trim underscores from the end |
|
| 32 | + $uname = mb_ereg_replace("[_]+$", "", $uname); |
|
| 33 | 33 | |
| 34 | - return $uname; |
|
| 35 | - } |
|
| 34 | + return $uname; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Formats a string to be used as an email (specifically strips whitespace |
|
| 39 | - * from the beginning/end of the Email, as well as immediately before/after |
|
| 40 | - * the @ in the Email). |
|
| 41 | - * |
|
| 42 | - * @param $email |
|
| 43 | - * |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public static function formatAsEmail($email) |
|
| 47 | - { |
|
| 48 | - // trim whitespace from the ends |
|
| 49 | - $newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email); |
|
| 37 | + /** |
|
| 38 | + * Formats a string to be used as an email (specifically strips whitespace |
|
| 39 | + * from the beginning/end of the Email, as well as immediately before/after |
|
| 40 | + * the @ in the Email). |
|
| 41 | + * |
|
| 42 | + * @param $email |
|
| 43 | + * |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public static function formatAsEmail($email) |
|
| 47 | + { |
|
| 48 | + // trim whitespace from the ends |
|
| 49 | + $newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email); |
|
| 50 | 50 | |
| 51 | - // trim whitespace from around the email address |
|
| 52 | - $newemail = mb_ereg_replace("[ \t]+@", "@", $newemail); |
|
| 53 | - $newemail = mb_ereg_replace("@[ \t]+", "@", $newemail); |
|
| 51 | + // trim whitespace from around the email address |
|
| 52 | + $newemail = mb_ereg_replace("[ \t]+@", "@", $newemail); |
|
| 53 | + $newemail = mb_ereg_replace("@[ \t]+", "@", $newemail); |
|
| 54 | 54 | |
| 55 | - return $newemail; |
|
| 56 | - } |
|
| 55 | + return $newemail; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Returns true if a string is a multibyte string |
|
| 60 | - * |
|
| 61 | - * @param string $string |
|
| 62 | - * |
|
| 63 | - * @return bool |
|
| 64 | - */ |
|
| 65 | - public function isMultibyte($string) |
|
| 66 | - { |
|
| 67 | - return strlen($string) !== mb_strlen($string); |
|
| 68 | - } |
|
| 58 | + /** |
|
| 59 | + * Returns true if a string is a multibyte string |
|
| 60 | + * |
|
| 61 | + * @param string $string |
|
| 62 | + * |
|
| 63 | + * @return bool |
|
| 64 | + */ |
|
| 65 | + public function isMultibyte($string) |
|
| 66 | + { |
|
| 67 | + return strlen($string) !== mb_strlen($string); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Make a string's first character uppercase |
|
| 72 | - * |
|
| 73 | - * @param string $string |
|
| 74 | - * |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function ucfirst($string) |
|
| 78 | - { |
|
| 79 | - if (ord($string) < 128) { |
|
| 80 | - return ucfirst($string); |
|
| 81 | - } |
|
| 82 | - else { |
|
| 83 | - return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
| 84 | - } |
|
| 85 | - } |
|
| 70 | + /** |
|
| 71 | + * Make a string's first character uppercase |
|
| 72 | + * |
|
| 73 | + * @param string $string |
|
| 74 | + * |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function ucfirst($string) |
|
| 78 | + { |
|
| 79 | + if (ord($string) < 128) { |
|
| 80 | + return ucfirst($string); |
|
| 81 | + } |
|
| 82 | + else { |
|
| 83 | + return mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | } |