1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 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 |
---|
25 | define('PHPWG_ROOT_PATH','./'); |
---|
26 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
27 | |
---|
28 | // +-----------------------------------------------------------------------+ |
---|
29 | // | Check Access and exit when user status is not ok | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | check_status(ACCESS_GUEST); |
---|
32 | |
---|
33 | //------------------------------------------------------------------ form check |
---|
34 | $search = array(); |
---|
35 | if (isset($_POST['submit'])) |
---|
36 | { |
---|
37 | foreach ($_POST as $post_key => $post_value) |
---|
38 | { |
---|
39 | if (!is_array($post_value)) |
---|
40 | { |
---|
41 | $_POST[$post_key] = pwg_db_real_escape_string($post_value); |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | if (isset($_POST['search_allwords']) |
---|
46 | and !preg_match('/^\s*$/', $_POST['search_allwords'])) |
---|
47 | { |
---|
48 | $drop_char_match = array( |
---|
49 | '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_', |
---|
50 | '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'); |
---|
51 | $drop_char_replace = array( |
---|
52 | ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ', |
---|
53 | ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' '); |
---|
54 | |
---|
55 | // Split words |
---|
56 | $search['fields']['allwords'] = array( |
---|
57 | 'words' => array_unique( |
---|
58 | preg_split( |
---|
59 | '/\s+/', |
---|
60 | str_replace( |
---|
61 | $drop_char_match, |
---|
62 | $drop_char_replace, |
---|
63 | $_POST['search_allwords'] |
---|
64 | ) |
---|
65 | ) |
---|
66 | ), |
---|
67 | 'mode' => $_POST['mode'], |
---|
68 | ); |
---|
69 | } |
---|
70 | |
---|
71 | if (isset($_POST['tags'])) |
---|
72 | { |
---|
73 | check_input_parameter('tags', $_POST, true, PATTERN_ID); |
---|
74 | |
---|
75 | $search['fields']['tags'] = array( |
---|
76 | 'words' => $_POST['tags'], |
---|
77 | 'mode' => $_POST['tag_mode'], |
---|
78 | ); |
---|
79 | } |
---|
80 | |
---|
81 | if ($_POST['search_author']) |
---|
82 | { |
---|
83 | $search['fields']['author'] = array( |
---|
84 | 'words' => preg_split( |
---|
85 | '/\s+/', |
---|
86 | $_POST['search_author'] |
---|
87 | ), |
---|
88 | 'mode' => 'OR', |
---|
89 | ); |
---|
90 | } |
---|
91 | |
---|
92 | if (isset($_POST['cat'])) |
---|
93 | { |
---|
94 | check_input_parameter('cat', $_POST, true, PATTERN_ID); |
---|
95 | |
---|
96 | $search['fields']['cat'] = array( |
---|
97 | 'words' => $_POST['cat'], |
---|
98 | 'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false, |
---|
99 | ); |
---|
100 | } |
---|
101 | |
---|
102 | // dates |
---|
103 | $type_date = $_POST['date_type']; |
---|
104 | |
---|
105 | if (!empty($_POST['start_year'])) |
---|
106 | { |
---|
107 | $search['fields'][$type_date.'-after'] = array( |
---|
108 | 'date' => sprintf( |
---|
109 | '%d-%02d-%02d', |
---|
110 | $_POST['start_year'], |
---|
111 | $_POST['start_month'] != 0 ? $_POST['start_month'] : '01', |
---|
112 | $_POST['start_day'] != 0 ? $_POST['start_day'] : '01' |
---|
113 | ), |
---|
114 | 'inc' => true, |
---|
115 | ); |
---|
116 | } |
---|
117 | |
---|
118 | if (!empty($_POST['end_year'])) |
---|
119 | { |
---|
120 | $search['fields'][$type_date.'-before'] = array( |
---|
121 | 'date' => sprintf( |
---|
122 | '%d-%02d-%02d', |
---|
123 | $_POST['end_year'], |
---|
124 | $_POST['end_month'] != 0 ? $_POST['end_month'] : '12', |
---|
125 | $_POST['end_day'] != 0 ? $_POST['end_day'] : '31' |
---|
126 | ), |
---|
127 | 'inc' => true, |
---|
128 | ); |
---|
129 | } |
---|
130 | |
---|
131 | if (!empty($search)) |
---|
132 | { |
---|
133 | // default search mode : each clause must be respected |
---|
134 | $search['mode'] = 'AND'; |
---|
135 | |
---|
136 | // register search rules in database, then they will be available on |
---|
137 | // thumbnails page and picture page. |
---|
138 | $query =' |
---|
139 | INSERT INTO '.SEARCH_TABLE.' |
---|
140 | (rules, last_seen) |
---|
141 | VALUES |
---|
142 | (\''.serialize($search).'\', NOW()) |
---|
143 | ;'; |
---|
144 | pwg_query($query); |
---|
145 | |
---|
146 | $search_id = pwg_db_insert_id(SEARCH_TABLE); |
---|
147 | } |
---|
148 | else |
---|
149 | { |
---|
150 | array_push($page['errors'], l10n('Empty query. No criteria has been entered.')); |
---|
151 | } |
---|
152 | } |
---|
153 | //----------------------------------------------------------------- redirection |
---|
154 | if (isset($_POST['submit']) and count($page['errors']) == 0) |
---|
155 | { |
---|
156 | redirect( |
---|
157 | make_index_url( |
---|
158 | array( |
---|
159 | 'section' => 'search', |
---|
160 | 'search' => $search_id, |
---|
161 | ) |
---|
162 | ) |
---|
163 | ); |
---|
164 | } |
---|
165 | //----------------------------------------------------- template initialization |
---|
166 | |
---|
167 | // |
---|
168 | // Start output of page |
---|
169 | // |
---|
170 | $title= l10n('Search'); |
---|
171 | $page['body_id'] = 'theSearchPage'; |
---|
172 | |
---|
173 | $template->set_filename('search' ,'search.tpl' ); |
---|
174 | |
---|
175 | $month_list = $lang['month']; |
---|
176 | $month_list[0]='------------'; |
---|
177 | ksort($month_list); |
---|
178 | |
---|
179 | $template->assign( |
---|
180 | array( |
---|
181 | 'F_SEARCH_ACTION' => 'search.php', |
---|
182 | 'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search', |
---|
183 | |
---|
184 | 'month_list' => $month_list, |
---|
185 | 'START_DAY_SELECTED' => @$_POST['start_day'], |
---|
186 | 'START_MONTH_SELECTED' => @$_POST['start_month'], |
---|
187 | 'END_DAY_SELECTED' => @$_POST['end_day'], |
---|
188 | 'END_MONTH_SELECTED' => @$_POST['end_month'], |
---|
189 | ) |
---|
190 | ); |
---|
191 | |
---|
192 | $available_tags = get_available_tags(); |
---|
193 | |
---|
194 | if (count($available_tags) > 0) |
---|
195 | { |
---|
196 | usort( $available_tags, 'tag_alpha_compare'); |
---|
197 | |
---|
198 | $template->assign( |
---|
199 | 'TAG_SELECTION', |
---|
200 | get_html_tag_selection( |
---|
201 | $available_tags, |
---|
202 | 'tags', |
---|
203 | isset($_POST['tags']) ? $_POST['tags'] : array() |
---|
204 | ) |
---|
205 | ); |
---|
206 | } |
---|
207 | |
---|
208 | //------------------------------------------------------------- categories form |
---|
209 | $query = ' |
---|
210 | SELECT id,name,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 | display_select_cat_wrapper($query, array(), 'category_options', false); |
---|
223 | |
---|
224 | |
---|
225 | // include menubar |
---|
226 | $themeconf = $template->get_template_vars('themeconf'); |
---|
227 | if (!isset($themeconf['hide_menu_on']) OR !in_array('theSearchPage', $themeconf['hide_menu_on'])) |
---|
228 | { |
---|
229 | include( PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
230 | } |
---|
231 | |
---|
232 | //------------------------------------------------------------ html code display |
---|
233 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
234 | include(PHPWG_ROOT_PATH.'include/page_messages.php'); |
---|
235 | $template->pparse('search'); |
---|
236 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
237 | ?> |
---|