1 | <?php |
---|
2 | defined('SMART_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * new tab on album properties page |
---|
6 | */ |
---|
7 | function smart_tab($sheets, $id) |
---|
8 | { |
---|
9 | if ($id == 'album') |
---|
10 | { |
---|
11 | global $category; |
---|
12 | |
---|
13 | if ($category['dir'] == null) |
---|
14 | { |
---|
15 | $sheets['smartalbum'] = array( |
---|
16 | 'caption' => 'SmartAlbum', |
---|
17 | 'url' => SMART_ADMIN.'-album&cat_id='.$_GET['cat_id'], |
---|
18 | ); |
---|
19 | } |
---|
20 | } |
---|
21 | |
---|
22 | return $sheets; |
---|
23 | } |
---|
24 | |
---|
25 | /** |
---|
26 | * admin plugins menu link |
---|
27 | */ |
---|
28 | function smart_admin_menu($menu) |
---|
29 | { |
---|
30 | $menu[] = array( |
---|
31 | 'NAME' => 'SmartAlbums', |
---|
32 | 'URL' => SMART_ADMIN, |
---|
33 | ); |
---|
34 | return $menu; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * Add a link into categories list to regenerate associations |
---|
39 | */ |
---|
40 | function smart_cat_list() |
---|
41 | { |
---|
42 | global $template, $page; |
---|
43 | |
---|
44 | if (!isset($smart_count)) |
---|
45 | { |
---|
46 | $smart_count = 0; |
---|
47 | } |
---|
48 | |
---|
49 | $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&parent_id='.$_GET['parent_id'] : null); |
---|
50 | |
---|
51 | /* get categories with smart filters */ |
---|
52 | $query = ' |
---|
53 | SELECT DISTINCT id, name |
---|
54 | FROM '.CATEGORIES_TABLE.' AS c |
---|
55 | INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf |
---|
56 | ON c.id = cf.category_id'; |
---|
57 | if (!isset($_GET['parent_id'])) |
---|
58 | { |
---|
59 | // $query.= ' |
---|
60 | // WHERE id_uppercat IS NULL'; |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | $query .= ' |
---|
65 | WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\''; |
---|
66 | } |
---|
67 | $query .= ' |
---|
68 | ;'; |
---|
69 | |
---|
70 | $smart_cats = query2array($query, 'id'); |
---|
71 | |
---|
72 | if (isset($_GET['smart_generate'])) |
---|
73 | { |
---|
74 | /* regenerate photo list | all (sub) categories */ |
---|
75 | if ($_GET['smart_generate'] == 'all') |
---|
76 | { |
---|
77 | foreach ($smart_cats as $category) |
---|
78 | { |
---|
79 | $associated_images = smart_make_associations($category['id']); |
---|
80 | |
---|
81 | $page['infos'][] = l10n( |
---|
82 | '%d photos associated to album %s', |
---|
83 | count($associated_images), |
---|
84 | '«'.trigger_change('render_category_name', $category['name'], 'admin_cat_list').'»' |
---|
85 | ); |
---|
86 | } |
---|
87 | } |
---|
88 | /* regenerate photo list | one category */ |
---|
89 | else |
---|
90 | { |
---|
91 | $associated_images = smart_make_associations($_GET['smart_generate']); |
---|
92 | |
---|
93 | $page['infos'][] = l10n( |
---|
94 | '%d photos associated to album %s', |
---|
95 | count($associated_images), |
---|
96 | '«'.trigger_change('render_category_name', $smart_cats[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'»' |
---|
97 | ); |
---|
98 | } |
---|
99 | |
---|
100 | define('SMART_NOT_UPDATE', 1); |
---|
101 | invalidate_user_cache(); |
---|
102 | } |
---|
103 | |
---|
104 | // create regenerate link |
---|
105 | $tpl_cat = array(); |
---|
106 | foreach ($smart_cats as $cat => $name) |
---|
107 | { |
---|
108 | $tpl_cat[$cat] = $self_url.'&smart_generate='.$cat; |
---|
109 | } |
---|
110 | if (count($smart_cats)) |
---|
111 | { |
---|
112 | $tpl_cat['all'] = $self_url.'&smart_generate=all'; |
---|
113 | } |
---|
114 | |
---|
115 | $template->assign(array( |
---|
116 | 'SMART_URL' => $tpl_cat, |
---|
117 | 'SMART_PATH' => SMART_PATH, |
---|
118 | )); |
---|
119 | |
---|
120 | $template->set_prefilter('categories', 'smart_cat_list_prefilter'); |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | function smart_cat_list_prefilter($content) |
---|
125 | { |
---|
126 | $search[0] = '{if isset($category.U_MANAGE_ELEMENTS) }'; |
---|
127 | $replacement[0] = $search[0].' |
---|
128 | {if isset($SMART_URL[$category.ID])} |
---|
129 | | <a href="{$SMART_URL[$category.ID]}">{\'Regenerate photos list of this SmartAlbum\'|@translate}</a> |
---|
130 | {/if}'; |
---|
131 | |
---|
132 | $search[1] = '<a href="#" id="autoOrderOpen">{\'apply automatic sort order\'|@translate}</a>'; |
---|
133 | $replacement[1] = $search[1].' |
---|
134 | {if isset($SMART_URL.all)}| <a href="{$SMART_URL.all}">{\'Regenerate photos list of all SmartAlbums\'|@translate}</a>{/if}'; |
---|
135 | |
---|
136 | $search[2] = '{$category.NAME}</a></strong>'; |
---|
137 | $replacement[2] = $search[2].' |
---|
138 | {if isset($SMART_URL[$category.ID])} |
---|
139 | <img src="'.SMART_PATH.'admin/template/lightning.png"> |
---|
140 | {/if}'; |
---|
141 | |
---|
142 | return str_replace($search, $replacement, $content); |
---|
143 | } |
---|