/includes/admin/pages/reports.php

  1. <?php 
  2. /** 
  3. * Reports class. 
  4. * 
  5. * @since 6.0.0 
  6. * 
  7. * @package MonsterInsights 
  8. * @subpackage Reports 
  9. * @author Chris Christoff 
  10. */ 
  11.  
  12. // Exit if accessed directly 
  13. if ( ! defined( 'ABSPATH' ) ) { 
  14. exit; 
  15.  
  16. /** 
  17. * Callback for getting all of the reports tabs for MonsterInsights. 
  18. * 
  19. * @since 6.0.0 
  20. * @access public 
  21. * 
  22. * @return array Array of tab information. 
  23. */ 
  24. function monsterinsights_get_reports() { 
  25. /**  
  26. * Developer Alert: 
  27. * 
  28. * Per the README, this is considered an internal hook and should 
  29. * not be used by other developers. This hook's behavior may be modified 
  30. * or the hook may be removed at any time, without warning. 
  31. */ 
  32. $reports = apply_filters( 'monsterinsights_get_reports', array() ); 
  33. return $reports; 
  34.  
  35. /** 
  36. * Callback to output the MonsterInsights reports page. 
  37. * 
  38. * @since 6.0.0 
  39. * @access public 
  40. * 
  41. * @return void 
  42. */ 
  43. function monsterinsights_reports_page() { 
  44. /**  
  45. * Developer Alert: 
  46. * 
  47. * Per the README, this is considered an internal hook and should 
  48. * not be used by other developers. This hook's behavior may be modified 
  49. * or the hook may be removed at any time, without warning. 
  50. */ 
  51. do_action( 'monsterinsights_head' ); 
  52.  
  53. if ( ! current_user_can( 'monsterinsights_view_dashboard' ) ) { 
  54. wp_die( esc_html__( 'Access denied' , 'google-analytics-for-wordpress' ) ); 
  55.  
  56. $dashboard_disabled = monsterinsights_get_option( 'dashboard_disabled', false ); 
  57. $profile_enabled = monsterinsights_get_option( 'analytics_profile', false ); // not using profile 
  58. $oauth_version = monsterinsights_get_option( 'oauth_version', '1.0' ); 
  59. $last_run = monsterinsights_get_option( 'cron_last_run', false ); 
  60. $failed = monsterinsights_get_option( 'cron_failed', false ); 
  61. $pro_access_key = get_option( 'monsterinsights_pro_access_token', false ); 
  62. $lite_access_key = get_option( 'monsterinsights_lite_access_token', false ); 
  63. $needs_re_auth = ( ( $failed && ( $last_run === false || monsterinsights_hours_between( $last_run ) >= 48 ) ) || ( empty( $pro_access_key ) && empty( $lite_access_key ) ) || ( version_compare( $oauth_version, '1.0', '<' ) ) ) ? true : false; 
  64. ?> 
  65. <?php echo monsterinsights_ublock_notice(); ?> 
  66.  
  67. <!-- Tabs --> 
  68. <h1 id="monsterinsights-reports-page-main-nav" class="monsterinsights-main-nav-container monsterinsights-nav-container" data-container="#monsterinsights-reports-pages" data-update-hashbang="1"> 
  69. <?php  
  70. $i = 0; 
  71. ?> 
  72. <a class="monsterinsights-main-nav-item monsterinsights-nav-item monsterinsights-spacing-item" href="#"> </a> 
  73. <?php 
  74. foreach ( (array) monsterinsights_get_reports() as $id => $title ) { 
  75. $class = ( 0 === $i ? 'monsterinsights-active' : '' );  
  76. ?> 
  77. <a class="monsterinsights-main-nav-item monsterinsights-nav-item <?php echo $class; ?>" href="#monsterinsights-main-tab-<?php echo esc_attr( $id ); ?>" title="<?php echo esc_attr( $title ); ?>"> 
  78. <?php echo esc_html( $title ); ?> 
  79. </a> 
  80. <?php  
  81. $i++;  
  82. ?> 
  83. </h1> 
  84.  
  85. <div id="monsterinsights-reports" class="wrap"> 
  86. <div class="monsterinsights-clear"> 
  87. <div class="monsterinsights-reports-action-bar"> 
  88. <div class="monsterinsights-reports-action-bar-title"> 
  89. <?php esc_html_e( 'Reports', 'google-analytics-for-wordpress' );?> 
  90. </div> 
  91. <div class="monsterinsights-reports-action-bar-actions"><?php  
  92. /**  
  93. * Developer Alert: 
  94. * 
  95. * Per the README, this is considered an internal hook and should 
  96. * not be used by other developers. This hook's behavior may be modified 
  97. * or the hook may be removed at any time, without warning. 
  98. */ 
  99. do_action( 'monsterinsights_tab_reports_actions' );  
  100. ?>  
  101. </div> 
  102. </div> 
  103.  
  104. <!-- Tab Panels --> 
  105. <div id="monsterinsights-reports-pages" class="monsterinsights-main-nav-tabs monsterinsights-nav-tabs" data-navigation="#monsterinsights-reports-page-main-nav"> 
  106. <h1 class="monsterinsights-hideme"></h1><!-- so wp notices are below the nav bar --> 
  107. <?php  
  108. $i = 0;  
  109. foreach ( (array) monsterinsights_get_reports() as $id => $title ) { 
  110. $class = ( 0 === $i ? 'monsterinsights-active' : '' );  
  111. ?> 
  112. <div id="monsterinsights-main-tab-<?php echo esc_attr( $id ); ?>" class="monsterinsights-main-nav-tab monsterinsights-nav-tab <?php echo $class; ?>"> 
  113. <?php if ( $dashboard_disabled ) { ?> 
  114. <?php  
  115. if ( current_user_can( 'monsterinsights_save_settings' ) ) { 
  116. echo monsterinsights_get_message( 'error', sprintf( 
  117. sprintf( 
  118. esc_html__( 'Please %1$senable the dashboard%2$s to see report data.', 'google-analytics-for-wordpress' ),  
  119. '<a href="' . admin_url( 'admin.php?page=monsterinsights_settings' ) . '">',  
  120. '</a>' 
  121. ) ); 
  122. } else { 
  123. echo monsterinsights_get_message( 'error', esc_html__( 'The Google oAuth authentication needs to be re-authenticated to view data.', 'google-analytics-for-wordpress' ) ); 
  124. ?> 
  125. <?php } else if ( ! $profile_enabled ) { ?> 
  126. <?php  
  127. if ( current_user_can( 'monsterinsights_save_settings' ) ) { 
  128. echo monsterinsights_get_message( 'error', sprintf( 
  129. sprintf( 
  130. esc_html__( 'Please %1$sauthenticate %2$swith Google Analytics to allow the plugin to fetch data.', 'google-analytics-for-wordpress' ),  
  131. '<a href="' . admin_url( 'admin.php?page=monsterinsights_settings' ) . '">',  
  132. '</a>' 
  133. ) ); 
  134. } else { 
  135. echo monsterinsights_get_message( 'error', esc_html__( 'The Google oAuth authentication needs to be re-authenticated to view data.', 'google-analytics-for-wordpress' ) ); 
  136. ?> 
  137. <?php } else if ( $needs_re_auth ) { ?> 
  138. <?php  
  139. if ( current_user_can( 'monsterinsights_save_settings' ) ) { 
  140. echo monsterinsights_get_message( 'error', sprintf( 
  141. sprintf( 
  142. esc_html__( 'Please %1$sre-authenticate%2$s with Google Analytics to allow the plugin to fetch data.', 'google-analytics-for-wordpress' ),  
  143. '<a href="' . admin_url( 'admin.php?page=monsterinsights_settings' ) . '">',  
  144. '</a>' 
  145. ) ); 
  146. } else { 
  147. echo monsterinsights_get_message( 'error', esc_html__( 'The Google oAuth authentication needs to be re-authenticated to view data.', 'google-analytics-for-wordpress' ) ); 
  148. ?> 
  149. <?php } else if ( $failed ) { ?> 
  150. <?php  
  151. if ( current_user_can( 'monsterinsights_save_settings' ) ) { 
  152. echo monsterinsights_get_message( 'error', sprintf( 
  153. sprintf( 
  154. esc_html__( 'Data is not up-to-date, there was an error in retrieving the data from Google Analytics. This error could be caused by several issues. If the error persists, please see %1$sthis page%2$s.', 'google-analytics-for-wordpress' ),  
  155. '<a href="https://www.monsterinsights.com/docs/blocked-connection/">',  
  156. '</a>' 
  157. ) ); 
  158. } else { 
  159. echo monsterinsights_get_message( 'error', esc_html__( 'The Google oAuth authentication needs to be re-authenticated to view data.', 'google-analytics-for-wordpress' ) ); 
  160. ?> 
  161. <?php } else { ?> 
  162. <div class="monsterinsights-reports-wrap"> 
  163. <?php 
  164. /**  
  165. * Developer Alert: 
  166. * 
  167. * Per the README, this is considered an internal hook and should 
  168. * not be used by other developers. This hook's behavior may be modified 
  169. * or the hook may be removed at any time, without warning. 
  170. */ 
  171. ?> 
  172. <?php do_action( 'monsterinsights_tab_reports_notices' ); ?> 
  173. <?php 
  174. /**  
  175. * Developer Alert: 
  176. * 
  177. * Per the README, this is considered an internal hook and should 
  178. * not be used by other developers. This hook's behavior may be modified 
  179. * or the hook may be removed at any time, without warning. 
  180. */ 
  181. ?> 
  182. <?php do_action( 'monsterinsights_tab_reports_' . $id ); ?> 
  183. </div> 
  184. <?php } ?> 
  185. </div> 
  186. <?php 
  187. $i++; 
  188. ?> 
  189. </div> 
  190. </div> 
  191. </div> 
  192. <?php 
.