get_option('blogname'), 'email' => get_option('admin_email'), 'url' => get_option('home')); curl_setopt($c, CURLOPT_POSTFIELDS, $data); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $ret = curl_exec($c); $code = curl_getinfo($c, CURLINFO_HTTP_CODE); curl_close($c); return json_decode($ret, true); } function pulsemaps_upgrade($opts, $first) { // Upgrade possible old widget style option. $style = get_option('pulsemaps_widget', null); if ($style !== null) { delete_option('pulsemaps_widget'); $opts['widget_width'] = 220; $opts['widget_color'] = 'F2EFE8'; $opts['widget_bgcolor'] = '99B2CF'; $opts['custom_color'] = 'F2EFE8'; $opts['custom_bgcolor'] = '99B2CF'; $opts['widget_type'] = 'plain'; if ($style == 'satellite') { $opts['widget_type'] = 'satellite'; } else if ($style == 'monochrome') { $opts['widget_bgcolor'] = '3B3B3B'; } } if (!isset($opts['plan'])) { $opts['plan'] = 'free'; } if (!isset($opts['widget_new_window'])) { $opts['widget_new_window'] = false; } if (!isset($opts['track_all'])) { $opts['track_all'] = false; } if (!isset($opts['widget_dots'])) { $opts['widget_dots'] = true; } if (!isset($opts['widget_meta'])) { $opts['widget_meta'] = '2'; } else if (is_bool($opts['widget_meta'])) { if ($opts['widget_meta']) { $opts['widget_meta'] = '2'; } else { $opts['widget_meta'] = '0'; } } if (!isset($opts['congrats'])) { $opts['congrats'] = false; } if (!isset($opts['activated'])) { $opts['activated'] = true; } global $pulsemaps_version; $opts['version'] = $pulsemaps_version; update_option('pulsemaps_options', $opts); } add_action('plugins_loaded', 'pulsemaps_upgrade_check'); function pulsemaps_upgrade_check() { global $pulsemaps_version; $opts = get_option('pulsemaps_options', array()); if (!isset($opts['version']) || $opts['version'] < $pulsemaps_version) { pulsemaps_upgrade($opts, !isset($opts['version'])); } } register_activation_hook(__FILE__, 'pulsemaps_install'); function pulsemaps_install() { $opts = get_option('pulsemaps_options', array()); if (!pulsemaps_registered()) { $ret = pulsemaps_register(); if ($ret['status'] == 'ok') { $opts['key'] = $ret['key']; $opts['id'] = $ret['id']; } else { error_log(json_encode($ret)); } } if (!isset($opts['widget_width'])) { $opts['widget_width'] = 220; } if (!isset($opts['widget_color'])) { $opts['widget_color'] = 'F2EFE8'; } if (!isset($opts['widget_bgcolor'])) { $opts['widget_bgcolor'] = '99B2CF'; } if (!isset($opts['custom_color'])) { $opts['custom_color'] = 'F2EFE8'; } if (!isset($opts['custom_bgcolor'])) { $opts['custom_bgcolor'] = '99B2CF'; } if (!isset($opts['widget_type'])) { $opts['widget_type'] = 'plain'; } if (!isset($opts['congrats'])) { $opts['congrats'] = false; } if (!isset($opts['activated'])) { $opts['activated'] = false; } if (!isset($opts['after_text'])) { $opts['after_text'] = ''; } update_option('pulsemaps_options', $opts); if (!wp_next_scheduled('pulsemaps_daily')) { wp_schedule_event(time(), 'daily', 'pulsemaps_daily'); } } register_deactivation_hook(__FILE__, 'pulsemaps_uninstall'); function pulsemaps_uninstall() { wp_clear_scheduled_hook('pulsemaps_daily'); } function pulsemaps_refresh() { global $pulsemaps_url; $opts = get_option('pulsemaps_options', array()); $c = curl_init($pulsemaps_url . '/refresh'); $data = array('key' => $opts['key'], 'name' => get_option('blogname'), 'url' => get_option('home')); curl_setopt($c, CURLOPT_POSTFIELDS, $data); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $ret = curl_exec($c); $code = curl_getinfo($c, CURLINFO_HTTP_CODE); curl_close($c); foreach (json_decode($ret, true) as $k => $v) { $opts[$k] = $v; } update_option('pulsemaps_options', $opts); } add_action('pulsemaps_daily', 'pulsemaps_refresh'); function pulsemaps_tracking_active() { if (is_active_widget(false, false, 'pulsemapswidget', true)) { return true; } $opts = get_option('pulsemaps_options', array()); return $opts['track_all']; } function pulsemaps_registered() { $opts = get_option('pulsemaps_options', array()); return isset($opts['key']) && isset($opts['id']); } function pulsemaps_activated() { $opts = get_option('pulsemaps_options', array()); return $opts['activated']; } function pulsemaps_plugin_version() { $plugin_data = get_plugin_data(__FILE__); $plugin_version = $plugin_data['Version']; return $plugin_version; } function pulsemaps_admin_url() { if (function_exists('admin_url')) { return admin_url(); } else { return get_option('siteurl') . '/wp-admin/'; } } function pulsemaps_settings_url() { return pulsemaps_admin_url() . 'options-general.php?page=pulsemaps'; } function pulsemaps_activate_notice() { global $pulsemaps_url; $opts = get_option('pulsemaps_options'); $id = $opts['id']; if (!pulsemaps_activated() && substr($_SERVER["PHP_SELF"], -11) != 'general.php' && $_GET["page"] != "pulsemaps") { echo '

Activate the PulseMaps service on the settings page.

'; } else if (substr($_SERVER["PHP_SELF"], -11) == 'widgets.php') { echo '

Drag the PulseMaps widget to a sidebar on the right to activate.

'; if (!$opts['congrats']) { $opts['congrats'] = true; update_option('pulsemaps_options', $opts); echo ''; } } else { $hide = pulsemaps_tracking_active() || !pulsemaps_activated(); echo ''; } } add_action('admin_notices', 'pulsemaps_activate_notice'); function pulsemaps_widgets_css() { ?> Settings'; array_unshift($links, $link); } return $links; } add_filter('plugin_action_links', 'pulsemaps_plugin_actions', 10, 2); function pulsemaps_async_tracker() { $opts = get_option('pulsemaps_options'); if ($opts['track_all'] && !is_user_logged_in()) { global $pulsemaps_url; ?> \n" . "Website visitor map by PulseMaps.com\n" . "" . "\n"; } add_shortcode('pulsemaps', 'pulsemaps_bigmap');