As the sun rises and the forest mist clears, and the clouds return and the caves darken, these changes of light and shadow are the morning and evening in the mountains. Wildflowers bloom with their subtle fragrance, fine trees flourish with their dense shade, the wind and frost are pure and clean, and the water recedes to reveal the rocks—these are the four seasons in the mountains. Going out in the morning and returning in the evening, the scenery of the four seasons is different, and the joy is endless.至于负者歌于途,行者休于树,前者呼,后者应,伛偻提携,往来而不绝者,滁人游也。临溪而渔,溪深而鱼肥,酿泉为酒,泉香而酒洌,山肴野蔌,杂然而前陈者,太守宴也。宴酣之乐,非丝非竹,射者中,弈者胜,觥筹交错,起坐而喧哗者,众宾欢也。苍颜白发,颓然乎其间者,太守醉也。
<?php
/**
* Tracks class.
*
* @package automattic/jetpack
*/
namespace Automattic\Jetpack\Plugin;
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Tracking as Tracks;
use IXR_Error;
use WP_Error;
use WP_User;
/**
* Tracks class.
*/
class Tracking {
/**
* Tracking object.
*
* @var Tracks
*
* @access private
*/
private $tracking;
/**
* Prevents the Tracking from being initialized more than once.
*
* @var bool
*/
private static $initialized = false;
/**
* Initialization function.
*/
public function init() {
if ( static::$initialized ) {
return;
}
static::$initialized = true;
$this->tracking = new Tracks( 'jetpack' );
// For tracking stuff via js/ajax.
add_action( 'admin_enqueue_scripts', array( $this->tracking, 'enqueue_tracks_scripts' ) );
add_action( 'jetpack_activate_module', array( $this, 'jetpack_activate_module' ), 1, 1 );
add_action( 'jetpack_deactivate_module', array( $this, 'jetpack_deactivate_module' ), 1, 1 );
add_action( 'jetpack_user_authorized', array( $this, 'jetpack_user_authorized' ) );
// Tracking XMLRPC server events.
add_action( 'jetpack_xmlrpc_server_event', array( $this, 'jetpack_xmlrpc_server_event' ), 10, 4 );
// Track that we've begun verifying the previously generated secret.
add_action( 'jetpack_verify_secrets_begin', array( $this, 'jetpack_verify_secrets_begin' ), 10, 2 );
add_action( 'jetpack_verify_secrets_success', array( $this, 'jetpack_verify_secrets_success' ), 10, 2 );
add_action( 'jetpack_verify_secrets_fail', array( $this, 'jetpack_verify_secrets_fail' ), 10, 3 );
add_action( 'jetpack_verify_api_authorization_request_error_double_encode', array( $this, 'jetpack_verify_api_authorization_request_error_double_encode' ) );
add_action( 'jetpack_connection_register_fail', array( $this, 'jetpack_connection_register_fail' ), 10, 2 );
add_action( 'jetpack_connection_register_success', array( $this, 'jetpack_connection_register_success' ) );
}
/**
* Track that a specific module has been activated.
*
* @access public
*
* @param string $module Module slug.
*/
public function jetpack_activate_module( $module ) {
$this->tracking->record_user_event( 'module_activated', array( 'module' => $module ) );
}
/**
* Track that a specific module has been deactivated.
*
* @access public
*
* @param string $module Module slug.
*/
public function jetpack_deactivate_module( $module ) {
$this->tracking->record_user_event( 'module_deactivated', array( 'module' => $module ) );
}
/**
* Track that the user has successfully received an auth token.
*
* @access public
*/
public function jetpack_user_authorized() {
$user_id = get_current_user_id();
$anon_id = get_user_meta( $user_id, 'jetpack_tracks_anon_id', true );
if ( $anon_id ) {
$this->tracking->record_user_event( '_aliasUser', array( 'anonId' => $anon_id ) );
delete_user_meta( $user_id, 'jetpack_tracks_anon_id' );
if ( ! headers_sent() ) {
setcookie( 'tk_ai', 'expired', time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), false ); // phpcs:ignore Jetpack.Functions.SetCookie -- Want this accessible.
}
}
$connection_manager = new Connection_Manager();
$wpcom_user_data = $connection_manager->get_connected_user_data( $user_id );
if ( isset( $wpcom_user_data['ID'] ) ) {
update_user_meta( $user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'] );
}
$this->tracking->record_user_event( 'wpa_user_linked', array() );
}
/**
* Track that we've begun verifying the secrets.
*
* @access public
*
* @param string $action Type of secret (one of 'register', 'authorize', 'publicize').
* @param WP_User $user The user object.
*/
public function jetpack_verify_secrets_begin( $action, $user ) {
$this->tracking->record_user_event( "jpc_verify_{$action}_begin", array(), $user );
}
/**
* Track that we've succeeded in verifying the secrets.
*
* @access public
*
* @param string $action Type of secret (one of 'register', 'authorize', 'publicize').
* @param WP_User $user The user object.
*/
public function jetpack_verify_secrets_success( $action, $user ) {
$this->tracking->record_user_event( "jpc_verify_{$action}_success", array(), $user );
}
/**
* Track that we've failed verifying the secrets.
*
* @access public
*
* @param string $action Type of secret (one of 'register', 'authorize', 'publicize').
* @param WP_User $user The user object.
* @param WP_Error $error Error object.
*/
public function jetpack_verify_secrets_fail( $action, $user, $error ) {
$this->tracking->record_user_event(
"jpc_verify_{$action}_fail",
array(
'error_code' => $error->get_error_code(),
'error_message' => $error->get_error_message(),
),
$user
);
}
/**
* Track a failed login attempt.
*
* @deprecated 13.9 Method is not longer in use.
*/
public function wp_login_failed() {
_deprecated_function( __METHOD__, '13.9' );
}
/**
* Track a connection failure at the registration step.
*
* @access public
*
* @param string|int $error The error code.
* @param WP_Error $registered The error object.
*/
public function jetpack_connection_register_fail( $error, $registered ) {
$this->tracking->record_user_event(
'jpc_register_fail',
array(
'error_code' => $error,
'error_message' => $registered->get_error_message(),
)
);
}
/**
* Track that the registration step of the connection has been successful.
*
* @access public
*
* @param string $from The 'from' GET parameter.
*/
public function jetpack_connection_register_success( $from ) {
$this->tracking->record_user_event(
'jpc_register_success',
array(
'from' => $from,
)
);
}
/**
* Handles the jetpack_xmlrpc_server_event action that combines several types of events that
* happen during request serving.
*
* @param String $action the action name, i.e., 'remote_authorize'.
* @param String $stage the execution stage, can be 'begin', 'success', 'error', etc.
* @param array|WP_Error|IXR_Error $parameters (optional) extra parameters to be passed to the tracked action.
* @param WP_User $user (optional) the acting user.
*/
public function jetpack_xmlrpc_server_event( $action, $stage, $parameters = array(), $user = null ) {
if ( is_wp_error( $parameters ) ) {
$parameters = array(
'error_code' => $parameters->get_error_code(),
'error_message' => $parameters->get_error_message(),
);
} elseif ( is_a( $parameters, IXR_Error::class ) ) {
$parameters = array(
'error_code' => $parameters->code,
'error_message' => $parameters->message,
);
}
$this->tracking->record_user_event( 'jpc_' . $action . '_' . $stage, $parameters, $user );
}
/**
* Track that the site is incorrectly double-encoding redirects from http to https.
*
* @access public
*/
public function jetpack_verify_api_authorization_request_error_double_encode() {
$this->tracking->record_user_event( 'error_double_encode' );
}
}