[aur-dev] [PATCH 1/2] Allow canonical links to packages (fixes FS#21600).

Lukas Fleischer archlinux at cryptocrack.de
Sat Nov 6 20:46:45 CET 2010


---
 web/html/packages.php         |    6 ++++++
 web/lib/pkgfuncs.inc          |   16 ++++++++++++++++
 web/template/pkg_comments.php |    2 +-
 3 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/web/html/packages.php b/web/html/packages.php
index 472f6a2..c777346 100644
--- a/web/html/packages.php
+++ b/web/html/packages.php
@@ -10,6 +10,8 @@ check_sid();                  # see if they're still logged in
 # Set the title to the current query if required
 if (isset($_GET['ID'])) {
 	if ($pkgname = pkgname_from_id($_GET['ID'])) { $title = $pkgname; }
+} else if (isset($_GET['N'])) {
+	$title = $pkgname = $_GET['N'];
 } else if (!empty($_GET['K'])) {
 	$title = __("Search Criteria") . ": " . $_GET['K'];
 } else {
@@ -74,6 +76,10 @@ if (isset($_GET['ID'])) {
 	} else {
 		package_details($_GET['ID'], $_COOKIE["AURSID"]);
 	}
+} else if (isset($_GET['N'])) {
+	include('pkg_search_form.php');
+	$id = pkgid_from_name($_GET['N']);
+	package_details($id, $_COOKIE["AURSID"]);
 } else {
 	if (!isset($_GET['K']) && !isset($_GET['SB'])) {
 		$_GET['SB'] = 'v';
diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
index 5605daa..a2b9efd 100644
--- a/web/lib/pkgfuncs.inc
+++ b/web/lib/pkgfuncs.inc
@@ -300,6 +300,22 @@ function pkgnotify_from_sid($sid="") {
 	return $pkgs;
 }
 
+# get ID of package based on its name
+#
+function pkgid_from_name($name = "") {
+	if (!empty($name)) {
+		$dbh = db_connect();
+		$q = "SELECT ID FROM Packages WHERE Name = '" . mysql_real_escape_string($name) . "'";
+		$result = db_query($q, $dbh);
+		if (mysql_num_rows($result) > 0) {
+			$id = mysql_result($result, 0);
+		} else {
+			$id = "";
+		}
+	}
+	return $id;
+}
+
 # get name of package based on pkgid
 #
 function pkgname_from_id($id="") {
diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php
index 02171a0..c541d67 100644
--- a/web/template/pkg_comments.php
+++ b/web/template/pkg_comments.php
@@ -29,7 +29,7 @@ while (list($indx, $carr) = each($comments)) { ?>
 </div>
 
 <?php
-$count = package_comments_count($_GET['ID']);
+$count = package_comments_count(isset($_GET['ID']) ? $_GET['ID'] : pkgid_from_name($_GET['N']));
 if ($count > 10 && !isset($_GET['comments'])) {
 	echo '<div class="pgbox">';
 	echo '<a href="'. $_SERVER['PHP_SELF'] . '?ID=' . $_REQUEST['ID'] . '&comments=all">'. __('Show all %s comments', $count) . '</a>';
-- 
1.7.3.2



More information about the aur-dev mailing list