Ad Inserter – WordPress Ads Management with AdSense Header Integration - Version 2.3.13

Version Description

  • Added support for lazy loading (Pro only)
  • Fix for unwanted insertions with some paragraph settings
  • Few minor bug fixes, cosmetic changes and code improvements
Download this release

Release Info

Developer spacetime
Plugin Icon 128x128 Ad Inserter – WordPress Ads Management with AdSense Header Integration
Version 2.3.13
Comparing to
See all releases

Code changes from version 2.3.12 to 2.3.13

ad-inserter.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
- Version: 2.3.12
6
  Description: Ad management plugin with advanced advertising options to automatically insert ad codes on your website
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
@@ -13,6 +13,11 @@ Plugin URI: http://adinserter.pro/documentation
13
 
14
  Change Log
15
 
 
 
 
 
 
16
  Ad Inserter 2.3.12 - 2018-07-04
17
  - Fix for urlencode error
18
  - Few other minor bug fixes
@@ -659,6 +664,7 @@ $ai_wp_data [AI_ANIMATION] = false;
659
  $ai_wp_data [AI_CLOSE_BUTTONS] = false;
660
  $ai_wp_data [AI_DISABLE_CACHING] = false;
661
  $ai_wp_data [AI_CLIENT_SIDE_INSERTION] = false;
 
662
 
663
  ai_load_settings ();
664
 
@@ -1770,6 +1776,7 @@ function ai_wp_enqueue_scripts_hook () {
1770
  $ai_wp_data [AI_STICK_TO_THE_CONTENT] ||
1771
  $ai_wp_data [AI_ANIMATION] ||
1772
  $ai_wp_data [AI_CLOSE_BUTTONS] ||
 
1773
  (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION && $ai_wp_data [AI_ADB_DETECTION]);
1774
 
1775
  if ($footer_inline_scripts ||
@@ -2071,8 +2078,10 @@ function add_footer_inline_scripts () {
2071
  if ($ai_wp_data [AI_ADB_DETECTION]) {
2072
  if (function_exists ('add_footer_inline_scripts_1')) add_footer_inline_scripts_1 (); else {
2073
  echo '<div id="banner-advert-container" class="ad-inserter chitika-ad" style="position:absolute; z-index: -10; height: 1px; width: 1px; top: -1px; left: -1px;"><img id="adsense" class="SponsorAds adsense" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"></div>', "\n";
 
2074
  echo "<script type='text/javascript' src='", plugins_url ('js/ads.js', __FILE__ ), "?ver=", rand (1, 9999999), "'></script>\n";
2075
  echo "<script type='text/javascript' src='", plugins_url ('js/sponsors.js', __FILE__ ), "?ver=", rand (1, 9999999), "'></script>\n";
 
2076
  }
2077
  }
2078
 
@@ -2088,6 +2097,7 @@ function add_footer_inline_scripts () {
2088
  $ai_wp_data [AI_STICK_TO_THE_CONTENT] ||
2089
  $ai_wp_data [AI_ANIMATION] ||
2090
  $ai_wp_data [AI_CLOSE_BUTTONS] ||
 
2091
  (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION && $ai_wp_data [AI_ADB_DETECTION]);
2092
 
2093
  if (($footer_inline_scripts || $ai_wp_data [AI_CLIENT_SIDE_INSERTION]) && !wp_script_is ('jquery', 'done')) {
@@ -2105,6 +2115,10 @@ function add_footer_inline_scripts () {
2105
 
2106
  $client_side_dynamic_blocks = get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT;
2107
 
 
 
 
 
2108
  if ($client_side_dynamic_blocks || isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION])) {
2109
  echo ai_get_js ('ai-rotate');
2110
  }
@@ -4549,7 +4563,7 @@ function ai_load_settings () {
4549
  $obj->load_options ($block);
4550
  $block_object [$block] = $obj;
4551
 
4552
- if ($obj->get_detection_server_side()) $ai_wp_data [AI_SERVER_SIDE_DETECTION] = true;
4553
  if ($obj->get_detection_client_side ()) {
4554
  $ai_wp_data [AI_CLIENT_SIDE_DETECTION] = true;
4555
 
@@ -6462,9 +6476,7 @@ ul.ai-debug-tools .ai-debug-tools-positions {
6462
  }
6463
  } else if ($menu_item ['id'] == 'ai-toolbar-settings') {
6464
  echo ' <li class="ai-debug-', $menu_item ['id'], ' ai-debug-tools-title">';
6465
- // echo '<a href="', $menu_item ['href'], '">', $menu_item ['title'], '</a>';
6466
- // echo '<a href="', $menu_item ['href'], '">', str_replace (AD_INSERTER_NAME, 'Debugging', $menu_item ['title']), '</a>';
6467
- echo '<a href="', $menu_item ['href'], '">', $menu_item ['title'], ' Debugging</a>';
6468
  echo "</li>\n";
6469
  }
6470
  }
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
+ Version: 2.3.13
6
  Description: Ad management plugin with advanced advertising options to automatically insert ad codes on your website
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
13
 
14
  Change Log
15
 
16
+ Ad Inserter 2.3.13 - 2018-07-11
17
+ - Added support for lazy loading (Pro only)
18
+ - Fix for unwanted insertions with some paragraph settings
19
+ - Few minor bug fixes, cosmetic changes and code improvements
20
+
21
  Ad Inserter 2.3.12 - 2018-07-04
22
  - Fix for urlencode error
23
  - Few other minor bug fixes
664
  $ai_wp_data [AI_CLOSE_BUTTONS] = false;
665
  $ai_wp_data [AI_DISABLE_CACHING] = false;
666
  $ai_wp_data [AI_CLIENT_SIDE_INSERTION] = false;
667
+ $ai_wp_data [AI_LAZY_LOADING] = false;
668
 
669
  ai_load_settings ();
670
 
1776
  $ai_wp_data [AI_STICK_TO_THE_CONTENT] ||
1777
  $ai_wp_data [AI_ANIMATION] ||
1778
  $ai_wp_data [AI_CLOSE_BUTTONS] ||
1779
+ $ai_wp_data [AI_LAZY_LOADING] ||
1780
  (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION && $ai_wp_data [AI_ADB_DETECTION]);
1781
 
1782
  if ($footer_inline_scripts ||
2078
  if ($ai_wp_data [AI_ADB_DETECTION]) {
2079
  if (function_exists ('add_footer_inline_scripts_1')) add_footer_inline_scripts_1 (); else {
2080
  echo '<div id="banner-advert-container" class="ad-inserter chitika-ad" style="position:absolute; z-index: -10; height: 1px; width: 1px; top: -1px; left: -1px;"><img id="adsense" class="SponsorAds adsense" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"></div>', "\n";
2081
+ echo '<!--noptimize-->', "\n";
2082
  echo "<script type='text/javascript' src='", plugins_url ('js/ads.js', __FILE__ ), "?ver=", rand (1, 9999999), "'></script>\n";
2083
  echo "<script type='text/javascript' src='", plugins_url ('js/sponsors.js', __FILE__ ), "?ver=", rand (1, 9999999), "'></script>\n";
2084
+ echo '<!--/noptimize-->', "\n";
2085
  }
2086
  }
2087
 
2097
  $ai_wp_data [AI_STICK_TO_THE_CONTENT] ||
2098
  $ai_wp_data [AI_ANIMATION] ||
2099
  $ai_wp_data [AI_CLOSE_BUTTONS] ||
2100
+ $ai_wp_data [AI_LAZY_LOADING] ||
2101
  (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION && $ai_wp_data [AI_ADB_DETECTION]);
2102
 
2103
  if (($footer_inline_scripts || $ai_wp_data [AI_CLIENT_SIDE_INSERTION]) && !wp_script_is ('jquery', 'done')) {
2115
 
2116
  $client_side_dynamic_blocks = get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT;
2117
 
2118
+ if ($ai_wp_data [AI_LAZY_LOADING]) {
2119
+ echo ai_get_js ('ai-load');
2120
+ }
2121
+
2122
  if ($client_side_dynamic_blocks || isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION])) {
2123
  echo ai_get_js ('ai-rotate');
2124
  }
4563
  $obj->load_options ($block);
4564
  $block_object [$block] = $obj;
4565
 
4566
+ if ($obj->get_detection_server_side()) $ai_wp_data [AI_SERVER_SIDE_DETECTION] = true;
4567
  if ($obj->get_detection_client_side ()) {
4568
  $ai_wp_data [AI_CLIENT_SIDE_DETECTION] = true;
4569
 
6476
  }
6477
  } else if ($menu_item ['id'] == 'ai-toolbar-settings') {
6478
  echo ' <li class="ai-debug-', $menu_item ['id'], ' ai-debug-tools-title">';
6479
+ echo '<a href="', $menu_item ['href'], '">', $menu_item ['title'], '</a>';
 
 
6480
  echo "</li>\n";
6481
  }
6482
  }
class.php CHANGED
@@ -408,6 +408,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
408
  $this->wp_options [AI_OPTION_BLOCK_NAME] = AD_NAME;
409
  $this->wp_options [AI_OPTION_DISABLE_INSERTION] = AI_DISABLED;
410
  $this->wp_options [AI_OPTION_SHOW_LABEL] = AI_DISABLED;
 
411
  $this->wp_options [AI_OPTION_TRACKING] = AI_DISABLED;
412
  $this->wp_options [AI_OPTION_AUTOMATIC_INSERTION] = AI_AUTOMATIC_INSERTION_DISABLED;
413
  $this->wp_options [AI_OPTION_HTML_SELECTOR] = AD_EMPTY_DATA;
@@ -510,6 +511,12 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
510
  return $show_label;
511
  }
512
 
 
 
 
 
 
 
513
  public function get_automatic_insertion (){
514
  global $ai_db_options;
515
 
@@ -1743,7 +1750,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1743
  }
1744
 
1745
  $temp_dynamic_blocks = $dynamic_blocks;
1746
- if (($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || $temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) && $ai_wp_data [AI_WP_AMP_PAGE]) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1747
 
1748
  switch ($temp_dynamic_blocks) {
1749
  case AI_DYNAMIC_BLOCKS_SERVER_SIDE:
@@ -1830,6 +1837,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1830
  } else $ad_index_code = ' $ai_index = mt_rand (1, count ($ai_code));';
1831
 
1832
  $this->w3tc_code = '$ai_code = unserialize (base64_decode (\''.base64_encode (serialize ($ads)).'\'));'.$ad_index_code.' $ai_code = base64_decode (\''.base64_encode ($additional_code).'\') . $ai_code [$ai_index - 1]; $ai_enabled = true;';
 
1833
  $processed_code = '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1834
  $processed_code .= $this->w3tc_code.' echo $ai_code;';
1835
  $processed_code .= '<!-- /mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
@@ -1838,9 +1846,10 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1838
  } else $processed_code = $additional_code . $processed_code;
