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

Version Description

  • Added support for W3TC/client-side check for cookies (in url parameter list) to support showing ads based on visitor's cookie consent
  • Added support for W3TC/client-side check for referers
  • Improved paragraph processing
  • 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.11
Comparing to
See all releases

Code changes from version 2.3.10 to 2.3.11

ad-inserter.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
- Version: 2.3.10
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,12 @@ Plugin URI: http://adinserter.pro/documentation
13
 
14
  Change Log
15
 
 
 
 
 
 
 
16
  Ad Inserter 2.3.10 - 2018-06-16
17
  - Added support for timed rotation
18
  - Added support for client-side insertion of dynamic blocks
@@ -851,8 +857,9 @@ function ai_toolbar_menu_items () {
851
  $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
852
  'id' => 'ai-toolbar-settings',
853
  // 'parent' => 'ai-toolbar',
854
- 'title' => '<span class="ab-icon'.$debug_settings_class.'"></span>'.AD_INSERTER_NAME,
855
  'href' => $top_menu_url,
 
856
  );
857
 
858
  $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
@@ -915,7 +922,9 @@ function ai_toolbar_menu_items () {
915
  $no_paragraph_counting_inside = get_no_paragraph_counting_inside ();
916
 
917
  foreach ($paragraph_blocks as $index => $paragraph_block) {
918
- $block_class = $debug_positions === '' && in_array ($ai_wp_data [AI_WP_DEBUG_BLOCK], $paragraph_block ['blocks']) ? ' on' : '';
 
 
919
  $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
920
  'id' => 'ai-toolbar-positions-'.$index,
921
  'parent' => 'ai-toolbar-positions',
@@ -926,7 +935,8 @@ function ai_toolbar_menu_items () {
926
  ($paragraph_block ['max'] != 0 ? ' max '.$paragraph_block ['max']. ' ' : '').
927
  ($paragraph_block ['blockquote'] ? ' +[' . $no_paragraph_counting_inside . '] ' : '').
928
  ($paragraph_block ['text'] != '' ? ($paragraph_block ['text_type'] == AD_DO_NOT_CONTAIN ? ' NC ' : ' C ').' ['.htmlentities ($paragraph_block ['text']).']' : ''),
929
- 'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $paragraph_block ['blocks'][0]),
 
930
  );
931
  }
932
 
@@ -1804,7 +1814,7 @@ function ai_get_client_side_styles () {
1804
  ".ai-rotate {position: relative;}\n" .
1805
  ".ai-rotate-hidden {visibility: hidden;}\n" .
1806
  ".ai-rotate-hidden-2 {position: absolute; top: 0; left: 0; width: 100%; height: 100%;}\n" .
1807
- ".ai-ip-data, .ai-ip-data-block {visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999;}\n";
1808
  }
1809
 
1810
  function add_head_inline_styles_and_scripts () {
@@ -1826,7 +1836,7 @@ function add_head_inline_styles_and_scripts () {
1826
  // echo ".ai-rotate {position: relative;}\n";
1827
  // echo ".ai-rotate-hidden {visibility: hidden;}\n";
1828
  // echo ".ai-rotate-hidden-2 {position: absolute; top: 0; left: 0; width: 100%; height: 100%;}\n";
1829
- // echo ".ai-ip-data, .ai-ip-data-block {visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999;}\n";
1830
 
1831
  echo ai_get_client_side_styles ();
1832
 
@@ -2089,10 +2099,16 @@ function add_footer_inline_scripts () {
2089
 
2090
  if ($footer_inline_scripts) echo "<script type='text/javascript'>\n";
2091
 
2092
- if (get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT || isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION])) {
 
 
2093
  echo ai_get_js ('ai-rotate');
2094
  }
2095
 
 
 
 
 
2096
  if ($ai_wp_data [AI_STICKY_WIDGETS]) {
2097
  echo ai_get_js ('ai-sidebar');
2098
  }
@@ -2476,7 +2492,7 @@ function ai_header_noindex () {
2476
  global $ai_wp_data;
2477
 
2478
  if ($ai_wp_data [AI_WP_DEBUGGING] != 0) {
2479
- echo '<meta name="robots" content="noindex"> <!-- ', AD_INSERTER_NAME, ' debugging enabled (', $ai_wp_data [AI_WP_DEBUGGING], ') -->', "\n";
2480
  }
2481
  }
2482
 
@@ -2907,8 +2923,8 @@ function ai_write_debug_info ($write_processing_log = false) {
2907
  $meta_string []= $key . ':' . $post_meta_field_item;
2908
  }
2909
  }
2910
- echo 'POST META: ', implode (', ', $meta_string), "\n";
2911
-
2912
  break;
2913
  case AI_PT_CATEGORY:
2914
  $category_data = get_the_category();
@@ -4770,13 +4786,13 @@ section.ai-debug-block {padding: 0; margin: 0;}
4770
  .ai-debug-adb-status.on {color: #f00;}
4771
  .ai-debug-adb-status.off {color: #0f0;}
4772
 
4773
- .ai-debug-block.ai-debug-ip {border-color: #00c5be;}
4774
- .ai-debug-bar.ai-debug-ip {background: #00c5be;}
4775
 
4776
  .ai-debug-adb-hidden {visibility: hidden; display: none;}
4777
  .ai-debug-adb-center {text-align: center; font-weight: bold; margin: 0; padding: 4px 0;}
4778
 
4779
- .ai-debug-bar {margin: 0; padding: 1px 0 1px 5px; color: white; font-size: 12px; font-family: arial; font-weight: normal; line-height: 20px; text-align: center;}
4780
 
4781
  .ai-debug-bar .ai-debug-text-left {float: left;}
4782
  .ai-debug-bar .ai-debug-text-right {float: right; padding-right: 3px;}
@@ -5909,7 +5925,6 @@ function ai_process_shortcode (&$block, $atts) {
5909
  "name" => "",
5910
  "ignore" => "",
5911
  "check" => "",
5912
- // "debugger" => "",
5913
  "adb" => "",
5914
  "css" => "",
5915
  "text" => "",
@@ -6495,3 +6510,207 @@ function ai_special_widget ($args, $instance, $block) {
6495
 
6496
  echo $args ['after_widget'];
6497
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
+ Version: 2.3.11
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.11 - 2018-07-03
17
+ - Added support for W3TC/client-side check for cookies (in url parameter list) to support showing ads based on visitor's cookie consent
18
+ - Added support for W3TC/client-side check for referers
19
+ - Improved paragraph processing
20
+ - Few minor bug fixes, cosmetic changes and code improvements
21
+
22
  Ad Inserter 2.3.10 - 2018-06-16
23
  - Added support for timed rotation
24
  - Added support for client-side insertion of dynamic blocks
857
  $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
858
  'id' => 'ai-toolbar-settings',
859
  // 'parent' => 'ai-toolbar',
860
+ 'title' => '<span class="ab-icon'.$debug_settings_class.'"></span>'.AD_INSERTER_NAME . ($debug_settings_on ? ' Debugging' : ''),
861
  'href' => $top_menu_url,
862
+ // 'meta' => $debug_settings_on ? array ('title' => 'Turn Debugging Off') : array (),
863
  );
864
 
865
  $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
922
  $no_paragraph_counting_inside = get_no_paragraph_counting_inside ();
923
 
924
  foreach ($paragraph_blocks as $index => $paragraph_block) {
925
+ $debug_block_active = $debug_positions === '' && in_array ($ai_wp_data [AI_WP_DEBUG_BLOCK], $paragraph_block ['blocks']);
926
+ $block_class = $debug_block_active ? ' on' : '';
927
+ // $block_class = $debug_positions === '' && in_array ($ai_wp_data [AI_WP_DEBUG_BLOCK], $paragraph_block ['blocks']) ? ' on' : '';
928
  $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
929
  'id' => 'ai-toolbar-positions-'.$index,
930
  'parent' => 'ai-toolbar-positions',
935
  ($paragraph_block ['max'] != 0 ? ' max '.$paragraph_block ['max']. ' ' : '').
936
  ($paragraph_block ['blockquote'] ? ' +[' . $no_paragraph_counting_inside . '] ' : '').
937
  ($paragraph_block ['text'] != '' ? ($paragraph_block ['text_type'] == AD_DO_NOT_CONTAIN ? ' NC ' : ' C ').' ['.htmlentities ($paragraph_block ['text']).']' : ''),
938
+ // 'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $paragraph_block ['blocks'][0]),
939
+ 'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $debug_block_active ? '' : $paragraph_block ['blocks'][0]),
940
  );
941
  }
942
 
1814
  ".ai-rotate {position: relative;}\n" .
1815
  ".ai-rotate-hidden {visibility: hidden;}\n" .
1816
  ".ai-rotate-hidden-2 {position: absolute; top: 0; left: 0; width: 100%; height: 100%;}\n" .
1817
+ ".ai-list-data, .ai-ip-data, .ai-list-block {visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999;}\n";
1818
  }
1819
 
1820
  function add_head_inline_styles_and_scripts () {
1836
  // echo ".ai-rotate {position: relative;}\n";
1837
  // echo ".ai-rotate-hidden {visibility: hidden;}\n";
1838
  // echo ".ai-rotate-hidden-2 {position: absolute; top: 0; left: 0; width: 100%; height: 100%;}\n";
1839
+ // echo ".ai-ip-data, .ai-list-block {visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999;}\n";
1840
 
1841
  echo ai_get_client_side_styles ();
1842
 
2099
 
2100
  if ($footer_inline_scripts) echo "<script type='text/javascript'>\n";
2101
 
2102
+ $client_side_dynamic_blocks = get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT;
2103
+
2104
+ if ($client_side_dynamic_blocks || isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION])) {
2105
  echo ai_get_js ('ai-rotate');
2106
  }
2107
 
2108
+ if ($client_side_dynamic_blocks) {
2109
+ echo ai_get_js ('ai-lists');
2110
+ }
2111
+
2112
  if ($ai_wp_data [AI_STICKY_WIDGETS]) {
2113
  echo ai_get_js ('ai-sidebar');
2114
  }
2492
  global $ai_wp_data;
2493
 
2494
  if ($ai_wp_data [AI_WP_DEBUGGING] != 0) {
2495
+ echo '<meta name="robots" content="noindex"> <!-- ', AD_INSERTER_NAME, ' debugging enabled (', strtoupper (decbin ($ai_wp_data [AI_WP_DEBUGGING])), ') -->', "\n";
2496
  }
2497
  }
2498
 
2923
  $meta_string []= $key . ':' . $post_meta_field_item;
2924
  }
2925
  }
2926
+ // echo 'POST META: ', implode (', ', $meta_string), "\n";
2927
+ echo 'POST META: ', str_replace (array ("<!--", "-->", "\n", "\r"), array ("[!--", "--]", "*n", "*r"), implode (', ', $meta_string)), "\n";
2928
  break;
2929
  case AI_PT_CATEGORY:
2930
  $category_data = get_the_category();
