Changeset 35219 for trunk/www


Ignore:
Timestamp:
Mar 21, 2008, 4:56:45 AM (12 years ago)
Author:
eridius@…
Message:

Clean up the criteria matching for the ports list

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/ports.php

    r35218 r35219  
    8484    if ($by && ($substr || $by == 'all')) {
    8585        $fields = 'name, path, version, description';
    86         $tables = $portsdb_name . '.portfiles AS p';
    87         if ($by == 'name') {
     86        $tables = "$portsdb_name.portfiles AS p";
     87        switch ($by) {
     88        case 'name':
    8889            $criteria = 'p.name LIKE \'%' . mysql_real_escape_string($substr) . '%\'';
     90            break;
     91        case 'category':
     92            $tables .= ", $portsdb_name.categories AS c";
     93            $criteria = 'c.portfile = p.name AND c.category = \'' . mysql_real_escape_string($substr) . '\'';
     94            break;
     95        case 'maintainer':
     96            $tables .= ", $portsdb_name.maintainers AS m";
     97            $criteria = 'm.portfile = p.name AND m.maintainer LIKE \'%' . mysql_real_escape_string($substr) . '%\'';
     98            break;
     99        case 'library':
     100            $criteria = 'p.name = \'' . mysql_real_escape_string($substr) . '\'';
     101            break;
     102        case 'variant':
     103            $tables .= ", $portsdb_name.variants AS v";
     104            $criteria = 'v.portfile = p.name AND v.variant = \'' . mysql_real_escape_string($substr) . '\'';
     105            break;
     106        case 'platform':
     107            $tables .= ", $portsdb_name.platforms AS pl";
     108            $criteria = 'pl.portfile = p.name AND pl.platform = \'' . mysql_real_escape_string($substr) . '\'';
     109            break;
     110        case 'all':
     111            $criteria = '';
     112            break;
    89113        }
    90         if ($by == 'category') {
    91             $tables .= ', ' . $portsdb_name . '.categories AS c';
    92             $criteria = 'c.portfile = p.name AND c.category = \'' . mysql_real_escape_string($substr) . '\'';
    93         }
    94         if ($by == 'maintainer') {
    95             $tables .= ', ' . $portsdb_name . '.maintainers AS m';
    96             $criteria = 'm.portfile = p.name AND m.maintainer LIKE \'%' . mysql_real_escape_string($substr) . '%\'';
    97         }
    98         if ($by == 'library') {
    99             $criteria = 'p.name = \'' . mysql_real_escape_string($substr) . '\'';
    100         }
    101         if ($by == 'variant') {
    102             $tables .= ', ' . $portsdb_name . '.variants AS v';
    103             $criteria = 'v.portfile = p.name AND v.variant = \'' . mysql_real_escape_string($substr) . '\'';
    104         }
    105         if ($by == 'platform') {
    106             $tables .= ', ' . $portsdb_name . '.platforms AS pl';
    107             $criteria = 'pl.portfile = p.name AND pl.platform = \'' . mysql_real_escape_string($substr) . '\'';
    108         }
    109         if ($criteria == '') {
    110             $where = '';
    111         } else {
    112             $where = 'WHERE ' . $criteria;
    113         }
    114         $query = 'SELECT DISTINCT ' . $fields . ' FROM ' . $tables . ' ' . $where . 'ORDER BY name';
     114        $where = ($criteria == '' ? '' : "WHERE $criteria");
     115        $query = "SELECT DISTINCT $fields FROM $tables $where ORDER BY name";
    115116        $result = mysql_query($query);
    116117       
Note: See TracChangeset for help on using the changeset viewer.