diff options
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/acctfuncs.inc.php | 42 | ||||
-rw-r--r-- | web/lib/aur.inc.php | 53 | ||||
-rw-r--r-- | web/lib/credentials.inc.php | 2 | ||||
-rw-r--r-- | web/lib/pkgbasefuncs.inc.php | 10 | ||||
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 4 |
5 files changed, 110 insertions, 1 deletions
diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index df573755..dc444842 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -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(); +} diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index feb4006b..e9530fc0 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -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); +} diff --git a/web/lib/credentials.inc.php b/web/lib/credentials.inc.php index d8698a87..c1251197 100644 --- a/web/lib/credentials.inc.php +++ b/web/lib/credentials.inc.php @@ -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: diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 72c33b6d..953a5817 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -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'); } } diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index ad254746..140b8fc2 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.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'); } } |