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 : $Id: search_rules.php 1851 2007-02-22 20:20:30Z rub $ |
---|
9 | // | last update : $Date: 2007-02-22 20:20:30 +0000 (Thu, 22 Feb 2007) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1851 $ |
---|
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 | /** |
---|
29 | * returns language value 'included' or 'excluded' depending on boolean |
---|
30 | * value. This function is useful only to make duplicate code shorter |
---|
31 | * |
---|
32 | * @param bool is_included |
---|
33 | * @return string |
---|
34 | */ |
---|
35 | function inc_exc_str($is_included) |
---|
36 | { |
---|
37 | return $is_included ? l10n('included') : l10n('excluded'); |
---|
38 | } |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | initialization | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | |
---|
44 | define('PHPWG_ROOT_PATH','./'); |
---|
45 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
46 | check_status(ACCESS_NONE); |
---|
47 | include_once( PHPWG_ROOT_PATH.'include/functions_search.inc.php' ); |
---|
48 | |
---|
49 | $page['body_id'] = 'thePopuphelpPage'; |
---|
50 | $title = l10n('PhpWebGallery Help'); |
---|
51 | $page['page_banner'] = '<h1>'.$title.'</h1>'; |
---|
52 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
53 | |
---|
54 | $template->set_filenames(array('search_rules' => 'search_rules.tpl')); |
---|
55 | |
---|
56 | // +-----------------------------------------------------------------------+ |
---|
57 | // | Textual rules creation | |
---|
58 | // +-----------------------------------------------------------------------+ |
---|
59 | |
---|
60 | // Rules are stored in database, serialized in an array. This array must be |
---|
61 | // transformed into a list of textual rules. |
---|
62 | |
---|
63 | $search = get_search_array($_GET['search_id']); |
---|
64 | |
---|
65 | if (isset($search['q'])) |
---|
66 | { |
---|
67 | $template->assign_block_vars( |
---|
68 | 'words', |
---|
69 | array( |
---|
70 | 'CONTENT' => $search['q'] |
---|
71 | ) |
---|
72 | ); |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | $template->assign_vars( |
---|
77 | array( |
---|
78 | 'INTRODUCTION' |
---|
79 | => 'OR' == $search['mode'] |
---|
80 | ? l10n('At least one listed rule must be satisfied.') |
---|
81 | : l10n('Each listed rule must be satisfied.'), |
---|
82 | ) |
---|
83 | ); |
---|
84 | } |
---|
85 | |
---|
86 | if (isset($search['fields']['allwords'])) |
---|
87 | { |
---|
88 | $template->assign_block_vars( |
---|
89 | 'words', |
---|
90 | array( |
---|
91 | 'CONTENT' => sprintf( |
---|
92 | l10n('searched words : %s'), |
---|
93 | join(', ', $search['fields']['allwords']['words']) |
---|
94 | ) |
---|
95 | ) |
---|
96 | ); |
---|
97 | } |
---|
98 | |
---|
99 | if (isset($search['fields']['tags'])) |
---|
100 | { |
---|
101 | $template->assign_block_vars( |
---|
102 | 'tags', |
---|
103 | array( |
---|
104 | 'LIST_INTRO' => ($search['fields']['tags']['mode'] == 'AND') |
---|
105 | ? l10n('All tags must match') |
---|
106 | : l10n('At least one tag must match') |
---|
107 | ) |
---|
108 | ); |
---|
109 | |
---|
110 | $query = ' |
---|
111 | SELECT name |
---|
112 | FROM '.TAGS_TABLE.' |
---|
113 | WHERE id IN ('.implode(',', $search['fields']['tags']['words']).') |
---|
114 | ;'; |
---|
115 | $result = pwg_query($query); |
---|
116 | while ($row = mysql_fetch_array($result)) |
---|
117 | { |
---|
118 | $template->assign_block_vars( |
---|
119 | 'tags.tag', |
---|
120 | array( |
---|
121 | 'NAME' => $row['name'], |
---|
122 | ) |
---|
123 | ); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | if (isset($search['fields']['author'])) |
---|
128 | { |
---|
129 | $template->assign_block_vars( |
---|
130 | 'words', |
---|
131 | array( |
---|
132 | 'CONTENT' => sprintf( |
---|
133 | l10n('author(s) : %s'), |
---|
134 | join(', ', $search['fields']['author']['words']) |
---|
135 | ) |
---|
136 | ) |
---|
137 | ); |
---|
138 | } |
---|
139 | |
---|
140 | if (isset($search['fields']['cat'])) |
---|
141 | { |
---|
142 | if ($search['fields']['cat']['sub_inc']) |
---|
143 | { |
---|
144 | // searching all the categories id of sub-categories |
---|
145 | $cat_ids = get_subcat_ids($search['fields']['cat']['words']); |
---|
146 | } |
---|
147 | else |
---|
148 | { |
---|
149 | $cat_ids = $search['fields']['cat']['words']; |
---|
150 | } |
---|
151 | |
---|
152 | $template->assign_block_vars( |
---|
153 | 'categories', |
---|
154 | array( |
---|
155 | 'LIST_INTRO' => l10n('Categories'), |
---|
156 | ) |
---|
157 | ); |
---|
158 | |
---|
159 | $query = ' |
---|
160 | SELECT id, uppercats, global_rank |
---|
161 | FROM '.CATEGORIES_TABLE.' |
---|
162 | WHERE id IN ('. |
---|
163 | implode(',', $cat_ids). |
---|
164 | ') |
---|
165 | ;'; |
---|
166 | $result = pwg_query($query); |
---|
167 | |
---|
168 | $categories = array(); |
---|
169 | if (!empty($result)) |
---|
170 | { |
---|
171 | while ($row = mysql_fetch_array($result)) |
---|
172 | { |
---|
173 | array_push($categories, $row); |
---|
174 | } |
---|
175 | } |
---|
176 | usort($categories, 'global_rank_compare'); |
---|
177 | |
---|
178 | foreach ($categories as $category) |
---|
179 | { |
---|
180 | $template->assign_block_vars( |
---|
181 | 'categories.category', |
---|
182 | array( |
---|
183 | 'NAME' => get_cat_display_name_cache( |
---|
184 | $category['uppercats'], |
---|
185 | null, // no url on category names |
---|
186 | false // no blank replacement |
---|
187 | ) |
---|
188 | ) |
---|
189 | ); |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | foreach (array('date_available', 'date_creation') as $datefield) |
---|
194 | { |
---|
195 | if ('date_available' == $datefield) |
---|
196 | { |
---|
197 | $lang_items = array( |
---|
198 | 'date' => 'became available on %s', |
---|
199 | 'period' => 'became available between %s (%s) and %s (%s)', |
---|
200 | 'after' => 'became available after %s (%s)', |
---|
201 | 'before' => 'became available before %s (%s)', |
---|
202 | ); |
---|
203 | } |
---|
204 | elseif ('date_creation' == $datefield) |
---|
205 | { |
---|
206 | $lang_items = array( |
---|
207 | 'date' => 'created on %s', |
---|
208 | 'period' => 'created between %s (%s) and %s (%s)', |
---|
209 | 'after' => 'created after %s (%s)', |
---|
210 | 'before' => 'created before %s (%s)', |
---|
211 | ); |
---|
212 | } |
---|
213 | |
---|
214 | $keys = array( |
---|
215 | 'date' => $datefield, |
---|
216 | 'after' => $datefield.'-after', |
---|
217 | 'before' => $datefield.'-before', |
---|
218 | ); |
---|
219 | |
---|
220 | if (isset($search['fields'][ $keys['date'] ])) |
---|
221 | { |
---|
222 | $template->assign_block_vars( |
---|
223 | $datefield, |
---|
224 | array( |
---|
225 | 'CONTENT' => sprintf( |
---|
226 | l10n($lang_items['date']), |
---|
227 | format_date($search['fields'][ $keys['date'] ]) |
---|
228 | ), |
---|
229 | ) |
---|
230 | ); |
---|
231 | } |
---|
232 | elseif (isset($search['fields'][ $keys['before'] ]) |
---|
233 | and isset($search['fields'][ $keys['after'] ])) |
---|
234 | { |
---|
235 | $template->assign_block_vars( |
---|
236 | $datefield, |
---|
237 | array( |
---|
238 | 'CONTENT' => sprintf( |
---|
239 | l10n($lang_items['period']), |
---|
240 | |
---|
241 | format_date($search['fields'][ $keys['after'] ]['date']), |
---|
242 | inc_exc_str($search['fields'][ $keys['after'] ]['inc']), |
---|
243 | |
---|
244 | format_date($search['fields'][ $keys['before'] ]['date']), |
---|
245 | inc_exc_str($search['fields'][ $keys['before'] ]['inc']) |
---|
246 | ), |
---|
247 | ) |
---|
248 | ); |
---|
249 | } |
---|
250 | elseif (isset($search['fields'][ $keys['before'] ])) |
---|
251 | { |
---|
252 | $template->assign_block_vars( |
---|
253 | $datefield, |
---|
254 | array( |
---|
255 | 'CONTENT' => sprintf( |
---|
256 | l10n($lang_items['before']), |
---|
257 | |
---|
258 | format_date($search['fields'][ $keys['before'] ]['date']), |
---|
259 | inc_exc_str($search['fields'][ $keys['before'] ]['inc']) |
---|
260 | ), |
---|
261 | ) |
---|
262 | ); |
---|
263 | } |
---|
264 | elseif (isset($search['fields'][ $keys['after'] ])) |
---|
265 | { |
---|
266 | $template->assign_block_vars( |
---|
267 | $datefield, |
---|
268 | array( |
---|
269 | 'CONTENT' => sprintf( |
---|
270 | l10n($lang_items['after']), |
---|
271 | |
---|
272 | format_date($search['fields'][ $keys['after'] ]['date']), |
---|
273 | inc_exc_str($search['fields'][ $keys['after'] ]['inc']) |
---|
274 | ) |
---|
275 | ) |
---|
276 | ); |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | // +-----------------------------------------------------------------------+ |
---|
281 | // | html code display | |
---|
282 | // +-----------------------------------------------------------------------+ |
---|
283 | |
---|
284 | $template->parse('search_rules'); |
---|
285 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
286 | ?> |
---|