|
1 | 1 | <?php |
2 | 2 | /*********************************************** |
3 | | -* File : admin_sync.php |
| 3 | +* File : admin_tag.php |
4 | 4 | * Project : piwigo-openstreetmap |
5 | 5 | * Descr : Create tags from reverse address |
6 | 6 | * |
7 | | -* Created : 03.07.2015 |
| 7 | +* Created : 06.07.2015 |
8 | 8 | * |
9 | | -* Copyright 2015 <xbgmsharp@gmail.com> |
| 9 | +* Copyright 2013-2015 <xbgmsharp@gmail.com> |
10 | 10 | * |
11 | 11 | * This program is free software: you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
|
41 | 41 | 'simulate' => true, |
42 | 42 | 'cat_id' => 0, |
43 | 43 | 'subcats_included' => true, |
| 44 | + 'osm_tag_group' => 'location', |
| 45 | + 'osm_tag_address_suburb' => false, |
44 | 46 | 'osm_tag_address_city_district' => false, |
45 | 47 | 'osm_tag_address_city' => true, |
46 | 48 | 'osm_tag_address_county' => false, |
|
50 | 52 | 'osm_tag_address_country_code' => false, |
51 | 53 | ); |
52 | 54 |
|
53 | | -if ( isset($_POST['osm_submit']) ) |
| 55 | +if ( isset($_POST['osm_tag_submit']) ) |
54 | 56 | { |
55 | 57 | // Override default value from the form |
56 | 58 | $sync_options = array( |
57 | 59 | 'overwrite' => isset($_POST['overwrite']), |
58 | 60 | 'simulate' => isset($_POST['simulate']), |
59 | 61 | 'cat_id' => isset($_POST['cat_id']) ? (int)$_POST['cat_id'] : 0, |
60 | 62 | 'subcats_included' => isset($_POST['subcats_included']), |
| 63 | + 'osm_tag_group' => $_POST['osm_taggroup'], |
| 64 | + 'osm_tag_address_suburb' => isset($_POST['osm_tag_address_suburb']), |
61 | 65 | 'osm_tag_address_city_district' => isset($_POST['osm_tag_address_city_district']), |
62 | 66 | 'osm_tag_address_city' => isset($_POST['osm_tag_address_city']), |
63 | 67 | 'osm_tag_address_county' => isset($_POST['osm_tag_address_county']), |
|
67 | 71 | 'osm_tag_address_country_code' => isset($_POST['osm_tag_address_country_code']) |
68 | 72 | ); |
69 | 73 |
|
70 | | - include_once( dirname(__FILE__).'/../../../include/functions_tag.inc.php' ); |
71 | | -// TODO allow to filter on overwrite |
| 74 | + // TODO allow to filter on overwrite |
72 | 75 | // Define files which lat and long avaiable |
73 | 76 | define('SQL_EXIF', "`latitude` IS NOT NULL AND `longitude` is NOT NULL"); |
74 | 77 | if ( $sync_options['cat_id']!=0 ) |
|
81 | 84 | $query .= 'id='.$sync_options['cat_id']; |
82 | 85 | $cat_ids = array_from_query($query, 'id'); |
83 | 86 |
|
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 |
85 | 88 | WHERE '. SQL_EXIF .' AND category_id IN ('.implode(',', $cat_ids).') |
86 | 89 | GROUP BY id'; |
87 | 90 | } |
88 | 91 | else |
89 | 92 | { |
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; |
91 | 94 | } |
92 | 95 |
|
93 | 96 | $images = hash_from_query( $query, 'id'); |
|
155 | 158 | //print_r($response['address']); |
156 | 159 | //print_r($sync_options); |
157 | 160 | $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 | + } |
158 | 166 | 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'] ); |
160 | 169 | } |
161 | 170 | 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'] ); |
163 | 173 | } |
164 | 174 | 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'] ); |
166 | 177 | } |
167 | 178 | 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'] ); |
169 | 181 | } |
170 | 182 | 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'] ); |
172 | 185 | } |
173 | 186 | 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'] ); |
175 | 189 | } |
176 | 190 | 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'])); |
178 | 208 | } |
179 | | - add_tags($tag_ids, [$image['id']]); |
180 | 209 | } |
181 | | - |
182 | 210 | //die("Done one image"); |
183 | 211 | } // Images loop |
184 | 212 |
|
|
199 | 227 | ); |
200 | 228 | } |
201 | 229 |
|
| 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 | + |
202 | 237 | $query = 'SELECT COUNT(*) FROM '.IMAGES_TABLE.' WHERE `latitude` IS NOT NULL and `longitude` IS NOT NULL '; |
203 | 238 | list($nb_geotagged) = pwg_db_fetch_array( pwg_query($query) ); |
204 | 239 |
|
|
0 commit comments