source: extensions/bmp_description/initadmin.php @ 32296

Last change on this file since 32296 was 32220, checked in by ddtddt, 4 years ago
File size: 4.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Batch Manager, Photo Description by plugin for Piwigo by TEMMII       |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2013-2020 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// +-----------------------------------------------------------------------+
21if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
22
23global $prefilter;
24 
25add_event_handler('get_batch_manager_prefilters', 'BMPD_add_batch_manager_prefilters');
26add_event_handler('perform_batch_manager_prefilters', 'BMPD_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
27
28function BMPD_add_batch_manager_prefilters($prefilters){
29  array_push($prefilters, array(
30    'ID' => 'BMPD',
31    'NAME' => l10n('With no description'),
32  ));
33        return $prefilters;
34}
35
36function BMPD_perform_batch_manager_prefilters($filter_sets, $prefilter){
37  if ($prefilter == 'BMPD'){
38    $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE comment is null;';
39    $filter_sets[] = array_from_query($query, 'id');
40  }
41  return $filter_sets;
42}
43
44add_event_handler('get_batch_manager_prefilters', 'BMPD2_add_batch_manager_prefilters');
45add_event_handler('perform_batch_manager_prefilters', 'BMPD2_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
46
47function BMPD2_add_batch_manager_prefilters($prefilters){
48  array_push($prefilters, array(
49    'ID' => 'BMPD2',
50    'NAME' => l10n('With description'),
51  ));
52  return $prefilters;
53}
54
55function BMPD2_perform_batch_manager_prefilters($filter_sets, $prefilter){
56  if ($prefilter == 'BMPD2'){
57    $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE comment is not null ;';
58    $filter_sets[] = array_from_query($query, 'id');
59  }
60  return $filter_sets;
61}
62
63add_event_handler('loc_end_element_set_global', 'BMPD_loc_end_element_set_global');
64add_event_handler('element_set_global_action', 'BMPD_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
65 
66function BMPD_loc_end_element_set_global(){
67  global $template, $pwg_loaded_plugins;
68        if (isset($pwg_loaded_plugins['ExtendedDescription'])){
69          $templatebmpd='
70           <input type="checkbox" name="check_BMPD4"> '.l10n('remove description').'<br>
71           <textarea rows="5" cols="50" placeholder="'.l10n('Type here the description')."  /  ".l10n('Use Extended Description tags...').'" class="description" name="BMPD3" id="BMPD3"></textarea><br>
72           <input type="checkbox" name="check_BMPD"> '.l10n('confirm').'
73          ';
74        }else{
75          $templatebmpd='
76           <input type="checkbox" name="check_BMPD4"> '.l10n('remove description').'<br>
77           <textarea rows="5" cols="50" placeholder="'.l10n('Type here the description').'" class="description" name="BMPD3" id="BMPD3"></textarea><br>
78           <input type="checkbox" name="check_BMPD"> '.l10n('confirm').'
79          ';
80        }
81  $template->append('element_set_global_plugins_actions', array(
82        'ID' => 'BMPD3', 
83        'NAME' => l10n('Set description'), 
84        'CONTENT' => $templatebmpd,
85  ));
86}
87
88function BMPD_element_set_global_action($action, $collection){
89  if ($action == 'BMPD3'){
90    global $page;
91    if (empty($_POST['check_BMPD'])){
92      array_push($page['warnings'], l10n('You need to confirm'));
93    }else{
94          if (isset($_POST['check_BMPD4'])){
95        $_POST['BMPD3'] = null;
96      }
97          $datas = array();
98                foreach ($collection as $image_id){
99                  array_push(
100                        $datas,
101                        array(
102                          'id' => $image_id,
103                          'comment' => $_POST['BMPD3']
104                          )
105                  );
106                }
107          mass_updates(
108                IMAGES_TABLE,
109                array('primary' => array('id'), 'update' => array('comment')),
110                $datas
111          );
112    }
113  }
114}
115
116?>
Note: See TracBrowser for help on using the repository browser.