source: extensions/manage_properties_photos/initadmin.php

Last change on this file was 32902, checked in by ddtddt, 15 months ago

[manage_properties_photos] compatybilité php8

File size: 7.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Manage Properties Photos plugin for Piwigo by TEMMII                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2007-2023 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// +-----------------------------------------------------------------------+
21
22//add admin menu
23/*
24add_event_handler('get_admin_plugin_menu_links', 'add_info_photo_admin_menu');
25function add_info_photo_admin_menu($menu){
26  if (is_webmaster()){
27    load_language('plugin.lang', ADD_PROP_PHOTO_PATH);
28    $menu[] = array(
29        'NAME' => l10n('Manage properties photos'),
30        'URL' => ADD_PROP_PHOTO_ADMIN,
31    );
32  }
33     return $menu;
34}
35*/
36add_event_handler('tabsheet_before_select', 'aip_tabsheet_before_select',
37    EVENT_HANDLER_PRIORITY_NEUTRAL);
38
39function aip_tabsheet_before_select($sheets, $id){
40  global $template, $page;
41  if ($id == 'photo'){
42    $sheets['iap'] = array(
43      'caption' => l10n('Properties additionals'),
44      'url' => ADD_PROP_PHOTO_ADMIN.'-iap&amp;image_id='.$_GET['image_id'],
45      );
46  }
47  return $sheets;
48}
49
50//add manage by batch Manager
51add_event_handler('loc_end_element_set_global', 'MPP_loc_end_element_set_global');
52add_event_handler('element_set_global_action', 'MPP_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
53 
54function MPP_loc_end_element_set_global(){
55  global $template, $pwg_loaded_plugins;
56 
57  $template->assign(array(
58  'ADD_PROP_PHOTO_PATH'=> get_root_url() . ADD_PROP_PHOTO_PATH,
59  )); 
60 
61  $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_TABLE . ' WHERE edit=1';
62  $test = pwg_query($q);
63  $row = pwg_db_fetch_assoc($test);
64  if (!empty($row)){
65        $propertieslist = array();
66        $propertieslist2 = tab_add_info_by_photo();
67        if (isset($pwg_loaded_plugins['ExtendedDescription'])){
68                add_event_handler('AP_render_content', 'get_user_language_desc');
69                $template->assign('useED',1);
70      }else{
71        $template->assign('useED',0);
72      }
73                $template->assign('DATADATE', date('Y-m-d').' 10:05:05');
74        while ($info_select = pwg_db_fetch_assoc($propertieslist2)){
75                $items = array(
76                        'IDINFOPHO' => $info_select['id_prop_pho'],
77                        'AIPWORDING' => trigger_change('AP_render_content',$info_select['wording']),
78                        'AIPTYP' => $info_select['Typ'],
79                );
80                if($info_select['Typ']==4||$info_select['Typ']==5){
81                        $items['AIPDATAPROP'] =  json_encode(unserialize($info_select['dataprop']));
82                }else{
83                        $items['AIPDATAPROP'] = "";
84                }               
85                if($info_select['wording']=="**delpho**"){
86                        $items['AIPWORDING'] =l10n('Delete photo');
87                }
88                $template->append('info_select', $items);
89        }
90       
91    $template->set_filename('MMPP', realpath(ADD_PROP_PHOTO_PATH.'mmp.tpl'));
92    $template->assign('propertieslist', $propertieslist);
93    $template->append('element_set_global_plugins_actions', array(
94      'ID' => 'MPP', 
95      'NAME' => l10n('Change photos properties'), 
96      'CONTENT' => $template->parse('MMPP', true)
97        ));
98  }
99}
100 
101function MPP_element_set_global_action($action, $collection){
102  if ($action == 'MPP'){
103        global $page,$template,$prefixeTable;
104    $id_prop_pho= $_POST['IDMPP'];
105        $Typ=$_POST['invisibleTyp'];
106        if($Typ==2){
107                $data= $_POST['datadate'];
108        }else if($Typ==4){
109                $data= $_POST['dataselect'];
110        }else if($Typ==5){
111                $data= $_POST['radioselect'];
112        }else{
113                $data= $_POST['dataglob'];
114        }
115       
116  if($Typ==2){
117        if (!empty($_POST['check_MPP'])){
118          foreach ($collection as $image_id){
119                $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_datadate WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho;
120                pwg_query($query);
121      }
122    }else{
123      foreach ($collection as $image_id){
124            $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_DATADATE_TABLE . ' WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho;
125        $test = pwg_query($q);
126        $row = pwg_db_fetch_assoc($test);
127        if (!empty($row)) {
128                  if ($data != '') {
129                        $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_datadate SET datadate="' . $data . '" WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho;
130                        pwg_query($query);
131                  }else{
132                        $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_datadate WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho;
133                        pwg_query($query);
134                  }
135        }else if ($data != ''){
136            $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_datadate(id_img,id_prop_pho,datadate) VALUES (' . $image_id . ',' . $id_prop_pho . ',"' . $data . '");';
137            pwg_query($query);
138        }
139      }
140    }
141  }else{
142        if (!empty($_POST['check_MPP'])){
143          foreach ($collection as $image_id){
144                $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho;
145                pwg_query($query);
146      }
147    }else{
148      foreach ($collection as $image_id){
149            $q = 'SELECT id_img FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho;
150        $test = pwg_query($q);
151        $row = pwg_db_fetch_assoc($test);
152        if (!empty($row)) {
153                  if ($data != '') {
154                        $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_data SET data="' . $data . '" WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho;
155                        pwg_query($query);
156                  }else{
157                        $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho;
158                        pwg_query($query);
159                  }
160        }else if ($data != ''){
161            $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_data(id_img,id_prop_pho,data) VALUES (' . $image_id . ',' . $id_prop_pho . ',"' . $data . '");';
162            pwg_query($query);
163        }
164      }
165    }
166  }
167  }
168}
169 
170add_event_handler('loc_begin_admin_page', 'mpp_change_admin_show');
171function mpp_change_admin_show(){
172  global $template;
173  $template->set_prefilter('config', 'mpp_change_admin_show_prefilter');
174}
175
176function mpp_change_admin_show_prefilter($content){
177  $search = '#(<fieldset id="pictureInfoConf">).*</fieldset>#ms';
178  return preg_replace($search, '
179  <fieldset id="pictureInfoConf">
180    <legend>{\'Photo Properties\'|@translate}</legend>
181          <a href="'.ADD_PROP_PHOTO_ADMIN.'"><span class="icon-arrows-cw"></span>{\'Manage properties photos\'|@translate}</a>
182  </fieldset>
183  ', $content);
184}
Note: See TracBrowser for help on using the repository browser.