Esempio n. 1
0
 /**
  * Annotate the event with all relevant info.
  * @param  mixed		$event Object or (flat) array
  * @return mixed        The transformed event array or WP_Error on failure.
  */
 static function validate_and_sanitize($event)
 {
     $event = (object) $event;
     // Required
     if (!$event->_en) {
         return new WP_Error('invalid_event', 'A valid event must be specified via `_en`', 400);
     }
     // delete non-routable addresses otherwise geoip will discard the record entirely
     if (property_exists($event, '_via_ip') && preg_match('/^192\\.168|^10\\./', $event->_via_ip)) {
         unset($event->_via_ip);
     }
     $validated = array('browser_type' => Jetpack_Tracks_Client::BROWSER_TYPE, '_aua' => Jetpack_Tracks_Client::get_user_agent());
     $_event = (object) array_merge((array) $event, $validated);
     // If you want to blacklist property names, do it here.
     // Make sure we have an event timestamp.
     if (!isset($_event->_ts)) {
         $_event->_ts = Jetpack_Tracks_Client::build_timestamp();
     }
     return $_event;
 }
Esempio n. 2
0
function jetpack_tracks_get_identity($user_id)
{
    // Meta is set, and user is still connected.  Use WPCOM ID
    $wpcom_id = get_user_meta($user_id, 'jetpack_tracks_wpcom_id', true);
    if ($wpcom_id && Jetpack::is_user_connected($user_id)) {
        return array('_ut' => 'wpcom:user_id', '_ui' => $wpcom_id);
    }
    // User is connected, but no meta is set yet.  Use WPCOM ID and set meta.
    if (Jetpack::is_user_connected($user_id)) {
        $wpcom_user_data = Jetpack::get_connected_user_data($user_id);
        add_user_meta($user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'], true);
        return array('_ut' => 'wpcom:user_id', '_ui' => $wpcom_user_data['ID']);
    }
    // User isn't linked at all.  Fall back to anonymous ID.
    $anon_id = get_user_meta($user_id, 'jetpack_tracks_anon_id', true);
    if (!$anon_id) {
        $anon_id = Jetpack_Tracks_Client::get_anon_id();
        add_user_meta($user_id, 'jetpack_tracks_anon_id', $anon_id, false);
    }
    if (!isset($_COOKIE['tk_ai']) && !headers_sent()) {
        setcookie('tk_ai', $anon_id);
    }
    return array('_ut' => 'anon', '_ui' => $anon_id);
}
 function page_admin_scripts()
 {
     if ($this->is_redirecting) {
         return;
         // No need for scripts on a fallback page
     }
     $is_dev_mode = Jetpack::is_development_mode();
     // Enqueue jp.js and localize it
     wp_enqueue_script('react-plugin', plugins_url('_inc/build/admin.js', JETPACK__PLUGIN_FILE), array(), JETPACK__VERSION, true);
     if (!$is_dev_mode) {
         // Required for Analytics
         wp_enqueue_script('jp-tracks', '//stats.wp.com/w.js', array(), gmdate('YW'), true);
     }
     $localeSlug = explode('_', get_locale());
     $localeSlug = $localeSlug[0];
     // Collecting roles that can view site stats
     $stats_roles = array();
     $enabled_roles = function_exists('stats_get_option') ? stats_get_option('roles') : array('administrator');
     foreach (get_editable_roles() as $slug => $role) {
         $stats_roles[$slug] = array('name' => translate_user_role($role['name']), 'canView' => is_array($enabled_roles) ? in_array($slug, $enabled_roles, true) : false);
     }
     $response = rest_do_request(new WP_REST_Request('GET', '/jetpack/v4/module/all'));
     $modules = $response->get_data();
     // Preparing translated fields for JSON encoding by transforming all HTML entities to
     // respective characters.
     foreach ($modules as $slug => $data) {
         $modules[$slug]['name'] = html_entity_decode($data['name']);
         $modules[$slug]['description'] = html_entity_decode($data['description']);
         $modules[$slug]['short_description'] = html_entity_decode($data['short_description']);
         $modules[$slug]['long_description'] = html_entity_decode($data['long_description']);
     }
     // Add objects to be passed to the initial state of the app
     wp_localize_script('react-plugin', 'Initial_State', array('WP_API_root' => esc_url_raw(rest_url()), 'WP_API_nonce' => wp_create_nonce('wp_rest'), 'pluginBaseUrl' => plugins_url('', JETPACK__PLUGIN_FILE), 'connectionStatus' => array('isActive' => Jetpack::is_active(), 'isStaging' => Jetpack::is_staging_site(), 'devMode' => array('isActive' => $is_dev_mode, 'constant' => defined('JETPACK_DEV_DEBUG') && JETPACK_DEV_DEBUG, 'url' => site_url() && false === strpos(site_url(), '.'), 'filter' => apply_filters('jetpack_development_mode', false)), 'isPublic' => '1' == get_option('blog_public'), 'isInIdentityCrisis' => Jetpack::validate_sync_error_idc_option()), 'dismissedNotices' => $this->get_dismissed_jetpack_notices(), 'isDevVersion' => Jetpack::is_development_version(), 'currentVersion' => JETPACK__VERSION, 'happinessGravIds' => jetpack_get_happiness_gravatar_ids(), 'getModules' => $modules, 'showJumpstart' => jetpack_show_jumpstart(), 'rawUrl' => Jetpack::build_raw_urls(get_home_url()), 'adminUrl' => esc_url(admin_url()), 'stats' => array('data' => array('general' => false, 'day' => false, 'week' => false, 'month' => false), 'roles' => $stats_roles), 'settingNames' => array('jetpack_holiday_snow_enabled' => function_exists('jetpack_holiday_snow_option_name') ? jetpack_holiday_snow_option_name() : false), 'userData' => array('currentUser' => jetpack_current_user_data()), 'locale' => $this->get_i18n_data(), 'localeSlug' => $localeSlug, 'jetpackStateNotices' => array('messageCode' => Jetpack::state('message'), 'errorCode' => Jetpack::state('error'), 'errorDescription' => Jetpack::state('error_description')), 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), 'currentIp' => function_exists('jetpack_protect_get_ip') ? jetpack_protect_get_ip() : false));
 }
