[aur-dev] [PATCH] Add description meta-element to package pages
Implements FS#33294 --- web/html/packages.php | 7 +++++-- web/lib/aur.inc.php | 3 ++- web/lib/pkgfuncs.inc.php | 24 ++++++++++++++++++++++++ web/template/header.php | 5 +++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/web/html/packages.php b/web/html/packages.php index 6182550..54386fc 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 and description to the current query if required +$description = ""; + if (isset($pkgname)) { $title = $pkgname; + $description = package_description($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, $description); ?> <?php if ($output): ?> diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 018d5c8..46ef340 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -297,13 +297,14 @@ function db_connect() { * * @return void */ -function html_header($title="") { +function html_header($title="", $description="") { global $AUR_LOCATION; global $DISABLE_HTTP_LOGIN; global $LANG; global $SUPPORTED_LANGS; $title = htmlspecialchars($title, ENT_QUOTES); + $description = htmlspecialchars($description, ENT_QUOTES); include('header.php'); return; diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index c00c33d..5230947 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -432,6 +432,30 @@ function pkgname_is_blacklisted($name, $dbh=NULL) { } /** + * Get the package description + * + * @param string $id The package ID to get description for + * + * @return string The package's description + **/ +function package_description($id=0, $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } + + $q = "SELECT Description FROM Packages "; + $q.= "WHERE ID = " . intval($id); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetch(PDO::FETCH_ASSOC); + if (!empty($row)) { + return $row['Description']; + } + } +} + +/** * Display the package details page * * @global string $AUR_LOCATION The AUR's URL used for notification e-mails diff --git a/web/template/header.php b/web/template/header.php index 92cb2ff..d6362a5 100644 --- a/web/template/header.php +++ b/web/template/header.php @@ -10,6 +10,11 @@ <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($description) && $description != "") { + print "<meta name='description' content='" . $description . "' />\n"; + } + ?> </head> <body> <div id="archnavbar" class="anb-aur"> -- 1.8.1
On Sat, Jan 5, 2013 at 11:32 AM, Marcel Korpel <marcel.lists@gmail.com> wrote:
Implements FS#33294
I like the idea of this patch. It would make search engine results for AUR packages far more sane.
--- web/html/packages.php | 7 +++++-- web/lib/aur.inc.php | 3 ++- web/lib/pkgfuncs.inc.php | 24 ++++++++++++++++++++++++ web/template/header.php | 5 +++++ 4 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/web/html/packages.php b/web/html/packages.php index 6182550..54386fc 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 and description to the current query if required +$description = ""; + if (isset($pkgname)) { $title = $pkgname; + $description = package_description($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, $description); ?>
<?php if ($output): ?> diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 018d5c8..46ef340 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -297,13 +297,14 @@ function db_connect() { * * @return void */ -function html_header($title="") { +function html_header($title="", $description="") { global $AUR_LOCATION; global $DISABLE_HTTP_LOGIN; global $LANG; global $SUPPORTED_LANGS;
$title = htmlspecialchars($title, ENT_QUOTES); + $description = htmlspecialchars($description, ENT_QUOTES);
include('header.php'); return; diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index c00c33d..5230947 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -432,6 +432,30 @@ function pkgname_is_blacklisted($name, $dbh=NULL) { }
/** + * Get the package description + * + * @param string $id The package ID to get description for + * + * @return string The package's description + **/ +function package_description($id=0, $dbh=NULL) { + if(!$dbh) { + $dbh = db_connect(); + } + + $q = "SELECT Description FROM Packages "; + $q.= "WHERE ID = " . intval($id); + $result = $dbh->query($q); + + if ($result) { + $row = $result->fetch(PDO::FETCH_ASSOC); + if (!empty($row)) { + return $row['Description']; + } + } +}
I don't really like that this fetches the package description when there is already a query that fetches all package information, including package description. This adds an extra query to every package page despite the same data being fetched later. I do see why you did it this way since html_header() outputs even before package_details() is called, but I think it would be desirable to solve this in a way that doesn't duplicate a query.
+ +/** * Display the package details page * * @global string $AUR_LOCATION The AUR's URL used for notification e-mails diff --git a/web/template/header.php b/web/template/header.php index 92cb2ff..d6362a5 100644 --- a/web/template/header.php +++ b/web/template/header.php @@ -10,6 +10,11 @@ <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($description) && $description != "") { + print "<meta name='description' content='" . $description . "' />\n"; + } + ?>
You can use the alternative syntax for control structures when mixing PHP with HTML. It can be easier to read: <?php if (!empty($description)): ?> <meta name="description" content="<?= $description ?>" /> <?php endif; ?>
</head> <body> <div id="archnavbar" class="anb-aur"> -- 1.8.1
participants (2)
-
canyonknight
-
Marcel Korpel