diff --git a/src/Changelog/ChangelogRoutes.php b/src/Changelog/ChangelogRoutes.php index 47f8578..aa29dc9 100644 --- a/src/Changelog/ChangelogRoutes.php +++ b/src/Changelog/ChangelogRoutes.php @@ -40,10 +40,10 @@ final class ChangelogRoutes { $this->authInfo = $authInfo; $this->comments = $comments; - $router->get('/changelog', [$this, 'getIndex']); - $router->get('/changelog.rss', [$this, 'getFeedRSS']); - $router->get('/changelog.atom', [$this, 'getFeedAtom']); - $router->get('/changelog/change/:id', [$this, 'getChange']); + $router->get('/changelog', $this->getIndex(...)); + $router->get('/changelog.rss', $this->getFeedRSS(...)); + $router->get('/changelog.atom', $this->getFeedAtom(...)); + $router->get('/changelog/change/:id', $this->getChange(...)); $router->get('/changelog.php', function($response, $request) { $changeId = $request->getParam('c', FILTER_SANITIZE_NUMBER_INT); diff --git a/src/DateCheck.php b/src/DateCheck.php deleted file mode 100644 index ff59eae..0000000 --- a/src/DateCheck.php +++ /dev/null @@ -1,27 +0,0 @@ - 12) - return false; - if($day < 1 || $day > 31) - return false; - - if($month === 2) - $days = $year === 0 || self::isLeapYear($year) ? 29 : 28; - elseif($month === 4 || $month === 6 || $month === 9 || $month === 11) - $days = 30; - else - $days = 31; - - return $day <= $days; - } -} diff --git a/src/Home/HomeRoutes.php b/src/Home/HomeRoutes.php index 1ac023d..16b9fd6 100644 --- a/src/Home/HomeRoutes.php +++ b/src/Home/HomeRoutes.php @@ -46,10 +46,10 @@ class HomeRoutes { $this->news = $news; $this->users = $users; - $router->get('/', [$this, 'getIndex']); + $router->get('/', $this->getIndex(...)); if(MSZ_DEBUG) - $router->get('/dev-landing', [$this, 'getLanding']); + $router->get('/dev-landing', $this->getLanding(...)); $router->get('/index.php', function($response) { $response->redirect(url('index'), true); diff --git a/src/Info/InfoRoutes.php b/src/Info/InfoRoutes.php index 5cb5afd..f4b06b8 100644 --- a/src/Info/InfoRoutes.php +++ b/src/Info/InfoRoutes.php @@ -17,9 +17,9 @@ class InfoRoutes { ]; public function __construct(IRouter $router) { - $router->get('/info', [$this, 'getIndex']); - $router->get('/info/:name', [$this, 'getDocsPage']); - $router->get('/info/:project/:name', [$this, 'getProjectPage']); + $router->get('/info', $this->getIndex(...)); + $router->get('/info/:name', $this->getDocsPage(...)); + $router->get('/info/:project/:name', $this->getProjectPage(...)); $router->get('/info.php', function($response) { $response->redirect(url('info'), true); diff --git a/src/News/NewsRoutes.php b/src/News/NewsRoutes.php index e055890..07dcb56 100644 --- a/src/News/NewsRoutes.php +++ b/src/News/NewsRoutes.php @@ -43,11 +43,11 @@ class NewsRoutes { $this->users = $users; $this->comments = $comments; - $router->get('/news', [$this, 'getIndex']); - $router->get('/news.rss', [$this, 'getFeedRss']); - $router->get('/news.atom', [$this, 'getFeedAtom']); - $router->get('/news/:category', [$this, 'getCategory']); - $router->get('/news/post/:id', [$this, 'getPost']); + $router->get('/news', $this->getIndex(...)); + $router->get('/news.rss', $this->getFeedRss(...)); + $router->get('/news.atom', $this->getFeedAtom(...)); + $router->get('/news/:category', $this->getCategory(...)); + $router->get('/news/post/:id', $this->getPost(...)); $router->get('/news.php', function($response, $request) { $postId = $request->getParam('n', FILTER_SANITIZE_NUMBER_INT) diff --git a/src/Satori/SatoriRoutes.php b/src/Satori/SatoriRoutes.php index eefaff8..58b9d8e 100644 --- a/src/Satori/SatoriRoutes.php +++ b/src/Satori/SatoriRoutes.php @@ -49,10 +49,10 @@ final class SatoriRoutes { }); }); - $router->use('/_satori', [$this, 'verifyRequest']); - $router->get('/_satori/get-profile-field', [$this, 'getProfileField']); - $router->get('/_satori/get-recent-forum-posts', [$this, 'getRecentForumPosts']); - $router->get('/_satori/get-recent-registrations', [$this, 'getRecentRegistrations']); + $router->use('/_satori', $this->verifyRequest(...)); + $router->get('/_satori/get-profile-field', $this->getProfileField(...)); + $router->get('/_satori/get-recent-forum-posts', $this->getRecentForumPosts(...)); + $router->get('/_satori/get-recent-registrations', $this->getRecentRegistrations(...)); } public function verifyRequest($response, $request) { diff --git a/src/SharpChat/SharpChatRoutes.php b/src/SharpChat/SharpChatRoutes.php index 08595d3..8b640bb 100644 --- a/src/SharpChat/SharpChatRoutes.php +++ b/src/SharpChat/SharpChatRoutes.php @@ -67,18 +67,18 @@ final class SharpChatRoutes { }); // Public endpoints - $router->get('/_sockchat/emotes', [$this, 'getEmotes']); - $router->get('/_sockchat/login', [$this, 'getLogin']); - $router->options('/_sockchat/token', [$this, 'getToken']); - $router->get('/_sockchat/token', [$this, 'getToken']); + $router->get('/_sockchat/emotes', $this->getEmotes(...)); + $router->get('/_sockchat/login', $this->getLogin(...)); + $router->options('/_sockchat/token', $this->getToken(...)); + $router->get('/_sockchat/token', $this->getToken(...)); // Private endpoints - $router->post('/_sockchat/bump', [$this, 'postBump']); - $router->post('/_sockchat/verify', [$this, 'postVerify']); - $router->get('/_sockchat/bans/list', [$this, 'getBanList']); - $router->get('/_sockchat/bans/check', [$this, 'getBanCheck']); - $router->post('/_sockchat/bans/create', [$this, 'postBanCreate']); - $router->delete('/_sockchat/bans/revoke', [$this, 'deleteBanRevoke']); + $router->post('/_sockchat/bump', $this->postBump(...)); + $router->post('/_sockchat/verify', $this->postVerify(...)); + $router->get('/_sockchat/bans/list', $this->getBanList(...)); + $router->get('/_sockchat/bans/check', $this->getBanCheck(...)); + $router->post('/_sockchat/bans/create', $this->postBanCreate(...)); + $router->delete('/_sockchat/bans/revoke', $this->deleteBanRevoke(...)); } public function getEmotes($response, $request): array { diff --git a/src/Tools.php b/src/Tools.php new file mode 100644 index 0000000..17e40f4 --- /dev/null +++ b/src/Tools.php @@ -0,0 +1,313 @@ + 12) + return false; + if($day < 1 || $day > 31) + return false; + + if($month === 2) + $days = $year === 0 || self::isLeapYear($year) ? 29 : 28; + elseif($month === 4 || $month === 6 || $month === 9 || $month === 11) + $days = 30; + else + $days = 31; + + return $day <= $days; + } + + // for your own sanity and the sanity of others, keep this one at the bottom + public static function countryName(string $code): string { + return match(strtoupper($code)) { + 'AD' => 'Andorra', + 'AE' => 'United Arab Emirates', + 'AF' => 'Afghanistan', + 'AG' => 'Antigua and Barbuda', + 'AI' => 'Anguilla', + 'AL' => 'Albania', + 'AM' => 'Armenia', + 'AO' => 'Angola', + 'AQ' => 'Antarctica', + 'AR' => 'Argentina', + 'AS' => 'American Samoa', + 'AT' => 'Austria', + 'AU' => 'Australia', + 'AW' => 'Aruba', + 'AX' => 'Åland', + 'AZ' => 'Azerbaijan', + + 'BA' => 'Bosnia and Herzegovina', + 'BB' => 'Barbados', + 'BD' => 'Bangladesh', + 'BE' => 'Belgium', + 'BF' => 'Burkina Faso', + 'BG' => 'Bulgaria', + 'BH' => 'Bahrain', + 'BI' => 'Burundi', + 'BJ' => 'Benin', + 'BL' => 'Saint Barthélemy', + 'BM' => 'Bermuda', + 'BN' => 'Brunei', + 'BO' => 'Bolivia', + 'BQ' => 'Bonaire, Sint Eustatius and Saba', + 'BR' => 'Brazil', + 'BS' => 'Bahamas', + 'BT' => 'Bhutan', + 'BV' => 'Bouvet Island', + 'BW' => 'Botswana', + 'BY' => 'Belarus', + 'BZ' => 'Belize', + + 'CA' => 'Canada', + 'CC' => 'Cocos (Keeling) Islands', + 'CD' => 'Democratic Republic of Congo', + 'CF' => 'Central African Republic', + 'CG' => 'Congo Republic', + 'CH' => 'Switzerland', + 'CI' => 'Ivory Coast', + 'CK' => 'Cook Islands', + 'CL' => 'Chile', + 'CM' => 'Cameroon', + 'CN' => 'China', + 'CO' => 'Colombia', + 'CR' => 'Costa Rica', + 'CU' => 'Cuba', + 'CV' => 'Cabo Verde', + 'CW' => 'Curaçao', + 'CX' => 'Christmas Island', + 'CY' => 'Cyprus', + 'CZ' => 'Czechia', + + 'DE' => 'Germany', + 'DJ' => 'Djibouti', + 'DK' => 'Denmark', + 'DM' => 'Dominica', + 'DO' => 'Dominican Republic', + 'DZ' => 'Algeria', + + 'EC' => 'Ecuador', + 'EE' => 'Estonia', + 'EG' => 'Egypt', + 'EH' => 'Western Sahara', + 'ER' => 'Eritrea', + 'ES' => 'Spain', + 'ET' => 'Ethiopia', + + 'FI' => 'Finland', + 'FJ' => 'Fiji', + 'FK' => 'Falkland Islands', + 'FM' => 'Micronesia', + 'FO' => 'Faroe Islands', + 'FR' => 'France', + + 'GA' => 'Gabon', + 'GB' => 'United Kingdom', + 'GD' => 'Grenada', + 'GE' => 'Georgia', + 'GF' => 'French Guiana', + 'GG' => 'Guernsey', + 'GH' => 'Ghana', + 'GI' => 'Gibraltar', + 'GL' => 'Greenland', + 'GM' => 'The Gambia', + 'GN' => 'Guinea', + 'GP' => 'Guadeloupe', + 'GQ' => 'Equatorial Guinea', + 'GR' => 'Greece', + 'GS' => 'South Georgia and South Sandwich Islands', + 'GT' => 'Guatemala', + 'GU' => 'Guam', + 'GW' => 'Guinea-Bissau', + 'GY' => 'Guyana', + + 'HK' => 'Hong Kong', + 'HM' => 'Heard and McDonald Islands', + 'HN' => 'Honduras', + 'HR' => 'Croatia', + 'HT' => 'Haiti', + 'HU' => 'Hungary', + + 'ID' => 'Indonesia', + 'IE' => 'Ireland', + 'IL' => 'Israel', + 'IM' => 'Isle of Man', + 'IN' => 'India', + 'IO' => 'British Indian Ocean Territory', + 'IQ' => 'Iraq', + 'IR' => 'Iran', + 'IS' => 'Iceland', + 'IT' => 'Italy', + + 'JE' => 'Jersey', + 'JM' => 'Jamaica', + 'JO' => 'Jordan', + 'JP' => 'Japan', + + 'KE' => 'Kenya', + 'KG' => 'Kyrgyzstan', + 'KH' => 'Cambodia', + 'KI' => 'Kiribati', + 'KM' => 'Comoros', + 'KN' => 'St Kitts and Nevis', + 'KP' => 'North Korea', + 'KR' => 'South Korea', + 'KW' => 'Kuwait', + 'KY' => 'Cayman Islands', + 'KZ' => 'Kazakhstan', + + 'LA' => 'Laos', + 'LB' => 'Lebanon', + 'LC' => 'Saint Lucia', + 'LI' => 'Liechtenstein', + 'LK' => 'Sri Lanka', + 'LR' => 'Liberia', + 'LS' => 'Lesotho', + 'LT' => 'Lithuania', + 'LU' => 'Luxembourg', + 'LV' => 'Latvia', + 'LY' => 'Libya', + + 'MA' => 'Morocco', + 'MC' => 'Monaco', + 'MD' => 'Moldova', + 'ME' => 'Montenegro', + 'MF' => 'Saint Martin', + 'MG' => 'Madagascar', + 'MH' => 'Marshall Islands', + 'MK' => 'North Macedonia', + 'ML' => 'Mali', + 'MM' => 'Myanmar', + 'MN' => 'Mongolia', + 'MO' => 'Macao', + 'MP' => 'Northern Mariana Islands', + 'MQ' => 'Martinique', + 'MR' => 'Mauritania', + 'MS' => 'Montserrat', + 'MT' => 'Malta', + 'MU' => 'Mauritius', + 'MV' => 'Maldives', + 'MW' => 'Malawi', + 'MX' => 'Mexico', + 'MY' => 'Malaysia', + 'MZ' => 'Mozambique', + + 'NA' => 'Namibia', + 'NC' => 'New Caledonia', + 'NE' => 'Niger', + 'NF' => 'Norfolk Island', + 'NG' => 'Nigeria', + 'NI' => 'Nicaragua', + 'NL' => 'Netherlands', + 'NO' => 'Norway', + 'NP' => 'Nepal', + 'NR' => 'Nauru', + 'NU' => 'Niue', + 'NZ' => 'New Zealand', + + 'OM' => 'Oman', + + 'PA' => 'Panama', + 'PE' => 'Peru', + 'PF' => 'French Polynesia', + 'PG' => 'Papua New Guinea', + 'PH' => 'Philippines', + 'PK' => 'Pakistan', + 'PL' => 'Poland', + 'PM' => 'Saint Pierre and Miquelon', + 'PN' => 'Pitcairn Islands', + 'PR' => 'Puerto Rico', + 'PS' => 'Palestine', + 'PT' => 'Portugal', + 'PW' => 'Palau', + 'PY' => 'Paraguay', + + 'QA' => 'Qatar', + + 'RE' => 'Réunion', + 'RO' => 'Romania', + 'RS' => 'Serbia', + 'RU' => 'Russia', + 'RW' => 'Rwanda', + + 'SA' => 'Saudi Arabia', + 'SB' => 'Solomon Islands', + 'SC' => 'Seychelles', + 'SD' => 'Sudan', + 'SE' => 'Sweden', + 'SG' => 'Singapore', + 'SH' => 'Saint Helena', + 'SI' => 'Slovenia', + 'SJ' => 'Svalbard and Jan Mayen', + 'SK' => 'Slovakia', + 'SL' => 'Sierra Leone', + 'SM' => 'San Marino', + 'SN' => 'Senegal', + 'SO' => 'Somalia', + 'SR' => 'Suriname', + 'SS' => 'South Sudan', + 'ST' => 'São Tomé and Príncipe', + 'SV' => 'El Salvador', + 'SX' => 'Sint Maarten', + 'SY' => 'Syria', + 'SZ' => 'Eswatini', + + 'TC' => 'Turks and Caicos Islands', + 'TD' => 'Chad', + 'TF' => 'French Southern Territories', + 'TG' => 'Togo', + 'TH' => 'Thailand', + 'TJ' => 'Tajikistan', + 'TK' => 'Tokelau', + 'TL' => 'Timor-Leste', + 'TM' => 'Turkmenistan', + 'TN' => 'Tunisia', + 'TO' => 'Tonga', + 'TR' => 'Turkey', + 'TT' => 'Trinidad and Tobago', + 'TV' => 'Tuvalu', + 'TW' => 'Taiwan', + 'TZ' => 'Tanzania', + + 'UA' => 'Ukraine', + 'UG' => 'Uganda', + 'UM' => 'U.S. Outlying Islands', + 'US' => 'United States', + 'UY' => 'Uruguay', + 'UZ' => 'Uzbekistan', + + 'VA' => 'Vatican City', + 'VC' => 'St Vincent and Grenadines', + 'VE' => 'Venezuela', + 'VG' => 'British Virgin Islands', + 'VI' => 'U.S. Virgin Islands', + 'VN' => 'Vietnam', + 'VU' => 'Vanuatu', + + 'WF' => 'Wallis and Futuna', + 'WS' => 'Samoa', + + 'XK' => 'Kosovo', + 'XM' => 'The Moon', + 'XS' => 'System', + 'XX' => 'Unknown', + + 'YE' => 'Yemen', + 'YT' => 'Mayotte', + + 'ZA' => 'South Africa', + 'ZM' => 'Zambia', + 'ZW' => 'Zimbabwe', + + default => 'Unknown', + }; + } +} diff --git a/src/TwigMisuzu.php b/src/TwigMisuzu.php index aa1e5f9..0c26829 100644 --- a/src/TwigMisuzu.php +++ b/src/TwigMisuzu.php @@ -5,6 +5,7 @@ use Index\ByteFormat; use Index\DateTime; use Index\Environment; use Misuzu\MisuzuContext; +use Misuzu\Tools; use Misuzu\Parsers\Parser; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; @@ -20,10 +21,9 @@ final class TwigMisuzu extends AbstractExtension { public function getFilters() { return [ - new TwigFilter('html_colour', 'html_colour'), - new TwigFilter('country_name', 'get_country_name'), + new TwigFilter('country_name', Tools::countryName(...)), new TwigFilter('parse_text', fn(string $text, int $parser): string => Parser::instance($parser)->parseText($text)), - new TwigFilter('time_format', [$this, 'timeFormat']), + new TwigFilter('time_format', $this->timeFormat(...)), ]; } @@ -31,14 +31,14 @@ final class TwigMisuzu extends AbstractExtension { return [ new TwigFunction('url_construct', 'url_construct'), new TwigFunction('url', 'url'), - new TwigFunction('csrf_token', fn() => CSRF::token()), - new TwigFunction('git_commit_hash', fn(bool $long = false) => GitInfo::hash($long)), - new TwigFunction('git_tag', fn() => GitInfo::tag()), - new TwigFunction('git_branch', fn() => GitInfo::branch()), + new TwigFunction('csrf_token', CSRF::token(...)), + new TwigFunction('git_commit_hash', GitInfo::hash(...)), + new TwigFunction('git_tag', GitInfo::tag(...)), + new TwigFunction('git_branch', GitInfo::branch(...)), new TwigFunction('startup_time', fn(float $time = MSZ_STARTUP) => microtime(true) - $time), - new TwigFunction('sql_query_count', fn() => $this->ctx->getDbQueryCount()), - new TwigFunction('ndx_version', fn() => Environment::getIndexVersion()), - new TwigFunction('byte_symbol', fn($bytes, $decimal = ByteFormat::DECIMAL_DEFAULT) => ByteFormat::format($bytes, $decimal)), + new TwigFunction('sql_query_count', $this->ctx->getDbQueryCount(...)), + new TwigFunction('ndx_version', Environment::getIndexVersion(...)), + new TwigFunction('byte_symbol', ByteFormat::format(...)), ]; } diff --git a/src/Users/Assets/AssetsRoutes.php b/src/Users/Assets/AssetsRoutes.php index 5397541..e2bfaf9 100644 --- a/src/Users/Assets/AssetsRoutes.php +++ b/src/Users/Assets/AssetsRoutes.php @@ -20,11 +20,11 @@ class AssetsRoutes { $this->bans = $bans; $this->users = $users; - $router->get('/assets/avatar', [$this, 'getAvatar']); - $router->get('/assets/avatar/:filename', [$this, 'getAvatar']); - $router->get('/assets/profile-background', [$this, 'getProfileBackground']); - $router->get('/assets/profile-background/:filename', [$this, 'getProfileBackground']); - $router->get('/user-assets.php', [$this, 'getUserAssets']); + $router->get('/assets/avatar', $this->getAvatar(...)); + $router->get('/assets/avatar/:filename', $this->getAvatar(...)); + $router->get('/assets/profile-background', $this->getProfileBackground(...)); + $router->get('/assets/profile-background/:filename', $this->getProfileBackground(...)); + $router->get('/user-assets.php', $this->getUserAssets(...)); } private function canViewAsset($request, UserInfo $assetUser): bool { diff --git a/src/Users/Users.php b/src/Users/Users.php index 1f0754a..56fcd2c 100644 --- a/src/Users/Users.php +++ b/src/Users/Users.php @@ -10,8 +10,8 @@ use Index\Data\DbStatementCache; use Index\Data\DbTools; use Index\Data\IDbConnection; use Index\Net\IPAddress; -use Misuzu\DateCheck; use Misuzu\Pagination; +use Misuzu\Tools; use Misuzu\Parsers\Parser; class Users { @@ -695,7 +695,7 @@ class Users { if($year > 0 && ($year < $currentYear - $yearRange || $year > $currentYear)) return 'year'; - if(!DateCheck::isValidDate($year, $month, $day)) + if(!Tools::isValidDate($year, $month, $day)) return 'date'; } diff --git a/templates/forum/macros.twig b/templates/forum/macros.twig index 8ac110c..b662330 100644 --- a/templates/forum/macros.twig +++ b/templates/forum/macros.twig @@ -21,9 +21,8 @@ {% set id = id|default('') %} {% endif %} -
0 %}id="{{ id }}"{% endif %}> +
0 %}id="{{ id }}"{% endif %} + {% if colour is not null %}style="--accent-colour: {{ colour }}"{% endif %}> {{ container_title(' ' ~ title) }} {% if forums|length > 0 %} diff --git a/templates/forum/posting.twig b/templates/forum/posting.twig index 16c7866..e8bb21d 100644 --- a/templates/forum/posting.twig +++ b/templates/forum/posting.twig @@ -43,7 +43,7 @@
{% endif %} -
+