| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | * Google Maps Widget |
| 4 | 4 | * Plugin usage tracking |
| 5 | - * (c) Web factory Ltd, 2012 - 2014 | |
| 5 | + * (c) Web factory Ltd, 2012 - 2015 | |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | // include only file |
| @@ -13,9 +13,9 @@ | ||
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | class GMW_tracking { |
| 16 | 16 | // set things up |
| 17 | - public static function init() { | |
| 17 | + static function init() { | |
| 18 | 18 | $options = get_option(GMW_OPTIONS); |
| 19 | 19 | |
| 20 | 20 | self::check_opt_in_out(); |
| 21 | 21 | |
| @@ -30,12 +30,15 @@ | ||
| 30 | 30 | } // init |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | // register additional cron interval |
| 34 | - public static function register_cron_intervals($schedules) { | |
| 34 | + static function register_cron_intervals($schedules) { | |
| 35 | 35 | $schedules['gmw_weekly'] = array( |
| 36 | 36 | 'interval' => DAY_IN_SECONDS * 7, |
| 37 | 37 | 'display' => 'Once a Week'); |
| 38 | + $schedules['gmw_biweekly'] = array( | |
| 39 | + 'interval' => DAY_IN_SECONDS * 14, | |
| 40 | + 'display' => 'Once every two Weeks'); | |
| 38 | 41 | |
| 39 | 42 | return $schedules; |
| 40 | 43 | } // cron_intervals |
| 41 | 44 | |
| @@ -40,20 +43,20 @@ | ||
| 40 | 43 | } // cron_intervals |
| 41 | 44 | |
| 42 | 45 | |
| 43 | 46 | // clear cron scheadule |
| 44 | - public static function clear_cron() { | |
| 47 | + static function clear_cron() { | |
| 45 | 48 | wp_clear_scheduled_hook(GMW_CRON); |
| 46 | 49 | } // clear_cron |
| 47 | 50 | |
| 48 | 51 | |
| 49 | 52 | // setup cron job when user allows tracking |
| 50 | - public static function setup_cron() { | |
| 53 | + static function setup_cron() { | |
| 51 | 54 | $options = get_option(GMW_OPTIONS); |
| 52 | 55 | |
| 53 | 56 | if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) { |
| 54 | 57 | if (!wp_next_scheduled(GMW_CRON)) { |
| 55 | - wp_schedule_event(time() + 300, 'gmw_weekly', GMW_CRON); | |
| 58 | + wp_schedule_event(time() + 300, 'gmw_biweekly', GMW_CRON); | |
| 56 | 59 | } |
| 57 | 60 | } else { |
| 58 | 61 | self::clear_cron(); |
| 59 | 62 | } |
| @@ -60,9 +63,9 @@ | ||
| 60 | 63 | } // setup_cron |
| 61 | 64 | |
| 62 | 65 | |
| 63 | 66 | // save user's choice for (not) allowing tracking |
| 64 | - public static function check_opt_in_out() { | |
| 67 | + static function check_opt_in_out() { | |
| 65 | 68 | $options = get_option(GMW_OPTIONS); |
| 66 | 69 | |
| 67 | 70 | if (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_in') { |
| 68 | 71 | $options['allow_tracking'] = true; |
| @@ -67,14 +70,14 @@ | ||
| 67 | 70 | if (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_in') { |
| 68 | 71 | $options['allow_tracking'] = true; |
| 69 | 72 | update_option(GMW_OPTIONS, $options); |
| 70 | 73 | self::send_data(true); |
| 71 | - wp_redirect(remove_query_arg('gmw_tracking')); | |
| 74 | + wp_redirect(esc_url_raw(remove_query_arg('gmw_tracking'))); | |
| 72 | 75 | die(); |
| 73 | 76 | } else if (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_out') { |
| 74 | 77 | $options['allow_tracking'] = false; |
| 75 | 78 | update_option(GMW_OPTIONS, $options); |
| 76 | - wp_redirect(remove_query_arg('gmw_tracking')); | |
| 79 | + wp_redirect(esc_url_raw(remove_query_arg('gmw_tracking'))); | |
| 77 | 80 | die(); |
| 78 | 81 | } |
| 79 | 82 | } // check_opt_in_out |
| 80 | 83 | |
| @@ -79,15 +82,15 @@ | ||
| 79 | 82 | } // check_opt_in_out |
| 80 | 83 | |
| 81 | 84 | |
| 82 | 85 | // display tracking notice |
| 83 | - public static function tracking_notice() { | |
| 86 | + static function tracking_notice() { | |
| 84 | 87 | $optin_url = add_query_arg('gmw_tracking', 'opt_in'); |
| 85 | 88 | $optout_url = add_query_arg('gmw_tracking', 'opt_out'); |
| 86 | 89 | |
| 87 | 90 | echo '<div class="updated"><p>'; |
| 88 | - echo __( 'Please help us improve <strong>Google Maps Widget</strong> by allowing us to track anonymous usage data. Absolutely <strong>no sensitive data is tracked</strong> (<a href="http://www.googlemapswidget.com/plugin-tracking-info/" target="_blank">complete disclosure & details of our tracking policy</a>).', 'google-maps-widget'); | |
| 89 | - echo '<br /><a href="' . esc_url($optin_url) . '" style="vertical-align: baseline;" class="button-primary">' . __('Allow', 'google-maps-widget') . '</a>'; | |
| 91 | + echo __('Please help us improve <strong>Google Maps Widget</strong> by allowing us to track anonymous usage data. Absolutely <strong>no sensitive data is tracked</strong> (<a href="http://www.googlemapswidget.com/plugin-tracking-info/" target="_blank">complete disclosure & details of our tracking policy</a>).', 'google-maps-widget'); | |
| 92 | + echo '<br /><a href="' . esc_url($optin_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary">' . __('Allow', 'google-maps-widget') . '</a>'; | |
| 90 | 93 | echo ' <a href="' . esc_url($optout_url) . '" class="">' . __('Do not allow tracking', 'google-maps-widget') . '</a>'; |
| 91 | 94 | echo '</p></div>'; |
| 92 | 95 | } // tracking_notice |
| 93 | 96 | |
| @@ -92,9 +95,9 @@ | ||
| 92 | 95 | } // tracking_notice |
| 93 | 96 | |
| 94 | 97 | |
| 95 | 98 | // send usage data once a week to our server |
| 96 | - public static function send_data($force = false) { | |
| 99 | + static function send_data($force = false) { | |
| 97 | 100 | $options = get_option(GMW_OPTIONS); |
| 98 | 101 | |
| 99 | 102 | if ($force == false && (!isset($options['allow_tracking']) || $options['allow_tracking'] !== true)) { |
| 100 | 103 | return; |
| @@ -109,9 +112,9 @@ | ||
| 109 | 112 | 'timeout' => 10, |
| 110 | 113 | 'redirection' => 3, |
| 111 | 114 | 'httpversion' => '1.0', |
| 112 | 115 | 'body' => $data, |
| 113 | - 'user-agent' => 'GMW/' . GMW_VER)); | |
| 116 | + 'user-agent' => 'GMW/' . GMW::$version)); | |
| 114 | 117 | |
| 115 | 118 | $options['last_tracking'] = current_time('timestamp'); |
| 116 | 119 | update_option(GMW_OPTIONS, $options); |
| 117 | 120 | } // send_data |
| @@ -117,34 +120,27 @@ | ||
| 117 | 120 | } // send_data |
| 118 | 121 | |
| 119 | 122 | |
| 120 | 123 | // get and prepare data that will be sent out |
| 121 | - public static function prepare_data() { | |
| 124 | + static function prepare_data() { | |
| 122 | 125 | $options = get_option(GMW_OPTIONS); |
| 123 | 126 | $data = array(); |
| 127 | + $current_user = wp_get_current_user(); | |
| 124 | 128 | |
| 125 | 129 | $data['url'] = home_url(); |
| 126 | - $data['admin_email'] = get_bloginfo('admin_email'); | |
| 130 | + if ($current_user && isset($current_user->user_email) && !empty($current_user->user_email)) { | |
| 131 | + $data['admin_email'] = $current_user->user_email; | |
| 132 | + } else { | |
| 133 | + $data['admin_email'] = get_bloginfo('admin_email'); | |
| 134 | + } | |
| 127 | 135 | $data['wp_version'] = get_bloginfo('version'); |
| 128 | - $data['gmw_version'] = GMW_VER; | |
| 136 | + $data['gmw_version'] = GMW::$version; | |
| 129 | 137 | $data['gmw_first_version'] = $options['first_version']; |
| 130 | 138 | $data['gmw_first_install'] = $options['first_install']; |
| 139 | + $data['gmw_activated'] = GMW::is_activated(); | |
| 140 | + $data['ioncube'] = extension_loaded('IonCube Loader'); | |
| 141 | + $data['gmw_count'] = self::count_active_widgets(); | |
| 131 | 142 | |
| 132 | - $data['gmw_count'] = 0; | |
| 133 | - $sidebars = get_option('sidebars_widgets', array()); | |
| 134 | - foreach ($sidebars as $sidebar_name => $widgets) { | |
| 135 | - if (strpos($sidebar_name, 'inactive') !== false || strpos($sidebar_name, 'orphaned') !== false) { | |
| 136 | - continue; | |
| 137 | - } | |
| 138 | - if (is_array($widgets)) { | |
| 139 | - foreach ($widgets as $widget_name) { | |
| 140 | - if (strpos($widget_name, 'googlemapswidget') !== false) { | |
| 141 | - $data['gmw_count']++; | |
| 142 | - } | |
| 143 | - } | |
| 144 | - } | |
| 145 | - } // foreach sidebar | |
| 146 | - | |
| 147 | 143 | if (get_bloginfo('version') < '3.4') { |
| 148 | 144 | $theme = get_theme_data(get_stylesheet_directory() . '/style.css'); |
| 149 | 145 | $data['theme_name'] = $theme['Name']; |
| 150 | 146 | $data['theme_version'] = $theme['Version']; |
| @@ -167,5 +163,27 @@ | ||
| 167 | 163 | } |
| 168 | 164 | |
| 169 | 165 | return $data; |
| 170 | 166 | } // prepare_data |
| 167 | + | |
| 168 | + | |
| 169 | + // counts the number of active GMW widgets in sidebars | |
| 170 | + static function count_active_widgets() { | |
| 171 | + $count = 0; | |
| 172 | + | |
| 173 | + $sidebars = get_option('sidebars_widgets', array()); | |
| 174 | + foreach ($sidebars as $sidebar_name => $widgets) { | |
| 175 | + if (strpos($sidebar_name, 'inactive') !== false || strpos($sidebar_name, 'orphaned') !== false) { | |
| 176 | + continue; | |
| 177 | + } | |
| 178 | + if (is_array($widgets)) { | |
| 179 | + foreach ($widgets as $widget_name) { | |
| 180 | + if (strpos($widget_name, 'googlemapswidget') !== false) { | |
| 181 | + $count++; | |
| 182 | + } | |
| 183 | + } | |
| 184 | + } | |
| 185 | + } // foreach sidebar | |
| 186 | + | |
| 187 | + return $count; | |
| 188 | + } // count_active_widgets | |
| 171 | 189 | } // class GMW_tracking |