12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- const COMMENTS_PREVIEW = 5;
- const COMMENTS_PER_PAGE = 20;
- const EMOJI_IDS = [
- 'normal' => '101',
- 'surprise' => '102',
- 'serious' => '103',
- 'heaven' => '104',
- 'happy' => '105',
- 'excited' => '106',
- 'sing' => '107',
- 'cry' => '108',
- 'normal2' => '201',
- 'shame2' => '202',
- 'love2' => '203',
- 'interesting2' => '204',
- 'blush2' => '205',
- 'fire2' => '206',
- 'angry2' => '207',
- 'shine2' => '208',
- 'panic2' => '209',
- 'normal3' => '301',
- 'satisfaction3' => '302',
- 'surprise3' => '303',
- 'smile3' => '304',
- 'shock3' => '305',
- 'gaze3' => '306',
- 'wink3' => '307',
- 'happy3' => '308',
- 'excited3' => '309',
- 'love3' => '310',
- 'normal4' => '401',
- 'surprise4' => '402',
- 'serious4' => '403',
- 'love4' => '404',
- 'shine4' => '405',
- 'sweat4' => '406',
- 'shame4' => '407',
- 'sleep4' => '408',
- 'heart' => '501',
- 'teardrop' => '502',
- 'star' => '503'
- ];
- function parse_comment($comment) {
- return preg_replace_callback('/\((.+?)\)/', function($matches) {
- if (isset(EMOJI_IDS[$matches[1]])) {
- $emoji_url = get_proxy_url('https://s.pximg.net/common/images/emoji/' . EMOJI_IDS[$matches[1]] . '.png');
- return "<img loading='lazy' class='emoji' src='{$emoji_url}' alt=' '>";
- }
- else return $matches[0];
- }, $comment);
- }
- function render_comment_list($comments) {
- if (!$comments) { ?>
- <p><?= get_string('artwork.comments-failed') ?></p><?php
- return;
- }
- foreach ($comments as $comment) { ?>
- <div class="comment">
- <div>
- <a href="<?= BASE_URL ?>/users/<?= $comment->commentUserId ?>">
- <img loading="lazy" class="avatar" src="<?= get_proxy_url($comment->img) ?>" alt=" ">
- </a>
- </div>
- <div>
- <div class="comment-info">
- <a href="<?= BASE_URL ?>/users/<?= $comment->commentUserId ?>">
- <?= htmlspecialchars($comment->userName) ?>
- </a><small><?= format_date($comment->commentDate, 'Asia/Tokyo') ?></small>
- </div>
- <p class="comment-content"><?php
- if ($comment->comment) {
- echo parse_comment($comment->comment);
- }
- else {
- $stamp_url = get_proxy_url('https://s.pximg.net/common/images/stamp/generated-stamps/' . $comment->stampId . '_s.jpg');
- echo "<img loading='lazy' class='stamp' src='{$stamp_url}' alt=' '>";
- } ?>
- </p><?php
- if (isset($comment->hasReplies) && $comment->hasReplies) { ?>
- <a class="button" target="_blank" href="<?= BASE_URL ?>/artworks/comments.php?type=replies&id=<?= $comment->id ?>">
- <?= get_string('artwork.view-replies') ?>
- </a><?php
- } ?>
- </div>
- </div><?php
- }
- }
|