source: extensions/SmartAlbums/admin/album.php @ 19722

Last change on this file since 19722 was 19722, checked in by mistic100, 11 years ago

undefined function get_tag_ids(), css tweaks

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