| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: OSM |
| 4 |
Plugin URI: https://wp-osm-plugin.hyumika.com |
| 5 |
Description: Embed OpenStreetMap-based maps in posts, pages, and widgets, including marker, GPX, and KML support. |
| 6 |
Version: 6.2.6 |
| 7 |
Author: MiKa |
| 8 |
Author URI: https://www.hyumika.com |
| 9 |
Requires at least: 5.0 |
| 10 |
Requires PHP: 5.3 |
| 11 |
License: GPL-2.0-or-later |
| 12 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 |
Text Domain: osm |
| 14 |
Domain Path: /languages |
| 15 |
*/ |
| 16 |
|
| 17 |
/* (c) Copyright 2026 MiKa (www.hyumika.com) |
| 18 |
|
| 19 |
This program is free software; you can redistribute it and/or modify |
| 20 |
it under the terms of the GNU General Public License as published by |
| 21 |
the Free Software Foundation; either version 2 of the License, or |
| 22 |
(at your option) any later version. |
| 23 |
|
| 24 |
This program is distributed in the hope that it will be useful, |
| 25 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 |
GNU General Public License for more details. |
| 28 |
|
| 29 |
You should have received a copy of the GNU General Public License |
| 30 |
along with this program; if not, write to the Free Software |
| 31 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 32 |
*/ |
| 33 |
|
| 34 |
define ("PLUGIN_VER", "V6.2.6"); |
| 35 |
|
| 36 |
// modify anything about the marker for tagged posts here |
| 37 |
// instead of the coding. |
| 38 |
define ("POST_MARKER_PNG", "marker_posts.png"); |
| 39 |
define ('POST_MARKER_PNG_HEIGHT', 2); |
| 40 |
define ('POST_MARKER_PNG_WIDTH', 2); |
| 41 |
|
| 42 |
define ("GCSTATS_MARKER_PNG", "geocache.png"); |
| 43 |
define ('GCSTATS_MARKER_PNG_HEIGHT', 25); |
| 44 |
define ('GCSTATS_MARKER_PNG_WIDTH', 25); |
| 45 |
|
| 46 |
define ("INDIV_MARKER", "marker_blue.png"); |
| 47 |
define ('INDIV_MARKER_PNG_HEIGHT', 25); |
| 48 |
define ('INDIV_MARKER_PNG_WIDTH', 25); |
| 49 |
|
| 50 |
// these defines are given by OpenStreetMap.org |
| 51 |
define ("URL_INDEX", "http://www.openstreetmap.org/index.html?"); |
| 52 |
define ("URL_LAT","&mlat="); |
| 53 |
define ("URL_LON","&mlon="); |
| 54 |
define ("URL_ZOOM_01","&zoom=["); |
| 55 |
define ("URL_ZOOM_02","]"); |
| 56 |
define ('ZOOM_LEVEL_GOOGLE_MAX',22); |
| 57 |
define ('ZOOM_LEVEL_MAX',18); // standard is 17, only mapnik is 18 |
| 58 |
define ('ZOOM_LEVEL_MIN',1); |
| 59 |
|
| 60 |
// other geo plugin defines |
| 61 |
// google-maps-geocoder |
| 62 |
define ("WPGMG_LAT", "lat"); |
| 63 |
define ("WPGMG_LON", "lng"); |
| 64 |
|
| 65 |
// some general defines |
| 66 |
define ('LAT_MIN',-90); |
| 67 |
define ('LAT_MAX',90); |
| 68 |
define ('LON_MIN',-180); |
| 69 |
define ('LON_MAX',180); |
| 70 |
|
| 71 |
// tracelevels |
| 72 |
define ('DEBUG_OFF', 0); |
| 73 |
define ('DEBUG_ERROR', 1); |
| 74 |
define ('DEBUG_WARNING', 2); |
| 75 |
define ('DEBUG_INFO', 3); |
| 76 |
define ('HTML_COMMENT', 10); |
| 77 |
|
| 78 |
// Load OSM library mode |
| 79 |
define ('SERVER_EMBEDDED', 1); |
| 80 |
define ('SERVER_WP_ENQUEUE', 2); |
| 81 |
|
| 82 |
define('OSM_PRIV_WP_CONTENT_URL', site_url() . '/wp-content' ); |
| 83 |
define('OSM_PRIV_WP_CONTENT_DIR', content_url() . 'wp-content' ); |
| 84 |
define('OSM_PRIV_WP_PLUGIN_URL', plugins_url() ); |
| 85 |
define('OSM_PRIV_WP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 86 |
|
| 87 |
define('OSM_PLUGIN_URL', OSM_PRIV_WP_PLUGIN_URL."/osm/"); |
| 88 |
define('OSM_PLUGIN_ICONS_URL', OSM_PLUGIN_URL."icons/"); |
| 89 |
define('URL_POST_MARKER', OSM_PLUGIN_URL.POST_MARKER_PNG); |
| 90 |
define('OSM_PLUGIN_THEMES_URL', OSM_PLUGIN_URL."themes/"); |
| 91 |
define('OSM_OPENLAYERS_THEMES_URL', content_url(). '/uploads/osm/theme/' ); |
| 92 |
define('OSM_PLUGIN_JS_URL', OSM_PLUGIN_URL."js/"); |
| 93 |
|
| 94 |
global $wp_version; |
| 95 |
if (version_compare($wp_version,"3.0","<")){ |
| 96 |
exit('[OSM plugin - ERROR]: At least Wordpress Version 3.0 is required for this plugin!'); |
| 97 |
} |
| 98 |
|
| 99 |
// get the configuratin by |
| 100 |
// default or costumer settings |
| 101 |
|
| 102 |
$OL3_LIBS_LOADED = 0; |
| 103 |
|
| 104 |
include ('osm-config.php'); |
| 105 |
|
| 106 |
|
| 107 |
// do not edit this |
| 108 |
//define ("Osm_TraceLevel", DEBUG_ERROR); |
| 109 |
//define ("Osm_TraceLevel", DEBUG_OFF); |
| 110 |
|
| 111 |
define ("Osm_TraceLevel", DEBUG_ERROR); |
| 112 |
|
| 113 |
|
| 114 |
// If the function exists this file is called as upload_mimes. |
| 115 |
// We don't do anything then. |
| 116 |
if ( ! function_exists( 'osm_restrict_mime_types' ) ) { |
| 117 |
// |
| 118 |
// Return allowed mime types |
| 119 |
// |
| 120 |
// @see function get_allowed_mime_types in wp-includes/functions.php |
| 121 |
// @param array $mime_types Array of mime types |
| 122 |
// @return array Array of mime types keyed by the file extension regex corresponding to those types. |
| 123 |
// |
| 124 |
function osm_restrict_mime_types( $mime_types ) { |
| 125 |
// Logging der aktuellen MIME-Typen, die erlaubt sind |
| 126 |
// error_log('Called osm_restrict_mime_types filter.'); |
| 127 |
|
| 128 |
// Füge gpx und kml zu den erlaubten MIME-Typen hinzu |
| 129 |
$mime_types['gpx'] = 'application/gpx+xml'; |
| 130 |
$mime_types['kml'] = 'application/vnd.google-earth.kml+xml'; |
| 131 |
|
| 132 |
// Logge die Liste der erlaubten MIME-Typen nach dem Hinzufügen |
| 133 |
// error_log('Allowed MIME types after modification: ' . print_r($mime_types, true)); |
| 134 |
|
| 135 |
return $mime_types; |
| 136 |
} |
| 137 |
|
| 138 |
function allow_osm_upload( $data, $file, $filename, $mimes ) { |
| 139 |
// Logging des Dateinamens und der empfangenen Mimetypen |
| 140 |
// error_log('Called allow_osm_upload for file: ' . $filename); |
| 141 |
// error_log('File MIME types received: ' . print_r($mimes, true)); |
| 142 |
|
| 143 |
// Hole die Dateiendung (unabhängig von Groß-/Kleinschreibung) |
| 144 |
$ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ); |
| 145 |
|
| 146 |
// Logge die erkannte Dateiendung |
| 147 |
// error_log('Detected file extension: ' . $ext); |
| 148 |
|
| 149 |
// Prüfe auf kml oder gpx und setze den entsprechenden MIME-Typ |
| 150 |
if ( $ext === 'kml' ) { |
| 151 |
// error_log('Processing KML file.'); |
| 152 |
$data['ext'] = 'kml'; |
| 153 |
$data['type'] = 'application/vnd.google-earth.kml+xml'; |
| 154 |
$data['proper_filename'] = $filename; |
| 155 |
} elseif ( $ext === 'gpx' ) { |
| 156 |
// error_log('Processing GPX file.'); |
| 157 |
$data['ext'] = 'gpx'; |
| 158 |
$data['type'] = 'application/gpx+xml'; |
| 159 |
$data['proper_filename'] = $filename; |
| 160 |
} else { |
| 161 |
// Logge, wenn die Dateiendung nicht unterstützt wird |
| 162 |
error_log('Unsupported file extension: ' . $ext); |
| 163 |
} |
| 164 |
|
| 165 |
// Logge die finalen Dateiinformationen, bevor sie zurückgegeben werden |
| 166 |
// error_log('File data to be returned: ' . print_r($data, true)); |
| 167 |
return $data; |
| 168 |
} |
| 169 |
|
| 170 |
// Filter einbinden, um zusätzliche MIME-Typen (gpx und kml) zu erlauben |
| 171 |
add_filter( 'upload_mimes', 'osm_restrict_mime_types' ); |
| 172 |
add_filter( 'wp_check_filetype_and_ext', 'allow_osm_upload', 10, 4 ); |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* AJAX handler to save a post geotag (lat/lon) and optional marker icon. |
| 177 |
* |
| 178 |
* Validates required request fields, checks nonce and permissions, sanitizes |
| 179 |
* input, updates post meta, and returns a JSON success/error response. |
| 180 |
*/ |
| 181 |
function saveGeotagAndPic() { |
| 182 |
|
| 183 |
if ( |
| 184 |
! isset( |
| 185 |
$_POST['lat'], |
| 186 |
$_POST['lon'], |
| 187 |
$_POST['icon'], |
| 188 |
$_POST['post_id'], |
| 189 |
$_POST['geotag_nonce'] |
| 190 |
) |
| 191 |
) { |
| 192 |
wp_send_json_error( 'Required data is missing.' ); |
| 193 |
} |
| 194 |
|
| 195 |
if ( ! wp_verify_nonce( $_POST['geotag_nonce'], 'osm_geotag_nonce' ) ) { |
| 196 |
wp_send_json_error( 'Invalid nonce.' ); |
| 197 |
} |
| 198 |
|
| 199 |
$post_id = absint( $_POST['post_id'] ); |
| 200 |
if ( ! $post_id || ! get_post( $post_id ) ) { |
| 201 |
wp_send_json_error( 'Invalid post ID.' ); |
| 202 |
} |
| 203 |
|
| 204 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
| 205 |
wp_send_json_error( 'Insufficient permissions.' ); |
| 206 |
} |
| 207 |
|
| 208 |
$lat = filter_var( $_POST['lat'], FILTER_VALIDATE_FLOAT ); |
| 209 |
$lon = filter_var( $_POST['lon'], FILTER_VALIDATE_FLOAT ); |
| 210 |
|
| 211 |
if ( $lat === false || $lon === false ) { |
| 212 |
wp_send_json_error( 'Invalid coordinates.' ); |
| 213 |
} |
| 214 |
|
| 215 |
$latlon = $lat . ',' . $lon; |
| 216 |
|
| 217 |
$icon = sanitize_text_field( wp_unslash( $_POST['icon'] ) ); |
| 218 |
|
| 219 |
if ( $icon !== '' ) { |
| 220 |
if ( ! preg_match( '/^[A-Za-z0-9_]+\.png$/', $icon ) ) { |
| 221 |
wp_send_json_error( 'Invalid icon format.' ); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
$custom_field = get_option( 'osm_custom_field', 'OSM_geo_data' ); |
| 226 |
|
| 227 |
delete_post_meta( $post_id, $custom_field ); |
| 228 |
delete_post_meta( $post_id, 'OSM_geo_icon' ); |
| 229 |
|
| 230 |
add_post_meta( $post_id, $custom_field, $latlon, true ); |
| 231 |
|
| 232 |
if ( $icon !== '' ) { |
| 233 |
add_post_meta( $post_id, 'OSM_geo_icon', $icon, true ); |
| 234 |
} |
| 235 |
wp_send_json_success( esc_html__('Location (geotag) saved successfully. You can use it at [Map & Locations].', 'osm')); |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
function osm_add_action_links ( $actions ) { |
| 240 |
$mylinks = array( |
| 241 |
'<a href="' . admin_url( 'options-general.php?page=osm' ) . '">Settings</a>', |
| 242 |
); |
| 243 |
$actions = array_merge( $actions, $mylinks ); |
| 244 |
return $actions; |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
function savePostMarker() { |
| 249 |
|
| 250 |
if ( |
| 251 |
! isset( |
| 252 |
$_POST['MarkerId'], |
| 253 |
$_POST['MarkerLat'], |
| 254 |
$_POST['MarkerLon'], |
| 255 |
$_POST['MarkerIcon'], |
| 256 |
$_POST['MarkerName'], |
| 257 |
$_POST['post_id'], |
| 258 |
$_POST['marker_nonce'], |
| 259 |
$_POST['MarkerText'] |
| 260 |
) |
| 261 |
) { |
| 262 |
wp_send_json_error( 'Required data is missing.' ); |
| 263 |
} |
| 264 |
|
| 265 |
$post_id = absint( wp_unslash( $_POST['post_id'] ) ); |
| 266 |
$nonce = sanitize_text_field( wp_unslash( $_POST['marker_nonce'] ) ); |
| 267 |
|
| 268 |
if ( ! wp_verify_nonce( $nonce, 'osm_marker_nonce' ) ) { |
| 269 |
wp_send_json_error( 'Invalid nonce.' ); |
| 270 |
} |
| 271 |
|
| 272 |
if ( ! $post_id || ! get_post( $post_id ) ) { |
| 273 |
wp_send_json_error( 'Invalid post ID.' ); |
| 274 |
} |
| 275 |
|
| 276 |
if ( ! current_user_can( 'edit_post', $post_id ) ) { |
| 277 |
wp_send_json_error( 'Insufficient permissions.' ); |
| 278 |
} |
| 279 |
|
| 280 |
// Validierung der Koordinaten |
| 281 |
$lat = filter_var( wp_unslash( $_POST['MarkerLat'] ), FILTER_VALIDATE_FLOAT ); |
| 282 |
$lon = filter_var( wp_unslash( $_POST['MarkerLon'] ), FILTER_VALIDATE_FLOAT ); |
| 283 |
|
| 284 |
if ( $lat === false || $lon === false ) { |
| 285 |
wp_send_json_error( 'Invalid coordinates.' ); |
| 286 |
} |
| 287 |
|
| 288 |
$MarkerLatLon = $lat . ',' . $lon; |
| 289 |
|
| 290 |
// Textfelder absichern |
| 291 |
$MarkerId = sanitize_key( wp_unslash( $_POST['MarkerId'] ) ); |
| 292 |
$MarkerName = sanitize_text_field( wp_unslash( $_POST['MarkerName'] ) ); |
| 293 |
|
| 294 |
$MarkerIcon = sanitize_text_field( wp_unslash( $_POST['MarkerIcon'] ) ); |
| 295 |
if ( $MarkerIcon !== '' && ! preg_match( '/^[A-Za-z0-9_]+\.png$/', $MarkerIcon ) ) { |
| 296 |
wp_send_json_error( 'Invalid icon format.' ); |
| 297 |
} |
| 298 |
|
| 299 |
// Nur bestimmte HTML-Tags zulassen |
| 300 |
$allowed_html = array( |
| 301 |
'a' => array( 'href' => array(), 'target' => array() ), |
| 302 |
'br' => array(), |
| 303 |
'b' => array(), |
| 304 |
'i' => array(), |
| 305 |
); |
| 306 |
$MarkerText = wp_kses( wp_unslash( $_POST['MarkerText'] ), $allowed_html ); |
| 307 |
|
| 308 |
// Metadaten setzen |
| 309 |
$prefix = 'OSM_Marker_0' . $MarkerId . '_'; |
| 310 |
|
| 311 |
delete_post_meta( $post_id, $prefix . 'Name' ); |
| 312 |
delete_post_meta( $post_id, $prefix . 'LatLon' ); |
| 313 |
delete_post_meta( $post_id, $prefix . 'Icon' ); |
| 314 |
delete_post_meta( $post_id, $prefix . 'Text' ); |
| 315 |
|
| 316 |
add_post_meta( $post_id, $prefix . 'Name', $MarkerName, true ); |
| 317 |
add_post_meta( $post_id, $prefix . 'LatLon', $MarkerLatLon, true ); |
| 318 |
add_post_meta( $post_id, $prefix . 'Icon', $MarkerIcon, true ); |
| 319 |
add_post_meta( $post_id, $prefix . 'Text', $MarkerText, true ); |
| 320 |
|
| 321 |
wp_send_json_success( esc_html__( 'Marker saved successfully.', 'osm' ) ); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
function osm_load_plugin_textdomain() { |
| 328 |
load_plugin_textdomain('osm', false, dirname(plugin_basename(__FILE__)) . '/languages/' ); |
| 329 |
} |
| 330 |
|
| 331 |
// If the function exists this file is called as post-upload-ui. |
| 332 |
// We don't do anything then. |
| 333 |
if ( ! function_exists( 'osm_restrict_mime_types_hint' ) ) { |
| 334 |
// add to wp |
| 335 |
add_action( 'post-upload-ui', 'osm_restrict_mime_types_hint' ); |
| 336 |
/** |
| 337 |
* Get an Hint about the allowed mime types |
| 338 |
* |
| 339 |
* @return void |
| 340 |
*/ |
| 341 |
function osm_restrict_mime_types_hint() { |
| 342 |
echo '<br />'; |
| 343 |
_e('OSM plugin added: GPX / KML','osm'); |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
// hook to create the meta box |
| 349 |
// enable in osm-config-sample.php |
| 350 |
if (OSM_enable_Ajax){ |
| 351 |
add_action( 'add_meta_boxes', 'osm_map_create' ); |
| 352 |
} |
| 353 |
include('osm-args-class.php'); |
| 354 |
include('osm-metabox.php'); |
| 355 |
include('osm_map/osm-oljs2.php'); |
| 356 |
include('osm_map_v3/osm-oljs3.php'); |
| 357 |
include('osm_map/osm-icon.php'); |
| 358 |
include('osm-icon-class.php'); |
| 359 |
|
| 360 |
|
| 361 |
function osm_enqueue_map_v3_assets() { |
| 362 |
$asset_handles = array( |
| 363 |
'styles' => array('osm-ol3-css', 'osm-ol3-ext-css', 'osm-map-css'), |
| 364 |
'scripts' => array('wp-polyfill', 'osm-ol3-library', 'osm-ol3-ext-library', 'osm-ol3-metabox-events', 'jquery', 'osm-map-startup'), |
| 365 |
); |
| 366 |
|
| 367 |
wp_enqueue_style('osm-ol3-css', Osm_OL_3_CSS); |
| 368 |
wp_enqueue_style('osm-ol3-ext-css', Osm_OL_3_Ext_CSS); |
| 369 |
wp_enqueue_style('osm-map-css', Osm_map_CSS); |
| 370 |
wp_enqueue_script('wp-polyfill'); // use WordPress built-in polyfill instead |
| 371 |
wp_enqueue_script('osm-ol3-library', Osm_OL_3_LibraryLocation, array(), null, false); |
| 372 |
wp_enqueue_script('osm-ol3-ext-library', Osm_OL_3_Ext_LibraryLocation, array('osm-ol3-library'), null, false); |
| 373 |
wp_enqueue_script('osm-ol3-metabox-events', Osm_OL_3_MetaboxEvents_LibraryLocation, array('osm-ol3-library'), null, false); |
| 374 |
wp_enqueue_script('osm-map-startup', Osm_map_startup_LibraryLocation, array('jquery', 'osm-ol3-library', 'osm-ol3-ext-library'), PLUGIN_VER, false); |
| 375 |
wp_localize_script('osm-map-startup', 'translations', array( |
| 376 |
'openlayer' => __('open layer', 'osm'), |
| 377 |
'openlayerAtStartup' => __('open layer at startup', 'osm'), |
| 378 |
'generateLink' => __('link to this map with opened layers', 'osm'), |
| 379 |
'shortDescription' => __('short description', 'osm'), |
| 380 |
'generatedShortCode' => __('to get a text control link paste this code in your wordpress editor', 'osm'), |
| 381 |
'closeLayer' => __('close layer', 'osm'), |
| 382 |
'cantGenerateLink' => __('put this string in the existing map short code to control this map', 'osm'), |
| 383 |
)); |
| 384 |
|
| 385 |
return $asset_handles; |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
function load_osm_map_v3_scripts($hook) { |
| 391 |
global $post, $wp_query; |
| 392 |
|
| 393 |
// Check all posts in the current query so that archive/multi-post pages |
| 394 |
// also load the scripts when *any* displayed post contains the shortcode. |
| 395 |
$needs_scripts = false; |
| 396 |
if ( ! empty( $wp_query->posts ) ) { |
| 397 |
foreach ( $wp_query->posts as $queried_post ) { |
| 398 |
if ( is_a( $queried_post, 'WP_Post' ) && has_shortcode( $queried_post->post_content, 'osm_map_v3' ) ) { |
| 399 |
$needs_scripts = true; |
| 400 |
break; |
| 401 |
} |
| 402 |
} |
| 403 |
} elseif ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'osm_map_v3' ) ) { |
| 404 |
$needs_scripts = true; |
| 405 |
} |
| 406 |
|
| 407 |
if ( ! $needs_scripts ) { |
| 408 |
return; |
| 409 |
} |
| 410 |
|
| 411 |
//for osm_map_v3 |
| 412 |
osm_enqueue_map_v3_assets(); |
| 413 |
} |
| 414 |
|
| 415 |
function load_osm_map_scripts($hook) { |
| 416 |
global $post; |
| 417 |
if ( ! is_a( $post, 'WP_Post' ) || ! has_shortcode( $post->post_content, 'osm_map' ) ) { |
| 418 |
return; |
| 419 |
} |
| 420 |
wp_enqueue_script(array ('jquery')); |
| 421 |
|
| 422 |
//for osm_map |
| 423 |
wp_enqueue_style('osm-map-css', Osm_map_CSS); |
| 424 |
wp_enqueue_script('osm-ol-library', Osm_OL_LibraryLocation); |
| 425 |
wp_enqueue_script('osm-osm-library', Osm_OSM_LibraryLocation); |
| 426 |
wp_enqueue_script('osm-harbours-library', Osm_harbours_LibraryLocation); |
| 427 |
wp_enqueue_script('osm-map-utils-library', Osm_map_utils_LibraryLocation); |
| 428 |
wp_enqueue_script('osm-utilities-library', Osm_utilities_LibraryLocation); |
| 429 |
wp_enqueue_script('OsmScript',OSM_PLUGIN_JS_URL.'osm-plugin-lib.js'); |
| 430 |
//wp_enqueue_script('OsnScript',Osm_GOOGLE_LibraryLocation); |
| 431 |
define ('OSM_LIBS_LOADED', 1); |
| 432 |
define ('OL_LIBS_LOADED', 1); |
| 433 |
define ('GOOGLE_LIBS_LOADED', 1); |
| 434 |
} |
| 435 |
|
| 436 |
// let's be unique ... |
| 437 |
// with this namespace |
| 438 |
class Osm |
| 439 |
{ |
| 440 |
static $OSM_ErrorMsg; |
| 441 |
private $localizionName; |
| 442 |
|
| 443 |
function __construct(){ |
| 444 |
$this->localizionName = 'OSM'; |
| 445 |
|
| 446 |
// create error object and add our errors |
| 447 |
self::$OSM_ErrorMsg = new WP_Error(); |
| 448 |
include('osm-error-msg.php'); |
| 449 |
|
| 450 |
|
| 451 |
// add the WP action |
| 452 |
add_action('wp_head', array(&$this, 'wp_head')); |
| 453 |
add_action('admin_head', array(&$this, 'admin_head')); |
| 454 |
add_action('admin_menu', array(&$this, 'admin_menu')); |
| 455 |
add_action('wp_enqueue_scripts', 'load_osm_map_scripts'); |
| 456 |
add_action('wp_enqueue_scripts', 'load_osm_map_v3_scripts'); |
| 457 |
add_action('widgets_init', 'register_osm_widget' ); |
| 458 |
add_action('wp_ajax_act_saveGeotag', 'saveGeotagAndPic'); |
| 459 |
add_action('wp_ajax_act_saveMarker', 'savePostMarker'); |
| 460 |
add_action('init', 'osm_load_plugin_textdomain'); |
| 461 |
|
| 462 |
// add the WP shortcode |
| 463 |
add_shortcode('osm_map',array(&$this, 'sc_showMap')); |
| 464 |
add_shortcode('osm_map_v3',array(&$this, 'sc_OL3JS')); |
| 465 |
add_shortcode('osm_info',array(&$this, 'sc_info')); |
| 466 |
|
| 467 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'osm_add_action_links' ); |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
} |
| 472 |
|
| 473 |
public static function traceErrorMsg($e = '') |
| 474 |
{ |
| 475 |
$EMsg = self::$OSM_ErrorMsg->get_error_message($e); |
| 476 |
if ($EMsg == null){ |
| 477 |
return $e; |
| 478 |
//return__("Unknown errormessage",$this->localizionName); |
| 479 |
} |
| 480 |
return $EMsg; |
| 481 |
} |
| 482 |
|
| 483 |
public static function traceText($a_Level, $a_String) |
| 484 |
{ |
| 485 |
$TracePrefix = array( |
| 486 |
DEBUG_ERROR =>'[OSM-Plugin-Error]:', |
| 487 |
DEBUG_WARNING=>'[OSM-Plugin-Warning]:', |
| 488 |
DEBUG_INFO=>'[OSM-Plugin-Info]:'); |
| 489 |
|
| 490 |
if ($a_Level == DEBUG_ERROR){ |
| 491 |
echo '<div class="osm_error_msg"><p><strong style="color:red">'.$TracePrefix[$a_Level].Osm::traceErrorMsg($a_String).'</strong></p></div>'; |
| 492 |
} |
| 493 |
else if ($a_Level <= Osm_TraceLevel){ |
| 494 |
echo $TracePrefix[$a_Level].$a_String.'<br>'; |
| 495 |
} |
| 496 |
else if ($a_Level == HTML_COMMENT){ |
| 497 |
echo "<!-- ".$a_String." --> \n"; |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
// add it to the Settings page |
| 502 |
static function options_page_osm() { |
| 503 |
// 0 = no error; |
| 504 |
// 1 = error occurred |
| 505 |
$Option_Error = 0; |
| 506 |
|
| 507 |
// Name des benutzerdefinierten Felds für Längen- und Breitengrad |
| 508 |
$osm_custom_field = get_option('osm_custom_field', 'OSM_geo_data'); |
| 509 |
|
| 510 |
// Standardwerte für die Karte |
| 511 |
$osm_default_lat = get_option('osm_default_lat', OSM_default_lat); |
| 512 |
$osm_default_lon = get_option('osm_default_lon', OSM_default_lon); |
| 513 |
$osm_default_zoom = get_option('osm_default_zoom', OSM_default_zoom); |
| 514 |
|
| 515 |
// Überprüfung, ob das Formular gesendet wurde und der Nonce korrekt ist |
| 516 |
if (isset($_POST['osm_options']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['osm_options'])), 'update_options')) { |
| 517 |
|
| 518 |
// Prüfen und verarbeiten der Default Latitude |
| 519 |
if (isset($_POST['osm_default_lat'])) { |
| 520 |
$temp_lat = (float) sanitize_text_field(wp_unslash($_POST['osm_default_lat'])); |
| 521 |
if ($temp_lat > LAT_MAX || $temp_lat < LAT_MIN) { |
| 522 |
$Option_Error = 1; |
| 523 |
Osm::traceText(DEBUG_ERROR, "e_default_lat_range"); |
| 524 |
} else { |
| 525 |
update_option('osm_default_lat', $temp_lat); |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
// Prüfen und verarbeiten der Default Longitude |
| 530 |
if (isset($_POST['osm_default_lon'])) { |
| 531 |
$temp_lon = (float) sanitize_text_field(wp_unslash($_POST['osm_default_lon'])); |
| 532 |
if ($temp_lon > LON_MAX || $temp_lon < LON_MIN) { |
| 533 |
$Option_Error = 1; |
| 534 |
Osm::traceText(DEBUG_ERROR, "e_default_lon_range"); |
| 535 |
} else { |
| 536 |
update_option('osm_default_lon', $temp_lon); |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
// Prüfen und verarbeiten der Default Zoom |
| 541 |
if (isset($_POST['osm_default_zoom'])) { |
| 542 |
$temp_zoom = (int) sanitize_text_field(wp_unslash($_POST['osm_default_zoom'])); |
| 543 |
if ($temp_zoom > 19 || $temp_zoom < 1) { |
| 544 |
$Option_Error = 1; |
| 545 |
Osm::traceText(DEBUG_ERROR, "e_default_zoom_range"); |
| 546 |
} else { |
| 547 |
update_option('osm_default_zoom', $temp_zoom); |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
// Erfolgs- oder Fehlermeldung |
| 552 |
if ($Option_Error == 0) { |
| 553 |
Osm::traceText(DEBUG_INFO, "i_options_updated"); |
| 554 |
} else { |
| 555 |
Osm::traceText(DEBUG_ERROR, "e_options_not_updated"); |
| 556 |
} |
| 557 |
|
| 558 |
} else { |
| 559 |
// Fehler bei der Nonce-Überprüfung |
| 560 |
if (isset($_POST['osm_options'])) { |
| 561 |
Osm::traceText(DEBUG_ERROR, "e_nonce_verification_failed"); |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
// Einbinden der Optionen-Seite |
| 566 |
include('osm-options.php'); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
// put meta tags into the head section |
| 571 |
function wp_head($not_used) |
| 572 |
{ |
| 573 |
global $wp_query; |
| 574 |
global $post; |
| 575 |
|
| 576 |
$lat = ''; |
| 577 |
$lon = ''; |
| 578 |
$CustomField = get_option('osm_custom_field','OSM_geo_data'); |
| 579 |
|
| 580 |
if (($CustomField != false) && (get_the_ID() !== false) && (get_post_meta($post->ID, $CustomField, true))){ |
| 581 |
$PostLatLon = get_post_meta($post->ID, $CustomField, true); |
| 582 |
if (!empty($PostLatLon)) { |
| 583 |
list($lat, $lon) = explode(',', $PostLatLon); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
// global Javascript variables |
| 589 |
echo '<script type="text/javascript"> |
| 590 |
|
| 591 |
/** all layers have to be in this global array - in further process each map will have something like vectorM[map_ol3js_n][layer_n] */ |
| 592 |
var vectorM = [[]]; |
| 593 |
|
| 594 |
/** global GET-Parameters */ |
| 595 |
var HTTP_GET_VARS = []; |
| 596 |
|
| 597 |
</script>'; |
| 598 |
|
| 599 |
if(is_single() && ($lat != '') && ($lon != '')){ |
| 600 |
$title = convert_chars(wp_strip_all_tags(get_bloginfo("name")))." - ".$wp_query->post->post_title; |
| 601 |
Osm::traceText(HTML_COMMENT, 'OSM plugin '.PLUGIN_VER.': adding geo meta tags:'); |
| 602 |
} |
| 603 |
else{ |
| 604 |
Osm::traceText(HTML_COMMENT, 'OSM plugin '.PLUGIN_VER.': did not add geo meta tags.'); |
| 605 |
return; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
// let's store geo data with W3 standard |
| 613 |
echo "<meta name=\"ICBM\" content=\"{$lat}, {$lon}\" />\n"; |
| 614 |
echo "<meta name=\"DC.title\" content=\"{$wp_query->post->post_title}\" />\n"; |
| 615 |
echo "<meta name=\"geo.placename\" content=\"{$wp_query->post->post_title}\"/>\n"; |
| 616 |
echo "<meta name=\"geo.position\" content=\"{$lat};{$lon}\" />\n"; |
| 617 |
} |
| 618 |
|
| 619 |
// global JS variable in admin area |
| 620 |
function admin_head($not_used) |
| 621 |
{ |
| 622 |
// global Javascript variables |
| 623 |
echo '<script type="text/javascript"> |
| 624 |
|
| 625 |
/** all layers have to be in this global array - in further process each map will have something like vectorM[map_ol3js_n][layer_n] */ |
| 626 |
var vectorM = [[]]; |
| 627 |
|
| 628 |
/** global GET-Parameters */ |
| 629 |
var HTTP_GET_VARS = []; |
| 630 |
|
| 631 |
</script>'; |
| 632 |
|
| 633 |
} |
| 634 |
|
| 635 |
function gps2Num($coordPart) { |
| 636 |
if ($coordPart === null || $coordPart === '') { |
| 637 |
return 0; |
| 638 |
} |
| 639 |
|
| 640 |
$parts = explode('/', (string) $coordPart, 2); |
| 641 |
if (!isset($parts[1]) || $parts[1] === '') { |
| 642 |
return floatval($parts[0]); |
| 643 |
} |
| 644 |
|
| 645 |
$denominator = floatval($parts[1]); |
| 646 |
if ($denominator == 0.0) { |
| 647 |
return floatval($parts[0]); |
| 648 |
} |
| 649 |
|
| 650 |
return floatval($parts[0]) / $denominator; |
| 651 |
} |
| 652 |
|
| 653 |
function getGps($exifCoord, $hemi) { |
| 654 |
$degrees = count($exifCoord) > 0 ? OSM::gps2Num($exifCoord[0]) : 0; |
| 655 |
$minutes = count($exifCoord) > 1 ? OSM::gps2Num($exifCoord[1]) : 0; |
| 656 |
$seconds = count($exifCoord) > 2 ? OSM::gps2Num($exifCoord[2]) : 0; |
| 657 |
|
| 658 |
$flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1; |
| 659 |
return $flip * ($degrees + $minutes / 60 + $seconds / 3600); |
| 660 |
} |
| 661 |
|
| 662 |
static function getPostMarkerCFN($a_Number, $a_FieldName) { |
| 663 |
$CustomFieldName = "OSM_Marker_0".$a_Number."_".$a_FieldName; |
| 664 |
return $CustomFieldName; |
| 665 |
} |
| 666 |
|
| 667 |
/** |
| 668 |
@param $a_import geotag(osm,osm_l) or postmarkers (1..9,all) |
| 669 |
@param $a_import_osm_cat_incl_name only for geotag (only used for geotagged) |
| 670 |
@param $a_import_osm_cat_excl_name only for getoag (only used for geotagged) |
| 671 |
@param $a_post_type (only used for geotagged) |
| 672 |
@param $a_import_osm_custom_tax_incl_name only for geotag |
| 673 |
@param $a_custom_taxonomy only for geotag |
| 674 |
@return list of markers |
| 675 |
*/ |
| 676 |
static function OL3_createMarkerList($a_import, $a_import_osm_cat_incl_name, $a_import_osm_cat_excl_name, $a_post_type, $a_import_osm_custom_tax_incl_name, $a_taxonomy) { |
| 677 |
Osm::traceText(DEBUG_INFO, "OL3_createMarkerList(".$a_import.",".$a_import_osm_cat_incl_name.",".$a_import_osm_cat_excl_name.",".$a_post_type.",".$a_import_osm_custom_tax_incl_name.",".$a_taxonomy.")"); |
| 678 |
|
| 679 |
global $post; |
| 680 |
$post_org = $post; |
| 681 |
|
| 682 |
// Initialize $pageposts |
| 683 |
$pageposts = []; |
| 684 |
|
| 685 |
// Posts or pages with geotags |
| 686 |
if ($a_import == 'osm' || $a_import == 'osm_l') { |
| 687 |
$CustomFieldName = get_option('osm_custom_field', 'OSM_geo_data'); |
| 688 |
global $wpdb; |
| 689 |
|
| 690 |
// Sanitize input |
| 691 |
$post_type = sanitize_key($a_post_type); |
| 692 |
$CustomFieldName = sanitize_text_field($CustomFieldName); |
| 693 |
|
| 694 |
// Query depending on category inclusion or exclusion |
| 695 |
if ($a_import_osm_cat_incl_name == "osm_all") { |
| 696 |
// Execute the query with placeholders inside get_results |
| 697 |
$pageposts = $wpdb->get_results( |
| 698 |
$wpdb->prepare(" |
| 699 |
SELECT DISTINCT wposts.* |
| 700 |
FROM {$wpdb->posts} wposts |
| 701 |
LEFT JOIN {$wpdb->postmeta} wpostmeta ON wposts.ID = wpostmeta.post_id |
| 702 |
LEFT JOIN {$wpdb->term_relationships} tr ON (wposts.ID = tr.object_id) |
| 703 |
LEFT JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) |
| 704 |
WHERE wpostmeta.meta_key = %s |
| 705 |
AND wposts.post_status = 'publish' |
| 706 |
AND wposts.post_type = %s |
| 707 |
", $CustomFieldName, $post_type), |
| 708 |
OBJECT |
| 709 |
); |
| 710 |
} else { |
| 711 |
// Execute the query with placeholders inside get_results |
| 712 |
$pageposts = $wpdb->get_results( |
| 713 |
$wpdb->prepare(" |
| 714 |
SELECT wposts.* |
| 715 |
FROM {$wpdb->posts} wposts |
| 716 |
JOIN {$wpdb->postmeta} wpostmeta ON (wpostmeta.post_id = wposts.ID) |
| 717 |
JOIN {$wpdb->term_relationships} tr ON (tr.object_id = wposts.ID) |
| 718 |
JOIN {$wpdb->term_taxonomy} tt ON (tt.term_taxonomy_id = tr.term_taxonomy_id) |
| 719 |
JOIN {$wpdb->terms} t ON tt.term_id = t.term_id |
| 720 |
WHERE wpostmeta.meta_key = %s |
| 721 |
AND wposts.post_status = 'publish' |
| 722 |
AND wposts.post_type = %s |
| 723 |
AND tt.taxonomy = %s |
| 724 |
AND t.name = %s |
| 725 |
", $CustomFieldName, $post_type, $a_taxonomy, $a_import_osm_cat_incl_name), |
| 726 |
OBJECT |
| 727 |
); |
| 728 |
} |
| 729 |
|
| 730 |
if ($pageposts) { |
| 731 |
$MarkerArray = []; |
| 732 |
foreach ($pageposts as $post) { |
| 733 |
setup_postdata($post); |
| 734 |
$Data = get_post_meta($post->ID, $CustomFieldName, true); |
| 735 |
// Remove spaces before and after commas |
| 736 |
$Data = preg_replace('/\s*,\s*/', ',', $Data); |
| 737 |
$GeoData_Array = explode(' ', $Data); |
| 738 |
$LatLon = explode(',', $GeoData_Array[0]); |
| 739 |
if (count($LatLon) < 2) { |
| 740 |
Osm::traceText(DEBUG_ERROR, '[OL3_createMarkerList]: Invalid geo data for post ID ' . $post->ID . ' (value: "' . $GeoData_Array[0] . '"). Please either correct or delete the geotag in the custom field "' . $CustomFieldName . '" of this post.'); |
| 741 |
continue; |
| 742 |
} |
| 743 |
list($temp_lat, $temp_lon) = $LatLon; |
| 744 |
$PostMarker = get_post_meta($post->ID, 'OSM_geo_icon', true); |
| 745 |
$PostMarker = Osm_icon::replaceOldIcon($PostMarker); |
| 746 |
|
| 747 |
// Create the marker text |
| 748 |
$Marker_Txt = '<a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a><br>'; |
| 749 |
$MarkerArray[] = array( |
| 750 |
'lat' => $temp_lat, |
| 751 |
'lon' => $temp_lon, |
| 752 |
'popup_height' => '100', |
| 753 |
'popup_width' => '150', |
| 754 |
'marker' => $PostMarker, |
| 755 |
'text' => $Marker_Txt, |
| 756 |
'Marker' => $PostMarker |
| 757 |
); |
| 758 |
} |
| 759 |
wp_reset_postdata(); // Reset global post data |
| 760 |
$post = $post_org; // Restore original post |
| 761 |
Osm::traceText(DEBUG_INFO, "[OL3_createMarkerList]: Found Marker " . count($MarkerArray)); |
| 762 |
return $MarkerArray; |
| 763 |
} else { |
| 764 |
Osm::traceText(DEBUG_ERROR, "[OL3_createMarkerList]: No posts/pages with geotag found!"); |
| 765 |
Osm::traceText(DEBUG_ERROR, "CustomFieldName: " . $CustomFieldName); |
| 766 |
Osm::traceText(DEBUG_ERROR, "tagged_type: " . $post_type); |
| 767 |
Osm::traceText(DEBUG_ERROR, "tagged_filter_type: " . $a_taxonomy); |
| 768 |
Osm::traceText(DEBUG_ERROR, "tagged_filter: " . $a_import_osm_cat_incl_name); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
// Handle single post marker (marker_id between 1 and 9) |
| 773 |
elseif (($a_import > 0) && ($a_import < 10)) { |
| 774 |
$PostMarkerCFN_LatLon = OSM::getPostMarkerCFN($a_import,"LatLon"); |
| 775 |
$PostMarkerCFN_Icon_Name = OSM::getPostMarkerCFN($a_import,"Icon"); |
| 776 |
$PostMarkerCFN_Name = OSM::getPostMarkerCFN($a_import,"Name"); |
| 777 |
$PostMarkerCFN_Text = OSM::getPostMarkerCFN($a_import,"Text"); |
| 778 |
|
| 779 |
$metapostLatLon = get_post_meta($post->ID, $PostMarkerCFN_LatLon, true); |
| 780 |
$metapostIcon_name = get_post_meta($post->ID, $PostMarkerCFN_Icon_Name, true); |
| 781 |
$metapostmarker_name = get_post_meta($post->ID, $PostMarkerCFN_Name, true); |
| 782 |
$metapostmarker_text = get_post_meta($post->ID, $PostMarkerCFN_Text, true); |
| 783 |
|
| 784 |
// Check lat lon |
| 785 |
$metapostLatLon = preg_replace('/\s*,\s*/', ',', trim($metapostLatLon)); |
| 786 |
$GeoData_Array = preg_split('/\s+/', $metapostLatLon); |
| 787 |
|
| 788 |
$temp_lat = 0; |
| 789 |
$temp_lon = 0; |
| 790 |
|
| 791 |
if (!empty($GeoData_Array[0])) { |
| 792 |
$coords = explode(',', $GeoData_Array[0]); |
| 793 |
|
| 794 |
if (count($coords) === 2) { |
| 795 |
$temp_lat = (float) $coords[0]; |
| 796 |
$temp_lon = (float) $coords[1]; |
| 797 |
} else { |
| 798 |
Osm::traceText( |
| 799 |
DEBUG_ERROR, |
| 800 |
'Invalid lat/lon format: ' . $GeoData_Array[0] |
| 801 |
); |
| 802 |
} |
| 803 |
} |
| 804 |
list($temp_lat, $temp_lon) = Osm::checkLatLongRange('Marker', $temp_lat, $temp_lon, 'no'); |
| 805 |
if (($temp_lat != 0) || ($temp_lon != 0)) { |
| 806 |
$PostMarker = Osm_icon::replaceOldIcon($metapostIcon_name); |
| 807 |
$Marker_Txt = '<p>' . $metapostmarker_text . '</p>'; |
| 808 |
$MarkerArray[] = array( |
| 809 |
'lat' => $temp_lat, |
| 810 |
'lon' => $temp_lon, |
| 811 |
'popup_height' => '100', |
| 812 |
'popup_width' => '150', |
| 813 |
'marker' => $PostMarker, |
| 814 |
'text' => $Marker_Txt, |
| 815 |
'Marker' => $PostMarker |
| 816 |
); |
| 817 |
} |
| 818 |
$post = $post_org; |
| 819 |
return $MarkerArray; |
| 820 |
} |
| 821 |
|
| 822 |
// Handle all post markers |
| 823 |
elseif ($a_import == "all") { |
| 824 |
$MarkerArray = []; |
| 825 |
for ($Counter = 1; $Counter < 10; $Counter++) { |
| 826 |
$PostMarkerCFN_LatLon = OSM::getPostMarkerCFN($Counter, "LatLon"); |
| 827 |
$PostMarkerCFN_Icon_Name = OSM::getPostMarkerCFN($Counter, "Icon"); |
| 828 |
$PostMarkerCFN_Name = OSM::getPostMarkerCFN($Counter, "Name"); |
| 829 |
$PostMarkerCFN_Text = OSM::getPostMarkerCFN($Counter, "Text"); |
| 830 |
|
| 831 |
$metapostLatLon = get_post_meta($post->ID, $PostMarkerCFN_LatLon, true); |
| 832 |
$metapostIcon_name = get_post_meta($post->ID, $PostMarkerCFN_Icon_Name, true); |
| 833 |
$metapostmarker_name = get_post_meta($post->ID, $PostMarkerCFN_Name, true); |
| 834 |
$metapostmarker_text = get_post_meta($post->ID, $PostMarkerCFN_Text, true); |
| 835 |
|
| 836 |
// Check lat lon |
| 837 |
$metapostLatLon = preg_replace('/\s*,\s*/', ',', trim($metapostLatLon)); |
| 838 |
$GeoData_Array = preg_split('/\s+/', $metapostLatLon); |
| 839 |
|
| 840 |
$temp_lat = 0; |
| 841 |
$temp_lon = 0; |
| 842 |
|
| 843 |
if (!empty($GeoData_Array[0])) { |
| 844 |
$coords = explode(',', $GeoData_Array[0]); |
| 845 |
|
| 846 |
if (count($coords) === 2) { |
| 847 |
$temp_lat = (float) $coords[0]; |
| 848 |
$temp_lon = (float) $coords[1]; |
| 849 |
} else { |
| 850 |
Osm::traceText( |
| 851 |
DEBUG_ERROR, |
| 852 |
'Invalid lat/lon format: ' . $GeoData_Array[0] |
| 853 |
); |
| 854 |
} |
| 855 |
} |
| 856 |
list($temp_lat, $temp_lon) = Osm::checkLatLongRange('Marker', $temp_lat, $temp_lon, 'no'); |
| 857 |
if (($temp_lat != 0) || ($temp_lon != 0)) { |
| 858 |
$PostMarker = Osm_icon::replaceOldIcon($metapostIcon_name); |
| 859 |
$Marker_Txt = $metapostmarker_text . ' </a><br>'; |
| 860 |
$MarkerArray[] = array( |
| 861 |
'lat' => $temp_lat, |
| 862 |
'lon' => $temp_lon, |
| 863 |
'popup_height' => '100', |
| 864 |
'popup_width' => '150', |
| 865 |
'marker' => $PostMarker, |
| 866 |
'text' => $Marker_Txt, |
| 867 |
'Marker' => $PostMarker |
| 868 |
); |
| 869 |
} |
| 870 |
} |
| 871 |
$post = $post_org; |
| 872 |
return $MarkerArray; |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
function createMarkerList($a_import, $a_import_UserName, $a_Customfield, $a_import_osm_cat_incl_name, $a_import_osm_cat_excl_name, $a_post_type, $a_import_osm_custom_tax_incl_name, $a_custom_taxonomy) |
| 880 |
{ |
| 881 |
Osm::traceText(DEBUG_INFO, "createMarkerList(".$a_import.",".$a_import_UserName.",".$a_Customfield.")"); |
| 882 |
global $post; |
| 883 |
$post_org = $post; |
| 884 |
|
| 885 |
// make a dummymarker to you use icon.clone later |
| 886 |
if ($a_import == 'gcstats'){ |
| 887 |
Osm::traceText(DEBUG_INFO, "Requesting data from gcStats-plugin"); |
| 888 |
include('osm-import.php'); |
| 889 |
} |
| 890 |
else if ($a_import == 'ecf'){ |
| 891 |
Osm::traceText(DEBUG_INFO, "Requesting data from comments"); |
| 892 |
include('osm-import.php'); |
| 893 |
} |
| 894 |
else if ($a_import == 'osm' || $a_import == 'osm_l'){ |
| 895 |
// let's see which posts are using our geo data ... |
| 896 |
Osm::traceText(DEBUG_INFO, "check all posts for osm geo custom fields"); |
| 897 |
$CustomFieldName = get_option('osm_custom_field','OSM_geo_data'); |
| 898 |
$recentPosts = new WP_Query(); |
| 899 |
$recentPosts->query('meta_key='.$CustomFieldName.'&post_status=publish'.'&showposts=-1'.'&post_type='.$a_post_type.''); |
| 900 |
while ($recentPosts->have_posts()) : $recentPosts->the_post(); |
| 901 |
$Data = get_post_meta($post->ID, $CustomFieldName, true); |
| 902 |
// remove space before and after comma |
| 903 |
$Data = preg_replace('/\s*,\s*/', ',',$Data); |
| 904 |
// get pairs of coordination |
| 905 |
$GeoData_Array = explode( ' ', $Data ); |
| 906 |
list($temp_lat, $temp_lon) = explode(',', $GeoData_Array[0]); |
| 907 |
//echo $post->ID.'Lat: '.$temp_lat.'Long '.$temp_lon.'<br>'; |
| 908 |
// check if a filter is set and geodata are set |
| 909 |
// if filter is set and set then pretend there are no geodata |
| 910 |
if (($a_import_osm_cat_incl_name != 'Osm_All' || $a_import_osm_cat_excl_name != 'Osm_None' || $a_import_osm_custom_tax_incl_name != 'Osm_All')&&($temp_lat != '' && $temp_lon != '')){ |
| 911 |
$categories = wp_get_post_categories($post->ID); |
| 912 |
foreach( $categories as $catid ) { |
| 913 |
$cat = get_category($catid); |
| 914 |
if (($a_import_osm_cat_incl_name != 'Osm_All') && (strtolower($cat->name) != (strtolower($a_import_osm_cat_incl_name)))){ |
| 915 |
$temp_lat = ''; |
| 916 |
$temp_lon = ''; |
| 917 |
} |
| 918 |
if (strtolower($cat->name) == (strtolower($a_import_osm_cat_excl_name))){ |
| 919 |
$temp_lat = ''; |
| 920 |
$temp_lon = ''; |
| 921 |
} |
| 922 |
} |
| 923 |
if ($a_import_osm_custom_tax_incl_name != 'Osm_All'){ // get rid of Invalid argument supplied for foreach() |
| 924 |
$mycustomcategories = get_the_terms( $post->ID, $a_import_osm_custom_tax_incl_name); |
| 925 |
foreach( $mycustomcategories as $term ) { |
| 926 |
$taxonomies[0] = $term->term_taxonomy_id; |
| 927 |
// Get rid of the other data stored in the object |
| 928 |
unset($term); |
| 929 |
} |
| 930 |
foreach( $taxonomies as $taxid ) { |
| 931 |
$termsObjects = wp_get_object_terms($post->ID, $a_custom_taxonomy); |
| 932 |
foreach ($termsObjects as $termsObject) { |
| 933 |
$currentCustomCat[] = $termsObject->name; |
| 934 |
} |
| 935 |
if (($a_import_osm_custom_tax_incl_name != 'Osm_All') && ! in_array($a_import_osm_custom_tax_incl_name, $currentCustomCat)) { |
| 936 |
$temp_lat = ''; |
| 937 |
$temp_lon = ''; |
| 938 |
} |
| 939 |
if (strtolower($currentCustomCat) == (strtolower($a_import_osm_cat_excl_name))){ |
| 940 |
$temp_lat = ''; |
| 941 |
$temp_lon = ''; |
| 942 |
} |
| 943 |
} |
| 944 |
} |
| 945 |
} |
| 946 |
if ($temp_lat != '' && $temp_lon != '') { |
| 947 |
// how many tags do we have in this post? |
| 948 |
$NumOfGeoTagsInPost = count($GeoData_Array); |
| 949 |
$PostMarker = get_post_meta($post->ID, 'OSM_geo_icon', true); |
| 950 |
$PostMarker = Osm_icon::replaceOldIcon($PostMarker); |
| 951 |
for ($TagNum = 0; $TagNum < $NumOfGeoTagsInPost; $TagNum++){ |
| 952 |
list($tag_lat, $tag_lon) = explode(',', $GeoData_Array[$TagNum]); |
| 953 |
list($tag_lat, $tag_lon) = Osm::checkLatLongRange('$marker_all_posts',$tag_lat, $tag_lon); |
| 954 |
//if ($a_import == 'osm_l' ){ |
| 955 |
$categories = wp_get_post_categories($post->ID); |
| 956 |
// take the last one but ignore those without a specific category |
| 957 |
foreach( $categories as $catid ) { |
| 958 |
$cat = get_category($catid); |
| 959 |
if ((strtolower($cat->name) == 'uncategorized') || (strtolower($cat->name) == 'allgemein')){ |
| 960 |
$Category_Txt = ''; |
| 961 |
} |
| 962 |
else{ |
| 963 |
$Category_Txt = $cat->name.': '; |
| 964 |
} |
| 965 |
} |
| 966 |
$Marker_Txt = '<a href="'.get_permalink($post->ID).'">'.$Category_Txt.get_the_title($post->ID).' </a><br>'; |
| 967 |
if ($a_import == 'osm_l' ){ |
| 968 |
$Marker_Txt .= get_the_excerpt($post->ID); |
| 969 |
} |
| 970 |
$MarkerArray[] = array('lat'=> $tag_lat,'lon'=>$tag_lon,'popup_height'=>'100', 'popup_width'=>'150', 'marker'=>$PostMarker, 'text'=>$Marker_Txt, 'Marker'=>$PostMarker); |
| 971 |
//} |
| 972 |
//else{ // plain osm without link to the post |
| 973 |
// $Marker_Txt = ' '; |
| 974 |
// $MarkerArray[] = array('lat'=> $tag_lat,'lon'=>$tag_lon,'popup_height'=>'100', 'popup_width'=>'150', 'marker'=>$Icon["name"], 'text'=>$Marker_Txt, 'Marker'=>$PostMarker); |
| 975 |
//} |
| 976 |
} |
| 977 |
} |
| 978 |
Osm::traceText(DEBUG_INFO, "Found Marker ".count($MarkerArray)); |
| 979 |
endwhile; |
| 980 |
} |
| 981 |
else if ($a_import == 'wpgmg'){ |
| 982 |
// let's see which posts are using our geo data ... |
| 983 |
Osm::traceText(DEBUG_INFO, "check all posts for wpgmg geo custom fields"); |
| 984 |
$recentPosts = new WP_Query(); |
| 985 |
$recentPosts->query('meta_key='.WPGMG_LAT.'&meta_key='.WPGMG_LON.'&showposts=-1'); |
| 986 |
while ($recentPosts->have_posts()) : $recentPosts->the_post(); |
| 987 |
include('osm-import.php'); |
| 988 |
if ($temp_lat != '' && $temp_lon != '') { |
| 989 |
list($temp_lat, $temp_lon) = $this->checkLatLongRange('$marker_all_posts',$temp_lat, $temp_lon); |
| 990 |
$MarkerArray[] = array('lat'=> $temp_lat,'lon'=>$temp_lon,'marker'=>$Icon["name"],'popup_height'=>'100', 'popup_width'=>'200'); |
| 991 |
} |
| 992 |
endwhile; |
| 993 |
} |
| 994 |
else if ($a_import == 'exif_m'){ |
| 995 |
$attachments = get_children( array( |
| 996 |
'post_parent' => get_the_ID(), |
| 997 |
'post_type' => 'attachment', |
| 998 |
'numberposts' => -1, // show all -1 |
| 999 |
'post_status' => 'inherit', |
| 1000 |
'post_mime_type' => 'image', |
| 1001 |
'order' => 'ASC', |
| 1002 |
'orderby' => 'menu_order ASC')); |
| 1003 |
|
| 1004 |
foreach ( $attachments as $attachment_id => $attachment ) { |
| 1005 |
$imagemeta = wp_get_attachment_metadata($attachment_id ); |
| 1006 |
|
| 1007 |
$img_src = wp_get_attachment_image_src($attachment_id,'full'); |
| 1008 |
$img_thmb = wp_get_attachment_image_src($attachment_id,'thumbnail'); |
| 1009 |
$Popup_width = $img_thmb[1]+20; |
| 1010 |
$Popup_height = $img_thmb[2]+10; |
| 1011 |
|
| 1012 |
$file = $img_src[0]; |
| 1013 |
if (is_callable('exif_read_data')) { |
| 1014 |
$exif = @exif_read_data($file); |
| 1015 |
if (!empty($exif['GPSLatitude'])) { |
| 1016 |
$lat = OSM::getGps($exif["GPSLatitude"], $exif['GPSLatitudeRef']); |
| 1017 |
} |
| 1018 |
if (!empty($exif['GPSLongitude'])) { |
| 1019 |
$lon = OSM::getGps($exif["GPSLongitude"], $exif['GPSLongitudeRef']); |
| 1020 |
} |
| 1021 |
} |
| 1022 |
$Marker_Txt = wp_get_attachment_image( $attachment_id ); |
| 1023 |
$MarkerArray[] = array('lat'=> $lat,'lon'=>$lon,'popup_height'=>$Popup_height, 'popup_width'=>$Popup_width, 'marker'=>$Icon["name"], 'text'=>$Marker_Txt, 'Marker'=>$PostMarker); |
| 1024 |
} |
| 1025 |
} |
| 1026 |
$post = $post_org; |
| 1027 |
return $MarkerArray; |
| 1028 |
} |
| 1029 |
|
| 1030 |
// if you miss a colour, just add it |
| 1031 |
public static function checkStyleColour($a_colour){ |
| 1032 |
if ($a_colour != 'red' && $a_colour != 'blue' && $a_colour != 'black' && $a_colour != 'green' && $a_colour != 'orange'){ |
| 1033 |
return "blue"; |
| 1034 |
} |
| 1035 |
return $a_colour; |
| 1036 |
} |
| 1037 |
|
| 1038 |
// get the layer for the markers |
| 1039 |
static function getImportLayer($a_type, $a_UserName, $Icon, $a_osm_cat_incl_name, $a_osm_cat_excl_name, $a_line_color, $a_line_width, $a_line_opacity, $a_post_type, $a_import_osm_custom_tax_incl_name, $a_custom_taxonomy, $a_MapName){ |
| 1040 |
|
| 1041 |
if ($a_type == 'osm_l'){ |
| 1042 |
$LayerName = 'TaggedPosts'; |
| 1043 |
if ($Icon["name"] != 'NoName'){ // <= ToDo |
| 1044 |
$PopUp = 'true'; |
| 1045 |
} |
| 1046 |
else { |
| 1047 |
$PopUp = 'false'; |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 1051 |
// import data from tagged posts |
| 1052 |
else if ($a_type == 'osm'){ |
| 1053 |
$LayerName = 'TaggedPosts'; |
| 1054 |
$PopUp = 'true'; |
| 1055 |
} |
| 1056 |
|
| 1057 |
// import data from wpgmg |
| 1058 |
else if ($a_type == 'wpgmg'){ |
| 1059 |
$LayerName = 'TaggedPosts'; |
| 1060 |
$PopUp = 'false'; |
| 1061 |
} |
| 1062 |
// import data from gcstats |
| 1063 |
else if ($a_type == 'gcstats'){ |
| 1064 |
$LayerName = 'GeoCaches'; |
| 1065 |
$PopUp = 'true'; |
| 1066 |
$Icon = Osm_icon::getIconsize(GCSTATS_MARKER_PNG); |
| 1067 |
$Icon["name"] = GCSTATS_MARKER_PNG; |
| 1068 |
} |
| 1069 |
// import data from ecf |
| 1070 |
else if ($a_type == 'ecf'){ |
| 1071 |
$LayerName = 'Comments'; |
| 1072 |
$PopUp = 'true'; |
| 1073 |
$Icon = Osm_icon::getIconsize(INDIV_MARKER); |
| 1074 |
$Icon["name"] = INDIV_MARKER; |
| 1075 |
} |
| 1076 |
// import data from ecf |
| 1077 |
else if ($a_type == 'exif_m'){ |
| 1078 |
$LayerName = 'Photos'; |
| 1079 |
$PopUp = 'true'; |
| 1080 |
} |
| 1081 |
else{ |
| 1082 |
Osm::traceText(DEBUG_ERROR, "e_import_unknwon"); |
| 1083 |
} |
| 1084 |
$MarkerArray = Osm::createMarkerList($a_type, $a_UserName,'Empty', $a_osm_cat_incl_name, $a_osm_cat_excl_name, $a_post_type, $a_import_osm_custom_tax_incl_name, $a_custom_taxonomy); |
| 1085 |
if ($a_line_color != 'none'){ |
| 1086 |
$line_color = Osm::checkStyleColour($a_line_color); |
| 1087 |
$txt = Osm_OpenLayers::addLines($MarkerArray, $line_color, $a_line_width, $a_MapName); |
| 1088 |
} |
| 1089 |
$txt .= Osm_OpenLayers::addMarkerListLayer($a_MapName, $Icon, $MarkerArray, $PopUp); |
| 1090 |
return $txt; |
| 1091 |
} |
| 1092 |
|
| 1093 |
// check Lat and Long |
| 1094 |
public static function getMapCenter($a_Lat, $a_Long, $a_import, $a_import_UserName){ |
| 1095 |
if ($a_import == 'wpgmg'){ |
| 1096 |
$Lat = OSM_getCoordinateLat($a_import); |
| 1097 |
$Lon = OSM_getCoordinateLong($a_import); |
| 1098 |
} |
| 1099 |
else if ($a_import == 'gcstats'){ |
| 1100 |
if (function_exists('gcStats__getInterfaceVersion')) { |
| 1101 |
$Val = gcStats__getMinMaxLat($a_import_UserName); |
| 1102 |
$Lat = ($Val["min"] + $Val["max"]) / 2; |
| 1103 |
$Val = gcStats__getMinMaxLon($a_import_UserName); |
| 1104 |
$Lon = ($Val["min"] + $Val["max"]) / 2; |
| 1105 |
} |
| 1106 |
else{ |
| 1107 |
Osm::traceText(DEBUG_WARNING, "getMapCenter() could not connect to gcStats plugin"); |
| 1108 |
$Lat = 0;$Long = 0; |
| 1109 |
} |
| 1110 |
} |
| 1111 |
else if ($a_Lat == '' || $a_Long == ''){ |
| 1112 |
$Lat = OSM_getCoordinateLat('osm'); |
| 1113 |
$Lon = OSM_getCoordinateLong('osm'); |
| 1114 |
} |
| 1115 |
else { |
| 1116 |
$Lat = $a_Lat; |
| 1117 |
$Lon = $a_Long; |
| 1118 |
} |
| 1119 |
return array($Lat,$Lon); |
| 1120 |
} |
| 1121 |
|
| 1122 |
|
| 1123 |
// check Lat and Long |
| 1124 |
public static function getCustomFieldData() |
| 1125 |
{ |
| 1126 |
Osm::traceText(DEBUG_INFO, "getCustomFieldData"); |
| 1127 |
//todo |
| 1128 |
return array($MarkerName, $FirstLat,$FirstLong); |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
// check Lat and Long |
| 1133 |
public static function checkLatLongRange($a_CallingId, $a_Lat, $a_Long, $a_traceError = "yes") |
| 1134 |
{ |
| 1135 |
Osm::traceText(DEBUG_INFO, "checkLatLongRange(".$a_CallingId.",".$a_Lat.",".$a_Long.",".$a_traceError.")"); |
| 1136 |
if ($a_Lat >= LAT_MIN && $a_Lat <= LAT_MAX && $a_Long >= LON_MIN && $a_Long <= LON_MAX && |
| 1137 |
preg_match('!^[^0-9]+$!', $a_Lat) != 1 && preg_match('!^[^0-9]+$!', $a_Long) != 1){ |
| 1138 |
// all is fine |
| 1139 |
} |
| 1140 |
else{ |
| 1141 |
if ($a_traceError == "yes"){ |
| 1142 |
Osm::traceText(DEBUG_ERROR, "e_lat_lon_range"); |
| 1143 |
Osm::traceText(DEBUG_INFO, "Error: ".$a_CallingId." Lat".$a_Lat." or Long".$a_Long); |
| 1144 |
} |
| 1145 |
$a_Lat = 0; |
| 1146 |
$a_Long = 0; |
| 1147 |
} |
| 1148 |
return array($a_Lat,$a_Long); |
| 1149 |
} |
| 1150 |
|
| 1151 |
public static function getGPXName($filepath){ |
| 1152 |
$file = basename($filepath, ".gpx"); // $file is set to "index" |
| 1153 |
return $file; |
| 1154 |
} |
| 1155 |
// shortcode for map with OpenLayers 3 |
| 1156 |
public static function sc_OL3JS($atts) { |
| 1157 |
static $MapCounter = 0; |
| 1158 |
|
| 1159 |
// Fallback for maps rendered from secondary queries/theme sections. |
| 1160 |
// If normal enqueue detection missed this request, print required assets here. |
| 1161 |
// This keeps the map functional without forcing global script loading. |
| 1162 |
$assets_html = ''; |
| 1163 |
if ( ! wp_script_is('osm-ol3-ext-library', 'done') ) { |
| 1164 |
$asset_handles = osm_enqueue_map_v3_assets(); |
| 1165 |
|
| 1166 |
ob_start(); |
| 1167 |
wp_print_styles($asset_handles['styles']); |
| 1168 |
wp_print_scripts($asset_handles['scripts']); |
| 1169 |
$assets_html = ob_get_clean(); |
| 1170 |
} |
| 1171 |
|
| 1172 |
include('osm_map_v3/osm-sc-osm_map_v3.php'); |
| 1173 |
if ($assets_html !== '') { |
| 1174 |
$output = $assets_html . $output; |
| 1175 |
} |
| 1176 |
return $output; |
| 1177 |
} |
| 1178 |
// shortcode for map with OpenLayers 2 |
| 1179 |
public static function sc_showMap($atts) { |
| 1180 |
static $MapCounter = 0; |
| 1181 |
include('osm_map/osm-sc-osm_map.php'); |
| 1182 |
return $output; |
| 1183 |
} |
| 1184 |
|
| 1185 |
// shortcode for image OpenLayers 2 |
| 1186 |
function sc_info($atts) { |
| 1187 |
include('osm-sc-info.php'); |
| 1188 |
return $output; |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
// add OSM-config page to Settings |
| 1193 |
function admin_menu($not_used){ |
| 1194 |
// place the info in the plugin settings page |
| 1195 |
add_options_page(__('OpenStreetMap Manager', 'osm'), __('OSM', 'osm'), 'manage_options', basename(__FILE__), array('Osm', 'options_page_osm')); |
| 1196 |
} |
| 1197 |
|
| 1198 |
} // End class Osm |
| 1199 |
|
| 1200 |
include('osm-widget.php'); |
| 1201 |
|
| 1202 |
|
| 1203 |
// register OSM_Widget widget |
| 1204 |
function register_osm_widget() { |
| 1205 |
register_widget( 'OSM_Tagged_Widget' ); |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
$pOsm = new Osm(); |
| 1211 |
|
| 1212 |
function OSM_isGeotagged(){ |
| 1213 |
global $post; |
| 1214 |
$temp_lat = 0; |
| 1215 |
$temp_lon= 0; |
| 1216 |
//$Data = get_post_meta($post->ID, 'OSM_geo_data', true); |
| 1217 |
$CustomFieldName = get_option('osm_custom_field','OSM_geo_data'); |
| 1218 |
$Data = get_post_meta($post->ID, $CustomFieldName, true); |
| 1219 |
if (!empty($Data)) { |
| 1220 |
$Data = preg_replace('/\s*,\s*/', ',',$Data); |
| 1221 |
// get pairs of coordination |
| 1222 |
$GeoData_Array = explode( ' ', $Data ); |
| 1223 |
list($temp_lat, $temp_lon) = explode(',', $GeoData_Array[0]); |
| 1224 |
list($temp_lat, $temp_lon) = Osm::checkLatLongRange('Marker',$temp_lat, $temp_lon,'no'); |
| 1225 |
} |
| 1226 |
if (($temp_lat != 0) || ($temp_lon != 0)){ |
| 1227 |
return 1; |
| 1228 |
} |
| 1229 |
else { |
| 1230 |
return 0; |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
// This is meant to be the interface used |
| 1236 |
// in your WP-template |
| 1237 |
|
| 1238 |
// returns Lat data of the first (!) coordination |
| 1239 |
function OSM_getCoordinateLat($a_import) |
| 1240 |
{ |
| 1241 |
global $post; |
| 1242 |
$a_import = strtolower($a_import); |
| 1243 |
if ($a_import == 'osm' || $a_import == 'osm_l'){ |
| 1244 |
$Data = get_post_meta($post->ID, get_option('osm_custom_field','OSM_geo_data'), true); |
| 1245 |
// remove space before and after comma |
| 1246 |
$Data = preg_replace('/\s*,\s*/', ',',$Data); |
| 1247 |
// get pairs of coordination |
| 1248 |
$GeoData_Array = explode( ' ', $Data ); |
| 1249 |
list($lat, $lon) = explode(',', $GeoData_Array[0]); |
| 1250 |
//list($lat, $lon) = explode(',', get_post_meta($post->ID, get_option('osm_custom_field','OSM_geo_data'), true)); |
| 1251 |
} |
| 1252 |
else if ($a_import == 'wpgmg'){ |
| 1253 |
$lat = get_post_meta($post->ID, WPGMG_LAT, true); |
| 1254 |
} |
| 1255 |
else { |
| 1256 |
Osm::traceText(DEBUG_ERROR, "e_php_getlat_missing_arg"); |
| 1257 |
$lat = 0; |
| 1258 |
} |
| 1259 |
if ($lat != '') { |
| 1260 |
return trim($lat); |
| 1261 |
} |
| 1262 |
return ''; |
| 1263 |
} |
| 1264 |
|
| 1265 |
// returns Lon data |
| 1266 |
function OSM_getCoordinateLong($a_import) |
| 1267 |
{ |
| 1268 |
global $post; |
| 1269 |
|
| 1270 |
$a_import = strtolower($a_import); |
| 1271 |
if ($a_import == 'osm' || $a_import == 'osm_l'){ |
| 1272 |
$Data = get_post_meta($post->ID, get_option('osm_custom_field','OSM_geo_data'), true); |
| 1273 |
// remove space before and after comma |
| 1274 |
$Data = preg_replace('/\s*,\s*/', ',',$Data); |
| 1275 |
// get pairs of coordination |
| 1276 |
$GeoData_Array = explode( ' ', $Data ); |
| 1277 |
list($lat, $lon) = explode(',', $GeoData_Array[0]); |
| 1278 |
//list($lat, $lon) = explode(',', get_post_meta($post->ID, get_option('osm_custom_field','OSM_geo_data'), true)); |
| 1279 |
} |
| 1280 |
else if ($a_import == 'wpgmg'){ |
| 1281 |
list($lon) = get_post_meta($post->ID,WPGMG_LON, true); |
| 1282 |
} |
| 1283 |
else { |
| 1284 |
Osm::traceText(DEBUG_ERROR, "e_php_getlon_missing_arg"); |
| 1285 |
$lon = 0; |
| 1286 |
} |
| 1287 |
if ($lon != '') { |
| 1288 |
return trim($lon); |
| 1289 |
} |
| 1290 |
return ''; |
| 1291 |
} |
| 1292 |
|
| 1293 |
function OSM_getOpenStreetMapUrl() { |
| 1294 |
$zoom_level = get_option('osm_zoom_level','7'); |
| 1295 |
$lat = $lat == ''? OSM_getCoordinateLat('osm') : $lat; |
| 1296 |
$lon = $lon == ''? OSM_getCoordinateLong('osm'): $lon; |
| 1297 |
return URL_INDEX.URL_LAT.$lat.URL_LON.$lon.URL_ZOOM_01.$zoom_level.URL_ZOOM_02; |
| 1298 |
} |
| 1299 |
|
| 1300 |
function OSM_echoOpenStreetMapUrl(){ |
| 1301 |
echo OSM_getOpenStreetMapUrl() ; |
| 1302 |
} |
| 1303 |
// functions to display a map in your theme |
| 1304 |
// by using the custom fields |
| 1305 |
// default values should be set only at sc_showMap() |
| 1306 |
function OSM_displayOpenStreetMap($a_widht, $a_hight, $a_zoom, $a_type){ |
| 1307 |
|
| 1308 |
$atts = array ('width' => $a_widht, |
| 1309 |
'height' => $a_hight, |
| 1310 |
'type' => $a_type, |
| 1311 |
'zoom' => $a_zoom, |
| 1312 |
'control' => 'off'); |
| 1313 |
|
| 1314 |
if ((OSM_getCoordinateLong("osm"))&&(OSM_getCoordinateLat("osm"))) { |
| 1315 |
echo OSM::sc_showMap($atts); |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
function OSM_displayOpenStreetMapExt($a_widht, $a_hight, $a_zoom, $a_type, $a_control, $a_marker_name, $a_marker_height, $a_marker_width, $a_marker_text, $a_ov_map, $a_marker_focus = 0, $a_routing = 'No', $a_theme = 'dark'){ |
| 1320 |
|
| 1321 |
$atts = array ('width' => $a_widht, |
| 1322 |
'height' => $a_hight, |
| 1323 |
'type' => $a_type, |
| 1324 |
'zoom' => $a_zoom, |
| 1325 |
'ov_map' => $a_ov_map, |
| 1326 |
'marker_name' => $a_marker_name, |
| 1327 |
'marker_height' => $a_marker_height, |
| 1328 |
'marker_width' => $a_marker_width, |
| 1329 |
'marker' => OSM_getCoordinateLat("osm") . ',' . OSM_getCoordinateLong("osm") . ',' . $a_marker_text, |
| 1330 |
'control' => $a_control, |
| 1331 |
'marker_focus' => $a_marker_focus, |
| 1332 |
'theme' => $a_theme, |
| 1333 |
'marker_routing' => $a_routing); |
| 1334 |
|
| 1335 |
if ((OSM_getCoordinateLong("osm"))&&(OSM_getCoordinateLat("osm"))) { |
| 1336 |
echo OSM::sc_showMap($atts); |
| 1337 |
} |
| 1338 |
} |
| 1339 |
?> |
| 1340 |
|