PluginProbe
Maps Widget for Google Maps / 4.23
Maps Widget for Google Maps v4.23
1.86 1.90 1.92 1.93 1.95 2.0 2.01 2.05 2.06 2.10 2.15 2.20 2.25 2.30 2.35 2.40 2.45 2.50 2.51 2.60 2.65 2.66 2.70 2.75 2.80 All 129 releases
google-maps-widget / google-maps-widget.php

google-maps-widget.php in Maps Widget for Google Maps 4.23, at google-maps-widget.php

1,603 lines 73.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Maps Widget for Google Maps
4 Plugin URI: https://www.gmapswidget.com/
5 Description: Display a single image super-fast loading Google Map in a widget. A larger, full featured map is available in a lightbox. Includes a user-friendly interface and numerous appearance options.
6 Author: WebFactory Ltd
7 Version: 4.23
8 Author URI: https://www.gmapswidget.com/
9 Text Domain: google-maps-widget
10 Domain Path: lang
11 Requires at least: 4.0
12 Requires PHP: 5.2
13 Tested up to: 6.1
14
15 Copyright 2012 - 2022 WebFactory Ltd (email : gmw@webfactoryltd.com)
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License, version 2, as
19 published by the Free Software Foundation.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31
32 // this is an include only WP file
33 if (!defined('ABSPATH')) {
34 wp_die('Do not load this file directly.');
35 }
36
37
38 if (!class_exists('GMW')) {
39
40 define('GMW_PLUGIN_DIR', plugin_dir_path(__FILE__));
41 define('GMW_PLUGIN_URL', plugin_dir_url(__FILE__));
42 define('GMW_BASE_FILE', basename(__FILE__));
43
44 require_once GMW_PLUGIN_DIR . 'gmw-widget.php';
45
46 class GMW {
47 static $version;
48 static $options = 'gmw_options';
49 static $licensing_servers = array('http://license.gmapswidget.com/', 'http://license2.gmapswidget.com/');
50
51
52 // get plugin version from header
53 static function get_plugin_version() {
54 $plugin_data = get_file_data(__FILE__, array('version' => 'Version'), 'plugin');
55 GMW::$version = $plugin_data['version'];
56
57 return $plugin_data['version'];
58 } // get_plugin_version
59
60
61 // hook everything up
62 static function init() {
63 if (is_admin()) {
64 // check if minimal required WP version is present
65 if (false === GMW::check_wp_version(4.0)) {
66 return false;
67 }
68
69 // check a few variables
70 GMW::maybe_upgrade();
71
72 // aditional links in plugin description
73 add_filter('plugin_action_links_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
74 array('GMW', 'plugin_action_links'));
75 add_filter('plugin_row_meta', array('GMW', 'plugin_meta_links'), 10, 2);
76
77 // enqueue admin scripts
78 add_action('admin_enqueue_scripts', array('GMW', 'admin_enqueue_scripts'), 100);
79 add_action('customize_controls_enqueue_scripts', array('GMW', 'admin_enqueue_scripts'));
80
81 // JS dialog markup
82 add_action('admin_footer', array('GMW', 'admin_dialogs_markup'));
83
84 // register AJAX endpoints
85 add_action('wp_ajax_gmw_test_api_key', array('GMW', 'test_api_key_ajax'));
86 add_action('wp_ajax_gmw_activate', array('GMW', 'activate_license_key_ajax'));
87 add_action('wp_ajax_gmw_dismiss_pointer', array('GMW', 'dismiss_pointer_ajax'));
88
89 // custom admin actions
90 add_action('admin_action_gmw_dismiss_notice', array('GMW', 'dismiss_notice'));
91
92 // add options menu
93 add_action('admin_menu', array('GMW', 'add_menus'));
94
95 // settings registration
96 add_action('admin_init', array('GMW', 'register_settings'));
97
98 // display various notices
99 add_action('current_screen', array('GMW', 'add_notices'));
100 } else {
101 // enqueue frontend scripts
102 add_action('wp_enqueue_scripts', array('GMW', 'register_scripts'));
103 add_action('wp_footer', array('GMW', 'dialogs_markup'));
104 }
105 } // init
106
107
108 // some things have to be loaded earlier
109 static function plugins_loaded() {
110 GMW::get_plugin_version();
111
112 load_plugin_textdomain('google-maps-widget', false, basename(dirname(__FILE__)) . '/lang');
113 } // plugins_loaded
114
115
116 // initialize widgets
117 static function widgets_init() {
118 register_widget('GoogleMapsWidget');
119 } // widgets_init
120
121
122 // all settings are saved in one option
123 static function register_settings() {
124 register_setting(GMW::$options, GMW::$options, array('GMW', 'sanitize_settings'));
125 } // register_settings
126
127
128 // sanitize settings on save
129 static function sanitize_settings($values) {
130 $old_options = GMW::get_options();
131
132 foreach ($values as $key => $value) {
133 switch ($key) {
134 case 'api_key':
135 $values[$key] = str_replace(' ', '', $value);
136 break;
137 } // switch
138 } // foreach
139
140 if (strlen($values['api_key']) < 30) {
141 add_settings_error(GMW::$options, 'api_key', __('Google Maps API key is not valid. Access <a href="https://console.developers.google.com/project">Google Developers Console</a> to generate a key for free.', 'google-maps-widget'), 'error');
142 }
143
144 return array_merge($old_options, $values);
145 } // sanitize_settings
146
147
148 // return default options
149 static function default_options() {
150 $defaults = array('sc_map' => 'gmw',
151 'api_key' => '',
152 'track_ga' => '0',
153 'include_jquery' => '1',
154 'include_gmaps_api' => '1',
155 'include_lightbox_js' => '1',
156 'include_lightbox_css' => '1',
157 'disable_tooltips' => '0',
158 'disable_sidebar' => '0',
159 'activation_code' => '',
160 'license_active' => '',
161 'license_expires' => '',
162 'license_type' => ''
163 );
164
165 return $defaults;
166 } // default_settings
167
168
169 // get plugin's options
170 static function get_options() {
171 $options = get_option(GMW::$options, array());
172
173 if (!is_array($options)) {
174 $options = array();
175 }
176 $options = array_merge(GMW::default_options(), $options);
177
178 return $options;
179 } // get_options
180
181
182 // update and set one or more options
183 static function set_options($new_options) {
184 if (!is_array($new_options)) {
185 return false;
186 }
187
188 $options = GMW::get_options();
189 $options = array_merge($options, $new_options);
190
191 update_option(GMW::$options, $options);
192
193 return $options;
194 } // set_options
195
196
197 // add widgets link to plugins page
198 static function plugin_action_links($links) {
199 $settings_link = '<a href="' . admin_url('options-general.php?page=gmw_options') . '" title="' . __('Settings for Maps Widget for Google Maps', 'google-maps-widget') . '">' . __('Settings', 'google-maps-widget') . '</a>';
200 $widgets_link = '<a href="' . admin_url('widgets.php') . '" title="' . __('Configure Maps Widget for Google Maps for your theme', 'google-maps-widget') . '">' . __('Widgets', 'google-maps-widget') . '</a>';
201
202 array_unshift($links, $settings_link);
203 array_unshift($links, $widgets_link);
204
205 return $links;
206 } // plugin_action_links
207
208
209 // add links to plugin's description in plugins table
210 static function plugin_meta_links($links, $file) {
211 $documentation_link = '<a target="_blank" href="http://www.gmapswidget.com/documentation/" title="' . __('View Maps Widget for Google Maps documentation', 'google-maps-widget') . '">'. __('Documentation', 'google-maps-widget') . '</a>';
212 $support_link = '<a target="_blank" href="http://wordpress.org/support/plugin/google-maps-widget" title="' . __('Problems? We are here to help!', 'google-maps-widget') . '">' . __('Support', 'google-maps-widget') . '</a>';
213 $review_link = '<a target="_blank" href="https://wordpress.org/support/view/plugin-reviews/google-maps-widget?filter=5#pages" title="' . __('If you like it, please review the plugin', 'google-maps-widget') . '">' . __('Review the plugin', 'google-maps-widget') . '</a>';
214 $activate_link = '<a href="' . esc_url(admin_url('options-general.php?page=gmw_options&gmw_open_promo_dialog')) . '">' . __('Activate PRO features', 'google-maps-widget') . '</a>';
215
216 if ($file == plugin_basename(__FILE__)) {
217 $links[] = $documentation_link;
218 $links[] = $support_link;
219 $links[] = $review_link;
220 if (!GMW::is_activated()) {
221 $links[] = $activate_link;
222 }
223 }
224
225 return $links;
226 } // plugin_meta_links
227
228
229 // check if user has the minimal WP version required by GMW
230 static function check_wp_version($min_version) {
231 if (!version_compare(get_bloginfo('version'), $min_version, '>=')) {
232 add_action('admin_notices', array('GMW', 'notice_min_version_error'));
233 return false;
234 }
235
236 return true;
237 } // check_wp_version
238
239
240 // display error message if WP version is too low
241 static function notice_min_version_error() {
242 echo '<div class="error"><p>' . sprintf(__('Maps Widget for Google Maps <b>requires WordPress version 4.0</b> or higher to function properly. You are using WordPress version %s. Please <a href="%s">update it</a>.', 'google-maps-widget'), get_bloginfo('version'), admin_url('update-core.php')) . '</p></div>';
243 } // notice_min_version_error
244
245
246 // get users maps api key or one of temporary plugin ones
247 static function get_api_key($type = 'static') {
248 $options = GMW::get_options();
249 $default_api_keys = array('AIzaSyBvCK51-6tqdH0gu_lsUK8SxlGrvfUzIfo');
250
251 if ($type == 'test' && strlen($options['api_key']) < 30) {
252 return false;
253 }
254
255 if ($type == 'fallback' && empty($options['api_key'])) {
256 shuffle($default_api_keys);
257 return $default_api_keys[0];
258 }
259
260 if (!empty($options['api_key'])) {
261 return $options['api_key'];
262 } else {
263 return false;
264 }
265 } // get_api_key
266
267
268 // checkes if API key is active for all needed API services
269 static function test_api_key_ajax() {
270 check_ajax_referer('gmw_test_api_key');
271
272 $msg = '';
273 $error = false;
274 $api_key = substr(sanitize_key(@$_GET['api_key']), 0, 128);
275
276 $test = wp_remote_get(esc_url_raw('https://maps.googleapis.com/maps/api/staticmap?center=new+york+usa&size=100x100&key=' . $api_key));
277 if (wp_remote_retrieve_response_message($test) == 'OK') {
278 $msg .= 'Google Static Maps API test - OK' . "\n";
279 } else {
280 $msg .= 'Google Static Maps API test - FAILED' . "\n";
281 $error = true;
282 }
283
284 $test = wp_remote_get(esc_url_raw('https://www.google.com/maps/embed/v1/place?q=new+york+usa&key=' . $api_key));
285 if (wp_remote_retrieve_response_message($test) == 'OK') {
286 $msg .= 'Google Embed Maps API test - OK' . "\n\n";
287 } else {
288 $msg .= 'Google Embed Maps API test - FAILED' . "\n\n";
289 $error = true;
290 }
291
292 if ($error) {
293 $msg .= 'Something is not right. Please read the instruction below on how to generate the API key and double-check everything.';
294 } else {
295 $msg = 'The API key is OK! Don\'t forget to save it ;)';
296 }
297
298 wp_send_json_success($msg);
299 } // test_api_key
300
301
302 // build a complete URL for the iframe map
303 static function build_lightbox_url($widget) {
304 $map_params = array();
305
306 if ($widget['lightbox_mode'] == 'place') {
307 $map_params['q'] = $widget['address'];
308 $map_params['attribution_source'] = get_bloginfo('name')? get_bloginfo('name'): 'Maps Widget for Google Maps';
309 $map_params['attribution_web_url'] = get_home_url();
310 $map_params['attribution_ios_deep_link_id'] = 'comgooglemaps://?daddr=' . $widget['address'];
311 $map_params['maptype'] = $widget['lightbox_map_type'];
312 $map_params['zoom'] = $widget['lightbox_zoom'];
313 } elseif ($widget['lightbox_mode'] == 'directions') {
314 $map_params['origin'] = $widget['lightbox_origin'];
315 $map_params['destination'] = $widget['address'];
316 $map_params['maptype'] = $widget['lightbox_map_type'];
317 if (!empty($widget['lightbox_unit']) && $widget['lightbox_unit'] != 'auto') {
318 $map_params['units'] = $widget['lightbox_unit'];
319 }
320 if ($widget['lightbox_zoom'] != 'auto') {
321 $map_params['zoom'] = $widget['lightbox_zoom'];
322 }
323 } elseif ($widget['lightbox_mode'] == 'search') {
324 if (($coordinates = GMW::get_coordinates($widget['address'])) !== false) {
325 $map_params['center'] = $coordinates['lat'] . ',' . $coordinates['lng'];
326 }
327 $map_params['q'] = $widget['lightbox_search'];
328 $map_params['maptype'] = $widget['lightbox_map_type'];
329 if ($widget['lightbox_zoom'] != 'auto') {
330 $map_params['zoom'] = $widget['lightbox_zoom'];
331 }
332 } elseif ($widget['lightbox_mode'] == 'view') {
333 if (($coordinates = GMW::get_coordinates($widget['address'])) !== false) {
334 $map_params['center'] = $coordinates['lat'] . ',' . $coordinates['lng'];
335 }
336 $map_params['maptype'] = $widget['lightbox_map_type'];
337 if ($widget['lightbox_zoom'] != 'auto') {
338 $map_params['zoom'] = $widget['lightbox_zoom'];
339 }
340 } elseif ($widget['lightbox_mode'] == 'streetview') {
341 if (($coordinates = GMW::get_coordinates($widget['address'])) !== false) {
342 $map_params['location'] = $coordinates['lat'] . ',' . $coordinates['lng'];
343 }
344 $map_params['heading'] = $widget['lightbox_heading'];
345 $map_params['pitch'] = $widget['lightbox_pitch'];
346 }
347
348 if ($widget['lightbox_lang'] != 'auto') {
349 $map_params['language'] = $widget['lightbox_lang'];
350 }
351 $map_params['key'] = GMW::get_api_key('embed');
352
353 $map_url = 'https://www.google.com/maps/embed/v1/' . $widget['lightbox_mode'] . '?';
354 $map_url .= http_build_query($map_params, null, '&amp;');
355
356 return $map_url;
357 } // build_lightbox_url
358
359
360 // fetch coordinates based on the address
361 static function get_coordinates($address, $force_refresh = false) {
362 $address_hash = md5('gmw_' . $address);
363
364 if ($force_refresh || ($data = get_transient($address_hash)) === false) {
365 $url = 'https://maps.googleapis.com/maps/api/geocode/xml?address=' . urlencode($address) . '&key=' . GMW::get_api_key('fallback');
366 $result = wp_remote_get(esc_url_raw($url), array('sslverify' => false, 'timeout' => 10));
367
368 if (!is_wp_error($result) && $result['response']['code'] == 200) {
369 $data = new SimpleXMLElement($result['body']);
370
371 if ($data->status == 'OK') {
372 $cache_value['lat'] = (string) $data->result->geometry->location->lat;
373 $cache_value['lng'] = (string) $data->result->geometry->location->lng;
374 $cache_value['address'] = (string) $data->result->formatted_address;
375
376 // cache coordinates for 2 months
377 set_transient($address_hash, $cache_value, MONTH_IN_SECONDS * 2);
378 $data = $cache_value;
379 $data['cached'] = false;
380 } elseif (!$data->status) {
381 return false;
382 } else {
383 return false;
384 }
385 } else {
386 return false;
387 }
388 } else {
389 // data is cached
390 $data['cached'] = true;
391 }
392
393 return $data;
394 } // get_coordinates
395
396
397 // print dialogs markup in footer
398 static function dialogs_markup() {
399 $out = '';
400 $js_vars = array();
401 $measure_title = array('dark');
402
403 if (empty(GoogleMapsWidget::$widgets)) {
404 return;
405 }
406
407 // add CSS and JS in footer
408 $js_vars['colorbox_css'] = GMW_PLUGIN_URL . 'css/gmw.css' . '?ver=' . GMW::$version;
409 wp_enqueue_script('gmw-colorbox');
410 wp_enqueue_script('gmw');
411 wp_localize_script('gmw', 'gmw_data', $js_vars);
412
413 foreach (GoogleMapsWidget::$widgets as $widget) {
414 $map_url = GMW::build_lightbox_url($widget);
415
416 if ($widget['lightbox_fullscreen']) {
417 $widget['lightbox_width'] = '100%';
418 $widget['lightbox_height'] = '100%';
419 }
420
421 $out .= '<div class="gmw-dialog" style="display: none;" data-map-height="' . $widget['lightbox_height'] . '"
422 data-map-width="' . $widget['lightbox_width'] . '" data-thumb-height="' . $widget['thumb_height'] . '"
423 data-thumb-width="' . $widget['thumb_width'] . '" data-map-skin="' . $widget['lightbox_skin'] . '"
424 data-map-iframe-url="' . $map_url . '" id="gmw-dialog-' . $widget['id'] . '" title="' . esc_attr($widget['title']) . '"
425 data-close-button="' . (int) in_array('close_button', $widget['lightbox_feature']) . '"
426 data-show-title="' . (int) in_array('title', $widget['lightbox_feature']) . '"
427 data-measure-title="' . (int) in_array($widget['lightbox_skin'], $measure_title) . '"
428 data-close-overlay="' . (int) in_array('overlay_close', $widget['lightbox_feature']) . '"
429 data-close-esc="' . (int) in_array('esc_close', $widget['lightbox_feature']) . '">';
430 if ($widget['lightbox_header']) {
431 $tmp = str_ireplace(array('{address}'), array($widget['address']), $widget['lightbox_header']);
432 $out .= '<div class="gmw-header">' . wpautop(do_shortcode($tmp)) . '</div>';
433 }
434 $out .= '<div class="gmw-map"></div>';
435 if ($widget['lightbox_footer']) {
436 $tmp = str_ireplace(array('{address}'), array($widget['address']), $widget['lightbox_footer']);
437 $out .= '<div class="gmw-footer">' . wpautop(do_shortcode($tmp)) . '</div>';
438 }
439 $out .= "</div>\n";
440 } // foreach $widgets
441
442 self::wp_kses_wf($out);
443 } // dialogs_markup
444
445
446 // add plugin menus
447 static function add_menus() {
448 $title = __('Maps Widget for Google Maps', 'google-maps-widget');
449 add_options_page($title, $title, 'manage_options', GMW::$options, array('GMW', 'settings_screen'));
450 } // add_menus
451
452
453 // handle dismiss button for notices
454 static function dismiss_notice() {
455 if (empty($_GET['notice'])) {
456 wp_safe_redirect(admin_url());
457 exit;
458 }
459
460 $notice_name = substr(sanitize_key($_GET['notice']), 0, 32);
461
462 if ($notice_name == 'upgrade') {
463 GMW::set_options(array('dismiss_notice_upgrade2' => true));
464 } elseif ($notice_name == 'rate') {
465 GMW::set_options(array('dismiss_notice_rate' => true));
466 } elseif ($notice_name == 'api_key') {
467 GMW::set_options(array('dismiss_notice_api_key' => true));
468 } elseif ($notice_name == 'olduser') {
469 GMW::set_options(array('dismiss_notice_olduser' => true));
470 } else {
471 wp_safe_redirect(admin_url());
472 exit;
473 }
474
475 if (!empty($_GET['redirect'])) {
476 wp_safe_redirect(esc_url($_GET['redirect']));
477 } else {
478 wp_safe_redirect(admin_url());
479 }
480
481 exit;
482 } // dismiss_notice
483
484
485 // controls which notices are shown
486 static function add_notices() {
487 $options = GMW::get_options();
488 $notice = false;
489 global $wp_version;
490
491 if (false == is_plugin_active('classic-widgets/classic-widgets.php') && version_compare($wp_version, '5.8', '>=') == true) {
492 $notice = true;
493 add_action('admin_notices', array('GMW', 'notice_classic_widgets'));
494 }
495
496 // upgrade notice is shown after install
497 if (!$notice && empty($options['dismiss_notice_upgrade2']) &&
498 !GMW::is_activated() &&
499 (current_time('timestamp') - $options['first_install']) > 2) {
500 add_action('admin_notices', array('GMW', 'notice_upgrade'));
501 $notice = true;
502 } // show upgrade notice
503
504 // API key notification is shown only on GMW settings page
505 if (!GMW::get_api_key('test') && GMW::is_plugin_admin_page('settings')) {
506 add_action('admin_notices', array('GMW', 'notice_api_key'));
507 $notice = true;
508 } // show api key notice
509
510 // rating notification is shown after 7 days if you have active widgets
511 if (!$notice && empty($options['dismiss_notice_rate']) &&
512 self::count_active_widgets() > 0 &&
513 (current_time('timestamp') - $options['first_install']) > (DAY_IN_SECONDS * 3)) {
514 add_action('admin_notices', array('GMW', 'notice_rate_plugin'));
515 $notice = true;
516 } // show rate notice
517
518 // upsell to old users
519 if (!$notice && empty($options['dismiss_notice_olduser']) &&
520 ((current_time('timestamp') - $options['first_install']) > (DAY_IN_SECONDS * 60))) {
521 add_action('admin_notices', array('GMW', 'notice_olduser'));
522 $notice = true;
523 } // upsell to old users
524 } // add_notices
525
526
527 // display error notice if classic widgets are not available
528 static function notice_classic_widgets() {
529 echo '<div class="error notice" style="max-width: 700px;"><p><b>🔥 IMPORTANT 🔥</b><br><br>Google Maps Widget is NOT compatible with the new widgets edit screen (powered by Gutenberg).
530 <br>Install the official <a href="' . admin_url('plugin-install.php?s=classic%20widgets&tab=search&type=term') . '">Classic Widgets</a> plugin if you want to continue using Google Maps Widget.<br>
531 Or install the <a href="' . admin_url('plugin-install.php?s=map%20block&tab=search&type=tag') . '">free Map Block plugin</a> as the fastest way to add a great map to any post or sidebar.</p></div>';
532 } // notice_classic_widgets
533
534
535 // display message to get pro features for GMW
536 static function notice_upgrade() {
537 $promo_delta = HOUR_IN_SECONDS - 2;
538 $options = GMW::get_options();
539 $activate_url = admin_url('options-general.php?page=gmw_options&gmw_open_promo_dialog');
540 $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'upgrade', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php'));
541
542 echo '<div id="gmw_activate_notice" class="updated notice"><p>' . __('<b>Maps Widget for Google Maps <span style="color: #d54e21;">PRO</span></b> has more than 50 extra features &amp; options. Our support is super fast &amp; friendly and with the unlimited license you can install GMW on as many sites as you need.</p>', 'google-maps-widget');
543
544 if (current_time('timestamp') - $options['first_install'] < $promo_delta) {
545 $delta = $options['first_install_gmt'] + $promo_delta - time();
546 $h = $delta / 3600 % 24;
547 if ($h) {
548 $h .= 'h';
549 } else {
550 $h = '';
551 }
552 $min = $delta / 60 % 60;
553 echo '<p>We\'ve prepared a special <b>20% welcoming discount</b> available only for another <b class="gmw-countdown" data-endtime="' . esc_attr(($options['first_install_gmt'] + $promo_delta)) . '" style="font-weight: bold;">' . esc_attr($h) . ' ' . esc_attr($min) . 'min</b>.</p>';
554 echo '<p><a href="' . esc_url($activate_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary"><b>Get a lifetime PRO license now for only $39 - LIMITED OFFER!</b></a>';
555 } else {
556 echo '<p><a href="' . esc_url($activate_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary">' . __('See what PRO has to offer', 'google-maps-widget') . '</a>';
557 }
558
559 echo '&nbsp;&nbsp;<a href="' . esc_url($dismiss_url) . '" class="">' . __('I\'m not interested (remove notice)', 'google-maps-widget') . '</a>';
560 echo '</p></div>';
561 } // notice_activate_extra_features
562
563
564 // display message to get pro features for GMW
565 static function notice_olduser() {
566 $options = GMW::get_options();
567 $activate_url = admin_url('options-general.php?page=gmw_options&gmw_open_promo_dialog');
568 $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'olduser', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php'));
569
570 echo '<div class="updated notice">';
571 echo '<p style="font-size: 14px;">We have a <a class="open_promo_dialog" href="' . esc_url($activate_url) . '">special offer</a> only for users like <b>you</b> who\'ve been using Maps Widget for Google Maps for a while: a <b>one time payment</b>, lifetime license for <b>only $39</b>! No nonsense!<br><a class="open_promo_dialog" href="' . esc_url($activate_url) . '">Upgrade now</a> to <span class="gmw-pro-red">PRO</span> &amp; get more than 50 extra options &amp; features.</p><br>';
572
573 echo '<a class="open_promo_dialog button button-primary" href="' . esc_url($activate_url) . '"><b>Grab the limited offer!</b></a>&nbsp;&nbsp;<a href="' . esc_url($dismiss_url) . '" style="margin: 3px 0 0 5px; display: inline-block;">' . __('I\'m not interested (remove notice)', 'google-maps-widget') . '</a>';
574 echo '</p></div>';
575 } // notice_olduser
576
577
578 // display message to rate plugin
579 static function notice_rate_plugin() {
580 $rate_url = 'https://wordpress.org/support/view/plugin-reviews/google-maps-widget?rate=5#postform';
581 $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'rate', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php'));
582
583 echo '<div id="gmw_rate_notice" class="updated notice"><p>' . __('Hi! We saw you\'ve been using <b>Maps Widget for Google Maps</b> for a week and wanted to ask for your help to make the plugin better.<br>We just need a minute of your time to rate the plugin. Thank you!', 'google-maps-widget');
584
585 echo '<br><a target="_blank" href="' . esc_url($rate_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary">' . __('Help make the plugin better by rating it', 'google-maps-widget') . '</a>';
586 echo '&nbsp;&nbsp;<a href="' . esc_url($dismiss_url) . '">' . __('I already rated the plugin', 'google-maps-widget') . '</a>';
587 echo '</p></div>';
588 } // notice_rate_plugin
589
590
591 // display message to enter API key
592 static function notice_api_key() {
593 echo '<div id="gmw_api_key_notice" class="error notice"><p>';
594 echo '<b>Important!</b> Google rules dictate that you have to register for a <b>free Google Maps API key</b>. ';
595 echo 'Please follow our <a href="http://www.gmapswidget.com/documentation/generate-google-maps-api-key/" target="_blank">short instructions</a> to get the key. If you don\'t configure the API key the maps will not work properly.';
596 echo '</p></div>';
597 } // notice_api_key
598
599
600 // register frontend scripts and styles
601 static function register_scripts() {
602 wp_register_style('gmw', GMW_PLUGIN_URL . 'css/gmw.css', array(), GMW::$version);
603
604 wp_register_script('gmw-colorbox', GMW_PLUGIN_URL . 'js/jquery.colorbox.min.js', array('jquery'), GMW::$version, true);
605 wp_register_script('gmw', GMW_PLUGIN_URL . 'js/gmw.js', array('jquery'), GMW::$version, true);
606 } // register_scripts
607
608
609 // enqueue CSS and JS scripts in admin
610 static function admin_enqueue_scripts() {
611 $js_localize = array('dialog_map_title' => __('Pick an address by drag &amp; dropping the pin', 'google-maps-widget'),
612 'undocumented_error' => __('An undocumented error has occured. Please refresh the page and try again.', 'google-maps-widget'),
613 'bad_api_key' => __('The API key format does not look right. Please double-check it.', 'google-maps-widget'),
614 'dialog_promo_title' => '<img alt="' . __('Maps Widget for Google Maps PRO', 'google-maps-widget') . '" title="' . __('Maps Widget for Google Maps PRO', 'google-maps-widget') . '" src="' . GMW_PLUGIN_URL . 'images/gmw-logo-pro-dialog.png' . '">',
615 'dialog_pins_title' => __('Pins Library', 'google-maps-widget'),
616 'plugin_name' => __('Maps Widget for Google Maps', 'google-maps-widget'),
617 'id_base' => 'googlemapswidget',
618 'map_picker_not_active' => __('Drag&drop address picking interface is a PRO feature. Interested in switching to PRO?', 'google-maps-widget'),
619 'customizer_address_picker' => __('At the moment, the address picker is not available in the theme customizer. Please use it in the admin widget GUI.', 'google-maps-widget'),
620 'customizer_pro_dialog' => __('To see what the PRO version offers please open GMW settings in the admin.', 'google-maps-widget'),
621 'map' => false,
622 'marker' => false,
623 'settings_url' => admin_url('options-general.php?page=gmw_options'),
624 'nonce_test_api_key' => wp_create_nonce('gmw_test_api_key'),
625 'nonce_activate_license_key' => wp_create_nonce('gmw_activate_license_key'),
626 'deactivate_confirmation' => __('Are you sure you want to deactivate Maps Widget for Google Maps?' . "\n" . 'All maps will be removed from the site. If you are removing it because of a problem please contact our support. They will be more than glad to help.', 'google-maps-widget'));
627
628 if (GMW::is_plugin_admin_page('widgets') || GMW::is_plugin_admin_page('settings') || is_customize_preview()) {
629 wp_enqueue_script('jquery-ui-tabs');
630 wp_enqueue_script('jquery-ui-dialog');
631 wp_enqueue_script('wp-pointer');
632 wp_enqueue_script('gmw-gmap', '//maps.google.com/maps/api/js?key=' . GMW::get_api_key('fallback'), array(), GMW::$version, true);
633 wp_enqueue_script('gmw-select2', GMW_PLUGIN_URL . 'js/select2.min.js', array('jquery'), GMW::$version, true);
634 wp_enqueue_script('gmw-admin', GMW_PLUGIN_URL . 'js/gmw-admin.js', array('jquery'), GMW::$version, true);
635
636 wp_enqueue_style('wp-jquery-ui-dialog');
637 wp_enqueue_style('wp-pointer');
638 wp_enqueue_style('gmw-select2', GMW_PLUGIN_URL . 'css/select2.min.css', array(), GMW::$version);
639 wp_enqueue_style('gmw-admin', GMW_PLUGIN_URL . 'css/gmw-admin.css', array(), GMW::$version);
640
641 wp_localize_script('gmw-admin', 'gmw', $js_localize);
642
643 // fix for agressive plugins
644 wp_dequeue_style('uiStyleSheet');
645 wp_dequeue_style('wpcufpnAdmin' );
646 wp_dequeue_style('unifStyleSheet' );
647 wp_dequeue_style('wpcufpn_codemirror');
648 wp_dequeue_style('wpcufpn_codemirrorTheme');
649 wp_dequeue_style('collapse-admin-css');
650 wp_dequeue_style('jquery-ui-css');
651 wp_dequeue_style('tribe-common-admin');
652 wp_dequeue_style('file-manager__jquery-ui-css');
653 wp_dequeue_style('file-manager__jquery-ui-css-theme');
654 wp_dequeue_style('wpmegmaps-jqueryui');
655 wp_dequeue_style('facebook-plugin-css');
656 wp_dequeue_style('facebook-tip-plugin-css');
657 wp_dequeue_style('facebook-member-plugin-css');
658 wp_dequeue_style('jquery-ui-tooltip-css');
659 wp_dequeue_style('social_warfare_admin');
660 } // if
661
662 if (GMW::is_plugin_admin_page('plugins')) {
663 wp_enqueue_script('gmw-admin-plugins', GMW_PLUGIN_URL . 'js/gmw-admin-plugins.js', array('jquery'), GMW::$version, true);
664 wp_localize_script('gmw-admin-plugins', 'gmw', $js_localize);
665 }
666
667
668 $pointers = get_transient('gmw_pointers');
669 if ($pointers && !GMW::is_plugin_admin_page('widgets') && !GMW::is_plugin_admin_page('settings')) {
670 $pointers['_nonce_dismiss_pointer'] = wp_create_nonce('gmw_dismiss_pointer');
671 wp_enqueue_script('wp-pointer');
672 wp_enqueue_script('gmw-pointers', plugins_url('js/gmw-admin-pointers.js', __FILE__), array('jquery'), self::$version, true);
673 wp_enqueue_style('wp-pointer');
674 wp_localize_script('wp-pointer', 'gmw_pointers', $pointers);
675 }
676 } // admin_enqueue_scripts
677
678
679 // reset all pointers to default state - visible
680 static function reset_pointers() {
681 $pointers = array();
682 $pointers['welcome'] = array('target' => '#menu-appearance', 'edge' => 'left', 'align' => 'right', 'content' => 'Thank you for installing <b>Maps Widget for Google Maps</b>! Please open <a href="' . admin_url('widgets.php'). '">Appearance - Widgets</a> to create your first map in seconds.');
683
684 set_transient('gmw_pointers', $pointers, 60 * DAY_IN_SECONDS);
685 } // reset_pointers
686
687
688 // permanently dismiss a pointer
689 static function dismiss_pointer_ajax() {
690 check_ajax_referer('gmw_dismiss_pointer');
691
692 $pointers = get_transient('gmw_pointers');
693
694 $pointer = substr(sanitize_key(@$_POST['pointer']), 0, 64);
695
696 if (empty($pointers) || empty($pointers[$pointer])) {
697 wp_send_json_error();
698 }
699
700 unset($pointers[$pointer]);
701 set_transient('gmw_pointers', $pointers);
702
703 wp_send_json_success();
704 } // dismiss_pointer_ajax
705
706
707 // check if plugin's admin page is shown
708 static function is_plugin_admin_page($page = 'widgets') {
709 $current_screen = get_current_screen();
710
711 if ($page == 'widgets' && $current_screen->id == 'widgets') {
712 return true;
713 }
714
715 if ($page == 'settings' && $current_screen->id == 'settings_page_gmw_options') {
716 return true;
717 }
718
719 if ($page == 'plugins' && $current_screen->id == 'plugins') {
720 return true;
721 }
722
723 return false;
724 } // is_plugin_admin_page
725
726
727 // check if license key is valid and not expired
728 static function is_activated() {
729 $options = GMW::get_options();
730
731 if (isset($options['license_active']) && $options['license_active'] === true &&
732 isset($options['license_expires']) && $options['license_expires'] >= date('Y-m-d')) {
733 return true;
734 } else {
735 return false;
736 }
737 } // is_activated
738
739
740 // check if activation code is valid
741 static function validate_activation_code($code) {
742 $request_params = array('sslverify' => false, 'timeout' => 15, 'redirection' => 2);
743 $request_args = array('action' => 'validate_license',
744 'code' => $code,
745 'codebase' => 'free',
746 'version' => GMW::$version,
747 'site' => get_home_url());
748
749 $out = array('success' => false, 'license_active' => false, 'activation_code' => $code, 'error' => '', 'license_type' => '', 'license_expires' => '1900-01-01');
750
751 $url = add_query_arg($request_args, GMW::$licensing_servers[0]);
752 $response = wp_remote_get(esc_url_raw($url), $request_params);
753
754 if (is_wp_error($response) || !wp_remote_retrieve_body($response)) {
755 $url = add_query_arg($request_args, GMW::$licensing_servers[1]);
756 $response = wp_remote_get(esc_url_raw($url), $request_params);
757 }
758
759 if (!is_wp_error($response) && wp_remote_retrieve_body($response)) {
760 $result = json_decode(wp_remote_retrieve_body($response), true);
761 if (is_array($result['data']) && sizeof($result['data']) == 4) {
762 $out['success'] = true;
763 $out = array_merge($out, $result['data']);
764 } else {
765 $out['error'] = 'Invalid response from licensing server. Please try again later.';
766 }
767 } else {
768 $out['error'] = 'Unable to contact licensing server. Please try again in a few moments.';
769 }
770
771 return $out;
772 } // validate_activation_code
773
774
775 // echo markup for promo dialog; only on widgets page
776 static function admin_dialogs_markup() {
777 $out = '';
778 $options = GMW::get_options();
779 $promo_delta = 1 * HOUR_IN_SECONDS - 5;
780 $promo_active = (bool) ((current_time('timestamp') - $options['first_install']) < $promo_delta);
781 $promo_active2 = (bool) ((current_time('timestamp') - $options['first_install']) > DAY_IN_SECONDS * 35);
782
783 if (GMW::is_plugin_admin_page('widgets') || GMW::is_plugin_admin_page('settings')) {
784 $current_user = wp_get_current_user();
785 if (empty($current_user->user_firstname)) {
786 $name = $current_user->display_name;
787 } else {
788 $name = $current_user->user_firstname;
789 }
790
791 $out .= '<div id="gmw_promo_dialog" style="display: none;">';
792
793 $out .= '<div id="gmw_dialog_intro" class="gmw_promo_dialog_screen">
794 <div class="content">
795 <div class="header"><p><a href="#" class="gmw_goto_pro">Learn more</a> about <span class="gmw-pro">PRO</span> features or <a href="#" class="gmw_goto_activation">enter your license key</a></p>';
796 if ($promo_active) {
797 $delta = $options['first_install_gmt'] + $promo_delta - time();
798 $h = $delta / 3600 % 24;
799 $min = $delta / 60 % 60;
800 $out .= '<div class="gmw-discount">We\'ve prepared a special <b>20% welcoming discount</b> available only for another <b class="gmw-countdown" data-endtime="' . ($options['first_install_gmt'] + $promo_delta) . '">' . $h . 'h ' . $min . 'min 0sec</b>. Discounts have been applied on the licenses below.</div>';
801 }
802 $out .= '</div>'; // header
803
804 $out .= '<table id="gmw-pricing-table">';
805 $out .= '<colgroup></colgroup><colgroup></colgroup><colgroup></colgroup>';
806 $out .= '<tr>';
807 $out .= '<td><div class="gmw-promo-icon"><img src="' . GMW_PLUGIN_URL . 'images/icon-agency.png" alt="Unlimited Agency Lifetime License" title="Unlimited Agency Lifetime License"></div><h3>Unlimited<br>Agency License</h3></td>';
808 $out .= '<td><div class="gmw-promo-icon"><img src="' . GMW_PLUGIN_URL . 'images/icon-unlimited.png" alt="Lifetime Personal License" title="Lifetime Personal License"></div><h3>Lifetime<br>Personal License</h3></td>';
809 $out .= '<td><div class="gmw-promo-icon"><img src="' . GMW_PLUGIN_URL . 'images/icon-yearly.png" alt="Yearly License" title="Yearly License"></div><h3>Single<br>Site License</h3></td>';
810 $out .= '</tr>';
811 $out .= '<tr>';
812 $out .= '<td>One Time Payment</td>';
813 $out .= '<td><span class="dashicons dashicons-yes"></span> One Time Payment</td>';
814 $out .= '<td>Yearly Payment</td>';
815 $out .= '</tr>';
816 $out .= '<tr>';
817 $out .= '<td>Unlimited Client &amp; Personal Sites</td>';
818 $out .= '<td><span class="dashicons dashicons-yes"></span> 1 Personal Site</td>';
819 $out .= '<td>1 Personal or Client Site</td>';
820 $out .= '</tr>';
821 $out .= '<tr>';
822 $out .= '<td>Lifetime Priority Support</td>';
823 $out .= '<td><span class="dashicons dashicons-yes"></span> Lifetime Priority Support</td>';
824 $out .= '<td>1 Year of Support</td>';
825 $out .= '</tr>';
826 $out .= '<tr>';
827 $out .= '<td>Lifetime Updates</td>';
828 $out .= '<td><span class="dashicons dashicons-yes"></span> Lifetime Updates</td>';
829 $out .= '<td>1 Year of Updates</td>';
830 $out .= '</tr>';
831 $out .= '<tr>';
832 $out .= '<td>';
833 if (1 || $promo_active) {
834 $out .= '<div class="gmw-promo-button gmw-promo-button-extra"><a href="https://gum.co/gmw-pro-agency/welcome?wanted=true&plugin_info=GMW+v' . GMW::$version . '" target="_blank" data-gumroad-single-product="true">only <strike>$79</strike> $54</a><span>discount: 32%</span></div>';
835 } else {
836 $out .= '<div class="gmw-promo-button"><a href="https://gum.co/gmw-pro-agency?wanted=true&plugin_info=GMW+v' . GMW::$version . '" data-noprevent="1" target="_blank" data-gumroad-single-product="true">BUY $79</a></div>';
837 }
838 $out .= '<span class="instant-download"><span class="dashicons dashicons-yes"></span> 100% No-Risk Money Back Guarantee<br><span class="dashicons dashicons-yes"></span> Secure payment<br><span class="dashicons dashicons-yes"></span> Instant activation</span>';
839 $out .= '</td>';
840 $out .= '<td>';
841 if (1 || $promo_active) {
842 $out .= '<div class="gmw-promo-button gmw-promo-button-extra"><a href="https://gum.co/gmw-pro/welcomegmw?wanted=true&plugin_info=GMW+v' . GMW::$version . '" target="_blank" data-gumroad-single-product="true">only <strike>$49</strike> $39</a><span>discount: 20%</span></div>';
843 } elseif ($promo_active2) {
844 $out .= '<div class="gmw-promo-button gmw-promo-button-extra"><a href="https://gum.co/gmw-pro/olduser4?wanted=true&plugin_info=GMW+v' . GMW::$version . '" target="_blank" data-gumroad-single-product="true">only <strike>$49</strike> $39</a><span>discount: 25%</span></div>';
845 } else {
846 $out .= '<div class="gmw-promo-button"><a href="https://gum.co/gmw-pro?wanted=true&plugin_info=GMW+v' . GMW::$version . '" data-noprevent="1" data-gumroad-single-product="true" target="_blank">BUY $49</a></div>';
847 }
848 $out .= '<span class="instant-download"><span class="dashicons dashicons-yes"></span> 100% No-Risk Money Back Guarantee<br><span class="dashicons dashicons-yes"></span> Secure payment<br><span class="dashicons dashicons-yes"></span> Instant activation</span>';
849 $out .= '</td>';
850 $out .= '<td><div class="gmw-promo-button"><a href="https://gum.co/gmw-yearly?wanted=false&yearly=true&plugin_info=GMW+v' . GMW::$version . '" data-noprevent="1" target="_blank" data-gumroad-single-product="true">$29 <small>/year</small></a></div>';
851 $out .= '<span class="instant-download"><span class="dashicons dashicons-yes"></span> 100% No-Risk Money Back Guarantee<br><span class="dashicons dashicons-yes"></span> Secure payment<br><span class="dashicons dashicons-yes"></span> Instant activation</span>';
852 $out .= '</td>';
853 $out .= '</tr>';
854 $out .= '</table>';
855
856 $out .= '</div></div>'; // dialog intro
857
858 $out .= '<div id="gmw_dialog_activate" style="display: none;" class="gmw_promo_dialog_screen">';
859 $out .= '<div class="content">';
860
861 if (GMW::is_activated()) {
862 $visible = ' style="display: none;"';
863 } else {
864 $visible = '';
865 }
866 $out .= '<div class="before_activate" ' . $visible . '><p class="input_row">
867 <input type="text" id="gmw_code" name="gmw_code" placeholder="Please enter the license key">
868 <span style="display: none;" class="error gmw_code">Unable to verify license key. Unknown error.</span></p>
869 <p class="center">
870 <a href="#" class="button button-primary" id="gmw_activate">Activate PRO features</a>
871 </p>
872 <p class="center">If you don\'t have a license key - <a href="#" class="gmw_goto_intro">Get it now</a></p>
873 </div>';
874
875
876 if (!GMW::is_activated()) {
877 $visible = ' style="display: none;"';
878 } else {
879 $visible = '';
880 }
881
882 $out .= '<div class="after_activate" ' . $visible . '>';
883 $out .= '<p class="center">Thank you for purchasing Maps Widget for Google Maps <b class="gmw-pro-red">PRO</b>! Your license has been verified.</p>';
884 $out .= '<ol class="gmw-faq-ul">
885 <li><a href="https://gmapswidget.com/pro-download/" target="_blank">Download</a> the PRO version ZIP file</li>
886 <li>Go to <a href="' . admin_url('plugin-install.php') . '">Plugins - Add New</a> and install the PRO version</li>
887 <li>When prompted, overwrite the free version with the PRO one</li>
888 <li>Create some maps ;)</li>
889 </ol>';
890 $out .= '</div>';
891
892 $out .= '</div>'; // content
893 $out .= '<div class="footer">
894 <ul class="gmw-faq-ul">
895 <li>Having problems paying or you misplaced your key? <a href="mailto:gmw@webfactoryltd.com?subject=Activation%20key%20problem">Email us</a></li>
896 <li>Key not working or can\'t upgrade? Our <a href="mailto:gmw@webfactoryltd.com?subject=Activation%20key%20problem">support</a> is here to help</li>
897 </ul>
898 </div>';
899 $out .= '</div>'; // activate screen
900
901 $out .= '<div id="gmw_dialog_pro_features" style="display: none;" class="gmw_promo_dialog_screen">
902 <div class="content">';
903 $out .= '<h4>See how <span class="gmw-pro-red">PRO</span> features can make your life easier!</h4>';
904 $out .= '<div class="features-left">';
905 $out .= '<b>Multiple pins support</b><br>';
906 $out .= '<ul class="features-list">';
907 $out .= '<li>Multiple pins support with per-pin options for appearance &amp; click behaviour</li>
908 <li>14 thumbnail &amp; lightbox map skins + create your own fully custom skin</li>
909 <li>1500+ map pins</li>
910 <li>4 extra map image formats for even faster loading</li>
911 <li>replace thumb with interactive map feature</li>
912 <li>extra hidden sidebar for easier shortcode handling</li>';
913 $out .= '</ul><br><br><b>Complete control over map design</b><br>';
914 $out .= '<ul class="features-list">';
915 $out .= '<li>19 map skins + build your own skin option</li>
916 <li>custom map language option</li>
917 <li>4 map modes; directions, view, street & streetview</li>
918 <li>fully customizable pin options for thumbnail map</li>
919 <li>Advanced cache &amp; fastest loading times</li>
920 <li>JS &amp; CSS optimization options</li>';
921 $out .= '</ul>';
922 $out .= '</div>';
923 $out .= '<div class="features-right">';
924 $out .= '<b>Advanced options</b><br>';
925 $out .= '<ul class="features-list">';
926 $out .= '<li>Full control over all pins</li>
927 <li>Complete shortcode support</li>
928 <li>Clustering support</li>
929 <li>Pins grouping &amp; filtering support</li>
930 <li>3 additional map link types</li>
931 <li>Fullscreen lightbox mode</li>
932 <li>Extra lightbox features</li>
933 <li>Disable thumbnail map - immediately load interactive map</li>';
934 $out .= '</ul><br><br><b>Unrivaled support</b><br>';
935 $out .= '<ul class="features-list">
936 <li>Clone widget feature</li>
937 <li>export & import tools</li>
938 <li>Google Analytics integration</li>
939 <li>Premium email support</li>
940 <li>Continuous updates &amp; new features</li>';
941 $out .= '</ul>';
942 $out .= '</div>';
943 $out .= ' </div>';
944 $out .= '<div class="footer">';
945 $out .= '<p class="center"><a href="#" class="button-secondary gmw_goto_intro">Go PRO now</a><br>
946 Or <a href="#" class="gmw_goto_activation">enter the license key</a> if you already have it.</p>';
947 $out .= '</div>';
948 $out .= '</div>'; // pro features screen
949
950 $out .= '</div>'; // dialog
951 } // promo dialog
952
953 // address picker and pins dialog
954 if (GMW::is_plugin_admin_page('widgets')) {
955 $out .= '<div id="gmw_map_dialog" style="display: none;">';
956 $out .= '<div id="gmw_map_canvas"></div><hr>';
957 $out .= '<div id="gmw_map_dialog_footer">';
958
959 $out .= '<p>Address picker is a <b class="gmw-pro-red">PRO</b> feature that gives you the option to easily drag &amp; drop the pin to any location you need and fine-tune its position. <a class="open_promo_dialog" href="#">Upgrade to PRO</a> to have full control over your pins.</p><input type="hidden" autofocus="autofocus" />';
960 $out .= '</div>'; // footer
961 $out .= '</div>'; // dialog
962 } // address picker and pins dialog if activated
963
964 self::wp_kses_wf($out);
965 } // admin_dialogs_markup
966
967
968 // complete options screen markup
969 static function settings_screen() {
970 if (!current_user_can('manage_options')) {
971 wp_die('Cheating? You don\'t have the right to access this page.', 'Maps Widget for Google Maps', array('back_link' => true));
972 }
973
974 $options = GMW::get_options();
975
976 echo '<div class="wrap gmw-options">';
977 echo '<h1><img alt="' . __('Maps Widget for Google Maps', 'google-maps-widget') . '" title="' . __('Maps Widget for Google Maps', 'google-maps-widget') . '" height="55" src="' . esc_url(GMW_PLUGIN_URL) . 'images/gmw-logo.png"> Maps Widget for Google Maps</h1>';
978
979 echo '<form method="post" action="options.php">';
980 settings_fields(GMW::$options);
981
982 echo '<div id="gmw-settings-tabs"><ul>';
983 echo '<li><a href="#gmw-settings">' . __('Settings', 'google-maps-widget') . '</a></li>';
984 echo '<li><a href="#gmw-import-pins">' . __('Import pins', 'google-maps-widget') . '</a></li>';
985 echo '<li><a href="#gmw-export">' . __('Export &amp; Import', 'google-maps-widget') . '</a></li>';
986 echo '<li><a href="#gmw-license">' . __('PRO License', 'google-maps-widget') . '</a></li>';
987 echo '</ul>';
988
989 echo '<div id="gmw-import-pins" style="display: none;">';
990 if (!GMW::is_activated()) {
991 echo '<p>Pins import is one of many <span class="gmw-pro-red">PRO</span> features. <a href="#" class="open_promo_dialog button button-primary">Upgrade now</a> to get access to more than 50 extra options &amp; features.</p>';
992 }
993
994 echo '<table class="form-table disabled">';
995 echo '<tr>
996 <th scope="row"><label for="widget_id">' . __('Maps Widget for Google Maps', 'google-maps-widget') . '</label></th>
997 <td><select disabled="disabled" name="' . esc_attr(GMW::$options) . '[widget_id]" id="widget_id">';
998 echo '<option value="">- select the widget to import pins to -</option>';
999 echo '</select><br><span class="description">Choose a widget you want to import pins to. Any existing pins will be overwritten with the new pins. Other widget options will not be altered in any way.</span></td></tr>';
1000
1001 echo '<tr>
1002 <th scope="row"><label for="pins_txt">' . __('Pins, copy/paste', 'google-maps-widget') . '</label></th>';
1003 echo '<td><textarea disabled="disabled" style="width: 500px;" rows="3" name="' . esc_attr(GMW::$options) . '[pins_txt]" id="pins_txt">';
1004 echo '</textarea><br><span class="description">Data has to be formatted in a CSV fashion. One pin per line, individual fields double quoted and separated by a comma. All fields have to be included.<br>
1005 Please refer to the <a href="https://www.gmapswidget.com/documentation/importing-pins/" target="_blank">detailed documentation article</a> or grab the <a href="https://www.gmapswidget.com/wp-content/uploads/2018/02/sample-pins-import.csv" target="_blank">sample import file and modify it.</span></td></tr>';
1006
1007 echo '<tr>
1008 <th scope="row"><label for="pins_file">' . __('Pins, upload file', 'google-maps-widget') . '</label></th>';
1009 echo '<td><input type="file" disabled="disabled" name="pins_file" id="pins_file">';
1010 echo '<br><span class="description">See rules noted for the field above.</span></td></tr>';
1011
1012 echo '<tr>
1013 <th scope="row" colspan="2"><input disabled="disabled" type="submit" name="submit-import-pins" id="submit-import-pins" class="button button-primary button-large" value="Import pins"><br><i style="font-weight: normal;">No data will be written to the widget until you confirm it in step #2.</i></th>';
1014 echo '</tr>';
1015 echo '</table>';
1016
1017 echo '</div>'; // import pins
1018
1019 echo '<div id="gmw-settings" style="display: none;">';
1020 echo '<table class="form-table">';
1021 echo '<tr>
1022 <th scope="row"><label for="api_key">' . __('Google Maps API Key', 'google-maps-widget') . '</label></th>
1023 <td><input name="' . esc_attr(GMW::$options) . '[api_key]" type="text" id="api_key" value="' . esc_attr($options['api_key']) . '" class="regular-text" placeholder="Google Maps API key" oninput="setCustomValidity(\'\')" oninvalid="this.setCustomValidity(\'Please use Google Developers Console to generate an API key and enter it here. It is completely free.\')">
1024 <p class="description">New Google Maps usage policy dictates that everyone using the maps should register for a free API key.<br>
1025 Detailed instruction on how to generate a key in under a minute are available in the <a href="http://www.gmapswidget.com/documentation/generate-google-maps-api-key/" target="_blank">documentation</a>.<br>If you already have a key make sure the following APIs are enabled: Google Maps JavaScript API, Google Static Maps API, Google Maps Embed API &amp; Google Maps Geocoding API.</p></td>
1026
1027 </tr>';
1028 echo '</table>';
1029 self::wp_kses_wf(get_submit_button(__('Save Settings', 'google-maps-widget')));
1030
1031 if (!GMW::is_activated()) {
1032 echo '<p>Not sure if you should upgrade to <span class="gmw-pro-red">PRO</span>? It offers more than 50 extra features like shortcodes, Google Analytics tracking, multiple pins support &amp; much more; <a href="#" class="open_promo_dialog button" data-target-screen="gmw_dialog_pro_features">compare features now</a>.</p>';
1033 }
1034
1035 echo '<h3 class="title disabled"><br>Advanced Settings - available in the PRO version</h3>';
1036 echo '<table class="form-table disabled">';
1037 echo '<tr>
1038 <th scope="row"><label for="sc_map">' . __('Map Shortcode', 'google-maps-widget') . '</label></th>
1039 <td><input class="regular-text" name="' . esc_attr(GMW::$options) . '[sc_map]" type="text" id="sc_map" value="' . esc_attr($options['sc_map']) . '" disabled="disabled" placeholder="Map shortcode" required="required" oninvalid="this.setCustomValidity(\'Please enter the shortcode you want to use for Maps Widget for Google Maps maps.\')" oninput="setCustomValidity(\'\')">
1040 <p class="description">If the default shortcode "gmw" is taken by another plugin change it to something else, eg: "gmaps".</p></td>
1041 </tr>';
1042 echo '<tr>
1043 <th scope="row"><label for="track_ga">' . __('Track with Google Analytics', 'google-maps-widget') . '</label></th>
1044 <td><input name="' . esc_attr(GMW::$options) . '[track_ga]" disabled="disabled" type="checkbox" id="track_ga" value="1"' . checked('1', $options['track_ga'], false) . '>
1045 <span class="description">Each time the interactive map is opened either in lightbox or as a thumbnail replacement a Google Analytics Event will be tracked.<br>You need to have GA already configured on the site. It is fully compatible with all GA plugins and all GA tracking code versions. Default: unchecked.</span></td></tr>';
1046 echo '<tr>
1047 <th scope="row"><label for="include_jquery">' . __('Include jQuery', 'google-maps-widget') . '</label></th>
1048 <td><input name="' . esc_attr(GMW::$options) . '[include_jquery]" disabled="disabled" type="checkbox" id="include_jquery" value="1"' . checked('1', $options['include_jquery'], false) . '>
1049 <span class="description">If you\'re experiencing problems with double jQuery include disable this option. Default: checked.</span></td></tr>';
1050 echo '<tr>
1051 <th scope="row"><label for="include_gmaps_api">' . __('Include Google Maps API JS', 'google-maps-widget') . '</label></th>
1052 <td><input disabled="disabled" name="' . esc_attr(GMW::$options) . '[include_gmaps_api]" type="checkbox" id="include_gmaps_api" value="1"' . checked('1', $options['include_gmaps_api'], false) . '>
1053 <span class="description">If your theme or other plugins already include Google Maps API JS disable this option. Default: checked.</span></td></tr>';
1054 echo '<tr>
1055 <th scope="row"><label for="include_lightbox_css">' . __('Include Colorbox &amp; Thumbnail CSS', 'google-maps-widget') . '</label></th>
1056 <td><input name="' . esc_attr(GMW::$options) . '[include_lightbox_css]" disabled="disabled" type="checkbox" id="include_lightbox_css" value="1"' . checked('1', $options['include_lightbox_css'], false) . '>
1057 <span class="description">If your theme or other plugins already include Colorbox CSS disable this option.<br>Please note that widget (thumbnail map) related CSS will also be removed which will cause minor differences in the way it\'s displayed. Default: checked.</span></td></tr>';
1058 echo '<tr>
1059 <th scope="row"><label for="include_lightbox_js">' . __('Include Colorbox JS', 'google-maps-widget') . '</label></th>
1060 <td><input name="' . esc_attr(GMW::$options) . '[include_lightbox_js]" disabled="disabled" type="checkbox" id="include_lightbox_js" value="1"' . checked('1', $options['include_lightbox_js'], false) . '>
1061 <span class="description">If your theme or other plugins already include Colorbox JS file disable this option. Default: checked.</span></td></tr>';
1062 echo '<tr>
1063 <th scope="row"><label for="disable_tooltips">' . __('Disable Admin Tooltips', 'google-maps-widget') . '</label></th>
1064 <td><input name="' . esc_attr(GMW::$options) . '[disable_tooltips]" type="checkbox" disabled="disabled" id="disable_tooltips" value="1"' . checked('1', $options['disable_tooltips'], false) . '>
1065 <span class="description">All settings in widget edit GUI have tooltips. This setting completely disables them. Default: unchecked.</span></td></tr>';
1066 echo '<tr>
1067 <th scope="row"><label for="disable_sidebar">' . __('Disable Hidden Sidebar', 'google-maps-widget') . '</label></th>
1068 <td><input name="' . esc_attr(GMW::$options) . '[disable_sidebar]" disabled="disabled" type="checkbox" id="disable_sidebar" value="1"' . checked('1', $options['disable_sidebar'], false) . '>
1069 <span class="description">Hidden sidebar helps you to build maps that are displayed with shortcodes. If it bothers you in the admin, disable it. Default: unchecked.</span></td></tr>';
1070 echo '</table>';
1071
1072 echo '</div>'; // settings tab
1073
1074 echo '<div id="gmw-export" style="display: none;">';
1075 if (!GMW::is_activated()) {
1076 echo '<p>Export &amp; Import are one of many <span class="gmw-pro-red">PRO</span> features. <a href="#" class="open_promo_dialog button button-primary">Upgrade now</a> to get access to more than 50 extra options &amp; features.</p>';
1077 }
1078 echo '<table class="form-table disabled">';
1079 echo '<tr>
1080 <th scope="row"><span>' . __('Export widgets', 'google-maps-widget') . '</span></th>
1081 <td><a href="#" class="button button-secondary button-disabled">Download export file</a>
1082 <p class="description">The export file will only contain Maps Widget for Maps Widget for Google Maps. This includes active (in sidebars) widgets and inactive ones as well.</p></td>
1083 </tr>';
1084 echo '<tr>
1085 <th scope="row"><span>' . __('Import widgets', 'google-maps-widget') . '</span></th>
1086 <td><input type="file" disabled="disabled" name="gmw_widgets_import" id="gmw_widgets_import" accept=".txt">
1087 <input type="button" disabled="disabled" name="submit-import" id="submit-import" class="button button-secondary button-large" value="Import widgets">';
1088 echo '<p class="description">Only use TXT export files generated by Maps Widget for Google Maps.<br>
1089 Existing GMW widgets will not be overwritten nor any other widgets touched. If you renamed a sidebar or old one no longer exists widgets will be placed in the inactive widgets area.</p></td>
1090 </tr>';
1091 echo '</table>';
1092 echo '</div>'; // export/import tab
1093
1094 echo '<div id="gmw-license" style="display: none;">';
1095 if (GMW::is_activated()) {
1096 echo '<p>Your <b class="gmw-pro-red">PRO</b> license is validated.';
1097 echo '<ol class="normal">
1098 <li><a href="https://gmapswidget.com/pro-download/" target="_blank">Download</a> the PRO version ZIP file</li>
1099 <li>Go to <a href="' . admin_url('plugin-install.php') . '">Plugins - Add New</a> and install the PRO version</li>
1100 <li>When prompted, overwrite the free version with the PRO one</li>
1101 <li>Create some maps ;)</li>
1102 </ol>';
1103 } else {
1104 echo '<p>If you already bought the <b class="gmw-pro-red">PRO</b> license please <a href="#" data-target-screen="gmw_dialog_activate" class="open_promo_dialog">enter your license key</a> to activate it.</p>';
1105 echo '<p>Interested in a lifetime <b class="gmw-pro-red">PRO</b> license that offers more than 50 extra fetures?&nbsp;&nbsp; <a href="#" class="open_promo_dialog button button-primary">Upgrade now!</a></p>';
1106 }
1107
1108 echo '</div>'; // license tab
1109
1110 echo '</form>';
1111 echo '</div>'; // wrap
1112 } // settings_screen
1113
1114
1115 // check activation code and save if valid
1116 static function activate_license_key_ajax() {
1117 check_ajax_referer('gmw_activate_license_key');
1118
1119 $code = substr(sanitize_key(@$_POST['code']), 0, 64);
1120 $code = str_replace(' ', '', $code);
1121
1122 if (strlen($code) < 6 || strlen($code) > 50) {
1123 wp_send_json_error(__('Please double-check the license key. The format is not valid.', 'google-maps-widget'));
1124 }
1125
1126 $tmp = GMW::validate_activation_code($code);
1127 if ($tmp['success']) {
1128 GMW::set_options(array('activation_code' => $code, 'license_active' => $tmp['license_active'], 'license_type' => $tmp['license_type'], 'license_expires' => $tmp['license_expires']));
1129 }
1130 if ($tmp['license_active'] && $tmp['success']) {
1131 wp_send_json_success();
1132 } else {
1133 wp_send_json_error($tmp['error']);
1134 }
1135 } // activate_license_key_ajax
1136
1137
1138 // helper function for creating dropdowns
1139 static function create_select_options($options, $selected = null, $output = true) {
1140 $out = "\n";
1141
1142 if(!is_array($selected)) {
1143 $selected = array($selected);
1144 }
1145
1146 foreach ($options as $tmp) {
1147 $data = '';
1148 if (isset($tmp['disabled'])) {
1149 $data .= ' disabled="disabled" ';
1150 }
1151 if ($tmp['val'] == '-1') {
1152 $data .= ' class="gmw_promo" ';
1153 }
1154 if (in_array($tmp['val'], $selected)) {
1155 $out .= "<option selected=\"selected\" value=\"{$tmp['val']}\"{$data}>{$tmp['label']}&nbsp;</option>\n";
1156 } else {
1157 $out .= "<option value=\"{$tmp['val']}\"{$data}>{$tmp['label']}&nbsp;</option>\n";
1158 }
1159 } // foreach
1160
1161 if ($output) {
1162 self::wp_kses_wf($out);
1163 } else {
1164 return $out;
1165 }
1166 } // create_select_options
1167
1168 static function wp_kses_wf($html)
1169 {
1170 add_filter('safe_style_css', function ($styles) {
1171 $styles_wf = array(
1172 'text-align',
1173 'margin',
1174 'color',
1175 'float',
1176 'border',
1177 'background',
1178 'background-color',
1179 'border-bottom',
1180 'border-bottom-color',
1181 'border-bottom-style',
1182 'border-bottom-width',
1183 'border-collapse',
1184 'border-color',
1185 'border-left',
1186 'border-left-color',
1187 'border-left-style',
1188 'border-left-width',
1189 'border-right',
1190 'border-right-color',
1191 'border-right-style',
1192 'border-right-width',
1193 'border-spacing',
1194 'border-style',
1195 'border-top',
1196 'border-top-color',
1197 'border-top-style',
1198 'border-top-width',
1199 'border-width',
1200 'caption-side',
1201 'clear',
1202 'cursor',
1203 'direction',
1204 'font',
1205 'font-family',
1206 'font-size',
1207 'font-style',
1208 'font-variant',
1209 'font-weight',
1210 'height',
1211 'letter-spacing',
1212 'line-height',
1213 'margin-bottom',
1214 'margin-left',
1215 'margin-right',
1216 'margin-top',
1217 'overflow',
1218 'padding',
1219 'padding-bottom',
1220 'padding-left',
1221 'padding-right',
1222 'padding-top',
1223 'text-decoration',
1224 'text-indent',
1225 'vertical-align',
1226 'width',
1227 'display',
1228 );
1229
1230 foreach ($styles_wf as $style_wf) {
1231 $styles[] = $style_wf;
1232 }
1233 return $styles;
1234 });
1235
1236 $allowed_tags = wp_kses_allowed_html('post');
1237 $allowed_tags['input'] = array(
1238 'type' => true,
1239 'style' => true,
1240 'class' => true,
1241 'id' => true,
1242 'checked' => true,
1243 'disabled' => true,
1244 'name' => true,
1245 'size' => true,
1246 'placeholder' => true,
1247 'value' => true,
1248 'data-*' => true,
1249 'size' => true,
1250 'disabled' => true
1251 );
1252
1253 $allowed_tags['textarea'] = array(
1254 'type' => true,
1255 'style' => true,
1256 'class' => true,
1257 'id' => true,
1258 'checked' => true,
1259 'disabled' => true,
1260 'name' => true,
1261 'size' => true,
1262 'placeholder' => true,
1263 'value' => true,
1264 'data-*' => true,
1265 'cols' => true,
1266 'rows' => true,
1267 'disabled' => true,
1268 'autocomplete' => true
1269 );
1270
1271 $allowed_tags['select'] = array(
1272 'type' => true,
1273 'style' => true,
1274 'class' => true,
1275 'id' => true,
1276 'checked' => true,
1277 'disabled' => true,
1278 'name' => true,
1279 'size' => true,
1280 'placeholder' => true,
1281 'value' => true,
1282 'data-*' => true,
1283 'multiple' => true,
1284 'disabled' => true
1285 );
1286
1287 $allowed_tags['option'] = array(
1288 'type' => true,
1289 'style' => true,
1290 'class' => true,
1291 'id' => true,
1292 'checked' => true,
1293 'disabled' => true,
1294 'name' => true,
1295 'size' => true,
1296 'placeholder' => true,
1297 'value' => true,
1298 'selected' => true,
1299 'data-*' => true
1300 );
1301 $allowed_tags['optgroup'] = array(
1302 'type' => true,
1303 'style' => true,
1304 'class' => true,
1305 'id' => true,
1306 'checked' => true,
1307 'disabled' => true,
1308 'name' => true,
1309 'size' => true,
1310 'placeholder' => true,
1311 'value' => true,
1312 'selected' => true,
1313 'data-*' => true,
1314 'label' => true
1315 );
1316
1317 $allowed_tags['a'] = array(
1318 'href' => true,
1319 'data-*' => true,
1320 'class' => true,
1321 'style' => true,
1322 'id' => true,
1323 'target' => true,
1324 'data-*' => true,
1325 'role' => true,
1326 'aria-controls' => true,
1327 'aria-selected' => true,
1328 'disabled' => true
1329 );
1330
1331 $allowed_tags['div'] = array(
1332 'style' => true,
1333 'class' => true,
1334 'id' => true,
1335 'data-*' => true,
1336 'role' => true,
1337 'aria-labelledby' => true,
1338 'value' => true,
1339 'aria-modal' => true,
1340 'tabindex' => true
1341 );
1342
1343 $allowed_tags['li'] = array(
1344 'style' => true,
1345 'class' => true,
1346 'id' => true,
1347 'data-*' => true,
1348 'role' => true,
1349 'aria-labelledby' => true,
1350 'value' => true,
1351 'aria-modal' => true,
1352 'tabindex' => true
1353 );
1354
1355 $allowed_tags['span'] = array(
1356 'style' => true,
1357 'class' => true,
1358 'id' => true,
1359 'data-*' => true,
1360 'aria-hidden' => true
1361 );
1362
1363 $allowed_tags['style'] = array(
1364 'class' => true,
1365 'id' => true,
1366 'type' => true
1367 );
1368
1369 $allowed_tags['fieldset'] = array(
1370 'class' => true,
1371 'id' => true,
1372 'type' => true
1373 );
1374
1375 $allowed_tags['link'] = array(
1376 'class' => true,
1377 'id' => true,
1378 'type' => true,
1379 'rel' => true,
1380 'href' => true,
1381 'media' => true
1382 );
1383
1384 $allowed_tags['form'] = array(
1385 'style' => true,
1386 'class' => true,
1387 'id' => true,
1388 'method' => true,
1389 'action' => true,
1390 'data-*' => true
1391 );
1392
1393 $allowed_tags['script'] = array(
1394 'class' => true,
1395 'id' => true,
1396 'type' => true,
1397 'src' => true
1398 );
1399
1400 echo wp_kses($html, $allowed_tags);
1401
1402 add_filter('safe_style_css', function ($styles) {
1403 $styles_wf = array(
1404 'text-align',
1405 'margin',
1406 'color',
1407 'float',
1408 'border',
1409 'background',
1410 'background-color',
1411 'border-bottom',
1412 'border-bottom-color',
1413 'border-bottom-style',
1414 'border-bottom-width',
1415 'border-collapse',
1416 'border-color',
1417 'border-left',
1418 'border-left-color',
1419 'border-left-style',
1420 'border-left-width',
1421 'border-right',
1422 'border-right-color',
1423 'border-right-style',
1424 'border-right-width',
1425 'border-spacing',
1426 'border-style',
1427 'border-top',
1428 'border-top-color',
1429 'border-top-style',
1430 'border-top-width',
1431 'border-width',
1432 'caption-side',
1433 'clear',
1434 'cursor',
1435 'direction',
1436 'font',
1437 'font-family',
1438 'font-size',
1439 'font-style',
1440 'font-variant',
1441 'font-weight',
1442 'height',
1443 'letter-spacing',
1444 'line-height',
1445 'margin-bottom',
1446 'margin-left',
1447 'margin-right',
1448 'margin-top',
1449 'overflow',
1450 'padding',
1451 'padding-bottom',
1452 'padding-left',
1453 'padding-right',
1454 'padding-top',
1455 'text-decoration',
1456 'text-indent',
1457 'vertical-align',
1458 'width'
1459 );
1460
1461 foreach ($styles_wf as $style_wf) {
1462 if (($key = array_search($style_wf, $styles)) !== false) {
1463 unset($styles[$key]);
1464 }
1465 }
1466 return $styles;
1467 });
1468 }
1469
1470
1471 // sanitizes color code string, leaves # intact
1472 static function sanitize_hex_color( $color ) {
1473 if (empty($color)) {
1474 return '#ff0000';
1475 }
1476
1477 // 3 or 6 hex digits
1478 if (preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color)) {
1479 return $color;
1480 }
1481 } // sanitize_hex_color
1482
1483
1484 // converts color from human readable to hex
1485 static function convert_color($color) {
1486 $color_codes = array('black' => '#000000', 'white' => '#ffffff',
1487 'brown' => '#a52a2a', 'green' => '#00ff00',
1488 'purple' => '#800080', 'yellow' => '#ffff00',
1489 'blue' => '#0000ff', 'gray' => '#808080',
1490 'orange' => '#ffa500', 'red' => '#ff0000');
1491
1492 $color = strtolower(trim($color));
1493
1494 if (empty($color) || !isset($color_codes[$color])) {
1495 return '#ff0000';
1496 } else {
1497 return $color_codes[$color];
1498 }
1499 } // convert_color
1500
1501
1502 // helper function for checkbox handling
1503 static function check_var_isset($values, $variables) {
1504 foreach ($variables as $key => $value) {
1505 if (!isset($values[$key])) {
1506 $values[$key] = $value;
1507 }
1508 }
1509
1510 return $values;
1511 } // check_var_isset
1512
1513
1514 // activate doesn't get fired on upgrades so we have to compensate
1515 public static function maybe_upgrade() {
1516 $options = GMW::get_options();
1517
1518 if (!isset($options['first_version']) || !isset($options['first_install'])) {
1519 $options['first_version'] = GMW::$version;
1520 $options['first_install_gmt'] = time();
1521 $options['first_install'] = current_time('timestamp');
1522 GMW::set_options($options);
1523 }
1524 } // maybe_upgrade
1525
1526
1527 // write down a few things on plugin activation
1528 // NO DATA for tracking is sent anywhere unless user explicitly agrees to it!
1529 static function activate() {
1530 $options = GMW::get_options();
1531
1532 if (!isset($options['first_version']) || !isset($options['first_install'])) {
1533 $options['first_version'] = GMW::$version;
1534 $options['first_install'] = current_time('timestamp');
1535 GMW::set_options($options);
1536 }
1537
1538 if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) {
1539 wp_clear_scheduled_hook('gmw_biweekly_cron');
1540 }
1541
1542 self::reset_pointers();
1543 } // activate
1544
1545
1546 // counts the number of active GMW widgets in all sidebars
1547 static function count_active_widgets() {
1548 $count = 0;
1549
1550 $sidebars = get_option('sidebars_widgets', array());
1551 foreach ($sidebars as $sidebar_name => $widgets) {
1552 if (strpos($sidebar_name, 'inactive') !== false || strpos($sidebar_name, 'orphaned') !== false) {
1553 continue;
1554 }
1555 if (is_array($widgets)) {
1556 foreach ($widgets as $widget_name) {
1557 if (strpos($widget_name, 'googlemapswidget') !== false) {
1558 $count++;
1559 }
1560 }
1561 }
1562 } // foreach sidebar
1563
1564 return $count;
1565 } // count_active_widgets
1566
1567
1568 // clean up on deactivation
1569 static function deactivate() {
1570 $options = GMW::get_options();
1571
1572 if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) {
1573 wp_clear_scheduled_hook('gmw_biweekly_cron');
1574 }
1575
1576 delete_transient('gmw_pointers');
1577 } // deactivate
1578
1579
1580 // clean up on uninstall / delete
1581 static function uninstall() {
1582 // at the moment, due to lite/pro upgrade we never delete options
1583 $options = GMW::get_options();
1584
1585 if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) {
1586 wp_clear_scheduled_hook('gmw_biweekly_cron');
1587 }
1588
1589 delete_transient('gmw_pointers');
1590 } // uninstall
1591 } // class GMW
1592
1593 } // if GMW class exists
1594
1595
1596 // hook everything up
1597 register_activation_hook(__FILE__, array('GMW', 'activate'));
1598 register_deactivation_hook(__FILE__, array('GMW', 'deactivate'));
1599 register_uninstall_hook(__FILE__, array('GMW', 'uninstall'));
1600 add_action('init', array('GMW', 'init'));
1601 add_action('plugins_loaded', array('GMW', 'plugins_loaded'));
1602 add_action('widgets_init', array('GMW', 'widgets_init'));
1603