mirror of
https://github.com/standardebooks/web.git
synced 2025-07-20 05:14:48 -04:00
Update PHPStan and Safe PHP, and review codebase for further type correctness
This commit is contained in:
parent
e2e14a3551
commit
9d1b66d19e
35 changed files with 301 additions and 169 deletions
|
@ -1,6 +1,6 @@
|
|||
<?
|
||||
$isReviewerView = Session::$User?->Benefits?->CanReviewArtwork ?? false;
|
||||
$submitterUserId = Session::$User?->Benefits?->CanUploadArtwork ? Session::$User->UserId : null;
|
||||
$isReviewerView = Session::$User?->Benefits->CanReviewArtwork ?? false;
|
||||
$submitterUserId = Session::$User?->Benefits->CanUploadArtwork ? Session::$User->UserId : null;
|
||||
$isSubmitterView = !$isReviewerView && $submitterUserId !== null;
|
||||
|
||||
$artworkFilterType = Enums\ArtworkFilterType::Approved;
|
||||
|
|
|
@ -11,8 +11,8 @@ $totalArtworkCount = 0;
|
|||
$pageDescription = '';
|
||||
$pageTitle = '';
|
||||
$queryString = '';
|
||||
$isReviewerView = Session::$User?->Benefits?->CanReviewArtwork ?? false;
|
||||
$submitterUserId = Session::$User?->Benefits?->CanUploadArtwork ? Session::$User->UserId : null;
|
||||
$isReviewerView = Session::$User?->Benefits->CanReviewArtwork ?? false;
|
||||
$submitterUserId = Session::$User?->Benefits->CanUploadArtwork ? Session::$User->UserId : null;
|
||||
$isSubmitterView = !$isReviewerView && $submitterUserId !== null;
|
||||
|
||||
try{
|
||||
|
@ -127,6 +127,7 @@ catch(Exceptions\ArtworkNotFoundException){
|
|||
Template::ExitWithCode(Enums\HttpCode::NotFound);
|
||||
}
|
||||
catch(Exceptions\PageOutOfBoundsException){
|
||||
/** @var string $queryStringWithoutPage */
|
||||
$url = '/artworks?page=' . $pages;
|
||||
if($queryStringWithoutPage != ''){
|
||||
$url .= '&' . $queryStringWithoutPage;
|
||||
|
|
|
@ -32,7 +32,9 @@ try{
|
|||
}
|
||||
catch(Exceptions\LoginRequiredException){
|
||||
if(isset($_SERVER['HTTP_REFERER'])){
|
||||
Template::RedirectToLogin(true, $_SERVER['HTTP_REFERER']);
|
||||
/** @var string $httpReferer */
|
||||
$httpReferer = $_SERVER['HTTP_REFERER'];
|
||||
Template::RedirectToLogin(true, $httpReferer);
|
||||
}
|
||||
else{
|
||||
preg_match('|(^/bulk-downloads/[^/]+?)/|ius', $path, $matches);
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
<?
|
||||
require_once('Core.php');
|
||||
?><?= Template::Header(['title' => 'How to Create SVGs from Maps with Several Colors', 'manual' => true, 'highlight' => 'contribute', 'description' => 'A guide to producing SVG from images such as maps with more than a single color.']) ?>
|
||||
<?= Template::Header(['title' => 'How to Create SVGs from Maps with Several Colors', 'manual' => true, 'highlight' => 'contribute', 'description' => 'A guide to producing SVG from images such as maps with more than a single color.']) ?>
|
||||
<main class="manual">
|
||||
<article class="step-by-step-guide">
|
||||
<h1>How to Create SVGs from Maps with Several Colors</h1>
|
||||
|
|
|
@ -80,7 +80,9 @@ try{
|
|||
ksort($queryStringParams);
|
||||
|
||||
// If all we did was select one tag, redirect the user to `/subjects/<TAG>` instead of `/ebooks?tag[0]=<TAG>`.
|
||||
if(sizeof($tags) == 1 && $query == '' && preg_match('|^/ebooks|iu', $_SERVER['REQUEST_URI'] ?? '')){
|
||||
/** @var string $requestUri */
|
||||
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
||||
if(sizeof($tags) == 1 && $query == '' && preg_match('|^/ebooks|iu', $requestUri)){
|
||||
unset($queryStringParams['tags']);
|
||||
$queryStringWithoutTags = http_build_query($queryStringParams);
|
||||
$url = '/subjects/' . $tags[0];
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
use function Safe\preg_match;
|
||||
|
||||
$feedType = '';
|
||||
preg_match('/^\/feeds\/(opds|rss|atom)/ius', $_SERVER['REQUEST_URI'], $matches);
|
||||
/** @var string $requestUri */
|
||||
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
|
||||
preg_match('/^\/feeds\/(opds|rss|atom)/ius', $requestUri, $matches);
|
||||
|
||||
if(sizeof($matches) > 0){
|
||||
$feedType = Enums\FeedType::tryFrom(strtolower($matches[1]));
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?
|
||||
use function Safe\glob;
|
||||
use function Safe\preg_replace;
|
||||
use function Safe\sort;
|
||||
|
||||
// Redirect to the latest version of the manual
|
||||
|
||||
|
|
|
@ -48,7 +48,9 @@ catch(Exceptions\AppException){
|
|||
<? if($poll->Start !== null && $poll->Start > NOW){ ?>
|
||||
<p class="center-notice">This poll opens on <?= $poll->Start->format(Enums\DateTimeFormat::FullDateTime->value) ?>.</p>
|
||||
<? }else{ ?>
|
||||
<p class="center-notice">This poll closed on <?= $poll->End->format(Enums\DateTimeFormat::FullDateTime->value) ?>.</p>
|
||||
<? if($poll->End !== null){ ?>
|
||||
<p class="center-notice">This poll closed on <?= $poll->End->format(Enums\DateTimeFormat::FullDateTime->value) ?>.</p>
|
||||
<? } ?>
|
||||
<p class="button-row narrow"><a href="<?= $poll->Url ?>/votes" class="button">View results</a></p>
|
||||
<? } ?>
|
||||
<? } ?>
|
||||
|
|
|
@ -30,6 +30,7 @@ if($httpMethod == Enums\HttpMethod::Patch){
|
|||
// HTTP 303, See other
|
||||
http_response_code(Enums\HttpCode::SeeOther->value);
|
||||
|
||||
/** @var string $redirect */
|
||||
$redirect = $_SERVER['HTTP_REFERER'] ?? '/';
|
||||
header('Location: ' . $redirect);
|
||||
}
|
||||
|
|
|
@ -6,11 +6,13 @@
|
|||
use function Safe\exec;
|
||||
use function Safe\file_get_contents;
|
||||
use function Safe\json_decode;
|
||||
use function Safe\get_cfg_var;
|
||||
use function Safe\glob;
|
||||
use function Safe\shell_exec;
|
||||
|
||||
$log = new Log(GITHUB_WEBHOOK_LOG_FILE_PATH);
|
||||
|
||||
try{
|
||||
$log = new Log(GITHUB_WEBHOOK_LOG_FILE_PATH);
|
||||
$lastPushHashFlag = '';
|
||||
|
||||
HttpInput::ValidateRequestMethod([Enums\HttpMethod::Post]);
|
||||
|
@ -20,7 +22,9 @@ try{
|
|||
$post = file_get_contents('php://input');
|
||||
|
||||
// Validate the GitHub secret.
|
||||
$splitHash = explode('=', $_SERVER['HTTP_X_HUB_SIGNATURE']);
|
||||
/** @var string $githubSignature */
|
||||
$githubSignature = $_SERVER['HTTP_X_HUB_SIGNATURE'] ?? '';
|
||||
$splitHash = explode('=', $githubSignature);
|
||||
$hashAlgorithm = $splitHash[0];
|
||||
$hash = $splitHash[1];
|
||||
|
||||
|
@ -80,7 +84,7 @@ try{
|
|||
|
||||
// Check the local repo's last commit. If it matches this push, then don't do anything; we're already up to date.
|
||||
|
||||
$lastCommitSha1 = trim(shell_exec('git -C ' . escapeshellarg($dir) . ' rev-parse HEAD 2>&1'));
|
||||
$lastCommitSha1 = trim(shell_exec('git -C ' . escapeshellarg($dir) . ' rev-parse HEAD 2>&1') ?? '');
|
||||
|
||||
if($lastCommitSha1 == ''){
|
||||
$log->Write('Error getting last local commit. Output: ' . $lastCommitSha1);
|
||||
|
@ -95,12 +99,11 @@ try{
|
|||
}
|
||||
|
||||
// Get the current HEAD hash and save for later.
|
||||
$output = [];
|
||||
exec('sudo --set-home --user=se-vcs-bot git -C ' . escapeshellarg($dir) . ' rev-parse HEAD', $output, $returnCode);
|
||||
if($returnCode != 0){
|
||||
$log->Write('Couldn\'t get last commit of local repo. Output: ' . implode("\n", $output));
|
||||
}
|
||||
else{
|
||||
elseif(sizeof($output ?? []) > 0){
|
||||
$lastPushHashFlag = ' --last-push-hash ' . escapeshellarg($output[0]);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,12 @@ use function Safe\curl_exec;
|
|||
use function Safe\curl_init;
|
||||
use function Safe\curl_setopt;
|
||||
use function Safe\file_get_contents;
|
||||
use function Safe\get_cfg_var;
|
||||
use function Safe\json_decode;
|
||||
|
||||
$log = new Log(POSTMARK_WEBHOOK_LOG_FILE_PATH);
|
||||
|
||||
try{
|
||||
$log = new Log(POSTMARK_WEBHOOK_LOG_FILE_PATH);
|
||||
/** @var string $smtpUsername */
|
||||
$smtpUsername = get_cfg_var('se.secrets.postmark.username');
|
||||
|
||||
|
@ -17,7 +19,9 @@ try{
|
|||
$apiKey = get_cfg_var('se.secrets.postmark.api_key');
|
||||
|
||||
// Ensure this webhook actually came from Postmark.
|
||||
if($apiKey != ($_SERVER['HTTP_X_SE_KEY'] ?? '')){
|
||||
/** @var string $postmarkKey */
|
||||
$postmarkKey = $_SERVER['HTTP_X_SE_KEY'] ?? '';
|
||||
if($apiKey != $postmarkKey){
|
||||
throw new Exceptions\InvalidCredentialsException();
|
||||
}
|
||||
|
||||
|
@ -76,7 +80,8 @@ try{
|
|||
http_response_code(Enums\HttpCode::NoContent->value);
|
||||
}
|
||||
catch(Exceptions\InvalidCredentialsException){
|
||||
$log->Write('Invalid key: ' . ($_SERVER['HTTP_X_SE_KEY'] ?? ''));
|
||||
/** @var string $postmarkKey */
|
||||
$log->Write('Invalid key: ' . $postmarkKey);
|
||||
http_response_code(Enums\HttpCode::Forbidden->value);
|
||||
}
|
||||
catch(Exceptions\WebhookException $ex){
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
<?
|
||||
use function Safe\file_get_contents;
|
||||
use function Safe\get_cfg_var;
|
||||
use function Safe\preg_match;
|
||||
use function Safe\json_decode;
|
||||
|
||||
// This webhook receives POSTs when email from a Fractured Atlas donation is received at the SE Zoho email account. This script processes the email, and inserts the donation ID into the database for later processing by `~se/web/scripts/process-pending-payments`.
|
||||
try{
|
||||
$log = new Log(ZOHO_WEBHOOK_LOG_FILE_PATH);
|
||||
$log = new Log(ZOHO_WEBHOOK_LOG_FILE_PATH);
|
||||
|
||||
try{
|
||||
HttpInput::ValidateRequestMethod([Enums\HttpMethod::Post]);
|
||||
|
||||
$log->Write('Received Zoho webhook.');
|
||||
|
@ -17,7 +18,9 @@ try{
|
|||
/** @var string $zohoWebhookSecret */
|
||||
$zohoWebhookSecret = get_cfg_var('se.secrets.zoho.webhook_secret');
|
||||
|
||||
if(!hash_equals($_SERVER['HTTP_X_HOOK_SIGNATURE'], base64_encode(hash_hmac('sha256', $post, $zohoWebhookSecret, true)))){
|
||||
/** @var string $zohoHookSignature */
|
||||
$zohoHookSignature = $_SERVER['HTTP_X_HOOK_SIGNATURE'];
|
||||
if(!hash_equals($zohoHookSignature, base64_encode(hash_hmac('sha256', $post, $zohoWebhookSecret, true)))){
|
||||
throw new Exceptions\InvalidCredentialsException();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue