[35219] trunk/www/ports.php

eridius at macports.org eridius at macports.org
Thu Mar 20 21:56:46 PDT 2008


Revision: 35219
          http://trac.macosforge.org/projects/macports/changeset/35219
Author:   eridius at macports.org
Date:     2008-03-20 21:56:45 -0700 (Thu, 20 Mar 2008)

Log Message:
-----------
Clean up the criteria matching for the ports list

Modified Paths:
--------------
    trunk/www/ports.php

Modified: trunk/www/ports.php
===================================================================
--- trunk/www/ports.php	2008-03-21 04:55:56 UTC (rev 35218)
+++ trunk/www/ports.php	2008-03-21 04:56:45 UTC (rev 35219)
@@ -83,35 +83,36 @@
     /* If valid criteria is specified (by set and a valid substring, or by set to all) we poll the db and display the results */
     if ($by && ($substr || $by == 'all')) {
         $fields = 'name, path, version, description';
-        $tables = $portsdb_name . '.portfiles AS p';
-        if ($by == 'name') {
+        $tables = "$portsdb_name.portfiles AS p";
+        switch ($by) {
+        case 'name':
             $criteria = 'p.name LIKE \'%' . mysql_real_escape_string($substr) . '%\'';
-        }
-        if ($by == 'category') {
-            $tables .= ', ' . $portsdb_name . '.categories AS c';
+            break;
+        case 'category':
+            $tables .= ", $portsdb_name.categories AS c";
             $criteria = 'c.portfile = p.name AND c.category = \'' . mysql_real_escape_string($substr) . '\'';
-        }
-        if ($by == 'maintainer') {
-            $tables .= ', ' . $portsdb_name . '.maintainers AS m';
+            break;
+        case 'maintainer':
+            $tables .= ", $portsdb_name.maintainers AS m";
             $criteria = 'm.portfile = p.name AND m.maintainer LIKE \'%' . mysql_real_escape_string($substr) . '%\'';
-        }
-        if ($by == 'library') {
+            break;
+        case 'library':
             $criteria = 'p.name = \'' . mysql_real_escape_string($substr) . '\'';
-        }
-        if ($by == 'variant') {
-            $tables .= ', ' . $portsdb_name . '.variants AS v';
+            break;
+        case 'variant':
+            $tables .= ", $portsdb_name.variants AS v";
             $criteria = 'v.portfile = p.name AND v.variant = \'' . mysql_real_escape_string($substr) . '\'';
-        }
-        if ($by == 'platform') {
-            $tables .= ', ' . $portsdb_name . '.platforms AS pl';
+            break;
+        case 'platform':
+            $tables .= ", $portsdb_name.platforms AS pl";
             $criteria = 'pl.portfile = p.name AND pl.platform = \'' . mysql_real_escape_string($substr) . '\'';
+            break;
+        case 'all':
+            $criteria = '';
+            break;
         }
-        if ($criteria == '') {
-            $where = '';
-        } else {
-            $where = 'WHERE ' . $criteria;
-        }
-        $query = 'SELECT DISTINCT ' . $fields . ' FROM ' . $tables . ' ' . $where . 'ORDER BY name';
+        $where = ($criteria == '' ? '' : "WHERE $criteria");
+        $query = "SELECT DISTINCT $fields FROM $tables $where ORDER BY name";
         $result = mysql_query($query);
         
         /* Main query sent to the DB */

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080320/f5dbff7c/attachment-0001.html 


More information about the macports-changes mailing list