4786
  .ai-debug-adb-status.on {color: #f00;}
4787
  .ai-debug-adb-status.off {color: #0f0;}
4788
 
4789
+ .ai-debug-block.ai-debug-lists {border-color: #00c5be;}
4790
+ .ai-debug-bar.ai-debug-lists {background: #00c5be;}
4791
 
4792
  .ai-debug-adb-hidden {visibility: hidden; display: none;}
4793
  .ai-debug-adb-center {text-align: center; font-weight: bold; margin: 0; padding: 4px 0;}
4794
 
4795
+ .ai-debug-bar {margin: 0; padding: 1px 0 1px 5px; color: white; font-size: 12px; font-family: arial; font-weight: normal; line-height: 20px; text-align: center; overflow: hidden; word-break: break-word;}
4796
 
4797
  .ai-debug-bar .ai-debug-text-left {float: left;}
4798
  .ai-debug-bar .ai-debug-text-right {float: right; padding-right: 3px;}
5925
  "name" => "",
5926
  "ignore" => "",
5927
  "check" => "",
 
5928
  "adb" => "",
5929
  "css" => "",
5930
  "text" => "",
6510
 
6511
  echo $args ['after_widget'];
6512
  }
6513
+
6514
+ function check_url_parameter_list ($url_parameters, $white_list, $server_side_check = true, $check_url_parameters = true, $check_cookies = true) {
6515
+
6516
+ $parameter_list = trim ($url_parameters);
6517
+
6518
+ $return = $white_list;
6519
+
6520
+ if ($check_url_parameters) {
6521
+ if ($check_cookies) {
6522
+ $parameters = array_merge ($_COOKIE, $_GET);
6523
+ } else $parameters = $_GET;
6524
+ } else $parameters = $_COOKIE;
6525
+
6526
+ foreach ($parameters as $index => $parameter) {
6527
+ $parameters [$index] = urlencode ($parameter);
6528
+ }
6529
+
6530
+ if ($parameter_list == AD_EMPTY_DATA || count ($parameters) == 0) {
6531
+ if ($server_side_check && $check_cookies) {
6532
+ return !$return;
6533
+ }
6534
+
6535
+ // Return true as client-side check will check cookies and decide
6536
+ return true;
6537
+ }
6538
+
6539
+ $parameters_listed = explode (",", $parameter_list);
6540
+ foreach ($parameters_listed as $index => $parameter_listed) {
6541
+ if (trim ($parameter_listed) == "") unset ($parameters_listed [$index]); else
6542
+ $parameters_listed [$index] = trim ($parameter_listed);
6543
+ }
6544
+
6545
+ foreach ($parameters_listed as $parameter) {
6546
+ if (strpos ($parameter, "=") !== false) {
6547
+ $parameter_value = explode ("=", $parameter);
6548
+ if (array_key_exists ($parameter_value [0], $parameters) && $parameters [$parameter_value [0]] == $parameter_value [1]) return $return;
6549
+ } else if (array_key_exists ($parameter, $parameters)) return $return;
6550
+ }
6551
+
6552
+ if ($server_side_check && $check_cookies) {
6553
+ return !$return;
6554
+ }
6555
+
6556
+ // Return true as client-side check will check cookies and decide
6557
+ return true;
6558
+ }
6559
+
6560
+ function check_check_referer_list ($referers, $white_list) {
6561
+
6562
+ if (isset ($_SERVER['HTTP_REFERER'])) {
6563
+ $referer_host = strtolower (parse_url ($_SERVER['HTTP_REFERER'], PHP_URL_HOST));
6564
+ } else $referer_host = '';
6565
+
6566
+ $return = $white_list;
6567
+
6568
+ $domains = strtolower (trim ($referers));
6569
+ if ($domains == AD_EMPTY_DATA) return !$return;
6570
+ $domains = explode (",", $domains);
6571
+
6572
+ foreach ($domains as $domain) {
6573
+ $domain = trim ($domain);
6574
+ if ($domain == "") continue;
6575
+
6576
+ if ($domain == "#") {
6577
+ if ($referer_host == "") return $return;
6578
+ } elseif ($domain == $referer_host) return $return;
6579
+ }
6580
+ return !$return;
6581
+ }
6582
+
6583
+ function get_paragraph_start_positions ($content, $multibyte, $paragraph_end_positions, $paragraph_start_strings, &$paragraph_positions, &$active_paragraph_positions) {
6584
+ foreach ($paragraph_start_strings as $paragraph_start_string) {
6585
+ if (trim ($paragraph_start_string) == '') continue;
6586
+
6587
+ $last_position = - 1;
6588
+
6589
+ $paragraph_start_string = trim ($paragraph_start_string);
6590
+ if ($paragraph_start_string == "#") {
6591
+ $paragraph_start = "\r\n\r\n";
6592
+ if (!in_array (0, $paragraph_positions)) {
6593
+ $paragraph_positions [] = 0;
6594
+ $active_paragraph_positions [0] = 1;
6595
+ }
6596
+ } else $paragraph_start = '<' . $paragraph_start_string;
6597
+
6598
+ if ($multibyte) {
6599
+ $paragraph_start_len = mb_strlen ($paragraph_start);
6600
+ while (mb_stripos ($content, $paragraph_start, $last_position + 1) !== false) {
6601
+ $last_position = mb_stripos ($content, $paragraph_start, $last_position + 1);
6602
+ if ($paragraph_start_string == "#") {
6603
+ $paragraph_positions [] = $last_position + 4;
6604
+ $active_paragraph_positions [$last_position + 4] = 1;
6605
+ } elseif (mb_substr ($content, $last_position + $paragraph_start_len, 1) == ">" || mb_substr ($content, $last_position + $paragraph_start_len, 1) == " ") {
6606
+ $paragraph_positions [] = $last_position;
6607
+ $active_paragraph_positions [$last_position] = 1;
6608
+ }
6609
+ }
6610
+ } else {
6611
+ $paragraph_start_len = strlen ($paragraph_start);
6612
+ while (stripos ($content, $paragraph_start, $last_position + 1) !== false) {
6613
+ $last_position = stripos ($content, $paragraph_start, $last_position + 1);
6614
+ if ($paragraph_start_string == "#") {
6615
+ $paragraph_positions [] = $last_position + 4;
6616
+ $active_paragraph_positions [$last_position + 4] = 1;
6617
+ } elseif ($content [$last_position + $paragraph_start_len] == ">" || $content [$last_position + $paragraph_start_len] == " ") {
6618
+ $paragraph_positions [] = $last_position;
6619
+ $active_paragraph_positions [$last_position] = 1;
6620
+ }
6621
+ }
6622
+ }
6623
+ }
6624
+
6625
+ // Consistency check
6626
+ if (count ($paragraph_end_positions) != 0) {
6627
+ foreach ($paragraph_end_positions as $index => $paragraph_end_position) {
6628
+ if ($index == 0) {
6629
+ if (!isset ($paragraph_positions [$index]) || $paragraph_positions [$index] >= $paragraph_end_position) {
6630
+ $paragraph_positions [$index] = 0;
6631
+ }
6632
+ } else {
6633
+ if (!isset ($paragraph_positions [$index]) || $paragraph_positions [$index] >= $paragraph_end_position || $paragraph_positions [$index] <= $paragraph_end_positions [$index - 1]) {
6634
+ $paragraph_positions [$index] = $paragraph_end_positions [$index - 1] + 1;
6635
+ }
6636
+ }
6637
+ }
6638
+ }
6639
+ }
6640
+
6641
+ function get_paragraph_end_positions ($content, $multibyte, $paragraph_start_positions, $paragraph_end_strings, &$paragraph_positions, &$active_paragraph_positions) {
6642
+
6643
+ $no_closing_tag = array ('img', 'hr', 'br');
6644
+
6645
+ foreach ($paragraph_end_strings as $paragraph_end_string) {
6646
+
6647
+ $last_position = - 1;
6648
+
6649
+ $paragraph_end_string = trim ($paragraph_end_string);
6650
+ if ($paragraph_end_string == '') continue;
6651
+
6652
+ if (in_array ($paragraph_end_string, $no_closing_tag)) {
6653
+ if (preg_match_all ("/<$paragraph_end_string(.*?)>/", $content, $images)) {
6654
+ foreach ($images [0] as $paragraph_end) {
6655
+ if ($multibyte) {
6656
+ $last_position = mb_stripos ($content, $paragraph_end, $last_position + 1) + mb_strlen ($paragraph_end) - 1;
6657
+ $paragraph_positions [] = $last_position;
6658
+ $active_paragraph_positions [$last_position] = 1;
6659
+ } else {
6660
+ $last_position = stripos ($content, $paragraph_end, $last_position + 1) + strlen ($paragraph_end) - 1;
6661
+ $paragraph_positions [] = $last_position;
6662
+ $active_paragraph_positions [$last_position] = 1;
6663
+ }
6664
+ }
6665
+ }
6666
+ continue;
6667
+ }
6668
+ elseif ($paragraph_end_string == "#") {
6669
+ $paragraph_end = "\r\n\r\n";
6670
+ if (!in_array ($last_content_position, $paragraph_positions)) {
6671
+ $paragraph_positions [] = $last_content_position;
6672
+ $active_paragraph_positions [$last_content_position] = 1;
6673
+ }
6674
+ } else $paragraph_end = '</' . $paragraph_end_string . '>';
6675
+
6676
+ if ($multibyte) {
6677
+ while (mb_stripos ($content, $paragraph_end, $last_position + 1) !== false) {
6678
+ $last_position = mb_stripos ($content, $paragraph_end, $last_position + 1) + mb_strlen ($paragraph_end) - 1;
6679
+ if ($paragraph_end_string == "#") {
6680
+ $paragraph_positions [] = $last_position - 4;
6681
+ $active_paragraph_positions [$last_position - 4] = 1;
6682
+ } else {
6683
+ $paragraph_positions [] = $last_position;
6684
+ $active_paragraph_positions [$last_position] = 1;
6685
+ }
6686
+ }
6687
+ } else {
6688
+ while (stripos ($content, $paragraph_end, $last_position + 1) !== false) {
6689
+ $last_position = stripos ($content, $paragraph_end, $last_position + 1) + strlen ($paragraph_end) - 1;
6690
+ if ($paragraph_end_string == "#") {
6691
+ $paragraph_positions [] = $last_position - 4;
6692
+ $active_paragraph_positions [$last_position - 4] = 1;
6693
+ } else {
6694
+ $paragraph_positions [] = $last_position;
6695
+ $active_paragraph_positions [$last_position] = 1;
6696
+ }
6697
+ }
6698
+ }
6699
+ }
6700
+
6701
+ // Consistency check
6702
+ if (count ($paragraph_start_positions) != 0) {
6703
+ foreach ($paragraph_start_positions as $index => $paragraph_start_position) {
6704
+ if ($index == count ($paragraph_start_positions) - 1) {
6705
+ if (!isset ($paragraph_positions [$index]) || $paragraph_positions [$index] <= $paragraph_start_position) {
6706
+ $paragraph_positions [$index] = strlen ($content) - 1;
6707
+ }
6708
+ } else {
6709
+ if (!isset ($paragraph_positions [$index]) || $paragraph_positions [$index] <= $paragraph_start_position || $paragraph_positions [$index] >= $paragraph_start_positions [$index + 1]) {
6710
+ $paragraph_positions [$index] = $paragraph_start_positions [$index + 1] - 1;
6711
+ }
6712
+ }
6713
+ }
6714
+ }
6715
+ }
6716
+
changelog.txt CHANGED
@@ -2,6 +2,41 @@
2
 
3
  This is an archive of older changelog entries. Most recent entries are maintained in readme.txt
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  = 2.2.9 =
6
  - Output buffering is now disabled by default (for position Above header you need to enable it)
7
  - Fix for min. paragraph number not processed
2
 
3
  This is an archive of older changelog entries. Most recent entries are maintained in readme.txt
4
 
5
+ = 2.2.16 =
6
+ - Fix for error when saving settings on multisite installation
7
+
8
+ = 2.2.15 =
9
+ - Fix for responsive AMP ads using center alignment
10
+
11
+ = 2.2.14 =
12
+ - Added code generator for placeholders
13
+ - Added option to disable caching (works with WP Super Cache, W3 Total Cache and WP Rocket)
14
+ - Added options to configure classes for wrapping div
15
+ - Added support for external tracking via Google Analytics and Piwik (Pro only)
16
+ - Added support for MaxMind geolocation databases (Pro only)
17
+ - Added option for close button on sticky ads (Pro only)
18
+ - Fix for no paragraph counting inside nested elements
19
+ - Few minor bug fixes, cosmetic changes and code improvements
20
+
21
+ = 2.2.13 =
22
+ - Added option to disable inline alignment styles for code blocks (using alignment classes)
23
+ - Fix for custom CSS codes with single quotation marks
24
+
25
+ = 2.2.12 =
26
+ - Fix for code block styles when block class name was not set
27
+
28
+ = 2.2.11 =
29
+ - Code block styles moved to classes
30
+ - Code block list moved to the sidebar
31
+ - Added preview buttons in code block list
32
+ - Fix for ad blocking detection when using https (Pro only)
33
+ - Few minor bug fixes, cosmetic changes and code improvements
34
+
35
+ = 2.2.10 =
36
+ - Fix for rotation editor code import/export
37
+ - Fix for errors when using old |rotate| separator
38
+ - Few minor bug fixes, cosmetic changes and code improvements
39
+
40
  = 2.2.9 =
41
  - Output buffering is now disabled by default (for position Above header you need to enable it)
42
  - Fix for min. paragraph number not processed
class.php CHANGED
@@ -5,7 +5,7 @@ require_once AD_INSERTER_PLUGIN_DIR.'constants.php';
5
  abstract class ai_BaseCodeBlock {
6
  var $wp_options;
7
  var $fallback;
8
- var $client_side_ip_address_detection;
9
  var $w3tc_code;
10
  var $w3tc_code2;
11
  var $before_w3tc_code2;
@@ -24,7 +24,7 @@ abstract class ai_BaseCodeBlock {
24
 
25
  $this->wp_options = array ();
26
  $this->fallback = 0;
27
- $this->client_side_ip_address_detection = false;
28
  $this->w3tc_code = '';
29
  $this->w3tc_code2 = '';
30
  $this->before_w3tc_code2 = '';
@@ -1692,6 +1692,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1692
  $version_names = array ();
1693
  $version_shares = array ();
1694
  $version_times = array ();
 
1695
 
1696
  foreach ($ai_wp_data [AI_SHORTCODES]['rotate'] as $index => $option) {
1697
  $version_names []= isset ($option ['name']) && trim ($option ['name']) != '' ? $option ['name'] : chr (ord ('A') + $index);
@@ -1703,6 +1704,8 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1703
  $option_time = isset ($option ['time']) && is_numeric ($option ['time']);
1704
  if ($option_time) $times = true;
1705
  $version_times []= $option_time ? intval ($option ['time']) : - 1;
 
 
1706
  }
1707
 
1708
  if ($shares) {
@@ -1735,7 +1738,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1735
  }
1736
 
1737
  if ($times) {
1738
- $dynamic_blocks = AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW;
1739
  $ai_wp_data [AI_CLIENT_SIDE_ROTATION] = true;
1740
  }
1741
 
@@ -1791,11 +1794,10 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1791
  }
1792
 
1793
  $version_name_data = " data-name='".base64_encode ($version_names [$index])."'";
 
1794
 
1795
  switch ($temp_dynamic_blocks) {
1796
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1797
- $version_time_data = $version_times [$index] >= 0 ? " data-time='".base64_encode ($version_times [$index])."'" : '';
1798
-
1799
  switch ($index) {
1800
  case 0:
1801
  if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
@@ -1813,7 +1815,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1813
  break;
1814
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1815
  $version_code_data = " data-code='".base64_encode ($ad)."'";
1816
- $processed_code .= "<div class='ai-rotate-option'".$version_name_data.$version_code_data.">\n</div>\n";
1817
  break;
1818
  }
1819
 
@@ -1859,7 +1861,11 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1859
  break;
1860
  case AI_DYNAMIC_BLOCKS_SERVER_SIDE_W3TC:
1861
  $this->w3tc_code .= '$ai_amp_separator = \'' . AD_AMP_SEPARATOR . '\'; $ai_amp_page = ' . ($ai_wp_data [AI_WP_AMP_PAGE] ? 'true' : 'false') . '; $ai_amp_enabled = ' . $this->get_enable_amp () . ';';
1862
- $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;';
 
 
 
 
1863
  $processed_code = '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1864
  $processed_code .= $this->w3tc_code.' echo $ai_code;';
1865
  $processed_code .= '<!-- /mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
@@ -1870,6 +1876,66 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1870
  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;
1871
 
1872
  if ($temp_dynamic_blocks != AI_DYNAMIC_BLOCKS_SERVER_SIDE) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1873
  $countries = trim (str_replace (' ', '', strtoupper ($this->get_ad_country_list (true))));
1874
  $country_list_type = $this->get_ad_country_list_type ();
1875
 
@@ -1883,10 +1949,10 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1883
  if ($country_list_type == AD_BLACK_LIST) $country_list_type = 'B'; else $country_list_type = 'W';
1884
  if ($ip_address_list_type == AD_BLACK_LIST) $ip_address_list_type = 'B'; else $ip_address_list_type = 'W';
1885
 
1886
- if ($countries != '' || $country_list_type == 'W') $country_attributes = "countries='$countries' country-list='$country_list_type'"; else $country_attributes = '';
1887
  if ($ip_addresses != '' || $ip_address_list_type == 'W') $ip_address_attributes = "ip-addresses='$ip_addresses' ip-address-list='$ip_address_list_type'"; else $ip_address_attributes = '';
1888
 
1889
- $this->client_side_ip_address_detection = true;
1890
 
1891
  switch ($dynamic_blocks) {
1892
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
@@ -1902,7 +1968,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1902
  }
1903
 
1904
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
1905
- $debug_ip = new ai_block_labels ('ai-debug-ip');
1906
  $processed_code = $debug_ip->bar ($country_attributes . ' ' . $ip_address_attributes, '', '<kbd class="ai-debug-name ai-ip-status"></kbd>', '<kbd class="ai-debug-name ai-ip-country"></kbd>') . $processed_code;
1907
  }
1908
 
@@ -2050,13 +2116,13 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2050
  } else $classes = array ();
2051
 
2052
  if ($hidden_widgets) return $hidden_viewports; else {
2053
- if ($this->client_side_ip_address_detection && !$ai_wp_data [AI_WP_AMP_PAGE]) {
2054
  $additional_block_style = 'visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999; ';
2055
  // if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
2056
- // $classes [] = 'ai-ip-data-block';
2057
  // }
2058
  // Needed to locate wrapping div
2059
- $classes [] = 'ai-ip-data-block';
2060
  } else {
2061
  $additional_block_style = '';
2062
  }
@@ -2165,6 +2231,8 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2165
  }
2166
  }
2167
 
 
 
2168
  return $code;
2169
  }
2170
 
@@ -2268,6 +2336,8 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2268
  $serverside_insertion_code = str_replace ('[#AI_CODE#]', $block_code, $serverside_insertion_code);
2269
  }
2270
 
 
 
2271
  return $serverside_insertion_code;
2272
  }
2273
 
@@ -2629,6 +2699,9 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2629
  $multibyte = get_paragraph_counting_functions() == AI_MULTIBYTE_PARAGRAPH_COUNTING_FUNCTIONS;
2630
 
2631
  $paragraph_positions = array ();
 
 
 
2632
 
2633
  $paragraph_tags = trim ($this->get_paragraph_tags());
2634
  if ($paragraph_tags == '') return $content;
@@ -2638,41 +2711,62 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2638
  $ai_last_check = AI_CHECK_PARAGRAPH_TAGS;
2639
  if (count ($paragraph_start_strings) == 0) return $content;
2640
 
2641
- foreach ($paragraph_start_strings as $paragraph_start_string) {
2642
- if (trim ($paragraph_start_string) == '') continue;
2643
 
2644
- $last_position = - 1;
 
2645
 
2646
- $paragraph_start_string = trim ($paragraph_start_string);
2647
- if ($paragraph_start_string == "#") {
2648
- $paragraph_start = "\r\n\r\n";
2649
- if (!in_array (0, $paragraph_positions)) $paragraph_positions [] = 0;
2650
- } else $paragraph_start = '<' . $paragraph_start_string;
2651
 
2652
- if ($multibyte) {
2653
- $paragraph_start_len = mb_strlen ($paragraph_start);
2654
- while (mb_stripos ($content, $paragraph_start, $last_position + 1) !== false) {
2655
- $last_position = mb_stripos ($content, $paragraph_start, $last_position + 1);
2656
- if ($paragraph_start_string == "#") $paragraph_positions [] = $last_position + 4; else
2657
- if (mb_substr ($content, $last_position + $paragraph_start_len, 1) == ">" || mb_substr ($content, $last_position + $paragraph_start_len, 1) == " ")
2658
- $paragraph_positions [] = $last_position;
2659
- }
2660
- } else {
2661
- $paragraph_start_len = strlen ($paragraph_start);
2662
- while (stripos ($content, $paragraph_start, $last_position + 1) !== false) {
2663
- $last_position = stripos ($content, $paragraph_start, $last_position + 1);
2664
- if ($paragraph_start_string == "#") $paragraph_positions [] = $last_position + 4; else
2665
- if ($content [$last_position + $paragraph_start_len] == ">" || $content [$last_position + $paragraph_start_len] == " ")
2666
- $paragraph_positions [] = $last_position;
2667
- }
2668
- }
2669
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2670
 
2671
  // Nothing to do
2672
  $ai_last_check = AI_CHECK_PARAGRAPHS_WITH_TAGS;
2673
- if (count ($paragraph_positions) == 0) return $content;
 
2674
 
2675
  sort ($paragraph_positions);
 
 
 
 
 
 
 
2676
 
2677
  if (!$this->get_count_inside_blockquote ()) {
2678
 
@@ -2721,7 +2815,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2721
 
2722
  if (count ($special_element_offsets) != 0) {
2723
 
2724
- $filtered_paragraph_positions = array ();
2725
  $inside_special_element = array ();
2726
 
2727
  foreach ($special_element_offsets as $special_element_offset) {
@@ -2730,51 +2824,76 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2730
  }
2731
  }
2732
 
2733
- foreach ($paragraph_positions as $paragraph_position) {
2734
- if (!in_array ($paragraph_position, $inside_special_element)) $filtered_paragraph_positions []= $paragraph_position;
 
2735
  }
2736
 
2737
- $paragraph_positions = $filtered_paragraph_positions;
2738
  }
2739
 
2740
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_NO_COUNTING_INSIDE;
2741
- if (count ($paragraph_positions) == 0) return $content;
 
2742
  }
