Version Description
Download this release
Release Info
Developer | webaware |
Plugin | Flexible Map |
Version | 1.14.0 |
Comparing to | |
See all releases |
Code changes from version 1.13.0 to 1.14.0
- changelog.md +12 -7
- flexible-map.php +5 -34
- includes/class.FlxMapAdmin.php +30 -13
- includes/class.FlxMapLocalisation.php +20 -2
- includes/class.FlxMapPlugin.php +22 -13
- includes/declare-strings.php +0 -19
- includes/functions-global.php +36 -0
- js/flexible-map.min.js +1 -1
- readme.txt +52 -56
- views/settings-form.php +16 -5
changelog.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2 |
|
3 |
## Changelog
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
### 1.13.0, 2018-01-15
|
6 |
|
7 |
* changed: bump version of Google Maps API to 3.30
|
@@ -12,7 +17,7 @@
|
|
12 |
|
13 |
### 1.12.0, 2016-06-27
|
14 |
|
15 |
-
* added: support for [Google Maps API key](https://
|
16 |
|
17 |
### 1.11.0, 2016-06-05
|
18 |
|
@@ -26,9 +31,9 @@
|
|
26 |
### 1.10.1, 2015-11-29
|
27 |
|
28 |
* fixed: NextGEN Gallery breaks localisation of maps by messing with order of `wp_print_footer_scripts` calls
|
29 |
-
* changed: Dutch translation updated / completed (thanks, [Chantal Coolsma](
|
30 |
* changed: German translation updated / completed (thanks, [Dominik Schilling](https://dominikschilling.de/)!)
|
31 |
-
* changed: Norwegian Bokmål translation updated / completed (thanks, [neonnero](
|
32 |
* changed: translations now accepted on [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map)
|
33 |
* changed: Localisation (l10n) slug changed from `flexible-map` to `wp-flexible-map`, with move to translate.wordpress.org
|
34 |
* changed: bump version of Google Maps API to 3.22; NB: [control sizes have no effect with API v3.22](https://developers.google.com/maps/articles/v322-controls-diff)
|
@@ -81,7 +86,7 @@
|
|
81 |
### 1.8.0, 2014-08-31
|
82 |
|
83 |
* fixed: Czech translation (thanks, [caslavak](https://profiles.wordpress.org/caslavak/)!)
|
84 |
-
* fixed: Norwegian translations (thanks, [neonnero](
|
85 |
* changed: localisation uses standard .mo files now; if you'd like to help translate, please [sign up for an account and dig in](https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map).
|
86 |
|
87 |
### 1.7.3.1, 2014-03-22
|
@@ -90,7 +95,7 @@
|
|
90 |
|
91 |
### 1.7.3, 2014-03-16
|
92 |
|
93 |
-
* fixed: German translation (thanks, [Carib Design](
|
94 |
* fixed: some themes (e.g. Evolve) mess up Google Maps directions markers
|
95 |
* fixed: CSS for infowindows with Google Maps Visual Refresh / API v3.15
|
96 |
* changed: removed instructions page, better handled by new homepage for plugin
|
@@ -113,7 +118,7 @@
|
|
113 |
### 1.7.0, 2013-10-12
|
114 |
|
115 |
* fixed: Greek translation (thanks, [Pantelis Orfanos](https://profiles.wordpress.org/ironwiller/)!)
|
116 |
-
* fixed: Dutch translation (thanks, [Ivan Beemster](
|
117 |
* fixed: KML map zoom sometimes doesn't happen on first page visit
|
118 |
* fixed: some themes (e.g. twentythirteen) mess up Google Maps directions markers
|
119 |
* fixed: Google link opens maps without marker (NB: <= IE8 not supported)
|
@@ -151,7 +156,7 @@
|
|
151 |
* fixed: infowindow auto-pans on load, to prevent the top of the bubble being cropped
|
152 |
* added: WordPress filter `flexmap_google_maps_api_args` for filtering array of arguments before building Google Maps API URL
|
153 |
* added: function flexmap_show_map() accepts an attribute "echo", and returns a string without output to screen when "echo"=>"false"
|
154 |
-
* changed: all scripts now loaded through wp_enqueue_scripts, including language scripts (thanks to a [tip from toscho](
|
155 |
* changed: bump version of Google Maps API to 3.11
|
156 |
|
157 |
### 1.6.0, 2012-12-30
|
2 |
|
3 |
## Changelog
|
4 |
|
5 |
+
### 1.14.0, 2018-06-07
|
6 |
+
|
7 |
+
* added: server API key to reduce `REQUEST_DENIED` errors from server side address resolution requests
|
8 |
+
* changed: bump version of Google Maps API to 3.32
|
9 |
+
|
10 |
### 1.13.0, 2018-01-15
|
11 |
|
12 |
* changed: bump version of Google Maps API to 3.30
|
17 |
|
18 |
### 1.12.0, 2016-06-27
|
19 |
|
20 |
+
* added: support for [Google Maps API key](https://cloud.google.com/maps-platform/#get-started), required [since 2016-06-22 for new websites](https://googlegeodevelopers.blogspot.com.au/2016/06/building-for-scale-updates-to-google.html).
|
21 |
|
22 |
### 1.11.0, 2016-06-05
|
23 |
|
31 |
### 1.10.1, 2015-11-29
|
32 |
|
33 |
* fixed: NextGEN Gallery breaks localisation of maps by messing with order of `wp_print_footer_scripts` calls
|
34 |
+
* changed: Dutch translation updated / completed (thanks, [Chantal Coolsma](https://webpressed.nl/) and [TacoVerdo](https://profiles.wordpress.org/tacoverdo)!)
|
35 |
* changed: German translation updated / completed (thanks, [Dominik Schilling](https://dominikschilling.de/)!)
|
36 |
+
* changed: Norwegian Bokmål translation updated / completed (thanks, [neonnero](https://www.neonnero.com/)!)
|
37 |
* changed: translations now accepted on [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map)
|
38 |
* changed: Localisation (l10n) slug changed from `flexible-map` to `wp-flexible-map`, with move to translate.wordpress.org
|
39 |
* changed: bump version of Google Maps API to 3.22; NB: [control sizes have no effect with API v3.22](https://developers.google.com/maps/articles/v322-controls-diff)
|
86 |
### 1.8.0, 2014-08-31
|
87 |
|
88 |
* fixed: Czech translation (thanks, [caslavak](https://profiles.wordpress.org/caslavak/)!)
|
89 |
+
* fixed: Norwegian translations (thanks, [neonnero](https://www.neonnero.com/)!)
|
90 |
* changed: localisation uses standard .mo files now; if you'd like to help translate, please [sign up for an account and dig in](https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map).
|
91 |
|
92 |
### 1.7.3.1, 2014-03-22
|
95 |
|
96 |
### 1.7.3, 2014-03-16
|
97 |
|
98 |
+
* fixed: German translation (thanks, [Carib Design](https://www.caribdesign.com/)!)
|
99 |
* fixed: some themes (e.g. Evolve) mess up Google Maps directions markers
|
100 |
* fixed: CSS for infowindows with Google Maps Visual Refresh / API v3.15
|
101 |
* changed: removed instructions page, better handled by new homepage for plugin
|
118 |
### 1.7.0, 2013-10-12
|
119 |
|
120 |
* fixed: Greek translation (thanks, [Pantelis Orfanos](https://profiles.wordpress.org/ironwiller/)!)
|
121 |
+
* fixed: Dutch translation (thanks, [Ivan Beemster](https://lijndiensten.com/)!)
|
122 |
* fixed: KML map zoom sometimes doesn't happen on first page visit
|
123 |
* fixed: some themes (e.g. twentythirteen) mess up Google Maps directions markers
|
124 |
* fixed: Google link opens maps without marker (NB: <= IE8 not supported)
|
156 |
* fixed: infowindow auto-pans on load, to prevent the top of the bubble being cropped
|
157 |
* added: WordPress filter `flexmap_google_maps_api_args` for filtering array of arguments before building Google Maps API URL
|
158 |
* added: function flexmap_show_map() accepts an attribute "echo", and returns a string without output to screen when "echo"=>"false"
|
159 |
+
* changed: all scripts now loaded through wp_enqueue_scripts, including language scripts (thanks to a [tip from toscho](https://wordpress.stackexchange.com/a/38335/24260))
|
160 |
* changed: bump version of Google Maps API to 3.11
|
161 |
|
162 |
### 1.6.0, 2012-12-30
|
flexible-map.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Flexible Map
|
4 |
Plugin URI: https://flexible-map.webaware.net.au/
|
5 |
Description: Embed Google Maps shortcodes in pages and posts, either by centre coordinates or street address, or by URL to a Google Earth KML file. <a href="https://flexible-map.webaware.net.au/manual/getting-started/">Get started</a> with a simple shortcode. See the <a href="https://flexible-map.webaware.net.au/manual/attribute-reference/">complete attribute reference</a> for more details.
|
6 |
-
Version: 1.
|
7 |
Author: WebAware
|
8 |
Author URI: https://shop.webaware.com.au/
|
9 |
Text Domain: wp-flexible-map
|
@@ -37,42 +37,13 @@ define('FLXMAP_PLUGIN_FILE', __FILE__);
|
|
37 |
define('FLXMAP_PLUGIN_ROOT', dirname(__FILE__) . '/');
|
38 |
define('FLXMAP_PLUGIN_NAME', basename(dirname(__FILE__)) . '/' . basename(__FILE__));
|
39 |
define('FLXMAP_PLUGIN_OPTIONS', 'flexible_map');
|
40 |
-
define('FLXMAP_PLUGIN_VERSION', '1.
|
41 |
|
42 |
// shortcode tags
|
43 |
define('FLXMAP_PLUGIN_TAG_MAP', 'flexiblemap');
|
44 |
|
45 |
-
|
46 |
-
|
47 |
require FLXMAP_PLUGIN_ROOT . 'includes/class.FlxMapPlugin.php';
|
48 |
$FlxMapPlugin = FlxMapPlugin::getInstance();
|
49 |
-
|
50 |
-
/**
|
51 |
-
* utility function so themes can easily display the map
|
52 |
-
* to return as a string without output to screen, add 'echo'=>'false' to array of attributes
|
53 |
-
* @param array $attrs
|
54 |
-
* @return string
|
55 |
-
*/
|
56 |
-
function flexmap_show_map($attrs) {
|
57 |
-
$plugin = FlxMapPlugin::getInstance();
|
58 |
-
$map = $plugin->getMap($attrs);
|
59 |
-
|
60 |
-
if (!isset($attrs['echo']) || FlxMapPlugin::isYes($attrs['echo'])) {
|
61 |
-
echo $map;
|
62 |
-
}
|
63 |
-
|
64 |
-
return $map;
|
65 |
-
}
|
66 |
-
|
67 |
-
/**
|
68 |
-
* load the scripts required for the maps to work, e.g. for single-page AJAX websites
|
69 |
-
* @param array $locales optional: an array of required locale scripts
|
70 |
-
*/
|
71 |
-
function flexmap_load_scripts($locales = array()) {
|
72 |
-
wp_enqueue_script('flxmap');
|
73 |
-
|
74 |
-
if (count($locales) > 0) {
|
75 |
-
$plugin = FlxMapPlugin::getInstance();
|
76 |
-
$plugin->setLocales($locales);
|
77 |
-
}
|
78 |
-
}
|
3 |
Plugin Name: Flexible Map
|
4 |
Plugin URI: https://flexible-map.webaware.net.au/
|
5 |
Description: Embed Google Maps shortcodes in pages and posts, either by centre coordinates or street address, or by URL to a Google Earth KML file. <a href="https://flexible-map.webaware.net.au/manual/getting-started/">Get started</a> with a simple shortcode. See the <a href="https://flexible-map.webaware.net.au/manual/attribute-reference/">complete attribute reference</a> for more details.
|
6 |
+
Version: 1.14.0
|
7 |
Author: WebAware
|
8 |
Author URI: https://shop.webaware.com.au/
|
9 |
Text Domain: wp-flexible-map
|
37 |
define('FLXMAP_PLUGIN_ROOT', dirname(__FILE__) . '/');
|
38 |
define('FLXMAP_PLUGIN_NAME', basename(dirname(__FILE__)) . '/' . basename(__FILE__));
|
39 |
define('FLXMAP_PLUGIN_OPTIONS', 'flexible_map');
|
40 |
+
define('FLXMAP_PLUGIN_VERSION', '1.14.0');
|
41 |
|
42 |
// shortcode tags
|
43 |
define('FLXMAP_PLUGIN_TAG_MAP', 'flexiblemap');
|
44 |
|
45 |
+
// kickstart the plug-in
|
46 |
+
require FLXMAP_PLUGIN_ROOT . 'includes/functions-global.php';
|
47 |
require FLXMAP_PLUGIN_ROOT . 'includes/class.FlxMapPlugin.php';
|
48 |
$FlxMapPlugin = FlxMapPlugin::getInstance();
|
49 |
+
$FlxMapPlugin->addHooks();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class.FlxMapAdmin.php
CHANGED
@@ -46,7 +46,8 @@ class FlxMapAdmin {
|
|
46 |
$options = get_option(FLXMAP_PLUGIN_OPTIONS, array());
|
47 |
|
48 |
$options = wp_parse_args($options, array(
|
49 |
-
'apiKey'
|
|
|
50 |
));
|
51 |
|
52 |
require FLXMAP_PLUGIN_ROOT . 'views/settings-form.php';
|
@@ -60,7 +61,8 @@ class FlxMapAdmin {
|
|
60 |
public function settingsValidate($input) {
|
61 |
$output = array();
|
62 |
|
63 |
-
$output['apiKey']
|
|
|
64 |
|
65 |
return $output;
|
66 |
}
|
@@ -71,11 +73,11 @@ class FlxMapAdmin {
|
|
71 |
public function addPluginDetailsLinks($links, $file) {
|
72 |
// add settings link
|
73 |
if ($file == FLXMAP_PLUGIN_NAME) {
|
74 |
-
$links[] = sprintf('<a href="https://flexible-map.webaware.net.au/manual/getting-started/" target="_blank">%s</a>', _x('Instructions', 'plugin details links', 'wp-flexible-map'));
|
75 |
-
$links[] = sprintf('<a href="https://wordpress.org/support/plugin/wp-flexible-map" target="_blank">%s</a>', _x('Get Help', 'plugin details links', 'wp-flexible-map'));
|
76 |
-
$links[] = sprintf('<a href="https://wordpress.org/plugins/wp-flexible-map/" target="_blank">%s</a>', _x('Rating', 'plugin details links', 'wp-flexible-map'));
|
77 |
-
$links[] = sprintf('<a href="https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map" target="_blank">%s</a>', _x('Translate', 'plugin details links', 'wp-flexible-map'));
|
78 |
-
$links[] = sprintf('<a href="https://shop.webaware.com.au/donations/?donation_for=Flexible+Map" target="_blank">%s</a>', _x('Donate', 'plugin details links', 'wp-flexible-map'));
|
79 |
}
|
80 |
|
81 |
return $links;
|
@@ -87,7 +89,7 @@ class FlxMapAdmin {
|
|
87 |
public function addPluginActionLinks($links) {
|
88 |
// add settings link
|
89 |
$url = admin_url('options-general.php?page=flexible-map');
|
90 |
-
$settings_link = sprintf('<a href="%s">%s</a>', $url, _x('Settings', 'plugin details links', 'wp-flexible-map'));
|
91 |
array_unshift($links, $settings_link);
|
92 |
|
93 |
return $links;
|
@@ -99,15 +101,30 @@ class FlxMapAdmin {
|
|
99 |
* @return array
|
100 |
*/
|
101 |
public function updateCheckLocales($locales) {
|
102 |
-
|
103 |
-
|
104 |
-
}
|
105 |
-
$localisation = new FlxMapLocalisation();
|
106 |
-
$langPacks = $localisation->getGlobalMapLocales();
|
107 |
|
108 |
$combined = array_unique(array_merge($locales, $langPacks));
|
109 |
|
110 |
return $combined;
|
111 |
}
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
}
|
46 |
$options = get_option(FLXMAP_PLUGIN_OPTIONS, array());
|
47 |
|
48 |
$options = wp_parse_args($options, array(
|
49 |
+
'apiKey' => '',
|
50 |
+
'apiServerKey' => '',
|
51 |
));
|
52 |
|
53 |
require FLXMAP_PLUGIN_ROOT . 'views/settings-form.php';
|
61 |
public function settingsValidate($input) {
|
62 |
$output = array();
|
63 |
|
64 |
+
$output['apiKey'] = trim(strip_tags($input['apiKey']));
|
65 |
+
$output['apiServerKey'] = trim(strip_tags($input['apiServerKey']));
|
66 |
|
67 |
return $output;
|
68 |
}
|
73 |
public function addPluginDetailsLinks($links, $file) {
|
74 |
// add settings link
|
75 |
if ($file == FLXMAP_PLUGIN_NAME) {
|
76 |
+
$links[] = sprintf('<a href="https://flexible-map.webaware.net.au/manual/getting-started/" rel="noopener" target="_blank">%s</a>', _x('Instructions', 'plugin details links', 'wp-flexible-map'));
|
77 |
+
$links[] = sprintf('<a href="https://wordpress.org/support/plugin/wp-flexible-map" rel="noopener" target="_blank">%s</a>', _x('Get Help', 'plugin details links', 'wp-flexible-map'));
|
78 |
+
$links[] = sprintf('<a href="https://wordpress.org/plugins/wp-flexible-map/" rel="noopener" target="_blank">%s</a>', _x('Rating', 'plugin details links', 'wp-flexible-map'));
|
79 |
+
$links[] = sprintf('<a href="https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map" rel="noopener" target="_blank">%s</a>', _x('Translate', 'plugin details links', 'wp-flexible-map'));
|
80 |
+
$links[] = sprintf('<a href="https://shop.webaware.com.au/donations/?donation_for=Flexible+Map" rel="noopener" target="_blank">%s</a>', _x('Donate', 'plugin details links', 'wp-flexible-map'));
|
81 |
}
|
82 |
|
83 |
return $links;
|
89 |
public function addPluginActionLinks($links) {
|
90 |
// add settings link
|
91 |
$url = admin_url('options-general.php?page=flexible-map');
|
92 |
+
$settings_link = sprintf('<a href="%s">%s</a>', esc_url($url), _x('Settings', 'plugin details links', 'wp-flexible-map'));
|
93 |
array_unshift($links, $settings_link);
|
94 |
|
95 |
return $links;
|
101 |
* @return array
|
102 |
*/
|
103 |
public function updateCheckLocales($locales) {
|
104 |
+
require_once FLXMAP_PLUGIN_ROOT . 'includes/class.FlxMapLocalisation.php';
|
105 |
+
$langPacks = FlxMapLocalisation::getGlobalMapLocales();
|
|
|
|
|
|
|
106 |
|
107 |
$combined = array_unique(array_merge($locales, $langPacks));
|
108 |
|
109 |
return $combined;
|
110 |
}
|
111 |
|
112 |
+
/**
|
113 |
+
* replace link placeholders with an external link
|
114 |
+
* @param string $template
|
115 |
+
* @param string $url
|
116 |
+
* @return string
|
117 |
+
*/
|
118 |
+
protected function addExternalLink($template, $url) {
|
119 |
+
$search = array(
|
120 |
+
'{{a}}',
|
121 |
+
'{{/a}}',
|
122 |
+
);
|
123 |
+
$replace = array(
|
124 |
+
sprintf('<a rel="noopener" target="_blank" href="%s">', esc_url($url)),
|
125 |
+
'</a>',
|
126 |
+
);
|
127 |
+
return str_replace($search, $replace, $template);
|
128 |
+
}
|
129 |
+
|
130 |
}
|
includes/class.FlxMapLocalisation.php
CHANGED
@@ -12,6 +12,22 @@ class FlxMapLocalisation {
|
|
12 |
const TEXT_DOMAIN = 'wp-flexible-map';
|
13 |
const TRANSIENT_LANGPACKS = 'flexible_map_langpacks';
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
/**
|
16 |
* get localisations for map scripts, ignoring admin localisations
|
17 |
* @param array $locales
|
@@ -41,6 +57,8 @@ class FlxMapLocalisation {
|
|
41 |
if ($mo->import_from_file($mofile)) {
|
42 |
$strings = self::getMoStrings($mofile);
|
43 |
if (!empty($strings)) {
|
|
|
|
|
44 |
$i18n[$locale] = $strings;
|
45 |
}
|
46 |
}
|
@@ -132,7 +150,7 @@ class FlxMapLocalisation {
|
|
132 |
* for global language updates from translate.wordpress.org
|
133 |
* @return array
|
134 |
*/
|
135 |
-
public function getGlobalMapLocales() {
|
136 |
$langPacks = get_site_transient(self::TRANSIENT_LANGPACKS);
|
137 |
|
138 |
if (!is_array($langPacks)) {
|
@@ -148,7 +166,7 @@ class FlxMapLocalisation {
|
|
148 |
* @param array $locales
|
149 |
*/
|
150 |
protected function updateGlobalMapLocales($locales) {
|
151 |
-
$langPacks =
|
152 |
$diff = array_diff($locales, $langPacks);
|
153 |
|
154 |
if (!empty($diff)) {
|
12 |
const TEXT_DOMAIN = 'wp-flexible-map';
|
13 |
const TRANSIENT_LANGPACKS = 'flexible_map_langpacks';
|
14 |
|
15 |
+
protected $script_strings;
|
16 |
+
|
17 |
+
/**
|
18 |
+
* initialise the class if it hasn't been
|
19 |
+
*/
|
20 |
+
public function __construct() {
|
21 |
+
// declare l10n strings used in JavaScript so a gettext scanner can find them
|
22 |
+
// and record for use in filtering localisations
|
23 |
+
$this->script_strings = array(
|
24 |
+
'Click for details' => __('Click for details', 'wp-flexible-map'),
|
25 |
+
'Directions' => __('Directions', 'wp-flexible-map'),
|
26 |
+
'From' => __('From', 'wp-flexible-map'),
|
27 |
+
'Get directions' => __('Get directions', 'wp-flexible-map'),
|
28 |
+
);
|
29 |
+
}
|
30 |
+
|
31 |
/**
|
32 |
* get localisations for map scripts, ignoring admin localisations
|
33 |
* @param array $locales
|
57 |
if ($mo->import_from_file($mofile)) {
|
58 |
$strings = self::getMoStrings($mofile);
|
59 |
if (!empty($strings)) {
|
60 |
+
// filter to only contain strings we need in JavaScript
|
61 |
+
$strings = array_intersect_key($strings, $this->script_strings);
|
62 |
$i18n[$locale] = $strings;
|
63 |
}
|
64 |
}
|
150 |
* for global language updates from translate.wordpress.org
|
151 |
* @return array
|
152 |
*/
|
153 |
+
public static function getGlobalMapLocales() {
|
154 |
$langPacks = get_site_transient(self::TRANSIENT_LANGPACKS);
|
155 |
|
156 |
if (!is_array($langPacks)) {
|
166 |
* @param array $locales
|
167 |
*/
|
168 |
protected function updateGlobalMapLocales($locales) {
|
169 |
+
$langPacks = self::getGlobalMapLocales();
|
170 |
$diff = array_diff($locales, $langPacks);
|
171 |
|
172 |
if (!empty($diff)) {
|
includes/class.FlxMapPlugin.php
CHANGED
@@ -8,8 +8,6 @@ if (!defined('ABSPATH')) {
|
|
8 |
* class for managing the plugin
|
9 |
*/
|
10 |
class FlxMapPlugin {
|
11 |
-
public $urlBase; // string: base URL path to files in plugin
|
12 |
-
|
13 |
protected $locale; // locale of current website
|
14 |
protected $locales = array(); // list of locales enqueued for localisation of maps
|
15 |
protected $mapTypes = array(); // custom Google Maps map types to be loaded with maps, keyed by mapTypeId
|
@@ -30,12 +28,15 @@ class FlxMapPlugin {
|
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
-
*
|
34 |
*/
|
35 |
private function __construct() {
|
36 |
-
|
37 |
-
$this->urlBase = plugin_dir_url(FLXMAP_PLUGIN_FILE);
|
38 |
|
|
|
|
|
|
|
|
|
39 |
add_action('init', array($this, 'init'));
|
40 |
|
41 |
if (is_admin()) {
|
@@ -85,7 +86,7 @@ class FlxMapPlugin {
|
|
85 |
public function enqueueScripts() {
|
86 |
$options = get_option(FLXMAP_PLUGIN_OPTIONS, array());
|
87 |
|
88 |
-
$args = array('v' => '3.
|
89 |
if (!empty($options['apiKey'])) {
|
90 |
$args['key'] = $options['apiKey'];
|
91 |
}
|
@@ -98,10 +99,10 @@ class FlxMapPlugin {
|
|
98 |
|
99 |
$min = SCRIPT_DEBUG ? '' : '.min';
|
100 |
$ver = SCRIPT_DEBUG ? time() : FLXMAP_PLUGIN_VERSION;
|
101 |
-
wp_register_script('flxmap', "
|
102 |
|
103 |
// theme writers: you can remove this stylesheet by calling wp_dequeue_script('flxmap');
|
104 |
-
wp_enqueue_style('flxmap',
|
105 |
}
|
106 |
|
107 |
/**
|
@@ -120,9 +121,7 @@ class FlxMapPlugin {
|
|
120 |
$localise = array();
|
121 |
|
122 |
if (!empty($this->locales)) {
|
123 |
-
|
124 |
-
require FLXMAP_PLUGIN_ROOT . 'includes/class.FlxMapLocalisation.php';
|
125 |
-
}
|
126 |
$localisation = new FlxMapLocalisation();
|
127 |
$i18n = $localisation->getLocalisations($this->locales);
|
128 |
if (!empty($i18n)) {
|
@@ -510,18 +509,28 @@ HTML;
|
|
510 |
|
511 |
/**
|
512 |
* get coordinate for given address
|
|
|
513 |
* @param string $address
|
514 |
* @param string $region
|
515 |
* @return array|false
|
516 |
*/
|
517 |
protected static function getAddressCoordinates($address, $region) {
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
// try to get a cached answer first
|
519 |
$cacheKey = 'flxmap_' . md5("$address|$region");
|
520 |
$coords = get_transient($cacheKey);
|
521 |
|
522 |
if ($coords === false) {
|
523 |
// build Google Maps geocoding query
|
524 |
-
$args = array(
|
|
|
|
|
|
|
525 |
if (!empty($region)) {
|
526 |
$args['region'] = urlencode($region);
|
527 |
}
|
@@ -541,7 +550,7 @@ HTML;
|
|
541 |
}
|
542 |
|
543 |
if ($result->status != 'OK') {
|
544 |
-
throw new Exception("error retrieving address: "
|
545 |
}
|
546 |
|
547 |
// success, return array with latitude and longitude
|
8 |
* class for managing the plugin
|
9 |
*/
|
10 |
class FlxMapPlugin {
|
|
|
|
|
11 |
protected $locale; // locale of current website
|
12 |
protected $locales = array(); // list of locales enqueued for localisation of maps
|
13 |
protected $mapTypes = array(); // custom Google Maps map types to be loaded with maps, keyed by mapTypeId
|
28 |
}
|
29 |
|
30 |
/**
|
31 |
+
* hide the constructor
|
32 |
*/
|
33 |
private function __construct() {
|
34 |
+
}
|
|
|
35 |
|
36 |
+
/**
|
37 |
+
* hook into WordPress actions and filters
|
38 |
+
*/
|
39 |
+
public function addHooks() {
|
40 |
add_action('init', array($this, 'init'));
|
41 |
|
42 |
if (is_admin()) {
|
86 |
public function enqueueScripts() {
|
87 |
$options = get_option(FLXMAP_PLUGIN_OPTIONS, array());
|
88 |
|
89 |
+
$args = array('v' => '3.32');
|
90 |
if (!empty($options['apiKey'])) {
|
91 |
$args['key'] = $options['apiKey'];
|
92 |
}
|
99 |
|
100 |
$min = SCRIPT_DEBUG ? '' : '.min';
|
101 |
$ver = SCRIPT_DEBUG ? time() : FLXMAP_PLUGIN_VERSION;
|
102 |
+
wp_register_script('flxmap', plugins_url("js/flexible-map$min.js", FLXMAP_PLUGIN_FILE), array('google-maps'), $ver, true);
|
103 |
|
104 |
// theme writers: you can remove this stylesheet by calling wp_dequeue_script('flxmap');
|
105 |
+
wp_enqueue_style('flxmap', plugins_url('css/styles.css', FLXMAP_PLUGIN_FILE), false, $ver);
|
106 |
}
|
107 |
|
108 |
/**
|
121 |
$localise = array();
|
122 |
|
123 |
if (!empty($this->locales)) {
|
124 |
+
require_once FLXMAP_PLUGIN_ROOT . 'includes/class.FlxMapLocalisation.php';
|
|
|
|
|
125 |
$localisation = new FlxMapLocalisation();
|
126 |
$i18n = $localisation->getLocalisations($this->locales);
|
127 |
if (!empty($i18n)) {
|
509 |
|
510 |
/**
|
511 |
* get coordinate for given address
|
512 |
+
* @link https://developers.google.com/maps/documentation/geocoding/intro
|
513 |
* @param string $address
|
514 |
* @param string $region
|
515 |
* @return array|false
|
516 |
*/
|
517 |
protected static function getAddressCoordinates($address, $region) {
|
518 |
+
// only if we have an API key for server requests
|
519 |
+
$options = get_option(FLXMAP_PLUGIN_OPTIONS, array());
|
520 |
+
if (empty($options['apiServerKey'])) {
|
521 |
+
return false;
|
522 |
+
}
|
523 |
+
|
524 |
// try to get a cached answer first
|
525 |
$cacheKey = 'flxmap_' . md5("$address|$region");
|
526 |
$coords = get_transient($cacheKey);
|
527 |
|
528 |
if ($coords === false) {
|
529 |
// build Google Maps geocoding query
|
530 |
+
$args = array(
|
531 |
+
'address' => urlencode($address),
|
532 |
+
'key' => $options['apiServerKey'],
|
533 |
+
);
|
534 |
if (!empty($region)) {
|
535 |
$args['region'] = urlencode($region);
|
536 |
}
|
550 |
}
|
551 |
|
552 |
if ($result->status != 'OK') {
|
553 |
+
throw new Exception(sprintf("error retrieving address: %s; %s", $result->status, $result->error_message));
|
554 |
}
|
555 |
|
556 |
// success, return array with latitude and longitude
|
includes/declare-strings.php
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
if (!defined('ABSPATH')) {
|
4 |
-
exit;
|
5 |
-
}
|
6 |
-
|
7 |
-
/**
|
8 |
-
* declare l10n strings used in JavaScript so a gettext scanner can find them
|
9 |
-
* NB: never called!
|
10 |
-
*/
|
11 |
-
function justDeclare() {
|
12 |
-
$strings = array(
|
13 |
-
__('Click for details', 'wp-flexible-map'),
|
14 |
-
__('Directions', 'wp-flexible-map'),
|
15 |
-
__('From', 'wp-flexible-map'),
|
16 |
-
__('Get directions', 'wp-flexible-map'),
|
17 |
-
);
|
18 |
-
}
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/functions-global.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
if (!defined('ABSPATH')) {
|
4 |
+
exit;
|
5 |
+
}
|
6 |
+
|
7 |
+
/**
|
8 |
+
* utility function so themes can easily display the map
|
9 |
+
* to return as a string without output to screen, add 'echo'=>'false' to array of attributes
|
10 |
+
* @param array $attrs
|
11 |
+
* @return string
|
12 |
+
*/
|
13 |
+
function flexmap_show_map($attrs) {
|
14 |
+
$plugin = FlxMapPlugin::getInstance();
|
15 |
+
$map = $plugin->getMap($attrs);
|
16 |
+
|
17 |
+
if (!isset($attrs['echo']) || FlxMapPlugin::isYes($attrs['echo'])) {
|
18 |
+
echo $map;
|
19 |
+
}
|
20 |
+
|
21 |
+
return $map;
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* load the scripts required for the maps to work, e.g. for single-page AJAX websites
|
26 |
+
* @param array $locales optional: an array of required locale scripts
|
27 |
+
*/
|
28 |
+
function flexmap_load_scripts($locales = array()) {
|
29 |
+
wp_enqueue_script('flxmap');
|
30 |
+
|
31 |
+
if (count($locales) > 0) {
|
32 |
+
$plugin = FlxMapPlugin::getInstance();
|
33 |
+
$plugin->setLocales($locales);
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
js/flexible-map.min.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
// Flexible Map
|
2 |
// https://flexible-map.webaware.net.au/
|
3 |
|
4 |
-
window.FlexibleMap=function(){"use strict";var e,t,i,r,o,n,a=!1;this.getMap=function(){return e},this.getCenter=function(){return t},this.setCenter=function(i){t=i,e.setCenter(t)},this.setMarkerLocation=function(e){i=e},this.getMarkerLocation=function(){return i},this.setMarkerPoint=function(e){r=e},this.getMarkerPoint=function(){return r},this.setMarkerInfowin=function(e){o=e},this.getMarkerInfowin=function(){return o},this.getKmlLayer=function(){return n},this.redrawOnce=function(){a||(a=!0,this.redraw())},this.showMap=function(i,r){t=new google.maps.LatLng(r[0],r[1]);var o,n={small:google.maps.ZoomControlStyle.SMALL,large:google.maps.ZoomControlStyle.LARGE,default:google.maps.ZoomControlStyle.DEFAULT},a=n.small;return this.zoomControlStyle in n&&(a=n[this.zoomControlStyle]),o={mapTypeId:this.mapTypeId,mapTypeControl:this.mapTypeControl,scaleControl:this.scaleControl,panControl:this.panControl,streetViewControl:this.streetViewControl,zoomControl:this.zoomControl,zoomControlOptions:{style:a},draggable:this.draggable,disableDoubleClickZoom:!this.dblclickZoom,scrollwheel:this.scrollwheel,center:t,zoom:this.zoom},this.mapTypeIds&&(o.mapTypeControlOptions={mapTypeIds:this.mapTypeIds.split(",")}),e=new google.maps.Map(document.getElementById(i),o),this.mapTypeId in this.mapTypes&&e.mapTypes.set(this.mapTypeId,this.mapTypes[this.mapTypeId]._styled_map),e},this.loadKmlMap=function(i){return n=new google.maps.KmlLayer({map:e,url:i}),google.maps.event.addListenerOnce(n,"defaultviewport_changed",function(){t=n.getDefaultViewport().getCenter()}),n},!this.localised&&"flxmap"in window&&this.localise(),this.mapTypeId=google.maps.MapTypeId.ROADMAP,this.mapTypeControl=!0,this.scaleControl=!1,this.panControl=!1,this.zoomControl=!0,this.zoomControlStyle="small",this.streetViewControl=!1,this.scrollwheel=!1,this.draggable=!0,this.dblclickZoom=!0,this.zoom=16,this.markerTitle="",this.markerDescription="",this.markerHTML="",this.markerLink="",this.markerLinkTarget="",this.markerLinkText=!1,this.markerIcon="",this.markerShowInfo=!0,this.markerDirections=!1,this.markerDirectionsShow=!1,this.markerDirectionsDefault="",this.markerAddress="",this.targetFix=!0,this.dirService=!1,this.dirRenderer=!1,this.dirDraggable=!1,this.dirSuppressMarkers=!1,this.dirShowSteps=!0,this.dirShowSearch=!0,this.dirTravelMode="driving",this.dirUnitSystem=void 0,this.region="",this.locale="en",this.localeActive=!1,this.kmlcache="none"},FlexibleMap.prototype=function(){"use strict";var e,t,i;document.addEventListener?(e=function(e,t,i){e.addEventListener(t,i,!1)},t=function(e){e.stopPropagation(),e.preventDefault()}):document.attachEvent&&(e=function(e,t,i){e.attachEvent("on"+t,function(){i.call(e,window.event)})},t=function(e){e.cancelBubble=!0,e.returnValue=0}),i="undefined"!=typeof MutationObserver?function(e,t){var i=document.getElementById(t).parentNode;function r(e){var t=window.getComputedStyle(e);return"none"===t.display||"hidden"===t.visibility}r(i)&&new MutationObserver(function(t,o){r(i)||(e.redrawOnce(),o.disconnect())}).observe(i,{attributes:!0,attributeFilter:["style"]})}:function(){};var r=function(){function e(e){var t=e.charCodeAt(0),i=t.toString(16);return t<256?"\\x"+("00"+i).slice(-2):"\\u"+("0000"+i).slice(-4)}return function(t){return t.replace(/[\\/"'&<>\x00-\x1f\x7f-\xa0\u2000-\u200f\u2028-\u202f]/g,e)}}();return{constructor:FlexibleMap,i18n:{},mapTypes:{},localised:!1,localise:function(){var e,t;if("i18n"in flxmap&&(FlexibleMap.prototype.i18n=flxmap.i18n),"mapTypes"in flxmap){t=flxmap.mapTypes;for(e in t)t[e]._styled_map=new google.maps.StyledMapType(t[e].styles,t[e].options);FlexibleMap.prototype.mapTypes=t}FlexibleMap.prototype.localised=!0},setlocale:function(e){return this.locale=e,e in this.i18n?this.localeActive=e:e.substr(0,2)in this.i18n?this.localeActive=e:this.localeActive=!1,this.localeActive},gettext:function(e){var t=this.localeActive;return t&&e in this.i18n[t]?this.i18n[t][e]:e},showKML:function(o,n,a){void 0!==a&&(this.zoom=a);var s=this,l=document.getElementById(o),c=l.getAttribute("data-flxmap"),d=this.showMap(o,[0,0]),m=this.loadKmlMap(function(e,t){var i,r,o,n=/^(\d+)\s*(minute|hour|day)s?$/.exec(t);if(n){switch(i=(new Date).getTime(),o=+n[1],n[2]){case"minute":o<5&&(o=5),r=i/(6e4*o);break;case"hour":r=i/(36e5*o);break;case"day":r=i/(864e5*o);break;default:r=!1}r&&(r=Math.floor(r),e+=(e.indexOf("?")>-1?"&":"?")+"nocache="+r)}return e}(n,this.kmlcache));i(this,o),void 0!==a&&google.maps.event.addListenerOnce(d,"zoom_changed",function(){d.setZoom(a),s.zoom=a}),(this.markerDirections||this.markerDirectionsShow)&&this.startDirService(d),google.maps.event.addListener(m,"click",function(e){var t=e.featureData;if(!t._flxmapOnce){if(t._flxmapOnce=!0,s.targetFix&&t.description){var i=/ target="_blank"/gi;t.description=t.description.replace(i,""),t.infoWindowHtml=t.infoWindowHtml.replace(i,"")}if(s.markerDirections){var o=e.latLng,n=o.lat()+","+o.lng()+",'"+r(t.name)+"',true",a='<br /><a href="#" data-flxmap-fix-opera="1" onclick="'+c+".showDirections("+n+'); return false;">'+s.gettext("Directions")+"</a>";t.infoWindowHtml=t.infoWindowHtml.replace(/<\/div><\/div>$/i,a+"</div></div>")}}}),window.opera&&this.markerDirections&&e(l,"click",function(e){e.target.getAttribute("data-flxmap-fix-opera")&&t(e)})},showMarker:function(r,o,n){var a=this.showMap(r,o),s=new google.maps.LatLng(n[0],n[1]),l=new google.maps.Marker({map:a,position:s,icon:this.markerIcon});if(this.setMarkerPoint(l),this.setMarkerLocation(s),i(this,r),this.markerTitle||(this.markerTitle=this.markerAddress),this.markerTitle||this.markerHTML||this.markerDescription||this.markerLink||this.markerDirections){var c,d,m,h,p,u,g=this,f=document.createElement("DIV");if(f.className="flxmap-infowin",(p=document.createElement("DIV")).className="flxmap-marker-title",this.markerTitle&&(p.appendChild(document.createTextNode(this.markerTitle)),l.setTitle(this.markerTitle)),f.appendChild(p),this.markerHTML&&((p=document.createElement("DIV")).innerHTML=this.markerHTML,f.appendChild(p)),this.markerDescription||this.markerLink){if((p=document.createElement("DIV")).className="flxmap-marker-link",this.markerDescription){for(c=0,d=(m=this.markerDescription.split("\n")).length;c<d;c++)c>0&&p.appendChild(document.createElement("BR")),p.appendChild(document.createTextNode(m[c]));this.markerLink&&p.appendChild(document.createElement("BR"))}this.markerLink&&((u=document.createElement("A")).href=this.markerLink,this.markerLinkTarget&&(u.target=this.markerLinkTarget),u.appendChild(document.createTextNode(this.markerLinkText||this.gettext("Click for details"))),p.appendChild(u)),f.appendChild(p)}this.markerDirections&&((p=document.createElement("DIV")).className="flxmap-directions-link",(u=document.createElement("A")).href="#",u.dataLatitude=n[0],u.dataLongitude=n[1],e(u,"click",function(e){t(e),g.showDirections(this.dataLatitude,this.dataLongitude,!0)}),u.appendChild(document.createTextNode(this.gettext("Directions"))),p.appendChild(u),f.appendChild(p)),h=new google.maps.InfoWindow({content:f}),this.setMarkerInfowin(h),this.markerShowInfo&&google.maps.event.addListenerOnce(a,"tilesloaded",function(){h.open(a,l)}),google.maps.event.addListener(l,"click",function(){h.open(a,l)});var k=function(){g.updateGoogleLink()};google.maps.event.addListener(a,"idle",k),google.maps.event.addListener(a,"center_changed",k),google.maps.event.addListenerOnce(a,"tilesloaded",k)}(this.markerDirections||this.markerDirectionsShow)&&(this.startDirService(a),this.markerDirectionsShow&&this.showDirections(n[0],n[1],!1))},showAddress:function(e,t){var i=this,r=new google.maps.Geocoder;this.markerAddress=t,""===this.markerTitle&&(this.markerTitle=t),r.geocode({address:t,region:this.region},function(t,r){if(r===google.maps.GeocoderStatus.OK){var o=t[0].geometry.location,n=[o.lat(),o.lng()];i.showMarker(e,n,n)}else window.alert("Map address returns error: "+r)})},updateGoogleLink:function(){if("querySelectorAll"in document)try{for(var e=this.getMap().getDiv(),t=this.getMarkerLocation(),i=e.querySelectorAll("a[href*='maps.google.com/maps']:not([href*='mps_dialog']):not([href*='&q='])"),r=0,o=i.length,n=encodeURIComponent((this.markerAddress?this.markerAddress:this.markerTitle)+" @"+t.lat()+","+t.lng());r<o;r++)i[r].href+="&mrt=loc&iwloc=A&q="+n}catch(e){}},redraw:function(){var e=this.getMap(),t=this.getKmlLayer();if(google.maps.event.trigger(e,"resize"),t)e.fitBounds(t.getDefaultViewport());else{e.setCenter(this.getCenter()),e.setZoom(this.zoom);var i=this.getMarkerInfowin();i&&i.open(e,this.getMarkerPoint())}},startDirService:function(e){this.dirService||(this.dirService=new google.maps.DirectionsService),this.dirRenderer||(this.dirRenderer=new google.maps.DirectionsRenderer({map:e,draggable:this.dirDraggable,suppressMarkers:this.dirSuppressMarkers,panel:this.dirShowSteps?document.getElementById(this.markerDirectionsDiv):null}))},showDirections:function(i,r,o){var n=this;function a(e){var t={origin:e,destination:""===n.markerAddress?new google.maps.LatLng(i,r):n.markerAddress};switch(n.region&&(t.region=n.region),n.dirTravelMode){case"bicycling":t.travelMode=google.maps.TravelMode.BICYCLING;break;case"driving":t.travelMode=google.maps.TravelMode.DRIVING;break;case"transit":t.travelMode=google.maps.TravelMode.TRANSIT;break;case"walking":t.travelMode=google.maps.TravelMode.WALKING}switch(n.dirUnitSystem){case"imperial":t.unitSystem=google.maps.UnitSystem.IMPERIAL;break;case"metric":t.unitSystem=google.maps.UnitSystem.METRIC}n.dirService.route(t,s)}function s(e,t){var i=google.maps.DirectionsStatus;switch(t){case i.OK:n.dirRenderer.setDirections(e);break;case i.ZERO_RESULTS:window.alert("No route could be found between the origin and destination.");break;case i.OVER_QUERY_LIMIT:window.alert("The webpage has gone over the requests limit in too short a period of time.");break;case i.REQUEST_DENIED:window.alert("The webpage is not allowed to use the directions service.");break;case i.INVALID_REQUEST:window.alert("Invalid directions request.");break;case i.NOT_FOUND:window.alert("Origin or destination was not found.");break;default:window.alert("A directions request could not be processed due to a server error. The request may succeed if you try again.")}}this.markerDirectionsDiv&&this.dirShowSearch&&function(){var i,r,s,l=document.getElementById(n.markerDirectionsDiv),c=document.createElement("form");for(r=l.lastChild;r;r=l.lastChild)l.removeChild(r);(r=document.createElement("p")).appendChild(document.createTextNode(n.gettext("From")+": ")),(s=document.createElement("input")).type="text",s.name="from",s.value=n.markerDirectionsDefault,r.appendChild(s),(i=document.createElement("input")).type="submit",i.value=n.gettext("Get directions"),r.appendChild(i),c.appendChild(r),l.appendChild(c),void 0===c.elements.from&&(c.elements.from=s),o&&s.focus(),e(c,"submit",function(e){t(e);var i=this.elements.from.value;/\S/.test(i)&&a(i)})}(),this.markerDirectionsDefault&&a(this.markerDirectionsDefault)}}}();
|
1 |
// Flexible Map
|
2 |
// https://flexible-map.webaware.net.au/
|
3 |
|
4 |
+
window.FlexibleMap=function(){"use strict";var n,a,t,i,r,o,e=!1;this.getMap=function(){return n},this.getCenter=function(){return a},this.setCenter=function(e){a=e,n.setCenter(a)},this.setMarkerLocation=function(e){t=e},this.getMarkerLocation=function(){return t},this.setMarkerPoint=function(e){i=e},this.getMarkerPoint=function(){return i},this.setMarkerInfowin=function(e){r=e},this.getMarkerInfowin=function(){return r},this.getKmlLayer=function(){return o},this.redrawOnce=function(){e||(e=!0,this.redraw())},this.showMap=function(e,t){a=new google.maps.LatLng(t[0],t[1]);var i,r={small:google.maps.ZoomControlStyle.SMALL,large:google.maps.ZoomControlStyle.LARGE,default:google.maps.ZoomControlStyle.DEFAULT},o=r.small;return this.zoomControlStyle in r&&(o=r[this.zoomControlStyle]),i={mapTypeId:this.mapTypeId,mapTypeControl:this.mapTypeControl,scaleControl:this.scaleControl,panControl:this.panControl,streetViewControl:this.streetViewControl,zoomControl:this.zoomControl,zoomControlOptions:{style:o},draggable:this.draggable,disableDoubleClickZoom:!this.dblclickZoom,scrollwheel:this.scrollwheel,center:a,zoom:this.zoom},this.mapTypeIds&&(i.mapTypeControlOptions={mapTypeIds:this.mapTypeIds.split(",")}),n=new google.maps.Map(document.getElementById(e),i),this.mapTypeId in this.mapTypes&&n.mapTypes.set(this.mapTypeId,this.mapTypes[this.mapTypeId]._styled_map),n},this.loadKmlMap=function(e){return o=new google.maps.KmlLayer({map:n,url:e}),google.maps.event.addListenerOnce(o,"defaultviewport_changed",function(){a=o.getDefaultViewport().getCenter()}),o},!this.localised&&"flxmap"in window&&this.localise(),this.mapTypeId=google.maps.MapTypeId.ROADMAP,this.mapTypeControl=!0,this.scaleControl=!1,this.panControl=!1,this.zoomControl=!0,this.zoomControlStyle="small",this.streetViewControl=!1,this.scrollwheel=!1,this.draggable=!0,this.dblclickZoom=!0,this.zoom=16,this.markerTitle="",this.markerDescription="",this.markerHTML="",this.markerLink="",this.markerLinkTarget="",this.markerLinkText=!1,this.markerIcon="",this.markerShowInfo=!0,this.markerDirections=!1,this.markerDirectionsShow=!1,this.markerDirectionsDefault="",this.markerAddress="",this.targetFix=!0,this.dirService=!1,this.dirRenderer=!1,this.dirDraggable=!1,this.dirSuppressMarkers=!1,this.dirShowSteps=!0,this.dirShowSearch=!0,this.dirTravelMode="driving",this.dirUnitSystem=void 0,this.region="",this.locale="en",this.localeActive=!1,this.kmlcache="none"},FlexibleMap.prototype=function(){"use strict";var g,f,k;document.addEventListener?(g=function(e,t,i){e.addEventListener(t,i,!1)},f=function(e){e.stopPropagation(),e.preventDefault()}):document.attachEvent&&(g=function(e,t,i){e.attachEvent("on"+t,function(){i.call(e,window.event)})},f=function(e){e.cancelBubble=!0,e.returnValue=0}),k="undefined"!=typeof MutationObserver?function(i,e){var r=document.getElementById(e).parentNode;function o(e){var t=window.getComputedStyle(e);return"none"===t.display||"hidden"===t.visibility}o(r)&&new MutationObserver(function(e,t){o(r)||(i.redrawOnce(),t.disconnect())}).observe(r,{attributes:!0,attributeFilter:["style"]})}:function(){};var l=function(){function t(e){var t=e.charCodeAt(0),i=t.toString(16);return t<256?"\\x"+("00"+i).slice(-2):"\\u"+("0000"+i).slice(-4)}return function(e){return e.replace(/[\\/"'&<>\x00-\x1f\x7f-\xa0\u2000-\u200f\u2028-\u202f]/g,t)}}();return{constructor:FlexibleMap,i18n:{},mapTypes:{},localised:!1,localise:function(){var e,t;if("i18n"in flxmap&&(FlexibleMap.prototype.i18n=flxmap.i18n),"mapTypes"in flxmap){for(e in t=flxmap.mapTypes)t[e]._styled_map=new google.maps.StyledMapType(t[e].styles,t[e].options);FlexibleMap.prototype.mapTypes=t}FlexibleMap.prototype.localised=!0},setlocale:function(e){return(this.locale=e)in this.i18n?this.localeActive=e:e.substr(0,2)in this.i18n?this.localeActive=e:this.localeActive=!1,this.localeActive},gettext:function(e){var t=this.localeActive;return t&&e in this.i18n[t]?this.i18n[t][e]:e},showKML:function(e,t,i){void 0!==i&&(this.zoom=i);var a=this,r=document.getElementById(e),s=r.getAttribute("data-flxmap"),o=this.showMap(e,[0,0]),n=this.loadKmlMap(function(e,t){var i,r,o,n=/^(\d+)\s*(minute|hour|day)s?$/.exec(t);if(n){switch(i=(new Date).getTime(),o=+n[1],n[2]){case"minute":o<5&&(o=5),r=i/(6e4*o);break;case"hour":r=i/(36e5*o);break;case"day":r=i/(864e5*o);break;default:r=!1}r&&(r=Math.floor(r),e+=(-1<e.indexOf("?")?"&":"?")+"nocache="+r)}return e}(t,this.kmlcache));k(this,e),void 0!==i&&google.maps.event.addListenerOnce(o,"zoom_changed",function(){o.setZoom(i),a.zoom=i}),(this.markerDirections||this.markerDirectionsShow)&&this.startDirService(o),google.maps.event.addListener(n,"click",function(e){var t=e.featureData;if(!t._flxmapOnce){if(t._flxmapOnce=!0,a.targetFix&&t.description){var i=/ target="_blank"/gi;t.description=t.description.replace(i,""),t.infoWindowHtml=t.infoWindowHtml.replace(i,"")}if(a.markerDirections){var r=e.latLng,o=r.lat()+","+r.lng()+",'"+l(t.name)+"',true",n='<br /><a href="#" data-flxmap-fix-opera="1" onclick="'+s+".showDirections("+o+'); return false;">'+a.gettext("Directions")+"</a>";t.infoWindowHtml=t.infoWindowHtml.replace(/<\/div><\/div>$/i,n+"</div></div>")}}}),window.opera&&this.markerDirections&&g(r,"click",function(e){e.target.getAttribute("data-flxmap-fix-opera")&&f(e)})},showMarker:function(e,t,i){var r=this.showMap(e,t),o=new google.maps.LatLng(i[0],i[1]),n=new google.maps.Marker({map:r,position:o,icon:this.markerIcon});if(this.setMarkerPoint(n),this.setMarkerLocation(o),k(this,e),this.markerTitle||(this.markerTitle=this.markerAddress),this.markerTitle||this.markerHTML||this.markerDescription||this.markerLink||this.markerDirections){var a,s,l,c,d,m,h=this,p=document.createElement("DIV");if(p.className="flxmap-infowin",(d=document.createElement("DIV")).className="flxmap-marker-title",this.markerTitle&&(d.appendChild(document.createTextNode(this.markerTitle)),n.setTitle(this.markerTitle)),p.appendChild(d),this.markerHTML&&((d=document.createElement("DIV")).innerHTML=this.markerHTML,p.appendChild(d)),this.markerDescription||this.markerLink){if((d=document.createElement("DIV")).className="flxmap-marker-link",this.markerDescription){for(a=0,s=(l=this.markerDescription.split("\n")).length;a<s;a++)0<a&&d.appendChild(document.createElement("BR")),d.appendChild(document.createTextNode(l[a]));this.markerLink&&d.appendChild(document.createElement("BR"))}this.markerLink&&((m=document.createElement("A")).href=this.markerLink,this.markerLinkTarget&&(m.target=this.markerLinkTarget),m.appendChild(document.createTextNode(this.markerLinkText||this.gettext("Click for details"))),d.appendChild(m)),p.appendChild(d)}this.markerDirections&&((d=document.createElement("DIV")).className="flxmap-directions-link",(m=document.createElement("A")).href="#",m.dataLatitude=i[0],m.dataLongitude=i[1],g(m,"click",function(e){f(e),h.showDirections(this.dataLatitude,this.dataLongitude,!0)}),m.appendChild(document.createTextNode(this.gettext("Directions"))),d.appendChild(m),p.appendChild(d)),c=new google.maps.InfoWindow({content:p}),this.setMarkerInfowin(c),this.markerShowInfo&&google.maps.event.addListenerOnce(r,"tilesloaded",function(){c.open(r,n)}),google.maps.event.addListener(n,"click",function(){c.open(r,n)});var u=function(){h.updateGoogleLink()};google.maps.event.addListener(r,"idle",u),google.maps.event.addListener(r,"center_changed",u),google.maps.event.addListenerOnce(r,"tilesloaded",u)}(this.markerDirections||this.markerDirectionsShow)&&(this.startDirService(r),this.markerDirectionsShow&&this.showDirections(i[0],i[1],!1))},showAddress:function(o,e){var n=this,t=new google.maps.Geocoder;this.markerAddress=e,""===this.markerTitle&&(this.markerTitle=e),t.geocode({address:e,region:this.region},function(e,t){if(t===google.maps.GeocoderStatus.OK){var i=e[0].geometry.location,r=[i.lat(),i.lng()];n.showMarker(o,r,r)}else window.alert("Map address returns error: "+t)})},updateGoogleLink:function(){if("querySelectorAll"in document)try{for(var e=this.getMap().getDiv(),t=this.getMarkerLocation(),i=e.querySelectorAll("a[href*='maps.google.com/maps']:not([href*='mps_dialog']):not([href*='&q='])"),r=0,o=i.length,n=encodeURIComponent((this.markerAddress?this.markerAddress:this.markerTitle)+" @"+t.lat()+","+t.lng());r<o;r++)i[r].href+="&mrt=loc&iwloc=A&q="+n}catch(e){}},redraw:function(){var e=this.getMap(),t=this.getKmlLayer();if(google.maps.event.trigger(e,"resize"),t)e.fitBounds(t.getDefaultViewport());else{e.setCenter(this.getCenter()),e.setZoom(this.zoom);var i=this.getMarkerInfowin();i&&i.open(e,this.getMarkerPoint())}},startDirService:function(e){this.dirService||(this.dirService=new google.maps.DirectionsService),this.dirRenderer||(this.dirRenderer=new google.maps.DirectionsRenderer({map:e,draggable:this.dirDraggable,suppressMarkers:this.dirSuppressMarkers,panel:this.dirShowSteps?document.getElementById(this.markerDirectionsDiv):null}))},showDirections:function(i,r,n){var a=this;function s(e){var t={origin:e,destination:""===a.markerAddress?new google.maps.LatLng(i,r):a.markerAddress};switch(a.region&&(t.region=a.region),a.dirTravelMode){case"bicycling":t.travelMode=google.maps.TravelMode.BICYCLING;break;case"driving":t.travelMode=google.maps.TravelMode.DRIVING;break;case"transit":t.travelMode=google.maps.TravelMode.TRANSIT;break;case"walking":t.travelMode=google.maps.TravelMode.WALKING}switch(a.dirUnitSystem){case"imperial":t.unitSystem=google.maps.UnitSystem.IMPERIAL;break;case"metric":t.unitSystem=google.maps.UnitSystem.METRIC}a.dirService.route(t,o)}function o(e,t){var i=google.maps.DirectionsStatus;switch(t){case i.OK:a.dirRenderer.setDirections(e);break;case i.ZERO_RESULTS:window.alert("No route could be found between the origin and destination.");break;case i.OVER_QUERY_LIMIT:window.alert("The webpage has gone over the requests limit in too short a period of time.");break;case i.REQUEST_DENIED:window.alert("The webpage is not allowed to use the directions service.");break;case i.INVALID_REQUEST:window.alert("Invalid directions request.");break;case i.NOT_FOUND:window.alert("Origin or destination was not found.");break;default:window.alert("A directions request could not be processed due to a server error. The request may succeed if you try again.")}}this.markerDirectionsDiv&&this.dirShowSearch&&function(){var e,t,i,r=document.getElementById(a.markerDirectionsDiv),o=document.createElement("form");for(t=r.lastChild;t;t=r.lastChild)r.removeChild(t);(t=document.createElement("p")).appendChild(document.createTextNode(a.gettext("From")+": ")),(i=document.createElement("input")).type="text",i.name="from",i.value=a.markerDirectionsDefault,t.appendChild(i),(e=document.createElement("input")).type="submit",e.value=a.gettext("Get directions"),t.appendChild(e),o.appendChild(t),r.appendChild(o),void 0===o.elements.from&&(o.elements.from=i),n&&i.focus(),g(o,"submit",function(e){f(e);var t=this.elements.from.value;/\S/.test(t)&&s(t)})}(),this.markerDirectionsDefault&&s(this.markerDirectionsDefault)}}}();
|
readme.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
Contributors: webaware
|
3 |
Plugin Name: Flexible Map
|
4 |
Plugin URI: https://flexible-map.webaware.net.au/
|
@@ -7,18 +7,18 @@ Donate link: https://shop.webaware.com.au/donations/?donation_for=Flexible+Map
|
|
7 |
Tags: google, map, maps, google maps, kml
|
8 |
Requires at least: 4.0
|
9 |
Tested up to: 4.9
|
10 |
-
Stable tag: 1.
|
11 |
Requires PHP: 5.3
|
12 |
License: GPLv2 or later
|
13 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
14 |
|
15 |
Embed Google Maps shortcodes in pages and posts, either by centre coordinates or street address, or by URL to a Google Earth KML file.
|
16 |
|
17 |
-
|
18 |
|
19 |
Flexible Map allows you to add Google Maps to your WordPress website with simple shortcodes.
|
20 |
|
21 |
-
|
22 |
|
23 |
* three ways to load a map:
|
24 |
* by centre coordinates
|
@@ -37,39 +37,45 @@ Flexible Map allows you to add Google Maps to your WordPress website with simple
|
|
37 |
[Get started with Flexible Map](https://flexible-map.webaware.net.au/manual/getting-started/).
|
38 |
[Read the manual online](https://flexible-map.webaware.net.au/manual/).
|
39 |
|
40 |
-
|
41 |
|
42 |
* directions on KML maps generously sponsored by [Roger Los](http://www.rogerlos.com/)
|
43 |
|
44 |
Thanks for sponsoring new features on WP Flexible Maps!
|
45 |
|
46 |
-
|
47 |
|
48 |
Many thanks to the generous efforts of our translators:
|
49 |
|
50 |
* Czech (cs) -- [caslavak](https://profiles.wordpress.org/caslavak/) and the [Czech translation team](https://translate.wordpress.org/locale/cs/default/wp-plugins/wp-flexible-map)
|
51 |
-
* Dutch (nl) -- [Ivan Beemster](
|
52 |
* English (en_CA) -- [the English (Canadian) translation team](https://translate.wordpress.org/locale/en-ca/default/wp-plugins/wp-flexible-map)
|
53 |
* French (fr) -- [mister klucha](https://profiles.wordpress.org/mister-klucha/) and the [French translation team](https://translate.wordpress.org/locale/fr/default/wp-plugins/wp-flexible-map)
|
54 |
-
* German (de) -- [Carib Design](
|
55 |
* Greek (el) -- [Pantelis Orfanos](https://profiles.wordpress.org/ironwiller/)
|
56 |
* Hungarian (hu) -- Krisztián Vörös
|
57 |
* Italian (it_IT) -- the [Italian translation team](https://translate.wordpress.org/locale/it/default/wp-plugins/wp-flexible-map)
|
58 |
* Korean (ko_KR) -- the [Korean translation team](https://translate.wordpress.org/locale/ko/default/wp-plugins/wp-flexible-map)
|
59 |
* Swedish (sv_SE) -- the [Swedish translation team](https://translate.wordpress.org/locale/sv/default/wp-plugins/wp-flexible-map)
|
60 |
-
* Norwegian: Bokmål (nb_NO) -- [neonnero](
|
61 |
-
* Norwegian: Nynorsk (nn_NO) -- [neonnero](
|
62 |
* Portuguese (pt_BR) -- Alexsandro Santos and Paulo Henrique
|
63 |
* Spanish (es) -- [edurramos](https://profiles.wordpress.org/edurramos/)
|
64 |
* Welsh (cy) -- [Dylan](https://profiles.wordpress.org/dtom-ct-wp/)
|
65 |
|
66 |
The initial translations for all other languages were made using Google Translate, so it's likely that some will be truly awful! If you'd like to help out by translating this plugin, please [sign up for an account and dig in](https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map).
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
1. Upload this plugin to your /wp-content/plugins/ directory.
|
71 |
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
72 |
-
3. Get an [API Key from Google](https://
|
73 |
4. Add the shortcode `[flexiblemap]` to your pages / posts to embed maps
|
74 |
|
75 |
There are two ways to load maps with this plugin:
|
@@ -79,7 +85,7 @@ There are two ways to load maps with this plugin:
|
|
79 |
|
80 |
To add a Flexible Map to a post or a page, add a shortcode `[flexiblemap]` and give it some useful attributes. A map can either be specified using centre coordinates or street address, or by loading a KML file.
|
81 |
|
82 |
-
|
83 |
|
84 |
Either the center or the address paramater is required. If you provide both, the centre coordinates will be used for the map centre, but directions will use the street address. (This will prevent directions from telling people how to get to the destination opposite yours!)
|
85 |
|
@@ -101,7 +107,7 @@ Either the center or the address paramater is required. If you provide both, the
|
|
101 |
[flexiblemap center="-32.891058,151.538042" title="Mount Sugarloaf" directions="true"]
|
102 |
[flexiblemap center="-32.918827,151.806164" title="Nobby's Head" directions="my-dir-div"]`
|
103 |
|
104 |
-
|
105 |
|
106 |
* **src**: the URL for a KML file to load map details from, e.g. *src="http://example.com/map.kml"*
|
107 |
* **targetfix**: prevent links from opening in new window, from [true, false], e.g. *targetfix="true"*; default=true
|
@@ -110,7 +116,7 @@ Either the center or the address paramater is required. If you provide both, the
|
|
110 |
*Sample*:
|
111 |
`[flexiblemap src="https://webaware.com.au/maps/example-toronto.kml" width="100%" height="400px"]`
|
112 |
|
113 |
-
|
114 |
|
115 |
* **width**: width in pixels or valid CSS units, e.g. *width="100%"*
|
116 |
* **height**: height in pixels or valid CSS units, e.g. *height="400px"*
|
@@ -139,7 +145,7 @@ Either the center or the address paramater is required. If you provide both, the
|
|
139 |
* **region**: specify region to help localise address searches for street address map and directions, taken from the list of [country codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) e.g. *region="AU"*
|
140 |
* **locale**: use a specific locale (language) for messages like the text of the Directions link, e.g. *locale="nl-BE"*
|
141 |
|
142 |
-
|
143 |
|
144 |
There is a PHP function `flexmap_show_map()` for theme and plugin developers. All of the same attributes for the shortcode can be passed to the function in an associative array. If you want it to return the map as a string without output to screen, add "echo"=>"false" to array of attributes.
|
145 |
|
@@ -169,15 +175,17 @@ There are also some filter hooks that allow you to change the behaviour of the p
|
|
169 |
|
170 |
For more information and examples, see [the reference website](https://flexible-map.webaware.net.au/).
|
171 |
|
172 |
-
|
173 |
|
174 |
-
|
175 |
|
176 |
-
|
177 |
|
178 |
-
|
179 |
|
180 |
-
|
|
|
|
|
181 |
|
182 |
Settings > Flexible Map
|
183 |
|
@@ -185,11 +193,11 @@ For everything else, just add some attributes to your shortcode telling the map
|
|
185 |
|
186 |
Of course, in WordPress there is a plugin for everything :) so if you *want* more settings, please install the [Flexible Map Options plugin](https://wordpress.org/plugins/wp-flexible-map-options/). That plugin lets you set some defaults so that if you use the same attributes over and over, you can put them all in one place.
|
187 |
|
188 |
-
|
189 |
|
190 |
Using a KML file, you can have as many markers on a map as you like, with as much detail in the info windows. With KML you can also change marker icons and add other nice features. You can generate your KML file from an application like Google Earth, or you can create it yourself (in a text editor or with your own programming). [Learn more about KML](https://developers.google.com/kml/).
|
191 |
|
192 |
-
|
193 |
|
194 |
Google Maps API caches the KML file, so it can take a while for your new changes to appear. To force a change, append a URL query parameter with a number (known as a cache buster) and increment the number each time you change the KML file. A nice simple and commonly used parameter name is v (for version), like this: http://example.com/my-map.kml?v=2
|
195 |
|
@@ -198,21 +206,21 @@ If your map is auto-generated or changes frequently, add the `kmlcache` attribut
|
|
198 |
`[flexiblemap src="https://webaware.com.au/maps/example-toronto.kml?v=2"]
|
199 |
[flexiblemap src="https://webaware.com.au/maps/example-toronto.kml" kmlcache="8 hours"]`
|
200 |
|
201 |
-
|
202 |
|
203 |
-
The Google Maps API supports many commonly used KML elements, but has some restrictions. Read about [Google Maps support for KML](https://developers.google.com/
|
204 |
|
205 |
-
|
206 |
|
207 |
When you use a street address instead of centre coordinates, you are effectively searching Google Maps for your location. Try being very specific about your address, including your town / city, state / province, and country to make sure Google can find where you mean. You can also specify your region with the `region` attribute to help Google Maps refine its search. If the marker is still in the wrong place, you might need to specify the location using centre coordinates instead.
|
208 |
|
209 |
-
|
210 |
|
211 |
When you use just centre coordinates for your map, the directions may send people to the location *opposite* your location! Yes, I know... anyway, if you specify both the centre coordinates and the street address, the map will be centred correctly and the directions will be to your address.
|
212 |
|
213 |
-
|
214 |
|
215 |
-
The plugin uses localised messages for things like the Directions link and the default message on links in info windows. If you have your [WordPress installation set to use your language](https://codex.wordpress.org/
|
216 |
|
217 |
Google Maps will use the locale information from your web browser to help display maps and directions in your language (see your browser's language settings). If you want to force the Google Maps language for every map on a page, you can use a filter hook. For example, here's how to force the Google Maps language to match the language of the page / post its on (e.g. when using WPML translated content):
|
218 |
|
@@ -223,13 +231,13 @@ function force_flexmap_map_language($args) {
|
|
223 |
return $args;
|
224 |
}`
|
225 |
|
226 |
-
|
227 |
|
228 |
The initial translations were made using Google Translate, so it's likely that some will be truly awful! If you'd like to help out by translating this plugin, please [sign up for an account and dig in](https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map).
|
229 |
|
230 |
-
|
231 |
|
232 |
-
When you hide the map in a tab, and then click on the tab to reveal its contents, sometimes the map doesn't know how big to draw until it is revealed. Since v1.9.0 most such problems are automatically resolved for modern browsers, including Internet Explorer 11 or later. If you need to support earlier versions that don't support [MutationObserver](
|
233 |
|
234 |
For jQuery UI tabs and accordions, download the .php file from [this gist](https://gist.github.com/webaware/05b27e3a99ccb00200f5), and install / activate it. If you'd prefer to add the jQuery code yourself, add this somewhere on the page (e.g. in your theme's footer):
|
235 |
|
@@ -250,20 +258,7 @@ For jQuery UI tabs and accordions, download the .php file from [this gist](https
|
|
250 |
})(jQuery);
|
251 |
</script>`
|
252 |
|
253 |
-
|
254 |
-
|
255 |
-
`<script>
|
256 |
-
jQuery("body").bind("tabsshow", function(event, ui) {
|
257 |
-
jQuery("#" + ui.panel.id + " div.flxmap-container").each(function() {
|
258 |
-
var flxmap = window[this.getAttribute("data-flxmap")];
|
259 |
-
flxmap.redrawOnce();
|
260 |
-
});
|
261 |
-
});
|
262 |
-
</script>`
|
263 |
-
|
264 |
-
For tabs in jQuery Tools, see [this support topic](https://wordpress.org/support/topic/tabs-map#post-3784706).
|
265 |
-
|
266 |
-
= How can I get access to the map object? =
|
267 |
|
268 |
If you want to add your own scripting for the map, you can get the map object by identifying the FlexibleMap global variable for your map, and asking it to getMap(). By default, each FlexibleMap is given a randomly generated ID and the global variable name is derived from that. The map's containing div has a data property with this global variable name. Here's some sample jQuery code that gets the map object for the (first) map:
|
269 |
|
@@ -285,7 +280,7 @@ And here's some sample jQuery code:
|
|
285 |
// ... use map ...
|
286 |
});`
|
287 |
|
288 |
-
|
289 |
|
290 |
The plugin only loads the required JavaScript scripts when it knows that they are needed. When your website uses AJAX to load a page, the normal WordPress footer action for that page doesn't happen, and the scripts aren't loaded. You can make the scripts load on every page by adding this snippet to the functions.php file in your theme:
|
291 |
|
@@ -302,13 +297,13 @@ To make it load locale scripts as well, e.g. for French and Chinese language tex
|
|
302 |
|
303 |
The plugin will detect when AJAX is being used via the [WordPress standard method](https://codex.wordpress.org/AJAX_in_Plugins), and adjust accordingly (but you still need to load the scripts as above). If another method is used, add `isajax='true'` to the shortcode attributes.
|
304 |
|
305 |
-
NB: currently, only AJAX methods that parse script tags will work correctly; this includes some [jQuery methods](
|
306 |
|
307 |
-
|
308 |
|
309 |
Either turn off CloudFlare Rocketscript :) or install the [Flxmap No Rocketscript](https://gist.github.com/webaware/8949605) plugin by loading that file into your website's wp-content/plugins folder and activating through the plugins admin page. Use the plugin if you still want Rocketscript to manage all of your other scripts but leave the Flexible Map scripts alone.
|
310 |
|
311 |
-
|
312 |
|
313 |
1. `[flexiblemap center="-32.918657,151.797894" title="Nobby's Head" zoom="14" width="100%" height="400px" directions="true" maptype="satellite"]`
|
314 |
2. `[flexiblemap address="116 Beaumont Street Hamilton NSW Australia" title="Raj's Corner" description="SWMBO's favourite Indian diner" width="100%" height="400px" directions="true"]`
|
@@ -316,16 +311,17 @@ Either turn off CloudFlare Rocketscript :) or install the [Flxmap No Rocketscrip
|
|
316 |
4. `[flexiblemap center="-34.916721,138.828878" width="100%" height="400px" title="Adelaide Hills" directions="true" showdirections="true" directionsfrom="Adelaide" region="au"]`
|
317 |
5. Setting screen with API key field
|
318 |
|
319 |
-
|
320 |
|
321 |
-
|
322 |
|
323 |
-
bump version of Google Maps API to 3.
|
324 |
|
325 |
-
|
326 |
|
327 |
The full changelog can be found [on GitHub](https://github.com/webaware/flexible-map/blob/master/changelog.md). Recent entries:
|
328 |
|
329 |
-
### 1.
|
330 |
|
331 |
-
*
|
|
1 |
+
# Flexible Map
|
2 |
Contributors: webaware
|
3 |
Plugin Name: Flexible Map
|
4 |
Plugin URI: https://flexible-map.webaware.net.au/
|
7 |
Tags: google, map, maps, google maps, kml
|
8 |
Requires at least: 4.0
|
9 |
Tested up to: 4.9
|
10 |
+
Stable tag: 1.14.0
|
11 |
Requires PHP: 5.3
|
12 |
License: GPLv2 or later
|
13 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
14 |
|
15 |
Embed Google Maps shortcodes in pages and posts, either by centre coordinates or street address, or by URL to a Google Earth KML file.
|
16 |
|
17 |
+
## Description
|
18 |
|
19 |
Flexible Map allows you to add Google Maps to your WordPress website with simple shortcodes.
|
20 |
|
21 |
+
### Features
|
22 |
|
23 |
* three ways to load a map:
|
24 |
* by centre coordinates
|
37 |
[Get started with Flexible Map](https://flexible-map.webaware.net.au/manual/getting-started/).
|
38 |
[Read the manual online](https://flexible-map.webaware.net.au/manual/).
|
39 |
|
40 |
+
### Sponsorships
|
41 |
|
42 |
* directions on KML maps generously sponsored by [Roger Los](http://www.rogerlos.com/)
|
43 |
|
44 |
Thanks for sponsoring new features on WP Flexible Maps!
|
45 |
|
46 |
+
### Translations
|
47 |
|
48 |
Many thanks to the generous efforts of our translators:
|
49 |
|
50 |
* Czech (cs) -- [caslavak](https://profiles.wordpress.org/caslavak/) and the [Czech translation team](https://translate.wordpress.org/locale/cs/default/wp-plugins/wp-flexible-map)
|
51 |
+
* Dutch (nl) -- [Ivan Beemster](https://lijndiensten.com/) and the [Dutch translation team](https://translate.wordpress.org/locale/nl/default/wp-plugins/wp-flexible-map)
|
52 |
* English (en_CA) -- [the English (Canadian) translation team](https://translate.wordpress.org/locale/en-ca/default/wp-plugins/wp-flexible-map)
|
53 |
* French (fr) -- [mister klucha](https://profiles.wordpress.org/mister-klucha/) and the [French translation team](https://translate.wordpress.org/locale/fr/default/wp-plugins/wp-flexible-map)
|
54 |
+
* German (de) -- [Carib Design](https://www.caribdesign.com/) and the [German translation team](https://translate.wordpress.org/locale/de/default/wp-plugins/wp-flexible-map)
|
55 |
* Greek (el) -- [Pantelis Orfanos](https://profiles.wordpress.org/ironwiller/)
|
56 |
* Hungarian (hu) -- Krisztián Vörös
|
57 |
* Italian (it_IT) -- the [Italian translation team](https://translate.wordpress.org/locale/it/default/wp-plugins/wp-flexible-map)
|
58 |
* Korean (ko_KR) -- the [Korean translation team](https://translate.wordpress.org/locale/ko/default/wp-plugins/wp-flexible-map)
|
59 |
* Swedish (sv_SE) -- the [Swedish translation team](https://translate.wordpress.org/locale/sv/default/wp-plugins/wp-flexible-map)
|
60 |
+
* Norwegian: Bokmål (nb_NO) -- [neonnero](https://www.neonnero.com/)
|
61 |
+
* Norwegian: Nynorsk (nn_NO) -- [neonnero](https://www.neonnero.com/)
|
62 |
* Portuguese (pt_BR) -- Alexsandro Santos and Paulo Henrique
|
63 |
* Spanish (es) -- [edurramos](https://profiles.wordpress.org/edurramos/)
|
64 |
* Welsh (cy) -- [Dylan](https://profiles.wordpress.org/dtom-ct-wp/)
|
65 |
|
66 |
The initial translations for all other languages were made using Google Translate, so it's likely that some will be truly awful! If you'd like to help out by translating this plugin, please [sign up for an account and dig in](https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map).
|
67 |
|
68 |
+
### Privacy
|
69 |
+
|
70 |
+
Flexible Map embeds Google Maps into your web pages. Please review Google's [Privacy and Personal Information](https://developers.google.com/maps/terms#3-privacy-and-personal-information) for information about how that affects your website's privacy policy. By using this plugin, you are agreeing to the terms of use for Google Maps.
|
71 |
+
|
72 |
+
The Flexible Map plugin itself does not collect any personally identifying information, and does not set any cookies itself.
|
73 |
+
|
74 |
+
## Installation
|
75 |
|
76 |
1. Upload this plugin to your /wp-content/plugins/ directory.
|
77 |
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
78 |
+
3. Get an [API Key from Google](https://cloud.google.com/maps-platform/#get-started) and add it to Settings > Flexible Map
|
79 |
4. Add the shortcode `[flexiblemap]` to your pages / posts to embed maps
|
80 |
|
81 |
There are two ways to load maps with this plugin:
|
85 |
|
86 |
To add a Flexible Map to a post or a page, add a shortcode `[flexiblemap]` and give it some useful attributes. A map can either be specified using centre coordinates or street address, or by loading a KML file.
|
87 |
|
88 |
+
### Attributes for centre coordinates or street address map
|
89 |
|
90 |
Either the center or the address paramater is required. If you provide both, the centre coordinates will be used for the map centre, but directions will use the street address. (This will prevent directions from telling people how to get to the destination opposite yours!)
|
91 |
|
107 |
[flexiblemap center="-32.891058,151.538042" title="Mount Sugarloaf" directions="true"]
|
108 |
[flexiblemap center="-32.918827,151.806164" title="Nobby's Head" directions="my-dir-div"]`
|
109 |
|
110 |
+
### Attributes for KML map
|
111 |
|
112 |
* **src**: the URL for a KML file to load map details from, e.g. *src="http://example.com/map.kml"*
|
113 |
* **targetfix**: prevent links from opening in new window, from [true, false], e.g. *targetfix="true"*; default=true
|
116 |
*Sample*:
|
117 |
`[flexiblemap src="https://webaware.com.au/maps/example-toronto.kml" width="100%" height="400px"]`
|
118 |
|
119 |
+
### Attributes for all maps
|
120 |
|
121 |
* **width**: width in pixels or valid CSS units, e.g. *width="100%"*
|
122 |
* **height**: height in pixels or valid CSS units, e.g. *height="400px"*
|
145 |
* **region**: specify region to help localise address searches for street address map and directions, taken from the list of [country codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) e.g. *region="AU"*
|
146 |
* **locale**: use a specific locale (language) for messages like the text of the Directions link, e.g. *locale="nl-BE"*
|
147 |
|
148 |
+
### Calling from templates or plugins
|
149 |
|
150 |
There is a PHP function `flexmap_show_map()` for theme and plugin developers. All of the same attributes for the shortcode can be passed to the function in an associative array. If you want it to return the map as a string without output to screen, add "echo"=>"false" to array of attributes.
|
151 |
|
175 |
|
176 |
For more information and examples, see [the reference website](https://flexible-map.webaware.net.au/).
|
177 |
|
178 |
+
## Frequently Asked Questions
|
179 |
|
180 |
+
### Do I need an API key?
|
181 |
|
182 |
+
Yes. You will need at minimum an API key for Maps, so that the Maps JavaScript API will work. If you want to add maps by address (not just coordinates or KML file), you will also need to select Places. If you want to use directions features of this plugin, you will also need to select Routes.
|
183 |
|
184 |
+
[Get your API keys from the Google Maps Platform](https://cloud.google.com/maps-platform/#get-started)
|
185 |
|
186 |
+
### Where are the settings?
|
187 |
+
|
188 |
+
You can set your [API keys](https://cloud.google.com/maps-platform/#get-started) in the WordPress admin:
|
189 |
|
190 |
Settings > Flexible Map
|
191 |
|
193 |
|
194 |
Of course, in WordPress there is a plugin for everything :) so if you *want* more settings, please install the [Flexible Map Options plugin](https://wordpress.org/plugins/wp-flexible-map-options/). That plugin lets you set some defaults so that if you use the same attributes over and over, you can put them all in one place.
|
195 |
|
196 |
+
### Can I add multiple markers to a map?
|
197 |
|
198 |
Using a KML file, you can have as many markers on a map as you like, with as much detail in the info windows. With KML you can also change marker icons and add other nice features. You can generate your KML file from an application like Google Earth, or you can create it yourself (in a text editor or with your own programming). [Learn more about KML](https://developers.google.com/kml/).
|
199 |
|
200 |
+
### Why won't my KML map update when I edit the KML file?
|
201 |
|
202 |
Google Maps API caches the KML file, so it can take a while for your new changes to appear. To force a change, append a URL query parameter with a number (known as a cache buster) and increment the number each time you change the KML file. A nice simple and commonly used parameter name is v (for version), like this: http://example.com/my-map.kml?v=2
|
203 |
|
206 |
`[flexiblemap src="https://webaware.com.au/maps/example-toronto.kml?v=2"]
|
207 |
[flexiblemap src="https://webaware.com.au/maps/example-toronto.kml" kmlcache="8 hours"]`
|
208 |
|
209 |
+
### What parts of KML are supported?
|
210 |
|
211 |
+
The Google Maps API supports many commonly used KML elements, but has some restrictions. Read about [Google Maps support for KML](https://developers.google.com/maps/documentation/javascript/kmllayer) in the developers' guide, and also see the list of supported KML elements on that page.
|
212 |
|
213 |
+
### Why won't the map show my place when I use the address attribute?
|
214 |
|
215 |
When you use a street address instead of centre coordinates, you are effectively searching Google Maps for your location. Try being very specific about your address, including your town / city, state / province, and country to make sure Google can find where you mean. You can also specify your region with the `region` attribute to help Google Maps refine its search. If the marker is still in the wrong place, you might need to specify the location using centre coordinates instead.
|
216 |
|
217 |
+
### How can I use centre coordinates for the map and have directions to my address?
|
218 |
|
219 |
When you use just centre coordinates for your map, the directions may send people to the location *opposite* your location! Yes, I know... anyway, if you specify both the centre coordinates and the street address, the map will be centred correctly and the directions will be to your address.
|
220 |
|
221 |
+
### How do I get the maps to use my language?
|
222 |
|
223 |
+
The plugin uses localised messages for things like the Directions link and the default message on links in info windows. If you have your [WordPress installation set to use your language](https://codex.wordpress.org/Installing_WordPress_in_Your_Language), the plugin should automatically pick it up. If you need to force it to pick up your language (or want to offer a different language), use the `locale` attribute, e.g. `locale="ru"` or `locale="zh-TW"`.
|
224 |
|
225 |
Google Maps will use the locale information from your web browser to help display maps and directions in your language (see your browser's language settings). If you want to force the Google Maps language for every map on a page, you can use a filter hook. For example, here's how to force the Google Maps language to match the language of the page / post its on (e.g. when using WPML translated content):
|
226 |
|
231 |
return $args;
|
232 |
}`
|
233 |
|
234 |
+
### You've translated my language badly / it's missing
|
235 |
|
236 |
The initial translations were made using Google Translate, so it's likely that some will be truly awful! If you'd like to help out by translating this plugin, please [sign up for an account and dig in](https://translate.wordpress.org/projects/wp-plugins/wp-flexible-map).
|
237 |
|
238 |
+
### The map is broken in tabs / accordions
|
239 |
|
240 |
+
When you hide the map in a tab, and then click on the tab to reveal its contents, sometimes the map doesn't know how big to draw until it is revealed. Since v1.9.0 most such problems are automatically resolved for modern browsers, including Internet Explorer 11 or later. If you need to support earlier versions that don't support [MutationObserver](https://caniuse.com/#feat=mutationobserver), add some script to your website to handle this yourself.
|
241 |
|
242 |
For jQuery UI tabs and accordions, download the .php file from [this gist](https://gist.github.com/webaware/05b27e3a99ccb00200f5), and install / activate it. If you'd prefer to add the jQuery code yourself, add this somewhere on the page (e.g. in your theme's footer):
|
243 |
|
258 |
})(jQuery);
|
259 |
</script>`
|
260 |
|
261 |
+
### How can I get access to the map object?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
If you want to add your own scripting for the map, you can get the map object by identifying the FlexibleMap global variable for your map, and asking it to getMap(). By default, each FlexibleMap is given a randomly generated ID and the global variable name is derived from that. The map's containing div has a data property with this global variable name. Here's some sample jQuery code that gets the map object for the (first) map:
|
264 |
|
280 |
// ... use map ...
|
281 |
});`
|
282 |
|
283 |
+
### Why won't the map load on my AJAX single-page website?
|
284 |
|
285 |
The plugin only loads the required JavaScript scripts when it knows that they are needed. When your website uses AJAX to load a page, the normal WordPress footer action for that page doesn't happen, and the scripts aren't loaded. You can make the scripts load on every page by adding this snippet to the functions.php file in your theme:
|
286 |
|
297 |
|
298 |
The plugin will detect when AJAX is being used via the [WordPress standard method](https://codex.wordpress.org/AJAX_in_Plugins), and adjust accordingly (but you still need to load the scripts as above). If another method is used, add `isajax='true'` to the shortcode attributes.
|
299 |
|
300 |
+
NB: currently, only AJAX methods that parse script tags will work correctly; this includes some [jQuery methods](https://stackoverflow.com/q/2203762/911083) (but [not all](https://stackoverflow.com/a/2699905/911083)). A future version of the plugin will be more AJAX friendly.
|
301 |
|
302 |
+
### I have CloudFlare Rocketscript turned on and the map doesn't work
|
303 |
|
304 |
Either turn off CloudFlare Rocketscript :) or install the [Flxmap No Rocketscript](https://gist.github.com/webaware/8949605) plugin by loading that file into your website's wp-content/plugins folder and activating through the plugins admin page. Use the plugin if you still want Rocketscript to manage all of your other scripts but leave the Flexible Map scripts alone.
|
305 |
|
306 |
+
## Screenshots
|
307 |
|
308 |
1. `[flexiblemap center="-32.918657,151.797894" title="Nobby's Head" zoom="14" width="100%" height="400px" directions="true" maptype="satellite"]`
|
309 |
2. `[flexiblemap address="116 Beaumont Street Hamilton NSW Australia" title="Raj's Corner" description="SWMBO's favourite Indian diner" width="100%" height="400px" directions="true"]`
|
311 |
4. `[flexiblemap center="-34.916721,138.828878" width="100%" height="400px" title="Adelaide Hills" directions="true" showdirections="true" directionsfrom="Adelaide" region="au"]`
|
312 |
5. Setting screen with API key field
|
313 |
|
314 |
+
## Upgrade Notice
|
315 |
|
316 |
+
### 1.14.0
|
317 |
|
318 |
+
bump version of Google Maps API to 3.32; add server API key for server side address resolution
|
319 |
|
320 |
+
## Changelog
|
321 |
|
322 |
The full changelog can be found [on GitHub](https://github.com/webaware/flexible-map/blob/master/changelog.md). Recent entries:
|
323 |
|
324 |
+
### 1.14.0, 2018-06-07
|
325 |
|
326 |
+
* added: server API key to reduce `REQUEST_DENIED` errors from server side address resolution requests
|
327 |
+
* changed: bump version of Google Maps API to 3.32
|
views/settings-form.php
CHANGED
@@ -7,7 +7,7 @@ if (!defined('ABSPATH')) {
|
|
7 |
?>
|
8 |
|
9 |
<div class="wrap">
|
10 |
-
<
|
11 |
|
12 |
<form action="<?php echo admin_url('options.php'); ?>" method="POST">
|
13 |
<?php settings_fields(FLXMAP_PLUGIN_OPTIONS); ?>
|
@@ -15,11 +15,22 @@ if (!defined('ABSPATH')) {
|
|
15 |
<table class="form-table">
|
16 |
|
17 |
<tr valign="top">
|
18 |
-
<th scope="row"><?php echo esc_html_x('API key', 'settings', 'wp-flexible-map'); ?></th>
|
19 |
<td>
|
20 |
-
<input type="text" class="regular-text" name="flexible_map[apiKey]" value="<?php echo esc_attr($options['apiKey']); ?>" />
|
21 |
-
<
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
</td>
|
24 |
</tr>
|
25 |
|
7 |
?>
|
8 |
|
9 |
<div class="wrap">
|
10 |
+
<h1><?php esc_html_e('Flexible Map', 'wp-flexible-map'); ?></h1>
|
11 |
|
12 |
<form action="<?php echo admin_url('options.php'); ?>" method="POST">
|
13 |
<?php settings_fields(FLXMAP_PLUGIN_OPTIONS); ?>
|
15 |
<table class="form-table">
|
16 |
|
17 |
<tr valign="top">
|
18 |
+
<th scope="row"><?php echo esc_html_x('JavaScript API key', 'settings', 'wp-flexible-map'); ?></th>
|
19 |
<td>
|
20 |
+
<input type="text" class="regular-text" name="flexible_map[apiKey]" value="<?php echo esc_attr($options['apiKey']); ?>" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
21 |
+
<p><?php
|
22 |
+
/* translators: {{a}} and {{/a}} will be replaced by HTML tags for a website link */
|
23 |
+
echo $this->addExternalLink(esc_html_x('Get your API key from the {{a}}Google Maps API website{{/a}}.', 'settings', 'wp-flexible-map'), 'https://cloud.google.com/maps-platform/#get-started');
|
24 |
+
?></p>
|
25 |
+
</td>
|
26 |
+
</tr>
|
27 |
+
|
28 |
+
<tr valign="top">
|
29 |
+
<th scope="row"><?php echo esc_html_x('Server API key', 'settings', 'wp-flexible-map'); ?></th>
|
30 |
+
<td>
|
31 |
+
<input type="text" class="regular-text" name="flexible_map[apiServerKey]" value="<?php echo esc_attr($options['apiServerKey']); ?>" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
32 |
+
<p><?php echo esc_html_x('This key helps reduce the number of queries your server makes for maps with an address.', 'settings', 'wp-flexible-map'); ?></p>
|
33 |
+
<p><?php echo esc_html_x('It can be the same as the JavaScript key, but it must not be restricted by HTTP referrer. If you have restricted your JavaScript key by referrer, please create another key for the server.', 'settings', 'wp-flexible-map'); ?></p>
|
34 |
</td>
|
35 |
</tr>
|
36 |
|