source: trunk/search.php @ 1008

Last change on this file since 1008 was 1008, checked in by plg, 18 years ago

Search engine redesign, first part :

  • new table #search to store search rules associated to a search id.
  • search rules are not passed through GET anymore, the search array build in search.php is serialized in #search table, so no need to rebuild it in function include/functions_category.inc.php::category_initialize
  • search array build code is improved (efficiency and layout) in search.php
  • SQL related to search is build in a dedicated function include/functions::get_sql_search_clause
  • direct search author:<...>, date_avalaible:<...>, date_creation:<...>, keywords:<...> from picture.php are not available anymore. They will come back later, with improvement (new design). Same for date_*:<> in calendar calendar category.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-01-20 14:34:37 +0000 (Fri, 20 Jan 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1008 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28//--------------------------------------------------------------------- include
29define('PHPWG_ROOT_PATH','./');
30include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
31//-------------------------------------------------- access authorization check
32check_login_authorization();
33//------------------------------------------------------------------ form check
34$errors = array();
35$search = array();
36if (isset($_POST['submit']))
37{
38  if (isset($_POST['search_allwords'])
39      and !preg_match('/^\s*$/', $_POST['search_allwords']))
40  {   
41    $drop_char_match = array(
42      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
43      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
44    $drop_char_replace = array(
45      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
46      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
47       
48    // Split words
49    $search['fields']['allwords'] = array(
50      'words' => array_unique(
51        preg_split(
52          '/\s+/',
53          str_replace(
54            $drop_char_match,
55            $drop_char_replace,
56            $_POST['search_allwords']
57            )
58          )
59        ),
60      'mode' => $_POST['mode'],
61      );
62  }
63 
64  if ($_POST['search_author'])
65  {
66    $search['fields']['author'] = array(
67      'words' => array($_POST['search_author']),
68      );
69  }
70 
71  if (isset($_POST['cat']))
72  {
73    $search['fields']['cat'] = array(
74      'words'   => $_POST['cat'],
75      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
76      );
77  }
78
79  // dates
80  $type_date = $_POST['date_type'];
81 
82  if (!empty($_POST['start_year']))
83  {
84//     $year = $_POST['start_year'];
85//     $month = $_POST['start_month'] != 0 ? $_POST['start_month'] : '01';
86//     $day = $_POST['start_day'] != 0 ? $_POST['start_day'] : '01';
87//     $date = $year.'-'.$month.'-'.$day;
88   
89//     $search['fields'][$type_date.'-after']['words'] = array($date);
90//     $search['fields'][$type_date.'-after']['mode'] = 'inc';
91
92    $search['fields'][$type_date.'-after'] = array(
93      'date' => join(
94        '-',
95        array(
96          $_POST['start_year'],
97          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
98          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
99          )
100        ),
101      'inc' => true,
102      );
103  }
104
105  if (!empty($_POST['end_year']))
106  {
107//     $year = $_POST['end_year'];
108//     $month = $_POST['end_month'] != 0 ? $_POST['end_month'] : '12';
109//     $day = $_POST['end_day'] != 0 ? $_POST['end_day'] : '31';
110//     $date = $year.'-'.$month.'-'.$day;
111   
112    $search['fields'][$type_date.'-before'] = array(
113      'date' => join(
114        '-',
115        array(
116          $_POST['end_year'],
117          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
118          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
119          )
120        ),
121      'inc' => true,
122      );
123  }
124 
125  if (!empty($search))
126  {
127    // default search mode : each clause must be respected
128    $search['mode'] = 'AND';
129
130//     echo '<pre>';
131//     print_r($_POST);
132//     echo '</pre>';
133
134//     echo '<pre>';
135//     print_r($search);
136//     echo '</pre>';
137   
138    // register search rules in database, then they will be available on
139    // thumbnails page and picture page.
140    $query ='
141INSERT INTO '.SEARCH_TABLE.'
142  (rules)
143  VALUES
144  (\''.serialize($search).'\')
145;';
146    pwg_query($query);
147
148    $search_id = mysql_insert_id();
149  }
150  else
151  {
152    array_push($errors, $lang['search_one_clause_at_least']);
153  }
154}
155//----------------------------------------------------------------- redirection
156if (isset($_POST['submit']) and count($errors) == 0)
157{
158  $url = 'category.php?cat=search&search='.$search_id;
159  redirect($url);
160}
161//----------------------------------------------------- template initialization
162
163// start date
164get_day_list('start_day', @$_POST['start_day']);
165get_month_list('start_month', @$_POST['start_month']);
166// end date
167get_day_list('end_day', @$_POST['end_day']);
168get_month_list('end_month', @$_POST['end_month']);
169
170//
171// Start output of page
172//
173$title= $lang['search_title'];
174$page['body_id'] = 'theSearchPage';
175include(PHPWG_ROOT_PATH.'include/page_header.php');
176
177$template->set_filenames( array('search'=>'search.tpl') );
178$template->assign_vars(array(
179  'L_SEARCH_TITLE' => $lang['search_title'],
180  'L_SEARCH_OPTIONS' => $lang['search_options'],
181  'L_RETURN' => $lang['home'],
182  'L_SUBMIT' => $lang['submit'],
183  'L_RESET' => $lang['reset'],
184  'L_SEARCH_KEYWORDS'=>$lang['search_keywords'],
185  'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'],
186  'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'],
187  'L_SEARCH_AUTHOR'=>$lang['search_author'],
188  'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'],
189  'L_SEARCH_CATEGORIES'=>$lang['search_categories'],
190  'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'],
191  'L_YES' => $lang['yes'],
192  'L_NO' => $lang['no'],
193  'L_SEARCH_DATE' => $lang['search_date'],
194  'L_TODAY' => $lang['today'],
195  'L_SEARCH_DATE_FROM'=>$lang['search_date_from'],
196  'L_SEARCH_DATE_TO'=>$lang['search_date_to'],
197  'L_DAYS'=>$lang['days'],
198  'L_MONTH'=>$lang['w_month'],
199  'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'],
200  'L_SEARCH_CREATION'=>$lang['search_date_creation'],
201  'L_SEARCH_AVAILABILITY'=>$lang['search_date_available'],
202  'L_RESULT_SORT'=>$lang['search_sort'],
203  'L_SORT_ASCENDING'=>$lang['search_ascending'],
204  'L_SORT_DESCENDING'=>$lang['search_descending'],
205 
206  'TODAY_DAY' => date('d', time()),
207  'TODAY_MONTH' => date('m', time()),
208  'TODAY_YEAR' => date('Y', time()),
209  'S_SEARCH_ACTION' => 'search.php',
210  'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=search',
211  'U_HOME' => 'category.php'
212  )
213);
214
215//------------------------------------------------------------- categories form
216$query = '
217SELECT name,id,date_last,nb_images,global_rank,uppercats
218  FROM '.CATEGORIES_TABLE;
219if ($user['forbidden_categories'] != '')
220{
221  $query.= '
222  WHERE id NOT IN ('.$user['forbidden_categories'].')';
223}
224$query.= '
225;';
226
227$selecteds = array();
228display_select_cat_wrapper($query, $selecteds, 'category_option', false);
229
230//-------------------------------------------------------------- errors display
231if (sizeof($errors) != 0)
232{
233  $template->assign_block_vars('errors',array());
234  foreach ($errors as $error)
235  {
236    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
237  }
238}
239//------------------------------------------------------------ log informations
240pwg_log( 'search', $title );
241$template->parse('search');
242include(PHPWG_ROOT_PATH.'include/page_tail.php');
243?>
Note: See TracBrowser for help on using the repository browser.