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

Version Description

  • Simplified AdSense integration
  • Added setting to define maximum number of blocks (ads) per page
  • Optimized the_content filter processing
  • Added setting for lazy loading offset (Pro only)
  • Fix for url parameter list when using client-side dynamic blocks
  • 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.14
Comparing to
See all releases

Code changes from version 2.3.13 to 2.3.14

ad-inserter.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
- Version: 2.3.13
6
  Description: Ad management plugin with advanced advertising options to automatically insert ad codes on your website
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
@@ -13,6 +13,14 @@ Plugin URI: http://adinserter.pro/documentation
13
 
14
  Change Log
15
 
 
 
 
 
 
 
 
 
16
  Ad Inserter 2.3.13 - 2018-07-11
17
  - Added support for lazy loading (Pro only)
18
  - Fix for unwanted insertions with some paragraph settings
@@ -665,6 +673,7 @@ $ai_wp_data [AI_CLOSE_BUTTONS] = false;
665
  $ai_wp_data [AI_DISABLE_CACHING] = false;
666
  $ai_wp_data [AI_CLIENT_SIDE_INSERTION] = false;
667
  $ai_wp_data [AI_LAZY_LOADING] = false;
 
668
 
669
  ai_load_settings ();
670
 
@@ -1106,6 +1115,7 @@ function ai_block_insertion_status ($block, $ai_last_check) {
1106
  case AI_CHECK_DISABLED_MANUALLY: $status .= "DISABLED BY HTML COMMENT"; break;
1107
 
1108
  case AI_CHECK_MAX_INSERTIONS: $status .= "MAX INSERTIONS " . $obj->get_maximum_insertions (); break;
 
1109
  case AI_CHECK_FILTER: $status .= ($obj->get_inverted_filter() ? 'INVERTED ' : '') . "FILTER " . $obj->get_call_filter(); break;
1110
  case AI_CHECK_PARAGRAPH_COUNTING: $status .= "PARAGRAPH COUNTING"; break;
1111
  case AI_CHECK_MIN_NUMBER_OF_WORDS: $status .= "MIN NUMBER OF WORDS " . intval ($obj->get_minimum_words()); break;
@@ -3396,51 +3406,47 @@ function ai_check_multisite_options (&$multisite_options) {
3396
  if (function_exists ('ai_check_multisite_options_2')) ai_check_multisite_options_2 ($multisite_options);
3397
  }
3398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3399
  function ai_check_plugin_options ($plugin_options = array ()) {
3400
  global $version_string;
3401
 
3402
  $plugin_options ['VERSION'] = $version_string;
3403
 
3404
- if (!isset ($plugin_options ['SYNTAX_HIGHLIGHTER_THEME'])) $plugin_options ['SYNTAX_HIGHLIGHTER_THEME'] = DEFAULT_SYNTAX_HIGHLIGHTER_THEME;
3405
 
3406
- if (!isset ($plugin_options ['BLOCK_CLASS_NAME'])) $plugin_options ['BLOCK_CLASS_NAME'] = DEFAULT_BLOCK_CLASS_NAME;
3407
- if (!isset ($plugin_options ['BLOCK_CLASS'])) $plugin_options ['BLOCK_CLASS'] = DEFAULT_BLOCK_CLASS;
3408
- if (!isset ($plugin_options ['BLOCK_NUMBER_CLASS'])) $plugin_options ['BLOCK_NUMBER_CLASS'] = DEFAULT_BLOCK_NUMBER_CLASS;
3409
- if (!isset ($plugin_options ['INLINE_STYLES'])) $plugin_options ['INLINE_STYLES'] = DEFAULT_INLINE_STYLES;
3410
 
3411
- if (!isset ($plugin_options ['MINIMUM_USER_ROLE'])) $plugin_options ['MINIMUM_USER_ROLE'] = DEFAULT_MINIMUM_USER_ROLE;
3412
 
3413
- if (!isset ($plugin_options ['STICKY_WIDGET_MODE'])) $plugin_options ['STICKY_WIDGET_MODE'] = DEFAULT_STICKY_WIDGET_MODE;
3414
 
3415
- if (!isset ($plugin_options ['STICKY_WIDGET_MARGIN'])) $plugin_options ['STICKY_WIDGET_MARGIN'] = DEFAULT_STICKY_WIDGET_MARGIN;
3416
- $sticky_widget_margin = $plugin_options ['STICKY_WIDGET_MARGIN'];
3417
- if (!is_numeric ($sticky_widget_margin)) {
3418
- $sticky_widget_margin = DEFAULT_STICKY_WIDGET_MARGIN;
3419
- }
3420
- $sticky_widget_margin = intval ($sticky_widget_margin);
3421
- if ($sticky_widget_margin < 0) {
3422
- $sticky_widget_margin = 0;
3423
- }
3424
- if ($sticky_widget_margin > 999) {
3425
- $sticky_widget_margin = 999;
3426
- }
3427
- $plugin_options ['STICKY_WIDGET_MARGIN'] = $sticky_widget_margin;
3428
 
 
 
3429
 
3430
- if (!isset ($plugin_options ['PLUGIN_PRIORITY'])) $plugin_options ['PLUGIN_PRIORITY'] = DEFAULT_PLUGIN_PRIORITY;
3431
- $plugin_priority = $plugin_options ['PLUGIN_PRIORITY'];
3432
- if (!is_numeric ($plugin_priority)) {
3433
- $plugin_priority = DEFAULT_PLUGIN_PRIORITY;
3434
- }
3435
- $plugin_priority = intval ($plugin_priority);
3436
- if ($plugin_priority < 0) {
3437
- $plugin_priority = 0;
3438
- }
3439
- if ($plugin_priority > 999999) {
3440
- $plugin_priority = 999999;
3441
- }
3442
- $plugin_options ['PLUGIN_PRIORITY'] = $plugin_priority;
3443
 
 
 
3444
 
3445
  if (!isset ($plugin_options ['DYNAMIC_BLOCKS'])) $plugin_options ['DYNAMIC_BLOCKS'] = DEFAULT_DYNAMIC_BLOCKS;
3446
  if (!isset ($plugin_options ['PARAGRAPH_COUNTING_FUNCTIONS'])) $plugin_options ['PARAGRAPH_COUNTING_FUNCTIONS'] = DEFAULT_PARAGRAPH_COUNTING_FUNCTIONS;
@@ -3645,6 +3651,22 @@ function get_sticky_widget_margin () {
3645
  return ($ai_db_options [AI_OPTION_GLOBAL]['STICKY_WIDGET_MARGIN']);
3646
  }
3647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3648
  function get_plugin_priority () {
3649
  global $ai_db_options;
3650
 
@@ -4279,10 +4301,21 @@ function ai_ajax_backend () {
4279
  if ($_GET ['adsense-authorization-code'] == '') {
4280
  delete_option (AI_ADSENSE_CLIENT_IDS);
4281
  delete_option (AI_ADSENSE_AUTH_CODE);
 
4282
 
4283
  delete_transient (AI_TRANSIENT_ADSENSE_TOKEN);
4284
  delete_transient (AI_TRANSIENT_ADSENSE_ADS);
4285
- } else update_option (AI_ADSENSE_AUTH_CODE, base64_decode ($_GET ['adsense-authorization-code']));
 
 
 
 
 
 
 
 
 
 
4286
  }
4287
  }
4288
 
@@ -4397,8 +4430,9 @@ function ai_generate_extract (&$settings) {
4397
  if ($obj->get_enable_404()) $page_types []= AI_PT_404;
4398
 
4399
  $automatic_insertion = $obj->get_automatic_insertion();
 
4400
 
4401
- if ($page_types) {
4402
 
4403
  // Change insertion position to actual server-side insertion position
4404
  switch ($automatic_insertion) {
@@ -4482,7 +4516,6 @@ function ai_generate_extract (&$settings) {
4482
  $manual_widget = $obj->get_enable_widget() == AI_ENABLED;
4483
  $manual_shortcode = $obj->get_enable_manual() == AI_ENABLED;
4484
  $manual_php_function = $obj->get_enable_php_call() == AI_ENABLED;
4485
- $enabled_insertion = $obj->get_disable_insertion() == AI_DISABLED;
4486
  if ($enabled_insertion && ($automatic || ($manual_widget && in_array ($block, $widget_blocks)) || $manual_shortcode || $manual_php_function)) {
4487
  $active_blocks []= $block;
4488
  }
@@ -4982,6 +5015,8 @@ function ai_settings () {
4982
  if (isset ($_POST ['minimum-user-role'])) $options ['MINIMUM_USER_ROLE'] = filter_string ($_POST ['minimum-user-role']);
4983
  if (isset ($_POST ['sticky-widget-mode'])) $options ['STICKY_WIDGET_MODE'] = filter_option ('STICKY_WIDGET_MODE', $_POST ['sticky-widget-mode']);
4984
  if (isset ($_POST ['sticky-widget-margin'])) $options ['STICKY_WIDGET_MARGIN'] = filter_option ('STICKY_WIDGET_MARGIN', $_POST ['sticky-widget-margin']);
 
 
4985
  if (isset ($_POST ['plugin_priority'])) $options ['PLUGIN_PRIORITY'] = filter_option ('PLUGIN_PRIORITY', $_POST ['plugin_priority']);
4986
  if (isset ($_POST ['dynamic_blocks'])) $options ['DYNAMIC_BLOCKS'] = filter_option ('DYNAMIC_BLOCKS', $_POST ['dynamic_blocks']);
4987
  if (isset ($_POST ['paragraph_counting_functions'])) $options ['PARAGRAPH_COUNTING_FUNCTIONS'] = filter_option ('PARAGRAPH_COUNTING_FUNCTIONS', $_POST ['paragraph_counting_functions']);
@@ -5247,9 +5282,19 @@ function ai_adinserter ($ad_number = '', $ignore = ''){
5247
  $ai_last_check = AI_CHECK_CODE;
5248
  if ($obj->ai_getCode () == '') return "";
5249
 
 
 
 
 
 
 
 
5250
  // Last check before insertion
5251
  if (!$obj->check_and_increment_block_counter ()) return "";
5252
 
 
 
 
5253
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5254
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) != 0) return "";
5255
 
@@ -5282,7 +5327,7 @@ function adinserter ($block = '', $ignore = '') {
5282
  function ai_content_hook ($content = '') {
5283
  global $block_object, $ad_inserter_globals, $ai_db_options_extract, $ai_wp_data, $ai_last_check, $ai_total_plugin_time, $special_element_tags;
5284
 
5285
- if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_ADMIN) return;
5286
 
5287
  $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
5288
  $globals_name = AI_CONTENT_COUNTER_NAME;
@@ -5335,59 +5380,77 @@ function ai_content_hook ($content = '') {
5335
  $obj = $block_object [$block];
5336
  $obj->clear_code_cache ();
5337
 
5338
- if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0 && !$positions_inserted && $ai_wp_data [AI_WP_DEBUG_BLOCK] <= $block) {
5339
- $preview = $block_object [$ai_wp_data [AI_WP_DEBUG_BLOCK]];
5340
- $content = $preview->before_paragraph ($content, true);
5341
- $content = $preview->after_paragraph ($content, true);
5342
- $positions_inserted = true;
5343
- }
5344
 
5345
- if (!$obj->check_server_side_detection ()) continue;
5346
- if (!$obj->check_page_types_lists_users ()) continue;
5347
- if (!$obj->check_post_page_exceptions ($selected_blocks)) continue;
5348
- if (!$obj->check_filter ($ad_inserter_globals [$globals_name])) continue;
5349
- if (!$obj->check_number_of_words ($content, $content_words)) continue;
 
 
5350
 
5351
- // Deprecated
5352
- $ai_last_check = AI_CHECK_DISABLED_MANUALLY;
5353
- if ($obj->display_disabled ($content)) continue;
 
 
5354
 
5355
- $ai_last_check = AI_CHECK_INSERTION_NOT_DISABLED;
5356
- if ($obj->get_disable_insertion ()) continue;
 
5357
 
5358
- // Last check before counter check before insertion
5359
- $ai_last_check = AI_CHECK_CODE;
5360
- if ($obj->ai_getCode () == '') continue;
5361
 
5362
- // Last check before insertion
5363
- if (!$obj->check_block_counter ()) continue;
 
5364
 
5365
- $automatic_insertion = $obj->get_automatic_insertion();
 
 
 
 
5366
 
5367
- if ($automatic_insertion == AI_AUTOMATIC_INSERTION_BEFORE_PARAGRAPH) {
5368
- $ai_last_check = AI_CHECK_PARAGRAPH_COUNTING;
5369
- $content = $obj->before_paragraph ($content);
5370
- }
5371
- elseif ($automatic_insertion == AI_AUTOMATIC_INSERTION_AFTER_PARAGRAPH) {
5372
- $ai_last_check = AI_CHECK_PARAGRAPH_COUNTING;
5373
- $content = $obj->after_paragraph ($content);
5374
- }
5375
- elseif ($automatic_insertion == AI_AUTOMATIC_INSERTION_BEFORE_CONTENT) {
5376
- $obj->increment_block_counter ();
5377
 
5378
- $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5379
- if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5380
- $content = $obj->get_code_for_serverside_insertion () . $content;
5381
- $ai_last_check = AI_CHECK_INSERTED;
 
5382
  }
5383
- }
5384
- elseif ($automatic_insertion == AI_AUTOMATIC_INSERTION_AFTER_CONTENT) {
5385
- $obj->increment_block_counter ();
 
 
 
5386
 
5387
- $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5388
- if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5389
- $content = $content . $obj->get_code_for_serverside_insertion ();
5390
- $ai_last_check = AI_CHECK_INSERTED;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5391
  }
5392
  }
5393
  }
@@ -5428,13 +5491,13 @@ function ai_content_hook ($content = '') {
5428
  $content = $preview->after_paragraph ($content, true);
5429
  }
5430
 
5431
- $content = preg_replace ("/\[\[AI_BP([\d]+?)\]\]/", "<section class='$class'>BEFORE PARAGRAPH $1</section>", $content);
5432
  $content = preg_replace ("/\[\[AI_AP([\d]+?)\]\]/", "<section class='$class'>AFTER PARAGRAPH $1</section>", $content);
5433
 
5434
  $counter = $ad_inserter_globals [$globals_name];
5435
  if ($counter == 1) $counter = '';
5436
 
5437
- $content = "<section class='$class'><a class='ai-debug-left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a> BEFORE CONTENT ".$counter."<a class='ai-debug-right'>".$content_words." words</a></section>". $content;
5438
 
5439
  if ($ai_wp_data [AI_WP_AMP_PAGE]) {
5440
  $content = get_page_type_debug_info ('AMP ') . $content;
@@ -5509,9 +5572,18 @@ function ai_excerpt_hook ($content = '') {
5509
  $ai_last_check = AI_CHECK_CODE;
5510
  if ($obj->ai_getCode () == '') continue;
5511
 
 
 
 
 
 
 
5512
  // Last check before insertion
5513
  if (!$obj->check_and_increment_block_counter ()) continue;
5514
 
 
 
 
5515
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5516
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5517
 
@@ -5645,9 +5717,18 @@ function ai_comment_callback ($comment, $args, $depth) {
5645
  $ai_last_check = AI_CHECK_CODE;
5646
  if ($obj->ai_getCode () == '') continue;
5647
 
 
 
 
 
 
 
5648
  // Last check before insertion
5649
  if (!$obj->check_and_increment_block_counter ()) continue;
5650
 
 
 
 
5651
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5652
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5653
  $ad_code .= $obj->get_code_for_serverside_insertion ();
@@ -5741,9 +5822,18 @@ function ai_comment_end_callback ($comment, $args, $depth) {
5741
  $ai_last_check = AI_CHECK_CODE;
5742
  if ($obj->ai_getCode () == '') continue;
5743
 
 
 
 
 
 
 
5744
  // Last check before insertion
5745
  if (!$obj->check_and_increment_block_counter ()) continue;
5746
 
 
 
 
5747
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5748
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5749
  $ad_code .= $obj->get_code_for_serverside_insertion ();
@@ -5794,9 +5884,18 @@ function ai_comment_end_callback ($comment, $args, $depth) {
5794
  $ai_last_check = AI_CHECK_CODE;
5795
  if ($obj->ai_getCode () == '') continue;
5796
 
 
 
 
 
 
 
5797
  // Last check before insertion
5798
  if (!$obj->check_and_increment_block_counter ()) continue;
5799
 
 
 
 
5800
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5801
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5802
  $ad_code .= $obj->get_code_for_serverside_insertion ();
@@ -5887,9 +5986,18 @@ function ai_custom_hook ($action, $name, $hook_parameter = null, $hook_check = n
5887
  $ai_last_check = AI_CHECK_CODE;
5888
  if ($obj->ai_getCode () == '') continue;
5889
 
 
 
 
 
 
 
5890
  // Last check before insertion
5891
  if (!$obj->check_and_increment_block_counter ()) continue;
5892
 
 
 
 
5893
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5894
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5895
  $ad_code .= $obj->get_code_for_serverside_insertion ();
@@ -6101,9 +6209,18 @@ function ai_process_shortcode (&$block, $atts) {
6101
  $ai_last_check = AI_CHECK_CODE;
6102
  if ($obj->ai_getCode () == '') return "";
6103
 
 
 
 
 
 
 
6104
  // Last check before insertion
6105
  if (!$obj->check_and_increment_block_counter ()) return "";
6106
 
 
 
 
6107
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
6108
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
6109
  $code = $obj->get_code_for_serverside_insertion (true, false, $code_only);
@@ -6145,14 +6262,6 @@ function ai_process_shortcodes ($atts, $content, $tag) {
6145
  return $shortcode;
6146
  }
6147
 
6148
- //function process_shortcodes_lc ($atts, $content, $tag) {
6149
- // return process_shortcodes ($atts, 'adinserter');
6150
- //}
6151
-
6152
- //function process_shortcodes_uc ($atts, $content, $tag) {
6153
- // return process_shortcodes ($atts, 'ADINSERTER');
6154
- //}
6155
-
6156
 
6157
  class ai_widget extends WP_Widget {
6158
 
@@ -6341,9 +6450,18 @@ function ai_widget_draw ($args, $instance, &$block) {
6341
  return;
6342
  }
6343
 
 
 
 
 
 
 
6344
  // Last check before insertion
6345
  if (!$obj->check_and_increment_block_counter ()) return;
6346
 
 
 
 
6347
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
6348
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
6349
 
@@ -6527,17 +6645,14 @@ function ai_special_widget ($args, $instance, $block) {
6527
  echo $args ['after_widget'];
6528
  }
6529
 
6530
- function check_url_parameter_list ($url_parameters, $white_list, $server_side_check = true, $check_url_parameters = true, $check_cookies = true) {
6531
-
6532
- $parameter_list = trim ($url_parameters);
6533
-
6534
  $return = $white_list;
 
6535
 
6536
- if ($check_url_parameters) {
6537
- if ($check_cookies) {
6538
- $parameters = array_merge ($_COOKIE, $_GET);
6539
- } else $parameters = $_GET;
6540
- } else $parameters = $_COOKIE;
6541
 
6542
  foreach ($parameters as $index => $parameter) {
6543
  if (is_string ($parameter)) {
@@ -6545,15 +6660,6 @@ function check_url_parameter_list ($url_parameters, $white_list, $server_side_ch
6545
  }
6546
  }
6547
 
6548
- if ($parameter_list == AD_EMPTY_DATA || count ($parameters) == 0) {
6549
- if ($server_side_check && $check_cookies) {
6550
- return !$return;
6551
- }
6552
-
6553
- // Return true as client-side check will check cookies and decide
6554
- return true;
6555
- }
6556
-
6557
  $parameters_listed = explode (",", $parameter_list);
6558
  foreach ($parameters_listed as $index => $parameter_listed) {
6559
  if (trim ($parameter_listed) == "") unset ($parameters_listed [$index]); else
@@ -6567,12 +6673,23 @@ function check_url_parameter_list ($url_parameters, $white_list, $server_side_ch
6567
  } else if (array_key_exists ($parameter, $parameters)) return $return;
6568
  }
6569
 
6570
- if ($server_side_check && $check_cookies) {
6571
- return !$return;
6572
- }
6573
 
6574
- // Return true as client-side check will check cookies and decide
6575
- return true;
 
 
 
 
 
 
 
 
 
 
 
6576
  }
6577
 
6578
  function check_check_referer_list ($referers, $white_list) {
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
+ Version: 2.3.14
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.14 - 2018-07-14
17
+ - Simplified AdSense integration
18
+ - Added setting to define maximum number of blocks (ads) per page
19
+ - Optimized the_content filter processing
20
+ - Added setting for lazy loading offset (Pro only)
21
+ - Fix for url parameter list when using client-side dynamic blocks
22
+ - Few minor bug fixes, cosmetic changes and code improvements
23
+
24
  Ad Inserter 2.3.13 - 2018-07-11
25
  - Added support for lazy loading (Pro only)
26
  - Fix for unwanted insertions with some paragraph settings
673
  $ai_wp_data [AI_DISABLE_CACHING] = false;
674
  $ai_wp_data [AI_CLIENT_SIDE_INSERTION] = false;
675
  $ai_wp_data [AI_LAZY_LOADING] = false;
676
+ $ai_wp_data [AI_PAGE_BLOCKS] = 0;
677
 
678
  ai_load_settings ();
679
 
1115
  case AI_CHECK_DISABLED_MANUALLY: $status .= "DISABLED BY HTML COMMENT"; break;
1116
 
1117
  case AI_CHECK_MAX_INSERTIONS: $status .= "MAX INSERTIONS " . $obj->get_maximum_insertions (); break;
1118
+ case AI_CHECK_MAX_PAGE_BLOCKS: $status .= "MAX PAGE BLOCKS " . get_max_page_blocks (); break;
1119
  case AI_CHECK_FILTER: $status .= ($obj->get_inverted_filter() ? 'INVERTED ' : '') . "FILTER " . $obj->get_call_filter(); break;
1120
  case AI_CHECK_PARAGRAPH_COUNTING: $status .= "PARAGRAPH COUNTING"; break;
1121
  case AI_CHECK_MIN_NUMBER_OF_WORDS: $status .= "MIN NUMBER OF WORDS " . intval ($obj->get_minimum_words()); break;
3406
  if (function_exists ('ai_check_multisite_options_2')) ai_check_multisite_options_2 ($multisite_options);
3407
  }
3408
 
3409
+ function ai_check_limits ($value, $min, $max, $default) {
3410
+ if (!is_numeric ($value)) {
3411
+ $value = $default;
3412
+ }
3413
+ $value = intval ($value);
3414
+ if ($value < $min) {
3415
+ $value = $min;
3416
+ }
3417
+ if ($value > $max) {
3418
+ $value = $max;
3419
+ }
3420
+ return $value;
3421
+ }
3422
+
3423
  function ai_check_plugin_options ($plugin_options = array ()) {
3424
  global $version_string;
3425
 
3426
  $plugin_options ['VERSION'] = $version_string;
3427
 
3428
+ if (!isset ($plugin_options ['SYNTAX_HIGHLIGHTER_THEME'])) $plugin_options ['SYNTAX_HIGHLIGHTER_THEME'] = DEFAULT_SYNTAX_HIGHLIGHTER_THEME;
3429
 
3430
+ if (!isset ($plugin_options ['BLOCK_CLASS_NAME'])) $plugin_options ['BLOCK_CLASS_NAME'] = DEFAULT_BLOCK_CLASS_NAME;
3431
+ if (!isset ($plugin_options ['BLOCK_CLASS'])) $plugin_options ['BLOCK_CLASS'] = DEFAULT_BLOCK_CLASS;
3432
+ if (!isset ($plugin_options ['BLOCK_NUMBER_CLASS'])) $plugin_options ['BLOCK_NUMBER_CLASS'] = DEFAULT_BLOCK_NUMBER_CLASS;
3433
+ if (!isset ($plugin_options ['INLINE_STYLES'])) $plugin_options ['INLINE_STYLES'] = DEFAULT_INLINE_STYLES;
3434
 
3435
+ if (!isset ($plugin_options ['MINIMUM_USER_ROLE'])) $plugin_options ['MINIMUM_USER_ROLE'] = DEFAULT_MINIMUM_USER_ROLE;
3436
 
3437
+ if (!isset ($plugin_options ['STICKY_WIDGET_MODE'])) $plugin_options ['STICKY_WIDGET_MODE'] = DEFAULT_STICKY_WIDGET_MODE;
3438
 
3439
+ if (!isset ($plugin_options ['STICKY_WIDGET_MARGIN'])) $plugin_options ['STICKY_WIDGET_MARGIN'] = DEFAULT_STICKY_WIDGET_MARGIN;
3440
+ $plugin_options ['STICKY_WIDGET_MARGIN'] = ai_check_limits ($plugin_options ['STICKY_WIDGET_MARGIN'], 0, 999, DEFAULT_STICKY_WIDGET_MARGIN);
 
 
 
 
 
 
 
 
 
 
 
3441
 
3442
+ if (!isset ($plugin_options ['LAZY_LOADING_OFFSET'])) $plugin_options ['LAZY_LOADING_OFFSET'] = DEFAULT_LAZY_LOADING_OFFSET;
3443
+ $plugin_options ['LAZY_LOADING_OFFSET'] = ai_check_limits ($plugin_options ['LAZY_LOADING_OFFSET'], 0, 9999, DEFAULT_LAZY_LOADING_OFFSET);
3444
 
3445
+ if (!isset ($plugin_options ['MAX_PAGE_BLOCKS'])) $plugin_options ['MAX_PAGE_BLOCKS'] = DEFAULT_MAX_PAGE_BLOCKS;
3446
+ $plugin_options ['MAX_PAGE_BLOCKS'] = ai_check_limits ($plugin_options ['MAX_PAGE_BLOCKS'], 0, 9999, DEFAULT_MAX_PAGE_BLOCKS);
 
 
 
 
 
 
 
 
 
 
 
3447
 
3448
+ if (!isset ($plugin_options ['PLUGIN_PRIORITY'])) $plugin_options ['PLUGIN_PRIORITY'] = DEFAULT_PLUGIN_PRIORITY;
3449
+ $plugin_options ['PLUGIN_PRIORITY'] = ai_check_limits ($plugin_options ['PLUGIN_PRIORITY'], 0, 999999, DEFAULT_PLUGIN_PRIORITY);
3450
 
3451
  if (!isset ($plugin_options ['DYNAMIC_BLOCKS'])) $plugin_options ['DYNAMIC_BLOCKS'] = DEFAULT_DYNAMIC_BLOCKS;
3452
  if (!isset ($plugin_options ['PARAGRAPH_COUNTING_FUNCTIONS'])) $plugin_options ['PARAGRAPH_COUNTING_FUNCTIONS'] = DEFAULT_PARAGRAPH_COUNTING_FUNCTIONS;
3651
  return ($ai_db_options [AI_OPTION_GLOBAL]['STICKY_WIDGET_MARGIN']);
3652
  }
3653
 
3654
+ function get_lazy_loading_offset () {
3655
+ global $ai_db_options;
3656
+
3657
+ if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['LAZY_LOADING_OFFSET'])) $ai_db_options [AI_OPTION_GLOBAL]['LAZY_LOADING_OFFSET'] = DEFAULT_LAZY_LOADING_OFFSET;
3658
+
3659
+ return ($ai_db_options [AI_OPTION_GLOBAL]['LAZY_LOADING_OFFSET']);
3660
+ }
3661
+
3662
+ function get_max_page_blocks () {
3663
+ global $ai_db_options;
3664
+
3665
+ if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['MAX_PAGE_BLOCKS'])) $ai_db_options [AI_OPTION_GLOBAL]['MAX_PAGE_BLOCKS'] = DEFAULT_MAX_PAGE_BLOCKS;
3666
+
3667
+ return ($ai_db_options [AI_OPTION_GLOBAL]['MAX_PAGE_BLOCKS']);
3668
+ }
3669
+
3670
  function get_plugin_priority () {
3671
  global $ai_db_options;
3672
 
4301
  if ($_GET ['adsense-authorization-code'] == '') {
4302
  delete_option (AI_ADSENSE_CLIENT_IDS);
4303
  delete_option (AI_ADSENSE_AUTH_CODE);
4304
+ delete_option (AI_ADSENSE_OWN_IDS);
4305
 
4306
  delete_transient (AI_TRANSIENT_ADSENSE_TOKEN);
4307
  delete_transient (AI_TRANSIENT_ADSENSE_ADS);
4308
+ }
4309
+ elseif (base64_decode ($_GET ['adsense-authorization-code']) == 'own-ids') {
4310
+ update_option (AI_ADSENSE_OWN_IDS, '1');
4311
+
4312
+ delete_option (AI_ADSENSE_CLIENT_IDS);
4313
+ delete_option (AI_ADSENSE_AUTH_CODE);
4314
+
4315
+ delete_transient (AI_TRANSIENT_ADSENSE_TOKEN);
4316
+ delete_transient (AI_TRANSIENT_ADSENSE_ADS);
4317
+ }
4318
+ else update_option (AI_ADSENSE_AUTH_CODE, base64_decode ($_GET ['adsense-authorization-code']));
4319
  }
4320
  }
4321
 
4430
  if ($obj->get_enable_404()) $page_types []= AI_PT_404;
4431
 
4432
  $automatic_insertion = $obj->get_automatic_insertion();
4433
+ $enabled_insertion = $obj->get_disable_insertion() == AI_DISABLED;
4434
 
4435
+ if ($page_types && $enabled_insertion) {
4436
 
4437
  // Change insertion position to actual server-side insertion position
4438
  switch ($automatic_insertion) {
4516
  $manual_widget = $obj->get_enable_widget() == AI_ENABLED;
4517
  $manual_shortcode = $obj->get_enable_manual() == AI_ENABLED;
4518
  $manual_php_function = $obj->get_enable_php_call() == AI_ENABLED;
 
4519
  if ($enabled_insertion && ($automatic || ($manual_widget && in_array ($block, $widget_blocks)) || $manual_shortcode || $manual_php_function)) {
4520
  $active_blocks []= $block;
4521
  }
5015
  if (isset ($_POST ['minimum-user-role'])) $options ['MINIMUM_USER_ROLE'] = filter_string ($_POST ['minimum-user-role']);
5016
  if (isset ($_POST ['sticky-widget-mode'])) $options ['STICKY_WIDGET_MODE'] = filter_option ('STICKY_WIDGET_MODE', $_POST ['sticky-widget-mode']);
5017
  if (isset ($_POST ['sticky-widget-margin'])) $options ['STICKY_WIDGET_MARGIN'] = filter_option ('STICKY_WIDGET_MARGIN', $_POST ['sticky-widget-margin']);
5018
+ if (isset ($_POST ['lazy-loading-offset'])) $options ['LAZY_LOADING_OFFSET'] = filter_option ('LAZY_LOADING_OFFSET', $_POST ['lazy-loading-offset']);
5019
+ if (isset ($_POST ['max-page-blocks'])) $options ['MAX_PAGE_BLOCKS'] = filter_option ('MAX_PAGE_BLOCKS', $_POST ['max-page-blocks']);
5020
  if (isset ($_POST ['plugin_priority'])) $options ['PLUGIN_PRIORITY'] = filter_option ('PLUGIN_PRIORITY', $_POST ['plugin_priority']);
5021
  if (isset ($_POST ['dynamic_blocks'])) $options ['DYNAMIC_BLOCKS'] = filter_option ('DYNAMIC_BLOCKS', $_POST ['dynamic_blocks']);
5022
  if (isset ($_POST ['paragraph_counting_functions'])) $options ['PARAGRAPH_COUNTING_FUNCTIONS'] = filter_option ('PARAGRAPH_COUNTING_FUNCTIONS', $_POST ['paragraph_counting_functions']);
5282
  $ai_last_check = AI_CHECK_CODE;
5283
  if ($obj->ai_getCode () == '') return "";
5284
 
5285
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
5286
+
5287
+ if ($max_page_blocks_enabled) {
5288
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
5289
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) return "";
5290
+ }
5291
+
5292
  // Last check before insertion
5293
  if (!$obj->check_and_increment_block_counter ()) return "";
5294
 
5295
+ // Increment page block counter
5296
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
5297
+
5298
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5299
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) != 0) return "";
5300
 
5327
  function ai_content_hook ($content = '') {
5328
  global $block_object, $ad_inserter_globals, $ai_db_options_extract, $ai_wp_data, $ai_last_check, $ai_total_plugin_time, $special_element_tags;
5329
 
5330
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_ADMIN) return $content;
5331
 
5332
  $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
5333
  $globals_name = AI_CONTENT_COUNTER_NAME;
5380
  $obj = $block_object [$block];
5381
  $obj->clear_code_cache ();
5382
 
5383
+ // Process content hook only if in_the_loop or filter is set
5384
+ $filter_type = $obj->get_filter_type ();
5385
+ $process_content = in_the_loop () || (($filter_type == AI_FILTER_AUTO || $filter_type == AI_FILTER_CONTENT_PROCESSING) && trim ($obj->get_call_filter()) != '');
 
 
 
5386
 
5387
+ if ($process_content) {
5388
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0 && !$positions_inserted && $ai_wp_data [AI_WP_DEBUG_BLOCK] <= $block) {
5389
+ $preview = $block_object [$ai_wp_data [AI_WP_DEBUG_BLOCK]];
5390
+ $content = $preview->before_paragraph ($content, true);
5391
+ $content = $preview->after_paragraph ($content, true);
5392
+ $positions_inserted = true;
5393
+ }
5394
 
5395
+ if (!$obj->check_server_side_detection ()) continue;
5396
+ if (!$obj->check_page_types_lists_users ()) continue;
5397
+ if (!$obj->check_post_page_exceptions ($selected_blocks)) continue;
5398
+ if (!$obj->check_filter ($ad_inserter_globals [$globals_name])) continue;
5399
+ if (!$obj->check_number_of_words ($content, $content_words)) continue;
5400
 
5401
+ // Deprecated
5402
+ $ai_last_check = AI_CHECK_DISABLED_MANUALLY;
5403
+ if ($obj->display_disabled ($content)) continue;
5404
 
5405
+ $ai_last_check = AI_CHECK_INSERTION_NOT_DISABLED;
5406
+ if ($obj->get_disable_insertion ()) continue;
 
5407
 
5408
+ // Last check before counter check before insertion
5409
+ $ai_last_check = AI_CHECK_CODE;
5410
+ if ($obj->ai_getCode () == '') continue;
5411
 
5412
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
5413
+ if ($max_page_blocks_enabled) {
5414
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
5415
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) continue;
5416
+ }
5417
 
5418
+ // Last check before insertion
5419
+ if (!$obj->check_block_counter ()) continue;
 
 
 
 
 
 
 
 
5420
 
5421
+ $automatic_insertion = $obj->get_automatic_insertion();
5422
+
5423
+ if ($automatic_insertion == AI_AUTOMATIC_INSERTION_BEFORE_PARAGRAPH) {
5424
+ $ai_last_check = AI_CHECK_PARAGRAPH_COUNTING;
5425
+ $content = $obj->before_paragraph ($content);
5426
  }
5427
+ elseif ($automatic_insertion == AI_AUTOMATIC_INSERTION_AFTER_PARAGRAPH) {
5428
+ $ai_last_check = AI_CHECK_PARAGRAPH_COUNTING;
5429
+ $content = $obj->after_paragraph ($content);
5430
+ }
5431
+ elseif ($automatic_insertion == AI_AUTOMATIC_INSERTION_BEFORE_CONTENT) {
5432
+ $obj->increment_block_counter ();
5433
 
5434
+ // Increment page block counter
5435
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
5436
+
5437
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5438
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5439
+ $content = $obj->get_code_for_serverside_insertion () . $content;
5440
+ $ai_last_check = AI_CHECK_INSERTED;
5441
+ }
5442
+ }
5443
+ elseif ($automatic_insertion == AI_AUTOMATIC_INSERTION_AFTER_CONTENT) {
5444
+ $obj->increment_block_counter ();
5445
+
5446
+ // Increment page block counter
5447
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
5448
+
5449
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5450
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5451
+ $content = $content . $obj->get_code_for_serverside_insertion ();
5452
+ $ai_last_check = AI_CHECK_INSERTED;
5453
+ }
5454
  }
5455
  }
5456
  }
5491
  $content = $preview->after_paragraph ($content, true);
5492
  }
5493
 
5494
+ $content = preg_replace ("/\[\[AI_BP([\d]+?)=([\d]+?)\]\]/", "<section class='$class'><a class='ai-debug-left' style='visibility: hidden;'>$2 words</a>BEFORE PARAGRAPH $1<a class='ai-debug-right'>$2 words</a></section>", $content);
5495
  $content = preg_replace ("/\[\[AI_AP([\d]+?)\]\]/", "<section class='$class'>AFTER PARAGRAPH $1</section>", $content);
5496
 
5497
  $counter = $ad_inserter_globals [$globals_name];
5498
  if ($counter == 1) $counter = '';
5499
 
5500
+ $content = "<section class='$class'><a class='ai-debug-left' style='visibility: hidden;'>".$content_words." words</a> BEFORE CONTENT ".$counter."<a class='ai-debug-right'>".$content_words." words</a></section>". $content;
5501
 
5502
  if ($ai_wp_data [AI_WP_AMP_PAGE]) {
5503
  $content = get_page_type_debug_info ('AMP ') . $content;
5572
  $ai_last_check = AI_CHECK_CODE;
5573
  if ($obj->ai_getCode () == '') continue;
5574
 
5575
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
5576
+ if ($max_page_blocks_enabled) {
5577
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
5578
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) continue;
5579
+ }
5580
+
5581
  // Last check before insertion
5582
  if (!$obj->check_and_increment_block_counter ()) continue;
5583
 
5584
+ // Increment page block counter
5585
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
5586
+
5587
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5588
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5589
 
5717
  $ai_last_check = AI_CHECK_CODE;
5718
  if ($obj->ai_getCode () == '') continue;
5719
 
5720
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
5721
+ if ($max_page_blocks_enabled) {
5722
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
5723
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) continue;
5724
+ }
5725
+
5726
  // Last check before insertion
