diff --git a/lib/Artwork.php b/lib/Artwork.php index e6982da9..2533bad6 100644 --- a/lib/Artwork.php +++ b/lib/Artwork.php @@ -49,7 +49,7 @@ class Artwork{ public ?string $Exception = null; public ?string $Notes = null; public ?ImageMimeType $MimeType = null; - public ?ArtworkStatus $Status = null; + public ?ArtworkStatusType $Status = null; protected ?string $_UrlName = null; protected ?string $_Url = null; @@ -287,7 +287,7 @@ class Artwork{ return true; } - if(($user->Benefits->CanReviewArtwork || $user->UserId == $this->SubmitterUserId) && ($this->Status == ArtworkStatus::Unverified || $this->Status == ArtworkStatus::Declined)){ + if(($user->Benefits->CanReviewArtwork || $user->UserId == $this->SubmitterUserId) && ($this->Status == ArtworkStatusType::Unverified || $this->Status == ArtworkStatusType::Declined)){ // Editors can edit an artwork, and submitters can edit their own artwork, if it's not yet approved. return true; } @@ -305,7 +305,7 @@ class Artwork{ return true; } - if($user->Benefits->CanReviewArtwork && $user->UserId != $this->SubmitterUserId && ($this->Status == ArtworkStatus::Unverified || $this->Status == ArtworkStatus::Declined)){ + if($user->Benefits->CanReviewArtwork && $user->UserId != $this->SubmitterUserId && ($this->Status == ArtworkStatusType::Unverified || $this->Status == ArtworkStatusType::Declined)){ // Editors can change the status of artwork they did not submit themselves, and that is not yet approved. return true; } @@ -883,7 +883,7 @@ class Artwork{ $artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year'); $artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa') ?? false; $artwork->Tags = HttpInput::Str(POST, 'artwork-tags') ?? []; - $artwork->Status = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '') ?? ArtworkStatus::Unverified; + $artwork->Status = ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '') ?? ArtworkStatusType::Unverified; $artwork->EbookUrl = HttpInput::Str(POST, 'artwork-ebook-url'); $artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us') ?? false; $artwork->PublicationYear = HttpInput::Int(POST, 'artwork-publication-year'); diff --git a/lib/ArtworkSort.php b/lib/ArtworkSortType.php similarity index 80% rename from lib/ArtworkSort.php rename to lib/ArtworkSortType.php index 57374b8b..9f3a7ed2 100644 --- a/lib/ArtworkSort.php +++ b/lib/ArtworkSortType.php @@ -1,5 +1,5 @@ $params An array of parameters to bind to the SQL statement. * @param class-string $class The type of object to return in the return array. - * @return Array + * + * @return Array An array of objects of type `$class`, or `stdClass` if `$class` is `null`. + * * @throws Exceptions\DuplicateDatabaseKeyException When a unique key constraint has been violated. * @throws Exceptions\DatabaseQueryException When an error occurs during execution of the query. */ @@ -128,11 +141,14 @@ class DbConnection{ * **Important note:** When joining against two tables, SQL only returns one column for the join key (typically an ID value). Therefore, if both objects require an ID, the filler method must explicitly assign the ID to one of the two objects that's missing it. The above example shows this behavior: note how we join on UserId, but only the Users result has the UserId column, even though the Posts table also has a UserId column. * * @template T + * * @param string $sql The SQL query to execute. * @param array $params An array of parameters to bind to the SQL statement. - * @param class-string $class The class to instantiate for each row, or null to return an array of rows. - * @return array|array> Returns an array of $class if $class is not null, otherwise returns an array of rows. - * @throws Exceptions\AppException If a class was specified but the class doesn't have a FromMultiTableRow method. + * @param class-string $class The class to instantiate for each row, or `null` to return an array of rows. + * + * @return array|array> An array of `$class` if `$class` is not `null`, otherwise an array of rows. + * + * @throws Exceptions\AppException If a class was specified but the class doesn't have a `FromMultiTableRow` method. * @throws Exceptions\DatabaseQueryException When an error occurs during execution of the query. */ public function MultiTableSelect(string $sql, array $params = [], ?string $class = null): array{ @@ -168,8 +184,13 @@ class DbConnection{ } /** + * Given a string of SQL, prepare a PDO handle by binding the parameters to the query. + * * @param string $sql The SQL query to execute. * @param array $params An array of parameters to bind to the SQL statement. + * + * @return \PdoStatement The `\PDOStatement` to be used to execute the query. + * * @throws Exceptions\DatabaseQueryException When an error occurs during execution of the query. */ private function PreparePdoHandle(string $sql, array $params): \PDOStatement{ @@ -208,9 +229,15 @@ class DbConnection{ } /** + * Execute a regular query and return the result as an array of objects. + * * @template T - * @param class-string $class - * @return array + * + * @param \PdoStatement $handle The PDO handle to execute. + * @param class-string $class The type of object to return in the return array. + * + * @return array An array of objects of type `$class`, or `stdClass` if `$class` is `null`. + * * @throws \PDOException When an error occurs during execution of the query. */ private function ExecuteQuery(\PDOStatement $handle, string $class = 'stdClass'): array{ @@ -282,9 +309,15 @@ class DbConnection{ } /** + * Execute a multi-table select query. + * * @template T - * @param ?class-string $class - * @return array|array> + * + * @param \PdoStatement $handle The PDO handle to execute. + * @param class-string $class The class to instantiate for each row, or `null` to return an array of rows. + * + * @return array|array> An array of `$class` if `$class` is not `null`, otherwise an array of rows. + * * @throws \PDOException When an error occurs during execution of the query. */ private function ExecuteMultiTableSelect(\PDOStatement $handle, ?string $class): array{ @@ -333,7 +366,13 @@ class DbConnection{ } /** - * @param array $metadata + * Given a column value and its database driver metadata, return a strongly-typed value. + * + * @param mixed $column The value of the column, most likely either a string or integer. + * @param array $metadata An array of metadata returned from the database driver. + * @param string $class The type of object that this return value will be part of. + * + * @return mixed The strongly-typed column value. */ private function GetColumnValue(mixed $column, array $metadata, string $class = 'stdClass'): mixed{ if($column === null){ @@ -402,6 +441,9 @@ class DbConnection{ /** * Get the ID of the last row that was inserted during this database connection. + * + * @return int The ID of the last row that was inserted during this database connection. + * * @throws Exceptions\DatabaseQueryException When the last inserted ID can't be determined. */ public function GetLastInsertedId(): int{ @@ -421,10 +463,14 @@ class DbConnection{ } /** - * @param \PDOException $ex The exception to create details from. - * @param string $sql The prepared SQL that caused the exception. - * @param array $params The parameters passed to the prepared SQL. - */ + * Create a detailed `Exceptions\DatabaseQueryException` from a `\PDOException`. + * + * @param \PDOException $ex The exception to create details from. + * @param string $sql The prepared SQL that caused the exception. + * @param array $params The parameters passed to the prepared SQL. + * + * @return Exceptions\DatabaseQueryException A more detailed exception to be thrown further up the stack. + */ private function CreateDetailedException(\PDOException $ex, string $sql, array $params): Exceptions\DatabaseQueryException{ // Throw a custom exception that includes more information on the query and paramaters return new Exceptions\DatabaseQueryException('Error when executing query: ' . $ex->getMessage() . '. Query: ' . $sql . '. Parameters: ' . vds($params)); diff --git a/lib/EbookFormat.php b/lib/EbookFormatType.php similarity index 89% rename from lib/EbookFormat.php rename to lib/EbookFormatType.php index b50b0ef6..ab2e63ac 100644 --- a/lib/EbookFormat.php +++ b/lib/EbookFormatType.php @@ -1,5 +1,5 @@ $Exceptions */ - public $Exceptions = []; + public array $Exceptions = []; public bool $HasExceptions = false; public bool $IsFatal = false; @@ -19,8 +19,7 @@ class ValidationException extends AppException{ public function Add(\Exception $exception, bool $isFatal = false): void{ /** @var ValidationException $exception */ - if(is_a($exception, static::class)){ - /** @var ValidationException $childException */ + if($exception instanceof static){ foreach($exception->Exceptions as $childException){ $this->Add($childException); } @@ -29,6 +28,8 @@ class ValidationException extends AppException{ $this->Exceptions[] = $exception; } + // Don't set $this->IsFatal directly, so that a non-fatal exception + // added later won't overwrite the fatality of a previous exception. if($isFatal){ $this->IsFatal = true; } @@ -45,10 +46,4 @@ class ValidationException extends AppException{ return false; } - - public function Clear(): void{ - unset($this->Exceptions); - $this->Exceptions = []; - $this->HasExceptions = false; - } } diff --git a/lib/Formatter.php b/lib/Formatter.php index 6f92abb7..038d2d84 100644 --- a/lib/Formatter.php +++ b/lib/Formatter.php @@ -2,6 +2,9 @@ use function Safe\preg_replace; class Formatter{ + /** + * Remove diacritics from a string. + */ public static function RemoveDiacritics(string $text): string{ if(!isset($GLOBALS['transliterator'])){ $GLOBALS['transliterator'] = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD); @@ -10,6 +13,21 @@ class Formatter{ return $GLOBALS['transliterator']->transliterate($text); } + /** + * Escape a string so that it's appropriate to use in a URL slug. + * + * This does the following to the string: + * + * 1. Removes any diacritics. + * + * 2. Removes apostrophes. + * + * 3. Converts the string to lowercase. + * + * 4. Converts any non-digit, non-letter character to a space. + * + * 5. Converts any sequence of one or more spaces to a single dash. + */ public static function MakeUrlSafe(string $text): string{ // Remove accent characters $text = self::RemoveDiacritics($text); @@ -32,24 +50,38 @@ class Formatter{ return $text; } + /** + * Escape a string so that it's safe to output directly into an HTML document. + */ public static function EscapeHtml(?string $text): string{ return htmlspecialchars(trim($text ?? ''), ENT_QUOTES, 'utf-8'); } + /** + * Escape a strin so that it's safe to output directly into an XML document. Note that this is **not the same** as escaping for HTML. Any query strings in URLs should already be URL-encoded, for example `?foo=bar+baz&x=y`. + */ public static function EscapeXml(?string $text): string{ - // Accepts a query string that has already been url-encoded. For example, - // ?foo=bar+baz&x=y return htmlspecialchars(trim($text ?? ''), ENT_QUOTES|ENT_XML1, 'utf-8'); } - public static function EscapeMarkdown(?string $text): string{ - $parsedown = new Parsedown(); - $parsedown->setSafeMode(true); - return $parsedown->text($text); + /** + * Convert a string of Markdown into HTML. + */ + public static function MarkdownToHtml(?string $text): string{ + if(!isset($GLOBALS['markdown-parser'])){ + $GLOBALS['markdown-parser'] = new Parsedown(); + $GLOBALS['markdown-parser']->setSafeMode(true); + } + + return $GLOBALS['markdown-parser']->text($text); } + /** + * Given a number of bytes, return a string containing a human-readable filesize. + * + * @see https://stackoverflow.com/a/5501447 + */ public static function ToFileSize(?int $bytes): string{ - // See https://stackoverflow.com/a/5501447 $output = ''; if($bytes >= 1073741824){ diff --git a/lib/Library.php b/lib/Library.php index 584d2d52..34d53338 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -19,12 +19,12 @@ class Library{ * @return array * @throws Exceptions\AppException */ - public static function FilterEbooks(string $query = null, array $tags = [], EbookSort $sort = null): array{ + public static function FilterEbooks(string $query = null, array $tags = [], EbookSortType $sort = null): array{ $ebooks = Library::GetEbooks(); $matches = $ebooks; if($sort === null){ - $sort = EbookSort::Newest; + $sort = EbookSortType::Newest; } if(sizeof($tags) > 0 && !in_array('all', $tags)){ // 0 tags means "all ebooks" @@ -51,13 +51,13 @@ class Library{ } switch($sort){ - case EbookSort::AuthorAlpha: + case EbookSortType::AuthorAlpha: usort($matches, function($a, $b){ return strcmp(mb_strtolower($a->Authors[0]->SortName), mb_strtolower($b->Authors[0]->SortName)); }); break; - case EbookSort::Newest: + case EbookSortType::Newest: usort($matches, function($a, $b){ if($a->Created < $b->Created){ return -1; @@ -73,7 +73,7 @@ class Library{ $matches = array_reverse($matches); break; - case EbookSort::ReadingEase: + case EbookSortType::ReadingEase: usort($matches, function($a, $b){ if($a->ReadingEase < $b->ReadingEase){ return -1; @@ -89,7 +89,7 @@ class Library{ $matches = array_reverse($matches); break; - case EbookSort::Length: + case EbookSortType::Length: usort($matches, function($a, $b){ if($a->WordCount < $b->WordCount){ return -1; @@ -170,10 +170,10 @@ class Library{ /** * @param string $query * @param string $status - * @param ArtworkSort $sort + * @param ArtworkSortType $sort * @return array|int> */ - public static function FilterArtwork(string $query = null, string $status = null, ArtworkSort $sort = null, int $submitterUserId = null, int $page = 1, int $perPage = ARTWORK_PER_PAGE): array{ + public static function FilterArtwork(string $query = null, string $status = null, ArtworkSortType $sort = null, int $submitterUserId = null, int $page = 1, int $perPage = ARTWORK_PER_PAGE): array{ // Returns an array of: // ['artworks'] => array, // ['artworksCount'] => int @@ -191,29 +191,29 @@ class Library{ if($status === null || $status == 'all'){ $statusCondition = 'Status = ?'; - $params[] = ArtworkStatus::Approved->value; + $params[] = ArtworkStatusType::Approved->value; } elseif($status == 'all-admin'){ $statusCondition = 'true'; } elseif($status == 'all-submitter' && $submitterUserId !== null){ $statusCondition = '(Status = ? or (Status = ? and SubmitterUserId = ?))'; - $params[] = ArtworkStatus::Approved->value; - $params[] = ArtworkStatus::Unverified->value; + $params[] = ArtworkStatusType::Approved->value; + $params[] = ArtworkStatusType::Unverified->value; $params[] = $submitterUserId; } elseif($status == 'unverified-submitter' && $submitterUserId !== null){ $statusCondition = 'Status = ? and SubmitterUserId = ?'; - $params[] = ArtworkStatus::Unverified->value; + $params[] = ArtworkStatusType::Unverified->value; $params[] = $submitterUserId; } elseif($status == 'in-use'){ $statusCondition = 'Status = ? and EbookUrl is not null'; - $params[] = ArtworkStatus::Approved->value; + $params[] = ArtworkStatusType::Approved->value; } - elseif($status == ArtworkStatus::Approved->value){ + elseif($status == ArtworkStatusType::Approved->value){ $statusCondition = 'Status = ? and EbookUrl is null'; - $params[] = ArtworkStatus::Approved->value; + $params[] = ArtworkStatusType::Approved->value; } else{ $statusCondition = 'Status = ?'; @@ -221,10 +221,10 @@ class Library{ } $orderBy = 'art.Created desc'; - if($sort == ArtworkSort::ArtistAlpha){ + if($sort == ArtworkSortType::ArtistAlpha){ $orderBy = 'a.Name'; } - elseif($sort == ArtworkSort::CompletedNewest){ + elseif($sort == ArtworkSortType::CompletedNewest){ $orderBy = 'art.CompletedYear desc'; } @@ -336,13 +336,13 @@ class Library{ } elseif($status == 'all-submitter' && $submitterUserId !== null){ $statusCondition = '(Status = ? or (Status = ? and SubmitterUserId = ?))'; - $params[] = ArtworkStatus::Approved->value; - $params[] = ArtworkStatus::Unverified->value; + $params[] = ArtworkStatusType::Approved->value; + $params[] = ArtworkStatusType::Unverified->value; $params[] = $submitterUserId; } else{ $statusCondition = 'Status = ?'; - $params[] = ArtworkStatus::Approved->value; + $params[] = ArtworkStatusType::Approved->value; } $params[] = $artistUrlName; // a.UrlName diff --git a/lib/Payment.php b/lib/Payment.php index 6c417ab2..d323c5ae 100644 --- a/lib/Payment.php +++ b/lib/Payment.php @@ -10,7 +10,7 @@ class Payment{ public int $PaymentId; public ?int $UserId = null; public DateTimeImmutable $Created; - public PaymentProcessor $Processor; + public PaymentProcessorType $Processor; public string $TransactionId; public float $Amount; public float $Fee; diff --git a/lib/PaymentProcessor.php b/lib/PaymentProcessor.php index b74389d3..e69de29b 100644 --- a/lib/PaymentProcessor.php +++ b/lib/PaymentProcessor.php @@ -1,4 +0,0 @@ -Artwork approval status diff --git a/templates/ArtworkList.php b/templates/ArtworkList.php index af24cc04..57f364fc 100644 --- a/templates/ArtworkList.php +++ b/templates/ArtworkList.php @@ -11,11 +11,11 @@ $artworks = $artworks ?? []; } switch($artwork->Status){ - case ArtworkStatus::Unverified: + case ArtworkStatusType::Unverified: $class .= ' unverified'; break; - case ArtworkStatus::Declined: + case ArtworkStatusType::Declined: $class .= ' declined'; break; } diff --git a/templates/ArtworkStatus.php b/templates/ArtworkStatus.php index 60189b25..67bfa139 100644 --- a/templates/ArtworkStatus.php +++ b/templates/ArtworkStatus.php @@ -2,8 +2,8 @@ $artwork = $artwork ?? null; ?> -Status == ArtworkStatus::Approved){ ?>Approved -Status == ArtworkStatus::Declined){ ?>Declined -Status == ArtworkStatus::Unverified){ ?>Unverified +Status == ArtworkStatusType::Approved){ ?>Approved +Status == ArtworkStatusType::Declined){ ?>Declined +Status == ArtworkStatusType::Unverified){ ?>Unverified EbookUrl !== null){ ?> — in useEbookUrl !== null){ ?> by Ebook !== null && $artwork->Ebook->Url !== null){ ?>Ebook->Title) ?>EbookUrl) ?> (unreleased) diff --git a/templates/SearchForm.php b/templates/SearchForm.php index 46f6a639..9a29ce18 100644 --- a/templates/SearchForm.php +++ b/templates/SearchForm.php @@ -17,10 +17,10 @@ $allSelected = sizeof($tags) == 0 || in_array('all', $tags); Sort diff --git a/www/artworks/get.php b/www/artworks/get.php index bc2a4d9b..b34c6af3 100644 --- a/www/artworks/get.php +++ b/www/artworks/get.php @@ -13,9 +13,9 @@ try{ // If the artwork is not approved, and we're not an admin or the submitter when they can edit, don't show it. if( - ($GLOBALS['User'] === null && $artwork->Status != ArtworkStatus::Approved) + ($GLOBALS['User'] === null && $artwork->Status != ArtworkStatusType::Approved) || - ($GLOBALS['User'] !== null && $artwork->Status != ArtworkStatus::Approved && $artwork->SubmitterUserId != $GLOBALS['User']->UserId && !$isReviewerView) + ($GLOBALS['User'] !== null && $artwork->Status != ArtworkStatusType::Approved && $artwork->SubmitterUserId != $GLOBALS['User']->UserId && !$isReviewerView) ){ throw new Exceptions\InvalidPermissionsException(); } @@ -135,12 +135,12 @@ catch(Exceptions\InvalidPermissionsException){ Exception !== null){ ?>

Public domain status exception reason

- Exception) ?> + Exception) ?> Notes !== null){ ?>

Special notes

- Notes) ?> + Notes) ?> CanBeEditedBy($GLOBALS['User'] ?? null)){ ?> @@ -161,9 +161,9 @@ catch(Exceptions\InvalidPermissionsException){ Artwork approval status diff --git a/www/artworks/index.php b/www/artworks/index.php index 3556a9c0..b1e40e85 100644 --- a/www/artworks/index.php +++ b/www/artworks/index.php @@ -5,7 +5,7 @@ $query = HttpInput::Str(GET, 'query'); $queryEbookUrl = HttpInput::Str(GET, 'query-ebook-url'); $status = HttpInput::Str(GET, 'status'); $filterArtworkStatus = $status; -$sort = ArtworkSort::tryFrom(HttpInput::Str(GET, 'sort') ?? ''); +$sort = ArtworkSortType::tryFrom(HttpInput::Str(GET, 'sort') ?? ''); $pages = 0; $totalArtworkCount = 0; $pageDescription = ''; @@ -26,7 +26,7 @@ try{ // If we're passed string values that are the same as the defaults, // set them to null so that we can have cleaner query strings in the navigation footer - if($sort == ArtworkSort::CreatedNewest){ + if($sort == ArtworkSortType::CreatedNewest){ $sort = null; } @@ -45,25 +45,25 @@ try{ } } - if(!$isReviewerView && !$isSubmitterView && !in_array($status, array('all', ArtworkStatus::Approved->value, 'in-use'))){ - $status = ArtworkStatus::Approved->value; + if(!$isReviewerView && !$isSubmitterView && !in_array($status, array('all', ArtworkStatusType::Approved->value, 'in-use'))){ + $status = ArtworkStatusType::Approved->value; $filterArtworkStatus = $status; } - if($isReviewerView && !in_array($status, array('all', ArtworkStatus::Unverified->value, ArtworkStatus::Declined->value, ArtworkStatus::Approved->value, 'in-use')) - && !in_array($filterArtworkStatus, array('all-admin', ArtworkStatus::Unverified->value, ArtworkStatus::Declined->value, ArtworkStatus::Approved->value, 'in-use'))){ - $status = ArtworkStatus::Approved->value; + if($isReviewerView && !in_array($status, array('all', ArtworkStatusType::Unverified->value, ArtworkStatusType::Declined->value, ArtworkStatusType::Approved->value, 'in-use')) + && !in_array($filterArtworkStatus, array('all-admin', ArtworkStatusType::Unverified->value, ArtworkStatusType::Declined->value, ArtworkStatusType::Approved->value, 'in-use'))){ + $status = ArtworkStatusType::Approved->value; $filterArtworkStatus = $status; } - if($isSubmitterView && !in_array($status, array('all', ArtworkStatus::Unverified->value, ArtworkStatus::Approved->value, 'in-use')) - && !in_array($filterArtworkStatus, array('all-submitter', 'unverified-submitter', ArtworkStatus::Approved->value, 'in-use'))){ - $status = ArtworkStatus::Approved->value; + if($isSubmitterView && !in_array($status, array('all', ArtworkStatusType::Unverified->value, ArtworkStatusType::Approved->value, 'in-use')) + && !in_array($filterArtworkStatus, array('all-submitter', 'unverified-submitter', ArtworkStatusType::Approved->value, 'in-use'))){ + $status = ArtworkStatusType::Approved->value; $filterArtworkStatus = $status; } if($queryEbookUrl !== null){ - $artworks = Db::Query('SELECT * from Artworks where EbookUrl = ? and Status = ? limit 1', [$queryEbookUrl, ArtworkStatus::Approved], Artwork::class); + $artworks = Db::Query('SELECT * from Artworks where EbookUrl = ? and Status = ? limit 1', [$queryEbookUrl, ArtworkStatusType::Approved], Artwork::class); $totalArtworkCount = sizeof($artworks); } else{ @@ -141,9 +141,9 @@ catch(Exceptions\PageOutOfBoundsException){ @@ -155,9 +155,9 @@ catch(Exceptions\PageOutOfBoundsException){ Sort diff --git a/www/artworks/new.php b/www/artworks/new.php index dfa165fe..7d840e8a 100644 --- a/www/artworks/new.php +++ b/www/artworks/new.php @@ -35,7 +35,7 @@ try{ $artwork->Artist = new Artist(); if($GLOBALS['User']->Benefits->CanReviewOwnArtwork){ - $artwork->Status = ArtworkStatus::Approved; + $artwork->Status = ArtworkStatusType::Approved; } } } diff --git a/www/artworks/post.php b/www/artworks/post.php index 7e51f6e4..4f88cebe 100644 --- a/www/artworks/post.php +++ b/www/artworks/post.php @@ -23,12 +23,12 @@ try{ // Only approved reviewers can set the status to anything but unverified when uploading. // The submitter cannot review their own submissions unless they have special permission. - if($artwork->Status !== ArtworkStatus::Unverified && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){ + if($artwork->Status !== ArtworkStatusType::Unverified && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){ throw new Exceptions\InvalidPermissionsException(); } // If the artwork is approved, set the reviewer - if($artwork->Status !== ArtworkStatus::Unverified){ + if($artwork->Status !== ArtworkStatusType::Unverified){ $artwork->ReviewerUserId = $GLOBALS['User']->UserId; } @@ -67,7 +67,7 @@ try{ $artwork->SubmitterUserId = $originalArtwork->SubmitterUserId; $artwork->Status = $originalArtwork->Status; // Overwrite any value got from POST because we need permission to change the status - $newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? ''); + $newStatus = ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? ''); if($newStatus !== null){ if($originalArtwork->Status != $newStatus && !$originalArtwork->CanStatusBeChangedBy($GLOBALS['User'])){ throw new Exceptions\InvalidPermissionsException(); @@ -108,7 +108,7 @@ try{ // We can PATCH the status, the ebook www filesystem path, or both. if(isset($_POST['artwork-status'])){ - $newStatus = ArtworkStatus::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? ''); + $newStatus = ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? ''); if($newStatus !== null){ if($artwork->Status != $newStatus && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){ throw new Exceptions\InvalidPermissionsException(); diff --git a/www/ebooks/download.php b/www/ebooks/download.php index e4b49a6b..49907a17 100644 --- a/www/ebooks/download.php +++ b/www/ebooks/download.php @@ -11,7 +11,7 @@ $downloadUrl = null; try{ $urlPath = HttpInput::Str(GET, 'url-path') ?? null; - $format = EbookFormat::tryFrom(HttpInput::Str(GET, 'format') ?? '') ?? EbookFormat::Epub; + $format = EbookFormatType::tryFrom(HttpInput::Str(GET, 'format') ?? '') ?? EbookFormatType::Epub; $wwwFilesystemPath = EBOOKS_DIST_PATH . $urlPath; // Do we have the ebook cached? @@ -24,19 +24,19 @@ try{ } switch($format){ - case EbookFormat::Kepub: + case EbookFormatType::Kepub: $downloadUrl = $ebook->KepubUrl; break; - case EbookFormat::Azw3: + case EbookFormatType::Azw3: $downloadUrl = $ebook->Azw3Url; break; - case EbookFormat::AdvancedEpub: + case EbookFormatType::AdvancedEpub: $downloadUrl = $ebook->AdvancedEpubUrl; break; - case EbookFormat::Epub: + case EbookFormatType::Epub: default: $downloadUrl = $ebook->EpubUrl; break; diff --git a/www/ebooks/ebook.php b/www/ebooks/ebook.php index fbd922fb..7b121330 100644 --- a/www/ebooks/ebook.php +++ b/www/ebooks/ebook.php @@ -230,7 +230,7 @@ catch(Exceptions\EbookNotFoundException){

- Compatible epub All devices and apps except Kindles and Kobos. + Compatible epub All devices and apps except Kindles and Kobos.

@@ -239,7 +239,7 @@ catch(Exceptions\EbookNotFoundException){
  • - azw3 Kindle devices and apps.KindleCoverUrl !== null){ ?> Also download the Kindle cover thumbnail to see the cover in your Kindle’s library. Despite what you’ve been told, Kindle does not natively support epub. You may also be interested in our Kindle FAQ. Also see our Kindle FAQ. + azw3 Kindle devices and apps.KindleCoverUrl !== null){ ?> Also download the Kindle cover thumbnail to see the cover in your Kindle’s library. Despite what you’ve been told, Kindle does not natively support epub. You may also be interested in our Kindle FAQ. Also see our Kindle FAQ.

  • @@ -248,7 +248,7 @@ catch(Exceptions\EbookNotFoundException){
  • - kepub Kobo devices and apps. You may also be interested in our Kobo FAQ. + kepub Kobo devices and apps. You may also be interested in our Kobo FAQ.

  • @@ -257,7 +257,7 @@ catch(Exceptions\EbookNotFoundException){
  • - Advanced epub An advanced format that uses the latest technology not yet fully supported by most ereaders. + Advanced epub An advanced format that uses the latest technology not yet fully supported by most ereaders.

  • diff --git a/www/ebooks/index.php b/www/ebooks/index.php index b05484dc..7e6f121d 100644 --- a/www/ebooks/index.php +++ b/www/ebooks/index.php @@ -7,7 +7,7 @@ $perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; $query = HttpInput::Str(GET, 'query') ?? ''; $tags = HttpInput::Array(GET, 'tags') ?? []; $view = ViewType::tryFrom(HttpInput::Str(GET, 'view') ?? ''); -$sort = EbookSort::tryFrom(HttpInput::Str(GET, 'sort') ?? ''); +$sort = EbookSortType::tryFrom(HttpInput::Str(GET, 'sort') ?? ''); $queryString = ''; $queryStringParams = []; $queryStringWithoutPage = ''; @@ -27,7 +27,7 @@ try{ $view = null; } - if($sort == EbookSort::Newest){ + if($sort == EbookSortType::Newest){ $sort = null; } diff --git a/www/webhooks/zoho.php b/www/webhooks/zoho.php index 0bbab671..e5e9d213 100644 --- a/www/webhooks/zoho.php +++ b/www/webhooks/zoho.php @@ -39,7 +39,7 @@ try{ values (utc_timestamp(), ?, ?) - ', [PaymentProcessor::FracturedAtlas, $transactionId]); + ', [PaymentProcessorType::FracturedAtlas, $transactionId]); $log->Write('Donation ID: ' . $transactionId); }