From b99d2aac1a9ab891de1f67e777e4c6c88cfc3f14 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Sun, 7 Jan 2024 15:47:40 -0600 Subject: [PATCH] Merge admin pages with regular pages for art system --- config/apache/standardebooks.org.conf | 6 +- config/apache/standardebooks.test.conf | 6 +- lib/Artwork.php | 32 ++---- lib/Library.php | 55 +++++----- templates/ArtworkDetail.php | 85 --------------- templates/ArtworkList.php | 14 +-- templates/ArtworkSearchForm.php | 33 ------ www/admin/artworks/get.php | 48 --------- www/admin/artworks/index.php | 88 ---------------- www/admin/artworks/post.php | 45 -------- www/artworks/get.php | 137 ++++++++++++++++++++++++- www/artworks/index.php | 89 ++++++++++++---- www/artworks/new.php | 2 +- www/artworks/post.php | 133 +++++++++++++++++------- www/css/artwork.css | 16 ++- 15 files changed, 348 insertions(+), 441 deletions(-) delete mode 100644 templates/ArtworkDetail.php delete mode 100644 templates/ArtworkSearchForm.php delete mode 100644 www/admin/artworks/get.php delete mode 100644 www/admin/artworks/index.php delete mode 100644 www/admin/artworks/post.php diff --git a/config/apache/standardebooks.org.conf b/config/apache/standardebooks.org.conf index a1b8e7f8..2f75b99e 100644 --- a/config/apache/standardebooks.org.conf +++ b/config/apache/standardebooks.org.conf @@ -297,12 +297,10 @@ Define webroot /standardebooks.org/web # Rewrite rules for cover art RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" - RewriteRule ^/admin/artworks/([^/\.]+)$ /admin/artworks/get.php?artworkid=$1 [L] + RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L] RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" - RewriteRule ^/admin/artworks/([^/\.]+)$ /admin/artworks/post.php?artworkid=$1 [L] - - RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist=$1&artwork=$2 [L] + RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/post.php?artist-url-name=$1&artwork-url-name=$2 [L] # Specific config for /bulk-downloads diff --git a/config/apache/standardebooks.test.conf b/config/apache/standardebooks.test.conf index 78c68668..905d41f0 100644 --- a/config/apache/standardebooks.test.conf +++ b/config/apache/standardebooks.test.conf @@ -279,12 +279,10 @@ Define webroot /standardebooks.org/web # Rewrite rules for cover art RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" - RewriteRule ^/admin/artworks/([^/\.]+)$ /admin/artworks/get.php?artworkid=$1 [L] + RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L] RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" - RewriteRule ^/admin/artworks/([^/\.]+)$ /admin/artworks/post.php?artworkid=$1 [L] - - RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist=$1&artwork=$2 [L] + RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/post.php?artist-url-name=$1&artwork-url-name=$2 [L] # Specific config for /bulk-downloads diff --git a/lib/Artwork.php b/lib/Artwork.php index cb6efc63..9ec163e3 100644 --- a/lib/Artwork.php +++ b/lib/Artwork.php @@ -21,6 +21,7 @@ use function Safe\sprintf; * @property Ebook $Ebook * @property Museum $Museum * @property User $Submitter + * @property User $Reviewer * @property ?ImageMimeType $MimeType */ class Artwork extends PropertiesBase{ @@ -80,6 +81,14 @@ class Artwork extends PropertiesBase{ return $this->_Submitter; } + protected function GetReviewer(): User{ + if($this->_Reviewer === null){ + $this->_Reviewer = User::Get($this->ReviewerUserId); + } + + return $this->_Reviewer; + } + protected function GetUrl(): string{ if($this->_Url === null){ $this->_Url = '/artworks/' . $this->Artist->UrlName . '/' . $this->UrlName; @@ -579,27 +588,4 @@ class Artwork extends PropertiesBase{ return $result[0]; } - - /** - * Gets a publically available Artwork, i.e., with approved or in_use status. - * Artwork with status unverifed and declined aren't available by URL. - */ - /** - * @throws \Exceptions\InvalidArtworkException - */ - public static function GetByUrlAndIsApproved(string $artistUrlName, string $artworkUrlName): Artwork{ - $result = Db::Query(' - SELECT Artworks.* - from Artworks - inner join Artists using (ArtistId) - where Status in ("approved", "in_use") and - Artists.UrlName = ? and Artworks.UrlName = ? - ', [$artistUrlName, $artworkUrlName], 'Artwork'); - - if(sizeof($result) == 0){ - throw new Exceptions\ArtworkNotFoundException(); - } - - return $result[0]; - } } diff --git a/lib/Library.php b/lib/Library.php index a89c0520..937d6c18 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -159,18 +159,6 @@ class Library{ return self::GetFromApcu('tags'); } - /** - * Browsable Artwork can be displayed publically, e.g., at /artworks. - * Unverified and declined Artwork shouldn't be browsable. - * @return array - */ - private static function GetBrowsableArtwork(): array{ - return Db::Query(' - SELECT * - from Artworks - where Status in ("approved", "in_use")', [], 'Artwork'); - } - /** * @param string $query * @param string $status @@ -178,30 +166,37 @@ class Library{ * @return array */ public static function FilterArtwork(string $query = null, string $status = null, string $sort = null): array{ - $artworks = Library::GetBrowsableArtwork(); + // Possible special statuses: + // null: same as "all" + // "all": Show all approved and in use artwork + // "all-admin": Show all artwork regardless of status + + $artworks = []; + + if($status === null || $status == 'all'){ + $artworks = Db::Query(' + SELECT * + from Artworks + where Status in ("approved", "in_use")', [], 'Artwork'); + } + elseif($status == 'all-admin'){ + $artworks = Db::Query(' + SELECT * + from Artworks', [], 'Artwork'); + } + else{ + $artworks = Db::Query(' + SELECT * + from Artworks + where Status = ?', [$status], 'Artwork'); + } + $matches = $artworks; if($sort === null){ $sort = SORT_COVER_ARTWORK_CREATED_NEWEST; } - if(in_array($status, [COVER_ARTWORK_STATUS_APPROVED, COVER_ARTWORK_STATUS_IN_USE], true)){ - $matches = []; - foreach($artworks as $artwork){ - if($status === $artwork->Status){ - $matches[] = $artwork; - } - } - } - else{ - $matches = []; - foreach($artworks as $artwork){ - if(in_array($artwork->Status, [COVER_ARTWORK_STATUS_APPROVED, COVER_ARTWORK_STATUS_IN_USE], true)){ - $matches[] = $artwork; - } - } - } - if($query !== null){ $filteredMatches = []; diff --git a/templates/ArtworkDetail.php b/templates/ArtworkDetail.php deleted file mode 100644 index d19c9436..00000000 --- a/templates/ArtworkDetail.php +++ /dev/null @@ -1,85 +0,0 @@ - - -