2743
 
 
2744
  $paragraph_min_words = intval ($this->get_minimum_paragraph_words());
2745
  $paragraph_max_words = intval ($this->get_maximum_paragraph_words());
2746
 
2747
  if ($paragraph_min_words != 0 || $paragraph_max_words != 0) {
2748
- $filtered_paragraph_positions = array ();
 
 
 
 
 
 
2749
  foreach ($paragraph_positions as $index => $paragraph_position) {
2750
 
 
 
2751
  if ($multibyte) {
2752
- $paragraph_code = $index == count ($paragraph_positions) - 1 ? mb_substr ($content, $paragraph_position) : mb_substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
 
2753
  } else {
2754
- $paragraph_code = $index == count ($paragraph_positions) - 1 ? substr ($content, $paragraph_position) : substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
 
2755
  }
2756
 
2757
- if ($this->check_number_of_words_in_paragraph ($paragraph_code, $paragraph_min_words, $paragraph_max_words)) $filtered_paragraph_positions [] = $paragraph_position;
 
2758
  }
2759
- $paragraph_positions = $filtered_paragraph_positions;
2760
  }
2761
 
2762
  // Nothing to do
2763
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS;
2764
- if (count ($paragraph_positions) == 0) return $content;
 
 
2765
 
2766
  $paragraph_texts = explode (",", html_entity_decode ($this->get_paragraph_text()));
2767
  if ($this->get_paragraph_text() != "" && count ($paragraph_texts) != 0) {
2768
 
2769
- $filtered_paragraph_positions = array ();
 
 
 
 
 
2770
  $paragraph_text_type = $this->get_paragraph_text_type ();
2771
 
2772
  foreach ($paragraph_positions as $index => $paragraph_position) {
2773
 
 
 
2774
  if ($multibyte) {
2775
- $paragraph_code = $index == count ($paragraph_positions) - 1 ? mb_substr ($content, $paragraph_position) : mb_substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
 
2776
  } else {
2777
- $paragraph_code = $index == count ($paragraph_positions) - 1 ? substr ($content, $paragraph_position) : substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
 
2778
  }
2779
 
2780
  if ($paragraph_text_type == AD_CONTAIN) {
@@ -2794,7 +2913,8 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2794
  }
2795
  }
2796
  }
2797
- if ($found) $filtered_paragraph_positions [] = $paragraph_position;
 
2798
  } elseif ($paragraph_text_type == AD_DO_NOT_CONTAIN) {
2799
  $found = false;
2800
  foreach ($paragraph_texts as $paragraph_text) {
@@ -2812,47 +2932,67 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2812
  }
2813
  }
2814
  }
2815
- if (!$found) $filtered_paragraph_positions [] = $paragraph_position;
 
2816
  }
2817
  }
2818
 
2819
- $paragraph_positions = $filtered_paragraph_positions;
2820
  }
2821
 
2822
  // Nothing to do
2823
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_TEXT;
2824
- if (count ($paragraph_positions) == 0) return $content;
 
2825
 
2826
 
2827
- if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
2828
- $paragraph_positions = array_reverse ($paragraph_positions);
 
2829
  }
 
2830
 
2831
 
2832
- // $position is index in $paragraph_positions
2833
- $position_text = trim ($this->get_paragraph_number());
2834
- $position = $position_text;
2835
- if ($position > 0 && $position < 1) {
2836
- $position = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
2837
  }
2838
- elseif ($position <= 0) {
2839
- $position = mt_rand (0, count ($paragraph_positions) - 1);
2840
- } else $position --;
2841
 
2842
 
 
 
2843
  // $positions contains indexes in $paragraph_positions
2844
- $positions = array ($position);
 
2845
  if (!$position_preview) {
2846
- if (strpos ($position_text, ',') !== false) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2847
  $positions = explode (',', str_replace (' ', '', $position_text));
2848
  foreach ($positions as $index => $position) {
2849
  if ($position > 0 && $position < 1) {
2850
  $positions [$index] = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
2851
  }
2852
- elseif ($position <= 0) {
 
 
 
2853
  $positions [$index] = mt_rand (0, count ($paragraph_positions) - 1);
2854
  }
2855
- else $positions [$index] = $position - 1;
2856
  }
2857
  }
2858
  elseif ($position_text == '') {
@@ -3127,7 +3267,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3127
 
3128
  foreach ($paragraph_positions as $counter => $paragraph_position) {
3129
  if ($position_preview) $inserted_code = "[[AI_BP".($counter + 1)."]]";
3130
- // elseif (!empty ($positions) && in_array ($counter + 1, $positions) && $this->check_block_counter ()) {
3131
  elseif (!empty ($positions) && in_array ($counter, $positions) && $this->check_block_counter ()) {
3132
 
3133
  $inserted = false;
@@ -3139,16 +3278,15 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3139
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3140
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3141
  $inserted_code = $this->get_code_for_serverside_insertion ();
 
3142
  $ai_last_check = AI_CHECK_INSERTED;
3143
  $inserted = true;
3144
  }
3145
  }
3146
- // $ai_last_check = AI_CHECK_INSERTED;
3147
  if ($debug_processing) ai_log (ai_log_block_status ($this->number, $ai_last_check));
3148
 
3149
  if (!$inserted) continue;
3150
  }
3151
- // else continue;
3152
  else {
3153
  if ($debug_processing && isset ($failed_clearance_positions [$counter])) ai_log (ai_log_block_status ($this->number, $failed_clearance_positions [$counter]));
3154
  continue;
@@ -3191,6 +3329,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3191
  } else {
3192
  $content = substr_replace ($content, $this->get_code_for_serverside_insertion (), $content_position, 0);
3193
  }
 
3194
 
3195
  $ai_last_check = AI_CHECK_INSERTED;
3196
  }
@@ -3203,11 +3342,14 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3203
  public function after_paragraph ($content, $position_preview = false) {
3204
  global $ai_wp_data, $ai_last_check, $special_element_tags;
3205
 
3206
- $no_closing_tag = array ('img', 'hr', 'br');
3207
 
3208
  $multibyte = get_paragraph_counting_functions() == AI_MULTIBYTE_PARAGRAPH_COUNTING_FUNCTIONS;
3209
 
3210
  $paragraph_positions = array ();
 
 
 
3211
 
3212
  if ($multibyte) {
3213
  $last_content_position = mb_strlen ($content) - 1;
@@ -3223,52 +3365,79 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3223
  $ai_last_check = AI_CHECK_PARAGRAPH_TAGS;
3224
  if (count ($paragraph_end_strings) == 0) return $content;
3225
 
3226
- foreach ($paragraph_end_strings as $paragraph_end_string) {
3227
 
3228
- $last_position = - 1;
3229
 
3230
- $paragraph_end_string = trim ($paragraph_end_string);
3231
- if ($paragraph_end_string == '') continue;
3232
 
3233
- if (in_array ($paragraph_end_string, $no_closing_tag)) {
3234
- if (preg_match_all ("/<$paragraph_end_string(.*?)>/", $content, $images)) {
3235
- foreach ($images [0] as $paragraph_end) {
3236
- if ($multibyte) {
3237
- $last_position = mb_stripos ($content, $paragraph_end, $last_position + 1) + mb_strlen ($paragraph_end) - 1;
3238
- $paragraph_positions [] = $last_position;
3239
- } else {
3240
- $last_position = stripos ($content, $paragraph_end, $last_position + 1) + strlen ($paragraph_end) - 1;
3241
- $paragraph_positions [] = $last_position;
3242
- }
3243
- }
3244
- }
3245
- continue;
3246
- }
3247
- elseif ($paragraph_end_string == "#") {
3248
- $paragraph_end = "\r\n\r\n";
3249
- if (!in_array ($last_content_position, $paragraph_positions)) $paragraph_positions [] = $last_content_position;
3250
- } else $paragraph_end = '</' . $paragraph_end_string . '>';
3251
-
3252
- if ($multibyte) {
3253
- while (mb_stripos ($content, $paragraph_end, $last_position + 1) !== false) {
3254
- $last_position = mb_stripos ($content, $paragraph_end, $last_position + 1) + mb_strlen ($paragraph_end) - 1;
3255
- if ($paragraph_end_string == "#") $paragraph_positions [] = $last_position - 4; else
3256
- $paragraph_positions [] = $last_position;
3257
- }
3258
- } else {
3259
- while (stripos ($content, $paragraph_end, $last_position + 1) !== false) {
3260
- $last_position = stripos ($content, $paragraph_end, $last_position + 1) + strlen ($paragraph_end) - 1;
3261
- if ($paragraph_end_string == "#") $paragraph_positions [] = $last_position - 4; else
3262
- $paragraph_positions [] = $last_position;
3263
- }
3264
- }
3265
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3266
 
3267
  // Nothing to do
3268
  $ai_last_check = AI_CHECK_PARAGRAPHS_WITH_TAGS;
3269
- if (count ($paragraph_positions) == 0) return $content;
 
 
3270
 
3271
  sort ($paragraph_positions);
 
 
 
 
 
 
 
3272
 
3273
  if (!$this->get_count_inside_blockquote ()) {
3274
 
@@ -3317,7 +3486,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3317
 
3318
  if (count ($special_element_offsets) != 0) {
3319
 
3320
- $filtered_paragraph_positions = array ();
3321
  $inside_special_element = array ();
3322
 
3323
  foreach ($special_element_offsets as $special_element_offset) {
@@ -3326,52 +3495,77 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3326
  }
3327
  }
3328
 
3329
- foreach ($paragraph_positions as $paragraph_position) {
3330
- if (!in_array ($paragraph_position, $inside_special_element)) $filtered_paragraph_positions []= $paragraph_position;
 
3331
  }
3332
 
3333
- $paragraph_positions = $filtered_paragraph_positions;
3334
  }
3335
 
3336
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_NO_COUNTING_INSIDE;
3337
- if (count ($paragraph_positions) == 0) return $content;
 
3338
  }
3339
 
 
3340
  $paragraph_min_words = intval ($this->get_minimum_paragraph_words());
3341
  $paragraph_max_words = intval ($this->get_maximum_paragraph_words());
3342
 
3343
  if ($paragraph_min_words != 0 || $paragraph_max_words != 0) {
3344
- $filtered_paragraph_positions = array ();
 
 
 
 
 
 
3345
  foreach ($paragraph_positions as $index => $paragraph_position) {
3346
 
 
 
3347
  if ($multibyte) {
3348
- $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]);
 
3349
  } else {
3350
- $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
 
3351
  }
3352
 
3353
- if ($this->check_number_of_words_in_paragraph ($paragraph_code, $paragraph_min_words, $paragraph_max_words)) $filtered_paragraph_positions [] = $paragraph_position;
 
3354
  }
3355
- $paragraph_positions = $filtered_paragraph_positions;
3356
  }
3357
 
 
3358
  // Nothing to do
3359
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS;
3360
- if (count ($paragraph_positions) == 0) return $content;
 
3361
 
3362
 
3363
  $paragraph_texts = explode (",", html_entity_decode ($this->get_paragraph_text()));
3364
  if ($this->get_paragraph_text() != "" && count ($paragraph_texts) != 0) {
3365
 
3366
- $filtered_paragraph_positions = array ();
 
 
 
 
 
3367
  $paragraph_text_type = $this->get_paragraph_text_type ();
3368
 
3369
  foreach ($paragraph_positions as $index => $paragraph_position) {
3370
 
 
 
3371
  if ($multibyte) {
3372
- $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]);
 
3373
  } else {
3374
- $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
 
3375
  }
3376
 
3377
  if ($paragraph_text_type == AD_CONTAIN) {
@@ -3392,7 +3586,8 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3392
  }
3393
 
3394
  }
3395
- if ($found) $filtered_paragraph_positions [] = $paragraph_position;
 
3396
  } elseif ($paragraph_text_type == AD_DO_NOT_CONTAIN) {
3397
  $found = false;
3398
  foreach ($paragraph_texts as $paragraph_text) {
@@ -3411,16 +3606,26 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3411
  }
3412
 
3413
  }
3414
- if (!$found) $filtered_paragraph_positions [] = $paragraph_position;
 
3415
  }
3416
  }
3417
 
3418
- $paragraph_positions = $filtered_paragraph_positions;
3419
  }
3420
 
 
3421
  // Nothing to do
3422
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_TEXT;
3423
- if (count ($paragraph_positions) == 0) return $content;
 
 
 
 
 
 
 
 
3424
 
3425
 
3426
  if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
@@ -3428,27 +3633,36 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3428
  }
3429
 
3430
 
3431
- // $position is index in $paragraph_positions
3432
  $position_text = trim ($this->get_paragraph_number());
3433
- $position = $position_text;
3434
- if ($position > 0 && $position < 1) {
3435
- $position = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
3436
- }
3437
- elseif ($position <= 0) {
3438
- $position = mt_rand (0, count ($paragraph_positions) - 1);
3439
- } else $position --;
3440
-
3441
 
3442
  // $positions contains indexes in $paragraph_positions
3443
- $positions = array ($position);
 
3444
  if (!$position_preview) {
3445
- if (strpos ($position_text, ',') !== false) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3446
  $positions = explode (',', str_replace (' ', '', $position_text));
3447
  foreach ($positions as $index => $position) {
3448
  if ($position > 0 && $position < 1) {
3449
  $positions [$index] = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
3450
  }
3451
- elseif ($position <= 0) {
 
 
 
3452
  $positions [$index] = mt_rand (0, count ($paragraph_positions) - 1);
3453
  }
3454
  else $positions [$index] = $position - 1;
@@ -3725,7 +3939,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3725
 
3726
  foreach ($paragraph_positions as $counter => $paragraph_position) {
3727
  if ($position_preview) $inserted_code = "[[AI_AP".($counter + 1)."]]";
3728
- // elseif (!empty ($positions) && in_array ($counter + 1, $positions) && $this->check_block_counter ()) {
3729
  elseif (!empty ($positions) && in_array ($counter, $positions) && $this->check_block_counter ()) {
3730
 
3731
  $inserted = false;
@@ -3737,6 +3950,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3737
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3738
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3739
  $inserted_code = $this->get_code_for_serverside_insertion ();
 
3740
  $ai_last_check = AI_CHECK_INSERTED;
3741
  $inserted = true;
3742
  }
@@ -3746,7 +3960,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3746
 
3747
  if (!$inserted) continue;
3748
  }
3749
- // else continue;
3750
  else {
3751
  if ($debug_processing && isset ($failed_clearance_positions [$counter])) ai_log (ai_log_block_status ($this->number, $failed_clearance_positions [$counter]));
3752
  continue;
@@ -3794,6 +4007,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3794
  $content = $content . $this->get_code_for_serverside_insertion (); else
3795
  $content = substr_replace ($content, $this->get_code_for_serverside_insertion (), $content_position + 1, 0);
3796
  }
 
3797
 
3798
  $ai_last_check = AI_CHECK_INSERTED;
3799
  }
@@ -4144,41 +4358,46 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
4144
  return !$return;
4145
  }
4146
 
