From 8e1051932eb86ef87f7b64efc86f50e633201b56 Mon Sep 17 00:00:00 2001 From: Marcel Korpel Date: Wed, 9 Jan 2013 17:41:33 +0000 Subject: Add description meta-element to package pages Implements FS#33294 Signed-off-by: Lukas Fleischer --- web/html/packages.php | 11 ++++--- web/lib/aur.inc.php | 2 +- web/lib/pkgfuncs.inc.php | 81 ++++++++++++++++++++++++++++++------------------ web/template/header.php | 3 ++ 4 files changed, 62 insertions(+), 35 deletions(-) (limited to 'web') diff --git a/web/html/packages.php b/web/html/packages.php index 61825501..c1e54e1b 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -20,9 +20,12 @@ if (!isset($pkgid) || !isset($pkgname)) { } } -# Set the title to the current query if required +# Set the title to the current query and get package details if required +$details = array(); + if (isset($pkgname)) { $title = $pkgname; + $details = get_package_details($pkgid); } else if (!empty($_GET['K'])) { $title = __("Search Criteria") . ": " . $_GET['K']; } else { @@ -93,7 +96,7 @@ if (check_token()) { } } -html_header($title); +html_header($title, $details); ?> @@ -105,10 +108,10 @@ if (isset($pkgid)) { include('pkg_search_form.php'); if ($pkgid) { if (isset($_COOKIE["AURSID"])) { - package_details($pkgid, $_COOKIE["AURSID"]); + display_package_details($pkgid, $details, $_COOKIE["AURSID"]); } else { - package_details($pkgid, null); + display_package_details($pkgid, $details, null); } } else { print __("Error trying to retrieve package details.")."
\n"; diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 018d5c82..e3921025 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/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index c00c33db..568ca3d1 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -431,18 +431,53 @@ function pkgname_is_blacklisted($name, $dbh=NULL) { return ($result->fetchColumn() > 0); } +/** + * 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 "

" . __("Error retrieving package details.") . "

\n"; + if (isset($row['error'])) { + print "

" . $row['error'] . "

\n"; } else { - $row = $result->fetch(PDO::FETCH_ASSOC); - if (empty($row)) { - print "

" . __("Package details could not be found.") . "

\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; } diff --git a/web/template/header.php b/web/template/header.php index 92cb2ff8..9cefedcb 100644 --- a/web/template/header.php +++ b/web/template/header.php @@ -10,6 +10,9 @@ ' /> + + +
-- cgit v1.2.3-24-g4f1b