| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | Plugin Name: Google Maps Widget |
| 4 | 4 | Plugin URI: http://www.googlemapswidget.com/ |
| 5 | 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: 2.25 | |
| 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 | |
| @@ -30,9 +30,8 @@ | ||
| 30 | 30 | die(); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
| 34 | -define('GMW_VER', '2.25'); | |
| 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 | |
| @@ -66,8 +67,14 @@ | ||
| 66 | 67 | |
| 67 | 68 | // register AJAX endpoints |
| 68 | 69 | add_action('wp_ajax_gmw_subscribe', array(__CLASS__, 'email_subscribe')); |
| 69 | 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(); | |
| 70 | 77 | } else { |
| 71 | 78 | // enqueue frontend scripts |
| 72 | 79 | add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); |
| 73 | 80 | add_action('wp_footer', array(__CLASS__, 'dialogs_markup')); |
| @@ -104,9 +111,10 @@ | ||
| 104 | 111 | static function plugin_meta_links($links, $file) { |
| 105 | 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>'; |
| 106 | 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>'; |
| 107 | 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>'; |
| 108 | - $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>'; | |
| 109 | 117 | |
| 110 | 118 | if ($file == plugin_basename(__FILE__)) { |
| 111 | 119 | $links[] = $documentation_link; |
| 112 | 120 | $links[] = $support_link; |
| @@ -111,8 +119,11 @@ | ||
| 111 | 119 | $links[] = $documentation_link; |
| 112 | 120 | $links[] = $support_link; |
| 113 | 121 | $links[] = $review_link; |
| 114 | 122 | $links[] = $donate_link; |
| 123 | + if (!self::is_activated()) { | |
| 124 | + $links[] = $activate_link; | |
| 125 | + } | |
| 115 | 126 | } |
| 116 | 127 | |
| 117 | 128 | return $links; |
| 118 | 129 | } // plugin_meta_links |
| @@ -120,17 +131,17 @@ | ||
| 120 | 131 | |
| 121 | 132 | // check if user has the minimal WP version required by the plugin |
| 122 | 133 | static function check_wp_version($min_version) { |
| 123 | 134 | if (!version_compare(get_bloginfo('version'), $min_version, '>=')) { |
| 124 | - add_action('admin_notices', array(__CLASS__, 'min_version_error')); | |
| 135 | + add_action('admin_notices', array(__CLASS__, 'notice_min_version_error')); | |
| 125 | 136 | } |
| 126 | 137 | } // check_wp_version |
| 127 | 138 | |
| 128 | 139 | |
| 129 | 140 | // display error message if WP version is too low |
| 130 | - static function min_version_error() { | |
| 131 | - 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>'; | |
| 132 | - } // 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 | |
| 133 | 144 | |
| 134 | 145 | |
| 135 | 146 | // print dialogs markup in footer |
| 136 | 147 | static function dialogs_markup() { |
| @@ -198,14 +209,88 @@ | ||
| 198 | 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>'; |
| 199 | 210 | } // notice_sc_conflict_error |
| 200 | 211 | |
| 201 | 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 | + | |
| 202 | 287 | // enqueue frontend scripts if necessary |
| 203 | 288 | static function enqueue_scripts() { |
| 204 | 289 | if (is_active_widget(false, false, 'googlemapswidget', true)) { |
| 205 | - wp_enqueue_style('gmw', plugins_url('/css/gmw.css', __FILE__), array(), GMW_VER); | |
| 206 | - wp_enqueue_script('gmw-colorbox', plugins_url('/js/jquery.colorbox.min.js', __FILE__), array('jquery'), GMW_VER, true); | |
| 207 | - 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); | |
| 208 | 293 | } |
| 209 | 294 | } // enqueue_scripts |
| 210 | 295 | |
| 211 | 296 | |
| @@ -215,19 +300,21 @@ | ||
| 215 | 300 | |
| 216 | 301 | if (self::is_plugin_admin_page() || isset($wp_customize)) { |
| 217 | 302 | wp_enqueue_script('jquery-ui-tabs'); |
| 218 | 303 | wp_enqueue_script('jquery-ui-dialog'); |
| 219 | - wp_enqueue_script('gmw-cookie', plugins_url('js/jquery.cookie.js', __FILE__), array('jquery'), GMW_VER, true); | |
| 220 | - wp_enqueue_script('gmw-admin', plugins_url('js/gmw-admin.js', __FILE__), array('jquery'), GMW_VER, true); | |
| 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); | |
| 221 | 306 | |
| 222 | 307 | wp_enqueue_style('wp-jquery-ui-dialog'); |
| 223 | - wp_enqueue_style('gmw-admin', plugins_url('css/gmw-admin.css', __FILE__), array(), GMW_VER); | |
| 308 | + wp_enqueue_style('gmw-admin', plugins_url('css/gmw-admin.css', __FILE__), array(), GMW::$version); | |
| 224 | 309 | |
| 225 | 310 | $js_localize = array('subscribe_ok' => __('Check your inbox. Email with activation code is on its way.', 'google-maps-widget'), |
| 226 | 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'), |
| 227 | 312 | 'subscribe_error' => __('Something is not right on our end. Sorry :( Try again later.', 'google-maps-widget'), |
| 228 | 313 | 'activate_ok' => __('Superb! Extra features are active ;)', 'google-maps-widget'), |
| 229 | - 'dialog_title' => __('GOOGLE MAPS WIDGET - Activate Extra Features', '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'); | |
| 230 | 317 | wp_localize_script('gmw-admin', 'gmw', $js_localize); |
| 231 | 318 | } // if |
| 232 | 319 | } // admin_enqueue_scripts |
| 233 | 320 | |
| @@ -269,17 +356,17 @@ | ||
| 269 | 356 | $name = $current_user->user_firstname; |
| 270 | 357 | } |
| 271 | 358 | |
| 272 | 359 | $out = '<div id="gmw_promo_dialog">'; |
| 273 | - $out .= '<div id="gmw_dialog_subscribe"><div class="content"><h3 class="center">' . __('Subscribe to our newsletter<br>and get extra features & options <b>for FREE</b>!', 'google-maps-widget') . '</h3>'; | |
| 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>'; | |
| 274 | 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>'; |
| 275 | 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>'; |
| 276 | - $out .= '<p class="center"><a id="gmw_subscribe" href="#" class="button button-primary big-button">Subscribe & activate extra features</a><br><a href="#" class="" id="gmw_already_subscribed">I\'m already subscribed</a></p></div>'; | |
| 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>'; | |
| 277 | 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>'; |
| 278 | 365 | $out .= '</div>'; // dialog subscribe |
| 279 | 366 | $out .= '<div id="gmw_dialog_activate"><div class="content"><h3 class="center">' . __('Enter your code and activate extra features', 'google-maps-widget') . '</h3>'; |
| 280 | 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>'; |
| 281 | - $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>Lost your code or having other problems? <a href="mailto:gmw@webfactoryltd.com?subject=Lost%20activation%20code">Email us</a>.</li><li>Code is valid for an unlimited number of plugin installations.</li></ul></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>'; | |
| 282 | 369 | $out .= '</div>'; // activate screen |
| 283 | 370 | $out .= '</div>'; // dialog |
| 284 | 371 | |
| 285 | 372 | echo $out; |
| @@ -299,22 +386,17 @@ | ||
| 299 | 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()))); |
| 300 | 387 | |
| 301 | 388 | // something's wrong with our server |
| 302 | 389 | if ($res['response']['code'] != 200 || is_wp_error($res)) { |
| 303 | - echo 'err'; | |
| 304 | - die(); | |
| 390 | + wp_send_json_error('unknown'); | |
| 305 | 391 | } |
| 306 | 392 | |
| 307 | 393 | if ($res['body'] == 'ok') { |
| 308 | - echo "ok"; | |
| 309 | - die(); | |
| 394 | + wp_send_json_success(); | |
| 310 | 395 | } elseif ($res['body'] == 'duplicate') { |
| 311 | - echo "duplicate"; | |
| 312 | - die(); | |
| 396 | + wp_send_json_error('duplicate'); | |
| 313 | 397 | } else { |
| 314 | - // todo var_dump($res['body']); | |
| 315 | - echo 'err'; | |
| 316 | - die(); | |
| 398 | + wp_send_json_error('unknown'); | |
| 317 | 399 | } |
| 318 | 400 | } // email_subscribe |
| 319 | 401 | |
| 320 | 402 | |
| @@ -319,9 +401,9 @@ | ||
| 319 | 401 | |
| 320 | 402 | |
| 321 | 403 | // check activation code and save if valid |
| 322 | 404 | static function activate_via_code() { |
| 323 | - $code = trim($_GET['code']); | |
| 405 | + $code = trim($_POST['code']); | |
| 324 | 406 | |
| 325 | 407 | if (self::validate_activation_code($code)) { |
| 326 | 408 | $options = get_option(GMW_OPTIONS); |
| 327 | 409 | $options['activation_code'] = $code; |
| @@ -327,11 +409,11 @@ | ||
| 327 | 409 | $options['activation_code'] = $code; |
| 328 | 410 | $options['activated'] = true; |
| 329 | 411 | update_option(GMW_OPTIONS, $options); |
| 330 | 412 | |
| 331 | - die("1"); | |
| 413 | + wp_send_json_success(); | |
| 332 | 414 | } else { |
| 333 | - die("0"); | |
| 415 | + wp_send_json_error(); | |
| 334 | 416 | } |
| 335 | 417 | } // email_activate |
| 336 | 418 | |
| 337 | 419 | |
| @@ -430,9 +512,9 @@ | ||
| 430 | 512 | public static function upgrade() { |
| 431 | 513 | $options = get_option(GMW_OPTIONS); |
| 432 | 514 | |
| 433 | 515 | if (!isset($options['first_version']) || !isset($options['first_install'])) { |
| 434 | - $options['first_version'] = GMW_VER; | |
| 516 | + $options['first_version'] = GMW::$version; | |
| 435 | 517 | $options['first_install'] = current_time('timestamp'); |
| 436 | 518 | update_option(GMW_OPTIONS, $options); |
| 437 | 519 | } |
| 438 | 520 | } // upgrade |
| @@ -443,9 +525,9 @@ | ||
| 443 | 525 | static function activate() { |
| 444 | 526 | $options = get_option(GMW_OPTIONS); |
| 445 | 527 | |
| 446 | 528 | if (!isset($options['first_version']) || !isset($options['first_install'])) { |
| 447 | - $options['first_version'] = GMW_VER; | |
| 529 | + $options['first_version'] = GMW::$version; | |
| 448 | 530 | $options['first_install'] = current_time('timestamp'); |
| 449 | 531 | $options['last_tracking'] = false; |
| 450 | 532 | update_option(GMW_OPTIONS, $options); |
| 451 | 533 | } |