DAY_IN_SECONDS * 7,
'display' => 'Once a Week');
$schedules['gmw_biweekly'] = array(
'interval' => DAY_IN_SECONDS * 14,
'display' => 'Once every two Weeks');
return $schedules;
} // cron_intervals
// clear cron scheadule
static function clear_cron() {
wp_clear_scheduled_hook(GMW_CRON);
} // clear_cron
// setup cron job when user allows tracking
static function setup_cron() {
$options = get_option(GMW_OPTIONS);
if (isset($options['allow_tracking']) && $options['allow_tracking'] === true) {
if (!wp_next_scheduled(GMW_CRON)) {
wp_schedule_event(time() + 300, 'gmw_biweekly', GMW_CRON);
}
} else {
self::clear_cron();
}
} // setup_cron
// save user's choice for (not) allowing tracking
static function check_opt_in_out() {
$options = get_option(GMW_OPTIONS);
if (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_in') {
$options['allow_tracking'] = true;
update_option(GMW_OPTIONS, $options);
self::send_data(true);
wp_redirect(esc_url_raw(remove_query_arg('gmw_tracking')));
die();
} else if (isset($_GET['gmw_tracking']) && $_GET['gmw_tracking'] == 'opt_out') {
$options['allow_tracking'] = false;
update_option(GMW_OPTIONS, $options);
wp_redirect(esc_url_raw(remove_query_arg('gmw_tracking')));
die();
}
} // check_opt_in_out
// display tracking notice
static function tracking_notice() {
$optin_url = add_query_arg('gmw_tracking', 'opt_in');
$optout_url = add_query_arg('gmw_tracking', 'opt_out');
echo '
';
} // tracking_notice
// send usage data once a week to our server
static function send_data($force = false) {
$options = get_option(GMW_OPTIONS);
if ($force == false && (!isset($options['allow_tracking']) || $options['allow_tracking'] !== true)) {
return;
}
if ($force == false && ($options['last_tracking'] && $options['last_tracking'] > strtotime( '-6 days'))) {
return;
}
$data = self::prepare_data();
$request = wp_remote_post('http://www.googlemapswidget.com/tracking.php', array(
'method' => 'POST',
'timeout' => 10,
'redirection' => 3,
'httpversion' => '1.0',
'body' => $data,
'user-agent' => 'GMW/' . GMW::$version));
$options['last_tracking'] = current_time('timestamp');
update_option(GMW_OPTIONS, $options);
} // send_data
// get and prepare data that will be sent out
static function prepare_data() {
$options = get_option(GMW_OPTIONS);
$data = array();
$current_user = wp_get_current_user();
$data['url'] = home_url();
if ($current_user && isset($current_user->user_email) && !empty($current_user->user_email)) {
$data['admin_email'] = $current_user->user_email;
} else {
$data['admin_email'] = get_bloginfo('admin_email');
}
$data['wp_version'] = get_bloginfo('version');
$data['gmw_version'] = GMW::$version;
$data['gmw_first_version'] = $options['first_version'];
$data['gmw_first_install'] = $options['first_install'];
$data['gmw_activated'] = GMW::is_activated();
$data['ioncube'] = extension_loaded('IonCube Loader');
$data['gmw_count'] = self::count_active_widgets();
if (get_bloginfo('version') < '3.4') {
$theme = get_theme_data(get_stylesheet_directory() . '/style.css');
$data['theme_name'] = $theme['Name'];
$data['theme_version'] = $theme['Version'];
} else {
$theme = wp_get_theme();
$data['theme_name'] = $theme->Name;
$data['theme_version'] = $theme->Version;
}
// get current plugin information
if (!function_exists('get_plugins')) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}
$plugins = get_plugins();
$active_plugins = get_option('active_plugins', array());
foreach ($active_plugins as $plugin) {
$data['plugins'][$plugin] = @$plugins[$plugin];
}
return $data;
} // prepare_data
// counts the number of active GMW widgets in sidebars
static function count_active_widgets() {
$count = 0;
$sidebars = get_option('sidebars_widgets', array());
foreach ($sidebars as $sidebar_name => $widgets) {
if (strpos($sidebar_name, 'inactive') !== false || strpos($sidebar_name, 'orphaned') !== false) {
continue;
}
if (is_array($widgets)) {
foreach ($widgets as $widget_name) {
if (strpos($widget_name, 'googlemapswidget') !== false) {
$count++;
}
}
}
} // foreach sidebar
return $count;
} // count_active_widgets
} // class GMW_tracking