stats_reports_page

Stats Report Page.

Description

stats_reports_page(); 

Usage

  1. if ( !function_exists( 'stats_reports_page' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'jetpack-by-wordpress-com/modules/stats.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = stats_reports_page(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/modules/stats.php  
  1. function stats_reports_page() { 
  2. if ( isset( $_GET['dashboard'] ) ) 
  3.  
  4. $blog_id = stats_get_option( 'blog_id' ); 
  5.  
  6. if ( !isset( $_GET['noheader'] ) && empty( $_GET['nojs'] ) && empty( $_COOKIE['stnojs'] ) ) { 
  7. $nojs_url = add_query_arg( 'nojs', '1' ); 
  8. $http = is_ssl() ? 'https' : 'http'; 
  9. // Loading message 
  10. // No JS fallback message 
  11. ?> 
  12. <div class="wrap"> 
  13. <h2><?php esc_html_e( 'Site Stats', jetpack); ?> <?php if ( current_user_can( 'jetpack_manage_modules' ) ) : ?><a style="font-size:13px;" href="<?php echo esc_url( admin_url('admin.php?page=jetpack&configure=stats') ); ?>"><?php esc_html_e( 'Configure', jetpack); ?></a><?php endif; ?></h2> 
  14. </div> 
  15. <div id="stats-loading-wrap" class="wrap"> 
  16. <p class="hide-if-no-js"><img width="32" height="32" alt="<?php esc_attr_e( 'Loading…', jetpack ); ?>" src="<?php 
  17. /** This filter is documented in modules/shortcodes/audio.php */ 
  18. echo esc_url( apply_filters( 'jetpack_static_url', "{$http}://en.wordpress.com/i/loading/loading-64.gif" ) ); ?>" /></p> 
  19. <p style="font-size: 11pt; margin: 0;"><a href="https://wordpress.com/stats/<?php echo $blog_id; ?>"><?php esc_html_e( 'View stats on WordPress.com right now', jetpack ); ?></a></p> 
  20. <p class="hide-if-js"><?php esc_html_e( 'Your Site Stats work better with Javascript enabled.', jetpack ); ?><br /> 
  21. <a href="<?php echo esc_url( $nojs_url ); ?>"><?php esc_html_e( 'View Site Stats without Javascript', jetpack ); ?></a>.</p> 
  22. </div> 
  23. <?php 
  24. return; 
  25.  
  26. $day = isset( $_GET['day'] ) && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $_GET['day'] ) ? $_GET['day'] : false; 
  27. $q = array( 
  28. 'noheader' => 'true',  
  29. 'proxy' => '',  
  30. 'page' => 'stats',  
  31. 'day' => $day,  
  32. 'blog' => $blog_id,  
  33. 'charset' => get_option( 'blog_charset' ),  
  34. 'color' => get_user_option( 'admin_color' ),  
  35. 'ssl' => is_ssl(),  
  36. 'j' => sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ),  
  37. ); 
  38. if ( get_locale() !== 'en_US' ) { 
  39. $q['jp_lang'] = get_locale(); 
  40. $args = array( 
  41. 'view' => array( 'referrers', 'postviews', 'searchterms', 'clicks', 'post', 'table' ),  
  42. 'numdays' => 'int',  
  43. 'day' => 'date',  
  44. 'unit' => array( 1, 7, 31, 'human' ),  
  45. 'humanize' => array( 'true' ),  
  46. 'num' => 'int',  
  47. 'summarize' => null,  
  48. 'post' => 'int',  
  49. 'width' => 'int',  
  50. 'height' => 'int',  
  51. 'data' => 'data',  
  52. 'blog_subscribers' => 'int',  
  53. 'comment_subscribers' => null,  
  54. 'type' => array( 'wpcom', 'email', 'pending' ),  
  55. 'pagenum' => 'int',  
  56. ); 
  57. foreach ( $args as $var => $vals ) { 
  58. if ( !isset( $_REQUEST[$var] ) ) 
  59. continue; 
  60. if ( is_array( $vals ) ) { 
  61. if ( in_array( $_REQUEST[$var], $vals ) ) 
  62. $q[$var] = $_REQUEST[$var]; 
  63. } elseif ( $vals == 'int' ) { 
  64. $q[$var] = intval( $_REQUEST[$var] ); 
  65. } elseif ( $vals == 'date' ) { 
  66. if ( preg_match( '/^\d{4}-\d{2}-\d{2}$/', $_REQUEST[$var] ) ) 
  67. $q[$var] = $_REQUEST[$var]; 
  68. } elseif ( $vals == null ) { 
  69. $q[$var] = ''; 
  70. } elseif ( $vals == 'data' ) { 
  71. if ( substr( $_REQUEST[$var], 0, 9 ) == 'index.php' ) 
  72. $q[$var] = $_REQUEST[$var]; 
  73.  
  74. if ( isset( $_GET['chart'] ) ) { 
  75. if ( preg_match( '/^[a-z0-9-]+$/', $_GET['chart'] ) ) { 
  76. $chart = sanitize_title( $_GET['chart'] ); 
  77. $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-includes/charts/{$chart}.php"; 
  78. } else { 
  79. $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-admin/index.php"; 
  80.  
  81. $url = add_query_arg( $q, $url ); 
  82. $method = 'GET'; 
  83. $timeout = 90; 
  84. $user_id = JETPACK_MASTER_USER; // means send the wp.com user_id 
  85.  
  86. $get = Jetpack_Client::remote_request( compact( 'url', 'method', 'timeout', 'user_id' ) ); 
  87. $get_code = wp_remote_retrieve_response_code( $get ); 
  88. if ( is_wp_error( $get ) || ( 2 != intval( $get_code / 100 ) && 304 != $get_code ) || empty( $get['body'] ) ) { 
  89. stats_print_wp_remote_error( $get, $url ); 
  90. } else { 
  91. if ( !empty( $get['headers']['content-type'] ) ) { 
  92. $type = $get['headers']['content-type']; 
  93. if ( substr( $type, 0, 5 ) == 'image' ) { 
  94. $img = $get['body']; 
  95. header( 'Content-Type: ' . $type ); 
  96. header( 'Content-Length: ' . strlen( $img ) ); 
  97. echo $img; 
  98. die(); 
  99. $body = stats_convert_post_titles( $get['body'] ); 
  100. $body = stats_convert_chart_urls( $body ); 
  101. $body = stats_convert_image_urls( $body ); 
  102. $body = stats_convert_admin_urls( $body ); 
  103. echo $body; 
  104. if ( isset( $_GET['noheader'] ) ) 
  105. die;