[aur-dev] [PATCH 2/2] Fetch possible lic types from the db, use foreach

Alexander Rødseth rodseth at gmail.com
Mon Oct 24 12:43:35 EDT 2011


---
 web/lib/pkgfuncs.inc.php         |   36 ++++++++++--------------------------
 web/template/pkg_search_form.php |   10 +++++-----
 2 files changed, 15 insertions(+), 31 deletions(-)

diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php
index 9a2074e..83252d7 100644
--- a/web/lib/pkgfuncs.inc.php
+++ b/web/lib/pkgfuncs.inc.php
@@ -94,34 +94,18 @@ function pkgCategories($dbh=NULL) {
 
 # grab the current list of distinct licenses
 #
-# "fromdb" is boolean and decides if the list of licenses
-# should be fetched from the available licenses in the database
-# or from a predefined list. Set to true or false here to make
-# either one the default. Set to false if the database load is too high.
-#
-function package_licenses($dbh=NULL, $fromdb=true) {
+function package_licenses($dbh=NULL) {
 	$lics = array();
-    if ($fromdb != false) {
-		if(!$dbh) {
-			$dbh = db_connect();
-		}
-		$q = "SELECT DISTINCT License FROM Packages WHERE License != '' ";
-		$q.= "ORDER BY License ASC";
-		$result = db_query($q, $dbh);
-		if ($result) {
-			while ($row = mysql_fetch_row($result)) {
-				$lics[] = $row[0];
-			}
+	if(!$dbh) {
+		$dbh = db_connect();
+	}
+	$q = "SELECT DISTINCT License FROM Packages WHERE License != '' ";
+	$q.= "ORDER BY License ASC";
+	$result = db_query($q, $dbh);
+	if ($result) {
+		while ($row = mysql_fetch_row($result)) {
+			$lics[] = $row[0];
 		}
-    } else {
-		// All possible licenses from
-		// https://wiki.archlinux.org/index.php/PKGBUILD#license
-		$lics = array("AGPL", "AGPL3", "APACHE", "Apache", "Artistic2.0",
-		              "BSD", "CCPL", "CDDL", "CPL", "custom", "EPL", "FDL",
-		              "FDL1.2", "FDL1.3", "GPL", "GPL2", "GPL3", "LGPL",
-		              "LGPL2.1", "LGPL3", "LPPL", "MIT", "MPL", "PHP", "PSF",
-		              "PerlArtistic", "Python", "RUBY", "ZLIB", "ZPL");
-		// sort($lics);
 	}
 	return $lics;
 }
diff --git a/web/template/pkg_search_form.php b/web/template/pkg_search_form.php
index 8c82859..c197fc3 100644
--- a/web/template/pkg_search_form.php
+++ b/web/template/pkg_search_form.php
@@ -125,18 +125,18 @@
 							<option value='0'><?php print __("Any"); ?></option>
 							<?php
 							$lics = package_licenses();
-							for($id = 0; $id < sizeof($lics); ++$id):
-								$lic = $lics[$id];
+							foreach (array_values($lics) as $id => $lic):
 								// "Any" occupies slot 0
 								$lid = $id+1;
+								$license_description = htmlspecialchars($lic);
 								if (isset($_REQUEST['license']) && $_REQUEST['license'] == $lid):
 							?>
-							<option value="<?php print $lid ?>" selected="selected"><?php print $lic; ?></option>
+							<option value="<?php print $lid ?>" selected="selected"><?php print $license_description; ?></option>
 							<?php else: ?>
-							<option value="<?php print $lid ?>"><?php print $lic; ?></option>
+							<option value="<?php print $lid ?>"><?php print $license_description; ?></option>
 							<?php
 								endif;
-							endfor;
+							endforeach;
 							?>
 						</select>
 					</li>
-- 
1.7.7



More information about the aur-dev mailing list