Advanced Ads - Version 1.14.2

Version Description

  • preparations for Advanced Ads Pro 2.4.2
  • fixed time zone difference in AdSense reporting
  • fixed script dependency in the backend
Download this release

Release Info

Developer webzunft
Plugin Icon 128x128 Advanced Ads
Version 1.14.2
Comparing to
See all releases

Code changes from version 1.14.1 to 1.14.2

admin/assets/js/admin.js CHANGED
@@ -1131,13 +1131,14 @@ if (! window.AdvancedAdsAdmin.AdImporter) window.AdvancedAdsAdmin.AdImporter = {
1131
  const tbody = $( '#mapi-table-wrap tbody' );
1132
  const btn = $('#mapi-toggle-idle');
1133
 
1134
- // update the style, if neccessary
1135
  const nbUnits = hideInactive
1136
  ? $( '#mapi-table-wrap tbody tr[data-active=1]' ).length
1137
  : $( '#mapi-table-wrap tbody tr' ).length;
1138
  if (nbUnits > 8) $( '#mapi-table-wrap' ).addClass('overflow');
1139
  else $( '#mapi-table-wrap' ).removeClass('overflow');
1140
 
 
1141
  if (hideInactive) {
1142
  btn.removeClass('dashicons-hidden');
1143
  btn.addClass('dashicons-visibility');
@@ -1155,14 +1156,25 @@ if (! window.AdvancedAdsAdmin.AdImporter) window.AdvancedAdsAdmin.AdImporter = {
1155
  tbody.find('tr[data-slotid]').show();
1156
  }
1157
 
1158
- tbody.find( 'tr' ).removeClass( 'selected' );
1159
  const selectedRow = AdvancedAdsAdmin.AdImporter.getSelectedRow();
 
1160
  if (selectedRow){
1161
- selectedRow.addClass( 'selected' );
1162
  selectedRow.show();
1163
- return selectedRow;
1164
  }
1165
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
1166
  },
1167
  getSelectedRow(){
1168
  const selectedId = AdvancedAdsAdmin.AdImporter.adNetwork.getSelectedId();
@@ -1207,10 +1219,23 @@ if (! window.AdvancedAdsAdmin.AdImporter) window.AdvancedAdsAdmin.AdImporter = {
1207
  }
1208
  AdvancedAdsAdmin.AdImporter.resizeAdListHeader();
1209
  },
 
 
 
 
 
 
 
 
 
 
1210
  setup: function (adNetwork) {
1211
  AdvancedAdsAdmin.AdImporter.adNetwork = adNetwork;
1212
  adNetwork.onSelected();
1213
- if (AdvancedAdsAdmin.AdImporter.isSetup) return;
 
 
 
1214
  AdvancedAdsAdmin.AdImporter.isSetup = true;
1215
 
1216
  $( document ).on( 'click', '.prevent-default', function( ev ) { ev.preventDefault() } );
@@ -1266,7 +1291,6 @@ if (! window.AdvancedAdsAdmin.AdImporter) window.AdvancedAdsAdmin.AdImporter = {
1266
  AdvancedAdsAdmin.AdImporter.adNetwork.onDomReady();
1267
  // AdvancedAdsAdmin.AdImporter.openExternalAdsList();
1268
 
1269
-
1270
  },
1271
 
1272
  /**
@@ -1457,6 +1481,13 @@ class AdvancedAdsAdNetwork{
1457
  console.error("Please override onSelected.");
1458
  }
1459
 
 
 
 
 
 
 
 
1460
  /**
1461
  * opens the selector list containing the external ad units
1462
  */
1131
  const tbody = $( '#mapi-table-wrap tbody' );
1132
  const btn = $('#mapi-toggle-idle');
1133
 
1134
+ // count the ad units to determine if there's a need for the overflow class (scrolling)
1135
  const nbUnits = hideInactive
1136
  ? $( '#mapi-table-wrap tbody tr[data-active=1]' ).length
1137
  : $( '#mapi-table-wrap tbody tr' ).length;
1138
  if (nbUnits > 8) $( '#mapi-table-wrap' ).addClass('overflow');
1139
  else $( '#mapi-table-wrap' ).removeClass('overflow');
1140
 
1141
+ // hide inactive ads, but always show the selected one (if any)
1142
  if (hideInactive) {
1143
  btn.removeClass('dashicons-hidden');
1144
  btn.addClass('dashicons-visibility');
1156
  tbody.find('tr[data-slotid]').show();
1157
  }
1158
 
 
1159
  const selectedRow = AdvancedAdsAdmin.AdImporter.getSelectedRow();
1160
+ tbody.find( 'tr' ).removeClass( 'selected' );
1161
  if (selectedRow){
1162
+ //make sure, it is visible before applying the zebra stripes
1163
  selectedRow.show();
 
1164
  }
1165
+
1166
+ // make the table's rows striped.
1167
+ const visible = tbody.find( 'tr:visible' );
1168
+ visible.filter( ':odd' ).css('background-color', '#FFFFFF');
1169
+ visible.filter( ':even' ).css('background-color', '#F9F9F9');
1170
+
1171
+ // highlight the selected row
1172
+ if (selectedRow){
1173
+ // highlight the selected row
1174
+ selectedRow.css('background-color', '');
1175
+ selectedRow.addClass( 'selected' );
1176
+ }
1177
+ return selectedRow || false;
1178
  },
1179
  getSelectedRow(){
1180
  const selectedId = AdvancedAdsAdmin.AdImporter.adNetwork.getSelectedId();
1219
  }
1220
  AdvancedAdsAdmin.AdImporter.resizeAdListHeader();
1221
  },
1222
+ /**
1223
+ * will be called every time the ad type is changed.
1224
+ * required for onBlur detection
1225
+ */
1226
+ onChangedAdType: function(){
1227
+ if (AdvancedAdsAdmin.AdImporter.adNetwork){
1228
+ AdvancedAdsAdmin.AdImporter.adNetwork.onBlur();
1229
+ AdvancedAdsAdmin.AdImporter.adNetwork = null;
1230
+ }
1231
+ },
1232
  setup: function (adNetwork) {
1233
  AdvancedAdsAdmin.AdImporter.adNetwork = adNetwork;
1234
  adNetwork.onSelected();
1235
+ if (AdvancedAdsAdmin.AdImporter.isSetup) {
1236
+ AdvancedAdsAdmin.AdImporter.highlightSelectedRowInExternalAdsList();
1237
+ return;
1238
+ }
1239
  AdvancedAdsAdmin.AdImporter.isSetup = true;
1240
 
1241
  $( document ).on( 'click', '.prevent-default', function( ev ) { ev.preventDefault() } );
1291
  AdvancedAdsAdmin.AdImporter.adNetwork.onDomReady();
1292
  // AdvancedAdsAdmin.AdImporter.openExternalAdsList();
1293
 
 
1294
  },
1295
 
1296
  /**
1481
  console.error("Please override onSelected.");
1482
  }
1483
 
1484
+ /**
1485
+ * will be called when an ad network deselected (ad type in edit ad)
1486
+ */
1487
+ onBlur(){
1488
+ console.error("Please override onBlur.");
1489
+ }
1490
+
1491
  /**
1492
  * opens the selector list containing the external ad units
1493
  */
admin/includes/class-ad-network.php CHANGED
@@ -171,7 +171,7 @@ abstract class Advanced_Ads_Ad_Network{
171
  $js_path = $this->get_javascript_base_path();
172
  if ($js_path) {
173
  $id = $this->get_js_library_name();
174
- wp_enqueue_script($id, $js_path, array('jquery', 'advanced-ads-admin-script'));
175
  // next we have to pass the data.
176
  $data = array(
177
  'nonce' => $this->get_nonce()
171
  $js_path = $this->get_javascript_base_path();
172
  if ($js_path) {
173
  $id = $this->get_js_library_name();
174
+ wp_enqueue_script($id, $js_path, array('jquery'));
175
  // next we have to pass the data.
176
  $data = array(
177
  'nonce' => $this->get_nonce()
admin/includes/class-notices.php CHANGED
@@ -171,13 +171,19 @@ class Advanced_Ads_Admin_Notices {
171
  }
172
  }
173
  // ask for a review after 2 days and when 3 ads were created and when not paused
174
- if ( ! in_array( 'review', $queue )
175
  && ! isset( $closed['review'] )
176
  && ( ! isset( $paused['review'] ) || $paused['review'] <= time() )
177
  && 172800 < ( time() - $activation)
178
  && 3 <= Advanced_Ads::get_number_of_ads()
179
  ) {
180
  $this->notices[] = 'review';
 
 
 
 
 
 
181
  }
182
  }
183
 
171
  }
172
  }
173
  // ask for a review after 2 days and when 3 ads were created and when not paused
174
+ if ( ! in_array( 'review', $queue )
175
  && ! isset( $closed['review'] )
176
  && ( ! isset( $paused['review'] ) || $paused['review'] <= time() )
177
  && 172800 < ( time() - $activation)
178
  && 3 <= Advanced_Ads::get_number_of_ads()
179
  ) {
180
  $this->notices[] = 'review';
181
+ } elseif ( 3 > Advanced_Ads::get_number_of_ads() ){
182
+ // remove the notice in case the number of ads dropped
183
+ $key = array_search( 'review', $this->notices );
184
+ if ( $key !== false ) {
185
+ unset( $this->notices[$key]);
186
+ }
187
  }
188
  }
189
 
admin/views/ad-main-metabox.php CHANGED
@@ -22,6 +22,7 @@
22
  <?php endif; ?>
23
  <script>
24
  jQuery( document ).on('change', '#advanced-ad-type input', function () {
 
25
  advads_update_ad_type_headline();
26
  });
27
 
22
  <?php endif; ?>
23
  <script>
24
  jQuery( document ).on('change', '#advanced-ad-type input', function () {
25
+ AdvancedAdsAdmin.AdImporter.onChangedAdType();
26
  advads_update_ad_type_headline();
27
  });
28
 
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.14.1
16
  * Author: Thomas Maier
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.14.1' );
43
 
44
  /*----------------------------------------------------------------------------*
45
  * Autoloading, modules and functions
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: https://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
+ * Version: 1.14.2
16
  * Author: Thomas Maier
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.14.2' );
43
 
44
  /*----------------------------------------------------------------------------*
45
  * Autoloading, modules and functions
classes/ad_placements.php CHANGED
@@ -475,7 +475,7 @@ class Advanced_Ads_Placements {
475
 
476
  foreach ( $offsets as $offset ) {
477
  // test ad is emtpy
478
- $adContent = Advanced_Ads_Select::get_instance()->get_ad_by_method( $placement_id, 'placement', $options );
479
  if ( trim( $adContent, $whitespaces ) === '' ) {
480
  continue;
481
  }
475
 
476
  foreach ( $offsets as $offset ) {
477
  // test ad is emtpy
478
+ $adContent = Advanced_Ads_Select::get_instance()->get_ad_by_method( $placement_id, 'placement', $placement_opts );
479
  if ( trim( $adContent, $whitespaces ) === '' ) {
480
  continue;
481
  }
modules/gadsense/admin/assets/js/adsense.js CHANGED
@@ -549,6 +549,10 @@ class AdvancedAdsNetworkAdsense extends AdvancedAdsAdNetwork{
549
  return $elems;
550
  }
551
 
 
 
 
 
552
  onSelected(){
553
  //handle a click from the "Switch to AdSense ad" button
554
  if (AdvancedAdsAdmin.AdImporter.adsenseCode){
549
  return $elems;
550
  }
551
 
552
+ onBlur(){
553
+
554
+ }
555
+
556
  onSelected(){
557
  //handle a click from the "Switch to AdSense ad" button
558
  if (AdvancedAdsAdmin.AdImporter.adsenseCode){
modules/gadsense/includes/class-adsense-report.php CHANGED
@@ -74,6 +74,7 @@ class Advanced_Ads_AdSense_Report_Builder{
74
  foreach ($this->metrics as $metric){
75
  $url .= "&metric=$metric->name";
76
  }
 
77
  return $url;
78
  }
79
  /**
@@ -107,8 +108,15 @@ class Advanced_Ads_AdSense_Report_Builder{
107
  }
108
 
109
  public static function get_age_in_seconds($updated_at){
110
- $timestamp = ($updated_at) ? $updated_at->getTimestamp() : 0;
111
- return (new DateTime())->getTimestamp() - $timestamp;
 
 
 
 
 
 
 
112
  }
113
 
114
  public function build($plotter, $type, $forceRefresh = false, $allowRefresh = true){
@@ -132,7 +140,7 @@ class Advanced_Ads_AdSense_Report_Builder{
132
  unset($response[$key]);
133
  }
134
  }
135
- $response['updatedAt'] = new DateTime();
136
  //set_transient($transient_id, $response, self::TRANSIENT_VALIDITY);
137
  //update_option($transient_id, $response);
138
  $this->save_option($transient_id, $response);
@@ -463,14 +471,21 @@ class Advanced_Ads_AdSense_Dashboard_Summary{
463
 
464
  if (! $report->updatedAt) $summary->age = __("Never", "advanced-ads");
465
  else{
 
 
466
  $date_format = get_option( 'date_format' );
467
- $date = new DateTime();
468
- $today_str = date_i18n($date_format, $date->getTimestamp());
469
- $date = $report->updatedAt;
470
- if (! is_a($date, 'DateTime')) $date = new DateTime();
471
- $is_today = date_i18n($date_format, $date->getTimestamp()) === $today_str;
472
- if ($is_today) $summary->age = date_i18n( get_option( 'time_format' ), $date->getTimestamp());
473
- else $summary->age = date_i18n($date_format, $date->getTimestamp());
 
 
 
 
 
474
  }
475
  $summary->valid = $report->valid;
476
  }
@@ -485,7 +500,27 @@ class Advanced_Ads_AdSense_Dashboard_Summary{
485
 
486
  return $summary;
487
  }
488
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
  private static final function sum($report, $col_index, $nb_days, $offset_days = 0){
490
  $dim = self::createDateDimensionValues($nb_days, $offset_days);
491
  return self::sumDim($report, $col_index, $dim);
74
  foreach ($this->metrics as $metric){
75
  $url .= "&metric=$metric->name";
76
  }
77
+ $url.="&useTimezoneReporting=true";
78
  return $url;
79
  }
80
  /**
108
  }
109
 
110
  public static function get_age_in_seconds($updated_at){
111
+ // when upgrading from a previous version of AA to V1.14.2+ a refresh of the adsense dashboard
112
+ // within one hour, might raise a notice when users are running their site in dev mode
113
+ // originally updated_at was a DateTime, it is a simple timestamp now, so we need to catch
114
+ // the DateTimes and replace them with numbers.
115
+ if (!$updated_at || ! is_integer($updated_at) ){
116
+ //trigger a reload, by setting it to a low, failsafe value
117
+ $updated_at = 0;
118
+ }
119
+ return (new DateTime())->getTimestamp() - $updated_at;
120
  }
121
 
122
  public function build($plotter, $type, $forceRefresh = false, $allowRefresh = true){
140
  unset($response[$key]);
141
  }
142
  }
143
+ $response['updatedAt'] = (new DateTime())->getTimestamp();
144
  //set_transient($transient_id, $response, self::TRANSIENT_VALIDITY);
145
  //update_option($transient_id, $response);
146
  $this->save_option($transient_id, $response);
471
 
472
  if (! $report->updatedAt) $summary->age = __("Never", "advanced-ads");
473
  else{
474
+ $tz = self::get_timezone();
475
+ $date = new DateTime('now', $tz);
476
  $date_format = get_option( 'date_format' );
477
+ $today_str = $date->format($date_format);
478
+
479
+ $date = new DateTime();
480
+ $date->setTimestamp($report->updatedAt);
481
+ $date->setTimezone($tz);
482
+
483
+ if (! is_a($date, 'DateTime')) {
484
+ $date = new DateTime('now', $tz);
485
+ }
486
+ $is_today = $date->format($date_format) === $today_str;
487
+ if ($is_today) $summary->age = $date->format( get_option( 'time_format' ));
488
+ else $summary->age = $date->format($date_format);
489
  }
490
  $summary->valid = $report->valid;
491
  }
500
 
501
  return $summary;
502
  }
503
+
504
+ private static final function get_timezone(){
505
+ $gmt_offset = get_option('gmt_offset');
506
+ $sign = $gmt_offset < 0 ? "-" : "+";
507
+ $gmt_offset = abs($gmt_offset);
508
+ $gmt_offset_modulo = fmod($gmt_offset, 1.0);
509
+ $hours = sprintf("%02d", $gmt_offset);
510
+ $minutes = "00";
511
+ if ($gmt_offset_modulo != 0){
512
+ $minutes = (int)($gmt_offset_modulo * 60);
513
+ }
514
+ $timezone_string = $sign . $hours . $minutes;
515
+ try {
516
+ $tz = new DateTimeZone($timezone_string);
517
+ } catch (Exception $e) {
518
+ error_log($e->getMessage());
519
+ $tz = new DateTimeZone();
520
+ }
521
+ return $tz;
522
+ }
523
+
524
  private static final function sum($report, $col_index, $nb_days, $offset_days = 0){
525
  $dim = self::createDateDimensionValues($nb_days, $offset_days);
526
  return self::sumDim($report, $col_index, $dim);
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: ads, ad manager, ad rotation, adsense, banner
5
  Requires at least: 4.6
6
  Tested up to: 5.2
7
  Requires PHP: 5.6
8
- Stable tag: 1.14.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -290,6 +290,12 @@ Yes. Advanced Ads is based on WordPress standards and therefore easily customiza
290
 
291
  == Changelog ==
292
 
 
 
 
 
 
 
293
  = 1.14.1 =
294
 
295
  * fixed issue with PHP 5.2 (please update to PHP 5.6.20 since it is the minimum requirement of WordPress)
5
  Requires at least: 4.6
6
  Tested up to: 5.2
7
  Requires PHP: 5.6
8
+ Stable tag: 1.14.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
290
 
291
  == Changelog ==
292
 
293
+ = 1.14.2 =
294
+
295
+ * preparations for [Advanced Ads Pro](https://wpadvancedads.com/add-ons/advanced-ads-pro/) 2.4.2
296
+ * fixed time zone difference in AdSense reporting
297
+ * fixed script dependency in the backend
298
+
299
  = 1.14.1 =
300
 
301
  * fixed issue with PHP 5.2 (please update to PHP 5.6.20 since it is the minimum requirement of WordPress)