artwork_sections.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. function render_artwork_images() {
  3. global $artwork, $settings;
  4. if ($artwork->pageCount == 1) {
  5. render_artwork_image(
  6. $artwork->urls->original, $artwork->urls->regular,
  7. $artwork->width, $artwork->height,
  8. sprintf(get_string('artwork.image-alt'), '1', '1')
  9. );
  10. return;
  11. }
  12. list($artwork_pages, $error) = get_artwork_pages($artwork->id);
  13. if ($error) {
  14. for ($p = 0; $p < $artwork->pageCount; $p ++) {
  15. $artwork_pages[$p] = [
  16. 'urls' => [
  17. 'regular' => str_replace('_p0', '_p' . $p, $artwork->urls->original),
  18. 'original' => str_replace('_p0', '_p' . $p, $artwork->urls->regular)
  19. ],
  20. 'width' => false,
  21. 'height' => false
  22. ];
  23. }
  24. }
  25. else {
  26. $artwork_pages = $artwork_pages['body'];
  27. }
  28. if ($settings['collapse-pages'] == 'off') {
  29. for ($p = 0; $p < $artwork->pageCount; $p ++) {
  30. render_artwork_image(
  31. $artwork_pages[$p]['urls']['original'], $artwork_pages[$p]['urls']['regular'],
  32. $artwork_pages[$p]['width'], $artwork_pages[$p]['height'],
  33. sprintf(get_string('artwork.image-alt'), $p + 1, $artwork->pageCount)
  34. );
  35. }
  36. return;
  37. }
  38. render_collapsed_content(
  39. 2, get_string('artwork.images-show-all'),
  40. function($page) use ($artwork, $artwork_pages) {
  41. for ($p = $page; $p < ($page == 0 ? 1 : $artwork->pageCount); $p ++) {
  42. render_artwork_image(
  43. $artwork_pages[$p]['urls']['original'], $artwork_pages[$p]['urls']['regular'],
  44. $artwork_pages[$p]['width'], $artwork_pages[$p]['height'],
  45. sprintf(get_string('artwork.image-alt'), $p + 1, $artwork->pageCount)
  46. );
  47. }
  48. }
  49. );
  50. }
  51. function render_artwork_image($original_url, $regular_url, $width, $height, $alt) { ?>
  52. <a target="_blank" href="<?= get_proxy_url($original_url) ?>">
  53. <img
  54. loading="lazy"
  55. alt="<?= $alt ?>" title="<?= $alt ?>"
  56. src="<?= get_proxy_url($regular_url) ?>"
  57. width="<?= $width ?>" height="<?= $height ?>"
  58. >
  59. </a><?php
  60. }
  61. function render_artwork_comments() {
  62. require_once __DIR__ . '/comments.php';
  63. global $artwork; ?>
  64. <h2><?= sprintf(get_string('artwork.comments'), $artwork->commentCount) ?></h2><?php
  65. if ($artwork->commentOff == 1) { ?>
  66. <p><?= get_string('artwork.comments-off') ?></p><?php
  67. return;
  68. }
  69. if ($artwork->commentCount == 0) { ?>
  70. <p><?= get_string('artwork.no-comments') ?></p><?php
  71. return;
  72. }
  73. list($comments, $error) = get_artwork_comments($artwork->id, 0, COMMENTS_PREVIEW + 1);
  74. if ($error) { ?>
  75. <p><?= get_string($error) ?></p><?php
  76. return;
  77. }
  78. $comments = $comments->body->comments;
  79. render_comment_list(array_slice($comments, 0, COMMENTS_PREVIEW));
  80. if (count($comments) > COMMENTS_PREVIEW) { ?>
  81. <p class="center">
  82. <a class="button" target="_blank" href="comments.php?id=<?= $artwork->id ?>">
  83. <?= get_string('artwork.show-more')?>
  84. </a>
  85. </p><?php
  86. }
  87. }
  88. function render_artwork_related() {
  89. require_once __DIR__ . '/artworks_grid.php';
  90. global $artwork; ?>
  91. <h2><?= get_string('artwork.related') ?></h2><?php
  92. list($related, $error) = get_artwork_related($artwork->id);
  93. if ($error) { ?>
  94. <p><?= get_string($error) ?></p><?php
  95. return;
  96. }
  97. $related = $related->body->illusts;
  98. render_artworks_grid($related, true, true);
  99. }