Implement capability to pin comments above others
[aur.git] / web / template / pkg_comments.php
blob2046364551d049a0794b419a387984778b5f3fc8
1 <?php
2 if (!isset($count)) {
3 $count = pkgbase_comments_count($base_id, $include_deleted);
5 ?>
6 <div id="news">
7 <h3>
8 <?php if (!isset($comments)): ?>
9 <?php $comments = $pinned ?>
10 <a href="<?= htmlentities(get_pkgbase_uri($pkgbase_name), ENT_QUOTES) . '?' . mkurl('comments=all') ?>" title="<?= __('View all comments' , $count) ?> (<?= $count ?>)"><?= __('Pinned Comments') ?></a>
11 <span class="arrow"></span>
12 <?php else: ?>
13 <a href="<?= htmlentities(get_pkgbase_uri($pkgbase_name), ENT_QUOTES) . '?' . mkurl('comments=all') ?>" title="<?= __('View all comments' , $count) ?> (<?= $count ?>)"><?= __('Latest Comments') ?></a>
14 <span class="arrow"></span>
15 <?php endif; ?>
16 </h3>
18 <?php while (list($indx, $row) = each($comments)): ?>
19 <?php
20 $date_fmtd = gmdate('Y-m-d H:i', $row['CommentTS']);
21 if ($row['UserName']) {
22 $user_fmtd = html_format_username($row['UserName']);
23 $heading = __('%s commented on %s', $user_fmtd, $date_fmtd);
24 } else {
25 $heading = __('Anonymous comment on %s', $date_fmtd);
28 if ($row['EditedTS']) {
29 $date_fmtd = gmdate('Y-m-d H:i', $row['EditedTS']);
30 $heading .= ' <span class="edited">(';
31 if ($row['DelUsersID']) {
32 $user_fmtd = html_format_username($row['DelUserName']);
33 $heading .= __('deleted on %s by %s', $date_fmtd, $user_fmtd);
34 } else {
35 $user_fmtd = html_format_username($row['EditUserName']);
36 $heading .= __('last edited on %s by %s', $date_fmtd, $user_fmtd);
38 $heading .= ')</span>';
41 $row['DelUserName'] = html_format_username($row['DelUserName']);
42 $row['EditUserName'] = html_format_username($row['EditUserName']);
44 <h4 id="comment-<?= $row['ID'] ?>"<?php if ($row['DelUsersID']): ?> class="comment-deleted"<?php endif; ?>>
45 <?= $heading ?>
46 <?php if (!$row['DelUsersID'] && can_delete_comment_array($row)): ?>
47 <form class="delete-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
48 <fieldset style="display:inline;">
49 <input type="hidden" name="action" value="do_DeleteComment" />
50 <input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
51 <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
52 <input type="image" class="delete-comment" src="/images/x.min.svg" width="11" height="11" alt="<?= __('Delete comment') ?>" title="<?= __('Delete comment') ?>" name="submit" value="1" />
53 </fieldset>
54 </form>
55 <?php endif; ?>
56 <?php if (!$row['DelUsersID'] && can_edit_comment_array($row)): ?>
57 <a href="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name) . 'edit-comment/?comment_id=' . $row['ID'], ENT_QUOTES) ?>" class="edit-comment" title="<?= __('Edit comment') ?>"><img src="/images/pencil.min.svg" alt="<?= __('Edit comment') ?>" width="11" height="11"></a>
58 <?php endif; ?>
60 <?php if (!$row['DelUsersID'] && !$row['PinnedTS'] && can_pin_comment_array($row) && !(pkgbase_comments_count($base_id, false, true) >= 5)): ?>
61 <form class="pin-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
62 <fieldset style="display:inline;">
63 <input type="hidden" name="action" value="do_PinComment" />
64 <input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
65 <input type="hidden" name="package_base" value="<?= $base_id ?>" />
66 <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
67 <input type="image" class="pin-comment" src="/images/pin.min.svg" width="11" height="11" alt="<?= __('Pin comment') ?>" title="<?= __('Pin comment') ?>" name="submit" value="1" />
68 </fieldset>
69 </form>
70 <?php endif; ?>
72 <?php if (!$row['DelUsersID'] && $row['PinnedTS'] && can_pin_comment_array($row)): ?>
73 <form class="pin-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
74 <fieldset style="display:inline;">
75 <input type="hidden" name="action" value="do_UnpinComment" />
76 <input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
77 <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
78 <input type="image" class="pin-comment" src="/images/unpin.min.svg" width="11" height="11" alt="<?= __('Unpin comment') ?>" title="<?= __('Unpin comment') ?>" name="submit" value="1" />
79 </fieldset>
80 </form>
81 <?php endif; ?>
82 </h4>
83 <div class="article-content<?php if ($row['DelUsersID']): ?> comment-deleted<?php endif; ?>">
84 <p>
85 <?= parse_comment($row['Comments']) ?>
86 </p>
87 </div>
88 <?php endwhile; ?>
90 <?php if ($count > 10 && !isset($_GET['comments']) && !isset($pinned)): ?>
91 <h3>
92 <a href="<?= htmlentities(get_pkgbase_uri($pkgbase_name), ENT_QUOTES) . '?' . mkurl('comments=all') ?>" title="<?= __('View all comments') ?> (<?= $count ?>)"><?= __('All comments', $count) ?></a>
93 </h3>
94 <?php endif; ?>
95 </div>
96 <script>
97 $(document).ready(function() {
98 $('.edit-comment').click(function () {
99 var parent_element = this.parentElement,
100 parent_id = parent_element.id,
101 comment_id = parent_id.substr(parent_id.indexOf('-') + 1),
102 edit_form = $(parent_element).next(),
103 _this = $(this);
104 add_busy_indicator(_this);
105 $.getJSON('<?= get_uri('/rpc') ?>', {
106 type: 'get-comment-form',
107 arg: comment_id,
108 base_id: <?= intval($base_id) ?>,
109 pkgbase_name: <?= json_encode($pkgbase_name) ?>
110 }, function (data) {
111 remove_busy_indicator(_this);
112 if (data.success) {
113 edit_form.html(data.form);
114 edit_form.find('textarea').focus();
115 } else {
116 alert(data.error);
119 return false;
122 function add_busy_indicator(sibling) {
123 sibling.after('<img src="/images/ajax-loader.gif" class="ajax-loader" width="16" height="11" alt="Busy…" />');
126 function remove_busy_indicator(sibling) {
127 sibling.next().remove();
130 </script>