[30631] | 1 | <?php |
---|
[31361] | 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Manage Properties Photos plugin for Piwigo | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[31409] | 5 | // | Copyright(C) 2014-2016 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){ |
---|
[30702] | 26 | load_language('plugin.lang', ADD_PROP_PHOTO_PATH); |
---|
[30631] | 27 | $menu[] = array( |
---|
[30702] | 28 | 'NAME' => l10n('Manage properties photos'), |
---|
| 29 | 'URL' => ADD_PROP_PHOTO_ADMIN, |
---|
[30631] | 30 | ); |
---|
| 31 | return $menu; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | add_event_handler('tabsheet_before_select', 'aip_tabsheet_before_select', |
---|
| 35 | EVENT_HANDLER_PRIORITY_NEUTRAL); |
---|
| 36 | |
---|
[31553] | 37 | function aip_tabsheet_before_select($sheets, $id){ |
---|
| 38 | global $template, $page; |
---|
| 39 | if ($id == 'photo'){ |
---|
[30631] | 40 | $sheets['iap'] = array( |
---|
[30702] | 41 | 'caption' => l10n('Properties additionals'), |
---|
| 42 | 'url' => ADD_PROP_PHOTO_ADMIN.'-iap&image_id='.$_GET['image_id'], |
---|
[30631] | 43 | ); |
---|
| 44 | } |
---|
| 45 | return $sheets; |
---|
| 46 | } |
---|
| 47 | |
---|
[31361] | 48 | //add manage by batch Manager |
---|
[31360] | 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 | |
---|
[31553] | 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'){ |
---|
[31363] | 62 | add_event_handler('AP_render_content', 'get_user_language_desc'); |
---|
| 63 | $template->assign('useED',1); |
---|
[31553] | 64 | }else{ |
---|
[31363] | 65 | $template->assign('useED',0); |
---|
[31553] | 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 | )); |
---|
[31360] | 77 | } |
---|
[31553] | 78 | } |
---|
[31360] | 79 | |
---|
[31553] | 80 | function MPP_element_set_global_action($action, $collection){ |
---|
| 81 | if ($action == 'MPP'){ |
---|
| 82 | global $page,$template,$prefixeTable; |
---|
| 83 | $id_prop_pho= $_POST['IDMPP']; |
---|
[31406] | 84 | $data= $_POST['dataglob']; |
---|
[31553] | 85 | if (!empty($_POST['check_MPP'])){ |
---|
| 86 | foreach ($collection as $image_id){ |
---|
[31406] | 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 | } |
---|
[31553] | 90 | }else{ |
---|
| 91 | foreach ($collection as $image_id){ |
---|
[31360] | 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) { |
---|
[31553] | 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 != ''){ |
---|
[31360] | 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 | } |
---|
[31553] | 110 | } |
---|
[31360] | 111 | |
---|
[31553] | 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> |
---|
[31554] | 123 | <a href="'.ADD_PROP_PHOTO_ADMIN.'"><span class="icon-arrows-cw"></span>{\'Manage properties photos\'|@translate}</a> |
---|
[31553] | 124 | </fieldset> |
---|
| 125 | ', $content); |
---|
| 126 | } |
---|