/includes/admin/googleauth.php

  1. <?php 
  2. /** 
  3. * Google oAuth Flow. 
  4. * 
  5. * @since 6.0.0 
  6. * 
  7. * @package MonsterInsights 
  8. * @subpackage Settings 
  9. * @author Chris Christoff 
  10. */ 
  11.  
  12. // Exit if accessed directly 
  13. if ( ! defined( 'ABSPATH' ) ) { 
  14. exit; 
  15.  
  16. function monsterinsights_google_auth_start_view( $reauth = false ) { 
  17. $class = ( $reauth ) ? 'monsterinsights_google_auth_reauth_start_view' : 'monsterinsights_google_auth_start_view' ; 
  18. ob_start();  
  19. ?> 
  20. <div class="<?php echo $class; ?>"> 
  21. <?php if ( $reauth ) { ?> 
  22. <div id="monsterinsights_google_auth_box_header"> 
  23. <div class="monsterinsights_google_auth_box_header_reauth"> 
  24. <?php esc_html_e( 'This process will replace your current Google Analytics connection.', 'google-analytics-for-wordpress' ); ?>  
  25. <a href="" class="monsterinsights_google_auth_box_cancel" title="<?php esc_attr_e( 'Cancel', 'google-analytics-for-wordpress' ); ?>" >  
  26. <?php esc_html_e( 'Cancel', 'google-analytics-for-wordpress' ); ?> 
  27. </a>  
  28. </div> 
  29. </div> 
  30. <?php } ?> 
  31. <div id="monsterinsights_google_auth_box_contents" <?php if ( $reauth ) { echo 'class="monsterinsights_google_auth_reauth"'; } ?> > 
  32. <?php if ( $reauth ) { ?> 
  33. <div class="monsterinsights_google_auth_view_title monsterinsights_google_auth_start_view_title"><?php esc_html_e( 'RE-AUTHENTICATE', 'google-analytics-for-wordpress' ); ?> </div> 
  34. <div class="monsterinsights_google_auth_view_description monsterinsights_google_auth_start_view_description"><?php esc_html_e( 'Re-authenticate your Google Analytics account with MonsterInsights', 'google-analytics-for-wordpress' ); ?> </div> 
  35. <?php } else { ?> 
  36. <div class="monsterinsights_google_auth_view_title monsterinsights_google_auth_view_title monsterinsights_google_auth_start_view_title"><?php esc_html_e( 'AUTHENTICATION', 'google-analytics-for-wordpress' ); ?> </div> 
  37. <div class="monsterinsights_google_auth_view_description monsterinsights_google_auth_start_view_description"><?php esc_html_e( 'Authenticate your Google Analytics account with MonsterInsights', 'google-analytics-for-wordpress' ); ?> </div> 
  38. <?php } ?> 
  39. <input type="hidden" id="monsterinsightsreauth" name="monsterinsightsreauth" value="<?php echo ( $reauth ) ? 'true' : 'false';?>"> 
  40. <input type="hidden" id="monsterinsightsview" name="monsterinsightsview" value="<?php echo 'start';?>"> 
  41. </div> 
  42. <div id="monsterinsights_google_auth_box_footer"> 
  43. <div id="monsterinsights_google_auth_box_footer_left"> 
  44. <a href="#" class="monsterinsights_google_auth_box_cancel" title="<?php esc_attr_e( 'Cancel', 'google-analytics-for-wordpress' ); ?>" > <?php esc_html_e( 'CANCEL', 'google-analytics-for-wordpress' ); ?></a>  
  45. </div> 
  46. <div id="monsterinsights_google_auth_box_footer_center"> 
  47.   
  48. </div> 
  49. <div id="monsterinsights_google_auth_box_footer_right"> 
  50. <a href="#" id="monsterinsights_google_auth_box_next" class="monsterinsights_google_auth_box_next" title="<?php esc_attr_e( 'Next', 'google-analytics-for-wordpress' ); ?>" > 
  51. <div id="monsterinsights_google_auth_box_footer_right_next"> 
  52. <?php esc_html_e( 'NEXT', 'google-analytics-for-wordpress' ); ?>  
  53. </div> 
  54. </a> 
  55. </div> 
  56. </div> 
  57. </div> 
  58. <?php 
  59. $contents = ob_get_contents(); 
  60. ob_end_clean(); 
  61. return $contents; 
  62. function monsterinsights_google_auth_enterkey_view( $reauth = false, $auth_url = '', $error = '' ) { 
  63. $class = ( $reauth ) ? 'monsterinsights_google_auth_reauth_enterkey_view' : 'monsterinsights_google_auth_enterkey_view' ; 
  64. $auth_url = esc_js( esc_url( $auth_url ) ); 
  65. ob_start();  
  66. ?> 
  67. <div class="<?php echo $class; ?>"> 
  68. <?php if ( $reauth ) { ?> 
  69. <div id="monsterinsights_google_auth_box_header"> 
  70. <div class="monsterinsights_google_auth_box_header_reauth"> 
  71. <?php esc_html_e( 'This process will replace your current Google Analytics connection.', 'google-analytics-for-wordpress' ); ?>  
  72. <a href="" class="monsterinsights_google_auth_box_cancel" title="<?php esc_attr_e( 'Cancel', 'google-analytics-for-wordpress' ); ?>" >  
  73. <?php esc_html_e( 'Cancel', 'google-analytics-for-wordpress' ); ?> 
  74. </a>  
  75. </div> 
  76. </div> 
  77. <?php } ?> 
  78. <div id="monsterinsights_google_auth_box_contents" <?php if ( $reauth ) { echo 'class="monsterinsights_google_auth_reauth"'; } ?> > 
  79. <div class="monsterinsights_google_auth_view_title monsterinsights_google_auth_enterkey_view_title"><?php esc_html_e( 'ENTER GOOGLE CODE', 'google-analytics-for-wordpress' ); ?> </div> 
  80. <a id="monsterinsights-google-oauth-window" class="button" onclick="monsterinsights_popupwindow('<?php echo esc_js( esc_attr( esc_url( $auth_url ) ) ); ?>', 500, 500);"><?php esc_html_e( 'Click To Get Google Code', 'google-analytics-for-wordpress' ); ?> </a> 
  81. <label for="monsterinsights_step_data" class="monsterinsights_google_auth_step_data_label_enterkey_view"><?php esc_html_e( 'Copy the Google code into the box below and click next', 'google-analytics-for-wordpress' ); ?> </label> 
  82. <input type="text" id="monsterinsights_step_data" class="monsterinsights_google_auth_step_data_enterkey_view" name="monsterinsights_step_data" placeholder="<?php esc_html_e( 'Paste Google Code here', 'google-analytics-for-wordpress'); ?>"> 
  83. <input type="hidden" id="monsterinsightsreauth" name="monsterinsightsreauth" value="<?php echo ($reauth) ? 'true' : 'false';?>"> 
  84. <input type="hidden" id="monsterinsightsview" name="monsterinsightsview" value="<?php echo 'enterkey';?>"> 
  85. <?php if ( ! empty( $error ) ) { ?> 
  86. <div class="monsterinsights_google_auth_enterkey_error notice notice-warning" style="margin:0px;padding:0px;"><p><?php esc_html_e( $error ); ?><p></div> 
  87. <?php } ?> 
  88. </div> 
  89. <div id="monsterinsights_google_auth_box_footer"> 
  90. <div id="monsterinsights_google_auth_box_footer_left"> 
  91. <a href="#" class="monsterinsights_google_auth_box_cancel" title="<?php esc_attr_e( 'Cancel', 'google-analytics-for-wordpress' ); ?>" > <?php esc_html_e( 'CANCEL', 'google-analytics-for-wordpress' ); ?></a>  
  92. </div> 
  93. <div id="monsterinsights_google_auth_box_footer_center"> 
  94.   
  95. </div> 
  96. <div id="monsterinsights_google_auth_box_footer_right"> 
  97. <a href="#" id="monsterinsights_google_auth_box_next" class="monsterinsights_google_auth_box_next" title="<?php esc_attr_e( 'Next', 'google-analytics-for-wordpress' ); ?>" > 
  98. <div id="monsterinsights_google_auth_box_footer_right_next"> 
  99. <?php esc_html_e( 'NEXT', 'google-analytics-for-wordpress' ); ?>  
  100. </div> 
  101. </a> 
  102. </div> 
  103. </div> 
  104. </div> 
  105. <?php 
  106. $contents = ob_get_contents(); 
  107. ob_end_clean(); 
  108. return $contents;  
  109. function monsterinsights_google_auth_selectprofile_view( $reauth = false, $selectprofile = '', $error = '' ) { 
  110. $class = ( $reauth ) ? 'monsterinsights_google_auth_reauth_selectprofile_view' : 'monsterinsights_google_auth_selectprofile_view' ; 
  111. ob_start();  
  112. ?> 
  113. <div class="<?php echo $class; ?>"> 
  114. <?php if ( $reauth ) { ?> 
  115. <div id="monsterinsights_google_auth_box_header"> 
  116. <div class="monsterinsights_google_auth_box_header_reauth"> 
  117. <?php esc_html_e( 'This process will replace your current Google Analytics connection.', 'google-analytics-for-wordpress' ); ?>  
  118. <a href="" class="monsterinsights_google_auth_box_cancel" title="<?php esc_attr_e( 'Cancel', 'google-analytics-for-wordpress' ); ?>" >  
  119. <?php esc_html_e( 'Cancel', 'google-analytics-for-wordpress' ); ?> 
  120. </a>  
  121. </div> 
  122. </div> 
  123. <?php } ?> 
  124. <div id="monsterinsights_google_auth_box_contents" <?php if ( $reauth ) { echo 'class="monsterinsights_google_auth_reauth"'; } ?> > 
  125.  
  126. <div class="monsterinsights_google_auth_view_title monsterinsights_google_auth_start_view_title"><?php esc_html_e( 'SELECT PROFILE', 'google-analytics-for-wordpress' ); ?> </div> 
  127. <div class="monsterinsights_google_auth_view_description monsterinsights_google_auth_start_view_description"><?php esc_html_e( 'Select the Google Analytics Profile to Use', 'google-analytics-for-wordpress' ); ?> </div> 
  128. <?php echo $selectprofile; ?> 
  129. <input type="hidden" id="monsterinsightsreauth" name="monsterinsightsreauth" value="<?php echo ( $reauth) ? 'true' : 'false';?>"> 
  130. <input type="hidden" id="monsterinsightsview" name="monsterinsightsview" value="<?php echo 'selectprofile';?>"> 
  131. <?php if ( ! empty( $error ) ) { ?> 
  132. <div class="monsterinsights_google_auth_selectprofile_error notice notice-warning" style="margin:0px;padding:0px;"><p><?php esc_html_e( $error ); ?><p></div> 
  133. <?php } ?> 
  134. </div> 
  135. <div id="monsterinsights_google_auth_box_footer"> 
  136. <div id="monsterinsights_google_auth_box_footer_left"> 
  137. <a href="#" class="monsterinsights_google_auth_box_cancel" title="<?php esc_attr_e( 'Cancel', 'google-analytics-for-wordpress' ); ?>" > <?php esc_html_e( 'CANCEL', 'google-analytics-for-wordpress' ); ?></a>  
  138. </div> 
  139. <div id="monsterinsights_google_auth_box_footer_center"> 
  140.   
  141. </div> 
  142. <div id="monsterinsights_google_auth_box_footer_right"> 
  143. <a href="#" id="monsterinsights_google_auth_box_next" class="monsterinsights_google_auth_box_next" title="<?php esc_attr_e( 'Next', 'google-analytics-for-wordpress' ); ?>" > 
  144. <div id="monsterinsights_google_auth_box_footer_right_next"> 
  145. <?php esc_html_e( 'NEXT', 'google-analytics-for-wordpress' ); ?>  
  146. </div> 
  147. </a> 
  148. </div> 
  149. </div> 
  150. </div> 
  151. <?php 
  152. $contents = ob_get_contents(); 
  153. ob_end_clean(); 
  154. return $contents;  
  155. function monsterinsights_google_auth_done_view( $reauth = false ) { 
  156. $class = ( $reauth ) ? 'monsterinsights_google_auth_reauth_done_view' : 'monsterinsights_google_auth_done_view' ; 
  157. ob_start();  
  158. ?> 
  159. <div class="<?php echo $class; ?>"> 
  160. <?php if ( $reauth ) { ?> 
  161. <div id="monsterinsights_google_auth_box_header"> 
  162. <div class="monsterinsights_google_auth_box_header_reauth"> 
  163. <?php esc_html_e( 'Your Google connection has been replaced.', 'google-analytics-for-wordpress' ); ?>  
  164. </div> 
  165. </div> 
  166. <?php } ?> 
  167. <div id="monsterinsights_google_auth_box_contents" <?php if ( $reauth ) { echo 'class="monsterinsights_google_auth_reauth"'; } ?> > 
  168. <div class="monsterinsights_google_auth_view_title monsterinsights_google_auth_start_view_title"><?php esc_html_e( 'DONE', 'google-analytics-for-wordpress' ); ?> </div> 
  169. <div class="monsterinsights_google_auth_view_description monsterinsights_google_auth_start_view_description"><?php esc_html_e( 'You\'re all set!', 'google-analytics-for-wordpress' ); ?> </div> 
  170. <input type="hidden" id="monsterinsightsreauth" name="monsterinsightsreauth" value="<?php echo ( $reauth) ? 'true' : 'false';?>"> 
  171. <input type="hidden" id="monsterinsightsview" name="monsterinsightsview" value="<?php echo 'done';?>"> 
  172. </div> 
  173. <div id="monsterinsights_google_auth_box_footer"> 
  174. <div id="monsterinsights_google_auth_box_footer_left"> 
  175.   
  176. </div> 
  177. <div id="monsterinsights_google_auth_box_footer_center"> 
  178.   
  179. </div> 
  180. <div id="monsterinsights_google_auth_box_footer_right"> 
  181. <a href="#" id="monsterinsights_google_auth_box_done" class="monsterinsights_google_auth_box_done" title="<?php esc_attr_e( 'Save and close', 'google-analytics-for-wordpress' ); ?>" > 
  182. <div id="monsterinsights_google_auth_box_footer_right_next"> 
  183. <?php esc_html_e( 'CLOSE', 'google-analytics-for-wordpress' ); ?>  
  184. </div> 
  185. </a> 
  186. </div> 
  187. </div> 
  188. </div> 
  189. <?php 
  190. $contents = ob_get_contents(); 
  191. ob_end_clean(); 
  192. return $contents;  
  193.  
  194. function monsterinsights_google_auth_error_view( $reauth = false, $error = '' ) { 
  195. $class = ( $reauth ) ? 'monsterinsights_google_auth_reauth_exit_view' : 'monsterinsights_google_auth_exit_view' ; 
  196. ob_start();  
  197. ?> 
  198. <div class="<?php echo $class; ?>"> 
  199. <?php if ( $reauth ) { ?> 
  200. <div id="monsterinsights_google_auth_box_header"> 
  201. <div class="monsterinsights_google_auth_box_header_reauth"> 
  202. <?php esc_html_e( 'An error has occured.', 'google-analytics-for-wordpress' ); ?>  
  203. <a href="" class="monsterinsights_google_auth_box_cancel" title="<?php esc_attr_e( 'Exit', 'google-analytics-for-wordpress' ); ?>" >  
  204. <?php esc_html_e( 'Exit', 'google-analytics-for-wordpress' ); ?> 
  205. </a>  
  206. </div> 
  207. </div> 
  208. <?php } ?> 
  209. <div id="monsterinsights_google_auth_box_contents" <?php if ( $reauth ) { echo 'class="monsterinsights_google_auth_reauth"'; } ?> > 
  210. <div class="monsterinsights_google_auth_view_title monsterinsights_google_auth_exit_view_title"><?php esc_html_e( 'ERROR', 'google-analytics-for-wordpress' ); ?> </div> 
  211. <div class="monsterinsights_google_auth_view_description monsterinsights_google_auth_exit_view_description"><?php echo $error; ?> </div> 
  212. <input type="hidden" id="monsterinsightsreauth" name="monsterinsightsreauth" value="<?php echo ( $reauth) ? 'true' : 'false';?>"> 
  213. <input type="hidden" id="monsterinsightsview" name="monsterinsightsview" value="<?php echo 'done';?>"> 
  214. </div> 
  215. <div id="monsterinsights_google_auth_box_footer"> 
  216. <div id="monsterinsights_google_auth_box_footer_left"> 
  217.   
  218. </div> 
  219. <div id="monsterinsights_google_auth_box_footer_center"> 
  220.   
  221. </div> 
  222. <div id="monsterinsights_google_auth_box_footer_right"> 
  223. <a href="#" id="monsterinsights_google_auth_box_cancel_error" class="monsterinsights_google_auth_box_cancel_error" title="<?php esc_attr_e( 'Exit', 'google-analytics-for-wordpress' ); ?>" > 
  224. <div id="monsterinsights_google_auth_box_footer_right_next"> 
  225. <?php esc_html_e( 'EXIT', 'google-analytics-for-wordpress' ); ?>  
  226. </div> 
  227. </a> 
  228. </div> 
  229. </div> 
  230. </div> 
  231. <?php 
  232. $contents = ob_get_contents(); 
  233. ob_end_clean(); 
  234. return $contents;  
.