4147
- function check_url_parameters () {
4148
- global $ai_wp_data;
4149
 
4150
- $parameter_list = trim ($this->get_url_parameter_list());
4151
- $parameter_list_type = $this->get_url_parameter_list_type();
4152
 
4153
- if ($parameter_list_type == AD_BLACK_LIST) $return = false; else $return = true;
 
4154
 
4155
- $parameters = array_merge ($_COOKIE, $_GET);
4156
 
4157
- if ($parameter_list == AD_EMPTY_DATA || count ($parameters) == 0) {
4158
- return !$return;
4159
- }
4160
 
4161
- $parameters_listed = explode (",", $parameter_list);
4162
- foreach ($parameters_listed as $index => $parameter_listed) {
4163
- if (trim ($parameter_listed) == "") unset ($parameters_listed [$index]); else
4164
- $parameters_listed [$index] = trim ($parameter_listed);
4165
- }
4166
 
4167
- // print_r ($parameter_listed);
4168
- // echo "<br />\n";
4169
- // echo " parameters: <br />\n";
4170
- // print_r ($_GET);
4171
- // echo ' listed parameters: ' . $parameter_list, "\n";
4172
- // echo "<br />\n";
4173
 
4174
- foreach ($parameters_listed as $parameter) {
4175
- if (strpos ($parameter, "=") !== false) {
4176
- $parameter_value = explode ("=", $parameter);
4177
- if (array_key_exists ($parameter_value [0], $parameters) && $parameters [$parameter_value [0]] == $parameter_value [1]) return $return;
4178
- } else if (array_key_exists ($parameter, $parameters)) return $return;
4179
- }
4180
 
4181
- return !$return;
 
 
 
 
 
 
 
 
 
4182
  }
4183
 
4184
  function check_scheduling () {
@@ -4228,27 +4447,34 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
4228
 
4229
  function check_referer () {
4230
 
4231
- $domain_list_type = $this->get_ad_domain_list_type ();
 
4232
 
4233
- if (isset ($_SERVER['HTTP_REFERER'])) {
4234
- $referer_host = strtolower (parse_url ($_SERVER['HTTP_REFERER'], PHP_URL_HOST));
4235
- } else $referer_host = '';
4236
 
4237
- if ($domain_list_type == AD_BLACK_LIST) $return = false; else $return = true;
4238
 
4239
- $domains = strtolower (trim ($this->get_ad_domain_list ()));
4240
- if ($domains == AD_EMPTY_DATA) return !$return;
4241
- $domains = explode (",", $domains);
4242
 
4243
- foreach ($domains as $domain) {
4244
- $domain = trim ($domain);
4245
- if ($domain == "") continue;
4246
 
4247
- if ($domain == "#") {
4248
- if ($referer_host == "") return $return;
4249
- } elseif ($domain == $referer_host) return $return;
4250
- }
4251
- return !$return;
 
 
 
 
 
 
4252
  }
4253
 
4254
  function check_number_of_words (&$content = null, $number_of_words = 0) {
@@ -4352,14 +4578,18 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
4352
  $ai_last_check = AI_CHECK_URL;
4353
  if (!$this->check_url ()) return false;
4354
 
 
 
4355
  $ai_last_check = AI_CHECK_URL_PARAMETER;
4356
- if (!$this->check_url_parameters ()) return false;
4357
 
4358
- $ai_last_check = AI_CHECK_REFERER;
4359
- if (!$this->check_referer ()) return false;
 
 
4360
 
4361
  if (function_exists ('ai_check_lists')) {
4362
- if (!ai_check_lists ($this)) return false;
4363
  }
4364
 
4365
  $ai_last_check = AI_CHECK_SCHEDULING;
5
  abstract class ai_BaseCodeBlock {
6
  var $wp_options;
7
  var $fallback;
8
+ var $client_side_list_detection;
9
  var $w3tc_code;
10
  var $w3tc_code2;
11
  var $before_w3tc_code2;
24
 
25
  $this->wp_options = array ();
26
  $this->fallback = 0;
27
+ $this->client_side_list_detection = false;
28
  $this->w3tc_code = '';
29
  $this->w3tc_code2 = '';
30
  $this->before_w3tc_code2 = '';
1692
  $version_names = array ();
1693
  $version_shares = array ();
1694
  $version_times = array ();
1695
+ $version_insert = array ();
1696
 
1697
  foreach ($ai_wp_data [AI_SHORTCODES]['rotate'] as $index => $option) {
1698
  $version_names []= isset ($option ['name']) && trim ($option ['name']) != '' ? $option ['name'] : chr (ord ('A') + $index);
1704
  $option_time = isset ($option ['time']) && is_numeric ($option ['time']);
1705
  if ($option_time) $times = true;
1706
  $version_times []= $option_time ? intval ($option ['time']) : - 1;
1707
+
1708
+ $version_insert []= isset ($option ['insert']);
1709
  }
1710
 
1711
  if ($shares) {
1738
  }
1739
 
1740
  if ($times) {
1741
+ if ($dynamic_blocks != AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW && $dynamic_blocks != AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) $dynamic_blocks = AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW;
1742
  $ai_wp_data [AI_CLIENT_SIDE_ROTATION] = true;
1743
  }
1744
 
1794
  }
1795
 
1796
  $version_name_data = " data-name='".base64_encode ($version_names [$index])."'";
1797
+ $version_time_data = $version_times [$index] >= 0 ? " data-time='".base64_encode ($version_times [$index])."'" : '';
1798
 
1799
  switch ($temp_dynamic_blocks) {
1800
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
 
 
1801
  switch ($index) {
1802
  case 0:
1803
  if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
1815
  break;
1816
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1817
  $version_code_data = " data-code='".base64_encode ($ad)."'";
1818
+ $processed_code .= "<div class='ai-rotate-option'".$version_name_data.$version_time_data.$version_code_data.">\n</div>\n";
1819
  break;
1820
  }
1821
 
1861
  break;
1862
  case AI_DYNAMIC_BLOCKS_SERVER_SIDE_W3TC:
1863
  $this->w3tc_code .= '$ai_amp_separator = \'' . AD_AMP_SEPARATOR . '\'; $ai_amp_page = ' . ($ai_wp_data [AI_WP_AMP_PAGE] ? 'true' : 'false') . '; $ai_amp_enabled = ' . $this->get_enable_amp () . ';';
1864
+
1865
+ // Fix to prevent converting && into &amp;&amp; on AMP pages
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.' -->';
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 ()));
1880
+ $url_parameters = base64_encode ($url_parameters_raw);
1881
+ $url_parameter_list_type = $this->get_url_parameter_list_type ();
1882
+
1883
+ $referers_raw = trim (str_replace (' ', '', strtolower ($this->get_ad_domain_list ())));
1884
+ $referers = base64_encode ($referers_raw);
1885
+ $referer_list_type = $this->get_ad_domain_list_type ();
1886
+
1887
+ if ($url_parameters != '' || $url_parameter_list_type == AD_WHITE_LIST || $referers != '' || $referer_list_type == AD_WHITE_LIST) {
1888
+ switch ($dynamic_blocks) {
1889
+ case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1890
+ case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1891
+ if ($url_parameter_list_type == AD_BLACK_LIST) $url_parameter_list_type = 'B'; else $url_parameter_list_type = 'W';
1892
+ if ($referer_list_type == AD_BLACK_LIST) $referer_list_type = 'B'; else $referer_list_type = 'W';
1893
+
1894
+ if ($url_parameters != '' || $url_parameter_list_type == 'W') $url_parameter_attributes = "parameter-list='$url_parameters' parameter-list-type='$url_parameter_list_type'"; else $url_parameter_attributes = '';
1895
+ if ($referers != '' || $referer_list_type == 'W') $referer_attributes = "referer-list='$referers' referer-list-type='$referer_list_type'"; else $referer_attributes = '';
1896
+
1897
+ $this->client_side_list_detection = true;
1898
+
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
+
1912
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
1913
+ if ($url_parameters != '' || $url_parameter_list_type == 'W') $url_parameter_attributes_dbg = "parameters='$url_parameters_raw' type='$url_parameter_list_type'"; else $url_parameter_attributes_dbg = '';
1914
+ if ($referers != '' || $referer_list_type == 'W') $referer_attributes_dbg = "referers='$referers_raw' type='$referer_list_type'"; else $referer_attributes_dbg = '';
1915
+
1916
+ $debug_ip = new ai_block_labels ('ai-debug-lists');
1917
+ $processed_code = $debug_ip->bar ($url_parameter_attributes_dbg . ' ' . $referer_attributes_dbg, '', '<kbd class="ai-debug-name ai-list-status"></kbd>', '<kbd class="ai-debug-name ai-list-info"></kbd>') . $processed_code;
1918
+ }
1919
+
1920
+ break;
1921
+ case AI_DYNAMIC_BLOCKS_SERVER_SIDE_W3TC:
1922
+ if ($this->w3tc_code == '') $this->w3tc_code = '$ai_code = base64_decode (\''.base64_encode ($processed_code).'\'); $ai_index = 0; $ai_enabled = true;';
1923
+
1924
+ if ($referers != '') {
1925
+ $this->w3tc_code .= ' if ($ai_enabled) $ai_enabled = check_check_referer_list (base64_decode (\''.$referers.'\'), '.($referer_list_type == AD_WHITE_LIST ? 'true':'false').');';
1926
+ } elseif ($referer_list_type == AD_WHITE_LIST) $this->w3tc_code .= ' $ai_enabled = false;';
1927
+
1928
+ if ($url_parameters != '') {
1929
+ $this->w3tc_code .= ' if ($ai_enabled) $ai_enabled = check_url_parameter_list (base64_decode (\''.$url_parameters.'\'), '.($url_parameter_list_type == AD_WHITE_LIST ? 'true':'false').', false, false, true);';
1930
+ } elseif ($url_parameter_list_type == AD_WHITE_LIST) $this->w3tc_code .= ' $ai_enabled = false;';
1931
+
1932
+ $processed_code = '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1933
+ $processed_code .= $this->w3tc_code.' if ($ai_enabled) echo $ai_code;';
1934
+ $processed_code .= '<!-- /mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1935
+ break;
1936
+ }
1937
+ }
1938
+
1939
  $countries = trim (str_replace (' ', '', strtoupper ($this->get_ad_country_list (true))));
1940
  $country_list_type = $this->get_ad_country_list_type ();
1941
 
1949
  if ($country_list_type == AD_BLACK_LIST) $country_list_type = 'B'; else $country_list_type = 'W';
1950
  if ($ip_address_list_type == AD_BLACK_LIST) $ip_address_list_type = 'B'; else $ip_address_list_type = 'W';
1951
 
1952
+ if ($countries != '' || $country_list_type == 'W') $country_attributes = "countries='$countries' country-list='$country_list_type'"; else $country_attributes = '';
1953
  if ($ip_addresses != '' || $ip_address_list_type == 'W') $ip_address_attributes = "ip-addresses='$ip_addresses' ip-address-list='$ip_address_list_type'"; else $ip_address_attributes = '';
1954
 
1955
+ $this->client_side_list_detection = true;
1956
 
1957
  switch ($dynamic_blocks) {
1958
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1968
  }
1969
 
1970
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
1971
+ $debug_ip = new ai_block_labels ('ai-debug-lists');
1972
  $processed_code = $debug_ip->bar ($country_attributes . ' ' . $ip_address_attributes, '', '<kbd class="ai-debug-name ai-ip-status"></kbd>', '<kbd class="ai-debug-name ai-ip-country"></kbd>') . $processed_code;
1973
  }
1974
 
2116
  } else $classes = array ();
2117
 
2118
  if ($hidden_widgets) return $hidden_viewports; else {
2119
+ if ($this->client_side_list_detection && !$ai_wp_data [AI_WP_AMP_PAGE]) {
2120
  $additional_block_style = 'visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999; ';
2121
  // if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
2122
+ // $classes [] = 'ai-list-block';
2123
  // }
2124
  // Needed to locate wrapping div
2125
+ $classes [] = 'ai-list-block';
2126
  } else {
2127
  $additional_block_style = '';
2128
  }
2231
  }
2232
  }
2233
 
2234
+ // echo "##1#", $this->w3tc_code, "###", $this->w3tc_code2, "##1#";
2235
+
2236
  return $code;
2237
  }
2238
 
2336
  $serverside_insertion_code = str_replace ('[#AI_CODE#]', $block_code, $serverside_insertion_code);
2337
  }
2338
 
2339
+ // echo "##2#", $this->w3tc_code, "###", $this->w3tc_code2, "##2#";
2340
+
2341
  return $serverside_insertion_code;
2342
  }
2343
 
2699
  $multibyte = get_paragraph_counting_functions() == AI_MULTIBYTE_PARAGRAPH_COUNTING_FUNCTIONS;
2700
 
2701
  $paragraph_positions = array ();
2702
+ $active_paragraph_positions = array ();
2703
+
2704
+ $dummy = array ();
2705
 
2706
  $paragraph_tags = trim ($this->get_paragraph_tags());
2707
  if ($paragraph_tags == '') return $content;
2711
  $ai_last_check = AI_CHECK_PARAGRAPH_TAGS;
2712
  if (count ($paragraph_start_strings) == 0) return $content;
2713
 
2714
+ get_paragraph_start_positions ($content, $multibyte, $dummy, $paragraph_start_strings, $paragraph_positions, $active_paragraph_positions);
 
2715
 
2716
+ // foreach ($paragraph_start_strings as $paragraph_start_string) {
2717
+ // if (trim ($paragraph_start_string) == '') continue;
2718
 
2719
+ // $last_position = - 1;
 
 
 
 
2720
 
2721
+ // $paragraph_start_string = trim ($paragraph_start_string);
2722
+ // if ($paragraph_start_string == "#") {
2723
+ // $paragraph_start = "\r\n\r\n";
2724
+ // if (!in_array (0, $paragraph_positions)) {
2725
+ // $paragraph_positions [] = 0;
2726
+ // $active_paragraph_positions [0] = 1;
2727
+ // }
2728
+ // } else $paragraph_start = '<' . $paragraph_start_string;
2729
+
2730
+ // if ($multibyte) {
2731
+ // $paragraph_start_len = mb_strlen ($paragraph_start);
2732
+ // while (mb_stripos ($content, $paragraph_start, $last_position + 1) !== false) {
2733
+ // $last_position = mb_stripos ($content, $paragraph_start, $last_position + 1);
2734
+ // if ($paragraph_start_string == "#") {
2735
+ // $paragraph_positions [] = $last_position + 4;
2736
+ // $active_paragraph_positions [$last_position + 4] = 1;
2737
+ // } elseif (mb_substr ($content, $last_position + $paragraph_start_len, 1) == ">" || mb_substr ($content, $last_position + $paragraph_start_len, 1) == " ") {
2738
+ // $paragraph_positions [] = $last_position;
2739
+ // $active_paragraph_positions [$last_position] = 1;
2740
+ // }
2741
+ // }
2742
+ // } else {
2743
+ // $paragraph_start_len = strlen ($paragraph_start);
2744
+ // while (stripos ($content, $paragraph_start, $last_position + 1) !== false) {
2745
+ // $last_position = stripos ($content, $paragraph_start, $last_position + 1);
2746
+ // if ($paragraph_start_string == "#") {
2747
+ // $paragraph_positions [] = $last_position + 4;
2748
+ // $active_paragraph_positions [$last_position + 4] = 1;
2749
+ // } elseif ($content [$last_position + $paragraph_start_len] == ">" || $content [$last_position + $paragraph_start_len] == " ") {
2750
+ // $paragraph_positions [] = $last_position;
2751
+ // $active_paragraph_positions [$last_position] = 1;
2752
+ // }
2753
+ // }
2754
+ // }
2755
+ // }
2756
 
2757
  // Nothing to do
2758
  $ai_last_check = AI_CHECK_PARAGRAPHS_WITH_TAGS;
2759
+ // if (count ($paragraph_positions) == 0) return $content;
2760
+ if (array_sum ($active_paragraph_positions) == 0) return $content;
2761
 
2762
  sort ($paragraph_positions);
2763
+ ksort ($active_paragraph_positions);
2764
+ $new_active_paragraph_positions = array ();
2765
+ foreach ($active_paragraph_positions as $active_paragraph_position) {
2766
+ $new_active_paragraph_positions [] = $active_paragraph_position;
2767
+ }
2768
+ $active_paragraph_positions = $new_active_paragraph_positions;
2769
+
2770
 
