Version Description
- Code cleanup per WordPress Coding Standards.
- Return rendered shortcode instead of echoing.
Download this release
Release Info
Developer | gwelser |
Plugin | Simple Google Map |
Version | 3.2 |
Comparing to | |
See all releases |
Code changes from version 3.1 to 3.2
- README.txt +6 -2
- admin/class-simple-google-map-admin.php +34 -32
- admin/partials/simple-google-map-admin-display.php +54 -49
- includes/class-simple-google-map-activator.php +9 -9
- includes/class-simple-google-map-deactivator.php +1 -3
- includes/class-simple-google-map-i18n.php +0 -1
- includes/class-simple-google-map-loader.php +44 -33
- includes/class-simple-google-map.php +1 -2
- public/class-simple-google-map-public.php +76 -16
- public/partials/simple-google-map-public-display.php +0 -49
- simple-google-map.php +1 -1
- widgets/simple-google-map-widget.php +156 -63
README.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: taylor_cnp, gwelser
|
|
3 |
Donate link: http://clarknikdelpowell.com/pay
|
4 |
Tags: google, google map, google maps, simple google map, no api key
|
5 |
Requires at least: 3.0.1
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 3.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -48,6 +48,10 @@ The shortcode name is SGM and here are the options..
|
|
48 |
|
49 |
== Changelog ==
|
50 |
|
|
|
|
|
|
|
|
|
51 |
= 3.1 =
|
52 |
* Add directions form to info bubble when directionsto is provided.
|
53 |
* Enqueue Google Maps script the proper way with conditional loading.
|
3 |
Donate link: http://clarknikdelpowell.com/pay
|
4 |
Tags: google, google map, google maps, simple google map, no api key
|
5 |
Requires at least: 3.0.1
|
6 |
+
Tested up to: 4.5.3
|
7 |
+
Stable tag: 3.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
48 |
|
49 |
== Changelog ==
|
50 |
|
51 |
+
= 3.2 =
|
52 |
+
* Code cleanup per [WordPress Coding Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards).
|
53 |
+
* Return rendered shortcode instead of echoing.
|
54 |
+
|
55 |
= 3.1 =
|
56 |
* Add directions form to info bubble when directionsto is provided.
|
57 |
* Enqueue Google Maps script the proper way with conditional loading.
|
admin/class-simple-google-map-admin.php
CHANGED
@@ -27,7 +27,7 @@ class Simple_Google_Map_Admin {
|
|
27 |
*
|
28 |
* @since 3.0.0
|
29 |
* @access private
|
30 |
-
* @var string
|
31 |
*/
|
32 |
private $plugin_name;
|
33 |
|
@@ -36,7 +36,7 @@ class Simple_Google_Map_Admin {
|
|
36 |
*
|
37 |
* @since 3.0.0
|
38 |
* @access private
|
39 |
-
* @var string
|
40 |
*/
|
41 |
private $version;
|
42 |
|
@@ -45,27 +45,28 @@ class Simple_Google_Map_Admin {
|
|
45 |
*
|
46 |
* @since 3.0.0
|
47 |
* @access private
|
48 |
-
* @var string
|
49 |
*/
|
50 |
-
|
51 |
|
52 |
/**
|
53 |
* Initialize the class and set its properties.
|
54 |
*
|
55 |
* @since 3.0.0
|
56 |
-
*
|
57 |
-
* @param string
|
|
|
58 |
*/
|
59 |
public function __construct( $plugin_name, $version ) {
|
60 |
|
61 |
-
$this->plugin_name
|
62 |
-
$this->version
|
63 |
-
$this->
|
64 |
-
'zoom'
|
65 |
-
'type'
|
66 |
-
'directionsto' => '',
|
67 |
-
'content'
|
68 |
-
|
69 |
|
70 |
}
|
71 |
|
@@ -76,7 +77,7 @@ class Simple_Google_Map_Admin {
|
|
76 |
*/
|
77 |
public function enqueue_styles() {
|
78 |
|
79 |
-
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/simple-google-map-admin.css',
|
80 |
|
81 |
}
|
82 |
|
@@ -87,51 +88,52 @@ class Simple_Google_Map_Admin {
|
|
87 |
*/
|
88 |
public function enqueue_scripts() {
|
89 |
|
90 |
-
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/simple-google-map-admin.js',
|
91 |
|
92 |
}
|
93 |
|
94 |
public function plugin_menu() {
|
95 |
|
96 |
-
add_options_page('Simple Google Map', 'Simple Google Map', 'activate_plugins', 'simple-google-map',
|
|
|
|
|
|
|
97 |
|
98 |
}
|
99 |
|
100 |
public function register_widgets() {
|
101 |
|
102 |
register_widget( 'Simple_Google_Map_Widget' );
|
103 |
-
|
104 |
}
|
105 |
|
106 |
public function plugin_options() {
|
107 |
|
108 |
-
if ( isset($_POST['submit']) ) {
|
109 |
|
110 |
-
$new_options['zoom']
|
111 |
-
$new_options['type']
|
112 |
$new_options['content'] = $_POST['content'];
|
113 |
-
if ( isset($_POST['editCSS']) ) {
|
114 |
$new_options['editCSS'] = $_POST['editCSS'];
|
115 |
}
|
116 |
-
if ( isset($_POST['nostyle']) ) {
|
117 |
$new_options['nostyle'] = $_POST['nostyle'];
|
118 |
}
|
119 |
|
120 |
-
$
|
121 |
-
|
122 |
-
update_option('SGMoptions', $
|
123 |
|
124 |
-
$
|
125 |
-
update_option('SGMcss', $
|
126 |
|
127 |
$message = '<div id="message" class="updated"><p>Simple Google Map settings updated.</p></div>';
|
128 |
} else {
|
129 |
-
$
|
130 |
-
$
|
131 |
}
|
132 |
|
133 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/simple-google-map-admin-display.php';
|
134 |
-
|
135 |
}
|
136 |
-
|
137 |
}
|
27 |
*
|
28 |
* @since 3.0.0
|
29 |
* @access private
|
30 |
+
* @var string $plugin_name The ID of this plugin.
|
31 |
*/
|
32 |
private $plugin_name;
|
33 |
|
36 |
*
|
37 |
* @since 3.0.0
|
38 |
* @access private
|
39 |
+
* @var string $version The current version of this plugin.
|
40 |
*/
|
41 |
private $version;
|
42 |
|
45 |
*
|
46 |
* @since 3.0.0
|
47 |
* @access private
|
48 |
+
* @var string $default_options The current default options of this plugin.
|
49 |
*/
|
50 |
+
private $default_options;
|
51 |
|
52 |
/**
|
53 |
* Initialize the class and set its properties.
|
54 |
*
|
55 |
* @since 3.0.0
|
56 |
+
*
|
57 |
+
* @param string $plugin_name The name of this plugin.
|
58 |
+
* @param string $version The version of this plugin.
|
59 |
*/
|
60 |
public function __construct( $plugin_name, $version ) {
|
61 |
|
62 |
+
$this->plugin_name = $plugin_name;
|
63 |
+
$this->version = $version;
|
64 |
+
$this->default_options = [
|
65 |
+
'zoom' => '12',
|
66 |
+
'type' => 'ROADMAP',
|
67 |
+
'directionsto' => '',
|
68 |
+
'content' => '',
|
69 |
+
];
|
70 |
|
71 |
}
|
72 |
|
77 |
*/
|
78 |
public function enqueue_styles() {
|
79 |
|
80 |
+
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/simple-google-map-admin.css', [], $this->version, 'all' );
|
81 |
|
82 |
}
|
83 |
|
88 |
*/
|
89 |
public function enqueue_scripts() {
|
90 |
|
91 |
+
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/simple-google-map-admin.js', [ 'jquery' ], $this->version, false );
|
92 |
|
93 |
}
|
94 |
|
95 |
public function plugin_menu() {
|
96 |
|
97 |
+
add_options_page( 'Simple Google Map', 'Simple Google Map', 'activate_plugins', 'simple-google-map', [
|
98 |
+
$this,
|
99 |
+
'plugin_options',
|
100 |
+
] );
|
101 |
|
102 |
}
|
103 |
|
104 |
public function register_widgets() {
|
105 |
|
106 |
register_widget( 'Simple_Google_Map_Widget' );
|
107 |
+
|
108 |
}
|
109 |
|
110 |
public function plugin_options() {
|
111 |
|
112 |
+
if ( isset( $_POST['submit'] ) ) {
|
113 |
|
114 |
+
$new_options['zoom'] = is_numeric( $_POST['zoom'] ) ? sanitize_text_field( $_POST['zoom'] ) : '';
|
115 |
+
$new_options['type'] = strtoupper( sanitize_text_field( $_POST['type'] ) );
|
116 |
$new_options['content'] = $_POST['content'];
|
117 |
+
if ( isset( $_POST['editCSS'] ) ) {
|
118 |
$new_options['editCSS'] = $_POST['editCSS'];
|
119 |
}
|
120 |
+
if ( isset( $_POST['nostyle'] ) ) {
|
121 |
$new_options['nostyle'] = $_POST['nostyle'];
|
122 |
}
|
123 |
|
124 |
+
$sgm_options = wp_parse_args( array_filter( $new_options ), $this->default_options );
|
125 |
+
|
126 |
+
update_option( 'SGMoptions', $sgm_options );
|
127 |
|
128 |
+
$sgm_css = $_POST['css'];
|
129 |
+
update_option( 'SGMcss', $sgm_css );
|
130 |
|
131 |
$message = '<div id="message" class="updated"><p>Simple Google Map settings updated.</p></div>';
|
132 |
} else {
|
133 |
+
$sgm_options = get_option( 'SGMoptions' );
|
134 |
+
$sgm_css = get_option( 'SGMcss' );
|
135 |
}
|
136 |
|
137 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/simple-google-map-admin-display.php';
|
|
|
138 |
}
|
|
|
139 |
}
|
admin/partials/simple-google-map-admin-display.php
CHANGED
@@ -12,64 +12,69 @@
|
|
12 |
* @subpackage Simple_Google_Map/admin/partials
|
13 |
*/
|
14 |
|
15 |
-
$
|
16 |
-
$
|
17 |
-
$
|
18 |
-
$
|
19 |
-
$
|
20 |
-
$
|
21 |
?>
|
22 |
|
23 |
<div class="wrap">
|
24 |
|
25 |
<h2>Simple Google Map</h2>
|
26 |
-
<?php echo $
|
27 |
|
28 |
-
<p>Here you can set the default options for every Simple Google Map on your pages/posts/sidebars. You can override
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
<form action="" method="post">
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
73 |
</form>
|
74 |
|
75 |
</div><!-- wrap -->
|
12 |
* @subpackage Simple_Google_Map/admin/partials
|
13 |
*/
|
14 |
|
15 |
+
$message_value = isset( $message ) ? $message : '';
|
16 |
+
$zoom_value = isset( $sgm_options['zoom'] ) ? $sgm_options['zoom'] : '';
|
17 |
+
$type_value = isset( $sgm_options['type'] ) ? $sgm_options['type'] : '';
|
18 |
+
$content_value = isset( $sgm_options['content'] ) ? $sgm_options['content'] : '';
|
19 |
+
$editcss_value = isset( $sgm_options['editCSS'] ) ? 'checked="checked"' : '';
|
20 |
+
$nostyle_value = isset( $sgm_options['nostyle'] ) ? 'checked="checked"' : '';
|
21 |
?>
|
22 |
|
23 |
<div class="wrap">
|
24 |
|
25 |
<h2>Simple Google Map</h2>
|
26 |
+
<?php echo $message_value; ?>
|
27 |
|
28 |
+
<p>Here you can set the default options for every Simple Google Map on your pages/posts/sidebars. You can override
|
29 |
+
these settings for any one Simple Google Map by simply adding the proper options to the shortcode/widget of that
|
30 |
+
map. Leave them undefined or blank and these settings will apply.</p>
|
31 |
+
<p>If you need help getting the latitude and longitude of your location try <a
|
32 |
+
href="http://stevemorse.org/jcal/latlon.php" target="_blank">this site</a>.</p>
|
33 |
|
34 |
<form action="" method="post">
|
35 |
|
36 |
+
<table class="form-table">
|
37 |
+
|
38 |
+
<tr valign="top">
|
39 |
+
<th><label for="zoom">Zoom Level</label></th>
|
40 |
+
<td>
|
41 |
+
<input name="zoom" type="text" value="<?php echo $zoom_value ?>"/><br/>
|
42 |
+
<span class="description">integer from 1 to 19</span>
|
43 |
+
</td>
|
44 |
+
</tr>
|
45 |
+
|
46 |
+
<tr valign="top">
|
47 |
+
<th><label for="type">Map Type</label></th>
|
48 |
+
<td>
|
49 |
+
<input type="text" name="type" value="<?php echo $type_value ?>"/><br/>
|
50 |
+
<span class="description">ROADMAP, SATELLITE, HYBRID, or TERRAIN</span>
|
51 |
+
</td>
|
52 |
+
</tr>
|
53 |
+
|
54 |
+
<tr valign="top">
|
55 |
+
<th><label for="content">Info Bubble Content</label></th>
|
56 |
+
<td><textarea name="content"><?php echo $content_value ?></textarea></td>
|
57 |
+
</tr>
|
58 |
+
|
59 |
+
<tr>
|
60 |
+
<th scope="row" colspan="2" class="th-full">
|
61 |
+
<label for="editCSS"><input type="checkbox" name="editCSS"
|
62 |
+
id="editCSS" <?php echo $editcss_value ?>/> I want to edit the Simple Google Map CSS</label>
|
63 |
+
<textarea name="css" id="SGMcss" rows="6"><?php echo $sgm_css ?></textarea>
|
64 |
+
</th>
|
65 |
+
</tr>
|
66 |
+
|
67 |
+
<tr>
|
68 |
+
<th scope="row" colspan="2" class="th-full">
|
69 |
+
<label for="nostyle"><input type="checkbox" name="nostyle" <?php echo $nostyle_value ?>
|
70 |
+
id="nostyle"/> Remove the Simple Google Map CSS, I will style it in the theme's stylesheet.</label>
|
71 |
+
</th>
|
72 |
+
</tr>
|
73 |
+
|
74 |
+
</table><!-- form-table -->
|
75 |
+
|
76 |
+
<p class="submit"><input type="submit" class="button-primary" name="submit" value="Save Changes"/></p>
|
77 |
+
|
78 |
</form>
|
79 |
|
80 |
</div><!-- wrap -->
|
includes/class-simple-google-map-activator.php
CHANGED
@@ -31,15 +31,15 @@ class Simple_Google_Map_Activator {
|
|
31 |
*/
|
32 |
public static function activate() {
|
33 |
|
34 |
-
$
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
update_option('SGMcss', $SGMcss);
|
42 |
|
|
|
|
|
43 |
}
|
44 |
-
|
45 |
}
|
31 |
*/
|
32 |
public static function activate() {
|
33 |
|
34 |
+
$sgm_defaults = [
|
35 |
+
'zoom' => '12',
|
36 |
+
'type' => 'ROADMAP',
|
37 |
+
'directionsto' => '',
|
38 |
+
'content' => '',
|
39 |
+
];
|
40 |
+
update_option( 'SGMoptions', $sgm_defaults );
|
|
|
41 |
|
42 |
+
$sgm_css = '#SGM {width:100%; height:300px;}#SGM .infoWindow {line-height:13px; font-size:10px;}#SGM input {margin:4px 4px 0 0; font-size:10px;}#SGM input.text {border:solid 1px #ccc; background-color:#fff; padding:2px;}';
|
43 |
+
update_option( 'SGMcss', $sgm_css );
|
44 |
}
|
|
|
45 |
}
|
includes/class-simple-google-map-deactivator.php
CHANGED
@@ -31,8 +31,6 @@ class Simple_Google_Map_Deactivator {
|
|
31 |
*/
|
32 |
public static function deactivate() {
|
33 |
|
34 |
-
delete_option('SGMoptions');
|
35 |
-
|
36 |
}
|
37 |
-
|
38 |
}
|
31 |
*/
|
32 |
public static function deactivate() {
|
33 |
|
34 |
+
delete_option( 'SGMoptions' );
|
|
|
35 |
}
|
|
|
36 |
}
|
includes/class-simple-google-map-i18n.php
CHANGED
@@ -59,5 +59,4 @@ class Simple_Google_Map_i18n {
|
|
59 |
public function set_domain( $domain ) {
|
60 |
$this->domain = $domain;
|
61 |
}
|
62 |
-
|
63 |
}
|
59 |
public function set_domain( $domain ) {
|
60 |
$this->domain = $domain;
|
61 |
}
|
|
|
62 |
}
|
includes/class-simple-google-map-loader.php
CHANGED
@@ -28,7 +28,7 @@ class Simple_Google_Map_Loader {
|
|
28 |
*
|
29 |
* @since 3.0.0
|
30 |
* @access protected
|
31 |
-
* @var array
|
32 |
*/
|
33 |
protected $actions;
|
34 |
|
@@ -37,7 +37,7 @@ class Simple_Google_Map_Loader {
|
|
37 |
*
|
38 |
* @since 3.0.0
|
39 |
* @access protected
|
40 |
-
* @var array
|
41 |
*/
|
42 |
protected $filters;
|
43 |
|
@@ -46,7 +46,7 @@ class Simple_Google_Map_Loader {
|
|
46 |
*
|
47 |
* @since 3.0.0
|
48 |
* @access protected
|
49 |
-
* @var array
|
50 |
*/
|
51 |
protected $shortcodes;
|
52 |
|
@@ -57,8 +57,8 @@ class Simple_Google_Map_Loader {
|
|
57 |
*/
|
58 |
public function __construct() {
|
59 |
|
60 |
-
$this->actions
|
61 |
-
$this->filters
|
62 |
$this->shortcodes = array();
|
63 |
|
64 |
}
|
@@ -67,13 +67,15 @@ class Simple_Google_Map_Loader {
|
|
67 |
* Add a new action to the collection to be registered with WordPress.
|
68 |
*
|
69 |
* @since 3.0.0
|
70 |
-
*
|
71 |
-
* @param
|
72 |
-
* @param
|
73 |
-
* @param
|
74 |
-
* @param int
|
|
|
75 |
*/
|
76 |
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
|
|
77 |
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
78 |
}
|
79 |
|
@@ -81,13 +83,15 @@ class Simple_Google_Map_Loader {
|
|
81 |
* Add a new filter to the collection to be registered with WordPress.
|
82 |
*
|
83 |
* @since 3.0.0
|
84 |
-
*
|
85 |
-
* @param
|
86 |
-
* @param
|
87 |
-
* @param
|
88 |
-
* @param int
|
|
|
89 |
*/
|
90 |
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
|
|
91 |
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
92 |
}
|
93 |
|
@@ -95,11 +99,13 @@ class Simple_Google_Map_Loader {
|
|
95 |
* Add a new shortcode to the collection to be registered with WordPress.
|
96 |
*
|
97 |
* @since 3.0.0
|
98 |
-
*
|
99 |
-
* @param
|
100 |
-
* @param
|
|
|
101 |
*/
|
102 |
public function add_shortcode( $tag, $component, $callback ) {
|
|
|
103 |
$this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback, '', '' );
|
104 |
}
|
105 |
|
@@ -109,26 +115,27 @@ class Simple_Google_Map_Loader {
|
|
109 |
*
|
110 |
* @since 3.0.0
|
111 |
* @access private
|
112 |
-
*
|
113 |
-
* @param
|
114 |
-
* @param
|
115 |
-
* @param
|
116 |
-
* @param
|
117 |
-
* @param int
|
|
|
|
|
118 |
* @return type The collection of actions and filters registered with WordPress.
|
119 |
*/
|
120 |
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
|
121 |
|
122 |
-
$hooks[] =
|
123 |
'hook' => $hook,
|
124 |
'component' => $component,
|
125 |
'callback' => $callback,
|
126 |
'priority' => $priority,
|
127 |
-
'accepted_args' => $accepted_args
|
128 |
-
|
129 |
|
130 |
return $hooks;
|
131 |
-
|
132 |
}
|
133 |
|
134 |
/**
|
@@ -139,17 +146,21 @@ class Simple_Google_Map_Loader {
|
|
139 |
public function run() {
|
140 |
|
141 |
foreach ( $this->filters as $hook ) {
|
142 |
-
add_filter( $hook['hook'],
|
|
|
|
|
|
|
143 |
}
|
144 |
|
145 |
foreach ( $this->actions as $hook ) {
|
146 |
-
add_action( $hook['hook'],
|
|
|
|
|
|
|
147 |
}
|
148 |
|
149 |
foreach ( $this->shortcodes as $hook ) {
|
150 |
-
add_shortcode( $hook['hook'],
|
151 |
}
|
152 |
-
|
153 |
}
|
154 |
-
|
155 |
}
|
28 |
*
|
29 |
* @since 3.0.0
|
30 |
* @access protected
|
31 |
+
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
|
32 |
*/
|
33 |
protected $actions;
|
34 |
|
37 |
*
|
38 |
* @since 3.0.0
|
39 |
* @access protected
|
40 |
+
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
|
41 |
*/
|
42 |
protected $filters;
|
43 |
|
46 |
*
|
47 |
* @since 3.0.0
|
48 |
* @access protected
|
49 |
+
* @var array $shortcodes The filters registered with WordPress to fire when the plugin loads.
|
50 |
*/
|
51 |
protected $shortcodes;
|
52 |
|
57 |
*/
|
58 |
public function __construct() {
|
59 |
|
60 |
+
$this->actions = array();
|
61 |
+
$this->filters = array();
|
62 |
$this->shortcodes = array();
|
63 |
|
64 |
}
|
67 |
* Add a new action to the collection to be registered with WordPress.
|
68 |
*
|
69 |
* @since 3.0.0
|
70 |
+
*
|
71 |
+
* @param string $hook The name of the WordPress action that is being registered.
|
72 |
+
* @param object $component A reference to the instance of the object on which the action is defined.
|
73 |
+
* @param string $callback The name of the function definition on the $component.
|
74 |
+
* @param int $priority The priority at which the function should be fired.
|
75 |
+
* @param int $accepted_args The number of arguments that should be passed to the $callback.
|
76 |
*/
|
77 |
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
78 |
+
|
79 |
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
80 |
}
|
81 |
|
83 |
* Add a new filter to the collection to be registered with WordPress.
|
84 |
*
|
85 |
* @since 3.0.0
|
86 |
+
*
|
87 |
+
* @param string $hook The name of the WordPress filter that is being registered.
|
88 |
+
* @param object $component A reference to the instance of the object on which the filter is defined.
|
89 |
+
* @param string $callback The name of the function definition on the $component.
|
90 |
+
* @param int $priority The priority at which the function should be fired.
|
91 |
+
* @param int $accepted_args The number of arguments that should be passed to the $callback.
|
92 |
*/
|
93 |
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
94 |
+
|
95 |
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
96 |
}
|
97 |
|
99 |
* Add a new shortcode to the collection to be registered with WordPress.
|
100 |
*
|
101 |
* @since 3.0.0
|
102 |
+
*
|
103 |
+
* @param string $tag The name of the WordPress filter that is being registered.
|
104 |
+
* @param object $component A reference to the instance of the object on which the filter is defined.
|
105 |
+
* @param string $callback The name of the function definition on the $component.
|
106 |
*/
|
107 |
public function add_shortcode( $tag, $component, $callback ) {
|
108 |
+
|
109 |
$this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback, '', '' );
|
110 |
}
|
111 |
|
115 |
*
|
116 |
* @since 3.0.0
|
117 |
* @access private
|
118 |
+
*
|
119 |
+
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
|
120 |
+
* @param string $hook The name of the WordPress filter that is being registered.
|
121 |
+
* @param object $component A reference to the instance of the object on which the filter is defined.
|
122 |
+
* @param string $callback The name of the function definition on the $component.
|
123 |
+
* @param int $priority The priority at which the function should be fired.
|
124 |
+
* @param int $accepted_args The number of arguments that should be passed to the $callback.
|
125 |
+
*
|
126 |
* @return type The collection of actions and filters registered with WordPress.
|
127 |
*/
|
128 |
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
|
129 |
|
130 |
+
$hooks[] = [
|
131 |
'hook' => $hook,
|
132 |
'component' => $component,
|
133 |
'callback' => $callback,
|
134 |
'priority' => $priority,
|
135 |
+
'accepted_args' => $accepted_args,
|
136 |
+
];
|
137 |
|
138 |
return $hooks;
|
|
|
139 |
}
|
140 |
|
141 |
/**
|
146 |
public function run() {
|
147 |
|
148 |
foreach ( $this->filters as $hook ) {
|
149 |
+
add_filter( $hook['hook'], [
|
150 |
+
$hook['component'],
|
151 |
+
$hook['callback'],
|
152 |
+
], $hook['priority'], $hook['accepted_args'] );
|
153 |
}
|
154 |
|
155 |
foreach ( $this->actions as $hook ) {
|
156 |
+
add_action( $hook['hook'], [
|
157 |
+
$hook['component'],
|
158 |
+
$hook['callback'],
|
159 |
+
], $hook['priority'], $hook['accepted_args'] );
|
160 |
}
|
161 |
|
162 |
foreach ( $this->shortcodes as $hook ) {
|
163 |
+
add_shortcode( $hook['hook'], [ $hook['component'], $hook['callback'] ] );
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
}
|
includes/class-simple-google-map.php
CHANGED
@@ -35,7 +35,7 @@ class Simple_Google_Map {
|
|
35 |
* @since 3.0.0
|
36 |
* @access protected
|
37 |
*/
|
38 |
-
protected static $instance =
|
39 |
|
40 |
/**
|
41 |
* The loader that's responsible for maintaining and registering all hooks that power
|
@@ -251,5 +251,4 @@ class Simple_Google_Map {
|
|
251 |
public function get_plugin_path() {
|
252 |
return $this->plugin_path;
|
253 |
}
|
254 |
-
|
255 |
}
|
35 |
* @since 3.0.0
|
36 |
* @access protected
|
37 |
*/
|
38 |
+
protected static $instance = null;
|
39 |
|
40 |
/**
|
41 |
* The loader that's responsible for maintaining and registering all hooks that power
|
251 |
public function get_plugin_path() {
|
252 |
return $this->plugin_path;
|
253 |
}
|
|
|
254 |
}
|
public/class-simple-google-map-public.php
CHANGED
@@ -55,7 +55,7 @@ class Simple_Google_Map_Public {
|
|
55 |
* @since 3.0.0
|
56 |
*
|
57 |
* @param string $plugin_name The name of the plugin.
|
58 |
-
* @param string $version
|
59 |
*/
|
60 |
public function __construct( $plugin_name, $version ) {
|
61 |
|
@@ -85,8 +85,8 @@ class Simple_Google_Map_Public {
|
|
85 |
*/
|
86 |
public function output_css() {
|
87 |
|
88 |
-
$
|
89 |
-
if ( isset( $
|
90 |
return;
|
91 |
}
|
92 |
|
@@ -103,23 +103,83 @@ class Simple_Google_Map_Public {
|
|
103 |
*/
|
104 |
public function map( $atts ) {
|
105 |
|
106 |
-
$
|
107 |
|
108 |
-
$lat
|
109 |
-
$lng
|
110 |
-
$zoom
|
111 |
-
$type
|
112 |
-
$content
|
113 |
-
$
|
114 |
|
115 |
-
$content
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
|
121 |
-
|
|
|
|
|
|
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
}
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
}
|
55 |
* @since 3.0.0
|
56 |
*
|
57 |
* @param string $plugin_name The name of the plugin.
|
58 |
+
* @param string $version The version of this plugin.
|
59 |
*/
|
60 |
public function __construct( $plugin_name, $version ) {
|
61 |
|
85 |
*/
|
86 |
public function output_css() {
|
87 |
|
88 |
+
$sgm_options = get_option( 'SGMoptions' );
|
89 |
+
if ( isset( $sgm_options['nostyle'] ) ) {
|
90 |
return;
|
91 |
}
|
92 |
|
103 |
*/
|
104 |
public function map( $atts ) {
|
105 |
|
106 |
+
$sgm_options = get_option( 'SGMoptions' ); // get options defined in admin page
|
107 |
|
108 |
+
$lat = isset( $atts['lat'] ) ? $atts['lat'] : '0';
|
109 |
+
$lng = isset( $atts['lng'] ) ? $atts['lng'] : '0';
|
110 |
+
$zoom = isset( $atts['zoom'] ) ? $atts['zoom'] : $sgm_options['zoom'];
|
111 |
+
$type = isset( $atts['type'] ) ? strtoupper( $atts['type'] ) : $sgm_options['type'];
|
112 |
+
$content = isset( $atts['content'] ) ? $atts['content'] : $sgm_options['content'];
|
113 |
+
$directions_to = isset( $atts['directionsto'] ) ? $atts['directionsto'] : '';
|
114 |
|
115 |
+
$content = $this->strip_last_chars( htmlspecialchars_decode( $content ), [
|
116 |
+
'<br>',
|
117 |
+
'<br/>',
|
118 |
+
'<br />',
|
119 |
+
] );
|
120 |
|
121 |
+
$directions_form = '';
|
122 |
+
if ( $directions_to ) {
|
123 |
+
$directions_form = '<form method="get" action="//maps.google.com/maps"><input type="hidden" name="daddr" value="' . $directions_to . '" /><input type="text" class="text" name="saddr" /><input type="submit" class="submit" value="Directions" /></form>';
|
124 |
+
}
|
125 |
|
126 |
+
$infowindow_arr = [ $content, $directions_to, $directions_form ];
|
127 |
+
$infowindow_content = implode( '<br>', array_filter( $infowindow_arr ) );
|
128 |
+
|
129 |
+
$map = '<script type="text/javascript">';
|
130 |
+
$map .= "function makeMap() {
|
131 |
+
var latlng = new google.maps.LatLng($lat, $lng);
|
132 |
+
var myOptions = {
|
133 |
+
zoom: $zoom,
|
134 |
+
center: latlng,
|
135 |
+
mapTypeControl: true,
|
136 |
+
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
|
137 |
+
navigationControl: true,
|
138 |
+
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
|
139 |
+
mapTypeId: google.maps.MapTypeId.$type
|
140 |
+
};
|
141 |
+
var map = new google.maps.Map(document.getElementById('SGM'), myOptions);
|
142 |
+
var contentstring = '<div class=\"infoWindow\">$infowindow_content</div>';
|
143 |
+
var infowindow = new google.maps.InfoWindow({
|
144 |
+
content: contentstring
|
145 |
+
});
|
146 |
+
var marker = new google.maps.Marker({
|
147 |
+
position: latlng,
|
148 |
+
map: map,
|
149 |
+
title: ''
|
150 |
+
});
|
151 |
+
google.maps.event.addListener(marker, 'click', function() {
|
152 |
+
infowindow.open(map,marker);
|
153 |
+
});
|
154 |
+
}
|
155 |
+
window.onload = makeMap;";
|
156 |
+
$map .= '</script>';
|
157 |
+
$map .= '<div id="SGM"></div>';
|
158 |
+
|
159 |
+
return $map;
|
160 |
}
|
161 |
|
162 |
+
public function strip_last_chars( $haystack, $needles ) {
|
163 |
+
|
164 |
+
if ( empty( $haystack ) ) {
|
165 |
+
return $haystack;
|
166 |
+
}
|
167 |
+
|
168 |
+
if ( ! is_array( $needles ) ) {
|
169 |
+
if ( substr( $haystack, strlen( $needles ) * - 1 ) === $needles ) {
|
170 |
+
$haystack = substr( $haystack, 0, strlen( $haystack ) - strlen( $needles ) );
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
if ( is_array( $needles ) ) {
|
175 |
+
foreach ( $needles as $needle ) {
|
176 |
+
if ( substr( $haystack, strlen( $needle ) * - 1 ) === $needle ) {
|
177 |
+
$haystack = substr( $haystack, 0, strlen( $haystack ) - strlen( $needle ) );
|
178 |
+
break;
|
179 |
+
}
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
return $haystack;
|
184 |
+
}
|
185 |
}
|
public/partials/simple-google-map-public-display.php
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Provide a public-facing view for the plugin
|
5 |
-
*
|
6 |
-
* This file is used to markup the public-facing aspects of the plugin.
|
7 |
-
*
|
8 |
-
* @link http://clarknikdelpowell.com
|
9 |
-
* @since 3.0.0
|
10 |
-
*
|
11 |
-
* @package Simple_Google_Map
|
12 |
-
* @subpackage Simple_Google_Map/public/partials
|
13 |
-
*/
|
14 |
-
?>
|
15 |
-
|
16 |
-
<script type='text/javascript'>
|
17 |
-
function makeMap() {
|
18 |
-
var latlng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $lng; ?>)
|
19 |
-
|
20 |
-
var myOptions = {
|
21 |
-
zoom: <?php echo $zoom; ?>,
|
22 |
-
center: latlng,
|
23 |
-
mapTypeControl: true,
|
24 |
-
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
|
25 |
-
navigationControl: true,
|
26 |
-
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
|
27 |
-
mapTypeId: google.maps.MapTypeId.<?php echo $type; ?>
|
28 |
-
};
|
29 |
-
var map = new google.maps.Map(document.getElementById('SGM'), myOptions);
|
30 |
-
|
31 |
-
var contentString = '<div class=\"infoWindow\"><?php echo $content.$directionsto.$directionsForm; ?></div>';
|
32 |
-
var infowindow = new google.maps.InfoWindow({
|
33 |
-
content: contentString
|
34 |
-
});
|
35 |
-
|
36 |
-
var marker = new google.maps.Marker({
|
37 |
-
position: latlng,
|
38 |
-
map: map,
|
39 |
-
title: ''
|
40 |
-
});
|
41 |
-
|
42 |
-
google.maps.event.addListener(marker, 'click', function() {
|
43 |
-
infowindow.open(map,marker);
|
44 |
-
});
|
45 |
-
}
|
46 |
-
window.onload = makeMap;
|
47 |
-
</script>
|
48 |
-
|
49 |
-
<div id='SGM'></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
simple-google-map.php
CHANGED
@@ -16,7 +16,7 @@
|
|
16 |
* Plugin Name: Simple Google Map
|
17 |
* Plugin URI: http://clarknikdelpowell.com/wordpress/simple-google-map
|
18 |
* Description: Embed a google map using shortcode or as a widget.
|
19 |
-
* Version: 3.
|
20 |
* Author: Taylor Gorman, Glenn Welser
|
21 |
* Author URI: http://clarknikdelpowell.com
|
22 |
* License: GPL-2.0+
|
16 |
* Plugin Name: Simple Google Map
|
17 |
* Plugin URI: http://clarknikdelpowell.com/wordpress/simple-google-map
|
18 |
* Description: Embed a google map using shortcode or as a widget.
|
19 |
+
* Version: 3.2
|
20 |
* Author: Taylor Gorman, Glenn Welser
|
21 |
* Author URI: http://clarknikdelpowell.com
|
22 |
* License: GPL-2.0+
|
widgets/simple-google-map-widget.php
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* Map widget
|
4 |
*
|
@@ -19,7 +20,9 @@ class Simple_Google_Map_Widget extends WP_Widget {
|
|
19 |
parent::__construct(
|
20 |
'simple-google-map-widget',
|
21 |
'Simple Google Map',
|
22 |
-
|
|
|
|
|
23 |
);
|
24 |
|
25 |
}
|
@@ -31,44 +34,54 @@ class Simple_Google_Map_Widget extends WP_Widget {
|
|
31 |
*/
|
32 |
public function form( $instance ) {
|
33 |
|
34 |
-
|
35 |
-
$
|
36 |
-
$
|
37 |
-
$
|
38 |
-
$
|
39 |
-
$
|
40 |
-
$
|
41 |
-
$content = isset($instance['content']) ? esc_attr($instance['content']) : '';
|
42 |
|
43 |
?>
|
44 |
-
|
45 |
-
<label for="<?php
|
46 |
-
<input class="widefat" id="<?php
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
<
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
<
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
<
|
61 |
-
|
62 |
-
<input class="widefat" id="<?php
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
<
|
67 |
-
|
68 |
-
<
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
<?php
|
73 |
|
74 |
}
|
@@ -80,15 +93,16 @@ class Simple_Google_Map_Widget extends WP_Widget {
|
|
80 |
*/
|
81 |
public function update( $new_instance, $old_instance ) {
|
82 |
|
83 |
-
$instance
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
92 |
|
93 |
}
|
94 |
|
@@ -101,26 +115,105 @@ class Simple_Google_Map_Widget extends WP_Widget {
|
|
101 |
|
102 |
extract( $instance );
|
103 |
|
104 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
if (
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
-
|
113 |
-
$directionsForm = '';
|
114 |
-
if ($directionsto) { $directionsForm = "<form method=\"get\" action=\"//maps.google.com/maps\"><input type=\"hidden\" name=\"daddr\" value=\"".$directionsto."\" /><input type=\"text\" class=\"text\" name=\"saddr\" /><input type=\"submit\" class=\"submit\" value=\"Directions\" /></form>"; }
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
123 |
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
-
|
|
|
|
1 |
<?php
|
2 |
+
|
3 |
/**
|
4 |
* Map widget
|
5 |
*
|
20 |
parent::__construct(
|
21 |
'simple-google-map-widget',
|
22 |
'Simple Google Map',
|
23 |
+
[
|
24 |
+
'description' => 'Add a google map to your blog or site',
|
25 |
+
]
|
26 |
);
|
27 |
|
28 |
}
|
34 |
*/
|
35 |
public function form( $instance ) {
|
36 |
|
37 |
+
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
|
38 |
+
$lat = isset( $instance['lat'] ) ? esc_attr( $instance['lat'] ) : '';
|
39 |
+
$lng = isset( $instance['lng'] ) ? esc_attr( $instance['lng'] ) : '';
|
40 |
+
$zoom = isset( $instance['zoom'] ) ? esc_attr( $instance['zoom'] ) : '';
|
41 |
+
$type = isset( $instance['type'] ) ? esc_attr( $instance['type'] ) : '';
|
42 |
+
$directionsto = isset( $instance['directionsto'] ) ? esc_attr( $instance['directionsto'] ) : '';
|
43 |
+
$content = isset( $instance['content'] ) ? esc_attr( $instance['content'] ) : '';
|
|
|
44 |
|
45 |
?>
|
46 |
+
<p>
|
47 |
+
<label for="<?php echo $this->get_field_id( 'title' ) ?>"><?php _e( 'Title:' ) ?></label>
|
48 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ) ?>"
|
49 |
+
name="<?php echo $this->get_field_name( 'title' ) ?>" type="text" value="<?php echo $title ?>"/>
|
50 |
+
</p>
|
51 |
+
<p>
|
52 |
+
<label for="<?php echo $this->get_field_id( 'lat' ) ?>"><?php _e( 'Latitude:' ) ?></label>
|
53 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'lat' ) ?>"
|
54 |
+
name="<?php echo $this->get_field_name( 'lat' ) ?>" type="text" value="<?php echo $lat ?>"/>
|
55 |
+
</p>
|
56 |
+
<p>
|
57 |
+
<label for="<?php echo $this->get_field_id( 'lng' ) ?>"><?php _e( 'Longitude:' ) ?></label>
|
58 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'lng' ) ?>"
|
59 |
+
name="<?php echo $this->get_field_name( 'lng' ) ?>" type="text" value="<?php echo $lng ?>"/>
|
60 |
+
</p>
|
61 |
+
<p>
|
62 |
+
<label
|
63 |
+
for="<?php echo $this->get_field_id( 'zoom' ) ?>"><?php _e( 'Zoom Level: <small>(1-19)</small>' ) ?></label>
|
64 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'zoom' ) ?>"
|
65 |
+
name="<?php echo $this->get_field_name( 'zoom' ) ?>" type="text" value="<?php echo $zoom ?>"/>
|
66 |
+
</p>
|
67 |
+
<p>
|
68 |
+
<label
|
69 |
+
for="<?php echo $this->get_field_id( 'type' ) ?>"><?php _e( 'Map Type:<br /><small>(ROADMAP, SATELLITE, HYBRID, TERRAIN)</small>' ) ?></label>
|
70 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'type' ) ?>"
|
71 |
+
name="<?php echo $this->get_field_name( 'type' ) ?>" type="text" value="<?php echo $type ?>"/>
|
72 |
+
</p>
|
73 |
+
<p>
|
74 |
+
<label
|
75 |
+
for="<?php echo $this->get_field_id( 'directionsto' ) ?>"><?php _e( 'Address for directions:' ) ?></label>
|
76 |
+
<input class="widefat" id="<?php echo $this->get_field_id( 'directionsto' ) ?>"
|
77 |
+
name="<?php echo $this->get_field_name( 'directionsto' ) ?>" type="text"
|
78 |
+
value="<?php echo $directionsto ?>"/>
|
79 |
+
</p>
|
80 |
+
<p>
|
81 |
+
<label for="<?php echo $this->get_field_id( 'content' ) ?>"><?php _e( 'Info Bubble Content:' ) ?></label>
|
82 |
+
<textarea rows="7" class="widefat" id="<?php echo $this->get_field_id( 'content' ) ?>"
|
83 |
+
name="<?php echo $this->get_field_name( 'content' ) ?>"><?php echo $content ?></textarea>
|
84 |
+
</p>
|
85 |
<?php
|
86 |
|
87 |
}
|
93 |
*/
|
94 |
public function update( $new_instance, $old_instance ) {
|
95 |
|
96 |
+
$instance = $old_instance;
|
97 |
+
$instance['title'] = esc_attr( $new_instance['title'] );
|
98 |
+
$instance['lat'] = esc_attr( $new_instance['lat'] );
|
99 |
+
$instance['lng'] = esc_attr( $new_instance['lng'] );
|
100 |
+
$instance['zoom'] = esc_attr( $new_instance['zoom'] );
|
101 |
+
$instance['type'] = esc_attr( $new_instance['type'] );
|
102 |
+
$instance['directionsto'] = esc_attr( $new_instance['directionsto'] );
|
103 |
+
$instance['content'] = esc_attr( $new_instance['content'] );
|
104 |
+
|
105 |
+
return $instance;
|
106 |
|
107 |
}
|
108 |
|
115 |
|
116 |
extract( $instance );
|
117 |
|
118 |
+
$sgm_options = get_option( 'SGMoptions' ); // get options defined in admin page
|
119 |
+
|
120 |
+
if ( ! $lat ) {
|
121 |
+
$lat = '0';
|
122 |
+
}
|
123 |
+
if ( ! $lng ) {
|
124 |
+
$lng = '0';
|
125 |
+
}
|
126 |
+
if ( ! $zoom ) {
|
127 |
+
$zoom = $sgm_options['zoom'];
|
128 |
+
} // 1-19
|
129 |
+
if ( ! $type ) {
|
130 |
+
$type = $sgm_options['type'];
|
131 |
+
} // ROADMAP, SATELLITE, HYBRID, TERRAIN
|
132 |
+
if ( ! $content ) {
|
133 |
+
$content = $sgm_options['content'];
|
134 |
+
}
|
135 |
+
if ( ! $directionsto ) {
|
136 |
+
$directions_to = '';
|
137 |
+
} else {
|
138 |
+
$directions_to = $directionsto;
|
139 |
+
}
|
140 |
+
|
141 |
+
$content = $this->strip_last_chars( htmlspecialchars_decode( $content ), [
|
142 |
+
'<br>',
|
143 |
+
'<br/>',
|
144 |
+
'<br />',
|
145 |
+
] );
|
146 |
+
|
147 |
+
$directions_form = '';
|
148 |
+
if ( $directions_to ) {
|
149 |
+
$directions_form = '<form method="get" action="//maps.google.com/maps"><input type="hidden" name="daddr" value="' . $directions_to . '" /><input type="text" class="text" name="saddr" /><input type="submit" class="submit" value="Directions" /></form>';
|
150 |
+
}
|
151 |
+
|
152 |
+
$infowindow_arr = [ $content, $directions_to, $directions_form ];
|
153 |
+
$infowindow_content = implode( '<br>', array_filter( $infowindow_arr ) );
|
154 |
|
155 |
+
extract( $args );
|
156 |
+
echo $before_widget;
|
157 |
+
if ( $instance['title'] ) {
|
158 |
+
echo $before_title . $instance['title'] . $after_title;
|
159 |
+
}
|
160 |
+
|
161 |
+
$map = '<script type="text/javascript">';
|
162 |
+
$map .= "function makeMap() {
|
163 |
+
var latlng = new google.maps.LatLng($lat, $lng);
|
164 |
+
var myOptions = {
|
165 |
+
zoom: $zoom,
|
166 |
+
center: latlng,
|
167 |
+
mapTypeControl: true,
|
168 |
+
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
|
169 |
+
navigationControl: true,
|
170 |
+
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
|
171 |
+
mapTypeId: google.maps.MapTypeId.$type
|
172 |
+
};
|
173 |
+
var map = new google.maps.Map(document.getElementById('SGM'), myOptions);
|
174 |
+
var contentstring = '<div class=\"infoWindow\">$infowindow_content</div>';
|
175 |
+
var infowindow = new google.maps.InfoWindow({
|
176 |
+
content: contentstring
|
177 |
+
});
|
178 |
+
var marker = new google.maps.Marker({
|
179 |
+
position: latlng,
|
180 |
+
map: map,
|
181 |
+
title: ''
|
182 |
+
});
|
183 |
+
google.maps.event.addListener(marker, 'click', function() {
|
184 |
+
infowindow.open(map,marker);
|
185 |
+
});
|
186 |
+
}
|
187 |
+
window.onload = makeMap;";
|
188 |
+
$map .= '</script>';
|
189 |
+
$map .= '<div id="SGM"></div>';
|
190 |
+
|
191 |
+
echo $map;
|
192 |
+
|
193 |
+
echo $after_widget;
|
194 |
+
}
|
195 |
|
196 |
+
public function strip_last_chars( $haystack, $needles ) {
|
|
|
|
|
197 |
|
198 |
+
if ( empty( $haystack ) ) {
|
199 |
+
return $haystack;
|
200 |
+
}
|
201 |
|
202 |
+
if ( ! is_array( $needles ) ) {
|
203 |
+
if ( substr( $haystack, strlen( $needles ) * - 1 ) === $needles ) {
|
204 |
+
$haystack = substr( $haystack, 0, strlen( $haystack ) - strlen( $needles ) );
|
205 |
+
}
|
206 |
+
}
|
207 |
|
208 |
+
if ( is_array( $needles ) ) {
|
209 |
+
foreach ( $needles as $needle ) {
|
210 |
+
if ( substr( $haystack, strlen( $needle ) * - 1 ) === $needle ) {
|
211 |
+
$haystack = substr( $haystack, 0, strlen( $haystack ) - strlen( $needle ) );
|
212 |
+
break;
|
213 |
+
}
|
214 |
+
}
|
215 |
+
}
|
216 |
|
217 |
+
return $haystack;
|
218 |
+
}
|
219 |
+
}
|