1839
 
1840
  $temp_dynamic_blocks = $dynamic_blocks;
1841
- if ($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_SERVER_SIDE_W3TC && $this->w3tc_code == '') $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1842
- elseif ($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1843
- elseif ($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
 
1844
 
1845
  switch ($temp_dynamic_blocks) {
1846
  case AI_DYNAMIC_BLOCKS_SERVER_SIDE:
@@ -1866,14 +1875,26 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1866
  // $this->w3tc_code .= 'if (strpos ($ai_code, $ai_amp_separator) !== false) {$codes = explode ($ai_amp_separator, $ai_code); $ai_code = trim ($codes [$ai_amp_page ? 1 : 0]); } else {if ($ai_amp_page && !$ai_amp_enabled) $ai_code = \'\';} $ai_enabled = true;';
1867
  $this->w3tc_code .= 'if (strpos ($ai_code, $ai_amp_separator) !== false) {$codes = explode ($ai_amp_separator, $ai_code); $ai_code = trim ($codes [$ai_amp_page ? 1 : 0]); } else {if ($ai_amp_page + !$ai_amp_enabled == 2) $ai_code = \'\';} $ai_enabled = true;';
1868
 
 
 
 
 
 
1869
  $processed_code = '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1870
  $processed_code .= $this->w3tc_code.' echo $ai_code;';
1871
  $processed_code .= '<!-- /mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1872
  break;
1873
  }
1874
 
 
 
 
 
 
 
 
1875
  $temp_dynamic_blocks = $dynamic_blocks;
1876
- if (($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || $temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) && $ai_wp_data [AI_WP_AMP_PAGE]) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1877
 
1878
  if ($temp_dynamic_blocks != AI_DYNAMIC_BLOCKS_SERVER_SIDE) {
1879
  $url_parameters_raw = trim (str_replace (' ', '', $this->get_url_parameter_list ()));
@@ -1899,13 +1920,13 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1899
  switch ($dynamic_blocks) {
1900
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1901
  if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
1902
- $processed_code = "\n<div class='ai-list-data' $referer_attributes $url_parameter_attributes>$processed_code</div>\n";
1903
- } else $processed_code = "\n<div class='ai-list-data' $referer_attributes $url_parameter_attributes style='visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999;'>$processed_code</div>\n";
1904
  break;
1905
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1906
  $code_data = "data-code='".base64_encode ($processed_code)."'";
1907
 
1908
- $processed_code = "\n<div class='ai-list-data' $referer_attributes $url_parameter_attributes $code_data></div>\n";
1909
  break;
1910
  }
1911
 
@@ -1957,13 +1978,13 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1957
  switch ($dynamic_blocks) {
1958
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1959
  if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
1960
- $processed_code = "\n<div class='ai-ip-data' $ip_address_attributes $country_attributes>$processed_code</div>\n";
1961
- } else $processed_code = "\n<div class='ai-ip-data' $ip_address_attributes $country_attributes style='visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999;'>$processed_code</div>\n";
1962
  break;
1963
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1964
  $code_data = "data-code='".base64_encode ($processed_code)."'";
1965
 
1966
- $processed_code = "\n<div class='ai-ip-data' $ip_address_attributes $country_attributes $code_data></div>\n";
1967
  break;
1968
  }
1969
 
@@ -2945,21 +2966,42 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2945
  // if (count ($paragraph_positions) == 0) return $content;
2946
  if (array_sum ($active_paragraph_positions) == 0) return $content;
2947
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2948
 
2949
  $filtered_paragraph_positions = array ();
2950
  foreach ($paragraph_positions as $index => $paragraph_position) {
2951
  if ($active_paragraph_positions [$index]) $filtered_paragraph_positions [] = $paragraph_position;
 
2952
  }
2953
  $paragraph_positions = $filtered_paragraph_positions;
2954
 
2955
 
2956
  if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
2957
- $paragraph_positions = array_reverse ($paragraph_positions);
2958
  }
2959
 
2960
 
2961
- $position_text = trim ($this->get_paragraph_number());
2962
-
2963
  // $positions contains indexes in $paragraph_positions
2964
  $positions = array ();
2965
 
@@ -3003,17 +3045,31 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3003
  $words_above = 0;
3004
  foreach ($paragraph_positions as $index => $paragraph_position) {
3005
 
 
 
 
 
 
 
 
 
 
3006
  if ($multibyte) {
3007
- $paragraph_code = $index == count ($paragraph_positions) - 1 ? mb_substr ($content, $paragraph_position) : mb_substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
 
3008
  } else {
3009
- $paragraph_code = $index == count ($paragraph_positions) - 1 ? substr ($content, $paragraph_position) : substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
 
3010
  }
3011
 
3012
  $words_above += number_of_words ($paragraph_code);
3013
- if ($words_above >= $min_words_above) {
3014
- // $positions []= $index + 1;
3015
- $positions []= $index;
3016
- $words_above = 0;
 
 
 
3017
  }
3018
 
3019
  }
@@ -3313,30 +3369,34 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3313
  return $content;
3314
  }
3315
 
3316
- // Deprecated since $postion is now in array $positions
3317
- $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
3318
- if (count ($paragraph_positions) >= intval ($this->get_paragraph_number_minimum())) {
3319
- $ai_last_check = AI_CHECK_PARAGRAPH_NUMBER;
3320
- if (count ($paragraph_positions) > $position) {
3321
- $this->increment_block_counter ();
3322
 
3323
- $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3324
- if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3325
- $content_position = $paragraph_positions [$position];
 
 
 
3326
 
3327
- if ($multibyte) {
3328
- $content = mb_substr ($content, 0, $content_position) . $this->get_code_for_serverside_insertion () . mb_substr ($content, $content_position);
3329
- } else {
3330
- $content = substr_replace ($content, $this->get_code_for_serverside_insertion (), $content_position, 0);
3331
- }
3332
- $this->clear_code_cache ();
3333
 
3334
- $ai_last_check = AI_CHECK_INSERTED;
3335
- }
3336
- }
3337
- }
 
 
3338
 
3339
- return $content;
 
 
 
 
 
3340
  }
3341
 
3342
  public function after_paragraph ($content, $position_preview = false) {
@@ -3526,7 +3586,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3526
 
3527
  if ($multibyte) {
3528
  // $paragraph_code = $index == 0 ? mb_substr ($content, 0, $paragraph_position + 1) : mb_substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
3529
- $paragraph_code = mb_substr ($content, $paragraph_start_positions [$index], $paragraph_position - $paragraph_start_positions [$index] +1);
3530
  } else {
3531
  // $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
3532
  $paragraph_code = substr ($content, $paragraph_start_positions [$index], $paragraph_position - $paragraph_start_positions [$index] + 1);
@@ -3620,6 +3680,28 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3620
  // if (count ($paragraph_positions) == 0) return $content;
3621
  if (array_sum ($active_paragraph_positions) == 0) return $content;
3622
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3623
 
3624
  $filtered_paragraph_positions = array ();
3625
  foreach ($paragraph_positions as $index => $paragraph_position) {
@@ -3633,8 +3715,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3633
  }
3634
 
3635
 
3636
- $position_text = trim ($this->get_paragraph_number());
3637
-
3638
  // $positions contains indexes in $paragraph_positions
3639
  $positions = array ();
3640
 
@@ -3676,17 +3756,30 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3676
  $words_above = 0;
3677
  foreach ($paragraph_positions as $index => $paragraph_position) {
3678
 
 
 
 
 
 
 
 
 
3679
  if ($multibyte) {
3680
- $paragraph_code = $index == 0 ? mb_substr ($content, 0, $paragraph_position + 1) : mb_substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
 
3681
  } else {
3682
- $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
 
3683
  }
3684
 
3685
  $words_above += number_of_words ($paragraph_code);
3686
- if ($words_above >= $min_words_above) {
3687
- // $positions []= $index + 1;
3688
- $positions []= $index;
3689
- $words_above = 0;
 
 
 
3690
  }
3691
 
3692
  }
@@ -3980,41 +4073,44 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3980
  $offset += strlen ($inserted_code);
3981
  }
3982
  }
3983
-
3984
  }
3985
 
3986
- $ai_last_check = AI_CHECK_NONE; // Already logged on each insertion
3987
  return $content;
3988
  }
3989
 
3990
- // Deprecated since $postion is now in array $positions
3991
- $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
3992
- if (count ($paragraph_positions) >= intval ($this->get_paragraph_number_minimum())) {
3993
- $ai_last_check = AI_CHECK_PARAGRAPH_NUMBER;
3994
- if (count ($paragraph_positions) > $position) {
3995
- $this->increment_block_counter ();
3996
-
3997
- $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3998
- if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3999
- $content_position = $paragraph_positions [$position];
4000
-
4001
- if ($multibyte) {
4002
- if ($content_position >= mb_strlen ($content) - 1)
4003
- $content = $content . $this->get_code_for_serverside_insertion (); else
4004
- $content = mb_substr ($content, 0, $content_position + 1) . $this->get_code_for_serverside_insertion () . mb_substr ($content, $content_position + 1);
4005
- } else {
4006
- if ($content_position >= strlen ($content) - 1)
4007
- $content = $content . $this->get_code_for_serverside_insertion (); else
4008
- $content = substr_replace ($content, $this->get_code_for_serverside_insertion (), $content_position + 1, 0);
4009
- }
4010
- $this->clear_code_cache ();
4011
 
4012
- $ai_last_check = AI_CHECK_INSERTED;
4013
- }
4014
- }
4015
- }
4016
 
4017
- return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4018
  }
4019
 
4020
 
408
  $this->wp_options [AI_OPTION_BLOCK_NAME] = AD_NAME;
409
  $this->wp_options [AI_OPTION_DISABLE_INSERTION] = AI_DISABLED;
410
  $this->wp_options [AI_OPTION_SHOW_LABEL] = AI_DISABLED;
411
+ $this->wp_options [AI_OPTION_LAZY_LOADING] = AI_DISABLED;
412
  $this->wp_options [AI_OPTION_TRACKING] = AI_DISABLED;
413
  $this->wp_options [AI_OPTION_AUTOMATIC_INSERTION] = AI_AUTOMATIC_INSERTION_DISABLED;
414
  $this->wp_options [AI_OPTION_HTML_SELECTOR] = AD_EMPTY_DATA;
511
  return $show_label;
512
  }
513
 
