|
52 | 52 | 'osm_tag_address_country_code' => false, |
53 | 53 | ); |
54 | 54 |
|
55 | | -if ( isset($_POST['osm_tag_submit']) ) |
| 55 | +// Check if tag_groups is present and active |
| 56 | +$query="SELECT COUNT(*) FROM ".PLUGINS_TABLE." WHERE `id`='tag_groups' AND `state`='active';"; |
| 57 | +list($tag_groups) = pwg_db_fetch_array( pwg_query($query) ); |
| 58 | +if ($tag_groups != 1) { |
| 59 | + $page['warnings'][] = "To use this feature you need the <a href='http://piwigo.org/ext/extension_view.php?eid=781' target='_blank'>tag_groups plugin</a> to be activate"; |
| 60 | +} |
| 61 | + |
| 62 | +// On submit |
| 63 | +if ( $tag_groups == 1 and isset($_POST['osm_tag_submit']) ) |
56 | 64 | { |
57 | 65 | // Override default value from the form |
58 | 66 | $sync_options = array( |
|
72 | 80 | ); |
73 | 81 |
|
74 | 82 | // TODO allow to filter on overwrite |
75 | | - // Define files which lat and long avaiable |
| 83 | + // Define files with lat and lon available |
76 | 84 | define('SQL_EXIF', "`latitude` IS NOT NULL AND `longitude` is NOT NULL"); |
77 | 85 | if ( $sync_options['cat_id']!=0 ) |
78 | 86 | { |
|
101 | 109 | foreach ($images as $image) |
102 | 110 | { |
103 | 111 | // Fech reverse location from API |
| 112 | + // http://wiki.openstreetmap.org/wiki/Nominatim |
104 | 113 | // https://nominatim.openstreetmap.org/reverse?format=xml&lat=51.082333&lon=10.366229&zoom=12 |
105 | 114 | // https://open.mapquestapi.com/nominatim/v1/reverse.php?format=xml&lat=48.858366666667&lon=2.2942166666667&zoom=12 |
106 | | - // http://wiki.openstreetmap.org/wiki/Nominatim |
107 | 115 | //$osm_url = "https://nominatim.openstreetmap.org/reverse?format=json&addressdetails=1&zoom=12&lat=". $image['latitude'] ."&lon=". $image['longitude']; |
108 | | - $osm_url = "https://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&addressdetails=1&zoom=12&lat=". $image['latitude'] ."&lon=". $image['longitude']; |
| 116 | + // As of Sept 2015 require a API KEY |
| 117 | + //$osm_url = "https://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&addressdetails=1&zoom=12&lat=". $image['latitude'] ."&lon=". $image['longitude']; |
| 118 | + //$osm_url = "http://localhost:8443/api/". $image['latitude'] ."/". $image['longitude']; |
| 119 | + $osm_url = "https://nominatim-xbgmsharp.rhcloud.com/api/". $image['latitude'] ."/". $image['longitude']; |
109 | 120 | //print $osm_url ."<br/>"; |
110 | 121 |
|
111 | 122 | // Ensure we do have PHP curl install |
112 | 123 | // Or should fallback to fopen |
113 | 124 | if (function_exists('curl_init')) |
114 | 125 | { |
115 | | - // Get cURL resource |
| 126 | + // Get Curl resource |
116 | 127 | $curl = curl_init(); |
117 | 128 | // Set some options http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy |
118 | 129 | curl_setopt_array($curl, array( |
|
127 | 138 | curl_close($curl); |
128 | 139 |
|
129 | 140 | } else { |
130 | | - // Curl module un available, use fopen |
| 141 | + // Curl module unavailable, use fopen |
131 | 142 | $opts = array( |
132 | 143 | 'http'=>array( |
133 | 144 | 'method'=>"GET", |
|
153 | 164 | //print_r($response); |
154 | 165 |
|
155 | 166 | // If reponse include [address] |
156 | | - if (isset($response) and isset($response['address']) and is_array($response['address'])) |
| 167 | + if (isset($response) and isset($response['success']) and isset($response['success'][0]) and isset($response['success'][0]['result']) |
| 168 | + and isset($response['success'][0]['result']['address']) and is_array($response['success'][0]['result']['address'])) |
157 | 169 | { |
| 170 | + $response['address'] = $response['success'][0]['result']['address']; |
158 | 171 | //print_r($response['address']); |
159 | 172 | //print_r($sync_options); |
160 | 173 | $tag_ids = array(); |
|
227 | 240 | ); |
228 | 241 | } |
229 | 242 |
|
230 | | -// Check if tag_groups is present and active |
231 | | -$query="SELECT COUNT(*) FROM ".PLUGINS_TABLE." WHERE `id`='tag_groups' AND `state`='active';"; |
232 | | -list($tag_groups) = pwg_db_fetch_array( pwg_query($query) ); |
233 | | -if ($tag_groups != 1) { |
234 | | - $page['warnings'][] = "To use this feature you need the <a href='http://piwigo.org/ext/extension_view.php?eid=781' target='_blank'>tag_groups plugin</a> to be activate"; |
235 | | -} |
236 | | - |
237 | 243 | $query = 'SELECT COUNT(*) FROM '.IMAGES_TABLE.' WHERE `latitude` IS NOT NULL and `longitude` IS NOT NULL '; |
238 | 244 | list($nb_geotagged) = pwg_db_fetch_array( pwg_query($query) ); |
239 | 245 |
|
|
0 commit comments