1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | /** |
---|
4 | * Add a link into categories list to regenerate associations |
---|
5 | */ |
---|
6 | $smart_count = 0; |
---|
7 | |
---|
8 | function smart_cat_list() |
---|
9 | { |
---|
10 | global $template, $page, $smart_count; |
---|
11 | include_once(SMART_PATH.'include/functions.inc.php'); |
---|
12 | $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&parent_id='.$_GET['parent_id'] : null); |
---|
13 | |
---|
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"; |
---|
19 | if (!isset($_GET['parent_id'])) |
---|
20 | { |
---|
21 | // $query.= ' |
---|
22 | // WHERE id_uppercat IS NULL'; |
---|
23 | } |
---|
24 | else |
---|
25 | { |
---|
26 | $query.= ' |
---|
27 | WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\''; |
---|
28 | } |
---|
29 | |
---|
30 | $result = pwg_query($query); |
---|
31 | $smart_cats = array(); |
---|
32 | while ($cat = pwg_db_fetch_assoc($result)) |
---|
33 | { |
---|
34 | $smart_cats[$cat['id']] = trigger_event('render_category_name', $cat['name']); |
---|
35 | } |
---|
36 | |
---|
37 | $smart_count = count($smart_cats); |
---|
38 | |
---|
39 | if (isset($_GET['smart_generate'])) |
---|
40 | { |
---|
41 | /* regenerate photo list | all (sub) categories */ |
---|
42 | if ($_GET['smart_generate'] == 'all') |
---|
43 | { |
---|
44 | foreach ($smart_cats as $cat => $name) |
---|
45 | { |
---|
46 | $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 | ))); |
---|
51 | } |
---|
52 | } |
---|
53 | /* regenerate photo list | one category */ |
---|
54 | else |
---|
55 | { |
---|
56 | $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 | ))); |
---|
61 | } |
---|
62 | |
---|
63 | invalidate_user_cache(true); |
---|
64 | } |
---|
65 | |
---|
66 | // create regenerate link |
---|
67 | $tpl_cat = array(); |
---|
68 | foreach ($smart_cats as $cat => $name) |
---|
69 | { |
---|
70 | $tpl_cat[$cat] = $self_url.'&smart_generate='.$cat; |
---|
71 | } |
---|
72 | $tpl_cat['all'] = $self_url.'&smart_generate=all'; |
---|
73 | |
---|
74 | $template->assign(array( |
---|
75 | 'SMART_URL' => $tpl_cat, |
---|
76 | 'SMART_PATH' => SMART_PATH, |
---|
77 | )); |
---|
78 | |
---|
79 | $template->set_prefilter('categories', 'smart_cat_list_prefilter'); |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | function smart_cat_list_prefilter($content, &$smarty) |
---|
84 | { |
---|
85 | global $smart_count; |
---|
86 | |
---|
87 | $search[0] = '<ul class="categoryActions">'; |
---|
88 | $replacement[0] = $search[0].' |
---|
89 | {if isset($SMART_URL[$category.ID])} |
---|
90 | <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> |
---|
91 | {/if}'; |
---|
92 | |
---|
93 | if ($smart_count > 0) |
---|
94 | { |
---|
95 | $search[1] = '</ul> |
---|
96 | </form> |
---|
97 | {/if}'; |
---|
98 | $replacement[1] = $search[1].' |
---|
99 | <form method="post" action="{$SMART_URL.all}"> |
---|
100 | <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}"> |
---|
101 | <p><input class="submit" type="submit" value="{\'regenerate photos list of all SmartAlbums\'|@translate}"></p> |
---|
102 | </form>'; |
---|
103 | } |
---|
104 | |
---|
105 | return str_replace($search, $replacement, $content); |
---|
106 | } |
---|
107 | |
---|
108 | ?> |
---|