summaryrefslogtreecommitdiffstats
path: root/web/lib/pkgfuncs.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'web/lib/pkgfuncs.inc.php')
-rw-r--r--web/lib/pkgfuncs.inc.php155
1 files changed, 94 insertions, 61 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index cfdd9a79..568ca3d1 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -432,17 +432,52 @@ function pkgname_is_blacklisted($name, $dbh=NULL) {
}
/**
+ * Get the package details
+ *
+ * @param string $id The package ID to get description for
+ * @param \PDO $dbh An already established database connection
+ *
+ * @return array The package's details OR error message
+ **/
+function get_package_details($id=0, $dbh=NULL) {
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "SELECT Packages.*,Category ";
+ $q.= "FROM Packages,PackageCategories ";
+ $q.= "WHERE Packages.CategoryID = PackageCategories.ID ";
+ $q.= "AND Packages.ID = " . intval($id);
+ $result = $dbh->query($q);
+
+ $row = array();
+
+ if (!$result) {
+ $row['error'] = __("Error retrieving package details.");
+ }
+ else {
+ $row = $result->fetch(PDO::FETCH_ASSOC);
+ if (empty($row)) {
+ $row['error'] = __("Package details could not be found.");
+ }
+ }
+
+ return $row;
+}
+
+/**
* Display the package details page
*
* @global string $AUR_LOCATION The AUR's URL used for notification e-mails
* @global bool $USE_VIRTUAL_URLS True if using URL rewriting, otherwise false
* @param string $id The package ID to get details page for
+ * @param array $row Package details retrieved by get_package_details
* @param string $SID The session ID of the visitor
* @param \PDO $dbh An already established database connection
*
* @return void
*/
-function package_details($id=0, $SID="", $dbh=NULL) {
+function display_package_details($id=0, $row, $SID="", $dbh=NULL) {
global $AUR_LOCATION;
global $USE_VIRTUAL_URLS;
@@ -450,42 +485,28 @@ function package_details($id=0, $SID="", $dbh=NULL) {
$dbh = db_connect();
}
- $q = "SELECT Packages.*,Category ";
- $q.= "FROM Packages,PackageCategories ";
- $q.= "WHERE Packages.CategoryID = PackageCategories.ID ";
- $q.= "AND Packages.ID = " . intval($id);
- $result = $dbh->query($q);
-
- if (!$result) {
- print "<p>" . __("Error retrieving package details.") . "</p>\n";
+ if (isset($row['error'])) {
+ print "<p>" . $row['error'] . "</p>\n";
}
else {
- $row = $result->fetch(PDO::FETCH_ASSOC);
- if (empty($row)) {
- print "<p>" . __("Package details could not be found.") . "</p>\n";
+ include('pkg_details.php');
- }
- else {
- include('pkg_details.php');
-
- # Actions Bar
- if ($SID) {
- include('actions_form.php');
- if (isset($_REQUEST['comment']) && check_token()) {
- $uid = uid_from_sid($SID, $dbh);
- add_package_comment($id, $uid, $_REQUEST['comment'], $dbh);
- }
- include('pkg_comment_form.php');
+ # Actions Bar
+ if ($SID) {
+ include('actions_form.php');
+ if (isset($_REQUEST['comment']) && check_token()) {
+ $uid = uid_from_sid($SID, $dbh);
+ add_package_comment($id, $uid, $_REQUEST['comment'], $dbh);
}
+ include('pkg_comment_form.php');
+ }
- # Print Comments
- $comments = package_comments($id, $dbh);
- if (!empty($comments)) {
- include('pkg_comments.php');
- }
+ # Print Comments
+ $comments = package_comments($id, $dbh);
+ if (!empty($comments)) {
+ include('pkg_comments.php');
}
}
- return;
}
@@ -772,33 +793,24 @@ function sanitize_ids($ids) {
}
/**
- * Flag and un-flag packages out-of-date
+ * Flag package(s) as out-of-date
*
* @global string $AUR_LOCATION The AUR's URL used for notification e-mails
* @param string $atype Account type, output of account_from_sid
* @param array $ids Array of package IDs to flag/unflag
- * @param bool $action true flags out-of-date, false un-flags. Flags by default
*
* @return string Translated success or error messages
*/
-function pkg_flag ($atype, $ids, $action=true, $dbh=NULL) {
+function pkg_flag($atype, $ids, $dbh=NULL) {
global $AUR_LOCATION;
if (!$atype) {
- if ($action) {
- return __("You must be logged in before you can flag packages.");
- } else {
- return __("You must be logged in before you can unflag packages.");
- }
+ return __("You must be logged in before you can flag packages.");
}
$ids = sanitize_ids($ids);
if (empty($ids)) {
- if ($action) {
- return __("You did not select any packages to flag.");
- } else {
- return __("You did not select any packages to unflag.");
- }
+ return __("You did not select any packages to flag.");
}
if(!$dbh) {
@@ -806,25 +818,13 @@ function pkg_flag ($atype, $ids, $action=true, $dbh=NULL) {
}
$q = "UPDATE Packages SET";
- if ($action) {
- $q.= " OutOfDateTS = UNIX_TIMESTAMP()";
- }
- else {
- $q.= " OutOfDateTS = NULL";
- }
+ $q.= " OutOfDateTS = UNIX_TIMESTAMP()";
$q.= " WHERE ID IN (" . implode(",", $ids) . ")";
-
- if (!$action && ($atype != "Trusted User" && $atype != "Developer")) {
- $q.= "AND MaintainerUID = " . uid_from_sid($_COOKIE["AURSID"], $dbh);
- }
-
- if ($action) {
- $q.= " AND OutOfDateTS IS NULL";
- }
+ $q.= " AND OutOfDateTS IS NULL";
$affected_pkgs = $dbh->exec($q);
- if ($action && $affected_pkgs > 0) {
+ if ($affected_pkgs > 0) {
# Notify of flagging by email
$f_name = username_from_sid($_COOKIE['AURSID'], $dbh);
$f_email = email_from_sid($_COOKIE['AURSID'], $dbh);
@@ -846,9 +846,42 @@ function pkg_flag ($atype, $ids, $action=true, $dbh=NULL) {
}
}
- if ($action) {
- return __("The selected packages have been flagged out-of-date.");
- } else {
+ return __("The selected packages have been flagged out-of-date.");
+}
+
+/**
+ * Unflag package(s) as out-of-date
+ *
+ * @param string $atype Account type, output of account_from_sid
+ * @param array $ids Array of package IDs to flag/unflag
+ *
+ * @return string Translated success or error messages
+ */
+function pkg_unflag($atype, $ids, $dbh=NULL) {
+ if (!$atype) {
+ return __("You must be logged in before you can unflag packages.");
+ }
+
+ $ids = sanitize_ids($ids);
+ if (empty($ids)) {
+ return __("You did not select any packages to unflag.");
+ }
+
+ if(!$dbh) {
+ $dbh = db_connect();
+ }
+
+ $q = "UPDATE Packages SET ";
+ $q.= "OutOfDateTS = NULL ";
+ $q.= "WHERE ID IN (" . implode(",", $ids) . ") ";
+
+ if ($atype != "Trusted User" && $atype != "Developer") {
+ $q.= "AND MaintainerUID = " . uid_from_sid($_COOKIE["AURSID"], $dbh);
+ }
+
+ $result = $dbh->exec($q);
+
+ if ($result) {
return __("The selected packages have been unflagged.");
}
}