artworks_grid.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. const ARTWORKS_PER_PAGE = 24;
  3. function render_artworks_grid($artworks_uncensored, $show_author = false, $collapsed = false, $reload_btn = false) {
  4. $artworks = [];
  5. foreach ($artworks_uncensored as $artwork) {
  6. if (!artwork_is_hidden($artwork)) array_push($artworks, $artwork);
  7. }
  8. if (!$artworks) { ?>
  9. <p><?= get_string($artworks_uncensored ? 'all-hidden' : 'no-works') ?></p><?php
  10. return;
  11. }
  12. $page_count = $collapsed ? ceil(count($artworks) / ARTWORKS_PER_PAGE) : 1;
  13. render_collapsed_content(
  14. $page_count,
  15. get_string('load-more'),
  16. function($page) use ($page_count, $artworks, $show_author, $collapsed, $reload_btn) {
  17. $artworks_in_page = $collapsed ? array_slice($artworks, $page * ARTWORKS_PER_PAGE, ARTWORKS_PER_PAGE) : $artworks;
  18. render_grid_body($artworks_in_page, $show_author, false);
  19. if ($page == $page_count - 1 && $reload_btn) { ?>
  20. <p class="center">
  21. <a href="" class="button"><?= get_string('discovery.reload') ?></a>
  22. </p><?php
  23. }
  24. }
  25. );
  26. }
  27. function render_grid_body($artworks, $show_author, $selectable) {
  28. $class = 'grid';
  29. if ($show_author) $class .= ' show-author'; ?>
  30. <div class="<?= $class ?>"><?php
  31. foreach ($artworks as $artwork) {
  32. render_cell($artwork, $selectable);
  33. } ?>
  34. </div><?php
  35. }
  36. function render_cell($artwork, $selectable) { ?>
  37. <div><?php
  38. render_thumbnail($artwork, $selectable); ?>
  39. <a class="title" href="<?= BASE_URL ?>/artworks/<?= $artwork->id ?>">
  40. <b><?= htmlspecialchars($artwork->title); ?></b>
  41. </a>
  42. <a class="author" href="<?= BASE_URL ?>/users/<?= $artwork->userId ?>">
  43. <img class="avatar" loading="lazy" src="<?= get_proxy_url($artwork->profileImageUrl) ?>" alt=" ">
  44. <div class="username"><?= htmlspecialchars($artwork->userName); ?></div>
  45. </a>
  46. </div><?php
  47. }
  48. function render_thumbnail($artwork, $selectable) {
  49. if ($selectable) { ?>
  50. <label class="thumbnail">
  51. <input type="checkbox" name="selection[<?= $artwork->id ?>]" autocomplete="off">
  52. <div class="selection-overlay"></div><?php
  53. render_thumbnail_content($artwork); ?>
  54. </label><?php
  55. return;
  56. } ?>
  57. <a class="thumbnail" href="<?= BASE_URL ?>/artworks/<?= $artwork->id ?>"><?php
  58. render_thumbnail_content($artwork); ?>
  59. </a><?php
  60. }
  61. function render_thumbnail_content($artwork) { ?>
  62. <div class="extra-info"><?php
  63. $restrict_type = get_xrestrict_string($artwork->xRestrict);
  64. if ($restrict_type) { ?>
  65. <div class="content-warning"><?= $restrict_type ?></div><?php
  66. }
  67. if ($artwork->pageCount > 1) { ?>
  68. <div class="page-count">&#128461; <?= $artwork->pageCount ?></div><?php
  69. }
  70. else if ($artwork->illustType == 2) { ?>
  71. <div class="page-count">&#9654;</div><?php
  72. } ?>
  73. </div>
  74. <img loading="lazy" src="<?= get_proxy_url($artwork->url) ?>" alt="<?= htmlspecialchars($artwork->alt); ?>"><?php
  75. }