514
+ public function get_lazy_loading (){
515
+ $lazy_loading = isset ($this->wp_options [AI_OPTION_LAZY_LOADING]) ? $this->wp_options [AI_OPTION_LAZY_LOADING] : AI_DISABLED;
516
+ if ($lazy_loading == '') $lazy_loading = AI_DISABLED;
517
+ return $lazy_loading;
518
+ }
519
+
520
  public function get_automatic_insertion (){
521
  global $ai_db_options;
522
 
1750
  }
1751
 
1752
  $temp_dynamic_blocks = $dynamic_blocks;
1753
+ if ($force_server_side_code || ($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || $temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) && $ai_wp_data [AI_WP_AMP_PAGE]) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1754
 
1755
  switch ($temp_dynamic_blocks) {
1756
  case AI_DYNAMIC_BLOCKS_SERVER_SIDE:
1837
  } else $ad_index_code = ' $ai_index = mt_rand (1, count ($ai_code));';
1838
 
1839
  $this->w3tc_code = '$ai_code = unserialize (base64_decode (\''.base64_encode (serialize ($ads)).'\'));'.$ad_index_code.' $ai_code = base64_decode (\''.base64_encode ($additional_code).'\') . $ai_code [$ai_index - 1]; $ai_enabled = true;';
1840
+
1841
  $processed_code = '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1842
  $processed_code .= $this->w3tc_code.' echo $ai_code;';
1843
  $processed_code .= '<!-- /mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1846
  } else $processed_code = $additional_code . $processed_code;
1847
 
1848
  $temp_dynamic_blocks = $dynamic_blocks;
1849
+ if ($force_server_side_code) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1850
+ elseif ($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_SERVER_SIDE_W3TC && $this->w3tc_code == '') $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1851
+ elseif ($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1852
+ elseif ($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1853
 
1854
  switch ($temp_dynamic_blocks) {
1855
  case AI_DYNAMIC_BLOCKS_SERVER_SIDE:
1875
  // $this->w3tc_code .= 'if (strpos ($ai_code, $ai_amp_separator) !== false) {$codes = explode ($ai_amp_separator, $ai_code); $ai_code = trim ($codes [$ai_amp_page ? 1 : 0]); } else {if ($ai_amp_page && !$ai_amp_enabled) $ai_code = \'\';} $ai_enabled = true;';
1876
  $this->w3tc_code .= 'if (strpos ($ai_code, $ai_amp_separator) !== false) {$codes = explode ($ai_amp_separator, $ai_code); $ai_code = trim ($codes [$ai_amp_page ? 1 : 0]); } else {if ($ai_amp_page + !$ai_amp_enabled == 2) $ai_code = \'\';} $ai_enabled = true;';
1877
 
1878
+ // Lazy loading code for W3TC cases with ROTATE separator
1879
+ if ($this->get_lazy_loading () && !$ai_wp_data [AI_WP_AMP_PAGE]) {
1880
+ $this->w3tc_code .= $this->w3tc_code.'$ai_lazy_code = base64_encode ($ai_code); $ai_wrapper_class = \''.base64_encode (get_block_class_name ()).'\'; $ai_code = \'<div class="ai-lazy" data-code="\'.$ai_lazy_code.\'" data-class="\'.$ai_wrapper_class.\'"></div>\'."\n";';
1881
+ }
1882
+
1883
  $processed_code = '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1884
  $processed_code .= $this->w3tc_code.' echo $ai_code;';
1885
  $processed_code .= '<!-- /mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1886
  break;
1887
  }
1888
 
1889
+ // Lazy loading code for all cases except W3TC with ROTATE separator
1890
+ if ($this->get_lazy_loading () && !$ai_wp_data [AI_WP_AMP_PAGE] && $this->w3tc_code == '') {
1891
+ $lazy_code = base64_encode ($processed_code);
1892
+ $wrapper_class = base64_encode (get_block_class_name ());
1893
+ $processed_code = '<div class="ai-lazy" data-code="'.$lazy_code.'" data-class="'.$wrapper_class.'"></div>'."\n";
1894
+ }
1895
+
1896
  $temp_dynamic_blocks = $dynamic_blocks;
1897
+ if ($force_server_side_code || ($temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || $temp_dynamic_blocks == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) && $ai_wp_data [AI_WP_AMP_PAGE]) $temp_dynamic_blocks = AI_DYNAMIC_BLOCKS_SERVER_SIDE;
1898
 
1899
  if ($temp_dynamic_blocks != AI_DYNAMIC_BLOCKS_SERVER_SIDE) {
1900
  $url_parameters_raw = trim (str_replace (' ', '', $this->get_url_parameter_list ()));
1920
  switch ($dynamic_blocks) {
1921
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1922
  if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
1923
+ $processed_code = "\n<div class='ai-dynamic ai-list-data' $referer_attributes $url_parameter_attributes>$processed_code</div>\n";
1924
+ } else $processed_code = "\n<div class='ai-dynamic ai-list-data' $referer_attributes $url_parameter_attributes style='visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999;'>$processed_code</div>\n";
1925
  break;
1926
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1927
  $code_data = "data-code='".base64_encode ($processed_code)."'";
1928
 
1929
+ $processed_code = "\n<div class='ai-dynamic ai-list-data' $referer_attributes $url_parameter_attributes $code_data></div>\n";
1930
  break;
1931
  }
1932
 
1978
  switch ($dynamic_blocks) {
1979
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1980
  if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
1981
+ $processed_code = "\n<div class='ai-dynamic ai-ip-data' $ip_address_attributes $country_attributes>$processed_code</div>\n";
1982
+ } else $processed_code = "\n<div class='ai-dynamic ai-ip-data' $ip_address_attributes $country_attributes style='visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999;'>$processed_code</div>\n";
1983
  break;
1984
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1985
  $code_data = "data-code='".base64_encode ($processed_code)."'";
1986
 
1987
+ $processed_code = "\n<div class='ai-dynamic ai-ip-data' $ip_address_attributes $country_attributes $code_data></div>\n";
1988
  break;
1989
  }
1990
 
2966
  // if (count ($paragraph_positions) == 0) return $content;
2967
  if (array_sum ($active_paragraph_positions) == 0) return $content;
2968
 
2969
+ $position_text = trim ($this->get_paragraph_number());
2970
+
2971
+
2972
+ // Prepare $paragraph_end_positions
2973
+ if (!$position_preview && $position_text == '') {
2974
+ if (!isset ($paragraph_end_positions)) {
2975
+ $paragraph_end_positions = array ();
2976
+ get_paragraph_end_positions ($content, $multibyte, $paragraph_positions, $paragraph_start_strings, $paragraph_end_positions, $dummy);
2977
+ }
2978
+
2979
+ $filtered_paragraph_end_positions = array ();
2980
+ // Use $paragraph_positions for counting as it is checked for consistency
2981
+ foreach ($paragraph_positions as $index => $paragraph_position) {
2982
+ if ($active_paragraph_positions [$index]) $filtered_paragraph_end_positions [] = $paragraph_end_positions [$index];
2983
+ }
2984
+ $paragraph_end_positions = $filtered_paragraph_end_positions;
2985
+
2986
+ if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
2987
+ $paragraph_end_positions = array_reverse ($paragraph_end_positions);
2988
+ }
2989
+ }
2990
+
2991
 
2992
  $filtered_paragraph_positions = array ();
2993
  foreach ($paragraph_positions as $index => $paragraph_position) {
2994
  if ($active_paragraph_positions [$index]) $filtered_paragraph_positions [] = $paragraph_position;
2995
+
2996
  }
2997
  $paragraph_positions = $filtered_paragraph_positions;
2998
 
2999
 
3000
  if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
3001
+ $paragraph_positions = array_reverse ($paragraph_positions);
3002
  }
3003
 
3004
 
 
 
3005
  // $positions contains indexes in $paragraph_positions
3006
  $positions = array ();
3007
 
3045
  $words_above = 0;
3046
  foreach ($paragraph_positions as $index => $paragraph_position) {
3047
 
3048
+ if ($this->get_direction_type() != AD_DIRECTION_FROM_BOTTOM) {
3049
+ if ($words_above >= $min_words_above) {
3050
+ // $positions []= $index + 1;
3051
+ $positions []= $index;
3052
+ $words_above = 0;
3053
+ }
3054
+ }
3055
+
3056
+
3057
  if ($multibyte) {
3058
+ // $paragraph_code = $index == count ($paragraph_positions) - 1 ? mb_substr ($content, $paragraph_position) : mb_substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
3059
+ $paragraph_code = mb_substr ($content, $paragraph_position, $paragraph_end_positions [$index] - $paragraph_position + 1);
3060
  } else {
3061
+ // $paragraph_code = $index == count ($paragraph_positions) - 1 ? substr ($content, $paragraph_position) : substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
3062
+ $paragraph_code = substr ($content, $paragraph_position, $paragraph_end_positions [$index] - $paragraph_position + 1);
3063
  }
3064
 
3065
  $words_above += number_of_words ($paragraph_code);
3066
+
3067
+ if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
3068
+ if ($words_above >= $min_words_above) {
3069
+ // $positions []= $index + 1;
3070
+ $positions []= $index;
3071
+ $words_above = 0;
3072
+ }
3073
  }
3074
 
3075
  }
3369
  return $content;
3370
  }
3371
 
3372
+ // empty $positions
3373
+ return $content;
3374
+
 
 
 
3375
 
3376
+ // // Deprecated since $postion is now in array $positions
3377
+ // $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
3378
+ // if (count ($paragraph_positions) >= intval ($this->get_paragraph_number_minimum())) {
3379
+ // $ai_last_check = AI_CHECK_PARAGRAPH_NUMBER;
3380
+ // if (count ($paragraph_positions) > $position) {
3381
+ // $this->increment_block_counter ();
3382
 
3383
+ // $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3384
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3385
+ // $content_position = $paragraph_positions [$position];
 
 
 
3386
 
3387
+ // if ($multibyte) {
3388
+ // $content = mb_substr ($content, 0, $content_position) . $this->get_code_for_serverside_insertion () . mb_substr ($content, $content_position);
3389
+ // } else {
3390
+ // $content = substr_replace ($content, $this->get_code_for_serverside_insertion (), $content_position, 0);
3391
+ // }
3392
+ // $this->clear_code_cache ();
3393
 
3394
+ // $ai_last_check = AI_CHECK_INSERTED;
3395
+ // }
3396
+ // }
3397
+ // }
3398
+
3399
+ // return $content;
3400
  }
3401
 
