PluginProbe
Maps Widget for Google Maps / 1.93
Maps Widget for Google Maps v1.93
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 1.93, at gmw-tracking.php

171 lines 5.7 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 - 2014
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
125 $data['url'] = home_url();
126 $data['admin_email'] = get_bloginfo('admin_email');
127 $data['wp_version'] = get_bloginfo('version');
128 $data['gmw_version'] = GMW_VER;
129 $data['gmw_first_version'] = $options['first_version'];
130 $data['gmw_first_install'] = $options['first_install'];
131
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 if (get_bloginfo('version') < '3.4') {
148 $theme = get_theme_data(get_stylesheet_directory() . '/style.css');
149 $data['theme_name'] = $theme['Name'];
150 $data['theme_version'] = $theme['Version'];
151 } else {
152 $theme = wp_get_theme();
153 $data['theme_name'] = $theme->Name;
154 $data['theme_version'] = $theme->Version;
155 }
156
157 // get current plugin information
158 if (!function_exists('get_plugins')) {
159 include ABSPATH . '/wp-admin/includes/plugin.php';
160 }
161
162 $plugins = get_plugins();
163 $active_plugins = get_option('active_plugins', array());
164
165 foreach ($active_plugins as $plugin) {
166 $data['plugins'][$plugin] = @$plugins[$plugin];
167 }
168
169 return $data;
170 } // prepare_data
171 } // class GMW_tracking