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 return stats_dashboard_widget_content(); } $blog_id = Stats_Options::get_option( 'blog_id' ); $stats_url = Redirect::get_url( 'calypso-stats' ); 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 ( 'index.php' === substr( $val, 0, 9 ) ) { $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 ( substr( $type, 0, 5 ) === '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 ); echo $body; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } 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; } } /** * Stats Convert Admin Urls. * * @access public * @param mixed $html HTML. * @return string */ function stats_convert_admin_urls( $html ) { return str_replace( 'index.php?page=stats', 'admin.php?page=stats', $html ); } /** * Stats Convert Image URLs. * * @access public * @param mixed $html HTML. * @return string */ function stats_convert_image_urls( $html ) { $url = set_url_scheme( 'https://' . STATS_DASHBOARD_SERVER ); $html = preg_replace( '|(["\'])(/i/stats.+)\\1|', '$1' . $url . '$2$1', $html ); return $html; } /** * Callback for preg_replace_callback used in stats_convert_chart_urls() * * @since 5.6.0 * * @param array $matches The matches resulting from the preg_replace_callback call. * @return string The admin url for the chart. */ function jetpack_stats_convert_chart_urls_callback( $matches ) { // If there is a query string, change the beginning '?' to a '&' so it fits into the middle of this query string. return 'admin.php?page=stats&noheader&chart=' . $matches[1] . str_replace( '?', '&', $matches[2] ); } /** * Stats Convert Chart URLs. * * @access public * @param mixed $html HTML. * @return string */ function stats_convert_chart_urls( $html ) { $html = preg_replace_callback( '|https?://[-.a-z0-9]+/wp-includes/charts/([-.a-z0-9]+).php(\??)|', 'jetpack_stats_convert_chart_urls_callback', $html ); return $html; } /** * Stats Convert Post Title HTML * * @access public * @param mixed $html HTML. * @return string */ function stats_convert_post_titles( $html ) { global $stats_posts; $pattern = ".*?"; if ( ! preg_match_all( "!$pattern!", $html, $matches ) ) { return $html; } $posts = get_posts( array( 'include' => implode( ',', $matches[1] ), 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => -1, 'suppress_filters' => false, ) ); foreach ( $posts as $post ) { $stats_posts[ $post->ID ] = $post; } $html = preg_replace_callback( "!$pattern!", 'stats_convert_post_title', $html ); return $html; } /** * Stats Convert Post Title Matches. * * @access public * @param mixed $matches Matches. * @return string */ function stats_convert_post_title( $matches ) { global $stats_posts; $post_id = $matches[1]; if ( isset( $stats_posts[ $post_id ] ) ) { return '' . get_the_title( $post_id ) . ''; } return $matches[0]; } /** * CSS to hide the tracking pixel smiley. * It is now hidden for everyone (used to be visible if you had set the hide_smile option). * * @access public * @return void */ function stats_hide_smile_css() { ?> '', 'proxy' => '', 'chart' => $chart, ), $args ), $url ); } /** * Stats AdminBar. * * @access public * @param mixed $wp_admin_bar WPAdminBar. * @return void */ function stats_admin_bar_menu( &$wp_admin_bar ) { $img_src = esc_attr( stats_get_image_chart_src( 'admin-bar-hours-scale' ) ); $img_src_2x = esc_attr( stats_get_image_chart_src( 'admin-bar-hours-scale-2x' ) ); $alt = esc_attr( __( 'Stats', 'jetpack' ) ); $title = esc_attr( __( 'Views over 48 hours. Click for more Jetpack Stats.', 'jetpack' ) ); $menu = array( 'id' => 'stats', 'href' => add_query_arg( 'page', 'stats', admin_url( 'admin.php' ) ), // no menu_page_url() blog-side. 'title' => ".
.
.
' . esc_html( get_the_title( $post['post_id'] ) ) . '', esc_html( number_format_i18n( $post['views'] ) ) ); ?>
%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 ) {
?>
Response code: ""
Content length: ""