Skip to content

Commit d376e5d

Browse files
committed
Improve tag management
- Add language parameterfor tag creation - Really apply simulate - Save option
1 parent 00121af commit d376e5d

2 files changed

Lines changed: 40 additions & 23 deletions

File tree

admin/admin_tag.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
'osm_tag_address_state' => isset($_POST['osm_tag_address_state']),
7777
'osm_tag_address_country' => isset($_POST['osm_tag_address_country']),
7878
'osm_tag_address_postcode' => isset($_POST['osm_tag_address_postcode']),
79-
'osm_tag_address_country_code' => isset($_POST['osm_tag_address_country_code'])
79+
'osm_tag_address_country_code' => isset($_POST['osm_tag_address_country_code']),
80+
'language' => preg_split("/_/",$_POST['language'])[0]
8081
);
8182

8283
// TODO allow to filter on overwrite
@@ -116,7 +117,7 @@
116117
// As of Sept 2015 require a API KEY
117118
//$osm_url = "https://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&addressdetails=1&zoom=12&lat=". $image['latitude'] ."&lon=". $image['longitude'];
118119
//$osm_url = "http://localhost:8443/api/". $image['latitude'] ."/". $image['longitude'];
119-
$osm_url = "https://nominatim-xbgmsharp.rhcloud.com/api/". $image['latitude'] ."/". $image['longitude'];
120+
$osm_url = "https://nominatim-xbgmsharp.rhcloud.com/api/". $image['latitude'] ."/". $image['longitude'] ."/". $sync_options['language'];
120121
//print $osm_url ."<br/>";
121122

122123
// Ensure we do have PHP curl install
@@ -170,47 +171,48 @@
170171
$response['address'] = $response['success'][0]['result']['address'];
171172
//print_r($response['address']);
172173
//print_r($sync_options);
173-
$tag_ids = array();
174174
$tag_names = array();
175175
if (isset($response['address']['suburb']) and $sync_options['osm_tag_address_suburb']) {
176-
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['suburb']) );
177176
array_push( $tag_names, $response['address']['suburb'] );
178177
}
179178
if (isset($response['address']['city_district']) and $sync_options['osm_tag_address_city_district']) {
180-
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['city_district']) );
181179
array_push( $tag_names, $response['address']['city_district'] );
182180
}
183181
if (isset($response['address']['city']) and $sync_options['osm_tag_address_city']) {
184-
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['city']) );
185182
array_push( $tag_names, $response['address']['city'] );
186183
}
187184
if (isset($response['address']['county']) and $sync_options['osm_tag_address_county']) {
188-
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['county']) );
189185
array_push( $tag_names, $response['address']['county'] );
190186
}
191187
if (isset($response['address']['state']) and $sync_options['osm_tag_address_state']) {
192-
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['state']) );
193188
array_push( $tag_names, $response['address']['state'] );
194189
}
195190
if (isset($response['address']['country']) and $sync_options['osm_tag_address_country']) {
196-
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['country']) );
197191
array_push( $tag_names, $response['address']['country'] );
198192
}
199193
if (isset($response['address']['postcode']) and $sync_options['osm_tag_address_postcode']) {
200-
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['postcode']) );
201194
array_push( $tag_names, $response['address']['postcode'] );
202195
}
203196
if (isset($response['address']['country_code']) and $sync_options['osm_tag_address_country_code']) {
204-
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['country_code']) );
205197
array_push( $tag_names, $response['address']['country_code'] );
206198
}
207-
//print_r($tag_ids);
208199
//print_r($tag_names);
209-
if (!empty($tag_ids) and !empty($tag_names))
200+
if (!empty($tag_names))
210201
{
211202
if (!$sync_options['simulate'])
212203
{
213-
add_tags($tag_ids, [$image['id']]);
204+
/* Create tag */
205+
$tag_ids = array();
206+
foreach ($tag_names as $tag_name)
207+
{
208+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$tag_name) );
209+
}
210+
/* Assign tags to image */
211+
//print_r($tag_ids);
212+
if (!empty($tag_ids))
213+
{
214+
add_tags($tag_ids, [$image['id']]);
215+
}
214216
}
215217
$datas[] = $image['id'];
216218
$infos[] = "Set tags '". osm_pprint_r($tag_names) ."' for ". $image['name'];
@@ -255,6 +257,9 @@
255257
'SUBCATS_INCLUDED_CHECKED' => $sync_options['subcats_included'] ? 'checked="checked"' : '',
256258
'NB_GEOTAGGED' => $nb_geotagged,
257259
'OSM_PATH' => OSM_PATH,
260+
'sync_options' => $sync_options,
261+
'language_options' => get_languages(),
262+
'language_selected' => get_default_language(),
258263
)
259264
);
260265

