Changeset 10980 for extensions/SmartAlbums/include
- Timestamp:
- May 21, 2011, 6:16:47 PM (14 years ago)
- Location:
- extensions/SmartAlbums/include
- Files:
-
- 2 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 *
Note: See TracChangeset
for help on using the changeset viewer.