3402
  public function after_paragraph ($content, $position_preview = false) {
3586
 
3587
  if ($multibyte) {
3588
  // $paragraph_code = $index == 0 ? mb_substr ($content, 0, $paragraph_position + 1) : mb_substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
3589
+ $paragraph_code = mb_substr ($content, $paragraph_start_positions [$index], $paragraph_position - $paragraph_start_positions [$index] + 1);
3590
  } else {
3591
  // $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
3592
  $paragraph_code = substr ($content, $paragraph_start_positions [$index], $paragraph_position - $paragraph_start_positions [$index] + 1);
3680
  // if (count ($paragraph_positions) == 0) return $content;
3681
  if (array_sum ($active_paragraph_positions) == 0) return $content;
3682
 
3683
+ $position_text = trim ($this->get_paragraph_number());
3684
+
3685
+
3686
+ // Prepare $paragraph_start_positions
3687
+ if (!$position_preview && $position_text == '') {
3688
+ if (!isset ($paragraph_start_positions)) {
3689
+ $paragraph_start_positions = array ();
3690
+ get_paragraph_start_positions ($content, $multibyte, $paragraph_positions, $paragraph_end_strings, $paragraph_start_positions, $dummy);
3691
+ }
3692
+
3693
+ $filtered_paragraph_positions = array ();
3694
+ // Use $paragraph_positions for counting as it is checked for consistency
3695
+ foreach ($paragraph_positions as $index => $paragraph_position) {
3696
+ if ($active_paragraph_positions [$index]) $filtered_paragraph_positions [] = $paragraph_start_positions [$index];
3697
+ }
3698
+ $paragraph_start_positions = $filtered_paragraph_positions;
3699
+
3700
+ if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
3701
+ $paragraph_start_positions = array_reverse ($paragraph_start_positions);
3702
+ }
3703
+ }
3704
+
3705
 
3706
  $filtered_paragraph_positions = array ();
3707
  foreach ($paragraph_positions as $index => $paragraph_position) {
3715
  }
3716
 
3717
 
 
 
3718
  // $positions contains indexes in $paragraph_positions
3719
  $positions = array ();
3720
 
3756
  $words_above = 0;
3757
  foreach ($paragraph_positions as $index => $paragraph_position) {
3758
 
3759
+ if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
3760
+ if ($words_above >= $min_words_above) {
3761
+ // $positions []= $index + 1;
3762
+ $positions []= $index;
3763
+ $words_above = 0;
3764
+ }
3765
+ }
3766
+
3767
  if ($multibyte) {
3768
+ // $paragraph_code = $index == 0 ? mb_substr ($content, 0, $paragraph_position + 1) : mb_substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
3769
+ $paragraph_code = mb_substr ($content, $paragraph_start_positions [$index], $paragraph_position - $paragraph_start_positions [$index] + 1);
3770
  } else {
3771
+ // $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
3772
+ $paragraph_code = substr ($content, $paragraph_start_positions [$index], $paragraph_position - $paragraph_start_positions [$index] + 1);
3773
  }
3774
 
3775
  $words_above += number_of_words ($paragraph_code);
3776
+
3777
+ if ($this->get_direction_type() != AD_DIRECTION_FROM_BOTTOM) {
3778
+ if ($words_above >= $min_words_above) {
3779
+ // $positions []= $index + 1;
3780
+ $positions []= $index;
3781
+ $words_above = 0;
3782
+ }
3783
  }
3784
 
3785
  }
4073
  $offset += strlen ($inserted_code);
4074
  }
4075
  }
 
4076
  }
4077
 
4078
+ $ai_last_check = AI_CHECK_NONE; // Already logged on each insertion
4079
  return $content;
4080
  }
4081
 
4082
+ // empty $positions
4083
+ return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4084
 
 
 
 
 
4085
 
4086
+ // // Deprecated since $postion is now in array $positions
4087
+ // $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
4088
+ // if (count ($paragraph_positions) >= intval ($this->get_paragraph_number_minimum())) {
4089
+ // $ai_last_check = AI_CHECK_PARAGRAPH_NUMBER;
4090
+ // if (count ($paragraph_positions) > $position) {
4091
+ // $this->increment_block_counter ();
4092
+
4093
+ // $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
4094
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
4095
+ // $content_position = $paragraph_positions [$position];
4096
+
4097
+ // if ($multibyte) {
4098
+ // if ($content_position >= mb_strlen ($content) - 1)
4099
+ // $content = $content . $this->get_code_for_serverside_insertion (); else
4100
+ // $content = mb_substr ($content, 0, $content_position + 1) . $this->get_code_for_serverside_insertion () . mb_substr ($content, $content_position + 1);
4101
+ // } else {
4102
+ // if ($content_position >= strlen ($content) - 1)
4103
+ // $content = $content . $this->get_code_for_serverside_insertion (); else
4104
+ // $content = substr_replace ($content, $this->get_code_for_serverside_insertion (), $content_position + 1, 0);
4105
+ // }
4106
+ // $this->clear_code_cache ();
4107
+
4108
+ // $ai_last_check = AI_CHECK_INSERTED;
4109
+ // }
4110
+ // }
4111
+ // }
4112
+
4113
+ // return $content;
4114
  }
4115
 
4116
 
constants.php CHANGED
@@ -24,7 +24,7 @@ if (!defined( 'AD_INSERTER_NAME'))
24
  define ('AD_INSERTER_NAME', 'Ad Inserter');
25
 
26
  if (!defined( 'AD_INSERTER_VERSION'))
27
- define ('AD_INSERTER_VERSION', '2.3.12');
28
 
29
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
30
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
@@ -62,6 +62,7 @@ define ('AI_OPTION_ENABLE_WIDGET', 'enable_widget');
62
  define ('AI_OPTION_PROCESS_PHP', 'process_php');
63
  define ('AI_OPTION_DISABLE_INSERTION', 'disable_insertion');
64
  define ('AI_OPTION_SHOW_LABEL', 'show_label');
 
65
  define ('AI_OPTION_TRACKING', 'tracking');
66
  define ('AI_OPTION_ENABLE_AJAX', 'enable_ajax');
67
  define ('AI_OPTION_ENABLE_FEED', 'enable_feed');
@@ -815,6 +816,7 @@ define ('AI_ANIMATION', 33);
815
  define ('AI_TRIGGER_ELEMENTS', 34);
816
  define ('AI_CLIENT_SIDE_ROTATION', 35);
817
  define ('AI_CLIENT_SIDE_CSS', 36);
 
818
 
819
  define ('AI_CONTEXT_NONE', 0);
820
  define ('AI_CONTEXT_CONTENT', 1);
24
  define ('AD_INSERTER_NAME', 'Ad Inserter');
25
 
26
  if (!defined( 'AD_INSERTER_VERSION'))
27
+ define ('AD_INSERTER_VERSION', '2.3.13');
28
 
29
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
30
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
62
  define ('AI_OPTION_PROCESS_PHP', 'process_php');
63
  define ('AI_OPTION_DISABLE_INSERTION', 'disable_insertion');
64
  define ('AI_OPTION_SHOW_LABEL', 'show_label');
65
+ define ('AI_OPTION_LAZY_LOADING', 'lazy_loading');
66
  define ('AI_OPTION_TRACKING', 'tracking');
67
  define ('AI_OPTION_ENABLE_AJAX', 'enable_ajax');
68
  define ('AI_OPTION_ENABLE_FEED', 'enable_feed');
816
  define ('AI_TRIGGER_ELEMENTS', 34);
817
  define ('AI_CLIENT_SIDE_ROTATION', 35);
818
  define ('AI_CLIENT_SIDE_CSS', 36);
819
+ define ('AI_LAZY_LOADING', 37);
820
 
821
  define ('AI_CONTEXT_NONE', 0);
822
  define ('AI_CONTEXT_CONTENT', 1);
css/ad-inserter.css CHANGED
@@ -1,5 +1,5 @@
1
  #ai-data {
2
- font-family: "2.3.12"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
1
  #ai-data {
2
+ font-family: "2.3.13"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
includes/js/ai-ads.js CHANGED
@@ -1,50 +1,54 @@
1
  var adsense_ad_names = [];
2
  var ai_preview_window = typeof ai_preview !== 'undefined';
3
 
4
- function ai_process_adsense_ads ($) {
5
  var ai_debug = typeof ai_debugging !== 'undefined';
6
- $('ins ins iframe').each (function () {
7
- var adsense_iframe = $(this);
8
- var adsense_width = adsense_iframe.attr ('width');
9
- var adsense_height = adsense_iframe.attr ('height');
10
- var adsense_iframe2 = adsense_iframe.contents().find ('iframe[allowtransparency]');
11
- var url_parameters = getAllUrlParams (adsense_iframe2.attr ('src'))
12
-
13
- if (typeof url_parameters ['client'] !== 'undefined') {
14
- var adsense_ad_client = url_parameters ['client'];
15
- var adsense_publisher_id = adsense_ad_client.replace ('ca-', '');
16
- var adsense_ad_slot = url_parameters ['slotname'];
17
- var adsense_index = url_parameters ['ifi'];
18
-
19
- if (ai_debug) console.log ('AI ADSENSE', adsense_index, adsense_ad_client, adsense_ad_slot, url_parameters ['format'], url_parameters ['w'], url_parameters ['h']);
20
-
21
- var adsense_overlay = $('<div class="ai-debug-ad-overlay"></div>');
22
-
23
- var adsense_ad_info = '';
24
- if (typeof adsense_ad_slot !== 'undefined') {
25
- var adsense_ad_name = '';
26
- if (typeof adsense_ad_names ['publisher_id'] !== 'undefined' &&
27
- adsense_ad_names ['publisher_id'] == adsense_publisher_id &&
28
- typeof adsense_ad_names [adsense_ad_slot] !== 'undefined') {
29
- adsense_ad_name = '<div class="ai-info ai-info-2">' + adsense_ad_names [adsense_ad_slot] + '</div>';
30
- }
31
- adsense_ad_info = '<div class="ai-info ai-info-1">' + adsense_ad_slot + '</div>' + adsense_ad_name;
32
- } else {
33
- var adsense_auto_ads = adsense_iframe.closest ('div.google-auto-placed').length != 0;
34
- if (adsense_auto_ads) {
35
- adsense_overlay.addClass ('ai-auto-ads');
36
- adsense_ad_info = '<div class="ai-info ai-info-1">Auto ads</div>';
37
- } else adsense_overlay.addClass ('ai-no-slot');
38
- }
39
 
40
- var adsense_info = $('<div class="ai-debug-ad-info"><div class="ai-info ai-info-1">AdSense #' + adsense_index + '</div><div class="ai-info ai-info-2">' + adsense_width + 'x' + adsense_height + '</div>' + adsense_ad_info + '</div>');
41
 
42
- adsense_iframe.after (adsense_info);
43
 
44
- if (!ai_preview_window) {
45
- adsense_iframe.after (adsense_overlay);
46
- }
47
  }
 
 
 
 
 
 
48
  });
49
  }