2771
  if (!$this->get_count_inside_blockquote ()) {
2772
 
2815
 
2816
  if (count ($special_element_offsets) != 0) {
2817
 
2818
+ // $filtered_paragraph_positions = array ();
2819
  $inside_special_element = array ();
2820
 
2821
  foreach ($special_element_offsets as $special_element_offset) {
2824
  }
2825
  }
2826
 
2827
+ foreach ($paragraph_positions as $index => $paragraph_position) {
2828
+ // if (!in_array ($paragraph_position, $inside_special_element)) $filtered_paragraph_positions []= $paragraph_position;
2829
+ if (in_array ($paragraph_position, $inside_special_element)) $active_paragraph_positions [$index] = 0;
2830
  }
2831
 
2832
+ // $paragraph_positions = $filtered_paragraph_positions;
2833
  }
2834
 
2835
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_NO_COUNTING_INSIDE;
2836
+ // if (count ($paragraph_positions) == 0) return $content;
2837
+ if (array_sum ($active_paragraph_positions) == 0) return $content;
2838
  }
2839
 
2840
+
2841
  $paragraph_min_words = intval ($this->get_minimum_paragraph_words());
2842
  $paragraph_max_words = intval ($this->get_maximum_paragraph_words());
2843
 
2844
  if ($paragraph_min_words != 0 || $paragraph_max_words != 0) {
2845
+
2846
+ if (!isset ($paragraph_end_positions)) {
2847
+ $paragraph_end_positions = array ();
2848
+ get_paragraph_end_positions ($content, $multibyte, $paragraph_positions, $paragraph_start_strings, $paragraph_end_positions, $dummy);
2849
+ }
2850
+
2851
+ // $filtered_paragraph_positions = array ();
2852
  foreach ($paragraph_positions as $index => $paragraph_position) {
2853
 
2854
+ if ($active_paragraph_positions [$index] == 0) continue;
2855
+
2856
  if ($multibyte) {
2857
+ // $paragraph_code = $index == count ($paragraph_positions) - 1 ? mb_substr ($content, $paragraph_position) : mb_substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
2858
+ $paragraph_code = mb_substr ($content, $paragraph_position, $paragraph_end_positions [$index] - $paragraph_position + 1);
2859
  } else {
2860
+ // $paragraph_code = $index == count ($paragraph_positions) - 1 ? substr ($content, $paragraph_position) : substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
2861
+ $paragraph_code = substr ($content, $paragraph_position, $paragraph_end_positions [$index] - $paragraph_position + 1);
2862
  }
2863
 
2864
+ // if ($this->check_number_of_words_in_paragraph ($paragraph_code, $paragraph_min_words, $paragraph_max_words)) $filtered_paragraph_positions [] = $paragraph_position;
2865
+ if (!$this->check_number_of_words_in_paragraph ($paragraph_code, $paragraph_min_words, $paragraph_max_words)) $active_paragraph_positions [$index] = 0;
2866
  }
2867
+ // $paragraph_positions = $filtered_paragraph_positions;
2868
  }
2869
 
2870
  // Nothing to do
2871
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS;
2872
+ // if (count ($paragraph_positions) == 0) return $content;
2873
+ if (array_sum ($active_paragraph_positions) == 0) return $content;
2874
+
2875
 
2876
  $paragraph_texts = explode (",", html_entity_decode ($this->get_paragraph_text()));
2877
  if ($this->get_paragraph_text() != "" && count ($paragraph_texts) != 0) {
2878
 
2879
+ if (!isset ($paragraph_end_positions)) {
2880
+ $paragraph_end_positions = array ();
2881
+ get_paragraph_end_positions ($content, $multibyte, $paragraph_positions, $paragraph_start_strings, $paragraph_end_positions, $dummy);
2882
+ }
2883
+
2884
+ // $filtered_paragraph_positions = array ();
2885
  $paragraph_text_type = $this->get_paragraph_text_type ();
2886
 
2887
  foreach ($paragraph_positions as $index => $paragraph_position) {
2888
 
2889
+ if ($active_paragraph_positions [$index] == 0) continue;
2890
+
2891
  if ($multibyte) {
2892
+ // $paragraph_code = $index == count ($paragraph_positions) - 1 ? mb_substr ($content, $paragraph_position) : mb_substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
2893
+ $paragraph_code = mb_substr ($content, $paragraph_position, $paragraph_end_positions [$index] - $paragraph_position + 1);
2894
  } else {
2895
+ // $paragraph_code = $index == count ($paragraph_positions) - 1 ? substr ($content, $paragraph_position) : substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
2896
+ $paragraph_code = substr ($content, $paragraph_position, $paragraph_end_positions [$index] - $paragraph_position + 1);
2897
  }
2898
 
2899
  if ($paragraph_text_type == AD_CONTAIN) {
2913
  }
2914
  }
2915
  }
2916
+ // if ($found) $filtered_paragraph_positions [] = $paragraph_position;
2917
+ if (!$found) $active_paragraph_positions [$index] = 0;
2918
  } elseif ($paragraph_text_type == AD_DO_NOT_CONTAIN) {
2919
  $found = false;
2920
  foreach ($paragraph_texts as $paragraph_text) {
2932
  }
2933
  }
2934
  }
2935
+ // if (!$found) $filtered_paragraph_positions [] = $paragraph_position;
2936
+ if ($found) $active_paragraph_positions [$index] = 0;
2937
  }
2938
  }
2939
 
2940
+ // $paragraph_positions = $filtered_paragraph_positions;
2941
  }
2942
 
2943
  // Nothing to do
2944
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_TEXT;
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
+
2966
  if (!$position_preview) {
2967
+ $position = $position_text;
2968
+
2969
+ if (is_numeric ($position)) {
2970
+ if ($position > 0 && $position < 1) {
2971
+ $position = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
2972
+ }
2973
+ elseif ($position < 0) {
2974
+ $position = count ($paragraph_positions) + $position;
2975
+ }
2976
+ elseif ($position == 0) {
2977
+ $position = mt_rand (0, count ($paragraph_positions) - 1);
2978
+ }
2979
+ else $position --;
2980
+
2981
+ $positions = array ($position);
2982
+ }
2983
+ elseif (strpos ($position_text, ',') !== false) {
2984
  $positions = explode (',', str_replace (' ', '', $position_text));
2985
  foreach ($positions as $index => $position) {
2986
  if ($position > 0 && $position < 1) {
2987
  $positions [$index] = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
2988
  }
2989
+ elseif ($position < 0) {
2990
+ $positions [$index] = count ($paragraph_positions) + $position;
2991
+ }
2992
+ elseif ($position == 0) {
2993
  $positions [$index] = mt_rand (0, count ($paragraph_positions) - 1);
2994
  }
2995
+ else $positions [$index] = $position - 1;
2996
  }
2997
  }
2998
  elseif ($position_text == '') {
3267
 
3268
  foreach ($paragraph_positions as $counter => $paragraph_position) {
3269
  if ($position_preview) $inserted_code = "[[AI_BP".($counter + 1)."]]";
 
3270
  elseif (!empty ($positions) && in_array ($counter, $positions) && $this->check_block_counter ()) {
3271
 
3272
  $inserted = false;
3278
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3279
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3280
  $inserted_code = $this->get_code_for_serverside_insertion ();
3281
+ $this->clear_code_cache ();
3282
  $ai_last_check = AI_CHECK_INSERTED;
3283
  $inserted = true;
3284
  }
3285
  }
 
3286
  if ($debug_processing) ai_log (ai_log_block_status ($this->number, $ai_last_check));
3287
 
3288
  if (!$inserted) continue;
3289
  }
 
3290
  else {
3291
  if ($debug_processing && isset ($failed_clearance_positions [$counter])) ai_log (ai_log_block_status ($this->number, $failed_clearance_positions [$counter]));
3292
  continue;
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
  }
3342
  public function after_paragraph ($content, $position_preview = false) {
3343
  global $ai_wp_data, $ai_last_check, $special_element_tags;
3344
 
3345
+ // $no_closing_tag = array ('img', 'hr', 'br');
3346
 
3347
  $multibyte = get_paragraph_counting_functions() == AI_MULTIBYTE_PARAGRAPH_COUNTING_FUNCTIONS;
3348
 
3349
  $paragraph_positions = array ();
3350
+ $active_paragraph_positions = array ();
3351
+
3352
+ $dummy = array ();
3353
 
3354
  if ($multibyte) {
3355
  $last_content_position = mb_strlen ($content) - 1;
3365
  $ai_last_check = AI_CHECK_PARAGRAPH_TAGS;
3366
  if (count ($paragraph_end_strings) == 0) return $content;
3367
 
3368
+ get_paragraph_end_positions ($content, $multibyte, $dummy, $paragraph_end_strings, $paragraph_positions, $active_paragraph_positions);
3369
 
 
3370
 
3371
+ // foreach ($paragraph_end_strings as $paragraph_end_string) {
 
3372
 
3373
+ // $last_position = - 1;
3374
+
3375
+ // $paragraph_end_string = trim ($paragraph_end_string);
3376
+ // if ($paragraph_end_string == '') continue;
3377
+
3378
+ // if (in_array ($paragraph_end_string, $no_closing_tag)) {
3379
+ // if (preg_match_all ("/<$paragraph_end_string(.*?)>/", $content, $images)) {
3380
+ // foreach ($images [0] as $paragraph_end) {
3381
+ // if ($multibyte) {
3382
+ // $last_position = mb_stripos ($content, $paragraph_end, $last_position + 1) + mb_strlen ($paragraph_end) - 1;
3383
+ // $paragraph_positions [] = $last_position;
3384
+ // $active_paragraph_positions [$last_position] = 1;
3385
+ // } else {
3386
+ // $last_position = stripos ($content, $paragraph_end, $last_position + 1) + strlen ($paragraph_end) - 1;
3387
+ // $paragraph_positions [] = $last_position;
3388
+ // $active_paragraph_positions [$last_position] = 1;
3389
+ // }
3390
+ // }
3391
+ // }
3392
+ // continue;
3393
+ // }
3394
+ // elseif ($paragraph_end_string == "#") {
3395
+ // $paragraph_end = "\r\n\r\n";
3396
+ // if (!in_array ($last_content_position, $paragraph_positions)) {
3397
+ // $paragraph_positions [] = $last_content_position;
3398
+ // $active_paragraph_positions [$last_content_position] = 1;
3399
+ // }
3400
+ // } else $paragraph_end = '</' . $paragraph_end_string . '>';
3401
+
3402
+ // if ($multibyte) {
3403
+ // while (mb_stripos ($content, $paragraph_end, $last_position + 1) !== false) {
3404
+ // $last_position = mb_stripos ($content, $paragraph_end, $last_position + 1) + mb_strlen ($paragraph_end) - 1;
3405
+ // if ($paragraph_end_string == "#") {
3406
+ // $paragraph_positions [] = $last_position - 4;
3407
+ // $active_paragraph_positions [$last_position - 4] = 1;
3408
+ // } else {
3409
+ // $paragraph_positions [] = $last_position;
3410
+ // $active_paragraph_positions [$last_position] = 1;
3411
+ // }
3412
+ // }
3413
+ // } else {
3414
+ // while (stripos ($content, $paragraph_end, $last_position + 1) !== false) {
3415
+ // $last_position = stripos ($content, $paragraph_end, $last_position + 1) + strlen ($paragraph_end) - 1;
3416
+ // if ($paragraph_end_string == "#") {
3417
+ // $paragraph_positions [] = $last_position - 4;
3418
+ // $active_paragraph_positions [$last_position - 4] = 1;
3419
+ // } else {
3420
+ // $paragraph_positions [] = $last_position;
3421
+ // $active_paragraph_positions [$last_position] = 1;
3422
+ // }
3423
+ // }
3424
+ // }
3425
+ // }
3426
 
3427
  // Nothing to do
3428
  $ai_last_check = AI_CHECK_PARAGRAPHS_WITH_TAGS;
3429
+ // if (count ($paragraph_positions) == 0) return $content;
3430
+ if (array_sum ($active_paragraph_positions) == 0) return $content;
3431
+
3432
 
3433
  sort ($paragraph_positions);
3434
+ ksort ($active_paragraph_positions);
3435
+ $new_active_paragraph_positions = array ();
3436
+ foreach ($active_paragraph_positions as $active_paragraph_position) {
3437
+ $new_active_paragraph_positions [] = $active_paragraph_position;
3438
+ }
3439
+ $active_paragraph_positions = $new_active_paragraph_positions;
3440
+
3441
 
3442
  if (!$this->get_count_inside_blockquote ()) {
3443
 
3486
 
3487
  if (count ($special_element_offsets) != 0) {
3488
 
3489
+ // $filtered_paragraph_positions = array ();
3490
  $inside_special_element = array ();
3491
 
3492
  foreach ($special_element_offsets as $special_element_offset) {
3495
  }
3496
  }
3497
 
3498
+ foreach ($paragraph_positions as $index => $paragraph_position) {
3499
+ // if (!in_array ($paragraph_position, $inside_special_element)) $filtered_paragraph_positions []= $paragraph_position;
3500
+ if (in_array ($paragraph_position, $inside_special_element)) $active_paragraph_positions [$index] = 0;
3501
  }
3502
 
3503
+ // $paragraph_positions = $filtered_paragraph_positions;
3504
  }
3505
 
3506
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_NO_COUNTING_INSIDE;
3507
+ // if (count ($paragraph_positions) == 0) return $content;
3508
+ if (array_sum ($active_paragraph_positions) == 0) return $content;
3509
  }
3510
 
3511
+
3512
  $paragraph_min_words = intval ($this->get_minimum_paragraph_words());
3513
  $paragraph_max_words = intval ($this->get_maximum_paragraph_words());
3514
 
3515
  if ($paragraph_min_words != 0 || $paragraph_max_words != 0) {
3516
+
3517
+ if (!isset ($paragraph_start_positions)) {
3518
+ $paragraph_start_positions = array ();
3519
+ get_paragraph_start_positions ($content, $multibyte, $paragraph_positions, $paragraph_end_strings, $paragraph_start_positions, $dummy);
3520
+ }
3521
+
3522
+ // $filtered_paragraph_positions = array ();
3523
  foreach ($paragraph_positions as $index => $paragraph_position) {
3524
 
3525
+ if ($active_paragraph_positions [$index] == 0) continue;
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);
3533
  }
3534
 
3535
+ // if ($this->check_number_of_words_in_paragraph ($paragraph_code, $paragraph_min_words, $paragraph_max_words)) $filtered_paragraph_positions [] = $paragraph_position;
3536
+ if (!$this->check_number_of_words_in_paragraph ($paragraph_code, $paragraph_min_words, $paragraph_max_words)) $active_paragraph_positions [$index] = 0;
3537
  }
3538
+ // $paragraph_positions = $filtered_paragraph_positions;
3539
  }
3540
 
3541
+
3542
  // Nothing to do
3543
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS;
3544
+ // if (count ($paragraph_positions) == 0) return $content;
3545
+ if (array_sum ($active_paragraph_positions) == 0) return $content;
3546
 
3547
 
3548
  $paragraph_texts = explode (",", html_entity_decode ($this->get_paragraph_text()));
3549
  if ($this->get_paragraph_text() != "" && count ($paragraph_texts) != 0) {
3550
 
3551
+ if (!isset ($paragraph_start_positions)) {
3552
+ $paragraph_start_positions = array ();
3553
+ get_paragraph_start_positions ($content, $multibyte, $paragraph_positions, $paragraph_end_strings, $paragraph_start_positions, $dummy);
3554
+ }
3555
+
3556
+ // $filtered_paragraph_positions = array ();
3557
  $paragraph_text_type = $this->get_paragraph_text_type ();
3558
 
3559
  foreach ($paragraph_positions as $index => $paragraph_position) {
3560
 
3561
+ if ($active_paragraph_positions [$index] == 0) continue;
3562
+
3563
  if ($multibyte) {
3564
+ // $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]);
3565
+ $paragraph_code = mb_substr ($content, $paragraph_start_positions [$index], $paragraph_position - $paragraph_start_positions [$index] + 1);
3566
  } else {
3567
+ // $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
3568
+ $paragraph_code = substr ($content, $paragraph_start_positions [$index], $paragraph_position - $paragraph_start_positions [$index] + 1);
3569
  }
3570
 
3571
  if ($paragraph_text_type == AD_CONTAIN) {
3586
  }
3587
 
3588
  }
3589
+ // if ($found) $filtered_paragraph_positions [] = $paragraph_position;
3590
+ if (!$found) $filtered_paragraph_positions [] = $active_paragraph_positions [$index] = 0;
3591
  } elseif ($paragraph_text_type == AD_DO_NOT_CONTAIN) {
3592
  $found = false;
3593
  foreach ($paragraph_texts as $paragraph_text) {
3606
  }
3607
 
3608
  }
