Erase login IP addresses after seven days
[aur.git] / web / template / pkg_comments.php
blob7d9bedcce51f64d0a90760731a0f36e277c25e90
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 = date('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 $is_deleted = $row['DelTS'];
29 $is_edited = $row['EditedTS'];
30 $is_pinned = $row['PinnedTS'];
32 if ($uid && $is_deleted) {
33 $date_fmtd = date('Y-m-d H:i', $row['DelTS']);
34 $heading .= ' <span class="edited">(';
35 if ($row['DelUserName']) {
36 $user_fmtd = html_format_username($row['DelUserName']);
37 $heading .= __('deleted on %s by %s', $date_fmtd, $user_fmtd);
38 } else {
39 $heading .= __('deleted on %s', $date_fmtd);
41 $heading .= ')</span>';
42 } elseif ($uid && $is_edited) {
43 $date_fmtd = date('Y-m-d H:i', $row['EditedTS']);
44 $heading .= ' <span class="edited">(';
45 if ($row['EditUserName']) {
46 $user_fmtd = html_format_username($row['EditUserName']);
47 $heading .= __('edited on %s by %s', $date_fmtd, $user_fmtd);
48 } else {
49 $heading .= __('edited on %s', $date_fmtd);
51 $heading .= ')</span>';
54 <h4 id="<?= isset($pinned) ? "pinned-" : "comment-" ?><?= $row['ID'] ?>"<?php if ($is_deleted): ?> class="comment-deleted"<?php endif; ?>>
55 <?= $heading ?>
56 <?php if ($is_deleted && has_credential(CRED_COMMENT_UNDELETE)): ?>
57 <form class="undelete-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
58 <fieldset style="display:inline;">
59 <input type="hidden" name="action" value="do_UndeleteComment" />
60 <input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
61 <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
62 <input type="image" class="undelete-comment" src="/images/action-undo.min.svg" width="11" height="11" alt="<?= __('Undelete comment') ?>" title="<?= __('Undelete comment') ?>" name="submit" value="1" />
63 </fieldset>
64 </form>
65 <?php endif;?>
67 <?php if (!$is_deleted && can_delete_comment_array($row)): ?>
68 <form class="delete-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
69 <fieldset style="display:inline;">
70 <input type="hidden" name="action" value="do_DeleteComment" />
71 <input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
72 <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
73 <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" />
74 </fieldset>
75 </form>
76 <?php endif; ?>
78 <?php if (!$is_deleted && can_edit_comment_array($row)): ?>
79 <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>
80 <?php endif; ?>
82 <?php if (!$is_deleted && !$is_pinned && can_pin_comment_array($row) && !(pkgbase_comments_count($base_id, false, true) >= 5)): ?>
83 <form class="pin-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
84 <fieldset style="display:inline;">
85 <input type="hidden" name="action" value="do_PinComment" />
86 <input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
87 <input type="hidden" name="package_base" value="<?= $base_id ?>" />
88 <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
89 <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" />
90 </fieldset>
91 </form>
92 <?php endif; ?>
94 <?php if (!$is_deleted && $is_pinned && can_pin_comment_array($row)): ?>
95 <form class="pin-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
96 <fieldset style="display:inline;">
97 <input type="hidden" name="action" value="do_UnpinComment" />
98 <input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
99 <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
100 <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" />
101 </fieldset>
102 </form>
103 <?php endif; ?>
104 </h4>
105 <div id="<?= isset($pinned) ? "pinned-" : "comment-" ?><?= $row['ID'] ?>-content" class="article-content<?php if ($is_deleted): ?> comment-deleted<?php endif; ?>">
106 <div>
107 <?php if (!empty($row['RenderedComment'])): ?>
108 <?= $row['RenderedComment'] ?>
109 <?php else: ?>
111 <?= parse_comment($row['Comments']) ?>
112 </p>
113 <?php endif; ?>
114 </div>
115 </div>
116 <?php endwhile; ?>
118 <?php if ($count > 10 && !isset($_GET['comments']) && !isset($pinned)): ?>
119 <h3>
120 <a href="<?= htmlentities(get_pkgbase_uri($pkgbase_name), ENT_QUOTES) . '?' . mkurl('comments=all') ?>" title="<?= __('View all comments') ?> (<?= $count ?>)"><?= __('All comments', $count) ?></a>
121 </h3>
122 <?php endif; ?>
123 </div>
124 <script>
125 $(document).ready(function() {
126 $('.edit-comment').click(function () {
127 var parent_element = this.parentElement,
128 parent_id = parent_element.id,
129 comment_id = parent_id.substr(parent_id.indexOf('-') + 1),
130 edit_form = $(parent_element).next(),
131 _this = $(this);
132 add_busy_indicator(_this);
133 $.getJSON('<?= get_uri('/rpc') ?>', {
134 type: 'get-comment-form',
135 arg: comment_id,
136 base_id: <?= intval($base_id) ?>,
137 pkgbase_name: <?= json_encode($pkgbase_name) ?>
138 }, function (data) {
139 remove_busy_indicator(_this);
140 if (data.success) {
141 edit_form.html(data.form);
142 edit_form.find('textarea').focus();
143 } else {
144 alert(data.error);
147 return false;
150 function add_busy_indicator(sibling) {
151 sibling.after('<img src="/images/ajax-loader.gif" class="ajax-loader" width="16" height="11" alt="Busy…" />');
154 function remove_busy_indicator(sibling) {
155 sibling.next().remove();
158 </script>