source: trunk/search.php @ 1015

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

Search engine redesign, second part :

improvement: in category.php, an icon opening a popup display the list of
search rules.

modification: function get_search_array is responsible of search rules
retrieving from database. This function is called from get_sql_search_clause
and from search_rules.php

modification: ability to search multiple authors. Warning: this version of
search tool can't search author names including any blank space.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 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-27 22:40:51 +0000 (Fri, 27 Jan 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1015 $
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' => preg_split(
68        '/\s+/',
69        $_POST['search_author']
70        ),
71      'mode' => 'OR',
72      );
73  }
74 
75  if (isset($_POST['cat']))
76  {
77    $search['fields']['cat'] = array(
78      'words'   => $_POST['cat'],
79      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
80      );
81  }
82
83  // dates
84  $type_date = $_POST['date_type'];
85 
86  if (!empty($_POST['start_year']))
87  {
88    $search['fields'][$type_date.'-after'] = array(
89      'date' => join(
90        '-',
91        array(
92          $_POST['start_year'],
93          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
94          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
95          )
96        ),
97      'inc' => true,
98      );
99  }
100
101  if (!empty($_POST['end_year']))
102  {
103    $search['fields'][$type_date.'-before'] = array(
104      'date' => join(
105        '-',
106        array(
107          $_POST['end_year'],
108          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
109          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
110          )
111        ),
112      'inc' => true,
113      );
114  }
115 
116  if (!empty($search))
117  {
118    // default search mode : each clause must be respected
119    $search['mode'] = 'AND';
120
121    // register search rules in database, then they will be available on
122    // thumbnails page and picture page.
123    $query ='
124INSERT INTO '.SEARCH_TABLE.'
125  (rules)
126  VALUES
127  (\''.serialize($search).'\')
128;';
129    pwg_query($query);
130
131    $search_id = mysql_insert_id();
132  }
133  else
134  {
135    array_push($errors, $lang['search_one_clause_at_least']);
136  }
137}
138//----------------------------------------------------------------- redirection
139if (isset($_POST['submit']) and count($errors) == 0)
140{
141  $url = 'category.php?cat=search&search='.$search_id;
142  redirect($url);
143}
144//----------------------------------------------------- template initialization
145
146// start date
147get_day_list('start_day', @$_POST['start_day']);
148get_month_list('start_month', @$_POST['start_month']);
149// end date
150get_day_list('end_day', @$_POST['end_day']);
151get_month_list('end_month', @$_POST['end_month']);
152
153//
154// Start output of page
155//
156$title= $lang['search_title'];
157$page['body_id'] = 'theSearchPage';
158include(PHPWG_ROOT_PATH.'include/page_header.php');
159
160$template->set_filenames( array('search'=>'search.tpl') );
161$template->assign_vars(array(
162  'L_SEARCH_TITLE' => $lang['search_title'],
163  'L_SEARCH_OPTIONS' => $lang['search_options'],
164  'L_RETURN' => $lang['home'],
165  'L_SUBMIT' => $lang['submit'],
166  'L_RESET' => $lang['reset'],
167  'L_SEARCH_KEYWORDS'=>$lang['search_keywords'],
168  'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'],
169  'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'],
170  'L_SEARCH_AUTHOR'=>$lang['search_author'],
171  'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'],
172  'L_SEARCH_CATEGORIES'=>$lang['search_categories'],
173  'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'],
174  'L_YES' => $lang['yes'],
175  'L_NO' => $lang['no'],
176  'L_SEARCH_DATE' => $lang['search_date'],
177  'L_TODAY' => $lang['today'],
178  'L_SEARCH_DATE_FROM'=>$lang['search_date_from'],
179  'L_SEARCH_DATE_TO'=>$lang['search_date_to'],
180  'L_DAYS'=>$lang['days'],
181  'L_MONTH'=>$lang['w_month'],
182  'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'],
183  'L_SEARCH_CREATION'=>$lang['search_date_creation'],
184  'L_SEARCH_AVAILABILITY'=>$lang['search_date_available'],
185  'L_RESULT_SORT'=>$lang['search_sort'],
186  'L_SORT_ASCENDING'=>$lang['search_ascending'],
187  'L_SORT_DESCENDING'=>$lang['search_descending'],
188 
189  'TODAY_DAY' => date('d', time()),
190  'TODAY_MONTH' => date('m', time()),
191  'TODAY_YEAR' => date('Y', time()),
192  'S_SEARCH_ACTION' => 'search.php',
193  'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=search',
194  'U_HOME' => 'category.php'
195  )
196);
197
198//------------------------------------------------------------- categories form
199$query = '
200SELECT name,id,date_last,nb_images,global_rank,uppercats
201  FROM '.CATEGORIES_TABLE;
202if ($user['forbidden_categories'] != '')
203{
204  $query.= '
205  WHERE id NOT IN ('.$user['forbidden_categories'].')';
206}
207$query.= '
208;';
209
210$selecteds = array();
211display_select_cat_wrapper($query, $selecteds, 'category_option', false);
212
213//-------------------------------------------------------------- errors display
214if (sizeof($errors) != 0)
215{
216  $template->assign_block_vars('errors',array());
217  foreach ($errors as $error)
218  {
219    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
220  }
221}
222//------------------------------------------------------------ log informations
223pwg_log( 'search', $title );
224$template->parse('search');
225include(PHPWG_ROOT_PATH.'include/page_tail.php');
226?>
Note: See TracBrowser for help on using the repository browser.