comments.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. const COMMENTS_PREVIEW = 5;
  3. const COMMENTS_PER_PAGE = 20;
  4. const EMOJI_IDS = [
  5. 'normal' => '101',
  6. 'surprise' => '102',
  7. 'serious' => '103',
  8. 'heaven' => '104',
  9. 'happy' => '105',
  10. 'excited' => '106',
  11. 'sing' => '107',
  12. 'cry' => '108',
  13. 'normal2' => '201',
  14. 'shame2' => '202',
  15. 'love2' => '203',
  16. 'interesting2' => '204',
  17. 'blush2' => '205',
  18. 'fire2' => '206',
  19. 'angry2' => '207',
  20. 'shine2' => '208',
  21. 'panic2' => '209',
  22. 'normal3' => '301',
  23. 'satisfaction3' => '302',
  24. 'surprise3' => '303',
  25. 'smile3' => '304',
  26. 'shock3' => '305',
  27. 'gaze3' => '306',
  28. 'wink3' => '307',
  29. 'happy3' => '308',
  30. 'excited3' => '309',
  31. 'love3' => '310',
  32. 'normal4' => '401',
  33. 'surprise4' => '402',
  34. 'serious4' => '403',
  35. 'love4' => '404',
  36. 'shine4' => '405',
  37. 'sweat4' => '406',
  38. 'shame4' => '407',
  39. 'sleep4' => '408',
  40. 'heart' => '501',
  41. 'teardrop' => '502',
  42. 'star' => '503'
  43. ];
  44. function parse_comment($comment) {
  45. return preg_replace_callback('/\((.+?)\)/', function($matches) {
  46. if (isset(EMOJI_IDS[$matches[1]])) {
  47. $emoji_url = get_proxy_url('https://s.pximg.net/common/images/emoji/' . EMOJI_IDS[$matches[1]] . '.png');
  48. return "<img loading='lazy' class='emoji' src='{$emoji_url}' alt=' '>";
  49. }
  50. else return $matches[0];
  51. }, $comment);
  52. }
  53. function render_comment_list($comments) {
  54. if (!$comments) { ?>
  55. <p><?= get_string('artwork.comments-failed') ?></p><?php
  56. return;
  57. }
  58. foreach ($comments as $comment) { ?>
  59. <div class="comment">
  60. <div>
  61. <a href="<?= BASE_URL ?>/users/<?= $comment->commentUserId ?>">
  62. <img loading="lazy" class="avatar" src="<?= get_proxy_url($comment->img) ?>" alt=" ">
  63. </a>
  64. </div>
  65. <div>
  66. <div class="comment-info">
  67. <a href="<?= BASE_URL ?>/users/<?= $comment->commentUserId ?>">
  68. <?= htmlspecialchars($comment->userName) ?>
  69. </a><small><?= format_date($comment->commentDate, 'Asia/Tokyo') ?></small>
  70. </div>
  71. <p class="comment-content"><?php
  72. if ($comment->comment) {
  73. echo parse_comment($comment->comment);
  74. }
  75. else {
  76. $stamp_url = get_proxy_url('https://s.pximg.net/common/images/stamp/generated-stamps/' . $comment->stampId . '_s.jpg');
  77. echo "<img loading='lazy' class='stamp' src='{$stamp_url}' alt=' '>";
  78. } ?>
  79. </p><?php
  80. if (isset($comment->hasReplies) && $comment->hasReplies) { ?>
  81. <a class="button" target="_blank" href="<?= BASE_URL ?>/artworks/comments.php?type=replies&id=<?= $comment->id ?>">
  82. <?= get_string('artwork.view-replies') ?>
  83. </a><?php
  84. } ?>
  85. </div>
  86. </div><?php
  87. }
  88. }