50
 
@@ -60,6 +64,7 @@ jQuery(document).ready(function($) {
60
  try {
61
  adsense_ad_names = JSON.parse (data);
62
 
 
63
  if (ai_debug) console.log ("AI ADSENSE DATA:", Object.keys (adsense_ad_names).length - 1, 'ad units');
64
 
65
  } catch (error) {
1
  var adsense_ad_names = [];
2
  var ai_preview_window = typeof ai_preview !== 'undefined';
3
 
4
+ function ai_process_adsense_ad (element) {
5
  var ai_debug = typeof ai_debugging !== 'undefined';
6
+ var adsense_iframe = jQuery(element);
7
+ var adsense_width = adsense_iframe.attr ('width');
8
+ var adsense_height = adsense_iframe.attr ('height');
9
+ var adsense_iframe2 = adsense_iframe.contents().find ('iframe[allowtransparency]');
10
+ var url_parameters = getAllUrlParams (adsense_iframe2.attr ('src'))
11
+
12
+ if (typeof url_parameters ['client'] !== 'undefined') {
13
+ var adsense_ad_client = url_parameters ['client'];
14
+ var adsense_publisher_id = adsense_ad_client.replace ('ca-', '');
15
+ var adsense_ad_slot = url_parameters ['slotname'];
16
+ var adsense_index = url_parameters ['ifi'];
17
+
18
+ if (ai_debug) console.log ('AI ADSENSE', adsense_index, adsense_ad_client, adsense_ad_slot, url_parameters ['format'], url_parameters ['w'], url_parameters ['h']);
19
+
20
+ var adsense_overlay = jQuery('<div class="ai-debug-ad-overlay"></div>');
21
+
22
+ var adsense_ad_info = '';
23
+ if (typeof adsense_ad_slot !== 'undefined') {
24
+ var adsense_ad_name = '';
25
+ if (typeof adsense_ad_names ['publisher_id'] !== 'undefined' &&
26
+ adsense_ad_names ['publisher_id'] == adsense_publisher_id &&
27
+ typeof adsense_ad_names [adsense_ad_slot] !== 'undefined') {
28
+ adsense_ad_name = '<div class="ai-info ai-info-2">' + adsense_ad_names [adsense_ad_slot] + '</div>';
29
+ }
30
+ adsense_ad_info = '<div class="ai-info ai-info-1">' + adsense_ad_slot + '</div>' + adsense_ad_name;
31
+ } else {
32
+ var adsense_auto_ads = adsense_iframe.closest ('div.google-auto-placed').length != 0;
33
+ if (adsense_auto_ads) {
34
+ adsense_overlay.addClass ('ai-auto-ads');
35
+ adsense_ad_info = '<div class="ai-info ai-info-1">Auto ads</div>';
36
+ } else adsense_overlay.addClass ('ai-no-slot');
37
+ }
 
38
 
39
+ var adsense_info = jQuery('<div class="ai-debug-ad-info"><div class="ai-info ai-info-1">AdSense #' + adsense_index + '</div><div class="ai-info ai-info-2">' + adsense_width + 'x' + adsense_height + '</div>' + adsense_ad_info + '</div>');
40
 
41
+ adsense_iframe.after (adsense_info);
42
 
43
+ if (!ai_preview_window) {
44
+ adsense_iframe.after (adsense_overlay);
 
45
  }
46
+ }
47
+ }
48
+
49
+ function ai_process_adsense_ads () {
50
+ jQuery('ins ins iframe').each (function () {
51
+ ai_process_adsense_ad (this);
52
  });
53
  }
54
 
64
  try {
65
  adsense_ad_names = JSON.parse (data);
66
 
67
+ if (ai_debug) console.log ('');
68
  if (ai_debug) console.log ("AI ADSENSE DATA:", Object.keys (adsense_ad_names).length - 1, 'ad units');
69
 
70
  } catch (error) {
includes/js/ai-ads.min.js CHANGED
@@ -1,9 +1,9 @@
1
  var adsense_ad_names=[];var ai_preview_window=typeof ai_preview!=="undefined";
2
- function ai_process_adsense_ads($){var ai_debug=typeof ai_debugging!=="undefined";$("ins ins iframe").each(function(){var adsense_iframe=$(this);var adsense_width=adsense_iframe.attr("width");var adsense_height=adsense_iframe.attr("height");var adsense_iframe2=adsense_iframe.contents().find("iframe[allowtransparency]");var url_parameters=getAllUrlParams(adsense_iframe2.attr("src"));if(typeof url_parameters["client"]!=="undefined"){var adsense_ad_client=url_parameters["client"];var adsense_publisher_id=
3
- adsense_ad_client.replace("ca-","");var adsense_ad_slot=url_parameters["slotname"];var adsense_index=url_parameters["ifi"];if(ai_debug)console.log("AI ADSENSE",adsense_index,adsense_ad_client,adsense_ad_slot,url_parameters["format"],url_parameters["w"],url_parameters["h"]);var adsense_overlay=$('<div class="ai-debug-ad-overlay"></div>');var adsense_ad_info="";if(typeof adsense_ad_slot!=="undefined"){var adsense_ad_name="";if(typeof adsense_ad_names["publisher_id"]!=="undefined"&&adsense_ad_names["publisher_id"]==
4
- adsense_publisher_id&&typeof adsense_ad_names[adsense_ad_slot]!=="undefined")adsense_ad_name='<div class="ai-info ai-info-2">'+adsense_ad_names[adsense_ad_slot]+"</div>";adsense_ad_info='<div class="ai-info ai-info-1">'+adsense_ad_slot+"</div>"+adsense_ad_name}else{var adsense_auto_ads=adsense_iframe.closest("div.google-auto-placed").length!=0;if(adsense_auto_ads){adsense_overlay.addClass("ai-auto-ads");adsense_ad_info='<div class="ai-info ai-info-1">Auto ads</div>'}else adsense_overlay.addClass("ai-no-slot")}var adsense_info=
5
- $('<div class="ai-debug-ad-info"><div class="ai-info ai-info-1">AdSense #'+adsense_index+'</div><div class="ai-info ai-info-2">'+adsense_width+"x"+adsense_height+"</div>"+adsense_ad_info+"</div>");adsense_iframe.after(adsense_info);if(!ai_preview_window)adsense_iframe.after(adsense_overlay)}})}
6
- jQuery(document).ready(function($){var ai_debug=typeof ai_debugging!=="undefined";var ajaxurl="AI_AJAXURL";var nonce="AI_NONCE";var adsense_data={"ai":1};$.post(ajaxurl,{"action":"ai_ajax","ai_check":nonce,"adsense-ad-units":adsense_data}).done(function(data){if(data!="")try{adsense_ad_names=JSON.parse(data);if(ai_debug)console.log("AI ADSENSE DATA:",Object.keys(adsense_ad_names).length-1,"ad units")}catch(error){if(ai_debug)console.log("AI ADSENSE DATA ERROR:",data)}}).fail(function(xhr,status,error){if(ai_debug)console.log("AI ADSENSE DATA ERROR:",
7
- xhr.status,xhr.statusText)}).always(function(data){if(ai_debug)console.log("AI ADSENSE DATA","END")});if(!ai_preview_window)setTimeout(function(){ai_process_adsense_ads(jQuery)},2E3)});
8
  function getAllUrlParams(url){var queryString=url?url.split("?")[1]:window.location.search.slice(1);var obj={};if(queryString){queryString=queryString.split("#")[0];var arr=queryString.split("&");for(var i=0;i<arr.length;i++){var a=arr[i].split("=");var paramNum=undefined;var paramName=a[0].replace(/\[\d*\]/,function(v){paramNum=v.slice(1,-1);return""});var paramValue=typeof a[1]==="undefined"?true:a[1];paramName=paramName.toLowerCase();paramValue=paramValue.toLowerCase();if(obj[paramName]){if(typeof obj[paramName]===
9
  "string")obj[paramName]=[obj[paramName]];if(typeof paramNum==="undefined")obj[paramName].push(paramValue);else obj[paramName][paramNum]=paramValue}else obj[paramName]=paramValue}}return obj};
1
  var adsense_ad_names=[];var ai_preview_window=typeof ai_preview!=="undefined";
2
+ function ai_process_adsense_ad(element){var ai_debug=typeof ai_debugging!=="undefined";var adsense_iframe=jQuery(element);var adsense_width=adsense_iframe.attr("width");var adsense_height=adsense_iframe.attr("height");var adsense_iframe2=adsense_iframe.contents().find("iframe[allowtransparency]");var url_parameters=getAllUrlParams(adsense_iframe2.attr("src"));if(typeof url_parameters["client"]!=="undefined"){var adsense_ad_client=url_parameters["client"];var adsense_publisher_id=adsense_ad_client.replace("ca-",
3
+ "");var adsense_ad_slot=url_parameters["slotname"];var adsense_index=url_parameters["ifi"];if(ai_debug)console.log("AI ADSENSE",adsense_index,adsense_ad_client,adsense_ad_slot,url_parameters["format"],url_parameters["w"],url_parameters["h"]);var adsense_overlay=jQuery('<div class="ai-debug-ad-overlay"></div>');var adsense_ad_info="";if(typeof adsense_ad_slot!=="undefined"){var adsense_ad_name="";if(typeof adsense_ad_names["publisher_id"]!=="undefined"&&adsense_ad_names["publisher_id"]==adsense_publisher_id&&
4
+ typeof adsense_ad_names[adsense_ad_slot]!=="undefined")adsense_ad_name='<div class="ai-info ai-info-2">'+adsense_ad_names[adsense_ad_slot]+"</div>";adsense_ad_info='<div class="ai-info ai-info-1">'+adsense_ad_slot+"</div>"+adsense_ad_name}else{var adsense_auto_ads=adsense_iframe.closest("div.google-auto-placed").length!=0;if(adsense_auto_ads){adsense_overlay.addClass("ai-auto-ads");adsense_ad_info='<div class="ai-info ai-info-1">Auto ads</div>'}else adsense_overlay.addClass("ai-no-slot")}var adsense_info=
5
+ jQuery('<div class="ai-debug-ad-info"><div class="ai-info ai-info-1">AdSense #'+adsense_index+'</div><div class="ai-info ai-info-2">'+adsense_width+"x"+adsense_height+"</div>"+adsense_ad_info+"</div>");adsense_iframe.after(adsense_info);if(!ai_preview_window)adsense_iframe.after(adsense_overlay)}}function ai_process_adsense_ads(){jQuery("ins ins iframe").each(function(){ai_process_adsense_ad(this)})}
6
+ jQuery(document).ready(function($){var ai_debug=typeof ai_debugging!=="undefined";var ajaxurl="AI_AJAXURL";var nonce="AI_NONCE";var adsense_data={"ai":1};$.post(ajaxurl,{"action":"ai_ajax","ai_check":nonce,"adsense-ad-units":adsense_data}).done(function(data){if(data!="")try{adsense_ad_names=JSON.parse(data);if(ai_debug)console.log("");if(ai_debug)console.log("AI ADSENSE DATA:",Object.keys(adsense_ad_names).length-1,"ad units")}catch(error){if(ai_debug)console.log("AI ADSENSE DATA ERROR:",data)}}).fail(function(xhr,
7
+ status,error){if(ai_debug)console.log("AI ADSENSE DATA ERROR:",xhr.status,xhr.statusText)}).always(function(data){if(ai_debug)console.log("AI ADSENSE DATA","END")});if(!ai_preview_window)setTimeout(function(){ai_process_adsense_ads(jQuery)},2E3)});
8
  function getAllUrlParams(url){var queryString=url?url.split("?")[1]:window.location.search.slice(1);var obj={};if(queryString){queryString=queryString.split("#")[0];var arr=queryString.split("&");for(var i=0;i<arr.length;i++){var a=arr[i].split("=");var paramNum=undefined;var paramName=a[0].replace(/\[\d*\]/,function(v){paramNum=v.slice(1,-1);return""});var paramValue=typeof a[1]==="undefined"?true:a[1];paramName=paramName.toLowerCase();paramValue=paramValue.toLowerCase();if(obj[paramName]){if(typeof obj[paramName]===
9
  "string")obj[paramName]=[obj[paramName]];if(typeof paramNum==="undefined")obj[paramName].push(paramValue);else obj[paramName][paramNum]=paramValue}else obj[paramName]=paramValue}}return obj};
includes/js/ai-lists.js CHANGED
@@ -116,13 +116,23 @@ jQuery (function ($) {
116
  block_wrapping_div.find ('.ai-debug-name.ai-list-status').text (enable_block ? 'VISIBLE' : 'HIDDEN');
117
  if (!enable_block) {
118
  $(this).hide ();
 
119
  } else {
120
  if (typeof $(this).data ('code') != 'undefined') {
121
  var block_code = atob ($(this).data ('code'));
122
  $(this).append (block_code);
123
  if (!ai_debug) $(this).attr ('data-code', '');
124
 
125
- // Doesn't process inserted code for rotation - it will be called with setTimeout 10 ms later
 
 
 
 
 
 
 
 
 
126
  }
127
  }
128
  });
116
  block_wrapping_div.find ('.ai-debug-name.ai-list-status').text (enable_block ? 'VISIBLE' : 'HIDDEN');
117
  if (!enable_block) {
118
  $(this).hide ();
119
+ block_wrapping_div.removeAttr ('data-ai');
120
  } else {
121
  if (typeof $(this).data ('code') != 'undefined') {
122
  var block_code = atob ($(this).data ('code'));
123
  $(this).append (block_code);
124
  if (!ai_debug) $(this).attr ('data-code', '');
125
 
126
+ if (typeof aiLazyLoading == 'function') {
127
+ $("div.ai-lazy", this).each (function (index, element) {
128
+ aiLazyLoading ({
129
+ lazyClass: 'ai-lazy',
130
+ lazyElement: this.element,
131
+ });
132
+ });
133
+ }
134
+
135
+ // Doesn't process inserted code for rotation - it will be called with setTimeout 5 ms later
136
  }
137
  }
138
  });
includes/js/ai-lists.min.js CHANGED
@@ -3,4 +3,5 @@ true;var referers_processed=false;var found=false;var referer_list=$(this).attr(
3
  if(list_referer=="#"){if(referrer==""){found=true;return false}}else if(list_referer==referrer){found=true;return false}});switch(referers_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block);referers_processed=true}if(enable_block){var parameter_list=$(this).attr("parameter-list");if(typeof parameter_list!="undefined"){var parameter_list_array=
4
  atob(parameter_list).split(",");var parameter_list_type=$(this).attr("parameter-list-type");if(ai_debug&&referers_processed)console.log("");if(ai_debug)console.log("AI LISTS cookies: ",cookies);if(ai_debug)console.log("AI LISTS parameter list:",atob(parameter_list),parameter_list_type);var found=false;$.each(parameter_list_array,function(index,list_parameter){if(list_parameter.indexOf("=")!=-1){if(cookies.indexOf(list_parameter)!=-1){found=true;return false}}else cookies.forEach(function(cookie){var cookie_data=
5
  cookie.split("=");if(list_parameter==cookie_data[0]){found=true;return false}})});switch(parameter_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block)}}$(this).css({"visibility":"","position":"","width":"","height":"","z-index":""}).removeClass("ai-list-data");var block_wrapping_div=$(this).closest("div.ai-list-block");block_wrapping_div.css({"visibility":"",
6
- "position":"","z-index":""}).removeClass("ai-list-block");block_wrapping_div.find(".ai-debug-name.ai-list-info").text(referrer);block_wrapping_div.find(".ai-debug-name.ai-list-status").text(enable_block?"VISIBLE":"HIDDEN");if(!enable_block)$(this).hide();else if(typeof $(this).data("code")!="undefined"){var block_code=atob($(this).data("code"));$(this).append(block_code);if(!ai_debug)$(this).attr("data-code","")}})};$(document).ready(function($){setTimeout(function(){ai_process_lists()},5)})});
 