5727
  if (!$obj->check_and_increment_block_counter ()) continue;
5728
 
5729
+ // Increment page block counter
5730
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
5731
+
5732
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5733
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5734
  $ad_code .= $obj->get_code_for_serverside_insertion ();
5822
  $ai_last_check = AI_CHECK_CODE;
5823
  if ($obj->ai_getCode () == '') continue;
5824
 
5825
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
5826
+ if ($max_page_blocks_enabled) {
5827
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
5828
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) continue;
5829
+ }
5830
+
5831
  // Last check before insertion
5832
  if (!$obj->check_and_increment_block_counter ()) continue;
5833
 
5834
+ // Increment page block counter
5835
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
5836
+
5837
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5838
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5839
  $ad_code .= $obj->get_code_for_serverside_insertion ();
5884
  $ai_last_check = AI_CHECK_CODE;
5885
  if ($obj->ai_getCode () == '') continue;
5886
 
5887
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
5888
+ if ($max_page_blocks_enabled) {
5889
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
5890
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) continue;
5891
+ }
5892
+
5893
  // Last check before insertion
5894
  if (!$obj->check_and_increment_block_counter ()) continue;
5895
 
5896
+ // Increment page block counter
5897
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
5898
+
5899
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
5900
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
5901
  $ad_code .= $obj->get_code_for_serverside_insertion ();
