From 5a6ea1e016d3de4ad092db529c8f984a8e940647 Mon Sep 17 00:00:00 2001 From: Peter van Wilderen Date: Wed, 17 Dec 2014 13:54:41 +0100 Subject: [PATCH 01/10] Test connection to google and show a warning --- admin/api-libs | 2 +- admin/class-admin.php | 27 ++++++++++++++++++++++----- admin/pages/settings.php | 22 +++++++++++++++------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/admin/api-libs b/admin/api-libs index 5b71769f..ed4d2715 160000 --- a/admin/api-libs +++ b/admin/api-libs @@ -1 +1 @@ -Subproject commit 5b71769f30a7d796c9225d68353aac2ff7c08f13 +Subproject commit ed4d2715e0fa71f702facb46047fe48b67d40638 diff --git a/admin/class-admin.php b/admin/class-admin.php index e159111e..a9fbabfa 100644 --- a/admin/class-admin.php +++ b/admin/class-admin.php @@ -244,22 +244,26 @@ public function translate_promo() { * * @return bool */ - public function check_google_access() { + public function check_google_access_from_wp() { $can_access_google = true; if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ) { $can_access_google = false; if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) { // Better to use the internal WP logic from this point forward. - $wp_http = new WP_Http(); - if ( $wp_http->block_request( 'https://www.googleapis.com/analytics/v3/management/accountSummaries' ) === false ) { - $can_access_google = true; - } + $can_access_google = $this->test_connection_to_google(); } } return $can_access_google; } + /** + * Check if we can access Google Apis from this server by making a dummy connection + */ + public function check_google_access() { + return $this->test_connection_to_google(); + } + /** * Load the page of a menu item in the GA plugin */ @@ -305,6 +309,19 @@ public function get_profiles() { return $return; } + /** + * Test a connection to Google + * + * @return bool + */ + private function test_connection_to_google(){ + $wp_http = new WP_Http(); + if ( $wp_http->block_request( 'https://www.googleapis.com/analytics/v3/management/accountSummaries' ) === false ) { + return true; + } + + return false; + } /** * Checks if there is a callback or reauth to get token from Google Analytics api diff --git a/admin/pages/settings.php b/admin/pages/settings.php index 254f0066..85d25c96 100644 --- a/admin/pages/settings.php +++ b/admin/pages/settings.php @@ -28,7 +28,11 @@ echo '

' . __( 'General settings', 'google-analytics-for-wordpress' ) . '

'; echo '
'; - if ( $yoast_ga_admin->check_google_access() ) { + + $wp_block_google = $yoast_ga_admin->check_google_access_from_wp(); + $check_google_access = $yoast_ga_admin->check_google_access(); + + if ( $wp_block_google && $check_google_access ) { $profiles = Yoast_GA_Admin_Form::parse_optgroups( $yoast_ga_admin->get_profiles() ); $ga_url = $_SERVER['PHP_SELF']; @@ -48,7 +52,7 @@ echo $yoast_ga_admin->get_tracking_code(); echo '
'; } else { - echo Yoast_GA_Admin_Form::select( __('Analytics profile', 'google-analytics-for-wordpress' ), 'analytics_profile', $profiles, null, false, __( 'Select a profile', 'google-analytics-for-wordpress' ) ); + echo Yoast_GA_Admin_Form::select( __( 'Analytics profile', 'google-analytics-for-wordpress' ), 'analytics_profile', $profiles, null, false, __( 'Select a profile', 'google-analytics-for-wordpress' ) ); echo '
'; echo ''; @@ -59,13 +63,17 @@ echo '
'; echo ''; - echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, __('Please leave this field empty if everything is all right for you', 'google-analytics-for-wordpress') ); + echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, __( 'Please leave this field empty if everything is all right for you', 'google-analytics-for-wordpress' ) ); echo ''; echo '
'; } else { echo '

' . __( 'Cannot connect to Google', 'google-analytics-for-wordpress' ) . '

'; - echo '

' . __( 'Your server is blocking requests to Google, to fix this, add *.googleapis.com to the WP_ACCESSIBLE_HOSTS constant in your wp-config.php or ask your webhost to do this.', 'google-analytics-for-wordpress' ) . '

'; + if ( $wp_block_google == false && $check_google_access == false ) { + echo '

' . __( 'Your server is blocking requests to Google, to fix this, add *.googleapis.com to the WP_ACCESSIBLE_HOSTS constant in your wp-config.php or ask your webhost to do this.', 'google-analytics-for-wordpress' ) . '

'; + } else { + echo '

' . __( 'Your firewall or webhost is blocking requests to Google, to fix this, please ask your webhost company to fix this.', 'google-analytics-for-wordpress' ) . '

'; + } echo '

' . __( 'Until this is fixed, you can only use the manual authentication method and cannot use the dashboards feature.', 'google-analytics-for-wordpress' ) . '

'; } @@ -74,7 +82,7 @@ echo ''; echo '
'; echo Yoast_GA_Admin_Form::input( 'text', null, 'manual_ua_code_field' ); - echo '

' . __('Warning: If you use a manual UA code, you won\'t be able to use the dashboards.', 'google-analytics-for-wordpress') . '

'; + echo '

' . __( 'Warning: If you use a manual UA code, you won\'t be able to use the dashboards.', 'google-analytics-for-wordpress' ) . '

'; echo '
'; echo '
'; ?> @@ -89,7 +97,7 @@
' . __( 'Universal settings', 'google-analytics-for-wordpress' ) . ''; - echo Yoast_GA_Admin_Form::input( 'checkbox', __( 'Enable Universal tracking', 'google-analytics-for-wordpress' ), 'enable_universal', null, sprintf( __( 'First enable Universal tracking in your Google Analytics account. How to do that, please read %1$sthis guide%2$s to learn how to do that.', 'google-analytics-for-wordpress' ), '', '' ) ); + echo Yoast_GA_Admin_Form::input( 'checkbox', __( 'Enable Universal tracking', 'google-analytics-for-wordpress' ), 'enable_universal', null, sprintf( __( 'First enable Universal tracking in your Google Analytics account. How to do that, please read %1$sthis guide%2$s to learn how to do that.', 'google-analytics-for-wordpress' ), '', '' ) ); echo Yoast_GA_Admin_Form::input( 'checkbox', __( 'Enable Demographics and Interest Reports', 'google-analytics-for-wordpress' ), 'demographics', null, sprintf( __( 'You have to enable the Demographics in Google Analytics before you can see the tracking data. We have a doc in our %1$sknowlegde base%2$s about this feature.', 'google-analytics-for-wordpress' ), '', '' ) ); ?>
@@ -139,7 +147,7 @@ jQuery(document).ready( function () { jQuery('#yoast-ga-form-select-settings-analytics_profile').chosen({ - group_search : true + group_search: true }); jQuery('#yoast-ga-form-select-settings-ignore_users').chosen({placeholder_text_multiple: ''}); } From 4c392e932b0b05268eb4691381036b5dc8716c58 Mon Sep 17 00:00:00 2001 From: Peter van Wilderen Date: Wed, 17 Dec 2014 14:37:26 +0100 Subject: [PATCH 02/10] Try again to use options instead of transients [References #84746428] --- admin/class-admin.php | 2 +- .../class-admin-dashboards-collector.php | 4 ++-- .../dashboards/class-admin-dashboards-data.php | 17 +++++------------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/admin/class-admin.php b/admin/class-admin.php index e159111e..da7e69a2 100644 --- a/admin/class-admin.php +++ b/admin/class-admin.php @@ -47,7 +47,7 @@ public function init_settings() { add_action( 'admin_notices', array( $this, 'config_warning' ) ); } - $last_run = get_transient( 'yst_ga_last_wp_run' ); + $last_run = get_option( 'yst_ga_last_wp_run' ); if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 48 ) { // Show error, something went wrong if ( ! is_null( $this->get_tracking_code() && current_user_can( 'manage_options' ) ) ) { diff --git a/admin/dashboards/class-admin-dashboards-collector.php b/admin/dashboards/class-admin-dashboards-collector.php index 777dc66a..6f5eb4f0 100644 --- a/admin/dashboards/class-admin-dashboards-collector.php +++ b/admin/dashboards/class-admin-dashboards-collector.php @@ -141,7 +141,7 @@ public function check_api_call_hook( ) { * @return datetime */ private function get_last_aggregate_run() { - return get_transient( 'yst_ga_last_wp_run' ); + return get_option( 'yst_ga_last_wp_run' ); } /** @@ -399,7 +399,7 @@ private function handle_response( $response, $metric, $dimensions, $start_date, * Success, set a transient which stores the latest runtime */ if ( ! empty( $response ) ) { - set_transient( 'yst_ga_last_wp_run', date( 'Y-m-d' ), 48 * HOUR_IN_SECONDS ); + update_option( 'yst_ga_last_wp_run', date( 'Y-m-d' ) ); } return Yoast_GA_Dashboards_Data::set( $name, $response, strtotime( $start_date ), strtotime( $end_date ), $store_as ); diff --git a/admin/dashboards/class-admin-dashboards-data.php b/admin/dashboards/class-admin-dashboards-data.php index f34e2e9d..06c8128d 100644 --- a/admin/dashboards/class-admin-dashboards-data.php +++ b/admin/dashboards/class-admin-dashboards-data.php @@ -12,13 +12,6 @@ class Yoast_GA_Dashboards_Data { - /** - * The time to store a transient (in seconds) - * - * @var int - */ - private static $store_transient_time = DAY_IN_SECONDS; - /** * Get a data object * @@ -27,16 +20,16 @@ class Yoast_GA_Dashboards_Data { * @return array */ public static function get( $type ) { - $transient = get_transient( 'yst_ga_' . $type ); + $option = get_option( 'yst_ga_' . $type ); - if ( false === $transient ) { - // Transient does not exist, abort + if ( false === $option ) { + // Option does not exist, abort return array(); } // @TODO loop through transient to get the correct date range - return $transient; + return $option; } /** @@ -59,7 +52,7 @@ public static function set( $type, $value, $start_date, $end_date, $store_as ) { 'value' => $value, ); - return set_transient( 'yst_ga_' . $type, $store, self::$store_transient_time ); + return update_option( 'yst_ga_' . $type, $store ); } } From 404b1ed3acc6e1270f1eb6182864ef251e69205a Mon Sep 17 00:00:00 2001 From: Peter van Wilderen Date: Wed, 17 Dec 2014 15:36:15 +0100 Subject: [PATCH 03/10] Show fetching warning only when people dont use manual ua --- admin/class-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/class-admin.php b/admin/class-admin.php index e159111e..0864fb46 100644 --- a/admin/class-admin.php +++ b/admin/class-admin.php @@ -50,7 +50,7 @@ public function init_settings() { $last_run = get_transient( 'yst_ga_last_wp_run' ); if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 48 ) { // Show error, something went wrong - if ( ! is_null( $this->get_tracking_code() && current_user_can( 'manage_options' ) ) ) { + if ( ! is_null( $this->get_tracking_code() && current_user_can( 'manage_options' ) ) && empty( $this->options['manual_ua_code_field'] ) ) { if ( ! isset( $_GET['page'] ) || ( isset( $_GET['page'] ) && $_GET['page'] !== 'yst_ga_settings' ) ) { add_action( 'admin_notices', array( $this, 'warning_fetching_data' ) ); } From 934cf7a05ae7bf54a678b7bc249ae1f615a62884 Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Wed, 17 Dec 2014 15:47:04 +0100 Subject: [PATCH 04/10] Change workflow for retrieve API details --- admin/class-admin-assets.php | 4 +++- admin/class-google-analytics.php | 9 +++++++++ admin/pages/settings.php | 17 ++++++++--------- assets/css/yoast_ga_styles.css | 4 ++++ assets/css/yoast_ga_styles.min.css | 2 +- .../focusable/focus-element-overlay.min.js | 1 + assets/js/yoast_ga_admin.js | 12 ++++++++++-- assets/js/yoast_ga_admin.min.js | 2 +- 8 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 assets/dependencies/focusable/focus-element-overlay.min.js diff --git a/admin/class-admin-assets.php b/admin/class-admin-assets.php index 7a6b1427..5b870117 100644 --- a/admin/class-admin-assets.php +++ b/admin/class-admin-assets.php @@ -11,7 +11,9 @@ class Yoast_GA_Admin_Assets { * Add the scripts to the admin head */ public static function enqueue_scripts() { - wp_enqueue_script( 'yoast_ga_admin', self::get_asset_path( 'assets/js/yoast_ga_admin' ) . self::file_ext( '.js' ), array( 'jquery' ), GAWP_VERSION ); + wp_enqueue_script( 'yoast_focusable', self::get_asset_path( 'assets/dependencies/focusable/focus-element-overlay.min.js' ), array( 'jquery' ), false ); + + wp_enqueue_script( 'yoast_ga_admin', self::get_asset_path( 'assets/js/yoast_ga_admin' ) . self::file_ext( '.js' ), array( 'jquery', 'yoast_focusable' ), GAWP_VERSION ); // Enqueue the qtip js file wp_enqueue_script( 'jquery-qtip', self::get_asset_path( 'assets/dependencies/qtip/jquery.qtip.min.js' ) , array( 'jquery' ), '1.0.0-RC3', true ); diff --git a/admin/class-google-analytics.php b/admin/class-google-analytics.php index f56dce61..4c6f9d25 100644 --- a/admin/class-google-analytics.php +++ b/admin/class-google-analytics.php @@ -152,6 +152,15 @@ protected function set_client() { $this->client = new Yoast_Google_Analytics_Client( $config ); } + /** + * Gets an authentication URL + * + * @return mixed + */ + public function create_auth_url() { + return $this->client->createAuthUrl(); + } + /** * Saving profile response in options * diff --git a/admin/pages/settings.php b/admin/pages/settings.php index 254f0066..c261f699 100644 --- a/admin/pages/settings.php +++ b/admin/pages/settings.php @@ -31,17 +31,16 @@ if ( $yoast_ga_admin->check_google_access() ) { $profiles = Yoast_GA_Admin_Form::parse_optgroups( $yoast_ga_admin->get_profiles() ); - $ga_url = $_SERVER['PHP_SELF']; - if ( isset( $_GET['page'] ) ) { - $ga_url .= '?page=' . $_GET['page']; - } - $ga_url .= '&reauth=true'; + + $auth_url = Yoast_Google_Analytics::get_instance()->create_auth_url(); + add_thickbox(); + echo ''; echo "
"; if ( count( $profiles ) == 0 ) { echo ''; echo '
'; echo ''; @@ -52,14 +51,14 @@ echo ''; } echo '
'; echo '
'; - echo ''; - echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, __('Please leave this field empty if everything is all right for you', 'google-analytics-for-wordpress') ); + echo ''; + echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, null ); echo ''; echo '
'; diff --git a/assets/css/yoast_ga_styles.css b/assets/css/yoast_ga_styles.css index b5b881ad..bba0f599 100644 --- a/assets/css/yoast_ga_styles.css +++ b/assets/css/yoast_ga_styles.css @@ -118,6 +118,10 @@ p.ga-topdescription { width: 325px; } +#yoast-ga-form-settings #oauth_code { + padding: 20px; +} + #yoast-ga-form-settings #oauth_code div { margin: 0 0 0 5px; } diff --git a/assets/css/yoast_ga_styles.min.css b/assets/css/yoast_ga_styles.min.css index 99dcf846..26351da9 100644 --- a/assets/css/yoast_ga_styles.min.css +++ b/assets/css/yoast_ga_styles.min.css @@ -1 +1 @@ -h2#yoast_ga_title{padding:9px 15px 4px 0;font-size:23px;font-weight:400;line-height:29px}.nav-tab-wrapper{margin-bottom:20px}.gatab{display:none}.gatab.active{display:block;padding:.5em .9em;border:1px solid #ddd;border-radius:0 3px 3px;background-color:#fff}.tabwrapper .gatab{padding:0;border:none;background:0 0}.tabwrapper .gatab h2{padding:9px 15px 4px 0;font-size:23px;font-weight:400}.ga-form-submit{margin-top:20px}.ga-form-label-left{float:left;width:250px;margin:0 0 0 5px;font-size:14px;font-weight:700;cursor:default}.ga-form-input{margin-top:10px}#yoast-ga-wrapper{display:table;width:auto;max-width:1150px}.yoast-ga-content{display:table-cell;min-width:850px;height:500px;margin:0;padding:0;vertical-align:top}.yoast-ga-banners{display:table-cell;width:261px;height:500px;margin:0;padding:20px;vertical-align:top}.ga-form-input{display:table;margin-bottom:20px}.ga-form-table{display:table-cell}.ga-form-description{display:block;float:right;max-width:325px;color:#999}p.ga-topdescription{max-width:600px}#ga-promote,.ga-promote{max-width:600px;padding-left:10px;border:1px solid #ccc;background-color:#fff}.ga-promote{margin-bottom:10px}#ga-promote p,.ga-promote p{margin:0;padding:1em 1em 1em 0}#yoast-ga-form-settings input[type=text]{width:325px}#yoast-ga-form-settings #oauth_code div{margin:0 0 0 5px}#yoast-ga-form-settings #oauth_code input[type=text]{width:275px}.ga-form .chosen-search input[type=text]{width:100%!important}.yoast-ga-content .chosen-container{width:325px!important}#enter_ua{display:none;margin-top:10px;padding-top:10px}#yoast-ga-form-text-settings-ga_general-manual_ua_code_field{margin-top:-30px}select.ga-multiple{width:300px;height:150px!important}.wpseotab .extension{float:left;box-sizing:border-box;width:350px;height:230px;margin:10px 20px 10px 0;border:1px solid #ccc}.wpseotab .extension p{margin:0;padding:10px}.wpseotab .extension h3{box-sizing:border-box;height:110px;margin:0;padding:20px 10px 0 120px;border-bottom:1px solid #ccc;background:left 10px/130px 100px no-repeat #fff}.wpseotab .extension button.installed{border-color:#00a000;background-color:#00a000;cursor:default}.wpseotab .extension .button-primary.activate-link{border-color:#f06000;background-color:#f18500}.extension a{text-decoration:none}.ecommerce h3{background-image:url(../img/eComm_130x100.png)!important}.ga_premium h3{background-image:url(../img/ga-premium-banner.png)!important}#ga-debug-info h3{height:30px;margin-top:10px;padding-left:16px;font-size:14px}.yoast_help{margin:2px 5px 0}#enter_ua div{display:inline-block;margin:0} \ No newline at end of file +h2#yoast_ga_title{padding:9px 15px 4px 0;font-size:23px;font-weight:400;line-height:29px}.nav-tab-wrapper{margin-bottom:20px}.gatab{display:none}.gatab.active{display:block;padding:.5em .9em;border:1px solid #ddd;border-radius:0 3px 3px;background-color:#fff}.tabwrapper .gatab{padding:0;border:none;background:0 0}.tabwrapper .gatab h2{padding:9px 15px 4px 0;font-size:23px;font-weight:400}.ga-form-submit{margin-top:20px}.ga-form-label-left{float:left;width:250px;margin:0 0 0 5px;font-size:14px;font-weight:700;cursor:default}.ga-form-input{margin-top:10px}#yoast-ga-wrapper{display:table;width:auto;max-width:1150px}.yoast-ga-content{display:table-cell;min-width:850px;height:500px;margin:0;padding:0;vertical-align:top}.yoast-ga-banners{display:table-cell;width:261px;height:500px;margin:0;padding:20px;vertical-align:top}.ga-form-input{display:table;margin-bottom:20px}.ga-form-table{display:table-cell}.ga-form-description{display:block;float:right;max-width:325px;color:#999}p.ga-topdescription{max-width:600px}#ga-promote,.ga-promote{max-width:600px;padding-left:10px;border:1px solid #ccc;background-color:#fff}.ga-promote{margin-bottom:10px}#ga-promote p,.ga-promote p{margin:0;padding:1em 1em 1em 0}#yoast-ga-form-settings input[type=text]{width:325px}#yoast-ga-form-settings #oauth_code{padding:20px}#yoast-ga-form-settings #oauth_code div{margin:0 0 0 5px}#yoast-ga-form-settings #oauth_code input[type=text]{width:275px}.ga-form .chosen-search input[type=text]{width:100%!important}.yoast-ga-content .chosen-container{width:325px!important}#enter_ua{display:none;margin-top:10px;padding-top:10px}#yoast-ga-form-text-settings-ga_general-manual_ua_code_field{margin-top:-30px}select.ga-multiple{width:300px;height:150px!important}.wpseotab .extension{float:left;box-sizing:border-box;width:350px;height:230px;margin:10px 20px 10px 0;border:1px solid #ccc}.wpseotab .extension p{margin:0;padding:10px}.wpseotab .extension h3{box-sizing:border-box;height:110px;margin:0;padding:20px 10px 0 120px;border-bottom:1px solid #ccc;background:left 10px/130px 100px no-repeat #fff}.wpseotab .extension button.installed{border-color:#00a000;background-color:#00a000;cursor:default}.wpseotab .extension .button-primary.activate-link{border-color:#f06000;background-color:#f18500}.extension a{text-decoration:none}.ecommerce h3{background-image:url(../img/eComm_130x100.png)!important}.ga_premium h3{background-image:url(../img/ga-premium-banner.png)!important}#ga-debug-info h3{height:30px;margin-top:10px;padding-left:16px;font-size:14px}.yoast_help{margin:2px 5px 0}#enter_ua div{display:inline-block;margin:0} \ No newline at end of file diff --git a/assets/dependencies/focusable/focus-element-overlay.min.js b/assets/dependencies/focusable/focus-element-overlay.min.js new file mode 100644 index 00000000..f8f59772 --- /dev/null +++ b/assets/dependencies/focusable/focus-element-overlay.min.js @@ -0,0 +1 @@ +!function(e){function n(){o(),jQuery("body").prepend('
'),p=jQuery("#overlay-layer"),h(),t()}function o(){jQuery.fn.focusable=function(e){return Focusable.setFocus(this,e),this}}function t(){p.on("click",".column",u),jQuery(window).on("resize",i),jQuery(window).on("keyup",d)}function i(){v&&(v=b.findOnResize?jQuery(v.selector):v,c())}function d(e){b.hideOnESC&&27===e.keyCode&&y&&a()}function u(){b.hideOnClick&&a()}function l(e,n){jQuery("body").css("overflow","hidden"),b=jQuery.extend(b,n),v=e,c(),p.fadeIn(b.fadeDuration)}function r(){p.find(".column").remove()}function a(){y=!1,v=null,jQuery("body").css("overflow",""),p.fadeOut(b.fadeDuration,r)}function c(){if(v){var e=0;for(y=!0,r();4>e;)f(e),e++}}function f(e){var n=v.offset(),o=0,t=0,i=s(v.outerWidth()),d="100%",u="";switch(e){case 0:i=s(n.left);break;case 1:t=s(n.left),d=s(n.top);break;case 2:t=s(n.left),o=s(v.outerHeight()+n.top);break;case 3:i="100%",t=s(v.outerWidth()+n.left)}u="top:"+o+";left:"+t+";width:"+i+";height:"+d,p.append('
')}function s(e){return e+"px"}function h(){var e=function(){var e=document.createElement("style");return e.appendChild(document.createTextNode("")),document.head.appendChild(e),e.sheet}();e.insertRule("#overlay-layer{ display:none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999; overflow: hidden; pointer-events: none; }",0),e.insertRule("#overlay-layer .column{ position: absolute; background: rgba(0,0,0,0.8); pointer-events: all; }",1)}var p=null,v=null,y=!1,b={fadeDuration:700,hideOnClick:!1,hideOnESC:!1,findOnResize:!1};jQuery(document).ready(n),e.Focusable={setFocus:l,hide:a,refresh:c}}(window); \ No newline at end of file diff --git a/assets/js/yoast_ga_admin.js b/assets/js/yoast_ga_admin.js index f123bc91..3d2d0d7b 100644 --- a/assets/js/yoast_ga_admin.js +++ b/assets/js/yoast_ga_admin.js @@ -1,3 +1,9 @@ +function yst_popupwindow(url, w, h) { + var left = (screen.width/2)-(w/2); + var top = (screen.height/8); + return window.open(url, '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); +} + jQuery(document).ready(function() { jQuery('#ga-tabs').find('a').click(function() { jQuery('#ga-tabs').find('a').removeClass('nav-tab-active'); @@ -27,7 +33,7 @@ jQuery(document).ready(function() { jQuery('#' + activeTab).addClass('active'); jQuery('#' + activeTab + '-tab').addClass('nav-tab-active'); - function yst_ga_switch_manual() { + function yst_ga_switch_manual() { if ( jQuery('#yoast-ga-form-checkbox-settings-manual_ua_code').is(':checked') ) { jQuery('#enter_ua').show(); jQuery("#yoast-ga-form-select-settings-analytics_profile").prop('disabled', true).trigger("chosen:updated"); @@ -48,7 +54,9 @@ jQuery(document).ready(function() { jQuery('#oauth_code').hide(); jQuery("#yst_ga_authenticate").click( function() { - jQuery('#oauth_code').show().focus(); + jQuery('#oauth_code').show(); + Focusable.setFocus(jQuery('#oauth_code'), {hideOnESC:true}); + jQuery('#oauth_code input').focus(); }); jQuery('.nav-tab-active').click(); diff --git a/assets/js/yoast_ga_admin.min.js b/assets/js/yoast_ga_admin.min.js index b0bd7968..0cbc1eed 100644 --- a/assets/js/yoast_ga_admin.min.js +++ b/assets/js/yoast_ga_admin.min.js @@ -1 +1 @@ -jQuery(document).ready(function(){function a(){jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").is(":checked")?(jQuery("#enter_ua").show(),jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",!0).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",!0),jQuery("#oauth_code").hide()):(jQuery("#enter_ua").hide(),jQuery("#yoast-ga-form-text-settings-manual_ua_code_field").attr("value",""),jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",!1).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",!1),jQuery("#oauth_code").show())}jQuery("#ga-tabs").find("a").click(function(){jQuery("#ga-tabs").find("a").removeClass("nav-tab-active"),jQuery(".gatab").removeClass("active");var a=jQuery(this).attr("id").replace("-tab","");jQuery("#"+a).addClass("active"),jQuery(this).addClass("nav-tab-active"),jQuery("#return_tab").val(a)}),jQuery("a.activate-link").click(function(){jQuery("#extensions.wpseotab").removeClass("active"),jQuery("#extensions-tab").removeClass("nav-tab-active"),jQuery("#licenses.wpseotab").addClass("active"),jQuery("#licenses-tab").addClass("nav-tab-active")});var b=window.location.hash.replace("#top#","");(""===b||"#_=_"===b)&&(b=jQuery(".gatab").attr("id")),jQuery("#"+b).addClass("active"),jQuery("#"+b+"-tab").addClass("nav-tab-active"),jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").click(function(){a()}),a(),jQuery("#oauth_code").hide(),jQuery("#yst_ga_authenticate").click(function(){jQuery("#oauth_code").show().focus()}),jQuery(".nav-tab-active").click(),jQuery(".yoast_help").qtip({position:{corner:{target:"topMiddle",tooltip:"bottomLeft"}},show:{when:{event:"mouseover"}},hide:{fixed:!0,when:{event:"mouseout"}},style:{tip:"bottomLeft",name:"blue"}})}); \ No newline at end of file +function yst_popupwindow(a,b,c){var d=screen.width/2-b/2,e=screen.height/8;return window.open(a,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+b+", height="+c+", top="+e+", left="+d)}jQuery(document).ready(function(){function a(){jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").is(":checked")?(jQuery("#enter_ua").show(),jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",!0).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",!0),jQuery("#oauth_code").hide()):(jQuery("#enter_ua").hide(),jQuery("#yoast-ga-form-text-settings-manual_ua_code_field").attr("value",""),jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",!1).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",!1),jQuery("#oauth_code").show())}jQuery("#ga-tabs").find("a").click(function(){jQuery("#ga-tabs").find("a").removeClass("nav-tab-active"),jQuery(".gatab").removeClass("active");var a=jQuery(this).attr("id").replace("-tab","");jQuery("#"+a).addClass("active"),jQuery(this).addClass("nav-tab-active"),jQuery("#return_tab").val(a)}),jQuery("a.activate-link").click(function(){jQuery("#extensions.wpseotab").removeClass("active"),jQuery("#extensions-tab").removeClass("nav-tab-active"),jQuery("#licenses.wpseotab").addClass("active"),jQuery("#licenses-tab").addClass("nav-tab-active")});var b=window.location.hash.replace("#top#","");(""===b||"#_=_"===b)&&(b=jQuery(".gatab").attr("id")),jQuery("#"+b).addClass("active"),jQuery("#"+b+"-tab").addClass("nav-tab-active"),jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").click(function(){a()}),a(),jQuery("#oauth_code").hide(),jQuery("#yst_ga_authenticate").click(function(){jQuery("#oauth_code").show(),Focusable.setFocus(jQuery("#oauth_code"),{hideOnESC:!0}),jQuery("#oauth_code input").focus()}),jQuery(".nav-tab-active").click(),jQuery(".yoast_help").qtip({position:{corner:{target:"topMiddle",tooltip:"bottomLeft"}},show:{when:{event:"mouseover"}},hide:{fixed:!0,when:{event:"mouseout"}},style:{tip:"bottomLeft",name:"blue"}})}); \ No newline at end of file From bff9b7b9f3dfa20400a833adbe128b67caaa6537 Mon Sep 17 00:00:00 2001 From: Peter van Wilderen Date: Wed, 17 Dec 2014 16:03:58 +0100 Subject: [PATCH 05/10] Function to check if it's allowed to show a warning message --- admin/class-admin.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/admin/class-admin.php b/admin/class-admin.php index 0864fb46..cc94d1b7 100644 --- a/admin/class-admin.php +++ b/admin/class-admin.php @@ -43,17 +43,15 @@ public function init_settings() { // Listener for reconnecting with google analytics $this->google_analytics_listener(); - if ( is_null( $this->get_tracking_code() ) ) { + if ( is_null( $this->get_tracking_code() ) && $this->show_admin_warning() ) { add_action( 'admin_notices', array( $this, 'config_warning' ) ); } $last_run = get_transient( 'yst_ga_last_wp_run' ); - if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 48 ) { + if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 1 ) { // Show error, something went wrong - if ( ! is_null( $this->get_tracking_code() && current_user_can( 'manage_options' ) ) && empty( $this->options['manual_ua_code_field'] ) ) { - if ( ! isset( $_GET['page'] ) || ( isset( $_GET['page'] ) && $_GET['page'] !== 'yst_ga_settings' ) ) { - add_action( 'admin_notices', array( $this, 'warning_fetching_data' ) ); - } + if ( ! is_null( $this->get_tracking_code() ) && empty( $this->options['manual_ua_code_field'] ) && $this->show_admin_warning() ) { + add_action( 'admin_notices', array( $this, 'warning_fetching_data' ) ); } } @@ -161,6 +159,21 @@ public static function ga_deactivation_hook() { } + /** + * Are we allowed to show an warning message? returns true if it's allowed + * + * @return bool + */ + private function show_admin_warning() { + if ( current_user_can( 'manage_options' ) ) { + if ( ! isset( $_GET['page'] ) || ( isset( $_GET['page'] ) && $_GET['page'] !== 'yst_ga_settings' ) ) { + return true; + } + } + + return false; + } + /** * Transform the Profile ID into an helpful UA code * From 6f73205b3cd6b9f597bc6077749c0b9d17b7a0eb Mon Sep 17 00:00:00 2001 From: Peter van Wilderen Date: Wed, 17 Dec 2014 16:21:46 +0100 Subject: [PATCH 06/10] Moved functions to google-analytics class --- admin/class-admin.php | 39 -------------------------------- admin/class-google-analytics.php | 39 ++++++++++++++++++++++++++++++++ admin/pages/settings.php | 7 +++--- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/admin/class-admin.php b/admin/class-admin.php index a9fbabfa..5f0614b6 100644 --- a/admin/class-admin.php +++ b/admin/class-admin.php @@ -239,31 +239,6 @@ public function translate_promo() { return $yoast_ga_i18n; } - /** - * Checks whether we'll ever be able to reach Google. - * - * @return bool - */ - public function check_google_access_from_wp() { - $can_access_google = true; - if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ) { - $can_access_google = false; - if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) { - // Better to use the internal WP logic from this point forward. - $can_access_google = $this->test_connection_to_google(); - } - } - - return $can_access_google; - } - - /** - * Check if we can access Google Apis from this server by making a dummy connection - */ - public function check_google_access() { - return $this->test_connection_to_google(); - } - /** * Load the page of a menu item in the GA plugin */ @@ -309,20 +284,6 @@ public function get_profiles() { return $return; } - /** - * Test a connection to Google - * - * @return bool - */ - private function test_connection_to_google(){ - $wp_http = new WP_Http(); - if ( $wp_http->block_request( 'https://www.googleapis.com/analytics/v3/management/accountSummaries' ) === false ) { - return true; - } - - return false; - } - /** * Checks if there is a callback or reauth to get token from Google Analytics api */ diff --git a/admin/class-google-analytics.php b/admin/class-google-analytics.php index 2ccad39d..3e49a1b6 100644 --- a/admin/class-google-analytics.php +++ b/admin/class-google-analytics.php @@ -128,6 +128,31 @@ public function get_options() { return get_option( $this->option_name ); } + /** + * Checks whether we'll ever be able to reach Google. + * + * @return bool + */ + public function check_google_access_from_wp() { + $can_access_google = true; + if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ) { + $can_access_google = false; + if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) { + // Better to use the internal WP logic from this point forward. + $can_access_google = $this->test_connection_to_google(); + } + } + + return $can_access_google; + } + + /** + * Check if we can access Google Apis from this server by making a dummy connection + */ + public function check_google_access() { + return $this->test_connection_to_google(); + } + /** * Updating the options based on $this->option_name and the internal property $this->options */ @@ -163,6 +188,20 @@ protected function save_profile_response( $accounts ) { $this->update_options(); } + /** + * Test a connection to Google + * + * @return bool + */ + private function test_connection_to_google(){ + $wp_http = new WP_Http(); + if ( $wp_http->block_request( 'https://www.googleapis.com/analytics/v3/management/accountSummaries' ) === false ) { + return true; + } + + return false; + } + /** * Format the accounts request * diff --git a/admin/pages/settings.php b/admin/pages/settings.php index 85d25c96..babafea2 100644 --- a/admin/pages/settings.php +++ b/admin/pages/settings.php @@ -29,9 +29,10 @@ echo '
'; - $wp_block_google = $yoast_ga_admin->check_google_access_from_wp(); - $check_google_access = $yoast_ga_admin->check_google_access(); - + $ga_class = Yoast_Google_Analytics::get_instance(); + $wp_block_google = $ga_class->check_google_access_from_wp(); + $check_google_access = $ga_class->check_google_access(); + if ( $wp_block_google && $check_google_access ) { $profiles = Yoast_GA_Admin_Form::parse_optgroups( $yoast_ga_admin->get_profiles() ); From 5ab3e6efe54e83c310262c807a8720f98b781bbb Mon Sep 17 00:00:00 2001 From: Peter van Wilderen Date: Wed, 17 Dec 2014 16:32:11 +0100 Subject: [PATCH 07/10] Change text label --- admin/pages/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/pages/settings.php b/admin/pages/settings.php index e045d78d..9738e951 100644 --- a/admin/pages/settings.php +++ b/admin/pages/settings.php @@ -72,7 +72,7 @@ if ( $wp_block_google == false && $check_google_access == false ) { echo '

' . __( 'Your server is blocking requests to Google, to fix this, add *.googleapis.com to the WP_ACCESSIBLE_HOSTS constant in your wp-config.php or ask your webhost to do this.', 'google-analytics-for-wordpress' ) . '

'; } else { - echo '

' . __( 'Your firewall or webhost is blocking requests to Google, to fix this, please ask your webhost company to fix this.', 'google-analytics-for-wordpress' ) . '

'; + echo '

' . __( 'Your firewall or webhost is blocking requests to Google, please ask your webhost company to fix this.', 'google-analytics-for-wordpress' ) . '

'; } echo '

' . __( 'Until this is fixed, you can only use the manual authentication method and cannot use the dashboards feature.', 'google-analytics-for-wordpress' ) . '

'; } From 63745085f03ae920d79d0fb4ce3b78a41051d026 Mon Sep 17 00:00:00 2001 From: Peter van Wilderen Date: Wed, 17 Dec 2014 17:44:38 +0100 Subject: [PATCH 08/10] Fixed merge conflict function --- admin/class-admin.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/admin/class-admin.php b/admin/class-admin.php index b67d3d68..4d6f506f 100644 --- a/admin/class-admin.php +++ b/admin/class-admin.php @@ -50,7 +50,7 @@ public function init_settings() { $last_run = get_option( 'yst_ga_last_wp_run' ); if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 48 ) { // Show error, something went wrong - if ( ! is_null( $this->get_tracking_code() ) && empty( $this->options['manual_ua_code_field'] ) && $this->show_admin_warning() ) { + if ( ! is_null( $this->get_tracking_code() ) && empty( $this->options['manual_ua_code_field'] ) && $this->show_admin_warning() ) { add_action( 'admin_notices', array( $this, 'warning_fetching_data' ) ); } } @@ -159,6 +159,21 @@ public static function ga_deactivation_hook() { } + /** + * Are we allowed to show an warning message? returns true if it's allowed + * + * @return bool + */ + private function show_admin_warning() { + if ( current_user_can( 'manage_options' ) ) { + if ( ! isset( $_GET['page'] ) || ( isset( $_GET['page'] ) && $_GET['page'] !== 'yst_ga_settings' ) ) { + return true; + } + } + + return false; + } + /** * Transform the Profile ID into an helpful UA code * From f56e821ff214b93008c4d3cd5a3afdf85282bf65 Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Wed, 17 Dec 2014 19:17:41 +0100 Subject: [PATCH 09/10] Upgrade the submodule includes --- admin/api-libs | 2 +- admin/license-manager | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/api-libs b/admin/api-libs index ed4d2715..bd0df92d 160000 --- a/admin/api-libs +++ b/admin/api-libs @@ -1 +1 @@ -Subproject commit ed4d2715e0fa71f702facb46047fe48b67d40638 +Subproject commit bd0df92dd392ca8d143c9537d2a5f695bdeafae1 diff --git a/admin/license-manager b/admin/license-manager index c07de105..7998010b 160000 --- a/admin/license-manager +++ b/admin/license-manager @@ -1 +1 @@ -Subproject commit c07de105a452e5dab39523c13c41b88f274a1d3d +Subproject commit 7998010b2dbd7dabf54906f30431b56d69a95d31 From 73d6e2aecbce7436077d06e1623d1f49e056c086 Mon Sep 17 00:00:00 2001 From: Andy Meerwaldt Date: Thu, 18 Dec 2014 14:42:32 +0100 Subject: [PATCH 10/10] Going from 5.2.7-beta to 5.2.7 --- googleanalytics.php | 4 ++-- readme.txt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/googleanalytics.php b/googleanalytics.php index c9e2f551..c3d0b742 100644 --- a/googleanalytics.php +++ b/googleanalytics.php @@ -4,7 +4,7 @@ Plugin URI: https://yoast.com/wordpress/plugins/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v504 Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. error page, search result and automatic clickout and download tracking. Author: Team Yoast -Version: 5.2.7-beta +Version: 5.2.7 Requires at least: 3.8 Author URI: https://yoast.com/ License: GPL v3 @@ -30,7 +30,7 @@ // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics, but has since been rewritten and refactored multiple times. -define( 'GAWP_VERSION', '5.2.7-beta' ); +define( 'GAWP_VERSION', '5.2.7' ); define( 'GAWP_FILE', __FILE__ ); diff --git a/readme.txt b/readme.txt index 17422e55..8ed7910e 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://yoast.com/donate/ Tags: analytics, google analytics, statistics, tracking, stats, google, yoast Requires at least: 3.8 Tested up to: 4.1 -Stable tag: 5.2.6 +Stable tag: 5.2.7 Track your WordPress site easily with the latest tracking codes and lots added data for search result pages and error pages. @@ -49,9 +49,9 @@ This section describes how to install the plugin and get it working. == Changelog == -= 5.2.7-beta = += 5.2.7 = -Release Date: December 17th, 2014 +Release Date: December 18th, 2014 * Bugfixes: * Increase timeout limit for request to Google API to prevent quickly session time-outs.