Changeset 11333 for extensions/SmartAlbums
- Timestamp:
- Jun 12, 2011, 5:56:09 PM (13 years ago)
- Location:
- extensions/SmartAlbums
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/SmartAlbums/include/functions.inc.php
r10980 r11333 9 9 function smart_make_associations($cat_id) 10 10 { 11 pwg_query( "DELETE FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;");11 pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;'); 12 12 13 13 $images = smart_get_pictures($cat_id); … … 21 21 'category_id' => $cat_id, 22 22 'smart' => true, 23 );23 ); 24 24 } 25 25 mass_inserts_ignore( … … 27 27 array_keys($datas[0]), 28 28 $datas 29 );29 ); 30 30 set_random_representant(array($cat_id)); 31 31 } … … 48 48 if ($filters == null) 49 49 { 50 $filters = pwg_query("SELECT * FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id." ORDER BY type ASC, cond ASC;"); 50 $query = ' 51 SELECT * 52 FROM '.CATEGORY_FILTERS_TABLE.' 53 WHERE category_id = '.$cat_id.' 54 ORDER BY type ASC, cond ASC 55 ;'; 56 $filters = pwg_query($query); 57 51 58 if (!pwg_db_num_rows($filters)) return array(); 52 59 … … 57 64 'cond' => $filter['cond'], 58 65 'value' => $filter['value'], 59 );66 ); 60 67 } 61 68 … … 78 85 foreach($tags_arr as $value) 79 86 { 80 $join[] = "".IMAGE_TAG_TABLE." AS it_$i_tags ON i.id = it_$i_tags.image_id";81 $where[] = "it_$i_tags.tag_id = ".$value."";87 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 88 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 82 89 $i_tags++; 83 90 } … … 85 92 else if ($filter['cond'] == 'one') 86 93 { 87 $join[] = "".IMAGE_TAG_TABLE." AS it_$i_tags ON i.id = it_$i_tags.image_id";88 $where[] = "it_$i_tags.tag_id IN (".$filter['value'].")";94 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 95 $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')'; 89 96 $i_tags++; 90 97 } 91 98 else if ($filter['cond'] == 'none') 92 99 { 93 $sub_query = "SELECT it_$i_tags.image_id 94 FROM ".IMAGE_TAG_TABLE." AS it_$i_tags 95 WHERE it_$i_tags.image_id = i.id 96 AND it_$i_tags.tag_id IN (".$filter['value'].") 97 GROUP BY it_$i_tags.image_id"; 98 $where[] = "NOT EXISTS (".$sub_query.")"; 100 $sub_query = ' 101 SELECT it_'.$i_tags.'.image_id 102 FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.' 103 WHERE 104 it_'.$i_tags.'.image_id = i.id AND 105 it_'.$i_tags.'.tag_id IN ('.$filter['value'].') 106 GROUP BY it_'.$i_tags.'.image_id 107 '; 108 $where[] = 'NOT EXISTS ('.$sub_query.')'; 99 109 $i_tags++; 100 110 } 101 111 else if ($filter['cond'] == 'only') 102 112 { 103 $sub_query = "SELECT it_$i_tags.image_id 104 FROM ".IMAGE_TAG_TABLE." AS it_$i_tags 105 WHERE it_$i_tags.image_id = i.id 106 AND it_$i_tags.tag_id NOT IN (".$filter['value'].") 107 GROUP BY it_$i_tags.image_id"; 108 $where[] = "NOT EXISTS (".$sub_query.")"; 113 $sub_query = ' 114 SELECT it_'.$i_tags.'.image_id 115 FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.' 116 WHERE 117 it_'.$i_tags.'.image_id = i.id AND 118 it_'.$i_tags.'.tag_id NOT IN ('.$filter['value'].') 119 GROUP BY it_'.$i_tags.'.image_id 120 '; 121 $where[] = 'NOT EXISTS ('.$sub_query.')'; 109 122 110 123 $i_tags++; … … 113 126 foreach($tags_arr as $value) 114 127 { 115 $join[] = "".IMAGE_TAG_TABLE." AS it_$i_tags ON i.id = it_$i_tags.image_id";116 $where[] = "it_$i_tags.tag_id = ".$value."";128 $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id'; 129 $where[] = 'it_'.$i_tags.'.tag_id = '.$value; 117 130 $i_tags++; 118 131 } … … 122 135 else if ($filter['type'] == 'date') 123 136 { 124 if ($filter['cond'] == 'the') $where[] = "date_available BETWEEN '".$filter['value']." 00:00:00' AND '".$filter['value']." 23:59:59'";125 else if ($filter['cond'] == 'before') $where[] = "date_available < '".$filter['value']." 00:00:00'";126 else if ($filter['cond'] == 'after') $where[] = "date_available > '".$filter['value']." 23:59:59'";137 if ($filter['cond'] == 'the') $where[] = 'date_available BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"'; 138 else if ($filter['cond'] == 'before') $where[] = 'date_available < "'.$filter['value'].' 00:00:00"'; 139 else if ($filter['cond'] == 'after') $where[] = 'date_available > "'.$filter['value'].' 23:59:59"'; 127 140 } 128 141 // limit 129 142 else if ($filter['type'] == 'limit') 130 143 { 131 $limit = "0, ".$filter['value'];144 $limit = '0, '.$filter['value']; 132 145 } 133 146 } 134 147 135 148 /* bluid query */ 136 $MainQuery = "SELECT i.id 137 FROM ( 138 SELECT i.id 139 FROM ".IMAGES_TABLE." AS i"."\n"; 140 141 if (isset($join)) 142 { 143 foreach ($join as $query) 144 { 145 $MainQuery .= "LEFT JOIN ".$query."\n"; 146 } 147 } 148 if (isset($where)) 149 { 150 $MainQuery .= "WHERE"."\n"; 151 $i = 0; 152 foreach ($where as $query) 153 { 154 if ($i != 0) $MainQuery .= "AND "; 155 $MainQuery .= $query."\n"; 156 $i++; 157 } 158 } 159 160 $MainQuery .= "GROUP BY i.id 161 ".$conf['order_by']." 162 ".(isset($limit) ? "LIMIT ".$limit : null)." 163 ) AS i 164 "; 165 149 $MainQuery = ' 150 SELECT i.id 151 FROM '.IMAGES_TABLE.' AS i'; 152 153 if (isset($join)) 154 { 155 foreach ($join as $query) 156 { 157 $MainQuery .= ' 158 LEFT JOIN '.$query; 159 } 160 } 161 if (isset($where)) 162 { 163 $MainQuery .= ' 164 WHERE'; 165 $i = 0; 166 foreach ($where as $query) 167 { 168 if ($i != 0) $MainQuery .= ' AND'; 169 $MainQuery .= ' 170 '.$query; 171 $i++; 172 } 173 } 174 175 $MainQuery .= ' 176 GROUP BY i.id 177 '.$conf['order_by_inside_category'].' 178 '.(isset($limit) ? "LIMIT ".$limit : null).' 179 ;'; 180 166 181 return array_from_query($MainQuery, 'id'); 167 182 } … … 189 204 else 190 205 { 191 $filter['value'] = implode(',', get_ fckb_tag_ids($filter['value']));206 $filter['value'] = implode(',', get_tag_ids($filter['value'])); 192 207 } 193 208 } -
extensions/SmartAlbums/init_cat_list.php
r11290 r11333 13 13 14 14 /* get categories with smart filters */ 15 $query = "SELECT DISTINCT id, name 16 FROM ".CATEGORIES_TABLE." AS c 17 INNER JOIN ".CATEGORY_FILTERS_TABLE." AS cf 18 ON c.id = cf.category_id"; 15 $query = ' 16 SELECT DISTINCT id, name 17 FROM '.CATEGORIES_TABLE.' AS c 18 INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf 19 ON c.id = cf.category_id'; 19 20 if (!isset($_GET['parent_id'])) 20 21 { … … 24 25 else 25 26 { 26 $query .= '27 27 $query .= ' 28 WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\''; 28 29 } 30 $query .= ' 31 ;'; 29 32 30 33 $result = pwg_query($query); … … 45 48 { 46 49 $associated_images = smart_make_associations($cat); 47 array_push($page['infos'], l10n_args(get_l10n_args( 48 '%d photos associated to album «%s»', 49 array(count($associated_images), $name) 50 ))); 50 array_push( 51 $page['infos'], 52 l10n_args(get_l10n_args( 53 '%d photos associated to album «%s»', 54 array(count($associated_images), $name) 55 )) 56 ); 51 57 } 52 58 } … … 55 61 { 56 62 $associated_images = smart_make_associations($_GET['smart_generate']); 57 array_push($page['infos'], l10n_args(get_l10n_args( 58 '%d photos associated to album «%s»', 59 array(count($associated_images), $smart_cats[$_GET['smart_generate']]) 60 ))); 63 array_push( 64 $page['infos'], 65 l10n_args(get_l10n_args( 66 '%d photos associated to album «%s»', 67 array(count($associated_images), $smart_cats[$_GET['smart_generate']]) 68 )) 69 ); 61 70 } 62 71 -
extensions/SmartAlbums/init_cat_modify.php
r10980 r11333 11 11 12 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.";"));13 list($cat_dir) = pwg_db_fetch_row(pwg_query('SELECT dir FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat_id.';')); 14 14 15 15 // category must be virtual … … 23 23 { 24 24 // test if it was a Smart Album 25 $result = pwg_query( "SELECT DISTINCT category_id FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");25 $result = pwg_query('SELECT DISTINCT category_id FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';'); 26 26 $was_smart = pwg_db_num_rows($result); 27 27 … … 29 29 if ($was_smart AND !isset($_POST['is_smart'])) 30 30 { 31 pwg_query( "DELETE FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;");32 pwg_query( "DELETE FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");31 pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;'); 32 pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';'); 33 33 } 34 34 /* no filter selected */ … … 40 40 else if (isset($_POST['is_smart']) AND count($_POST['filters']) > 0) 41 41 { 42 pwg_query( "DELETE FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id.";");42 pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';'); 43 43 44 44 $limit_is_set = false; … … 47 47 if (($filter = smart_check_filter($filter)) != false) 48 48 { 49 pwg_query("INSERT INTO ".CATEGORY_FILTERS_TABLE." 50 VALUES(".$cat_id.", '".$filter['type']."', '".$filter['cond']."', '".$filter['value']."');"); 49 $query = ' 50 INSERT INTO '.CATEGORY_FILTERS_TABLE.' 51 VALUES( 52 '.$cat_id.', 53 "'.$filter['type'].'", 54 "'.$filter['cond'].'", 55 "'.$filter['value'].'" 56 ) 57 ;'; 58 pwg_query($query); 51 59 } 52 60 } … … 59 67 60 68 /* select options, for html_options */ 61 $template->assign('options', array( 62 'tags' => array( 63 'all' => l10n('All these tags'), 64 'one' => l10n('One of these tags'), 65 'none' => l10n('None of these tags'), 66 'only' => l10n('Only these tags'), 67 ), 68 'date' => array( 69 'the' => l10n('Added the'), 70 'before' => l10n('Added before the'), 71 'after' => l10n('Added after the'), 72 ), 73 'limit' => array('limit' => 'limit'), // second filter not used 74 )); 69 $template->assign( 70 'options', 71 array( 72 'tags' => array( 73 'all' => l10n('All these tags'), 74 'one' => l10n('One of these tags'), 75 'none' => l10n('None of these tags'), 76 'only' => l10n('Only these tags'), 77 ), 78 'date' => array( 79 'the' => l10n('Added the'), 80 'before' => l10n('Added before the'), 81 'after' => l10n('Added after the'), 82 ), 83 'limit' => array('limit' => 'limit'), // second filter not used 84 ) 85 ); 75 86 76 87 /* get filters for this album */ 77 $filters = pwg_query( "SELECT * FROM ".CATEGORY_FILTERS_TABLE." WHERE category_id = ".$cat_id." ORDER BY type ASC, cond ASC;");88 $filters = pwg_query('SELECT * FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.' ORDER BY type ASC, cond ASC;'); 78 89 while ($filter = pwg_db_fetch_assoc($filters)) 79 90 { … … 81 92 if ($filter['type'] == 'tags') 82 93 { 83 $query = "84 85 86 87 FROM ".TAGS_TABLE."88 WHERE id IN(".$filter['value'].")89 ";90 $filter['value'] = get_ fckb_taglist($query);94 $query = ' 95 SELECT 96 id AS tag_id, 97 name AS tag_name 98 FROM '.TAGS_TABLE.' 99 WHERE id IN('.$filter['value'].') 100 '; 101 $filter['value'] = get_taglist($query); 91 102 } 92 103 … … 98 109 } 99 110 111 /* all tags */ 112 $query = ' 113 SELECT 114 id AS tag_id, 115 name AS tag_name 116 FROM '.TAGS_TABLE.' 117 ;'; 118 $tags = get_taglist($query); 119 100 120 /* get image number */ 101 121 if ($template->get_template_vars('IMAGE_COUNT') == null) 102 122 { 103 list($image_num) = pwg_db_fetch_row(pwg_query( "SELECT count(*) FROM ".IMAGE_CATEGORY_TABLE." WHERE category_id = ".$cat_id." AND smart = true;"));123 list($image_num) = pwg_db_fetch_row(pwg_query('SELECT count(*) FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;')); 104 124 $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num)); 105 125 } … … 108 128 'SMART_PATH' => SMART_PATH, 109 129 'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php', 130 'tags' => $tags, 110 131 )); 111 132 $template->set_prefilter('categories', 'smart_cat_modify_prefilter'); -
extensions/SmartAlbums/language/fr_FR/plugin.lang.php
r11290 r11333 10 10 $lang['One of these tags'] = 'Un des tags'; 11 11 $lang['None of these tags'] = 'Aucun des tags'; 12 $lang['Only these tags'] = ' Tousles tags';12 $lang['Only these tags'] = 'Seulement les tags'; 13 13 $lang['Added the'] = 'Ajouté le'; 14 14 $lang['Added before the'] = 'Ajouté avant le'; -
extensions/SmartAlbums/maintain.inc.php
r10871 r11333 6 6 7 7 /* create table to store filters */ 8 pwg_query("CREATE TABLE IF NOT EXISTS `" . $prefixeTable . "category_filters` ( 9 `category_id` smallint(5) unsigned NOT NULL, 10 `type` varchar(16) NOT NULL, 11 `cond` varchar(16) NULL, 12 `value` text 13 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); 8 pwg_query( 9 'CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'category_filters` ( 10 `category_id` smallint(5) unsigned NOT NULL, 11 `type` varchar(16) NOT NULL, 12 `cond` varchar(16) NULL, 13 `value` text 14 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 15 ;'); 14 16 15 17 /* add a collumn to image_category_table */ 16 pwg_query( "ALTER TABLE `" . IMAGE_CATEGORY_TABLE . "` ADD `smart` ENUM('true', 'false') NOT NULL DEFAULT 'false';");18 pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM("true", "false") NOT NULL DEFAULT "false";'); 17 19 18 20 /* config parameter */ … … 24 26 global $prefixeTable; 25 27 26 pwg_query( "DROP TABLE `" . $prefixeTable . "category_filters`;");27 pwg_query( "ALTER TABLE `" . IMAGE_CATEGORY_TABLE . "` DROP `smart`;");28 pwg_query( "DELETE FROM `" . CONFIG_TABLE . "` WHERE param = 'SmartAlbums';");28 pwg_query('DROP TABLE `' . $prefixeTable . 'category_filters`;'); 29 pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;'); 30 pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "SmartAlbums";'); 29 31 } 30 32 ?> -
extensions/SmartAlbums/template/cat_modify.tpl
r10980 r11333 74 74 }); 75 75 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 ); 90 }); 76 jQuery(".tagSelect").tokenInput( 77 {/literal} 78 [{foreach from=$tags item=tag name=tags}{ldelim}"name":"{$tag.name|@escape:'javascript'}","id":"{$tag.id}"{rdelim}{if !$smarty.foreach.tags.last},{/if}{/foreach}], 79 {ldelim} 80 hintText: '{'Type in a search term'|@translate}', 81 noResultsText: '{'No results'|@translate}', 82 searchingText: '{'Searching...'|@translate}', 83 animateDropdown: false, 84 preventDuplicates: true, 85 allowCreation: false 86 {literal} 87 } 88 ); 91 89 } 92 90
Note: See TracChangeset
for help on using the changeset viewer.