admin/admin_tag.tpl

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,36 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
7676
<ul>
7777
<li>
7878
<label>
79-
<input type="text" name="osm_taggroup" value="location" placeholder="location" required="" /> {'Name of the tag group'|@translate}
79+
{'Name of the tag group'|@translate}:
80+
<input type="text" name="osm_taggroup" value="{$sync_options.osm_tag_group}" placeholder="location" required="" />
8081
</label>
8182
</li>
8283
<li>
8384
<label>{'Use as tag'|@translate} : </label><br/>
8485
<div style="padding-left: 25px">
85-
<input type="checkbox" name="osm_tag_address_suburb" value="true" {if $osm_tag_address_suburb}checked="checked"{/if}/> {'suburb'|@translate}<br />
86-
<input type="checkbox" name="osm_tag_address_city_district" value="true" {if $osm_tag_address_city_district}checked="checked"{/if}/> {'city_district'|@translate}<br />
87-
<input type="checkbox" name="osm_tag_address_city" value="true" checked="checked"/> {'city'|@translate}<br />
88-
<input type="checkbox" name="osm_tag_address_county" value="true" {if $osm_tag_address_county}checked="checked"{/if}/> {'county'|@translate}<br />
89-
<input type="checkbox" name="osm_tag_address_state" value="true" {if $osm_tag_address_state}checked="checked"{/if}/> {'state'|@translate}<br />
90-
<input type="checkbox" name="osm_tag_address_country" value="true" {if $osm_tag_address_country}checked="checked"{/if}/> {'country'|@translate}<br />
91-
<input type="checkbox" name="osm_tag_address_postcode" value="true" {if $osm_tag_address_postcode}checked="checked"{/if}/> {'postcode'|@translate}<br />
92-
<input type="checkbox" name="osm_tag_address_country_code" value="true" {if $osm_tag_address_country_code}checked="checked"{/if}/> {'country_code'|@translate}<br />
86+
<input type="checkbox" name="osm_tag_address_suburb" value="true" {if $sync_options.osm_tag_address_suburb}checked="checked"{/if}/> {'suburb'|@translate}<br />
87+
<input type="checkbox" name="osm_tag_address_city_district" value="true" {if $sync_options.osm_tag_address_city_district}checked="checked"{/if}/> {'city_district'|@translate}<br />
88+
<input type="checkbox" name="osm_tag_address_city" value="true" {if $sync_options.osm_tag_address_city}checked="checked"{/if}/> {'city'|@translate}<br />
89+
<input type="checkbox" name="osm_tag_address_county" value="true" {if $sync_options.osm_tag_address_county}checked="checked"{/if}/> {'county'|@translate}<br />
90+
<input type="checkbox" name="osm_tag_address_state" value="true" {if $sync_options.osm_tag_address_state}checked="checked"{/if}/> {'state'|@translate}<br />
91+
<input type="checkbox" name="osm_tag_address_country" value="true" {if $sync_options.osm_tag_address_country}checked="checked"{/if}/> {'country'|@translate}<br />
92+
<input type="checkbox" name="osm_tag_address_postcode" value="true" {if $sync_options.osm_tag_address_postcode}checked="checked"{/if}/> {'postcode'|@translate}<br />
93+
<input type="checkbox" name="osm_tag_address_country_code" value="true" {if $sync_options.osm_tag_address_country_code}checked="checked"{/if}/> {'country_code'|@translate}<br />
9394
</div>
9495
<small>{'Create tag using one or multiple value from the address part'|@translate}</small>
9596
</li>
97+
98+
<li>
99+
<label>{'Language'|@translate} :</label><br/>
100+
<div id="action_language" class="bulkAction">
101+
<select name="language" size="1">
102+
{html_options options=$language_options selected=$language_selected}
103+
</select>
104+
</div>
105+
<small>{'Fetch the result in a specific language, mostly for the country and city fields, eg: (EN:Japan, ES:Japón, FR:Japon, JP:日本)'|@translate}</small>
106+
</li>
96107
</ul>
108+
97109
</fieldset>
98110
99111
<fieldset id="syncSimulation">

0 commit comments

Comments
 (0)