1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | /** |
---|
4 | * Add a link into categories list to regenerate associations |
---|
5 | */ |
---|
6 | |
---|
7 | function smart_cat_list() |
---|
8 | { |
---|
9 | global $template, $page; |
---|
10 | include_once(SMART_PATH.'include/functions.inc.php'); |
---|
11 | $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&parent_id='.$_GET['parent_id'] : null); |
---|
12 | |
---|
13 | /* get categories with smart filters */ |
---|
14 | $query = "SELECT DISTINCT id, name |
---|
15 | FROM ".CATEGORIES_TABLE." AS c |
---|
16 | INNER JOIN ".CATEGORY_FILTERS_TABLE." AS cf |
---|
17 | ON c.id = cf.category_id"; |
---|
18 | if (!isset($_GET['parent_id'])) |
---|
19 | { |
---|
20 | // $query.= ' |
---|
21 | // WHERE id_uppercat IS NULL'; |
---|
22 | } |
---|
23 | else |
---|
24 | { |
---|
25 | $query.= ' |
---|
26 | WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\''; |
---|
27 | } |
---|
28 | |
---|
29 | $result = pwg_query($query); |
---|
30 | $categories = array(); |
---|
31 | while ($cat = pwg_db_fetch_assoc($result)) |
---|
32 | { |
---|
33 | $categories[$cat['id']] = trigger_event('render_category_name', $cat['name']); |
---|
34 | } |
---|
35 | |
---|
36 | if (isset($_GET['smart_generate'])) |
---|
37 | { |
---|
38 | /* regenerate photo list | all (sub) categories */ |
---|
39 | if ($_GET['smart_generate'] == 'all') |
---|
40 | { |
---|
41 | foreach ($categories as $cat => $name) |
---|
42 | { |
---|
43 | $associated_images = smart_make_associations($cat); |
---|
44 | array_push($page['infos'], l10n_args(get_l10n_args( |
---|
45 | '%d photos associated to album «%s»', |
---|
46 | array(count($associated_images), $name) |
---|
47 | ))); |
---|
48 | } |
---|
49 | } |
---|
50 | /* regenerate photo list | one category */ |
---|
51 | else |
---|
52 | { |
---|
53 | $associated_images = smart_make_associations($_GET['smart_generate']); |
---|
54 | array_push($page['infos'], l10n_args(get_l10n_args( |
---|
55 | '%d photos associated to album «%s»', |
---|
56 | array(count($associated_images), $categories[$_GET['smart_generate']]) |
---|
57 | ))); |
---|
58 | } |
---|
59 | |
---|
60 | invalidate_user_cache(true); |
---|
61 | } |
---|
62 | |
---|
63 | // create regenerate link |
---|
64 | $tpl_cat = array(); |
---|
65 | foreach ($categories as $cat => $name) |
---|
66 | { |
---|
67 | $tpl_cat[$cat] = $self_url.'&smart_generate='.$cat; |
---|
68 | } |
---|
69 | $tpl_cat['all'] = $self_url.'&smart_generate=all'; |
---|
70 | |
---|
71 | $template->assign(array( |
---|
72 | 'SMART_URL' => $tpl_cat, |
---|
73 | 'SMART_PATH' => SMART_PATH, |
---|
74 | )); |
---|
75 | |
---|
76 | $template->set_prefilter('categories', 'smart_cat_list_prefilter'); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | function smart_cat_list_prefilter($content, &$smarty) |
---|
81 | { |
---|
82 | $search[0] = '<ul class="categoryActions">'; |
---|
83 | $replacement[0] = $search[0].' |
---|
84 | {if isset($SMART_URL[$category.ID])} |
---|
85 | <li><a href="{$SMART_URL[$category.ID]}" title="{\'regenerate photos list\'|@translate}"><img src="{$SMART_PATH}template/refresh.png" class="button" alt="{\'regenerate photos list\'|@translate}"></a></li> |
---|
86 | {/if}'; |
---|
87 | |
---|
88 | $search[1] = '</ul> |
---|
89 | </form> |
---|
90 | {/if}'; |
---|
91 | $replacement[1] = $search[1].' |
---|
92 | <form method="post" action="{$SMART_URL.all}"> |
---|
93 | <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}"> |
---|
94 | <p><input class="submit" type="submit" value="{\'regenerate photos list of all SmartAlbums\'|@translate}"></p> |
---|
95 | </form>'; |
---|
96 | |
---|
97 | return str_replace($search, $replacement, $content); |
---|
98 | } |
---|
99 | |
---|
100 | ?> |
---|