3
  if(list_referer=="#"){if(referrer==""){found=true;return false}}else if(list_referer==referrer){found=true;return false}});switch(referers_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block);referers_processed=true}if(enable_block){var parameter_list=$(this).attr("parameter-list");if(typeof parameter_list!="undefined"){var parameter_list_array=
4
  atob(parameter_list).split(",");var parameter_list_type=$(this).attr("parameter-list-type");if(ai_debug&&referers_processed)console.log("");if(ai_debug)console.log("AI LISTS cookies: ",cookies);if(ai_debug)console.log("AI LISTS parameter list:",atob(parameter_list),parameter_list_type);var found=false;$.each(parameter_list_array,function(index,list_parameter){if(list_parameter.indexOf("=")!=-1){if(cookies.indexOf(list_parameter)!=-1){found=true;return false}}else cookies.forEach(function(cookie){var cookie_data=
5
  cookie.split("=");if(list_parameter==cookie_data[0]){found=true;return false}})});switch(parameter_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block)}}$(this).css({"visibility":"","position":"","width":"","height":"","z-index":""}).removeClass("ai-list-data");var block_wrapping_div=$(this).closest("div.ai-list-block");block_wrapping_div.css({"visibility":"",
6
+ "position":"","z-index":""}).removeClass("ai-list-block");block_wrapping_div.find(".ai-debug-name.ai-list-info").text(referrer);block_wrapping_div.find(".ai-debug-name.ai-list-status").text(enable_block?"VISIBLE":"HIDDEN");if(!enable_block){$(this).hide();block_wrapping_div.removeAttr("data-ai")}else if(typeof $(this).data("code")!="undefined"){var block_code=atob($(this).data("code"));$(this).append(block_code);if(!ai_debug)$(this).attr("data-code","");if(typeof aiLazyLoading=="function")$("div.ai-lazy",
7
+ this).each(function(index,element){aiLazyLoading({lazyClass:"ai-lazy",lazyElement:this.element})})}})};$(document).ready(function($){setTimeout(function(){ai_process_lists()},5)})});
includes/js/ai-rotate.js CHANGED
@@ -4,6 +4,8 @@ jQuery (function ($) {
4
  var ai_debug = typeof ai_debugging !== 'undefined';
5
  var rotate_options = $(".ai-rotate-option", rotation_block);
6
 
 
 
7
  if (ai_debug) console.log ('');
8
  if (ai_debug) console.log ('AI ROTATE process rotation:', rotate_options.length, 'options');
9
 
@@ -175,6 +177,12 @@ jQuery (function ($) {
175
  });
176
  }
177
 
 
 
 
 
 
 
178
  $(document).ready(function($) {
179
  setTimeout (function() {ai_process_rotations ();}, 10);
180
  });
4
  var ai_debug = typeof ai_debugging !== 'undefined';
5
  var rotate_options = $(".ai-rotate-option", rotation_block);
6
 
7
+ if (rotate_options.length == 0) return;
8
+
9
  if (ai_debug) console.log ('');
10
  if (ai_debug) console.log ('AI ROTATE process rotation:', rotate_options.length, 'options');
11
 
177
  });
178
  }
179
 
180
+ ai_process_rotations_in_element = function (el) {
181
+ $("div.ai-rotate", el).each (function (index, element) {
182
+ ai_process_rotation (this);
183
+ });
184
+ }
185
+
186
  $(document).ready(function($) {
187
  setTimeout (function() {ai_process_rotations ();}, 10);
188
  });