5986
  $ai_last_check = AI_CHECK_CODE;
5987
  if ($obj->ai_getCode () == '') continue;
5988
 
5989
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
5990
+ if ($max_page_blocks_enabled) {
5991
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
5992
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) continue;
5993
+ }
5994
+
5995
  // Last check before insertion
5996
  if (!$obj->check_and_increment_block_counter ()) continue;
5997
 
5998
+ // Increment page block counter
5999
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
6000
+
6001
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
6002
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
6003
  $ad_code .= $obj->get_code_for_serverside_insertion ();
6209
  $ai_last_check = AI_CHECK_CODE;
6210
  if ($obj->ai_getCode () == '') return "";
6211
 
6212
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
6213
+ if ($max_page_blocks_enabled) {
6214
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
6215
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) return "";
6216
+ }
6217
+
6218
  // Last check before insertion
6219
  if (!$obj->check_and_increment_block_counter ()) return "";
6220
 
6221
+ // Increment page block counter
6222
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
6223
+
6224
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
6225
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
6226
  $code = $obj->get_code_for_serverside_insertion (true, false, $code_only);
6262
  return $shortcode;
6263
  }
6264
 
 
 
 
 
 
 
 
 
6265
 
6266
  class ai_widget extends WP_Widget {
6267
 
6450
  return;
6451
  }
