BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

commentsview.class.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. #declare(strict_types=1);
  3. class CommentsView
  4. {
  5. /**
  6. * Render a thread of comments
  7. * @param array $Thread An array as returned by Comments::load
  8. * @param int $LastRead PostID of the last read post
  9. * @param string $Baselink Link to the site these comments are on
  10. */
  11. public static function render_comments($Thread, $LastRead, $Baselink)
  12. {
  13. foreach ($Thread as $Post) {
  14. list($PostID, $AuthorID, $AddedTime, $CommentBody, $EditedUserID, $EditedTime, $EditedUsername) = array_values($Post);
  15. self::render_comment($AuthorID, $PostID, $CommentBody, $AddedTime, $EditedUserID, $EditedTime, $Baselink . "&amp;postid=$PostID#post$PostID", ($PostID > $LastRead));
  16. }
  17. }
  18. /**
  19. * Render one comment
  20. * @param int $AuthorID
  21. * @param int $PostID
  22. * @param string $Body
  23. * @param string $AddedTime
  24. * @param int $EditedUserID
  25. * @param string $EditedTime
  26. * @param string $Link The link to the post elsewhere on the site
  27. * @param string $Header The header used in the post
  28. * @param bool $Tools Whether or not to show [Edit], [Report] etc.
  29. *
  30. * todo: Find a better way to pass the page (artist, collages, requests, torrents) to this function than extracting it from $Link
  31. */
  32. public static function render_comment($AuthorID, $PostID, $Body, $AddedTime, $EditedUserID, $EditedTime, $Link, $Unread = false, $Header = '', $Tools = true)
  33. {
  34. $UserInfo = Users::user_info($AuthorID);
  35. $Header = Users::format_username($AuthorID, true, true, true, true, true) . time_diff($AddedTime) . $Header; ?>
  36. <table
  37. class="forum_post box vertical_margin<?=(!Users::has_avatars_enabled() ? ' noavatar' : '') . ($Unread ? ' forum_unread' : '')?>"
  38. id="post<?=$PostID?>">
  39. <colgroup>
  40. <?php if (Users::has_avatars_enabled()) { ?>
  41. <col class="col_avatar" />
  42. <?php } ?>
  43. <col class="col_post_body" />
  44. </colgroup>
  45. <tr class="colhead_dark">
  46. <td colspan="<?=(Users::has_avatars_enabled() ? 2 : 1)?>">
  47. <div class="float_left"><a class="post_id"
  48. href="<?=$Link?>">#<?=$PostID?></a>
  49. <?=$Header?>
  50. <?php if ($Tools) { ?>
  51. - <a href="#quickpost"
  52. onclick="Quote('<?=$PostID?>','<?=$UserInfo['Username']?>', true);"
  53. class="brackets">Quote</a>
  54. <?php if ($AuthorID == G::$LoggedUser['ID'] || check_perms('site_moderate_forums')) { ?>
  55. - <a href="#post<?=$PostID?>"
  56. onclick="Edit_Form('<?=$PostID?>','');"
  57. class="brackets">Edit</a>
  58. <?php }
  59. if (check_perms('site_moderate_forums')) { ?>
  60. - <a href="#post<?=$PostID?>"
  61. onclick="Delete('<?=$PostID?>');"
  62. class="brackets">Delete</a>
  63. <?php } ?>
  64. </div>
  65. <div id="bar<?=$PostID?>" class="float_right">
  66. <a href="reports.php?action=report&amp;type=comment&amp;id=<?=$PostID?>"
  67. class="brackets">Report</a>
  68. <?php
  69. if (check_perms('users_warn') && $AuthorID != G::$LoggedUser['ID'] && G::$LoggedUser['Class'] >= $UserInfo['Class']) {
  70. ?>
  71. <form class="manage_form hidden" name="user"
  72. id="warn<?=$PostID?>" action="comments.php" method="post">
  73. <input type="hidden" name="action" value="warn" />
  74. <input type="hidden" name="postid" value="<?=$PostID?>" />
  75. </form>
  76. - <a href="#"
  77. onclick="$('#warn<?=$PostID?>').raw().submit(); return false;"
  78. class="brackets">Warn</a>
  79. <?php
  80. } ?>
  81. &nbsp;
  82. <a href="#">&uarr;</a>
  83. <?php } ?>
  84. </div>
  85. </td>
  86. </tr>
  87. <tr>
  88. <?php if (Users::has_avatars_enabled()) { ?>
  89. <td class="avatar" valign="top">
  90. <?=Users::show_avatar($UserInfo['Avatar'], $AuthorID, $UserInfo['Username'], G::$LoggedUser['DisableAvatars'])?>
  91. </td>
  92. <?php } ?>
  93. <td class="body" valign="top">
  94. <div id="content<?=$PostID?>">
  95. <?=Text::full_format($Body)?>
  96. <?php if ($EditedUserID) { ?>
  97. <br />
  98. <br />
  99. <div class="last_edited">
  100. <?php if (check_perms('site_admin_forums')) { ?>
  101. <a href="#content<?=$PostID?>"
  102. onclick="LoadEdit('<?=substr($Link, 0, strcspn($Link, '.'))?>', <?=$PostID?>, 1); return false;">&laquo;</a>
  103. <?php } ?>
  104. Last edited by
  105. <?=Users::format_username($EditedUserID, false, false, false) ?>
  106. <?=time_diff($EditedTime, 2, true, true)?>
  107. <?php } ?>
  108. </div>
  109. </div>
  110. </td>
  111. </tr>
  112. </table>
  113. <?php
  114. }
  115. }