Move enums into their own namespace

This commit is contained in:
Alex Cabal 2024-11-08 16:34:21 -06:00
parent c3c588cc1b
commit be5574eaec
45 changed files with 164 additions and 154 deletions

View file

@ -48,8 +48,8 @@ class Artwork{
public ?bool $IsPublishedInUs = null; public ?bool $IsPublishedInUs = null;
public ?string $Exception = null; public ?string $Exception = null;
public ?string $Notes = null; public ?string $Notes = null;
public ?ImageMimeType $MimeType = null; public ?Enums\ImageMimeType $MimeType = null;
public ?ArtworkStatusType $Status = null; public ?Enums\ArtworkStatusType $Status = null;
protected ?string $_UrlName = null; protected ?string $_UrlName = null;
protected ?string $_Url = null; protected ?string $_Url = null;
@ -290,7 +290,7 @@ class Artwork{
return true; return true;
} }
if(($user->Benefits->CanReviewArtwork || $user->UserId == $this->SubmitterUserId) && ($this->Status == ArtworkStatusType::Unverified || $this->Status == ArtworkStatusType::Declined)){ if(($user->Benefits->CanReviewArtwork || $user->UserId == $this->SubmitterUserId) && ($this->Status == Enums\ArtworkStatusType::Unverified || $this->Status == Enums\ArtworkStatusType::Declined)){
// Editors can edit an artwork, and submitters can edit their own artwork, if it's not yet approved. // Editors can edit an artwork, and submitters can edit their own artwork, if it's not yet approved.
return true; return true;
} }
@ -308,7 +308,7 @@ class Artwork{
return true; return true;
} }
if($user->Benefits->CanReviewArtwork && $user->UserId != $this->SubmitterUserId && ($this->Status == ArtworkStatusType::Unverified || $this->Status == ArtworkStatusType::Declined)){ if($user->Benefits->CanReviewArtwork && $user->UserId != $this->SubmitterUserId && ($this->Status == Enums\ArtworkStatusType::Unverified || $this->Status == Enums\ArtworkStatusType::Declined)){
// Editors can change the status of artwork they did not submit themselves, and that is not yet approved. // Editors can change the status of artwork they did not submit themselves, and that is not yet approved.
return true; return true;
} }
@ -661,7 +661,7 @@ class Artwork{
* @throws Exceptions\InvalidImageUploadException * @throws Exceptions\InvalidImageUploadException
*/ */
public function Create(?string $imagePath = null): void{ public function Create(?string $imagePath = null): void{
$this->MimeType = ImageMimeType::FromFile($imagePath); $this->MimeType = Enums\ImageMimeType::FromFile($imagePath);
$this->Validate($imagePath, true); $this->Validate($imagePath, true);
@ -729,7 +729,7 @@ class Artwork{
$this->_UrlName = null; $this->_UrlName = null;
if($imagePath !== null){ if($imagePath !== null){
$this->MimeType = ImageMimeType::FromFile($imagePath); $this->MimeType = Enums\ImageMimeType::FromFile($imagePath);
// Manually set the updated timestamp, because if we only update the image and nothing else, the row's updated timestamp won't change automatically. // Manually set the updated timestamp, because if we only update the image and nothing else, the row's updated timestamp won't change automatically.
$this->Updated = NOW; $this->Updated = NOW;
@ -880,7 +880,7 @@ class Artwork{
$artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year'); $artwork->CompletedYear = HttpInput::Int(POST, 'artwork-year');
$artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa') ?? false; $artwork->CompletedYearIsCirca = HttpInput::Bool(POST, 'artwork-year-is-circa') ?? false;
$artwork->Tags = HttpInput::Str(POST, 'artwork-tags') ?? []; $artwork->Tags = HttpInput::Str(POST, 'artwork-tags') ?? [];
$artwork->Status = ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '') ?? ArtworkStatusType::Unverified; $artwork->Status = Enums\ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '') ?? Enums\ArtworkStatusType::Unverified;
$artwork->EbookUrl = HttpInput::Str(POST, 'artwork-ebook-url'); $artwork->EbookUrl = HttpInput::Str(POST, 'artwork-ebook-url');
$artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us') ?? false; $artwork->IsPublishedInUs = HttpInput::Bool(POST, 'artwork-is-published-in-us') ?? false;
$artwork->PublicationYear = HttpInput::Int(POST, 'artwork-publication-year'); $artwork->PublicationYear = HttpInput::Int(POST, 'artwork-publication-year');

View file

@ -4,7 +4,7 @@ use function Safe\preg_replace;
class ArtworkTag extends Tag{ class ArtworkTag extends Tag{
public function __construct(){ public function __construct(){
$this->Type = TagType::Artwork; $this->Type = Enums\TagType::Artwork;
} }
// ******* // *******
@ -45,7 +45,7 @@ class ArtworkTag extends Tag{
$error->Add(new Exceptions\InvalidArtworkTagNameException()); $error->Add(new Exceptions\InvalidArtworkTagNameException());
} }
if($this->Type != TagType::Artwork){ if($this->Type != Enums\TagType::Artwork){
$error->Add(new Exceptions\InvalidArtworkTagTypeException($this->Type)); $error->Add(new Exceptions\InvalidArtworkTagTypeException($this->Type));
} }
@ -77,7 +77,7 @@ class ArtworkTag extends Tag{
from Tags from Tags
where Name = ? where Name = ?
and Type = ? and Type = ?
', [$artworkTag->Name, TagType::Artwork], ArtworkTag::class); ', [$artworkTag->Name, Enums\TagType::Artwork], ArtworkTag::class);
if(isset($result[0])){ if(isset($result[0])){
return $result[0]; return $result[0];

View file

@ -10,7 +10,7 @@ class Collection{
public int $CollectionId; public int $CollectionId;
public string $Name; public string $Name;
public string $UrlName; public string $UrlName;
public ?CollectionType $Type = null; public ?Enums\CollectionType $Type = null;
protected ?string $_Url = null; protected ?string $_Url = null;
protected function GetUrl(): string{ protected function GetUrl(): string{
@ -85,7 +85,7 @@ class Collection{
$error->Add(new Exceptions\CollectionUrlNameRequiredException()); $error->Add(new Exceptions\CollectionUrlNameRequiredException());
} }
if($this->Type !== null && ($this->Type != CollectionType::Series && $this->Type != CollectionType::Set)){ if($this->Type !== null && ($this->Type != Enums\CollectionType::Series && $this->Type != Enums\CollectionType::Set)){
$error->Add(new Exceptions\InvalidCollectionTypeException($this->Type)); $error->Add(new Exceptions\InvalidCollectionTypeException($this->Type));
} }

View file

@ -775,7 +775,7 @@ class Ebook{
$cm->SequenceNumber = (int)$s; $cm->SequenceNumber = (int)$s;
} }
foreach($xml->xpath('/package/metadata/meta[@refines="#' . $id . '"][@property="collection-type"]') ?: [] as $s){ foreach($xml->xpath('/package/metadata/meta[@refines="#' . $id . '"][@property="collection-type"]') ?: [] as $s){
$cm->Collection->Type = CollectionType::tryFrom((string)$s) ?? CollectionType::Unknown; $cm->Collection->Type = Enums\CollectionType::tryFrom((string)$s) ?? Enums\CollectionType::Unknown;
} }
$collectionMemberships[] = $cm; $collectionMemberships[] = $cm;
} }
@ -901,32 +901,32 @@ class Ebook{
foreach($xml->xpath('/package/metadata/dc:source') ?: [] as $element){ foreach($xml->xpath('/package/metadata/dc:source') ?: [] as $element){
$ebookSource = new EbookSource(); $ebookSource = new EbookSource();
$ebookSource->Url = (string)$element; $ebookSource->Url = (string)$element;
$ebookSource->Type = EbookSourceType::Other; $ebookSource->Type = Enums\EbookSourceType::Other;
if(mb_stripos($ebookSource->Url, 'gutenberg.org/') !== false){ if(mb_stripos($ebookSource->Url, 'gutenberg.org/') !== false){
$ebookSource->Type = EbookSourceType::ProjectGutenberg; $ebookSource->Type = Enums\EbookSourceType::ProjectGutenberg;
} }
elseif(mb_stripos($ebookSource->Url, 'gutenberg.net.au/') !== false){ elseif(mb_stripos($ebookSource->Url, 'gutenberg.net.au/') !== false){
$ebookSource->Type = EbookSourceType::ProjectGutenbergAustralia; $ebookSource->Type = Enums\EbookSourceType::ProjectGutenbergAustralia;
} }
elseif(mb_stripos($ebookSource->Url, 'gutenberg.ca/') !== false){ elseif(mb_stripos($ebookSource->Url, 'gutenberg.ca/') !== false){
$ebookSource->Type = EbookSourceType::ProjectGutenbergCanada; $ebookSource->Type = Enums\EbookSourceType::ProjectGutenbergCanada;
} }
elseif(mb_stripos($ebookSource->Url, 'archive.org/details') !== false){ elseif(mb_stripos($ebookSource->Url, 'archive.org/details') !== false){
// `/details` excludes Wayback Machine URLs which may sometimes occur, for example in Lyrical Ballads. // `/details` excludes Wayback Machine URLs which may sometimes occur, for example in Lyrical Ballads.
$ebookSource->Type = EbookSourceType::InternetArchive; $ebookSource->Type = Enums\EbookSourceType::InternetArchive;
} }
elseif(mb_stripos($ebookSource->Url, 'hathitrust.org/') !== false){ elseif(mb_stripos($ebookSource->Url, 'hathitrust.org/') !== false){
$ebookSource->Type = EbookSourceType::HathiTrust; $ebookSource->Type = Enums\EbookSourceType::HathiTrust;
} }
elseif(mb_stripos($ebookSource->Url, 'wikisource.org/') !== false){ elseif(mb_stripos($ebookSource->Url, 'wikisource.org/') !== false){
$ebookSource->Type = EbookSourceType::Wikisource; $ebookSource->Type = Enums\EbookSourceType::Wikisource;
} }
elseif(mb_stripos($ebookSource->Url, 'books.google.com/') !== false || mb_stripos($ebookSource->Url, 'google.com/books/') !== false){ elseif(mb_stripos($ebookSource->Url, 'books.google.com/') !== false || mb_stripos($ebookSource->Url, 'google.com/books/') !== false){
$ebookSource->Type = EbookSourceType::GoogleBooks; $ebookSource->Type = Enums\EbookSourceType::GoogleBooks;
} }
elseif(mb_stripos($ebookSource->Url, 'www.fadedpage.com') !== false){ elseif(mb_stripos($ebookSource->Url, 'www.fadedpage.com') !== false){
$ebookSource->Type = EbookSourceType::FadedPage; $ebookSource->Type = Enums\EbookSourceType::FadedPage;
} }
$sources[] = $ebookSource; $sources[] = $ebookSource;

View file

@ -4,7 +4,7 @@ use Safe\DateTimeImmutable;
class EbookSource{ class EbookSource{
public ?int $EbookId = null; public ?int $EbookId = null;
public EbookSourceType $Type; public Enums\EbookSourceType $Type;
public string $Url; public string $Url;
public ?int $SortOrder = null; public ?int $SortOrder = null;

View file

@ -1,7 +1,7 @@
<? <?
class EbookTag extends Tag{ class EbookTag extends Tag{
public function __construct(){ public function __construct(){
$this->Type = TagType::Ebook; $this->Type = Enums\TagType::Ebook;
} }
// ******* // *******
@ -48,7 +48,7 @@ class EbookTag extends Tag{
$error->Add(new Exceptions\EbookTagNameRequiredException()); $error->Add(new Exceptions\EbookTagNameRequiredException());
} }
if($this->Type != TagType::Ebook){ if($this->Type != Enums\TagType::Ebook){
$error->Add(new Exceptions\InvalidEbookTagTypeException($this->Type)); $error->Add(new Exceptions\InvalidEbookTagTypeException($this->Type));
} }
@ -81,7 +81,7 @@ class EbookTag extends Tag{
from Tags from Tags
where Name = ? where Name = ?
and Type = ? and Type = ?
', [$name, TagType::Ebook], EbookTag::class); ', [$name, Enums\TagType::Ebook], EbookTag::class);
if(isset($result[0])){ if(isset($result[0])){
return $result[0]; return $result[0];

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum ArtworkSortType: string{ enum ArtworkSortType: string{
case CreatedNewest = 'created-newest'; case CreatedNewest = 'created-newest';
case ArtistAlpha = 'artist-alpha'; case ArtistAlpha = 'artist-alpha';

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum ArtworkStatusType: string{ enum ArtworkStatusType: string{
case Unverified = 'unverified'; case Unverified = 'unverified';
case Declined = 'declined'; case Declined = 'declined';

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum CollectionType: string{ enum CollectionType: string{
case Series = 'series'; case Series = 'series';
case Set = 'set'; case Set = 'set';

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum EbookFormatType: string{ enum EbookFormatType: string{
case Epub = 'epub'; case Epub = 'epub';
case Azw3 = 'azw3'; case Azw3 = 'azw3';

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum EbookSortType: string{ enum EbookSortType: string{
case Newest = 'newest'; case Newest = 'newest';
case AuthorAlpha = 'author-alpha'; case AuthorAlpha = 'author-alpha';

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum EbookSourceType: string{ enum EbookSourceType: string{
case ProjectGutenberg = 'project_gutenberg'; case ProjectGutenberg = 'project_gutenberg';
case ProjectGutenbergAustralia = 'project_gutenberg_australia'; case ProjectGutenbergAustralia = 'project_gutenberg_australia';

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
use function Safe\mime_content_type; use function Safe\mime_content_type;
enum ImageMimeType: string{ enum ImageMimeType: string{

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum PaymentProcessorType: string{ enum PaymentProcessorType: string{
case FracturedAtlas = 'fractured_atlas'; case FracturedAtlas = 'fractured_atlas';
} }

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum TagType: string{ enum TagType: string{
case Artwork = 'artwork'; case Artwork = 'artwork';
case Ebook = 'ebook'; case Ebook = 'ebook';

View file

@ -1,4 +1,6 @@
<? <?
namespace Enums;
enum ViewType: string{ enum ViewType: string{
case Grid = 'grid'; case Grid = 'grid';
case List = 'list'; case List = 'list';

View file

@ -1,13 +1,11 @@
<? <?
namespace Exceptions; namespace Exceptions;
use \TagType;
class InvalidArtworkTagTypeException extends AppException{ class InvalidArtworkTagTypeException extends AppException{
/** @var string $message */ /** @var string $message */
protected $message = 'Type should be `TagType::Artwork`.'; protected $message = 'Type should be `Enums\TagType::Artwork`.';
public function __construct(?TagType $tagType){ public function __construct(?\Enums\TagType $tagType){
if($tagType !== null){ if($tagType !== null){
$this->message .= ' Type provided: ' . $tagType->value; $this->message .= ' Type provided: ' . $tagType->value;
} }

View file

@ -1,14 +1,11 @@
<?php <?
namespace Exceptions; namespace Exceptions;
use \CollectionType;
class InvalidCollectionTypeException extends AppException{ class InvalidCollectionTypeException extends AppException{
/** @var string $message */ /** @var string $message */
protected $message = 'Collection type should be `series` or `set` according to the EPUB specification.'; protected $message = 'Collection type should be `series` or `set` according to the EPUB specification.';
public function __construct(?CollectionType $collectionType){ public function __construct(?\Enums\CollectionType $collectionType){
if($collectionType !== null){ if($collectionType !== null){
$this->message .= ' Type provided: ' . $collectionType->value; $this->message .= ' Type provided: ' . $collectionType->value;
} }

View file

@ -1,13 +1,11 @@
<? <?
namespace Exceptions; namespace Exceptions;
use \TagType;
class InvalidEbookTagTypeException extends AppException{ class InvalidEbookTagTypeException extends AppException{
/** @var string $message */ /** @var string $message */
protected $message = 'Type should be `TagType::Ebook`.'; protected $message = 'Type should be `Enums\TagType::Ebook`.';
public function __construct(?TagType $tagType){ public function __construct(?\Enums\TagType $tagType){
if($tagType !== null){ if($tagType !== null){
$this->message .= ' Type provided: ' . $tagType->value; $this->message .= ' Type provided: ' . $tagType->value;
} }

View file

@ -1,5 +1,4 @@
<?php <?
namespace Exceptions; namespace Exceptions;
class InvalidFileUploadException extends AppException{ class InvalidFileUploadException extends AppException{

View file

@ -1,5 +1,4 @@
<?php <?
namespace Exceptions; namespace Exceptions;
class InvalidImageUploadException extends AppException{ class InvalidImageUploadException extends AppException{

View file

@ -1,5 +1,4 @@
<?php <?
namespace Exceptions; namespace Exceptions;
class InvalidMimeTypeException extends AppException{ class InvalidMimeTypeException extends AppException{

View file

@ -8,11 +8,11 @@ use function Safe\unlink;
class Image{ class Image{
public string $Path; public string $Path;
public ?ImageMimeType $MimeType = null; public ?Enums\ImageMimeType $MimeType = null;
public function __construct(string $path){ public function __construct(string $path){
$this->Path = $path; $this->Path = $path;
$this->MimeType = ImageMimeType::FromFile($path); $this->MimeType = Enums\ImageMimeType::FromFile($path);
} }
/** /**
@ -22,16 +22,16 @@ class Image{
*/ */
private function GetImageHandle(){ private function GetImageHandle(){
switch($this->MimeType){ switch($this->MimeType){
case ImageMimeType::JPG: case Enums\ImageMimeType::JPG:
$handle = \Safe\imagecreatefromjpeg($this->Path); $handle = \Safe\imagecreatefromjpeg($this->Path);
break; break;
case ImageMimeType::BMP: case Enums\ImageMimeType::BMP:
$handle = \Safe\imagecreatefrombmp($this->Path); $handle = \Safe\imagecreatefrombmp($this->Path);
break; break;
case ImageMimeType::PNG: case Enums\ImageMimeType::PNG:
$handle = \Safe\imagecreatefrompng($this->Path); $handle = \Safe\imagecreatefrompng($this->Path);
break; break;
case ImageMimeType::TIFF: case Enums\ImageMimeType::TIFF:
$handle = $this->GetImageHandleFromTiff(); $handle = $this->GetImageHandleFromTiff();
break; break;
default: default:

View file

@ -16,7 +16,7 @@ class Library{
* @param array<string> $tags * @param array<string> $tags
* @return array{ebooks: array<Ebook>, ebooksCount: int} * @return array{ebooks: array<Ebook>, ebooksCount: int}
*/ */
public static function FilterEbooks(string $query = null, array $tags = [], EbookSortType $sort = null, int $page = 1, int $perPage = EBOOKS_PER_PAGE): array{ public static function FilterEbooks(string $query = null, array $tags = [], Enums\EbookSortType $sort = null, int $page = 1, int $perPage = EBOOKS_PER_PAGE): array{
$limit = $perPage; $limit = $perPage;
$offset = (($page - 1) * $perPage); $offset = (($page - 1) * $perPage);
$joinContributors = ''; $joinContributors = '';
@ -25,15 +25,15 @@ class Library{
$whereCondition = 'where true'; $whereCondition = 'where true';
$orderBy = 'e.EbookCreated desc'; $orderBy = 'e.EbookCreated desc';
if($sort == EbookSortType::AuthorAlpha){ if($sort == Enums\EbookSortType::AuthorAlpha){
$joinContributors = 'inner join Contributors con using (EbookId)'; $joinContributors = 'inner join Contributors con using (EbookId)';
$whereCondition .= ' AND con.MarcRole = "aut"'; $whereCondition .= ' AND con.MarcRole = "aut"';
$orderBy = 'con.SortName, e.EbookCreated desc'; $orderBy = 'con.SortName, e.EbookCreated desc';
} }
elseif($sort == EbookSortType::ReadingEase){ elseif($sort == Enums\EbookSortType::ReadingEase){
$orderBy = 'e.ReadingEase desc'; $orderBy = 'e.ReadingEase desc';
} }
elseif($sort == EbookSortType::Length){ elseif($sort == Enums\EbookSortType::Length){
$orderBy = 'e.WordCount'; $orderBy = 'e.WordCount';
} }
@ -200,7 +200,7 @@ class Library{
/** /**
* @return array{artworks: array<Artwork>, artworksCount: int} * @return array{artworks: array<Artwork>, artworksCount: int}
*/ */
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{ public static function FilterArtwork(?string $query = null, ?string $status = null, ?Enums\ArtworkSortType $sort = null, ?int $submitterUserId = null, int $page = 1, int $perPage = ARTWORK_PER_PAGE): array{
// $status is either the string value of an ArtworkStatus enum, or one of these special statuses: // $status is either the string value of an ArtworkStatus enum, or one of these special statuses:
// null: same as "all" // null: same as "all"
// "all": Show all approved and in use artwork // "all": Show all approved and in use artwork
@ -214,29 +214,29 @@ class Library{
if($status === null || $status == 'all'){ if($status === null || $status == 'all'){
$statusCondition = 'Status = ?'; $statusCondition = 'Status = ?';
$params[] = ArtworkStatusType::Approved->value; $params[] = Enums\ArtworkStatusType::Approved->value;
} }
elseif($status == 'all-admin'){ elseif($status == 'all-admin'){
$statusCondition = 'true'; $statusCondition = 'true';
} }
elseif($status == 'all-submitter' && $submitterUserId !== null){ elseif($status == 'all-submitter' && $submitterUserId !== null){
$statusCondition = '(Status = ? or (Status = ? and SubmitterUserId = ?))'; $statusCondition = '(Status = ? or (Status = ? and SubmitterUserId = ?))';
$params[] = ArtworkStatusType::Approved->value; $params[] = Enums\ArtworkStatusType::Approved->value;
$params[] = ArtworkStatusType::Unverified->value; $params[] = Enums\ArtworkStatusType::Unverified->value;
$params[] = $submitterUserId; $params[] = $submitterUserId;
} }
elseif($status == 'unverified-submitter' && $submitterUserId !== null){ elseif($status == 'unverified-submitter' && $submitterUserId !== null){
$statusCondition = 'Status = ? and SubmitterUserId = ?'; $statusCondition = 'Status = ? and SubmitterUserId = ?';
$params[] = ArtworkStatusType::Unverified->value; $params[] = Enums\ArtworkStatusType::Unverified->value;
$params[] = $submitterUserId; $params[] = $submitterUserId;
} }
elseif($status == 'in-use'){ elseif($status == 'in-use'){
$statusCondition = 'Status = ? and EbookUrl is not null'; $statusCondition = 'Status = ? and EbookUrl is not null';
$params[] = ArtworkStatusType::Approved->value; $params[] = Enums\ArtworkStatusType::Approved->value;
} }
elseif($status == ArtworkStatusType::Approved->value){ elseif($status == Enums\ArtworkStatusType::Approved->value){
$statusCondition = 'Status = ? and EbookUrl is null'; $statusCondition = 'Status = ? and EbookUrl is null';
$params[] = ArtworkStatusType::Approved->value; $params[] = Enums\ArtworkStatusType::Approved->value;
} }
else{ else{
$statusCondition = 'Status = ?'; $statusCondition = 'Status = ?';
@ -244,10 +244,10 @@ class Library{
} }
$orderBy = 'art.Created desc'; $orderBy = 'art.Created desc';
if($sort == ArtworkSortType::ArtistAlpha){ if($sort == Enums\ArtworkSortType::ArtistAlpha){
$orderBy = 'a.Name'; $orderBy = 'a.Name';
} }
elseif($sort == ArtworkSortType::CompletedNewest){ elseif($sort == Enums\ArtworkSortType::CompletedNewest){
$orderBy = 'art.CompletedYear desc'; $orderBy = 'art.CompletedYear desc';
} }
@ -364,13 +364,13 @@ class Library{
} }
elseif($status == 'all-submitter' && $submitterUserId !== null){ elseif($status == 'all-submitter' && $submitterUserId !== null){
$statusCondition = '(Status = ? or (Status = ? and SubmitterUserId = ?))'; $statusCondition = '(Status = ? or (Status = ? and SubmitterUserId = ?))';
$params[] = ArtworkStatusType::Approved->value; $params[] = Enums\ArtworkStatusType::Approved->value;
$params[] = ArtworkStatusType::Unverified->value; $params[] = Enums\ArtworkStatusType::Unverified->value;
$params[] = $submitterUserId; $params[] = $submitterUserId;
} }
else{ else{
$statusCondition = 'Status = ?'; $statusCondition = 'Status = ?';
$params[] = ArtworkStatusType::Approved->value; $params[] = Enums\ArtworkStatusType::Approved->value;
} }
$params[] = $artistUrlName; // a.UrlName $params[] = $artistUrlName; // a.UrlName

View file

@ -10,7 +10,7 @@ class Payment{
public int $PaymentId; public int $PaymentId;
public ?int $UserId = null; public ?int $UserId = null;
public DateTimeImmutable $Created; public DateTimeImmutable $Created;
public PaymentProcessorType $Processor; public Enums\PaymentProcessorType $Processor;
public string $TransactionId; public string $TransactionId;
public float $Amount; public float $Amount;
public float $Fee; public float $Fee;

View file

@ -8,7 +8,7 @@ class Tag{
public int $TagId; public int $TagId;
public string $Name; public string $Name;
public TagType $Type; public Enums\TagType $Type;
protected ?string $_UrlName = null; protected ?string $_UrlName = null;
protected ?string $_Url = null; protected ?string $_Url = null;
} }

View file

@ -73,7 +73,7 @@ function InsertTransaction(string $transactionId): bool{
values (utc_timestamp(), values (utc_timestamp(),
?, ?,
?)', ?)',
[PaymentProcessorType::FracturedAtlas, $transactionId]); [Enums\PaymentProcessorType::FracturedAtlas, $transactionId]);
return true; return true;
} }

View file

@ -69,9 +69,9 @@ try{
$driver = FirefoxDriver::start($capabilities); $driver = FirefoxDriver::start($capabilities);
foreach($pendingPayments as $pendingPayment){ foreach($pendingPayments as $pendingPayment){
$pendingPayment->Processor = PaymentProcessorType::from($pendingPayment->Processor); $pendingPayment->Processor = Enums\PaymentProcessorType::from($pendingPayment->Processor);
switch($pendingPayment->Processor){ switch($pendingPayment->Processor){
case PaymentProcessorType::FracturedAtlas: case Enums\PaymentProcessorType::FracturedAtlas:
$log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...'); $log->Write('Processing donation ' . $pendingPayment->TransactionId . ' ...');
if(Db::QueryBool(' if(Db::QueryBool('

View file

@ -87,7 +87,7 @@ $isEditForm = $isEditForm ?? false;
type="file" type="file"
name="artwork-image" name="artwork-image"
<? if(!$isEditForm){ ?>required="required"<? } ?> <? if(!$isEditForm){ ?>required="required"<? } ?>
accept="<?= implode(',', ImageMimeType::Values()) ?>" accept="<?= implode(',', Enums\ImageMimeType::Values()) ?>"
/> />
</label> </label>
</fieldset> </fieldset>
@ -179,9 +179,9 @@ $isEditForm = $isEditForm ?? false;
<span>Artwork approval status</span> <span>Artwork approval status</span>
<span> <span>
<select name="artwork-status"> <select name="artwork-status">
<option value="<?= ArtworkStatusType::Unverified->value ?>"<? if($artwork->Status == ArtworkStatusType::Unverified){ ?> selected="selected"<? } ?>>Unverified</option> <option value="<?= Enums\ArtworkStatusType::Unverified->value ?>"<? if($artwork->Status == Enums\ArtworkStatusType::Unverified){ ?> selected="selected"<? } ?>>Unverified</option>
<option value="<?= ArtworkStatusType::Declined->value ?>"<? if($artwork->Status == ArtworkStatusType::Declined){ ?> selected="selected"<? } ?>>Declined</option> <option value="<?= Enums\ArtworkStatusType::Declined->value ?>"<? if($artwork->Status == Enums\ArtworkStatusType::Declined){ ?> selected="selected"<? } ?>>Declined</option>
<option value="<?= ArtworkStatusType::Approved->value ?>"<? if($artwork->Status == ArtworkStatusType::Approved){ ?> selected="selected"<? } ?>>Approved</option> <option value="<?= Enums\ArtworkStatusType::Approved->value ?>"<? if($artwork->Status == Enums\ArtworkStatusType::Approved){ ?> selected="selected"<? } ?>>Approved</option>
</select> </select>
</span> </span>
</label> </label>

View file

@ -13,11 +13,11 @@
} }
switch($artwork->Status){ switch($artwork->Status){
case ArtworkStatusType::Unverified: case Enums\ArtworkStatusType::Unverified:
$class .= ' unverified'; $class .= ' unverified';
break; break;
case ArtworkStatusType::Declined: case Enums\ArtworkStatusType::Declined:
$class .= ' declined'; $class .= ' declined';
break; break;
} }

View file

@ -4,10 +4,10 @@
* @var array<Ebook> $ebooks * @var array<Ebook> $ebooks
*/ */
$view = $view ?? ViewType::Grid; $view = $view ?? Enums\ViewType::Grid;
$collection = $collection ?? null; $collection = $collection ?? null;
?> ?>
<ol class="ebooks-list<? if($view == ViewType::List){ ?> list<? }else{ ?> grid<? } ?>"<? if($collection !== null){ ?> typeof="schema:BookSeries" about="<?= $collection->Url ?>"<? } ?>> <ol class="ebooks-list<? if($view == Enums\ViewType::List){ ?> list<? }else{ ?> grid<? } ?>"<? if($collection !== null){ ?> typeof="schema:BookSeries" about="<?= $collection->Url ?>"<? } ?>>
<? if($collection !== null){ ?> <? if($collection !== null){ ?>
<meta property="schema:name" content="<?= Formatter::EscapeHtml($collection->Name) ?>"/> <meta property="schema:name" content="<?= Formatter::EscapeHtml($collection->Name) ?>"/>
<? } ?> <? } ?>
@ -26,7 +26,7 @@ $collection = $collection ?? null;
</a> </a>
</div> </div>
<p><a href="<?= $ebook->Url ?>" property="schema:url"><span property="schema:name"><?= Formatter::EscapeHtml($ebook->Title) ?></span></a></p> <p><a href="<?= $ebook->Url ?>" property="schema:url"><span property="schema:name"><?= Formatter::EscapeHtml($ebook->Title) ?></span></a></p>
<? if($view == ViewType::Grid){ ?> <? if($view == Enums\ViewType::Grid){ ?>
<? foreach($ebook->Authors as $author){ ?> <? foreach($ebook->Authors as $author){ ?>
<p class="author" typeof="schema:Person" property="schema:author" resource="<?= $ebook->AuthorsUrl ?>"><? if($author->Name != 'Anonymous'){ ?><a href="<?= Formatter::EscapeHtml(SITE_URL . $ebook->AuthorsUrl) ?>" property="schema:url"><span property="schema:name"><?= Formatter::EscapeHtml($author->Name) ?></span></a><? } ?></p> <p class="author" typeof="schema:Person" property="schema:author" resource="<?= $ebook->AuthorsUrl ?>"><? if($author->Name != 'Anonymous'){ ?><a href="<?= Formatter::EscapeHtml(SITE_URL . $ebook->AuthorsUrl) ?>" property="schema:url"><span property="schema:name"><?= Formatter::EscapeHtml($author->Name) ?></span></a><? } ?></p>
<? } ?> <? } ?>

View file

@ -1,8 +1,8 @@
<? <?
/** /**
* @var array<string> $tags * @var array<string> $tags
* @var EbookSortType $sort * @var Enums\EbookSortType $sort
* @var ViewType $view * @var Enums\ViewType $view
* @var int $perPage * @var int $perPage
*/ */
@ -24,10 +24,10 @@ $isAllSelected = sizeof($tags) == 0 || in_array('all', $tags);
<span>Sort</span> <span>Sort</span>
<span> <span>
<select name="sort"> <select name="sort">
<option value="<?= EbookSortType::Newest->value ?>"<? if($sort == EbookSortType::Newest){ ?> selected="selected"<? } ?>>S.E. release date (new &#x2192; old)</option> <option value="<?= Enums\EbookSortType::Newest->value ?>"<? if($sort == Enums\EbookSortType::Newest){ ?> selected="selected"<? } ?>>S.E. release date (new &#x2192; old)</option>
<option value="<?= EbookSortType::AuthorAlpha->value ?>"<? if($sort == EbookSortType::AuthorAlpha){ ?> selected="selected"<? } ?>>Author name (a &#x2192; z)</option> <option value="<?= Enums\EbookSortType::AuthorAlpha->value ?>"<? if($sort == Enums\EbookSortType::AuthorAlpha){ ?> selected="selected"<? } ?>>Author name (a &#x2192; z)</option>
<option value="<?= EbookSortType::ReadingEase->value ?>"<? if($sort == EbookSortType::ReadingEase){ ?> selected="selected"<? } ?>>Reading ease (easy &#x2192; hard)</option> <option value="<?= Enums\EbookSortType::ReadingEase->value ?>"<? if($sort == Enums\EbookSortType::ReadingEase){ ?> selected="selected"<? } ?>>Reading ease (easy &#x2192; hard)</option>
<option value="<?= EbookSortType::Length->value ?>"<? if($sort == EbookSortType::Length){ ?> selected="selected"<? } ?>>Length (short &#x2192; long)</option> <option value="<?= Enums\EbookSortType::Length->value ?>"<? if($sort == Enums\EbookSortType::Length){ ?> selected="selected"<? } ?>>Length (short &#x2192; long)</option>
</select> </select>
</span> </span>
</label> </label>
@ -35,8 +35,8 @@ $isAllSelected = sizeof($tags) == 0 || in_array('all', $tags);
<span>View</span> <span>View</span>
<span> <span>
<select name="view"> <select name="view">
<option value="<?= ViewType::Grid->value ?>"<? if($view == ViewType::Grid){ ?> selected="selected"<? } ?>>Grid</option> <option value="<?= Enums\ViewType::Grid->value ?>"<? if($view == Enums\ViewType::Grid){ ?> selected="selected"<? } ?>>Grid</option>
<option value="<?= ViewType::List->value ?>"<? if($view == ViewType::List){ ?> selected="selected"<? } ?>>List</option> <option value="<?= Enums\ViewType::List->value ?>"<? if($view == Enums\ViewType::List){ ?> selected="selected"<? } ?>>List</option>
</select> </select>
</span> </span>
</label> </label>

View file

@ -33,9 +33,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 the artwork is not approved, and we're not an admin or the submitter when they can edit, don't show it.
if( if(
($GLOBALS['User'] === null && $artwork->Status != ArtworkStatusType::Approved) ($GLOBALS['User'] === null && $artwork->Status != Enums\ArtworkStatusType::Approved)
|| ||
($GLOBALS['User'] !== null && $artwork->Status != ArtworkStatusType::Approved && $artwork->SubmitterUserId != $GLOBALS['User']->UserId && !$isReviewerView) ($GLOBALS['User'] !== null && $artwork->Status != Enums\ArtworkStatusType::Approved && $artwork->SubmitterUserId != $GLOBALS['User']->UserId && !$isReviewerView)
){ ){
throw new Exceptions\InvalidPermissionsException(); throw new Exceptions\InvalidPermissionsException();
} }
@ -182,9 +182,9 @@ catch(Exceptions\InvalidPermissionsException){
<span>Artwork approval status</span> <span>Artwork approval status</span>
<span> <span>
<select name="artwork-status"> <select name="artwork-status">
<option value="<?= ArtworkStatusType::Unverified->value ?>"<? if($artwork->Status == ArtworkStatusType::Unverified){ ?> selected="selected"<? } ?>>Unverified</option> <option value="<?= Enums\ArtworkStatusType::Unverified->value ?>"<? if($artwork->Status == Enums\ArtworkStatusType::Unverified){ ?> selected="selected"<? } ?>>Unverified</option>
<option value="<?= ArtworkStatusType::Declined->value ?>"<? if($artwork->Status == ArtworkStatusType::Declined){ ?> selected="selected"<? } ?>>Declined</option> <option value="<?= Enums\ArtworkStatusType::Declined->value ?>"<? if($artwork->Status == Enums\ArtworkStatusType::Declined){ ?> selected="selected"<? } ?>>Declined</option>
<option value="<?= ArtworkStatusType::Approved->value ?>"<? if($artwork->Status == ArtworkStatusType::Approved){ ?> selected="selected"<? } ?>>Approved</option> <option value="<?= Enums\ArtworkStatusType::Approved->value ?>"<? if($artwork->Status == Enums\ArtworkStatusType::Approved){ ?> selected="selected"<? } ?>>Approved</option>
</select> </select>
</span> </span>
</label> </label>

View file

@ -5,7 +5,7 @@ $query = HttpInput::Str(GET, 'query');
$queryEbookUrl = HttpInput::Str(GET, 'query-ebook-url'); $queryEbookUrl = HttpInput::Str(GET, 'query-ebook-url');
$status = HttpInput::Str(GET, 'status'); $status = HttpInput::Str(GET, 'status');
$filterArtworkStatus = $status; $filterArtworkStatus = $status;
$sort = ArtworkSortType::tryFrom(HttpInput::Str(GET, 'sort') ?? ''); $sort = Enums\ArtworkSortType::tryFrom(HttpInput::Str(GET, 'sort') ?? '');
$pages = 0; $pages = 0;
$totalArtworkCount = 0; $totalArtworkCount = 0;
$pageDescription = ''; $pageDescription = '';
@ -26,7 +26,7 @@ try{
// If we're passed string values that are the same as the defaults, // 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 // set them to null so that we can have cleaner query strings in the navigation footer
if($sort == ArtworkSortType::CreatedNewest){ if($sort == Enums\ArtworkSortType::CreatedNewest){
$sort = null; $sort = null;
} }
@ -45,25 +45,25 @@ try{
} }
} }
if(!$isReviewerView && !$isSubmitterView && !in_array($status, array('all', ArtworkStatusType::Approved->value, 'in-use'))){ if(!$isReviewerView && !$isSubmitterView && !in_array($status, array('all', Enums\ArtworkStatusType::Approved->value, 'in-use'))){
$status = ArtworkStatusType::Approved->value; $status = Enums\ArtworkStatusType::Approved->value;
$filterArtworkStatus = $status; $filterArtworkStatus = $status;
} }
if($isReviewerView && !in_array($status, array('all', ArtworkStatusType::Unverified->value, ArtworkStatusType::Declined->value, ArtworkStatusType::Approved->value, 'in-use')) if($isReviewerView && !in_array($status, array('all', Enums\ArtworkStatusType::Unverified->value, Enums\ArtworkStatusType::Declined->value, Enums\ArtworkStatusType::Approved->value, 'in-use'))
&& !in_array($filterArtworkStatus, array('all-admin', ArtworkStatusType::Unverified->value, ArtworkStatusType::Declined->value, ArtworkStatusType::Approved->value, 'in-use'))){ && !in_array($filterArtworkStatus, array('all-admin', Enums\ArtworkStatusType::Unverified->value, Enums\ArtworkStatusType::Declined->value, Enums\ArtworkStatusType::Approved->value, 'in-use'))){
$status = ArtworkStatusType::Approved->value; $status = Enums\ArtworkStatusType::Approved->value;
$filterArtworkStatus = $status; $filterArtworkStatus = $status;
} }
if($isSubmitterView && !in_array($status, array('all', ArtworkStatusType::Unverified->value, ArtworkStatusType::Approved->value, 'in-use')) if($isSubmitterView && !in_array($status, array('all', Enums\ArtworkStatusType::Unverified->value, Enums\ArtworkStatusType::Approved->value, 'in-use'))
&& !in_array($filterArtworkStatus, array('all-submitter', 'unverified-submitter', ArtworkStatusType::Approved->value, 'in-use'))){ && !in_array($filterArtworkStatus, array('all-submitter', 'unverified-submitter', Enums\ArtworkStatusType::Approved->value, 'in-use'))){
$status = ArtworkStatusType::Approved->value; $status = Enums\ArtworkStatusType::Approved->value;
$filterArtworkStatus = $status; $filterArtworkStatus = $status;
} }
if($queryEbookUrl !== null){ if($queryEbookUrl !== null){
$artworks = Db::Query('SELECT * from Artworks where EbookUrl = ? and Status = ? limit 1', [$queryEbookUrl, ArtworkStatusType::Approved], Artwork::class); $artworks = Db::Query('SELECT * from Artworks where EbookUrl = ? and Status = ? limit 1', [$queryEbookUrl, Enums\ArtworkStatusType::Approved], Artwork::class);
$totalArtworkCount = sizeof($artworks); $totalArtworkCount = sizeof($artworks);
} }
else{ else{
@ -139,9 +139,9 @@ catch(Exceptions\PageOutOfBoundsException){
<span> <span>
<select name="status" size="1"> <select name="status" size="1">
<option value="all"<? if($status === null){ ?> selected="selected"<? } ?>>All</option> <option value="all"<? if($status === null){ ?> selected="selected"<? } ?>>All</option>
<? if($isReviewerView || $isSubmitterView){ ?><option value="<?= ArtworkStatusType::Unverified->value ?>"<? if($status == ArtworkStatusType::Unverified->value){ ?> selected="selected"<? } ?>>Unverified</option><? } ?> <? if($isReviewerView || $isSubmitterView){ ?><option value="<?= Enums\ArtworkStatusType::Unverified->value ?>"<? if($status == Enums\ArtworkStatusType::Unverified->value){ ?> selected="selected"<? } ?>>Unverified</option><? } ?>
<? if($isReviewerView){ ?><option value="<?= ArtworkStatusType::Declined->value ?>"<? if($status == ArtworkStatusType::Declined->value){ ?> selected="selected"<? } ?>>Declined</option><? } ?> <? if($isReviewerView){ ?><option value="<?= Enums\ArtworkStatusType::Declined->value ?>"<? if($status == Enums\ArtworkStatusType::Declined->value){ ?> selected="selected"<? } ?>>Declined</option><? } ?>
<option value="<?= ArtworkStatusType::Approved->value ?>"<? if($status == ArtworkStatusType::Approved->value){ ?> selected="selected"<? } ?>>Approved, not in use</option> <option value="<?= Enums\ArtworkStatusType::Approved->value ?>"<? if($status == Enums\ArtworkStatusType::Approved->value){ ?> selected="selected"<? } ?>>Approved, not in use</option>
<option value="in-use"<? if($status == 'in-use'){ ?> selected="selected"<? } ?>>In use</option> <option value="in-use"<? if($status == 'in-use'){ ?> selected="selected"<? } ?>>In use</option>
</select> </select>
</span> </span>
@ -153,9 +153,9 @@ catch(Exceptions\PageOutOfBoundsException){
<span>Sort</span> <span>Sort</span>
<span> <span>
<select name="sort"> <select name="sort">
<option value="<?= ArtworkSortType::CreatedNewest->value ?>"<? if($sort == ArtworkSortType::CreatedNewest){ ?> selected="selected"<? } ?>>Date added (new &#x2192; old)</option> <option value="<?= Enums\ArtworkSortType::CreatedNewest->value ?>"<? if($sort == Enums\ArtworkSortType::CreatedNewest){ ?> selected="selected"<? } ?>>Date added (new &#x2192; old)</option>
<option value="<?= ArtworkSortType::ArtistAlpha->value ?>"<? if($sort == ArtworkSortType::ArtistAlpha){ ?> selected="selected"<? } ?>>Artist name (a &#x2192; z)</option> <option value="<?= Enums\ArtworkSortType::ArtistAlpha->value ?>"<? if($sort == Enums\ArtworkSortType::ArtistAlpha){ ?> selected="selected"<? } ?>>Artist name (a &#x2192; z)</option>
<option value="<?= ArtworkSortType::CompletedNewest->value ?>"<? if($sort == ArtworkSortType::CompletedNewest){ ?> selected="selected"<? } ?>>Date of artwork completion (new &#x2192; old)</option> <option value="<?= Enums\ArtworkSortType::CompletedNewest->value ?>"<? if($sort == Enums\ArtworkSortType::CompletedNewest){ ?> selected="selected"<? } ?>>Date of artwork completion (new &#x2192; old)</option>
</select> </select>
</span> </span>
</label> </label>

View file

@ -36,7 +36,7 @@ try{
$artwork->Artist = new Artist(); $artwork->Artist = new Artist();
if($GLOBALS['User']->Benefits->CanReviewOwnArtwork){ if($GLOBALS['User']->Benefits->CanReviewOwnArtwork){
$artwork->Status = ArtworkStatusType::Approved; $artwork->Status = Enums\ArtworkStatusType::Approved;
} }
} }
} }

View file

@ -24,12 +24,12 @@ try{
// Only approved reviewers can set the status to anything but unverified when uploading. // 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. // The submitter cannot review their own submissions unless they have special permission.
if($artwork->Status !== ArtworkStatusType::Unverified && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){ if($artwork->Status !== Enums\ArtworkStatusType::Unverified && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){
throw new Exceptions\InvalidPermissionsException(); throw new Exceptions\InvalidPermissionsException();
} }
// If the artwork is approved, set the reviewer // If the artwork is approved, set the reviewer
if($artwork->Status !== ArtworkStatusType::Unverified){ if($artwork->Status !== Enums\ArtworkStatusType::Unverified){
$artwork->ReviewerUserId = $GLOBALS['User']->UserId; $artwork->ReviewerUserId = $GLOBALS['User']->UserId;
} }
@ -58,7 +58,7 @@ try{
$artwork->SubmitterUserId = $originalArtwork->SubmitterUserId; $artwork->SubmitterUserId = $originalArtwork->SubmitterUserId;
$artwork->Status = $originalArtwork->Status; // Overwrite any value got from POST because we need permission to change the status $artwork->Status = $originalArtwork->Status; // Overwrite any value got from POST because we need permission to change the status
$newStatus = ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? ''); $newStatus = Enums\ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '');
if($newStatus !== null){ if($newStatus !== null){
if($originalArtwork->Status != $newStatus && !$originalArtwork->CanStatusBeChangedBy($GLOBALS['User'])){ if($originalArtwork->Status != $newStatus && !$originalArtwork->CanStatusBeChangedBy($GLOBALS['User'])){
throw new Exceptions\InvalidPermissionsException(); throw new Exceptions\InvalidPermissionsException();
@ -89,7 +89,7 @@ try{
// We can PATCH the status, the ebook www filesystem path, or both. // We can PATCH the status, the ebook www filesystem path, or both.
if(isset($_POST['artwork-status'])){ if(isset($_POST['artwork-status'])){
$newStatus = ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? ''); $newStatus = Enums\ArtworkStatusType::tryFrom(HttpInput::Str(POST, 'artwork-status') ?? '');
if($newStatus !== null){ if($newStatus !== null){
if($artwork->Status != $newStatus && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){ if($artwork->Status != $newStatus && !$artwork->CanStatusBeChangedBy($GLOBALS['User'])){
throw new Exceptions\InvalidPermissionsException(); throw new Exceptions\InvalidPermissionsException();

View file

@ -50,7 +50,7 @@ catch(Exceptions\CollectionNotFoundException){
<? if(sizeof($ebooks) == 0){ ?> <? if(sizeof($ebooks) == 0){ ?>
<p class="no-results">No ebooks matched your filters. You can try different filters, or <a href="/ebooks">browse all of our ebooks</a>.</p> <p class="no-results">No ebooks matched your filters. You can try different filters, or <a href="/ebooks">browse all of our ebooks</a>.</p>
<? }else{ ?> <? }else{ ?>
<?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => ViewType::Grid, 'collection' => $collectionObject]) ?> <?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => Enums\ViewType::Grid, 'collection' => $collectionObject]) ?>
<? } ?> <? } ?>
<p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p> <p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p>

View file

@ -31,7 +31,7 @@ catch(Exceptions\AuthorNotFoundException){
<a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/downloads">Download collection</a> <a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/downloads">Download collection</a>
<a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/feeds">Feeds for this author</a> <a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/feeds">Feeds for this author</a>
</p> </p>
<?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => ViewType::Grid]) ?> <?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => Enums\ViewType::Grid]) ?>
<p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p> <p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p>
<?= Template::ContributeAlert() ?> <?= Template::ContributeAlert() ?>
</main> </main>

View file

@ -13,21 +13,21 @@ try{
$identifier = EBOOKS_IDENTIFIER_PREFIX . $urlPath; $identifier = EBOOKS_IDENTIFIER_PREFIX . $urlPath;
$ebook = Ebook::GetByIdentifier($identifier); $ebook = Ebook::GetByIdentifier($identifier);
$format = EbookFormatType::tryFrom(HttpInput::Str(GET, 'format') ?? '') ?? EbookFormatType::Epub; $format = Enums\EbookFormatType::tryFrom(HttpInput::Str(GET, 'format') ?? '') ?? Enums\EbookFormatType::Epub;
switch($format){ switch($format){
case EbookFormatType::Kepub: case Enums\EbookFormatType::Kepub:
$downloadUrl = $ebook->KepubUrl; $downloadUrl = $ebook->KepubUrl;
break; break;
case EbookFormatType::Azw3: case Enums\EbookFormatType::Azw3:
$downloadUrl = $ebook->Azw3Url; $downloadUrl = $ebook->Azw3Url;
break; break;
case EbookFormatType::AdvancedEpub: case Enums\EbookFormatType::AdvancedEpub:
$downloadUrl = $ebook->AdvancedEpubUrl; $downloadUrl = $ebook->AdvancedEpubUrl;
break; break;
case EbookFormatType::Epub: case Enums\EbookFormatType::Epub:
default: default:
$downloadUrl = $ebook->EpubUrl; $downloadUrl = $ebook->EpubUrl;
break; break;

View file

@ -45,21 +45,21 @@ try{
// Divide our sources into transcriptions and scans. // Divide our sources into transcriptions and scans.
foreach($ebook->Sources as $source){ foreach($ebook->Sources as $source){
switch($source->Type){ switch($source->Type){
case EbookSourceType::ProjectGutenberg: case Enums\EbookSourceType::ProjectGutenberg:
case EbookSourceType::ProjectGutenbergAustralia: case Enums\EbookSourceType::ProjectGutenbergAustralia:
case EbookSourceType::ProjectGutenbergCanada: case Enums\EbookSourceType::ProjectGutenbergCanada:
case EbookSourceType::Wikisource: case Enums\EbookSourceType::Wikisource:
case EbookSourceType::FadedPage: case Enums\EbookSourceType::FadedPage:
$transcriptionSources[] = $source; $transcriptionSources[] = $source;
break; break;
case EbookSourceType::InternetArchive: case Enums\EbookSourceType::InternetArchive:
case EbookSourceType::HathiTrust: case Enums\EbookSourceType::HathiTrust:
case EbookSourceType::GoogleBooks: case Enums\EbookSourceType::GoogleBooks:
$scanSources[] = $source; $scanSources[] = $source;
break; break;
case EbookSourceType::Other: case Enums\EbookSourceType::Other:
$otherSources[] = $source; $otherSources[] = $source;
break; break;
} }
@ -223,7 +223,7 @@ catch(Exceptions\EbookNotFoundException){
<meta property="schema:description" content="epub"/> <meta property="schema:description" content="epub"/>
<meta property="schema:encodingFormat" content="application/epub+zip"/> <meta property="schema:encodingFormat" content="application/epub+zip"/>
<p> <p>
<span><a property="schema:contentUrl" rel="nofollow" href="<?= $ebook->Url ?>/download?format=<?= EbookFormatType::Epub->value ?>" class="epub">Compatible epub</a></span> <span></span> <span>All devices and apps except Kindles and Kobos.</span> <span><a property="schema:contentUrl" rel="nofollow" href="<?= $ebook->Url ?>/download?format=<?= Enums\EbookFormatType::Epub->value ?>" class="epub">Compatible epub</a></span> <span></span> <span>All devices and apps except Kindles and Kobos.</span>
</p> </p>
</li> </li>
<? } ?> <? } ?>
@ -232,7 +232,7 @@ catch(Exceptions\EbookNotFoundException){
<li property="schema:encoding" typeof="schema:MediaObject"> <li property="schema:encoding" typeof="schema:MediaObject">
<meta property="schema:encodingFormat" content="application/x-mobipocket-ebook"/> <meta property="schema:encodingFormat" content="application/x-mobipocket-ebook"/>
<p> <p>
<span><a property="schema:contentUrl" rel="nofollow" href="<?= $ebook->Url ?>/download?format=<?= EbookFormatType::Azw3->value ?>" class="amazon"><span property="schema:description">azw3</span></a></span> <span></span> <span>Kindle devices and apps.<? if($ebook->KindleCoverUrl !== null){ ?> Also download the <a href="<?= $ebook->KindleCoverUrl ?>">Kindle cover thumbnail</a> to see the cover in your Kindles library. Despite what youve been told, <a href="/help/how-to-use-our-ebooks#kindle-epub">Kindle does not natively support epub.</a> You may also be interested in our <a href="/help/how-to-use-our-ebooks#kindle-faq">Kindle FAQ</a>.<? }else{ ?> Also see our <a href="/how-to-use-our-ebooks#kindle-faq">Kindle FAQ</a>.<? } ?></span> <span><a property="schema:contentUrl" rel="nofollow" href="<?= $ebook->Url ?>/download?format=<?= Enums\EbookFormatType::Azw3->value ?>" class="amazon"><span property="schema:description">azw3</span></a></span> <span></span> <span>Kindle devices and apps.<? if($ebook->KindleCoverUrl !== null){ ?> Also download the <a href="<?= $ebook->KindleCoverUrl ?>">Kindle cover thumbnail</a> to see the cover in your Kindles library. Despite what youve been told, <a href="/help/how-to-use-our-ebooks#kindle-epub">Kindle does not natively support epub.</a> You may also be interested in our <a href="/help/how-to-use-our-ebooks#kindle-faq">Kindle FAQ</a>.<? }else{ ?> Also see our <a href="/how-to-use-our-ebooks#kindle-faq">Kindle FAQ</a>.<? } ?></span>
</p> </p>
</li> </li>
<? } ?> <? } ?>
@ -241,7 +241,7 @@ catch(Exceptions\EbookNotFoundException){
<li property="schema:encoding" typeof="schema:MediaObject"> <li property="schema:encoding" typeof="schema:MediaObject">
<meta property="schema:encodingFormat" content="application/kepub+zip"/> <meta property="schema:encodingFormat" content="application/kepub+zip"/>
<p> <p>
<span><a property="schema:contentUrl" rel="nofollow" href="<?= $ebook->Url ?>/download?format=<?= EbookFormatType::Kepub->value ?>" class="kobo"><span property="schema:description">kepub</span></a></span> <span></span> <span>Kobo devices and apps. You may also be interested in our <a href="/help/how-to-use-our-ebooks#kobo-faq">Kobo FAQ</a>.</span> <span><a property="schema:contentUrl" rel="nofollow" href="<?= $ebook->Url ?>/download?format=<?= Enums\EbookFormatType::Kepub->value ?>" class="kobo"><span property="schema:description">kepub</span></a></span> <span></span> <span>Kobo devices and apps. You may also be interested in our <a href="/help/how-to-use-our-ebooks#kobo-faq">Kobo FAQ</a>.</span>
</p> </p>
</li> </li>
<? } ?> <? } ?>
@ -250,7 +250,7 @@ catch(Exceptions\EbookNotFoundException){
<li property="schema:encoding" typeof="schema:MediaObject"> <li property="schema:encoding" typeof="schema:MediaObject">
<meta property="schema:encodingFormat" content="application/epub+zip"/> <meta property="schema:encodingFormat" content="application/epub+zip"/>
<p> <p>
<span><a property="schema:contentUrl" rel="nofollow" href="<?= $ebook->Url ?>/download?format=<?= EbookFormatType::AdvancedEpub->value ?>" class="epub"><span property="schema:description">Advanced epub</span></a></span> <span></span> <span>An advanced format that uses the latest technology not yet fully supported by most ereaders.</span> <span><a property="schema:contentUrl" rel="nofollow" href="<?= $ebook->Url ?>/download?format=<?= Enums\EbookFormatType::AdvancedEpub->value ?>" class="epub"><span property="schema:description">Advanced epub</span></a></span> <span></span> <span>An advanced format that uses the latest technology not yet fully supported by most ereaders.</span>
</p> </p>
</li> </li>
<? } ?> <? } ?>
@ -338,15 +338,15 @@ catch(Exceptions\EbookNotFoundException){
<? foreach($transcriptionSources as $source){ ?> <? foreach($transcriptionSources as $source){ ?>
<li> <li>
<p> <p>
<? if($source->Type == EbookSourceType::ProjectGutenberg){ ?> <? if($source->Type == Enums\EbookSourceType::ProjectGutenberg){ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg</a>
<? }elseif($source->Type == EbookSourceType::ProjectGutenbergAustralia){ ?> <? }elseif($source->Type == Enums\EbookSourceType::ProjectGutenbergAustralia){ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Australia</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Australia</a>
<? }elseif($source->Type == EbookSourceType::ProjectGutenbergCanada){ ?> <? }elseif($source->Type == Enums\EbookSourceType::ProjectGutenbergCanada){ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Canada</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="project-gutenberg">Transcription at Project Gutenberg Canada</a>
<? }elseif($source->Type == EbookSourceType::Wikisource){ ?> <? }elseif($source->Type == Enums\EbookSourceType::Wikisource){ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="wikisource">Transcription at Wikisource</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="wikisource">Transcription at Wikisource</a>
<? }elseif($source->Type == EbookSourceType::FadedPage){ ?> <? }elseif($source->Type == Enums\EbookSourceType::FadedPage){ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Transcription at Faded Page</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Transcription at Faded Page</a>
<? }else{?> <? }else{?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Transcription</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Transcription</a>
@ -364,11 +364,11 @@ catch(Exceptions\EbookNotFoundException){
<? foreach($scanSources as $source){ ?> <? foreach($scanSources as $source){ ?>
<li> <li>
<p> <p>
<? if($source->Type == EbookSourceType::InternetArchive){ ?> <? if($source->Type == Enums\EbookSourceType::InternetArchive){ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="internet-archive">Page scans at the Internet Archive</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="internet-archive">Page scans at the Internet Archive</a>
<? }elseif($source->Type == EbookSourceType::HathiTrust){ ?> <? }elseif($source->Type == Enums\EbookSourceType::HathiTrust){ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="hathitrust">Page scans at HathiTrust</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="hathitrust">Page scans at HathiTrust</a>
<? }elseif($source->Type == EbookSourceType::GoogleBooks){ ?> <? }elseif($source->Type == Enums\EbookSourceType::GoogleBooks){ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="google">Page scans at Google Books</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="google">Page scans at Google Books</a>
<? }else{ ?> <? }else{ ?>
<a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Page scans</a> <a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe">Page scans</a>
@ -386,7 +386,7 @@ catch(Exceptions\EbookNotFoundException){
<? foreach($otherSources as $source){ ?> <? foreach($otherSources as $source){ ?>
<li> <li>
<p> <p>
<? if($source->Type == EbookSourceType::Other){ ?><a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe"><?= Formatter::EscapeHtml(preg_replace(['|https?://(en\.)?|', '|/.+$|'], '', (string)$source->Url)) /* force type to (string) to satisfy PHPStan */ ?></a><? } ?> <? if($source->Type == Enums\EbookSourceType::Other){ ?><a href="<?= Formatter::EscapeHtml($source->Url) ?>" class="globe"><?= Formatter::EscapeHtml(preg_replace(['|https?://(en\.)?|', '|/.+$|'], '', (string)$source->Url)) /* force type to (string) to satisfy PHPStan */ ?></a><? } ?>
</p> </p>
</li> </li>
<? } ?> <? } ?>

View file

@ -6,8 +6,8 @@ $pages = 0;
$perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; $perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
$query = HttpInput::Str(GET, 'query') ?? ''; $query = HttpInput::Str(GET, 'query') ?? '';
$tags = HttpInput::Array(GET, 'tags') ?? []; $tags = HttpInput::Array(GET, 'tags') ?? [];
$view = ViewType::tryFrom(HttpInput::Str(GET, 'view') ?? ''); $view = Enums\ViewType::tryFrom(HttpInput::Str(GET, 'view') ?? '');
$sort = EbookSortType::tryFrom(HttpInput::Str(GET, 'sort') ?? ''); $sort = Enums\EbookSortType::tryFrom(HttpInput::Str(GET, 'sort') ?? '');
$queryString = ''; $queryString = '';
$queryStringParams = []; $queryStringParams = [];
$queryStringWithoutPage = ''; $queryStringWithoutPage = '';
@ -23,11 +23,11 @@ try{
// If we're passed string values that are the same as the defaults, // 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 // set them to null so that we can have cleaner query strings in the navigation footer
if($view === ViewType::Grid){ if($view === Enums\ViewType::Grid){
$view = null; $view = null;
} }
if($sort == EbookSortType::Newest){ if($sort == Enums\EbookSortType::Newest){
$sort = null; $sort = null;
} }

View file

@ -9,7 +9,7 @@ try{
$count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; $count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
if($query !== ''){ if($query !== ''){
$ebooks = Library::FilterEbooks($query, [], EbookSortType::Newest, $startPage, $count)['ebooks']; $ebooks = Library::FilterEbooks($query, [], Enums\EbookSortType::Newest, $startPage, $count)['ebooks'];
} }
} }
catch(\Exception){ catch(\Exception){

View file

@ -9,7 +9,7 @@ try{
$count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; $count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
if($query !== ''){ if($query !== ''){
$ebooks = Library::FilterEbooks($query, [], EbookSortType::Newest, $startPage, $count)['ebooks']; $ebooks = Library::FilterEbooks($query, [], Enums\EbookSortType::Newest, $startPage, $count)['ebooks'];
} }
} }
catch(\Exception){ catch(\Exception){

View file

@ -9,7 +9,7 @@ try{
$count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; $count = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
if($query !== ''){ if($query !== ''){
$ebooks = Library::FilterEbooks($query, [], EbookSortType::Newest, $startPage, $count)['ebooks']; $ebooks = Library::FilterEbooks($query, [], Enums\EbookSortType::Newest, $startPage, $count)['ebooks'];
} }
} }
catch(\Exception){ catch(\Exception){

View file

@ -39,7 +39,7 @@ try{
values (utc_timestamp(), values (utc_timestamp(),
?, ?,
?) ?)
', [PaymentProcessorType::FracturedAtlas, $transactionId]); ', [Enums\PaymentProcessorType::FracturedAtlas, $transactionId]);
$log->Write('Donation ID: ' . $transactionId); $log->Write('Donation ID: ' . $transactionId);
} }