[aur-dev] [PATCH] Add description meta-element to package pages

Marcel Korpel marcel.lists at gmail.com
Sat Jan 5 11:32:50 EST 2013


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



More information about the aur-dev mailing list