3609
+ // if (!$found) $filtered_paragraph_positions [] = $paragraph_position;
3610
+ if ($found) $active_paragraph_positions [$index] = 0;
3611
  }
3612
  }
3613
 
3614
+ // $paragraph_positions = $filtered_paragraph_positions;
3615
  }
3616
 
3617
+
3618
  // Nothing to do
3619
  $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_TEXT;
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) {
3626
+ if ($active_paragraph_positions [$index]) $filtered_paragraph_positions [] = $paragraph_position;
3627
+ }
3628
+ $paragraph_positions = $filtered_paragraph_positions;
3629
 
3630
 
3631
  if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
3633
  }
3634
 
3635
 
 
3636
  $position_text = trim ($this->get_paragraph_number());
 
 
 
 
 
 
 
 
3637
 
3638
  // $positions contains indexes in $paragraph_positions
3639
+ $positions = array ();
3640
+
3641
  if (!$position_preview) {
3642
+ $position = $position_text;
3643
+
3644
+ if (is_numeric ($position)) {
3645
+ if ($position > 0 && $position < 1) {
3646
+ $position = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
3647
+ }
3648
+ elseif ($position < 0) {
3649
+ $position = count ($paragraph_positions) + $position;
3650
+ }
3651
+ elseif ($position == 0) {
3652
+ $position = mt_rand (0, count ($paragraph_positions) - 1);
3653
+ } else $position --;
3654
+ $positions = array ($position);
3655
+ }
3656
+ elseif (strpos ($position_text, ',') !== false) {
3657
  $positions = explode (',', str_replace (' ', '', $position_text));
3658
  foreach ($positions as $index => $position) {
3659
  if ($position > 0 && $position < 1) {
3660
  $positions [$index] = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
3661
  }
3662
+ elseif ($position < 0) {
3663
+ $positions [$index] = count ($paragraph_positions) + $position;
3664
+ }
3665
+ elseif ($position == 0) {
3666
  $positions [$index] = mt_rand (0, count ($paragraph_positions) - 1);
3667
  }
3668
  else $positions [$index] = $position - 1;
3939
 
3940
  foreach ($paragraph_positions as $counter => $paragraph_position) {
3941
  if ($position_preview) $inserted_code = "[[AI_AP".($counter + 1)."]]";
 
3942
  elseif (!empty ($positions) && in_array ($counter, $positions) && $this->check_block_counter ()) {
3943
 
3944
  $inserted = false;
3950
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3951
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3952
  $inserted_code = $this->get_code_for_serverside_insertion ();
3953
+ $this->clear_code_cache ();
3954
  $ai_last_check = AI_CHECK_INSERTED;
3955
  $inserted = true;
3956
  }
3960
 
3961
  if (!$inserted) continue;
3962
  }
 
3963
  else {
3964
  if ($debug_processing && isset ($failed_clearance_positions [$counter])) ai_log (ai_log_block_status ($this->number, $failed_clearance_positions [$counter]));
3965
  continue;
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
  }
4358
  return !$return;
4359
  }
4360
 
4361
+ function check_url_parameters ($server_side_check) {
 
4362
 
4363
+ // global $ai_wp_data;
 
4364
 
4365
+ // $parameter_list = trim ($this->get_url_parameter_list());
4366
+ // $parameter_list_type = $this->get_url_parameter_list_type();
4367
 
4368
+ // if ($parameter_list_type == AD_BLACK_LIST) $return = false; else $return = true;
4369
 
4370
+ // if (get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_SERVER_SIDE || ((get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) && $ai_wp_data [AI_WP_AMP_PAGE])) {
4371
+ // $parameters = array_merge ($_COOKIE, $_GET);
4372
+ // } else $parameters = array_merge ($_GET);
4373
 
4374
+ // if ($parameter_list == AD_EMPTY_DATA || count ($parameters) == 0) {
4375
+ // return !$return;
4376
+ // }
 
 
4377
 
4378
+ // $parameters_listed = explode (",", $parameter_list);
4379
+ // foreach ($parameters_listed as $index => $parameter_listed) {
4380
+ // if (trim ($parameter_listed) == "") unset ($parameters_listed [$index]); else
4381
+ // $parameters_listed [$index] = trim ($parameter_listed);
4382
+ // }
 
4383
 
4384
+ //// print_r ($parameter_listed);
4385
+ //// echo "<br />\n";
4386
+ //// echo " parameters: <br />\n";
4387
+ //// print_r ($_GET);
4388
+ //// echo ' listed parameters: ' . $parameter_list, "\n";
4389
+ //// echo "<br />\n";
4390
 
4391
+ // foreach ($parameters_listed as $parameter) {
4392
+ // if (strpos ($parameter, "=") !== false) {
4393
+ // $parameter_value = explode ("=", $parameter);
4394
+ // if (array_key_exists ($parameter_value [0], $parameters) && $parameters [$parameter_value [0]] == $parameter_value [1]) return $return;
4395
+ // } else if (array_key_exists ($parameter, $parameters)) return $return;
4396
+ // }
4397
+
4398
+ // return !$return;
4399
+
4400
+ return check_url_parameter_list ($this->get_url_parameter_list(), $this->get_url_parameter_list_type() == AD_WHITE_LIST, true, true, $server_side_check);
4401
  }
4402
 
4403
  function check_scheduling () {
4447
 
4448
  function check_referer () {
4449
 
4450
+ // if (get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_SERVER_SIDE || ((get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) && $ai_wp_data [AI_WP_AMP_PAGE])) {
4451
+ // $domain_list_type = $this->get_ad_domain_list_type ();
4452
 
4453
+ // if (isset ($_SERVER['HTTP_REFERER'])) {
4454
+ // $referer_host = strtolower (parse_url ($_SERVER['HTTP_REFERER'], PHP_URL_HOST));
4455
+ // } else $referer_host = '';
4456
 
4457
+ // if ($domain_list_type == AD_BLACK_LIST) $return = false; else $return = true;
4458
 
4459
+ // $domains = strtolower (trim ($this->get_ad_domain_list ()));
4460
+ // if ($domains == AD_EMPTY_DATA) return !$return;
4461
+ // $domains = explode (",", $domains);
4462
 
4463
+ // foreach ($domains as $domain) {
4464
+ // $domain = trim ($domain);
4465
+ // if ($domain == "") continue;
4466
 
4467
+ // if ($domain == "#") {
4468
+ // if ($referer_host == "") return $return;
4469
+ // } elseif ($domain == $referer_host) return $return;
4470
+ // }
4471
+ // return !$return;
4472
+ // }
4473
+
4474
+ // return true;
4475
+
4476
+
4477
+ return check_check_referer_list ($this->get_ad_domain_list(), $this->get_ad_domain_list_type() == AD_WHITE_LIST);
4478
  }
4479
 
4480
  function check_number_of_words (&$content = null, $number_of_words = 0) {
4578
  $ai_last_check = AI_CHECK_URL;
4579
  if (!$this->check_url ()) return false;
4580
 
4581
+ $server_side_check = get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_SERVER_SIDE || ((get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT) && $ai_wp_data [AI_WP_AMP_PAGE]);
4582
+
4583
  $ai_last_check = AI_CHECK_URL_PARAMETER;
4584
+ if (!$this->check_url_parameters ($server_side_check)) return false;
4585
 
4586
+ if ($server_side_check) {
4587
+ $ai_last_check = AI_CHECK_REFERER;
4588
+ if (!$this->check_referer ()) return false;
4589
+ }
4590
 
4591
  if (function_exists ('ai_check_lists')) {
4592
+ if (!ai_check_lists ($this, $server_side_check)) return false;
4593
  }
4594
 
4595
  $ai_last_check = AI_CHECK_SCHEDULING;
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.10');
28
 
29
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
30
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
24
  define ('AD_INSERTER_NAME', 'Ad Inserter');
25
 
26
  if (!defined( 'AD_INSERTER_VERSION'))
27
+ define ('AD_INSERTER_VERSION', '2.3.11');
28
 
29
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
30
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
css/ad-inserter.css CHANGED
@@ -1,5 +1,5 @@
1
  #ai-data {
2
- font-family: "2.3.10"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
@@ -40,11 +40,11 @@
40
  }
41
 
42
  button.ai-top-button {
43
- min-width: 52px;
44
  }
45
 
46
  .ai-top-button.ui-button-text-only .ui-button-text {
47
- padding: .4em 0.6em;
48
  }
49
 
50
  .adsense-list .ui-button-text, .select-image .ui-button-text {
1
  #ai-data {
2
+ font-family: "2.3.11"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
40
  }
41
 
42
  button.ai-top-button {
43
+ min-width: 50px;
44
  }
45
 
46
  .ai-top-button.ui-button-text-only .ui-button-text {
47
+ padding: .4em 0.5em;
48
  }
49
 
50
  .adsense-list .ui-button-text, .select-image .ui-button-text {
includes/js/ai-adb.js CHANGED
@@ -160,6 +160,7 @@ var ai_adb_redirection_url = "AI_ADB_REDIRECTION_PAGE";
160
  function ai_adb_process_content () {
161
  (function ($) {
162
 
 
163
  if (ai_adb_debugging) console.log ("AI ad blocking CONTENT PROCESSING");
164
 
165
  $(".AI_ADB_CONTENT_CSS_BEGIN_CLASS").each (function () {
160
  function ai_adb_process_content () {
161
  (function ($) {
162
 
163
+ if (ai_adb_debugging) console.log ('');
164
  if (ai_adb_debugging) console.log ("AI ad blocking CONTENT PROCESSING");
165
 
166
  $(".AI_ADB_CONTENT_CSS_BEGIN_CLASS").each (function () {
includes/js/ai-adb.min.js CHANGED
@@ -15,10 +15,10 @@ while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3
15
  input.length){enc1=keyString.indexOf(input.charAt(i++));enc2=keyString.indexOf(input.charAt(i++));enc3=keyString.indexOf(input.charAt(i++));enc4=keyString.indexOf(input.charAt(i++));chr1=enc1<<2|enc2>>4;chr2=(enc2&15)<<4|enc3>>2;chr3=(enc3&3)<<6|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64)output=output+String.fromCharCode(chr2);if(enc4!=64)output=output+String.fromCharCode(chr3)}output=uTF8Decode(output);return output}})})(jQuery);var ai_adb=false;
16
  var ai_adb_debugging=typeof ai_debugging!=="undefined";var ai_adb_active=false;var ai_adb_counter=0;var ai_adb_overlay=AI_ADB_OVERLAY_WINDOW;var ai_adb_message_window=AI_ADB_MESSAGE_WINDOW;var ai_adb_message_undismissible=AI_FUNCB_GET_UNDISMISSIBLE_MESSAGE;var ai_adb_act_cookie_name="aiADB";var ai_adb_pgv_cookie_name="aiADB_PV";var ai_adb_page_redirection_cookie_name="aiADB_PR";var ai_adb_message_cookie_lifetime=AI_FUNCT_GET_NO_ACTION_PERIOD;var ai_adb_action=AI_FUNC_GET_ADB_ACTION;
17
  var ai_adb_page_views=AI_FUNCT_GET_DELAY_ACTION;var ai_adb_selectors="AI_ADB_SELECTORS";var ai_adb_redirection_url="AI_ADB_REDIRECTION_PAGE";
18
- function ai_adb_process_content(){(function($){if(ai_adb_debugging)console.log("AI ad blocking CONTENT PROCESSING");$(".AI_ADB_CONTENT_CSS_BEGIN_CLASS").each(function(){var ai_adb_parent=$(this).parent();if(ai_adb_debugging)console.log("AI ad blocking parent",ai_adb_parent.prop("tagName"),'id="'+ai_adb_parent.attr("id")+'"','class="'+ai_adb_parent.attr("class")+'"');var ai_adb_css=$(this).data("css");if(typeof ai_adb_css=="undefined")ai_adb_css="display: none !important;";var ai_adb_selectors=$(this).data("selectors");
19
- if(typeof ai_adb_selectors=="undefined"||ai_adb_selectors=="")ai_adb_selectors="p";if(ai_adb_debugging)console.log("AI ad blocking CSS, css='"+ai_adb_css+"'","selectors='"+ai_adb_selectors+"'");var ai_adb_action=false;$(ai_adb_parent).find(".AI_ADB_CONTENT_CSS_BEGIN_CLASS, "+ai_adb_selectors).each(function(){if($(this).hasClass("AI_ADB_CONTENT_CSS_BEGIN_CLASS")){$(this).remove();ai_adb_action=true}else if($(this).hasClass("AI_ADB_CONTENT_CSS_END_CLASS")){$(this).remove();ai_adb_action=false}else if(ai_adb_action){var ai_adb_style=
20
- $(this).attr("style");if(typeof ai_adb_style=="undefined")ai_adb_style="";$(this).attr("style",ai_adb_style+";"+ai_adb_css)}})});$(".AI_ADB_CONTENT_DELETE_BEGIN_CLASS").each(function(){var ai_adb_parent=$(this).parent();if(ai_adb_debugging)console.log("AI ad blocking DELETE, parent",ai_adb_parent.prop("tagName"),'id="'+ai_adb_parent.attr("id")+'"','class="'+ai_adb_parent.attr("class")+'"');var ai_adb_selectors=$(this).data("selectors");if(typeof ai_adb_selectors=="undefined"||ai_adb_selectors=="")ai_adb_selectors=
21
- "p";if(ai_adb_debugging)console.log("AI ad blocking DELETE, selectors='"+ai_adb_selectors+"'");var ai_adb_action=false;$(ai_adb_parent).find(".AI_ADB_CONTENT_DELETE_BEGIN_CLASS, "+ai_adb_selectors).each(function(){if($(this).hasClass("AI_ADB_CONTENT_DELETE_BEGIN_CLASS")){$(this).remove();ai_adb_action=true}else if($(this).hasClass("AI_ADB_CONTENT_DELETE_END_CLASS")){$(this).remove();ai_adb_action=false}else if(ai_adb_action)$(this).remove()})});$(".AI_ADB_CONTENT_REPLACE_BEGIN_CLASS").each(function(){var ai_adb_parent=
22
  $(this).parent();if(ai_adb_debugging)console.log("AI ad blocking REPLACE, parent",ai_adb_parent.prop("tagName"),'id="'+ai_adb_parent.attr("id")+'"','class="'+ai_adb_parent.attr("class")+'"');var ai_adb_text=$(this).data("text");if(typeof ai_adb_text=="undefined")ai_adb_text="";var ai_adb_css=$(this).data("css");if(typeof ai_adb_css=="undefined")ai_adb_css="";var ai_adb_selectors=$(this).data("selectors");if(typeof ai_adb_selectors=="undefined"||ai_adb_selectors=="")ai_adb_selectors="p";if(ai_adb_debugging)console.log("AI ad blocking REPLACE, text='"+
23
  ai_adb_text+"'","css='"+ai_adb_css+"'","selectors='"+ai_adb_selectors+"'");var ai_adb_action=false;$(ai_adb_parent).find(".AI_ADB_CONTENT_REPLACE_BEGIN_CLASS, "+ai_adb_selectors).each(function(){if($(this).hasClass("AI_ADB_CONTENT_REPLACE_BEGIN_CLASS")){$(this).remove();ai_adb_action=true}else if($(this).hasClass("AI_ADB_CONTENT_REPLACE_END_CLASS")){$(this).remove();ai_adb_action=false}else if(ai_adb_action){if(ai_adb_text.length!=0){var n=Math.round($(this).text().length/(ai_adb_text.length+1));
24
  $(this).text(Array(n+1).join(ai_adb_text+" "))}else $(this).text("");var ai_adb_style=$(this).attr("style");if(typeof ai_adb_style=="undefined")ai_adb_style="";$(this).attr("style",ai_adb_style+";"+ai_adb_css)}})})})(jQuery)}
15
  input.length){enc1=keyString.indexOf(input.charAt(i++));enc2=keyString.indexOf(input.charAt(i++));enc3=keyString.indexOf(input.charAt(i++));enc4=keyString.indexOf(input.charAt(i++));chr1=enc1<<2|enc2>>4;chr2=(enc2&15)<<4|enc3>>2;chr3=(enc3&3)<<6|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64)output=output+String.fromCharCode(chr2);if(enc4!=64)output=output+String.fromCharCode(chr3)}output=uTF8Decode(output);return output}})})(jQuery);var ai_adb=false;
