Changeset 16104 for extensions/SmartAlbums/include
- Timestamp:
- Jun 27, 2012, 9:19:07 PM (12 years ago)
- Location:
- extensions/SmartAlbums/include
- Files:
-
- 1 deleted
- 3 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
extensions/SmartAlbums/include/cat_list.php
r12863 r16104 42 42 { 43 43 $associated_images = smart_make_associations($category['id']); 44 array_push( 45 $page['infos'], 46 sprintf( 47 l10n('%d photos associated to album %s'), 44 array_push($page['infos'], 45 sprintf(l10n('%d photos associated to album %s'), 48 46 count($associated_images), 49 '«'.trigger_event( 50 'render_category_name', 51 $category['name'], 52 'admin_cat_list' 53 ).'»' 47 '«'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'»' 54 48 ) 55 49 ); … … 60 54 { 61 55 $associated_images = smart_make_associations($_GET['smart_generate']); 62 array_push( 63 $page['infos'], 64 sprintf( 65 l10n('%d photos associated to album %s'), 56 array_push($page['infos'], 57 sprintf(l10n('%d photos associated to album %s'), 66 58 count($associated_images), 67 '«'.trigger_event( 68 'render_category_name', 69 $smart_cats[$_GET['smart_generate']]['name'], 70 'admin_cat_list' 71 ).'»' 59 '«'.trigger_event('render_category_name', $smart_cats[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'»' 72 60 ) 73 61 ); … … 99 87 global $smart_count; 100 88 101 $search[0] = '{if isset($category.U_ SYNC) }';102 $replacement[0] = '89 $search[0] = '{if isset($category.U_MANAGE_ELEMENTS) }'; 90 $replacement[0] = $search[0].' 103 91 {if isset($SMART_URL[$category.ID])} 104 <li><a href="{$SMART_URL[$category.ID]}" title="{\'Regenerate photos list of this SmartAlbum\'|@translate}"><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/synchronize.png" class="button" alt="{\'Regenerate photos list of this SmartAlbum\'|@translate}"></a></li> 105 {/if}' 106 .$search[0]; 92 | <a href="{$SMART_URL[$category.ID]}">{\'Regenerate photos list of this SmartAlbum\'|@translate}</a> 93 {/if}'; 107 94 108 95 if ($smart_count > 0) 109 96 { 110 $search[1] = '</ul> 111 </form>'; 97 $search[1] = '<a href="#" id="autoOrderOpen">{\'apply automatic sort order\'|@translate}</a>'; 112 98 $replacement[1] = $search[1].' 113 <form method="post" action="{$SMART_URL.all}"> 114 <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}"> 115 <p><input class="submit" type="submit" value="{\'Regenerate photos list of all SmartAlbums\'|@translate}"></p> 116 </form>'; 99 | <a href="{$SMART_URL.all}">{\'Regenerate photos list of all SmartAlbums\'|@translate}</a>'; 117 100 } 101 102 $search[2] = '{$category.NAME}</a></strong>'; 103 $replacement[2] = $search[2].' 104 {if isset($SMART_URL[$category.ID])} 105 <img src="'.SMART_PATH.'admin/template/lightning.png"> 106 {/if}'; 118 107 119 108 return str_replace($search, $replacement, $content); -
extensions/SmartAlbums/include/count_images.php
r11334 r16104 6 6 define('PHPWG_ROOT_PATH','./../../../'); 7 7 define('IN_ADMIN', true); 8 8 9 include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); 10 11 if (!is_admin()) die('Hacking attempt!'); 12 9 13 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 10 14 include_once(SMART_PATH.'include/functions.inc.php'); 15 16 load_language('plugin.lang', SMART_PATH); 17 $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']); 11 18 12 19 if (isset($_POST['filters'])) … … 22 29 array_push($filters, $filter); 23 30 } 31 else 32 { 33 echo '<span class="filter_error">'.$page['errors'][ count($page['errors'])-1 ].'</span>'; 34 exit; 35 } 24 36 } 25 37 … … 31 43 } 32 44 33 echo l10n_dec('%d photo', '%d photos', count($associated_images));45 echo '<span class="count_image">'.l10n_dec('%d photo', '%d photos', count($associated_images)).'</span>'; 34 46 35 47 ?> -
extensions/SmartAlbums/include/functions.inc.php
r12864 r16104 36 36 } 37 37 38 // repres antant, try to not overwrite if still in images list38 // representant, try to not overwrite if still in images list 39 39 $query = ' 40 40 SELECT representative_picture_id … … 46 46 if ( !in_array($rep_id, $images) ) 47 47 { 48 if (!function_exists('set_random_representant')) 49 { 50 include(PHPWG_ROOT_PATH.'admin/include/functions.php'); 51 } 48 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 52 49 set_random_representant(array($cat_id)); 53 50 } … … 64 61 { 65 62 global $conf; 66 67 if (!is_array($conf['SmartAlbums'])) $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);68 63 69 64 if ( defined('SMART_NOT_UPDATE') OR !$conf['SmartAlbums']['update_on_upload'] ) return; … … 94 89 95 90 /* get filters */ 96 if ($filters == null) 97 { 98 $filters = array(); 99 91 if ($filters === null) 92 { 100 93 $query = ' 101 94 SELECT * … … 106 99 $result = pwg_query($query); 107 100 108 if (!pwg_db_num_rows($result)) return $filters;101 if (!pwg_db_num_rows($result)) return array(); 109 102 103 $filters = array(); 110 104 while ($row = pwg_db_fetch_assoc($result)) 111 105 { … … 117 111 } 118 112 } 113 else if (!count($filters)) 114 { 115 return array(); 116 } 119 117 120 118 /* build constrains */ 121 119 ## generate 'join', 'where' arrays and 'limit' string to create the SQL query 122 ## inspired by PicsEngine by Michael Villar120 ## inspired by PicsEngine 3 by Michael Villar 123 121 $i_tags = 1; 124 122 foreach ($filters as $filter) 125 123 { 126 // tags 127 if ($filter['type'] == 'tags') 128 { 129 if($filter['cond'] == "all") 130 { 131 $tags_arr = explode(',', $filter['value']); 124 switch ($filter['type']) 125 { 126 // tags 127 case 'tags': 128 { 129 switch ($filter['cond']) 130 { 131 // search images which have all tags 132 case 'all': 133 { 134 $tags_arr = explode(',', $filter['value']); 135 foreach($tags_arr as $value) 136 { 137 $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id'; 138 $where[] = 'it'.$i_tags.'.tag_id = '.$value; 139 $i_tags++; 140 } 141 142 break; 143 } 144 // search images which tags are in the list 145 case 'one': 146 { 147 $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id'; 148 $where[] = 'it'.$i_tags.'.tag_id IN ('.$filter['value'].')'; 149 $i_tags++; 150 151 break; 152 } 153 // exclude images which tags are in the list 154 case 'none': 155 { 156 $sub_query = ' 157 SELECT it'.$i_tags.'.image_id 158 FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.' 159 WHERE 160 it'.$i_tags.'.image_id = i.id AND 161 it'.$i_tags.'.tag_id IN ('.$filter['value'].') 162 GROUP BY it'.$i_tags.'.image_id 163 '; 164 $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id'; 165 $where[] = 'NOT EXISTS ('.$sub_query.')'; 166 $i_tags++; 167 168 break; 169 } 170 // exclude images which tags are not in the list and search images which have all tags 171 case 'only': 172 { 173 $sub_query = ' 174 SELECT it'.$i_tags.'.image_id 175 FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.' 176 WHERE 177 it'.$i_tags.'.image_id = i.id AND 178 it'.$i_tags.'.tag_id NOT IN ('.$filter['value'].') 179 GROUP BY it'.$i_tags.'.image_id 180 '; 181 $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id'; 182 $where[] = 'NOT EXISTS ('.$sub_query.')'; 183 $i_tags++; 184 185 $tags_arr = explode(',', $filter['value']); 186 foreach($tags_arr as $value) 187 { 188 $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id'; 189 $where[] = 'it'.$i_tags.'.tag_id = '.$value; 190 $i_tags++; 191 } 192 193 break; 194 } 195 } 132 196 133 foreach($tags_arr as $value) 134 { 135 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 136 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 137 $i_tags++; 138 } 139 } 140 else if ($filter['cond'] == 'one') 141 { 142 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 143 $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')'; 144 $i_tags++; 145 } 146 else if ($filter['cond'] == 'none') 147 { 148 $sub_query = ' 149 SELECT it_'.$i_tags.'.image_id 150 FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.' 151 WHERE 152 it_'.$i_tags.'.image_id = i.id AND 153 it_'.$i_tags.'.tag_id IN ('.$filter['value'].') 154 GROUP BY it_'.$i_tags.'.image_id 155 '; 156 $where[] = 'NOT EXISTS ('.$sub_query.')'; 157 $i_tags++; 158 } 159 else if ($filter['cond'] == 'only') 160 { 161 $sub_query = ' 162 SELECT it_'.$i_tags.'.image_id 163 FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.' 164 WHERE 165 it_'.$i_tags.'.image_id = i.id AND 166 it_'.$i_tags.'.tag_id NOT IN ('.$filter['value'].') 167 GROUP BY it_'.$i_tags.'.image_id 168 '; 169 $where[] = 'NOT EXISTS ('.$sub_query.')'; 197 break; 198 } 199 200 // date 201 case 'date': 202 { 203 switch ($filter['cond']) 204 { 205 case 'the_post': 206 $where[] = 'date_available BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"'; 207 break; 208 case 'before_post': 209 $where[] = 'date_available < "'.$filter['value'].' 00:00:00"'; 210 break; 211 case 'after_post': 212 $where[] = 'date_available > "'.$filter['value'].' 23:59:59"'; 213 break; 214 case 'the_taken': 215 $where[] = 'date_creation BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"'; 216 break; 217 case 'before_taken': 218 $where[] = 'date_creation < "'.$filter['value'].' 00:00:00"'; 219 break; 220 case 'after_taken': 221 $where[] = 'date_creation > "'.$filter['value'].' 23:59:59"'; 222 break; 223 } 224 225 break; 226 } 170 227 171 $i_tags++; 172 $tags_arr = explode(',', $filter['value']); 228 // name 229 case 'name': 230 { 231 switch ($filter['cond']) 232 { 233 case 'contain': 234 $where[] = 'name LIKE "%'.$filter['value'].'%"'; 235 break; 236 case 'begin': 237 $where[] = 'name LIKE "'.$filter['value'].'%"'; 238 break; 239 case 'end': 240 $where[] = 'name LIKE "%'.$filter['value'].'"'; 241 break; 242 case 'not_contain': 243 $where[] = 'name NOT LIKE "%'.$filter['value'].'%"'; 244 break; 245 case 'not_begin': 246 $where[] = 'name NOT LIKE "'.$filter['value'].'%"'; 247 break; 248 case 'not_end': 249 $where[] = 'name NOT LIKE "%'.$filter['value'].'"'; 250 break; 251 } 173 252 174 foreach($tags_arr as $value) 175 { 176 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 177 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 178 $i_tags++; 179 } 180 } 181 } 182 // date 183 else if ($filter['type'] == 'date') 184 { 185 switch ($filter['cond']) 186 { 187 case 'the': 188 $where[] = 'date_available BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"'; 189 break; 190 case 'before': 191 $where[] = 'date_available < "'.$filter['value'].' 00:00:00"'; 192 break; 193 case 'after': 194 $where[] = 'date_available > "'.$filter['value'].' 23:59:59"'; 195 break; 196 case 'the_crea': 197 $where[] = 'date_creation BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"'; 198 break; 199 case 'before_crea': 200 $where[] = 'date_creation < "'.$filter['value'].' 00:00:00"'; 201 break; 202 case 'after_crea': 203 $where[] = 'date_creation > "'.$filter['value'].' 23:59:59"'; 204 break; 205 } 206 } 207 // limit 208 else if ($filter['type'] == 'limit') 209 { 210 $limit = '0, '.$filter['value']; 253 break; 254 } 255 256 // author 257 case 'author': 258 { 259 switch ($filter['cond']) 260 { 261 case 'is': 262 if ($filter['value'] != 'NULL') $filter['value'] = '"'.$filter['value'].'"'; 263 $where[] = 'author = '.$filter['value'].''; 264 break; 265 case 'not_is': 266 if ($filter['value'] != 'NULL') $filter['value'] = '"'.$filter['value'].'"'; 267 $where[] = 'author != '.$filter['value'].''; 268 break; 269 case 'in': 270 $filter['value'] = '"'.str_replace(',', '","', $filter['value']).'"'; 271 $where[] = 'author IN('.$filter['value'].')'; 272 break; 273 case 'not_in': 274 $filter['value'] = '"'.str_replace(',', '","', $filter['value']).'"'; 275 $where[] = 'author NOT IN('.$filter['value'].')'; 276 break; 277 } 278 279 break; 280 } 281 282 // hit 283 case 'hit': 284 { 285 switch ($filter['cond']) 286 { 287 case 'less': 288 $where[] = 'hit < '.$filter['value'].''; 289 break; 290 case 'more': 291 $where[] = 'hit >= '.$filter['value'].''; 292 break; 293 } 294 295 break; 296 } 297 298 // level 299 case 'level': 300 { 301 $where[] = 'level = '.$filter['value'].''; 302 break; 303 } 304 305 // limit 306 case 'limit': 307 { 308 $limit = '0, '.$filter['value']; 309 break; 310 } 211 311 } 212 312 } … … 219 319 if (isset($join)) 220 320 { 221 foreach ($join as $query) 222 { 223 $MainQuery .= ' 224 LEFT JOIN '.$query; 225 } 321 $MainQuery.= ' 322 LEFT JOIN '.implode("\n LEFT JOIN ", $join); 226 323 } 227 324 if (isset($where)) 228 325 { 229 $MainQuery .= ' 230 WHERE'; 231 $i = 0; 232 foreach ($where as $query) 233 { 234 if ($i != 0) $MainQuery .= ' AND'; 235 $MainQuery .= ' 236 '.$query; 237 $i++; 238 } 239 } 240 241 $MainQuery .= ' 326 $MainQuery.= ' 327 WHERE 328 '.implode("\n AND ", $where); 329 } 330 331 $MainQuery.= ' 242 332 GROUP BY i.id 243 '.$conf['order_by'].'333 '.$conf['order_by'].' 244 334 '.(isset($limit) ? "LIMIT ".$limit : null).' 245 335 ;'; 246 336 337 // file_put_contents(SMART_PATH.'query.sql', $MainQuery); 247 338 return array_from_query($MainQuery, 'id'); 248 339 } … … 256 347 function smart_check_filter($filter) 257 348 { 258 global $ limit_is_set, $page;349 global $page, $limit_is_set, $level_is_set; 259 350 $error = false; 351 352 if (!isset($limit_is_set)) $limit_is_set = false; 353 if (!isset($level_is_set)) $level_is_set = false; 260 354 261 355 # tags … … 281 375 } 282 376 } 377 # name 378 else if ($filter['type'] == 'name') 379 { 380 if (empty($filter['value'])) 381 { 382 $error = true; 383 array_push($page['errors'], l10n('Name is empty')); 384 } 385 } 386 # author 387 else if ($filter['type'] == 'author') 388 { 389 if (empty($filter['value'])) 390 { 391 $error = true; 392 array_push($page['errors'], l10n('Author is empty')); 393 } 394 else 395 { 396 $filter['value'] = preg_replace('#([ ]?),([ ]?)#', ',', $filter['value']); 397 } 398 } 399 # hit 400 else if ($filter['type'] == 'hit') 401 { 402 if (!preg_match('#([0-9]{1,})#', $filter['value'])) 403 { 404 $error = true; 405 array_push($page['errors'], l10n('Hits must be an integer')); 406 } 407 } 408 # level 409 else if ($filter['type'] == 'level') 410 { 411 if ($level_is_set == true) // only one level is allowed, first is saved 412 { 413 $error = true; 414 array_push($page['errors'], l10n('You can\'t use more than one level filter')); 415 } 416 else 417 { 418 $level_is_set = true; 419 } 420 } 283 421 # limit 284 422 else if ($filter['type'] == 'limit') … … 292 430 { 293 431 $error = true; 294 array_push($page['errors'], l10n('You can\'t use more than one limit '));432 array_push($page['errors'], l10n('You can\'t use more than one limit filter')); 295 433 } 296 434 else … … 374 512 } 375 513 } 514 376 515 ?> -
extensions/SmartAlbums/include/index.php
r11380 r16104 1 1 <?php 2 // +-----------------------------------------------------------------------+3 // | Piwigo - a PHP based photo gallery |4 // +-----------------------------------------------------------------------+5 // | Copyright(C) 2008-2011 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 // Recursive call25 2 $url = '../'; 26 3 header( 'Request-URI: '.$url ); -
extensions/SmartAlbums/include/page_items.php
r12863 r16104 3 3 4 4 /** 5 * Remove form $page['items'] picture that musn't be displayed5 * Remove picture that musn't be displayed from $page['items'] 6 6 * 7 7 * here we get all pictures that current user could see
Note: See TracChangeset
for help on using the changeset viewer.