[29246] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Batch Manager Prefilters |
---|
[10379] | 4 | Version: auto |
---|
[29246] | 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( |
---|
| 22 | $prefilters, |
---|
| 23 | array('ID' => 'with tags', 'NAME' => l10n('with tags')), |
---|
| 24 | array('ID' => 'with author', 'NAME' => l10n('with author')), |
---|
| 25 | array('ID' => 'without author', 'NAME' => l10n('without author')), |
---|
| 26 | array('ID' => 'no_title', 'NAME' => l10n('With no title')), |
---|
| 27 | array('ID' => 'no_date_creation', 'NAME' => l10n('With no creation date')) |
---|
| 28 | ); |
---|
| 29 | |
---|
| 30 | return $prefilters; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | function perform_bmp($filter_sets, $prefilter) |
---|
| 34 | { |
---|
| 35 | if ('with tags' == $prefilter) |
---|
| 36 | { |
---|
| 37 | $query = 'SELECT DISTINCT image_id FROM '.IMAGE_TAG_TABLE.';'; |
---|
| 38 | array_push($filter_sets, array_from_query($query, 'image_id')); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | if ('with author' == $prefilter) |
---|
| 42 | { |
---|
| 43 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE author IS NOT NULL;'; |
---|
| 44 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | if ('without author' == $prefilter) |
---|
| 48 | { |
---|
| 49 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE author IS NULL;'; |
---|
| 50 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | if ('no_title' == $prefilter) |
---|
| 54 | { |
---|
| 55 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE name IS NULL OR name = \'\';'; |
---|
| 56 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if ('no_date_creation' == $prefilter) |
---|
| 60 | { |
---|
| 61 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE date_creation IS NULL;'; |
---|
| 62 | array_push($filter_sets, array_from_query($query, 'id')); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | return $filter_sets; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | function element_set_global_action_bmp($action) |
---|
| 69 | { |
---|
| 70 | if ((@$_SESSION['bulk_manager_filter']['prefilter'] == 'with tags' and in_array($action, array('add_tags', 'del_tags'))) |
---|
[29247] | 71 | or (in_array(@$_SESSION['bulk_manager_filter']['prefilter'], array('with author', 'without author')) and $action == 'author') |
---|
| 72 | or (in_array(@$_SESSION['bulk_manager_filter']['prefilter'], array('no_date_creation')) and $action == 'date_creation') |
---|
| 73 | or (in_array(@$_SESSION['bulk_manager_filter']['prefilter'], array('no_title')) and $action == 'title') |
---|
| 74 | ) |
---|
[29246] | 75 | { |
---|
| 76 | // let's refresh the page because we the current set might be modified |
---|
| 77 | redirect(get_root_url().'admin.php?page='.$_GET['page']); |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
[10379] | 81 | ?> |
---|