search improved

git-svn-id: http://piwigo.org/svn/trunk@17 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
z0rglub
2003-05-25 08:31:39 +00:00
parent 887c7ee4d4
commit 1de10bd66f
11 changed files with 176 additions and 628 deletions
+1 -2
View File
@@ -37,9 +37,8 @@ include_once( PREFIXE_INCLUDE.'./include/vtemplate.class.php' );
// 2. $conf['order_by'] = " order by file asc";
// will only order pictures by file ascending
// without taking into account the date_available
$conf['order_by'] = ' order by date_available desc, file asc';
$conf['order_by'] = ' ORDER BY date_available DESC, file ASC';
$conf['repertoire_image'] = './images/';
$conf['nb_image_row'] = array('4','5','6','7','8');
$conf['nb_row_page'] = array('2','3','4','5','6','7','10','20','1000');
$conf['version'] = '1.3';
+21 -10
View File
@@ -169,7 +169,7 @@ function get_dirs( $rep )
{
while ( $file = readdir ( $opendir ) )
{
if ( $file != "." and $file != ".." and is_dir ( $rep.$file ) )
if ( $file != '.' and $file != '..' and is_dir ( $rep.$file ) )
{
array_push( $sub_rep, $file );
}
@@ -274,14 +274,14 @@ function get_themes( $theme_dir )
return $themes;
}
// - The replace_search function replaces a $search string by the search in
// another color
// - add_style replaces the
// $search into <span style="$style">$search</span>
// in the given $string.
// - The function does not replace characters in HTML tags
function replace_search( $string, $search )
function add_style( $string, $search, $style )
{
//return $string;
$style_search = "background-color:white;color:red;";
$return_string = "";
$return_string = '';
$remaining = $string;
$start = 0;
@@ -291,21 +291,32 @@ function replace_search( $string, $search )
while ( is_numeric( $start ) and is_numeric( $end ) )
{
$treatment = substr ( $remaining, 0, $start );
$treatment = str_replace( $search, '<span style="'.$style_search.'">'.
$treatment = str_replace( $search, '<span style="'.$style.'">'.
$search.'</span>', $treatment );
$return_string.= $treatment.substr ( $remaining, $start,
$end - $start + 1 );
$return_string.= $treatment.substr( $remaining, $start, $end-$start+1 );
$remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
$start = strpos ( $remaining, '<' );
$end = strpos ( $remaining, '>' );
}
$treatment = str_replace( $search, '<span style="'.$style_search.'">'.
$treatment = str_replace( $search, '<span style="'.$style.'">'.
$search.'</span>', $remaining );
$return_string.= $treatment;
return $return_string;
}
// replace_search replaces a searched words array string by the search in
// another style for the given $string.
function replace_search( $string, $search )
{
$words = explode( ',', $search );
$style = 'background-color:white;color:red;';
foreach ( $words as $word ) {
$string = add_style( $string, $word, $style );
}
return $string;
}
function database_connection()
{
// $cfgHote,$cfgUser,$cfgPassword,$cfgBase;
+46 -30
View File
@@ -132,7 +132,7 @@ function display_cat( $id_uppercat, $indent, $restriction, $tab_expand )
$url = "./category.php?cat=".$page['cat']."&amp;expand=$expand";
if ( $page['cat'] == 'search' )
{
$url.= "&amp;search=".$_GET['search'];
$url.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
}
$lien_cat = add_session_id( $url );
if ( $row['name'] == "" )
@@ -381,7 +381,15 @@ function initialize_category( $calling_page = 'category' )
}
else
{
$query = '';
if ( $page['cat'] == 'search' or $page['cat'] == 'most_visited'
or $page['cat'] == 'recent' or $page['cat'] == 'best_rated' )
{
// we must not show pictures of a forbidden category
$restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
foreach ( $restricted_cats as $restricted_cat ) {
$where_append.= ' AND cat_id != '.$restricted_cat;
}
}
// search result
if ( $page['cat'] == 'search' )
{
@@ -391,16 +399,40 @@ function initialize_category( $calling_page = 'category' )
$page['title'].= ' : <span style="font-style:italic;">';
$page['title'].= $_GET['search']."</span>";
}
$page['where'] = " WHERE ( file LIKE '%".$_GET['search']."%'";
$page['where'].= " OR name LIKE '%".$_GET['search']."%'";
$page['where'].= " OR comment LIKE '%".$_GET['search']."%' )";
$page['where'] = ' WHERE (';
$fields = array( 'file', 'name', 'comment' );
$words = explode( ',', $_GET['search'] );
$sql_search = array();
foreach ( $words as $i => $word ) {
if ( $_GET['mode'] == 'OR' )
{
if ( $i != 0 ) $page['where'].= ' OR';
foreach ( $fields as $j => $field ) {
if ( $j != 0 ) $page['where'].= ' OR';
$page['where'].= ' '.$field." LIKE '%".$word."%'";
}
}
else if ( $_GET['mode'] == 'AND' )
{
if ( $i != 0 ) $page['where'].= ' AND';
$page['where'].= ' (';
foreach ( $fields as $j => $field ) {
if ( $j != 0 ) $page['where'].= ' OR';
$page['where'].= ' '.$field." LIKE '%".$word."%'";
}
$page['where'].= ' )';
}
}
$page['where'].= ' )';
$page['where'].= $where_append;
$query = 'SELECT COUNT(*) AS nb_total_images';
$query.= ' FROM '.PREFIX_TABLE.'images';
$query.= $page['where'];
$query.= ';';
$url.= '&amp;search='.$_GET['search'];
$url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
// favorites displaying
else if ( $page['cat'] == 'fav' )
@@ -425,6 +457,7 @@ function initialize_category( $calling_page = 'category' )
$date = time() - 60*60*24*$user['short_period'];
$page['where'] = " WHERE date_available > '";
$page['where'].= date( 'Y-m-d', $date )."'";
$page['where'].= $where_append;
$query = 'SELECT COUNT(*) AS nb_total_images';
$query.= ' FROM '.PREFIX_TABLE.'images';
@@ -435,7 +468,7 @@ function initialize_category( $calling_page = 'category' )
else if ( $page['cat'] == 'most_visited' )
{
$page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
$page['where'] = ' WHERE cat_id != -1';
$page['where'] = ' WHERE cat_id != -1'.$where_append;
$conf['order_by'] = ' ORDER BY hit DESC, file ASC';
$page['cat_nb_images'] = $conf['top_number'];
if ( $page['start'] + $user['nb_image_page'] >= $conf['top_number'] )
@@ -450,16 +483,6 @@ function initialize_category( $calling_page = 'category' )
$row = mysql_fetch_array( $result );
$page['cat_nb_images'] = $row['nb_total_images'];
}
if ( $page['cat'] == 'search' or $page['cat'] == 'most_visited'
or $page['cat'] == 'recent' or $page['cat'] == 'best_rated' )
{
// we must not show pictures of a forbidden category
$restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
foreach ( $restricted_cats as $restricted_cat ) {
$page['where'].= ' AND cat_id != '.$restricted_cat;
}
}
}
if ( $calling_page == 'category' )
{
@@ -518,23 +541,16 @@ function get_non_empty_sub_cat_ids( $id_uppercat )
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
if ( $row['nb_images'] == 0 )
{
$non_empty_cat = get_first_non_empty_cat_id( $row['id'] );
}
else
{
$non_empty_cat = $row['id'];
}
// only categories with findable picture in any of its subcats is
// represented.
if ( $non_empty_cat != false )
if ( ( $row['nb_images'] != 0 and $non_empty_cat = $row['id'] )
or $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ) )
{
$temp_cat = array(
'id' => $row['id'],
'name' => $row['name'],
'dir' => $row['dir'],
'date_dernier' => $row['date_dernier'],
'id' => $row['id'],
'name' => $row['name'],
'dir' => $row['dir'],
'date_dernier' => $row['date_dernier'],
'non_empty_cat' => $non_empty_cat );
array_push( $cats, $temp_cat );
}