Esempio n. 4
0
 /**
  * Enqueue scripts for the notice
  */
 function enqueue_idc_notice_files()
 {
     wp_enqueue_script('jetpack-idc-js', plugins_url('_inc/idc-notice.js', JETPACK__PLUGIN_FILE), array('jquery'), JETPACK__VERSION, true);
     wp_localize_script('jetpack-idc-js', 'idcL10n', array('apiRoot' => esc_url_raw(rest_url()), 'nonce' => wp_create_nonce('wp_rest'), 'tracksUserData' => Jetpack_Tracks_Client::get_connected_user_tracks_identity(), 'currentUrl' => remove_query_arg('_wpnonce', remove_query_arg('jetpack_idc_clear_confirmation')), 'tracksEventData' => array('isAdmin' => current_user_can('jetpack_disconnect'), 'currentScreen' => self::$current_screen ? self::$current_screen->id : false)));
     if (!wp_style_is('jetpack-dops-style')) {
         wp_register_style('jetpack-dops-style', plugins_url('_inc/build/admin.dops-style.css', JETPACK__PLUGIN_FILE), array(), JETPACK__VERSION);
     }
     wp_enqueue_style('jetpack-idc-css', plugins_url('css/jetpack-idc.css', JETPACK__PLUGIN_FILE), array('jetpack-dops-style'), JETPACK__VERSION);
     // Required for Tracks
     wp_enqueue_script('jp-tracks', '//stats.wp.com/w.js', array(), gmdate('YW'), true);
     wp_enqueue_script('jp-tracks-functions', plugins_url('_inc/lib/tracks/tracks-callables.js', JETPACK__PLUGIN_FILE), array(), JETPACK__VERSION, false);
 }