From af8e86ea0981f21f5008e6bc8ec2f581505145c1 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 18 Mar 2019 20:59:46 +0100 Subject: [PATCH] Reduced ->value calls. --- public/auth.php | 2 +- public/auth/login.php | 14 +++++++------- public/auth/logout.php | 2 +- public/auth/password.php | 12 ++++++------ public/auth/register.php | 12 ++++++------ public/auth/twofactor.php | 8 ++++---- public/changelog.php | 8 ++++---- public/comments.php | 6 +++--- public/forum/forum.php | 2 +- public/members.php | 6 +++--- public/news.php | 6 +++--- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/public/auth.php b/public/auth.php index 467dcfcf..fbee367f 100644 --- a/public/auth.php +++ b/public/auth.php @@ -4,7 +4,7 @@ use Misuzu\Request\RequestVar; require_once '../misuzu.php'; -switch (RequestVar::get()->select('m')->value()) { +switch (RequestVar::get()->select('m')->string()) { case 'logout': echo tpl_render('auth.logout'); break; diff --git a/public/auth/login.php b/public/auth/login.php index ad47b59d..6ce4108e 100644 --- a/public/auth/login.php +++ b/public/auth/login.php @@ -10,7 +10,7 @@ if (user_session_active()) { if (isset(RequestVar::get()->resolve_user)) { header('Content-Type: text/plain; charset=utf-8'); - echo user_id_from_username(RequestVar::get()->resolve_user->value('string')); + echo user_id_from_username(RequestVar::get()->resolve_user->string()); return; } @@ -28,7 +28,7 @@ while (!empty($login->value('array'))) { } $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ''; - $loginRedirect = $login->redirect->value('string', ''); + $loginRedirect = $login->redirect->string(''); if ($login->username->empty() || $login->password->empty()) { $notices[] = "You didn't fill in a username and/or password."; @@ -40,7 +40,7 @@ while (!empty($login->value('array'))) { break; } - $loginUsername = $login->username->value('string', ''); + $loginUsername = $login->username->string(''); $userData = user_find_for_login($loginUsername); $attemptsRemainingError = sprintf( "%d attempt%s remaining", @@ -55,7 +55,7 @@ while (!empty($login->value('array'))) { break; } - $loginPassword = $login->password->value('string', ''); + $loginPassword = $login->password->string(''); if (!password_verify($loginPassword, $userData['password'])) { user_login_attempt_record(false, $userData['user_id'], $ipAddress, $userAgent); $notices[] = $loginFailedError; @@ -101,9 +101,9 @@ while (!empty($login->value('array'))) { return; } -$welcomeMode = RequestVar::get()->welcome->value('bool', false); -$loginUsername = $login->username->value('string') ?? RequestVar::get()->username->value('string', ''); -$loginRedirect = $welcomeMode ? url('index') : RequestVar::get()->redirect->value('string') ?? $_SERVER['HTTP_REFERER'] ?? url('index'); +$welcomeMode = RequestVar::get()->welcome->bool(false); +$loginUsername = $login->username->string() ?? RequestVar::get()->username->string(''); +$loginRedirect = $welcomeMode ? url('index') : RequestVar::get()->redirect->string() ?? $_SERVER['HTTP_REFERER'] ?? url('index'); $sitePrivateMessage = $siteIsPrivate ? config_get_default('', 'Private', 'message') : ''; $canResetPassword = $siteIsPrivate ? boolval(config_get_default(false, 'Private', 'password_reset')) : true; $canRegisterAccount = !$siteIsPrivate; diff --git a/public/auth/logout.php b/public/auth/logout.php index fa849a29..b87cdcdb 100644 --- a/public/auth/logout.php +++ b/public/auth/logout.php @@ -8,7 +8,7 @@ if (!user_session_active()) { return; } -if (csrf_verify('logout', RequestVar::get()->token->value('string', ''))) { +if (csrf_verify('logout', RequestVar::get()->token->string())) { setcookie('msz_auth', '', -9001, '/', '', true, true); user_session_stop(true); header(sprintf('Location: %s', url('index'))); diff --git a/public/auth/password.php b/public/auth/password.php index 0ea445c9..f092c799 100644 --- a/public/auth/password.php +++ b/public/auth/password.php @@ -10,7 +10,7 @@ if (user_session_active()) { $reset = RequestVar::post()->reset; $forgot = RequestVar::post()->forgot; -$userId = $reset->user->value('int') ?? RequestVar::get()->user->value('int', 0); +$userId = $reset->user->int() ?? RequestVar::get()->user->int(0); $username = $userId > 0 ? user_username_from_id($userId) : ''; if ($userId > 0 && empty($username)) { @@ -31,15 +31,15 @@ while ($canResetPassword) { break; } - $verificationCode = $reset->verification->value('string', ''); + $verificationCode = $reset->verification->string(''); if (!user_recovery_token_validate($userId, $verificationCode)) { $notices[] = 'Invalid verification code!'; break; } - $passwordNew = $reset->password->new->value('string', ''); - $passwordConfirm = $reset->password->confirm->value('string', ''); + $passwordNew = $reset->password->new->string(''); + $passwordConfirm = $reset->password->confirm->string(''); if (empty($passwordNew) || empty($passwordConfirm) || $passwordNew !== $passwordConfirm) { @@ -83,7 +83,7 @@ while ($canResetPassword) { break; } - $forgotUser = user_find_for_reset($forgot->email->value('string')); + $forgotUser = user_find_for_reset($forgot->email->string()); if (empty($forgotUser)) { $notices[] = "This e-mail address is not registered with us."; @@ -129,7 +129,7 @@ MSG; echo tpl_render($userId > 0 ? 'auth.password_reset' : 'auth.password_forgot', [ 'password_notices' => $notices, - 'password_email' => $forgot->email->value('string', ''), + 'password_email' => $forgot->email->string(''), 'password_attempts_remaining' => $remainingAttempts, 'password_user_id' => $userId, 'password_username' => $username, diff --git a/public/auth/register.php b/public/auth/register.php index b1beafdf..84f4f473 100644 --- a/public/auth/register.php +++ b/public/auth/register.php @@ -31,7 +31,7 @@ while (!$restricted && !empty($register->value('array'))) { break; } - $checkSpamBot = mb_strtolower($register->question->value('string', '')); + $checkSpamBot = mb_strtolower($register->question->string('')); $spamBotValid = [ '19', '21', 'nineteen', 'nine-teen', 'nine teen', 'twentyone', 'twenty-one', 'twenty one', ]; @@ -41,13 +41,13 @@ while (!$restricted && !empty($register->value('array'))) { break; } - $username = $register->username->value('string', ''); + $username = $register->username->string(''); $usernameValidation = user_validate_username($username, true); if ($usernameValidation !== '') { $notices[] = MSZ_USER_USERNAME_VALIDATION_STRINGS[$usernameValidation]; } - $email = $register->email->value('string', ''); + $email = $register->email->string(''); $emailValidation = user_validate_email($email, true); if ($emailValidation !== '') { $notices[] = $emailValidation === 'in-use' @@ -55,7 +55,7 @@ while (!$restricted && !empty($register->value('array'))) { : 'The e-mail address you entered is invalid!'; } - $password = $register->password->value('string', ''); + $password = $register->password->string(''); if (user_validate_password($password) !== '') { $notices[] = 'Your password is too weak!'; } @@ -83,7 +83,7 @@ while (!$restricted && !empty($register->value('array'))) { echo tpl_render('auth.register', [ 'register_notices' => $notices, - 'register_username' => $register->username->value('string', ''), - 'register_email' => $register->email->value('string', ''), + 'register_username' => $register->username->string(''), + 'register_email' => $register->email->string(''), 'register_restricted' => $restricted, ]); diff --git a/public/auth/twofactor.php b/public/auth/twofactor.php index 8174c75c..484b1192 100644 --- a/public/auth/twofactor.php +++ b/public/auth/twofactor.php @@ -13,7 +13,7 @@ $notices = []; $ipAddress = ip_remote_address(); $remainingAttempts = user_login_attempts_remaining($ipAddress); $tokenInfo = user_auth_tfa_token_info( - RequestVar::get()->token->value('string') ?? $twofactor->token->value('string', '') + RequestVar::get()->token->string() ?? $twofactor->token->string('') ); // checking user_totp_key specifically because there's a fringe chance that @@ -30,7 +30,7 @@ while (!empty($twofactor->value('array'))) { } $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? ''; - $redirect = $twofactor->redirect->value('string', ''); + $redirect = $twofactor->redirect->string(''); if ($twofactor->code->empty()) { $notices[] = 'Code field was empty.'; @@ -42,7 +42,7 @@ while (!empty($twofactor->value('array'))) { break; } - $givenCode = $twofactor->code->value('string', ''); + $givenCode = $twofactor->code->string(''); $currentCode = totp_generate($tokenInfo['user_totp_key']); $previousCode = totp_generate($tokenInfo['user_totp_key'], time() - 30); @@ -81,7 +81,7 @@ while (!empty($twofactor->value('array'))) { echo tpl_render('auth.twofactor', [ 'twofactor_notices' => $notices, - 'twofactor_redirect' => RequestVar::get()->redirect->value('string') ?? url('index'), + 'twofactor_redirect' => RequestVar::get()->redirect->string() ?? url('index'), 'twofactor_attempts_remaining' => $remainingAttempts, 'twofactor_token' => $tokenInfo['tfa_token'], ]); diff --git a/public/changelog.php b/public/changelog.php index 96d479a7..752b6ea8 100644 --- a/public/changelog.php +++ b/public/changelog.php @@ -3,10 +3,10 @@ use Misuzu\Request\RequestVar; require_once '../misuzu.php'; -$changelogChange = RequestVar::get()->select('c')->value('int', 0); -$changelogDate = RequestVar::get()->select('d')->value('string', ''); -$changelogUser = RequestVar::get()->select('u')->value('int', 0); -$changelogTags = RequestVar::get()->select('t')->value('string', ''); +$changelogChange = RequestVar::get()->select('c')->int(); +$changelogDate = RequestVar::get()->select('d')->string(); +$changelogUser = RequestVar::get()->select('u')->int(); +$changelogTags = RequestVar::get()->select('t')->string(); tpl_var('comments_perms', $commentPerms = comments_get_perms(user_session_current('user_id', 0))); diff --git a/public/comments.php b/public/comments.php index 314de7d5..deb475e6 100644 --- a/public/comments.php +++ b/public/comments.php @@ -39,8 +39,8 @@ if (user_warning_check_expiration($currentUserId, MSZ_WARN_SILENCE) > 0) { header(csrf_http_header('comments')); $commentPerms = comments_get_perms($currentUserId); -$commentId = RequestVar::get()->select('c')->value('int', 0); -$commentMode = RequestVar::get()->select('m')->value(); +$commentId = RequestVar::get()->select('c')->int(); +$commentMode = RequestVar::get()->select('m')->string(); switch ($commentMode) { case 'pin': @@ -91,7 +91,7 @@ switch ($commentMode) { break; } - $vote = RequestVar::get()->select('v')->value('int', MSZ_COMMENTS_VOTE_INDIFFERENT); + $vote = RequestVar::get()->select('v')->int(MSZ_COMMENTS_VOTE_INDIFFERENT); if (!comments_vote_type_valid($vote)) { echo render_info_or_json($isXHR, 'Invalid vote action.', 400); diff --git a/public/forum/forum.php b/public/forum/forum.php index 11aa76e7..08819f33 100644 --- a/public/forum/forum.php +++ b/public/forum/forum.php @@ -3,7 +3,7 @@ use Misuzu\Request\RequestVar; require_once '../../misuzu.php'; -$forumId = RequestVar::get()->select('f')->value('int'); +$forumId = RequestVar::get()->select('f')->int(0); $forumId = max($forumId, 0); if ($forumId === 0) { diff --git a/public/members.php b/public/members.php index a04d9198..b53e038d 100644 --- a/public/members.php +++ b/public/members.php @@ -3,9 +3,9 @@ use Misuzu\Request\RequestVar; require_once '../misuzu.php'; -$roleId = RequestVar::get()->select('r')->value('int', MSZ_ROLE_MAIN); -$orderBy = RequestVar::get()->select('ss')->value(); -$orderDir = RequestVar::get()->select('sd')->value(); +$roleId = RequestVar::get()->select('r')->int(MSZ_ROLE_MAIN); +$orderBy = RequestVar::get()->select('ss')->string(); +$orderDir = RequestVar::get()->select('sd')->string(); $orderDirs = [ 'asc' => 'Ascending', diff --git a/public/news.php b/public/news.php index a7c2df8c..1e560704 100644 --- a/public/news.php +++ b/public/news.php @@ -5,14 +5,14 @@ require_once '../misuzu.php'; if (RequestVar::get()->isset('n')) { header(sprintf('Location: %s', url('news-post', [ - 'post' => RequestVar::get()->select('n')->value('int'), + 'post' => RequestVar::get()->select('n')->int(), ]))); http_response_code(301); return; } -$categoryId = RequestVar::get()->select('c')->value('int'); -$postId = RequestVar::get()->select('p')->value('int'); +$categoryId = RequestVar::get()->select('c')->int(); +$postId = RequestVar::get()->select('p')->int(); if ($postId > 0) { $post = news_post_get($postId);