[aur-dev] [PATCH v2 2/2] Implement capability to pin comments above others

Mark Weiman mark.weiman at markzz.com
Thu Dec 3 21:19:23 UTC 2015


Implements FS#10863

Signed-off-by: Mark Weiman <mark.weiman at markzz.com>
---
 web/html/css/aurweb.css       | 18 ++++++++++++++++--
 web/lib/pkgbasefuncs.inc.php  | 10 +++++++++-
 web/lib/pkgfuncs.inc.php      | 10 +++++++++-
 web/template/pkg_comments.php | 41 ++++++++++++++++++++++++++++++++++++-----
 4 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/web/html/css/aurweb.css b/web/html/css/aurweb.css
index 11af747..5b36df0 100644
--- a/web/html/css/aurweb.css
+++ b/web/html/css/aurweb.css
@@ -101,7 +101,7 @@
 	color: #999;
 }
 
-.delete-comment-form, .edit-comment {
+.delete-comment-form, .pin-comment-form, .edit-comment {
 	float: right;
 	margin-left: 8px;
 }
@@ -118,12 +118,26 @@
 	opacity: 0.6;
 }
 
-.delete-comment:hover, .edit-comment:hover {
+.delete-comment:hover, .edit-comment:hover, .pin-comment:hover {
 	-webkit-filter: none;
 	filter: none;
 	opacity: 1;
 }
 
+.pin-comment {
+    float: right;
+    font-weight: 600;
+    background: none!important;
+    border: none; 
+    padding: 0!important;
+    font: inherit;
+    cursor: pointer;
+    color: #3366aa;
+    -webkit-filter: grayscale(100%);
+    filter: grayscale(100%);
+    opacity: 0.6;
+}
+
 .ajax-loader {
 	float: right;
 	position: relative;
diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php
index bb050a6..ea3ce0d 100644
--- a/web/lib/pkgbasefuncs.inc.php
+++ b/web/lib/pkgbasefuncs.inc.php
@@ -264,9 +264,17 @@ function pkgbase_display_details($base_id, $row, $SID="") {
 		if ($SID) {
 			include('pkg_comment_box.php');
 		}
+		
+		$include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED);
+
+        $limit_pinned = isset($_GET['pinned']) ? 0 : 5;
+        $pinned = pkgbase_comments($base_id, $limit_pinned, false, true);
+        if (!empty($pinned)) {
+            include('pkg_comments.php');
+            unset($pinned);
+        }
 
 		$limit = isset($_GET['comments']) ? 0 : 10;
-		$include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED);
 		$comments = pkgbase_comments($base_id, $limit, $include_deleted);
 		if (!empty($comments)) {
 			include('pkg_comments.php');
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index 1c15114..c0ed99c 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -622,9 +622,17 @@ function pkg_display_details($id=0, $row, $SID="") {
 		if ($SID) {
 			include('pkg_comment_box.php');
 		}
+		
+		$include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED);
+
+        $limit_pinned = isset($_GET['pinned']) ? 0 : 5;
+        $pinned = pkgbase_comments($base_id, $limit_pinned, false, true);
+        if (!empty($pinned)) {
+            include('pkg_comments.php');
+            unset($pinned);
+        }
 
 		$limit = isset($_GET['comments']) ? 0 : 10;
-		$include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED);
 		$comments = pkgbase_comments($base_id, $limit, $include_deleted);
 		if (!empty($comments)) {
 			include('pkg_comments.php');
diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php
index 21ce16f..8f1fb9f 100644
--- a/web/template/pkg_comments.php
+++ b/web/template/pkg_comments.php
@@ -6,13 +6,20 @@ if (isset($row['BaseID'])) {
 	/* On a package base details page. */
 	$base_id = $row['ID'];
 }
-$include_deleted = has_credential(CRED_COMMENT_VIEW_DELETED);
-$count = pkgbase_comments_count($base_id, $include_deleted);
+if (!isset($count)) {
+	$count = pkgbase_comments_count($base_id, $include_deleted);
+}
 ?>
 <div id="news">
 	<h3>
-		<a href="<?= htmlentities(get_pkgbase_uri($pkgbase_name), ENT_QUOTES) . '?' . mkurl('comments=all') ?>" title="<?= __('View all comments' , $count) ?> (<?= $count ?>)"><?= __('Latest Comments') ?></a>
-		<span class="arrow"></span>
+       <?php if (!isset($comments)): ?>
+    	    <?php $comments = $pinned ?>
+       		<a href="<?= htmlentities(get_pkgbase_uri($pkgbase_name), ENT_QUOTES) . '?' . mkurl('comments=all') ?>" title="<?= __('View all comments' , $count) ?> (<?= $count ?>)"><?= __('Pinned Comments') ?></a>
+               <span class="arrow"></span>
+               <?php else: ?>
+                <a href="<?= htmlentities(get_pkgbase_uri($pkgbase_name), ENT_QUOTES) . '?' . mkurl('comments=all') ?>" title="<?= __('View all comments' , $count) ?> (<?= $count ?>)"><?= __('Latest Comments') ?></a>
+               <span class="arrow"></span>
+               <?php endif; ?>
 	</h3>
 
 	<?php while (list($indx, $row) = each($comments)): ?>
@@ -56,6 +63,30 @@ $count = pkgbase_comments_count($base_id, $include_deleted);
 			<?php if (!$row['DelUsersID'] && can_edit_comment_array($row)): ?>
 			<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>
 			<?php endif; ?>
+
+            <?php if (!$row['DelUsersID'] && !$row['PinnedUsersID'] && can_pin_comment_array($row)): ?>
+            	<form class="pin-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
+                	<fieldset style="display:inline;">
+                    	<input type="hidden" name="action" value="do_PinComment" />
+                        <input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
+                        <input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
+                        <input type="submit" class="pin-comment" value="<?= __('Pin') ?>" width="11" height="11" 
+                               alt="<?= __('Pin comment') ?>" title="<?= __('Pin comment') ?>" name="submit" value="1" />
+                    </fieldset>
+            	</form>
+            <?php endif; ?>
+                       
+            <?php if (!$row['DelUsersID'] && $row['PinnedUsersID'] && can_pin_comment_array($row)): ?>
+            	<form class="pin-comment-form" method="post" action="<?= htmlspecialchars(get_pkgbase_uri($pkgbase_name), ENT_QUOTES); ?>">
+            		<fieldset style="display:inline;">
+            			<input type="hidden" name="action" value="do_UnpinComment" />
+            			<input type="hidden" name="comment_id" value="<?= $row['ID'] ?>" />
+            			<input type="hidden" name="token" value="<?= htmlspecialchars($_COOKIE['AURSID']) ?>" />
+            			<input type="submit" class="pin-comment" value="<?= __('Unpin') ?>" width="11" height="11" 
+                               alt="<?= __('Unin comment') ?>" title="<?= __('Pin comment') ?>" name="submit" value="1" />
+            		</fieldset>
+            	</form>
+            <?php endif; ?>
 		</h4>
 		<div class="article-content<?php if ($row['DelUsersID']): ?> comment-deleted<?php endif; ?>">
 			<p>
@@ -64,7 +95,7 @@ $count = pkgbase_comments_count($base_id, $include_deleted);
 		</div>
 	<?php endwhile; ?>
 
-<?php if ($count > 10 && !isset($_GET['comments'])): ?>
+<?php if ($count > 10 && !isset($_GET['comments']) && !isset($pinned)): ?>
 	<h3>
 		<a href="<?= htmlentities(get_pkgbase_uri($pkgbase_name), ENT_QUOTES) . '?' . mkurl('comments=all') ?>" title="<?= __('View all comments') ?> (<?= $count ?>)"><?= __('All comments', $count) ?></a>
 	</h3>
-- 
2.6.3


More information about the aur-dev mailing list