Skip to content

Commit 442f749

Browse files
committed
Updated Geo reverse address, now use API proxy.
1 parent 98989fe commit 442f749

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

admin/admin_tag.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@
5252
'osm_tag_address_country_code' => false,
5353
);
5454

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']) )
5664
{
5765
// Override default value from the form
5866
$sync_options = array(
@@ -72,7 +80,7 @@
7280
);
7381

7482
// TODO allow to filter on overwrite
75-
// Define files which lat and long avaiable
83+
// Define files with lat and lon available
7684
define('SQL_EXIF', "`latitude` IS NOT NULL AND `longitude` is NOT NULL");
7785
if ( $sync_options['cat_id']!=0 )
7886
{
@@ -101,18 +109,21 @@
101109
foreach ($images as $image)
102110
{
103111
// Fech reverse location from API
112+
// http://wiki.openstreetmap.org/wiki/Nominatim
104113
// https://nominatim.openstreetmap.org/reverse?format=xml&lat=51.082333&lon=10.366229&zoom=12
105114
// 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
107115
//$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'];
109120
//print $osm_url ."<br/>";
110121

111122
// Ensure we do have PHP curl install
112123
// Or should fallback to fopen
113124
if (function_exists('curl_init'))
114125
{
115-
// Get cURL resource
126+
// Get Curl resource
116127
$curl = curl_init();
117128
// Set some options http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
118129
curl_setopt_array($curl, array(
@@ -127,7 +138,7 @@
127138
curl_close($curl);
128139

129140
} else {
130-
// Curl module un available, use fopen
141+
// Curl module unavailable, use fopen
131142
$opts = array(
132143
'http'=>array(
133144
'method'=>"GET",
@@ -153,8 +164,10 @@
153164
//print_r($response);
154165

155166
// 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']))
157169
{
170+
$response['address'] = $response['success'][0]['result']['address'];
158171
//print_r($response['address']);
159172
//print_r($sync_options);
160173
$tag_ids = array();
@@ -227,13 +240,6 @@
227240
);
228241
}
229242

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-
237243
$query = 'SELECT COUNT(*) FROM '.IMAGES_TABLE.' WHERE `latitude` IS NOT NULL and `longitude` IS NOT NULL ';
238244
list($nb_geotagged) = pwg_db_fetch_array( pwg_query($query) );
239245

admin/admin_tag.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
9191
<input type="checkbox" name="osm_tag_address_postcode" value="true" {if $osm_tag_address_postcode}checked="checked"{/if}/> {'postcode'|@translate}<br />
9292
<input type="checkbox" name="osm_tag_address_country_code" value="true" {if $osm_tag_address_country_code}checked="checked"{/if}/> {'country_code'|@translate}<br />
9393
</div>
94-
<small>{'Create tag using one or multiple value from the adress part'|@translate}</small>
94+
<small>{'Create tag using one or multiple value from the address part'|@translate}</small>
9595
</li>
9696
</ul>
9797
</fieldset>

0 commit comments

Comments
 (0)