Changeset 17


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

search improved

Location:
trunk
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/configuration.php

    r10 r17  
    243243      }
    244244    }
    245     $query.= " where pseudo = 'visiteur';";
     245    $query.= " where username = 'guest';";
    246246    mysql_query( $query );
    247247  }
     
    796796$vtp->addSession( $sub, 'line' );
    797797$vtp->addSession( $sub, 'param_line' );
    798 $vtp->setVar( $sub, 'param_line.name', $lang['conf_upload_maxwidth_thumbnail'] );
     798$vtp->setVar( $sub, 'param_line.name',$lang['conf_upload_maxwidth_thumbnail']);
    799799$vtp->addSession( $sub, 'text' );
    800800$vtp->setVar( $sub, 'text.name', 'upload_maxwidth_thumbnail' );
    801801$vtp->setVar( $sub, 'text.value', $upload_maxwidth_thumbnail );
    802802$vtp->closeSession( $sub, 'text' );
    803 $vtp->setVar( $sub, 'param_line.def', $lang['conf_upload_maxwidth_thumbnail_info'] );
     803$vtp->setVar($sub,'param_line.def',$lang['conf_upload_maxwidth_thumbnail_info']);
    804804$vtp->closeSession( $sub, 'param_line' );
    805805$vtp->closeSession( $sub, 'line' );
     
    807807$vtp->addSession( $sub, 'line' );
    808808$vtp->addSession( $sub, 'param_line' );
    809 $vtp->setVar( $sub, 'param_line.name', $lang['conf_upload_maxheight_thumbnail'] );
     809$vtp->setVar( $sub,'param_line.name',$lang['conf_upload_maxheight_thumbnail']);
    810810$vtp->addSession( $sub, 'text' );
    811811$vtp->setVar( $sub, 'text.name', 'upload_maxheight_thumbnail' );
  • trunk/category.php

    r16 r17  
    171171  if ( $page['cat'] == 'search' )
    172172  {
    173     $url.= '&search='.$_GET['search'];
     173    $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode'];
    174174  }
    175175  $vtp->setVar( $handle, 'summary.url', add_session_id( $url ) );
     
    244244  $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
    245245  $query.= ';';
     246  echo $query;
    246247  $result = mysql_query( $query );
    247248
     
    249250  $vtp->addSession( $handle, 'line' );
    250251  // iteration counter to use a new <tr> every "$nb_image_line" pictures
    251   $i = 1;
     252  $cell_number = 1;
     253  // iteration counter to be sure not to create too much lines in the table
     254  $line_number = 1;
    252255  while ( $row = mysql_fetch_array( $result ) )
    253256  {
     
    295298    if ( $page['cat'] == 'search' )
    296299    {
    297       $url_link.= '&amp;search='.$_GET['search'];
     300      $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    298301    }
    299302    // date of availability for creation icon
    300     $date = explode( '-', $row['date_available'] );
    301     $date = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
     303    list( $year,$month,$day ) = explode( '-', $row['date_available'] );
     304    $date = mktime( 0, 0, 0, $month, $day, $year );
    302305    // sending vars to display
    303306    $vtp->addSession( $handle, 'thumbnail' );
     
    323326    $vtp->closeSession( $handle, 'thumbnail' );
    324327   
    325     if ( $i == $user['nb_image_line'] )
    326     {
     328    if ( $cell_number++ == $user['nb_image_line'] )
     329    {
     330      // creating a new line
    327331      $vtp->closeSession( $handle, 'line' );
    328       $vtp->addSession( $handle, 'line' );
    329       $i = 1;
    330     }
    331     else
    332     {
    333       $i++;
    334     }
    335   }
    336   if ( $i < $user['nb_image_line'] )
    337   {
    338     $vtp->closeSession( $handle, 'line' );
     332      // the number of the next cell is 1
     333      $cell_number = 1;
     334      // we only create a new line if it does not exceed the maximum line
     335      // per page for the logged user
     336      if ( $line_number++ < $user['nb_line_page'] )
     337      {
     338        $vtp->addSession( $handle, 'line' );
     339      }
     340    }
    339341  }
    340342  $vtp->closeSession( $handle, 'thumbnails' );
     
    348350
    349351  $subcats = get_non_empty_sub_cat_ids( $page['cat'] );
    350   $i = 1;
    351   foreach ( $subcats as $subcat) {
     352  $cell_number = 1;
     353  foreach ( $subcats as $id => $subcat ) {
    352354    $result = get_cat_info( $subcat['non_empty_cat'] );
    353355    $cat_directory = $result['dir'];
     
    374376    $image_row = mysql_fetch_array( $image_result );
    375377
    376     $file = substr ( $image_row['file'], 0,
    377                      strrpos ( $image_row['file'], '.' ) );
     378    $file = get_filename_wo_extension( $image_row['file'] );
    378379
    379380    // creating links for thumbnail and associated category
     
    384385    $lien_image.= $image_row['file'];
    385386
    386     $thumbnail_title = '';
     387    $thumbnail_title = $lang['hint_category'];
    387388
    388389    $url_link = './category.php?cat='.$subcat['id'];
    389390    if ( !in_array( $page['cat'], $page['tab_expand'] ) )
    390391    {
    391       $page['tab_expand'][sizeof( $page['tab_expand'] )] = $page['cat'];
     392      array_push( $page['tab_expand'], $page['cat'] );
    392393      $page['expand'] = implode( ',', $page['tab_expand'] );
    393394    }
    394395    $url_link.= '&amp;expand='.$page['expand'];
     396    list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] );
     397    $date = mktime( 0, 0, 0, $month, $day, $year );
    395398
    396399    // sending vars to display
     
    401404    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
    402405    $vtp->setVar( $handle, 'thumbnail.name', $name );
    403 
    404     list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] );
    405     $date = mktime( 0, 0, 0, $month, $day, $year );
    406406    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
    407 
    408407    $vtp->closeSession( $handle, 'thumbnail' );
    409408
    410     if ( $i == $user['nb_image_line'] )
     409    if ( $cell_number++ == $user['nb_image_line'] )
    411410    {
    412411      $vtp->closeSession( $handle, 'line' );
    413       $vtp->addSession( $handle, 'line' );
    414       $i = 1;
    415     }
    416     else
    417     {
    418       $i++;
    419     }
     412      $cell_number = 1;
     413      // we open a new line if the subcat was not the last one
     414      if ( $id < count( $subcats ) - 1 )
     415      {
     416        $vtp->addSession( $handle, 'line' );
     417      }
     418    }
     419  }
     420  if ( $id < count( $subcats ) - 1 )
     421  {
     422    $vtp->closeSession( $handle, 'line' );
    420423  }
    421424  $vtp->closeSession( $handle, 'thumbnails' );
  • trunk/include/config.inc.php

    r14 r17  
    3838//    will only order pictures by file ascending
    3939//    without taking into account the date_available
    40 $conf['order_by'] = ' order by date_available desc, file asc';
     40$conf['order_by'] = ' ORDER BY date_available DESC, file ASC';
    4141
    42 $conf['repertoire_image']   = './images/';
    4342$conf['nb_image_row']       = array('4','5','6','7','8');
    4443$conf['nb_row_page']        = array('2','3','4','5','6','7','10','20','1000');
  • trunk/include/functions.inc.php

    r15 r17  
    170170    while ( $file = readdir ( $opendir ) )
    171171    {
    172       if ( $file != "." and $file != ".." and is_dir ( $rep.$file ) )
     172      if ( $file != '.' and $file != '..' and is_dir ( $rep.$file ) )
    173173      {
    174174        array_push( $sub_rep, $file );
     
    275275}
    276276
    277 // - The replace_search function replaces a $search string by the search in
    278 //   another color
     277// - add_style replaces the
     278//         $search  into <span style="$style">$search</span>
     279// in the given $string.
    279280// - The function does not replace characters in HTML tags
    280 function replace_search( $string, $search )
     281function add_style( $string, $search, $style )
    281282{
    282283  //return $string;
    283   $style_search = "background-color:white;color:red;";
    284   $return_string = "";
     284  $return_string = '';
    285285  $remaining = $string;
    286286
     
    292292  {
    293293    $treatment = substr ( $remaining, 0, $start );
    294     $treatment = str_replace( $search, '<span style="'.$style_search.'">'.
     294    $treatment = str_replace( $search, '<span style="'.$style.'">'.
    295295                              $search.'</span>', $treatment );
    296     $return_string.= $treatment.substr ( $remaining, $start,
    297                                          $end - $start + 1 );
     296    $return_string.= $treatment.substr( $remaining, $start, $end-$start+1 );
    298297    $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
    299298    $start = strpos ( $remaining, '<' );
    300299    $end   = strpos ( $remaining, '>' );
    301300  }
    302   $treatment = str_replace( $search, '<span style="'.$style_search.'">'.
     301  $treatment = str_replace( $search, '<span style="'.$style.'">'.
    303302                            $search.'</span>', $remaining );
    304303  $return_string.= $treatment;
    305304               
    306305  return $return_string;
     306}
     307
     308// replace_search replaces a searched words array string by the search in
     309// another style for the given $string.
     310function replace_search( $string, $search )
     311{
     312  $words = explode( ',', $search );
     313  $style = 'background-color:white;color:red;';
     314  foreach ( $words as $word ) {
     315    $string = add_style( $string, $word, $style );
     316  }
     317  return $string;
    307318}
    308319
  • trunk/include/functions_category.inc.php

    r16 r17  
    133133      if ( $page['cat'] == 'search' )
    134134      {
    135         $url.= "&amp;search=".$_GET['search'];
     135        $url.= "&amp;search=".$_GET['search'].'&amp;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 );
  • trunk/language/francais.php

    r13 r17  
    181181// page search
    182182$lang['search_title'] = 'Recherche';
    183 $lang['invalid_search'] = 'La recherche doit porter sur 3 caractères ou plus';
     183// start version 1.3
     184$lang['invalid_search'] = 'Les mots recherchés doivent comporter plus de 3 caractères et ne doivent pas inclure de caractères de ponctuation';
     185$lang['search_mode_or'] = 'au moins un mot';
     186$lang['search_mode_and'] = 'tous les mots';
     187// end version 1.3
    184188$lang['search_field_search'] = 'Rechercher';
    185189$lang['search_return_main_page'] = 'Retour à la page des miniatures';
  • trunk/picture.php

    r10 r17  
    133133    if ( $page['cat'] == 'search' )
    134134    {
    135       $redirect.= '&search='.$_GET['search'];
     135      $redirect.= '&search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    136136    }
    137137    $url = add_session_id( $redirect, true );
     
    212212  if ( $page['cat'] == 'search' )
    213213  {
    214     $url_link.= '&amp;search='.$_GET['search'];
     214    $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    215215  }
    216216  // sending vars for display
     
    286286if ( $page['cat'] == 'search' )
    287287{
    288   $url_link.= "&amp;search=".$_GET['search'];
     288  $url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
    289289}
    290290$vtp->setGlobalVar( $handle, 'picture_link', add_session_id( $url_link ) );
     
    386386  if ( $page['cat'] == 'search' )
    387387  {
    388     $url.= '&amp;search='.$_GET['search'];
     388    $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    389389  }
    390390  $vtp->addSession( $handle, 'favorite' );
     
    459459  if ( $page['cat'] == 'search' )
    460460  {
    461     $url_link.= "&amp;search=".$_GET['search'];
     461    $url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
    462462  }
    463463  // sending vars for display
     
    512512  if ( $page['cat'] == 'search' )
    513513  {
    514     $url.= '&amp;search='.$_GET['search'];
     514    $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    515515  }
    516516  if( !isset( $_GET['start'] )
  • trunk/profile.php

    r14 r17  
    133133    if ( $page['cat'] == 'search' )
    134134    {
    135       $url.= '&search='.$_GET['search'];
     135      $url.= '&search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    136136    }
    137137    $url = add_session_id( $url, true );
     
    153153if ( $page['cat'] == 'search' )
    154154{
    155   $url.= '&amp;search='.$_GET['search'];
     155  $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    156156}
    157157$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
  • trunk/search.php

    r10 r17  
    2424if ( isset( $_POST['search'] ) )
    2525{
    26   $i = 0;
    27   if ( strlen( $_POST['search'] ) > 2 )
     26  $redirect = true;
     27  $search = array();
     28  $words = preg_split( '/\s+/', $_POST['search'] );
     29  foreach ( $words as $i => $word ) {
     30    if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) )
     31    {
     32      array_push( $search, $word );
     33    }
     34    else
     35    {
     36      $redirect = false;
     37      array_push( $error, $lang['invalid_search'] );
     38      break;
     39    }
     40  }
     41  $search = array_unique( $search );
     42  $search = implode( ',', $search );
     43  if ( $redirect )
    2844  {
    29     $url = add_session_id( 'category.php?cat=search&search='.
    30                            $_POST['search'], true );
     45    $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode'];
     46    $url = add_session_id( $url, true );
    3147    header( 'Request-URI: '.$url );
    3248    header( 'Content-Location: '.$url ); 
    3349    header( 'Location: '.$url );
    3450    exit();
    35   }
    36   else
    37   {
    38     $error[$i++] = $lang['invalid_search'];
    3951  }
    4052}
     
    6880  $vtp->closeSession( $handle, 'errors' );
    6981}
    70 //---------------------------------------------------------------- search field
     82//------------------------------------------------------------------------ form
     83// search field
    7184$vtp->addSession( $handle, 'line' );
    7285$vtp->setVar( $handle, 'line.name', $lang['search_field_search'] );
     
    7790$vtp->closeSession( $handle, 'text' );
    7891$vtp->closeSession( $handle, 'line' );
     92// mode of search : match all words or at least one of this words
     93$vtp->addSession( $handle, 'line' );
     94$vtp->addSession( $handle, 'group' );
     95
     96$vtp->addSession( $handle, 'radio' );
     97$vtp->setVar( $handle, 'radio.name', 'mode' );
     98$vtp->setVar( $handle, 'radio.value', 'OR' );
     99$vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
     100if ( $_POST['mode'] == 'OR' or $_POST['mode'] == '' )
     101{
     102  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
     103}
     104$vtp->closeSession( $handle, 'radio' );
     105
     106$vtp->addSession( $handle, 'radio' );
     107$vtp->setVar( $handle, 'radio.name', 'mode' );
     108$vtp->setVar( $handle, 'radio.value', 'AND' );
     109$vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
     110if ( $_POST['mode'] == 'AND' )
     111{
     112  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
     113}
     114$vtp->closeSession( $handle, 'radio' );
     115
     116$vtp->closeSession( $handle, 'group' );
     117$vtp->closeSession( $handle, 'line' );
    79118//---------------------------------------------------- return to main page link
    80119$vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
     
    83122echo $code;
    84123//------------------------------------------------------------ log informations
     124pwg_log( 'category', $page['title'] );
     125mysql_close();
    85126$query = 'insert into '.PREFIX_TABLE.'history';
    86127$query.= '(date,login,IP,page) values';
  • trunk/template/default/search.vtp

    r2 r17  
    4848                      <input type="text" name="{#name}" size="{#size}" value="{#value}" />
    4949                      <!--/VTP_text-->
     50                      <!--VTP_group-->
     51                        <!--VTP_radio-->
     52                        <input type="radio" name="{#name}" value="{#value}"{#checked}/>{#option}
     53                        <!--/VTP_radio-->
     54                      <!--/VTP_group-->
    5055                    </td>
    5156                  </tr>
Note: See TracChangeset for help on using the changeset viewer.