Changeset 10980
- Timestamp:
- May 21, 2011, 6:16:47 PM (13 years ago)
- Location:
- extensions/SmartAlbums
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/SmartAlbums/include/count_images.php
r10871 r10980 1 1 <?php 2 /** 3 * Count images for AJAX info 4 */ 5 2 6 define('PHPWG_ROOT_PATH','./../../../'); 3 7 define('IN_ADMIN', true); 4 8 include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); 9 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); 5 10 include_once(SMART_PATH.'include/functions.inc.php'); 6 11 7 $error = false; 12 $filters = array(); 13 $limit_is_set = false; 8 14 foreach ($_POST['filters'] as $filter) 9 15 { 10 if ( $filter['type'] == 'tags')16 if (($filter = smart_check_filter($filter)) != false) 11 17 { 12 $filter['value'] = str_replace(' ', null, $filter['value']); 13 } 14 else if ($filter['type'] == 'date') 15 { 16 if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value'])) 17 { 18 $error = true; 19 } 20 } 21 else if ($filter['type'] == 'limit') 22 { 23 if (!preg_match('#([0-9]{1,})#', $filter['value'])) 24 { 25 $error = true; 26 } 27 else if (isset($limit_is_set)) 28 { 29 $error = true; 30 } 31 else 32 { 33 $limit_is_set = true; 34 } 18 array_push($filters, $filter); 35 19 } 36 20 } 37 21 38 if ($error == false) 39 { 40 $associated_images = SmartAlbums_get_pictures($_POST['cat_id'], $_POST['filters']); 41 echo l10n_dec('%d photo', '%d photos', count($associated_images)); 42 } 43 else 44 { 45 echo 'error'; 46 } 22 $associated_images = smart_get_pictures($_POST['cat_id'], $filters); 23 echo l10n_dec('%d photo', '%d photos', count($associated_images)); 24 47 25 ?> -
extensions/SmartAlbums/include/functions.inc.php
r10871 r10980 7 7 * @return array 8 8 */ 9 function SmartAlbums_make_associations($cat_id)9 function smart_make_associations($cat_id) 10 10 { 11 11 pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;"); 12 12 13 $images = SmartAlbums_get_pictures($cat_id); 14 $dbfields = array('image_id', 'category_id', 'smart'); 13 $images = smart_get_pictures($cat_id); 15 14 16 15 if (count($images) != 0) … … 24 23 ); 25 24 } 26 mass_inserts_ignore(IMAGE_CATEGORY_TABLE, $dbfields, $datas); 25 mass_inserts_ignore( 26 IMAGE_CATEGORY_TABLE, 27 array_keys($datas[0]), 28 $datas 29 ); 30 set_random_representant(array($cat_id)); 27 31 } 28 32 … … 37 41 * @return array 38 42 */ 39 function SmartAlbums_get_pictures($cat_id, $filters = null)43 function smart_get_pictures($cat_id, $filters = null) 40 44 { 41 45 global $conf; … … 165 169 166 170 /** 171 * Check if the filter is proper 172 * 173 * @param array filter 174 * @return array or false 175 */ 176 function smart_check_filter($filter) 177 { 178 global $limit_is_set, $page; 179 $error = false; 180 181 # tags 182 if ($filter['type'] == 'tags') 183 { 184 if ($filter['value'] == null) // tags fields musn't be null 185 { 186 $error = true; 187 array_push($page['errors'], l10n('No tag selected')); 188 } 189 else 190 { 191 $filter['value'] = implode(',', get_fckb_tag_ids($filter['value'])); 192 } 193 } 194 # date 195 else if ($filter['type'] == 'date') 196 { 197 if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value'])) // dates must be proper 198 { 199 $error = true; 200 array_push($page['errors'], l10n('Date string is malformed')); 201 } 202 } 203 # limit 204 else if ($filter['type'] == 'limit') 205 { 206 if (!preg_match('#([0-9]{1,})#', $filter['value'])) // limit must be an integer 207 { 208 $error = true; 209 array_push($page['errors'], l10n('Limit must be an integer')); 210 } 211 else if ($limit_is_set == true) // only one limit is allowed, first is saved 212 { 213 $error = true; 214 array_push($page['errors'], l10n('You can\'t use more than one limit')); 215 } 216 else 217 { 218 $limit_is_set = true; 219 } 220 } 221 222 # out 223 if ($error == false) 224 { 225 return $filter; 226 } 227 else 228 { 229 return false; 230 } 231 } 232 233 234 /** 167 235 * inserts multiple lines in a table, ignore duplicate entries 168 236 * -
extensions/SmartAlbums/init_cat_modify.php
r10871 r10980 1 1 <?php 2 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 3 /** 4 * Add the SmartAlbums configuration tool to virtual cats' configuration page 5 */ 6 4 7 function smart_cat_modify() 5 8 { 6 9 global $template; 7 10 include_once(SMART_PATH.'include/functions.inc.php'); 11 8 12 $cat_id = $_GET['cat_id']; 13 list($cat_dir) = pwg_db_fetch_row(pwg_query("SELECT dir FROM ".CATEGORIES_TABLE." WHERE id = ".$cat_id.";")); 9 14 15 // category must be virtual 16 if ($cat_dir != NULL) 17 { 18 return; 19 } 20 21 /* SAVE FILTERS */ 10 22 if (isset($_POST['submitFilters'])) 11 23 { 12 24 // test if it was a Smart Album 13 25 $result = pwg_query("SELECT DISTINCT category_id FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";"); 14 $ _was_smart = pwg_db_num_rows($result);26 $was_smart = pwg_db_num_rows($result); 15 27 16 28 /* this album is no longer a SmartAlbum */ 17 if ($ _was_smart AND !isset($_POST['is_smart']))29 if ($was_smart AND !isset($_POST['is_smart'])) 18 30 { 19 31 pwg_query("DELETE FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;"); … … 29 41 { 30 42 pwg_query("DELETE FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";"); 31 43 44 $limit_is_set = false; 32 45 foreach ($_POST['filters'] as $filter) 33 46 { 34 $error = false; 35 if ($filter['type'] == 'tags') 36 { 37 $filter['value'] = str_replace(' ', null, $filter['value']); 38 } 39 else if ($filter['type'] == 'date') 40 { 41 if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value'])) 42 { 43 $error = true; 44 array_push($page['errors'], l10n('Date string is malformed')); 45 } 46 } 47 else if ($filter['type'] == 'limit') 48 { 49 if (!preg_match('#([0-9]{1,})#', $filter['value'])) 50 { 51 $error = true; 52 array_push($page['errors'], l10n('Limit must be an integer')); 53 } 54 else if (isset($limit_is_set)) 55 { 56 $error = true; 57 array_push($page['errors'], l10n('You can\'t use more than one limit')); 58 } 59 else 60 { 61 $limit_is_set = true; 62 } 63 } 64 65 if ($error == false) 47 if (($filter = smart_check_filter($filter)) != false) 66 48 { 67 49 pwg_query("INSERT INTO ".CATEGORY_FILTERS_TABLE." … … 70 52 } 71 53 72 $associated_images = SmartAlbums_make_associations($cat_id); 54 $associated_images = smart_make_associations($cat_id); 55 invalidate_user_cache(true); 73 56 $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images))); 74 75 set_random_representant(array($cat_id));76 invalidate_user_cache(true);77 57 } 78 58 } 79 59 80 /* select options */60 /* select options, for html_options */ 81 61 $template->assign('options', array( 82 62 'tags' => array( … … 91 71 'after' => l10n('Added after the'), 92 72 ), 93 'limit' => array('limit' => 'limit'), 73 'limit' => array('limit' => 'limit'), // second filter not used 94 74 )); 95 75 … … 98 78 while ($filter = pwg_db_fetch_assoc($filters)) 99 79 { 80 // get tags name and id 81 if ($filter['type'] == 'tags') 82 { 83 $query = " 84 SELECT 85 id AS tag_id, 86 name AS tag_name 87 FROM ".TAGS_TABLE." 88 WHERE id IN(".$filter['value'].") 89 "; 90 $filter['value'] = get_fckb_taglist($query); 91 } 92 100 93 $template->append('filters', array( 101 94 'TYPE' => $filter['type'], -
extensions/SmartAlbums/main.inc.php
r10871 r10980 3 3 Plugin Name: SmartAlbums 4 4 Version: auto 5 Description: Eas y create dynamic albums with tags, date and other criteria6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid= 5 Description: Easily create dynamic albums with tags, date and other criteria 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=544 7 7 Author: Mistic 8 8 Author URI: http://www.strangeplanet.fr … … 18 18 if (script_basename() == 'admin') 19 19 { 20 include_once(SMART_PATH.'init_cat_modify.php'); 20 add_event_handler('loc_begin_cat_modify', 'smart_init_cat_modify'); 21 function smart_init_cat_modify() 22 { 23 include_once(SMART_PATH.'init_cat_modify.php'); 24 smart_cat_modify(); 25 } 21 26 22 add_event_handler('loc_begin_cat_modify', 'smart_cat_modify'); 27 add_event_handler('loc_begin_cat_list', 'smart_init_cat_list'); 28 function smart_init_cat_list() 29 { 30 include_once(SMART_PATH.'init_cat_list.php'); 31 smart_cat_list(); 32 } 23 33 } 24 34 -
extensions/SmartAlbums/template/cat_modify.tpl
r10871 r10980 1 1 {combine_css path=$SMART_PATH|@cat:"template/style.css"} 2 2 {include file='include/datepicker.inc.tpl'} 3 {combine_script id='jquery. fcbkcomplete' load='async' require='jquery' path='themes/default/js/plugins/jquery.fcbkcomplete.js'}3 {combine_script id='jquery.tokeninput' load='async' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'} 4 4 5 {footer_script require='jquery ,jquery.fcbkcomplete'}5 {footer_script require='jquery.tokeninput'} 6 6 var lang = new Array(); 7 7 lang['tags filter'] = "{'tags filter'|@translate}"; … … 34 34 $('input[name="is_smart"]').change(function() { 35 35 $('#SmartAlbum_options').toggle(); 36 $('input[name="count _images"]').toggle();36 $('input[name="countImages"]').toggle(); 37 37 }); 38 38 39 $('input[name="count _images"]').click(function() {40 count _images($(this).closest('form'));39 $('input[name="countImages"]').click(function() { 40 countImages($(this).closest('form')); 41 41 return false; 42 42 }); 43 43 44 44 function add_filter(type) { 45 // add line 45 46 $('<li class="filter_'+ type +'" id="filter_'+ i +'"></li>').appendTo('#filterList'); 46 47 47 $('#filter_'+ i).html( 48 '<a href="#" class="removeFilter" title="'+ lang['remove this filter'] +'"><span>[x]</span></a>'+ 49 '<input type="hidden" name="filters['+ i +'][type]" value="'+ type +'"/>'+ 50 ' '+ lang[type +' filter'] + 51 52 ' <select name="filters['+ i +'][cond]">'+ options[type] +'</select>'+ 53 ' <input type="text" name="filters['+ i +'][value]"/>' 54 ); 48 //set content 49 content = '<a href="#" class="removeFilter" title="'+ lang['remove this filter'] +'"><span>[x]</span></a>'+ 50 '<input type="hidden" name="filters['+ i +'][type]" value="'+ type +'"/> '+ lang[type +' filter'] + 51 ' <select name="filters['+ i +'][cond]">'+ options[type] +'</select>'; 55 52 56 // reinit handler 53 if (type == 'tags') { 54 content += ' <select name="filters['+ i +'][value]" class="tagSelect"></select>'; 55 } else { 56 content += ' <input type="text" name="filters['+ i +'][value]"/>'; 57 } 58 59 $('#filter_'+ i).html(content); 60 61 // reinit handlers 57 62 init_jquery_handlers(); 58 63 i++; … … 69 74 }); 70 75 71 $('.filter_tags input[type="text"]').each(function() {72 if ($(this).hasClass('fcbk_initialized') == false) {73 $(this).fcbkcomplete({74 json_url: "admin.php?fckb_tags=1",75 cache: false,76 filter_case: false,77 filter_hide: true,78 firstselected: true,79 filter_selected: true,80 maxitems: 100,81 newel: false82 });83 $(this).addClass('fcbk_initialized');84 }76 jQuery.getJSON('admin.php?fckb_tags=1', function(data) { 77 jQuery(".tagSelect").tokenInput( 78 data, 79 { 80 {/literal} 81 hintText: '{'Type in a search term'|@translate}', 82 noResultsText: '{'No results'|@translate}', 83 searchingText: '{'Searching...'|@translate}', 84 animateDropdown: false, 85 preventDuplicates: true, 86 allowCreation: true 87 {literal} 88 } 89 ); 85 90 }); 86 91 } 87 92 88 function count _images(form) {93 function countImages(form) { 89 94 {/literal} 90 95 jQuery.post("{$COUNT_SCRIPT_URL}", 'cat_id={$CAT_ID}&'+form.serialize(), … … 122 127 </select> 123 128 129 {if $filter.TYPE == 'tags'} 130 <select name="filters[{$i}][value]" class="tagSelect"> 131 {foreach from=$filter.VALUE item=tag} 132 <option value="{$tag.id}" class="selected">{$tag.name}</option> 133 {/foreach} 134 </select> 135 {else} 124 136 <input type="text" name="filters[{$i}][value]" value="{$filter.VALUE}"/> 137 {/if} 125 138 </li> 126 139 {counter} … … 144 157 <p class="actionButtons" id="applyFilterBlock"> 145 158 <input class="submit" type="submit" value="{'Submit'|@translate}" name="submitFilters"/> 146 <input class="submit" type="submit" value="{'Count'|@translate}" name="count _images" {if !isset($filters)}style="display:none;"{/if}/>159 <input class="submit" type="submit" value="{'Count'|@translate}" name="countImages" {if !isset($filters)}style="display:none;"{/if}/> 147 160 <span class="count_images_display">{$IMAGE_COUNT}</span> 148 161 </p> -
extensions/SmartAlbums/template/style.css
r10871 r10980 2 2 display:none; 3 3 } 4 .token-input-list { 5 display:inline-block; 6 vertical-align:bottom; 7 } 8 #batchManagerGlobal #filterList li.token-input-token { 9 margin-bottom:3px !important 10 } 11 #batchManagerGlobal #filterList li.token-input-input-token { 12 margin-bottom:0px !important; 13 }
Note: See TracChangeset
for help on using the changeset viewer.