source: trunk/search.php @ 4423

Revision 4325, 6.7 KB checked in by nikrou, 10 years ago (diff)

Feature 1244 resolved
Replace all mysql functions in core code by ones independant of database engine

Fix small php code synxtax : hash must be accessed with [ ] and not { }.

  • Property svn:eol-style set to LF
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24//--------------------------------------------------------------------- include
25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
27
28// +-----------------------------------------------------------------------+
29// | Check Access and exit when user status is not ok                      |
30// +-----------------------------------------------------------------------+
31check_status(ACCESS_GUEST);
32
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 (isset($_POST['tags']))
65  {
66    $search['fields']['tags'] = array(
67      'words' => $_POST['tags'],
68      'mode'  => $_POST['tag_mode'],
69      );
70  }
71
72  if ($_POST['search_author'])
73  {
74    $search['fields']['author'] = array(
75      'words' => preg_split(
76        '/\s+/',
77        $_POST['search_author']
78        ),
79      'mode' => 'OR',
80      );
81  }
82
83  if (isset($_POST['cat']))
84  {
85    $search['fields']['cat'] = array(
86      'words'   => $_POST['cat'],
87      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
88      );
89  }
90
91  // dates
92  $type_date = $_POST['date_type'];
93
94  if (!empty($_POST['start_year']))
95  {
96    $search['fields'][$type_date.'-after'] = array(
97      'date' => join(
98        '-',
99        array(
100          $_POST['start_year'],
101          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
102          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
103          )
104        ),
105      'inc' => true,
106      );
107  }
108
109  if (!empty($_POST['end_year']))
110  {
111    $search['fields'][$type_date.'-before'] = array(
112      'date' => join(
113        '-',
114        array(
115          $_POST['end_year'],
116          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
117          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
118          )
119        ),
120      'inc' => true,
121      );
122  }
123
124  if (!empty($search))
125  {
126    // default search mode : each clause must be respected
127    $search['mode'] = 'AND';
128
129    // register search rules in database, then they will be available on
130    // thumbnails page and picture page.
131    $query ='
132INSERT INTO '.SEARCH_TABLE.'
133  (rules, last_seen)
134  VALUES
135  (\''.serialize($search).'\', NOW())
136;';
137    pwg_query($query);
138
139    $search_id = pwg_db_insert_id();
140  }
141  else
142  {
143    array_push($errors, l10n('search_one_clause_at_least'));
144  }
145}
146//----------------------------------------------------------------- redirection
147if (isset($_POST['submit']) and count($errors) == 0)
148{
149  redirect(
150    make_index_url(
151      array(
152        'section' => 'search',
153        'search'  => $search_id,
154        )
155      )
156    );
157}
158//----------------------------------------------------- template initialization
159
160//
161// Start output of page
162//
163$title= l10n('search_title');
164$page['body_id'] = 'theSearchPage';
165
166$template->set_filename('search' ,'search.tpl' );
167
168$month_list = $lang['month'];
169$month_list[0]='------------';
170ksort($month_list);
171
172$template->assign(
173  array(
174    'F_SEARCH_ACTION' => 'search.php',
175    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
176
177    'month_list' => $month_list,
178    'START_DAY_SELECTED' => @$_POST['start_day'],
179    'START_MONTH_SELECTED' => @$_POST['start_month'],
180    'END_DAY_SELECTED' => @$_POST['end_day'],
181    'END_MONTH_SELECTED' => @$_POST['end_month'],
182    )
183  );
184
185$available_tags = get_available_tags();
186
187if (count($available_tags) > 0)
188{
189  usort( $available_tags, 'tag_alpha_compare');
190
191  $template->assign(
192    'TAG_SELECTION',
193    get_html_tag_selection(
194        $available_tags,
195        'tags',
196        isset($_POST['tags']) ? $_POST['tags'] : array()
197        )
198    );
199}
200
201//------------------------------------------------------------- categories form
202$query = '
203SELECT id,name,global_rank,uppercats
204  FROM '.CATEGORIES_TABLE.'
205'.get_sql_condition_FandF
206  (
207    array
208      (
209        'forbidden_categories' => 'id',
210        'visible_categories' => 'id'
211      ),
212    'WHERE'
213  ).'
214;';
215display_select_cat_wrapper($query, array(), 'category_options', false);
216
217//-------------------------------------------------------------- errors display
218if (sizeof($errors) != 0)
219{
220  $template->assign('errors', $errors);
221}
222//------------------------------------------------------------ log informations
223include(PHPWG_ROOT_PATH.'include/page_header.php');
224$template->pparse('search');
225include(PHPWG_ROOT_PATH.'include/page_tail.php');
226?>
Note: See TracBrowser for help on using the repository browser.