diff options
Diffstat (limited to 'plugins/jetpack/modules/stats.php')
-rw-r--r-- | plugins/jetpack/modules/stats.php | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/plugins/jetpack/modules/stats.php b/plugins/jetpack/modules/stats.php index bcd9deea..6169caa6 100644 --- a/plugins/jetpack/modules/stats.php +++ b/plugins/jetpack/modules/stats.php @@ -202,7 +202,7 @@ function stats_build_view_data() { $blog = Jetpack_Options::get_option( 'id' ); $tz = get_option( 'gmt_offset' ); $v = 'ext'; - $blog_url = parse_url( site_url() ); + $blog_url = wp_parse_url( site_url() ); $srv = $blog_url['host']; $j = sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ); if ( $wp_the_query->is_single || $wp_the_query->is_page || $wp_the_query->is_posts_page ) { @@ -465,7 +465,7 @@ function stats_reports_load() { add_action( 'admin_print_styles', 'stats_reports_css' ); if ( isset( $_GET['nojs'] ) && $_GET['nojs'] ) { - $parsed = parse_url( admin_url() ); + $parsed = wp_parse_url( admin_url() ); // Remember user doesn't want JS. setcookie( 'stnojs', '1', time() + 172800, $parsed['path'] ); // 2 days. } @@ -513,7 +513,7 @@ function stats_reports_css() { * @return void */ function stats_js_remove_stnojs_cookie() { - $parsed = parse_url( admin_url() ); + $parsed = wp_parse_url( admin_url() ); ?> <script type="text/javascript"> /* <![CDATA[ */ @@ -931,7 +931,7 @@ function stats_admin_bar_head() { if ( ! current_user_can( 'view_stats' ) ) return; - if ( function_exists( 'is_admin_bar_showing' ) && ! is_admin_bar_showing() ) { + if ( ! is_admin_bar_showing() ) { return; } @@ -958,7 +958,7 @@ function stats_admin_bar_head() { } #wpadminbar .quicklinks li#wp-admin-bar-stats a img { height: 24px; - padding: 4px 0; + margin: 4px 0; max-width: none; border: none; } @@ -983,7 +983,15 @@ function stats_admin_bar_menu( &$wp_admin_bar ) { $title = esc_attr( __( 'Views over 48 hours. Click for more Site Stats.', 'jetpack' ) ); - $menu = array( 'id' => 'stats', 'title' => "<div><script type='text/javascript'>var src;if(typeof(window.devicePixelRatio)=='undefined'||window.devicePixelRatio<2){src='$img_src';}else{src='$img_src_2x';}document.write('<img src=\''+src+'\' alt=\'$alt\' title=\'$title\' />');</script></div>", 'href' => $url ); + $menu = array( + 'id' => 'stats', + 'href' => $url, + ); + if ( Jetpack_AMP_Support::is_amp_request() ) { + $menu['title'] = "<amp-img src='$img_src_2x' width=112 height=24 layout=fixed alt='$alt' title='$title'></amp-img>"; + } else { + $menu['title'] = "<div><script type='text/javascript'>var src;if(typeof(window.devicePixelRatio)=='undefined'||window.devicePixelRatio<2){src='$img_src';}else{src='$img_src_2x';}document.write('<img src=\''+src+'\' alt=\'$alt\' title=\'$title\' />');</script></div>"; + } $wp_admin_bar->add_menu( $menu ); } @@ -1196,7 +1204,7 @@ function stats_jetpack_dashboard_widget() { <input type="hidden" name="widget_id" value="dashboard_stats" /> <?php submit_button( __( 'Submit', 'jetpack' ) ); ?> </form> - <span id="js-toggle-stats_dashboard_widget_control"> + <span class="js-toggle-stats_dashboard_widget_control"> <?php esc_html_e( 'Configure', 'jetpack' ); ?> </span> <div id="dashboard_stats"> @@ -1206,7 +1214,7 @@ function stats_jetpack_dashboard_widget() { </div> <script> jQuery(document).ready(function($){ - var $toggle = $('#js-toggle-stats_dashboard_widget_control'); + var $toggle = $('.js-toggle-stats_dashboard_widget_control'); $toggle.parent().prev().append( $toggle ); $toggle.show().click(function(e){ @@ -1218,7 +1226,7 @@ function stats_jetpack_dashboard_widget() { }); </script> <style> - #js-toggle-stats_dashboard_widget_control { + .js-toggle-stats_dashboard_widget_control { display: none; float: right; margin-top: 0.2em; @@ -1447,7 +1455,6 @@ function stats_dashboard_widget_content() { } ?> -<a class="button" href="admin.php?page=stats"><?php esc_html_e( 'View All', 'jetpack' ); ?></a> <div id="stats-info"> <div id="top-posts" class='stats-section'> <div class="stats-section-inner"> @@ -1483,15 +1490,28 @@ function stats_dashboard_widget_content() { <p class="nothing"><?php esc_html_e( 'Sorry, nothing to report.', 'jetpack' ); ?></p> <?php } else { -?> - <p><?php echo join( ', ', $searches );?></p> - <?php + foreach ( $searches as $search_term_item ) { + printf( + '<p>%s</p>', + $search_term_item + ); + } } ?> </div> </div> </div> <div class="clear"></div> +<div class="stats-view-all"> +<?php + printf( + '<a class="button" target="_blank" rel="noopener noreferrer" href="%1$s">%2$s</a>', + esc_url( "https://wordpress.com/stats/day/" . Jetpack::build_raw_urls( get_home_url() ) ), + esc_html__( 'View all stats', 'jetpack' ) + ); +?> +</div> +<div class="clear"></div> <?php exit; } @@ -1725,6 +1745,9 @@ function stats_get_from_restapi( $args = array(), $resource = '' ) { $time = key( $stats_cache[ $cache_key ] ); if ( time() - $time < ( 5 * MINUTE_IN_SECONDS ) ) { $cached_stats = $stats_cache[ $cache_key ][ $time ]; + if ( is_wp_error( $cached_stats ) ) { + return $cached_stats; + } $cached_stats = (object) array_merge( array( 'cached_at' => $time ), (array) $cached_stats ); return $cached_stats; } @@ -1734,12 +1757,11 @@ function stats_get_from_restapi( $args = array(), $resource = '' ) { // Do the dirty work. $response = Jetpack_Client::wpcom_json_api_request_as_blog( $endpoint, $api_version, $args ); if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { - // If bad, just return it, don't cache. - return $response; + $data = is_wp_error( $response ) ? $response : new WP_Error( 'stats_error' ); + } else { + $data = json_decode( wp_remote_retrieve_body( $response ) ); } - $data = json_decode( wp_remote_retrieve_body( $response ) ); - // Expire old keys. foreach ( $stats_cache as $k => $cache ) { if ( ! is_array( $cache ) || ( 5 * MINUTE_IN_SECONDS ) < time() - key( $cache ) ) { |