diff --git a/class.admin.php b/class.admin.php index 780a153..80ac5da 100644 --- a/class.admin.php +++ b/class.admin.php @@ -70,12 +70,12 @@ public function admin_menu() if (current_user_can('manage_options')) { $main_link = 'leaflet-map'; } else { - $main_link = 'leaflet-get-shortcode'; + $main_link = 'leaflet-shortcode-helper'; } add_menu_page("Leaflet Map", "Leaflet Map", 'manage_options', $main_link, array($this, "settings_page"), plugins_url('images/leaf.png', LEAFLET_MAP__PLUGIN_FILE)); add_submenu_page("leaflet-map", "Default Values", "Default Values", 'manage_options', "leaflet-map", array($this, "settings_page")); - add_submenu_page("leaflet-map", "Shortcode Helper", "Shortcode Helper", 'edit_posts', "leaflet-get-shortcode", array($this, "shortcode_page")); + add_submenu_page("leaflet-map", "Shortcode Helper", "Shortcode Helper", 'edit_posts', "leaflet-shortcode-helper", array($this, "shortcode_page")); } /** @@ -96,7 +96,7 @@ public function settings_page() public function shortcode_page() { wp_enqueue_style('leaflet_admin_stylesheet'); - wp_enqueue_script('custom_plugin_js', plugins_url('scripts/get-shortcode.min.js', LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false); + wp_enqueue_script('custom_plugin_js', plugins_url('scripts/shortcode-helper.min.js', LEAFLET_MAP__PLUGIN_FILE), Array('leaflet_js'), false); include 'templates/shortcode-helper.php'; } diff --git a/class.geocoder.php b/class.geocoder.php index 4e13c91..1e55aae 100644 --- a/class.geocoder.php +++ b/class.geocoder.php @@ -95,7 +95,8 @@ private function get_url( $url ) { curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_REFERER, get_site_url()); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); @@ -133,9 +134,9 @@ private function google_geocode ( $address ) { return (Object) $location; } - } - - return $this->not_found; + } + + throw new Exception('No Address Found'); } /** @@ -149,8 +150,8 @@ private function osm_geocode ( $address ) { $geocode_url = 'https://nominatim.openstreetmap.org/?format=json&limit=1&q='; $geocode_url .= $address; $json = $this->get_url($geocode_url); - $json = json_decode($json); - + $json = json_decode($json); + if (is_array($json) && is_object($json[0]) && $json[0]->lat) { @@ -161,7 +162,7 @@ private function osm_geocode ( $address ) { ); } - return $this->not_found; + throw new Exception('No Address Found'); } /** @@ -190,6 +191,6 @@ private function dawa_geocode ( $address ) { return $location; } - return $this->not_found; + throw new Exception('No Address Found'); } } \ No newline at end of file diff --git a/class.plugin-settings.php b/class.plugin-settings.php index 0912e32..73f154c 100644 --- a/class.plugin-settings.php +++ b/class.plugin-settings.php @@ -259,11 +259,11 @@ private function __construct() ), 'geocoder' => array( 'display_name'=>__('Geocoder', 'leaflet-map'), - 'default' => 'google', + 'default' => 'osm', 'type' => 'select', 'options' => array( - 'google' => __('Google Maps', 'leaflet-map'), 'osm' => __('OpenStreetMap Nominatim', 'leaflet-map'), + 'google' => __('Google Maps', 'leaflet-map'), 'dawa' => __('Denmark Addresses', 'leaflet-map') ), 'helptext' => __('Select the Geocoding provider to use to retrieve addresses defined in shortcode.', 'leaflet-map') diff --git a/leaflet-map.php b/leaflet-map.php index 1f5f0b1..1e45932 100644 --- a/leaflet-map.php +++ b/leaflet-map.php @@ -8,7 +8,7 @@ * Author URI: https://twitter.com/bozdoz/ * Text Domain: leaflet-map * Domain Path: /languages/ - * Version: 2.11.0 + * Version: 2.11.1 * License: GPL2 * Leaflet Map is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ exit; } -define('LEAFLET_MAP__PLUGIN_VERSION', '2.11.0'); +define('LEAFLET_MAP__PLUGIN_VERSION', '2.11.1'); define('LEAFLET_MAP__PLUGIN_FILE', __FILE__); define('LEAFLET_MAP__PLUGIN_DIR', plugin_dir_path(__FILE__)); diff --git a/readme.txt b/readme.txt index a005635..00288da 100644 --- a/readme.txt +++ b/readme.txt @@ -6,9 +6,9 @@ Contributors: bozdoz, Remigr, nielsalstrup, jeromelebleu, gerital Donate link: https://www.paypal.me/bozdoz Tags: leaflet, map, mobile, javascript, openstreetmap, mapquest, interactive Requires at least: 3.0.1 -Tested up to: 4.9.4 -Version: 2.11.0 -Stable tag: 2.11.0 +Tested up to: 4.9.7 +Version: 2.11.1 +Stable tag: 2.11.1 License: GPLv2 License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -124,6 +124,10 @@ Yes: use the keyword `attribution` in your shortcode (semi-colon separated list == Changelog == += 2.11.1 = +* Added Dockerfiles to github +* Made OpenStreetMap default geocoder in light of new Google API payment plans + = 2.11.0 = * Added Popup Anchor for custom markers * Added SVG Markers diff --git a/scripts/get-shortcode.min.js b/scripts/get-shortcode.min.js deleted file mode 100644 index 778dfe5..0000000 --- a/scripts/get-shortcode.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(){WPLeafletMapPlugin.add(function(){var e=document.getElementById("map-shortcode"),t=document.getElementById("marker-shortcode"),n=WPLeafletMapPlugin.maps[0],a=WPLeafletMapPlugin.markers[0];function l(){var e=a.getLatLng();t.value="[leaflet-marker lat="+e.lat+" lng="+e.lng+"]"}function c(){var t=n.getCenter();e.value="[leaflet-map lat="+t.lat+" lng="+t.lng+" zoom="+n.getZoom()+"]"}a.on("drag",l),n.on("move",c),c(),l(),e.addEventListener?(e.addEventListener("click",function(){this.select()}),t.addEventListener("click",function(){this.select()})):(e.attachEvent("onclick",function(){e.select()}),t.attachEvent("onclick",function(){t.select()}))})}(); diff --git a/scripts/get-shortcode.js b/scripts/shortcode-helper.js similarity index 83% rename from scripts/get-shortcode.js rename to scripts/shortcode-helper.js index 5eee764..c4262df 100644 --- a/scripts/get-shortcode.js +++ b/scripts/shortcode-helper.js @@ -18,7 +18,8 @@ } function update_map () { - var latlng = map_1.getCenter(); + var bounds = map_1.getBounds(); + var latlng = bounds.getCenter(); map_input.value = '[leaflet-map lat=' + latlng.lat + ' lng=' + @@ -26,6 +27,12 @@ ' zoom=' + map_1.getZoom() + ']'; + + // update marker if outside of bounds + if (!bounds.contains(marker_1.getLatLng())) { + // move marker to center + marker_1.setLatLng(latlng); + } } marker_1.on('drag', update_marker); diff --git a/scripts/shortcode-helper.min.js b/scripts/shortcode-helper.min.js new file mode 100644 index 0000000..9adfeed --- /dev/null +++ b/scripts/shortcode-helper.min.js @@ -0,0 +1 @@ +!function(){WPLeafletMapPlugin.add(function(){var t=document.getElementById("map-shortcode"),e=document.getElementById("marker-shortcode"),n=WPLeafletMapPlugin.maps[0],a=WPLeafletMapPlugin.markers[0];function l(){var t=a.getLatLng();e.value="[leaflet-marker lat="+t.lat+" lng="+t.lng+"]"}function c(){var e=n.getBounds(),l=e.getCenter();t.value="[leaflet-map lat="+l.lat+" lng="+l.lng+" zoom="+n.getZoom()+"]",e.contains(a.getLatLng())||a.setLatLng(l)}a.on("drag",l),n.on("move",c),c(),l(),t.addEventListener?(t.addEventListener("click",function(){this.select()}),e.addEventListener("click",function(){this.select()})):(t.attachEvent("onclick",function(){t.select()}),e.attachEvent("onclick",function(){e.select()}))})}();