Ignore:
Timestamp:
May 25, 2003, 10:31:39 AM (21 years ago)
Author:
z0rglub
Message:

search improved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_category.inc.php

    r16 r17  
    133133      if ( $page['cat'] == 'search' )
    134134      {
    135         $url.= "&search=".$_GET['search'];
     135        $url.= "&search=".$_GET['search'].'&mode='.$_GET['mode'];
    136136      }
    137137      $lien_cat = add_session_id( $url );
     
    382382    else
    383383    {
    384       $query = '';
     384      if ( $page['cat'] == 'search' or $page['cat'] == 'most_visited'
     385           or $page['cat'] == 'recent' or $page['cat'] == 'best_rated' )
     386      {
     387        // we must not show pictures of a forbidden category
     388        $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
     389        foreach ( $restricted_cats as $restricted_cat ) {
     390          $where_append.= ' AND cat_id != '.$restricted_cat;
     391        }
     392      }
    385393      // search result
    386394      if ( $page['cat'] == 'search' )
     
    392400          $page['title'].= $_GET['search']."</span>";
    393401        }
    394         $page['where'] = " WHERE ( file LIKE '%".$_GET['search']."%'";
    395         $page['where'].= " OR name LIKE '%".$_GET['search']."%'";
    396         $page['where'].= " OR comment LIKE '%".$_GET['search']."%' )";
     402
     403        $page['where'] = ' WHERE (';
     404        $fields = array( 'file', 'name', 'comment' );
     405        $words = explode( ',', $_GET['search'] );
     406        $sql_search = array();
     407        foreach ( $words as $i => $word ) {
     408          if ( $_GET['mode'] == 'OR' )
     409          {
     410            if ( $i != 0 ) $page['where'].= ' OR';
     411            foreach ( $fields as $j => $field ) {
     412              if ( $j != 0 ) $page['where'].= ' OR';
     413              $page['where'].= ' '.$field." LIKE '%".$word."%'";
     414            }
     415          }
     416          else if ( $_GET['mode'] == 'AND' )
     417          {
     418            if ( $i != 0 ) $page['where'].= ' AND';
     419            $page['where'].= ' (';
     420            foreach ( $fields as $j => $field ) {
     421              if ( $j != 0 ) $page['where'].= ' OR';
     422              $page['where'].= ' '.$field." LIKE '%".$word."%'";
     423            }
     424            $page['where'].= ' )';
     425          }
     426        }
     427        $page['where'].= ' )';
     428        $page['where'].= $where_append;
    397429
    398430        $query = 'SELECT COUNT(*) AS nb_total_images';
     
    401433        $query.= ';';
    402434
    403         $url.= '&amp;search='.$_GET['search'];
     435        $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    404436      }
    405437      // favorites displaying
     
    426458        $page['where'] = " WHERE date_available > '";
    427459        $page['where'].= date( 'Y-m-d', $date )."'";
     460        $page['where'].= $where_append;
    428461
    429462        $query = 'SELECT COUNT(*) AS nb_total_images';
     
    436469      {
    437470        $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
    438         $page['where'] = ' WHERE cat_id != -1';
     471        $page['where'] = ' WHERE cat_id != -1'.$where_append;
    439472        $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
    440473        $page['cat_nb_images'] = $conf['top_number'];
     
    450483        $row = mysql_fetch_array( $result );
    451484        $page['cat_nb_images'] = $row['nb_total_images'];
    452       }
    453      
    454       if ( $page['cat'] == 'search' or $page['cat'] == 'most_visited'
    455            or $page['cat'] == 'recent' or $page['cat'] == 'best_rated' )
    456       {
    457         // we must not show pictures of a forbidden category
    458         $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
    459         foreach ( $restricted_cats as $restricted_cat ) {
    460           $page['where'].= ' AND cat_id != '.$restricted_cat;
    461         }
    462485      }
    463486    }
     
    519542  while ( $row = mysql_fetch_array( $result ) )
    520543  {
    521     if ( $row['nb_images'] == 0 )
    522     {
    523       $non_empty_cat = get_first_non_empty_cat_id( $row['id'] );
    524     }
    525     else
    526     {
    527       $non_empty_cat = $row['id'];
    528     }
    529544    // only categories with findable picture in any of its subcats is
    530545    // represented.
    531     if ( $non_empty_cat != false )
     546    if ( ( $row['nb_images'] != 0 and $non_empty_cat = $row['id'] )
     547         or $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ) )
    532548    {
    533549      $temp_cat = array(
    534         'id' => $row['id'],
    535         'name' => $row['name'],
    536         'dir' => $row['dir'],
    537         'date_dernier' => $row['date_dernier'],
     550        'id'            => $row['id'],
     551        'name'          => $row['name'],
     552        'dir'           => $row['dir'],
     553        'date_dernier'  => $row['date_dernier'],
    538554        'non_empty_cat' => $non_empty_cat );
    539555      array_push( $cats, $temp_cat );
Note: See TracChangeset for help on using the changeset viewer.