16
  var ai_adb_debugging=typeof ai_debugging!=="undefined";var ai_adb_active=false;var ai_adb_counter=0;var ai_adb_overlay=AI_ADB_OVERLAY_WINDOW;var ai_adb_message_window=AI_ADB_MESSAGE_WINDOW;var ai_adb_message_undismissible=AI_FUNCB_GET_UNDISMISSIBLE_MESSAGE;var ai_adb_act_cookie_name="aiADB";var ai_adb_pgv_cookie_name="aiADB_PV";var ai_adb_page_redirection_cookie_name="aiADB_PR";var ai_adb_message_cookie_lifetime=AI_FUNCT_GET_NO_ACTION_PERIOD;var ai_adb_action=AI_FUNC_GET_ADB_ACTION;
17
  var ai_adb_page_views=AI_FUNCT_GET_DELAY_ACTION;var ai_adb_selectors="AI_ADB_SELECTORS";var ai_adb_redirection_url="AI_ADB_REDIRECTION_PAGE";
18
+ function ai_adb_process_content(){(function($){if(ai_adb_debugging)console.log("");if(ai_adb_debugging)console.log("AI ad blocking CONTENT PROCESSING");$(".AI_ADB_CONTENT_CSS_BEGIN_CLASS").each(function(){var ai_adb_parent=$(this).parent();if(ai_adb_debugging)console.log("AI ad blocking parent",ai_adb_parent.prop("tagName"),'id="'+ai_adb_parent.attr("id")+'"','class="'+ai_adb_parent.attr("class")+'"');var ai_adb_css=$(this).data("css");if(typeof ai_adb_css=="undefined")ai_adb_css="display: none !important;";
19
+ var ai_adb_selectors=$(this).data("selectors");if(typeof ai_adb_selectors=="undefined"||ai_adb_selectors=="")ai_adb_selectors="p";if(ai_adb_debugging)console.log("AI ad blocking CSS, css='"+ai_adb_css+"'","selectors='"+ai_adb_selectors+"'");var ai_adb_action=false;$(ai_adb_parent).find(".AI_ADB_CONTENT_CSS_BEGIN_CLASS, "+ai_adb_selectors).each(function(){if($(this).hasClass("AI_ADB_CONTENT_CSS_BEGIN_CLASS")){$(this).remove();ai_adb_action=true}else if($(this).hasClass("AI_ADB_CONTENT_CSS_END_CLASS")){$(this).remove();
20
+ ai_adb_action=false}else if(ai_adb_action){var ai_adb_style=$(this).attr("style");if(typeof ai_adb_style=="undefined")ai_adb_style="";$(this).attr("style",ai_adb_style+";"+ai_adb_css)}})});$(".AI_ADB_CONTENT_DELETE_BEGIN_CLASS").each(function(){var ai_adb_parent=$(this).parent();if(ai_adb_debugging)console.log("AI ad blocking DELETE, parent",ai_adb_parent.prop("tagName"),'id="'+ai_adb_parent.attr("id")+'"','class="'+ai_adb_parent.attr("class")+'"');var ai_adb_selectors=$(this).data("selectors");if(typeof ai_adb_selectors==
21
+ "undefined"||ai_adb_selectors=="")ai_adb_selectors="p";if(ai_adb_debugging)console.log("AI ad blocking DELETE, selectors='"+ai_adb_selectors+"'");var ai_adb_action=false;$(ai_adb_parent).find(".AI_ADB_CONTENT_DELETE_BEGIN_CLASS, "+ai_adb_selectors).each(function(){if($(this).hasClass("AI_ADB_CONTENT_DELETE_BEGIN_CLASS")){$(this).remove();ai_adb_action=true}else if($(this).hasClass("AI_ADB_CONTENT_DELETE_END_CLASS")){$(this).remove();ai_adb_action=false}else if(ai_adb_action)$(this).remove()})});$(".AI_ADB_CONTENT_REPLACE_BEGIN_CLASS").each(function(){var ai_adb_parent=
22
  $(this).parent();if(ai_adb_debugging)console.log("AI ad blocking REPLACE, parent",ai_adb_parent.prop("tagName"),'id="'+ai_adb_parent.attr("id")+'"','class="'+ai_adb_parent.attr("class")+'"');var ai_adb_text=$(this).data("text");if(typeof ai_adb_text=="undefined")ai_adb_text="";var ai_adb_css=$(this).data("css");if(typeof ai_adb_css=="undefined")ai_adb_css="";var ai_adb_selectors=$(this).data("selectors");if(typeof ai_adb_selectors=="undefined"||ai_adb_selectors=="")ai_adb_selectors="p";if(ai_adb_debugging)console.log("AI ad blocking REPLACE, text='"+
23
  ai_adb_text+"'","css='"+ai_adb_css+"'","selectors='"+ai_adb_selectors+"'");var ai_adb_action=false;$(ai_adb_parent).find(".AI_ADB_CONTENT_REPLACE_BEGIN_CLASS, "+ai_adb_selectors).each(function(){if($(this).hasClass("AI_ADB_CONTENT_REPLACE_BEGIN_CLASS")){$(this).remove();ai_adb_action=true}else if($(this).hasClass("AI_ADB_CONTENT_REPLACE_END_CLASS")){$(this).remove();ai_adb_action=false}else if(ai_adb_action){if(ai_adb_text.length!=0){var n=Math.round($(this).text().length/(ai_adb_text.length+1));
24
  $(this).text(Array(n+1).join(ai_adb_text+" "))}else $(this).text("");var ai_adb_style=$(this).attr("style");if(typeof ai_adb_style=="undefined")ai_adb_style="";$(this).attr("style",ai_adb_style+";"+ai_adb_css)}})})})(jQuery)}
