index.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. require_once __DIR__ . '/../include/utils.php';
  3. require_once __DIR__ . '/../include/artworks_grid.php';
  4. require_once __DIR__ . '/../include/paginator.php';
  5. require_once __DIR__ . '/../include/truncated_text.php';
  6. if (!isset($_GET['id']) || !ctype_digit($_GET['id'])) {
  7. die_with_message(400, get_string('illegal-id'));
  8. }
  9. $id = $_GET['id'];
  10. list($info, $error) = get_user_info($id);
  11. if ($error) {
  12. die_with_message(500, get_string($error));
  13. }
  14. $info = $info->body;
  15. $categories = ['artworks', 'illustrations', 'manga', 'bookmarks'];
  16. if (!isset($_GET['category']) || !in_array($_GET['category'], $categories)) {
  17. $_GET['category'] = 'artworks';
  18. }
  19. $category = $_GET['category'];
  20. $pathname = BASE_URL . "/users/$id";
  21. render_page_header($info->name);
  22. ?>
  23. <div class="container">
  24. <h1 class="img-with-text">
  25. <img loading="lazy" class="avatar" src="<?= get_proxy_url($info->imageBig) ?>" alt=" ">
  26. <span><?= htmlspecialchars($info->name) ?></span>
  27. </h1>
  28. <div class="description">
  29. <?= render_truncated_text(str_replace(PHP_EOL, "<br />", htmlspecialchars($info->comment))) ?>
  30. </div>
  31. <div class="category-selector"><?php
  32. foreach ($categories as $c) { ?>
  33. <a href="<?= "$pathname/$c" ?>" class="<?php if ($c == $category) echo 'selected'; ?>">
  34. <?= get_string('user.' . $c) ?>
  35. </a><?php
  36. } ?>
  37. </div>
  38. <?php
  39. switch (true) {
  40. case ($category == 'bookmarks'):
  41. /* bookmarks tab */
  42. $current_page = (isset($_GET['p']) && ctype_digit($_GET['p']) && $_GET['p'] > 0) ? $_GET['p'] : 1;
  43. list($bookmarks, $error) = get_user_bookmarks(
  44. $id,
  45. ARTWORKS_PER_PAGE * ($current_page - 1),
  46. ARTWORKS_PER_PAGE
  47. );
  48. if ($error) { ?>
  49. <p><?= get_string($error); ?></p><?php
  50. break;
  51. }
  52. $bookmarks = $bookmarks->body;
  53. $page_count = ceil($bookmarks->total / ARTWORKS_PER_PAGE);?>
  54. <h2 id="artworks"><?= sprintf(get_string('user.work-count'), $bookmarks->total) ?></h2><?php
  55. render_artworks_grid($bookmarks->works, true);
  56. render_paginator($page_count, $current_page, function($page) use ($pathname) {
  57. return "$pathname/bookmarks?p=$page#artworks";
  58. });
  59. break;
  60. case (isset($_GET['tag']) && strlen($_GET['tag'])):
  61. /* all/illusts/manga tab with tag */
  62. $tag = $_GET['tag'];
  63. $current_page = (isset($_GET['p']) && ctype_digit($_GET['p']) && $_GET['p'] > 0) ? $_GET['p'] : 1;
  64. list($artworks, $error) = get_user_artworks_with_tag(
  65. $id, $category, $tag,
  66. ARTWORKS_PER_PAGE * ($current_page - 1), ARTWORKS_PER_PAGE
  67. );
  68. if ($error) { ?>
  69. <p><?= get_string($error); ?></p><?php
  70. break;
  71. }
  72. $artworks = $artworks->body;
  73. $page_count = ceil($artworks->total / ARTWORKS_PER_PAGE); ?>
  74. <h2 id="artworks"><?= sprintf(get_string('user.work-count-with-tag'), htmlspecialchars($tag), $artworks->total) ?></h2>
  75. <div class="frequent-tags">
  76. <a href="<?= "$pathname/$category" ?>"><?= get_string('user.clear-filter') ?></a>
  77. </div><?php
  78. render_artworks_grid($artworks->works);
  79. render_paginator($page_count, $current_page, function($page) use ($pathname, $category, $tag) {
  80. $tag_encoded = urlencode($tag);
  81. return "$pathname/$category/$tag_encoded?p=$page#artworks";
  82. });
  83. break;
  84. default:
  85. /* all/illusts/manga tab without tag */
  86. list($artworks_list, $error) = get_user_artworks_list($id);
  87. if ($error) { ?>
  88. <p><?= get_string($error); ?></p><?php
  89. break;
  90. }
  91. $selected_ids = [];
  92. if ($category == 'artworks' || $category == 'illustrations') {
  93. $selected_ids = array_merge(array_keys($artworks_list['body']['illusts']), $selected_ids);
  94. }
  95. if ($category == 'artworks' || $category == 'manga') {
  96. $selected_ids = array_merge(array_keys($artworks_list['body']['manga']), $selected_ids);
  97. }
  98. rsort($selected_ids);
  99. $artwork_count = count($selected_ids); ?>
  100. <h2 id="artworks"><?= sprintf(get_string('user.work-count'), $artwork_count) ?></h2><?php
  101. if (empty($selected_ids)) { ?>
  102. <p><?= get_string('no-works') ?></p><?php
  103. break;
  104. }
  105. list($frequent_tags, $error) = get_frequent_tags(array_slice($selected_ids, 0, 50));
  106. if (!$error) {
  107. $frequent_tags = $frequent_tags->body ?>
  108. <div class="frequent-tags"><?php
  109. foreach ($frequent_tags as $tag) {
  110. $tag_encoded = urlencode($tag->tag) ?>
  111. <a href="<?= "$pathname/$category/$tag_encoded" ?>">
  112. <b><?= htmlspecialchars($tag->tag) ?></b>
  113. <small><?= htmlspecialchars($tag->tag_translation) ?></small>
  114. </a><?php
  115. } ?>
  116. </div><?php
  117. }
  118. $page_count = ceil($artwork_count / ARTWORKS_PER_PAGE);
  119. $current_page = (
  120. isset($_GET['p']) && ctype_digit($_GET['p']) && $_GET['p'] > 0 && $_GET['p'] <= $page_count
  121. ) ? $_GET['p'] : 1;
  122. $selected_ids_in_page = array_slice($selected_ids, ($current_page - 1) * ARTWORKS_PER_PAGE, ARTWORKS_PER_PAGE);
  123. list($artworks, $error) = get_user_artworks($id, $selected_ids_in_page);
  124. if ($error) { ?>
  125. <p><?= get_string($error) ?></p><?php
  126. }
  127. $artworks = $artworks->body->works;
  128. render_artworks_grid($artworks);
  129. render_paginator($page_count, $current_page, function($page) use ($pathname, $category) {
  130. return "$pathname/$category?p=$page#artworks";
  131. });
  132. } ?>
  133. </div>
  134. <?php
  135. render_page_footer();