1 | <?php |
---|
2 | defined('SMART_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Basic checks | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | |
---|
8 | check_status(ACCESS_ADMINISTRATOR); |
---|
9 | |
---|
10 | $page['active_menu'] = get_active_menu('album'); |
---|
11 | |
---|
12 | check_input_parameter('cat_id', $_GET, false, PATTERN_ID); |
---|
13 | $cat_id = $_GET['cat_id']; |
---|
14 | |
---|
15 | $admin_album_base_url = get_root_url().'admin.php?page=album-'.$cat_id; |
---|
16 | $self_url = SMART_ADMIN.'-album&cat_id='.$cat_id; |
---|
17 | |
---|
18 | $query = ' |
---|
19 | SELECT * |
---|
20 | FROM '.CATEGORIES_TABLE.' |
---|
21 | WHERE id = '.$cat_id.' |
---|
22 | ;'; |
---|
23 | $category = pwg_db_fetch_assoc(pwg_query($query)); |
---|
24 | |
---|
25 | if (!isset($category['id'])) |
---|
26 | { |
---|
27 | die("unknown album"); |
---|
28 | } |
---|
29 | |
---|
30 | // category must be virtual |
---|
31 | if ($category['dir'] != NULL) |
---|
32 | { |
---|
33 | die("physical album"); |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | // | Tabs | |
---|
39 | // +-----------------------------------------------------------------------+ |
---|
40 | |
---|
41 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
42 | $tabsheet = new tabsheet(); |
---|
43 | $tabsheet->set_id('album'); |
---|
44 | $tabsheet->select('smartalbum'); |
---|
45 | $tabsheet->assign(); |
---|
46 | |
---|
47 | |
---|
48 | // +-----------------------------------------------------------------------+ |
---|
49 | // | Save Filters | |
---|
50 | // +-----------------------------------------------------------------------+ |
---|
51 | |
---|
52 | if (isset($_POST['submitFilters'])) |
---|
53 | { |
---|
54 | if (defined('SMART_DEBUG')) |
---|
55 | { |
---|
56 | var_dump($_POST['filters']); |
---|
57 | } |
---|
58 | |
---|
59 | // test if it was a Smart Album |
---|
60 | $query = ' |
---|
61 | SELECT DISTINCT category_id |
---|
62 | FROM '.CATEGORY_FILTERS_TABLE.' |
---|
63 | WHERE category_id = '.$cat_id.' |
---|
64 | ;'; |
---|
65 | $was_smart = pwg_db_num_rows(pwg_query($query)); |
---|
66 | |
---|
67 | /* this album is no longer a SmartAlbum */ |
---|
68 | if ($was_smart and !isset($_POST['is_smart'])) |
---|
69 | { |
---|
70 | pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;'); |
---|
71 | pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';'); |
---|
72 | |
---|
73 | set_random_representant(array($cat_id)); |
---|
74 | |
---|
75 | define('SMART_NOT_UPDATE', 1); |
---|
76 | invalidate_user_cache(); |
---|
77 | } |
---|
78 | /* no filter selected */ |
---|
79 | else if (isset($_POST['is_smart']) and empty($_POST['filters'])) |
---|
80 | { |
---|
81 | $page['errors'][] = l10n('No filter selected'); |
---|
82 | } |
---|
83 | /* everything is fine */ |
---|
84 | else if (isset($_POST['is_smart'])) |
---|
85 | { |
---|
86 | pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';'); |
---|
87 | |
---|
88 | $inserts = array(); |
---|
89 | foreach ($_POST['filters'] as $filter) |
---|
90 | { |
---|
91 | if (($filter = smart_check_filter($filter)) != false) |
---|
92 | { |
---|
93 | $filter['category_id'] = $cat_id; |
---|
94 | $inserts[] = $filter; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | mass_inserts( |
---|
99 | CATEGORY_FILTERS_TABLE, |
---|
100 | array('category_id', 'type', 'cond', 'value'), |
---|
101 | $inserts, |
---|
102 | array('ignore'=>true) |
---|
103 | ); |
---|
104 | |
---|
105 | $associated_images = smart_make_associations($cat_id); |
---|
106 | $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images))); |
---|
107 | |
---|
108 | $page['infos'][] = l10n('%d photos associated to album %s', count($associated_images), ''); |
---|
109 | |
---|
110 | define('SMART_NOT_UPDATE', 1); |
---|
111 | invalidate_user_cache(); |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | // +-----------------------------------------------------------------------+ |
---|
116 | // | Display page | |
---|
117 | // +-----------------------------------------------------------------------+ |
---|
118 | |
---|
119 | /* select options, for html_options */ |
---|
120 | $options = array( |
---|
121 | 'tags' => array( |
---|
122 | 'name' => l10n('Tags'), |
---|
123 | 'options' => array( |
---|
124 | 'all' => l10n('All these tags'), |
---|
125 | 'one' => l10n('One of these tags'), |
---|
126 | 'none' => l10n('None of these tags'), |
---|
127 | 'only' => l10n('Only these tags'), |
---|
128 | ), |
---|
129 | ), |
---|
130 | 'date' => array( |
---|
131 | 'name' => l10n('Date'), |
---|
132 | 'options' => array( |
---|
133 | 'the_post' => l10n('Added on'), |
---|
134 | 'before_post' => l10n('Added before'), |
---|
135 | 'after_post' => l10n('Added after'), |
---|
136 | 'the_taken' => l10n('Created on'), |
---|
137 | 'before_taken' => l10n('Created before'), |
---|
138 | 'after_taken' => l10n('Created after'), |
---|
139 | ), |
---|
140 | ), |
---|
141 | 'name' => array( |
---|
142 | 'name' => l10n('Photo name'), |
---|
143 | 'options' => array( |
---|
144 | 'contain' => l10n('Contains'), |
---|
145 | 'begin' => l10n('Begins with'), |
---|
146 | 'end' => l10n('Ends with'), |
---|
147 | 'not_contain' => l10n('Doesn\'t contain'), |
---|
148 | 'not_begin' => l10n('Doesn\'t begin with'), |
---|
149 | 'not_end' => l10n('Doesn\'t end with'), |
---|
150 | 'regex' => l10n('Regular expression'), |
---|
151 | ), |
---|
152 | ), |
---|
153 | 'album' => array( |
---|
154 | 'name' => l10n('Album'), |
---|
155 | 'options' => array( |
---|
156 | 'all' => l10n('All these albums'), |
---|
157 | 'one' => l10n('One of these albums'), |
---|
158 | 'none' => l10n('None of these albums'), |
---|
159 | 'only' => l10n('Only these albums'), |
---|
160 | ), |
---|
161 | ), |
---|
162 | 'dimensions' => array( |
---|
163 | 'name' => l10n('Dimensions'), |
---|
164 | 'options' => array( |
---|
165 | 'width' => l10n('Width'), |
---|
166 | 'height' => l10n('Height'), |
---|
167 | 'ratio' => l10n('Ratio').' ('.l10n('Width').'/'.l10n('Height').')', |
---|
168 | ), |
---|
169 | ), |
---|
170 | 'author' => array( |
---|
171 | 'name' => l10n('Author'), |
---|
172 | 'options' => array( |
---|
173 | 'is' => l10n('Is'), |
---|
174 | 'in' => l10n('Is in'), |
---|
175 | 'not_is' => l10n('Is not'), |
---|
176 | 'not_in' => l10n('Is not in'), |
---|
177 | 'regex' => l10n('Regular expression'), |
---|
178 | ), |
---|
179 | ), |
---|
180 | 'hit' => array( |
---|
181 | 'name' => l10n('Hits'), |
---|
182 | 'options' => array( |
---|
183 | 'less' => l10n('Bellow'), |
---|
184 | 'more' => l10n('Above'), |
---|
185 | ), |
---|
186 | ), |
---|
187 | 'rating_score' => array( |
---|
188 | 'name' => l10n('Rating score'), |
---|
189 | 'options' => array( |
---|
190 | 'less' => l10n('Bellow'), |
---|
191 | 'more' => l10n('Above'), |
---|
192 | ), |
---|
193 | ), |
---|
194 | 'level' => array( |
---|
195 | 'name' => l10n('Privacy level'), |
---|
196 | 'options' => array(), |
---|
197 | ), |
---|
198 | 'limit' => array( |
---|
199 | 'name' => l10n('Max. number of photos'), |
---|
200 | 'options' => array(), |
---|
201 | ), |
---|
202 | ); |
---|
203 | $template->assign('options', $options); |
---|
204 | |
---|
205 | |
---|
206 | /* get filters for this album */ |
---|
207 | $query = ' |
---|
208 | SELECT * |
---|
209 | FROM '.CATEGORY_FILTERS_TABLE.' |
---|
210 | WHERE category_id = '.$cat_id.' |
---|
211 | ORDER BY |
---|
212 | type ASC, |
---|
213 | cond ASC |
---|
214 | ;'; |
---|
215 | $result = pwg_query($query); |
---|
216 | |
---|
217 | $template->assign('filter_mode', 'and'); |
---|
218 | |
---|
219 | while ($filter = pwg_db_fetch_assoc($result)) |
---|
220 | { |
---|
221 | if ($filter['type'] == 'mode') |
---|
222 | { |
---|
223 | $template->assign('filter_mode', $filter['value']); |
---|
224 | continue; |
---|
225 | } |
---|
226 | else if ($filter['type'] == 'tags') |
---|
227 | { |
---|
228 | $query = ' |
---|
229 | SELECT id, name |
---|
230 | FROM '.TAGS_TABLE.' |
---|
231 | WHERE id IN('.$filter['value'].') |
---|
232 | ;'; |
---|
233 | $filter['value'] = get_taglist($query); |
---|
234 | } |
---|
235 | |
---|
236 | $template->append('filters', $filter); |
---|
237 | } |
---|
238 | |
---|
239 | |
---|
240 | /* format types */ |
---|
241 | $template->assign('format_options', array( |
---|
242 | 'portrait' => l10n('Portrait'), |
---|
243 | 'square' => l10n('square'), |
---|
244 | 'lanscape' => l10n('Landscape'), |
---|
245 | 'panorama' => l10n('Panorama'), |
---|
246 | )); |
---|
247 | |
---|
248 | /* all tags */ |
---|
249 | $query = ' |
---|
250 | SELECT id, name |
---|
251 | FROM '.TAGS_TABLE.' |
---|
252 | ;'; |
---|
253 | $template->assign('all_tags', get_taglist($query)); |
---|
254 | |
---|
255 | /* all albums */ |
---|
256 | $query = ' |
---|
257 | SELECT |
---|
258 | id, |
---|
259 | name, |
---|
260 | uppercats, |
---|
261 | global_rank |
---|
262 | FROM '.CATEGORIES_TABLE.' |
---|
263 | ;'; |
---|
264 | display_select_cat_wrapper($query, array(), 'all_albums'); |
---|
265 | |
---|
266 | // +-----------------------------------------------------------------------+ |
---|
267 | // | dimensions | |
---|
268 | // +-----------------------------------------------------------------------+ |
---|
269 | |
---|
270 | $widths = array(); |
---|
271 | $heights = array(); |
---|
272 | $ratios = array(); |
---|
273 | |
---|
274 | // get all width, height and ratios |
---|
275 | $query = ' |
---|
276 | SELECT |
---|
277 | DISTINCT width, height |
---|
278 | FROM '.IMAGES_TABLE.' |
---|
279 | WHERE width IS NOT NULL |
---|
280 | AND height IS NOT NULL |
---|
281 | ;'; |
---|
282 | $result = pwg_query($query); |
---|
283 | |
---|
284 | while ($row = pwg_db_fetch_assoc($result)) |
---|
285 | { |
---|
286 | if ($row['width']>0 && $row['height']>0) |
---|
287 | { |
---|
288 | $widths[] = $row['width']; |
---|
289 | $heights[] = $row['height']; |
---|
290 | $ratios[] = floor($row['width'] / $row['height'] * 100) / 100; |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | $widths = array_unique($widths); |
---|
295 | sort($widths); |
---|
296 | |
---|
297 | $heights = array_unique($heights); |
---|
298 | sort($heights); |
---|
299 | |
---|
300 | $ratios = array_unique($ratios); |
---|
301 | sort($ratios); |
---|
302 | |
---|
303 | $dimensions['bounds'] = array( |
---|
304 | 'min_width' => $widths[0], |
---|
305 | 'max_width' => $widths[count($widths)-1], |
---|
306 | 'min_height' => $heights[0], |
---|
307 | 'max_height' => $heights[count($heights)-1], |
---|
308 | 'min_ratio' => $ratios[0], |
---|
309 | 'max_ratio' => $ratios[count($ratios)-1], |
---|
310 | ); |
---|
311 | |
---|
312 | // find ratio categories |
---|
313 | $ratio_categories = array( |
---|
314 | 'portrait' => array(), |
---|
315 | 'square' => array(), |
---|
316 | 'landscape' => array(), |
---|
317 | 'panorama' => array(), |
---|
318 | ); |
---|
319 | |
---|
320 | foreach ($ratios as $ratio) |
---|
321 | { |
---|
322 | if ($ratio < 0.95) |
---|
323 | { |
---|
324 | $ratio_categories['portrait'][] = $ratio; |
---|
325 | } |
---|
326 | else if ($ratio >= 0.95 and $ratio <= 1.05) |
---|
327 | { |
---|
328 | $ratio_categories['square'][] = $ratio; |
---|
329 | } |
---|
330 | else if ($ratio > 1.05 and $ratio < 2) |
---|
331 | { |
---|
332 | $ratio_categories['landscape'][] = $ratio; |
---|
333 | } |
---|
334 | else if ($ratio >= 2) |
---|
335 | { |
---|
336 | $ratio_categories['panorama'][] = $ratio; |
---|
337 | } |
---|
338 | } |
---|
339 | |
---|
340 | foreach ($ratio_categories as $ratio_name => $ratio_values) |
---|
341 | { |
---|
342 | if (count($ratio_values) > 0) |
---|
343 | { |
---|
344 | $dimensions['ratio_'.$ratio_name] = array( |
---|
345 | 'min' => $ratio_values[0], |
---|
346 | 'max' => array_pop($ratio_values), |
---|
347 | ); |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | $template->assign('dimensions', $dimensions); |
---|
352 | |
---|
353 | /* get image number */ |
---|
354 | if ($template->get_template_vars('IMAGE_COUNT') == null) |
---|
355 | { |
---|
356 | $query = ' |
---|
357 | SELECT count(1) |
---|
358 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
359 | WHERE |
---|
360 | category_id = '.$cat_id.' |
---|
361 | AND smart = true |
---|
362 | '; |
---|
363 | |
---|
364 | list($image_num) = pwg_db_fetch_row(pwg_query($query)); |
---|
365 | $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num)); |
---|
366 | } |
---|
367 | |
---|
368 | |
---|
369 | /* template vars */ |
---|
370 | if (isset($_GET['new_smart'])) |
---|
371 | { |
---|
372 | $template->assign('new_smart', true); |
---|
373 | } |
---|
374 | |
---|
375 | $template->assign(array( |
---|
376 | 'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php', |
---|
377 | 'level_options' => get_privacy_level_options(), |
---|
378 | 'F_ACTION' => $self_url, |
---|
379 | 'CATEGORIES_NAV' => get_cat_display_name_cache($category['uppercats'], SMART_ADMIN.'-album&cat_id='), |
---|
380 | )); |
---|
381 | |
---|
382 | $template->set_filename('SmartAlbums_content', realpath(SMART_PATH . 'admin/template/album.tpl')); |
---|