'; add_action( 'jetpack_modules_loaded', 'stats_load' ); /** * Load Stats. * * @access public * @return void */ function stats_load() { Jetpack::enable_module_configurable( __FILE__ ); // Only run the callback for those who can see the stats. if ( is_user_logged_in() && current_user_can( 'view_stats' ) ) { add_action( 'wp_head', 'stats_admin_bar_head', 100 ); } add_action( 'jetpack_admin_menu', 'stats_admin_menu' ); add_filter( 'pre_option_db_version', 'stats_ignore_db_version' ); // Add an icon to see stats in WordPress.com for a particular post. add_action( 'admin_print_styles-edit.php', 'jetpack_stats_load_admin_css' ); add_filter( 'manage_posts_columns', 'jetpack_stats_post_table' ); add_filter( 'manage_pages_columns', 'jetpack_stats_post_table' ); add_action( 'manage_posts_custom_column', 'jetpack_stats_post_table_cell', 10, 2 ); add_action( 'manage_pages_custom_column', 'jetpack_stats_post_table_cell', 10, 2 ); // Filter for adding the Jetpack plugin version to tracking stats. add_filter( 'stats_array', 'filter_stats_array_add_jp_version' ); require_once __DIR__ . '/stats/class-jetpack-stats-upgrade-nudges.php'; add_action( 'updating_jetpack_version', array( 'Jetpack_Stats_Upgrade_Nudges', 'unset_nudges_setting' ) ); } /** * Checks if filter is set and dnt is enabled. * * @deprecated 11.5 * @return bool */ function jetpack_is_dnt_enabled() { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Main::jetpack_is_dnt_enabled' ); return Stats::jetpack_is_dnt_enabled(); } /** * Prevent sparkline img requests being redirected to upgrade.php. * See wp-admin/admin.php where it checks $wp_db_version. * * @access public * @param mixed $version Version. * @return string $version. */ function stats_ignore_db_version( $version ) { if ( is_admin() && isset( $_GET['page'] ) && 'stats' === $_GET['page'] && // phpcs:ignore WordPress.Security.NonceVerification.Recommended isset( $_GET['chart'] ) && strpos( $_GET['chart'], 'admin-bar-hours' ) === 0 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput ) { global $wp_db_version; return $wp_db_version; } return $version; } /** * Maps view_stats cap to read cap as needed. * * @deprecated 11.5 * * @access public * @param mixed $caps Caps. * @param mixed $cap Cap. * @param mixed $user_id User ID. * @return array Possibly mapped capabilities for meta capability. */ function stats_map_meta_caps( $caps, $cap, $user_id ) { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Main::map_meta_caps' ); return Stats::map_meta_caps( $caps, $cap, $user_id ); } /** * Stats Template Redirect. * * @deprecated 11.5 * @access public * @return void */ function stats_template_redirect() { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Main::template_redirect' ); Stats::template_redirect(); } /** * Stats Build View Data. * * @deprecated 11.5 * @access public * @return array */ function stats_build_view_data() { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Tracking_Pixel::build_view_data' ); return Stats_Tracking_Pixel::build_view_data(); } /** * Stats Get Options. * * @deprecated 11.5 * * @access public * @return array */ function stats_get_options() { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::get_options' ); return Stats_Options::get_options(); } /** * Get Stats Options. * * @deprecated 11.5 * * @access public * @param mixed $option Option. * @return mixed|null */ function stats_get_option( $option ) { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::get_option' ); return Stats_Options::get_option( $option ); } /** * Stats Set Options. * * @deprecated 11.5 * * @access public * @param mixed $option Option. * @param mixed $value Value. * @return bool */ function stats_set_option( $option, $value ) { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::set_option' ); return Stats_Options::set_option( $option, $value ); } /** * Stats Set Options. * * @deprecated 11.5 * * @access public * @param mixed $options Options. * @return bool */ function stats_set_options( $options ) { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::set_options' ); return Stats_Options::set_options( $options ); } /** * Stats Upgrade Options. * * @deprecated 11.5 * * @access public * @param mixed $options Options. * @return array|bool */ function stats_upgrade_options( $options ) { _deprecated_function( __METHOD__, 'jetpack-11.5', 'Automattic\Jetpack\Stats\Options::upgrade_options' ); return Stats_Options::upgrade_options( $options ); } /** * Admin Pages. * * @access public * @return void */ function stats_admin_menu() { global $pagenow; // If we're at an old Stats URL, redirect to the new one. // Don't even bother with caps, menu_page_url(), etc. Just do it. if ( 'index.php' === $pagenow && isset( $_GET['page'] ) && 'stats' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $redirect_url = str_replace( array( '/wp-admin/index.php?', '/wp-admin/?' ), '/wp-admin/admin.php?', isset( $_SERVER['REQUEST_URI'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : null ); $relative_pos = strpos( $redirect_url, '/wp-admin/' ); if ( false !== $relative_pos ) { wp_safe_redirect( admin_url( substr( $redirect_url, $relative_pos + 10 ) ) ); exit; } } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! ( new Host() )->is_woa_site() && isset( $_GET['enable_new_stats'] ) && '1' === $_GET['enable_new_stats'] ) { // Passing true enables Odyssey Stats. // We're ignorning the return value for now. Stats_Main::update_new_stats_status( true ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! Stats_Options::get_option( 'enable_odyssey_stats' ) || isset( $_GET['noheader'] ) ) { // Show old Jetpack Stats interface for: // - When the "enable_odyssey_stats" option is disabled. // - When being shown in the adminbar outside of wp-admin. $hook = Admin_Menu::add_menu( __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'stats', 'jetpack_admin_ui_stats_report_page_wrapper' ); add_action( "load-$hook", 'stats_reports_load' ); } else { // Enable the new Odyssey Stats experience. $stats_dashboard = new Stats_Dashboard(); $hook = Admin_Menu::add_menu( __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'stats', array( $stats_dashboard, 'render' ), 1 ); add_action( "load-$hook", array( $stats_dashboard, 'admin_init' ) ); } } /** * Stats Admin Path. * * @access public * @return string */ function stats_admin_path() { return Jetpack::module_configuration_url( __FILE__ ); } /** * Stats Reports Load. * * @access public * @return void */ function stats_reports_load() { require_once __DIR__ . '/stats/class-jetpack-stats-upgrade-nudges.php'; Jetpack_Stats_Upgrade_Nudges::init(); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'underscore' ); Jetpack_Admin_Page::load_wrapper_styles(); add_action( 'admin_print_styles', 'stats_reports_css' ); if ( ! empty( $_GET['nojs'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $parsed = wp_parse_url( admin_url() ); // Remember user doesn't want JS. setcookie( 'stnojs', '1', time() + 172800, $parsed['path'], COOKIE_DOMAIN, is_ssl(), true ); // 2 days. } if ( ! empty( $_COOKIE['stnojs'] ) ) { // Detect if JS is on. If so, remove cookie so next page load is via JS. add_action( 'admin_print_footer_scripts', 'stats_js_remove_stnojs_cookie' ); } elseif ( ! isset( $_GET['noheader'] ) && empty( $_GET['nojs'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended // Normal page load. Load page content via JS. add_action( 'admin_print_footer_scripts', 'stats_js_load_page_via_ajax' ); add_action( 'admin_print_footer_scripts', 'stats_script_dismiss_nudge_handler' ); } } /** * JavaScript to dismiss the Odyssey nudge. * * @access public * @return void */ function stats_script_dismiss_nudge_handler() { ?> true ) ); } else { stats_reports_page(); } } /** * Stats Report Page. * * @access public * @param bool $main_chart_only (default: false) Main Chart Only. */ function stats_reports_page( $main_chart_only = false ) { if ( isset( $_GET['dashboard'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended stats_dashboard_widget_content(); exit; // @phan-suppress-current-line PhanPluginUnreachableCode -- Safer to include it even though stats_dashboard_widget_content() never returns. } $blog_id = Stats_Options::get_option( 'blog_id' ); $learn_url = Redirect::get_url( 'jetpack-stats-learn-more' ); $redirect_url = admin_url( 'admin.php?page=stats&enable_new_stats=1' ); $stats_bg_url = plugins_url( 'images/odyssey-upgrade/background.png', JETPACK__PLUGIN_FILE ); $stats_bg_gradient_url = plugins_url( 'images/odyssey-upgrade/gradient.png', JETPACK__PLUGIN_FILE ); if ( ! $main_chart_only && ! isset( $_GET['noheader'] ) && empty( $_GET['nojs'] ) && empty( $_COOKIE['stnojs'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $nojs_url = add_query_arg( 'nojs', '1' ); $http = is_ssl() ? 'https' : 'http'; // Loading message. No JS fallback message. ?>
'true', 'proxy' => '', 'page' => 'stats', 'day' => $day, 'blog' => $blog_id, 'charset' => get_option( 'blog_charset' ), 'color' => get_user_option( 'admin_color' ), 'ssl' => is_ssl(), 'j' => sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ), ); if ( get_locale() !== 'en_US' ) { $q['jp_lang'] = get_locale(); } // Only show the main chart, without extra header data, or metaboxes. $q['main_chart_only'] = $main_chart_only; $args = array( 'view' => array( 'referrers', 'postviews', 'searchterms', 'clicks', 'post', 'table' ), 'numdays' => 'int', 'day' => 'date', 'unit' => array( '1', '7', '31', 'human' ), 'humanize' => array( 'true' ), 'num' => 'int', 'summarize' => null, 'post' => 'int', 'width' => 'int', 'height' => 'int', 'data' => 'data', 'blog_subscribers' => 'int', 'comment_subscribers' => null, 'type' => array( 'wpcom', 'email', 'pending' ), 'pagenum' => 'int', 'masterbar' => null, ); foreach ( $args as $var => $vals ) { if ( ! isset( $_REQUEST[ $var ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended continue; } $val = wp_unslash( $_REQUEST[ $var ] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized if ( is_array( $vals ) ) { if ( in_array( $val, $vals, true ) ) { $q[ $var ] = $val; } } elseif ( 'int' === $vals ) { $q[ $var ] = (int) $val; } elseif ( 'date' === $vals ) { if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $val ) ) { $q[ $var ] = $val; } } elseif ( null === $vals ) { $q[ $var ] = ''; } elseif ( 'data' === $vals ) { if ( str_starts_with( $val, 'index.php' ) ) { $q[ $var ] = $val; } } } if ( isset( $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( preg_match( '/^[a-z0-9-]+$/', $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput $chart = sanitize_title( $_GET['chart'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-includes/charts/{$chart}.php"; } } else { $url = 'https://' . STATS_DASHBOARD_SERVER . '/wp-admin/index.php'; } $url = add_query_arg( $q, $url ); $method = 'GET'; $timeout = 90; $user_id = 0; // Means use the blog token. $get = Client::remote_request( compact( 'url', 'method', 'timeout', 'user_id' ) ); $get_code = wp_remote_retrieve_response_code( $get ); if ( is_wp_error( $get ) || ( 2 !== (int) ( $get_code / 100 ) && 304 !== $get_code ) || empty( $get['body'] ) ) { stats_print_wp_remote_error( $get, $url ); } else { if ( ! empty( $get['headers']['content-type'] ) ) { $type = $get['headers']['content-type']; if ( str_starts_with( $type, 'image' ) ) { $img = $get['body']; header( 'Content-Type: ' . $type ); header( 'Content-Length: ' . strlen( $img ) ); echo $img; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped die(); } } $body = stats_convert_post_titles( $get['body'] ); $body = stats_convert_chart_urls( $body ); $body = stats_convert_image_urls( $body ); $body = stats_convert_admin_urls( $body ); // The response can contain either the content to display OR // the scripts for the chart UI. The following calls inspect the // response, insert the Odyssey nudge as needed, and make sure // everything is output correctly. stats_print_header_section( $body ); stats_print_odyssey_nudge( $body ); stats_print_content_section( $body ); stats_print_chart_scripts( $body ); } if ( isset( $_GET['page'] ) && 'stats' === $_GET['page'] && ! isset( $_GET['chart'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $tracking = new Tracking(); $tracking->record_user_event( 'wpa_page_view', array( 'path' => 'old_stats' ) ); } if ( isset( $_GET['noheader'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended die; } } /** * Legacy Stats: Print Header Section * * @access public * @param mixed $html HTML. * @return void */ function stats_print_header_section( $html ) { $header = stats_parse_header_section( $html ); if ( $header !== '' ) { echo $header; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } /** * Legacy Stats: Print Content Section * * @access public * @param mixed $html HTML. * @return void */ function stats_print_content_section( $html ) { $content = stats_parse_content_section( $html ); if ( $content !== '' ) { echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } /** * Legacy Stats: Print Chart Scripts * * @access public * @param mixed $html HTML. * @return void */ function stats_print_chart_scripts( $html ) { if ( is_chart_scripts( $html ) ) { echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } /** * Legacy Stats: Test for presence of chart scripts * * @access public * @param mixed $html Input HTML that may or may not include the chart scripts. * @return bool */ function is_chart_scripts( $html ) { $pos = strpos( $html, STATS_CONTENT_MARKER ); return $pos === false; } /** * Legacy Stats: Parse Header Section * * Returns the section of the content up to and including the date header. * * @access public * @param mixed $html HTML. * @return string */ function stats_parse_header_section( $html ) { $head = strstr( $html, STATS_CONTENT_MARKER, true ); // Enforce a string result instead of string|false. if ( $head === false ) { return ''; } return $head; } /** * Legacy Stats: Print Content Section * * Returns the section of the content excluding the date header. * * @access public * @param mixed $html HTML. * @return string */ function stats_parse_content_section( $html ) { $body = strstr( $html, STATS_BODY_MARKER ); // Enforce a string result instead of string|false. if ( $body === false ) { return ''; } return $body; } /** * Legacy Stats: Determine if we need to show the Odyssey upgrade nudge. * * @access public * @return boolean */ function stats_should_show_odyssey_nudge() { $stats_notices = ( new Stats_Notices() )->get_notices_to_show(); return isset( $stats_notices[ Stats_Notices::OPT_IN_NEW_STATS_NOTICE_ID ] ) && $stats_notices[ Stats_Notices::OPT_IN_NEW_STATS_NOTICE_ID ]; } /** * Legacy Stats: Print the Odyssey upgrade nudge. * * @access public * @param mixed $html HTML. * @return void */ function stats_print_odyssey_nudge( $html ) { if ( ! stats_should_show_odyssey_nudge() ) { return; } $pos = strpos( $html, STATS_CONTENT_MARKER ); if ( $pos === false ) { return; } $learn_url = Redirect::get_url( 'jetpack-stats-learn-more' ); $redirect_url = admin_url( 'admin.php?page=stats&enable_new_stats=1' ); ?>.
.
.
%s', esc_html__( 'Jetpack Support', 'jetpack' ) ) ); ?>
User Agent: "" Page URL: "http" API URL: "" get_error_codes() as $code ) { foreach ( $get->get_error_messages( $code ) as $message ) { print esc_html( $code ) . ': "' . esc_html( $message ) . '"'; } } } else { $get_code = wp_remote_retrieve_response_code( $get ); $content_length = strlen( wp_remote_retrieve_body( $get ) ); ?> Response code: "" Content length: ""