includes/js/ai-rotate.min.js CHANGED
@@ -1,10 +1,10 @@
1
- jQuery(function($){ai_process_rotation=function(rotation_block){var ai_debug=typeof ai_debugging!=="undefined";var rotate_options=$(".ai-rotate-option",rotation_block);if(ai_debug)console.log("");if(ai_debug)console.log("AI ROTATE process rotation:",rotate_options.length,"options");rotate_options.hide();if(typeof $(rotation_block).data("next")=="undefined"){var thresholds_data=$(rotation_block).data("shares");if(typeof thresholds_data==="string"){var thresholds=JSON.parse(atob(thresholds_data));var random_threshold=
2
- Math.round(Math.random()*100);for(var index=0;index<thresholds.length;index++){var random_index=index;if(random_threshold<=thresholds[index])break}}else{var random_index=Math.floor(Math.random()*rotate_options.length);var d=new Date;var n=d.getMilliseconds();if(n%2)random_index=rotate_options.length-random_index-1}}else{var random_index=parseInt($(rotation_block).attr("data-next"));if(ai_debug)console.log("AI TIMED ROTATE next index: ",random_index)}var option=$(rotate_options[random_index]);var option_time_text=
3
- "";if(typeof option.data("time")!="undefined"){var rotation_time=atob(option.data("time"));if(ai_debug){var option_name=atob(option.data("name"));console.log("AI TIMED ROTATE index:",random_index,"name:",option_name,"time:",rotation_time)}if(rotation_time==0&&rotate_options.length>1){var next_random_index=random_index;do{next_random_index++;if(next_random_index>=rotate_options.length)next_random_index=0;var next_option=$(rotate_options[next_random_index]);if(typeof next_option.data("time")=="undefined"){random_index=
4
- next_random_index;option=$(rotate_options[random_index]);rotation_time=0;if(ai_debug)console.log("AI TIMED ROTATE next option has no time: ",next_random_index);break}var next_rotation_time=atob(next_option.data("time"));if(ai_debug)console.log("AI TIMED ROTATE check:",next_random_index,"time:",next_rotation_time)}while(next_rotation_time==0&&next_random_index!=random_index);if(rotation_time!=0){random_index=next_random_index;option=$(rotate_options[random_index]);rotation_time=atob(option.data("time"))}if(ai_debug)console.log("AI TIMED ROTATE index:",
5
- random_index,"time:",rotation_time)}if(rotation_time>0){var next_random_index=random_index+1;if(next_random_index>=rotate_options.length)next_random_index=0;if(typeof $(rotation_block).data("info")!="undefined"){var block_info=JSON.parse(atob($(rotation_block).data("info")));var rotation_id=block_info[0];$(rotation_block).attr("data-next",next_random_index);setTimeout(function(){ai_process_rotation($("div.ai-rotate.ai-"+rotation_id))},rotation_time*1E3);option_time_text=" ("+rotation_time+" s)"}}}else{if(!ai_debug)rotate_options.each(function(index){if(index!=
6
- random_index)$(this).remove()});if(ai_debug)console.log("AI ROTATE no time");if(ai_debug)console.log("AI ROTATE index:",random_index)}option.css({"display":"","visibility":"","position":"","width":"","height":"","top":"","left":""}).removeClass("ai-rotate-hidden").removeClass("ai-rotate-hidden-2");$(rotation_block).css({"position":""});if(typeof option.data("code")!="undefined"){rotate_options.empty();var option_code=atob(option.data("code"));option.append(option_code)}var option_name="";var debug_block_frame=
7
- $(rotation_block).closest(".ai-debug-block");if(typeof debug_block_frame!="undefined"){var option_name=atob(option.data("name"));var name_tag=debug_block_frame.find("kbd.ai-option-name");var nested_debug_block=debug_block_frame.find(".ai-debug-block");if(typeof nested_debug_block!="undefined"){var name_tag2=nested_debug_block.find("kbd.ai-option-name");name_tag=name_tag.slice(0,name_tag.length-name_tag2.length)}if(typeof name_tag!="undefined"){var separator=name_tag.first().data("separator");if(typeof separator==
8
- "undefined")separator="";name_tag.html(separator+option_name+option_time_text)}}var tracking_updated=false;var adb_show_wrapping_div=$(rotation_block).closest(".ai-adb-show");if(typeof adb_show_wrapping_div!="undefined")if(typeof adb_show_wrapping_div.data("ai-tracking")!="undefined"){var data=JSON.parse(atob(adb_show_wrapping_div.data("ai-tracking")));if(typeof data!=="undefined"&&data.constructor===Array){data[1]=random_index+1;data[3]=option_name;adb_show_wrapping_div.data("ai-tracking",btoa(JSON.stringify(data)));
9
- tracking_updated=true}}if(!tracking_updated){var wrapping_div=$(rotation_block).closest("div[data-ai]");if(typeof wrapping_div.data("ai")!="undefined"){var data=JSON.parse(atob(wrapping_div.data("ai")));if(typeof data!=="undefined"&&data.constructor===Array){data[1]=random_index+1;data[3]=option_name;wrapping_div.data("ai",btoa(JSON.stringify(data)))}}}};function ai_process_rotations(){$("div.ai-rotate").each(function(index,element){ai_process_rotation(this)})}$(document).ready(function($){setTimeout(function(){ai_process_rotations()},
10
- 10)})});
1
+ jQuery(function($){ai_process_rotation=function(rotation_block){var ai_debug=typeof ai_debugging!=="undefined";var rotate_options=$(".ai-rotate-option",rotation_block);if(rotate_options.length==0)return;if(ai_debug)console.log("");if(ai_debug)console.log("AI ROTATE process rotation:",rotate_options.length,"options");rotate_options.hide();if(typeof $(rotation_block).data("next")=="undefined"){var thresholds_data=$(rotation_block).data("shares");if(typeof thresholds_data==="string"){var thresholds=
2
+ JSON.parse(atob(thresholds_data));var random_threshold=Math.round(Math.random()*100);for(var index=0;index<thresholds.length;index++){var random_index=index;if(random_threshold<=thresholds[index])break}}else{var random_index=Math.floor(Math.random()*rotate_options.length);var d=new Date;var n=d.getMilliseconds();if(n%2)random_index=rotate_options.length-random_index-1}}else{var random_index=parseInt($(rotation_block).attr("data-next"));if(ai_debug)console.log("AI TIMED ROTATE next index: ",random_index)}var option=
3
+ $(rotate_options[random_index]);var option_time_text="";if(typeof option.data("time")!="undefined"){var rotation_time=atob(option.data("time"));if(ai_debug){var option_name=atob(option.data("name"));console.log("AI TIMED ROTATE index:",random_index,"name:",option_name,"time:",rotation_time)}if(rotation_time==0&&rotate_options.length>1){var next_random_index=random_index;do{next_random_index++;if(next_random_index>=rotate_options.length)next_random_index=0;var next_option=$(rotate_options[next_random_index]);
4
+ if(typeof next_option.data("time")=="undefined"){random_index=next_random_index;option=$(rotate_options[random_index]);rotation_time=0;if(ai_debug)console.log("AI TIMED ROTATE next option has no time: ",next_random_index);break}var next_rotation_time=atob(next_option.data("time"));if(ai_debug)console.log("AI TIMED ROTATE check:",next_random_index,"time:",next_rotation_time)}while(next_rotation_time==0&&next_random_index!=random_index);if(rotation_time!=0){random_index=next_random_index;option=$(rotate_options[random_index]);
5
+ rotation_time=atob(option.data("time"))}if(ai_debug)console.log("AI TIMED ROTATE index:",random_index,"time:",rotation_time)}if(rotation_time>0){var next_random_index=random_index+1;if(next_random_index>=rotate_options.length)next_random_index=0;if(typeof $(rotation_block).data("info")!="undefined"){var block_info=JSON.parse(atob($(rotation_block).data("info")));var rotation_id=block_info[0];$(rotation_block).attr("data-next",next_random_index);setTimeout(function(){ai_process_rotation($("div.ai-rotate.ai-"+
6
+ rotation_id))},rotation_time*1E3);option_time_text=" ("+rotation_time+" s)"}}}else{if(!ai_debug)rotate_options.each(function(index){if(index!=random_index)$(this).remove()});if(ai_debug)console.log("AI ROTATE no time");if(ai_debug)console.log("AI ROTATE index:",random_index)}option.css({"display":"","visibility":"","position":"","width":"","height":"","top":"","left":""}).removeClass("ai-rotate-hidden").removeClass("ai-rotate-hidden-2");$(rotation_block).css({"position":""});if(typeof option.data("code")!=
7
+ "undefined"){rotate_options.empty();var option_code=atob(option.data("code"));option.append(option_code)}var option_name="";var debug_block_frame=$(rotation_block).closest(".ai-debug-block");if(typeof debug_block_frame!="undefined"){var option_name=atob(option.data("name"));var name_tag=debug_block_frame.find("kbd.ai-option-name");var nested_debug_block=debug_block_frame.find(".ai-debug-block");if(typeof nested_debug_block!="undefined"){var name_tag2=nested_debug_block.find("kbd.ai-option-name");
8
+ name_tag=name_tag.slice(0,name_tag.length-name_tag2.length)}if(typeof name_tag!="undefined"){var separator=name_tag.first().data("separator");if(typeof separator=="undefined")separator="";name_tag.html(separator+option_name+option_time_text)}}var tracking_updated=false;var adb_show_wrapping_div=$(rotation_block).closest(".ai-adb-show");if(typeof adb_show_wrapping_div!="undefined")if(typeof adb_show_wrapping_div.data("ai-tracking")!="undefined"){var data=JSON.parse(atob(adb_show_wrapping_div.data("ai-tracking")));
9
+ if(typeof data!=="undefined"&&data.constructor===Array){data[1]=random_index+1;data[3]=option_name;adb_show_wrapping_div.data("ai-tracking",btoa(JSON.stringify(data)));tracking_updated=true}}if(!tracking_updated){var wrapping_div=$(rotation_block).closest("div[data-ai]");if(typeof wrapping_div.data("ai")!="undefined"){var data=JSON.parse(atob(wrapping_div.data("ai")));if(typeof data!=="undefined"&&data.constructor===Array){data[1]=random_index+1;data[3]=option_name;wrapping_div.data("ai",btoa(JSON.stringify(data)))}}}};
10
+ function ai_process_rotations(){$("div.ai-rotate").each(function(index,element){ai_process_rotation(this)})}ai_process_rotations_in_element=function(el){$("div.ai-rotate",el).each(function(index,element){ai_process_rotation(this)})};$(document).ready(function($){setTimeout(function(){ai_process_rotations()},10)})});
includes/preview.php CHANGED
@@ -2132,6 +2132,7 @@ Single pages (posts and static pages) have also additional setting for individua
2132
  <?php
2133
  if ($sticky) echo ai_get_js ('ai-sticky');
2134
  echo ai_get_js ('ai-rotate');
 
2135
  if ($sticky) echo "setTimeout (function() {AOS.init();}, 200);\n";
