| @@ -1,16 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: Google Maps Widget |
| 4 | 4 | Plugin URI: http://www.googlemapswidget.com/ |
| 5 | -Description: Display a single-image super-fast loading Google map in a widget. A larger, full featured map is available on click in a lightbox. | |
| 5 | +Description: Display a single-image super-fast loading Google map in a widget. A larger, full featured map is available on click in a lightbox. Includes shortcode support and numerous options. | |
| 6 | 6 | Author: Web factory Ltd |
| 7 | -Version: 1.93 | |
| 7 | +Version: 2.50 | |
| 8 | 8 | Author URI: http://www.webfactoryltd.com/ |
| 9 | 9 | Text Domain: google-maps-widget |
| 10 | 10 | Domain Path: lang |
| 11 | 11 | |
| 12 | - Copyright 2012 - 2014 Web factory Ltd (email : gmw@webfactoryltd.com) | |
| 12 | + Copyright 2012 - 2015 Web factory Ltd (email : gmw@webfactoryltd.com) | |
| 13 | 13 | |
| 14 | 14 | This program is free software; you can redistribute it and/or modify |
| 15 | 15 | it under the terms of the GNU General Public License, version 2, as |
| 16 | 16 | published by the Free Software Foundation. |
| @@ -30,9 +30,8 @@ | ||
| 30 | 30 | die(); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
| 34 | -define('GMW_VER', '1.93'); | |
| 35 | 34 | define('GMW_OPTIONS', 'gmw_options'); |
| 36 | 35 | define('GMW_CRON', 'gmw_cron'); |
| 37 | 36 | |
| 38 | 37 | |
| @@ -40,8 +39,10 @@ | ||
| 40 | 39 | require_once 'gmw-tracking.php'; |
| 41 | 40 | |
| 42 | 41 | |
| 43 | 42 | class GMW { |
| 43 | + static $version = 2.50; | |
| 44 | + | |
| 44 | 45 | // hook everything up |
| 45 | 46 | static function init() { |
| 46 | 47 | GMW_tracking::init(); |
| 47 | 48 | |
| @@ -48,8 +49,9 @@ | ||
| 48 | 49 | if (is_admin()) { |
| 49 | 50 | // check if minimal required WP version is used |
| 50 | 51 | self::check_wp_version(3.3); |
| 51 | 52 | |
| 53 | + // check some variables | |
| 52 | 54 | self::upgrade(); |
| 53 | 55 | |
| 54 | 56 | // aditional links in plugin description |
| 55 | 57 | add_filter('plugin_action_links_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__), |
| @@ -58,13 +60,29 @@ | ||
| 58 | 60 | |
| 59 | 61 | // enqueue admin scripts |
| 60 | 62 | add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts')); |
| 61 | 63 | add_action('customize_controls_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts')); |
| 64 | + | |
| 65 | + // JS dialog markup | |
| 66 | + add_action('admin_footer', array(__CLASS__, 'admin_dialogs_markup')); | |
| 67 | + | |
| 68 | + // register AJAX endpoints | |
| 69 | + add_action('wp_ajax_gmw_subscribe', array(__CLASS__, 'email_subscribe')); | |
| 70 | + add_action('wp_ajax_gmw_activate', array(__CLASS__, 'activate_via_code')); | |
| 71 | + | |
| 72 | + // handle dismiss button for all notices | |
| 73 | + add_action('admin_action_gmw_dismiss_notice', array(__CLASS__, 'dismiss_notice')); | |
| 74 | + | |
| 75 | + // display various notices | |
| 76 | + self::add_notices(); | |
| 62 | 77 | } else { |
| 63 | 78 | // enqueue frontend scripts |
| 64 | 79 | add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); |
| 65 | 80 | add_action('wp_footer', array(__CLASS__, 'dialogs_markup')); |
| 66 | 81 | } |
| 82 | + | |
| 83 | + // add shortcode support | |
| 84 | + self::add_shortcode(); | |
| 67 | 85 | } // init |
| 68 | 86 | |
| 69 | 87 | |
| 70 | 88 | // some things have to be loaded earlier |
| @@ -93,9 +111,10 @@ | ||
| 93 | 111 | static function plugin_meta_links($links, $file) { |
| 94 | 112 | $documentation_link = '<a target="_blank" href="http://www.googlemapswidget.com/documentation/" title="' . __('View Google Maps Widget documentation', 'google-maps-widget') . '">'. __('Documentation', 'google-maps-widget') . '</a>'; |
| 95 | 113 | $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>'; |
| 96 | 114 | $review_link = '<a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/google-maps-widget" title="' . __('If you like it, please review the plugin', 'google-maps-widget') . '">' . __('Review the plugin', 'google-maps-widget') . '</a>'; |
| 97 | - $donate_link = '<a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=gordan%40webfactoryltd%2ecom&lc=US&item_name=Google%20Maps%20Widget&no_note=0¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest" title="' . __('If you feel we deserve it, buy us coffee', 'google-maps-widget') . '">' . __('Donate', 'google-maps-widget') . '</a>'; | |
| 115 | + $donate_link = '<a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?business=gordan@webfactoryltd.com&cmd=_xclick¤cy_code=USD&amount=&item_name=Google%20Maps%20Widget%20Donation" title="' . __('If you feel we deserve it, buy us coffee', 'google-maps-widget') . '">' . __('Donate', 'google-maps-widget') . '</a>'; | |
| 116 | + $activate_link = '<a href="' . esc_url(admin_url('widgets.php?gmw_open_promo_dialog')) . '">' . __('Activate premium features for <b>FREE</b>', 'google-maps-widget') . '</a>'; | |
| 98 | 117 | |
| 99 | 118 | if ($file == plugin_basename(__FILE__)) { |
| 100 | 119 | $links[] = $documentation_link; |
| 101 | 120 | $links[] = $support_link; |
| @@ -100,8 +119,11 @@ | ||
| 100 | 119 | $links[] = $documentation_link; |
| 101 | 120 | $links[] = $support_link; |
| 102 | 121 | $links[] = $review_link; |
| 103 | 122 | $links[] = $donate_link; |
| 123 | + if (!self::is_activated()) { | |
| 124 | + $links[] = $activate_link; | |
| 125 | + } | |
| 104 | 126 | } |
| 105 | 127 | |
| 106 | 128 | return $links; |
| 107 | 129 | } // plugin_meta_links |
| @@ -109,17 +131,17 @@ | ||
| 109 | 131 | |
| 110 | 132 | // check if user has the minimal WP version required by the plugin |
| 111 | 133 | static function check_wp_version($min_version) { |
| 112 | 134 | if (!version_compare(get_bloginfo('version'), $min_version, '>=')) { |
| 113 | - add_action('admin_notices', array(__CLASS__, 'min_version_error')); | |
| 135 | + add_action('admin_notices', array(__CLASS__, 'notice_min_version_error')); | |
| 114 | 136 | } |
| 115 | 137 | } // check_wp_version |
| 116 | 138 | |
| 117 | 139 | |
| 118 | 140 | // display error message if WP version is too low |
| 119 | - static function min_version_error() { | |
| 120 | - echo '<div class="error"><p>' . sprintf('Google Maps Widget <b>requires WordPress version 3.3</b> or higher to function properly. You are using WordPress version %s. Please <a href="%s">update it</a>.', get_bloginfo('version'), admin_url('update-core.php')) . '</p></div>'; | |
| 121 | - } // min_version_error | |
| 141 | + static function notice_min_version_error() { | |
| 142 | + echo '<div class="error"><p>' . sprintf(__('Google Maps Widget <b>requires WordPress version 3.3</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>'; | |
| 143 | + } // notice_min_version_error | |
| 122 | 144 | |
| 123 | 145 | |
| 124 | 146 | // print dialogs markup in footer |
| 125 | 147 | static function dialogs_markup() { |
| @@ -162,17 +184,113 @@ | ||
| 162 | 184 | $out .= "</div>\n"; |
| 163 | 185 | } // foreach $widgets |
| 164 | 186 | |
| 165 | 187 | echo $out; |
| 166 | - } // run_scroller | |
| 188 | + } // dialogs_markup | |
| 167 | 189 | |
| 168 | 190 | |
| 191 | + // check availability and register shortcode | |
| 192 | + static function add_shortcode() { | |
| 193 | + global $shortcode_tags; | |
| 194 | + | |
| 195 | + if (isset($shortcode_tags['gmw'])) { | |
| 196 | + add_action('admin_notices', array(__CLASS__, 'notice_sc_conflict_error')); | |
| 197 | + } else { | |
| 198 | + add_shortcode('gmw', array(__CLASS__, 'do_shortcode')); | |
| 199 | + } | |
| 200 | + } // add_shortcode | |
| 201 | + | |
| 202 | + | |
| 203 | + // display notice if shortcode name is already taken | |
| 204 | + static function notice_sc_conflict_error() { | |
| 205 | + if (!self::is_activated()) { | |
| 206 | + return; | |
| 207 | + } | |
| 208 | + | |
| 209 | + echo '<div class="error"><p><strong>' . __('Google Maps Widget shortcode is not active!', 'google-maps-widget') . '</strong>' . __(' Shortcode <i>[gmw]</i> is already in use by another plugin or theme. Please deactivate that theme or plugin.', 'google-maps-widget') . '</p></div>'; | |
| 210 | + } // notice_sc_conflict_error | |
| 211 | + | |
| 212 | + | |
| 213 | + // handle dismiss button for all notices | |
| 214 | + // todo - convert all notices | |
| 215 | + static function dismiss_notice() { | |
| 216 | + $options = get_option(GMW_OPTIONS, array()); | |
| 217 | + | |
| 218 | + if (isset($_GET['notice']) && $_GET['notice'] == 'upgrade') { | |
| 219 | + $options['dismiss_notice_upgrade'] = true; | |
| 220 | + update_option(GMW_OPTIONS, $options); | |
| 221 | + } | |
| 222 | + if (isset($_GET['notice']) && $_GET['notice'] == 'rate') { | |
| 223 | + $options['dismiss_notice_rate'] = true; | |
| 224 | + update_option(GMW_OPTIONS, $options); | |
| 225 | + } | |
| 226 | + | |
| 227 | + if ($_GET['redirect']) { | |
| 228 | + wp_redirect($_GET['redirect']); | |
| 229 | + } else { | |
| 230 | + wp_redirect(admin_url()); | |
| 231 | + } | |
| 232 | + exit; | |
| 233 | + } // dismiss_notice | |
| 234 | + | |
| 235 | + | |
| 236 | + // maybe show some notices | |
| 237 | + static function add_notices() { | |
| 238 | + $options = get_option(GMW_OPTIONS, array()); | |
| 239 | + $notice = false; | |
| 240 | + | |
| 241 | + if ((!isset($options['dismiss_notice_upgrade']) || $options['dismiss_notice_upgrade'] == false) && | |
| 242 | + !self::is_activated() && | |
| 243 | + (GMW_tracking::count_active_widgets() > 0 || (current_time('timestamp') - $options['first_install']) > (DAY_IN_SECONDS * 3))) { | |
| 244 | + add_action('admin_notices', array(__CLASS__, 'notice_activate_extra_features')); | |
| 245 | + $notice = true; | |
| 246 | + } // show upgrade notice | |
| 247 | + | |
| 248 | + if (!$notice && | |
| 249 | + (!isset($options['dismiss_notice_rate']) || $options['dismiss_notice_rate'] == false) && | |
| 250 | + GMW_tracking::count_active_widgets() > 0 && | |
| 251 | + (current_time('timestamp') - $options['first_install']) > (DAY_IN_SECONDS * 20)) { | |
| 252 | + add_action('admin_notices', array(__CLASS__, 'notice_rate_plugin')); | |
| 253 | + } // show rate notice | |
| 254 | + } // add_notices | |
| 255 | + | |
| 256 | + | |
| 257 | + // display message to get extra features for GMW | |
| 258 | + static function notice_activate_extra_features() { | |
| 259 | + $activate_url = admin_url('widgets.php?gmw_open_promo_dialog'); | |
| 260 | + $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'upgrade', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); | |
| 261 | + | |
| 262 | + // todo detect WP version and add support for "is-dismissible" | |
| 263 | + // todo remove style from HTML | |
| 264 | + echo '<div id="gmw_activate_notice" class="updated notice"><p>' . __('<b>Google Maps Widget</b> has extra premium features you can get for <b style="color: #d54e21;">FREE</b>. This is a limited time offer so act now!', 'google-maps-widget'); | |
| 265 | + | |
| 266 | + echo '<br /><a href="' . esc_url($activate_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary">' . __('Activate premium features for <b>FREE</b>', 'google-maps-widget') . '</a>'; | |
| 267 | + echo ' <a href="' . esc_url($dismiss_url) . '" class="">' . __('Dismiss notice', 'google-maps-widget') . '</a>'; | |
| 268 | + echo '</p></div>'; | |
| 269 | + } // notice_activate_extra_features | |
| 270 | + | |
| 271 | + | |
| 272 | + // display message to get extra features for GMW | |
| 273 | + static function notice_rate_plugin() { | |
| 274 | + $rate_url = 'https://wordpress.org/support/view/plugin-reviews/google-maps-widget?rate=5#postform'; | |
| 275 | + $dismiss_url = add_query_arg(array('action' => 'gmw_dismiss_notice', 'notice' => 'rate', 'redirect' => urlencode($_SERVER['REQUEST_URI'])), admin_url('admin.php')); | |
| 276 | + | |
| 277 | + // todo detect WP version and add support for "is-dismissible" | |
| 278 | + // todo remove style from HTML | |
| 279 | + echo '<div id="gmw_rate_notice" class="updated notice"><p>' . __('Hi! We saw you\'ve been using <b>Google Maps Widget</b> for some time and wanted to ask for your help to make the plugin even better.<br>We don\'t need money :), just a minute of your time to rate the plugin. Thank you!', 'google-maps-widget'); | |
| 280 | + | |
| 281 | + echo '<br /><a target="_blank" href="' . esc_url($rate_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary">' . __('Help us out & rate the plugin', 'google-maps-widget') . '</a>'; | |
| 282 | + echo ' <a href="' . esc_url($dismiss_url) . '" class="">' . __('Dismiss notice', 'google-maps-widget') . '</a>'; | |
| 283 | + echo '</p></div>'; | |
| 284 | + } // notice_rate_plugin | |
| 285 | + | |
| 286 | + | |
| 169 | 287 | // enqueue frontend scripts if necessary |
| 170 | 288 | static function enqueue_scripts() { |
| 171 | 289 | if (is_active_widget(false, false, 'googlemapswidget', true)) { |
| 172 | - wp_enqueue_style('gmw', plugins_url('/css/gmw.css', __FILE__), array(), GMW_VER); | |
| 173 | - wp_enqueue_script('gmw-colorbox', plugins_url('/js/jquery.colorbox-min.js', __FILE__), array('jquery'), GMW_VER, true); | |
| 174 | - wp_enqueue_script('gmw', plugins_url('/js/gmw.js', __FILE__), array('jquery'), GMW_VER, true); | |
| 290 | + wp_enqueue_style('gmw', plugins_url('/css/gmw.css', __FILE__), array(), GMW::$version); | |
| 291 | + wp_enqueue_script('gmw-colorbox', plugins_url('/js/jquery.colorbox.min.js', __FILE__), array('jquery'), GMW::$version, true); | |
| 292 | + wp_enqueue_script('gmw', plugins_url('/js/gmw.js', __FILE__), array('jquery'), GMW::$version, true); | |
| 175 | 293 | } |
| 176 | 294 | } // enqueue_scripts |
| 177 | 295 | |
| 178 | 296 | |
| @@ -181,11 +299,23 @@ | ||
| 181 | 299 | global $wp_customize; |
| 182 | 300 | |
| 183 | 301 | if (self::is_plugin_admin_page() || isset($wp_customize)) { |
| 184 | 302 | wp_enqueue_script('jquery-ui-tabs'); |
| 185 | - wp_enqueue_script('gmw-cookie', plugins_url('js/jquery.cookie.js', __FILE__), array('jquery'), GMW_VER, true); | |
| 186 | - wp_enqueue_script('gmw-admin', plugins_url('js/gmw-admin.js', __FILE__), array('jquery'), GMW_VER, true); | |
| 187 | - wp_enqueue_style('gmw-admin', plugins_url('css/gmw-admin.css', __FILE__), array(), GMW_VER); | |
| 303 | + wp_enqueue_script('jquery-ui-dialog'); | |
| 304 | + wp_enqueue_script('gmw-cookie', plugins_url('js/jquery.cookie.js', __FILE__), array('jquery'), GMW::$version, true); | |
| 305 | + wp_enqueue_script('gmw-admin', plugins_url('js/gmw-admin.js', __FILE__), array('jquery'), GMW::$version, true); | |
| 306 | + | |
| 307 | + wp_enqueue_style('wp-jquery-ui-dialog'); | |
| 308 | + wp_enqueue_style('gmw-admin', plugins_url('css/gmw-admin.css', __FILE__), array(), GMW::$version); | |
| 309 | + | |
| 310 | + $js_localize = array('subscribe_ok' => __('Check your inbox. Email with activation code is on its way.', 'google-maps-widget'), | |
| 311 | + 'subscribe_duplicate' => __('You are already subscribed to our list. One activation code is valid for all sites so just use the code you already have.', 'google-maps-widget'), | |
| 312 | + 'subscribe_error' => __('Something is not right on our end. Sorry :( Try again later.', 'google-maps-widget'), | |
| 313 | + 'activate_ok' => __('Superb! Extra features are active ;)', 'google-maps-widget'), | |
| 314 | + 'dialog_title' => __('GOOGLE MAPS WIDGET - Activate Extra Features', 'google-maps-widget'), | |
| 315 | + 'undocumented_error' => __('An undocumented error has occured. Please refresh the page and try again.', 'google-maps-widget'), | |
| 316 | + 'id_base' => 'googlemapswidget'); | |
| 317 | + wp_localize_script('gmw-admin', 'gmw', $js_localize); | |
| 188 | 318 | } // if |
| 189 | 319 | } // admin_enqueue_scripts |
| 190 | 320 | |
| 191 | 321 | |
| @@ -200,8 +330,104 @@ | ||
| 200 | 330 | } |
| 201 | 331 | } // is_plugin_admin_page |
| 202 | 332 | |
| 203 | 333 | |
| 334 | + // check if activate-by-subscribing features have been activated | |
| 335 | + static function is_activated() { | |
| 336 | + $options = get_option(GMW_OPTIONS); | |
| 337 | + | |
| 338 | + if (isset($options['activated']) && $options['activated'] === true) { | |
| 339 | + return true; | |
| 340 | + } else { | |
| 341 | + return false; | |
| 342 | + } | |
| 343 | + } // is_activated | |
| 344 | + | |
| 345 | + | |
| 346 | + // echo markup for promo dialog; only on widgets page | |
| 347 | + static function admin_dialogs_markup() { | |
| 348 | + if (!self::is_plugin_admin_page()) { | |
| 349 | + return false; | |
| 350 | + } | |
| 351 | + | |
| 352 | + $current_user = wp_get_current_user(); | |
| 353 | + if (empty($current_user->user_firstname)) { | |
| 354 | + $name = $current_user->display_name; | |
| 355 | + } else { | |
| 356 | + $name = $current_user->user_firstname; | |
| 357 | + } | |
| 358 | + | |
| 359 | + $out = '<div id="gmw_promo_dialog">'; | |
| 360 | + $out .= '<div id="gmw_dialog_subscribe"><div class="content"><h3 class="center">' . __('Fill out the form and<br>get extra features & options <b>for FREE</b> instantly!', 'google-maps-widget') . '</h3>'; | |
| 361 | + $out .= '<p class="input_row"><input value="' . $name . '" type="text" id="gmw_name" name="gmw_name" placeholder="Your name"><span class="error name" style="display: none;">Please enter your name.</span></p>'; | |
| 362 | + $out .= '<p class="input_row"><input value="' . $current_user->user_email . '" type="text" name="gmw_email" id="gmw_email" placeholder="Your email address"><span style="display: none;" class="error email">Please double check your email address.</span></p>'; | |
| 363 | + $out .= '<p class="center"><a id="gmw_subscribe" href="#" class="button button-primary big-button">Activate extra features</a><br><a href="#" class="" id="gmw_already_subscribed">I already have an activation code</a></p></div>'; | |
| 364 | + $out .= '<div class="footer"><p><b>Why subscribe?</b></p><ul><li>We\'ll never share your email address</li><li>We won\'t spam you or overwhelm with emails</li><li>Be the first to get notified about new features</li><li>You\'ll get all future upgrades for free as well</li><li>You\'ll get discounts for our premium WP plugins</li></ul></div>'; | |
| 365 | + $out .= '</div>'; // dialog subscribe | |
| 366 | + $out .= '<div id="gmw_dialog_activate"><div class="content"><h3 class="center">' . __('Enter your code and activate extra features', 'google-maps-widget') . '</h3>'; | |
| 367 | + $out .= '<p class="input_row"><input type="text" id="gmw_code" name="gmw_code" placeholder="Your activation code"><span style="display: none;" class="error gmw_code">Please double check the activation code.</span></p><p class="center"><a href="#" class="button button-primary big-button" id="gmw_activate">Activate extra features</a></p></div>'; | |
| 368 | + $out .= '<div class="footer"><p><b>FAQ</b></p><ul><li>Already subscribed? Enter your activation code above.</li><li>Didn\'t receive the email? Check your SPAM folder.</li><li>Still not getting the email? Try a different email address.</li><li>Code is valid for an unlimited number of plugin installations.</li></ul></div>'; | |
| 369 | + $out .= '</div>'; // activate screen | |
| 370 | + $out .= '</div>'; // dialog | |
| 371 | + | |
| 372 | + echo $out; | |
| 373 | + } // admin_dialogs_markup | |
| 374 | + | |
| 375 | + | |
| 376 | + // send user's email to MailChimp via our server | |
| 377 | + static function email_subscribe() { | |
| 378 | + $name = trim($_POST['name']); | |
| 379 | + $email = trim($_POST['email']); | |
| 380 | + if (defined('WPLANG')) { | |
| 381 | + $lang = strtolower(substr(WPLANG, 0, 2)); | |
| 382 | + } else { | |
| 383 | + $lang = 'en'; | |
| 384 | + } | |
| 385 | + | |
| 386 | + $res = wp_remote_post('http://www.googlemapswidget.com/subscribe.php', array('body' => array('name' => $name, 'email' => $email, 'lang' => $lang, 'ip' => $_SERVER['REMOTE_ADDR'], 'site' => get_home_url()))); | |
| 387 | + | |
| 388 | + // something's wrong with our server | |
| 389 | + if ($res['response']['code'] != 200 || is_wp_error($res)) { | |
| 390 | + wp_send_json_error('unknown'); | |
| 391 | + } | |
| 392 | + | |
| 393 | + if ($res['body'] == 'ok') { | |
| 394 | + wp_send_json_success(); | |
| 395 | + } elseif ($res['body'] == 'duplicate') { | |
| 396 | + wp_send_json_error('duplicate'); | |
| 397 | + } else { | |
| 398 | + wp_send_json_error('unknown'); | |
| 399 | + } | |
| 400 | + } // email_subscribe | |
| 401 | + | |
| 402 | + | |
| 403 | + // check activation code and save if valid | |
| 404 | + static function activate_via_code() { | |
| 405 | + $code = trim($_POST['code']); | |
| 406 | + | |
| 407 | + if (self::validate_activation_code($code)) { | |
| 408 | + $options = get_option(GMW_OPTIONS); | |
| 409 | + $options['activation_code'] = $code; | |
| 410 | + $options['activated'] = true; | |
| 411 | + update_option(GMW_OPTIONS, $options); | |
| 412 | + | |
| 413 | + wp_send_json_success(); | |
| 414 | + } else { | |
| 415 | + wp_send_json_error(); | |
| 416 | + } | |
| 417 | + } // email_activate | |
| 418 | + | |
| 419 | + | |
| 420 | + // check if activation code for additional features is valid | |
| 421 | + static function validate_activation_code($code) { | |
| 422 | + if (strlen($code) == 6 && ($code[0] + $code[5]) == 9) { | |
| 423 | + return true; | |
| 424 | + } else { | |
| 425 | + return false; | |
| 426 | + } | |
| 427 | + } // validate_activation_code | |
| 428 | + | |
| 429 | + | |
| 204 | 430 | // helper function for creating dropdowns |
| 205 | 431 | static function create_select_options($options, $selected = null, $output = true) { |
| 206 | 432 | $out = "\n"; |
| 207 | 433 | |
| @@ -219,9 +445,9 @@ | ||
| 219 | 445 | return $out; |
| 220 | 446 | } |
| 221 | 447 | } // create_select_options |
| 222 | 448 | |
| 223 | - | |
| 449 | + | |
| 224 | 450 | // fetch coordinates based on the address |
| 225 | 451 | static function get_coordinates($address, $force_refresh = false) { |
| 226 | 452 | $address_hash = md5('gmw' . $address); |
| 227 | 453 | |
| @@ -230,9 +456,9 @@ | ||
| 230 | 456 | $result = wp_remote_get($url); |
| 231 | 457 | |
| 232 | 458 | if (!is_wp_error($result) && $result['response']['code'] == 200) { |
| 233 | 459 | $data = new SimpleXMLElement($result['body']); |
| 234 | - | |
| 460 | + | |
| 235 | 461 | if ($data->status == 'OK') { |
| 236 | 462 | $cache_value['lat'] = (string) $data->result->geometry->location->lat; |
| 237 | 463 | $cache_value['lng'] = (string) $data->result->geometry->location->lng; |
| 238 | 464 | $cache_value['address'] = (string) $data->result->formatted_address; |
| @@ -256,14 +482,39 @@ | ||
| 256 | 482 | return $data; |
| 257 | 483 | } // get_coordinates |
| 258 | 484 | |
| 259 | 485 | |
| 486 | + // shortcode support for any GMW instance | |
| 487 | + static function do_shortcode($atts, $content = null) { | |
| 488 | + if (!self::is_activated()) { | |
| 489 | + return; | |
| 490 | + } | |
| 491 | + | |
| 492 | + global $wp_widget_factory; | |
| 493 | + $atts = shortcode_atts(array('id' => 0), $atts); | |
| 494 | + $id = (int) $atts['id']; | |
| 495 | + $widgets = get_option('widget_googlemapswidget'); | |
| 496 | + | |
| 497 | + if (!$id || !isset($widgets[$id]) || empty($widgets[$id])) { | |
| 498 | + echo '<span class="gmw-error">Google Maps Widget shortcode error - please double-check the widget ID.</span>'; | |
| 499 | + } else { | |
| 500 | + $widget_args = $widgets[$id]; | |
| 501 | + $widget_instance['widget_id'] = 'googlemapswidget-' . $id; | |
| 502 | + $widget_instance['widget_name'] = 'Google Maps Widget'; | |
| 503 | + | |
| 504 | + echo '<span class="gmw-shortcode-widget">'; | |
| 505 | + the_widget('GoogleMapsWidget', $widget_args, $widget_instance); | |
| 506 | + echo '</span>'; | |
| 507 | + } | |
| 508 | + } // do_shortcode | |
| 509 | + | |
| 510 | + | |
| 260 | 511 | // activate doesn't get fired on upgrades so we have to compensate |
| 261 | 512 | public static function upgrade() { |
| 262 | 513 | $options = get_option(GMW_OPTIONS); |
| 263 | 514 | |
| 264 | 515 | if (!isset($options['first_version']) || !isset($options['first_install'])) { |
| 265 | - $options['first_version'] = GMW_VER; | |
| 516 | + $options['first_version'] = GMW::$version; | |
| 266 | 517 | $options['first_install'] = current_time('timestamp'); |
| 267 | 518 | update_option(GMW_OPTIONS, $options); |
| 268 | 519 | } |
| 269 | 520 | } // upgrade |
| @@ -274,9 +525,9 @@ | ||
| 274 | 525 | static function activate() { |
| 275 | 526 | $options = get_option(GMW_OPTIONS); |
| 276 | 527 | |
| 277 | 528 | if (!isset($options['first_version']) || !isset($options['first_install'])) { |
| 278 | - $options['first_version'] = GMW_VER; | |
| 529 | + $options['first_version'] = GMW::$version; | |
| 279 | 530 | $options['first_install'] = current_time('timestamp'); |
| 280 | 531 | $options['last_tracking'] = false; |
| 281 | 532 | update_option(GMW_OPTIONS, $options); |
| 282 | 533 | } |
| @@ -286,15 +537,22 @@ | ||
| 286 | 537 | // clean up on deactivation |
| 287 | 538 | static function deactivate() { |
| 288 | 539 | $options = get_option(GMW_OPTIONS); |
| 289 | 540 | |
| 290 | - if (isset($options['allow_tracking']) && $options['allow_tracking'] === false) { | |
| 291 | - unset($options['allow_tracking']); | |
| 292 | - update_option(GMW_OPTIONS, $options); | |
| 293 | - } elseif (isset($options['allow_tracking']) && $options['allow_tracking'] === true) { | |
| 541 | + if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) { | |
| 294 | 542 | GMW_tracking::clear_cron(); |
| 295 | 543 | } |
| 296 | - } // activate | |
| 544 | + } // deactivate | |
| 545 | + | |
| 546 | + | |
| 547 | + // clean up on uninstall / delete | |
| 548 | + static function uninstall() { | |
| 549 | + if (!defined('WP_UNINSTALL_PLUGIN')) { | |
| 550 | + return; | |
| 551 | + } | |
| 552 | + | |
| 553 | + delete_option(GMW_OPTIONS); | |
| 554 | + } // uninstall | |
| 297 | 555 | } // class GMW |
| 298 | 556 | |
| 299 | 557 | |
| 300 | 558 | // hook everything up |
| @@ -299,7 +557,8 @@ | ||
| 299 | 557 | |
| 300 | 558 | // hook everything up |
| 301 | 559 | register_activation_hook(__FILE__, array('GMW', 'activate')); |
| 302 | 560 | register_deactivation_hook(__FILE__, array('GMW', 'deactivate')); |
| 561 | +register_uninstall_hook(__FILE__, array('GMW', 'uninstall')); | |
| 303 | 562 | add_action('init', array('GMW', 'init')); |
| 304 | 563 | add_action('plugins_loaded', array('GMW', 'plugins_loaded')); |
| 305 | 564 | add_action('widgets_init', array('GMW', 'widgets_init')); |