Name) ?>

- - - - - - - - - - -

Metadata

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

U.S. public domain proof

-MuseumUrl !== null){ ?> -

Museum page

-

MuseumUrl) ?>

- Museum !== null){ ?> -
-

Approved museum: Museum->Name) ?> (Museum->Domain) ?>)

-
- -
-

Not an approved museum.

-
- - - -PublicationYear !== null){ ?> -

Page scans

-
    -
  • Year book was published: PublicationYear !== null){ ?>PublicationYear ?>Not provided
  • -
  • Page scan of book publication year: PublicationYearPageUrl !== null){ ?>LinkNot provided
  • -
  • Page scan of rights statement: CopyrightPageUrl !== null){ ?>LinkNot provided
  • -
  • Page scan of artwork: ArtworkPageUrl !== null){ ?>LinkNot provided
  • -
- - -Exception !== null){ ?> -

Special public domain exception

- Exception) ?> - diff --git a/templates/ArtworkList.php b/templates/ArtworkList.php index 58347f70..4a9d1e77 100644 --- a/templates/ArtworkList.php +++ b/templates/ArtworkList.php @@ -1,32 +1,26 @@
    - - AdminUrl; ?> - - Url; ?> -
  1. -

    Name) ?>

    +

    Name) ?>

    Artist->Name) ?> Artist->AlternateSpellings) > 0){ ?>(AKA , ', array_map('Formatter::ToPlainText', $artwork->Artist->AlternateSpellings)) ?>)

    Year completed: CompletedYear === null){ ?>UnknownCompletedYearIsCirca){ ?>CircaCompletedYear ?>

    - Status == COVER_ARTWORK_STATUS_IN_USE){ ?>

    Status: $artwork]) ?>

    + Status == COVER_ARTWORK_STATUS_IN_USE){ ?>

    Status: $artwork]) ?>

    Tags) > 0){ ?>

    Tags:

    diff --git a/templates/ArtworkSearchForm.php b/templates/ArtworkSearchForm.php deleted file mode 100644 index 571f61f0..00000000 --- a/templates/ArtworkSearchForm.php +++ /dev/null @@ -1,33 +0,0 @@ - diff --git a/www/admin/artworks/get.php b/www/admin/artworks/get.php deleted file mode 100644 index 798f88cc..00000000 --- a/www/admin/artworks/get.php +++ /dev/null @@ -1,48 +0,0 @@ -Status == COVER_ARTWORK_STATUS_APPROVED || $artwork->Status == COVER_ARTWORK_STATUS_IN_USE){ - http_response_code(302); - header('Location: ' . $artwork->Url); - exit(); - } - - // We got here because an artwork submission had errors and the user has to try again - if($exception){ - http_response_code(422); - session_unset(); - } -} -catch(Exceptions\AppException){ - Template::Emit404(); -} - -?> 'Review Artwork', 'artwork' => true, 'highlight' => '', 'description' => 'Unverified artwork.']) ?> -
    - $exception]) ?> -
    - $artwork, 'isAdminView' => true]) ?> - Status == COVER_ARTWORK_STATUS_DECLINED){ ?> -

    Status

    -

    This artwork has been declined by a reviewer.

    - - Status == COVER_ARTWORK_STATUS_UNVERIFIED){ ?> -

    Review

    -

    Review the metadata and PD proof for this artwork submission. Approve to make it available for future producers.

    -
    - - - -
    - -
    -
    - diff --git a/www/admin/artworks/index.php b/www/admin/artworks/index.php deleted file mode 100644 index d9134b93..00000000 --- a/www/admin/artworks/index.php +++ /dev/null @@ -1,88 +0,0 @@ -Benefits->CanReviewArtwork){ - throw new Exceptions\InvalidPermissionsException(); - } - - if($status !== null){ - $artwork = Artwork::Get(HttpInput::Int(SESSION, 'artwork-id')); - - http_response_code(201); - session_unset(); - } - - if($page <= 0){ - $page = 1; - } - - $unverifiedArtworks = Db::Query(' - SELECT * - from Artworks - where Status = "unverified" - order by Created asc - limit ?, ? - ', [($page - 1) * $perPage, $perPage + 1], 'Artwork'); - - if(sizeof($unverifiedArtworks) > $perPage){ - array_pop($unverifiedArtworks); - $hasNextPage = true; - } -} -catch(Exceptions\LoginRequiredException){ - Template::RedirectToLogin(); -} -catch(Exceptions\InvalidPermissionsException){ - Template::Emit403(); // No permissions to submit artwork -} - -?> 'Artwork Review Queue', 'artwork' => true, 'highlight' => '', 'description' => 'The queue of unverified artwork.']) ?> -
    -
    -

    Artwork Review Queue

    - - -

    - - Name) ?> approved. - - Artwork approved. - -

    - - -

    - - Name) ?> declined. - - Artwork declined. - -

    - - -

    No artwork to review.

    - - $unverifiedArtworks, 'useAdminUrl' => true]) ?> - -
    - - -
    - diff --git a/www/admin/artworks/post.php b/www/admin/artworks/post.php deleted file mode 100644 index 005784de..00000000 --- a/www/admin/artworks/post.php +++ /dev/null @@ -1,45 +0,0 @@ -Benefits->CanReviewArtwork){ - throw new Exceptions\InvalidPermissionsException(); - } - - $artwork = Artwork::Get(HttpInput::Int(GET, 'artworkid')); - $artwork->Status = HttpInput::Str(POST, 'status', false); - $artwork->ReviewerUserId = $GLOBALS['User']->UserId; - $artwork->Save(); - - $_SESSION['artwork-id'] = $artwork->ArtworkId; - $_SESSION['status'] = $artwork->Status; - - http_response_code(303); - header('Location: /admin/artworks'); -} -catch(Exceptions\InvalidRequestException){ - http_response_code(405); -} -catch(Exceptions\LoginRequiredException){ - Template::RedirectToLogin(); -} -catch(Exceptions\InvalidPermissionsException){ - Template::Emit403(); // No permissions to submit artwork -} -catch(Exceptions\ArtworkNotFoundException){ - Template::Emit404(); -} -catch(Exceptions\AppException $exception){ - $_SESSION['exception'] = $exception; - - http_response_code(303); - header('Location: /admin/artworks/' . $artwork->ArtworkId); -} diff --git a/www/artworks/get.php b/www/artworks/get.php index 606f0055..174463cb 100644 --- a/www/artworks/get.php +++ b/www/artworks/get.php @@ -1,10 +1,31 @@ Benefits->CanReviewArtwork ?? false; - $artwork = Artwork::GetByUrlAndIsApproved($artistUrlName, $artworkUrlName); + // If the artwork is not approved, and we're not an admin, don't show it. + if($artwork->Status != COVER_ARTWORK_STATUS_APPROVED && $artwork->Status != COVER_ARTWORK_STATUS_IN_USE && !$isAdminView){ + throw new Exceptions\ArtworkNotFoundException(); + } + + // We got here because an artwork was successfully submitted + if($saved){ + session_unset(); + } + + // We got here because an artwork submission had errors and the user has to try again + if($exception){ + http_response_code(422); + $artwork = $_SESSION['artwork'] ?? $artwork; + session_unset(); + } } catch(Exceptions\ArtworkNotFoundException){ Template::Emit404(); @@ -13,7 +34,115 @@ catch(Exceptions\ArtworkNotFoundException){ ?> $artwork->Name, 'artwork' => true]) ?>
    - $artwork]) ?> +

    Name) ?>

    + + $exception]) ?> + + +

    Artwork saved!

    + + + + + + + + + + + +

    Metadata

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    U.S. public domain proof

    + MuseumUrl !== null){ ?> +

    Museum page

    +

    MuseumUrl) ?>

    + Museum !== null){ ?> +
    +

    Approved museum: Museum->Name) ?> (Museum->Domain) ?>)

    +
    + +
    +

    Not an approved museum.

    +
    + + + + PublicationYear !== null){ ?> +

    Page scans

    +
      +
    • Year book was published: PublicationYear !== null){ ?>PublicationYear ?>Not provided
    • +
    • Page scan of book publication year: PublicationYearPageUrl !== null){ ?>LinkNot provided
    • +
    • Page scan of rights statement: CopyrightPageUrl !== null){ ?>LinkNot provided
    • +
    • Page scan of artwork: ArtworkPageUrl !== null){ ?>LinkNot provided
    • +
    + + + Exception !== null){ ?> +

    Special public domain exception

    + Exception) ?> + + + +

    Reviewer options

    +

    Review the metadata and PD proof for this artwork submission. Approve to make it available for future producers.

    +
    + + + + +
    +
    diff --git a/www/artworks/index.php b/www/artworks/index.php index ad4d7559..f3ccf8de 100644 --- a/www/artworks/index.php +++ b/www/artworks/index.php @@ -11,6 +11,7 @@ $totalArtworkCount = 0; $pageDescription = ''; $pageTitle = ''; $queryString = ''; +$isAdminView = $GLOBALS['User']?->Benefits?->CanReviewArtwork ?? false; if($page <= 0){ $page = 1; @@ -26,10 +27,20 @@ if($sort !== null){ $sort = mb_strtolower($sort); } -if($sort === 'created-newest'){ +if($sort == 'created-newest'){ $sort = null; } +if($status == 'all'){ + if($isAdminView){ + $status = 'all-admin'; + } +} + +if(!$isAdminView && $status !== 'all' && $status != COVER_ARTWORK_STATUS_APPROVED && $status != COVER_ARTWORK_STATUS_IN_USE){ + $status = COVER_ARTWORK_STATUS_APPROVED; +} + $artworks = Library::FilterArtwork($query != '' ? $query : null, $status, $sort); $pageTitle = 'Browse Artwork'; $pages = ceil(sizeof($artworks) / $perPage); @@ -63,24 +74,64 @@ if($perPage !== COVER_ARTWORK_PER_PAGE){

    Browse U.S. Public Domain Artwork

    You can help Standard Ebooks by submitting new public domain artwork to add to this catalog for use in future ebooks. For free access to the submission form, contact the Editor-in-Chief.

    - $query, 'status' => $status, 'sort' => $sort, 'perPage' => $perPage]) ?> - - -

    No artwork matched your filters. You can try different filters, or browse all artwork.

    - - $artworks, 'useAdminUrl' => false]) ?> - - 0){ ?> - - + + + + + +

    No artwork matched your filters. You can try different filters, or browse all artwork.

    + + $artworks, 'showStatus' => $isAdminView && ($status == 'all' || $status == 'all-admin')]) ?> + + + 0){ ?> + +
    diff --git a/www/artworks/new.php b/www/artworks/new.php index c69576c7..efe214c7 100644 --- a/www/artworks/new.php +++ b/www/artworks/new.php @@ -137,7 +137,7 @@ catch(Exceptions\InvalidPermissionsException){