[30631] | 1 | <?php |
---|
[31361] | 2 | // +-----------------------------------------------------------------------+ |
---|
[32135] | 3 | // | Manage Properties Photos plugin for Piwigo by TEMMII | |
---|
[31361] | 4 | // +-----------------------------------------------------------------------+ |
---|
[32135] | 5 | // | Copyright(C) 2007-2020 ddtddt http://temmii.com/piwigo/ | |
---|
[31361] | 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 | // +-----------------------------------------------------------------------+ |
---|
[30631] | 21 | |
---|
[31360] | 22 | //add admin menu |
---|
[30631] | 23 | add_event_handler('get_admin_plugin_menu_links', 'add_info_photo_admin_menu'); |
---|
| 24 | |
---|
[31553] | 25 | function add_info_photo_admin_menu($menu){ |
---|
[32188] | 26 | if (is_webmaster()){ |
---|
[30702] | 27 | load_language('plugin.lang', ADD_PROP_PHOTO_PATH); |
---|
[30631] | 28 | $menu[] = array( |
---|
[30702] | 29 | 'NAME' => l10n('Manage properties photos'), |
---|
| 30 | 'URL' => ADD_PROP_PHOTO_ADMIN, |
---|
[30631] | 31 | ); |
---|
[32188] | 32 | } |
---|
[30631] | 33 | return $menu; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | add_event_handler('tabsheet_before_select', 'aip_tabsheet_before_select', |
---|
| 37 | EVENT_HANDLER_PRIORITY_NEUTRAL); |
---|
| 38 | |
---|
[31553] | 39 | function aip_tabsheet_before_select($sheets, $id){ |
---|
| 40 | global $template, $page; |
---|
| 41 | if ($id == 'photo'){ |
---|
[30631] | 42 | $sheets['iap'] = array( |
---|
[30702] | 43 | 'caption' => l10n('Properties additionals'), |
---|
| 44 | 'url' => ADD_PROP_PHOTO_ADMIN.'-iap&image_id='.$_GET['image_id'], |
---|
[30631] | 45 | ); |
---|
| 46 | } |
---|
| 47 | return $sheets; |
---|
| 48 | } |
---|
| 49 | |
---|
[31361] | 50 | //add manage by batch Manager |
---|
[31360] | 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 | |
---|
[31553] | 54 | function MPP_loc_end_element_set_global(){ |
---|
[32221] | 55 | global $template, $pwg_loaded_plugins; |
---|
[32135] | 56 | |
---|
| 57 | $template->assign(array( |
---|
| 58 | 'ADD_PROP_PHOTO_PATH'=> get_root_url() . ADD_PROP_PHOTO_PATH, |
---|
| 59 | )); |
---|
| 60 | |
---|
[31553] | 61 | $q = 'SELECT 1 FROM ' . ADD_PROP_PHOTO_TABLE . ' WHERE edit=1'; |
---|
| 62 | $test = pwg_query($q); |
---|
| 63 | $row = pwg_db_fetch_assoc($test); |
---|
[32180] | 64 | if (!empty($row)){ |
---|
[31553] | 65 | $propertieslist = array(); |
---|
| 66 | $propertieslist2 = tab_add_info_by_photo(); |
---|
[32221] | 67 | if (isset($pwg_loaded_plugins['ExtendedDescription'])){ |
---|
[31363] | 68 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
| 69 | $template->assign('useED',1); |
---|
[31553] | 70 | }else{ |
---|
[31363] | 71 | $template->assign('useED',0); |
---|
[31553] | 72 | } |
---|
[32162] | 73 | $template->assign('DATADATE', date('Y-m-d').' 10:05:05'); |
---|
[32135] | 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'])); |
---|
[32162] | 82 | } |
---|
[32135] | 83 | if($info_select['wording']=="**delpho**"){ |
---|
| 84 | $items['AIPWORDING'] =l10n('Delete photo'); |
---|
| 85 | } |
---|
| 86 | $template->append('info_select', $items); |
---|
| 87 | } |
---|
| 88 | |
---|
[31553] | 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 | )); |
---|
[31360] | 96 | } |
---|
[31553] | 97 | } |
---|
[31360] | 98 | |
---|
[31553] | 99 | function MPP_element_set_global_action($action, $collection){ |
---|
| 100 | if ($action == 'MPP'){ |
---|
| 101 | global $page,$template,$prefixeTable; |
---|
| 102 | $id_prop_pho= $_POST['IDMPP']; |
---|
[32135] | 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){ |
---|
[31553] | 115 | if (!empty($_POST['check_MPP'])){ |
---|
| 116 | foreach ($collection as $image_id){ |
---|
[32135] | 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){ |
---|
[31406] | 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 | } |
---|
[31553] | 145 | }else{ |
---|
| 146 | foreach ($collection as $image_id){ |
---|
[32135] | 147 | $q = 'SELECT id_img FROM ' . ADD_PROP_PHOTO_DATA_TABLE . ' WHERE id_img=' . $image_id . ' AND id_prop_pho=' . $id_prop_pho; |
---|
[31360] | 148 | $test = pwg_query($q); |
---|
| 149 | $row = pwg_db_fetch_assoc($test); |
---|
[32135] | 150 | if (!empty($row)) { |
---|
[31553] | 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 != ''){ |
---|
[31360] | 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 | } |
---|
[32135] | 165 | } |
---|
[31553] | 166 | } |
---|
[31360] | 167 | |
---|
[31553] | 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, &$smarty){ |
---|
| 175 | $search = '#(<fieldset id="pictureInfoConf">).*</fieldset>#ms'; |
---|
| 176 | return preg_replace($search, ' |
---|
| 177 | <fieldset id="pictureInfoConf"> |
---|
| 178 | <legend>{\'Photo Properties\'|@translate}</legend> |
---|
[31554] | 179 | <a href="'.ADD_PROP_PHOTO_ADMIN.'"><span class="icon-arrows-cw"></span>{\'Manage properties photos\'|@translate}</a> |
---|
[31553] | 180 | </fieldset> |
---|
| 181 | ', $content); |
---|
| 182 | } |
---|