[22247] | 1 | <?php |
---|
[31469] | 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Batch Manager, Photo Description by plugin for Piwigo | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2013-2016 ddtddt http://temmii.com/piwigo/ | |
---|
| 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 8 | // | it under the terms of the GNU General Public License as published by | |
---|
| 9 | // | the Free Software Foundation | |
---|
| 10 | // | | |
---|
| 11 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 12 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 13 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 14 | // | General Public License for more details. | |
---|
| 15 | // | | |
---|
| 16 | // | You should have received a copy of the GNU General Public License | |
---|
| 17 | // | along with this program; if not, write to the Free Software | |
---|
| 18 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 19 | // | USA. | |
---|
| 20 | // +-----------------------------------------------------------------------+ |
---|
[22247] | 21 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 22 | |
---|
| 23 | load_language('plugin.lang', BMPD_PATH); |
---|
| 24 | |
---|
| 25 | global $prefilter; |
---|
[31469] | 26 | |
---|
| 27 | add_event_handler('get_batch_manager_prefilters', 'BMPD_add_batch_manager_prefilters'); |
---|
| 28 | add_event_handler('perform_batch_manager_prefilters', 'BMPD_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[22247] | 29 | |
---|
[31469] | 30 | function BMPD_add_batch_manager_prefilters($prefilters){ |
---|
| 31 | array_push($prefilters, array( |
---|
[22247] | 32 | 'ID' => 'BMPD', |
---|
[22253] | 33 | 'NAME' => l10n('With no description'), |
---|
[22247] | 34 | )); |
---|
| 35 | return $prefilters; |
---|
| 36 | } |
---|
| 37 | |
---|
[31469] | 38 | function BMPD_perform_batch_manager_prefilters($filter_sets, $prefilter){ |
---|
| 39 | if ($prefilter == 'BMPD'){ |
---|
| 40 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE comment is null;'; |
---|
[22247] | 41 | $filter_sets[] = array_from_query($query, 'id'); |
---|
| 42 | } |
---|
[31469] | 43 | return $filter_sets; |
---|
[22247] | 44 | } |
---|
| 45 | |
---|
[31469] | 46 | add_event_handler('get_batch_manager_prefilters', 'BMPD2_add_batch_manager_prefilters'); |
---|
| 47 | add_event_handler('perform_batch_manager_prefilters', 'BMPD2_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[22247] | 48 | |
---|
[31469] | 49 | function BMPD2_add_batch_manager_prefilters($prefilters){ |
---|
| 50 | array_push($prefilters, array( |
---|
[22247] | 51 | 'ID' => 'BMPD2', |
---|
| 52 | 'NAME' => l10n('With description'), |
---|
| 53 | )); |
---|
[31469] | 54 | return $prefilters; |
---|
[22247] | 55 | } |
---|
| 56 | |
---|
[31469] | 57 | function BMPD2_perform_batch_manager_prefilters($filter_sets, $prefilter){ |
---|
| 58 | if ($prefilter == 'BMPD2'){ |
---|
| 59 | $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE comment is not null ;'; |
---|
[22247] | 60 | $filter_sets[] = array_from_query($query, 'id'); |
---|
| 61 | } |
---|
[31469] | 62 | return $filter_sets; |
---|
[22247] | 63 | } |
---|
| 64 | |
---|
[31469] | 65 | add_event_handler('loc_end_element_set_global', 'BMPD_loc_end_element_set_global'); |
---|
| 66 | add_event_handler('element_set_global_action', 'BMPD_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
[22253] | 67 | |
---|
[31469] | 68 | function BMPD_loc_end_element_set_global(){ |
---|
[22253] | 69 | global $template; |
---|
[31469] | 70 | $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); |
---|
| 71 | if($PAED['state'] == 'active'){ |
---|
| 72 | $templatebmpd=' |
---|
| 73 | <input type="checkbox" name="check_BMPD4"> '.l10n('remove description').'<br> |
---|
| 74 | <textarea rows="5" cols="50" placeholder="'.l10n('Type here the description')." / ".l10n('Use Extended Description tags...').'" class="description" name="BMPD3" id="BMPD3"></textarea><br> |
---|
| 75 | <input type="checkbox" name="check_BMPD"> '.l10n('confirm').' |
---|
| 76 | '; |
---|
| 77 | }else{ |
---|
| 78 | $templatebmpd=' |
---|
| 79 | <input type="checkbox" name="check_BMPD4"> '.l10n('remove description').'<br> |
---|
| 80 | <textarea rows="5" cols="50" placeholder="'.l10n('Type here the description').'" class="description" name="BMPD3" id="BMPD3"></textarea><br> |
---|
| 81 | <input type="checkbox" name="check_BMPD"> '.l10n('confirm').' |
---|
| 82 | '; |
---|
| 83 | } |
---|
[22253] | 84 | $template->append('element_set_global_plugins_actions', array( |
---|
[31469] | 85 | 'ID' => 'BMPD3', |
---|
| 86 | 'NAME' => l10n('Set description'), |
---|
| 87 | 'CONTENT' => $templatebmpd, |
---|
[22253] | 88 | )); |
---|
| 89 | } |
---|
| 90 | |
---|
[31469] | 91 | function BMPD_element_set_global_action($action, $collection) { |
---|
| 92 | if ($action == 'BMPD3'){ |
---|
[22253] | 93 | global $page; |
---|
[31469] | 94 | if (empty($_POST['check_BMPD'])){ |
---|
[22253] | 95 | array_push($page['warnings'], l10n('You need to confirm')); |
---|
[31469] | 96 | }else{ |
---|
| 97 | if (isset($_POST['check_BMPD4'])){ |
---|
| 98 | $_POST['BMPD3'] = null; |
---|
| 99 | } |
---|
| 100 | $datas = array(); |
---|
| 101 | foreach ($collection as $image_id){ |
---|
| 102 | array_push( |
---|
| 103 | $datas, |
---|
| 104 | array( |
---|
| 105 | 'id' => $image_id, |
---|
| 106 | 'comment' => $_POST['BMPD3'] |
---|
| 107 | ) |
---|
| 108 | ); |
---|
| 109 | } |
---|
| 110 | mass_updates( |
---|
| 111 | IMAGES_TABLE, |
---|
| 112 | array('primary' => array('id'), 'update' => array('comment')), |
---|
| 113 | $datas |
---|
| 114 | ); |
---|
[22253] | 115 | } |
---|
| 116 | } |
---|
[31469] | 117 | } |
---|
[22253] | 118 | |
---|
[22247] | 119 | ?> |
---|