1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Batch Manager, Added By |
---|
4 | Version: auto |
---|
5 | Description: Add filter "Added by" in Batch Manager |
---|
6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid= |
---|
7 | Author: plg |
---|
8 | Author URI: http://le-gall.net/pierrick |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | |
---|
13 | add_event_handler('loc_end_element_set_global', 'bmab_add_filter'); |
---|
14 | function bmab_add_filter() |
---|
15 | { |
---|
16 | global $conf, $template; |
---|
17 | |
---|
18 | $query = ' |
---|
19 | SELECT |
---|
20 | u.'.$conf['user_fields']['username'].' AS username, |
---|
21 | i.added_by, |
---|
22 | COUNT(*) AS counter |
---|
23 | FROM '.USERS_TABLE.' AS u |
---|
24 | INNER JOIN '.IMAGES_TABLE.' AS i ON u.'.$conf['user_fields']['id'].' = i.added_by |
---|
25 | GROUP BY i.added_by |
---|
26 | ORDER BY u.'.$conf['user_fields']['username'].' ASC |
---|
27 | ;'; |
---|
28 | $result = pwg_query($query); |
---|
29 | |
---|
30 | $added_by_options = array(); |
---|
31 | while ($row = pwg_db_fetch_assoc($result)) |
---|
32 | { |
---|
33 | $added_by_options[$row['added_by']] = $row['username'].' ('.l10n_dec('%d photo', '%d photos', $row['counter']).')'; |
---|
34 | } |
---|
35 | $template->assign('added_by_options', $added_by_options); |
---|
36 | |
---|
37 | $template->assign( |
---|
38 | 'added_by_selected', |
---|
39 | isset($_SESSION['bulk_manager_filter']['added_by']) ? $_SESSION['bulk_manager_filter']['added_by'] : '' |
---|
40 | ); |
---|
41 | |
---|
42 | $template->set_prefilter('batch_manager_global', 'bmab_add_filter_prefilter'); |
---|
43 | } |
---|
44 | |
---|
45 | function bmab_add_filter_prefilter($content, &$smarty) |
---|
46 | { |
---|
47 | // first we add the (hidden by default) block to select the user |
---|
48 | $pattern = '#</ul>\s*<p class="actionButtons">#ms'; |
---|
49 | $replacement = ' |
---|
50 | <li id="filter_added_by" {if !isset($filter.added_by)}style="display:none"{/if}> |
---|
51 | <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a> |
---|
52 | <input type="checkbox" name="filter_added_by_use" class="useFilterCheckbox" {if isset($filter.added_by)}checked="checked"{/if}> |
---|
53 | {\'Added by %s\'|@translate|sprintf:""} |
---|
54 | <select name="filter_added_by"> |
---|
55 | {html_options options=$added_by_options selected=$added_by_selected} |
---|
56 | </select> |
---|
57 | </li> |
---|
58 | </ul> |
---|
59 | |
---|
60 | <p class="actionButtons"> |
---|
61 | '; |
---|
62 | $content = preg_replace($pattern, $replacement, $content); |
---|
63 | |
---|
64 | // then we add the "Added by" in the filter selector |
---|
65 | $pattern = '#</select>\s*<a id="removeFilters"#ms'; |
---|
66 | $replacement = ' |
---|
67 | <option value="filter_added_by" {if isset($filter.added_by)}disabled="disabled"{/if}>{\'Added by %s\'|@translate|sprintf:""}</option> |
---|
68 | </select> |
---|
69 | <a id="removeFilters" |
---|
70 | '; |
---|
71 | $content = preg_replace($pattern, $replacement, $content); |
---|
72 | |
---|
73 | return $content; |
---|
74 | } |
---|
75 | |
---|
76 | add_event_handler('loc_begin_element_set_global', 'bmab_perform_filter', 50, 2); |
---|
77 | function bmab_perform_filter() |
---|
78 | { |
---|
79 | global $page; |
---|
80 | |
---|
81 | if (isset($_POST['filter_added_by_use'])) |
---|
82 | { |
---|
83 | check_input_parameter('filter_added_by', $_POST, false, PATTERN_ID); |
---|
84 | $_SESSION['bulk_manager_filter']['added_by'] = $_POST['filter_added_by']; |
---|
85 | } |
---|
86 | |
---|
87 | if (isset($_SESSION['bulk_manager_filter']['added_by'])) |
---|
88 | { |
---|
89 | $query = ' |
---|
90 | SELECT |
---|
91 | id |
---|
92 | FROM '.IMAGES_TABLE.' |
---|
93 | WHERE added_by = '.$_SESSION['bulk_manager_filter']['added_by'].' |
---|
94 | ;'; |
---|
95 | if (empty($page['cat_elements_id'])) |
---|
96 | { |
---|
97 | $page['cat_elements_id'] = array_from_query($query, 'id'); |
---|
98 | } |
---|
99 | else |
---|
100 | { |
---|
101 | $page['cat_elements_id'] = array_intersect($page['cat_elements_id'], array_from_query($query, 'id')); |
---|
102 | } |
---|
103 | } |
---|
104 | } |
---|
105 | ?> |
---|