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 | |
---|
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 = ' |
---|
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'; |
---|
20 | if (!isset($_GET['parent_id'])) |
---|
21 | { |
---|
22 | // $query.= ' |
---|
23 | // WHERE id_uppercat IS NULL'; |
---|
24 | } |
---|
25 | else |
---|
26 | { |
---|
27 | $query .= ' |
---|
28 | WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\''; |
---|
29 | } |
---|
30 | $query .= ' |
---|
31 | ;'; |
---|
32 | |
---|
33 | $smart_cats = hash_from_query($query, 'id'); |
---|
34 | $smart_count = count($smart_cats); |
---|
35 | |
---|
36 | if (isset($_GET['smart_generate'])) |
---|
37 | { |
---|
38 | /* regenerate photo list | all (sub) categories */ |
---|
39 | if ($_GET['smart_generate'] == 'all') |
---|
40 | { |
---|
41 | foreach ($smart_cats as $category) |
---|
42 | { |
---|
43 | $associated_images = smart_make_associations($category['id']); |
---|
44 | array_push($page['infos'], |
---|
45 | sprintf(l10n('%d photos associated to album %s'), |
---|
46 | count($associated_images), |
---|
47 | '«'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'»' |
---|
48 | ) |
---|
49 | ); |
---|
50 | } |
---|
51 | } |
---|
52 | /* regenerate photo list | one category */ |
---|
53 | else |
---|
54 | { |
---|
55 | $associated_images = smart_make_associations($_GET['smart_generate']); |
---|
56 | array_push($page['infos'], |
---|
57 | sprintf(l10n('%d photos associated to album %s'), |
---|
58 | count($associated_images), |
---|
59 | '«'.trigger_event('render_category_name', $smart_cats[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'»' |
---|
60 | ) |
---|
61 | ); |
---|
62 | } |
---|
63 | |
---|
64 | define('SMART_NOT_UPDATE', 1); |
---|
65 | invalidate_user_cache(); |
---|
66 | } |
---|
67 | |
---|
68 | // create regenerate link |
---|
69 | $tpl_cat = array(); |
---|
70 | foreach ($smart_cats as $cat => $name) |
---|
71 | { |
---|
72 | $tpl_cat[$cat] = $self_url.'&smart_generate='.$cat; |
---|
73 | } |
---|
74 | $tpl_cat['all'] = $self_url.'&smart_generate=all'; |
---|
75 | |
---|
76 | $template->assign(array( |
---|
77 | 'SMART_URL' => $tpl_cat, |
---|
78 | 'SMART_PATH' => SMART_PATH, |
---|
79 | )); |
---|
80 | |
---|
81 | $template->set_prefilter('categories', 'smart_cat_list_prefilter'); |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | function smart_cat_list_prefilter($content, &$smarty) |
---|
86 | { |
---|
87 | global $smart_count; |
---|
88 | |
---|
89 | $search[0] = '{if isset($category.U_MANAGE_ELEMENTS) }'; |
---|
90 | $replacement[0] = $search[0].' |
---|
91 | {if isset($SMART_URL[$category.ID])} |
---|
92 | | <a href="{$SMART_URL[$category.ID]}">{\'Regenerate photos list of this SmartAlbum\'|@translate}</a> |
---|
93 | {/if}'; |
---|
94 | |
---|
95 | if ($smart_count > 0) |
---|
96 | { |
---|
97 | $search[1] = '<a href="#" id="autoOrderOpen">{\'apply automatic sort order\'|@translate}</a>'; |
---|
98 | $replacement[1] = $search[1].' |
---|
99 | | <a href="{$SMART_URL.all}">{\'Regenerate photos list of all SmartAlbums\'|@translate}</a>'; |
---|
100 | } |
---|
101 | |
---|
102 | $search[2] = '{$category.NAME}</a></strong>'; |
---|
103 | $replacement[2] = $search[2].' |
---|
104 | {if isset($SMART_URL[$category.ID])} |
---|
105 | <img src="'.SMART_PATH.'admin/template/lightning.png"> |
---|
106 | {/if}'; |
---|
107 | |
---|
108 | return str_replace($search, $replacement, $content); |
---|
109 | } |
---|
110 | |
---|
111 | ?> |
---|