mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Allow listing all comments from a user
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
a7865ef5aa
commit
3578e77ad4
12 changed files with 258 additions and 30 deletions
|
@ -1403,3 +1403,45 @@ function accept_terms($uid, $termrev) {
|
|||
$dbh->exec($q);
|
||||
}
|
||||
}
|
||||
|
||||
function account_comments($uid, $limit, $offset=0) {
|
||||
$dbh = DB::connect();
|
||||
$q = "SELECT PackageComments.ID, Comments, UsersID, ";
|
||||
$q.= "PackageBaseId, CommentTS, DelTS, EditedTS, B.UserName AS EditUserName, ";
|
||||
$q.= "PinnedTS, ";
|
||||
$q.= "C.UserName as DelUserName, RenderedComment, ";
|
||||
$q.= "PB.ID as PackageBaseID, PB.Name as PackageBaseName ";
|
||||
$q.= "FROM PackageComments ";
|
||||
$q.= "LEFT JOIN PackageBases PB ON PackageComments.PackageBaseID = PB.ID ";
|
||||
$q.= "LEFT JOIN Users A ON PackageComments.UsersID = A.ID ";
|
||||
$q.= "LEFT JOIN Users B ON PackageComments.EditedUsersID = B.ID ";
|
||||
$q.= "LEFT JOIN Users C ON PackageComments.DelUsersID = C.ID ";
|
||||
$q.= "WHERE A.ID = " . $dbh->quote($uid) . " ";
|
||||
$q.= "ORDER BY CommentTS DESC";
|
||||
|
||||
if ($limit > 0) {
|
||||
$q.=" LIMIT " . intval($limit);
|
||||
}
|
||||
|
||||
if ($offset > 0) {
|
||||
$q.=" OFFSET " . intval($offset);
|
||||
}
|
||||
|
||||
$result = $dbh->query($q);
|
||||
if (!$result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $result->fetchAll();
|
||||
}
|
||||
|
||||
function account_comments_count($uid) {
|
||||
$dbh = DB::connect();
|
||||
$q = "SELECT COUNT(*) ";
|
||||
$q.= "FROM PackageComments ";
|
||||
$q.= "LEFT JOIN Users A ON PackageComments.UsersID = A.ID ";
|
||||
$q.= "WHERE A.ID = " . $dbh->quote($uid);
|
||||
|
||||
$result = $dbh->query($q);
|
||||
return $result->fetchColumn();
|
||||
}
|
||||
|
|
|
@ -705,3 +705,56 @@ function aur_location() {
|
|||
}
|
||||
return $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate pagination templates
|
||||
*
|
||||
* @return array The array of pagination templates, per page, and offset values
|
||||
*/
|
||||
function calculate_pagination($total_comment_count) {
|
||||
/* Sanitize paging variables. */
|
||||
if (isset($_GET["O"])) {
|
||||
$_GET["O"] = max(intval($_GET["O"]), 0);
|
||||
} else {
|
||||
$_GET["O"] = 0;
|
||||
}
|
||||
$offset = $_GET["O"];
|
||||
|
||||
if (isset($_GET["PP"])) {
|
||||
$_GET["PP"] = bound(intval($_GET["PP"]), 1, 250);
|
||||
} else {
|
||||
$_GET["PP"] = 10;
|
||||
}
|
||||
$per_page = $_GET["PP"];
|
||||
|
||||
// Page offsets start at zero, so page 2 has offset 1, which means that we
|
||||
// need to add 1 to the offset to get the current page.
|
||||
$current_page = ceil($offset / $per_page) + 1;
|
||||
$num_pages = ceil($total_comment_count / $per_page);
|
||||
$pagination_templs = array();
|
||||
|
||||
if ($current_page > 1) {
|
||||
$previous_page = $current_page - 1;
|
||||
$previous_offset = ($previous_page - 1) * $per_page;
|
||||
$pagination_templs['« ' . __('First')] = 0;
|
||||
$pagination_templs['‹ ' . __('Previous')] = $previous_offset;
|
||||
}
|
||||
|
||||
if ($current_page - 5 > 1) {
|
||||
$pagination_templs["..."] = false;
|
||||
}
|
||||
|
||||
for ($i = max($current_page - 5, 1); $i <= min($num_pages, $current_page + 5); $i++) {
|
||||
$pagination_templs[$i] = ($i - 1) * $per_page;
|
||||
}
|
||||
|
||||
if ($current_page + 5 < $num_pages)
|
||||
$pagination_templs["... "] = false;
|
||||
|
||||
if ($current_page < $num_pages) {
|
||||
$pagination_templs[__('Next') . ' ›'] = $current_page * $per_page;
|
||||
$pagination_templs[__('Last') . ' »'] = ($num_pages - 1) * $per_page;
|
||||
}
|
||||
|
||||
return array($pagination_templs, $per_page, $offset);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ define("CRED_ACCOUNT_EDIT", 2);
|
|||
define("CRED_ACCOUNT_EDIT_DEV", 3);
|
||||
define("CRED_ACCOUNT_LAST_LOGIN", 4);
|
||||
define("CRED_ACCOUNT_SEARCH", 5);
|
||||
define("CRED_ACCOUNT_LIST_COMMENTS", 28);
|
||||
define("CRED_COMMENT_DELETE", 6);
|
||||
define("CRED_COMMENT_UNDELETE", 27);
|
||||
define("CRED_COMMENT_VIEW_DELETED", 22);
|
||||
|
@ -48,6 +49,7 @@ function has_credential($credential, $approved_users=array()) {
|
|||
$atype = account_from_sid($_COOKIE['AURSID']);
|
||||
|
||||
switch ($credential) {
|
||||
case CRED_ACCOUNT_LIST_COMMENTS:
|
||||
case CRED_PKGBASE_FLAG:
|
||||
case CRED_PKGBASE_NOTIFY:
|
||||
case CRED_PKGBASE_VOTE:
|
||||
|
|
|
@ -44,7 +44,7 @@ function pkgbase_comments_count($base_id, $include_deleted, $only_pinned=false)
|
|||
*
|
||||
* @return array All package comment information for a specific package base
|
||||
*/
|
||||
function pkgbase_comments($base_id, $limit, $include_deleted, $only_pinned=false) {
|
||||
function pkgbase_comments($base_id, $limit, $include_deleted, $only_pinned=false, $offset=0) {
|
||||
$base_id = intval($base_id);
|
||||
$limit = intval($limit);
|
||||
if (!$base_id) {
|
||||
|
@ -71,6 +71,9 @@ function pkgbase_comments($base_id, $limit, $include_deleted, $only_pinned=false
|
|||
if ($limit > 0) {
|
||||
$q.=" LIMIT " . $limit;
|
||||
}
|
||||
if ($offset > 0) {
|
||||
$q.=" OFFSET " . $offset;
|
||||
}
|
||||
$result = $dbh->query($q);
|
||||
if (!$result) {
|
||||
return null;
|
||||
|
@ -273,6 +276,7 @@ function pkgbase_display_details($base_id, $row, $SID="") {
|
|||
include('pkgbase_details.php');
|
||||
|
||||
if ($SID) {
|
||||
$comment_section = "package";
|
||||
include('pkg_comment_box.php');
|
||||
}
|
||||
|
||||
|
@ -281,13 +285,17 @@ function pkgbase_display_details($base_id, $row, $SID="") {
|
|||
$limit_pinned = isset($_GET['pinned']) ? 0 : 5;
|
||||
$pinned = pkgbase_comments($base_id, $limit_pinned, false, true);
|
||||
if (!empty($pinned)) {
|
||||
$comment_section = "package";
|
||||
include('pkg_comments.php');
|
||||
}
|
||||
unset($pinned);
|
||||
|
||||
|
||||
$limit = isset($_GET['comments']) ? 0 : 10;
|
||||
$comments = pkgbase_comments($base_id, $limit, $include_deleted);
|
||||
|
||||
if (!empty($comments)) {
|
||||
$comment_section = "package";
|
||||
include('pkg_comments.php');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -624,13 +624,17 @@ function pkg_display_details($id=0, $row, $SID="") {
|
|||
$limit_pinned = isset($_GET['pinned']) ? 0 : 5;
|
||||
$pinned = pkgbase_comments($base_id, $limit_pinned, false, true);
|
||||
if (!empty($pinned)) {
|
||||
$comment_section = "package";
|
||||
include('pkg_comments.php');
|
||||
}
|
||||
unset($pinned);
|
||||
|
||||
|
||||
$limit = isset($_GET['comments']) ? 0 : 10;
|
||||
$comments = pkgbase_comments($base_id, $limit, $include_deleted);
|
||||
|
||||
if (!empty($comments)) {
|
||||
$comment_section = "package";
|
||||
include('pkg_comments.php');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue