Advanced Ads - Version 1.29.1

Version Description

  • Fix: ensure Advanced_Ads_Adsense_Report_Helper JavaScript global is defined
  • Fix: hide AdSense setting submit button if there is no publisher ID
  • Fix: show error message when no AdSense account data found
Download this release

Release Info

Developer advancedads
Plugin Icon 128x128 Advanced Ads
Version 1.29.1
Comparing to
See all releases

Code changes from version 1.29.0 to 1.29.1

admin/includes/class-overview-widgets.php CHANGED
@@ -256,8 +256,9 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
256
  ?>
257
  <script>
258
  window.gadsenseData = window.gadsenseData || {};
259
- gadsenseData['pubId'] = '<?php echo esc_html( $pub_id ); ?>';
260
  window.Advanced_Ads_Adsense_Report_Helper.nonce = '<?php echo esc_html( $nonce ); ?>';
 
261
  </script>
262
  <?php
263
  }
@@ -295,22 +296,28 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
295
  if ( wp_verify_nonce( $post_data['nonce'], 'advads-gadsense-dashboard' ) === false ) {
296
  wp_send_json_error( 'Unauthorized request', 401 );
297
  }
298
- $report = new Advanced_Ads_AdSense_Report( $post_data['type'], $post_data['filter'] );
 
 
 
 
 
 
 
299
 
300
  if ( $report->get_data()->is_valid() ) {
301
  // There is valid data
302
  wp_send_json_success( array( 'html' => $report->get_markup() ) );
303
  }
304
 
305
- $got_fresh_report = $report->get_fresh_report();
306
-
307
- if ( $got_fresh_report === true ) {
308
  // we got new data from Google;
309
  wp_send_json_success( array( 'html' => $report->get_markup() ) );
310
  }
311
 
 
312
  // Send markup with error info.
313
- wp_send_json_success( array( 'html' => '<div class="error"><p>' . $got_fresh_report . '</p></div>' ) );
314
  }
315
 
316
  /**
256
  ?>
257
  <script>
258
  window.gadsenseData = window.gadsenseData || {};
259
+ window.Advanced_Ads_Adsense_Report_Helper = window.Advanced_Ads_Adsense_Report_Helper || {};
260
  window.Advanced_Ads_Adsense_Report_Helper.nonce = '<?php echo esc_html( $nonce ); ?>';
261
+ gadsenseData['pubId'] = '<?php echo esc_html( $pub_id ); ?>';
262
  </script>
263
  <?php
264
  }
296
  if ( wp_verify_nonce( $post_data['nonce'], 'advads-gadsense-dashboard' ) === false ) {
297
  wp_send_json_error( 'Unauthorized request', 401 );
298
  }
299
+ $report_type = in_array( $post_data['type'], array( 'domain', 'unit' ), true ) ? $post_data['type'] : false;
300
+
301
+ if ( ! $report_type ) {
302
+ wp_send_json_error( 'Invalid arguments', 400 );
303
+ }
304
+
305
+ $report_filter = wp_strip_all_tags( $post_data['filter'] );
306
+ $report = new Advanced_Ads_AdSense_Report( $report_type, $report_filter );
307
 
308
  if ( $report->get_data()->is_valid() ) {
309
  // There is valid data
310
  wp_send_json_success( array( 'html' => $report->get_markup() ) );
311
  }
312
 
313
+ if ( $report->refresh_report() ) {
 
 
314
  // we got new data from Google;
315
  wp_send_json_success( array( 'html' => $report->get_markup() ) );
316
  }
317
 
318
+ $error_message = $report->get_last_api_error();
319
  // Send markup with error info.
320
+ wp_send_json_success( array( 'html' => '<div class="error"><p>' . wp_kses_post( $error_message ) . '</p></div>' ) );
321
  }
322
 
323
  /**
advanced-ads.php CHANGED
@@ -12,7 +12,7 @@
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: https://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
- * Version: 1.29.0
16
  * Author: Thomas Maier, Advanced Ads GmbH
17
  * Author URI: https://wpadvancedads.com
18
  * Text Domain: advanced-ads
@@ -39,7 +39,7 @@ define( 'ADVADS_BASE_DIR', dirname( ADVADS_BASE ) ); // directory of the plugin
39
  // general and global slug, e.g. to store options in WP.
40
  define( 'ADVADS_SLUG', 'advanced-ads' );
41
  define( 'ADVADS_URL', 'https://wpadvancedads.com/' );
42
- define( 'ADVADS_VERSION', '1.29.0' );
43
 
44
  // Autoloading, modules and functions.
45
 
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: https://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
+ * Version: 1.29.1
16
  * Author: Thomas Maier, Advanced Ads GmbH
17
  * Author URI: https://wpadvancedads.com
18
  * Text Domain: advanced-ads
39
  // general and global slug, e.g. to store options in WP.
40
  define( 'ADVADS_SLUG', 'advanced-ads' );
41
  define( 'ADVADS_URL', 'https://wpadvancedads.com/' );
42
+ define( 'ADVADS_VERSION', '1.29.1' );
43
 
44
  // Autoloading, modules and functions.
45
 
languages/advanced-ads.pot CHANGED
@@ -2,14 +2,14 @@
2
  # This file is distributed under the same license as the Advanced Ads plugin.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Advanced Ads 1.29.0\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/advanced-ads/\n"
7
  "Last-Translator: Thomas Maier <post@webzunft.de>\n"
8
  "Language-Team: webgilde <support@wpadvancedads.com>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
- "POT-Creation-Date: 2021-10-05T10:37:17+02:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.4.0\n"
15
  "X-Domain: advanced-ads\n"
@@ -52,24 +52,24 @@ msgid "After which paragraph?"
52
  msgstr ""
53
 
54
  #: admin/class-advanced-ads-admin.php:220
55
- #: modules/gadsense/includes/class-adsense-report.php:126
56
  msgid "Today"
57
  msgstr ""
58
 
59
  #: admin/class-advanced-ads-admin.php:221
60
- #: modules/gadsense/includes/class-adsense-report.php:127
61
  msgid "Yesterday"
62
  msgstr ""
63
 
64
  #: admin/class-advanced-ads-admin.php:222
65
- #: modules/gadsense/includes/class-adsense-report.php:130
66
  msgid "This Month"
67
  msgstr ""
68
 
69
  #. translators: 1: The number of days.
70
  #: admin/class-advanced-ads-admin.php:224
71
- #: modules/gadsense/includes/class-adsense-report.php:129
72
- #: modules/gadsense/includes/class-adsense-report.php:132
73
  msgid "Last %1$d days"
74
  msgstr ""
75
 
@@ -458,7 +458,7 @@ msgid "Pro Feature"
458
  msgstr ""
459
 
460
  #: admin/includes/class-admin-upgrades.php:107
461
- #: admin/includes/class-overview-widgets.php:453
462
  msgid "A quick and error-free way of implementing ad units from your Google Ad Manager account."
463
  msgstr ""
464
 
@@ -801,133 +801,133 @@ msgstr ""
801
  msgid "Show %s hidden notices"
802
  msgstr ""
803
 
804
- #: admin/includes/class-overview-widgets.php:348
805
  msgid "How to download, install and activate an add-on."
806
  msgstr ""
807
 
808
- #: admin/includes/class-overview-widgets.php:356
809
  msgid "The solution for professional websites."
810
  msgstr ""
811
 
812
- #: admin/includes/class-overview-widgets.php:365
813
  #: admin/views/upgrades/pro-tab.php:7
814
  msgid "support for cached sites"
815
  msgstr ""
816
 
817
  #. translators: %s is the name of another plugin.
818
- #: admin/includes/class-overview-widgets.php:381
819
- #: admin/includes/class-overview-widgets.php:393
820
- #: admin/includes/class-overview-widgets.php:405
821
- #: admin/includes/class-overview-widgets.php:417
822
  msgid "integrates with <strong>%s</strong>"
823
  msgstr ""
824
 
825
- #: admin/includes/class-overview-widgets.php:422
826
  msgid "click fraud protection, lazy load, ad-block ads"
827
  msgstr ""
828
 
829
- #: admin/includes/class-overview-widgets.php:423
830
  #: admin/views/upgrades/pro-tab.php:8
831
  msgid "11 more display and visitor conditions"
832
  msgstr ""
833
 
834
- #: admin/includes/class-overview-widgets.php:424
835
  #: admin/views/upgrades/pro-tab.php:9
836
  msgid "6 more placements"
837
  msgstr ""
838
 
839
- #: admin/includes/class-overview-widgets.php:425
840
  #: admin/views/upgrades/pro-tab.php:10
841
  msgid "placement tests for ad optimization"
842
  msgstr ""
843
 
844
- #: admin/includes/class-overview-widgets.php:426
845
  #: admin/views/upgrades/pro-tab.php:11
846
  msgid "ad grids and many more advanced features"
847
  msgstr ""
848
 
849
- #: admin/includes/class-overview-widgets.php:441
850
  msgid "Analyze clicks and impressions of your ads locally or in Google Analytics, share reports, and limit ads to a specific number of impressions or clicks."
851
  msgstr ""
852
 
853
- #: admin/includes/class-overview-widgets.php:447
854
  msgid "Display ads based on the device or the size of your visitor’s browser, and control ads on AMP pages."
855
  msgstr ""
856
 
857
- #: admin/includes/class-overview-widgets.php:459
858
  msgid "Increase click rates on your ads by placing them in sticky positions above, next or below your site."
859
  msgstr ""
860
 
861
- #: admin/includes/class-overview-widgets.php:465
862
  msgid "Users will never miss an ad or other information in a PopUp. Choose when it shows up and for how long a user can close it."
863
  msgstr ""
864
 
865
- #: admin/includes/class-overview-widgets.php:471
866
  msgid "Target visitors with ads that match their geo location and make more money with regional campaigns."
867
  msgstr ""
868
 
869
- #: admin/includes/class-overview-widgets.php:477
870
  msgid "Earn more money and let advertisers pay for ad space directly on the frontend of your site."
871
  msgstr ""
872
 
873
- #: admin/includes/class-overview-widgets.php:483
874
  msgid "Create a beautiful and simple slider from your ads to show more information on less space."
875
  msgstr ""
876
 
877
- #: admin/includes/class-overview-widgets.php:489
878
  msgid "Place AdSense In-feed ads between posts on homepage, category, and archive pages."
879
  msgstr ""
880
 
881
- #: admin/includes/class-overview-widgets.php:492
882
- #: admin/includes/class-overview-widgets.php:682
883
- #: admin/includes/class-overview-widgets.php:698
884
  msgid "Install now"
885
  msgstr ""
886
 
887
- #: admin/includes/class-overview-widgets.php:510
888
- #: admin/includes/class-overview-widgets.php:528
889
- #: admin/includes/class-overview-widgets.php:553
890
- #: admin/includes/class-overview-widgets.php:571
891
- #: admin/includes/class-overview-widgets.php:589
892
- #: admin/includes/class-overview-widgets.php:607
893
- #: admin/includes/class-overview-widgets.php:625
894
- #: admin/includes/class-overview-widgets.php:643
895
- #: admin/includes/class-overview-widgets.php:661
896
  msgid "Activate now"
897
  msgstr ""
898
 
899
- #: admin/includes/class-overview-widgets.php:536
900
  msgid "Visit your ad statistics"
901
  msgstr ""
902
 
903
- #: admin/includes/class-overview-widgets.php:678
904
  msgid "Use Genesis specific ad positions."
905
  msgstr ""
906
 
907
- #: admin/includes/class-overview-widgets.php:694
908
  msgid "Manage ad positions with WPBakery Page Builder (formerly Visual Composer)."
909
  msgstr ""
910
 
911
- #: admin/includes/class-overview-widgets.php:710
912
  msgid "Our best deal with all add-ons included."
913
  msgstr ""
914
 
915
- #: admin/includes/class-overview-widgets.php:712
916
- #: admin/includes/class-overview-widgets.php:728
917
  msgid "Get full access"
918
  msgstr ""
919
 
920
- #: admin/includes/class-overview-widgets.php:726
921
  msgid "A one-time payment for four years of support and updates. The package saves you up to 70% compared to individually purchasing our add-ons."
922
  msgstr ""
923
 
924
- #: admin/includes/class-overview-widgets.php:744
925
  #: admin/views/conditions/ad-display-metabox.php:37
926
  #: admin/views/conditions/ad-visitor-metabox.php:37
927
  msgid "Visit the manual"
928
  msgstr ""
929
 
930
- #: admin/includes/class-overview-widgets.php:747
931
  msgid "Get this add-on"
932
  msgstr ""
933
 
@@ -2534,7 +2534,7 @@ msgstr ""
2534
 
2535
  #. translators: %1$s is an anchor (link) opening tag, %2$s is the closing tag.
2536
  #: classes/ad-health-notices.php:865
2537
- #: modules/gadsense/includes/class-mapi.php:1648
2538
  msgid "Learn more about AdSense account issues %1$shere%2$s."
2539
  msgstr ""
2540
 
@@ -3719,13 +3719,13 @@ msgid "Enable AMP Auto ads"
3719
  msgstr ""
3720
 
3721
  #. translators: AdSense ID.
3722
- #: modules/gadsense/includes/adsense-report-api.php:129
3723
  msgid "Error while retrieving report for \"%s\"."
3724
  msgstr ""
3725
 
3726
  #. translators: AdSense ID.
3727
- #: modules/gadsense/includes/adsense-report-api.php:140
3728
- #: modules/gadsense/includes/adsense-report-api.php:149
3729
  msgid "Invalid response while retrieving report for \"%s\"."
3730
  msgstr ""
3731
 
@@ -3741,7 +3741,7 @@ msgstr ""
3741
  msgid "Your AdSense Publisher ID is missing."
3742
  msgstr ""
3743
 
3744
- #: modules/gadsense/includes/class-adsense-report.php:82
3745
  msgid "No valid tokens"
3746
  msgstr ""
3747
 
@@ -3755,115 +3755,115 @@ msgid "Error while retrieving ad code for \"%s\"."
3755
  msgstr ""
3756
 
3757
  #. translators: %s: ad unit ID.
3758
- #: modules/gadsense/includes/class-mapi.php:399
3759
  msgid "Invalid response while retrieving ad code for \"%s\"."
3760
  msgstr ""
3761
 
3762
  #. translators: the publisher ID.
3763
- #: modules/gadsense/includes/class-mapi.php:458
3764
- #: modules/gadsense/includes/class-mapi.php:528
3765
  msgid "Error while retrieving adUnits list for \"%s\"."
3766
  msgstr ""
3767
 
3768
  #. translators: %s is the publisher ID.
3769
- #: modules/gadsense/includes/class-mapi.php:466
3770
  msgid "Invalid response while retrieving adUnits list for \"%s\"."
3771
  msgstr ""
3772
 
3773
- #: modules/gadsense/includes/class-mapi.php:474
3774
  msgid "Reason:"
3775
  msgstr ""
3776
 
3777
- #: modules/gadsense/includes/class-mapi.php:475
3778
  msgid "Message:"
3779
  msgstr ""
3780
 
3781
  #. translators: %1$s is the AdSense publisher ID; %2$s a starting a tag to the AdSense ad unit list and %3$s the closing link.
3782
- #: modules/gadsense/includes/class-mapi.php:489
3783
  msgid "The account \"%1$s\" does not seem to have any ad units. Please create some %2$shere%3$s."
3784
  msgstr ""
3785
 
3786
- #: modules/gadsense/includes/class-mapi.php:606
3787
  msgid "It seems that some changes have been made in the Advanced Ads settings. Please refresh this page."
3788
  msgstr ""
3789
 
3790
- #: modules/gadsense/includes/class-mapi.php:613
3791
  msgid "Advanced Ads does not have access to your account (<code>%s</code>) anymore."
3792
  msgstr ""
3793
 
3794
- #: modules/gadsense/includes/class-mapi.php:657
3795
  msgid "error while renewing access token for \"%s\""
3796
  msgstr ""
3797
 
3798
  #. translators: %s AdSense account ID
3799
- #: modules/gadsense/includes/class-mapi.php:684
3800
  msgid "invalid response received while renewing access token for \"%s\""
3801
  msgstr ""
3802
 
3803
- #: modules/gadsense/includes/class-mapi.php:686
3804
  msgid "You could try to connect again under Advanced Ads > Settings > AdSense."
3805
  msgstr ""
3806
 
3807
- #: modules/gadsense/includes/class-mapi.php:755
3808
  msgid "This ad code is from a different AdSense Account"
3809
  msgstr ""
3810
 
3811
- #: modules/gadsense/includes/class-mapi.php:992
3812
  msgid "Invalid response body while retrieving account alerts"
3813
  msgstr ""
3814
 
3815
- #: modules/gadsense/includes/class-mapi.php:1001
3816
  msgid "error while retrieving account alerts"
3817
  msgstr ""
3818
 
3819
- #: modules/gadsense/includes/class-mapi.php:1118
3820
  msgid "No token provided. Token data needed to get account details."
3821
  msgstr ""
3822
 
3823
- #: modules/gadsense/includes/class-mapi.php:1138
3824
- #: modules/gadsense/includes/class-mapi.php:1142
3825
  msgid "No AdSense account data found."
3826
  msgstr ""
3827
 
3828
- #: modules/gadsense/includes/class-mapi.php:1394
3829
- #: modules/gadsense/includes/class-mapi.php:1412
3830
  #: modules/gadsense/includes/class-network-adsense.php:514
3831
  msgctxt "AdSense ad type"
3832
  msgid "Matched Content"
3833
  msgstr ""
3834
 
3835
- #: modules/gadsense/includes/class-mapi.php:1397
3836
- #: modules/gadsense/includes/class-mapi.php:1415
3837
  #: modules/gadsense/includes/class-network-adsense.php:515
3838
  msgctxt "AdSense ad type"
3839
  msgid "In-article"
3840
  msgstr ""
3841
 
3842
- #: modules/gadsense/includes/class-mapi.php:1399
3843
- #: modules/gadsense/includes/class-mapi.php:1418
3844
  #: modules/gadsense/includes/class-network-adsense.php:516
3845
  msgctxt "AdSense ad type"
3846
  msgid "In-feed"
3847
  msgstr ""
3848
 
3849
- #: modules/gadsense/includes/class-mapi.php:1406
3850
  #: modules/gadsense/includes/class-network-adsense.php:517
3851
  msgctxt "AdSense ad type"
3852
  msgid "Display"
3853
  msgstr ""
3854
 
3855
- #: modules/gadsense/includes/class-mapi.php:1409
3856
  #: modules/gadsense/includes/class-network-adsense.php:518
3857
  msgctxt "AdSense ad type"
3858
  msgid "Link"
3859
  msgstr ""
3860
 
3861
- #: modules/gadsense/includes/class-mapi.php:1615
3862
  msgid "There are one or more warnings about the currently linked AdSense account. You can view them <a href=\"%s\">here</a>"
3863
  msgstr ""
3864
 
3865
  #. translators: 1:A link to the settings page translators: 2:The name of an ad network
3866
- #: modules/gadsense/includes/class-mapi.php:1702
3867
  msgid "Please try to <a href=\"%1$s\" target=\"_blank\">reconnect to your %2$s account</a>."
3868
  msgstr ""
3869
 
2
  # This file is distributed under the same license as the Advanced Ads plugin.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Advanced Ads 1.29.1\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/advanced-ads/\n"
7
  "Last-Translator: Thomas Maier <post@webzunft.de>\n"
8
  "Language-Team: webgilde <support@wpadvancedads.com>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "POT-Creation-Date: 2021-10-14T12:39:27+02:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.4.0\n"
15
  "X-Domain: advanced-ads\n"
52
  msgstr ""
53
 
54
  #: admin/class-advanced-ads-admin.php:220
55
+ #: modules/gadsense/includes/class-adsense-report.php:159
56
  msgid "Today"
57
  msgstr ""
58
 
59
  #: admin/class-advanced-ads-admin.php:221
60
+ #: modules/gadsense/includes/class-adsense-report.php:160
61
  msgid "Yesterday"
62
  msgstr ""
63
 
64
  #: admin/class-advanced-ads-admin.php:222
65
+ #: modules/gadsense/includes/class-adsense-report.php:163
66
  msgid "This Month"
67
  msgstr ""
68
 
69
  #. translators: 1: The number of days.
70
  #: admin/class-advanced-ads-admin.php:224
71
+ #: modules/gadsense/includes/class-adsense-report.php:162
72
+ #: modules/gadsense/includes/class-adsense-report.php:165
73
  msgid "Last %1$d days"
74
  msgstr ""
75
 
458
  msgstr ""
459
 
460
  #: admin/includes/class-admin-upgrades.php:107
461
+ #: admin/includes/class-overview-widgets.php:460
462
  msgid "A quick and error-free way of implementing ad units from your Google Ad Manager account."
463
  msgstr ""
464
 
801
  msgid "Show %s hidden notices"
802
  msgstr ""
803
 
804
+ #: admin/includes/class-overview-widgets.php:355
805
  msgid "How to download, install and activate an add-on."
806
  msgstr ""
807
 
808
+ #: admin/includes/class-overview-widgets.php:363
809
  msgid "The solution for professional websites."
810
  msgstr ""
811
 
812
+ #: admin/includes/class-overview-widgets.php:372
813
  #: admin/views/upgrades/pro-tab.php:7
814
  msgid "support for cached sites"
815
  msgstr ""
816
 
817
  #. translators: %s is the name of another plugin.
818
+ #: admin/includes/class-overview-widgets.php:388
819
+ #: admin/includes/class-overview-widgets.php:400
820
+ #: admin/includes/class-overview-widgets.php:412
821
+ #: admin/includes/class-overview-widgets.php:424
822
  msgid "integrates with <strong>%s</strong>"
823
  msgstr ""
824
 
825
+ #: admin/includes/class-overview-widgets.php:429
826
  msgid "click fraud protection, lazy load, ad-block ads"
827
  msgstr ""
828
 
829
+ #: admin/includes/class-overview-widgets.php:430
830
  #: admin/views/upgrades/pro-tab.php:8
831
  msgid "11 more display and visitor conditions"
832
  msgstr ""
833
 
834
+ #: admin/includes/class-overview-widgets.php:431
835
  #: admin/views/upgrades/pro-tab.php:9
836
  msgid "6 more placements"
837
  msgstr ""
838
 
839
+ #: admin/includes/class-overview-widgets.php:432
840
  #: admin/views/upgrades/pro-tab.php:10
841
  msgid "placement tests for ad optimization"
842
  msgstr ""
843
 
844
+ #: admin/includes/class-overview-widgets.php:433
845
  #: admin/views/upgrades/pro-tab.php:11
846
  msgid "ad grids and many more advanced features"
847
  msgstr ""
848
 
849
+ #: admin/includes/class-overview-widgets.php:448
850
  msgid "Analyze clicks and impressions of your ads locally or in Google Analytics, share reports, and limit ads to a specific number of impressions or clicks."
851
  msgstr ""
852
 
853
+ #: admin/includes/class-overview-widgets.php:454
854
  msgid "Display ads based on the device or the size of your visitor’s browser, and control ads on AMP pages."
855
  msgstr ""
856
 
857
+ #: admin/includes/class-overview-widgets.php:466
858
  msgid "Increase click rates on your ads by placing them in sticky positions above, next or below your site."
859
  msgstr ""
860
 
861
+ #: admin/includes/class-overview-widgets.php:472
862
  msgid "Users will never miss an ad or other information in a PopUp. Choose when it shows up and for how long a user can close it."
863
  msgstr ""
864
 
865
+ #: admin/includes/class-overview-widgets.php:478
866
  msgid "Target visitors with ads that match their geo location and make more money with regional campaigns."
867
  msgstr ""
868
 
869
+ #: admin/includes/class-overview-widgets.php:484
870
  msgid "Earn more money and let advertisers pay for ad space directly on the frontend of your site."
871
  msgstr ""
872
 
873
+ #: admin/includes/class-overview-widgets.php:490
874
  msgid "Create a beautiful and simple slider from your ads to show more information on less space."
875
  msgstr ""
876
 
877
+ #: admin/includes/class-overview-widgets.php:496
878
  msgid "Place AdSense In-feed ads between posts on homepage, category, and archive pages."
879
  msgstr ""
880
 
881
+ #: admin/includes/class-overview-widgets.php:499
882
+ #: admin/includes/class-overview-widgets.php:689
883
+ #: admin/includes/class-overview-widgets.php:705
884
  msgid "Install now"
885
  msgstr ""
886
 
887
+ #: admin/includes/class-overview-widgets.php:517
888
+ #: admin/includes/class-overview-widgets.php:535
889
+ #: admin/includes/class-overview-widgets.php:560
890
+ #: admin/includes/class-overview-widgets.php:578
891
+ #: admin/includes/class-overview-widgets.php:596
892
+ #: admin/includes/class-overview-widgets.php:614
893
+ #: admin/includes/class-overview-widgets.php:632
894
+ #: admin/includes/class-overview-widgets.php:650
895
+ #: admin/includes/class-overview-widgets.php:668
896
  msgid "Activate now"
897
  msgstr ""
898
 
899
+ #: admin/includes/class-overview-widgets.php:543
900
  msgid "Visit your ad statistics"
901
  msgstr ""
902
 
903
+ #: admin/includes/class-overview-widgets.php:685
904
  msgid "Use Genesis specific ad positions."
905
  msgstr ""
906
 
907
+ #: admin/includes/class-overview-widgets.php:701
908
  msgid "Manage ad positions with WPBakery Page Builder (formerly Visual Composer)."
909
  msgstr ""
910
 
911
+ #: admin/includes/class-overview-widgets.php:717
912
  msgid "Our best deal with all add-ons included."
913
  msgstr ""
914
 
915
+ #: admin/includes/class-overview-widgets.php:719
916
+ #: admin/includes/class-overview-widgets.php:735
917
  msgid "Get full access"
918
  msgstr ""
919
 
920
+ #: admin/includes/class-overview-widgets.php:733
921
  msgid "A one-time payment for four years of support and updates. The package saves you up to 70% compared to individually purchasing our add-ons."
922
  msgstr ""
923
 
924
+ #: admin/includes/class-overview-widgets.php:751
925
  #: admin/views/conditions/ad-display-metabox.php:37
926
  #: admin/views/conditions/ad-visitor-metabox.php:37
927
  msgid "Visit the manual"
928
  msgstr ""
929
 
930
+ #: admin/includes/class-overview-widgets.php:754
931
  msgid "Get this add-on"
932
  msgstr ""
933
 
2534
 
2535
  #. translators: %1$s is an anchor (link) opening tag, %2$s is the closing tag.
2536
  #: classes/ad-health-notices.php:865
2537
+ #: modules/gadsense/includes/class-mapi.php:1644
2538
  msgid "Learn more about AdSense account issues %1$shere%2$s."
2539
  msgstr ""
2540
 
3719
  msgstr ""
3720
 
3721
  #. translators: AdSense ID.
3722
+ #: modules/gadsense/includes/adsense-report-api.php:141
3723
  msgid "Error while retrieving report for \"%s\"."
3724
  msgstr ""
3725
 
3726
  #. translators: AdSense ID.
3727
+ #: modules/gadsense/includes/adsense-report-api.php:152
3728
+ #: modules/gadsense/includes/adsense-report-api.php:161
3729
  msgid "Invalid response while retrieving report for \"%s\"."
3730
  msgstr ""
3731
 
3741
  msgid "Your AdSense Publisher ID is missing."
3742
  msgstr ""
3743
 
3744
+ #: modules/gadsense/includes/class-adsense-report.php:99
3745
  msgid "No valid tokens"
3746
  msgstr ""
3747
 
3755
  msgstr ""
3756
 
3757
  #. translators: %s: ad unit ID.
3758
+ #: modules/gadsense/includes/class-mapi.php:398
3759
  msgid "Invalid response while retrieving ad code for \"%s\"."
3760
  msgstr ""
3761
 
3762
  #. translators: the publisher ID.
3763
+ #: modules/gadsense/includes/class-mapi.php:457
3764
+ #: modules/gadsense/includes/class-mapi.php:527
3765
  msgid "Error while retrieving adUnits list for \"%s\"."
3766
  msgstr ""
3767
 
3768
  #. translators: %s is the publisher ID.
3769
+ #: modules/gadsense/includes/class-mapi.php:465
3770
  msgid "Invalid response while retrieving adUnits list for \"%s\"."
3771
  msgstr ""
3772
 
3773
+ #: modules/gadsense/includes/class-mapi.php:473
3774
  msgid "Reason:"
3775
  msgstr ""
3776
 
3777
+ #: modules/gadsense/includes/class-mapi.php:474
3778
  msgid "Message:"
3779
  msgstr ""
3780
 
3781
  #. translators: %1$s is the AdSense publisher ID; %2$s a starting a tag to the AdSense ad unit list and %3$s the closing link.
3782
+ #: modules/gadsense/includes/class-mapi.php:488
3783
  msgid "The account \"%1$s\" does not seem to have any ad units. Please create some %2$shere%3$s."
3784
  msgstr ""
3785
 
3786
+ #: modules/gadsense/includes/class-mapi.php:605
3787
  msgid "It seems that some changes have been made in the Advanced Ads settings. Please refresh this page."
3788
  msgstr ""
3789
 
3790
+ #: modules/gadsense/includes/class-mapi.php:612
3791
  msgid "Advanced Ads does not have access to your account (<code>%s</code>) anymore."
3792
  msgstr ""
3793
 
3794
+ #: modules/gadsense/includes/class-mapi.php:656
3795
  msgid "error while renewing access token for \"%s\""
3796
  msgstr ""
3797
 
3798
  #. translators: %s AdSense account ID
3799
+ #: modules/gadsense/includes/class-mapi.php:683
3800
  msgid "invalid response received while renewing access token for \"%s\""
3801
  msgstr ""
3802
 
3803
+ #: modules/gadsense/includes/class-mapi.php:685
3804
  msgid "You could try to connect again under Advanced Ads > Settings > AdSense."
3805
  msgstr ""
3806
 
3807
+ #: modules/gadsense/includes/class-mapi.php:754
3808
  msgid "This ad code is from a different AdSense Account"
3809
  msgstr ""
3810
 
3811
+ #: modules/gadsense/includes/class-mapi.php:991
3812
  msgid "Invalid response body while retrieving account alerts"
3813
  msgstr ""
3814
 
3815
+ #: modules/gadsense/includes/class-mapi.php:1000
3816
  msgid "error while retrieving account alerts"
3817
  msgstr ""
3818
 
3819
+ #: modules/gadsense/includes/class-mapi.php:1115
3820
  msgid "No token provided. Token data needed to get account details."
3821
  msgstr ""
3822
 
3823
+ #: modules/gadsense/includes/class-mapi.php:1135
3824
+ #: modules/gadsense/includes/class-mapi.php:1139
3825
  msgid "No AdSense account data found."
3826
  msgstr ""
3827
 
3828
+ #: modules/gadsense/includes/class-mapi.php:1390
3829
+ #: modules/gadsense/includes/class-mapi.php:1408
3830
  #: modules/gadsense/includes/class-network-adsense.php:514
3831
  msgctxt "AdSense ad type"
3832
  msgid "Matched Content"
3833
  msgstr ""
3834
 
3835
+ #: modules/gadsense/includes/class-mapi.php:1393
3836
+ #: modules/gadsense/includes/class-mapi.php:1411
3837
  #: modules/gadsense/includes/class-network-adsense.php:515
3838
  msgctxt "AdSense ad type"
3839
  msgid "In-article"
3840
  msgstr ""
3841
 
3842
+ #: modules/gadsense/includes/class-mapi.php:1395
3843
+ #: modules/gadsense/includes/class-mapi.php:1414
3844
  #: modules/gadsense/includes/class-network-adsense.php:516
3845
  msgctxt "AdSense ad type"
3846
  msgid "In-feed"
3847
  msgstr ""
3848
 
3849
+ #: modules/gadsense/includes/class-mapi.php:1402
3850
  #: modules/gadsense/includes/class-network-adsense.php:517
3851
  msgctxt "AdSense ad type"
3852
  msgid "Display"
3853
  msgstr ""
3854
 
3855
+ #: modules/gadsense/includes/class-mapi.php:1405
3856
  #: modules/gadsense/includes/class-network-adsense.php:518
3857
  msgctxt "AdSense ad type"
3858
  msgid "Link"
3859
  msgstr ""
3860
 
3861
+ #: modules/gadsense/includes/class-mapi.php:1611
3862
  msgid "There are one or more warnings about the currently linked AdSense account. You can view them <a href=\"%s\">here</a>"
3863
  msgstr ""
3864
 
3865
  #. translators: 1:A link to the settings page translators: 2:The name of an ad network
3866
+ #: modules/gadsense/includes/class-mapi.php:1698
3867
  msgid "Please try to <a href=\"%1$s\" target=\"_blank\">reconnect to your %2$s account</a>."
3868
  msgstr ""
3869
 
modules/gadsense/admin/assets/js/adsense.js CHANGED
@@ -56,7 +56,7 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
56
  }
57
  jQuery( document ).trigger( 'gadsenseFormatAdContent', [adContent] );
58
 
59
- if ( 'undefined' != typeof ( window.gadsenseAdContent ) ) {
60
  adContent = window.gadsenseAdContent;
61
  delete( window.gadsenseAdContent );
62
  }
@@ -153,9 +153,8 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
153
  */
154
  getSavedDetails( slotID ) {
155
  if ( typeof this.codes[slotID] !== 'undefined' ) {
156
- var code = this.codes[slotID];
157
- var parsed = this.processAdCode( code );
158
- if ( parsed !== false) {
159
  jQuery( '#remote-ad-unsupported-ad-type' ).css( 'display', 'none' );
160
  this.closeAdSelector();
161
  this.preventCloseAdSelector = false;
@@ -186,8 +185,7 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
186
  jQuery( '#mapi-loading-overlay' ).css( 'display', 'none' );
187
  if ( typeof response.code !== 'undefined' ) {
188
  jQuery( '#remote-ad-code-msg' ).empty();
189
- var parsed = self.processAdCode( response.code );
190
- if ( parsed !== false ) {
191
  self.codes[slotID] = response.code;
192
  AdvancedAdsAdmin.AdImporter.unitIsSupported( slotID );
193
  }
@@ -230,51 +228,51 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
230
  * @return {!Object}
231
  */
232
  parseAdContent( content ) {
233
- var rawContent = ( 'undefined' != typeof ( content ) ) ? content.trim() : '';
234
- var theAd = {};
235
- var theContent = jQuery( '<div />' ).html( rawContent );
236
- var adByGoogle = theContent.find( 'ins' );
237
- theAd.slotId = adByGoogle.attr( 'data-ad-slot' ) || '';
238
- if ( 'undefined' != typeof ( adByGoogle.attr( 'data-ad-client' ) ) ) {
239
  theAd.pubId = adByGoogle.attr( 'data-ad-client' ).substr( 3 );
240
  }
241
 
242
- if ( undefined !== theAd.slotId && '' != theAd.pubId ) {
243
  theAd.display = adByGoogle.css( 'display' );
244
  theAd.format = adByGoogle.attr( 'data-ad-format' );
245
  theAd.layout = adByGoogle.attr( 'data-ad-layout' ); // for In-feed and In-article
246
  theAd.layout_key = adByGoogle.attr( 'data-ad-layout-key' ); // for InFeed
247
  theAd.style = adByGoogle.attr( 'style' ) || '';
248
 
249
- /* normal ad */
250
- if ( 'undefined' == typeof ( theAd.format ) && - 1 != theAd.style.indexOf( 'width' ) ) {
251
  theAd.type = 'normal';
252
  theAd.width = adByGoogle.css( 'width' ).replace( 'px', '' );
253
  theAd.height = adByGoogle.css( 'height' ).replace( 'px', '' );
254
- } else if ( 'undefined' != typeof ( theAd.format ) && 'auto' == theAd.format ) {
255
  // Responsive ad, auto resize.
256
  theAd.type = 'responsive';
257
- } else if ( 'undefined' != typeof ( theAd.format ) && 'link' == theAd.format ) {
258
  // Older link unit format; for new ads the format type is no longer needed; link units are created through the AdSense panel
259
- if ( - 1 != theAd.style.indexOf( 'width' ) ) {
260
- // is fixed size
261
  theAd.width = adByGoogle.css( 'width' ).replace( 'px', '' );
262
  theAd.height = adByGoogle.css( 'height' ).replace( 'px', '' );
263
  theAd.type = 'link';
264
  } else {
265
- // is responsive
266
  theAd.type = 'link-responsive';
267
  }
268
- } else if ( 'undefined' != typeof ( theAd.format ) && 'autorelaxed' == theAd.format ) {
269
  // Responsive Matched Content
270
  theAd.type = 'matched-content';
271
- } else if ( 'undefined' != typeof ( theAd.format ) && 'fluid' == theAd.format ) {
272
  // In-article & In-feed ads.
273
- if ( 'undefined' != typeof ( theAd.layout ) && 'in-article' == theAd.layout ) {
274
- // In-article
275
  theAd.type = 'in-article';
276
  } else {
277
- // In-feed
278
  theAd.type = 'in-feed';
279
  }
280
  }
@@ -283,15 +281,14 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
283
  /**
284
  * Synchronous code
285
  */
286
- if ( rawContent.indexOf( 'google_ad_slot' ) !== -1 ) {
287
- var adClient = rawContent.match( /google_ad_client ?= ?["']([^'"]+)/ );
288
- var adSlot = rawContent.match( /google_ad_slot ?= ?["']([^'"]+)/ );
289
- var adFormat = rawContent.match( /google_ad_format ?= ?["']([^'"]+)/ );
290
- var adWidth = rawContent.match( /google_ad_width ?= ?([\d]+)/ );
291
- var adHeight = rawContent.match( /google_ad_height ?= ?([\d]+)/ );
292
 
293
  theAd = {};
294
-
295
  theAd.pubId = adClient[1].substr( 3 );
296
 
297
  if ( adSlot !== null ) {
@@ -306,7 +303,6 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
306
  if ( adHeight !== null ) {
307
  theAd.height = parseInt( adHeight[1] );
308
  }
309
-
310
  if ( typeof theAd.format === 'undefined' ) {
311
  theAd.type = 'normal';
312
  }
@@ -317,11 +313,11 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
317
  theAd.type = jQuery( '#unit-type' ).val();
318
  }
319
 
320
- /* Page-Level ad */
321
  if ( rawContent.indexOf( 'enable_page_level_ads' ) !== - 1 || /script[^>]+data-ad-client=/.test( rawContent ) ) {
322
  theAd = {'parse_message': 'pageLevelAd'};
323
  } else if ( ! theAd.type ) {
324
- /* Unknown ad */
325
  theAd = {'parse_message': 'unknownAd'};
326
  }
327
 
@@ -353,16 +349,16 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
353
  advads_show_adsense_auto_ads_warning();
354
  break;
355
  case 'unknownAd' :
356
- // Not recognized ad code
357
- if ( this.parseCodeBtnClicked && 'post-new.php' == gadsenseData.pagenow ) {
358
- // do not show if just after switching to AdSense ad type on ad creation
359
  jQuery( '#pastecode-msg' ).append( jQuery( '<p />' ).css( 'color', 'red' ).html( gadsenseData.msg.unknownAd ) );
360
  }
361
  break;
362
  default:
363
  this.setDetailsFromAdCode( parseResult );
364
- if ( 'undefined' != typeof AdsenseMAPI && 'undefined' != typeof AdsenseMAPI.hasToken && parseResult.pubId == AdsenseMAPI.pubId ) {
365
- var content = jQuery( '#advanced-ads-ad-parameters input[name="advanced_ad[content]"]' ).val();
366
  this.mapiSaveAdCode( content, parseResult.slotId );
367
  this.makeReadOnly();
368
  }
@@ -406,8 +402,7 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
406
  jQuery( '#ad-resize-type' ).val( 'auto' );
407
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val( '' );
408
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val( '' );
409
- }
410
- if ( theAd.type === 'in-article' ) {
411
  jQuery( '#unit-type' ).val( 'in-article' );
412
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val( '' );
413
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val( '' );
@@ -417,9 +412,9 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
417
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val( '' );
418
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val( '' );
419
  }
420
- var storedPubId = gadsenseData.pubId;
421
 
422
- if ( '' !== storedPubId && theAd.pubId != storedPubId && '' != theAd.slotId ) {
423
  jQuery( '#adsense-ad-param-error' ).text( gadsenseData.msg.pubIdMismatch );
424
  } else {
425
  jQuery( '#adsense-ad-param-error' ).empty();
@@ -432,7 +427,7 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
432
  * Legacy method
433
  */
434
  updateAdsenseType() {
435
- var type = jQuery( '#unit-type' ).val();
436
  jQuery( '.advads-adsense-layout' ).hide();
437
  jQuery( '.advads-adsense-layout' ).next( 'div' ).hide();
438
  jQuery( '.advads-adsense-layout-key' ).hide();
@@ -485,8 +480,8 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
485
  * Show / hide position warning.
486
  */
487
  show_float_warnings( unit_type ) {
488
- var resize_type = jQuery( '#ad-resize-type' ).val();
489
- var position = jQuery( '#advanced-ad-output-position input[name="advanced_ad[output][position]"]:checked' ).val();
490
 
491
  if (
492
  ( ['link-responsive', 'matched-content', 'in-article', 'in-feed'].indexOf( unit_type ) !== - 1
@@ -516,16 +511,15 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
516
  }
517
 
518
  getCustomInputs() {
519
- var $div1 = jQuery( '#unit-code' ).closest( 'div' );
520
- var $label1 = $div1.prev();
521
- var $hr1 = $div1.next();
522
- var $label2 = $hr1.next();
523
- var $div2 = $label2.next();
524
- var $layoutKey = jQuery( '#ad-layout-key' ).closest( 'div' );
525
- var $layoutKeyLabel = $layoutKey.prev( '#advads-adsense-layout-key' );
526
 
527
- var $elems = $div1.add( $label1 ).add( $hr1 ).add( $label2 ).add( $div2 ).add( $layoutKey ).add( $layoutKeyLabel );
528
- return $elems;
529
  }
530
 
531
  onBlur() {
@@ -546,7 +540,7 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
546
  const parsedAd = this.parseAdContentFailsafe( this.codes[this.getSelectedId()] );
547
  if ( parsedAd ) {
548
  // We need to check if the type of the ad is different from the default. this marks a manually setup ad.
549
- if ( jQuery( '#unit-type' ).val() !== parsedAd.type ) {
550
  // This ad was manually setup. don't open the selector, but switch to manual select.
551
  switchToManualSetup = true;
552
 
@@ -572,8 +566,8 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
572
  jQuery( document ).on( 'click', '.advads-adsense-submit-code', function ( ev ) {
573
  ev.preventDefault();
574
  self.parseCodeBtnClicked = true;
575
- var rawContent = jQuery( '.advads-adsense-content' ).val();
576
- var parseResult = self.parseAdContent( rawContent );
577
  self.handleParseResult( parseResult );
578
  if ( AdvancedAdsAdmin.AdImporter.highlightSelectedRowInExternalAdsList() ) {
579
  AdvancedAdsAdmin.AdImporter.openExternalAdsList();
@@ -586,7 +580,7 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
586
  nonce: AdsenseMAPI.nonce
587
  } )
588
  .fail( function ( r ) {
589
- var $notice = jQuery( '<div>' ).addClass( 'notice notice-error' ).html( jQuery( '<p>' ).text( r.responseJSON.data.message ) );
590
  jQuery( '#post' ).before( $notice );
591
  jQuery( 'body html' ).animate(
592
  {
@@ -604,8 +598,8 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
604
  } );
605
 
606
  jQuery( document ).on( 'gadsenseUnitChanged', function () {
607
- var $row = jQuery( 'tr[data-slotid$="' + jQuery( '#unit-code' ).val() + '"]' ),
608
- type = window.adsenseAdvancedAdsJS.ad_types.display;
609
 
610
  switch ( jQuery( '#unit-type' ).val() ) {
611
  case 'matched-content':
@@ -630,12 +624,12 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
630
  self.checkAdSlotId( this );
631
  } );
632
 
633
- let inputCode = jQuery( '#unit-code' );
634
  if ( inputCode ) {
635
  this.checkAdSlotId( inputCode[0] );
636
  }
637
 
638
- jQuery( document ).on( 'change', '#ad-resize-type', function ( ev ) {
639
  self.show_float_warnings( 'responsive' );
640
  } );
641
  this.updateAdsenseType();
@@ -650,7 +644,7 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
650
 
651
  jQuery( '#wpwrap' ).on(
652
  'advads-mapi-adlist-opened',
653
- function ( ev ) {
654
  // Update ad unit list to v2 data the first time the ad list is opened.
655
  if ( jQuery( '#mapi-force-v2-list-update' ).length ) {
656
  jQuery( '#mapi-wrap i[data-mapiaction="updateList"]' ).trigger( 'click' );
@@ -667,9 +661,9 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
667
  if ( typeof show === 'undefined' ) {
668
  show = false;
669
  }
670
- let icon = jQuery( '#mapi-archived-ads' );
671
- let title = icon.attr( 'title' );
672
- let altTitle = icon.attr( 'data-alt-title' );
673
  if ( show ) {
674
  jQuery( '#mapi-table-wrap tbody tr[data-archived="1"]' ).show();
675
  icon.removeClass( 'dashicons-visibility' ).addClass( 'dashicons-hidden' ).attr( 'title', altTitle ).attr( 'data-alt-title', title );
@@ -681,12 +675,11 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
681
 
682
  checkAdSlotId( elm ) {
683
  if ( jQuery( elm ).attr( 'id' ) === 'unit-code' ) {
684
- var val = jQuery( elm ).val();
685
  if ( val ) {
686
  val = val.trim();
687
  }
688
- if ( val.length > 0 && ( gadsenseData.pubId && - 1 != val.indexOf( gadsenseData.pubId.substr( 4 ) ) ) ) {
689
- // if ( val.length > 0 && -1 != val.indexOf( gadsenseData.pubId.substr( 4 ) ) ) {
690
  jQuery( '#advads-pubid-in-slot' ).css( 'display', 'block' );
691
  jQuery( elm ).css( 'background-color', 'rgba(255, 235, 59, 0.33)' );
692
  this.updateAdsenseType();
@@ -726,18 +719,18 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
726
  if ( typeof AdsenseMAPI.hasToken === 'undefined' ) {
727
  return;
728
  }
729
- var slotId = jQuery( '#unit-code' ).val();
730
  if ( ! slotId ) {
731
  return;
732
  }
733
 
734
- var type = jQuery( '#unit-type' ).val();
735
- var width = jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val().trim();
736
- var height = jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val().trim();
737
- var layout = jQuery( '#ad-layout' ).val();
738
- var layoutKey = jQuery( '#ad-layout-key' ).val();
739
 
740
- var code = false;
741
 
742
  switch ( type ) {
743
  case 'in-feed':
@@ -828,7 +821,7 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
828
  }
829
 
830
  getMapiAction( action ) {
831
- var self = this;
832
  if ( action === 'toggleidle' ) {
833
  return function ( ev, el ) {
834
  self.hideIdle = ! self.hideIdle;
@@ -840,27 +833,27 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork {
840
  }
841
 
842
  // Creates a Advanced_Ads_Adsense_Report_UI instance on the fly
843
- window.Advanced_Ads_Adsense_Report_Helper = window.Advanced_Ads_Adsense_Report_Helper || {
844
- init: function ( element ) {
845
- if ( jQuery( element ).attr( 'data-arguments' ) ) {
846
- try {
847
- let reportArgs = JSON.parse( jQuery( element ).attr( 'data-arguments' ) );
848
- jQuery( element ).data( 'advadsAdsenseReport', new Advanced_Ads_Adsense_Report_UI( element, reportArgs ) );
849
- } catch ( ex ) {
850
- console.error( 'Cannot parse report arguments' );
851
- }
852
  }
853
- },
854
- getReportObject: function () {
855
- let reportElem = jQuery( '.advanced-ads-adsense-dashboard' );
856
- if ( reportElem.length ) {
857
- let report = reportElem.data( 'advadsAdsenseReport' );
858
- if ( typeof report.refresh === 'function' ) {
859
- return report;
860
- }
 
861
  }
862
- return false;
863
  }
 
864
  };
865
 
866
  class Advanced_Ads_Adsense_Report_UI {
@@ -879,7 +872,7 @@ class Advanced_Ads_Adsense_Report_UI {
879
 
880
  // Get markup for the current arguments.
881
  refresh() {
882
- let self = this;
883
  this.$el.html( '<p style="text-align:center;"><span class="report-need-refresh spinner advads-ad-parameters-spinner advads-spinner"></span></p>' );
884
  jQuery.ajax( {
885
  type: 'POST',
@@ -905,7 +898,7 @@ class Advanced_Ads_Adsense_Report_UI {
905
  if ( this.$el.find( '.report-need-refresh' ).length ) {
906
  this.refresh();
907
  }
908
- let self = this;
909
 
910
  // Hide dropdown on click on everything but the dropdown and its children.
911
  jQuery( document ).on( 'click', '#wpwrap', function () {
@@ -932,4 +925,4 @@ class Advanced_Ads_Adsense_Report_UI {
932
  self.refresh();
933
  } );
934
  }
935
- };
56
  }
57
  jQuery( document ).trigger( 'gadsenseFormatAdContent', [adContent] );
58
 
59
+ if ( typeof window.gadsenseAdContent !== 'undefined' ) {
60
  adContent = window.gadsenseAdContent;
61
  delete( window.gadsenseAdContent );
62
  }
153
  */
154
  getSavedDetails( slotID ) {
155
  if ( typeof this.codes[slotID] !== 'undefined' ) {
156
+ const parsed = this.processAdCode( this.codes[slotID] );
157
+ if ( parsed !== false ) {
 
158
  jQuery( '#remote-ad-unsupported-ad-type' ).css( 'display', 'none' );
159
  this.closeAdSelector();
160
  this.preventCloseAdSelector = false;
185
  jQuery( '#mapi-loading-overlay' ).css( 'display', 'none' );
186
  if ( typeof response.code !== 'undefined' ) {
187
  jQuery( '#remote-ad-code-msg' ).empty();
188
+ if ( self.processAdCode( response.code ) !== false ) {
 
189
  self.codes[slotID] = response.code;
190
  AdvancedAdsAdmin.AdImporter.unitIsSupported( slotID );
191
  }
228
  * @return {!Object}
229
  */
230
  parseAdContent( content ) {
231
+ const rawContent = typeof content !== 'undefined' ? content.trim() : '';
232
+ const theContent = jQuery( '<div />' ).html( rawContent );
233
+ const adByGoogle = theContent.find( 'ins' );
234
+ let theAd = {};
235
+ theAd.slotId = adByGoogle.attr( 'data-ad-slot' ) || '';
236
+ if ( typeof adByGoogle.attr( 'data-ad-client' ) !== 'undefined' ) {
237
  theAd.pubId = adByGoogle.attr( 'data-ad-client' ).substr( 3 );
238
  }
239
 
240
+ if ( theAd.slotId !== undefined && theAd.pubId !== '' ) {
241
  theAd.display = adByGoogle.css( 'display' );
242
  theAd.format = adByGoogle.attr( 'data-ad-format' );
243
  theAd.layout = adByGoogle.attr( 'data-ad-layout' ); // for In-feed and In-article
244
  theAd.layout_key = adByGoogle.attr( 'data-ad-layout-key' ); // for InFeed
245
  theAd.style = adByGoogle.attr( 'style' ) || '';
246
 
247
+ // Normal ad.
248
+ if ( typeof theAd.format === 'undefined' && theAd.style.indexOf( 'width' ) !== - 1 ) {
249
  theAd.type = 'normal';
250
  theAd.width = adByGoogle.css( 'width' ).replace( 'px', '' );
251
  theAd.height = adByGoogle.css( 'height' ).replace( 'px', '' );
252
+ } else if ( typeof theAd.format !== 'undefined' && theAd.format === 'auto' ) {
253
  // Responsive ad, auto resize.
254
  theAd.type = 'responsive';
255
+ } else if ( typeof theAd.format !== 'undefined' && theAd.format === 'link' ) {
256
  // Older link unit format; for new ads the format type is no longer needed; link units are created through the AdSense panel
257
+ if ( theAd.style.indexOf( 'width' ) !== - 1 ) {
258
+ // Is fixed size.
259
  theAd.width = adByGoogle.css( 'width' ).replace( 'px', '' );
260
  theAd.height = adByGoogle.css( 'height' ).replace( 'px', '' );
261
  theAd.type = 'link';
262
  } else {
263
+ // Is responsive.
264
  theAd.type = 'link-responsive';
265
  }
266
+ } else if ( typeof theAd.format !== 'undefined' && theAd.format === 'autorelaxed' ) {
267
  // Responsive Matched Content
268
  theAd.type = 'matched-content';
269
+ } else if ( typeof theAd.format !== 'undefined' && theAd.format === 'fluid' ) {
270
  // In-article & In-feed ads.
271
+ if ( typeof theAd.layout !== 'undefined' && theAd.layout === 'in-article' ) {
272
+ // In-article.
273
  theAd.type = 'in-article';
274
  } else {
275
+ // In-feed.
276
  theAd.type = 'in-feed';
277
  }
278
  }
281
  /**
282
  * Synchronous code
283
  */
284
+ if ( rawContent.indexOf( 'google_ad_slot' ) !== - 1 ) {
285
+ const adClient = rawContent.match( /google_ad_client ?= ?["']([^'"]+)/ );
286
+ const adSlot = rawContent.match( /google_ad_slot ?= ?["']([^'"]+)/ );
287
+ const adFormat = rawContent.match( /google_ad_format ?= ?["']([^'"]+)/ );
288
+ const adWidth = rawContent.match( /google_ad_width ?= ?([\d]+)/ );
289
+ const adHeight = rawContent.match( /google_ad_height ?= ?([\d]+)/ );
290
 
291
  theAd = {};
 
292
  theAd.pubId = adClient[1].substr( 3 );
293
 
294
  if ( adSlot !== null ) {
303
  if ( adHeight !== null ) {
304
  theAd.height = parseInt( adHeight[1] );
305
  }
 
306
  if ( typeof theAd.format === 'undefined' ) {
307
  theAd.type = 'normal';
308
  }
313
  theAd.type = jQuery( '#unit-type' ).val();
314
  }
315
 
316
+ // Page-Level ad.
317
  if ( rawContent.indexOf( 'enable_page_level_ads' ) !== - 1 || /script[^>]+data-ad-client=/.test( rawContent ) ) {
318
  theAd = {'parse_message': 'pageLevelAd'};
319
  } else if ( ! theAd.type ) {
320
+ // Unknown ad.
321
  theAd = {'parse_message': 'unknownAd'};
322
  }
323
 
349
  advads_show_adsense_auto_ads_warning();
350
  break;
351
  case 'unknownAd' :
352
+ // Not recognized ad code.
353
+ if ( this.parseCodeBtnClicked && 'post-new.php' === gadsenseData.pagenow ) {
354
+ // do not show if just after switching to AdSense ad type on ad creation.
355
  jQuery( '#pastecode-msg' ).append( jQuery( '<p />' ).css( 'color', 'red' ).html( gadsenseData.msg.unknownAd ) );
356
  }
357
  break;
358
  default:
359
  this.setDetailsFromAdCode( parseResult );
360
+ if ( typeof AdsenseMAPI !== 'undefined' && typeof AdsenseMAPI.hasToken !== 'undefined' && AdsenseMAPI.pubId === parseResult.pubId ) {
361
+ const content = jQuery( '#advanced-ads-ad-parameters input[name="advanced_ad[content]"]' ).val();
362
  this.mapiSaveAdCode( content, parseResult.slotId );
363
  this.makeReadOnly();
364
  }
402
  jQuery( '#ad-resize-type' ).val( 'auto' );
403
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val( '' );
404
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val( '' );
405
+ } else if ( theAd.type === 'in-article' ) {
 
406
  jQuery( '#unit-type' ).val( 'in-article' );
407
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val( '' );
408
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val( '' );
412
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val( '' );
413
  jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val( '' );
414
  }
415
+ const storedPubId = gadsenseData.pubId;
416
 
417
+ if ( storedPubId !== '' && theAd.pubId !== storedPubId && theAd.slotId !== '' ) {
418
  jQuery( '#adsense-ad-param-error' ).text( gadsenseData.msg.pubIdMismatch );
419
  } else {
420
  jQuery( '#adsense-ad-param-error' ).empty();
427
  * Legacy method
428
  */
429
  updateAdsenseType() {
430
+ const type = jQuery( '#unit-type' ).val();
431
  jQuery( '.advads-adsense-layout' ).hide();
432
  jQuery( '.advads-adsense-layout' ).next( 'div' ).hide();
433
  jQuery( '.advads-adsense-layout-key' ).hide();
480
  * Show / hide position warning.
481
  */
482
  show_float_warnings( unit_type ) {
483
+ const resize_type = jQuery( '#ad-resize-type' ).val();
484
+ const position = jQuery( '#advanced-ad-output-position input[name="advanced_ad[output][position]"]:checked' ).val();
485
 
486
  if (
487
  ( ['link-responsive', 'matched-content', 'in-article', 'in-feed'].indexOf( unit_type ) !== - 1
511
  }
512
 
513
  getCustomInputs() {
514
+ const $div1 = jQuery( '#unit-code' ).closest( 'div' );
515
+ const $label1 = $div1.prev();
516
+ const $hr1 = $div1.next();
517
+ const $label2 = $hr1.next();
518
+ const $div2 = $label2.next();
519
+ const $layoutKey = jQuery( '#ad-layout-key' ).closest( 'div' );
520
+ const $layoutKeyLabel = $layoutKey.prev( '#advads-adsense-layout-key' );
521
 
522
+ return $div1.add( $label1 ).add( $hr1 ).add( $label2 ).add( $div2 ).add( $layoutKey ).add( $layoutKeyLabel );
 
523
  }
524
 
525
  onBlur() {
540
  const parsedAd = this.parseAdContentFailsafe( this.codes[this.getSelectedId()] );
541
  if ( parsedAd ) {
542
  // We need to check if the type of the ad is different from the default. this marks a manually setup ad.
543
+ if ( parsedAd.type !== jQuery( '#unit-type' ).val() ) {
544
  // This ad was manually setup. don't open the selector, but switch to manual select.
545
  switchToManualSetup = true;
546
 
566
  jQuery( document ).on( 'click', '.advads-adsense-submit-code', function ( ev ) {
567
  ev.preventDefault();
568
  self.parseCodeBtnClicked = true;
569
+ const rawContent = jQuery( '.advads-adsense-content' ).val();
570
+ const parseResult = self.parseAdContent( rawContent );
571
  self.handleParseResult( parseResult );
572
  if ( AdvancedAdsAdmin.AdImporter.highlightSelectedRowInExternalAdsList() ) {
573
  AdvancedAdsAdmin.AdImporter.openExternalAdsList();
580
  nonce: AdsenseMAPI.nonce
581
  } )
582
  .fail( function ( r ) {
583
+ const $notice = jQuery( '<div>' ).addClass( 'notice notice-error' ).html( jQuery( '<p>' ).text( r.responseJSON.data.message ) );
584
  jQuery( '#post' ).before( $notice );
585
  jQuery( 'body html' ).animate(
586
  {
598
  } );
599
 
600
  jQuery( document ).on( 'gadsenseUnitChanged', function () {
601
+ const $row = jQuery( 'tr[data-slotid$="' + jQuery( '#unit-code' ).val() + '"]' );
602
+ let type = window.adsenseAdvancedAdsJS.ad_types.display;
603
 
604
  switch ( jQuery( '#unit-type' ).val() ) {
605
  case 'matched-content':
624
  self.checkAdSlotId( this );
625
  } );
626
 
627
+ const inputCode = jQuery( '#unit-code' );
628
  if ( inputCode ) {
629
  this.checkAdSlotId( inputCode[0] );
630
  }
631
 
632
+ jQuery( document ).on( 'change', '#ad-resize-type', function () {
633
  self.show_float_warnings( 'responsive' );
634
  } );
635
  this.updateAdsenseType();
644
 
645
  jQuery( '#wpwrap' ).on(
646
  'advads-mapi-adlist-opened',
647
+ function () {
648
  // Update ad unit list to v2 data the first time the ad list is opened.
649
  if ( jQuery( '#mapi-force-v2-list-update' ).length ) {
650
  jQuery( '#mapi-wrap i[data-mapiaction="updateList"]' ).trigger( 'click' );
661
  if ( typeof show === 'undefined' ) {
662
  show = false;
663
  }
664
+ const icon = jQuery( '#mapi-archived-ads' );
665
+ const title = icon.attr( 'title' );
666
+ const altTitle = icon.attr( 'data-alt-title' );
667
  if ( show ) {
668
  jQuery( '#mapi-table-wrap tbody tr[data-archived="1"]' ).show();
669
  icon.removeClass( 'dashicons-visibility' ).addClass( 'dashicons-hidden' ).attr( 'title', altTitle ).attr( 'data-alt-title', title );
675
 
676
  checkAdSlotId( elm ) {
677
  if ( jQuery( elm ).attr( 'id' ) === 'unit-code' ) {
678
+ let val = jQuery( elm ).val();
679
  if ( val ) {
680
  val = val.trim();
681
  }
682
+ if ( val.length > 0 && gadsenseData.pubId && val.indexOf( gadsenseData.pubId.substr( 4 ) ) !== -1 ) {
 
683
  jQuery( '#advads-pubid-in-slot' ).css( 'display', 'block' );
684
  jQuery( elm ).css( 'background-color', 'rgba(255, 235, 59, 0.33)' );
685
  this.updateAdsenseType();
719
  if ( typeof AdsenseMAPI.hasToken === 'undefined' ) {
720
  return;
721
  }
722
+ const slotId = jQuery( '#unit-code' ).val();
723
  if ( ! slotId ) {
724
  return;
725
  }
726
 
727
+ const type = jQuery( '#unit-type' ).val();
728
+ const width = jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[width]"]' ).val().trim();
729
+ const height = jQuery( '#advanced-ads-ad-parameters-size input[name="advanced_ad[height]"]' ).val().trim();
730
+ const layout = jQuery( '#ad-layout' ).val();
731
+ const layoutKey = jQuery( '#ad-layout-key' ).val();
732
 
733
+ let code = false;
734
 
735
  switch ( type ) {
736
  case 'in-feed':
821
  }
822
 
823
  getMapiAction( action ) {
824
+ const self = this;
825
  if ( action === 'toggleidle' ) {
826
  return function ( ev, el ) {
827
  self.hideIdle = ! self.hideIdle;
833
  }
834
 
835
  // Creates a Advanced_Ads_Adsense_Report_UI instance on the fly
836
+ window.Advanced_Ads_Adsense_Report_Helper = window.Advanced_Ads_Adsense_Report_Helper || {};
837
+ window.Advanced_Ads_Adsense_Report_Helper.init = function ( element ) {
838
+ if ( jQuery( element ).attr( 'data-arguments' ) ) {
839
+ try {
840
+ const reportArgs = JSON.parse( jQuery( element ).attr( 'data-arguments' ) );
841
+ jQuery( element ).data( 'advadsAdsenseReport', new Advanced_Ads_Adsense_Report_UI( element, reportArgs ) );
842
+ } catch ( ex ) {
843
+ console.error( 'Cannot parse report arguments' );
 
844
  }
845
+ }
846
+ };
847
+
848
+ window.Advanced_Ads_Adsense_Report_Helper.getReportObject = function () {
849
+ const reportElem = jQuery( '.advanced-ads-adsense-dashboard' );
850
+ if ( reportElem.length ) {
851
+ let report = reportElem.data( 'advadsAdsenseReport' );
852
+ if ( typeof report.refresh === 'function' ) {
853
+ return report;
854
  }
 
855
  }
856
+ return false;
857
  };
858
 
859
  class Advanced_Ads_Adsense_Report_UI {
872
 
873
  // Get markup for the current arguments.
874
  refresh() {
875
+ const self = this;
876
  this.$el.html( '<p style="text-align:center;"><span class="report-need-refresh spinner advads-ad-parameters-spinner advads-spinner"></span></p>' );
877
  jQuery.ajax( {
878
  type: 'POST',
898
  if ( this.$el.find( '.report-need-refresh' ).length ) {
899
  this.refresh();
900
  }
901
+ const self = this;
902
 
903
  // Hide dropdown on click on everything but the dropdown and its children.
904
  jQuery( document ).on( 'click', '#wpwrap', function () {
925
  self.refresh();
926
  } );
927
  }
928
+ }
modules/gadsense/admin/assets/js/connect-adsense.js CHANGED
@@ -164,19 +164,21 @@
164
  INSTANCE.switchContent( 'error' );
165
  INSTANCE.frame.find( '.error-message' ).text( JSON.stringify( response ) );
166
  }
167
- } else {
168
- if ( response.data.error ) {
 
 
 
169
  INSTANCE.switchContent( 'error' );
170
- INSTANCE.frame.find( '.error-message' ).text( response.data.error );
171
- if ( 'undefined' != typeof AdsenseMAPI.connectErrorMsg[response.data.error] ) {
172
- INSTANCE.frame.find( '.error-description' ).html( AdsenseMAPI.connectErrorMsg[response.data.error] );
173
  }
174
- } else if ( response.data.message ) {
175
- INSTANCE.frame.find( '.error-message' ).text( response.data.message );
176
  }
 
177
  }
178
- },
179
- error: function ( request, status, error ) {
180
  $( '#gadsense-loading-overlay' ).css( 'display', 'none' );
181
  }
182
  } );
164
  INSTANCE.switchContent( 'error' );
165
  INSTANCE.frame.find( '.error-message' ).text( JSON.stringify( response ) );
166
  }
167
+ }
168
+ },
169
+ error: function ( request, status, error ) {
170
+ if ( request.responseJSON ) {
171
+ if ( request.responseJSON.data.error ) {
172
  INSTANCE.switchContent( 'error' );
173
+ INSTANCE.frame.find( '.error-message' ).text( request.responseJSON.data.error );
174
+ if ( typeof AdsenseMAPI.connectErrorMsg[request.responseJSON.data.error] !== 'undefined' ) {
175
+ INSTANCE.frame.find( '.error-description' ).html( AdsenseMAPI.connectErrorMsg[request.responseJSON.data.error] );
176
  }
177
+ } else if ( request.responseJSON.data.message ) {
178
+ INSTANCE.frame.find( '.error-message' ).text( request.responseJSON.data.message );
179
  }
180
+ return;
181
  }
 
 
182
  $( '#gadsense-loading-overlay' ).css( 'display', 'none' );
183
  }
184
  } );
modules/gadsense/admin/assets/js/mapi-settings.js CHANGED
@@ -139,7 +139,7 @@
139
  } );
140
 
141
  $( function(){
142
- if ( '' === $( '#adsense-id' ).val().trim() && $('#adsense-manual-config').is(':visible') ) {
143
  $( '#adsense #submit' ).parent().css( 'display', 'none' );
144
  }
145
  } );
139
  } );
140
 
141
  $( function(){
142
+ if ( $( '#adsense-id' ).val().trim() === '' ) {
143
  $( '#adsense #submit' ).parent().css( 'display', 'none' );
144
  }
145
  } );
modules/gadsense/includes/adsense-report-api.php CHANGED
@@ -6,19 +6,18 @@
6
  class Advanced_Ads_AdSense_Report_Api {
7
 
8
  /**
9
- * Report endpoint.
10
  *
11
  * @var string
12
  */
13
- const ENDPOINT_URL = 'https://adsense.googleapis.com/v2/accounts/%pubid%/reports:generate?startDate.year=%SY%&startDate.month=%SM%&startDate.day=%SD%'
14
- . '&endDate.year=%EY%&endDate.day=%ED%&endDate.month=%EM%&dimensions=%DIM%&dimensions=DATE&metrics=ESTIMATED_EARNINGS&reportingTimeZone=ACCOUNT_TIME_ZONE';
15
 
16
  /**
17
- * Version of the AdSense Management API in use (for getting fresh data).
18
  *
19
  * @var string
20
  */
21
- const API_VERSION = '2.0';
22
 
23
  /**
24
  * Report type
@@ -51,6 +50,20 @@ class Advanced_Ads_AdSense_Report_Api {
51
  $this->type = $type;
52
  $this->access_token = Advanced_Ads_AdSense_MAPI::get_access_token( $publisher_id );
53
  $this->publisher_id = $publisher_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  }
55
 
56
  /**
@@ -87,9 +100,8 @@ class Advanced_Ads_AdSense_Report_Api {
87
  */
88
  public function call_google() {
89
  $dimension = $this->type === 'unit' ? 'AD_UNIT_ID' : 'DOMAIN_NAME';
90
- $today = date_create( 'now' );
91
- $start_date = date_create( 'now' )->sub( date_interval_create_from_date_string( '28 days' ) );
92
-
93
  // Replace placeholder in the endpoint with actual arguments.
94
  $url = str_replace(
95
  array(
@@ -112,7 +124,7 @@ class Advanced_Ads_AdSense_Report_Api {
112
  $today->format( 'n' ),
113
  $today->format( 'j' ),
114
  ),
115
- self::ENDPOINT_URL
116
  );
117
 
118
  $headers = array(
@@ -152,10 +164,10 @@ class Advanced_Ads_AdSense_Report_Api {
152
  }
153
 
154
  $response_body['api_version'] = self::API_VERSION;
155
- $response_body['timestamp'] = time();
156
 
157
  return array(
158
- 'status' => true,
159
  'response_body' => $response_body,
160
  );
161
  }
6
  class Advanced_Ads_AdSense_Report_Api {
7
 
8
  /**
9
+ * Version of the AdSense Management API in use (for getting fresh data).
10
  *
11
  * @var string
12
  */
13
+ const API_VERSION = '2.0';
 
14
 
15
  /**
16
+ * Report API endpoint.
17
  *
18
  * @var string
19
  */
20
+ private $endpoint_url;
21
 
22
  /**
23
  * Report type
50
  $this->type = $type;
51
  $this->access_token = Advanced_Ads_AdSense_MAPI::get_access_token( $publisher_id );
52
  $this->publisher_id = $publisher_id;
53
+
54
+ $endpoint_args = array(
55
+ 'startDate.year' => '%SY%', // Start date's year - integer (4 digits).
56
+ 'startDate.month' => '%SM%', // Start date's month - integer.
57
+ 'startDate.day' => '%SD%', // Start date's integer - integer.
58
+ 'endDate.year' => '%EY%', // End date's year - integer (4 digits).
59
+ 'endDate.month' => '%EM%', // End date's month - integer.
60
+ 'endDate.day' => '%ED%', // End date's integer - integer.
61
+ 'dimension1' => '%DIM%', // Primary reporting dimension (domain name or ad unit name).
62
+ 'dimension2' => 'DATE', // Secondary reporting dimension.
63
+ 'metrics' => 'ESTIMATED_EARNINGS', // Report metrics.
64
+ 'reportingTimeZone' => 'ACCOUNT_TIME_ZONE', // Time zone used in report data.
65
+ );
66
+ $this->endpoint_url = str_replace( array( 'dimension1', 'dimension2' ), 'dimensions', add_query_arg( $endpoint_args, 'https://adsense.googleapis.com/v2/accounts/%pubid%/reports:generate' ) );
67
  }
68
 
69
  /**
100
  */
101
  public function call_google() {
102
  $dimension = $this->type === 'unit' ? 'AD_UNIT_ID' : 'DOMAIN_NAME';
103
+ $today = new DateTimeImmutable();
104
+ $start_date = $today->sub( date_interval_create_from_date_string( '28 days' ) );
 
105
  // Replace placeholder in the endpoint with actual arguments.
106
  $url = str_replace(
107
  array(
124
  $today->format( 'n' ),
125
  $today->format( 'j' ),
126
  ),
127
+ $this->endpoint_url
128
  );
129
 
130
  $headers = array(
164
  }
165
 
166
  $response_body['api_version'] = self::API_VERSION;
167
+ $response_body['timestamp'] = time();
168
 
169
  return array(
170
+ 'status' => true,
171
  'response_body' => $response_body,
172
  );
173
  }
modules/gadsense/includes/adsense-report-data.php CHANGED
@@ -36,7 +36,7 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
36
  /**
37
  * Report type. 'unit' or 'domain'.
38
  *
39
- * @var null|string
40
  */
41
  private $type;
42
 
@@ -161,7 +161,7 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
161
  foreach ( $row['cells'] as $index => $cell ) {
162
  switch ( $headers[ $index ] ) {
163
  case 'DATE':
164
- $earning->date = new DateTime( $cell['value'] );
165
  break;
166
  case 'ESTIMATED_EARNINGS':
167
  $earning->estimated_earning = (float) $cell['value'];
@@ -229,10 +229,10 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
229
  * @return int[]
230
  */
231
  public function get_sums( $filter = '' ) {
232
- $today = new DateTime();
233
- $yesterday = date_create()->sub( date_interval_create_from_date_string( '1 day' ) );
234
- $prev7 = date_create()->sub( date_interval_create_from_date_string( '7 days' ) );
235
- $prev28 = date_create()->sub( date_interval_create_from_date_string( '28 days' ) );
236
  $sums = array(
237
  'today' => 0,
238
  'yesterday' => 0,
@@ -273,12 +273,12 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
273
  /**
274
  * Get an integer representation of a DateTime object to be used in date comparison.
275
  *
276
- * @param DateTime $date the DateTime object.
277
  *
278
  * @return int
279
  */
280
  private function date_ymd( $date ) {
281
- if ( $date instanceof DateTime ) {
282
  return (int) $date->format( 'Ymd' );
283
  }
284
 
36
  /**
37
  * Report type. 'unit' or 'domain'.
38
  *
39
+ * @var string
40
  */
41
  private $type;
42
 
161
  foreach ( $row['cells'] as $index => $cell ) {
162
  switch ( $headers[ $index ] ) {
163
  case 'DATE':
164
+ $earning->date = new DateTimeImmutable( $cell['value'] );
165
  break;
166
  case 'ESTIMATED_EARNINGS':
167
  $earning->estimated_earning = (float) $cell['value'];
229
  * @return int[]
230
  */
231
  public function get_sums( $filter = '' ) {
232
+ $today = new DateTimeImmutable();
233
+ $yesterday = $today->sub( date_interval_create_from_date_string( '1 day' ) );
234
+ $prev7 = $today->sub( date_interval_create_from_date_string( '7 days' ) );
235
+ $prev28 = $today->sub( date_interval_create_from_date_string( '28 days' ) );
236
  $sums = array(
237
  'today' => 0,
238
  'yesterday' => 0,
273
  /**
274
  * Get an integer representation of a DateTime object to be used in date comparison.
275
  *
276
+ * @param DateTimeInterface $date the date object.
277
  *
278
  * @return int
279
  */
280
  private function date_ymd( $date ) {
281
+ if ( $date instanceof DateTimeInterface ) {
282
  return (int) $date->format( 'Ymd' );
283
  }
284
 
modules/gadsense/includes/class-adsense-report.php CHANGED
@@ -28,6 +28,13 @@ class Advanced_Ads_AdSense_Report {
28
  */
29
  private $data_object;
30
 
 
 
 
 
 
 
 
31
  /**
32
  * Instance constructor.
33
  *
@@ -52,11 +59,12 @@ class Advanced_Ads_AdSense_Report {
52
  /**
53
  * Tries to get fresh data from Google.
54
  *
55
- * @return bool|string true if new data was obtained, an error message otherwise.
56
  */
57
- public function get_fresh_report() {
58
  $api_helper = new Advanced_Ads_AdSense_Report_Api( $this->type );
59
  $error = array();
 
60
  if ( $api_helper->has_token() ) {
61
  $response = $api_helper->call_google();
62
  if ( $response['status'] === true ) {
@@ -65,21 +73,46 @@ class Advanced_Ads_AdSense_Report {
65
  return true;
66
  }
67
  if ( isset( $response['msg'] ) ) {
68
- $error['msg'] = $response['msg'];
 
 
69
  }
70
  }
 
71
  if ( $api_helper->has_token_error() ) {
72
  $error = $api_helper->get_token_error();
73
  }
74
 
75
  if ( isset( $error['msg'] ) ) {
76
- return wp_kses_post( $error['msg'] );
 
 
77
  }
 
78
  if ( isset( $error['raw'] ) ) {
79
- return wp_kses_post( $error['raw'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  }
81
 
82
- return esc_html__( 'No valid tokens', 'advanced-ads' );
83
  }
84
 
85
  /**
28
  */
29
  private $data_object;
30
 
31
+ /**
32
+ * Error from the last attempt to call Google.
33
+ *
34
+ * @var string
35
+ */
36
+ private $last_api_error_message;
37
+
38
  /**
39
  * Instance constructor.
40
  *
59
  /**
60
  * Tries to get fresh data from Google.
61
  *
62
+ * @return bool true if we got fresh data.
63
  */
64
+ public function refresh_report() {
65
  $api_helper = new Advanced_Ads_AdSense_Report_Api( $this->type );
66
  $error = array();
67
+
68
  if ( $api_helper->has_token() ) {
69
  $response = $api_helper->call_google();
70
  if ( $response['status'] === true ) {
73
  return true;
74
  }
75
  if ( isset( $response['msg'] ) ) {
76
+ $this->last_api_error_message = $response['msg'];
77
+
78
+ return false;
79
  }
80
  }
81
+
82
  if ( $api_helper->has_token_error() ) {
83
  $error = $api_helper->get_token_error();
84
  }
85
 
86
  if ( isset( $error['msg'] ) ) {
87
+ $this->last_api_error_message = $error['msg'];
88
+
89
+ return false;
90
  }
91
+
92
  if ( isset( $error['raw'] ) ) {
93
+ $this->last_api_error_message = $error['raw'];
94
+
95
+ return false;
96
+ }
97
+
98
+ if ( empty( $this->last_api_error_message ) ) {
99
+ $this->last_api_error_message = __( 'No valid tokens', 'advanced-ads' );
100
+ }
101
+
102
+ return false;
103
+ }
104
+
105
+ /**
106
+ * Retrieve the error message from the last API call.
107
+ *
108
+ * @return string Error message from the last API call.
109
+ */
110
+ public function get_last_api_error() {
111
+ if ( empty( $this->last_api_error_message ) ) {
112
+ return '';
113
  }
114
 
115
+ return $this->last_api_error_message;
116
  }
117
 
118
  /**
modules/gadsense/includes/class-mapi.php CHANGED
@@ -376,7 +376,6 @@ class Advanced_Ads_AdSense_MAPI {
376
  if ( $ad_code === null || ! isset( $ad_code['adCode'] ) ) {
377
  if ( $ad_code['error']
378
  && $ad_code['error']['errors']
379
- && isset( $ad_code['error']['errors'][0] )
380
  && isset( $ad_code['error']['errors'][0]['reason'] )
381
  && $ad_code['error']['errors'][0]['reason'] === 'doesNotSupportAdUnitType'
382
  ) {
@@ -1025,15 +1024,13 @@ class Advanced_Ads_AdSense_MAPI {
1025
  if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
1026
  die;
1027
  }
1028
- $nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
1029
- if ( false !== wp_verify_nonce( $nonce, 'advads-mapi' ) && isset( $_POST['account'] ) ) {
1030
- $account = stripslashes( $_POST['account'] );
 
1031
  $units = self::get_ad_units( $account );
1032
 
1033
  if ( true === $units ) {
1034
- $options = self::get_option();
1035
- $ad_units = $options['accounts'][ $account ]['ad_units'];
1036
-
1037
  ob_start();
1038
  Advanced_Ads_AdSense_Admin::get_mapi_ad_selector();
1039
  $ad_selector = ob_get_clean();
@@ -1104,7 +1101,7 @@ class Advanced_Ads_AdSense_MAPI {
1104
  $nonce = isset( $post_data['nonce'] ) ? $post_data['nonce'] : '';
1105
 
1106
  if ( ! wp_verify_nonce( $nonce, 'advads-mapi' ) ) {
1107
- die( 'invalid authorization' );
1108
  }
1109
 
1110
  $url = 'https://adsense.googleapis.com/v2/accounts';
@@ -1150,44 +1147,43 @@ class Advanced_Ads_AdSense_MAPI {
1150
 
1151
  if ( is_wp_error( $child_accounts ) ) {
1152
  wp_send_json_error( $child_accounts, 500 );
1153
- } else {
1154
- $accounts_list = json_decode( trim( $child_accounts['body'] ), true );
1155
- if ( trim( $child_accounts['body'] ) === '{}' ) {
1156
- // Standard AdSense account.
1157
- $options = self::get_option();
1158
- $options['connect_error'] = array();
1159
- update_option( self::OPTNAME, $options );
1160
- self::save_token_from_data( $token_data, $accounts['accounts'][0] );
1161
- wp_send_json_success( array(
1162
- 'reload' => true,
1163
- ) );
1164
- }
1165
- if ( $accounts_list !== null ) {
1166
- // Network account.
1167
- $details = array();
1168
- $html = '';
1169
- $details[ $pub_id ] = array(
1170
- 'id' => $pub_id,
1171
- 'name' => $accounts['accounts'][0]['displayName'],
1172
- );
1173
- $html .= sprintf( '<option value="%1$s">%2$s [%3$s]</option>', esc_attr( $pub_id ), esc_html( $accounts['accounts'][0]['displayName'] ), esc_html( $pub_id ) );
1174
 
1175
- foreach ( $accounts_list['accounts'] as $item ) {
1176
- $account_id = explode( '/', $item['name'] )[1];
1177
- $details[ $account_id ] = array(
1178
- 'id' => $account_id,
1179
- 'name' => $item['displayName'],
1180
- );
1181
- $html .= sprintf( '<option value="%1$s">%2$s [%3$s]</option>', esc_attr( $account_id ), esc_html( $item['displayName'] ), esc_html( $account_id ) );
1182
- }
1183
- wp_send_json_success( array(
1184
- 'details' => $details,
1185
- 'html' => $html,
1186
- 'token_data' => $token_data,
1187
- ) );
1188
  }
1189
- wp_send_json_error( array( 'message' => 'unexpected response - get child accounts' ) );
 
 
 
 
1190
  }
 
1191
  }
1192
  }
1193
 
376
  if ( $ad_code === null || ! isset( $ad_code['adCode'] ) ) {
377
  if ( $ad_code['error']
378
  && $ad_code['error']['errors']
 
379
  && isset( $ad_code['error']['errors'][0]['reason'] )
380
  && $ad_code['error']['errors'][0]['reason'] === 'doesNotSupportAdUnitType'
381
  ) {
1024
  if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) ) ) {
1025
  die;
1026
  }
1027
+ $post_vars = wp_unslash( $_POST );
1028
+ $nonce = isset( $post_vars['nonce'] ) ? wp_strip_all_tags( $post_vars['nonce'] ) : '';
1029
+ if ( wp_verify_nonce( $nonce, 'advads-mapi' ) && isset( $post_vars['account'] ) ) {
1030
+ $account = wp_strip_all_tags( stripslashes( $post_vars['account'] ) );
1031
  $units = self::get_ad_units( $account );
1032
 
1033
  if ( true === $units ) {
 
 
 
1034
  ob_start();
1035
  Advanced_Ads_AdSense_Admin::get_mapi_ad_selector();
1036
  $ad_selector = ob_get_clean();
1101
  $nonce = isset( $post_data['nonce'] ) ? $post_data['nonce'] : '';
1102
 
1103
  if ( ! wp_verify_nonce( $nonce, 'advads-mapi' ) ) {
1104
+ wp_send_json_error( 'invalid authorization', 401 );
1105
  }
1106
 
1107
  $url = 'https://adsense.googleapis.com/v2/accounts';
1147
 
1148
  if ( is_wp_error( $child_accounts ) ) {
1149
  wp_send_json_error( $child_accounts, 500 );
1150
+ }
1151
+ $accounts_list = json_decode( trim( $child_accounts['body'] ), true );
1152
+ if ( trim( $child_accounts['body'] ) === '{}' ) {
1153
+ // Standard AdSense account.
1154
+ $options = self::get_option();
1155
+ $options['connect_error'] = array();
1156
+ update_option( self::OPTNAME, $options );
1157
+ self::save_token_from_data( $token_data, $accounts['accounts'][0] );
1158
+ wp_send_json_success( array(
1159
+ 'reload' => true,
1160
+ ) );
1161
+ }
1162
+ if ( $accounts_list !== null ) {
1163
+ // Network account.
1164
+ $details = array();
1165
+ $html = '';
1166
+ $details[ $pub_id ] = array(
1167
+ 'id' => $pub_id,
1168
+ 'name' => $accounts['accounts'][0]['displayName'],
1169
+ );
1170
+ $html .= sprintf( '<option value="%1$s">%2$s [%3$s]</option>', esc_attr( $pub_id ), esc_html( $accounts['accounts'][0]['displayName'] ), esc_html( $pub_id ) );
1171
 
1172
+ foreach ( $accounts_list['accounts'] as $item ) {
1173
+ $account_id = explode( '/', $item['name'] )[1];
1174
+ $details[ $account_id ] = array(
1175
+ 'id' => $account_id,
1176
+ 'name' => $item['displayName'],
1177
+ );
1178
+ $html .= sprintf( '<option value="%1$s">%2$s [%3$s]</option>', esc_attr( $account_id ), esc_html( $item['displayName'] ), esc_html( $account_id ) );
 
 
 
 
 
 
1179
  }
1180
+ wp_send_json_success( array(
1181
+ 'details' => $details,
1182
+ 'html' => $html,
1183
+ 'token_data' => $token_data,
1184
+ ) );
1185
  }
1186
+ wp_send_json_error( array( 'message' => 'unexpected response - get child accounts' ), 400 );
1187
  }
1188
  }
1189
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: ads, ad manager, ad rotation, adsense, banner
4
  Requires at least: 4.9
5
  Tested up to: 5.8
6
  Requires PHP: 5.6
7
- Stable tag: 1.29.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -322,6 +322,12 @@ Yes. You can use plenty of [hooks](https://wpadvancedads.com/codex/) to customiz
322
 
323
  == Changelog ==
324
 
 
 
 
 
 
 
325
  = 1.29.0 =
326
 
327
  - Improvement: update AdSense API to V2
4
  Requires at least: 4.9
5
  Tested up to: 5.8
6
  Requires PHP: 5.6
7
+ Stable tag: 1.29.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
322
 
323
  == Changelog ==
324
 
325
+ = 1.29.1 =
326
+
327
+ - Fix: ensure `Advanced_Ads_Adsense_Report_Helper` JavaScript global is defined
328
+ - Fix: hide AdSense setting submit button if there is no publisher ID
329
+ - Fix: show error message when no AdSense account data found
330
+
331
  = 1.29.0 =
332
 
333
  - Improvement: update AdSense API to V2