diff options
author | z0rglub <z0rglub@piwigo.org> | 2004-07-26 20:45:12 +0000 |
---|---|---|
committer | z0rglub <z0rglub@piwigo.org> | 2004-07-26 20:45:12 +0000 |
commit | 4ae92eb06d3c61ae59443b1983264da2e99e01fb (patch) | |
tree | 0a3a456e29f2c73b46250b68939359dd8bb49c2a | |
parent | 3610e7f3609b3e37e83a94770d25e7d08bd3f784 (diff) |
use new search URL variable
git-svn-id: http://piwigo.org/svn/trunk@456 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | include/category_calendar.inc.php | 6 | ||||
-rw-r--r-- | include/category_default.inc.php | 2 | ||||
-rw-r--r-- | include/functions_category.inc.php | 149 |
3 files changed, 122 insertions, 35 deletions
diff --git a/include/category_calendar.inc.php b/include/category_calendar.inc.php index 2ffe6eaa4..0c44c5ea8 100644 --- a/include/category_calendar.inc.php +++ b/include/category_calendar.inc.php @@ -423,6 +423,12 @@ SELECT file,tn_ext,date_available,storage_category_id $thumbnail_title = $lang['calendar_picture_hint'].$name; $url_link = PHPWG_ROOT_PATH.'category.php?cat=search'; + $url_link.= '&search=date_available:'.$_GET['day']; + if ($calendar_category != 0) + { + $url_link.= ';cat:'.$calendar_category.'|AND'; + } + $template->assign_block_vars( 'thumbnails.line.thumbnail', array( diff --git a/include/category_default.inc.php b/include/category_default.inc.php index 594712fbb..5c8023f73 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -104,7 +104,7 @@ while ($row = mysql_fetch_array($result)) $url_link.= '&image_id='.$row['id']; if ($page['cat'] == 'search') { - $url_link.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; + $url_link.= '&search='.$_GET['search']; } $template->assign_block_vars( diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 500070f80..30abdd271 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -94,7 +94,6 @@ function check_cat_id( $cat ) } } if ( $cat == 'fav' - or $cat == 'search' or $cat == 'most_visited' or $cat == 'best_rated' or $cat == 'recent_pics' @@ -103,6 +102,10 @@ function check_cat_id( $cat ) { $page['cat'] = $cat; } + if ($cat == 'search' and isset($_GET['search'])) + { + $page['cat'] = $cat; + } } } @@ -448,6 +451,43 @@ function initialize_category( $calling_page = 'category' ) // search result if ( $page['cat'] == 'search' ) { + // analyze search string given in URL (created in search.php) + $tokens = explode('|', $_GET['search']); + + if (isset($tokens[1]) and $tokens[1] == 'AND') + { + $search['mode'] = 'AND'; + } + else + { + $search['mode'] = 'OR'; + } + + $search_tokens = explode(';', $tokens[0]); + foreach ($search_tokens as $search_token) + { + $tokens = explode(':', $search_token); + $field_name = $tokens[0]; + $field_content = $tokens[1]; + + $tokens = explode('~', $tokens[1]); + if (isset($tokens[1])) + { + $search['fields'][$field_name]['mode'] = $tokens[1]; + } + else + { + $search['fields'][$field_name]['mode'] = ''; + } + + $search['fields'][$field_name]['words'] = array(); + $tokens = explode(',', $tokens[0]); + foreach ($tokens as $token) + { + array_push($search['fields'][$field_name]['words'], $token); + } + } + $page['title'] = $lang['search_result']; if ( $calling_page == 'picture' ) { @@ -455,48 +495,89 @@ function initialize_category( $calling_page = 'category' ) $page['title'].= $_GET['search']."</span>"; } - $page['where'] = ' WHERE ('; - $fields = array( 'file', 'name', 'comment', 'keywords' ); - $words = explode( ',', $_GET['search'] ); - $sql_search = array(); - foreach ( $words as $i => $word ) { - // if the user searchs any of the words, the where statement must - // be : - // field1 LIKE '%$word1%' OR field2 LIKE '%$word1%' ... - // OR field1 LIKE '%$word2%' OR field2 LIKE '%$word2%' ... - if ( $_GET['mode'] == 'OR' ) + // SQL where clauses are stored in $clauses array during query + // construction + $clauses = array(); + + $textfields = array('file', 'name', 'comment', 'keywords', 'author'); + foreach ($textfields as $textfield) + { + if (isset($search['fields'][$textfield])) { - if ( $i != 0 ) $page['where'].= ' OR'; - foreach ( $fields as $j => $field ) { - if ( $j != 0 ) $page['where'].= ' OR'; - $page['where'].= ' '.$field." LIKE '%".$word."%'"; + $local_clauses = array(); + foreach ($search['fields'][$textfield]['words'] as $word) + { + array_push($local_clauses, $textfield." LIKE '%".$word."%'"); } + // adds brackets around where clauses + array_walk($local_clauses,create_function('&$s','$s="(".$s.")";')); + array_push($clauses, + implode(' '.$search['fields'][$textfield]['mode'].' ', + $local_clauses)); + } + } + + $datefields = array('date_available', 'date_creation'); + foreach ($datefields as $datefield) + { + $key = $datefield; + if (isset($search['fields'][$key])) + { + $local_clause = $datefield." = '"; + $local_clause.= str_replace('.', '-', + $search['fields'][$key]['words'][0]); + $local_clause.= "'"; + array_push($clauses, $local_clause); } - // if the user searchs all the words : - // ( field1 LIKE '%$word1%' OR field2 LIKE '%$word1%' ) - // AND ( field1 LIKE '%$word2%' OR field2 LIKE '%$word2%' ) - else if ( $_GET['mode'] == 'AND' ) + + foreach (array('after','before') as $suffix) { - if ( $i != 0 ) $page['where'].= ' AND'; - $page['where'].= ' ('; - foreach ( $fields as $j => $field ) { - if ( $j != 0 ) $page['where'].= ' OR'; - $page['where'].= ' '.$field." LIKE '%".$word."%'"; + $key = $datefield.'-'.$suffix; + if (isset($search['fields'][$key])) + { + $local_clause = $datefield; + if ($suffix == 'after') + { + $local_clause.= ' >'; + } + else + { + $local_clause.= ' <'; + } + if (isset($search['fields'][$key]['mode']) + and $search['fields'][$key]['mode'] == 'inc') + { + $local_clause.= '='; + } + $local_clause.= " '"; + $local_clause.= str_replace('.', '-', + $search['fields'][$key]['words'][0]); + $local_clause.= "'"; + array_push($clauses, $local_clause); } - $page['where'].= ' )'; } } - $page['where'].= ' )'; - if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden; - $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images'; - $query.= ' FROM '.IMAGES_TABLE; - $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic'; - $query.= ' ON id = ic.image_id'; - $query.= $page['where']; - $query.= ';'; + if (isset($search['fields']['cat'])) + { + $local_clause = 'category_id IN ('; + $local_clause.= implode(',',$search['fields']['cat']['words']); + $local_clause.= ')'; + array_push($clauses, $local_clause); + } + + // adds brackets around where clauses + array_walk($clauses, create_function('&$s', '$s = "(".$s.")";')); + $page['where'] = 'WHERE '.implode(' '.$search['mode'].' ', $clauses); + if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden; - $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; + $query = ' +SELECT COUNT(DISTINCT(id)) AS nb_total_images + FROM '.IMAGES_TABLE.' + INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id + '.$page['where'].' +;'; + $url.= '&search='.$_GET['search']; } // favorites displaying else if ( $page['cat'] == 'fav' ) |