source: trunk/search.php @ 1119

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

improvement: tags replace keywords. Better data model, less
limitations. Each image can be associated to as many tag as needed. Tags can
contain non ASCII characters. Oriented navigation with tags by association.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 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-04-02 22:26:19 +0000 (Sun, 02 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1119 $
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
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35check_status(ACCESS_GUEST);
36
37//------------------------------------------------------------------ form check
38$errors = array();
39$search = array();
40if (isset($_POST['submit']))
41{
42  if (isset($_POST['search_allwords'])
43      and !preg_match('/^\s*$/', $_POST['search_allwords']))
44  {
45    $drop_char_match = array(
46      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
47      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
48    $drop_char_replace = array(
49      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
50      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
51
52    // Split words
53    $search['fields']['allwords'] = array(
54      'words' => array_unique(
55        preg_split(
56          '/\s+/',
57          str_replace(
58            $drop_char_match,
59            $drop_char_replace,
60            $_POST['search_allwords']
61            )
62          )
63        ),
64      'mode' => $_POST['mode'],
65      );
66  }
67
68  if (isset($_POST['tags']))
69  {
70    $search['fields']['tags'] = array(
71      'words' => $_POST['tags'],
72      'mode'  => $_POST['tag_mode'],
73      );
74  }
75 
76  if ($_POST['search_author'])
77  {
78    $search['fields']['author'] = array(
79      'words' => preg_split(
80        '/\s+/',
81        $_POST['search_author']
82        ),
83      'mode' => 'OR',
84      );
85  }
86
87  if (isset($_POST['cat']))
88  {
89    $search['fields']['cat'] = array(
90      'words'   => $_POST['cat'],
91      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
92      );
93  }
94
95  // dates
96  $type_date = $_POST['date_type'];
97
98  if (!empty($_POST['start_year']))
99  {
100    $search['fields'][$type_date.'-after'] = array(
101      'date' => join(
102        '-',
103        array(
104          $_POST['start_year'],
105          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
106          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
107          )
108        ),
109      'inc' => true,
110      );
111  }
112
113  if (!empty($_POST['end_year']))
114  {
115    $search['fields'][$type_date.'-before'] = array(
116      'date' => join(
117        '-',
118        array(
119          $_POST['end_year'],
120          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
121          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
122          )
123        ),
124      'inc' => true,
125      );
126  }
127
128  if (!empty($search))
129  {
130    // default search mode : each clause must be respected
131    $search['mode'] = 'AND';
132
133    // register search rules in database, then they will be available on
134    // thumbnails page and picture page.
135    $query ='
136INSERT INTO '.SEARCH_TABLE.'
137  (rules)
138  VALUES
139  (\''.serialize($search).'\')
140;';
141    pwg_query($query);
142
143    $search_id = mysql_insert_id();
144  }
145  else
146  {
147    array_push($errors, $lang['search_one_clause_at_least']);
148  }
149}
150//----------------------------------------------------------------- redirection
151if (isset($_POST['submit']) and count($errors) == 0)
152{
153  redirect(
154    make_index_url(
155      array(
156        'section' => 'search',
157        'search'  => $search_id,
158        )
159      )
160    );
161}
162//----------------------------------------------------- template initialization
163
164// start date
165get_day_list('start_day', @$_POST['start_day']);
166get_month_list('start_month', @$_POST['start_month']);
167// end date
168get_day_list('end_day', @$_POST['end_day']);
169get_month_list('end_month', @$_POST['end_month']);
170
171//
172// Start output of page
173//
174$title= $lang['search_title'];
175$page['body_id'] = 'theSearchPage';
176include(PHPWG_ROOT_PATH.'include/page_header.php');
177
178$template->set_filenames( array('search'=>'search.tpl') );
179$template->assign_vars(array(
180  'L_SEARCH_TITLE' => $lang['search_title'],
181  'L_SEARCH_OPTIONS' => $lang['search_options'],
182  'L_RETURN' => $lang['home'],
183  'L_SUBMIT' => $lang['submit'],
184  'L_RESET' => $lang['reset'],
185  'L_SEARCH_KEYWORDS'=>$lang['search_keywords'],
186  'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'],
187  'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'],
188  'L_SEARCH_AUTHOR'=>$lang['search_author'],
189  'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'],
190  'L_SEARCH_CATEGORIES'=>$lang['search_categories'],
191  'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'],
192  'L_YES' => $lang['yes'],
193  'L_NO' => $lang['no'],
194  'L_SEARCH_DATE' => $lang['search_date'],
195  'L_TODAY' => $lang['today'],
196  'L_SEARCH_DATE_FROM'=>$lang['search_date_from'],
197  'L_SEARCH_DATE_TO'=>$lang['search_date_to'],
198  'L_DAYS'=>$lang['days'],
199  'L_MONTH'=>$lang['w_month'],
200  'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'],
201  'L_RESULT_SORT'=>$lang['search_sort'],
202  'L_SORT_ASCENDING'=>$lang['search_ascending'],
203  'L_SORT_DESCENDING'=>$lang['search_descending'],
204
205  'TODAY_DAY' => date('d', time()),
206  'TODAY_MONTH' => date('m', time()),
207  'TODAY_YEAR' => date('Y', time()),
208  'S_SEARCH_ACTION' => 'search.php',
209  'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=search',
210  'U_HOME' => make_index_url(),
211
212  'TAG_SELECTION' => get_html_tag_selection(
213    get_available_tags(
214      isset($user['forbidden_categories'])
215      ? explode(',', $user['forbidden_categories'])
216      : null
217      ),
218    'tags',
219    isset($_POST['tags']) ? $_POST['tags'] : array()
220    ),
221  )
222);
223
224//------------------------------------------------------------- categories form
225$query = '
226SELECT name,id,date_last,nb_images,global_rank,uppercats
227  FROM '.CATEGORIES_TABLE;
228if ($user['forbidden_categories'] != '')
229{
230  $query.= '
231  WHERE id NOT IN ('.$user['forbidden_categories'].')';
232}
233$query.= '
234;';
235
236$selecteds = array();
237display_select_cat_wrapper($query, $selecteds, 'category_option', false);
238
239//-------------------------------------------------------------- errors display
240if (sizeof($errors) != 0)
241{
242  $template->assign_block_vars('errors',array());
243  foreach ($errors as $error)
244  {
245    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
246  }
247}
248//------------------------------------------------------------ log informations
249pwg_log( 'search', $title );
250$template->parse('search');
251include(PHPWG_ROOT_PATH.'include/page_tail.php');
252?>
Note: See TracBrowser for help on using the repository browser.