Add description meta-element to package pages

Implements FS#33294

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Marcel Korpel 2013-01-09 17:41:33 +00:00 committed by Lukas Fleischer
parent b004333ead
commit 8e1051932e
4 changed files with 66 additions and 39 deletions

View file

@ -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);
?>
<?php if ($output): ?>
@ -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.")."<br />\n";

View file

@ -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;

View file

@ -432,20 +432,14 @@ function pkgname_is_blacklisted($name, $dbh=NULL) {
}
/**
* Display the package details page
* Get the package details
*
* @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 string $SID The session ID of the visitor
* @param string $id The package ID to get description for
* @param \PDO $dbh An already established database connection
*
* @return void
*/
function package_details($id=0, $SID="", $dbh=NULL) {
global $AUR_LOCATION;
global $USE_VIRTUAL_URLS;
* @return array The package's details OR error message
**/
function get_package_details($id=0, $dbh=NULL) {
if(!$dbh) {
$dbh = db_connect();
}
@ -456,14 +450,43 @@ function package_details($id=0, $SID="", $dbh=NULL) {
$q.= "AND Packages.ID = " . intval($id);
$result = $dbh->query($q);
$row = array();
if (!$result) {
print "<p>" . __("Error retrieving package details.") . "</p>\n";
$row['error'] = __("Error retrieving package details.");
}
else {
$row = $result->fetch(PDO::FETCH_ASSOC);
if (empty($row)) {
print "<p>" . __("Package details could not be found.") . "</p>\n";
$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 display_package_details($id=0, $row, $SID="", $dbh=NULL) {
global $AUR_LOCATION;
global $USE_VIRTUAL_URLS;
if(!$dbh) {
$dbh = db_connect();
}
if (isset($row['error'])) {
print "<p>" . $row['error'] . "</p>\n";
}
else {
include('pkg_details.php');
@ -485,8 +508,6 @@ function package_details($id=0, $SID="", $dbh=NULL) {
}
}
}
return;
}
/* pkg_search_page(SID)

View file

@ -10,6 +10,9 @@
<link rel='shortcut icon' href='/images/favicon.ico' />
<link rel='alternate' type='application/rss+xml' title='Newest Packages RSS' href='<?= get_uri('/rss/'); ?>' />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php if (isset($details['Description']) && !empty($details['Description'])): ?>
<meta name="description" content="<?= htmlspecialchars($details['Description']) ?>" />
<?php endif; ?>
</head>
<body>
<div id="archnavbar" class="anb-aur">