1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Manage Properties Photos plugin for Piwigo by TEMMII | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2007-2022 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 | /* |
---|
24 | add_event_handler('get_admin_plugin_menu_links', 'add_info_photo_admin_menu'); |
---|
25 | function 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 | */ |
---|
36 | add_event_handler('tabsheet_before_select', 'aip_tabsheet_before_select', |
---|
37 | EVENT_HANDLER_PRIORITY_NEUTRAL); |
---|
38 | |
---|
39 | function 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&image_id='.$_GET['image_id'], |
---|
45 | ); |
---|
46 | } |
---|
47 | return $sheets; |
---|
48 | } |
---|
49 | |
---|
50 | //add manage by batch Manager |
---|
51 | add_event_handler('loc_end_element_set_global', 'MPP_loc_end_element_set_global'); |
---|
52 | add_event_handler('element_set_global_action', 'MPP_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
53 | |
---|
54 | function 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 | } |
---|
83 | if($info_select['wording']=="**delpho**"){ |
---|
84 | $items['AIPWORDING'] =l10n('Delete photo'); |
---|
85 | } |
---|
86 | $template->append('info_select', $items); |
---|
87 | } |
---|
88 | |
---|
89 | $template->set_filename('MMPP', realpath(ADD_PROP_PHOTO_PATH.'mmp.tpl')); |
---|
90 | $template->assign('propertieslist', $propertieslist); |
---|
91 | $template->append('element_set_global_plugins_actions', array( |
---|
92 | 'ID' => 'MPP', |
---|
93 | 'NAME' => l10n('Change photos properties'), |
---|
94 | 'CONTENT' => $template->parse('MMPP', true) |
---|
95 | )); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | function MPP_element_set_global_action($action, $collection){ |
---|
100 | if ($action == 'MPP'){ |
---|
101 | global $page,$template,$prefixeTable; |
---|
102 | $id_prop_pho= $_POST['IDMPP']; |
---|
103 | $Typ=$_POST['invisibleTyp']; |
---|
104 | if($Typ==2){ |
---|
105 | $data= $_POST['datadate']; |
---|
106 | }else if($Typ==4){ |
---|
107 | $data= $_POST['dataselect']; |
---|
108 | }else if($Typ==5){ |
---|
109 | $data= $_POST['radioselect']; |
---|
110 | }else{ |
---|
111 | $data= $_POST['dataglob']; |
---|
112 | } |
---|
113 | |
---|
114 | if($Typ==2){ |
---|
115 | if (!empty($_POST['check_MPP'])){ |
---|
116 | foreach ($collection as $image_id){ |
---|
117 | $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_datadate WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
118 | pwg_query($query); |
---|
119 | } |
---|
120 | }else{ |
---|
121 | foreach ($collection as $image_id){ |
---|
122 | $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_DATADATE_TABLE . ' WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
123 | $test = pwg_query($q); |
---|
124 | $row = pwg_db_fetch_assoc($test); |
---|
125 | if (!empty($row)) { |
---|
126 | if ($data != '') { |
---|
127 | $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_datadate SET datadate="' . $data . '" WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
128 | pwg_query($query); |
---|
129 | }else{ |
---|
130 | $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_datadate WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
131 | pwg_query($query); |
---|
132 | } |
---|
133 | }else if ($data != ''){ |
---|
134 | $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_datadate(id_img,id_prop_pho,datadate) VALUES (' . $image_id . ',' . $id_prop_pho . ',"' . $data . '");'; |
---|
135 | pwg_query($query); |
---|
136 | } |
---|
137 | } |
---|
138 | } |
---|
139 | }else{ |
---|
140 | if (!empty($_POST['check_MPP'])){ |
---|
141 | foreach ($collection as $image_id){ |
---|
142 | $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
143 | pwg_query($query); |
---|
144 | } |
---|
145 | }else{ |
---|
146 | foreach ($collection as $image_id){ |
---|
147 | $q = 'SELECT id_img FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
148 | $test = pwg_query($q); |
---|
149 | $row = pwg_db_fetch_assoc($test); |
---|
150 | if (!empty($row)) { |
---|
151 | if ($data != '') { |
---|
152 | $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_data SET data="' . $data . '" WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
153 | pwg_query($query); |
---|
154 | }else{ |
---|
155 | $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
156 | pwg_query($query); |
---|
157 | } |
---|
158 | }else if ($data != ''){ |
---|
159 | $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_data(id_img,id_prop_pho,data) VALUES (' . $image_id . ',' . $id_prop_pho . ',"' . $data . '");'; |
---|
160 | pwg_query($query); |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | add_event_handler('loc_begin_admin_page', 'mpp_change_admin_show'); |
---|
169 | function mpp_change_admin_show(){ |
---|
170 | global $template; |
---|
171 | $template->set_prefilter('config', 'mpp_change_admin_show_prefilter'); |
---|
172 | } |
---|
173 | |
---|
174 | function mpp_change_admin_show_prefilter($content){ |
---|
175 | $search = '#(<fieldset id="pictureInfoConf">).*</fieldset>#ms'; |
---|
176 | return preg_replace($search, ' |
---|
177 | <fieldset id="pictureInfoConf"> |
---|
178 | <legend>{\'Photo Properties\'|@translate}</legend> |
---|
179 | <a href="'.ADD_PROP_PHOTO_ADMIN.'"><span class="icon-arrows-cw"></span>{\'Manage properties photos\'|@translate}</a> |
---|
180 | </fieldset> |
---|
181 | ', $content); |
---|
182 | } |
---|