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 HD', 'NAME' => l10n('with HD')), |
---|
24 | array('ID' => 'without HD', 'NAME' => l10n('without HD')), |
---|
25 | array('ID' => 'with author', 'NAME' => l10n('with author')), |
---|
26 | array('ID' => 'without author', 'NAME' => l10n('without author')) |
---|
27 | ); |
---|
28 | |
---|
29 | return $prefilters; |
---|
30 | } |
---|
31 | |
---|
32 | function perform_bmp($filter_sets, $prefilter) |
---|
33 | { |
---|
34 | if ('with tags' == $prefilter) |
---|
35 | { |
---|
36 | $query = 'SELECT DISTINCT image_id FROM '.IMAGE_TAG_TABLE.';'; |
---|
37 | array_push($filter_sets, array_from_query($query, 'image_id')); |
---|
38 | } |
---|
39 | |
---|
40 | if ('with HD' == $prefilter) |
---|
41 | { |
---|
42 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE has_high IS NOT NULL;'; |
---|
43 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
44 | } |
---|
45 | |
---|
46 | if ('without HD' == $prefilter) |
---|
47 | { |
---|
48 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE has_high IS NULL;'; |
---|
49 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
50 | } |
---|
51 | |
---|
52 | if ('with author' == $prefilter) |
---|
53 | { |
---|
54 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE author IS NOT NULL;'; |
---|
55 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
56 | } |
---|
57 | |
---|
58 | if ('without author' == $prefilter) |
---|
59 | { |
---|
60 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE author IS NULL;'; |
---|
61 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
62 | } |
---|
63 | |
---|
64 | return $filter_sets; |
---|
65 | } |
---|
66 | |
---|
67 | function element_set_global_action_bmp($action) |
---|
68 | { |
---|
69 | if ((@$_SESSION['bulk_manager_filter']['prefilter'] == 'with tags' and in_array($action, array('add_tags', 'del_tags'))) |
---|
70 | or (in_array(@$_SESSION['bulk_manager_filter']['prefilter'], array('with author', 'without author')) and $action == 'author')) |
---|
71 | { |
---|
72 | // let's refresh the page because we the current set might be modified |
---|
73 | redirect(get_root_url().'admin.php?page='.$_GET['page']); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | ?> |
---|