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