1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Manage Properties Photos plugin for Piwigo | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2014-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 | // +-----------------------------------------------------------------------+ |
---|
21 | |
---|
22 | //add admin menu |
---|
23 | add_event_handler('get_admin_plugin_menu_links', 'add_info_photo_admin_menu'); |
---|
24 | |
---|
25 | function add_info_photo_admin_menu($menu){ |
---|
26 | load_language('plugin.lang', ADD_PROP_PHOTO_PATH); |
---|
27 | $menu[] = array( |
---|
28 | 'NAME' => l10n('Manage properties photos'), |
---|
29 | 'URL' => ADD_PROP_PHOTO_ADMIN, |
---|
30 | ); |
---|
31 | return $menu; |
---|
32 | } |
---|
33 | |
---|
34 | add_event_handler('tabsheet_before_select', 'aip_tabsheet_before_select', |
---|
35 | EVENT_HANDLER_PRIORITY_NEUTRAL); |
---|
36 | |
---|
37 | function aip_tabsheet_before_select($sheets, $id){ |
---|
38 | global $template, $page; |
---|
39 | if ($id == 'photo'){ |
---|
40 | $sheets['iap'] = array( |
---|
41 | 'caption' => l10n('Properties additionals'), |
---|
42 | 'url' => ADD_PROP_PHOTO_ADMIN.'-iap&image_id='.$_GET['image_id'], |
---|
43 | ); |
---|
44 | } |
---|
45 | return $sheets; |
---|
46 | } |
---|
47 | |
---|
48 | //add manage by batch Manager |
---|
49 | add_event_handler('loc_end_element_set_global', 'MPP_loc_end_element_set_global'); |
---|
50 | add_event_handler('element_set_global_action', 'MPP_element_set_global_action', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); |
---|
51 | |
---|
52 | function MPP_loc_end_element_set_global(){ |
---|
53 | global $template; |
---|
54 | $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_TABLE . ' WHERE edit=1'; |
---|
55 | $test = pwg_query($q); |
---|
56 | $row = pwg_db_fetch_assoc($test); |
---|
57 | if (count($row) > 0){ |
---|
58 | $propertieslist = array(); |
---|
59 | $propertieslist2 = tab_add_info_by_photo(); |
---|
60 | $PAED = pwg_db_fetch_assoc(pwg_query("SELECT state FROM " . PLUGINS_TABLE . " WHERE id = 'ExtendedDescription';")); |
---|
61 | if($PAED['state'] == 'active'){ |
---|
62 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
63 | $template->assign('useED',1); |
---|
64 | }else{ |
---|
65 | $template->assign('useED',0); |
---|
66 | } |
---|
67 | while ($row = pwg_db_fetch_assoc($propertieslist2)){ |
---|
68 | $propertieslist[$row['id_prop_pho']] = trigger_change('AP_render_content', $row['wording']); |
---|
69 | } |
---|
70 | $template->set_filename('MMPP', realpath(ADD_PROP_PHOTO_PATH.'mmp.tpl')); |
---|
71 | $template->assign('propertieslist', $propertieslist); |
---|
72 | $template->append('element_set_global_plugins_actions', array( |
---|
73 | 'ID' => 'MPP', |
---|
74 | 'NAME' => l10n('Change photos properties'), |
---|
75 | 'CONTENT' => $template->parse('MMPP', true) |
---|
76 | )); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | function MPP_element_set_global_action($action, $collection){ |
---|
81 | if ($action == 'MPP'){ |
---|
82 | global $page,$template,$prefixeTable; |
---|
83 | $id_prop_pho= $_POST['IDMPP']; |
---|
84 | $data= $_POST['dataglob']; |
---|
85 | if (!empty($_POST['check_MPP'])){ |
---|
86 | foreach ($collection as $image_id){ |
---|
87 | $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
88 | pwg_query($query); |
---|
89 | } |
---|
90 | }else{ |
---|
91 | foreach ($collection as $image_id){ |
---|
92 | $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
93 | $test = pwg_query($q); |
---|
94 | $row = pwg_db_fetch_assoc($test); |
---|
95 | if (count($row) > 0) { |
---|
96 | if ($data != '') { |
---|
97 | $query = 'UPDATE ' . $prefixeTable . 'add_properties_photos_data SET data="' . $data . '" WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
98 | pwg_query($query); |
---|
99 | }else{ |
---|
100 | $query = 'DELETE FROM ' . $prefixeTable . 'add_properties_photos_data WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
101 | pwg_query($query); |
---|
102 | } |
---|
103 | }else if ($data != ''){ |
---|
104 | $query = 'INSERT ' . $prefixeTable . 'add_properties_photos_data(id_img,id_prop_pho,data) VALUES (' . $image_id . ',' . $id_prop_pho . ',"' . $data . '");'; |
---|
105 | pwg_query($query); |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | add_event_handler('loc_begin_admin_page', 'mpp_change_admin_show'); |
---|
113 | function mpp_change_admin_show(){ |
---|
114 | global $template; |
---|
115 | $template->set_prefilter('config', 'mpp_change_admin_show_prefilter'); |
---|
116 | } |
---|
117 | |
---|
118 | function mpp_change_admin_show_prefilter($content, &$smarty){ |
---|
119 | $search = '#(<fieldset id="pictureInfoConf">).*</fieldset>#ms'; |
---|
120 | return preg_replace($search, ' |
---|
121 | <fieldset id="pictureInfoConf"> |
---|
122 | <legend>{\'Photo Properties\'|@translate}</legend> |
---|
123 | <a href="'.ADD_PROP_PHOTO_ADMIN.'"><span class="icon-arrows-cw"></span>{\'Manage properties photos\'|@translate}</a> |
---|
124 | </fieldset> |
---|
125 | ', $content); |
---|
126 | } |
---|