123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- const ARTWORKS_PER_PAGE = 24;
- function render_artworks_grid($artworks_uncensored, $show_author = false, $collapsed = false, $reload_btn = false) {
- $artworks = [];
- foreach ($artworks_uncensored as $artwork) {
- if (!artwork_is_hidden($artwork)) array_push($artworks, $artwork);
- }
- if (!$artworks) { ?>
- <p><?= get_string($artworks_uncensored ? 'all-hidden' : 'no-works') ?></p><?php
- return;
- }
- $page_count = $collapsed ? ceil(count($artworks) / ARTWORKS_PER_PAGE) : 1;
- render_collapsed_content(
- $page_count,
- get_string('load-more'),
- function($page) use ($page_count, $artworks, $show_author, $collapsed, $reload_btn) {
- $artworks_in_page = $collapsed ? array_slice($artworks, $page * ARTWORKS_PER_PAGE, ARTWORKS_PER_PAGE) : $artworks;
- render_grid_body($artworks_in_page, $show_author, false);
- if ($page == $page_count - 1 && $reload_btn) { ?>
- <p class="center">
- <a href="" class="button"><?= get_string('discovery.reload') ?></a>
- </p><?php
- }
- }
- );
- }
- function render_grid_body($artworks, $show_author, $selectable) {
- $class = 'grid';
- if ($show_author) $class .= ' show-author'; ?>
- <div class="<?= $class ?>"><?php
- foreach ($artworks as $artwork) {
- render_cell($artwork, $selectable);
- } ?>
- </div><?php
- }
- function render_cell($artwork, $selectable) { ?>
- <div><?php
- render_thumbnail($artwork, $selectable); ?>
- <a class="title" href="<?= BASE_URL ?>/artworks/<?= $artwork->id ?>">
- <b><?= htmlspecialchars($artwork->title); ?></b>
- </a>
- <a class="author" href="<?= BASE_URL ?>/users/<?= $artwork->userId ?>">
- <img class="avatar" loading="lazy" src="<?= get_proxy_url($artwork->profileImageUrl) ?>" alt=" ">
- <div class="username"><?= htmlspecialchars($artwork->userName); ?></div>
- </a>
- </div><?php
- }
- function render_thumbnail($artwork, $selectable) {
- if ($selectable) { ?>
- <label class="thumbnail">
- <input type="checkbox" name="selection[<?= $artwork->id ?>]" autocomplete="off">
- <div class="selection-overlay"></div><?php
- render_thumbnail_content($artwork); ?>
- </label><?php
- return;
- } ?>
- <a class="thumbnail" href="<?= BASE_URL ?>/artworks/<?= $artwork->id ?>"><?php
- render_thumbnail_content($artwork); ?>
- </a><?php
- }
- function render_thumbnail_content($artwork) { ?>
- <div class="extra-info"><?php
- $restrict_type = get_xrestrict_string($artwork->xRestrict);
- if ($restrict_type) { ?>
- <div class="content-warning"><?= $restrict_type ?></div><?php
- }
- if ($artwork->pageCount > 1) { ?>
- <div class="page-count">🗍 <?= $artwork->pageCount ?></div><?php
- }
- else if ($artwork->illustType == 2) { ?>
- <div class="page-count">▶</div><?php
- } ?>
- </div>
- <img loading="lazy" src="<?= get_proxy_url($artwork->url) ?>" alt="<?= htmlspecialchars($artwork->alt); ?>"><?php
- }
|