* * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ************************************************/ // Check whether we are indeed included by Piwigo. if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); // Hook to add a new filter in the batch mode add_event_handler('get_batch_manager_prefilters', 'osm_get_batch_manager_prefilters'); function osm_get_batch_manager_prefilters($prefilters) { $prefilters[] = array('ID' => 'osm0', 'NAME' => l10n('OSM Geotagged')); $prefilters[] = array('ID' => 'osm1', 'NAME' => l10n('OSM Not geotagged')); return $prefilters; } // Hook to perfom the filter in the batch mode add_event_handler('perform_batch_manager_prefilters', 'osm_perform_batch_manager_prefilters', 50, 2); function osm_perform_batch_manager_prefilters($filter_sets, $prefilter) { if ($prefilter==="osm0") $filter = "`lat` IS NOT NULL and `lon` IS NOT NULL"; else if ($prefilter==="osm1") $filter = "`lat` IS NULL OR `lon` IS NULL"; if ( isset($filter) ) { $query = "SELECT id FROM ".IMAGES_TABLE." WHERE ".$filter; $filter_sets[] = array_from_query($query, 'id'); } return $filter_sets; } // Hook to show action when selected add_event_handler('loc_end_element_set_global', 'osm_loc_end_element_set_global'); function osm_loc_end_element_set_global() { global $template; $template->append('element_set_global_plugins_actions', array('ID' => 'openstreetmap', 'NAME'=>l10n('OSM GeoTag'), 'CONTENT' => ' (Empty values will erase coordinates) ')); } // Hook to perform the action on in global mode add_event_handler('element_set_global_action', 'osm_element_set_global_action', 50, 2); function osm_element_set_global_action($action, $collection) { if ($action!=="openstreetmap") return; global $page; $lat = trim($_POST['osmlat']); $lon = trim($_POST['osmlon']); if ( strlen($lat)>0 and strlen($lon)>0 ) { if ( (double)$lat<=90 and (double)$lat>=-90 and (double)$lon<=180 and (double)$lon>=-180 ) $update_query = 'lat='.$lat.', lon='.$lon; else $page['errors'][] = 'Invalid lat or lon value'; } elseif ( strlen($lat)==0 and strlen($lon)==0 ) $update_query = 'lat=NULL, lon=NULL'; else $page['errors'][] = 'Both lat/lon must be empty or not empty'; if (isset($update_query)) { $update_query = 'UPDATE '.IMAGES_TABLE.' SET '.$update_query.' WHERE id IN ('.implode(',',$collection).')'; pwg_query($update_query); } } // Hook to perform the action on in single mode add_event_handler('loc_begin_element_set_unit', 'osm_loc_begin_element_set_unit'); function osm_loc_begin_element_set_unit() { global $page; if (!isset($_POST['submit'])) return; $collection = explode(',', $_POST['element_ids']); $query = "SELECT `id`, `lat`, `lon` FROM ".IMAGES_TABLE." WHERE id IN (".implode(',',$collection).")"; $datas = array(); $errors = array(); $form_errors = 0; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { if (!isset($_POST['osmlat-'.$row['id']])) { $form_errors++; continue; } $error = false; $data = array( 'id' => $row['id'], 'lat' => trim($_POST['osmlat-'.$row['id']]), 'lon' => trim($_POST['osmlon-'.$row['id']]) ); if ( strlen($data['lat'])>0 and strlen($data['lon'])>0 ) { if ( (double)$data['lat']>90 or (double)$data['lat']<-90 or (double)$data['lon']>180 or (double)$data['lon']<-180 ) $error = true; } elseif ( strlen($data['lat'])==0 and strlen($data['lon'])==0 ) { // nothing } else { $error = true; } if ($error) $errors[] = $row['name']; else $datas[] = $data; } mass_updates( IMAGES_TABLE, array( 'primary' => array('id'), 'update' => array('lat', 'lon') ), $datas ); if (count($errors)>0) { $page['errors'][] = 'Invalid lat or lon value for files: '.implode(', ', $errors); } if ($form_errors) $page['errors'][] = 'OpenStreetMap: Invalid form submission for '.$form_errors.' photos'; } // Hoook for batch manager in single mode add_event_handler('loc_end_element_set_unit', 'osm_loc_end_element_set_unit'); function osm_loc_end_element_set_unit() { global $template, $conf, $page, $is_category, $category_info; $template->set_prefilter('batch_manager_unit', 'osm_prefilter_batch_manager_unit'); } function osm_prefilter_batch_manager_unit($content) { $needle = ''; $pos = strpos($content, $needle); if ($pos!==false) { $add = '{\'OSM Geotag\'|@translate} '; $content = substr_replace($content, $add, $pos, 0); } return $content; }