summaryrefslogtreecommitdiffstats
path: root/web/lib/pkgfuncs.inc.php
diff options
context:
space:
mode:
authorMark Weiman <mark.weiman@markzz.com>2015-12-12 01:01:31 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2015-12-12 15:09:47 +0100
commit7d4c0c9ffa55ca60aea24b6aa64417783a15ea80 (patch)
treed5f9ddb43f6af10feb2ac375ed4ad87bf4771c93 /web/lib/pkgfuncs.inc.php
parent3088fd0f389dbe4be1c7e62931ed18658ca6d7a2 (diff)
downloadaur-7d4c0c9ffa55ca60aea24b6aa64417783a15ea80.tar.gz
aur-7d4c0c9ffa55ca60aea24b6aa64417783a15ea80.tar.xz
Implement capability to pin comments above others
Adds capability to pin comments before others. Implements FS#10863. Signed-off-by: Mark Weiman <mark.weiman@markzz.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web/lib/pkgfuncs.inc.php')
-rw-r--r--web/lib/pkgfuncs.inc.php51
1 files changed, 50 insertions, 1 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index cedc360e..c2bbe387 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -83,6 +83,47 @@ function can_edit_comment_array($comment) {
}
/**
+ * Determine if the user can pin a specific package comment
+ *
+ * Only the Package Maintainer, Trusted Users, and Developers can pin
+ * comments. This function is used for the backend side of comment pinning.
+ *
+ * @param string $comment_id The comment ID in the database
+ *
+ * @return bool True if the user can pin the comment, otherwise false
+ */
+function can_pin_comment($comment_id=0) {
+ $dbh = DB::connect();
+
+ $q = "SELECT MaintainerUID FROM PackageBases AS pb ";
+ $q.= "LEFT JOIN PackageComments AS pc ON pb.ID = pc.PackageBaseID ";
+ $q.= "WHERE pc.ID = " . intval($comment_id);
+ $result = $dbh->query($q);
+
+ if (!$result) {
+ return false;
+ }
+
+ $uid = $result->fetch(PDO::FETCH_COLUMN, 0);
+
+ return has_credential(CRED_COMMENT_PIN, array($uid));
+}
+
+/**
+ * Determine if the user can edit a specific package comment using an array
+ *
+ * Only the Package Maintainer, Trusted Users, and Developers can pin
+ * comments. This function is used for the frontend side of comment pinning.
+ *
+ * @param array $comment All database information relating a specific comment
+ *
+ * @return bool True if the user can edit the comment, otherwise false
+ */
+function can_pin_comment_array($comment) {
+ return can_pin_comment($comment['ID']);
+}
+
+/**
* Check to see if the package name already exists in the database
*
* @param string $name The package name to check
@@ -582,8 +623,16 @@ function pkg_display_details($id=0, $row, $SID="") {
include('pkg_comment_box.php');
}
- $limit = isset($_GET['comments']) ? 0 : 10;
$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;
$comments = pkgbase_comments($base_id, $limit, $include_deleted);
if (!empty($comments)) {
include('pkg_comments.php');