6452
 
6453
+ $max_page_blocks_enabled = $obj->get_max_page_blocks_enabled ();
6454
+ if ($max_page_blocks_enabled) {
6455
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
6456
+ if ($ai_wp_data [AI_PAGE_BLOCKS] >= get_max_page_blocks ()) return;
6457
+ }
6458
+
6459
  // Last check before insertion
6460
  if (!$obj->check_and_increment_block_counter ()) return;
6461
 
6462
+ // Increment page block counter
6463
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
6464
+
6465
  $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
6466
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
6467
 
6645
  echo $args ['after_widget'];
6646
  }
6647
 
6648
+ function check_url_parameter_cookie_list ($list, $white_list, $parameters, &$found) {
6649
+ $parameter_list = trim ($list);
 
 
6650
  $return = $white_list;
6651
+ $found = true;
6652
 
6653
+ if ($parameter_list == AD_EMPTY_DATA || count ($parameters) == 0) {
6654
+ return !$return;
6655
+ }
 
 
6656
 
6657
  foreach ($parameters as $index => $parameter) {
6658
  if (is_string ($parameter)) {
6660
  }
6661
  }
6662
 
 
 
 
 
 
 
 
 
 
6663
  $parameters_listed = explode (",", $parameter_list);
6664
  foreach ($parameters_listed as $index => $parameter_listed) {
6665
  if (trim ($parameter_listed) == "") unset ($parameters_listed [$index]); else
6673
  } else if (array_key_exists ($parameter, $parameters)) return $return;
6674
  }
6675
 
6676
+ $found = false;
6677
+ return !$return;
6678
+ }
6679
 
6680
+
6681
+ function check_url_parameter_list ($url_parameters, $white_list, &$found) {
6682
+ return check_url_parameter_cookie_list ($url_parameters, $white_list, $_GET, $found);
6683
+ }
6684
+
6685
+ function check_cookie_list ($url_parameters, $white_list) {
6686
+ $dummy = false;
6687
+ return check_url_parameter_cookie_list ($url_parameters, $white_list, $_COOKIE, $dummy);
6688
+ }
6689
+
6690
+ function check_url_parameter_and_cookie_list ($url_parameters, $white_list) {
6691
+ $dummy = false;
6692
+ return check_url_parameter_cookie_list ($url_parameters, $white_list, array_merge ($_COOKIE, $_GET), $dummy);
6693
  }
6694
 
6695
  function check_check_referer_list ($referers, $white_list) {
class.php CHANGED
@@ -34,6 +34,7 @@ abstract class ai_BaseCodeBlock {
34
  $this->additional_code_before = '';
35
  $this->additional_code_after = '';
36
  $this->counters = '';
 
37
 
38
  $this->labels = new ai_block_labels ();
39
 
@@ -483,6 +484,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
483
  $this->wp_options [AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES] = AI_DISABLED;
484
  $this->wp_options [AI_OPTION_ENABLE_AJAX] = AI_ENABLED;
485
  $this->wp_options [AI_OPTION_DISABLE_CACHING] = AI_DISABLED;
 
486
  $this->wp_options [AI_OPTION_ENABLE_FEED] = AI_DISABLED;
487
  $this->wp_options [AI_OPTION_ENABLED_ON_WHICH_PAGES] = AI_NO_INDIVIDUAL_EXCEPTIONS;
488
  $this->wp_options [AI_OPTION_ENABLED_ON_WHICH_POSTS] = AI_NO_INDIVIDUAL_EXCEPTIONS;
@@ -1415,6 +1417,11 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1415
  return $option;
1416
  }
1417
 
 
 
 
 
 
1418
  // Used for shortcodes
1419
  public function get_enable_manual (){
1420
  $option = isset ($this->wp_options [AI_OPTION_ENABLE_MANUAL]) ? $this->wp_options [AI_OPTION_ENABLE_MANUAL] : AI_DISABLED;
@@ -1618,6 +1625,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1618
  // Clear the codes for cases when the code block is called more than once
1619
  $this->additional_code_before = '';
1620
  $this->additional_code_after = '';
 
1621
 
1622
  // Code for ad label, close button
1623
  $additional_code = '';
@@ -1905,15 +1913,15 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1905
  $referers = base64_encode ($referers_raw);
1906
  $referer_list_type = $this->get_ad_domain_list_type ();
1907
 
1908
- if ($url_parameters != '' || $url_parameter_list_type == AD_WHITE_LIST || $referers != '' || $referer_list_type == AD_WHITE_LIST) {
1909
  switch ($dynamic_blocks) {
1910
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1911
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1912
  if ($url_parameter_list_type == AD_BLACK_LIST) $url_parameter_list_type = 'B'; else $url_parameter_list_type = 'W';
1913
  if ($referer_list_type == AD_BLACK_LIST) $referer_list_type = 'B'; else $referer_list_type = 'W';
1914
 
1915
- 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 = '';
1916
- if ($referers != '' || $referer_list_type == 'W') $referer_attributes = "referer-list='$referers' referer-list-type='$referer_list_type'"; else $referer_attributes = '';
1917
 
1918
  $this->client_side_list_detection = true;
1919
 
@@ -1931,8 +1939,8 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1931
  }
1932
 
1933
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
1934
- 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 = '';
1935
- if ($referers != '' || $referer_list_type == 'W') $referer_attributes_dbg = "referers='$referers_raw' type='$referer_list_type'"; else $referer_attributes_dbg = '';
1936
 
1937
  $debug_ip = new ai_block_labels ('ai-debug-lists');
1938
  $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;
@@ -1946,9 +1954,11 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1946
  $this->w3tc_code .= ' if ($ai_enabled) $ai_enabled = check_check_referer_list (base64_decode (\''.$referers.'\'), '.($referer_list_type == AD_WHITE_LIST ? 'true':'false').');';
1947
  } elseif ($referer_list_type == AD_WHITE_LIST) $this->w3tc_code .= ' $ai_enabled = false;';
1948
 
1949
- if ($url_parameters != '') {
1950
- $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);';
1951
- } elseif ($url_parameter_list_type == AD_WHITE_LIST) $this->w3tc_code .= ' $ai_enabled = false;';
 
 
1952
 
1953
  $processed_code = '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1954
  $processed_code .= $this->w3tc_code.' if ($ai_enabled) echo $ai_code;';
@@ -2252,8 +2262,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2252
  }
2253
  }
2254
 
2255
- // echo "##1#", $this->w3tc_code, "###", $this->w3tc_code2, "##1#";
2256
-
2257
  return $code;
2258
  }
2259
 
@@ -2357,8 +2365,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2357
  $serverside_insertion_code = str_replace ('[#AI_CODE#]', $block_code, $serverside_insertion_code);
2358
  }
2359
 
2360
- // echo "##2#", $this->w3tc_code, "###", $this->w3tc_code2, "##2#";
2361
-
2362
  return $serverside_insertion_code;
2363
  }
2364
 
@@ -2970,7 +2976,8 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2970
 
2971
 
2972
  // Prepare $paragraph_end_positions
