stats_dashboard_widget_content

Stats Dashboard Widget Content.

Description

stats_dashboard_widget_content(); 

Usage

  1. if ( !function_exists( 'stats_dashboard_widget_content' ) ) { 
  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_dashboard_widget_content(); 
  7.  

Defined (1)

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

/modules/stats.php  
  1. function stats_dashboard_widget_content() { 
  2. if ( !isset( $_GET['width'] ) || ( !$width = (int) ( $_GET['width'] / 2 ) ) || $width < 250 ) 
  3. $width = 370; 
  4. if ( !isset( $_GET['height'] ) || ( !$height = (int) $_GET['height'] - 36 ) || $height < 230 ) 
  5. $height = 180; 
  6.  
  7. $_width = $width - 5; 
  8. $_height = $height - ( $GLOBALS['is_winIE'] ? 16 : 5 ); // hack! 
  9.  
  10. $blog_id = Jetpack_Options::get_option( 'id' ); 
  11.  
  12. $q = array( 
  13. 'noheader' => 'true',  
  14. 'proxy' => '',  
  15. 'blog' => $blog_id,  
  16. 'page' => 'stats',  
  17. 'chart' => '',  
  18. 'unit' => $options['chart'],  
  19. 'color' => get_user_option( 'admin_color' ),  
  20. 'width' => $_width,  
  21. 'height' => $_height,  
  22. 'ssl' => is_ssl(),  
  23. 'j' => sprintf( '%s:%s', JETPACK__API_VERSION, JETPACK__VERSION ),  
  24. ); 
  25.  
  26. $url = 'https://' . STATS_DASHBOARD_SERVER . "/wp-admin/index.php"; 
  27.  
  28. $url = add_query_arg( $q, $url ); 
  29. $method = 'GET'; 
  30. $timeout = 90; 
  31. $user_id = JETPACK_MASTER_USER
  32.  
  33. $get = Jetpack_Client::remote_request( compact( 'url', 'method', 'timeout', 'user_id' ) ); 
  34. $get_code = wp_remote_retrieve_response_code( $get ); 
  35. if ( is_wp_error( $get ) || ( 2 != intval( $get_code / 100 ) && 304 != $get_code ) || empty( $get['body'] ) ) { 
  36. stats_print_wp_remote_error( $get, $url ); 
  37. } else { 
  38. $body = stats_convert_post_titles($get['body']); 
  39. $body = stats_convert_chart_urls($body); 
  40. $body = stats_convert_image_urls($body); 
  41. echo $body; 
  42.  
  43. $post_ids = array(); 
  44.  
  45. $csv_end_date = date( 'Y-m-d', current_time( 'timestamp' ) ); 
  46. $csv_args = array( 'top' => "&limit=8&end=$csv_end_date", 'search' => "&limit=5&end=$csv_end_date" ); 
  47. /** translators: Stats dashboard widget postviews list: "$post_title $views Views" */ 
  48. $printf = __( '%1$s %2$s Views' , jetpack ); 
  49.  
  50. foreach ( $top_posts = stats_get_csv( 'postviews', "days=$options[top]$csv_args[top]" ) as $i => $post ) { 
  51. if ( $post['post_id'] == 0 ) { 
  52. unset( $top_posts[$i] ); 
  53. continue; 
  54. $post_ids[] = $post['post_id']; 
  55.  
  56. // cache 
  57. get_posts( array( 'include' => join( ', ', array_unique( $post_ids ) ) ) ); 
  58.  
  59. $searches = array(); 
  60. foreach ( $search_terms = stats_get_csv( 'searchterms', "days=$options[search]$csv_args[search]" ) as $search_term ) { 
  61. if ( $search_term['searchterm'] == 'encrypted_search_terms' ) 
  62. continue; 
  63. $searches[] = esc_html( $search_term['searchterm'] ); 
  64.  
  65. ?> 
  66. <a class="button" href="admin.php?page=stats"><?php _e( 'View All', jetpack ); ?></a> 
  67. <div id="stats-info"> 
  68. <div id="top-posts" class='stats-section'> 
  69. <div class="stats-section-inner"> 
  70. <h4 class="heading"><?php _e( 'Top Posts' , jetpack ); ?></h4> 
  71. <?php 
  72. if ( empty( $top_posts ) ) { 
  73. ?> 
  74. <p class="nothing"><?php _e( 'Sorry, nothing to report.', jetpack ); ?></p> 
  75. <?php 
  76. } else { 
  77. foreach ( $top_posts as $post ) { 
  78. if ( !get_post( $post['post_id'] ) ) 
  79. continue; 
  80. ?> 
  81. <p><?php printf( 
  82. $printf,  
  83. '<a href="' . get_permalink( $post['post_id'] ) . '">' . get_the_title( $post['post_id'] ) . '</a>',  
  84. number_format_i18n( $post['views'] ) 
  85. ); ?></p> 
  86. <?php 
  87. ?> 
  88. </div> 
  89. </div> 
  90. <div id="top-search" class='stats-section'> 
  91. <div class="stats-section-inner"> 
  92. <h4 class="heading"><?php _e( 'Top Searches' , jetpack ); ?></h4> 
  93. <?php 
  94. if ( empty( $searches ) ) { 
  95. ?> 
  96. <p class="nothing"><?php _e( 'Sorry, nothing to report.', jetpack ); ?></p> 
  97. <?php 
  98. } else { 
  99. ?> 
  100. <p><?php echo join( ',   ', $searches );?></p> 
  101. <?php 
  102. ?> 
  103. </div> 
  104. </div> 
  105. </div> 
  106. <div class="clear"></div> 
  107. <?php 
  108. exit;