GMW_tracking

The Google Maps Widget GMW tracking class.

Defined (1)

The class is defined in the following location(s).

/gmw-tracking.php  
  1. class GMW_tracking { 
  2. static $cron_biweekly = 'gmw_biweekly_cron'; 
  3.  
  4. // set things up 
  5. static function init() { 
  6. self::check_opt_in_out(); 
  7.  
  8. add_action(self::$cron_biweekly, array(__CLASS__, 'send_data')); 
  9. GMW_tracking::setup_cron(); 
  10. } // init 
  11.  
  12.  
  13. // register additional cron interval 
  14. static function register_cron_intervals($schedules) { 
  15. $schedules['gmw_weekly'] = array( 
  16. 'interval' => DAY_IN_SECONDS * 7,  
  17. 'display' => 'Once a Week'); 
  18. $schedules['gmw_biweekly'] = array( 
  19. 'interval' => DAY_IN_SECONDS * 14,  
  20. 'display' => 'Once every two Weeks'); 
  21.  
  22. return $schedules; 
  23. } // cron_intervals 
  24.  
  25.  
  26. // clear cron scheadule 
  27. static function clear_cron() { 
  28. wp_clear_scheduled_hook(self::$cron_biweekly); 
  29. } // clear_cron 
  30.  
  31.  
  32. // setup cron job when user allows tracking 
  33. static function setup_cron() { 
  34. $options = GMW::get_options(); 
  35.  
  36. if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) { 
  37. if (!wp_next_scheduled(self::$cron_biweekly)) { 
  38. wp_schedule_event(current_time('timestamp') + 60, 'gmw_biweekly', self::$cron_biweekly); 
  39. } else { 
  40. self::clear_cron(); 
  41. } // setup_cron 
  42.  
  43.  
  44. // save user's choice for (not) allowing tracking 
  45. static function check_opt_in_out() { 
  46. if (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_in') { 
  47. GMW::set_options(array('allow_tracking' => true)); 
  48. self::send_data(true); 
  49. wp_redirect(esc_url_raw(remove_query_arg('gmw_tracking'))); 
  50. die(); 
  51. } elseif (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_out') { 
  52. GMW::set_options(array('allow_tracking' => false)); 
  53. wp_redirect(esc_url_raw(remove_query_arg('gmw_tracking'))); 
  54. die(); 
  55. } // check_opt_in_out 
  56.  
  57.  
  58. // display tracking notice 
  59. static function tracking_notice() { 
  60. $optin_url = add_query_arg('gmw_tracking', 'opt_in'); 
  61. $optout_url = add_query_arg('gmw_tracking', 'opt_out'); 
  62.  
  63. echo '<div class="updated"><p>'; 
  64. echo __('Please help us improve <strong>Google Maps Widget</strong> by allowing tracking of anonymous usage data. Absolutely <strong>no sensitive data is tracked</strong> (<a href="http://www.gmapswidget.com/plugin-tracking-info/" target="_blank">complete disclosure & details of our tracking policy</a>).', 'google-maps-widget'); 
  65. echo '<br /><a href="' . esc_url($optin_url) . '" style="vertical-align: baseline; margin-top: 15px;" class="button-primary">' . __('Allow', 'google-maps-widget') . '</a>'; 
  66. echo '  <a href="' . esc_url($optout_url) . '" class="">' . __('Do not allow tracking', 'google-maps-widget') . '</a>'; 
  67. echo '</p></div>'; 
  68. } // tracking_notice 
  69.  
  70.  
  71. // send usage data once a week to our server 
  72. static function send_data($force = false) { 
  73. $options = GMW::get_options(); 
  74.  
  75. if ($force == false && (!isset($options['allow_tracking']) || $options['allow_tracking'] !== true)) { 
  76. return; 
  77. if ($force == false && ($options['last_tracking'] && $options['last_tracking'] > strtotime( '-6 days'))) { 
  78. return; 
  79.  
  80. $data = self::prepare_data(); 
  81. $request = wp_remote_post('http://www.gmapswidget.com/tracking.php', array( 
  82. 'method' => 'POST',  
  83. 'timeout' => 10,  
  84. 'redirection' => 3,  
  85. 'httpversion' => '1.0',  
  86. 'body' => $data,  
  87. 'user-agent' => 'GMW/' . GMW::$version)); 
  88.  
  89. $options['last_tracking'] = current_time('timestamp'); 
  90. update_option(GMW::$options, $options); 
  91. } // send_data 
  92.  
  93.  
  94. // get and prepare data that will be sent out 
  95. static function prepare_data() { 
  96. $options = GMW::get_options(); 
  97. $data = array(); 
  98. $current_user = wp_get_current_user(); 
  99.  
  100. $data['url'] = home_url(); 
  101. if ($current_user && isset($current_user->user_email) && !empty($current_user->user_email)) { 
  102. $data['admin_email'] = $current_user->user_email; 
  103. } else { 
  104. $data['admin_email'] = get_bloginfo('admin_email'); 
  105. $data['wp_version'] = get_bloginfo('version'); 
  106. $data['gmw_version'] = GMW::$version; 
  107. $data['gmw_first_version'] = $options['first_version']; 
  108. $data['gmw_first_install'] = $options['first_install']; 
  109. $data['ioncube'] = extension_loaded('IonCube Loader'); 
  110. $data['gmw_count'] = self::count_active_widgets(); 
  111.  
  112. $theme = wp_get_theme(); 
  113. $data['theme_name'] = $theme->Name; 
  114. $data['theme_version'] = $theme->Version; 
  115.  
  116. // get current plugin information 
  117. if (!function_exists('get_plugins')) { 
  118. include ABSPATH . '/wp-admin/includes/plugin.php'; 
  119.  
  120. $plugins = get_plugins(); 
  121. $active_plugins = get_option('active_plugins', array()); 
  122.  
  123. foreach ($active_plugins as $plugin) { 
  124. $data['plugins'][$plugin] = @$plugins[$plugin]; 
  125.  
  126. return $data; 
  127. } // prepare_data 
  128.  
  129.  
  130. // counts the number of active GMW widgets in sidebars 
  131. static function count_active_widgets() { 
  132. $count = 0; 
  133.  
  134. $sidebars = get_option('sidebars_widgets', array()); 
  135. foreach ($sidebars as $sidebar_name => $widgets) { 
  136. if (strpos($sidebar_name, 'inactive') !== false || strpos($sidebar_name, 'orphaned') !== false) { 
  137. continue; 
  138. if (is_array($widgets)) { 
  139. foreach ($widgets as $widget_name) { 
  140. if (strpos($widget_name, 'googlemapswidget') !== false) { 
  141. $count++; 
  142. } // foreach sidebar 
  143.  
  144. return $count; 
  145. } // count_active_widgets 
  146. } // class GMW_tracking