2973
- if (!$position_preview && $position_text == '') {
 
2974
  if (!isset ($paragraph_end_positions)) {
2975
  $paragraph_end_positions = array ();
2976
  get_paragraph_end_positions ($content, $multibyte, $paragraph_positions, $paragraph_start_strings, $paragraph_end_positions, $dummy);
@@ -3317,26 +3324,42 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
3317
 
3318
  $real_positions = array ();
3319
  foreach ($positions as $position_index) $real_positions []= $position_index >= 0 ? $position_index + 1 : '*';
3320
- if ($debug_processing && $this->number != 0) ai_log ('BLOCK ' . $this->number . ' INSERTION POSITIONS: ' . implode (', ', $real_positions));
3321
 
3322
  $min_paragraphs = intval ($this->get_paragraph_number_minimum());
 
3323
 
3324
  foreach ($paragraph_positions as $counter => $paragraph_position) {
3325
- if ($position_preview) $inserted_code = "[[AI_BP".($counter + 1)."]]";
 
 
 
 
 
 
 
 
3326
  elseif (!empty ($positions) && in_array ($counter, $positions) && $this->check_block_counter ()) {
3327
 
3328
  $inserted = false;
3329
 
3330
  $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
3331
  if (count ($paragraph_positions) >= $min_paragraphs) {
3332
- $this->increment_block_counter ();
3333
-
3334
- $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3335
- if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3336
- $inserted_code = $this->get_code_for_serverside_insertion ();
3337
- $this->clear_code_cache ();
3338
- $ai_last_check = AI_CHECK_INSERTED;
3339
- $inserted = true;
 
 
 
 
 
 
 
3340
  }
3341
  }
3342
  if ($debug_processing) ai_log (ai_log_block_status ($this->number, $ai_last_check));
@@ -4026,9 +4049,10 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
4026
 
4027
  $real_positions = array ();
4028
  foreach ($positions as $position_index) $real_positions []= $position_index >= 0 ? $position_index + 1 : '*';
4029
- if ($debug_processing && $this->number != 0) ai_log ('BLOCK ' . $this->number . ' INSERTION POSITIONS: ' . implode (', ', $real_positions));
4030
 
4031
  $min_paragraphs = intval ($this->get_paragraph_number_minimum());
 
4032
 
4033
  foreach ($paragraph_positions as $counter => $paragraph_position) {
4034
  if ($position_preview) $inserted_code = "[[AI_AP".($counter + 1)."]]";
@@ -4038,14 +4062,21 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
4038
 
4039
  $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
4040
  if (count ($paragraph_positions) >= $min_paragraphs) {
4041
- $this->increment_block_counter ();
4042
-
4043
- $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
4044
- if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
4045
- $inserted_code = $this->get_code_for_serverside_insertion ();
4046
- $this->clear_code_cache ();
4047
- $ai_last_check = AI_CHECK_INSERTED;
4048
- $inserted = true;
 
 
 
 
 
 
 
4049
  }
4050
  }
4051
 
@@ -4454,48 +4485,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
4454
  return !$return;
4455
  }
4456
 
4457
- function check_url_parameters ($server_side_check) {
4458
-
4459
- // global $ai_wp_data;
4460
-
4461
- // $parameter_list = trim ($this->get_url_parameter_list());
4462
- // $parameter_list_type = $this->get_url_parameter_list_type();
4463
-
4464
- // if ($parameter_list_type == AD_BLACK_LIST) $return = false; else $return = true;
4465
-
4466
- // 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])) {
4467
- // $parameters = array_merge ($_COOKIE, $_GET);
4468
- // } else $parameters = array_merge ($_GET);
4469
-
4470
- // if ($parameter_list == AD_EMPTY_DATA || count ($parameters) == 0) {
4471
- // return !$return;
4472
- // }
4473
-
4474
- // $parameters_listed = explode (",", $parameter_list);
4475
- // foreach ($parameters_listed as $index => $parameter_listed) {
4476
- // if (trim ($parameter_listed) == "") unset ($parameters_listed [$index]); else
4477
- // $parameters_listed [$index] = trim ($parameter_listed);
4478
- // }
4479
-
4480
- //// print_r ($parameter_listed);
4481
- //// echo "<br />\n";
4482
- //// echo " parameters: <br />\n";
4483
- //// print_r ($_GET);
4484
- //// echo ' listed parameters: ' . $parameter_list, "\n";
4485
- //// echo "<br />\n";
4486
-
4487
- // foreach ($parameters_listed as $parameter) {
4488
- // if (strpos ($parameter, "=") !== false) {
4489
- // $parameter_value = explode ("=", $parameter);
4490
- // if (array_key_exists ($parameter_value [0], $parameters) && $parameters [$parameter_value [0]] == $parameter_value [1]) return $return;
4491
- // } else if (array_key_exists ($parameter, $parameters)) return $return;
4492
- // }
4493
-
4494
- // return !$return;
4495
-
4496
- return check_url_parameter_list ($this->get_url_parameter_list(), $this->get_url_parameter_list_type() == AD_WHITE_LIST, true, true, $server_side_check);
4497
- }
4498
-
4499
  function check_scheduling () {
4500
 
4501
  switch ($this->get_scheduling()) {
@@ -4677,7 +4666,17 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
4677
  $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]);
4678
 
4679
  $ai_last_check = AI_CHECK_URL_PARAMETER;
4680
- if (!$this->check_url_parameters ($server_side_check)) return false;
 
 
 
 
 
 
 
 
 
 
4681
 
4682
  if ($server_side_check) {
4683
  $ai_last_check = AI_CHECK_REFERER;
34
  $this->additional_code_before = '';
35
  $this->additional_code_after = '';
36
  $this->counters = '';
37
+ $this->client_side_cookie_check = false;
38
 
39
  $this->labels = new ai_block_labels ();
40
 
484
  $this->wp_options [AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES] = AI_DISABLED;
485
  $this->wp_options [AI_OPTION_ENABLE_AJAX] = AI_ENABLED;
486
  $this->wp_options [AI_OPTION_DISABLE_CACHING] = AI_DISABLED;
487
+ $this->wp_options [AI_OPTION_MAX_PAGE_BLOCKS_ENABLED] = AI_DISABLED;
488
  $this->wp_options [AI_OPTION_ENABLE_FEED] = AI_DISABLED;
489
  $this->wp_options [AI_OPTION_ENABLED_ON_WHICH_PAGES] = AI_NO_INDIVIDUAL_EXCEPTIONS;
490
  $this->wp_options [AI_OPTION_ENABLED_ON_WHICH_POSTS] = AI_NO_INDIVIDUAL_EXCEPTIONS;
1417
  return $option;
1418
  }
1419
 
1420
+ public function get_max_page_blocks_enabled (){
1421
+ $option = isset ($this->wp_options [AI_OPTION_MAX_PAGE_BLOCKS_ENABLED]) ? $this->wp_options [AI_OPTION_MAX_PAGE_BLOCKS_ENABLED] : AI_DISABLED;
1422
+ return $option;
1423
+ }
1424
+
1425
  // Used for shortcodes
1426
  public function get_enable_manual (){
1427
  $option = isset ($this->wp_options [AI_OPTION_ENABLE_MANUAL]) ? $this->wp_options [AI_OPTION_ENABLE_MANUAL] : AI_DISABLED;
1625
  // Clear the codes for cases when the code block is called more than once
1626
  $this->additional_code_before = '';
1627
  $this->additional_code_after = '';
1628
+ $this->w3tc_code = '';
1629
 
1630
  // Code for ad label, close button
1631
  $additional_code = '';
1913
  $referers = base64_encode ($referers_raw);
1914
  $referer_list_type = $this->get_ad_domain_list_type ();
1915
 
1916
+ if ($this->client_side_cookie_check && ($url_parameters != '' || $url_parameter_list_type == AD_WHITE_LIST) || $referers != '' || $referer_list_type == AD_WHITE_LIST) {
1917
  switch ($dynamic_blocks) {
1918
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW:
1919
  case AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT:
1920
  if ($url_parameter_list_type == AD_BLACK_LIST) $url_parameter_list_type = 'B'; else $url_parameter_list_type = 'W';
1921
  if ($referer_list_type == AD_BLACK_LIST) $referer_list_type = 'B'; else $referer_list_type = 'W';
1922
 
1923
+ if ($this->client_side_cookie_check && ($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 = '';
1924
+ if ( $referers != '' || $referer_list_type == 'W') $referer_attributes = "referer-list='$referers' referer-list-type='$referer_list_type'"; else $referer_attributes = '';
1925
 
1926
  $this->client_side_list_detection = true;
1927
 
1939
  }
1940
 
1941
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
1942
+ if ($this->client_side_cookie_check && ($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 = '';
1943
+ if ( $referers != '' || $referer_list_type == 'W') $referer_attributes_dbg = "referers='$referers_raw' type='$referer_list_type'"; else $referer_attributes_dbg = '';
1944
 
1945
  $debug_ip = new ai_block_labels ('ai-debug-lists');
1946
  $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;
1954
  $this->w3tc_code .= ' if ($ai_enabled) $ai_enabled = check_check_referer_list (base64_decode (\''.$referers.'\'), '.($referer_list_type == AD_WHITE_LIST ? 'true':'false').');';
1955
  } elseif ($referer_list_type == AD_WHITE_LIST) $this->w3tc_code .= ' $ai_enabled = false;';
1956
 
1957
+ if ($this->client_side_cookie_check) {
1958
+ if ($url_parameters != '') {
1959
+ $this->w3tc_code .= ' if ($ai_enabled) $ai_enabled = check_cookie_list (base64_decode (\''.$url_parameters.'\'), '.($url_parameter_list_type == AD_WHITE_LIST ? 'true':'false').');';
1960
+ } elseif ($url_parameter_list_type == AD_WHITE_LIST) $this->w3tc_code .= ' $ai_enabled = false;';
1961
+ }
1962
 
1963
  $processed_code = '<!-- mfunc '.W3TC_DYNAMIC_SECURITY.' -->';
1964
  $processed_code .= $this->w3tc_code.' if ($ai_enabled) echo $ai_code;';
2262
  }
2263
  }
2264
 
 
 
2265
  return $code;
2266
  }
2267
 
2365
  $serverside_insertion_code = str_replace ('[#AI_CODE#]', $block_code, $serverside_insertion_code);
2366
  }
2367
 
 
 
2368
  return $serverside_insertion_code;
2369
  }
2370
 
2976
 
2977
 
2978
  // Prepare $paragraph_end_positions
2979
+ // if (!$position_preview && $position_text == '') {
2980
+ if ($position_preview || $position_text == '') {
2981
  if (!isset ($paragraph_end_positions)) {
2982
  $paragraph_end_positions = array ();
2983
  get_paragraph_end_positions ($content, $multibyte, $paragraph_positions, $paragraph_start_strings, $paragraph_end_positions, $dummy);
3324
 
3325
  $real_positions = array ();
3326
  foreach ($positions as $position_index) $real_positions []= $position_index >= 0 ? $position_index + 1 : '*';
3327
+ if ($debug_processing && $this->number != 0 && count ($real_positions) != 0) ai_log ('BLOCK ' . $this->number . ' INSERTION POSITIONS: ' . implode (', ', $real_positions));
3328
 
3329
  $min_paragraphs = intval ($this->get_paragraph_number_minimum());
3330
+ $max_page_blocks_enabled = $this->get_max_page_blocks_enabled ();
3331
 
3332
  foreach ($paragraph_positions as $counter => $paragraph_position) {
3333
+ if ($position_preview) {
3334
+ if ($multibyte) {
3335
+ $paragraph_code = mb_substr ($content, $paragraph_position, $paragraph_end_positions [$counter] - $paragraph_position + 1);
3336
+ } else {
3337
+ $paragraph_code = substr ($content, $paragraph_position, $paragraph_end_positions [$counter] - $paragraph_position + 1);
3338
+ }
3339
+ $paragraph_words = number_of_words ($paragraph_code);
3340
+ $inserted_code = "[[AI_BP".($counter + 1)."=".$paragraph_words."]]";
3341
+ }
3342
  elseif (!empty ($positions) && in_array ($counter, $positions) && $this->check_block_counter ()) {
3343
 
3344
  $inserted = false;
3345
 
3346
  $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
3347
  if (count ($paragraph_positions) >= $min_paragraphs) {
3348
+
3349
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
3350
+ if (!$max_page_blocks_enabled || $ai_wp_data [AI_PAGE_BLOCKS] < get_max_page_blocks ()) {
3351
+ $this->increment_block_counter ();
3352
+
3353
+ // Increment page block counter
3354
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
3355
+
3356
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
3357
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
3358
+ $inserted_code = $this->get_code_for_serverside_insertion ();
3359
+ $this->clear_code_cache ();
3360
+ $ai_last_check = AI_CHECK_INSERTED;
3361
+ $inserted = true;
3362
+ }
3363
  }
3364
  }
3365
  if ($debug_processing) ai_log (ai_log_block_status ($this->number, $ai_last_check));
4049
 
4050
  $real_positions = array ();
4051
  foreach ($positions as $position_index) $real_positions []= $position_index >= 0 ? $position_index + 1 : '*';
4052
+ if ($debug_processing && $this->number != 0 && count ($real_positions) != 0) ai_log ('BLOCK ' . $this->number . ' INSERTION POSITIONS: ' . implode (', ', $real_positions));
4053
 
4054
  $min_paragraphs = intval ($this->get_paragraph_number_minimum());
4055
+ $max_page_blocks_enabled = $this->get_max_page_blocks_enabled ();
4056
 
4057
  foreach ($paragraph_positions as $counter => $paragraph_position) {
4058
  if ($position_preview) $inserted_code = "[[AI_AP".($counter + 1)."]]";
4062
 
4063
  $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
4064
  if (count ($paragraph_positions) >= $min_paragraphs) {
4065
+
4066
+ $ai_last_check = AI_CHECK_MAX_PAGE_BLOCKS;
4067
+ if (!$max_page_blocks_enabled || $ai_wp_data [AI_PAGE_BLOCKS] < get_max_page_blocks ()) {
4068
+ $this->increment_block_counter ();
4069
+
4070
+ // Increment page block counter
4071
+ if ($max_page_blocks_enabled) $ai_wp_data [AI_PAGE_BLOCKS] ++;
4072
+
4073
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
4074
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
4075
+ $inserted_code = $this->get_code_for_serverside_insertion ();
4076
+ $this->clear_code_cache ();
4077
+ $ai_last_check = AI_CHECK_INSERTED;
4078
+ $inserted = true;
4079
+ }
4080
  }
4081
  }
4082
 
4485
  return !$return;
4486
  }
4487
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4488
  function check_scheduling () {
4489
 
4490
  switch ($this->get_scheduling()) {
4666
  $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]);
4667
 
4668
  $ai_last_check = AI_CHECK_URL_PARAMETER;
4669
+ switch ($server_side_check) {
4670
+ case true:
4671
+ if (!check_url_parameter_and_cookie_list ($this->get_url_parameter_list(), $this->get_url_parameter_list_type() == AD_WHITE_LIST)) return false;
4672
+ default:
4673
+ $url_parameter_found = false;
4674
+ $url_parameter_list_pass = check_url_parameter_list ($this->get_url_parameter_list(), $this->get_url_parameter_list_type() == AD_WHITE_LIST, $url_parameter_found);
4675
+
4676
+ if ($url_parameter_found && !$url_parameter_list_pass) return false;
4677
+
4678
+ if (!$url_parameter_found) $this->client_side_cookie_check = true;
4679
+ }
4680
 
4681
  if ($server_side_check) {
4682
  $ai_last_check = AI_CHECK_REFERER;
constants.php CHANGED
@@ -9,6 +9,8 @@ define ('AI_OPTION_GLOBAL', 'global');
9
  define ('AI_OPTION_EXTRACT', 'extract');
10
  define ('AI_ADSENSE_CLIENT_IDS', 'ai-adsense-client-ids');
11
  define ('AI_ADSENSE_AUTH_CODE', 'ai-adsense-auth-code');
 
 
12
 
13
  if (!defined ('AD_INSERTER_PLUGIN_DIR'))
14
  define ('AD_INSERTER_PLUGIN_DIR', plugin_dir_path (__FILE__));
@@ -24,7 +26,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.13');
28
 
29
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
30
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
@@ -68,6 +70,7 @@ define ('AI_OPTION_ENABLE_AJAX', 'enable_ajax');
68
  define ('AI_OPTION_ENABLE_FEED', 'enable_feed');
69
  define ('AI_OPTION_ENABLE_404', 'enable_404');
70
  define ('AI_OPTION_DISABLE_CACHING', 'disable_caching');
 
71
  define ('AI_OPTION_BLOCK_NAME', 'name');
72
  define ('AI_OPTION_AUTOMATIC_INSERTION', 'display_type');
73
  define ('AI_OPTION_PARAGRAPH_NUMBER', 'paragraph_number');
@@ -602,6 +605,8 @@ define ('DEFAULT_INLINE_STYLES', AI_ENABLED);
602
  define ('DEFAULT_MINIMUM_USER_ROLE', 'administrator');
603
  define ('DEFAULT_STICKY_WIDGET_MODE', AI_STICKY_WIDGET_MODE_CSS);
604
  define ('DEFAULT_STICKY_WIDGET_MARGIN', 15);
 
 
605
  define ('DEFAULT_PLUGIN_PRIORITY', 99999);
606
  define ('DEFAULT_DYNAMIC_BLOCKS', AI_DYNAMIC_BLOCKS_SERVER_SIDE);
607
  define ('DEFAULT_PARAGRAPH_COUNTING_FUNCTIONS', AI_STANDARD_PARAGRAPH_COUNTING_FUNCTIONS);
@@ -739,6 +744,7 @@ define ('AI_CHECK_PARAGRAPH_COUNTING', 29);
739
  define ('AI_CHECK_ENABLED_PHP', 30);
740
  define ('AI_CHECK_ENABLED_SHORTCODE', 31);
741
  define ('AI_CHECK_PARAGRAPHS_MIN_NUMBER', 32);
 
742
 
743
  define ('AI_CHECK_DEBUG_NO_INSERTION', 33);
744
  define ('AI_CHECK_PARAGRAPH_TAGS', 34);
@@ -817,6 +823,7 @@ define ('AI_TRIGGER_ELEMENTS', 34);
817
  define ('AI_CLIENT_SIDE_ROTATION', 35);
818
  define ('AI_CLIENT_SIDE_CSS', 36);
819
  define ('AI_LAZY_LOADING', 37);
 
820
 
821
  define ('AI_CONTEXT_NONE', 0);
822
  define ('AI_CONTEXT_CONTENT', 1);
@@ -855,6 +862,13 @@ define ('AI_DEBUG_NO_INSERTION', 0x10);
855
  define ('AI_DEBUG_AD_BLOCKING', 0x20);
856
  define ('AI_DEBUG_AD_BLOCKING_STATUS', 0x40);
857
 
 
 
 
 
 
 
 
858
  if (!defined ('AD_INSERTER_BLOCKS'))
859
  define ('AD_INSERTER_BLOCKS', 16);
860
 
9
  define ('AI_OPTION_EXTRACT', 'extract');
10
  define ('AI_ADSENSE_CLIENT_IDS', 'ai-adsense-client-ids');
11
  define ('AI_ADSENSE_AUTH_CODE', 'ai-adsense-auth-code');
12
+ define ('AI_ADSENSE_OWN_IDS', 'ai-adsense-own-ids');
13
+ define ('AI_ADSENSE_API_IDS', true);
14
 
15
  if (!defined ('AD_INSERTER_PLUGIN_DIR'))
16
  define ('AD_INSERTER_PLUGIN_DIR', plugin_dir_path (__FILE__));
26
  define ('AD_INSERTER_NAME', 'Ad Inserter');
27
 
28
  if (!defined( 'AD_INSERTER_VERSION'))
29
+ define ('AD_INSERTER_VERSION', '2.3.14');
30
 
31
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
32
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
70
  define ('AI_OPTION_ENABLE_FEED', 'enable_feed');
71
  define ('AI_OPTION_ENABLE_404', 'enable_404');
72
  define ('AI_OPTION_DISABLE_CACHING', 'disable_caching');
73
+ define ('AI_OPTION_MAX_PAGE_BLOCKS_ENABLED', 'max_page_blocks');
74
  define ('AI_OPTION_BLOCK_NAME', 'name');
75
  define ('AI_OPTION_AUTOMATIC_INSERTION', 'display_type');
76
  define ('AI_OPTION_PARAGRAPH_NUMBER', 'paragraph_number');
605
  define ('DEFAULT_MINIMUM_USER_ROLE', 'administrator');
606
  define ('DEFAULT_STICKY_WIDGET_MODE', AI_STICKY_WIDGET_MODE_CSS);
607
  define ('DEFAULT_STICKY_WIDGET_MARGIN', 15);
608
+ define ('DEFAULT_LAZY_LOADING_OFFSET', 600);
609
+ define ('DEFAULT_MAX_PAGE_BLOCKS', 3);
610
  define ('DEFAULT_PLUGIN_PRIORITY', 99999);
611
  define ('DEFAULT_DYNAMIC_BLOCKS', AI_DYNAMIC_BLOCKS_SERVER_SIDE);
612
  define ('DEFAULT_PARAGRAPH_COUNTING_FUNCTIONS', AI_STANDARD_PARAGRAPH_COUNTING_FUNCTIONS);
744
  define ('AI_CHECK_ENABLED_PHP', 30);
745
  define ('AI_CHECK_ENABLED_SHORTCODE', 31);
746
  define ('AI_CHECK_PARAGRAPHS_MIN_NUMBER', 32);
747
+ define ('AI_CHECK_MAX_PAGE_BLOCKS', 33);
748
 
749
  define ('AI_CHECK_DEBUG_NO_INSERTION', 33);
750
  define ('AI_CHECK_PARAGRAPH_TAGS', 34);
823
  define ('AI_CLIENT_SIDE_ROTATION', 35);
824
  define ('AI_CLIENT_SIDE_CSS', 36);
825
  define ('AI_LAZY_LOADING', 37);
826
+ define ('AI_PAGE_BLOCKS', 38);
827
 
828
  define ('AI_CONTEXT_NONE', 0);
829
  define ('AI_CONTEXT_CONTENT', 1);
862
  define ('AI_DEBUG_AD_BLOCKING', 0x20);
863
  define ('AI_DEBUG_AD_BLOCKING_STATUS', 0x40);
864
 
865
+ if (defined ('AI_ADSENSE_API_IDS')) {
866
+ if (!defined ('AI_CI_STRING')) {
867
+ define ('AI_CI_STRING', 'MzUwNTk3MTU2NDMwLWJzdWU1ODdmbzFjdTU4NDk1Z3B2amoxaHBnYWJ1OGpsLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29t');
868
+ define ('AI_CS_STRING', 'eFMwZ2I1bzNWVmtRZ29RRGpEOVl6Yk96');
869
+ }
870
+ }
871
+
872
  if (!defined ('AD_INSERTER_BLOCKS'))
873
  define ('AD_INSERTER_BLOCKS', 16);
874
 
css/ad-inserter.css CHANGED
@@ -1,5 +1,5 @@
1
  #ai-data {
2
- font-family: "2.3.13"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
1
  #ai-data {
2
+ font-family: "2.3.14"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
includes/adsense-api.php CHANGED
@@ -3,7 +3,16 @@
3
  //ini_set ('display_errors', 1);
4
  //error_reporting (E_ALL);
5
 
6
- if (($adsense_client_ids = get_option (AI_ADSENSE_CLIENT_IDS)) !== false) {
 
 
 
 
 
 
 
 
 
7
  define ('AI_ADSENSE_CLIENT_ID', $adsense_client_ids ['ID']);
8
  define ('AI_ADSENSE_CLIENT_SECRET', $adsense_client_ids ['SECRET']);
9
  }
@@ -106,7 +115,6 @@ class adsense_api {
106
  $this->authenticate();
107
 
108
  if ($this->isTokenValid ()) {
109
-
110
  $adsense_service = $this->getAdSenseService();
111
 
112
  $adsense_adsense_accounts = $adsense_service->accounts;
3
  //ini_set ('display_errors', 1);
4
  //error_reporting (E_ALL);
5
 
6
+ // GPT
7
+ // define ('AI_ADSENSE_CLIENT_ID', '607114800573.apps.googleusercontent.com');
8
+ // define ('AI_ADSENSE_CLIENT_SECRET', '2muX2P9FHRNtm6BURa49t1z6');
9
+ // define ('AI_ADSENSE_DEVELOPER_KEY', 'AIzaSyCDZtqhLeAp1XM-xS52nzQ7NwnrOH0UE2U');
10
+
11
+ if (defined ('AI_CI_STRING') && get_option (AI_ADSENSE_OWN_IDS) === false) {
12
+ define ('AI_ADSENSE_CLIENT_ID', base64_decode (AI_CI_STRING));
13
+ define ('AI_ADSENSE_CLIENT_SECRET', base64_decode (AI_CS_STRING));
14
+ }
15
+ elseif (($adsense_client_ids = get_option (AI_ADSENSE_CLIENT_IDS)) !== false) {
16
  define ('AI_ADSENSE_CLIENT_ID', $adsense_client_ids ['ID']);
17
  define ('AI_ADSENSE_CLIENT_SECRET', $adsense_client_ids ['SECRET']);
18
  }
115
  $this->authenticate();
116
 
117
  if ($this->isTokenValid ()) {
 
118
  $adsense_service = $this->getAdSenseService();
119
 
120
  $adsense_adsense_accounts = $adsense_service->accounts;
includes/js/ai-lists.js CHANGED
@@ -24,7 +24,6 @@ jQuery (function ($) {
24
  ai_list_blocks.each (function () {
25
 
26
  var enable_block = true;
27
- var referers_processed = false;
28
 
29
  var found = false;
30
 
@@ -62,7 +61,6 @@ jQuery (function ($) {
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) {
@@ -71,7 +69,7 @@ jQuery (function ($) {
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
 
24
  ai_list_blocks.each (function () {
25
 
26
  var enable_block = true;
 
27
 
28
  var found = false;
29
 
61
 
62
  if (ai_debug) console.log ("AI LISTS list found", found);
63
  if (ai_debug) console.log ("AI LISTS list pass", enable_block);
 
64
  }
65
 
66
  if (enable_block) {
69
  var parameter_list_array = atob (parameter_list).split (",");
70
  var parameter_list_type = $(this).attr ("parameter-list-type");
71
 
72
+ if (ai_debug) console.log ('');
73
  if (ai_debug) console.log ("AI LISTS cookies: ", cookies);
74
  if (ai_debug) console.log ("AI LISTS parameter list:", atob (parameter_list), parameter_list_type);
75
 
includes/js/ai-lists.min.js CHANGED
@@ -1,7 +1,7 @@
1
  jQuery(function($){function getHostName(url){var match=url.match(/:\/\/(.[^/:]+)/i);if(match!=null&&match.length>1&&typeof match[1]==="string"&&match[1].length>0)return match[1];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");if(ai_list_blocks.length)ai_list_blocks.each(function(){var enable_block=
2
- 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,function(index,list_referer){if(list_referer=="")return true;
3
- if(list_referer=="#"){if(referrer==""){found=true;return false}}else if(list_referer==referrer){found=true;return false}});switch(referers_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block);referers_processed=true}if(enable_block){var parameter_list=$(this).attr("parameter-list");if(typeof parameter_list!="undefined"){var parameter_list_array=
4
- atob(parameter_list).split(",");var parameter_list_type=$(this).attr("parameter-list-type");if(ai_debug&&referers_processed)console.log("");if(ai_debug)console.log("AI LISTS cookies: ",cookies);if(ai_debug)console.log("AI LISTS parameter list:",atob(parameter_list),parameter_list_type);var found=false;$.each(parameter_list_array,function(index,list_parameter){if(list_parameter.indexOf("=")!=-1){if(cookies.indexOf(list_parameter)!=-1){found=true;return false}}else cookies.forEach(function(cookie){var cookie_data=
5
- cookie.split("=");if(list_parameter==cookie_data[0]){found=true;return false}})});switch(parameter_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block)}}$(this).css({"visibility":"","position":"","width":"","height":"","z-index":""}).removeClass("ai-list-data");var block_wrapping_div=$(this).closest("div.ai-list-block");block_wrapping_div.css({"visibility":"",
6
- "position":"","z-index":""}).removeClass("ai-list-block");block_wrapping_div.find(".ai-debug-name.ai-list-info").text(referrer);block_wrapping_div.find(".ai-debug-name.ai-list-status").text(enable_block?"VISIBLE":"HIDDEN");if(!enable_block){$(this).hide();block_wrapping_div.removeAttr("data-ai")}else if(typeof $(this).data("code")!="undefined"){var block_code=atob($(this).data("code"));$(this).append(block_code);if(!ai_debug)$(this).attr("data-code","");if(typeof aiLazyLoading=="function")$("div.ai-lazy",
7
- this).each(function(index,element){aiLazyLoading({lazyClass:"ai-lazy",lazyElement:this.element})})}})};$(document).ready(function($){setTimeout(function(){ai_process_lists()},5)})});
1
  jQuery(function($){function getHostName(url){var match=url.match(/:\/\/(.[^/:]+)/i);if(match!=null&&match.length>1&&typeof match[1]==="string"&&match[1].length>0)return match[1];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");if(ai_list_blocks.length)ai_list_blocks.each(function(){var enable_block=
2
+ true;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,function(index,list_referer){if(list_referer=="")return true;if(list_referer=="#"){if(referrer==
3
+ ""){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)}if(enable_block){var parameter_list=$(this).attr("parameter-list");if(typeof parameter_list!="undefined"){var parameter_list_array=atob(parameter_list).split(",");var parameter_list_type=
4
+ $(this).attr("parameter-list-type");if(ai_debug)console.log("");if(ai_debug)console.log("AI LISTS cookies: ",cookies);if(ai_debug)console.log("AI LISTS parameter list:",atob(parameter_list),parameter_list_type);var found=false;$.each(parameter_list_array,function(index,list_parameter){if(list_parameter.indexOf("=")!=-1){if(cookies.indexOf(list_parameter)!=-1){found=true;return false}}else cookies.forEach(function(cookie){var cookie_data=cookie.split("=");if(list_parameter==cookie_data[0]){found=
5
+ true;return false}})});switch(parameter_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block)}}$(this).css({"visibility":"","position":"","width":"","height":"","z-index":""}).removeClass("ai-list-data");var block_wrapping_div=$(this).closest("div.ai-list-block");block_wrapping_div.css({"visibility":"","position":"","z-index":""}).removeClass("ai-list-block");
6
+ block_wrapping_div.find(".ai-debug-name.ai-list-info").text(referrer);block_wrapping_div.find(".ai-debug-name.ai-list-status").text(enable_block?"VISIBLE":"HIDDEN");if(!enable_block){$(this).hide();block_wrapping_div.removeAttr("data-ai")}else if(typeof $(this).data("code")!="undefined"){var block_code=atob($(this).data("code"));$(this).append(block_code);if(!ai_debug)$(this).attr("data-code","");if(typeof aiLazyLoading=="function")$("div.ai-lazy",this).each(function(index,element){aiLazyLoading({lazyClass:"ai-lazy",
7
+ lazyElement:this.element})})}})};$(document).ready(function($){setTimeout(function(){ai_process_lists()},5)})});
js/ad-inserter.js CHANGED
@@ -1,4 +1,4 @@
1
- var javascript_version = "2.3.13";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
@@ -3420,6 +3420,15 @@ jQuery(document).ready(function($) {
3420
  });
3421
  });
3422
 
 
 
 
 
 
 
 
 
 
3423
  return;
3424
  } else
3425
 
@@ -3435,6 +3444,8 @@ jQuery(document).ready(function($) {
3435
  data_container.text ('Loading...');
3436
 
3437
  if ($(this).hasClass ('clear-adsense')) authorization_code = '';
 
 
3438
 
3439
  update_adsense_authorization (authorization_code);
3440
  });
1
+ var javascript_version = "2.3.14";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
3420
  });
3421
  });
3422
 
3423
+ $(".authorize-adsense", data_container).click (function () {
3424
+
3425
+ $('#adsense-list-controls').show ();
3426
+ data_container.text ('Loading...');
3427
+
3428
+ authorization_code = '';
3429
+ update_adsense_authorization (authorization_code);
3430
+ });
3431
+
3432
  return;
3433
  } else
3434
 
3444
  data_container.text ('Loading...');
3445
 
3446
  if ($(this).hasClass ('clear-adsense')) authorization_code = '';
3447
+ if ($(this).hasClass ('own-ids')) authorization_code = 'own-ids';
3448
+
3449
 
3450
  update_adsense_authorization (authorization_code);
3451
  });
readme.txt CHANGED
@@ -1,4 +1,4 @@
1
- === Ad Inserter - WordPress Ads Management with AdSense Header Integration ===
2
 
3
  Contributors: spacetime
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4
@@ -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.12
10
  License: GPLv3
11
 
12
  Insert and manage ads: Amazon, Google AdSense ads, banner rotation, sticky widget ads, AMP, PHP, HTML, CSS, Javascript, tracking, footer, header code
@@ -244,7 +244,7 @@ Support the advancement of this plugin:
244
  1. Go to Wordpress Plugins menu, click Add New button
245
  2. Search for `ad inserter`
246
  3. Click 'Install Now'
247
- 4. Activate Ad Inserter on the Plugin dashboard
248
 
249
  = Uploading plugin file =
250
 
@@ -252,14 +252,15 @@ Support the advancement of this plugin:
252
  2. Click Upload Plugin
253
  3. Select `ad-inserter.zip` from your computer
254
  4. Click 'Install Now'
255
- 5. Activate Ad Inserter in the Plugin dashboard
256
 
257
  = Using FTP =
258
 
259
  1. Download `ad-inserter.zip`
260
  2. Extract `ad-inserter` directory to your computer
261
- 3. Upload `ad-inserter` directory to the `/wp-content/plugins/` directory
262
- 4. Activate Ad Inserter in the Plugin dashboard
 
263
 
264
  **Ad Inserter Pro Installation**
265
 
@@ -431,7 +432,7 @@ amzn_assoc_linkid = "cf1873f027a57f63cede634cfd444bea";
431
  </script>
432
  <script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>`
433
 
434
- Use your own tracking id! Please note `[adinserter data='smart_tag']` as default search phrase. This makes this widget contextual. It will show products related to the tags for this post.
435
 
436
  You can also use <a href="https://codex.wordpress.org/Custom_Fields" target="_blank">custom fields</a> to make the widget contextual. For example, if you define in posts custom field named `amazon-keyword` you can use `[adinserter custom-field='amazon-keyword']' for `amzn_assoc_default_search_phrase` variable.
437
 
@@ -671,6 +672,14 @@ AD CODE RIGHT
671
 
672
  == Changelog ==
673
 
 
 
 
 
 
 
 
 
674
  = 2.3.13 =
675
  - Added support for lazy loading (Pro only)
676
  - Fix for unwanted insertions with some paragraph settings
@@ -757,6 +766,14 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
757
 
758
  == Upgrade Notice ==
759
 
 
 
 
 
 
 
 
 
760
  = 2.3.13 =
761
  Added support for lazy loading (Pro only);
762
  Fix for unwanted insertions with some paragraph settings;
1
+ === Ad Inserter - WordPress Ads with AdSense Header Integration ===
2
 
3
  Contributors: spacetime
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4
6
  Requires at least: 4.0
7
  Tested up to: 4.9
8
  Requires PHP: 5.6
9
+ Stable tag: 2.3.13
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
244
  1. Go to Wordpress Plugins menu, click Add New button
245
  2. Search for `ad inserter`
246
  3. Click 'Install Now'
247
+ 4. Activate Ad Inserter on the Plugins dashboard
248
 
249
  = Uploading plugin file =
250
 
252
  2. Click Upload Plugin
253
  3. Select `ad-inserter.zip` from your computer
254
  4. Click 'Install Now'
255
+ 5. Activate Ad Inserter on the Plugins dashboard
256
 
257
  = Using FTP =
258
 
259
  1. Download `ad-inserter.zip`
260
  2. Extract `ad-inserter` directory to your computer
261
+ 3. Make sure `ad-inserter` directory contains plugin files and not another `ad-inserter` directory inside
262
+ 4. Upload `ad-inserter` directory to the `/wp-content/plugins/` directory
263
+ 5. Activate Ad Inserter on the Plugins dashboard
264
 
265
  **Ad Inserter Pro Installation**
266
 
432
  </script>
433
  <script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>`
434
 
435
+ Use your own tracking id! Please note `[adinserter data='smart-tag']` as default search phrase. This makes this widget contextual. It will show products related to the tags for this post.
436
 
437
  You can also use <a href="https://codex.wordpress.org/Custom_Fields" target="_blank">custom fields</a> to make the widget contextual. For example, if you define in posts custom field named `amazon-keyword` you can use `[adinserter custom-field='amazon-keyword']' for `amzn_assoc_default_search_phrase` variable.
438
 
672
 
673
  == Changelog ==
674
 
675
+ = 2.3.14 =
676
+ - Simplified AdSense integration
677
+ - Added setting to define maximum number of blocks (ads) per page
678
+ - Optimized the_content filter processing
679
+ - Added setting for lazy loading offset (Pro only)
680
+ - Fix for url parameter list when using client-side dynamic blocks
681
+ - Few minor bug fixes, cosmetic changes and code improvements
682
+
683
  = 2.3.13 =
684
  - Added support for lazy loading (Pro only)
685
  - Fix for unwanted insertions with some paragraph settings
766
 
767
  == Upgrade Notice ==
768
 
769
+ = 2.3.14 =
770
+ Simplified AdSense integration;
771
+ Added setting to define maximum number of blocks (ads) per page;
772
+ Optimized the_content filter processing;
773
+ Added setting for lazy loading offset (Pro only);
774
+ Fix for url parameter list when using client-side dynamic blocks;
775
+ Few minor bug fixes, cosmetic changes and code improvements
776
+
777
  = 2.3.13 =
778
  Added support for lazy loading (Pro only);
779
  Fix for unwanted insertions with some paragraph settings;
settings.php CHANGED
@@ -426,6 +426,7 @@ function generate_settings_form (){
426
  $obj->get_enable_ajax () != AI_ENABLED ||
427
  $obj->get_enable_404 () == AI_ENABLED ||
428
  $obj->get_enable_feed () == AI_ENABLED ||
 
429
  $obj->get_disable_caching ();
430
 
431
  $word_count_options =
@@ -1681,9 +1682,14 @@ function generate_settings_form (){
1681
  </select>
1682
  </td>
1683
  <td>
1684
- Max <input type="text" style="width: 32px;" name="<?php echo AI_OPTION_MAXIMUM_INSERTIONS, WP_FORM_FIELD_POSTFIX, $block; ?>" default="<?php echo $default->get_maximum_insertions (); ?>" value="<?php echo $obj->get_maximum_insertions (); ?>" size="1" maxlength="3" title="Empty or 0 means no limit" /> insertions
1685
  </td>
1686
- <td style="width: 50%">
 
 
 
 
 
1687
  <span style="float: right;">
1688
  <input type="hidden" name="<?php echo AI_OPTION_DISABLE_CACHING, WP_FORM_FIELD_POSTFIX, $block; ?>" value="0" />
1689
  <input id="disable-caching-<?php echo $block; ?>" type="checkbox" name="<?php echo AI_OPTION_DISABLE_CACHING, WP_FORM_FIELD_POSTFIX, $block; ?>" value="1" default="<?php echo $default->get_disable_caching (); ?>" <?php if ($obj->get_disable_caching () == AI_ENABLED) echo 'checked '; ?> />
@@ -1994,6 +2000,14 @@ function generate_settings_form (){
1994
  <input type="text" name="ad-label" style="width: 100%;" value="<?php echo get_ad_label (); ?>" default="<?php echo DEFAULT_AD_TITLE; ?>" size="60" maxlength="500" />
1995
  </td>
1996
  </tr>
 
 
 
 
 
 
 
 
1997
 
1998
  <?php if (function_exists ('ai_general_settings_2')) ai_general_settings_2 (); ?>
1999
 
@@ -2962,7 +2976,6 @@ function adsense_list () {
2962
 
2963
  $show_all_ad_units = isset ($_GET ["all"]) && $_GET ["all"];
2964
  ?>
2965
-
2966
  <table id="ai-adsense-ad-units-table" class="exceptions" cellspacing=0 cellpadding=0 style="width: 100%;">
2967
  <thead>
2968
  <tr>
@@ -3025,25 +3038,44 @@ function adsense_list () {
3025
  <div id="adsense-data" style="display: none;" data-publisher-id="<?php echo $publisher_id; ?>"></div>
3026
 
3027
  <?php
3028
- } else echo "<div style='margin: 10px 0 0 20px;'>$error</div>";
 
 
3029
 
 
 
 
 
 
 
3030
  }
3031
 
3032
  elseif (defined ('AI_ADSENSE_CLIENT_ID')) {
3033
  $adsense = new adsense_api();
 
3034
  ?>
3035
  <table class="responsive-table" cellspacing=0 cellpadding=0 style="width: 100%;">
3036
  <tbody>
3037
  <tr>
3038
  <td colspan="2" style="white-space: inherit;">
3039
  <div class="rounded" style="margin: 0;">
 
 
 
3040
  <h2 style="margin: 5px 0; float: left;"><strong><?php echo AD_INSERTER_NAME; ?></strong> AdSense Integration - Step 2</h2>
 
3041
  <a href="https://www.google.com/adsense/login" class="simple-link" style="float: right;" target="_blank" title="Google AdSense Home"><img src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ga-logo.png" style="margin: 3px 0 -4px 0;"/></a>
3042
  <div style="clear: both;"></div>
3043
  </div>
 
 
 
 
 
3044
  <p style="text-align: justify;">Now you can authorize <?php echo AD_INSERTER_NAME; ?> to access your AdSense account. Click on the <strong>Get Authorization Code</strong> button to open a new window where you can allow access.
3045
  When you get the code copy it to the field below and click on the button <strong>Authorize</strong>.</p>
3046
  <p style="text-align: justify;">If you get error <strong>invalid client</strong> click on the button <strong>Clear and return to Step 1</strong> to re-enter Client ID and Client Secret.</p>
 
3047
  </td>
3048
  </tr>
3049
  <tr>
@@ -3060,7 +3092,11 @@ function adsense_list () {
3060
  </tr>
3061
  <tr>
3062
  <td>
 
 
 
3063
  <button type="button" class="ai-top-button authorize-adsense clear-adsense" style="display: none; float: left; width: 162px; outline-color: transparent;">Clear and return to Step 1</button>
 
3064
  </td>
3065
  <td>
3066
  <button type="button" class="ai-top-button authorize-adsense" style="display: none; float: right; width: 162px; outline-color: transparent;">Authorize</button>
@@ -3131,7 +3167,12 @@ function adsense_list () {
3131
  <td>&nbsp;</td>
3132
  </tr>
3133
  <tr>
3134
- <td></td>
 
 
 
 
 
3135
  <td>
3136
  <button type="button" id="save-client-ids" class="ai-top-button" style="display: none; float: right; width: 162px; outline-color: transparent;">Save</button>
3137
  </td>
@@ -3454,6 +3495,7 @@ function sidebar_pro () {
3454
  <li><a href="https://adinserter.pro/code-editing#ad-rotation" class="simple-link" target="_blank">Ad rotation</a> (works also with caching)</li>
3455
  <li>Ad impression and click <a href="https://adinserter.pro/tracking" class="simple-link" target="_blank">tracking</a> (works also with Javascript ads like AdSense)</li>
3456
  <li>Support for <a href="https://adinserter.pro/tracking#ab-testing" class="simple-link" target="_blank">A/B testing</a></li>
 
3457
  <li>Support for ads on <a href="http://adinserter.pro/settings#amp" class="simple-link" target="_blank">AMP pages</a></li>
3458
  <li>Support for contextual <a href="https://adinserter.pro/settings#amazon" class="simple-link" target="_blank">Amazon Native Shopping Ads</a> (responsive)</li>
3459
  <li>Custom CSS class name for wrapping divs to avoid ad blockers</li>
426
  $obj->get_enable_ajax () != AI_ENABLED ||
427
  $obj->get_enable_404 () == AI_ENABLED ||
428
  $obj->get_enable_feed () == AI_ENABLED ||
429
+ $obj->get_max_page_blocks_enabled () ||
430
  $obj->get_disable_caching ();
431
 
432
  $word_count_options =
1682
  </select>
1683
  </td>
1684
  <td>
1685
+ Max <input type="text" style="width: 32px;" name="<?php echo AI_OPTION_MAXIMUM_INSERTIONS, WP_FORM_FIELD_POSTFIX, $block; ?>" default="<?php echo $default->get_maximum_insertions (); ?>" value="<?php echo $obj->get_maximum_insertions (); ?>" size="1" maxlength="3" title="Maximum number of insertion of this block. Empty or 0 means no limit" /> insertions
1686
  </td>
1687
+ <td>
1688
+ <input type="hidden" name="<?php echo AI_OPTION_MAX_PAGE_BLOCKS_ENABLED, WP_FORM_FIELD_POSTFIX, $block; ?>" value="0" />
1689
+ <input id="max-page-blocks-<?php echo $block; ?>" type="checkbox" name="<?php echo AI_OPTION_MAX_PAGE_BLOCKS_ENABLED, WP_FORM_FIELD_POSTFIX, $block; ?>" value="1" title="Count this block for Max blocks per page limit (defined on the tab &#9881; / tab General)" default="<?php echo $default->get_max_page_blocks_enabled (); ?>" <?php if ($obj->get_max_page_blocks_enabled () == AI_ENABLED) echo 'checked '; ?> />
1690
+ <label for="max-page-blocks-<?php echo $block; ?>" title="Count this block for Max blocks per page limit (defined on the tab &#9881; / tab General)">Max blocks per page</label>
1691
+ </td>
1692
+ <td style="width: 30%">
1693
  <span style="float: right;">
1694
  <input type="hidden" name="<?php echo AI_OPTION_DISABLE_CACHING, WP_FORM_FIELD_POSTFIX, $block; ?>" value="0" />
1695
  <input id="disable-caching-<?php echo $block; ?>" type="checkbox" name="<?php echo AI_OPTION_DISABLE_CACHING, WP_FORM_FIELD_POSTFIX, $block; ?>" value="1" default="<?php echo $default->get_disable_caching (); ?>" <?php if ($obj->get_disable_caching () == AI_ENABLED) echo 'checked '; ?> />
2000
  <input type="text" name="ad-label" style="width: 100%;" value="<?php echo get_ad_label (); ?>" default="<?php echo DEFAULT_AD_TITLE; ?>" size="60" maxlength="500" />
2001
  </td>
2002
  </tr>
2003
+ <tr>
2004
+ <td>
2005
+ Max blocks per page
2006
+ </td>
2007
+ <td>
2008
+ <input type="text" name="max-page-blocks" value="<?php echo get_max_page_blocks (); ?>" default="<?php echo DEFAULT_MAX_PAGE_BLOCKS; ?>" title="Maximum number of inserted blocks per page. You need to enable Max page insertions (button Misc / tab Insertion) to count block for this limit." size="6" maxlength="4" />
2009
+ </td>
2010
+ </tr>
2011
 
2012
  <?php if (function_exists ('ai_general_settings_2')) ai_general_settings_2 (); ?>
2013
 
2976
 
2977
  $show_all_ad_units = isset ($_GET ["all"]) && $_GET ["all"];
2978
  ?>
 
2979
  <table id="ai-adsense-ad-units-table" class="exceptions" cellspacing=0 cellpadding=0 style="width: 100%;">
2980
  <thead>
2981
  <tr>
3038
  <div id="adsense-data" style="display: none;" data-publisher-id="<?php echo $publisher_id; ?>"></div>
3039
 
3040
  <?php
3041
+ } else {
3042
+ echo
3043
+ "<div style='margin: 10px 0 0 20px;'>$error</div>";
3044
 
3045
+ if (strpos ($error, 'unauthorized_client') !== false) {
3046
+ echo "<div style='margin-top: 10px; border: 1px solid #ddd; border-radius: 5px; padding: 10px;'>Please <strong>clear authorization</strong> with the button ",
3047
+ '<span class="list-button lb-size-16 ui-icon ui-icon-power" style="display: inline-block; margin-bottom: -3px;"></span>',
3048
+ " above and once again authorize access to your AdSense account.</div>";
3049
+ }
3050
+ }
3051
  }
3052
 
3053
  elseif (defined ('AI_ADSENSE_CLIENT_ID')) {
3054
  $adsense = new adsense_api();
3055
+ $adsense_ids = defined ('AI_CI_STRING') && get_option (AI_ADSENSE_OWN_IDS) === false;
3056
  ?>
3057
  <table class="responsive-table" cellspacing=0 cellpadding=0 style="width: 100%;">
3058
  <tbody>
3059
  <tr>
3060
  <td colspan="2" style="white-space: inherit;">
3061
  <div class="rounded" style="margin: 0;">
3062
+ <?php if ($adsense_ids): ?>
3063
+ <h2 style="margin: 5px 0; float: left;"><strong><?php echo AD_INSERTER_NAME; ?></strong> AdSense Integration</h2>
3064
+ <?php else: ?>
3065
  <h2 style="margin: 5px 0; float: left;"><strong><?php echo AD_INSERTER_NAME; ?></strong> AdSense Integration - Step 2</h2>
3066
+ <?php endif; ?>
3067
  <a href="https://www.google.com/adsense/login" class="simple-link" style="float: right;" target="_blank" title="Google AdSense Home"><img src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ga-logo.png" style="margin: 3px 0 -4px 0;"/></a>
3068
  <div style="clear: both;"></div>
3069
  </div>
3070
+ <?php if ($adsense_ids): ?>
3071
+ <p style="text-align: justify;">Authorize <?php echo AD_INSERTER_NAME; ?> to access your AdSense account. Click on the <strong>Get Authorization Code</strong> button to open a new window where you can allow access.
3072
+ When you get the code copy it to the field below and click on the button <strong>Authorize</strong>.</p>
3073
+ <p style="text-align: justify;">If you get error, can't access ad units or would like to use own Google API IDs click on the button <strong>Use own API IDs</strong> to enter Client ID and Client Secret.</p>
3074
+ <?php else: ?>
3075
  <p style="text-align: justify;">Now you can authorize <?php echo AD_INSERTER_NAME; ?> to access your AdSense account. Click on the <strong>Get Authorization Code</strong> button to open a new window where you can allow access.
3076
  When you get the code copy it to the field below and click on the button <strong>Authorize</strong>.</p>
3077
  <p style="text-align: justify;">If you get error <strong>invalid client</strong> click on the button <strong>Clear and return to Step 1</strong> to re-enter Client ID and Client Secret.</p>
3078
+ <?php endif; ?>
3079
  </td>
3080
  </tr>
3081
  <tr>
3092
  </tr>
3093
  <tr>
3094
  <td>
3095
+ <?php if ($adsense_ids): ?>
3096
+ <button type="button" class="ai-top-button authorize-adsense own-ids" style="display: none; float: left; width: 162px; outline-color: transparent;">Use own API IDs</button>
3097
+ <?php else: ?>
3098
  <button type="button" class="ai-top-button authorize-adsense clear-adsense" style="display: none; float: left; width: 162px; outline-color: transparent;">Clear and return to Step 1</button>
3099
+ <?php endif; ?>
3100
  </td>
3101
  <td>
3102
  <button type="button" class="ai-top-button authorize-adsense" style="display: none; float: right; width: 162px; outline-color: transparent;">Authorize</button>
3167
  <td>&nbsp;</td>
3168
  </tr>
3169
  <tr>
3170
+ <td>
3171
+ <?php if (defined ('AI_ADSENSE_API_IDS') && defined ('AI_CI_STRING')): ?>
3172
+ <button type="button" class="ai-top-button authorize-adsense clear-adsense" style="display: none; float: left; width: 162px; outline-color: transparent;">Use default API IDs</button>
3173
+ <?php else: ?>
3174
+ <?php endif; ?>
3175
+ </td>
3176
  <td>
3177
  <button type="button" id="save-client-ids" class="ai-top-button" style="display: none; float: right; width: 162px; outline-color: transparent;">Save</button>
3178
  </td>
3495
  <li><a href="https://adinserter.pro/code-editing#ad-rotation" class="simple-link" target="_blank">Ad rotation</a> (works also with caching)</li>
3496
  <li>Ad impression and click <a href="https://adinserter.pro/tracking" class="simple-link" target="_blank">tracking</a> (works also with Javascript ads like AdSense)</li>
3497
  <li>Support for <a href="https://adinserter.pro/tracking#ab-testing" class="simple-link" target="_blank">A/B testing</a></li>
3498
+ <li>Support for <a href="https://adinserter.pro/documentation#lazy-loading" class="simple-link" target="_blank">lazy loading</a></li>
3499
  <li>Support for ads on <a href="http://adinserter.pro/settings#amp" class="simple-link" target="_blank">AMP pages</a></li>
3500
  <li>Support for contextual <a href="https://adinserter.pro/settings#amazon" class="simple-link" target="_blank">Amazon Native Shopping Ads</a> (responsive)</li>
3501
  <li>Custom CSS class name for wrapping divs to avoid ad blockers</li>