From e4ce82fc27e1e10d697815928ef06c692a3f56da Mon Sep 17 00:00:00 2001 From: plegall Date: Sun, 5 Dec 2004 11:47:40 +0000 Subject: - search modified : possible to partially fill the date, allwords are separated from more specific search, separation of HTML (in template) and PHP code) git-svn-id: http://piwigo.org/svn/trunk@634 68402e56-0260-453c-a942-63ccdbb3a9ee --- search.php | 187 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 111 insertions(+), 76 deletions(-) (limited to 'search.php') diff --git a/search.php b/search.php index 1c613817d..47a5ddc77 100644 --- a/search.php +++ b/search.php @@ -35,25 +35,27 @@ $errors = array(); $search = array(); if (isset($_POST['submit'])) { - if ($_POST['search_allwords'] && - !preg_match('/^\s*$/', $_POST['search_allwords'])) + if (isset($_POST['search_allwords']) + and !preg_match('/^\s*$/', $_POST['search_allwords'])) { $local_search = array(); - $search_keywords = $_POST['search_allwords']; - $drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', - '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', - ':', '\\', '/', '=', '\'', '!', '*'); - $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' - , ' ', '' , ' ', ' ', ' ', ' ', ' '); - $search_keywords = str_replace($drop_char_match, $drop_char_replace, $search_keywords); + $search_allwords = $_POST['search_allwords']; + $drop_char_match = array( + '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_', + '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'); + $drop_char_replace = array( + ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ', + ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' '); + $search_allwords = str_replace($drop_char_match, + $drop_char_replace, + $search_allwords); - // Split words - $words = preg_split('#\s+#', $search_keywords); + // Split words + $words = preg_split('/\s+/', $search_allwords); $words = array_unique($words); - $search['fields']['allwords'] = array(); - $search['fields']['allwords']['words'] =$words; - $search['fields']['allwords']['mode']= $_POST['mode']; + $search['fields']['allwords'] = array(); + $search['fields']['allwords']['words'] = $words; + $search['fields']['allwords']['mode'] = $_POST['mode']; } if ($_POST['search_author']) @@ -66,48 +68,57 @@ if (isset($_POST['submit'])) { $search['fields']['cat'] = array(); $search['fields']['cat']['words'] = $_POST['cat']; - if (isset($_POST['subcats-included'])) + if ($_POST['subcats-included'] == 1) { $search['fields']['cat']['mode'] = 'sub_inc'; } } + + // dates + $type_date = $_POST['date_type']; if (!empty($_POST['start_year'])) - { - $type_date = $_POST['date_type']; + { + $year = $_POST['start_year']; + $month = $_POST['start_month'] != 0 ? $_POST['start_month'] : '01'; + $day = $_POST['start_day'] != 0 ? $_POST['start_day'] : '01'; + $date = $year.'-'.$month.'-'.$day; + + $search['fields'][$type_date.'-after']['words'] = array($date); + $search['fields'][$type_date.'-after']['mode'] = 'inc'; + } - // start event - $date = $_POST['start_year'].'.'.$_POST['start_month'].'.'.$_POST['start_day']; - $search['fields'][$type_date]['words'] = array($date); - - // duration - $search_duration = 0; - if ( !empty($date) && !empty( $_POST['end_year']) ) + if (!empty($_POST['end_year'])) { - $end_date = $_POST['end_year'].'.'.$_POST['end_month'].'.'.$_POST['end_day']; - $search['fields'][$type_date]['mode'] = $end_date; + $year = $_POST['end_year']; + $month = $_POST['end_month'] != 0 ? $_POST['end_month'] : '12'; + $day = $_POST['end_day'] != 0 ? $_POST['end_day'] : '31'; + $date = $year.'-'.$month.'-'.$day; + + $search['fields'][$type_date.'-before']['words'] = array($date); + $search['fields'][$type_date.'-before']['mode'] = 'inc'; } - } + // search string (for URL) creation $search_string = ''; $tokens = array(); if (!empty($search)) { - foreach (array_keys($search['fields']) as $field) - { - $token = $field.':'; - $token.= implode(',', $search['fields'][$field]['words']); - if (isset($search['fields'][$field]['mode'])) + foreach (array_keys($search['fields']) as $field) { - $token.= '~'.$search['fields'][$field]['mode']; + $token = $field.':'; + $token.= implode(',', $search['fields'][$field]['words']); + if (isset($search['fields'][$field]['mode'])) + { + $token.= '~'.$search['fields'][$field]['mode']; + } + array_push($tokens, $token); + } + $search_string.= implode(';', $tokens); + if (count($tokens) > 1) + { + $search_string.= '|AND'; } - array_push($tokens, $token); - } - $search_string.= implode(';', $tokens); - if (count($tokens) > 1) - { - $search_string.= '|AND'; - } } else { @@ -121,41 +132,69 @@ if (isset($_POST['submit']) and count($errors) == 0) $url = add_session_id($url, true); redirect($url); } - //----------------------------------------------------- template initialization -// day list -$start_day = ''; -// month list -$start_month = ''; + global $template, $lang; + + $template->assign_block_vars( + $blockname, array('SELECTED' => '', + 'VALUE' => 0, + 'OPTION' => '------------')); -// day list -$end_day = ''; -// month list -$end_month = ''; +// start date +get_day_list('start_day', @$_POST['start_day']); +get_month_list('start_month', @$_POST['start_month']); +// end date +get_day_list('end_day', @$_POST['end_day']); +get_month_list('end_month', @$_POST['end_month']); // // Start output of page @@ -198,10 +237,6 @@ $template->assign_vars(array( 'TODAY_DAY' => date('d', time()), 'TODAY_MONTH' => date('m', time()), 'TODAY_YEAR' => date('Y', time()), - 'E_CALENDAR_MONTH' => $end_month, - 'E_CALENDAR_DAY' => $end_day, - 'S_CALENDAR_MONTH' => $start_month, - 'S_CALENDAR_DAY' => $start_day, 'S_SEARCH_ACTION' => add_session_id( 'search.php' ), 'U_HOME' => add_session_id( 'category.php' ) ) @@ -211,11 +246,11 @@ $template->assign_vars(array( $query = ' SELECT name,id,date_last,nb_images,global_rank,uppercats FROM '.CATEGORIES_TABLE; - if ($user['forbidden_categories'] != '') - { - $query.= ' +if ($user['forbidden_categories'] != '') +{ + $query.= ' WHERE id NOT IN ('.$user['forbidden_categories'].')'; - } +} $query.= ' ;'; -- cgit v1.2.3