includes/js/ai-lists.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery (function ($) {
2
+ function getHostName (url) {
3
+ var match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i);
4
+ if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) {
5
+ return match [2];
6
+ } else {
7
+ return null;
8
+ }
9
+ }
10
+
11
+ ai_process_lists = function () {
12
+ var ai_debug = typeof ai_debugging !== 'undefined';
13
+ var cookies = document.cookie.split (";");
14
+ var referrer = document.referrer;
15
+
16
+ cookies.forEach (function (cookie, index) {
17
+ cookies [index] = cookie.trim();
18
+ });
19
+
20
+ if (referrer != '') referrer = getHostName (referrer);
21
+
22
+ var ai_list_blocks = $("div.ai-list-data");
23
+ if (ai_list_blocks.length) {
24
+ ai_list_blocks.each (function () {
25
+
26
+ var enable_block = true;
27
+ var referers_processed = false;
28
+
29
+ var found = false;
30
+
31
+ var referer_list = $(this).attr ("referer-list");
32
+ if (typeof referer_list != "undefined") {
33
+ var referer_list_array = atob (referer_list).split (",");
34
+ var referers_list_type = $(this).attr ("referer-list-type");
35
+
36
+ if (ai_debug) console.log ('');
37
+ if (ai_debug) console.log ("AI LISTS referer: ", referrer);
38
+ if (ai_debug) console.log ("AI LISTS referer list:", atob (referer_list), referers_list_type);
39
+
40
+ $.each (referer_list_array, function (index, list_referer) {
41
+ if (list_referer == '') return true;
42
+
43
+ if (list_referer == '#') {
44
+ if (referrer == "") {
45
+ found = true;
46
+ return false;
47
+ }
48
+ } else if (list_referer == referrer) {
49
+ found = true;
50
+ return false;
51
+ }
52
+ });
53
+
54
+ switch (referers_list_type) {
55
+ case "B":
56
+ if (found) enable_block = false;
57
+ break;
58
+ case "W":
59
+ if (!found) enable_block = false;
60
+ break;
61
+ }
62
+
63
+ if (ai_debug) console.log ("AI LISTS list found", found);
64
+ if (ai_debug) console.log ("AI LISTS list pass", enable_block);
65
+ referers_processed = true;
66
+ }
67
+
68
+ if (enable_block) {
69
+ var parameter_list = $(this).attr ("parameter-list");
70
+ if (typeof parameter_list != "undefined") {
71
+ var parameter_list_array = atob (parameter_list).split (",");
72
+ var parameter_list_type = $(this).attr ("parameter-list-type");
73
+
74
+ if (ai_debug && referers_processed) console.log ('');
75
+ if (ai_debug) console.log ("AI LISTS cookies: ", cookies);
76
+ if (ai_debug) console.log ("AI LISTS parameter list:", atob (parameter_list), parameter_list_type);
77
+
78
+ var found = false;
79
+
80
+ $.each (parameter_list_array, function (index, list_parameter) {
81
+
82
+ if (list_parameter.indexOf ('=') != - 1) {
83
+ if (cookies.indexOf (list_parameter) != - 1) {
84
+ found = true;
85
+ return false;
86
+ }
87
+ } else {
88
+ cookies.forEach (function (cookie) {
89
+ var cookie_data = cookie.split ("=");
90
+ if (list_parameter == cookie_data [0]) {
91
+ found = true;
92
+ return false;
93
+ }
94
+ });
95
+ }
96
+ });
97
+
98
+ switch (parameter_list_type) {
99
+ case "B":
100
+ if (found) enable_block = false;
101
+ break;
102
+ case "W":
103
+ if (!found) enable_block = false;
104
+ break;
105
+ }
106
+
107
+ if (ai_debug) console.log ("AI LISTS list found", found);
108
+ if (ai_debug) console.log ("AI LISTS list pass", enable_block);
109
+ }
110
+ }
111
+
112
+ $(this).css ({"visibility": "", "position": "", "width": "", "height": "", "z-index": ""}).removeClass ('ai-list-data');
113
+ var block_wrapping_div = $(this).closest ('div.ai-list-block');
114
+ block_wrapping_div.css ({"visibility": "", "position": "", "z-index": ""}).removeClass ('ai-list-block');
115
+ block_wrapping_div.find ('.ai-debug-name.ai-list-info').text (referrer);
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
+ });
129
+ }
130
+ }
131
+
132
+ $(document).ready(function($) {
133
+ setTimeout (function() {ai_process_lists ();}, 5);
134
+ });
135
+ });
includes/js/ai-lists.min.js ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ jQuery(function($){function getHostName(url){var match=url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i);if(match!=null&&match.length>2&&typeof match[2]==="string"&&match[2].length>0)return match[2];else return null}ai_process_lists=function(){var ai_debug=typeof ai_debugging!=="undefined";var cookies=document.cookie.split(";");var referrer=document.referrer;cookies.forEach(function(cookie,index){cookies[index]=cookie.trim()});if(referrer!="")referrer=getHostName(referrer);var ai_list_blocks=$("div.ai-list-data");
2
+ if(ai_list_blocks.length)ai_list_blocks.each(function(){var enable_block=true;var referers_processed=false;var found=false;var referer_list=$(this).attr("referer-list");if(typeof referer_list!="undefined"){var referer_list_array=atob(referer_list).split(",");var referers_list_type=$(this).attr("referer-list-type");if(ai_debug)console.log("");if(ai_debug)console.log("AI LISTS referer: ",referrer);if(ai_debug)console.log("AI LISTS referer list:",atob(referer_list),referers_list_type);$.each(referer_list_array,
3
+ function(index,list_referer){if(list_referer=="")return true;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");
4
+ if(typeof parameter_list!="undefined"){var parameter_list_array=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)!=
5
+ -1){found=true;return false}}else cookies.forEach(function(cookie){var cookie_data=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");
6
+ var block_wrapping_div=$(this).closest("div.ai-list-block");block_wrapping_div.css({"visibility":"","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",
7
+ "")}})};$(document).ready(function($){setTimeout(function(){ai_process_lists()},5)})});
includes/js/ai-rotate.js CHANGED
@@ -4,6 +4,7 @@ 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 ('AI ROTATE process rotation:', rotate_options.length, 'options');
8
 
9
  rotate_options.hide ();
@@ -33,7 +34,7 @@ jQuery (function ($) {
33
  } else {
34
  var random_index = parseInt ($(rotation_block).attr ('data-next'));
35
 
36
- if (ai_debug) console.log ('AI TIMED ROTATE next: ', random_index);
37
  }
38
 
39
  var option = $(rotate_options [random_index]);
@@ -42,7 +43,10 @@ jQuery (function ($) {
42
  if (typeof option.data ('time') != 'undefined') {
43
  var rotation_time = atob (option.data ('time'));
44
 
45
- if (ai_debug) console.log ('AI TIMED ROTATE index:', random_index, 'time:', rotation_time);
 
 
 
46
 
47
  if (rotation_time == 0 && rotate_options.length > 1) {
48
  var next_random_index = random_index;
@@ -112,12 +116,11 @@ jQuery (function ($) {
112
  // }, 500, function() {
113
  // });
114
 
115
-
116
  if (typeof option.data ('code') != 'undefined') {
 
 
117
  var option_code = atob (option.data ('code'));
118
  option.append (option_code);
119
-
120
- if (!ai_debug) option.attr ('data-code', '');
121
  }
122
 
123
  var option_name = '';
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
 
10
  rotate_options.hide ();
34
  } else {
35
  var random_index = parseInt ($(rotation_block).attr ('data-next'));
36
 
37
+ if (ai_debug) console.log ('AI TIMED ROTATE next index: ', random_index);
38
  }
39
 
40
  var option = $(rotate_options [random_index]);
43
  if (typeof option.data ('time') != 'undefined') {
44
  var rotation_time = atob (option.data ('time'));
45
 
46
+ if (ai_debug) {
47
+ var option_name = atob (option.data ('name'));
48
+ console.log ('AI TIMED ROTATE index:', random_index, 'name:', option_name, 'time:', rotation_time);
49
+ }
50
 
51
  if (rotation_time == 0 && rotate_options.length > 1) {
52
  var next_random_index = random_index;
116
  // }, 500, function() {
117
  // });
118
 
 
119
  if (typeof option.data ('code') != 'undefined') {
120
+ rotate_options.empty();
121
+
122
  var option_code = atob (option.data ('code'));
123
  option.append (option_code);
 
 
124
  }
125
 
126
  var option_name = '';
includes/js/ai-rotate.min.js CHANGED
@@ -1,9 +1,9 @@
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("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=Math.round(Math.random()*
2
- 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: ",random_index)}var option=$(rotate_options[random_index]);var option_time_text="";if(typeof option.data("time")!=
3
- "undefined"){var rotation_time=atob(option.data("time"));if(ai_debug)console.log("AI TIMED ROTATE index:",random_index,"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=next_random_index;option=$(rotate_options[random_index]);rotation_time=0;if(ai_debug)console.log("AI TIMED ROTATE next option has no time: ",
4
- 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:",random_index,"time:",rotation_time)}if(rotation_time>0){var next_random_index=random_index+
5
- 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!=random_index)$(this).remove()});
6
- 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"){var option_code=atob(option.data("code"));option.append(option_code);if(!ai_debug)option.attr("data-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()},
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()},
includes/js/ai-sidebar.js CHANGED
@@ -8,6 +8,7 @@ jQuery(document).ready(function($) {
8
  var widget = $(this);
9
  var widget_width = widget.width();
10
 
 
11
  if (ai_debug) console.log ("WIDGET:", widget.width (), widget.prop ("tagName"), widget.attr ("id"));
12
 
13
  var already_sticky_js = false;
8
  var widget = $(this);
9
  var widget_width = widget.width();
10
 
11
+ if (ai_debug) console.log ('');
12
  if (ai_debug) console.log ("WIDGET:", widget.width (), widget.prop ("tagName"), widget.attr ("id"));
13
 
14
  var already_sticky_js = false;
includes/js/ai-sidebar.min.js CHANGED
@@ -1,4 +1,4 @@
1
- jQuery(document).ready(function($){var sticky_widget_mode=AI_FUNC_GET_STICKY_WIDGET_MODE;var sticky_widget_margin=AI_FUNC_GET_STICKY_WIDGET_MARGIN;var document_width=$(document).width();var ai_debug=typeof ai_debugging!=="undefined";$(".ai-sticky-widget").each(function(){var widget=$(this);var widget_width=widget.width();if(ai_debug)console.log("WIDGET:",widget.width(),widget.prop("tagName"),widget.attr("id"));var already_sticky_js=false;var sidebar=widget.parent();while(sidebar.prop("tagName")!=
2
  "BODY"){if(sidebar.hasClass("theiaStickySidebar")){already_sticky_js=true;break}if(ai_debug)console.log("SIDEBAR:",sidebar.width(),sidebar.prop("tagName"),sidebar.attr("id"));var parent_element=sidebar.parent();var parent_element_width=parent_element.width();if(parent_element_width>widget_width*1.2||parent_element_width>document_width/2)break;sidebar=parent_element}if(already_sticky_js){if(ai_debug)console.log("JS STICKY SIDEBAR ALREADY SET");return}var new_sidebar_top=sidebar.offset().top-widget.offset().top+
3
  sticky_widget_margin;if(ai_debug)console.log("NEW SIDEBAR TOP:",new_sidebar_top);if(sticky_widget_mode==0)if(sidebar.css("position")!="sticky"||isNaN(parseInt(sidebar.css("top")))||sidebar.css("top")<new_sidebar_top){sidebar.css("position","sticky").css("top",new_sidebar_top);if(ai_debug)console.log("CSS STICKY SIDEBAR, TOP:",new_sidebar_top)}else{if(ai_debug)console.log("CSS STICKY SIDEBAR ALREADY SET")}else{sidebar.theiaStickySidebar({additionalMarginTop:new_sidebar_top,sidebarBehavior:"stick-to-top"});
4
  if(ai_debug)console.log("JS STICKY SIDEBAR, TOP:",new_sidebar_top)}})});
1
+ jQuery(document).ready(function($){var sticky_widget_mode=AI_FUNC_GET_STICKY_WIDGET_MODE;var sticky_widget_margin=AI_FUNC_GET_STICKY_WIDGET_MARGIN;var document_width=$(document).width();var ai_debug=typeof ai_debugging!=="undefined";$(".ai-sticky-widget").each(function(){var widget=$(this);var widget_width=widget.width();if(ai_debug)console.log("");if(ai_debug)console.log("WIDGET:",widget.width(),widget.prop("tagName"),widget.attr("id"));var already_sticky_js=false;var sidebar=widget.parent();while(sidebar.prop("tagName")!=
2
  "BODY"){if(sidebar.hasClass("theiaStickySidebar")){already_sticky_js=true;break}if(ai_debug)console.log("SIDEBAR:",sidebar.width(),sidebar.prop("tagName"),sidebar.attr("id"));var parent_element=sidebar.parent();var parent_element_width=parent_element.width();if(parent_element_width>widget_width*1.2||parent_element_width>document_width/2)break;sidebar=parent_element}if(already_sticky_js){if(ai_debug)console.log("JS STICKY SIDEBAR ALREADY SET");return}var new_sidebar_top=sidebar.offset().top-widget.offset().top+
3
  sticky_widget_margin;if(ai_debug)console.log("NEW SIDEBAR TOP:",new_sidebar_top);if(sticky_widget_mode==0)if(sidebar.css("position")!="sticky"||isNaN(parseInt(sidebar.css("top")))||sidebar.css("top")<new_sidebar_top){sidebar.css("position","sticky").css("top",new_sidebar_top);if(ai_debug)console.log("CSS STICKY SIDEBAR, TOP:",new_sidebar_top)}else{if(ai_debug)console.log("CSS STICKY SIDEBAR ALREADY SET")}else{sidebar.theiaStickySidebar({additionalMarginTop:new_sidebar_top,sidebarBehavior:"stick-to-top"});
4
  if(ai_debug)console.log("JS STICKY SIDEBAR, TOP:",new_sidebar_top)}})});
js/ad-inserter.js CHANGED
@@ -1,4 +1,4 @@
1
- var javascript_version = "2.3.10";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
1
+ var javascript_version = "2.3.11";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
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.9
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
@@ -17,7 +17,7 @@ Ad management plugin with many advanced advertising features to insert ads at op
17
 
18
  Supports all kinds of ads including **Google AdSense ads**, contextual **Amazon Native Shopping Ads**, **Media.net ads** and **rotating banner ads.**
19
 
20
- Ad Inserter is more than just ad manager plugin for ads. It provides many advanced options to insert opt-in forms, header scripts, AMP ads, Javascript, CSS, HTML, PHP, analytics, tracking or advert code anywhere on the page.
21
 
22
  **Ad Inserter can insert ads where other plugins fail**.
23
  It's all about the settings.
@@ -119,12 +119,12 @@ 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 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)
126
  * Black/White-list IP addresses or countries (works also with caching)
127
- * Ad impression and click tracking (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
@@ -154,7 +154,9 @@ You can also use shortcodes from other plugins (for example, to insert ads from
154
  **Ad Inserter can insert ads where other plugins fail**.
155
  It's all about the settings.
156
 
157
- **Ad Inserter Ad Manager - One Plugin - Many Functions - All Ads**
 
 
158
 
159
  Ad Inserter is not just another plugin for WordPress ads. Do you enjoy finding the right plugin to solve a particular problem on your site? For example:
160
 
@@ -275,7 +277,7 @@ If you deactivate and delete Ad Inserter, the settings will stay in the database
275
  *Please Note*
276
 
277
  Ad Inserter inserts only the code you configure (blocks 1 - 16, Header, Footer). The code you see is the code that will be inserted (+ some internal scripts for plugin features).
278
- When you deactivate Ad Inserter it can't insert anything as WordPress doesn't call it. Please check page source code before you make any conclusion.
279
  Of course, if you configure code block with some javacript ad code, then this code may generate ads. But please, don't blame the plugin for this.
280
  You can also use Ad Inserter to insert code for AdSense Auto ads on each page (usually in the header). However, **the exact placement of ads will be done by the ad code, not Ad Inserter!**
281
  [https://adinserter.pro/adsense-ads#auto-ads](https://adinserter.pro/adsense-ads#auto-ads)
@@ -353,12 +355,46 @@ Blank AdSense ad block means that the code is inserted properly only the ad code
353
 
354
  See [AdSense ads not displayed](https://adinserter.pro/adsense-ads#ads-not-displayed) for details. In such case you can try other ad networks for contextual ads. Check <a href="https://adinserter.pro/documentation#ads-not-displayed">Ads Not Displayed</a> for more information.
355
 
356
- = Settings for widget =
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
 
358
- * Nothing needed, just enter the code and save settings - widget is enabled by default
359
- * Go to Appearance / Widgets, drag Ad Inserter widget to the sidebar or any other widget position, select code block and click on Save
360
- * Optionally you can enable Sticky widget - this means that this widget (and widgets below) will stay fixed in the sidebar when the page is scrolled - Sticky Sidebar
361
- * You can also make other widgets sticky even if you don't use Ad Inserter widgets - drag Ad Inserter widget to the sidebar ABOVE the top widget that needs to be sticky, select Dummy Widget for Block, check Sticky and save widget
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  * In general plugin settings (tab &#9881;) you can also define Sticky Widget Top Margin to precisely define top position where the first sticky widget will stick
363
 
364
  Additional note regarding *Sticky Widgets* - *Sticky Sidebars*:
@@ -400,7 +436,7 @@ You can also use <a href="https://codex.wordpress.org/Custom_Fields" target="_bl
400
  You can also try with `[adinserter data='tag']', `[adinserter data='short-title']`, `[adinserter data='category']` or `[adinserter data='short-category']`. For more options check <a href="http://adinserter.pro/documentation#code-block-options" target="_blank">Ad Inserter documentation page</a>.
401
 
402
 
403
- = Settings for ... =
404
 
405
  Check <a href="http://adinserter.pro/settings" target="_blank">common Ad Inserter settings</a>
406
 
@@ -427,14 +463,14 @@ Configure block 3 with
427
  Use block 3 to insert ads and make sure all 3 blocks are enabled for the same page types (Posts, Pages, Homepage, etc.).
428
 
429
 
430
- = I use After Content insertion position but the code is inserted after the stuff provided by other plugins. How can I insert directly after post content?
431
 
432
  This happens because Ad Inserter processes posts last and therefore "sees" also content added by other plugins.
433
 
434
  Try to set Ad Inserter plugin priority to 10 (early processing, Ad Inserter settings - tab &#9881; / tab General).
435
 
436
 
437
- = How can I add some title or label (e.g. Advertisements) above the ad? =
438
 
439
  If this is a sidebar widget then you can simply name the widget.
440
 
@@ -633,6 +669,12 @@ AD CODE RIGHT
633
 
634
  == Changelog ==
635
 
 
 
 
 
 
 
636
  = 2.3.10 =
637
  - Added support for timed rotation
638
  - Added support for client-side insertion of dynamic blocks
@@ -704,6 +746,12 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
704
 
705
  == Upgrade Notice ==
706
 
 
 
 
 
 
 
707
  = 2.3.10 =
708
  Added support for timed rotation;
709
  Added support for client-side insertion of dynamic blocks;
6
  Requires at least: 4.0
7
  Tested up to: 4.9
8
  Requires PHP: 5.6
9
+ Stable tag: 2.3.10
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
17
 
18
  Supports all kinds of ads including **Google AdSense ads**, contextual **Amazon Native Shopping Ads**, **Media.net ads** and **rotating banner ads.**
19
 
20
+ Ad Inserter is more than just ad manager or plugin for ads. It provides many advanced options to insert opt-in forms, header scripts, AMP ads, Javascript, CSS, HTML, PHP, analytics, tracking or advert code anywhere on the page.
21
 
22
  **Ad Inserter can insert ads where other plugins fail**.
23
  It's all about the settings.
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)
126
  * Black/White-list IP addresses or countries (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
  * [Sticky ads](https://adinserter.pro/alignments-and-styles#sticky-ads) with optional close button
154
  **Ad Inserter can insert ads where other plugins fail**.
155
  It's all about the settings.
156
 
157
+ **Ad Inserter - WordPress Ad Manager**
158
+
159
+ *One Plugin for All Ads*
160
 
161
  Ad Inserter is not just another plugin for WordPress ads. Do you enjoy finding the right plugin to solve a particular problem on your site? For example:
162
 
277
  *Please Note*
278
 
279
  Ad Inserter inserts only the code you configure (blocks 1 - 16, Header, Footer). The code you see is the code that will be inserted (+ some internal scripts for plugin features).
280
+ When you deactivate Ad Inserter it can't insert anything as WordPress doesn't call it. If you still see ads please clear all the caches and check page source code before you make any conclusion.
281
  Of course, if you configure code block with some javacript ad code, then this code may generate ads. But please, don't blame the plugin for this.
282
  You can also use Ad Inserter to insert code for AdSense Auto ads on each page (usually in the header). However, **the exact placement of ads will be done by the ad code, not Ad Inserter!**
283
  [https://adinserter.pro/adsense-ads#auto-ads](https://adinserter.pro/adsense-ads#auto-ads)
355
 
356
  See [AdSense ads not displayed](https://adinserter.pro/adsense-ads#ads-not-displayed) for details. In such case you can try other ad networks for contextual ads. Check <a href="https://adinserter.pro/documentation#ads-not-displayed">Ads Not Displayed</a> for more information.
357
 
358
+ = What is GDPR? =
359
+
360
+ The GDPR (General Data Protection Regulation) is a regulation in European Union (EU) on data protection and privacy for all individuals within the EU and the European Economic Area (EEA) that was designed to harmonize data privacy laws across Europe. If you collect personal information from any EU citizen (within or outside the EU), you must first obtain explicit and unambiguous consent.
361
+
362
+ = GDPR compliance: What cookies does the plugin use =
363
+
364
+ Ad Inserter itself does not use cookies except for ad blocking detection when you use delayed action.
365
+
366
+ In this case 3 cookies may be used (to store pageviews and action settings): `aiADB`, `aiADB_PV` and `aiADB_PR`. However, no personal data is stored in the cookies.
367
+
368
+ Of course, the ads you may insert with the plugin may use own cookies - please check with ad networks for details.
369
+
370
+ = How to display a GDPR compliant cookie message? =
371
+
372
+ You can use any plugin for GDPR compliance / cookie consent. For example:
373
+
374
+ * [Cookie Notice for GDPR](https://wordpress.org/plugins/cookie-notice/)
375
+ * [Cookie Consent](https://wordpress.org/plugins/uk-cookie-consent/)
376
+ * [GDPR Cookie Consent](https://wordpress.org/plugins/cookie-law-info/)
377
+
378
+ PLEASE NOTE: Installing GDPR plugin alone does not make your site GDPR compliant. Since ads you insert may use various cookies, you may need to make sure you have necessary configurations in place. Please check next question regarding showing ads based on visitor's consent.
379
 
380
+ = How to show ads based on visitor's consent? =
381
+
382
+ Ad Inserter supports inserting (showing) ads based on cookies or cookie values. You can define cookie conditions by black/white-listing *Url parameters* (where also [cookies are checked](https://adinserter.pro/lists#cookies)).
383
+
384
+ PLEASE NOTE: If you are using caching (very likely) you also need to set **Dynamic blocks** to **Client-side insert** (tab &#9881; / tab General) in order to check cookies in visitor's browser and not when the page is generated.
385
+
386
+ For example, If you are using one of the following plugins for cookie consent you need to **white-list the following cookie and value in Url parameter list**:
387
+
388
+ * [GDPR Cookie Consent](https://wordpress.org/plugins/cookie-law-info/) - White-list `viewed_cookie_policy=yes`
389
+ * [Cookie Notice for GDPR](https://wordpress.org/plugins/cookie-notice/) - White-list `cookie_notice_accepted=true`
390
+ * [Cookie Consent](https://wordpress.org/plugins/uk-cookie-consent/) - White-list `catAccCookies=1`
391
+
392
+ = Settings for widget ads =
393
+
394
+ * Nothing needed, just enter the code for ads and save settings - widget is enabled by default
395
+ * Go to Appearance / Widgets, drag Ad Inserter widget to the sidebar or any other widget position, select block and click on Save (button Save might be disabled until you make some change)
396
+ * Optionally you can enable Sticky widget - this means that this widget (and widgets below) will stay fixed in the sidebar when the page is scrolled - Sticky sidebar or Fixed widget feature
397
+ * You can also make other widgets sticky even if you don't use Ad Inserter ads - drag Ad Inserter widget to the sidebar ABOVE the top widget that needs to be sticky, select Dummy Widget for Block, check Sticky and save widget
398
  * In general plugin settings (tab &#9881;) you can also define Sticky Widget Top Margin to precisely define top position where the first sticky widget will stick
399
 
400
  Additional note regarding *Sticky Widgets* - *Sticky Sidebars*:
436
  You can also try with `[adinserter data='tag']', `[adinserter data='short-title']`, `[adinserter data='category']` or `[adinserter data='short-category']`. For more options check <a href="http://adinserter.pro/documentation#code-block-options" target="_blank">Ad Inserter documentation page</a>.
437
 
438
 
439
+ = Settings for ads ... =
440
 
441
  Check <a href="http://adinserter.pro/settings" target="_blank">common Ad Inserter settings</a>
442
 
463
  Use block 3 to insert ads and make sure all 3 blocks are enabled for the same page types (Posts, Pages, Homepage, etc.).
464
 
465
 
466
+ = I use After Content insertion position but the ads are inserted after the stuff provided by other plugins. How can I insert ads directly after post content?
467
 
468
  This happens because Ad Inserter processes posts last and therefore "sees" also content added by other plugins.
469
 
470
  Try to set Ad Inserter plugin priority to 10 (early processing, Ad Inserter settings - tab &#9881; / tab General).
471
 
472
 
473
+ = How can I add some title or label (e.g. Advertisements) above the ads? =
474
 
475
  If this is a sidebar widget then you can simply name the widget.
476
 
669
 
670
  == Changelog ==
671
 
672
+ = 2.3.11 =
673
+ - Added support for W3TC/client-side check for cookies (in url parameter list) to support showing ads based on visitor's cookie consent
674
+ - Added support for W3TC/client-side check for referers
675
+ - Improved paragraph processing
676
+ - Few minor bug fixes, cosmetic changes and code improvements
677
+
678
  = 2.3.10 =
679
  - Added support for timed rotation
680
  - Added support for client-side insertion of dynamic blocks
746
 
747
  == Upgrade Notice ==
748
 
749
+ = 2.3.11 =
750
+ Added support for W3TC/client-side check for cookies (in url parameter list) to support showing ads based on visitor's cookie consent;
751
+ Added support for W3TC/client-side check for referers;
752
+ Improved paragraph processing;
753
+ Few minor bug fixes, cosmetic changes and code improvements
754
+
755
  = 2.3.10 =
756
  Added support for timed rotation;
757
  Added support for client-side insertion of dynamic blocks;