source: extensions/bmp_description/initadmin.php @ 32021

Last change on this file since 32021 was 31469, checked in by ddtddt, 8 years ago

[extensions] - bmp_description - 2.8

File size: 4.7 KB
Line 
1<?php
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// +-----------------------------------------------------------------------+
21if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
22
23load_language('plugin.lang', BMPD_PATH);
24
25global $prefilter;
26 
27add_event_handler('get_batch_manager_prefilters', 'BMPD_add_batch_manager_prefilters');
28add_event_handler('perform_batch_manager_prefilters', 'BMPD_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
29
30function BMPD_add_batch_manager_prefilters($prefilters){
31  array_push($prefilters, array(
32    'ID' => 'BMPD',
33    'NAME' => l10n('With no description'),
34  ));
35        return $prefilters;
36}
37
38function BMPD_perform_batch_manager_prefilters($filter_sets, $prefilter){
39  if ($prefilter == 'BMPD'){
40    $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE comment is null;';
41    $filter_sets[] = array_from_query($query, 'id');
42  }
43  return $filter_sets;
44}
45
46add_event_handler('get_batch_manager_prefilters', 'BMPD2_add_batch_manager_prefilters');
47add_event_handler('perform_batch_manager_prefilters', 'BMPD2_perform_batch_manager_prefilters', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
48
49function BMPD2_add_batch_manager_prefilters($prefilters){
50  array_push($prefilters, array(
51    'ID' => 'BMPD2',
52    'NAME' => l10n('With description'),
53  ));
54  return $prefilters;
55}
56
57function BMPD2_perform_batch_manager_prefilters($filter_sets, $prefilter){
58  if ($prefilter == 'BMPD2'){
59    $query = 'SELECT id FROM '.IMAGES_TABLE.' WHERE comment is not null ;';
60    $filter_sets[] = array_from_query($query, 'id');
61  }
62  return $filter_sets;
63}
64
65add_event_handler('loc_end_element_set_global', 'BMPD_loc_end_element_set_global');
66add_event_handler('element_set_global_action', 'BMPD_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
67 
68function BMPD_loc_end_element_set_global(){
69        global $template;
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                }
84        $template->append('element_set_global_plugins_actions', array(
85      'ID' => 'BMPD3', 
86      'NAME' => l10n('Set description'), 
87      'CONTENT' => $templatebmpd,
88        ));
89 }
90
91function BMPD_element_set_global_action($action, $collection) {
92  if ($action == 'BMPD3'){
93    global $page;
94    if (empty($_POST['check_BMPD'])){
95      array_push($page['warnings'], l10n('You need to confirm'));
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          );
115    }
116  }
117}
118
119?>
Note: See TracBrowser for help on using the repository browser.