2136
  if (defined ('AI_ADSENSE_OVERLAY')) {
2137
  echo ai_get_js ('ai-ads');
2132
  <?php
2133
  if ($sticky) echo ai_get_js ('ai-sticky');
2134
  echo ai_get_js ('ai-rotate');
2135
+ echo ai_get_js ('ai-load');
2136
  if ($sticky) echo "setTimeout (function() {AOS.init();}, 200);\n";
2137
  if (defined ('AI_ADSENSE_OVERLAY')) {
2138
  echo ai_get_js ('ai-ads');
js/ad-inserter.js CHANGED
@@ -1,4 +1,4 @@
1
- var javascript_version = "2.3.12";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
@@ -1604,7 +1604,7 @@ jQuery(document).ready(function($) {
1604
  });
1605
  $("input#show-label-"+tab).change (function() {
1606
  var block = $(this).attr('id').replace ("show-label-", "");
1607
- process_display_elements (block);
1608
  });
1609
  $("#enable-shortcode-"+tab).change (function() {
1610
  var block = $(this).attr('id').replace ("enable-shortcode-", "");
1
+ var javascript_version = "2.3.13";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
1604
  });
1605
  $("input#show-label-"+tab).change (function() {
1606
  var block = $(this).attr('id').replace ("show-label-", "");
1607
+ // process_display_elements (block);
1608
  });
1609
  $("#enable-shortcode-"+tab).change (function() {
1610
  var block = $(this).attr('id').replace ("enable-shortcode-", "");
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: ads, adsense, header footer code, ad management, sticky fixed widgets, adv
6
  Requires at least: 4.0
7
  Tested up to: 4.9
8
  Requires PHP: 5.6
9
- Stable tag: 2.3.11
10
  License: GPLv3
11
 
12
  Insert and manage ads: Amazon, Google AdSense ads, banner rotation, sticky widget ads, AMP, PHP, HTML, CSS, Javascript, tracking, footer, header code
@@ -119,7 +119,7 @@ Amazon suggests to use Ad Inserter to add Native Shopping Ads to Wordpress posts
119
 
120
  Check <a href="https://affiliate-program.amazon.com/help/topic/t405" target="_blank">Wordpress Integration Guide for Native Shopping Ads</a>. Ad Inserter supports also advanced contextual ads: check settings for <a href="https://adinserter.pro/settings#amazon">contextual Native Shopping Ads</a> that show ads with items related to the post content (using post tags).
121
 
122
- And if you need more ads with page/category specific settings, ad statistics and metrics for impressions and clicks, A/B testing, sticky ads, slider ads, pop-up ads, geotargeting or geolocation to serve country-specific ads, functions to protect content from users using ad blockers, functions to serve different ads for users using ad blockers, multisite options to limit settings for ads, to block some IP addresses, to schedule ads, there is **Ad Inserter Pro** - all-in-one <a href="http://adinserter.pro/" target="_blank">WordPress ad management plugin</a> that has many advanced features:
123
 
124
  * 64 code (ad) blocks (64 different insertion configurations for ads)
125
  * Geolocation using Webnet77 or <a href="http://www.maxmind.com/" target="_blank">MaxMind</a> databases (works also with caching)
@@ -127,6 +127,7 @@ And if you need more ads with page/category specific settings, ad statistics and
127
  * Ad impression and click statistics (works also with `<iframe>` Javascript ads like Google AdSense)
128
  * External tracking via Google Analytics or Matomo (Piwik)
129
  * A/B testing - discover ads and settings that perform best
 
130
  * [Sticky ads](https://adinserter.pro/alignments-and-styles#sticky-ads) with optional close button
131
  * Sticky sidebar ads (stick to the screen or to the content)
132
  * Floating slide-in banner ads
@@ -180,6 +181,7 @@ Ad Inserter is not just another plugin for WordPress ads. Do you enjoy finding t
180
  * to detect ad blocking
181
  * to insert banner ads
182
  * to insert PHP or HTML code into posts
 
183
  * to insert tracking, footer or header code
184
  * to insert PHP, HTML, CSS, shortcodes
185
  * to insert Google analytics code
@@ -669,6 +671,11 @@ AD CODE RIGHT
669
 
670
  == Changelog ==
671
 
 
 
 
 
 
672
  = 2.3.12 =
673
  - Fix for urlencode error
674
  - Few other minor bug fixes
@@ -692,7 +699,7 @@ AD CODE RIGHT
692
  - Few minor bug fixes, cosmetic changes and code improvements
693
 
694
  = 2.3.8 =
695
- - Added support rotation option shares
696
  - Added support for sticky ad settings and animations (Pro only)
697
  - Few minor bug fixes, cosmetic changes and code improvements
698
 
@@ -750,6 +757,11 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
750
 
751
  == Upgrade Notice ==
752
 
 
 
 
 
 
753
  = 2.3.12 =
754
  Fix for urlencode error;
755
  Few other minor bug fixes
@@ -773,7 +785,7 @@ Added non-interaction parameter to external tracking (Pro only);
773
  Few minor bug fixes, cosmetic changes and code improvements
774
 
775
  = 2.3.8 =
776
- Added support rotation option shares;
777
  Added support for sticky ad settings and animations (Pro only);
778
  Few minor bug fixes, cosmetic changes and code improvements
779
 
6
  Requires at least: 4.0
7
  Tested up to: 4.9
8
  Requires PHP: 5.6
9
+ Stable tag: 2.3.12
10
  License: GPLv3
11
 
12
  Insert and manage ads: Amazon, Google AdSense ads, banner rotation, sticky widget ads, AMP, PHP, HTML, CSS, Javascript, tracking, footer, header code
119
 
120
  Check <a href="https://affiliate-program.amazon.com/help/topic/t405" target="_blank">Wordpress Integration Guide for Native Shopping Ads</a>. Ad Inserter supports also advanced contextual ads: check settings for <a href="https://adinserter.pro/settings#amazon">contextual Native Shopping Ads</a> that show ads with items related to the post content (using post tags).
121
 
122
+ And if you need more ads with page/category specific settings, ad statistics and metrics for impressions and clicks, A/B testing, lazy loading ads, sticky ads, slider ads, pop-up ads, geotargeting or geolocation to serve country-specific ads, functions to protect content from users using ad blockers, functions to serve different ads for users using ad blockers, multisite options to limit settings for ads, to block some IP addresses, to schedule ads, there is **Ad Inserter Pro** - all-in-one <a href="http://adinserter.pro/" target="_blank">WordPress ad management plugin</a> that has many advanced features:
123
 
124
  * 64 code (ad) blocks (64 different insertion configurations for ads)
125
  * Geolocation using Webnet77 or <a href="http://www.maxmind.com/" target="_blank">MaxMind</a> databases (works also with caching)
127
  * Ad impression and click statistics (works also with `<iframe>` Javascript ads like Google AdSense)
128
  * External tracking via Google Analytics or Matomo (Piwik)
129
  * A/B testing - discover ads and settings that perform best
130
+ * Lazy loading ads
131
  * [Sticky ads](https://adinserter.pro/alignments-and-styles#sticky-ads) with optional close button
132
  * Sticky sidebar ads (stick to the screen or to the content)
133
  * Floating slide-in banner ads
181
  * to detect ad blocking
182
  * to insert banner ads
183
  * to insert PHP or HTML code into posts
184
+ * to insert PHP ads
185
  * to insert tracking, footer or header code
186
  * to insert PHP, HTML, CSS, shortcodes
187
  * to insert Google analytics code
671
 
672
  == Changelog ==
673
 
674
+ = 2.3.13 =
675
+ - Added support for lazy loading (Pro only)
676
+ - Fix for unwanted insertions with some paragraph settings
677
+ - Few minor bug fixes, cosmetic changes and code improvements
678
+
679
  = 2.3.12 =
680
  - Fix for urlencode error
681
  - Few other minor bug fixes
699
  - Few minor bug fixes, cosmetic changes and code improvements
700
 
701
  = 2.3.8 =
702
+ - Added support for rotation option shares
703
  - Added support for sticky ad settings and animations (Pro only)
704
  - Few minor bug fixes, cosmetic changes and code improvements
705
 
757
 
758
  == Upgrade Notice ==
759
 
760
+ = 2.3.13 =
761
+ Added support for lazy loading (Pro only);
762
+ Fix for unwanted insertions with some paragraph settings;
763
+ Few minor bug fixes, cosmetic changes and code improvements
764
+
765
  = 2.3.12 =
766
  Fix for urlencode error;
767
  Few other minor bug fixes
785
  Few minor bug fixes, cosmetic changes and code improvements
786
 
787
  = 2.3.8 =
788
+ Added support for rotation option shares;
789
  Added support for sticky ad settings and animations (Pro only);
790
  Few minor bug fixes, cosmetic changes and code improvements
791
 
settings.php CHANGED
@@ -438,7 +438,7 @@ function generate_settings_form (){
438
 
439
  $adb_block_action_active = $obj->get_adb_block_action () != AI_ADB_BLOCK_ACTION_DO_NOTHING;
440
 
441
- $display_options = $obj->get_show_label () || $obj->get_close_button ();
442
 
443
  $show_misc =
444
  $insertion_options ||
@@ -1762,6 +1762,7 @@ function generate_settings_form (){
1762
  <input style="" id="show-label-<?php echo $block; ?>" type="checkbox" name="<?php echo AI_OPTION_SHOW_LABEL, WP_FORM_FIELD_POSTFIX, $block; ?>" value="1" default="<?php echo $default->get_show_label (); ?>" <?php if ($obj->get_show_label () == AI_ENABLED) echo 'checked '; ?> />
1763
  <label for="show-label-<?php echo $block; ?>">Ad label</label>
1764
  </td>
 
1765
  <td>
1766
  <?php if (function_exists ('ai_display_close')) ai_display_close ($block, $obj, $default, 'close-button-'.$block, AI_OPTION_CLOSE_BUTTON . WP_FORM_FIELD_POSTFIX . $block); ?>
1767
  </td>
@@ -2429,7 +2430,7 @@ function generate_settings_form (){
2429
  Used blocks
2430
  </td>
2431
  <td>
2432
- <?php if (isset ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS])) echo count ($used_blocks), ' (', implode (', ', array_slice ($used_blocks, 0, 26)), count ($used_blocks) > 26 ? ',...' : '', ')'; ?>
2433
  </td>
2434
  </tr>
2435
  <?php if (function_exists ('ai_system_debugging')) ai_system_debugging (); ?>
438
 
439
  $adb_block_action_active = $obj->get_adb_block_action () != AI_ADB_BLOCK_ACTION_DO_NOTHING;
440
 
441
+ $display_options = $obj->get_show_label () || $obj->get_lazy_loading () || $obj->get_close_button ();
442
 
443
  $show_misc =
444
  $insertion_options ||
1762
  <input style="" id="show-label-<?php echo $block; ?>" type="checkbox" name="<?php echo AI_OPTION_SHOW_LABEL, WP_FORM_FIELD_POSTFIX, $block; ?>" value="1" default="<?php echo $default->get_show_label (); ?>" <?php if ($obj->get_show_label () == AI_ENABLED) echo 'checked '; ?> />
1763
  <label for="show-label-<?php echo $block; ?>">Ad label</label>
1764
  </td>
1765
+ <?php if (function_exists ('ai_display_lazy')) ai_display_lazy ($block, $obj, $default, 'lazy-loading-'.$block, AI_OPTION_CLOSE_BUTTON . WP_FORM_FIELD_POSTFIX . $block); ?>
1766
  <td>
1767
  <?php if (function_exists ('ai_display_close')) ai_display_close ($block, $obj, $default, 'close-button-'.$block, AI_OPTION_CLOSE_BUTTON . WP_FORM_FIELD_POSTFIX . $block); ?>
1768
  </td>
2430
  Used blocks
2431
  </td>
2432
  <td>
2433
+ <?php if (isset ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS])) echo count ($used_blocks), ' (', implode (', ', array_slice ($used_blocks, 0, 24)), count ($used_blocks) > 24 ? ',...' : '', ')'; ?>
2434
  </td>
2435
  </tr>
2436
  <?php if (function_exists ('ai_system_debugging')) ai_system_debugging (); ?>