Skip to content

Commit ea21ee6

Browse files
committed
Add Reverse GeoCode Tags
1 parent e5a3b9a commit ea21ee6

4 files changed

Lines changed: 105 additions & 37 deletions

File tree

admin/admin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949

5050
$tabsheet = new tabsheet();
5151
$tabsheet->add( 'config', '<span class="icon-cog"></span>' . l10n('Configuration'), add_url_params( $my_base_url, array('tab'=>'config') ) );
52-
$tabsheet->add( 'loc', '<span class="osm-location"></span>' . l10n('Location'), add_url_params( $my_base_url, array('tab'=>'loc') ) );
52+
$tabsheet->add( 'tag', '<span class="icon-tags"></span>' . l10n('Tags'), add_url_params( $my_base_url, array('tab'=>'tag') ) );
53+
$tabsheet->add( 'place', '<span class="osm-location"></span>' . l10n('Places'), add_url_params( $my_base_url, array('tab'=>'place') ) );
5354
$tabsheet->select($page['tab']);
5455

5556
$tabsheet->assign();

admin/admin_boot.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,27 @@ function osm_photo_add_tab($sheets, $id)
5757
return $sheets;
5858
}
5959

60+
/* Pretty Print recursive */
61+
function osm_pprint_r(array $array, $glue = ', <br/>', $size = 4)
62+
{
63+
// Split tag array in chuck of $size for nicer display
64+
$chunk_arr = array_chunk( $array, $size, true);
65+
66+
// Generate ouput
67+
$output = "";
68+
foreach ( $chunk_arr as $row ) {
69+
foreach ( $row as $key ) {
70+
//printf('[%2s] ', $key);
71+
$output .= $key.", ";
72+
}
73+
$output .= "<br/>";
74+
}
75+
76+
// Removes last $glue from string
77+
strlen($glue) > 0 and $output = substr($output, 0, -strlen($glue));
78+
79+
return (string) $output;
80+
}
81+
82+
6083
?>
Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22
/***********************************************
3-
* File : admin_sync.php
3+
* File : admin_tag.php
44
* Project : piwigo-openstreetmap
55
* Descr : Create tags from reverse address
66
*
7-
* Created : 03.07.2015
7+
* Created : 06.07.2015
88
*
9-
* Copyright 2015 <xbgmsharp@gmail.com>
9+
* Copyright 2013-2015 <xbgmsharp@gmail.com>
1010
*
1111
* This program is free software: you can redistribute it and/or modify
1212
* it under the terms of the GNU General Public License as published by
@@ -41,6 +41,8 @@
4141
'simulate' => true,
4242
'cat_id' => 0,
4343
'subcats_included' => true,
44+
'osm_tag_group' => 'location',
45+
'osm_tag_address_suburb' => false,
4446
'osm_tag_address_city_district' => false,
4547
'osm_tag_address_city' => true,
4648
'osm_tag_address_county' => false,
@@ -50,14 +52,16 @@
5052
'osm_tag_address_country_code' => false,
5153
);
5254

53-
if ( isset($_POST['osm_submit']) )
55+
if ( isset($_POST['osm_tag_submit']) )
5456
{
5557
// Override default value from the form
5658
$sync_options = array(
5759
'overwrite' => isset($_POST['overwrite']),
5860
'simulate' => isset($_POST['simulate']),
5961
'cat_id' => isset($_POST['cat_id']) ? (int)$_POST['cat_id'] : 0,
6062
'subcats_included' => isset($_POST['subcats_included']),
63+
'osm_tag_group' => $_POST['osm_taggroup'],
64+
'osm_tag_address_suburb' => isset($_POST['osm_tag_address_suburb']),
6165
'osm_tag_address_city_district' => isset($_POST['osm_tag_address_city_district']),
6266
'osm_tag_address_city' => isset($_POST['osm_tag_address_city']),
6367
'osm_tag_address_county' => isset($_POST['osm_tag_address_county']),
@@ -67,8 +71,7 @@
6771
'osm_tag_address_country_code' => isset($_POST['osm_tag_address_country_code'])
6872
);
6973

70-
include_once( dirname(__FILE__).'/../../../include/functions_tag.inc.php' );
71-
// TODO allow to filter on overwrite
74+
// TODO allow to filter on overwrite
7275
// Define files which lat and long avaiable
7376
define('SQL_EXIF', "`latitude` IS NOT NULL AND `longitude` is NOT NULL");
7477
if ( $sync_options['cat_id']!=0 )
@@ -81,13 +84,13 @@
8184
$query .= 'id='.$sync_options['cat_id'];
8285
$cat_ids = array_from_query($query, 'id');
8386

84-
$query='SELECT `id`, `latitude`, `longitude` FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
87+
$query='SELECT `id`, `name`, `latitude`, `longitude` FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
8588
WHERE '. SQL_EXIF .' AND category_id IN ('.implode(',', $cat_ids).')
8689
GROUP BY id';
8790
}
8891
else
8992
{
90-
$query='SELECT `id`, `latitude`, `longitude` FROM '.IMAGES_TABLE.' WHERE '. SQL_EXIF;
93+
$query='SELECT `id`, `name`, `latitude`, `longitude` FROM '.IMAGES_TABLE.' WHERE '. SQL_EXIF;
9194
}
9295

9396
$images = hash_from_query( $query, 'id');
@@ -155,30 +158,55 @@
155158
//print_r($response['address']);
156159
//print_r($sync_options);
157160
$tag_ids = array();
161+
$tag_names = array();
162+
if (isset($response['address']['suburb']) and $sync_options['osm_tag_address_suburb']) {
163+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['suburb']) );
164+
array_push( $tag_names, $response['address']['suburb'] );
165+
}
158166
if (isset($response['address']['city_district']) and $sync_options['osm_tag_address_city_district']) {
159-
array_push( $tag_ids, tag_id_from_tag_name("location:".$response['address']['city_district']) );
167+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['city_district']) );
168+
array_push( $tag_names, $response['address']['city_district'] );
160169
}
161170
if (isset($response['address']['city']) and $sync_options['osm_tag_address_city']) {
162-
array_push( $tag_ids, tag_id_from_tag_name("location:".$response['address']['city']) );
171+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['city']) );
172+
array_push( $tag_names, $response['address']['city'] );
163173
}
164174
if (isset($response['address']['county']) and $sync_options['osm_tag_address_county']) {
165-
array_push( $tag_ids, tag_id_from_tag_name("location:".$response['address']['county']) );
175+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['county']) );
176+
array_push( $tag_names, $response['address']['county'] );
166177
}
167178
if (isset($response['address']['state']) and $sync_options['osm_tag_address_state']) {
168-
array_push( $tag_ids, tag_id_from_tag_name("location:".$response['address']['state']) );
179+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['state']) );
180+
array_push( $tag_names, $response['address']['state'] );
169181
}
170182
if (isset($response['address']['country']) and $sync_options['osm_tag_address_country']) {
171-
array_push( $tag_ids, tag_id_from_tag_name("location:".$response['address']['country']) );
183+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['country']) );
184+
array_push( $tag_names, $response['address']['country'] );
172185
}
173186
if (isset($response['address']['postcode']) and $sync_options['osm_tag_address_postcode']) {
174-
array_push( $tag_ids, tag_id_from_tag_name("location:".$response['address']['postcode']) );
187+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['postcode']) );
188+
array_push( $tag_names, $response['address']['postcode'] );
175189
}
176190
if (isset($response['address']['country_code']) and $sync_options['osm_tag_address_country_code']) {
177-
array_push( $tag_ids, tag_id_from_tag_name("location:".$response['address']['country_code']) );
191+
array_push( $tag_ids, tag_id_from_tag_name($sync_options['osm_tag_group'].":".$response['address']['country_code']) );
192+
array_push( $tag_names, $response['address']['country_code'] );
193+
}
194+
//print_r($tag_ids);
195+
//print_r($tag_names);
196+
if (!empty($tag_ids) and !empty($tag_names))
197+
{
198+
if (!$sync_options['simulate'])
199+
{
200+
add_tags($tag_ids, [$image['id']]);
201+
}
202+
$datas[] = $image['id'];
203+
$infos[] = "Set tags '". osm_pprint_r($tag_names) ."' for ". $image['name'];
204+
}
205+
else
206+
{
207+
$warnings = "No valid tags for ". $image['name'] . " available tag: ". osm_pprint_r(array_keys($response['address']));
178208
}
179-
add_tags($tag_ids, [$image['id']]);
180209
}
181-
182210
//die("Done one image");
183211
} // Images loop
184212

@@ -199,6 +227,13 @@
199227
);
200228
}
201229

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+
$template->assign('plg_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+
202237
$query = 'SELECT COUNT(*) FROM '.IMAGES_TABLE.' WHERE `latitude` IS NOT NULL and `longitude` IS NOT NULL ';
203238
list($nb_geotagged) = pwg_db_fetch_array( pwg_query($query) );
204239

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</style>
1313
{/html_head}
1414
15-
Find the address base on the GPS (latitude, longitude) metadata information from the database.
15+
Create tags from the address base on the GPS (latitude, longitude) metadata information.
1616
<br/><br/>
1717
Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" target="_blanck">plugin documentation</a> for additional information. Create an <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/issues" target="_blanck">issue</a> for support, or feedback, or feature request.
1818
@@ -23,18 +23,29 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
2323
</ul>
2424
</div>
2525
26+
{if not empty($plg_warnings)}
27+
<h3>{'Warnings'|@translate}</h3>
28+
<div class="warnings">
29+
<ul>
30+
{foreach from=$plg_warnings item=warning}
31+
<li>{$warning}</li>
32+
{/foreach}
33+
</ul>
34+
</div>
35+
{/if}
36+
2637
{if isset($metadata_result)}
2738
<div class="osm_layout">
2839
<legend>Synchronization results</legend>
2940
<ul>
30-
<li>{$metadata_result.NB_ELEMENTS_DONE} {'photos updated in the database'|@translate}</li>
31-
<li>{$metadata_result.NB_ELEMENTS_CANDIDATES} {'photos candidates for metadata synchronization'|@translate}</li>
41+
<li>{$metadata_result.NB_ELEMENTS_DONE} {'tags updated in the database'|@translate}</li>
42+
<li>{$metadata_result.NB_ELEMENTS_CANDIDATES} {'photos candidates for tags synchronization'|@translate}</li>
3243
<li>{$metadata_result.NB_WARNINGS} {'warnings during synchronization'|@translate}</li>
3344
<li>{$metadata_result.NB_ERRORS} {'errors during synchronization'|@translate}</li>
3445
</ul>
3546
3647
{if not empty($sync_errors)}
37-
<h3>{'SYNC_ERRORS'|@translate}</h3>
48+
<h3>{'Error list'|@translate}</h3>
3849
<div class="errors">
3950
<ul>
4051
{foreach from=$sync_errors item=error}
@@ -45,7 +56,7 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
4556
{/if}
4657
4758
{if not empty($sync_warnings)}
48-
<h3>{'SYNC_WARNINGS'|@translate}</h3>
59+
<h3>{'Warnings'|@translate}</h3>
4960
<div class="warnings">
5061
<ul>
5162
{foreach from=$sync_warnings item=warning}
@@ -56,7 +67,7 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
5667
{/if}
5768
5869
{if not empty($sync_infos)}
59-
<h3>{'SYNC_INFOS'|@translate}</h3>
70+
<h3>{'Detailed informations'|@translate}</h3>
6071
<div class="infos">
6172
<ul>
6273
{foreach from=$sync_infos item=info}
@@ -71,33 +82,31 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
7182
7283
<form action="" method="post" id="update">
7384
74-
<fieldset id="syncOverwrite">
85+
<fieldset id="tags">
7586
<legend>{'Manage tags'|@translate}</legend>
7687
<ul>
7788
<li>
78-
<label>{'TAG_ADDRESS'|@translate} : </label><br/>
89+
<label>
90+
<input type="text" name="osm_taggroup" value="location" placeholder="location" required="" /> {'Name of the tag group'|@translate}
91+
</label>
92+
</li>
93+
<li>
94+
<label>{'Use as tag'|@translate} : </label><br/>
7995
<div style="padding-left: 25px">
96+
<input type="checkbox" name="osm_tag_address_suburb" value="true" {if $osm_tag_address_suburb}checked="checked"{/if}/> {'suburb'|@translate}<br />
8097
<input type="checkbox" name="osm_tag_address_city_district" value="true" {if $osm_tag_address_city_district}checked="checked"{/if}/> {'city_district'|@translate}<br />
81-
<input type="checkbox" name="osm_tag_address_city" value="true" {if $osm_tag_address_city}checked="checked"{/if}/> {'city'|@translate}<br />
98+
<input type="checkbox" name="osm_tag_address_city" value="true" checked="checked"/> {'city'|@translate}<br />
8299
<input type="checkbox" name="osm_tag_address_county" value="true" {if $osm_tag_address_county}checked="checked"{/if}/> {'county'|@translate}<br />
83100
<input type="checkbox" name="osm_tag_address_state" value="true" {if $osm_tag_address_state}checked="checked"{/if}/> {'state'|@translate}<br />
84101
<input type="checkbox" name="osm_tag_address_country" value="true" {if $osm_tag_address_country}checked="checked"{/if}/> {'country'|@translate}<br />
85102
<input type="checkbox" name="osm_tag_address_postcode" value="true" {if $osm_tag_address_postcode}checked="checked"{/if}/> {'postcode'|@translate}<br />
86103
<input type="checkbox" name="osm_tag_address_country_code" value="true" {if $osm_tag_address_country_code}checked="checked"{/if}/> {'country_code'|@translate}<br />
87104
</div>
88-
<small>{'TAG_ADDRESS_DESC'|@translate}</small>
105+
<small>{'Create tag using one or multiple value from the adress part'|@translate}</small>
89106
</li>
90107
</ul>
91108
</fieldset>
92109
93-
<fieldset id="syncOverwrite">
94-
<legend>{'OVERWRITE_LGD'|@translate}</legend>
95-
<ul>
96-
<label><input type="checkbox" name="overwrite" value="1" checked="checked"> {'OVERWRITE'|@translate}</label>
97-
<br/><small>{'OVERWRITE_DESC'|@translate}</small>
98-
</ul>
99-
</fieldset>
100-
101110
<fieldset id="syncSimulation">
102111
<legend>{'Simulation'|@translate}</legend>
103112
<ul>
@@ -119,6 +128,6 @@ Refer to the <a href="https://github.com/xbgmsharp/piwigo-openstreetmap/wiki" ta
119128
</fieldset>
120129
121130
<p>
122-
<input type="submit" value="{'Submit'|@translate}" name="osm_submit">
131+
<input type="submit" value="{'Submit'|@translate}" name="osm_tag_submit">
123132
</p>
124133
</form>

0 commit comments

Comments
 (0)