Changeset 634 for trunk/search.php
- Timestamp:
- Dec 5, 2004, 12:47:40 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/search.php
r629 r634 36 36 if (isset($_POST['submit'])) 37 37 { 38 if ( $_POST['search_allwords'] &&39 !preg_match('/^\s*$/', $_POST['search_allwords']))38 if (isset($_POST['search_allwords']) 39 and !preg_match('/^\s*$/', $_POST['search_allwords'])) 40 40 { 41 41 $local_search = array(); 42 $search_keywords = $_POST['search_allwords']; 43 $drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', 44 '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', 45 ':', '\\', '/', '=', '\'', '!', '*'); 46 $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 47 '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' 48 , ' ', '' , ' ', ' ', ' ', ' ', ' '); 49 $search_keywords = str_replace($drop_char_match, $drop_char_replace, $search_keywords); 42 $search_allwords = $_POST['search_allwords']; 43 $drop_char_match = array( 44 '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_', 45 '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'); 46 $drop_char_replace = array( 47 ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ', 48 ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' '); 49 $search_allwords = str_replace($drop_char_match, 50 $drop_char_replace, 51 $search_allwords); 50 52 51 52 $words = preg_split('#\s+#', $search_keywords);53 // Split words 54 $words = preg_split('/\s+/', $search_allwords); 53 55 $words = array_unique($words); 54 55 $search['fields']['allwords']['words'] =$words;56 $search['fields']['allwords']['mode']= $_POST['mode'];56 $search['fields']['allwords'] = array(); 57 $search['fields']['allwords']['words'] = $words; 58 $search['fields']['allwords']['mode'] = $_POST['mode']; 57 59 } 58 60 … … 67 69 $search['fields']['cat'] = array(); 68 70 $search['fields']['cat']['words'] = $_POST['cat']; 69 if ( isset($_POST['subcats-included']))71 if ($_POST['subcats-included'] == 1) 70 72 { 71 73 $search['fields']['cat']['mode'] = 'sub_inc'; 72 74 } 73 75 } 76 77 // dates 78 $type_date = $_POST['date_type']; 74 79 75 80 if (!empty($_POST['start_year'])) 76 { 77 $type_date = $_POST['date_type']; 78 79 // start event 80 $date = $_POST['start_year'].'.'.$_POST['start_month'].'.'.$_POST['start_day']; 81 $search['fields'][$type_date]['words'] = array($date); 82 83 // duration 84 $search_duration = 0; 85 if ( !empty($date) && !empty( $_POST['end_year']) ) 86 { 87 $end_date = $_POST['end_year'].'.'.$_POST['end_month'].'.'.$_POST['end_day']; 88 $search['fields'][$type_date]['mode'] = $end_date; 89 } 90 } 81 { 82 $year = $_POST['start_year']; 83 $month = $_POST['start_month'] != 0 ? $_POST['start_month'] : '01'; 84 $day = $_POST['start_day'] != 0 ? $_POST['start_day'] : '01'; 85 $date = $year.'-'.$month.'-'.$day; 86 87 $search['fields'][$type_date.'-after']['words'] = array($date); 88 $search['fields'][$type_date.'-after']['mode'] = 'inc'; 89 } 90 91 if (!empty($_POST['end_year'])) 92 { 93 $year = $_POST['end_year']; 94 $month = $_POST['end_month'] != 0 ? $_POST['end_month'] : '12'; 95 $day = $_POST['end_day'] != 0 ? $_POST['end_day'] : '31'; 96 $date = $year.'-'.$month.'-'.$day; 97 98 $search['fields'][$type_date.'-before']['words'] = array($date); 99 $search['fields'][$type_date.'-before']['mode'] = 'inc'; 100 } 101 91 102 // search string (for URL) creation 92 103 $search_string = ''; … … 94 105 if (!empty($search)) 95 106 { 96 foreach (array_keys($search['fields']) as $field)97 {98 $token = $field.':';99 $token.= implode(',', $search['fields'][$field]['words']);100 if (isset($search['fields'][$field]['mode']))101 {102 $token.= '~'.$search['fields'][$field]['mode'];103 }104 array_push($tokens, $token);105 }106 $search_string.= implode(';', $tokens);107 if (count($tokens) > 1)108 {109 $search_string.= '|AND';110 }107 foreach (array_keys($search['fields']) as $field) 108 { 109 $token = $field.':'; 110 $token.= implode(',', $search['fields'][$field]['words']); 111 if (isset($search['fields'][$field]['mode'])) 112 { 113 $token.= '~'.$search['fields'][$field]['mode']; 114 } 115 array_push($tokens, $token); 116 } 117 $search_string.= implode(';', $tokens); 118 if (count($tokens) > 1) 119 { 120 $search_string.= '|AND'; 121 } 111 122 } 112 123 else … … 122 133 redirect($url); 123 134 } 124 125 135 //----------------------------------------------------- template initialization 126 // day list 127 $start_day = '<select name="start_day">'; 128 for ($i=0; $i <= 31; $i++) 129 { 130 $start_day .= '<option value="' . $i . '" >' . ( ($i == 0) ? ' -- ' : str_pad($i, 2, '0', STR_PAD_LEFT) ) . '</option>'; 131 } 132 $start_day .= '</select>'; 133 134 // month list 135 $start_month = '<select name="start_month">'; 136 $start_month .= '<option value="0"> ------------ </option>'; 137 for ($i=1; $i <= 12; $i++) 138 { 139 $start_month .= '<option value="' . $i . '">' . $lang['month'][$i] . '</option>'; 140 } 141 $start_month .= '</select>'; 142 143 // day list 144 $end_day = '<select name="end_day">'; 145 for ($i=0; $i <= 31; $i++) 146 { 147 $end_day .= '<option value="' . $i . '" >' . ( ($i == 0) ? ' -- ' : str_pad($i, 2, '0', STR_PAD_LEFT) ) . '</option>'; 148 } 149 $end_day .= '</select>'; 150 151 // month list 152 $end_month = '<select name="end_month">'; 153 $end_month .= '<option value="0"> ------------ </option>'; 154 for ($i=1; $i <= 12; $i++) 155 { 156 $end_month .= '<option value="' . $i . '">' . $lang['month'][$i] . '</option>'; 157 } 158 $end_month .= '</select>'; 136 /** 137 * instantiate number list for days in a template block 138 * 139 * @param string blockname 140 * @param string selection 141 */ 142 function get_day_list($blockname, $selection) 143 { 144 global $template; 145 146 $template->assign_block_vars( 147 $blockname, array('SELECTED' => '', 'VALUE' => 0, 'OPTION' => '--')); 148 149 for ($i = 1; $i <= 31; $i++) 150 { 151 $selected = ''; 152 if ($i == (int)$selection) 153 { 154 $selected = 'selected="selected"'; 155 } 156 $template->assign_block_vars( 157 $blockname, array('SELECTED' => $selected, 158 'VALUE' => $i, 159 'OPTION' => str_pad($i, 2, '0', STR_PAD_LEFT))); 160 } 161 } 162 163 /** 164 * instantiate month list in a template block 165 * 166 * @param string blockname 167 * @param string selection 168 */ 169 function get_month_list($blockname, $selection) 170 { 171 global $template, $lang; 172 173 $template->assign_block_vars( 174 $blockname, array('SELECTED' => '', 175 'VALUE' => 0, 176 'OPTION' => '------------')); 177 178 for ($i = 1; $i <= 12; $i++) 179 { 180 $selected = ''; 181 if ($i == (int)$selection) 182 { 183 $selected = 'selected="selected"'; 184 } 185 $template->assign_block_vars( 186 $blockname, array('SELECTED' => $selected, 187 'VALUE' => $i, 188 'OPTION' => $lang['month'][$i])); 189 } 190 } 191 192 // start date 193 get_day_list('start_day', @$_POST['start_day']); 194 get_month_list('start_month', @$_POST['start_month']); 195 // end date 196 get_day_list('end_day', @$_POST['end_day']); 197 get_month_list('end_month', @$_POST['end_month']); 159 198 160 199 // … … 199 238 'TODAY_MONTH' => date('m', time()), 200 239 'TODAY_YEAR' => date('Y', time()), 201 'E_CALENDAR_MONTH' => $end_month,202 'E_CALENDAR_DAY' => $end_day,203 'S_CALENDAR_MONTH' => $start_month,204 'S_CALENDAR_DAY' => $start_day,205 240 'S_SEARCH_ACTION' => add_session_id( 'search.php' ), 206 241 'U_HOME' => add_session_id( 'category.php' ) … … 212 247 SELECT name,id,date_last,nb_images,global_rank,uppercats 213 248 FROM '.CATEGORIES_TABLE; 214 215 216 249 if ($user['forbidden_categories'] != '') 250 { 251 $query.= ' 217 252 WHERE id NOT IN ('.$user['forbidden_categories'].')'; 218 253 } 219 254 $query.= ' 220 255 ;';
Note: See TracChangeset
for help on using the changeset viewer.