1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Batch Manager Prefilters |
---|
4 | Version: auto |
---|
5 | Description: Add some prefilters in Batch Manager. |
---|
6 | Plugin URI: auto |
---|
7 | Author: P@t |
---|
8 | Author URI: http://www.gauchon.com |
---|
9 | */ |
---|
10 | |
---|
11 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
12 | |
---|
13 | add_event_handler('get_batch_manager_prefilters', 'add_bmp'); |
---|
14 | add_event_handler('perform_batch_manager_prefilters', 'perform_bmp', 50, 2); |
---|
15 | add_event_handler('element_set_global_action', 'element_set_global_action_bmp'); |
---|
16 | |
---|
17 | function add_bmp($prefilters) |
---|
18 | { |
---|
19 | load_language('plugin.lang', dirname(__FILE__).'/'); |
---|
20 | |
---|
21 | array_push($prefilters, |
---|
22 | array('ID' => 'with tags', 'NAME' => l10n('with tags')), |
---|
23 | array('ID' => 'with author', 'NAME' => l10n('with author')), |
---|
24 | array('ID' => 'without author', 'NAME' => l10n('without author')) |
---|
25 | ); |
---|
26 | |
---|
27 | return $prefilters; |
---|
28 | } |
---|
29 | |
---|
30 | function perform_bmp($filter_sets, $prefilter) |
---|
31 | { |
---|
32 | if ('with tags' == $prefilter) |
---|
33 | { |
---|
34 | $query = 'SELECT DISTINCT image_id FROM '.IMAGE_TAG_TABLE.';'; |
---|
35 | array_push($filter_sets, array_from_query($query, 'image_id')); |
---|
36 | } |
---|
37 | |
---|
38 | if ('with author' == $prefilter) |
---|
39 | { |
---|
40 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE author IS NOT NULL;'; |
---|
41 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
42 | } |
---|
43 | |
---|
44 | if ('without author' == $prefilter) |
---|
45 | { |
---|
46 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE author IS NULL;'; |
---|
47 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
48 | } |
---|
49 | |
---|
50 | return $filter_sets; |
---|
51 | } |
---|
52 | |
---|
53 | function element_set_global_action_bmp($action) |
---|
54 | { |
---|
55 | if ((@$_SESSION['bulk_manager_filter']['prefilter'] == 'with tags' and in_array($action, array('add_tags', 'del_tags'))) |
---|
56 | or (in_array(@$_SESSION['bulk_manager_filter']['prefilter'], array('with author', 'without author')) and $action == 'author')) |
---|
57 | { |
---|
58 | // let's refresh the page because we the current set might be modified |
---|
59 | redirect(get_root_url().'admin.php?page='.$_GET['page']); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | ?> |
---|