1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 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 | // | PhpWebGallery - a PHP based picture gallery | |
---|
25 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
26 | // | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net | |
---|
27 | // +-----------------------------------------------------------------------+ |
---|
28 | // | file : $Id: search.php 2297 2008-04-04 22:57:23Z plg $ |
---|
29 | // | last update : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $ |
---|
30 | // | last modifier : $Author: plg $ |
---|
31 | // | revision : $Revision: 2297 $ |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | // | This program is free software; you can redistribute it and/or modify | |
---|
34 | // | it under the terms of the GNU General Public License as published by | |
---|
35 | // | the Free Software Foundation | |
---|
36 | // | | |
---|
37 | // | This program is distributed in the hope that it will be useful, but | |
---|
38 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
39 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
40 | // | General Public License for more details. | |
---|
41 | // | | |
---|
42 | // | You should have received a copy of the GNU General Public License | |
---|
43 | // | along with this program; if not, write to the Free Software | |
---|
44 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
45 | // | USA. | |
---|
46 | // +-----------------------------------------------------------------------+ |
---|
47 | |
---|
48 | //--------------------------------------------------------------------- include |
---|
49 | define('PHPWG_ROOT_PATH','./'); |
---|
50 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
51 | |
---|
52 | // +-----------------------------------------------------------------------+ |
---|
53 | // | Check Access and exit when user status is not ok | |
---|
54 | // +-----------------------------------------------------------------------+ |
---|
55 | check_status(ACCESS_GUEST); |
---|
56 | |
---|
57 | //------------------------------------------------------------------ form check |
---|
58 | $errors = array(); |
---|
59 | $search = array(); |
---|
60 | if (isset($_POST['submit'])) |
---|
61 | { |
---|
62 | if (isset($_POST['search_allwords']) |
---|
63 | and !preg_match('/^\s*$/', $_POST['search_allwords'])) |
---|
64 | { |
---|
65 | $drop_char_match = array( |
---|
66 | '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_', |
---|
67 | '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'); |
---|
68 | $drop_char_replace = array( |
---|
69 | ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ', |
---|
70 | ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' '); |
---|
71 | |
---|
72 | // Split words |
---|
73 | $search['fields']['allwords'] = array( |
---|
74 | 'words' => array_unique( |
---|
75 | preg_split( |
---|
76 | '/\s+/', |
---|
77 | str_replace( |
---|
78 | $drop_char_match, |
---|
79 | $drop_char_replace, |
---|
80 | $_POST['search_allwords'] |
---|
81 | ) |
---|
82 | ) |
---|
83 | ), |
---|
84 | 'mode' => $_POST['mode'], |
---|
85 | ); |
---|
86 | } |
---|
87 | |
---|
88 | if (isset($_POST['tags'])) |
---|
89 | { |
---|
90 | $search['fields']['tags'] = array( |
---|
91 | 'words' => $_POST['tags'], |
---|
92 | 'mode' => $_POST['tag_mode'], |
---|
93 | ); |
---|
94 | } |
---|
95 | |
---|
96 | if ($_POST['search_author']) |
---|
97 | { |
---|
98 | $search['fields']['author'] = array( |
---|
99 | 'words' => preg_split( |
---|
100 | '/\s+/', |
---|
101 | $_POST['search_author'] |
---|
102 | ), |
---|
103 | 'mode' => 'OR', |
---|
104 | ); |
---|
105 | } |
---|
106 | |
---|
107 | if (isset($_POST['cat'])) |
---|
108 | { |
---|
109 | $search['fields']['cat'] = array( |
---|
110 | 'words' => $_POST['cat'], |
---|
111 | 'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false, |
---|
112 | ); |
---|
113 | } |
---|
114 | |
---|
115 | // dates |
---|
116 | $type_date = $_POST['date_type']; |
---|
117 | |
---|
118 | if (!empty($_POST['start_year'])) |
---|
119 | { |
---|
120 | $search['fields'][$type_date.'-after'] = array( |
---|
121 | 'date' => join( |
---|
122 | '-', |
---|
123 | array( |
---|
124 | $_POST['start_year'], |
---|
125 | $_POST['start_month'] != 0 ? $_POST['start_month'] : '01', |
---|
126 | $_POST['start_day'] != 0 ? $_POST['start_day'] : '01', |
---|
127 | ) |
---|
128 | ), |
---|
129 | 'inc' => true, |
---|
130 | ); |
---|
131 | } |
---|
132 | |
---|
133 | if (!empty($_POST['end_year'])) |
---|
134 | { |
---|
135 | $search['fields'][$type_date.'-before'] = array( |
---|
136 | 'date' => join( |
---|
137 | '-', |
---|
138 | array( |
---|
139 | $_POST['end_year'], |
---|
140 | $_POST['end_month'] != 0 ? $_POST['end_month'] : '12', |
---|
141 | $_POST['end_day'] != 0 ? $_POST['end_day'] : '31', |
---|
142 | ) |
---|
143 | ), |
---|
144 | 'inc' => true, |
---|
145 | ); |
---|
146 | } |
---|
147 | |
---|
148 | if (!empty($search)) |
---|
149 | { |
---|
150 | // default search mode : each clause must be respected |
---|
151 | $search['mode'] = 'AND'; |
---|
152 | |
---|
153 | // register search rules in database, then they will be available on |
---|
154 | // thumbnails page and picture page. |
---|
155 | $query =' |
---|
156 | INSERT INTO '.SEARCH_TABLE.' |
---|
157 | (rules, last_seen) |
---|
158 | VALUES |
---|
159 | (\''.serialize($search).'\', NOW()) |
---|
160 | ;'; |
---|
161 | pwg_query($query); |
---|
162 | |
---|
163 | $search_id = mysql_insert_id(); |
---|
164 | } |
---|
165 | else |
---|
166 | { |
---|
167 | array_push($errors, l10n('search_one_clause_at_least')); |
---|
168 | } |
---|
169 | } |
---|
170 | //----------------------------------------------------------------- redirection |
---|
171 | if (isset($_POST['submit']) and count($errors) == 0) |
---|
172 | { |
---|
173 | redirect( |
---|
174 | make_index_url( |
---|
175 | array( |
---|
176 | 'section' => 'search', |
---|
177 | 'search' => $search_id, |
---|
178 | ) |
---|
179 | ) |
---|
180 | ); |
---|
181 | } |
---|
182 | //----------------------------------------------------- template initialization |
---|
183 | |
---|
184 | // |
---|
185 | // Start output of page |
---|
186 | // |
---|
187 | $title= l10n('search_title'); |
---|
188 | $page['body_id'] = 'theSearchPage'; |
---|
189 | |
---|
190 | $template->set_filename('search' ,'search.tpl' ); |
---|
191 | |
---|
192 | $month_list = $lang['month']; |
---|
193 | $month_list[0]='------------'; |
---|
194 | ksort($month_list); |
---|
195 | |
---|
196 | $template->assign( |
---|
197 | array( |
---|
198 | 'F_SEARCH_ACTION' => 'search.php', |
---|
199 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search', |
---|
200 | |
---|
201 | 'month_list' => $month_list, |
---|
202 | 'START_DAY_SELECTED' => @$_POST['start_day'], |
---|
203 | 'START_MONTH_SELECTED' => @$_POST['start_month'], |
---|
204 | 'END_DAY_SELECTED' => @$_POST['end_day'], |
---|
205 | 'END_MONTH_SELECTED' => @$_POST['end_month'], |
---|
206 | ) |
---|
207 | ); |
---|
208 | |
---|
209 | $available_tags = get_available_tags(); |
---|
210 | |
---|
211 | if (count($available_tags) > 0) |
---|
212 | { |
---|
213 | usort( $available_tags, 'name_compare'); |
---|
214 | |
---|
215 | $template->assign( |
---|
216 | 'TAG_SELECTION', |
---|
217 | get_html_tag_selection( |
---|
218 | $available_tags, |
---|
219 | 'tags', |
---|
220 | isset($_POST['tags']) ? $_POST['tags'] : array() |
---|
221 | ) |
---|
222 | ); |
---|
223 | } |
---|
224 | |
---|
225 | //------------------------------------------------------------- categories form |
---|
226 | $query = ' |
---|
227 | SELECT name,id,date_last,nb_images,global_rank,uppercats |
---|
228 | FROM '.CATEGORIES_TABLE.' |
---|
229 | '.get_sql_condition_FandF |
---|
230 | ( |
---|
231 | array |
---|
232 | ( |
---|
233 | 'forbidden_categories' => 'id', |
---|
234 | 'visible_categories' => 'id' |
---|
235 | ), |
---|
236 | 'WHERE' |
---|
237 | ).' |
---|
238 | ;'; |
---|
239 | display_select_cat_wrapper($query, array(), 'category_options', false); |
---|
240 | |
---|
241 | //-------------------------------------------------------------- errors display |
---|
242 | if (sizeof($errors) != 0) |
---|
243 | { |
---|
244 | $template->assign('errors', $errors); |
---|
245 | } |
---|
246 | //------------------------------------------------------------ log informations |
---|
247 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
248 | $template->pparse('search'); |
---|
249 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
250 | ?> |
---|