source: branches/1.7/search.php @ 26062

Last change on this file since 26062 was 2015, checked in by rub, 18 years ago

Replace some $lang by l10n

Merge BSF 2013:2014 into branch-1_7

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: search.php 2015 2007-05-15 20:26:56Z rub $
8// | last update   : $Date: 2007-05-15 20:26:56 +0000 (Tue, 15 May 2007) $
9// | last modifier : $Author: rub $
10// | revision      : $Revision: 2015 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27//--------------------------------------------------------------------- include
28define('PHPWG_ROOT_PATH','./');
29include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_GUEST);
35
36//------------------------------------------------------------------ form check
37$errors = array();
38$search = array();
39if (isset($_POST['submit']))
40{
41  if (isset($_POST['search_allwords'])
42      and !preg_match('/^\s*$/', $_POST['search_allwords']))
43  {
44    $drop_char_match = array(
45      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
46      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
47    $drop_char_replace = array(
48      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
49      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
50
51    // Split words
52    $search['fields']['allwords'] = array(
53      'words' => array_unique(
54        preg_split(
55          '/\s+/',
56          str_replace(
57            $drop_char_match,
58            $drop_char_replace,
59            $_POST['search_allwords']
60            )
61          )
62        ),
63      'mode' => $_POST['mode'],
64      );
65  }
66
67  if (isset($_POST['tags']))
68  {
69    $search['fields']['tags'] = array(
70      'words' => $_POST['tags'],
71      'mode'  => $_POST['tag_mode'],
72      );
73  }
74
75  if ($_POST['search_author'])
76  {
77    $search['fields']['author'] = array(
78      'words' => preg_split(
79        '/\s+/',
80        $_POST['search_author']
81        ),
82      'mode' => 'OR',
83      );
84  }
85
86  if (isset($_POST['cat']))
87  {
88    $search['fields']['cat'] = array(
89      'words'   => $_POST['cat'],
90      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
91      );
92  }
93
94  // dates
95  $type_date = $_POST['date_type'];
96
97  if (!empty($_POST['start_year']))
98  {
99    $search['fields'][$type_date.'-after'] = array(
100      'date' => join(
101        '-',
102        array(
103          $_POST['start_year'],
104          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
105          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
106          )
107        ),
108      'inc' => true,
109      );
110  }
111
112  if (!empty($_POST['end_year']))
113  {
114    $search['fields'][$type_date.'-before'] = array(
115      'date' => join(
116        '-',
117        array(
118          $_POST['end_year'],
119          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
120          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
121          )
122        ),
123      'inc' => true,
124      );
125  }
126
127  if (!empty($search))
128  {
129    // default search mode : each clause must be respected
130    $search['mode'] = 'AND';
131
132    // register search rules in database, then they will be available on
133    // thumbnails page and picture page.
134    $query ='
135INSERT INTO '.SEARCH_TABLE.'
136  (rules, last_seen)
137  VALUES
138  (\''.serialize($search).'\', NOW())
139;';
140    pwg_query($query);
141
142    $search_id = mysql_insert_id();
143  }
144  else
145  {
146    array_push($errors, l10n('search_one_clause_at_least'));
147  }
148}
149//----------------------------------------------------------------- redirection
150if (isset($_POST['submit']) and count($errors) == 0)
151{
152  redirect(
153    make_index_url(
154      array(
155        'section' => 'search',
156        'search'  => $search_id,
157        )
158      )
159    );
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= l10n('search_title');
174$page['body_id'] = 'theSearchPage';
175
176$template->set_filenames( array('search'=>'search.tpl') );
177
178$template->assign_vars(
179  array(
180    'TODAY_DAY' => date('d', time()),
181    'TODAY_MONTH' => date('m', time()),
182    'TODAY_YEAR' => date('Y', time()),
183    'S_SEARCH_ACTION' => 'search.php',
184    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
185    'U_HOME' => make_index_url(),
186    )
187  );
188
189$available_tags = get_available_tags();
190
191if (count($available_tags) > 0)
192{
193  usort( $available_tags, 'name_compare');
194
195  $template->assign_block_vars('tags', array());
196 
197  $template->assign_vars(
198    array(
199      'TAG_SELECTION' => get_html_tag_selection(
200        $available_tags,
201        'tags',
202        isset($_POST['tags']) ? $_POST['tags'] : array()
203        ),
204      )
205    );
206}
207
208//------------------------------------------------------------- categories form
209$query = '
210SELECT name,id,date_last,nb_images,global_rank,uppercats
211  FROM '.CATEGORIES_TABLE.'
212'.get_sql_condition_FandF
213  (
214    array
215      (
216        'forbidden_categories' => 'id',
217        'visible_categories' => 'id'
218      ),
219    'WHERE'
220  ).'
221;';
222
223$selecteds = array();
224display_select_cat_wrapper($query, $selecteds, 'category_option', false);
225
226//-------------------------------------------------------------- errors display
227if (sizeof($errors) != 0)
228{
229  $template->assign_block_vars('errors',array());
230  foreach ($errors as $error)
231  {
232    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
233  }
234}
235//------------------------------------------------------------ log informations
236include(PHPWG_ROOT_PATH.'include/page_header.php');
237$template->parse('search');
238include(PHPWG_ROOT_PATH.'include/page_tail.php');
239?>
Note: See TracBrowser for help on using the repository browser.