comments.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. require_once __DIR__ . '/../include/utils.php';
  3. require_once __DIR__ . '/../include/comments.php';
  4. if (!isset($_GET['id']) || !ctype_digit($_GET['id'])) {
  5. die_with_message(400, get_string('illegal-id'));
  6. }
  7. $is_replies = (isset($_GET['type']) && $_GET['type'] == 'replies');
  8. $id = $_GET['id'];
  9. $current_page = (isset($_GET['p']) && ctype_digit($_GET['p']) && $_GET['p'] > 0) ? $_GET['p'] : 1;
  10. list($comments, $error) = $is_replies
  11. ? get_artwork_comment_replies($id, $current_page)
  12. : get_artwork_comments($id, COMMENTS_PER_PAGE * ($current_page - 1), COMMENTS_PER_PAGE);
  13. if ($error) {
  14. die_with_message(500, get_string($error));
  15. }
  16. $comments = $comments->body;
  17. $title = sprintf(get_string($is_replies ? 'artwork.replies-popup' : 'artwork.comments-popup'), $id);
  18. render_page_header($title);
  19. ?>
  20. <div class="container container-card">
  21. <div class="comments">
  22. <h1><?= $title ?></h1>
  23. <?php render_comment_list($comments->comments) ?>
  24. <p class="paginator"><?php
  25. $query_prefix = $is_replies ? "?type=replies&id=$id&p=" : "?id=$id&p=";
  26. if ($current_page != 1) { ?>
  27. <a href="<?= $query_prefix . ($current_page - 1) ?>">◂</a><?php
  28. } ?>
  29. <a class="selected"><?= $current_page ?></a><?php
  30. if ($comments->hasNext) { ?>
  31. <a href="<?= $query_prefix . ($current_page + 1) ?>">▸</a><?php
  32. } ?>
  33. </p>
  34. </div>
  35. </div>
  36. <?php
  37. render_page_footer();