summaryrefslogtreecommitdiffstats
path: root/web/lib
diff options
context:
space:
mode:
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/aur.inc.php2
-rw-r--r--web/lib/aurjson.class.php22
-rw-r--r--web/lib/pkgfuncs.inc.php155
3 files changed, 116 insertions, 63 deletions
diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php
index e02c8353..d8c5cb49 100644
--- a/web/lib/aur.inc.php
+++ b/web/lib/aur.inc.php
@@ -297,7 +297,7 @@ function db_connect() {
*
* @return void
*/
-function html_header($title="") {
+function html_header($title="", $details=array()) {
global $AUR_LOCATION;
global $DISABLE_HTTP_LOGIN;
global $LANG;
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 949c34f3..616b7838 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -15,7 +15,7 @@ include_once("aur.inc.php");
class AurJSON {
private $dbh = false;
private static $exposed_methods = array(
- 'search', 'info', 'multiinfo', 'msearch'
+ 'search', 'info', 'multiinfo', 'msearch', 'suggest'
);
private static $fields = array(
'Packages.ID', 'Name', 'Version', 'CategoryID', 'Description', 'URL',
@@ -276,5 +276,25 @@ class AurJSON {
return $this->process_query('msearch', $where_condition);
}
+
+ /**
+ * Get all package names that start with $search.
+ * @param string $search Search string.
+ * @return string The JSON formatted response data.
+ **/
+ private function suggest($search) {
+ $query = 'SELECT Name FROM Packages WHERE Name LIKE ' .
+ $this->dbh->quote(addcslashes($search, '%_') . '%') .
+ ' ORDER BY Name ASC LIMIT 20';
+
+ $result = $this->dbh->query($query);
+ $result_array = array();
+
+ if ($result) {
+ $result_array = $result->fetchAll(PDO::FETCH_COLUMN, 0);
+ }
+
+ return json_encode($result_array);
+ }
}
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.");
}
}