PluginProbe
Maps Widget for Google Maps / 2.25
Maps Widget for Google Maps v2.25
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 / gmw-tracking.php

gmw-tracking.php in Maps Widget for Google Maps 2.25, at gmw-tracking.php

178 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Google Maps Widget
4 * Plugin usage tracking
5 * (c) Web factory Ltd, 2012 - 2015
6 */
7
8
9 // include only file
10 if (!defined('ABSPATH')) {
11 die();
12 }
13
14
15 class GMW_tracking {
16 // set things up
17 public static function init() {
18 $options = get_option(GMW_OPTIONS);
19
20 self::check_opt_in_out();
21
22 // ask user if he wants to allow tracking
23 if (is_admin() && !isset($options['allow_tracking'])) {
24 add_action('admin_notices', array(__CLASS__, 'tracking_notice'));
25 }
26
27 add_action(GMW_CRON, array(__CLASS__, 'send_data'));
28 // todo - write this properly, so it doesn't run each time, $force ...
29 GMW_tracking::setup_cron();
30 } // init
31
32
33 // register additional cron interval
34 public static function register_cron_intervals($schedules) {
35 $schedules['gmw_weekly'] = array(
36 'interval' => DAY_IN_SECONDS * 7,
37 'display' => 'Once a Week');
38
39 return $schedules;
40 } // cron_intervals
41
42
43 // clear cron scheadule
44 public static function clear_cron() {
45 wp_clear_scheduled_hook(GMW_CRON);
46 } // clear_cron
47
48
49 // setup cron job when user allows tracking
50 public static function setup_cron() {
51 $options = get_option(GMW_OPTIONS);
52
53 if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) {
54 if (!wp_next_scheduled(GMW_CRON)) {
55 wp_schedule_event(time() + 300, 'gmw_weekly', GMW_CRON);
56 }
57 } else {
58 self::clear_cron();
59 }
60 } // setup_cron
61
62
63 // save user's choice for (not) allowing tracking
64 public static function check_opt_in_out() {
65 $options = get_option(GMW_OPTIONS);
66
67 if (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_in') {
68 $options['allow_tracking'] = true;
69 update_option(GMW_OPTIONS, $options);
70 self::send_data(true);
71 wp_redirect(remove_query_arg('gmw_tracking'));
72 die();
73 } else if (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_out') {
74 $options['allow_tracking'] = false;
75 update_option(GMW_OPTIONS, $options);
76 wp_redirect(remove_query_arg('gmw_tracking'));
77 die();
78 }
79 } // check_opt_in_out
80
81
82 // display tracking notice
83 public static function tracking_notice() {
84 $optin_url = add_query_arg('gmw_tracking', 'opt_in');
85 $optout_url = add_query_arg('gmw_tracking', 'opt_out');
86
87 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 &amp; 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>';
90 echo '&nbsp;&nbsp;<a href="' . esc_url($optout_url) . '" class="">' . __('Do not allow tracking', 'google-maps-widget') . '</a>';
91 echo '</p></div>';
92 } // tracking_notice
93
94
95 // send usage data once a week to our server
96 public static function send_data($force = false) {
97 $options = get_option(GMW_OPTIONS);
98
99 if ($force == false && (!isset($options['allow_tracking']) || $options['allow_tracking'] !== true)) {
100 return;
101 }
102 if ($force == false && ($options['last_tracking'] && $options['last_tracking'] > strtotime( '-6 days'))) {
103 return;
104 }
105
106 $data = self::prepare_data();
107 $request = wp_remote_post('http://www.googlemapswidget.com/tracking.php', array(
108 'method' => 'POST',
109 'timeout' => 10,
110 'redirection' => 3,
111 'httpversion' => '1.0',
112 'body' => $data,
113 'user-agent' => 'GMW/' . GMW_VER));
114
115 $options['last_tracking'] = current_time('timestamp');
116 update_option(GMW_OPTIONS, $options);
117 } // send_data
118
119
120 // get and prepare data that will be sent out
121 public static function prepare_data() {
122 $options = get_option(GMW_OPTIONS);
123 $data = array();
124 $current_user = wp_get_current_user();
125
126 $data['url'] = home_url();
127 if ($current_user && isset($current_user->user_email) && !empty($current_user->user_email)) {
128 $data['admin_email'] = $current_user->user_email;
129 } else {
130 $data['admin_email'] = get_bloginfo('admin_email');
131 }
132 $data['wp_version'] = get_bloginfo('version');
133 $data['gmw_version'] = GMW_VER;
134 $data['gmw_first_version'] = $options['first_version'];
135 $data['gmw_first_install'] = $options['first_install'];
136 $data['gmw_activated'] = GMW::is_activated();
137 $data['ioncube'] = extension_loaded('IonCube Loader');
138
139 $data['gmw_count'] = 0;
140 $sidebars = get_option('sidebars_widgets', array());
141 foreach ($sidebars as $sidebar_name => $widgets) {
142 if (strpos($sidebar_name, 'inactive') !== false || strpos($sidebar_name, 'orphaned') !== false) {
143 continue;
144 }
145 if (is_array($widgets)) {
146 foreach ($widgets as $widget_name) {
147 if (strpos($widget_name, 'googlemapswidget') !== false) {
148 $data['gmw_count']++;
149 }
150 }
151 }
152 } // foreach sidebar
153
154 if (get_bloginfo('version') < '3.4') {
155 $theme = get_theme_data(get_stylesheet_directory() . '/style.css');
156 $data['theme_name'] = $theme['Name'];
157 $data['theme_version'] = $theme['Version'];
158 } else {
159 $theme = wp_get_theme();
160 $data['theme_name'] = $theme->Name;
161 $data['theme_version'] = $theme->Version;
162 }
163
164 // get current plugin information
165 if (!function_exists('get_plugins')) {
166 include ABSPATH . '/wp-admin/includes/plugin.php';
167 }
168
169 $plugins = get_plugins();
170 $active_plugins = get_option('active_plugins', array());
171
172 foreach ($active_plugins as $plugin) {
173 $data['plugins'][$plugin] = @$plugins[$plugin];
174 }
175
176 return $data;
177 } // prepare_data
178 } // class GMW_tracking