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

Version Description

  • Redesigned user interface
  • Added many debugging tools for easier troubleshooting
  • New feature: Code preview tool with visual CSS editor
  • New feature: Label inserted blocks
  • New feature: Show available positions for automatic insertion
  • New feature: Show HTML tags in posts/static pages
  • New feature: Log Ad Inserter processing
  • Improved loading speed of the settings page
  • Improved block insertion processing speed
  • Added support to avoid inserion near images, headers and other elements
  • Added option to avoid insertion in feeds
  • Added option to display code blocks only to administrators
  • Added option for publishig date check for display positions Before/After Content
  • Added option for server-side device check for header and footer code
  • Added option for maximum page/post words
  • Added option for maximum paragraph words
  • Added option to black/white-list post IDs
  • Added option to black/white-list url query parameters
  • Added warning if the settings page is blocked by ad blocker
  • Added warning if old cached version of javascript is loaded on the settings page
  • Added support for multisite installations to disable settings, widgets and exceptions on network sites (Pro only)
  • Block names can be edited by clicking on the name
  • Filters now work also on posts and single pages
  • CSS code for client-side detection moved to inline CSS
  • Bug fix: Minimum user roles for exception editing was not calculated properly
  • Bug fix: Server-side detection checkbox was not saved properly
  • Many other minor bug fixes, code improvements and cosmetic changes
Download this release

Release Info

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

Code changes from version 1.7.0 to 2.0.0

ad-inserter.php CHANGED
@@ -1,8 +1,8 @@
1
  <?php
2
  /*
3
  Plugin Name: Ad Inserter
4
- Version: 1.7.0
5
- Description: Insert any ad code into Wordpress. Perfect for AdSense or Amazon ads. Simply enter any HTML, Javascript or PHP code and select where and how you want to display it.
6
  Author: Igor Funa
7
  Author URI: http://igorfuna.com/
8
  Plugin URI: http://tinymonitor.com/ad-inserter
@@ -11,6 +11,35 @@ Plugin URI: http://tinymonitor.com/ad-inserter
11
  /*
12
  Change Log
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  Ad Inserter 1.7.0 - 16 August 2016
15
  - Bug fix: Shortcodes did not ignore post/static page exceptions
16
  - Slightly redesigned user interface
@@ -217,9 +246,6 @@ Ad Inserter 1.0.0 - 14/11/2010
217
  */
218
 
219
 
220
- //ini_set('display_errors',1);
221
- //error_reporting (E_ALL);
222
-
223
  if (!defined ('AD_INSERTER_PLUGIN_DIR'))
224
  define ('AD_INSERTER_PLUGIN_DIR', plugin_dir_path (__FILE__));
225
 
@@ -231,16 +257,18 @@ if (version_compare ($wp_version, "4.0", "<")) {
231
  exit ($exit_msg);
232
  }
233
 
 
 
234
  //include required files
235
  require_once AD_INSERTER_PLUGIN_DIR.'class.php';
236
  require_once AD_INSERTER_PLUGIN_DIR.'constants.php';
237
  require_once AD_INSERTER_PLUGIN_DIR.'settings.php';
238
  require_once AD_INSERTER_PLUGIN_DIR.'preview.php';
239
 
240
- $ad_interter_globals = array ();
241
-
242
- // Load options
243
- ai_load_options ();
244
 
245
  $version_array = explode (".", AD_INSERTER_VERSION);
246
  $version_string = "";
@@ -248,20 +276,44 @@ foreach ($version_array as $number) {
248
  $version_string .= sprintf ("%02d", $number);
249
  }
250
 
251
- $server_side_detection = false;
252
- $client_side_detection = false;
 
 
 
 
 
 
 
 
 
 
253
 
 
254
  $block_object = array ();
 
 
 
 
 
 
 
 
 
255
  for ($counter = 1; $counter <= AD_INSERTER_BLOCKS; $counter ++) {
256
- $obj = new ai_Block ($counter);
257
- $obj->load_options ($counter);
258
- $block_object [$counter] = $obj;
259
 
260
- if ($obj->get_detection_server_side()) $server_side_detection = true;
261
- if ($obj->get_detection_client_side ()) $client_side_detection = true;
262
  }
263
 
264
- if ($server_side_detection) {
 
 
 
 
 
 
265
  require_once AD_INSERTER_PLUGIN_DIR.'includes/Mobile_Detect.php';
266
 
267
  $detect = new ai_Mobile_Detect;
@@ -277,33 +329,399 @@ if ($server_side_detection) {
277
  define ('AI_DESKTOP', true);
278
  }
279
 
280
- $plugin_priority = get_plugin_priority ();
 
 
281
 
282
- // Set hooks
283
  add_action ('admin_menu', 'ai_admin_menu_hook');
284
- add_filter ('the_content', 'ai_content_hook', $plugin_priority);
285
- add_filter ('the_excerpt', 'ai_excerpt_hook', $plugin_priority);
286
- add_action ('loop_start', 'ai_loop_start_hook');
287
- add_action ('loop_end', 'ai_loop_end_hook');
288
  add_action ('init', 'ai_init_hook');
289
  //add_action ('admin_notices', 'ai_admin_notice_hook');
290
- add_action ('wp_head', 'ai_wp_head_hook');
291
- add_action ('wp_footer', 'ai_wp_footer_hook');
 
 
 
 
 
 
 
 
 
 
292
  add_action ('widgets_init', 'ai_widgets_init_hook');
293
  add_action ('add_meta_boxes', 'ai_add_meta_box_hook');
294
  add_action ('save_post', 'ai_save_meta_box_data_hook');
295
 
296
  if (function_exists ('ai_hooks')) ai_hooks ();
297
 
298
- if ($client_side_detection) {
299
- add_action ('wp_enqueue_scripts', 'ai_enqueue_scripts_hook');
300
- }
301
 
302
  add_filter ('plugin_action_links_'.plugin_basename (__FILE__), 'ai_plugin_action_links');
303
  add_filter ('plugin_row_meta', 'ai_set_plugin_meta', 10, 2);
304
  add_action ('wp_ajax_ai_preview', 'ai_preview');
305
  add_action ('wp_ajax_nopriv_ai_preview', 'ai_preview');
306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  function ai_init_hook() {
308
  global $block_object;
309
 
@@ -313,7 +731,9 @@ function ai_init_hook() {
313
  function ai_admin_menu_hook () {
314
  global $ai_settings_page;
315
 
316
- $ai_settings_page = add_submenu_page ('options-general.php', AD_INSERTER_TITLE.' Options', AD_INSERTER_TITLE, 'manage_options', basename(__FILE__), 'ai_settings');
 
 
317
  add_action ('admin_enqueue_scripts', 'ai_admin_enqueue_scripts');
318
  }
319
 
@@ -322,18 +742,75 @@ function ai_admin_enqueue_scripts ($hook_suffix) {
322
  global $ai_settings_page;
323
 
324
  if ($hook_suffix == $ai_settings_page) {
325
- wp_enqueue_script ('ad-inserter-js', plugins_url ('js/ad-inserter.js', __FILE__), array ('jquery', 'jquery-ui-tabs', 'jquery-ui-button', 'jquery-ui-tooltip', 'jquery-ui-dialog'), AD_INSERTER_VERSION);
326
- wp_enqueue_style ('ad-inserter-jquery-ui', plugins_url ('css/jquery-ui-1.10.3.custom.min.css', __FILE__), false, null);
327
- wp_enqueue_style ('ad-inserter', plugins_url ('css/ad-inserter.css', __FILE__), false, AD_INSERTER_VERSION);
328
-
329
- wp_enqueue_script ('ad-ace', plugins_url ('includes/ace/src-min-noconflict/ace.js', __FILE__ ), array (), AD_INSERTER_VERSION);
330
- wp_enqueue_script ('ad-ace-ext-modelist', plugins_url ('includes/ace/src-min-noconflict/ext-modelist.js', __FILE__ ), array (), AD_INSERTER_VERSION);
 
 
 
 
 
 
 
 
 
331
  }
332
  }
333
 
334
  function ai_enqueue_scripts_hook () {
335
- // wp_enqueue_style ('ad-inserter-devices', plugins_url ( 'css/devices.css', __FILE__), false, AD_INSERTER_VERSION);
336
- wp_enqueue_style ('ad-inserter-viewports', plugins_url ( 'css/viewports.css', __FILE__), false, filemtime (plugin_dir_path (__FILE__ ).'css/viewports.css'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  }
338
 
339
  function ai_admin_notice_hook () {
@@ -364,6 +841,8 @@ function ai_admin_notice_hook () {
364
  }
365
 
366
  function ai_plugin_action_links ($links) {
 
 
367
  $settings_link = '<a href="'.admin_url ('options-general.php?page=ad-inserter.php').'">Settings</a>';
368
  array_unshift ($links, $settings_link);
369
  return $links;
@@ -376,7 +855,7 @@ function ai_set_plugin_meta ($links, $file) {
376
  if (stripos ($link, "update") !== false) unset ($links [$index]);
377
  }
378
  }
379
- // if (stripos (AD_INSERTER_TITLE, "pro") === false) {
380
  // $new_links = array ('donate' => '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4" target="_blank">Donate</a>');
381
  // $links = array_merge ($links, $new_links);
382
  // }
@@ -384,11 +863,14 @@ function ai_set_plugin_meta ($links, $file) {
384
  return $links;
385
  }
386
 
387
- function ai_current_user_role_ok () {
 
388
  $role_values = array ("super-admin" => 6, "administrator" => 5, "editor" => 4, "author" => 3, "contributor" => 2, "subscriber" => 1);
389
  global $wp_roles;
390
 
391
- $minimum_user_role = isset ($role_values [get_minimum_user_role ()]) ? $role_values [get_minimum_user_role ()] : 0;
 
 
392
 
393
  $user_role = 0;
394
  $current_user = wp_get_current_user();
@@ -397,12 +879,9 @@ function ai_current_user_role_ok () {
397
  // Fix for empty roles
398
  if (isset ($current_user->caps) && count ($current_user->caps) != 0) {
399
  $caps = $current_user->caps;
400
- if (isset ($caps ["super-admin"]) && $caps ["super-admin"]) $roles []= "super-admin";
401
- if (isset ($caps ["administrator"]) && $caps ["administrator"]) $roles []= "administrator";
402
- if (isset ($caps ["editor"]) && $caps ["editor"]) $roles []= "editor";
403
- if (isset ($caps ["author"]) && $caps ["author"]) $roles []= "author";
404
- if (isset ($caps ["contributor"]) && $caps ["contributor"]) $roles []= "contributor";
405
- if (isset ($caps ["subscriber"]) && $caps ["subscriber"]) $roles []= "subscriber";
406
  }
407
 
408
  foreach ($roles as $role) {
@@ -410,7 +889,12 @@ function ai_current_user_role_ok () {
410
  if ($current_user_role > $user_role) $user_role = $current_user_role;
411
  }
412
 
413
- return $user_role >= $minimum_user_role;
 
 
 
 
 
414
  }
415
 
416
 
@@ -418,12 +902,14 @@ function ai_add_meta_box_hook() {
418
 
419
  if (!ai_current_user_role_ok ()) return;
420
 
 
 
421
  $screens = array ('post', 'page');
422
 
423
  foreach ($screens as $screen) {
424
  add_meta_box (
425
  'adinserter_sectionid',
426
- AD_INSERTER_TITLE.' Exceptions',
427
  'ai_meta_box_callback',
428
  $screen
429
  );
@@ -452,7 +938,8 @@ function ai_meta_box_callback ($post) {
452
  echo ' <td style="padding: 0 10px 0 10px;">Automatic Display Type</td>';
453
  echo ' <td style="padding: 0 5px 0 5px;">Posts</td>';
454
  echo ' <td style="padding: 0 5px 0 5px;">Pages</td>';
455
- echo ' <td style="padding: 0 5px 0 5px;">Manual</td>';
 
456
  echo ' <td style="padding: 0 5px 0 5px;">PHP</td>';
457
  echo ' <td style="padding: 0 10px 0 10px;">Default</td>';
458
  echo ' <td style="padding: 0 10px 0 10px;">For this ', $post_type, '</td>';
@@ -487,6 +974,9 @@ function ai_meta_box_callback ($post) {
487
  if ($obj->get_display_settings_page ()) echo '&check;';
488
  echo ' </td>';
489
  echo ' <td style="padding: 0 10px 0 10px; text-align: center;">';
 
 
 
490
  if ($obj->get_enable_manual ()) echo '&check;';
491
  echo ' </td>';
492
  echo ' <td style="padding: 0 10px 0 10px; text-align: center;">';
@@ -521,7 +1011,7 @@ function ai_meta_box_callback ($post) {
521
  echo '</tbody>';
522
  echo '</table>';
523
 
524
- echo '<p>Default behavior for all code blocks for ', $post_type, 's (enabled or disabled) can be configured on <a href="/wp-admin/options-general.php?page=ad-inserter.php" target="_blank">', AD_INSERTER_TITLE, ' Settings page</a>. Here you can configure exceptions for this ', $post_type, '.</p>';
525
  }
526
 
527
  function ai_save_meta_box_data_hook ($post_id) {
@@ -557,34 +1047,230 @@ function ai_save_meta_box_data_hook ($post_id) {
557
  }
558
 
559
  function ai_widgets_init_hook () {
 
560
  register_widget ('ai_widget');
561
  }
562
 
563
  function ai_wp_head_hook () {
564
- $obj = new ai_AdH();
565
- $obj->load_options ("h");
 
 
 
 
 
 
 
 
566
 
567
  if ($obj->get_enable_manual ()) {
568
- echo ai_getCode ($obj);
 
569
  }
 
 
570
  }
571
 
572
  function ai_wp_footer_hook () {
573
- $obj = new ai_AdF();
574
- $obj->load_options ("f");
 
 
 
 
 
 
 
 
575
 
576
  if ($obj->get_enable_manual ()) {
577
- echo ai_getCode ($obj);
 
578
  }
 
 
579
  }
580
 
581
- function ai_check_plugin_options ($plugin_options = array ()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
582
 
583
- $version_array = explode (".", AD_INSERTER_VERSION);
584
- $version_string = "";
585
- foreach ($version_array as $number) {
586
- $version_string .= sprintf ("%02d", $number);
 
 
 
 
 
 
 
 
 
 
 
587
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
588
 
589
  $plugin_options ['VERSION'] = $version_string;
590
 
@@ -609,7 +1295,8 @@ function ai_check_plugin_options ($plugin_options = array ()) {
609
  }
610
  $plugin_options ['PLUGIN_PRIORITY'] = $plugin_priority;
611
 
612
- if (!isset ($plugin_options ['TAG_DEBUGGING'])) $plugin_options ['TAG_DEBUGGING'] = DEFAULT_TAG_DEBUGGING;
 
613
 
614
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
615
  $viewport_name_option_name = 'VIEWPORT_NAME_' . $viewport;
@@ -658,32 +1345,46 @@ function ai_check_plugin_options ($plugin_options = array ()) {
658
  return ($plugin_options);
659
  }
660
 
661
- function ai_get_option ($option_name) {
662
- $options = get_option ($option_name);
663
-
664
  if (is_array ($options)) {
665
  foreach ($options as $key => $option) {
666
- $options [$key] = stripslashes ($option);
667
  }
668
  } else if (is_string ($options)) $options = stripslashes ($options);
 
669
 
 
 
 
 
670
  return ($options);
671
  }
672
 
673
  function ai_load_options () {
674
- global $ai_db_options;
 
 
675
 
676
  $ai_db_options = get_option (WP_OPTION_NAME);
 
677
 
678
- if (is_array ($ai_db_options)) {
679
- foreach ($ai_db_options as $block_number => $block_options) {
680
- if (is_array ($block_options)) {
681
- foreach ($block_options as $key => $option) {
682
- $ai_db_options [$block_number][$key] = stripslashes ($option);
683
- }
684
- } else if (is_string ($block_options)) $ai_db_options [$block_number] = stripslashes ($block_options);
685
- }
686
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
687
  }
688
 
689
  function get_syntax_highlighter_theme () {
@@ -738,17 +1439,70 @@ function get_plugin_priority () {
738
  return ($plugin_db_options ['PLUGIN_PRIORITY']);
739
  }
740
 
741
- function get_tag_debugging () {
742
  global $ai_db_options;
743
 
744
  if (isset ($ai_db_options [AI_GLOBAL_OPTION_NAME])) $plugin_db_options = $ai_db_options [AI_GLOBAL_OPTION_NAME]; else $plugin_db_options = '';
745
- if (!$plugin_db_options) $plugin_db_options = get_option (AD_OPTIONS);
746
 
747
- if (!isset ($plugin_db_options ['TAG_DEBUGGING']) || $plugin_db_options ['TAG_DEBUGGING'] == '') {
748
- $plugin_db_options ['TAG_DEBUGGING'] = DEFAULT_TAG_DEBUGGING;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749
  }
750
 
751
- return ($plugin_db_options ['TAG_DEBUGGING']);
752
  }
753
 
754
  function get_viewport_name ($viewport_number) {
@@ -806,7 +1560,11 @@ function filter_option ($option, $value, $delete_escaped_backslashes = true){
806
  $value = str_replace (array ("\\", "/", "?", "\"", "<", ">", "[", "]"), "", $value);
807
  $value = esc_html ($value);
808
  }
809
- elseif ($option == AI_OPTION_PARAGRAPH_TEXT) {
 
 
 
 
810
  $value = esc_html ($value);
811
  }
812
  elseif ($option == AI_OPTION_NAME ||
@@ -814,12 +1572,19 @@ function filter_option ($option, $value, $delete_escaped_backslashes = true){
814
  $option == AI_OPTION_DOMAIN_LIST ||
815
  $option == AI_OPTION_CATEGORY_LIST ||
816
  $option == AI_OPTION_TAG_LIST ||
 
817
  $option == AI_OPTION_URL_LIST ||
 
818
  $option == AI_OPTION_PARAGRAPH_TEXT_TYPE ||
819
  $option == AI_OPTION_PARAGRAPH_NUMBER ||
820
  $option == AI_OPTION_MIN_PARAGRAPHS ||
 
 
 
821
  $option == AI_OPTION_MIN_WORDS ||
 
822
  $option == AI_OPTION_MIN_PARAGRAPH_WORDS ||
 
823
  $option == AI_OPTION_MAXIMUM_INSERTIONS ||
824
  $option == AI_OPTION_AFTER_DAYS ||
825
  $option == AI_OPTION_EXCERPT_NUMBER ||
@@ -838,32 +1603,196 @@ function filter_option_hf ($option, $value){
838
  } elseif ($option == AI_OPTION_ENABLE_MANUAL) {
839
  } elseif ($option == AI_OPTION_PROCESS_PHP) {
840
  } elseif ($option == AI_OPTION_ENABLE_404) {
 
 
841
  }
842
 
843
  return $value;
844
  }
845
 
846
  function ai_preview () {
 
847
 
848
- check_admin_referer ("adinserter_preview", "ai_check");
849
 
850
- if (isset ($_GET ["ai_code"])) {
851
- $block = $_GET ["ai_code"];
852
  if (is_numeric ($block) && $block >= 1 && $block <= AD_INSERTER_BLOCKS) {
853
  generate_code_preview ($block);
854
  }
855
  }
856
 
 
 
 
 
 
 
 
 
 
 
 
857
  die ();
858
  }
859
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
860
  function ai_settings () {
861
  global $ai_db_options, $block_object;
862
 
863
  if (isset ($_POST [AI_FORM_SAVE])) {
864
 
 
 
 
865
  check_admin_referer ('save_adinserter_settings');
866
 
 
 
 
 
 
 
 
867
  $import_switch_name = AI_OPTION_IMPORT . WP_FORM_FIELD_POSTFIX . '0';
868
  if (isset ($_POST [$import_switch_name]) && $_POST [$import_switch_name] == "1") {
869
  // Import Ad Inserter settings
@@ -877,17 +1806,23 @@ function ai_settings () {
877
  // Try to import individual settings
878
  $ai_options = array ();
879
 
880
- $invalid_blocks = array ();
881
  for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
882
  $ad = new ai_Block ($block);
883
 
884
  if (isset ($ai_db_options [$block])) $saved_settings = $ai_db_options [$block]; else
885
  $saved_settings = $ad->wp_options;
886
 
 
 
 
 
 
 
887
  $import_switch_name = AI_OPTION_IMPORT . WP_FORM_FIELD_POSTFIX . $block;
888
  if (isset ($_POST [$import_switch_name]) && $_POST [$import_switch_name] == "1") {
889
 
890
  $exported_settings = @unserialize (base64_decode (str_replace (array ("\\\""), array ("\""), $_POST ["export_settings_" . $block])));
 
891
  if ($exported_settings !== false) {
892
  foreach (array_keys ($ad->wp_options) as $key){
893
  if ($key == AI_OPTION_NAME) {
@@ -898,6 +1833,7 @@ function ai_settings () {
898
  } else {
899
  if (isset ($exported_settings [$key])) {
900
  $ad->wp_options [$key] = filter_option ($key, $exported_settings [$key], false);
 
901
  }
902
  }
903
  }
@@ -910,14 +1846,12 @@ function ai_settings () {
910
  $form_field_name = $key . WP_FORM_FIELD_POSTFIX . $block;
911
  if (isset ($_POST [$form_field_name])){
912
  $ad->wp_options [$key] = filter_option ($key, $_POST [$form_field_name]);
 
913
  }
914
  }
915
  }
916
 
917
- if (isset ($_POST [AI_OPTION_NAME . WP_FORM_FIELD_POSTFIX . $block]))
918
- $ai_options [$block] = $ad->wp_options; else
919
- $ai_options [$block] = $saved_settings;
920
-
921
  delete_option (str_replace ("#", $block, AD_ADx_OPTIONS));
922
  }
923
 
@@ -949,7 +1883,8 @@ function ai_settings () {
949
  $options ['BLOCK_CLASS_NAME'] = filter_html_class ($_POST ['block-class-name']);
950
  $options ['MINIMUM_USER_ROLE'] = filter_string ($_POST ['minimum-user-role']);
951
  $options ['PLUGIN_PRIORITY'] = filter_option ('plugin_priority', $_POST ['plugin_priority']);
952
- $options ['TAG_DEBUGGING'] = filter_string ($_POST ['tag_debugging']);
 
953
 
954
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
955
  if (isset ($_POST ['viewport-name-'.$viewport]))
@@ -958,69 +1893,35 @@ function ai_settings () {
958
  $options ['VIEWPORT_WIDTH_'.$viewport] = filter_option ('viewport_width', $_POST ['viewport-width-'.$viewport]);
959
  }
960
 
 
 
961
  $ai_options [AI_GLOBAL_OPTION_NAME] = ai_check_plugin_options ($options);
962
  }
963
 
964
  if (!empty ($invalid_blocks)) {
965
  if ($invalid_blocks [0] == 0) {
966
- echo "<div class='error' style='margin: 5px 15px 2px 0px; padding: 10px;'>Error importing ", AD_INSERTER_TITLE, " settings.</div>";
967
  } else echo "<div class='error' style='margin: 5px 15px 2px 0px; padding: 10px;'>Error importing settings for block", count ($invalid_blocks) == 1 ? "" : "s:", " ", implode (", ", $invalid_blocks), ".</div>";
968
  }
969
 
 
 
 
970
  $ai_options [AI_GLOBAL_OPTION_NAME]['TIMESTAMP'] = time ();
971
 
972
  update_option (WP_OPTION_NAME, $ai_options);
973
 
974
- // Reload options
975
- ai_load_options ();
976
-
977
- // Generate viewports.css file
978
- $viewports = array ();
979
- for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
980
- $viewport_name = get_viewport_name ($viewport);
981
- $viewport_width = get_viewport_width ($viewport);
982
- if ($viewport_name != '') {
983
- $viewports []= array ('index' => $viewport, 'name' => $viewport_name, 'width' => $viewport_width);
984
- }
985
- }
986
-
987
- $style = '';
988
- if (count ($viewports) != 0) {
989
- $style .= "/* " . AD_INSERTER_TITLE . " version " . AD_INSERTER_VERSION ." - viewport classes */\n\n";
990
- $style .= "/* DO NOT MODIFY - This file is automatically generated when you save ".AD_INSERTER_TITLE." settings */\n";
991
- foreach ($viewports as $index => $viewport) {
992
- $style .= "\n/* " . $viewport ['name'] . " */\n\n";
993
- if ($viewport ['index'] == 1) {
994
- foreach (array_reverse ($viewports) as $index2 => $viewport2) {
995
- if ($viewport2 ['index'] != 1) {
996
- $style .= ".ai-viewport-" . $viewport2 ['index'] . " { display: none !important;}\n";
997
- }
998
- }
999
- $style .= ".ai-viewport-1 { display: inherit !important;}\n";
1000
- $style .= ".ai-viewport-0 { display: none !important;}\n";
1001
- } else {
1002
- $style .= "@media ";
1003
- if ($index != count ($viewports) - 1)
1004
- $style .= "(min-width: " . $viewport ['width'] . "px) and ";
1005
- $style .= "(max-width: " . ($viewports [$index - 1]['width'] - 1) . "px) {\n";
1006
- foreach ($viewports as $index2 => $viewport2) {
1007
- if ($viewport2 ['index'] == 1)
1008
- $style .= ".ai-viewport-" . $viewport2 ['index'] . " { display: none !important;}\n";
1009
- elseif ($viewport ['index'] == $viewport2 ['index'])
1010
- $style .= ".ai-viewport-" . $viewport2 ['index'] . " { display: inherit !important;}\n";
1011
-
1012
- }
1013
- $style .= "}\n";
1014
- }
1015
- }
1016
  }
1017
- file_put_contents (plugin_dir_path (__FILE__ ).'css/viewports.css', $style);
1018
 
1019
- for ($counter = 1; $counter <= AD_INSERTER_BLOCKS; $counter ++) {
1020
- $obj = new ai_Block ($counter);
1021
- $obj->load_options ($counter);
1022
- $block_object [$counter] = $obj;
1023
- }
1024
 
1025
  delete_option (str_replace ("#", "Header", AD_ADx_OPTIONS));
1026
  delete_option (str_replace ("#", "Footer", AD_ADx_OPTIONS));
@@ -1032,36 +1933,22 @@ function ai_settings () {
1032
 
1033
  check_admin_referer ('save_adinserter_settings');
1034
 
1035
- $ai_options = array ();
1036
-
1037
  for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
1038
- $ad = new ai_Block ($block);
1039
- $ai_options [$block] = $ad->wp_options;
1040
-
1041
  delete_option (str_replace ("#", $block, AD_ADx_OPTIONS));
1042
  }
1043
 
1044
- $adH = new ai_AdH();
1045
- $adF = new ai_AdF();
1046
-
1047
- $ai_options [AI_HEADER_OPTION_NAME] = $adH->wp_options;
1048
- $ai_options [AI_FOOTER_OPTION_NAME] = $adF->wp_options;
1049
- $ai_options [AI_GLOBAL_OPTION_NAME] = ai_check_plugin_options ();
1050
- update_option (WP_OPTION_NAME, $ai_options);
1051
-
1052
- // Reload options
1053
- ai_load_options ();
1054
-
1055
- for ($counter = 1; $counter <= AD_INSERTER_BLOCKS; $counter ++) {
1056
- $obj = new ai_Block ($counter);
1057
- $obj->load_options ($counter);
1058
- $block_object [$counter] = $obj;
1059
- }
1060
-
1061
  delete_option (str_replace ("#", "Header", AD_ADx_OPTIONS));
1062
  delete_option (str_replace ("#", "Footer", AD_ADx_OPTIONS));
1063
  delete_option (AD_OPTIONS);
1064
 
 
 
 
 
 
 
 
 
1065
  echo "<div class='error' style='margin: 5px 15px 2px 0px; padding: 10px;'>Settings cleared.</div>";
1066
  }
1067
 
@@ -1069,515 +1956,394 @@ function ai_settings () {
1069
  }
1070
 
1071
 
1072
- function adinserter ($ad_number = ""){
1073
- global $block_object, $ad_interter_globals;
1074
 
1075
- if ($ad_number == "") return "";
1076
 
 
1077
  if (!is_numeric ($ad_number)) return "";
1078
-
1079
  $ad_number = (int) $ad_number;
1080
-
1081
  if ($ad_number < 1 || $ad_number > AD_INSERTER_BLOCKS) return "";
1082
 
1083
- // Load options from db
1084
- $obj = $block_object [$ad_number];
1085
-
1086
- $globals_name = 'FUNCTION_CALL_COUNTER' . $ad_number;
1087
 
1088
  if (!isset ($ad_interter_globals [$globals_name])) {
1089
  $ad_interter_globals [$globals_name] = 1;
1090
  } else $ad_interter_globals [$globals_name] ++;
1091
 
1092
- $display_for_users = $obj->get_display_for_users ();
1093
 
1094
- if ($display_for_users == AD_DISPLAY_LOGGED_IN_USERS && !is_user_logged_in ()) return "";
1095
- if ($display_for_users == AD_DISPLAY_NOT_LOGGED_IN_USERS && is_user_logged_in ()) return "";
1096
 
1097
- if ($obj->get_detection_server_side ()) {
1098
- $display_for_devices = $obj->get_display_for_devices ();
1099
-
1100
- if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES && !AI_DESKTOP) return "";
1101
- if ($display_for_devices == AD_DISPLAY_MOBILE_DEVICES && !AI_MOBILE) return "";
1102
- if ($display_for_devices == AD_DISPLAY_TABLET_DEVICES && !AI_TABLET) return "";
1103
- if ($display_for_devices == AD_DISPLAY_PHONE_DEVICES && !AI_PHONE) return "";
1104
- if ($display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES && !(AI_DESKTOP || AI_TABLET)) return "";
1105
- if ($display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES && !(AI_DESKTOP || AI_PHONE)) return "";
1106
  }
1107
 
1108
- if (!$obj->get_enable_php_call ()) return "";
1109
-
1110
- if (is_front_page ()){
1111
- if (!$obj->get_display_settings_home()) return "";
1112
- } else if (is_single ()) {
1113
- if (!$obj->get_display_settings_post ()) return "";
1114
-
1115
- $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1116
- $selected_blocks = explode (",", $meta_value);
1117
 
1118
- $enabled_on_text = $obj->get_ad_enabled_on_which_posts ();
1119
- if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1120
- if (in_array ($obj->number, $selected_blocks)) return "";
1121
- }
1122
- elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1123
- if (!in_array ($obj->number, $selected_blocks)) return "";
1124
- }
1125
- } elseif (is_page ()) {
1126
- if (!$obj->get_display_settings_page ()) return "";
1127
 
 
1128
  $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1129
  $selected_blocks = explode (",", $meta_value);
1130
 
1131
- $enabled_on_text = $obj->get_ad_enabled_on_which_pages ();
1132
- if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1133
- if (in_array ($obj->number, $selected_blocks)) return "";
1134
- }
1135
- elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1136
- if (!in_array ($obj->number, $selected_blocks)) return "";
1137
- }
1138
- } elseif (is_category()){
1139
- if (!$obj->get_display_settings_category()) return "";
1140
- } elseif (is_search()){
1141
- if (!$obj->get_display_settings_search()) return "";
1142
- } elseif (is_archive()){
1143
- if (!$obj->get_display_settings_archive()) return "";
1144
- } elseif (is_404()){
1145
- if (!$obj->get_enable_404()) return "";
1146
  }
1147
 
1148
- if ($obj->get_ad_data() == AD_EMPTY_DATA) return "";
 
 
 
 
1149
 
1150
- if (!$obj->check_category ()) return "";
 
 
1151
 
1152
- if (!$obj->check_tag ()) return "";
 
1153
 
1154
- if (!$obj->check_url ()) return "";
 
 
 
 
1155
 
1156
- if (!$obj->check_date ()) return "";
 
1157
 
1158
- if (!$obj->check_referer ()) return "";
1159
 
1160
- $counter_settings = $obj->get_call_filter();
1161
- $numbers = array ();
1162
- if (strpos ($counter_settings, ",") !== false) {
1163
- $numbers = explode (",", $counter_settings);
1164
- } else $numbers []= $counter_settings;
1165
- if ($counter_settings != 0 && !in_array ($ad_interter_globals [$globals_name], $numbers)) return "";
1166
 
1167
- if (!$obj->check_and_increment_block_counter ()) return "";
 
1168
 
1169
- $block_class_name = get_block_class_name ();
1170
 
1171
- if ($obj->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $ad_code = ai_getAdCode ($obj); else
1172
- $ad_code = "<div class='" . $block_class_name . " " . $block_class_name . "-" . $ad_number. $obj->get_viewport_classes () . "' style='" . $obj->get_alignmet_style() . "'>" . ai_getAdCode ($obj) . "</div>";
1173
 
1174
- return $ad_code;
1175
- }
 
1176
 
 
1177
 
1178
- function ai_content_hook ($content = ''){
1179
- global $block_object, $ad_interter_globals;
1180
 
1181
- if (!isset ($ad_interter_globals ['CONTENT_COUNTER'])) {
1182
- $ad_interter_globals ['CONTENT_COUNTER'] = 1;
1183
- } else $ad_interter_globals ['CONTENT_COUNTER'] ++;
1184
 
1185
- $tag_debugging = get_tag_debugging ();
 
 
 
 
 
 
 
1186
 
1187
- if ($tag_debugging != AI_OPTION_BEFORE_PROCESSING || !is_user_logged_in ())
1188
- for ($counter = 1; $counter <= AD_INSERTER_BLOCKS; $counter ++) {
1189
- $obj = $block_object [$counter];
1190
 
1191
- $display_type = $obj->get_display_type();
 
1192
 
1193
- if ($display_type != AD_SELECT_BEFORE_PARAGRAPH &&
1194
- $display_type != AD_SELECT_AFTER_PARAGRAPH &&
1195
- $display_type != AD_SELECT_BEFORE_CONTENT &&
1196
- $display_type != AD_SELECT_AFTER_CONTENT) continue;
1197
 
1198
- $display_for_users = $obj->get_display_for_users ();
 
1199
 
1200
- if ($display_for_users == AD_DISPLAY_LOGGED_IN_USERS && !is_user_logged_in ()) continue;
1201
- if ($display_for_users == AD_DISPLAY_NOT_LOGGED_IN_USERS && is_user_logged_in ()) continue;
1202
 
1203
- if ($obj->get_detection_server_side ()) {
1204
- $display_for_devices = $obj->get_display_for_devices ();
1205
 
1206
- if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES && !AI_DESKTOP) continue;
1207
- if ($display_for_devices == AD_DISPLAY_MOBILE_DEVICES && !AI_MOBILE) continue;
1208
- if ($display_for_devices == AD_DISPLAY_TABLET_DEVICES && !AI_TABLET) continue;
1209
- if ($display_for_devices == AD_DISPLAY_PHONE_DEVICES && !AI_PHONE) continue;
1210
- if ($display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES && !(AI_DESKTOP || AI_TABLET)) continue;
1211
- if ($display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES && !(AI_DESKTOP || AI_PHONE)) continue;
1212
- }
1213
 
1214
- //if empty data, continue with next block
1215
- if ($obj->get_ad_data() == AD_EMPTY_DATA) {
1216
- continue;
1217
- }
 
1218
 
1219
- $blog_page = false;
 
 
1220
 
1221
- if (is_single ()) {
1222
- if (!$obj->get_display_settings_post ()) continue;
1223
 
1224
- $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1225
- $selected_blocks = explode (",", $meta_value);
1226
 
1227
- $enabled_on_text = $obj->get_ad_enabled_on_which_posts ();
1228
- if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1229
- if (in_array ($obj->number, $selected_blocks)) continue;
1230
  }
1231
- elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1232
- if (!in_array ($obj->number, $selected_blocks)) continue;
 
1233
  }
1234
- } elseif (is_page ()) {
1235
- if (!$obj->get_display_settings_page ()) continue;
1236
-
1237
- $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1238
- $selected_blocks = explode (",", $meta_value);
1239
 
1240
- $enabled_on_text = $obj->get_ad_enabled_on_which_pages ();
1241
- if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1242
- if (in_array ($obj->number, $selected_blocks)) continue;
1243
- }
1244
- elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1245
- if (!in_array ($obj->number, $selected_blocks)) continue;
1246
  }
1247
- }
1248
- elseif (is_front_page ()){
1249
- if (!$obj->get_display_settings_home()) continue;
1250
- $blog_page = true;
1251
- }
1252
- elseif (is_category()){
1253
- if (!$obj->get_display_settings_category()) continue;
1254
- $blog_page = true;
1255
- }
1256
- elseif (is_search()){
1257
- if (!$obj->get_display_settings_search()) continue;
1258
- $blog_page = true;
1259
- }
1260
- elseif (is_archive()){
1261
- if (!$obj->get_display_settings_archive()) continue;
1262
- $blog_page = true;
1263
- }
1264
- elseif (is_404()){
1265
- if (!$obj->get_enable_404()) continue;
1266
- }
1267
 
1268
- if ($blog_page) {
1269
- $counter_settings = $obj->get_call_filter();
1270
- $numbers = array ();
1271
- if (strpos ($counter_settings, ",") !== false) {
1272
- $numbers = explode (",", $counter_settings);
1273
- } else $numbers []= $counter_settings;
1274
- if ($counter_settings != 0 && !in_array ($ad_interter_globals ['CONTENT_COUNTER'], $numbers)) continue;
1275
  }
 
 
1276
 
1277
- // Deprecated
1278
- if ($obj->display_disabled ($content)) continue;
1279
-
1280
- if (!$obj->check_category ()) continue;
1281
-
1282
- if (!$obj->check_tag ()) continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1283
 
1284
- if (!$obj->check_url ()) continue;
 
1285
 
1286
- if (!$obj->check_date ()) continue;
 
 
 
 
1287
 
1288
- if (!$obj->check_referer ()) continue;
 
1289
 
1290
- if (!$obj->check_block_counter ()) continue;
 
1291
 
1292
- $inserted = false;
1293
 
1294
- if ($display_type == AD_SELECT_BEFORE_PARAGRAPH) {
1295
- $content = $obj->before_paragraph ($content, $inserted);
1296
- if ($inserted) $obj->increment_block_counter ();
1297
- }
1298
- elseif ($display_type == AD_SELECT_AFTER_PARAGRAPH) {
1299
- $content = $obj->after_paragraph ($content, $inserted);
1300
- if ($inserted) $obj->increment_block_counter ();
1301
- }
1302
- elseif ($display_type == AD_SELECT_BEFORE_CONTENT) {
1303
- $content = $obj->before_content ($content);
1304
- $obj->increment_block_counter ();
1305
- }
1306
- elseif ($display_type == AD_SELECT_AFTER_CONTENT) {
1307
- $content = $obj->after_content ($content);
1308
- $obj->increment_block_counter ();
1309
- }
1310
  }
1311
 
1312
- if ($tag_debugging != AI_OPTION_DISABLED && is_user_logged_in ()) {
1313
- $content = preg_replace ("/\r\n\r\n/", "\r\n\r\n<h6 style='display: block; font-family: Courier, \"Courier New\", monospace; font-weight: bold; font-size: 12px; border: 1px solid #000; padding: 2px; margin: 12px 0;'>\\r\\n\\r\\n</h6>", $content);
1314
-
1315
- $content = preg_replace ("/<p([^>]*?)>/i", "<h6 style='display: block; font-family: Courier, \"Courier New\", monospace; font-weight: bold; font-size: 12px; border: 1px solid blue; padding: 2px; margin: 12px 0;'>&lt;p$1&gt;</h6><p$1>", $content);
1316
- $content = preg_replace ("/<div([^>]*?)>/i", "<h6 style='display: block; font-family: Courier, \"Courier New\", monospace; font-weight: bold; font-size: 12px; border: 1px solid #0a0; padding: 2px; margin: 12px 0;'>&lt;div$1&gt;</h6><div$1>", $content);
1317
- $content = preg_replace ("/<(?!h6|a|br|strong|p|div)([a-z0-9]+)([^>]*?)>/i", "<h6 style='display: block; font-family: Courier, \"Courier New\", monospace; font-weight: bold; font-size: 12px; border: 1px solid red; padding: 2px; margin: 12px 0;'>&lt;$1$2&gt;</h6><$1$2>", $content);
1318
-
1319
- $content = preg_replace ("/<\/p>/i", "</p><h6 style='display: block; font-family: Courier, \"Courier New\", monospace; font-weight: bold; font-size: 12px; border: 1px solid blue; padding: 2px; margin: 12px 0;'>&lt;/p&gt;</h6>", $content);
1320
- $content = preg_replace ("/<\/div>/i", "</div><h6 style='display: block; font-family: Courier, \"Courier New\", monospace; font-weight: bold; font-size: 12px; border: 1px solid #0a0; padding: 2px; margin: 12px 0;'>&lt;/div&gt;</h6>", $content);
1321
- $content = preg_replace ("/<\/(?!h6|a|br|strong|p|div)([a-z0-9]+)>/i", "</$1><h6 style='display: block; font-family: Courier, \"Courier New\", monospace; font-weight: bold; font-size: 12px; border: 1px solid red; padding: 2px; margin: 12px 0;'>&lt;/$1&gt;</h6>", $content);
1322
  }
1323
 
 
 
1324
  return $content;
1325
  }
1326
 
1327
  // Process Before/After Excerpt postion
1328
  function ai_excerpt_hook ($content = ''){
1329
- global $ad_interter_globals, $block_object;
1330
 
1331
- if (strpos ($_SERVER ['REQUEST_URI'], '/wp-admin/') === 0) return;
1332
 
1333
- if (!isset ($ad_interter_globals ['EXCERPT'])) {
1334
- $ad_interter_globals ['EXCERPT'] = 1;
1335
- } else $ad_interter_globals ['EXCERPT'] ++;
1336
- $excerpt_counter = $ad_interter_globals ['EXCERPT'];
1337
 
1338
- for ($block_index = 1; $block_index <= AD_INSERTER_BLOCKS; $block_index ++) {
1339
- $obj = $block_object [$block_index];
1340
-
1341
- $display_type = $obj->get_display_type ();
1342
 
1343
- if ($display_type != AD_SELECT_BEFORE_EXCERPT && $display_type != AD_SELECT_AFTER_EXCERPT) continue;
1344
 
1345
- $display_for_users = $obj->get_display_for_users ();
1346
 
1347
- if ($display_for_users == AD_DISPLAY_LOGGED_IN_USERS && !is_user_logged_in ()) continue;
1348
- if ($display_for_users == AD_DISPLAY_NOT_LOGGED_IN_USERS && is_user_logged_in ()) continue;
1349
 
1350
- if ($obj->get_detection_server_side ()) {
1351
- $display_for_devices = $obj->get_display_for_devices ();
1352
 
1353
- if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES && !AI_DESKTOP) continue;
1354
- if ($display_for_devices == AD_DISPLAY_MOBILE_DEVICES && !AI_MOBILE) continue;
1355
- if ($display_for_devices == AD_DISPLAY_TABLET_DEVICES && !AI_TABLET) continue;
1356
- if ($display_for_devices == AD_DISPLAY_PHONE_DEVICES && !AI_PHONE) continue;
1357
- if ($display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES && !(AI_DESKTOP || AI_TABLET)) continue;
1358
- if ($display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES && !(AI_DESKTOP || AI_PHONE)) continue;
1359
- }
1360
 
1361
- $counter_settings = $obj->get_call_filter();
1362
- $numbers = array ();
1363
- if (strpos ($counter_settings, ",") !== false) {
1364
- $numbers = explode (",", $counter_settings);
1365
- } else $numbers []= $counter_settings;
1366
 
1367
- if ($counter_settings != 0 && !in_array ($excerpt_counter, $numbers)) continue;
 
 
1368
 
1369
- if (is_front_page ()){
1370
- if (!$obj->get_display_settings_home()) continue;
1371
- }
1372
- elseif (is_category()){
1373
- if (!$obj->get_display_settings_category()) continue;
1374
- }
1375
- elseif (is_search()){
1376
- if (!$obj->get_display_settings_search()) continue;
1377
- }
1378
- elseif (is_archive()){
1379
- if (!$obj->get_display_settings_archive()) continue;
1380
- }
1381
- elseif (is_404()){
1382
- if (!$obj->get_enable_404()) continue;
1383
- }
1384
 
1385
- //if empty data, continue with next
1386
- if ($obj->get_ad_data() == AD_EMPTY_DATA){
1387
- continue;
1388
- }
1389
 
1390
- // Deprecated
1391
- if ($obj->display_disabled ($content)) continue;
 
 
1392
 
1393
- if (!$obj->check_category ()) continue;
 
 
1394
 
1395
- if (!$obj->check_tag ()) continue;
1396
 
1397
- if (!$obj->check_url ()) continue;
 
1398
 
1399
- if (!$obj->check_referer ()) continue;
1400
 
1401
- if (!$obj->check_and_increment_block_counter ()) continue;
 
 
1402
 
1403
- $block_class_name = get_block_class_name ();
 
 
1404
 
1405
- if ($obj->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $ad_code = ai_getAdCode ($obj); else
1406
- $ad_code = "<div class='" . $block_class_name . " " . $block_class_name . "-" . $block_index . $obj->get_viewport_classes () . "' style='" . $obj->get_alignmet_style() . "'>" . ai_getAdCode ($obj) . "</div>";
 
1407
 
1408
- if ($display_type == AD_SELECT_BEFORE_EXCERPT)
1409
- $content = $ad_code . $content; else
1410
- $content = $content . $ad_code;
 
1411
  }
1412
 
 
 
1413
  return $content;
1414
  }
1415
 
1416
  // Process Before / After Post postion
1417
 
1418
  function ai_before_after_post ($query, $display_type){
1419
- global $block_object, $ad_interter_globals;
 
 
 
 
1420
 
1421
  if (!method_exists ($query, 'is_main_query')) return;
1422
  if (!$query->is_main_query()) return;
1423
- if (is_feed()) return;
1424
- if (strpos ($_SERVER ['REQUEST_URI'], '/wp-admin/') === 0) return;
1425
 
1426
- $globals_name = 'LOOP_COUNTER_'.str_replace (" ", "", $display_type);
1427
 
1428
  if (!isset ($ad_interter_globals [$globals_name])) {
1429
  $ad_interter_globals [$globals_name] = 1;
1430
  } else $ad_interter_globals [$globals_name] ++;
1431
 
1432
- $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1433
- $selected_blocks = explode (",", $meta_value);
1434
-
1435
- $ad_code = "";
1436
-
1437
- for ($block_index = 1; $block_index <= AD_INSERTER_BLOCKS; $block_index ++) {
1438
- $obj = $block_object [$block_index];
1439
-
1440
- if ($obj->get_display_type () != $display_type) continue;
1441
 
1442
- $display_for_users = $obj->get_display_for_users ();
1443
-
1444
- if ($display_for_users == AD_DISPLAY_LOGGED_IN_USERS && !is_user_logged_in ()) continue;
1445
- if ($display_for_users == AD_DISPLAY_NOT_LOGGED_IN_USERS && is_user_logged_in ()) continue;
1446
-
1447
- if ($obj->get_detection_server_side ()) {
1448
- $display_for_devices = $obj->get_display_for_devices ();
1449
-
1450
- if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES && !AI_DESKTOP) continue;
1451
- if ($display_for_devices == AD_DISPLAY_MOBILE_DEVICES && !AI_MOBILE) continue;
1452
- if ($display_for_devices == AD_DISPLAY_TABLET_DEVICES && !AI_TABLET) continue;
1453
- if ($display_for_devices == AD_DISPLAY_PHONE_DEVICES && !AI_PHONE) continue;
1454
- if ($display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES && !(AI_DESKTOP || AI_TABLET)) continue;
1455
- if ($display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES && !(AI_DESKTOP || AI_PHONE)) continue;
1456
- }
1457
 
1458
- if (is_front_page ()){
1459
- if (!$obj->get_display_settings_home()) continue;
1460
- }
1461
- elseif (is_page()){
1462
- if (!$obj->get_display_settings_page()) continue;
1463
 
1464
- $enabled_on_text = $obj->get_ad_enabled_on_which_pages ();
1465
- if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1466
- if (in_array ($obj->number, $selected_blocks)) continue;
1467
- }
1468
- elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1469
- if (!in_array ($obj->number, $selected_blocks)) continue;
1470
- }
1471
- }
1472
- elseif (is_single()){
1473
- if (!$obj->get_display_settings_post()) continue;
1474
 
1475
- $enabled_on_text = $obj->get_ad_enabled_on_which_posts ();
1476
- if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1477
- if (in_array ($obj->number, $selected_blocks)) continue;
1478
- }
1479
- elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1480
- if (!in_array ($obj->number, $selected_blocks)) continue;
1481
- }
1482
- }
1483
- elseif (is_category()){
1484
- if (!$obj->get_display_settings_category()) continue;
1485
- }
1486
- elseif (is_search()){
1487
- if (!$obj->get_display_settings_search()) continue;
1488
- }
1489
- elseif (is_archive()){
1490
- if (!$obj->get_display_settings_archive()) continue;
1491
- }
1492
- elseif (is_404()){
1493
- if (!$obj->get_enable_404()) continue;
1494
- }
1495
 
1496
- //if empty data, continue with next
1497
- if ($obj->get_ad_data() == AD_EMPTY_DATA) continue;
1498
 
1499
- if (!$obj->check_category ()) continue;
1500
 
1501
- if (!$obj->check_tag ()) continue;
 
1502
 
1503
- if (!$obj->check_url ()) continue;
 
1504
 
1505
- if (!$obj->check_date ()) continue;
1506
 
1507
- if (!$obj->check_referer ()) continue;
 
1508
 
1509
- $counter_settings = $obj->get_call_filter();
1510
- $numbers = array ();
1511
- if (strpos ($counter_settings, ",") !== false) {
1512
- $numbers = explode (",", $counter_settings);
1513
- } else $numbers []= $counter_settings;
1514
- if ($counter_settings != 0 && !in_array ($ad_interter_globals [$globals_name], $numbers)) continue;
1515
 
 
1516
  if (!$obj->check_and_increment_block_counter ()) continue;
1517
 
1518
- $block_class_name = get_block_class_name ();
1519
-
1520
- if ($obj->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $ad_code .= ai_getAdCode ($obj); else
1521
- $ad_code .= "<div class='" . $block_class_name . " " . $block_class_name . "-" . $block_index . $obj->get_viewport_classes () . "' style='" . $obj->get_alignmet_style() . "'>" . ai_getAdCode ($obj) . "</div>";
 
1522
  }
 
1523
 
1524
  echo $ad_code;
1525
  }
1526
 
1527
  // Process Before Post postion
1528
  function ai_loop_start_hook ($query){
 
 
 
1529
  ai_before_after_post ($query, AD_SELECT_BEFORE_POST);
 
1530
  }
1531
 
1532
 
1533
  // Process After Post postion
1534
  function ai_loop_end_hook ($query){
 
 
 
1535
  ai_before_after_post ($query, AD_SELECT_AFTER_POST);
 
1536
  }
1537
 
1538
-
1539
- function ai_getCode ($obj){
1540
- $code = $obj->get_ad_data();
1541
-
1542
- if ($obj->get_process_php ()) {
1543
- ob_start ();
1544
- eval ("?>". $code . "<?php ");
1545
- $code = ob_get_clean ();
1546
- }
1547
-
1548
- return $code;
1549
- }
1550
-
1551
-
1552
- function ai_getAdCode ($obj){
1553
-
1554
- $ad_code = $obj->get_ad_data_replaced();
1555
-
1556
- if ($obj->get_process_php ()) {
1557
- ob_start ();
1558
- eval ("?>". $ad_code . "<?php ");
1559
- $ad_code = ob_get_clean ();
1560
- }
1561
-
1562
- if (strpos ($ad_code, AD_SEPARATOR) !== false) {
1563
- $ads = explode (AD_SEPARATOR, $ad_code);
1564
- $ad_code = $ads [rand (0, sizeof ($ads) - 1)];
1565
- }
1566
-
1567
- return do_shortcode ($ad_code);
1568
- }
1569
-
1570
-
1571
- function process_shortcodes ($atts) {
1572
- global $block_object;
1573
 
1574
  $parameters = shortcode_atts (array (
1575
  "block" => "",
1576
  "name" => "",
1577
  "ignore" => "",
1578
  ), $atts);
 
1579
  if (is_numeric ($parameters ['block'])) $block = intval ($parameters ['block']); else $block = 0;
1580
- if ($block < 1 && $block > AD_INSERTER_BLOCKS) {
1581
  $block = 0;
1582
  } elseif ($parameters ['name'] != '') {
1583
  $shortcode_name = strtolower ($parameters ['name']);
@@ -1591,6 +2357,8 @@ function process_shortcodes ($atts) {
1591
  }
1592
  }
1593
 
 
 
1594
  if ($block == 0) return "";
1595
 
1596
  // IGNORE SETTINGS
@@ -1602,87 +2370,38 @@ function process_shortcodes ($atts) {
1602
  $ignore_array = explode (",", str_replace (" ", "", $parameters ['ignore']));
1603
  }
1604
 
 
 
1605
  $obj = $block_object [$block];
 
1606
 
 
1607
  if (!$obj->get_enable_manual ()) return "";
1608
 
1609
- $display_for_users = $obj->get_display_for_users ();
1610
-
1611
- if ($display_for_users == AD_DISPLAY_LOGGED_IN_USERS && !is_user_logged_in ()) return "";
1612
- if ($display_for_users == AD_DISPLAY_NOT_LOGGED_IN_USERS && is_user_logged_in ()) return "";
1613
-
1614
- if ($obj->get_detection_server_side ()) {
1615
- $display_for_devices = $obj->get_display_for_devices ();
1616
-
1617
- if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES && !AI_DESKTOP) return "";
1618
- if ($display_for_devices == AD_DISPLAY_MOBILE_DEVICES && !AI_MOBILE) return "";
1619
- if ($display_for_devices == AD_DISPLAY_TABLET_DEVICES && !AI_TABLET) return "";
1620
- if ($display_for_devices == AD_DISPLAY_PHONE_DEVICES && !AI_PHONE) return "";
1621
- if ($display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES && !(AI_DESKTOP || AI_TABLET)) return "";
1622
- if ($display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES && !(AI_DESKTOP || AI_PHONE)) return "";
1623
- }
1624
-
1625
- if (is_front_page ()){
1626
- if (!$obj->get_display_settings_home() && !in_array ("page_type", $ignore_array)) return "";
1627
- } else if (is_single ()) {
1628
- if (!$obj->get_display_settings_post () && !in_array ("page_type", $ignore_array)) return "";
1629
- if (!$obj->check_date ()) return "";
1630
-
1631
- //// Exceptions are only for automatic insertion
1632
- // $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1633
- // $selected_blocks = explode (",", $meta_value);
1634
-
1635
- // $enabled_on_text = $obj->get_ad_enabled_on_which_posts ();
1636
- // if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1637
- // if (in_array ($obj->number, $selected_blocks)) return "";
1638
- // }
1639
- // elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1640
- // if (!in_array ($obj->number, $selected_blocks)) return "";
1641
- // }
1642
- ////
1643
-
1644
- } elseif (is_page ()) {
1645
- if (!$obj->get_display_settings_page () && !in_array ("page_type", $ignore_array)) return "";
1646
- if (!$obj->check_date ()) return "";
1647
-
1648
- //// Exceptions are only for automatic insertion
1649
- // $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1650
- // $selected_blocks = explode (",", $meta_value);
1651
 
1652
- // $enabled_on_text = $obj->get_ad_enabled_on_which_pages ();
1653
- // if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1654
- // if (in_array ($obj->number, $selected_blocks)) return "";
1655
- // }
1656
- // elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1657
- // if (!in_array ($obj->number, $selected_blocks)) return "";
1658
- // }
1659
- ////
1660
 
1661
- } elseif (is_category()){
1662
- if (!$obj->get_display_settings_category() && !in_array ("page_type", $ignore_array)) return "";
1663
- } elseif (is_search()){
1664
- if (!$obj->get_display_settings_search() && !in_array ("page_type", $ignore_array)) return "";
1665
- } elseif (is_archive()){
1666
- if (!$obj->get_display_settings_archive() && !in_array ("page_type", $ignore_array)) return "";
1667
- } elseif (is_404()){
1668
- if (!$obj->get_enable_404() && !in_array ("page_type", $ignore_array)) return "";
1669
  }
 
1670
 
1671
- if (!$obj->check_url ()) return "";
1672
-
1673
- if (!$obj->check_referer ()) return "";
1674
-
1675
- if (!$obj->check_category ()) return "";
1676
-
1677
- if (!$obj->check_tag ()) return "";
1678
-
1679
- if (!$obj->check_and_increment_block_counter ()) return "";
1680
-
1681
- $block_class_name = get_block_class_name ();
1682
 
1683
- if ($obj->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $ad_code = ai_getAdCode ($obj); else
1684
- $ad_code = "<div class='" . $block_class_name . " " . $block_class_name . "-" . $block . $obj->get_viewport_classes () . "' style='" . $obj->get_alignmet_style() . "'>" . ai_getAdCode ($obj) . "</div>";
1685
- return ($ad_code);
 
 
 
 
 
 
 
1686
  }
1687
 
1688
 
@@ -1691,39 +2410,28 @@ class ai_widget extends WP_Widget {
1691
  function __construct () {
1692
  parent::__construct (
1693
  false, // Base ID
1694
- AD_INSERTER_TITLE, // Name
1695
  array ( // Args
1696
  'classname' => 'ai_widget',
1697
- 'description' => AD_INSERTER_TITLE.' code block widget.')
1698
  );
1699
  }
1700
 
1701
- function widget ($args, $instance) {
1702
- global $block_object;
1703
-
1704
- // Widget output
1705
-
1706
- $title = !empty ($instance ['widget-title']) ? $instance ['widget-title'] : '';
1707
- $block = !empty ($instance ['block']) ? $instance ['block'] : 1;
1708
-
1709
- $ad = $block_object [$block];
1710
- ai_widget_draw ($block, $ad, $args, $title);
1711
- }
1712
-
1713
  function form ($instance) {
1714
  global $block_object;
1715
 
1716
  // Output admin widget options form
1717
 
1718
  $widget_title = !empty ($instance ['widget-title']) ? $instance ['widget-title'] : '';
1719
- $block = !empty ($instance ['block']) ? $instance ['block'] : 1;
1720
-
1721
- $obj = $block_object [$block];
1722
 
1723
- $title = '[' . $block . '] ' . $obj->get_ad_name();
1724
- if (!empty ($widget_title)) $title .= ' - ' . $widget_title;
1725
 
1726
- if (!$obj->get_enable_widget ()) $title .= ' - DISABLED'
 
 
 
1727
 
1728
  ?>
1729
  <input id="<?php echo $this->get_field_id ('title'); ?>" name="<?php echo $this->get_field_name ('title'); ?>" type="hidden" value="<?php echo esc_attr ($title); ?>">
@@ -1742,6 +2450,7 @@ class ai_widget extends WP_Widget {
1742
  ?>
1743
  <option value='<?php echo $block_index; ?>' <?php if ($block_index == $block) echo 'selected="selected"'; ?>><?php echo $obj->get_ad_name(), !$obj->get_enable_widget ()? ' - DISABLED' : ''; ?></option>
1744
  <?php } ?>
 
1745
  </select>
1746
  </p>
1747
 
@@ -1758,117 +2467,118 @@ class ai_widget extends WP_Widget {
1758
 
1759
  $instance ['widget-title'] = (!empty ($new_instance ['widget-title'])) ? strip_tags ($new_instance ['widget-title']) : '';
1760
  $instance ['title'] = (!empty ($new_instance ['title'])) ? strip_tags ($new_instance ['title']) : '';
1761
- $instance ['block'] = (!empty ($new_instance ['block'])) ? $new_instance ['block'] : 1;
1762
 
1763
  return $instance;
1764
  }
1765
- }
1766
 
 
 
1767
 
1768
- function ai_widget_draw ($block, $obj, $args, $title = '') {
1769
- global $ad_interter_globals;
1770
 
1771
- if (!isset ($ad_interter_globals ['WIDGET_COUNTER_'.$block])) {
1772
- $ad_interter_globals ['WIDGET_COUNTER_'.$block] = 1;
1773
- } else $ad_interter_globals ['WIDGET_COUNTER_'.$block] ++;
1774
 
1775
- if (!$obj->get_enable_widget ()) return;
1776
 
1777
- $display_for_users = $obj->get_display_for_users ();
 
 
 
1778
 
1779
- if ($display_for_users == AD_DISPLAY_LOGGED_IN_USERS && !is_user_logged_in ()) return;
1780
- if ($display_for_users == AD_DISPLAY_NOT_LOGGED_IN_USERS && is_user_logged_in ()) return;
1781
 
1782
- if ($obj->get_detection_server_side ()) {
1783
- $display_for_devices = $obj->get_display_for_devices ();
1784
 
1785
- if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES && !AI_DESKTOP) return;
1786
- if ($display_for_devices == AD_DISPLAY_MOBILE_DEVICES && !AI_MOBILE) return;;
1787
- if ($display_for_devices == AD_DISPLAY_TABLET_DEVICES && !AI_TABLET) return;
1788
- if ($display_for_devices == AD_DISPLAY_PHONE_DEVICES && !AI_PHONE) return;
1789
- if ($display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES && !(AI_DESKTOP || AI_TABLET)) return;
1790
- if ($display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES && !(AI_DESKTOP || AI_PHONE)) return;
1791
- }
1792
 
1793
- //if empty data, continue next
1794
- if($obj->get_ad_data()==AD_EMPTY_DATA){
1795
- return;
 
1796
  }
1797
 
1798
- if(is_front_page ()){
1799
- if (!$obj->get_display_settings_home()) return;
1800
- }
1801
- elseif(is_page()){
1802
- if (!$obj->get_display_settings_page()) return;
1803
 
1804
- $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1805
- $selected_blocks = explode (",", $meta_value);
1806
 
1807
- $enabled_on_text = $obj->get_ad_enabled_on_which_pages ();
1808
- if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1809
- if (in_array ($obj->number, $selected_blocks)) return;
1810
- }
1811
- elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1812
- if (!in_array ($obj->number, $selected_blocks)) return;
1813
- }
1814
- }
1815
- elseif(is_single()){
1816
- if (!$obj->get_display_settings_post()) return;
1817
 
1818
- $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1819
- $selected_blocks = explode (",", $meta_value);
1820
 
1821
- $enabled_on_text = $obj->get_ad_enabled_on_which_posts ();
1822
- if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1823
- if (in_array ($obj->number, $selected_blocks)) return;
1824
- }
1825
- elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1826
- if (!in_array ($obj->number, $selected_blocks)) return;
1827
- }
1828
- }
1829
- elseif(is_category()){
1830
- if (!$obj->get_display_settings_category()) return;
1831
- }
1832
- elseif(is_search()){
1833
- if (!$obj->get_display_settings_search()) return;
1834
- }
1835
- elseif(is_archive()){
1836
- if (!$obj->get_display_settings_archive()) return;
1837
- }
1838
- elseif (is_404()){
1839
- if (!$obj->get_enable_404()) return;
1840
- }
1841
 
1842
- if (!$obj->check_category ()) return;
1843
 
1844
- if (!$obj->check_tag ()) return;
1845
 
1846
- if (!$obj->check_url ()) return;
 
 
 
 
1847
 
1848
- if (!$obj->check_referer ()) return;
 
 
1849
 
1850
- $counter_settings = $obj->get_call_filter();
1851
- $numbers = array ();
1852
- if (strpos ($counter_settings, ",") !== false) {
1853
- $numbers = explode (",", $counter_settings);
1854
- } else $numbers []= $counter_settings;
1855
- if ($counter_settings != 0 && !in_array ($ad_interter_globals ['WIDGET_COUNTER_'.$block], $numbers)) return;
1856
 
 
1857
  if (!$obj->check_and_increment_block_counter ()) return;
1858
 
1859
- $block_class_name = get_block_class_name ();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1860
 
1861
- $viewport_classes = $obj->get_viewport_classes ();
1862
- if ($viewport_classes != "") echo "<div class='" . $viewport_classes . "'>";
1863
  echo $args ['before_widget'];
1864
 
 
 
1865
  if (!empty ($title)) {
1866
  echo $args ['before_title'], apply_filters ('widget_title', $title), $args ['after_title'];
1867
  }
1868
 
1869
- if ($obj->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) echo ai_getAdCode ($obj); else
1870
- echo "<div class='" . $block_class_name . " " . $block_class_name . "-" . $block . "' style='" . $obj->get_alignmet_style (0) . "'>" . ai_getAdCode ($obj) . "</div>";
 
 
 
 
 
 
 
 
 
 
 
 
1871
 
1872
  echo $args ['after_widget'];
1873
- if ($viewport_classes != "") echo "</div>";
1874
  }
1
  <?php
2
  /*
3
  Plugin Name: Ad Inserter
4
+ Version: 2.0.0
5
+ Description: Insert any ad or code into Wordpress. Perfect for all kinds of ads. Simply enter any ad or HTML/Javascript/PHP code and select where and how you want to display it.
6
  Author: Igor Funa
7
  Author URI: http://igorfuna.com/
8
  Plugin URI: http://tinymonitor.com/ad-inserter
11
  /*
12
  Change Log
13
 
14
+ Ad Inserter 2.0.0 - 23 September 2016
15
+ - Redesigned user interface
16
+ - Added many debugging tools for easier troubleshooting
17
+ - New feature: Code preview tool with visual CSS editor
18
+ - New feature: Label inserted blocks
19
+ - New feature: Show available positions for automatic insertion
20
+ - New feature: Show HTML tags in posts/static pages
21
+ - New feature: Log Ad Inserter processing
22
+ - Improved loading speed of the settings page
23
+ - Improved block insertion processing speed
24
+ - Added support to avoid insertion near images, headers and other elements
25
+ - Added option to avoid insertion in feeds
26
+ - Added option to display code blocks only to administrators
27
+ - Added option for publishig date check for display positions Before/After Content
28
+ - Added option for server-side device check for header and footer code
29
+ - Added option for maximum page/post words
30
+ - Added option for maximum paragraph words
31
+ - Added option to black/white-list post IDs
32
+ - Added option to black/white-list url query parameters
33
+ - Added warning if the settings page is blocked by ad blocker
34
+ - Added warning if old cached version of javascript is loaded on the settings page
35
+ - Added support for multisite installations to disable settings, widgets and exceptions on network sites (Pro only)
36
+ - Block names can be edited by clicking on the name
37
+ - Filters now work also on posts and single pages
38
+ - CSS code for client-side detection moved to inline CSS
39
+ - Bug fix: Minimum user roles for exception editing was not calculated properly
40
+ - Bug fix: Server-side detection checkbox was not saved properly
41
+ - Many other minor bug fixes, code improvements and cosmetic changes
42
+
43
  Ad Inserter 1.7.0 - 16 August 2016
44
  - Bug fix: Shortcodes did not ignore post/static page exceptions
45
  - Slightly redesigned user interface
246
  */
247
 
248
 
 
 
 
249
  if (!defined ('AD_INSERTER_PLUGIN_DIR'))
250
  define ('AD_INSERTER_PLUGIN_DIR', plugin_dir_path (__FILE__));
251
 
257
  exit ($exit_msg);
258
  }
259
 
260
+ global $block_object, $ai_wp_data, $ad_interter_globals, $ai_last_check, $ai_last_time, $ai_processing_log, $ai_db_options_extract, $ai_db_options;
261
+
262
  //include required files
263
  require_once AD_INSERTER_PLUGIN_DIR.'class.php';
264
  require_once AD_INSERTER_PLUGIN_DIR.'constants.php';
265
  require_once AD_INSERTER_PLUGIN_DIR.'settings.php';
266
  require_once AD_INSERTER_PLUGIN_DIR.'preview.php';
267
 
268
+ if (isset ($_GET [AI_URL_DEBUG_PHP]) && $_GET [AI_URL_DEBUG_PHP] != '') {
269
+ ini_set ('display_errors', 1);
270
+ error_reporting (E_ALL);
271
+ }
272
 
273
  $version_array = explode (".", AD_INSERTER_VERSION);
274
  $version_string = "";
276
  $version_string .= sprintf ("%02d", $number);
277
  }
278
 
279
+ $ai_wp_data [AI_WP_DEBUGGING] = 0;
280
+ $ai_wp_data [AI_WP_URL] = remove_parameters_from_url ($_SERVER ['REQUEST_URI']);
281
+
282
+ if (!session_id()) session_start();
283
+
284
+ if (!isset ($_GET [AI_URL_DEBUG]))
285
+ if ((isset ($_GET [AI_URL_DEBUG_PROCESSING]) && $_GET [AI_URL_DEBUG_PROCESSING] == 1) || (isset ($_SESSION ['AI_WP_DEBUGGING']) && ($_SESSION ['AI_WP_DEBUGGING'] & AI_DEBUG_PROCESSING) != 0)) {
286
+ $ai_wp_data [AI_WP_DEBUGGING] |= AI_DEBUG_PROCESSING;
287
+ $ai_last_time = microtime ();
288
+ $ai_processing_log = array ();
289
+ ai_log ("INITIALIZATION START");
290
+ }
291
 
292
+ $ad_interter_globals = array ();
293
  $block_object = array ();
294
+
295
+ ai_load_settings ();
296
+
297
+ $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_NONE;
298
+ $ai_wp_data [AI_WP_USER] = AI_USER_NOT_SET;
299
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_NONE;
300
+ $ai_wp_data [SERVER_SIDE_DETECTION] = false;
301
+ $ai_wp_data [CLIENT_SIDE_DETECTION] = false;
302
+
303
  for ($counter = 1; $counter <= AD_INSERTER_BLOCKS; $counter ++) {
304
+ $obj = $block_object [$counter];
 
 
305
 
306
+ if ($obj->get_detection_server_side()) $ai_wp_data [SERVER_SIDE_DETECTION] = true;
307
+ if ($obj->get_detection_client_side ()) $ai_wp_data [CLIENT_SIDE_DETECTION] = true;
308
  }
309
 
310
+ $adH = $block_object [AI_HEADER_OPTION_NAME];
311
+ $adF = $block_object [AI_FOOTER_OPTION_NAME];
312
+ if ($adH->get_detection_server_side()) $ai_wp_data [SERVER_SIDE_DETECTION] = true;
313
+ if ($adF->get_detection_server_side()) $ai_wp_data [SERVER_SIDE_DETECTION] = true;
314
+
315
+
316
+ if ($ai_wp_data [SERVER_SIDE_DETECTION]) {
317
  require_once AD_INSERTER_PLUGIN_DIR.'includes/Mobile_Detect.php';
318
 
319
  $detect = new ai_Mobile_Detect;
329
  define ('AI_DESKTOP', true);
330
  }
331
 
332
+ if (isset ($_POST [AI_FORM_SAVE]))
333
+ define ('AI_SYNTAX_HIGHLIGHTING', isset ($_POST ["syntax-highlighter-theme"]) && $_POST ["syntax-highlighter-theme"] != AI_OPTION_DISABLED); else
334
+ define ('AI_SYNTAX_HIGHLIGHTING', $ai_db_options [AI_GLOBAL_OPTION_NAME]["SYNTAX_HIGHLIGHTER_THEME"] != AI_OPTION_DISABLED);
335
 
 
336
  add_action ('admin_menu', 'ai_admin_menu_hook');
337
+
 
 
 
338
  add_action ('init', 'ai_init_hook');
339
  //add_action ('admin_notices', 'ai_admin_notice_hook');
340
+
341
+ add_action( 'wp', 'ai_wp_hook');
342
+
343
+ if ($adH->get_enable_manual ())
344
+ add_action ('wp_head', 'ai_wp_head_hook');
345
+
346
+ if ($adF->get_enable_manual ())
347
+ add_action ('wp_footer', 'ai_wp_footer_hook');
348
+
349
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0)
350
+ add_action ('shutdown', 'ai_shutdown_hook');
351
+
352
  add_action ('widgets_init', 'ai_widgets_init_hook');
353
  add_action ('add_meta_boxes', 'ai_add_meta_box_hook');
354
  add_action ('save_post', 'ai_save_meta_box_data_hook');
355
 
356
  if (function_exists ('ai_hooks')) ai_hooks ();
357
 
358
+ add_action ('wp_enqueue_scripts', 'ai_enqueue_scripts_hook');
 
 
359
 
360
  add_filter ('plugin_action_links_'.plugin_basename (__FILE__), 'ai_plugin_action_links');
361
  add_filter ('plugin_row_meta', 'ai_set_plugin_meta', 10, 2);
362
  add_action ('wp_ajax_ai_preview', 'ai_preview');
363
  add_action ('wp_ajax_nopriv_ai_preview', 'ai_preview');
364
 
365
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("INITIALIZATION END\n");
366
+
367
+
368
+
369
+ function ai_toolbar ($wp_admin_bar) {
370
+ global $block_object, $ai_wp_data;
371
+
372
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) == 0) $debug_blocks = 1; else $debug_blocks = 0;
373
+ $debug_blocks_class = $debug_blocks == 0 ? ' on' : '';
374
+
375
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) == 0) $debug_positions = 0; else $debug_positions = '';
376
+ $debug_positions_class = $debug_positions === '' ? ' on' : '';
377
+
378
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_TAGS) == 0) $debug_tags = 1; else $debug_tags = 0;
379
+ $debug_tags_class = $debug_tags == 0 ? ' on' : '';
380
+
381
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) == 0) $debug_processing = 1; else $debug_processing = 0;
382
+ $debug_processing_class = $debug_processing == 0 ? ' on' : '';
383
+
384
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) $debug_no_insertion = 1; else $debug_no_insertion = 0;
385
+ $debug_no_insertion_class = $debug_no_insertion == 0 ? ' on' : '';
386
+
387
+ $debug_settings_on = $debug_blocks == 0 || $debug_positions === '' || $debug_tags == 0 || $debug_processing == 0 || $debug_no_insertion == 0;
388
+
389
+ $debug_settings_class = $debug_settings_on ? ' on' : '';
390
+ $top_menu_url = $debug_settings_on ? add_query_arg (AI_URL_DEBUG, '0', remove_parameters_from_url ($_SERVER ['REQUEST_URI'])) :
391
+ add_query_arg (array (AI_URL_DEBUG_BLOCKS => '1', AI_URL_DEBUG_POSITIONS => '0', AI_URL_DEBUG_TAGS => '1'), remove_parameters_from_url ($_SERVER ['REQUEST_URI']));
392
+
393
+ $wp_admin_bar->add_node (array (
394
+ 'id' => 'ai-toolbar',
395
+ 'group' => true
396
+ ));
397
+ $wp_admin_bar->add_node (array (
398
+ 'id' => 'ai-toolbar-settings',
399
+ 'parent' => 'ai-toolbar',
400
+ 'title' => '<span class="ab-icon'.$debug_settings_class.'"></span>'.AD_INSERTER_NAME,
401
+ 'href' => $top_menu_url,
402
+ ));
403
+ $wp_admin_bar->add_node (array (
404
+ 'id' => 'ai-toolbar-blocks',
405
+ 'parent' => 'ai-toolbar-settings',
406
+ 'title' => '<span class="ab-icon'.$debug_blocks_class.'"></span>Label Blocks',
407
+ 'href' => set_url_parameter (AI_URL_DEBUG_BLOCKS, $debug_blocks),
408
+ ));
409
+ $wp_admin_bar->add_node (array (
410
+ 'id' => 'ai-toolbar-positions',
411
+ 'parent' => 'ai-toolbar-settings',
412
+ 'title' => '<span class="ab-icon'.$debug_positions_class.'"></span>Show Positions',
413
+ 'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $debug_positions),
414
+ ));
415
+
416
+ $paragraph_blocks = array ();
417
+ for ($block = 0; $block <= AD_INSERTER_BLOCKS; $block ++) {
418
+ $obj = $block_object [$block];
419
+ $display = $obj->get_display_type();
420
+ if ($block == 0 || $display == AD_SELECT_BEFORE_PARAGRAPH || $display == AD_SELECT_AFTER_PARAGRAPH) {
421
+
422
+ $block_tags = trim ($block_object [$block]->get_paragraph_tags ());
423
+ $direction = $block_object [$block]->get_direction_type() == AD_DIRECTION_FROM_TOP ? 't' : 'b';
424
+ $paragraph_min_words = intval ($obj->get_minimum_paragraph_words());
425
+ $paragraph_max_words = intval ($obj->get_maximum_paragraph_words());
426
+ $paragraph_text_type = $obj->get_paragraph_text_type ();
427
+ $paragraph_text = trim (html_entity_decode ($obj->get_paragraph_text()));
428
+ $inside_blockquote = $obj->get_count_inside_blockquote ();
429
+
430
+ if ($block_tags != '') {
431
+ $found = false;
432
+ foreach ($paragraph_blocks as $index => $paragraph_block) {
433
+ if ($paragraph_block ['tags'] == $block_tags &&
434
+ $paragraph_block ['direction'] == $direction &&
435
+ $paragraph_block ['min'] == $paragraph_min_words &&
436
+ $paragraph_block ['max'] == $paragraph_max_words &&
437
+ $paragraph_block ['text_type'] == $paragraph_text_type &&
438
+ $paragraph_block ['text'] == $paragraph_text &&
439
+ $paragraph_block ['blockquote'] == $inside_blockquote
440
+ ) {
441
+ $found = true;
442
+ break;
443
+ }
444
+ }
445
+ if ($found) array_push ($paragraph_blocks [$index]['blocks'], $block); else
446
+ $paragraph_blocks []= array ('blocks' => array ($block),
447
+ 'tags' => $block_tags,
448
+ 'direction' => $direction,
449
+ 'min' => $paragraph_min_words,
450
+ 'max' => $paragraph_max_words,
451
+ 'text_type' => $paragraph_text_type,
452
+ 'text' => $paragraph_text,
453
+ 'blockquote' => $inside_blockquote,
454
+ );
455
+ }
456
+ }
457
+ }
458
+
459
+ foreach ($paragraph_blocks as $index => $paragraph_block) {
460
+ $block_class = $debug_positions === '' && in_array ($ai_wp_data [AI_WP_DEBUG_BLOCK], $paragraph_block ['blocks']) ? ' on' : '';
461
+ $wp_admin_bar->add_node (array (
462
+ 'id' => 'ai-toolbar-positions-'.$index,
463
+ 'parent' => 'ai-toolbar-positions',
464
+ 'title' => '<span class="ab-icon'.$block_class.'"></span>'.
465
+ $paragraph_block ['tags'].
466
+ ($paragraph_block ['direction'] == 'b' ? ' <span class="dashicons dashicons-arrow-up-alt up-icon"></span>' : '').
467
+ ($paragraph_block ['min'] != 0 ? ' min '.$paragraph_block ['min']. ' ' : '').
468
+ ($paragraph_block ['max'] != 0 ? ' max '.$paragraph_block ['max']. ' ' : '').
469
+ ($paragraph_block ['blockquote'] ? ' blockquote ' : '').
470
+ ($paragraph_block ['text'] != '' ? ($paragraph_block ['text_type'] == AD_DO_NOT_CONTAIN ? ' NC ' : ' C ').' '.$paragraph_block ['text'] : ''),
471
+ 'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $paragraph_block ['blocks'][0]),
472
+ ));
473
+ }
474
+
475
+ $wp_admin_bar->add_node (array (
476
+ 'id' => 'ai-toolbar-tags',
477
+ 'parent' => 'ai-toolbar-settings',
478
+ 'title' => '<span class="ab-icon'.$debug_tags_class.'"></span>Show HTML Tags',
479
+ 'href' => set_url_parameter (AI_URL_DEBUG_TAGS, $debug_tags),
480
+ ));
481
+ $wp_admin_bar->add_node (array (
482
+ 'id' => 'ai-toolbar-no-insertion',
483
+ 'parent' => 'ai-toolbar-settings',
484
+ 'title' => '<span class="ab-icon'.$debug_no_insertion_class.'"></span>Disable Insertion',
485
+ 'href' => set_url_parameter (AI_URL_DEBUG_NO_INSERTION, $debug_no_insertion),
486
+ ));
487
+ $wp_admin_bar->add_node (array (
488
+ 'id' => 'ai-toolbar-processing',
489
+ 'parent' => 'ai-toolbar-settings',
490
+ 'title' => '<span class="ab-icon'.$debug_processing_class.'"></span>Log Processing',
491
+ 'href' => set_url_parameter (AI_URL_DEBUG_PROCESSING, $debug_processing),
492
+ ));
493
+ }
494
+
495
+ function set_user () {
496
+ global $ai_wp_data;
497
+
498
+ if ($ai_wp_data [AI_WP_USER] != AI_USER_NOT_SET) return;
499
+
500
+ $ai_wp_data [AI_WP_USER] = AI_USER_NOT_LOGGED_IN;
501
+ if (is_user_logged_in ()) $ai_wp_data [AI_WP_USER] |= AI_USER_LOGGED_IN;
502
+ if (current_user_role () >= 5) $ai_wp_data [AI_WP_USER] |= AI_USER_ADMINISTRATOR;
503
+ }
504
+
505
+ function set_page_type () {
506
+ global $ai_wp_data;
507
+
508
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_NONE) return;
509
+
510
+ if (is_admin()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_ADMIN;
511
+ elseif (is_feed()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_FEED;
512
+ elseif (is_404()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_404;
513
+ elseif (is_front_page ()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_HOMEPAGE;
514
+ elseif (is_page()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_STATIC;
515
+ elseif (is_single()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_POST;
516
+ elseif (is_category()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_CATEGORY;
517
+ elseif (is_search()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_SEARCH;
518
+ elseif (is_archive()) $ai_wp_data [AI_WP_PAGE_TYPE] = AI_PT_ARCHIVE;
519
+ }
520
+
521
+ function ai_log_message ($message) {
522
+ global $ai_last_time, $ai_processing_log;
523
+ $ai_processing_log []= rtrim (sprintf ("%4d %-50s", (microtime () - $ai_last_time) * 1000, $message));
524
+ }
525
+
526
+ function ai_log_filter_content ($content_string) {
527
+
528
+ $content_string = preg_replace ("/\[\[AI_[A|B]P([\d].?)\]\]/", "", $content_string);
529
+ return str_replace (array ("<!--", "-->", "\n", "\r"), "", $content_string);
530
+ }
531
+
532
+ function ai_log_content (&$content) {
533
+ if (strlen ($content) < 100) ai_log (ai_log_filter_content ($content) . ' ['.strlen ($content).']');
534
+ ai_log (ai_log_filter_content (substr ($content, 0, 60)) . ' ... ' . ai_log_filter_content (substr ($content, - 60)) . ' ['.number_of_words ($content).']');
535
+ }
536
+
537
+ function ai_log_block_status ($block, $ai_last_check) {
538
+ global $block_object;
539
+
540
+ if ($ai_last_check == AI_CHECK_INSERTED) return "BLOCK $block INSERTED";
541
+ $status = "BLOCK $block FAILED CHECK: ";
542
+ $obj = $block_object [$block];
543
+ switch ($ai_last_check) {
544
+ case AI_CHECK_PAGE_TYPE_FRONT_PAGE: $status .= "ENABLED ON HOMEPAGE"; break;
545
+ case AI_CHECK_PAGE_TYPE_STATIC_PAGE: $status .= "ENABLED ON STATIC PAGE"; break;
546
+ case AI_CHECK_PAGE_TYPE_POST: $status .= "ENABLED ON POST"; break;
547
+ case AI_CHECK_PAGE_TYPE_CATEGORY: $status .= "ENABLED ON CATEGORY"; break;
548
+ case AI_CHECK_PAGE_TYPE_SEARCH: $status .= "ENABLED ON SEARCH"; break;
549
+ case AI_CHECK_PAGE_TYPE_ARCHIVE: $status .= "ENABLED ON ARCHIVE"; break;
550
+ case AI_CHECK_PAGE_TYPE_FEED: $status .= "ENABLED ON FEED"; break;
551
+ case AI_CHECK_PAGE_TYPE_404: $status .= "ENABLED ON 404"; break;
552
+
553
+
554
+ case AI_CHECK_DESKTOP_DEVICES: $status .= "DESKTOP DEVICES"; break;
555
+ case AI_CHECK_MOBILE_DEVICES: $status .= "MOBILE DEVICES"; break;
556
+ case AI_CHECK_TABLET_DEVICES: $status .= "TABLET DEVICES"; break;
557
+ case AI_CHECK_PHONE_DEVICES: $status .= "PHONE DEVICES"; break;
558
+ case AI_CHECK_DESKTOP_TABLET_DEVICES: $status .= "DESKTOP TABLET DEVICES"; break;
559
+ case AI_CHECK_DESKTOP_PHONE_DEVICES: $status .= "DESKTOP PHONE DEVICES"; break;
560
+
561
+ case AI_CHECK_CATEGORY: $status .= "CATEGORY"; break;
562
+ case AI_CHECK_TAG: $status .= "TAG"; break;
563
+ case AI_CHECK_ID: $status .= "ID"; break;
564
+ case AI_CHECK_URL: $status .= "URL"; break;
565
+ case AI_CHECK_URL_PARAMETER: $status .= "URL PARAMETER"; break;
566
+ case AI_CHECK_REFERER: $status .= "REFERER"; break;
567
+ case AI_CHECK_DATE: $status .= "DATE"; break;
568
+ case AI_CHECK_CODE: $status .= "CODE NOT EMPTY"; break;
569
+ case AI_CHECK_LOGGED_IN_USER: $status .= "LOGGED-IN USER"; break;
570
+ case AI_CHECK_NOT_LOGGED_IN_USER: $status .= "NOT LOGGED-IN USER"; break;
571
+ case AI_CHECK_ADMINISTRATOR: $status .= "ADMINISTRATOR"; break;
572
+
573
+ case AI_CHECK_ENABLED_ON_ALL_EXCEPT_ON_SELECTED: $status .= "ENABLED ON ALL EXCEPT ON SELECTED"; break;
574
+ case AI_CHECK_ENABLED_ONLY_ON_SELECTED: $status .= "ENABLED ONLY ON SELECTED"; break;
575
+ case AI_CHECK_DISABLED_MANUALLY: $status .= "404"; break;
576
+
577
+ case AI_CHECK_MAX_INSERTIONS: $status .= "MAX INSERTIONS " . $obj->get_maximum_insertions (); break;
578
+ case AI_CHECK_FILTER: $status .= "FILTER " . $obj->get_call_filter(); break;
579
+ case AI_CHECK_PARAGRAPH_COUNTING: $status .= "PARAGRAPH COUNTING"; break;
580
+ case AI_CHECK_NUMBER_OF_WORDS: $status .= "NUMBER OF WORDS"; break;
581
+ case AI_CHECK_DEBUG_NO_INSERTION: $status .= "DEBUG NO INSERTION"; break;
582
+ case AI_CHECK_PARAGRAPH_TAGS: $status .= "PARAGRAPH TAGS"; break;
583
+ case AI_CHECK_PARAGRAPHS_WITH_TAGS: $status .= "PARAGRAPHS WITH TAGS"; break;
584
+ case AI_CHECK_PARAGRAPHS_AFTER_BLOCKQUOTE: $status .= "PARAGRAPHS AFTER BLOCKQUOTE"; break;
585
+ case AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS: $status .= "PARAGRAPHS AFTER MIN MAX WORDS"; break;
586
+ case AI_CHECK_PARAGRAPHS_AFTER_TEXT: $status .= "PARAGRAPHS AFTER TEXT"; break;
587
+ case AI_CHECK_PARAGRAPHS_AFTER_CLEARANCE: $status .= "PARAGRAPHS AFTER CLEARANCE"; break;
588
+ case AI_CHECK_PARAGRAPHS_MIN_NUMBER: $status .= "PARAGRAPHS MIN NUMBER"; break;
589
+
590
+ case AI_CHECK_DO_NOT_INSERT: $status .= "PARAGRAPH CLEARANCE"; break;
591
+ case AI_CHECK_AD_ABOVE: $status .= "PARAGRAPH CLEARANCE ABOVE"; break;
592
+ case AI_CHECK_AD_BELOW: $status .= "PARAGRAPH CLEARANCE BELOW"; break;
593
+
594
+ case AI_CHECK_ENABLED: $status .= "ENABLED"; break;
595
+ case AI_CHECK_NONE: $status = "BLOCK $block"; break;
596
+ default: $status .= "?"; break;
597
+ }
598
+ $ai_last_check = AI_CHECK_NONE;
599
+ return $status;
600
+ }
601
+
602
+ function ai_log ($message = "") {
603
+ global $ai_last_time, $ai_processing_log;
604
+
605
+ if ($message != "") {
606
+ if ($message [strlen ($message) - 1] == "\n") {
607
+ ai_log_message (str_replace ("\n", "", $message));
608
+ $ai_processing_log []= "";
609
+ } else ai_log_message ($message);
610
+ } else $ai_processing_log []= "";
611
+ $ai_last_time = microtime ();
612
+ }
613
+
614
+ function remove_parameters_from_url ($url, $parameter = '') {
615
+ if ($parameter == '')
616
+ $parameters = array (AI_URL_DEBUG, AI_URL_DEBUG_PROCESSING, AI_URL_DEBUG_BLOCKS, AI_URL_DEBUG_USER, AI_URL_DEBUG_TAGS, AI_URL_DEBUG_POSITIONS, AI_URL_DEBUG_NO_INSERTION); else
617
+ $parameters = array ($parameter);
618
+
619
+ foreach ($parameters as $parameter) {
620
+ if (stripos ($url, '?'.$parameter.'=') !== false) {
621
+ $url = preg_replace ("/".$parameter."=[^&]*/", "", $url);
622
+ $url = rtrim (str_replace ('?&', '?', $url), "?");
623
+ }
624
+ elseif (stripos ($url, "&".$parameter."=") !== false)
625
+ $url = preg_replace ("/&".$parameter."=[^&]*/", "", $url);
626
+ }
627
+
628
+ return $url;
629
+ }
630
+
631
+ function current_url () {
632
+ if (isset ($_SERVER ["HTTPS"]) && $_SERVER ["HTTPS"] == "on")
633
+ $url = "https://"; else
634
+ $url = "http://";
635
+ $url .= $_SERVER ['SERVER_NAME'];
636
+ if($_SERVER['SERVER_PORT'] != 80)
637
+ $url .= ":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
638
+ $url .= $_SERVER["REQUEST_URI"];
639
+ return $url;
640
+ }
641
+
642
+ function set_url_parameter ($parameter, $value) {
643
+ $url = remove_parameters_from_url (current_url ());
644
+
645
+ if (stripos ($url, $parameter) !== false) {
646
+ $url = preg_replace ("/($parameter=[^&]*)/", $parameter .'=' . $value, $url);
647
+ } else {
648
+ if (strpos ($url, '?') !== false)
649
+ $url .= '&' . $parameter .'=' . $value; else
650
+ $url .= '?' . $parameter .'=' . $value;
651
+ }
652
+ return $url;
653
+ }
654
+
655
+ function number_of_words (&$content) {
656
+ $text = str_replace ("\r", "", $content);
657
+ $text = str_replace (array ("\n", " "), " ", $text);
658
+ $text = str_replace (" ", " ", $text);
659
+ $text = strip_tags ($text);
660
+ return count (explode (" ", $text));
661
+ }
662
+
663
+ function ai_wp_hook () {
664
+ global $ai_wp_data, $ai_db_options_extract;
665
+
666
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("WP HOOK START");
667
+ set_page_type ();
668
+ set_user ();
669
+
670
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_ADMIN)
671
+ add_action( 'admin_bar_menu', 'ai_toolbar', 20);
672
+
673
+ if (isset ($_GET [AI_URL_DEBUG_USER]) && $_GET [AI_URL_DEBUG_USER] != 0) $ai_wp_data [AI_WP_USER] = $_GET [AI_URL_DEBUG_USER];
674
+
675
+ $url_debugging = get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0;
676
+
677
+ if (!session_id()) session_start();
678
+
679
+ if (isset ($_GET [AI_URL_DEBUG]) && $_GET [AI_URL_DEBUG] == 0) {
680
+ unset ($_SESSION ['AI_WP_DEBUGGING']);
681
+ unset ($_SESSION ['AI_WP_DEBUG_BLOCK']);
682
+ } else {
683
+ if (isset ($_SESSION ['AI_WP_DEBUGGING'])) $_SESSION ['AI_WP_DEBUGGING'] |= $ai_wp_data [AI_WP_DEBUGGING]; else $_SESSION ['AI_WP_DEBUGGING'] = $ai_wp_data [AI_WP_DEBUGGING];
684
+ if (!isset ($_SESSION ['AI_WP_DEBUG_BLOCK'])) $_SESSION ['AI_WP_DEBUG_BLOCK'] = 0;
685
+
686
+ if (isset ($_GET [AI_URL_DEBUG_BLOCKS]))
687
+ if ($_GET [AI_URL_DEBUG_BLOCKS] && $url_debugging) $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_BLOCKS; else $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_BLOCKS;
688
+
689
+ if (isset ($_GET [AI_URL_DEBUG_TAGS]))
690
+ if ($_GET [AI_URL_DEBUG_TAGS] && $url_debugging) $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_TAGS; else $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_TAGS;
691
+
692
+ if (isset ($_GET [AI_URL_DEBUG_NO_INSERTION]))
693
+ if ($_GET [AI_URL_DEBUG_NO_INSERTION] && $url_debugging) $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_NO_INSERTION; else $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_NO_INSERTION;
694
+
695
+ if (isset ($_GET [AI_URL_DEBUG_POSITIONS])) {
696
+ if ($_GET [AI_URL_DEBUG_POSITIONS] !== '' && $url_debugging) $_SESSION ['AI_WP_DEBUGGING'] |= AI_DEBUG_POSITIONS; else $_SESSION ['AI_WP_DEBUGGING'] &= ~AI_DEBUG_POSITIONS;
697
+ if (is_numeric ($_GET [AI_URL_DEBUG_POSITIONS])) $_SESSION ['AI_WP_DEBUG_BLOCK'] = intval ($_GET [AI_URL_DEBUG_POSITIONS]);
698
+ if ($_SESSION ['AI_WP_DEBUG_BLOCK'] < 0 || $_SESSION ['AI_WP_DEBUG_BLOCK'] > AD_INSERTER_BLOCKS) $_SESSION ['AI_WP_DEBUG_BLOCK'] = 0;
699
+ }
700
+
701
+ $ai_wp_data [AI_WP_DEBUGGING] = $_SESSION ['AI_WP_DEBUGGING'];
702
+ $ai_wp_data [AI_WP_DEBUG_BLOCK] = $_SESSION ['AI_WP_DEBUG_BLOCK'];
703
+ }
704
+
705
+ $debug_positions = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0;
706
+ $debug_tags_positions = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS)) != 0;
707
+ $debug_tags_positions_blocks = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS | AI_DEBUG_BLOCKS)) != 0;
708
+
709
+ $plugin_priority = get_plugin_priority ();
710
+ if (isset ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_tags_positions)
711
+ add_filter ('the_content', 'ai_content_hook', $plugin_priority);
712
+
713
+ if (isset ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_tags_positions_blocks)
714
+ add_filter ('the_excerpt', 'ai_excerpt_hook', $plugin_priority);
715
+
716
+ if (isset ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
717
+ add_action ('loop_start', 'ai_loop_start_hook');
718
+
719
+ if (isset ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) && count ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) != 0 || $debug_positions)
720
+ add_action ('loop_end', 'ai_loop_end_hook');
721
+
722
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("WP HOOK END\n");
723
+ };
724
+
725
  function ai_init_hook() {
726
  global $block_object;
727
 
731
  function ai_admin_menu_hook () {
732
  global $ai_settings_page;
733
 
734
+ if (is_multisite() && !is_main_site () && !multisite_settings_page_enabled ()) return;
735
+
736
+ $ai_settings_page = add_submenu_page ('options-general.php', AD_INSERTER_NAME.' Options', AD_INSERTER_NAME, 'manage_options', basename(__FILE__), 'ai_settings');
737
  add_action ('admin_enqueue_scripts', 'ai_admin_enqueue_scripts');
738
  }
739
 
742
  global $ai_settings_page;
743
 
744
  if ($hook_suffix == $ai_settings_page) {
745
+ wp_enqueue_script ('ai-admin-js', plugins_url ('js/ad-inserter.js', __FILE__), array (
746
+ 'jquery',
747
+ 'jquery-ui-tabs',
748
+ 'jquery-ui-button',
749
+ 'jquery-ui-tooltip',
750
+ ), AD_INSERTER_VERSION);
751
+ wp_enqueue_style ('ai-admin-jquery-ui', plugins_url ('css/jquery-ui-1.10.3.custom.min.css', __FILE__), false, null);
752
+ wp_enqueue_style ('ai-admin', plugins_url ('css/ad-inserter.css', __FILE__), false, AD_INSERTER_VERSION);
753
+
754
+ // wp_add_inline_style ('ai-admin', AI_SETTINGS_STYLE);
755
+
756
+ if (AI_SYNTAX_HIGHLIGHTING) {
757
+ wp_enqueue_script ('ai-ace', plugins_url ('includes/ace/src-min-noconflict/ace.js', __FILE__ ), array (), AD_INSERTER_VERSION, true);
758
+ wp_enqueue_script ('ai-ace-ext-modelist', plugins_url ('includes/ace/src-min-noconflict/ext-modelist.js', __FILE__ ), array (), AD_INSERTER_VERSION, true);
759
+ }
760
  }
761
  }
762
 
763
  function ai_enqueue_scripts_hook () {
764
+ global $ai_wp_data;
765
+
766
+ $style = "#wp-admin-bar-ai-toolbar-settings .ab-icon:before {
767
+ content: '\\f111';
768
+ top: 2px;
769
+ color: rgba(240,245,250,.6)!important;
770
+ }
771
+ #wp-admin-bar-ai-toolbar-settings-default .ab-icon:before {
772
+ top: 0px;
773
+ }
774
+ #wp-admin-bar-ai-toolbar-settings .ab-icon.on:before {
775
+ color: #00f200!important;
776
+ }
777
+ #wp-admin-bar-ai-toolbar-settings-default li, #wp-admin-bar-ai-toolbar-settings-default a,
778
+ #wp-admin-bar-ai-toolbar-settings-default li:hover, #wp-admin-bar-ai-toolbar-settings-default a:hover {
779
+ border: 1px solid transparent;
780
+ }
781
+ #wp-admin-bar-ai-toolbar-blocks .ab-icon:before {
782
+ content: '\\f135';
783
+ }
784
+ #wp-admin-bar-ai-toolbar-positions .ab-icon:before {
785
+ content: '\\f207';
786
+ }
787
+ #wp-admin-bar-ai-toolbar-positions-default .ab-icon:before {
788
+ content: '\\f522';
789
+ }
790
+ #wp-admin-bar-ai-toolbar-tags .ab-icon:before {
791
+ content: '\\f475';
792
+ }
793
+ #wp-admin-bar-ai-toolbar-no-insertion .ab-icon:before {
794
+ content: '\\f214';
795
+ }
796
+ #wp-admin-bar-ai-toolbar-processing .ab-icon:before {
797
+ content: '\\f464';
798
+ }
799
+ #wp-admin-bar-ai-toolbar-positions span.up-icon {
800
+ padding-top: 2px;
801
+ }
802
+ #wp-admin-bar-ai-toolbar-positions .up-icon:before {
803
+ font: 400 20px/1 dashicons;
804
+ }";
805
+
806
+ if ($ai_wp_data [CLIENT_SIDE_DETECTION] || get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0)
807
+ wp_enqueue_style ('ai-frontend', plugins_url ('css/dummy.css', __FILE__), false, filemtime (plugin_dir_path (__FILE__ ).'css/dummy.css'));
808
+
809
+ if ($ai_wp_data [CLIENT_SIDE_DETECTION])
810
+ wp_add_inline_style ('ai-frontend', get_viewport_css ());
811
+
812
+ if (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0)
813
+ wp_add_inline_style ('ai-frontend', $style);
814
  }
815
 
816
  function ai_admin_notice_hook () {
841
  }
842
 
843
  function ai_plugin_action_links ($links) {
844
+ if (is_multisite() && !is_main_site () && !multisite_settings_page_enabled ()) return $links;
845
+
846
  $settings_link = '<a href="'.admin_url ('options-general.php?page=ad-inserter.php').'">Settings</a>';
847
  array_unshift ($links, $settings_link);
848
  return $links;
855
  if (stripos ($link, "update") !== false) unset ($links [$index]);
856
  }
857
  }
858
+ // if (stripos (AD_INSERTER_NAME, "pro") === false) {
859
  // $new_links = array ('donate' => '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4" target="_blank">Donate</a>');
860
  // $links = array_merge ($links, $new_links);
861
  // }
863
  return $links;
864
  }
865
 
866
+
867
+ function current_user_role ($user_role_name = "") {
868
  $role_values = array ("super-admin" => 6, "administrator" => 5, "editor" => 4, "author" => 3, "contributor" => 2, "subscriber" => 1);
869
  global $wp_roles;
870
 
871
+ if ($user_role_name != "") {
872
+ return isset ($role_values [$user_role_name]) ? $role_values [$user_role_name] : 0;
873
+ }
874
 
875
  $user_role = 0;
876
  $current_user = wp_get_current_user();
879
  // Fix for empty roles
880
  if (isset ($current_user->caps) && count ($current_user->caps) != 0) {
881
  $caps = $current_user->caps;
882
+ foreach ($role_values as $role_name => $role_value) {
883
+ if (isset ($caps [$role_name]) && $caps [$role_name]) $roles []= $role_name;
884
+ }
 
 
 
885
  }
886
 
887
  foreach ($roles as $role) {
889
  if ($current_user_role > $user_role) $user_role = $current_user_role;
890
  }
891
 
892
+ return $user_role;
893
+ }
894
+
895
+
896
+ function ai_current_user_role_ok () {
897
+ return current_user_role () >= current_user_role (get_minimum_user_role ());
898
  }
899
 
900
 
902
 
903
  if (!ai_current_user_role_ok ()) return;
904
 
905
+ if (is_multisite() && !is_main_site () && !multisite_exceptions_enabled ()) return;
906
+
907
  $screens = array ('post', 'page');
908
 
909
  foreach ($screens as $screen) {
910
  add_meta_box (
911
  'adinserter_sectionid',
912
+ AD_INSERTER_NAME.' Exceptions',
913
  'ai_meta_box_callback',
914
  $screen
915
  );
938
  echo ' <td style="padding: 0 10px 0 10px;">Automatic Display Type</td>';
939
  echo ' <td style="padding: 0 5px 0 5px;">Posts</td>';
940
  echo ' <td style="padding: 0 5px 0 5px;">Pages</td>';
941
+ echo ' <td style="padding: 0 5px 0 5px;">Widget</td>';
942
+ echo ' <td style="padding: 0 5px 0 5px;">Shortcode</td>';
943
  echo ' <td style="padding: 0 5px 0 5px;">PHP</td>';
944
  echo ' <td style="padding: 0 10px 0 10px;">Default</td>';
945
  echo ' <td style="padding: 0 10px 0 10px;">For this ', $post_type, '</td>';
974
  if ($obj->get_display_settings_page ()) echo '&check;';
975
  echo ' </td>';
976
  echo ' <td style="padding: 0 10px 0 10px; text-align: center;">';
977
+ if ($obj->get_enable_widget ()) echo '&check;';
978
+ echo ' </td>';
979
+ echo ' <td style="padding: 0 10px 0 10px; text-align: center;">';
980
  if ($obj->get_enable_manual ()) echo '&check;';
981
  echo ' </td>';
982
  echo ' <td style="padding: 0 10px 0 10px; text-align: center;">';
1011
  echo '</tbody>';
1012
  echo '</table>';
1013
 
1014
+ echo '<p>Default behavior for all code blocks for ', $post_type, 's (enabled or disabled) can be configured on <a href="', admin_url ('options-general.php?page=ad-inserter.php'), '" target="_blank">', AD_INSERTER_NAME, ' Settings page</a>. Here you can configure exceptions for this ', $post_type, '.</p>';
1015
  }
1016
 
1017
  function ai_save_meta_box_data_hook ($post_id) {
1047
  }
1048
 
1049
  function ai_widgets_init_hook () {
1050
+ if (is_multisite() && !is_main_site () && !multisite_widgets_enabled ()) return;
1051
  register_widget ('ai_widget');
1052
  }
1053
 
1054
  function ai_wp_head_hook () {
1055
+ global $block_object, $ai_wp_data;
1056
+
1057
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("HEAD HOOK START");
1058
+
1059
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_NONE;
1060
+
1061
+ $obj = $block_object [AI_HEADER_OPTION_NAME];
1062
+ $obj->clear_code_cache ();
1063
+
1064
+ if (!$obj->check_server_side_detection ()) return;
1065
 
1066
  if ($obj->get_enable_manual ()) {
1067
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_404 && !$obj->get_enable_404()) return;
1068
+ echo $obj->ai_getCode ();
1069
  }
1070
+
1071
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("HEAD HOOK END\n");
1072
  }
1073
 
1074
  function ai_wp_footer_hook () {
1075
+ global $block_object, $ai_wp_data;
1076
+
1077
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("FOOTER HOOK START");
1078
+
1079
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_FOOTER;
1080
+
1081
+ $obj = $block_object [AI_FOOTER_OPTION_NAME];
1082
+ $obj->clear_code_cache ();
1083
+
1084
+ if (!$obj->check_server_side_detection ()) return;
1085
 
1086
  if ($obj->get_enable_manual ()) {
1087
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_404 && !$obj->get_enable_404()) return;
1088
+ echo $obj->ai_getCode ();
1089
  }
1090
+
1091
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("FOOTER HOOK END\n");
1092
  }
1093
 
1094
+ function ai_write_debug_info ($write_processing_log = false) {
1095
+ global $block_object, $ai_last_time, $ai_processing_log, $ai_db_options_extract, $ai_wp_data, $ai_db_options;
1096
+
1097
+ echo sprintf ("%-25s%s\n\n", AD_INSERTER_NAME, AD_INSERTER_VERSION);
1098
+ echo "GENERATED (WP time): ", date ("Y-m-d H:i:s", time() + get_option ('gmt_offset') * 3600), "\n";
1099
+ echo "GENERATED (Server time): ", date ("Y-m-d H:i:s", time()), "\n";
1100
+
1101
+ echo "SETTINGS: ";
1102
+ if (isset ($ai_db_options ['global']['VERSION']))
1103
+ echo (int) ($ai_db_options ['global']['VERSION'][0].$ai_db_options ['global']['VERSION'][1]), '.',
1104
+ (int) ($ai_db_options ['global']['VERSION'][2].$ai_db_options ['global']['VERSION'][3]), '.',
1105
+ (int) ($ai_db_options ['global']['VERSION'][4].$ai_db_options ['global']['VERSION'][5]);
1106
+
1107
+ echo "\n";
1108
+ echo "SETTINGS TIMESTAMP: ";
1109
+ echo isset ($ai_db_options ['global']['TIMESTAMP']) ? date ("Y-m-d H:i:s", $ai_db_options ['global']['TIMESTAMP'] + get_option ('gmt_offset') * 3600) : "", "\n";
1110
+ echo "MULTISITE: ", is_multisite() ? "YES" : "NO", "\n";
1111
+ if (is_multisite()) {
1112
+ echo "MAIN SITE: ", is_main_site () ? "YES" : "NO", "\n";
1113
+ }
1114
 
1115
+ echo "USER: ";
1116
+ if (($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) == AI_USER_LOGGED_IN) echo "LOGGED-IN "; else echo "NOT LOGGED-IN ";
1117
+ if (($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) == AI_USER_ADMINISTRATOR) echo "ADMINISTRATOR";
1118
+ echo "\n";
1119
+ echo "PAGE TYPE: ";
1120
+ switch ($ai_wp_data [AI_WP_PAGE_TYPE]) {
1121
+ case AI_PT_STATIC: echo "STATIC PAGE"; break;
1122
+ case AI_PT_POST: echo "POST"; break;
1123
+ case AI_PT_HOMEPAGE: echo "HOMEPAGE"; break;
1124
+ case AI_PT_CATEGORY: echo "CATEGORY PAGE"; break;
1125
+ case AI_PT_ARCHIVE: echo "ARCHIVE PAGE"; break;
1126
+ case AI_PT_SEARCH: echo "SEARCH PAGE"; break;
1127
+ case AI_PT_404: echo "404 PAGE"; break;
1128
+ case AI_PT_FEED: echo "FEED"; break;
1129
+ default: echo "?"; break;
1130
  }
1131
+ echo "\n";
1132
+ echo 'ID: ', get_the_ID(), "\n";
1133
+ echo 'URL: ', $ai_wp_data [AI_WP_URL], "\n";
1134
+ echo 'REFERER: ', isset ($_SERVER['HTTP_REFERER']) ? remove_parameters_from_url ($_SERVER['HTTP_REFERER']) : "", "\n";
1135
+ echo 'CLIENT-SIDE DETECTION: ', $ai_wp_data [CLIENT_SIDE_DETECTION] ? 'USED' : "NOT USED", "\n";
1136
+ echo 'SERVER-SIDE DETECTION: ', $ai_wp_data [SERVER_SIDE_DETECTION] ? 'USED' : "NOT USED", "\n";
1137
+ if ($ai_wp_data [SERVER_SIDE_DETECTION]) {
1138
+ echo 'SERVER-SIDE DEVICE: ';
1139
+ if (AI_DESKTOP) echo "DESKTOP\n";
1140
+ elseif (AI_TABLET) echo "TABLET\n";
1141
+ elseif (AI_PHONE) echo "PHONE\n";
1142
+ else echo "?\n";
1143
+ }
1144
+
1145
+ echo "\n";
1146
+
1147
+ $default = new ai_Block (1);
1148
+
1149
+ echo "BLOCK SETTINGS Po Pa Hp Cp Ap Sp Fe 404 Wi Sh PHP\n";
1150
+ for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
1151
+ $obj = $block_object [$block];
1152
+
1153
+ $settings = "";
1154
+ $display_settings = '';
1155
+ $alignment_settings = '';
1156
+ $default_settings = true;
1157
+ $display_type = '';
1158
+ foreach (array_keys ($default->wp_options) as $key){
1159
+ switch ($key) {
1160
+ case AI_OPTION_CODE:
1161
+ case AI_OPTION_NAME:
1162
+ continue 2;
1163
+ case AI_OPTION_DISPLAY_ON_PAGES:
1164
+ case AI_OPTION_DISPLAY_ON_POSTS:
1165
+ case AI_OPTION_DISPLAY_ON_HOMEPAGE:
1166
+ case AI_OPTION_DISPLAY_ON_CATEGORY_PAGES:
1167
+ case AI_OPTION_DISPLAY_ON_SEARCH_PAGES:
1168
+ case AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES:
1169
+ case AI_OPTION_ENABLE_FEED:
1170
+ case AI_OPTION_ENABLE_404:
1171
+ case AI_OPTION_ENABLE_MANUAL:
1172
+ case AI_OPTION_ENABLE_WIDGET:
1173
+ case AI_OPTION_ENABLE_PHP_CALL:
1174
+ if ($obj->wp_options [$key] != $default->wp_options [$key]) $default_settings = false;
1175
+ continue 2;
1176
+ }
1177
+ if ($obj->wp_options [$key] != $default->wp_options [$key]) {
1178
+ $default_settings = false;
1179
+ switch ($key) {
1180
+ case AI_OPTION_DISPLAY_TYPE:
1181
+ $display_settings = $obj->wp_options [$key];
1182
+ break;
1183
+ case AI_OPTION_ALIGNMENT_TYPE:
1184
+ $alignment_settings = " " . $obj->wp_options [$key];
1185
+ break;
1186
+ case AI_OPTION_PARAGRAPH_TEXT:
1187
+ case AI_OPTION_AVOID_TEXT_ABOVE:
1188
+ case AI_OPTION_AVOID_TEXT_BELOW:
1189
+ $settings .= " " . $key . ": " . html_entity_decode ($obj->wp_options [$key]);
1190
+ break;
1191
+ default:
1192
+ $settings .= " " . $key . ": " . $obj->wp_options [$key];
1193
+ break;
1194
+ }
1195
+ } else
1196
+ switch ($key) {
1197
+ case AI_OPTION_DISPLAY_TYPE:
1198
+ $display_settings = $obj->wp_options [$key];
1199
+ break;
1200
+ case AI_OPTION_ALIGNMENT_TYPE:
1201
+ $alignment_settings = " " . $obj->wp_options [$key];
1202
+ break;
1203
+ }
1204
+ }
1205
+ if ($default_settings && $settings == '') continue;
1206
+ $settings = $display_settings . $alignment_settings . $settings;
1207
+
1208
+ echo sprintf ("%2d %-21s ", $block, substr ($obj->get_ad_name(), 0, 21));
1209
+
1210
+ echo $obj->get_display_settings_post() ? "o" : ".", " ";
1211
+ echo $obj->get_display_settings_page() ? "o" : ".", " ";
1212
+ echo $obj->get_display_settings_home() ? "o" : ".", " ";
1213
+ echo $obj->get_display_settings_category() ? "o" : ".", " ";
1214
+ echo $obj->get_display_settings_archive() ? "o" : ".", " ";
1215
+ echo $obj->get_display_settings_search() ? "o" : ".", " ";
1216
+ echo $obj->get_enable_feed() ? "o" : ".", " ";
1217
+ echo $obj->get_enable_404() ? "o" : ".", " ";
1218
+ echo $obj->get_enable_widget() ? "x" : ".", " ";
1219
+ echo $obj->get_enable_manual() ? "x" : ".", " ";
1220
+ echo $obj->get_enable_php_call() ? "x" : ".", " ";
1221
+
1222
+ echo $settings, "\n";
1223
+ }
1224
+ echo "\n";
1225
+
1226
+ echo "TOTAL BLOCKS\n";
1227
+ if (count ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][AI_PT_ANY]))
1228
+ echo "CONTENT HOOK BLOCKS: ", implode (", ", $ai_db_options_extract [CONTENT_HOOK_BLOCKS][AI_PT_ANY]), "\n";
1229
+ if (count ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][AI_PT_ANY]))
1230
+ echo "EXCERPT HOOK BLOCKS: ", implode (", ", $ai_db_options_extract [EXCERPT_HOOK_BLOCKS][AI_PT_ANY]), "\n";
1231
+ if (count ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][AI_PT_ANY]))
1232
+ echo "LOOP START HOOK BLOCKS: ", implode (", ", $ai_db_options_extract [LOOP_START_HOOK_BLOCKS][AI_PT_ANY]), "\n";
1233
+ if (count ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][AI_PT_ANY]))
1234
+ echo "LOOP END HOOK BLOCKS: ", implode (", ", $ai_db_options_extract [LOOP_END_HOOK_BLOCKS][AI_PT_ANY]), "\n";
1235
+
1236
+
1237
+ echo "\nPAGE TYPE BLOCKS\n";
1238
+ if (count ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
1239
+ echo "CONTENT HOOK BLOCKS: ", implode (", ", $ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
1240
+ if (count ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
1241
+ echo "EXCERPT HOOK BLOCKS: ", implode (", ", $ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
1242
+ if (count ($ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
1243
+ echo "LOOP START HOOK BLOCKS: ", implode (", ", $ai_db_options_extract [LOOP_START_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
1244
+ if (count ($ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]))
1245
+ echo "LOOP END HOOK BLOCKS: ", implode (", ", $ai_db_options_extract [LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]), "\n";
1246
+
1247
+ if ($write_processing_log) {
1248
+ echo "\nTIME EVENT\n";
1249
+ echo "======================================\n";
1250
+
1251
+ foreach ($ai_processing_log as $log_line) {
1252
+ echo $log_line, "\n";
1253
+ }
1254
+ }
1255
+ }
1256
+
1257
+ function ai_shutdown_hook () {
1258
+ global $ai_wp_data;
1259
+
1260
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) == 0 || !(get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0)) return;
1261
+ echo "\n<!--\n\n";
1262
+ ai_write_debug_info (true);
1263
+ echo "\n-->\n";
1264
+ }
1265
+
1266
+ function ai_check_multisite_options (&$multisite_options) {
1267
+ if (!isset ($multisite_options ['MULTISITE_SETTINGS_PAGE'])) $multisite_options ['MULTISITE_SETTINGS_PAGE'] = DEFAULT_MULTISITE_SETTINGS_PAGE;
1268
+ if (!isset ($multisite_options ['MULTISITE_WIDGETS'])) $multisite_options ['MULTISITE_WIDGETS'] = DEFAULT_MULTISITE_WIDGETS;
1269
+ if (!isset ($multisite_options ['MULTISITE_EXCEPTIONS'])) $multisite_options ['MULTISITE_EXCEPTIONS'] = DEFAULT_MULTISITE_EXCEPTIONS;
1270
+ }
1271
+
1272
+ function ai_check_plugin_options ($plugin_options = array ()) {
1273
+ global $version_string;
1274
 
1275
  $plugin_options ['VERSION'] = $version_string;
1276
 
1295
  }
1296
  $plugin_options ['PLUGIN_PRIORITY'] = $plugin_priority;
1297
 
1298
+ if (!isset ($plugin_options ['REMOTE_DEBUGGING'])) $plugin_options ['REMOTE_DEBUGGING'] = DEFAULT_REMOTE_DEBUGGING;
1299
+ if (!isset ($plugin_options ['JAVASCRIPT_DEBUGGING'])) $plugin_options ['JAVASCRIPT_DEBUGGING'] = DEFAULT_JAVASCRIPT_DEBUGGING;
1300
 
1301
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
1302
  $viewport_name_option_name = 'VIEWPORT_NAME_' . $viewport;
1345
  return ($plugin_options);
1346
  }
1347
 
1348
+ function option_stripslashes (&$options) {
 
 
1349
  if (is_array ($options)) {
1350
  foreach ($options as $key => $option) {
1351
+ option_stripslashes ($options [$key]);
1352
  }
1353
  } else if (is_string ($options)) $options = stripslashes ($options);
1354
+ }
1355
 
1356
+ // Deprecated
1357
+ function ai_get_option ($option_name) {
1358
+ $options = get_option ($option_name);
1359
+ option_stripslashes ($options);
1360
  return ($options);
1361
  }
1362
 
1363
  function ai_load_options () {
1364
+ global $ai_db_options, $ai_db_options_multisite, $ai_wp_data;
1365
+
1366
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("LOAD OPTIONS START");
1367
 
1368
  $ai_db_options = get_option (WP_OPTION_NAME);
1369
+ option_stripslashes ($ai_db_options);
1370
 
1371
+ if (is_multisite()) {
1372
+ $ai_db_options_multisite = get_site_option (WP_OPTION_NAME);
1373
+ option_stripslashes ($ai_db_options_multisite);
 
 
 
 
 
1374
  }
1375
+
1376
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("LOAD OPTIONS END");
1377
+ }
1378
+
1379
+ function get_viewport_css () {
1380
+ global $ai_db_options;
1381
+
1382
+ if (isset ($ai_db_options [AI_GLOBAL_OPTION_NAME])) $plugin_db_options = $ai_db_options [AI_GLOBAL_OPTION_NAME]; else $plugin_db_options = '';
1383
+ if (!$plugin_db_options) $plugin_db_options = get_option (AD_OPTIONS); // Old options
1384
+
1385
+ if (!isset ($plugin_db_options ['VIEWPORT_CSS'])) $plugin_db_options ['VIEWPORT_CSS'] = generate_viewport_css ();
1386
+
1387
+ return ($plugin_db_options ['VIEWPORT_CSS']);
1388
  }
1389
 
1390
  function get_syntax_highlighter_theme () {
1439
  return ($plugin_db_options ['PLUGIN_PRIORITY']);
1440
  }
1441
 
1442
+ function get_remote_debugging () {
1443
  global $ai_db_options;
1444
 
1445
  if (isset ($ai_db_options [AI_GLOBAL_OPTION_NAME])) $plugin_db_options = $ai_db_options [AI_GLOBAL_OPTION_NAME]; else $plugin_db_options = '';
 
1446
 
1447
+ if (!isset ($plugin_db_options ['REMOTE_DEBUGGING']) || $plugin_db_options ['REMOTE_DEBUGGING'] == '') {
1448
+ $plugin_db_options ['REMOTE_DEBUGGING'] = DEFAULT_REMOTE_DEBUGGING;
1449
+ }
1450
+
1451
+ return ($plugin_db_options ['REMOTE_DEBUGGING']);
1452
+ }
1453
+
1454
+ function get_javascript_debugging () {
1455
+ global $ai_db_options;
1456
+
1457
+ if (isset ($ai_db_options [AI_GLOBAL_OPTION_NAME])) $plugin_db_options = $ai_db_options [AI_GLOBAL_OPTION_NAME]; else $plugin_db_options = '';
1458
+
1459
+ if (!isset ($plugin_db_options ['JAVASCRIPT_DEBUGGING']) || $plugin_db_options ['JAVASCRIPT_DEBUGGING'] == '') {
1460
+ $plugin_db_options ['JAVASCRIPT_DEBUGGING'] = DEFAULT_JAVASCRIPT_DEBUGGING;
1461
+ }
1462
+
1463
+ return ($plugin_db_options ['JAVASCRIPT_DEBUGGING']);
1464
+ }
1465
+
1466
+ function multisite_settings_page_enabled () {
1467
+ global $ai_db_options_multisite;
1468
+
1469
+ if (is_multisite()) {
1470
+ if (!isset ($ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE']) || $ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE'] == '') {
1471
+ $ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE'] = DEFAULT_MULTISITE_SETTINGS_PAGE;
1472
+ }
1473
+
1474
+ return ($ai_db_options_multisite ['MULTISITE_SETTINGS_PAGE']);
1475
+ }
1476
+
1477
+ return DEFAULT_MULTISITE_SETTINGS_PAGE;
1478
+ }
1479
+
1480
+ function multisite_widgets_enabled () {
1481
+ global $ai_db_options_multisite;
1482
+
1483
+ if (is_multisite()) {
1484
+ if (!isset ($ai_db_options_multisite ['MULTISITE_WIDGETS']) || $ai_db_options_multisite ['MULTISITE_WIDGETS'] == '') {
1485
+ $ai_db_options_multisite ['MULTISITE_WIDGETS'] = DEFAULT_MULTISITE_WIDGETS;
1486
+ }
1487
+
1488
+ return ($ai_db_options_multisite ['MULTISITE_WIDGETS']);
1489
+ }
1490
+
1491
+ return DEFAULT_MULTISITE_WIDGETS;
1492
+ }
1493
+
1494
+ function multisite_exceptions_enabled () {
1495
+ global $ai_db_options_multisite;
1496
+
1497
+ if (is_multisite()) {
1498
+ if (!isset ($ai_db_options_multisite ['MULTISITE_EXCEPTIONS']) || $ai_db_options_multisite ['MULTISITE_EXCEPTIONS'] == '') {
1499
+ $ai_db_options_multisite ['MULTISITE_EXCEPTIONS'] = DEFAULT_MULTISITE_EXCEPTIONS;
1500
+ }
1501
+
1502
+ return ($ai_db_options_multisite ['MULTISITE_EXCEPTIONS']);
1503
  }
1504
 
1505
+ return DEFAULT_MULTISITE_EXCEPTIONS;
1506
  }
1507
 
1508
  function get_viewport_name ($viewport_number) {
1560
  $value = str_replace (array ("\\", "/", "?", "\"", "<", ">", "[", "]"), "", $value);
1561
  $value = esc_html ($value);
1562
  }
1563
+ elseif (
1564
+ $option == AI_OPTION_PARAGRAPH_TEXT ||
1565
+ $option == AI_OPTION_AVOID_TEXT_ABOVE ||
1566
+ $option == AI_OPTION_AVOID_TEXT_BELOW
1567
+ ) {
1568
  $value = esc_html ($value);
1569
  }
1570
  elseif ($option == AI_OPTION_NAME ||
1572
  $option == AI_OPTION_DOMAIN_LIST ||
1573
  $option == AI_OPTION_CATEGORY_LIST ||
1574
  $option == AI_OPTION_TAG_LIST ||
1575
+ $option == AI_OPTION_ID_LIST ||
1576
  $option == AI_OPTION_URL_LIST ||
1577
+ $option == AI_OPTION_URL_PARAMETER_LIST ||
1578
  $option == AI_OPTION_PARAGRAPH_TEXT_TYPE ||
1579
  $option == AI_OPTION_PARAGRAPH_NUMBER ||
1580
  $option == AI_OPTION_MIN_PARAGRAPHS ||
1581
+ $option == AI_OPTION_AVOID_PARAGRAPHS_ABOVE ||
1582
+ $option == AI_OPTION_AVOID_PARAGRAPHS_BELOW ||
1583
+ $option == AI_OPTION_AVOID_TRY_LIMIT ||
1584
  $option == AI_OPTION_MIN_WORDS ||
1585
+ $option == AI_OPTION_MAX_WORDS ||
1586
  $option == AI_OPTION_MIN_PARAGRAPH_WORDS ||
1587
+ $option == AI_OPTION_MAX_PARAGRAPH_WORDS ||
1588
  $option == AI_OPTION_MAXIMUM_INSERTIONS ||
1589
  $option == AI_OPTION_AFTER_DAYS ||
1590
  $option == AI_OPTION_EXCERPT_NUMBER ||
1603
  } elseif ($option == AI_OPTION_ENABLE_MANUAL) {
1604
  } elseif ($option == AI_OPTION_PROCESS_PHP) {
1605
  } elseif ($option == AI_OPTION_ENABLE_404) {
1606
+ } elseif ($option == AI_OPTION_DETECT_SERVER_SIDE) {
1607
+ } elseif ($option == AI_OPTION_DISPLAY_FOR_DEVICES) {
1608
  }
1609
 
1610
  return $value;
1611
  }
1612
 
1613
  function ai_preview () {
1614
+ global $ai_db_options, $block_object;
1615
 
1616
+ check_admin_referer ("adinserter_data", "ai_check");
1617
 
1618
+ if (isset ($_GET ["preview"])) {
1619
+ $block = $_GET ["preview"];
1620
  if (is_numeric ($block) && $block >= 1 && $block <= AD_INSERTER_BLOCKS) {
1621
  generate_code_preview ($block);
1622
  }
1623
  }
1624
 
1625
+ if (isset ($_GET ["export"])) {
1626
+ $block = $_GET ["export"];
1627
+ if (is_numeric ($block)) {
1628
+ if ($block == 0) echo base64_encode (serialize ($ai_db_options));
1629
+ elseif ($block >= 1 && $block <= AD_INSERTER_BLOCKS) {
1630
+ $obj = $block_object [$block];
1631
+ echo base64_encode (serialize ($obj->wp_options));
1632
+ }
1633
+ }
1634
+ }
1635
+
1636
  die ();
1637
  }
1638
 
1639
+ function ai_generate_extract (&$settings) {
1640
+
1641
+ $obj = new ai_Block (1);
1642
+
1643
+ $extract = array ();
1644
+ $content_hook_blocks = array ();
1645
+ $excerpt_hook_blocks = array ();
1646
+ $loop_start_hook_blocks = array ();
1647
+ $loop_end_hook_blocks = array ();
1648
+
1649
+ $content_hook_blocks = array (AI_PT_ANY => array (), AI_PT_HOMEPAGE => array(), AI_PT_CATEGORY => array(), AI_PT_SEARCH => array(), AI_PT_ARCHIVE => array(), AI_PT_STATIC => array(), AI_PT_POST => array(), AI_PT_404 => array(), AI_PT_FEED => array());
1650
+ $excerpt_hook_blocks = array (AI_PT_ANY => array (), AI_PT_HOMEPAGE => array(), AI_PT_CATEGORY => array(), AI_PT_SEARCH => array(), AI_PT_ARCHIVE => array(), AI_PT_STATIC => array(), AI_PT_POST => array(), AI_PT_404 => array(), AI_PT_FEED => array());
1651
+ $loop_start_hook_blocks = array (AI_PT_ANY => array (), AI_PT_HOMEPAGE => array(), AI_PT_CATEGORY => array(), AI_PT_SEARCH => array(), AI_PT_ARCHIVE => array(), AI_PT_STATIC => array(), AI_PT_POST => array(), AI_PT_404 => array(), AI_PT_FEED => array());
1652
+ $loop_end_hook_blocks = array (AI_PT_ANY => array (), AI_PT_HOMEPAGE => array(), AI_PT_CATEGORY => array(), AI_PT_SEARCH => array(), AI_PT_ARCHIVE => array(), AI_PT_STATIC => array(), AI_PT_POST => array(), AI_PT_404 => array(), AI_PT_FEED => array());
1653
+
1654
+ // Generate extracted data
1655
+ for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
1656
+ $obj->number = $block;
1657
+ $obj->wp_options = $settings [$block];
1658
+
1659
+ $page_types = array ();
1660
+ if ($obj->get_display_settings_home()) $page_types []= AI_PT_HOMEPAGE;
1661
+ if ($obj->get_display_settings_page()) $page_types []= AI_PT_STATIC;
1662
+ if ($obj->get_display_settings_post()) $page_types []= AI_PT_POST;
1663
+ if ($obj->get_display_settings_category()) $page_types []= AI_PT_CATEGORY;
1664
+ if ($obj->get_display_settings_search()) $page_types []= AI_PT_SEARCH;
1665
+ if ($obj->get_display_settings_archive()) $page_types []= AI_PT_ARCHIVE;
1666
+ if ($obj->get_enable_feed()) $page_types []= AI_PT_FEED;
1667
+ if ($obj->get_enable_404()) $page_types []= AI_PT_404;
1668
+
1669
+ if ($page_types) {
1670
+ switch ($obj->get_display_type()) {
1671
+ case AD_SELECT_BEFORE_PARAGRAPH:
1672
+ case AD_SELECT_AFTER_PARAGRAPH:
1673
+ case AD_SELECT_BEFORE_CONTENT:
1674
+ case AD_SELECT_AFTER_CONTENT:
1675
+ foreach ($page_types as $block_page_type) $content_hook_blocks [$block_page_type][]= $block;
1676
+ $content_hook_blocks [AI_PT_ANY][]= $block;
1677
+ break;
1678
+ case AD_SELECT_BEFORE_EXCERPT:
1679
+ case AD_SELECT_AFTER_EXCERPT:
1680
+ foreach ($page_types as $block_page_type) $excerpt_hook_blocks [$block_page_type][]= $block;
1681
+ $excerpt_hook_blocks [AI_PT_ANY][]= $block;
1682
+ break;
1683
+ case AD_SELECT_BEFORE_POST:
1684
+ foreach ($page_types as $block_page_type) $loop_start_hook_blocks [$block_page_type][]= $block;
1685
+ $loop_start_hook_blocks [AI_PT_ANY][]= $block;
1686
+ break;
1687
+ case AD_SELECT_AFTER_POST:
1688
+ foreach ($page_types as $block_page_type) $loop_end_hook_blocks [$block_page_type][]= $block;
1689
+ $loop_end_hook_blocks [AI_PT_ANY][]= $block;
1690
+ break;
1691
+ }
1692
+ }
1693
+ }
1694
+
1695
+ $extract [CONTENT_HOOK_BLOCKS] = $content_hook_blocks;
1696
+ $extract [EXCERPT_HOOK_BLOCKS] = $excerpt_hook_blocks;
1697
+ $extract [LOOP_START_HOOK_BLOCKS] = $loop_start_hook_blocks;
1698
+ $extract [LOOP_END_HOOK_BLOCKS] = $loop_end_hook_blocks;
1699
+
1700
+ return ($extract);
1701
+ }
1702
+
1703
+ function ai_load_settings () {
1704
+ global $ai_db_options, $block_object, $ai_db_options_extract, $ai_wp_data, $version_string;
1705
+
1706
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("LOAD SETTINGS START");
1707
+
1708
+ ai_load_options ();
1709
+
1710
+ if (isset ($ai_db_options [AI_EXTRACT_OPTION_NAME]) && $ai_db_options ['global']['VERSION'] == $version_string)
1711
+ $ai_db_options_extract = $ai_db_options [AI_EXTRACT_OPTION_NAME]; else
1712
+ $ai_db_options_extract = ai_generate_extract ($ai_db_options);
1713
+
1714
+ $obj = new ai_Block (0);
1715
+ $obj->wp_options [AI_OPTION_NAME] = 'Default';
1716
+ $block_object [0] = $obj;
1717
+ for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
1718
+ $obj = new ai_Block ($block);
1719
+ $obj->load_options ($block);
1720
+ $block_object [$block] = $obj;
1721
+ }
1722
+
1723
+ $adH = new ai_AdH();
1724
+ $adF = new ai_AdF();
1725
+ $adH->load_options (AI_HEADER_OPTION_NAME);
1726
+ $adF->load_options (AI_FOOTER_OPTION_NAME);
1727
+ $block_object [AI_HEADER_OPTION_NAME] = $adH;
1728
+ $block_object [AI_FOOTER_OPTION_NAME] = $adF;
1729
+
1730
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("LOAD SETTINGS END");
1731
+ }
1732
+
1733
+
1734
+ function generate_viewport_css () {
1735
+
1736
+ $viewports = array ();
1737
+ for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
1738
+ $viewport_name = get_viewport_name ($viewport);
1739
+ $viewport_width = get_viewport_width ($viewport);
1740
+ if ($viewport_name != '') {
1741
+ $viewports []= array ('index' => $viewport, 'name' => $viewport_name, 'width' => $viewport_width);
1742
+ }
1743
+ }
1744
+
1745
+ $viewport_styles = '';
1746
+ if (count ($viewports) != 0) {
1747
+ // $viewport_styles .= "/* " . AD_INSERTER_NAME . " version " . AD_INSERTER_VERSION ." - viewport classes */\n\n";
1748
+ // $viewport_styles .= "/* DO NOT MODIFY - This file is automatically generated when you save ".AD_INSERTER_NAME." settings */\n";
1749
+ foreach ($viewports as $index => $viewport) {
1750
+ // $viewport_styles .= "\n/* " . $viewport ['name'] . " */\n\n";
1751
+ if ($viewport ['index'] == 1) {
1752
+ foreach (array_reverse ($viewports) as $index2 => $viewport2) {
1753
+ if ($viewport2 ['index'] != 1) {
1754
+ $viewport_styles .= ".ai-viewport-" . $viewport2 ['index'] . " { display: none !important;}\n";
1755
+ }
1756
+ }
1757
+ $viewport_styles .= ".ai-viewport-1 { display: inherit !important;}\n";
1758
+ $viewport_styles .= ".ai-viewport-0 { display: none !important;}\n";
1759
+ } else {
1760
+ $viewport_styles .= "@media ";
1761
+ if ($index != count ($viewports) - 1)
1762
+ $viewport_styles .= "(min-width: " . $viewport ['width'] . "px) and ";
1763
+ $viewport_styles .= "(max-width: " . ($viewports [$index - 1]['width'] - 1) . "px) {\n";
1764
+ foreach ($viewports as $index2 => $viewport2) {
1765
+ if ($viewport2 ['index'] == 1)
1766
+ $viewport_styles .= ".ai-viewport-" . $viewport2 ['index'] . " { display: none !important;}\n";
1767
+ elseif ($viewport ['index'] == $viewport2 ['index'])
1768
+ $viewport_styles .= ".ai-viewport-" . $viewport2 ['index'] . " { display: inherit !important;}\n";
1769
+
1770
+ }
1771
+ $viewport_styles .= "}\n";
1772
+ }
1773
+ }
1774
+ }
1775
+ return ($viewport_styles);
1776
+ }
1777
+
1778
+
1779
  function ai_settings () {
1780
  global $ai_db_options, $block_object;
1781
 
1782
  if (isset ($_POST [AI_FORM_SAVE])) {
1783
 
1784
+ // echo count ($_POST);
1785
+ // print_r ($_POST);
1786
+
1787
  check_admin_referer ('save_adinserter_settings');
1788
 
1789
+ $subpage = 'main';
1790
+ $start = 1;
1791
+ $end = 16;
1792
+ if (function_exists ('ai_settings_parameters')) ai_settings_parameters ($subpage, $start, $end);
1793
+
1794
+ $invalid_blocks = array ();
1795
+
1796
  $import_switch_name = AI_OPTION_IMPORT . WP_FORM_FIELD_POSTFIX . '0';
1797
  if (isset ($_POST [$import_switch_name]) && $_POST [$import_switch_name] == "1") {
1798
  // Import Ad Inserter settings
1806
  // Try to import individual settings
1807
  $ai_options = array ();
1808
 
 
1809
  for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
1810
  $ad = new ai_Block ($block);
1811
 
1812
  if (isset ($ai_db_options [$block])) $saved_settings = $ai_db_options [$block]; else
1813
  $saved_settings = $ad->wp_options;
1814
 
1815
+ if ($block < $start || $block > $end) {
1816
+ $ai_options [$block] = $saved_settings;
1817
+ continue;
1818
+ }
1819
+
1820
+ $block_settings = 0;
1821
  $import_switch_name = AI_OPTION_IMPORT . WP_FORM_FIELD_POSTFIX . $block;
1822
  if (isset ($_POST [$import_switch_name]) && $_POST [$import_switch_name] == "1") {
1823
 
1824
  $exported_settings = @unserialize (base64_decode (str_replace (array ("\\\""), array ("\""), $_POST ["export_settings_" . $block])));
1825
+
1826
  if ($exported_settings !== false) {
1827
  foreach (array_keys ($ad->wp_options) as $key){
1828
  if ($key == AI_OPTION_NAME) {
1833
  } else {
1834
  if (isset ($exported_settings [$key])) {
1835
  $ad->wp_options [$key] = filter_option ($key, $exported_settings [$key], false);
1836
+ $block_settings ++;
1837
  }
1838
  }
1839
  }
1846
  $form_field_name = $key . WP_FORM_FIELD_POSTFIX . $block;
1847
  if (isset ($_POST [$form_field_name])){
1848
  $ad->wp_options [$key] = filter_option ($key, $_POST [$form_field_name]);
1849
+ $block_settings ++;
1850
  }
1851
  }
1852
  }
1853
 
1854
+ $ai_options [$block] = $ad->wp_options;
 
 
 
1855
  delete_option (str_replace ("#", $block, AD_ADx_OPTIONS));
1856
  }
1857
 
1883
  $options ['BLOCK_CLASS_NAME'] = filter_html_class ($_POST ['block-class-name']);
1884
  $options ['MINIMUM_USER_ROLE'] = filter_string ($_POST ['minimum-user-role']);
1885
  $options ['PLUGIN_PRIORITY'] = filter_option ('plugin_priority', $_POST ['plugin_priority']);
1886
+ $options ['REMOTE_DEBUGGING'] = filter_option ('remote_debugging', $_POST ['remote_debugging']);
1887
+ $options ['JAVASCRIPT_DEBUGGING'] = filter_option ('javascript_debugging', $_POST ['javascript_debugging']);
1888
 
1889
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
1890
  if (isset ($_POST ['viewport-name-'.$viewport]))
1893
  $options ['VIEWPORT_WIDTH_'.$viewport] = filter_option ('viewport_width', $_POST ['viewport-width-'.$viewport]);
1894
  }
1895
 
1896
+ $options ['VIEWPORT_CSS'] = generate_viewport_css ();
1897
+
1898
  $ai_options [AI_GLOBAL_OPTION_NAME] = ai_check_plugin_options ($options);
1899
  }
1900
 
1901
  if (!empty ($invalid_blocks)) {
1902
  if ($invalid_blocks [0] == 0) {
1903
+ echo "<div class='error' style='margin: 5px 15px 2px 0px; padding: 10px;'>Error importing ", AD_INSERTER_NAME, " settings.</div>";
1904
  } else echo "<div class='error' style='margin: 5px 15px 2px 0px; padding: 10px;'>Error importing settings for block", count ($invalid_blocks) == 1 ? "" : "s:", " ", implode (", ", $invalid_blocks), ".</div>";
1905
  }
1906
 
1907
+ // Generate and save extract
1908
+ $ai_options [AI_EXTRACT_OPTION_NAME] = ai_generate_extract ($ai_options);
1909
+
1910
  $ai_options [AI_GLOBAL_OPTION_NAME]['TIMESTAMP'] = time ();
1911
 
1912
  update_option (WP_OPTION_NAME, $ai_options);
1913
 
1914
+ // Multisite
1915
+ if (is_multisite () && is_main_site ()) {
1916
+ $options = array ();
1917
+ $options ['MULTISITE_SETTINGS_PAGE'] = filter_option ('multisite_settings_page', $_POST ['multisite_settings_page']);
1918
+ $options ['MULTISITE_WIDGETS'] = filter_option ('multisite_widgets', $_POST ['multisite_widgets']);
1919
+ $options ['MULTISITE_EXCEPTIONS'] = filter_option ('multisite_exceptions', $_POST ['multisite_exceptions']);
1920
+ ai_check_multisite_options ($options);
1921
+ update_site_option (WP_OPTION_NAME, $options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1922
  }
 
1923
 
1924
+ ai_load_settings ();
 
 
 
 
1925
 
1926
  delete_option (str_replace ("#", "Header", AD_ADx_OPTIONS));
1927
  delete_option (str_replace ("#", "Footer", AD_ADx_OPTIONS));
1933
 
1934
  check_admin_referer ('save_adinserter_settings');
1935
 
 
 
1936
  for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
 
 
 
1937
  delete_option (str_replace ("#", $block, AD_ADx_OPTIONS));
1938
  }
1939
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1940
  delete_option (str_replace ("#", "Header", AD_ADx_OPTIONS));
1941
  delete_option (str_replace ("#", "Footer", AD_ADx_OPTIONS));
1942
  delete_option (AD_OPTIONS);
1943
 
1944
+ delete_option (WP_OPTION_NAME);
1945
+ delete_option (WP_AD_INSERTER_PRO_LICENSE);
1946
+ if (is_multisite () && is_main_site ()) {
1947
+ delete_site_option (WP_OPTION_NAME, $options);
1948
+ }
1949
+
1950
+ ai_load_settings ();
1951
+
1952
  echo "<div class='error' style='margin: 5px 15px 2px 0px; padding: 10px;'>Settings cleared.</div>";
1953
  }
1954
 
1956
  }
1957
 
1958
 
1959
+ function ai_adinserter ($ad_number = '', $ignore = ''){
1960
+ global $block_object, $ad_interter_globals, $ai_wp_data, $ai_last_check;
1961
 
1962
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
1963
 
1964
+ if ($ad_number == "") return "";
1965
  if (!is_numeric ($ad_number)) return "";
 
1966
  $ad_number = (int) $ad_number;
 
1967
  if ($ad_number < 1 || $ad_number > AD_INSERTER_BLOCKS) return "";
1968
 
1969
+ $globals_name = AI_PHP_FUNCTION_CALL_COUNTER_NAME . $ad_number;
 
 
 
1970
 
1971
  if (!isset ($ad_interter_globals [$globals_name])) {
1972
  $ad_interter_globals [$globals_name] = 1;
1973
  } else $ad_interter_globals [$globals_name] ++;
1974
 
1975
+ if ($debug_processing) ai_log ("PHP FUNCTION CALL adinserter ($ad_number".($ignore == '' ? '' : ', \''.$ignore)."') [" . $ad_interter_globals [$globals_name] . ']');
1976
 
1977
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_PHP_FUNCTION;
 
1978
 
1979
+ $ignore_array = array ();
1980
+ if (trim ($ignore) != '') {
1981
+ $ignore_array = explode (",", str_replace (" ", "", $ignore));
 
 
 
 
 
 
1982
  }
1983
 
1984
+ $obj = $block_object [$ad_number];
1985
+ $obj->clear_code_cache ();
 
 
 
 
 
 
 
1986
 
1987
+ $ai_last_check = AI_CHECK_ENABLED;
1988
+ if (!$obj->get_enable_php_call ()) return "";
1989
+ if (!$obj->check_server_side_detection ()) return "";
1990
+ if (!$obj->check_page_types_lists_users (in_array ("page_type", $ignore_array))) return "";
1991
+ if (!$obj->check_filter ($ad_interter_globals [$globals_name])) return "";
 
 
 
 
1992
 
1993
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_POST || $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_STATIC) {
1994
  $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1995
  $selected_blocks = explode (",", $meta_value);
1996
 
1997
+ if (!$obj->check_post_page_exceptions ($selected_blocks)) return "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1998
  }
1999
 
2000
+ // Last check before insertion
2001
+ if (!$obj->check_and_increment_block_counter ()) return "";
2002
+
2003
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
2004
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) != 0) return "";
2005
 
2006
+ $ai_last_check = AI_CHECK_INSERTED;
2007
+ return $obj->get_code_for_insertion ();
2008
+ }
2009
 
2010
+ function adinserter ($block = '', $ignore = '') {
2011
+ global $ai_last_check, $ai_wp_data;
2012
 
2013
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
2014
+ $ai_last_check = AI_CHECK_NONE;
2015
+ $code = ai_adinserter ($block, $ignore);
2016
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($block, $ai_last_check));
2017
+ if ($debug_processing) ai_log ("PHP FUNCTION CALL END\n");
2018
 
2019
+ return $code;
2020
+ }
2021
 
 
2022
 
 
 
 
 
 
 
2023
 
2024
+ function ai_content_hook ($content = ''){
2025
+ global $block_object, $ad_interter_globals, $ai_db_options_extract, $ai_wp_data, $ai_last_check;
2026
 
2027
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_ADMIN) return;
2028
 
2029
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
2030
+ $globals_name = AI_CONTENT_COUNTER_NAME;
2031
 
2032
+ if (!isset ($ad_interter_globals [$globals_name])) {
2033
+ $ad_interter_globals [$globals_name] = 1;
2034
+ } else $ad_interter_globals [$globals_name] ++;
2035
 
2036
+ if ($debug_processing) ai_log ("CONTENT HOOK START [" . $ad_interter_globals [$globals_name] . ']');
2037
 
2038
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_CONTENT;
 
2039
 
2040
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
2041
+ $content_words = number_of_words ($content);
 
2042
 
2043
+ $positions_inserted = false;
2044
+ if ($ai_wp_data [AI_WP_DEBUG_BLOCK] == 0) {
2045
+ $preview = $block_object [0];
2046
+ $content = $preview->before_paragraph ($content, true);
2047
+ $content = $preview->after_paragraph ($content, true);
2048
+ $positions_inserted = true;
2049
+ }
2050
+ }
2051
 
2052
+ if ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]]) {
2053
+ if ($debug_processing) ai_log_content ($content);
 
2054
 
2055
+ $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
2056
+ $selected_blocks = explode (",", $meta_value);
2057
 
2058
+ $ai_last_check = AI_CHECK_NONE;
2059
+ $current_block = 0;
 
 
2060
 
2061
+ foreach ($ai_db_options_extract [CONTENT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]] as $block) {
2062
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($current_block, $ai_last_check));
2063
 
2064
+ $current_block = $block;
 
2065
 
2066
+ $obj = $block_object [$block];
2067
+ $obj->clear_code_cache ();
2068
 
2069
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0 && !$positions_inserted && $ai_wp_data [AI_WP_DEBUG_BLOCK] <= $block) {
2070
+ $preview = $block_object [$ai_wp_data [AI_WP_DEBUG_BLOCK]];
2071
+ $content = $preview->before_paragraph ($content, true);
2072
+ $content = $preview->after_paragraph ($content, true);
2073
+ $positions_inserted = true;
2074
+ }
 
2075
 
2076
+ if (!$obj->check_server_side_detection ()) continue;
2077
+ if (!$obj->check_page_types_lists_users ()) continue;
2078
+ if (!$obj->check_post_page_exceptions ($selected_blocks)) continue;
2079
+ if (!$obj->check_filter ($ad_interter_globals [$globals_name])) continue;
2080
+ if (!$obj->check_number_of_words ($content)) continue;
2081
 
2082
+ // Deprecated
2083
+ $ai_last_check = AI_CHECK_DISABLED_MANUALLY;
2084
+ if ($obj->display_disabled ($content)) continue;
2085
 
2086
+ // Last check before insertion
2087
+ if (!$obj->check_block_counter ()) continue;
2088
 
2089
+ $display_type = $obj->get_display_type();
 
2090
 
2091
+ if ($display_type == AD_SELECT_BEFORE_PARAGRAPH) {
2092
+ $ai_last_check = AI_CHECK_PARAGRAPH_COUNTING;
2093
+ $content = $obj->before_paragraph ($content);
2094
  }
2095
+ elseif ($display_type == AD_SELECT_AFTER_PARAGRAPH) {
2096
+ $ai_last_check = AI_CHECK_PARAGRAPH_COUNTING;
2097
+ $content = $obj->after_paragraph ($content);
2098
  }
2099
+ elseif ($display_type == AD_SELECT_BEFORE_CONTENT) {
2100
+ $obj->increment_block_counter ();
 
 
 
2101
 
2102
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
2103
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
2104
+ $content = $obj->get_code_for_insertion () . $content;
2105
+ $ai_last_check = AI_CHECK_INSERTED;
2106
+ }
 
2107
  }
2108
+ elseif ($display_type == AD_SELECT_AFTER_CONTENT) {
2109
+ $obj->increment_block_counter ();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2110
 
2111
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
2112
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
2113
+ $content = $content . $obj->get_code_for_insertion ();
2114
+ $ai_last_check = AI_CHECK_INSERTED;
2115
+ }
2116
+ }
 
2117
  }
2118
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($current_block, $ai_last_check));
2119
+ }
2120
 
2121
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_TAGS) != 0) {
2122
+ $style = AI_DEBUG_TAGS_STYLE;
2123
+
2124
+ $content = preg_replace ("/\r\n\r\n/", "\r\n\r\n<kbd style='$style background: #0ff; color: #000;'>\\r\\n\\r\\n</kbd>", $content);
2125
+
2126
+ $content = preg_replace ("/<p>/i", "<p><kbd style='$style background: #0a0;'>&lt;p&gt;</kbd>", $content);
2127
+ // $content = preg_replace ("/<p ([^>]*?)>/i", "<p$1><kbd style='$style background: #0a0;'>&lt;p$1&gt;</kbd>", $content); // Full p tags
2128
+ $content = preg_replace ("/<p ([^>]*?)>/i", "<p$1><kbd style='$style background: #0a0;'>&lt;p&gt;</kbd>", $content);
2129
+ // $content = preg_replace ("/<div([^>]*?)>/i", "<div$1><kbd style='$style background: #46f;'>&lt;div$1&gt;</kbd>", $content); // Full div tags
2130
+ $content = preg_replace ("/<div([^>]*?)>/i", "<div$1><kbd style='$style background: #46f;'>&lt;div&gt;</kbd>", $content);
2131
+ $content = preg_replace ("/<h([1-6])([^>]*?)>/i", "<h$1$2><kbd style='$style background: #d4e;'>&lt;h$1&gt;</kbd>", $content);
2132
+ $content = preg_replace ("/<img([^>]*?)>/i", "<img$1><kbd style='$style background: #ee0; color: #000'>&lt;img$1&gt;</kbd>", $content);
2133
+ $content = preg_replace ("/<pre([^>]*?)>/i", "<pre$1><kbd style='$style background: #222;'>&lt;pre&gt;</kbd>", $content);
2134
+ $content = preg_replace ("/<(?!section|ins|script|kbd|a|strong|pre|p|div|h[1-6]|img)([a-z0-9]+)([^>]*?)>/i", "<$1$2><kbd style='$style background: #fb0; color: #000;'>&lt;$1$2&gt;</kbd>", $content);
2135
+
2136
+ $content = preg_replace ("/<\/p>/i", "<kbd style='$style background: #0a0;'>&lt;/p&gt;</kbd></p>", $content);
2137
+ $content = preg_replace ("/<\/div>/i", "<kbd style='$style background: #46f;'>&lt;/div&gt;</kbd></div>", $content);
2138
+ $content = preg_replace ("/<\/h([1-6])>/i", "<kbd style='$style background: #d4e;'>&lt;/h$1&gt;</kbd></h$1>", $content);
2139
+ $content = preg_replace ("/<\/pre>/i", "<kbd style='$style background: #222;'>&lt;/pre&gt;</kbd></pre>", $content);
2140
+ $content = preg_replace ("/<\/(?!section|ins|script|kbd|a|strong|pre|p|div|h[1-6])([a-z0-9]+)>/i", "<kbd style='$style background: #fb0; color: #000;'>&lt;/$1&gt;</kbd></$1>", $content);
2141
+ }
2142
 
2143
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
2144
+ $style = AI_DEBUG_POSITIONS_STYLE;
2145
 
2146
+ if (!$positions_inserted) {
2147
+ $preview = $block_object [$ai_wp_data [AI_WP_DEBUG_BLOCK]];
2148
+ $content = $preview->before_paragraph ($content, true);
2149
+ $content = $preview->after_paragraph ($content, true);
2150
+ }
2151
 
2152
+ $content = preg_replace ("/\[\[AI_BP([\d]+?)\]\]/", "<section style='$style'>BEFORE PARAGRAPH $1</section>", $content);
2153
+ $content = preg_replace ("/\[\[AI_AP([\d]+?)\]\]/", "<section style='$style'>AFTER PARAGRAPH $1</section>", $content);
2154
 
2155
+ $counter = $ad_interter_globals [$globals_name];
2156
+ if ($counter == 1) $counter = '';
2157
 
2158
+ $content = "<section style='$style'><a style='float: left; font-size: 10px; text-decoration: none; color: transparent; padding: 0px 10px 0 0;'>".$content_words." words</a>BEFORE CONTENT ".$counter."<a style='float: right; font-size: 10px; text-decoration: none; color: #88f; padding: 0px 10px 0 0;'>".$content_words." words</a></section>". $content;
2159
 
2160
+ $content = $content . "<section style='".AI_DEBUG_POSITIONS_STYLE."'>AFTER CONTENT ".$counter."</section>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2161
  }
2162
 
2163
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_TAGS) != 0) {
2164
+ $content = '<kbd style="display: none">[HTML TAGS REMOVED]</kbd>' . $content;
 
 
 
 
 
 
 
 
2165
  }
2166
 
2167
+ if ($debug_processing) ai_log ("CONTENT HOOK END\n");
2168
+
2169
  return $content;
2170
  }
2171
 
2172
  // Process Before/After Excerpt postion
2173
  function ai_excerpt_hook ($content = ''){
2174
+ global $ad_interter_globals, $block_object, $ai_db_options_extract, $ai_wp_data, $ai_last_check;
2175
 
2176
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_ADMIN) return;
2177
 
2178
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
2179
+ $globals_name = AI_EXCERPT_COUNTER_NAME;
 
 
2180
 
2181
+ if (!isset ($ad_interter_globals [$globals_name])) {
2182
+ $ad_interter_globals [$globals_name] = 1;
2183
+ } else $ad_interter_globals [$globals_name] ++;
 
2184
 
2185
+ if ($debug_processing) ai_log ("EXCERPT HOOK START [" . $ad_interter_globals [$globals_name] . ']');
2186
 
2187
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_EXCERPT;
2188
 
2189
+ $ai_last_check = AI_CHECK_NONE;
2190
+ $current_block = 0;
2191
 
2192
+ foreach ($ai_db_options_extract [EXCERPT_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]] as $block) {
2193
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($current_block, $ai_last_check));
2194
 
2195
+ $current_block = $block;
2196
+ $obj = $block_object [$block];
2197
+ $obj->clear_code_cache ();
 
 
 
 
2198
 
2199
+ if (!$obj->check_server_side_detection ()) continue;
2200
+ if (!$obj->check_page_types_lists_users ()) continue;
2201
+ if (!$obj->check_filter ($ad_interter_globals [$globals_name])) continue;
 
 
2202
 
2203
+ // Deprecated
2204
+ $ai_last_check = AI_CHECK_DISABLED_MANUALLY;
2205
+ if ($obj->display_disabled ($content)) continue;
2206
 
2207
+ // Last check before insertion
2208
+ if (!$obj->check_and_increment_block_counter ()) continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
2209
 
2210
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
2211
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
 
 
2212
 
2213
+ $display_type = $obj->get_display_type ();
2214
+ if ($display_type == AD_SELECT_BEFORE_EXCERPT)
2215
+ $content = $obj->get_code_for_insertion () . $content; else
2216
+ $content = $content . $obj->get_code_for_insertion ();
2217
 
2218
+ $ai_last_check = AI_CHECK_INSERTED;
2219
+ }
2220
+ }
2221
 
2222
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($current_block, $ai_last_check));
2223
 
2224
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
2225
+ $style = AI_DEBUG_POSITIONS_STYLE;
2226
 
2227
+ $content = "<section style='$style'>BEFORE EXCERPT ".$ad_interter_globals [$globals_name]."</section>". $content . "<section style='$style'>AFTER EXCERPT ".$ad_interter_globals [$globals_name]."</section>";
2228
 
2229
+ // Color positions from the content hook
2230
+ $content = preg_replace ("/((BEFORE|AFTER) (CONTENT|PARAGRAPH) ?[\d]*)/", "<span style='color: blue;'> [$1] </span>", $content);
2231
+ }
2232
 
2233
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_TAGS) != 0) {
2234
+ // Remove marked tags from the content hook
2235
+ $content = preg_replace ("/&lt;(.+?)&gt;/", "", $content);
2236
 
2237
+ // Color text to mark removed HTML tags
2238
+ $content = str_replace ('[HTML TAGS REMOVED]', "<span style='color: red;'>[HTML TAGS REMOVED]</span>", $content);
2239
+ }
2240
 
2241
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
2242
+ // Remove block labels from the content hook
2243
+ if (strpos ($content, '>[AI]<') === false)
2244
+ $content = preg_replace ("/\[AI\](.+?)\[\/AI\]/", "", $content);
2245
  }
2246
 
2247
+ if ($debug_processing) ai_log ("EXCERPT HOOK END\n");
2248
+
2249
  return $content;
2250
  }
2251
 
2252
  // Process Before / After Post postion
2253
 
2254
  function ai_before_after_post ($query, $display_type){
2255
+ global $block_object, $ad_interter_globals, $ai_db_options_extract, $ai_wp_data, $ai_last_check;
2256
+
2257
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
2258
+
2259
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_ADMIN) return;
2260
 
2261
  if (!method_exists ($query, 'is_main_query')) return;
2262
  if (!$query->is_main_query()) return;
 
 
2263
 
2264
+ $globals_name = $display_type == AD_SELECT_BEFORE_POST ? AI_LOOP_BEFORE_COUNTER_NAME : AI_LOOP_AFTER_COUNTER_NAME;
2265
 
2266
  if (!isset ($ad_interter_globals [$globals_name])) {
2267
  $ad_interter_globals [$globals_name] = 1;
2268
  } else $ad_interter_globals [$globals_name] ++;
2269
 
2270
+ $ai_wp_data [AI_CONTEXT] = $display_type == AD_SELECT_BEFORE_POST ? AI_CONTEXT_BEFORE_POST : AI_CONTEXT_AFTER_POST;
 
 
 
 
 
 
 
 
2271
 
2272
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2273
 
2274
+ $style = AI_DEBUG_POSITIONS_STYLE;
 
 
 
 
2275
 
2276
+ $counter = $ad_interter_globals [$globals_name];
2277
+ if ($counter == 1) $counter = '';
 
 
 
 
 
 
 
 
2278
 
2279
+ echo "<section style='$style'>".($display_type == AD_SELECT_BEFORE_POST ? "BEFORE" : "AFTER")." POST ".$counter."</section>";
2280
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2281
 
2282
+ $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
2283
+ $selected_blocks = explode (",", $meta_value);
2284
 
2285
+ $ad_code = "";
2286
 
2287
+ $ai_last_check = AI_CHECK_NONE;
2288
+ $current_block = 0;
2289
 
2290
+ foreach ($ai_db_options_extract [$display_type == AD_SELECT_BEFORE_POST ? LOOP_START_HOOK_BLOCKS : LOOP_END_HOOK_BLOCKS][$ai_wp_data [AI_WP_PAGE_TYPE]] as $block) {
2291
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($current_block, $ai_last_check));
2292
 
2293
+ $current_block = $block;
2294
 
2295
+ $obj = $block_object [$block];
2296
+ $obj->clear_code_cache ();
2297
 
2298
+ if (!$obj->check_server_side_detection ()) continue;
2299
+ if (!$obj->check_page_types_lists_users ()) continue;
2300
+ if (!$obj->check_post_page_exceptions ($selected_blocks)) continue;
2301
+ if (!$obj->check_filter ($ad_interter_globals [$globals_name])) continue;
 
 
2302
 
2303
+ // Last check before insertion
2304
  if (!$obj->check_and_increment_block_counter ()) continue;
2305
 
2306
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
2307
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
2308
+ $ad_code .= $obj->get_code_for_insertion ();
2309
+ $ai_last_check = AI_CHECK_INSERTED;
2310
+ }
2311
  }
2312
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($current_block, $ai_last_check));
2313
 
2314
  echo $ad_code;
2315
  }
2316
 
2317
  // Process Before Post postion
2318
  function ai_loop_start_hook ($query){
2319
+ global $ai_wp_data;
2320
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
2321
+ if ($debug_processing) ai_log ("LOOP START HOOK START");
2322
  ai_before_after_post ($query, AD_SELECT_BEFORE_POST);
2323
+ if ($debug_processing) ai_log ("LOOP START HOOK END\n");
2324
  }
2325
 
2326
 
2327
  // Process After Post postion
2328
  function ai_loop_end_hook ($query){
2329
+ global $ai_wp_data;
2330
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
2331
+ if ($debug_processing) ai_log ("LOOP END HOOK START");
2332
  ai_before_after_post ($query, AD_SELECT_AFTER_POST);
2333
+ if ($debug_processing) ai_log ("LOOP END HOOK END\n");
2334
  }
2335
 
2336
+ function process_shortcode (&$block, $atts) {
2337
+ global $block_object, $ai_last_check, $ai_wp_data;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2338
 
2339
  $parameters = shortcode_atts (array (
2340
  "block" => "",
2341
  "name" => "",
2342
  "ignore" => "",
2343
  ), $atts);
2344
+
2345
  if (is_numeric ($parameters ['block'])) $block = intval ($parameters ['block']); else $block = 0;
2346
+ if ($block < 1 || $block > AD_INSERTER_BLOCKS) {
2347
  $block = 0;
2348
  } elseif ($parameters ['name'] != '') {
2349
  $shortcode_name = strtolower ($parameters ['name']);
2357
  }
2358
  }
2359
 
2360
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("SHORTCODE $block");
2361
+
2362
  if ($block == 0) return "";
2363
 
2364
  // IGNORE SETTINGS
2370
  $ignore_array = explode (",", str_replace (" ", "", $parameters ['ignore']));
2371
  }
2372
 
2373
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_SHORTCODE;
2374
+
2375
  $obj = $block_object [$block];
2376
+ $obj->clear_code_cache ();
2377
 
2378
+ $ai_last_check = AI_CHECK_ENABLED;
2379
  if (!$obj->get_enable_manual ()) return "";
2380
 
2381
+ if (!$obj->check_server_side_detection ()) return "";
2382
+ if (!$obj->check_page_types_lists_users (in_array ("page_type", $ignore_array))) return "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2383
 
2384
+ // Last check before insertion
2385
+ if (!$obj->check_and_increment_block_counter ()) return "";
 
 
 
 
 
 
2386
 
2387
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
2388
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
2389
+ $ai_last_check = AI_CHECK_INSERTED;
2390
+ return $obj->get_code_for_insertion ();
 
 
 
 
2391
  }
2392
+ }
2393
 
 
 
 
 
 
 
 
 
 
 
 
2394
 
2395
+ function process_shortcodes ($atts) {
2396
+ global $ai_last_check, $ai_wp_data;
2397
+
2398
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
2399
+ $ai_last_check = AI_CHECK_NONE;
2400
+ $block = 0;
2401
+ $shortcode = process_shortcode ($block, $atts);
2402
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($block, $ai_last_check));
2403
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("SHORTCODE END\n");
2404
+ return $shortcode;
2405
  }
2406
 
2407
 
2410
  function __construct () {
2411
  parent::__construct (
2412
  false, // Base ID
2413
+ AD_INSERTER_NAME, // Name
2414
  array ( // Args
2415
  'classname' => 'ai_widget',
2416
+ 'description' => AD_INSERTER_NAME.' code block widget.')
2417
  );
2418
  }
2419
 
 
 
 
 
 
 
 
 
 
 
 
 
2420
  function form ($instance) {
2421
  global $block_object;
2422
 
2423
  // Output admin widget options form
2424
 
2425
  $widget_title = !empty ($instance ['widget-title']) ? $instance ['widget-title'] : '';
2426
+ $block = isset ($instance ['block']) ? $instance ['block'] : 1;
 
 
2427
 
2428
+ if ($block == 0) $title = 'Debugger'; else {
2429
+ $obj = $block_object [$block];
2430
 
2431
+ $title = '[' . $block . '] ' . $obj->get_ad_name();
2432
+ if (!empty ($widget_title)) $title .= ' - ' . $widget_title;
2433
+ if (!$obj->get_enable_widget ()) $title .= ' - DISABLED';
2434
+ }
2435
 
2436
  ?>
2437
  <input id="<?php echo $this->get_field_id ('title'); ?>" name="<?php echo $this->get_field_name ('title'); ?>" type="hidden" value="<?php echo esc_attr ($title); ?>">
2450
  ?>
2451
  <option value='<?php echo $block_index; ?>' <?php if ($block_index == $block) echo 'selected="selected"'; ?>><?php echo $obj->get_ad_name(), !$obj->get_enable_widget ()? ' - DISABLED' : ''; ?></option>
2452
  <?php } ?>
2453
+ <option value='0' <?php if ($block == 0) echo 'selected="selected"'; ?>>Debugger</option>
2454
  </select>
2455
  </p>
2456
 
2467
 
2468
  $instance ['widget-title'] = (!empty ($new_instance ['widget-title'])) ? strip_tags ($new_instance ['widget-title']) : '';
2469
  $instance ['title'] = (!empty ($new_instance ['title'])) ? strip_tags ($new_instance ['title']) : '';
2470
+ $instance ['block'] = (isset ($new_instance ['block'])) ? $new_instance ['block'] : 1;
2471
 
2472
  return $instance;
2473
  }
 
2474
 
2475
+ function widget ($args, $instance) {
2476
+ global $ai_last_check, $ai_wp_data;
2477
 
2478
+ $ai_last_check = AI_CHECK_NONE;
 
2479
 
2480
+ $block = 0;
2481
+ ai_widget_draw ($args, $instance, $block);
 
2482
 
2483
+ $debug_processing = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0;
2484
 
2485
+ if ($debug_processing && $ai_last_check != AI_CHECK_NONE) ai_log (ai_log_block_status ($block, $ai_last_check));
2486
+ if ($debug_processing) ai_log ("WIDGET END\n");
2487
+ }
2488
+ }
2489
 
 
 
2490
 
2491
+ function ai_widget_draw ($args, $instance, &$block) {
2492
+ global $block_object, $ad_interter_globals, $ai_wp_data, $ai_last_check;
2493
 
2494
+ $block = isset ($instance ['block']) ? $instance ['block'] : 1;
 
 
 
 
 
 
2495
 
2496
+ if ($block == 0) {
2497
+ if (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0)
2498
+ ai_widget_draw_debugger ($args, $instance, $block);
2499
+ return;
2500
  }
2501
 
2502
+ if ($block < 1 || $block > AD_INSERTER_BLOCKS) return;
 
 
 
 
2503
 
2504
+ $title = !empty ($instance ['widget-title']) ? $instance ['widget-title'] : '';
 
2505
 
2506
+ $obj = $block_object [$block];
2507
+ $obj->clear_code_cache ();
 
 
 
 
 
 
 
 
2508
 
2509
+ $globals_name = AI_WIDGET_COUNTER_NAME . $block;
 
2510
 
2511
+ if (!isset ($ad_interter_globals [$globals_name])) {
2512
+ $ad_interter_globals [$globals_name] = 1;
2513
+ } else $ad_interter_globals [$globals_name] ++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2514
 
2515
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) ai_log ("WIDGET (". $obj->number . ') ['.$ad_interter_globals [$globals_name] . ']');
2516
 
2517
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_WIDGET;
2518
 
2519
+ $ai_last_check = AI_CHECK_ENABLED;
2520
+ if (!$obj->get_enable_widget ()) return;
2521
+ if (!$obj->check_server_side_detection ()) return;
2522
+ if (!$obj->check_page_types_lists_users ()) return;
2523
+ if (!$obj->check_filter ($ad_interter_globals [$globals_name])) return;
2524
 
2525
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_POST || $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_STATIC) {
2526
+ $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
2527
+ $selected_blocks = explode (",", $meta_value);
2528
 
2529
+ if (!$obj->check_post_page_exceptions ($selected_blocks)) return;
2530
+ }
 
 
 
 
2531
 
2532
+ // Last check before insertion
2533
  if (!$obj->check_and_increment_block_counter ()) return;
2534
 
2535
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
2536
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
2537
+ $viewport_classes = trim ($obj->get_viewport_classes ());
2538
+ if ($viewport_classes != "") echo "<div class='" . $viewport_classes . "'>";
2539
+ echo $args ['before_widget'];
2540
+
2541
+ if (!empty ($title)) {
2542
+ echo $args ['before_title'], apply_filters ('widget_title', $title), $args ['after_title'];
2543
+ }
2544
+
2545
+ echo $obj->get_code_for_insertion (false);
2546
+
2547
+ echo $args ['after_widget'];
2548
+ if ($viewport_classes != "") echo "</div>";
2549
+
2550
+ $ai_last_check = AI_CHECK_INSERTED;
2551
+
2552
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0 && $obj->get_detection_client_side())
2553
+ echo $obj->get_code_for_insertion (false, true);
2554
+ }
2555
+ }
2556
+
2557
+ function ai_widget_draw_debugger ($args, $instance, &$block) {
2558
+ global $ai_wp_data, $ai_db_options, $block_object;
2559
 
 
 
2560
  echo $args ['before_widget'];
2561
 
2562
+ $title = !empty ($instance ['widget-title']) ? $instance ['widget-title'] : '';
2563
+
2564
  if (!empty ($title)) {
2565
  echo $args ['before_title'], apply_filters ('widget_title', $title), $args ['after_title'];
2566
  }
2567
 
2568
+ echo "<pre style='", AI_DEBUG_WIDGET_STYLE, "'>\n";
2569
+ ai_write_debug_info ();
2570
+ echo "</pre>";
2571
+
2572
+ if ($ai_wp_data [CLIENT_SIDE_DETECTION]) {
2573
+ for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
2574
+ $viewport_name = get_viewport_name ($viewport);
2575
+ if ($viewport_name != '') {
2576
+ echo "<pre class='ai-viewport-" . $viewport ."' style='", AI_DEBUG_WIDGET_STYLE, "'>\n";
2577
+ echo "CLIENT-SIDE DEVICE: ", $viewport_name;
2578
+ echo "</pre>";
2579
+ }
2580
+ }
2581
+ }
2582
 
2583
  echo $args ['after_widget'];
 
2584
  }
class.php CHANGED
@@ -9,10 +9,12 @@ abstract class ai_BaseCodeBlock {
9
 
10
  $this->wp_options = array ();
11
 
12
- $this->wp_options [AI_OPTION_CODE] = AD_EMPTY_DATA;
13
- $this->wp_options [AI_OPTION_PROCESS_PHP] = AD_SETTINGS_NOT_CHECKED;
14
- $this->wp_options [AI_OPTION_ENABLE_MANUAL] = AD_SETTINGS_NOT_CHECKED;
15
- $this->wp_options [AI_OPTION_ENABLE_404] = AD_SETTINGS_NOT_CHECKED;
 
 
16
  }
17
 
18
  public function load_options ($block) {
@@ -247,9 +249,77 @@ abstract class ai_BaseCodeBlock {
247
 
248
  public function get_enable_404 (){
249
  $enable_404 = isset ($this->wp_options [AI_OPTION_ENABLE_404]) ? $this->wp_options [AI_OPTION_ENABLE_404] : "";
250
- if ($enable_404 == '') $enable_404 = AI_OPTION_ENABLE_404;
251
  return $enable_404;
252
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  }
254
 
255
  abstract class ai_CodeBlock extends ai_BaseCodeBlock {
@@ -265,18 +335,33 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
265
  $this->wp_options [AI_OPTION_NAME] = AD_NAME;
266
  $this->wp_options [AI_OPTION_DISPLAY_TYPE] = AD_SELECT_NONE;
267
  $this->wp_options [AI_OPTION_PARAGRAPH_NUMBER] = AD_ONE;
268
- $this->wp_options [AI_OPTION_MIN_PARAGRAPHS] = AD_ZERO;
269
- $this->wp_options [AI_OPTION_MIN_WORDS] = AD_ZERO;
270
- $this->wp_options [AI_OPTION_MIN_PARAGRAPH_WORDS] = AD_ZERO;
 
 
 
271
  $this->wp_options [AI_OPTION_PARAGRAPH_TAGS] = DEFAULT_PARAGRAPH_TAGS;
272
- $this->wp_options [AI_OPTION_EXCERPT_NUMBER] = AD_ZERO;
 
 
 
 
 
 
 
 
273
  $this->wp_options [AI_OPTION_DIRECTION_TYPE] = AD_DIRECTION_FROM_TOP;
274
  $this->wp_options [AI_OPTION_ALIGNMENT_TYPE] = AD_ALIGNMENT_NONE;
275
  $this->wp_options [AI_OPTION_GENERAL_TAG] = AD_GENERAL_TAG;
276
  $this->wp_options [AI_OPTION_AFTER_DAYS] = AD_ZERO;
277
- $this->wp_options [AI_OPTION_MAXIMUM_INSERTIONS] = AD_ZERO;
 
 
278
  $this->wp_options [AI_OPTION_URL_LIST] = AD_EMPTY_DATA;
279
  $this->wp_options [AI_OPTION_URL_LIST_TYPE] = AD_BLACK_LIST;
 
 
280
  $this->wp_options [AI_OPTION_DOMAIN_LIST] = AD_EMPTY_DATA;
281
  $this->wp_options [AI_OPTION_DOMAIN_LIST_TYPE] = AD_BLACK_LIST;
282
  $this->wp_options [AI_OPTION_CATEGORY_LIST] = AD_EMPTY_DATA;
@@ -289,6 +374,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
289
  $this->wp_options [AI_OPTION_DISPLAY_ON_CATEGORY_PAGES] = AD_SETTINGS_NOT_CHECKED;
290
  $this->wp_options [AI_OPTION_DISPLAY_ON_SEARCH_PAGES] = AD_SETTINGS_NOT_CHECKED;
291
  $this->wp_options [AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES] = AD_SETTINGS_NOT_CHECKED;
 
292
  $this->wp_options [AI_OPTION_ENABLED_ON_WHICH_PAGES] = AD_ENABLED_ON_ALL;
293
  $this->wp_options [AI_OPTION_ENABLED_ON_WHICH_POSTS] = AD_ENABLED_ON_ALL;
294
  $this->wp_options [AI_OPTION_ENABLE_PHP_CALL] = AD_SETTINGS_NOT_CHECKED;
@@ -297,8 +383,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
297
  $this->wp_options [AI_OPTION_PARAGRAPH_TEXT_TYPE] = AD_DO_NOT_CONTAIN;
298
  $this->wp_options [AI_OPTION_CUSTOM_CSS] = AD_EMPTY_DATA;
299
  $this->wp_options [AI_OPTION_DISPLAY_FOR_USERS] = AD_DISPLAY_ALL_USERS;
300
- $this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES] = AD_DISPLAY_DESKTOP_DEVICES;
301
- $this->wp_options [AI_OPTION_DETECT_SERVER_SIDE] = AD_SETTINGS_NOT_CHECKED;
302
  $this->wp_options [AI_OPTION_DETECT_CLIENT_SIDE] = AD_SETTINGS_NOT_CHECKED;
303
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
304
  $this->wp_options [AI_OPTION_DETECT_VIEWPORT . '_' . $viewport] = AD_SETTINGS_NOT_CHECKED;
@@ -322,13 +406,16 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
322
 
323
  public function get_paragraph_number_minimum(){
324
  $option = isset ($this->wp_options [AI_OPTION_MIN_PARAGRAPHS]) ? $this->wp_options [AI_OPTION_MIN_PARAGRAPHS] : "";
325
- if ($option == '') $option = AD_ZERO;
326
  return $option;
327
  }
328
 
329
  public function get_minimum_words(){
330
  $option = isset ($this->wp_options [AI_OPTION_MIN_WORDS]) ? $this->wp_options [AI_OPTION_MIN_WORDS] : "";
331
- if ($option == '') $option = AD_ZERO;
 
 
 
 
332
  return $option;
333
  }
334
 
@@ -339,13 +426,66 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
339
 
340
  public function get_minimum_paragraph_words(){
341
  $option = isset ($this->wp_options [AI_OPTION_MIN_PARAGRAPH_WORDS]) ? $this->wp_options [AI_OPTION_MIN_PARAGRAPH_WORDS] : "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  if ($option == '') $option = AD_ZERO;
343
  return $option;
344
  }
345
 
 
 
 
 
 
 
346
  public function get_call_filter(){
347
  $option = isset ($this->wp_options [AI_OPTION_EXCERPT_NUMBER]) ? $this->wp_options [AI_OPTION_EXCERPT_NUMBER] : "";
348
- if ($option == '') $option = AD_ZERO;
 
 
 
 
 
349
  return $option;
350
  }
351
 
@@ -373,7 +513,11 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
373
  public function alignmet_style ($alignment_type, $margin = DEFAULT_MARGIN){
374
  if ($margin < 0) $margin = 0;
375
 
376
- if ($alignment_type == AD_ALIGNMENT_LEFT) {
 
 
 
 
377
  $style = "text-align: left; margin: ".$margin."px 0px;";
378
  }
379
  elseif ($alignment_type == AD_ALIGNMENT_RIGHT) {
@@ -392,7 +536,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
392
  $style = $this->get_custom_css ();
393
  }
394
  else {
395
- $style = "margin: ".$margin."px 0px;";
396
  }
397
 
398
  return $style;
@@ -498,6 +642,12 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
498
  return $option;
499
  }
500
 
 
 
 
 
 
 
501
  public function get_enable_manual (){
502
  $option = isset ($this->wp_options [AI_OPTION_ENABLE_MANUAL]) ? $this->wp_options [AI_OPTION_ENABLE_MANUAL] : "";
503
  if ($option == '') {
@@ -513,37 +663,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
513
  global $ai_db_options;
514
 
515
  $enable_widget = isset ($this->wp_options [AI_OPTION_ENABLE_WIDGET]) ? $this->wp_options [AI_OPTION_ENABLE_WIDGET] : "";
516
-
517
- // if ($ai_db_options ['global']['VERSION'] < '010608') {
518
- // if (isset ($this->wp_options [AI_OPTION_DISPLAY_TYPE]) && $this->wp_options [AI_OPTION_DISPLAY_TYPE] == AD_SELECT_WIDGET) $enable_widget = AD_SETTINGS_CHECKED;
519
- // else {
520
- // // Check for block not set for Widgets but at least one Ad Inserter widget is used
521
- // $sidebar_widgets = wp_get_sidebars_widgets();
522
- // $widget_options = get_option ('widget_ai_widget');
523
- // foreach ($sidebar_widgets as $sidebar_index => $sidebar_widget) {
524
- // if (is_array ($sidebar_widget) && isset ($GLOBALS ['wp_registered_sidebars'][$sidebar_index]['name'])) {
525
- // $sidebar_name = $GLOBALS ['wp_registered_sidebars'][$sidebar_index]['name'];
526
- // if ($sidebar_name != "") {
527
- // foreach ($sidebar_widget as $widget) {
528
- // if (preg_match ("/ai_widget-([\d]+)/", $widget, $widget_id)) {
529
- // if (isset ($widget_id [1]) && is_numeric ($widget_id [1])) {
530
- // $widget_option = $widget_options [$widget_id [1]];
531
- // $widget_block = $widget_option ['block'];
532
- // if ($widget_block == $this->number) {
533
- // $enable_widget = AD_SETTINGS_CHECKED;
534
- // break 2;
535
- // }
536
- // }
537
- // }
538
- // }
539
- // }
540
- // }
541
- // }
542
- // }
543
- // }
544
-
545
- // if ($enable_widget == '') $enable_widget = AD_SETTINGS_NOT_CHECKED;
546
-
547
  if ($enable_widget == '') $enable_widget = AD_SETTINGS_CHECKED;
548
 
549
  return $enable_widget;
@@ -579,30 +698,15 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
579
 
580
  public function get_display_for_users (){
581
  if (isset ($this->wp_options [AI_OPTION_DISPLAY_FOR_USERS])) {
582
- $display_for_users = $this->wp_options [AI_OPTION_DISPLAY_FOR_USERS];
583
  } else $display_for_users = '';
584
  if ($display_for_users == '') $display_for_users = AD_DISPLAY_ALL_USERS;
585
- return $display_for_users;
586
- }
587
-
588
- public function get_display_for_devices (){
589
- if (isset ($this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES])) {
590
- $display_for_devices = $this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES];
591
- } else $display_for_devices = '';
592
- // convert old option
593
- if ($display_for_devices == '' || $display_for_devices == AD_DISPLAY_ALL_DEVICES) $display_for_devices = AD_DISPLAY_DESKTOP_DEVICES;
594
- return $display_for_devices;
595
- }
596
 
597
- public function get_detection_server_side(){
598
- // Check old settings for all devices
599
- if (isset ($this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES])) {
600
- $display_for_devices = $this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES];
601
- } else $display_for_devices = '';
602
- if ($display_for_devices == AD_DISPLAY_ALL_DEVICES) $option = AD_SETTINGS_NOT_CHECKED; else
603
 
604
- $option = isset ($this->wp_options [AI_OPTION_DETECT_SERVER_SIDE]) ? $this->wp_options [AI_OPTION_DETECT_SERVER_SIDE] : AD_SETTINGS_NOT_CHECKED;
605
- return $option;
606
  }
607
 
608
  public function get_detection_client_side(){
@@ -621,215 +725,125 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
621
  return $option;
622
  }
623
 
624
- public function get_detection_viewport ($viewport){
625
- global $ai_db_options;
626
 
627
- $option_name = AI_OPTION_DETECT_VIEWPORT . '_' . $viewport;
628
- $option = isset ($this->wp_options [$option_name]) ? $this->wp_options [$option_name] : AD_SETTINGS_NOT_CHECKED;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
 
630
- if ($ai_db_options ['global']['VERSION'] < '010605' && $this->get_detection_client_side()) {
631
- if (isset ($this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES])) {
632
- $display_for_devices = $this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES];
633
- } else $display_for_devices = '';
634
 
635
- if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES ||
636
- $display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES ||
637
- $display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES) {
638
- switch ($viewport) {
639
- case 1:
640
- $option = AD_SETTINGS_CHECKED;
641
- break;
642
- default:
643
- $option = AD_SETTINGS_NOT_CHECKED;
644
- }
645
- }
646
- elseif ($display_for_devices == AD_DISPLAY_TABLET_DEVICES ||
647
- $display_for_devices == AD_DISPLAY_MOBILE_DEVICES ||
648
- $display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES) {
649
- switch ($viewport) {
650
- case 2:
651
- $option = AD_SETTINGS_CHECKED;
652
- break;
653
- default:
654
- $option = AD_SETTINGS_NOT_CHECKED;
655
- }
656
- }
657
- elseif ($display_for_devices == AD_DISPLAY_PHONE_DEVICES ||
658
- $display_for_devices == AD_DISPLAY_MOBILE_DEVICES ||
659
- $display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES) {
660
- switch ($viewport) {
661
- case 3:
662
- $option = AD_SETTINGS_CHECKED;
663
- break;
664
- default:
665
- $option = AD_SETTINGS_NOT_CHECKED;
666
- }
667
- }
668
- elseif ($display_for_devices == AD_DISPLAY_ALL_DEVICES) $option = AD_SETTINGS_NOT_CHECKED;
669
- }
670
 
671
- return $option;
 
 
 
 
 
672
  }
673
 
674
- public function get_ad_data_replaced(){
675
-
676
- $general_tag = isset ($this->wp_options [AI_OPTION_GENERAL_TAG]) ? $this->wp_options [AI_OPTION_GENERAL_TAG] : "";
677
-
678
- $general_tag = str_replace ("&amp;", " and ", $general_tag);
679
- $title = $general_tag;
680
- $short_title = $general_tag;
681
- $category = $general_tag;
682
- $short_category = $general_tag;
683
- $tag = $general_tag;
684
- $smart_tag = $general_tag;
685
- if (is_category ()) {
686
- $categories = get_the_category();
687
- if (!empty ($categories)) {
688
- $first_category = reset ($categories);
689
- $category = str_replace ("&amp;", "and", $first_category->name);
690
- if ($category == "Uncategorized") $category = $general_tag;
691
- } else {
692
- $category = $general_tag;
693
- }
694
- if (strpos ($category, ",") !== false) {
695
- $short_category = trim (substr ($category, 0, strpos ($category, ",")));
696
- } else $short_category = $category;
697
- if (strpos ($short_category, "and") !== false) {
698
- $short_category = trim (substr ($short_category, 0, strpos ($short_category, "and")));
699
- }
700
 
701
- $title = $category;
702
- $title = str_replace ("&amp;", "and", $title);
703
- $short_title = implode (" ", array_slice (explode (" ", $title), 0, 3));
704
- $tag = $short_title;
705
- $smart_tag = $short_title;
706
- } elseif (is_tag ()) {
707
- $title = single_tag_title('', false);
708
- $title = str_replace (array ("&amp;", "#"), array ("and", ""), $title);
709
- $short_title = implode (" ", array_slice (explode (" ", $title), 0, 3));
710
- $category = $short_title;
711
- if (strpos ($category, ",") !== false) {
712
- $short_category = trim (substr ($category, 0, strpos ($category, ",")));
713
- } else $short_category = $category;
714
- if (strpos ($short_category, "and") !== false) {
715
- $short_category = trim (substr ($short_category, 0, strpos ($short_category, "and")));
716
- }
717
- $tag = $short_title;
718
- $smart_tag = $short_title;
719
- } elseif (is_search ()) {
720
- $title = get_search_query();
721
- $title = str_replace ("&amp;", "and", $title);
722
- $short_title = implode (" ", array_slice (explode (" ", $title), 0, 3));
723
- $category = $short_title;
724
- if (strpos ($category, ",") !== false) {
725
- $short_category = trim (substr ($category, 0, strpos ($category, ",")));
726
- } else $short_category = $category;
727
- if (strpos ($short_category, "and") !== false) {
728
- $short_category = trim (substr ($short_category, 0, strpos ($short_category, "and")));
729
- }
730
- $tag = $short_title;
731
- $smart_tag = $short_title;
732
- } elseif (is_page () || is_single ()) {
733
- $title = get_the_title();
734
- $title = str_replace ("&amp;", "and", $title);
735
-
736
- $short_title = implode (" ", array_slice (explode (" ", $title), 0, 3));
737
-
738
- $categories = get_the_category();
739
- if (!empty ($categories)) {
740
- $first_category = reset ($categories);
741
- $category = str_replace ("&amp;", "and", $first_category->name);
742
- if ($category == "Uncategorized") $category = $general_tag;
743
- } else {
744
- $category = $short_title;
745
- }
746
- if (strpos ($category, ",") !== false) {
747
- $short_category = trim (substr ($category, 0, strpos ($category, ",")));
748
- } else $short_category = $category;
749
- if (strpos ($short_category, "and") !== false) {
750
- $short_category = trim (substr ($short_category, 0, strpos ($short_category, "and")));
751
- }
752
 
753
- $tags = get_the_tags();
754
- if (!empty ($tags)) {
 
 
755
 
756
- $first_tag = reset ($tags);
757
- $tag = str_replace (array ("&amp;", "#"), array ("and", ""), $first_tag->name);
 
 
758
 
759
- $tag_array = array ();
760
- foreach ($tags as $tag_data) {
761
- $tag_array [] = explode (" ", $tag_data->name);
762
- }
763
 
764
- $selected_tag = '';
 
 
 
765
 
766
- if (count ($tag_array [0]) == 2) $selected_tag = $tag_array [0];
767
- elseif (count ($tag_array) > 1 && count ($tag_array [1]) == 2) $selected_tag = $tag_array [1];
768
- elseif (count ($tag_array) > 2 && count ($tag_array [2]) == 2) $selected_tag = $tag_array [2];
769
- elseif (count ($tag_array) > 3 && count ($tag_array [3]) == 2) $selected_tag = $tag_array [3];
770
- elseif (count ($tag_array) > 4 && count ($tag_array [4]) == 2) $selected_tag = $tag_array [4];
771
 
 
 
772
 
773
- if ($selected_tag == '' && count ($tag_array) >= 2 && count ($tag_array [0]) == 1 && count ($tag_array [1]) == 1) {
774
 
775
- if (strpos ($tag_array [0][0], $tag_array [1][0]) !== false) $tag_array = array_slice ($tag_array, 1, count ($tag_array) - 1);
776
- if (strpos ($tag_array [1][0], $tag_array [0][0]) !== false) $tag_array = array_slice ($tag_array, 1, count ($tag_array) - 1);
 
 
777
 
778
- if (count ($tag_array) >= 2 && count ($tag_array [0]) == 1 && count ($tag_array [1]) == 1) {
779
- $selected_tag = array ($tag_array [0][0], $tag_array [1][0]);
780
- }
781
- }
782
 
783
- if ($selected_tag == '') {
784
- $first_tag = reset ($tags);
785
- $smart_tag = implode (" ", array_slice (explode (" ", $first_tag->name), 0, 3));
786
- } else $smart_tag = implode (" ", $selected_tag);
787
 
788
- $smart_tag = str_replace (array ("&amp;", "#"), array ("and", ""), $smart_tag);
 
 
789
 
790
- } else {
791
- $tag = $category;
792
- $smart_tag = $category;
793
- }
794
- }
795
 
796
- $title = str_replace (array ("'", '"'), array ("&#8217;", "&#8221;"), $title);
797
- $title = html_entity_decode ($title, ENT_QUOTES, "utf-8");
798
-
799
- $short_title = str_replace (array ("'", '"'), array ("&#8217;", "&#8221;"), $short_title);
800
- $short_title = html_entity_decode ($short_title, ENT_QUOTES, "utf-8");
801
-
802
- $search_query = "";
803
- if (isset ($_SERVER['HTTP_REFERER'])) {
804
- $referrer = $_SERVER['HTTP_REFERER'];
805
- } else $referrer = '';
806
- if (preg_match ("/[\.\/](google|yahoo|bing|ask)\.[a-z\.]{2,5}[\/]/i", $referrer, $search_engine)){
807
- $referrer_query = parse_url ($referrer);
808
- $referrer_query = isset ($referrer_query ["query"]) ? $referrer_query ["query"] : "";
809
- parse_str ($referrer_query, $value);
810
- $search_query = isset ($value ["q"]) ? $value ["q"] : "";
811
- if ($search_query == "") {
812
- $search_query = isset ($value ["p"]) ? $value ["p"] : "";
813
- }
814
- }
815
- if ($search_query == "") $search_query = $smart_tag;
816
-
817
- $author = get_the_author_meta ('display_name');
818
- $author_name = get_the_author_meta ('first_name') . " " . get_the_author_meta ('last_name');
819
- if ($author_name == '') $author_name = $author;
820
-
821
- $ad_data = preg_replace ("/{title}/i", $title, parent::get_ad_data());
822
- $ad_data = preg_replace ("/{short_title}/i", $short_title, $ad_data);
823
- $ad_data = preg_replace ("/{category}/i", $category, $ad_data);
824
- $ad_data = preg_replace ("/{short_category}/i", $short_category, $ad_data);
825
- $ad_data = preg_replace ("/{tag}/i", $tag, $ad_data);
826
- $ad_data = preg_replace ("/{smart_tag}/i", $smart_tag, $ad_data);
827
- $ad_data = preg_replace ("/{search_query}/i", $search_query, $ad_data);
828
- $ad_data = preg_replace ("/{author}/i", $author, $ad_data);
829
- $ad_data = preg_replace ("/{author_name}/i", $author_name, $ad_data);
830
-
831
- return $ad_data;
832
- }
833
 
834
  public function get_ad_general_tag(){
835
  $option = isset ($this->wp_options [AI_OPTION_GENERAL_TAG]) ? $this->wp_options [AI_OPTION_GENERAL_TAG] : "";
@@ -845,7 +859,17 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
845
 
846
  public function get_maximum_insertions (){
847
  $option = isset ($this->wp_options [AI_OPTION_MAXIMUM_INSERTIONS]) ? $this->wp_options [AI_OPTION_MAXIMUM_INSERTIONS] : "";
848
- if ($option == '') $option = AD_ZERO;
 
 
 
 
 
 
 
 
 
 
849
  return $option;
850
  }
851
 
@@ -860,6 +884,17 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
860
  return $option;
861
  }
862
 
 
 
 
 
 
 
 
 
 
 
 
863
  public function get_ad_domain_list(){
864
  $option = isset ($this->wp_options [AI_OPTION_DOMAIN_LIST]) ? $this->wp_options [AI_OPTION_DOMAIN_LIST] : "";
865
  return $option;
@@ -934,7 +969,43 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
934
  return ($viewport_classes);
935
  }
936
 
937
- public function before_paragraph ($content, &$inserted) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
938
 
939
  $paragraph_positions = array ();
940
 
@@ -943,6 +1014,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
943
 
944
  $paragraph_start_strings = explode (",", $paragraph_tags);
945
 
 
946
  if (count ($paragraph_start_strings) == 0) return $content;
947
 
948
  foreach ($paragraph_start_strings as $paragraph_start_string) {
@@ -960,29 +1032,63 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
960
 
961
  while (stripos ($content, $paragraph_start, $last_position + 1) !== false) {
962
  $last_position = stripos ($content, $paragraph_start, $last_position + 1);
963
- if ($paragraph_start_string == "#" || $content [$last_position + $paragraph_start_len] == ">" || $content [$last_position + $paragraph_start_len] == " ")
 
964
  $paragraph_positions [] = $last_position;
965
  }
966
  }
967
 
968
  // Nothing to do
969
- if (sizeof ($paragraph_positions) == 0) return $content;
 
970
 
971
  sort ($paragraph_positions);
972
 
973
- $paragraph_min_words = $this->get_minimum_paragraph_words();
974
- if ($paragraph_min_words != 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
975
  $filtered_paragraph_positions = array ();
976
  foreach ($paragraph_positions as $index => $paragraph_position) {
977
  $paragraph_code = $index == count ($paragraph_positions) - 1 ? substr ($content, $paragraph_position) : substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
978
- $number_of_words = sizeof (explode (" ", strip_tags ($paragraph_code)));
979
- if ($number_of_words >= $paragraph_min_words) $filtered_paragraph_positions [] = $paragraph_position;
980
  }
981
  $paragraph_positions = $filtered_paragraph_positions;
982
  }
983
 
 
 
 
 
 
984
  $paragraph_texts = explode (",", html_entity_decode ($this->get_paragraph_text()));
985
- if ($this->get_paragraph_text() != "" && count ($paragraph_texts != 0)) {
986
 
987
  $filtered_paragraph_positions = array ();
988
  $paragraph_text_type = $this->get_paragraph_text_type ();
@@ -1015,44 +1121,158 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1015
  }
1016
 
1017
  // Nothing to do
1018
- if (sizeof ($paragraph_positions) == 0) return $content;
 
 
1019
 
1020
  $position = $this->get_paragraph_number();
1021
 
1022
  if ($position > 0 && $position < 1) {
1023
- $position = intval ($position * (sizeof ($paragraph_positions) - 1) + 0.5);
1024
  }
1025
  elseif ($position <= 0) {
1026
- $position = rand (0, sizeof ($paragraph_positions) - 1);
1027
  } else $position --;
1028
 
1029
  if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
1030
  $paragraph_positions = array_reverse ($paragraph_positions);
1031
  }
1032
 
1033
- $text = str_replace ("\r", "", $content);
1034
- $text = str_replace (array ("\n", " "), " ", $text);
1035
- $text = str_replace (" ", " ", $text);
1036
- $text = strip_tags ($text);
1037
- $number_of_words = sizeof (explode (" ", $text));
1038
 
1039
- if (sizeof ($paragraph_positions) > $position && sizeof ($paragraph_positions) >= $this->get_paragraph_number_minimum() && $number_of_words >= $this->get_minimum_words()) {
1040
- $content_position = $paragraph_positions [$position];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1041
 
1042
- $block_class_name = get_block_class_name ();
 
 
 
 
 
 
 
 
 
 
 
 
 
1043
 
1044
- $display_for_devices = $this->get_display_for_devices ();
1045
 
1046
- if ($this->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $content = substr_replace ($content, ai_getAdCode ($this), $content_position, 0); else
1047
- $content = substr_replace ($content, "<div class='" . $block_class_name . " " . $block_class_name . "-" . $this->number . $this->get_viewport_classes () . "' style='" . $this->get_alignmet_style() . "'>" . ai_getAdCode ($this) . "</div>", $content_position, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1048
 
1049
- $inserted = true;
 
 
 
 
 
 
 
 
1050
  }
1051
 
1052
  return $content;
1053
  }
1054
 
1055
- public function after_paragraph ($content, &$inserted) {
 
1056
 
1057
  $paragraph_positions = array ();
1058
  $last_content_position = strlen ($content) - 1;
@@ -1062,6 +1282,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1062
 
1063
  $paragraph_end_strings = explode (",", $paragraph_tags);
1064
 
 
1065
  if (count ($paragraph_end_strings) == 0) return $content;
1066
 
1067
  foreach ($paragraph_end_strings as $paragraph_end_string) {
@@ -1077,28 +1298,62 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1077
 
1078
  while (stripos ($content, $paragraph_end, $last_position + 1) !== false) {
1079
  $last_position = stripos ($content, $paragraph_end, $last_position + 1) + strlen ($paragraph_end) - 1;
1080
- $paragraph_positions [] = $last_position;
 
1081
  }
1082
  }
1083
 
1084
  // Nothing to do
1085
- if (sizeof ($paragraph_positions) == 0) return $content;
 
1086
 
1087
  sort ($paragraph_positions);
1088
 
1089
- $paragraph_min_words = $this->get_minimum_paragraph_words();
1090
- if ($paragraph_min_words != 0) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1091
  $filtered_paragraph_positions = array ();
1092
  foreach ($paragraph_positions as $index => $paragraph_position) {
1093
  $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
1094
- $number_of_words = sizeof (explode (" ", strip_tags ($paragraph_code)));
1095
- if ($number_of_words >= $paragraph_min_words) $filtered_paragraph_positions [] = $paragraph_position;
1096
  }
1097
  $paragraph_positions = $filtered_paragraph_positions;
1098
  }
1099
 
 
 
 
 
 
1100
  $paragraph_texts = explode (",", html_entity_decode ($this->get_paragraph_text()));
1101
- if ($this->get_paragraph_text() != "" && count ($paragraph_texts != 0)) {
1102
 
1103
  $filtered_paragraph_positions = array ();
1104
  $paragraph_text_type = $this->get_paragraph_text_type ();
@@ -1131,76 +1386,159 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1131
  }
1132
 
1133
  // Nothing to do
1134
- if (sizeof ($paragraph_positions) == 0) return $content;
 
 
1135
 
1136
  $position = $this->get_paragraph_number();
1137
 
1138
  if ($position > 0 && $position < 1) {
1139
- $position = intval ($position * (sizeof ($paragraph_positions) - 1) + 0.5);
1140
  }
1141
  elseif ($position <= 0) {
1142
- $position = rand (0, sizeof ($paragraph_positions) - 1);
1143
  } else $position --;
1144
 
1145
  if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
1146
  $paragraph_positions = array_reverse ($paragraph_positions);
1147
  }
1148
 
1149
- $text = str_replace ("\r", "", $content);
1150
- $text = str_replace (array ("\n", " "), " ", $text);
1151
- $text = str_replace (" ", " ", $text);
1152
- $text = strip_tags ($text);
1153
- $number_of_words = sizeof (explode (" ", $text));
1154
 
1155
- if (sizeof ($paragraph_positions) > $position && sizeof ($paragraph_positions) >= $this->get_paragraph_number_minimum() && $number_of_words >= $this->get_minimum_words()) {
1156
- $content_position = $paragraph_positions [$position];
1157
 
1158
- $block_class_name = get_block_class_name ();
 
 
 
 
1159
 
1160
- $display_for_devices = $this->get_display_for_devices ();
 
 
 
 
 
 
 
 
 
 
 
1161
 
1162
- if ($content_position >= strlen ($content) - 1) {
1163
- if ($this->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $content = $content . ai_getAdCode ($this); else
1164
- $content = $content . "<div class='" . $block_class_name . " " . $block_class_name . "-" . $this->number . $this->get_viewport_classes () . "' style='" . $this->get_alignmet_style() . "'>" . ai_getAdCode ($this) . "</div>";
1165
- } else {
1166
- if ($this->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $content = substr_replace ($content, ai_getAdCode ($this), $content_position + 1, 0); else
1167
- $content = substr_replace ($content, "<div class='" . $block_class_name . " " . $block_class_name . "-" . $this->number . $this->get_viewport_classes () . "' style='" . $this->get_alignmet_style() . "'>" . ai_getAdCode ($this) . "</div>", $content_position + 1, 0);
 
 
1168
  }
1169
 
1170
- $inserted = true;
1171
- }
 
 
 
 
 
 
 
 
 
 
1172
 
1173
- return $content;
1174
- }
1175
 
1176
- public function before_content ($content) {
1177
- $block_class_name = get_block_class_name ();
 
 
 
 
 
 
1178
 
1179
- $display_for_devices = $this->get_display_for_devices ();
1180
 
1181
- $text = str_replace (array ("\n", " "), " ", $content);
1182
- $text = strip_tags ($text);
1183
- $number_of_words = sizeof (explode (" ", $text));
1184
 
1185
- if ($number_of_words < $this->get_minimum_words()) return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1186
 
1187
- if ($this->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) return ai_getAdCode ($this) . $content; else
1188
- return "<div class='" . $block_class_name . " " . $block_class_name . "-" . $this->number . $this->get_viewport_classes () . "' style='" . $this->get_alignmet_style() . "'>" . ai_getAdCode ($this) . "</div>" . $content;
1189
- }
 
 
1190
 
1191
- public function after_content ($content) {
1192
- $block_class_name = get_block_class_name ();
 
1193
 
1194
- $display_for_devices = $this->get_display_for_devices ();
1195
 
1196
- $text = str_replace (array ("\n", " "), " ", $content);
1197
- $text = strip_tags ($text);
1198
- $number_of_words = sizeof (explode (" ", $text));
 
 
 
 
 
 
 
 
 
 
1199
 
1200
- if ($number_of_words < $this->get_minimum_words()) return $content;
 
 
 
 
 
 
 
 
 
 
 
1201
 
1202
- if ($this->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) return $content . ai_getAdCode ($this); else
1203
- return $content . "<div class='" . $block_class_name . " " . $block_class_name . "-" . $this->number . $this->get_viewport_classes () . "' style='" . $this->get_alignmet_style() . "'>" . ai_getAdCode ($this) . "</div>";
1204
  }
1205
 
1206
  // Deprecated
@@ -1216,8 +1554,8 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1216
  $ad_tag = strtolower (trim ($tag));
1217
  $ad_name = strtolower (trim ($this->get_ad_name()));
1218
  if ($ad_tag == $ad_name || $ad_tag == $this->number) {
1219
- if ($this->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $ad_code = ai_getAdCode ($this); else
1220
- $ad_code = "<div class='" . $block_class_name . " " . $block_class_name . "-" . $this->number . $this->get_viewport_classes () . "' style='" . $this->get_alignmet_style() . "'>" . ai_getAdCode ($this) . "</div>";
1221
  $content = preg_replace ("/{adinserter " . $tag . "}/", $ad_code, $content);
1222
  }
1223
  }
@@ -1247,8 +1585,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1247
  $categories = trim (strtolower ($this->get_ad_block_cat()));
1248
  $cat_type = $this->get_ad_block_cat_type();
1249
 
1250
- // echo ' listed categories: ' . $categories, "<br />\n";
1251
-
1252
  if ($cat_type == AD_BLACK_LIST) {
1253
 
1254
  if($categories == AD_EMPTY_DATA) return true;
@@ -1257,8 +1593,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1257
 
1258
  foreach (get_the_category() as $post_category) {
1259
 
1260
- //echo '<br/> post category name : ' . $post_category->cat_name;
1261
-
1262
  foreach ($cats_listed as $cat_disabled){
1263
 
1264
  $cat_disabled = trim ($cat_disabled);
@@ -1266,14 +1600,10 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1266
  $post_category_name = strtolower ($post_category->cat_name);
1267
  $post_category_slug = strtolower ($post_category->slug);
1268
 
1269
- //echo '<br/>Category disabled loop : ' . $cat_disabled . '<br/> category name : ' . $post_category_name;
1270
-
1271
  if ($post_category_name == $cat_disabled || $post_category_slug == $cat_disabled) {
1272
- //echo ' match';
1273
  return false;
1274
- }else{
1275
- //echo ' not match';
1276
- }
1277
  }
1278
  }
1279
  return true;
@@ -1286,8 +1616,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1286
 
1287
  foreach (get_the_category() as $post_category) {
1288
 
1289
- //echo '<br/> post category name : ' . $post_category->cat_name;
1290
-
1291
  foreach ($cats_listed as $cat_enabled) {
1292
 
1293
  $cat_enabled = trim ($cat_enabled);
@@ -1295,14 +1623,10 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1295
  $post_category_name = strtolower ($post_category->cat_name);
1296
  $post_category_slug = strtolower ($post_category->slug);
1297
 
1298
- // echo '<br/>Category enabled loop : ' . $cat_enabled . '<br/> category name : ' . $post_category_name . '<br/> category slug: ' . $post_category_slug;
1299
-
1300
  if ($post_category_name == $cat_enabled || $post_category_slug == $cat_enabled) {
1301
- // echo '#match';
1302
  return true;
1303
- }else{
1304
- // echo '#no match';
1305
- }
1306
  }
1307
  }
1308
  return false;
@@ -1321,8 +1645,6 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1321
  }
1322
  $has_any_of_the_given_tags = has_tag ($tags_listed);
1323
 
1324
- // echo ' listed tags: ' . $tags, "\n";
1325
-
1326
  if ($tag_type == AD_BLACK_LIST) {
1327
 
1328
  if ($tags == AD_EMPTY_DATA) return true;
@@ -1351,17 +1673,54 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1351
  }
1352
  }
1353
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1354
  function check_url () {
 
 
 
1355
 
1356
- $urls = $this->get_ad_url_list();
1357
  $url_type = $this->get_ad_url_list_type();
1358
 
1359
- $page_url = $_SERVER ['REQUEST_URI'];
 
 
 
 
1360
 
1361
- $urls = trim ($urls);
1362
  $urls_listed = explode (" ", $urls);
1363
  foreach ($urls_listed as $index => $url_listed) {
1364
- if ($url_listed == "") unset ($urls_listed [$index]); else
1365
  $urls_listed [$index] = trim ($url_listed);
1366
  }
1367
 
@@ -1371,14 +1730,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1371
  // echo ' listed urls: ' . $urls, "\n";
1372
  // echo "<br />\n";
1373
 
1374
- if ($url_type == AD_BLACK_LIST) $return = false; else $return = true;
1375
-
1376
- if ($urls == AD_EMPTY_DATA) {
1377
- return !$return;
1378
- }
1379
-
1380
  foreach ($urls_listed as $url_listed) {
1381
- if ($url_listed [0] == '') continue;
1382
  if ($url_listed == '*') return $return;
1383
 
1384
  if ($url_listed [0] == '*') {
@@ -1394,19 +1746,55 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1394
  $url_listed = substr ($url_listed, 0, strlen ($url_listed) - 1);
1395
  if (strpos ($page_url, $url_listed) === 0) return $return;
1396
  }
1397
- else if ($url_listed == $page_url) return $return;
1398
  }
1399
  return !$return;
1400
  }
1401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1402
  function check_date () {
1403
 
1404
- $after_days = trim ($this->get_ad_after_day());
 
1405
 
1406
- // If 0 display immediately
1407
- if($after_days == AD_ZERO || $after_days == AD_EMPTY_DATA) return true;
1408
 
1409
- return (date ('U', time ()) >= get_the_date ('U') + $after_days * 86400);
1410
  }
1411
 
1412
  function check_referer () {
@@ -1420,7 +1808,7 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1420
  if ($domain_list_type == AD_BLACK_LIST) $return = false; else $return = true;
1421
 
1422
  $domains = trim ($this->get_ad_domain_list ());
1423
- if ($domains == "") return !$return;
1424
  $domains = explode (",", $domains);
1425
 
1426
  foreach ($domains as $domain) {
@@ -1434,27 +1822,203 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1434
  return !$return;
1435
  }
1436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1437
  function check_and_increment_block_counter () {
1438
- global $ad_interter_globals;
1439
 
1440
- $global_name = 'BLOCK_' . $this->number . '_COUNTER';
1441
- $max_insertions = $this->get_maximum_insertions ();
1442
  if (!isset ($ad_interter_globals [$global_name])) {
1443
  $ad_interter_globals [$global_name] = 0;
1444
  }
 
1445
  if ($max_insertions != 0 && $ad_interter_globals [$global_name] >= $max_insertions) return false;
1446
  $ad_interter_globals [$global_name] ++;
 
1447
  return true;
1448
  }
1449
 
1450
  function check_block_counter () {
1451
  global $ad_interter_globals;
1452
 
1453
- $global_name = 'BLOCK_' . $this->number . '_COUNTER';
1454
- $max_insertions = $this->get_maximum_insertions ();
1455
  if (!isset ($ad_interter_globals [$global_name])) {
1456
  $ad_interter_globals [$global_name] = 0;
1457
  }
 
1458
  if ($max_insertions != 0 && $ad_interter_globals [$global_name] >= $max_insertions) return false;
1459
  return true;
1460
  }
@@ -1462,7 +2026,9 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1462
  function increment_block_counter () {
1463
  global $ad_interter_globals;
1464
 
1465
- $global_name = 'BLOCK_' . $this->number . '_COUNTER';
 
 
1466
  if (!isset ($ad_interter_globals [$global_name])) {
1467
  $ad_interter_globals [$global_name] = 0;
1468
  }
@@ -1470,6 +2036,165 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1470
  return;
1471
  }
1472
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1473
  }
1474
 
1475
 
9
 
10
  $this->wp_options = array ();
11
 
12
+ $this->wp_options [AI_OPTION_CODE] = AD_EMPTY_DATA;
13
+ $this->wp_options [AI_OPTION_PROCESS_PHP] = AD_SETTINGS_NOT_CHECKED;
14
+ $this->wp_options [AI_OPTION_ENABLE_MANUAL] = AD_SETTINGS_NOT_CHECKED;
15
+ $this->wp_options [AI_OPTION_ENABLE_404] = AD_SETTINGS_NOT_CHECKED;
16
+ $this->wp_options [AI_OPTION_DETECT_SERVER_SIDE] = AD_SETTINGS_NOT_CHECKED;
17
+ $this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES] = AD_DISPLAY_DESKTOP_DEVICES;
18
  }
19
 
20
  public function load_options ($block) {
249
 
250
  public function get_enable_404 (){
251
  $enable_404 = isset ($this->wp_options [AI_OPTION_ENABLE_404]) ? $this->wp_options [AI_OPTION_ENABLE_404] : "";
252
+ if ($enable_404 == '') $enable_404 = AD_SETTINGS_NOT_CHECKED;
253
  return $enable_404;
254
  }
255
+
256
+ public function get_detection_server_side(){
257
+ // Check old settings for all devices
258
+ if (isset ($this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES])) {
259
+ $display_for_devices = $this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES];
260
+ } else $display_for_devices = '';
261
+ if ($display_for_devices == AD_DISPLAY_ALL_DEVICES) $option = AD_SETTINGS_NOT_CHECKED; else
262
+
263
+ $option = isset ($this->wp_options [AI_OPTION_DETECT_SERVER_SIDE]) ? $this->wp_options [AI_OPTION_DETECT_SERVER_SIDE] : AD_SETTINGS_NOT_CHECKED;
264
+ return $option;
265
+ }
266
+
267
+ function check_server_side_detection () {
268
+ global $ai_last_check;
269
+
270
+ if ($this->get_detection_server_side ()) {
271
+ $display_for_devices = $this->get_display_for_devices ();
272
+
273
+ $ai_last_check = AI_CHECK_DESKTOP_DEVICES;
274
+ if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES && !AI_DESKTOP) return false;
275
+ $ai_last_check = AI_CHECK_MOBILE_DEVICES;
276
+ if ($display_for_devices == AD_DISPLAY_MOBILE_DEVICES && !AI_MOBILE) return false;
277
+ $ai_last_check = AI_CHECK_TABLET_DEVICES;
278
+ if ($display_for_devices == AD_DISPLAY_TABLET_DEVICES && !AI_TABLET) return false;
279
+ $ai_last_check = AI_CHECK_PHONE_DEVICES;
280
+ if ($display_for_devices == AD_DISPLAY_PHONE_DEVICES && !AI_PHONE) return false;
281
+ $ai_last_check = AI_CHECK_DESKTOP_TABLET_DEVICES;
282
+ if ($display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES && !(AI_DESKTOP || AI_TABLET)) return false;
283
+ $ai_last_check = AI_CHECK_DESKTOP_PHONE_DEVICES;
284
+ if ($display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES && !(AI_DESKTOP || AI_PHONE)) return false;
285
+ }
286
+ return true;
287
+ }
288
+
289
+ public function get_display_for_devices (){
290
+ if (isset ($this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES])) {
291
+ $display_for_devices = $this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES];
292
+ } else $display_for_devices = '';
293
+ // convert old option
294
+ if ($display_for_devices == '' || $display_for_devices == AD_DISPLAY_ALL_DEVICES) $display_for_devices = AD_DISPLAY_DESKTOP_DEVICES;
295
+ return $display_for_devices;
296
+ }
297
+
298
+ public function clear_code_cache (){
299
+ unset ($this->wp_options ['GENERATED_CODE']);
300
+ }
301
+
302
+ public function ai_getCode (){
303
+ $code = $this->get_ad_data();
304
+
305
+ if ($this->get_process_php ()) {
306
+ $global_name = 'GENERATED_CODE';
307
+ if (isset ($this->wp_options [$global_name])) return $this->wp_options [$global_name];
308
+
309
+ ob_start ();
310
+ eval ("?>". $code . "<?php ");
311
+ $code = ob_get_clean ();
312
+ if (strpos ($code, __FILE__)) {
313
+ if (preg_match ("/(.+) in ".str_replace ("/", "\/", __FILE__)."/", $code, $error_message))
314
+ $code = "PHP error in " . AD_INSERTER_NAME . " code block ".$this->number . " - " . $this->get_ad_name() . "<br />\n" . $error_message [1];
315
+ }
316
+
317
+ // Cache generated code
318
+ $this->wp_options [$global_name] = $code;
319
+ }
320
+
321
+ return $code;
322
+ }
323
  }
324
 
325
  abstract class ai_CodeBlock extends ai_BaseCodeBlock {
335
  $this->wp_options [AI_OPTION_NAME] = AD_NAME;
336
  $this->wp_options [AI_OPTION_DISPLAY_TYPE] = AD_SELECT_NONE;
337
  $this->wp_options [AI_OPTION_PARAGRAPH_NUMBER] = AD_ONE;
338
+ $this->wp_options [AI_OPTION_MIN_PARAGRAPHS] = AD_EMPTY_DATA;
339
+ $this->wp_options [AI_OPTION_MIN_WORDS] = AD_EMPTY_DATA;
340
+ $this->wp_options [AI_OPTION_MAX_WORDS] = AD_EMPTY_DATA;
341
+ $this->wp_options [AI_OPTION_MIN_PARAGRAPH_WORDS] = AD_EMPTY_DATA;
342
+ $this->wp_options [AI_OPTION_MAX_PARAGRAPH_WORDS] = AD_EMPTY_DATA;
343
+ $this->wp_options [AI_OPTION_COUNT_INSIDE_BLOCKQUOTE] = AD_SETTINGS_NOT_CHECKED;
344
  $this->wp_options [AI_OPTION_PARAGRAPH_TAGS] = DEFAULT_PARAGRAPH_TAGS;
345
+ $this->wp_options [AI_OPTION_AVOID_PARAGRAPHS_ABOVE] = AD_EMPTY_DATA;
346
+ $this->wp_options [AI_OPTION_AVOID_PARAGRAPHS_BELOW] = AD_EMPTY_DATA;
347
+ $this->wp_options [AI_OPTION_AVOID_TEXT_ABOVE] = AD_EMPTY_DATA;
348
+ $this->wp_options [AI_OPTION_AVOID_TEXT_BELOW] = AD_EMPTY_DATA;
349
+ $this->wp_options [AI_OPTION_AVOID_ACTION] = AD_TRY_TO_SHIFT_POSITION;
350
+ $this->wp_options [AI_OPTION_AVOID_TRY_LIMIT] = AD_ONE;
351
+ $this->wp_options [AI_OPTION_AVOID_DIRECTION] = AD_BELOW_AND_THEN_ABOVE;
352
+ $this->wp_options [AI_OPTION_EXCERPT_NUMBER] = AD_EMPTY_DATA;
353
+ $this->wp_options [AI_OPTION_FILTER_TYPE] = AI_OPTION_FILTER_AUTO;
354
  $this->wp_options [AI_OPTION_DIRECTION_TYPE] = AD_DIRECTION_FROM_TOP;
355
  $this->wp_options [AI_OPTION_ALIGNMENT_TYPE] = AD_ALIGNMENT_NONE;
356
  $this->wp_options [AI_OPTION_GENERAL_TAG] = AD_GENERAL_TAG;
357
  $this->wp_options [AI_OPTION_AFTER_DAYS] = AD_ZERO;
358
+ $this->wp_options [AI_OPTION_MAXIMUM_INSERTIONS] = AD_EMPTY_DATA;
359
+ $this->wp_options [AI_OPTION_ID_LIST] = AD_EMPTY_DATA;
360
+ $this->wp_options [AI_OPTION_ID_LIST_TYPE] = AD_BLACK_LIST;
361
  $this->wp_options [AI_OPTION_URL_LIST] = AD_EMPTY_DATA;
362
  $this->wp_options [AI_OPTION_URL_LIST_TYPE] = AD_BLACK_LIST;
363
+ $this->wp_options [AI_OPTION_URL_PARAMETER_LIST] = AD_EMPTY_DATA;
364
+ $this->wp_options [AI_OPTION_URL_PARAMETER_LIST_TYPE] = AD_BLACK_LIST;
365
  $this->wp_options [AI_OPTION_DOMAIN_LIST] = AD_EMPTY_DATA;
366
  $this->wp_options [AI_OPTION_DOMAIN_LIST_TYPE] = AD_BLACK_LIST;
367
  $this->wp_options [AI_OPTION_CATEGORY_LIST] = AD_EMPTY_DATA;
374
  $this->wp_options [AI_OPTION_DISPLAY_ON_CATEGORY_PAGES] = AD_SETTINGS_NOT_CHECKED;
375
  $this->wp_options [AI_OPTION_DISPLAY_ON_SEARCH_PAGES] = AD_SETTINGS_NOT_CHECKED;
376
  $this->wp_options [AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES] = AD_SETTINGS_NOT_CHECKED;
377
+ $this->wp_options [AI_OPTION_ENABLE_FEED] = AD_SETTINGS_NOT_CHECKED;
378
  $this->wp_options [AI_OPTION_ENABLED_ON_WHICH_PAGES] = AD_ENABLED_ON_ALL;
379
  $this->wp_options [AI_OPTION_ENABLED_ON_WHICH_POSTS] = AD_ENABLED_ON_ALL;
380
  $this->wp_options [AI_OPTION_ENABLE_PHP_CALL] = AD_SETTINGS_NOT_CHECKED;
383
  $this->wp_options [AI_OPTION_PARAGRAPH_TEXT_TYPE] = AD_DO_NOT_CONTAIN;
384
  $this->wp_options [AI_OPTION_CUSTOM_CSS] = AD_EMPTY_DATA;
385
  $this->wp_options [AI_OPTION_DISPLAY_FOR_USERS] = AD_DISPLAY_ALL_USERS;
 
 
386
  $this->wp_options [AI_OPTION_DETECT_CLIENT_SIDE] = AD_SETTINGS_NOT_CHECKED;
387
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
388
  $this->wp_options [AI_OPTION_DETECT_VIEWPORT . '_' . $viewport] = AD_SETTINGS_NOT_CHECKED;
406
 
407
  public function get_paragraph_number_minimum(){
408
  $option = isset ($this->wp_options [AI_OPTION_MIN_PARAGRAPHS]) ? $this->wp_options [AI_OPTION_MIN_PARAGRAPHS] : "";
 
409
  return $option;
410
  }
411
 
412
  public function get_minimum_words(){
413
  $option = isset ($this->wp_options [AI_OPTION_MIN_WORDS]) ? $this->wp_options [AI_OPTION_MIN_WORDS] : "";
414
+ return $option;
415
+ }
416
+
417
+ public function get_maximum_words(){
418
+ $option = isset ($this->wp_options [AI_OPTION_MAX_WORDS]) ? $this->wp_options [AI_OPTION_MAX_WORDS] : "";
419
  return $option;
420
  }
421
 
426
 
427
  public function get_minimum_paragraph_words(){
428
  $option = isset ($this->wp_options [AI_OPTION_MIN_PARAGRAPH_WORDS]) ? $this->wp_options [AI_OPTION_MIN_PARAGRAPH_WORDS] : "";
429
+ return $option;
430
+ }
431
+
432
+ public function get_maximum_paragraph_words(){
433
+ $option = isset ($this->wp_options [AI_OPTION_MAX_PARAGRAPH_WORDS]) ? $this->wp_options [AI_OPTION_MAX_PARAGRAPH_WORDS] : "";
434
+ return $option;
435
+ }
436
+
437
+ public function get_count_inside_blockquote(){
438
+ $option = isset ($this->wp_options [AI_OPTION_COUNT_INSIDE_BLOCKQUOTE]) ? $this->wp_options [AI_OPTION_COUNT_INSIDE_BLOCKQUOTE] : "";
439
+ if ($option == '') $option = AD_SETTINGS_NOT_CHECKED;
440
+ return $option;
441
+ }
442
+
443
+ public function get_avoid_paragraphs_above(){
444
+ $option = isset ($this->wp_options [AI_OPTION_AVOID_PARAGRAPHS_ABOVE]) ? $this->wp_options [AI_OPTION_AVOID_PARAGRAPHS_ABOVE] : "";
445
+ return $option;
446
+ }
447
+
448
+ public function get_avoid_paragraphs_below(){
449
+ $option = isset ($this->wp_options [AI_OPTION_AVOID_PARAGRAPHS_BELOW]) ? $this->wp_options [AI_OPTION_AVOID_PARAGRAPHS_BELOW] : "";
450
+ return $option;
451
+ }
452
+
453
+ public function get_avoid_text_above(){
454
+ $option = isset ($this->wp_options [AI_OPTION_AVOID_TEXT_ABOVE]) ? $this->wp_options [AI_OPTION_AVOID_TEXT_ABOVE] : "";
455
+ return $option;
456
+ }
457
+
458
+ public function get_avoid_text_below(){
459
+ $option = isset ($this->wp_options [AI_OPTION_AVOID_TEXT_BELOW]) ? $this->wp_options [AI_OPTION_AVOID_TEXT_BELOW] : "";
460
+ return $option;
461
+ }
462
+
463
+ public function get_avoid_action(){
464
+ $option = isset ($this->wp_options [AI_OPTION_AVOID_ACTION]) ? $this->wp_options [AI_OPTION_AVOID_ACTION] : "";
465
+ if ($option == '') $option = AD_TRY_TO_SHIFT_POSITION;
466
+ return $option;
467
+ }
468
+
469
+ public function get_avoid_try_limit(){
470
+ $option = isset ($this->wp_options [AI_OPTION_AVOID_TRY_LIMIT]) ? $this->wp_options [AI_OPTION_AVOID_TRY_LIMIT] : "";
471
  if ($option == '') $option = AD_ZERO;
472
  return $option;
473
  }
474
 
475
+ public function get_avoid_direction(){
476
+ $option = isset ($this->wp_options [AI_OPTION_AVOID_DIRECTION]) ? $this->wp_options [AI_OPTION_AVOID_DIRECTION] : "";
477
+ if ($option == '') $option = AD_BELOW_AND_THEN_ABOVE;
478
+ return $option;
479
+ }
480
+
481
  public function get_call_filter(){
482
  $option = isset ($this->wp_options [AI_OPTION_EXCERPT_NUMBER]) ? $this->wp_options [AI_OPTION_EXCERPT_NUMBER] : "";
483
+ return $option;
484
+ }
485
+
486
+ public function get_filter_type(){
487
+ $option = isset ($this->wp_options [AI_OPTION_FILTER_TYPE]) ? $this->wp_options [AI_OPTION_FILTER_TYPE] : "";
488
+ if ($option == '') $option = AI_OPTION_FILTER_AUTO;
489
  return $option;
490
  }
491
 
513
  public function alignmet_style ($alignment_type, $margin = DEFAULT_MARGIN){
514
  if ($margin < 0) $margin = 0;
515
 
516
+
517
+ if ($alignment_type == AD_ALIGNMENT_NONE) {
518
+ $style = "margin: ".$margin."px 0px;";
519
+ }
520
+ elseif ($alignment_type == AD_ALIGNMENT_LEFT) {
521
  $style = "text-align: left; margin: ".$margin."px 0px;";
522
  }
523
  elseif ($alignment_type == AD_ALIGNMENT_RIGHT) {
536
  $style = $this->get_custom_css ();
537
  }
538
  else {
539
+ $style = "";
540
  }
541
 
542
  return $style;
642
  return $option;
643
  }
644
 
645
+ public function get_enable_feed (){
646
+ $enable_feed = isset ($this->wp_options [AI_OPTION_ENABLE_FEED]) ? $this->wp_options [AI_OPTION_ENABLE_FEED] : "";
647
+ if ($enable_feed == '') $enable_feed = AD_SETTINGS_NOT_CHECKED;
648
+ return $enable_feed;
649
+ }
650
+
651
  public function get_enable_manual (){
652
  $option = isset ($this->wp_options [AI_OPTION_ENABLE_MANUAL]) ? $this->wp_options [AI_OPTION_ENABLE_MANUAL] : "";
653
  if ($option == '') {
663
  global $ai_db_options;
664
 
665
  $enable_widget = isset ($this->wp_options [AI_OPTION_ENABLE_WIDGET]) ? $this->wp_options [AI_OPTION_ENABLE_WIDGET] : "";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
666
  if ($enable_widget == '') $enable_widget = AD_SETTINGS_CHECKED;
667
 
668
  return $enable_widget;
698
 
699
  public function get_display_for_users (){
700
  if (isset ($this->wp_options [AI_OPTION_DISPLAY_FOR_USERS])) {
701
+ $display_for_users = $this->wp_options [AI_OPTION_DISPLAY_FOR_USERS];
702
  } else $display_for_users = '';
703
  if ($display_for_users == '') $display_for_users = AD_DISPLAY_ALL_USERS;
 
 
 
 
 
 
 
 
 
 
 
704
 
705
+ elseif ($display_for_users == 'all') $display_for_users = AD_DISPLAY_ALL_USERS;
706
+ elseif ($display_for_users == 'logged in') $display_for_users = AD_DISPLAY_LOGGED_IN_USERS;
707
+ elseif ($display_for_users == 'not logged in') $display_for_users = AD_DISPLAY_NOT_LOGGED_IN_USERS;
 
 
 
708
 
709
+ return $display_for_users;
 
710
  }
711
 
712
  public function get_detection_client_side(){
725
  return $option;
726
  }
727
 
728
+ public function get_detection_viewport ($viewport){
729
+ global $ai_db_options;
730
 
731
+ $option_name = AI_OPTION_DETECT_VIEWPORT . '_' . $viewport;
732
+ $option = isset ($this->wp_options [$option_name]) ? $this->wp_options [$option_name] : AD_SETTINGS_NOT_CHECKED;
733
+
734
+ if ($ai_db_options ['global']['VERSION'] < '010605' && $this->get_detection_client_side()) {
735
+ if (isset ($this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES])) {
736
+ $display_for_devices = $this->wp_options [AI_OPTION_DISPLAY_FOR_DEVICES];
737
+ } else $display_for_devices = '';
738
+
739
+ if ($display_for_devices == AD_DISPLAY_DESKTOP_DEVICES ||
740
+ $display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES ||
741
+ $display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES) {
742
+ switch ($viewport) {
743
+ case 1:
744
+ $option = AD_SETTINGS_CHECKED;
745
+ break;
746
+ default:
747
+ $option = AD_SETTINGS_NOT_CHECKED;
748
+ }
749
+ }
750
+ elseif ($display_for_devices == AD_DISPLAY_TABLET_DEVICES ||
751
+ $display_for_devices == AD_DISPLAY_MOBILE_DEVICES ||
752
+ $display_for_devices == AD_DISPLAY_DESKTOP_TABLET_DEVICES) {
753
+ switch ($viewport) {
754
+ case 2:
755
+ $option = AD_SETTINGS_CHECKED;
756
+ break;
757
+ default:
758
+ $option = AD_SETTINGS_NOT_CHECKED;
759
+ }
760
+ }
761
+ elseif ($display_for_devices == AD_DISPLAY_PHONE_DEVICES ||
762
+ $display_for_devices == AD_DISPLAY_MOBILE_DEVICES ||
763
+ $display_for_devices == AD_DISPLAY_DESKTOP_PHONE_DEVICES) {
764
+ switch ($viewport) {
765
+ case 3:
766
+ $option = AD_SETTINGS_CHECKED;
767
+ break;
768
+ default:
769
+ $option = AD_SETTINGS_NOT_CHECKED;
770
+ }
771
+ }
772
+ elseif ($display_for_devices == AD_DISPLAY_ALL_DEVICES) $option = AD_SETTINGS_NOT_CHECKED;
773
+ }
774
 
775
+ return $option;
776
+ }
 
 
777
 
778
+ public function ai_get_counters (&$title){
779
+ global $ai_wp_data, $ad_interter_globals;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
780
 
781
+ $counters = '';
782
+ $title = 'Counters:';
783
+
784
+ if (isset ($ad_interter_globals [AI_CONTENT_COUNTER_NAME]) && ($ai_wp_data [AI_CONTEXT] == AI_CONTEXT_CONTENT || $ai_wp_data [AI_CONTEXT] == AI_CONTEXT_SHORTCODE)) {
785
+ $counters .= ' C='.$ad_interter_globals [AI_CONTENT_COUNTER_NAME];
786
+ $title .= ' C= Content, ';
787
  }
788
 
789
+ if (isset ($ad_interter_globals [AI_EXCERPT_COUNTER_NAME]) && $ai_wp_data [AI_CONTEXT] == AI_CONTEXT_EXCERPT) {
790
+ $counters .= ' X='.$ad_interter_globals [AI_EXCERPT_COUNTER_NAME];
791
+ $title .= ' X = Excerpt, ';
792
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
793
 
794
+ if (isset ($ad_interter_globals [AI_LOOP_BEFORE_COUNTER_NAME]) && $ai_wp_data [AI_CONTEXT] == AI_CONTEXT_BEFORE_POST) {
795
+ $counters .= ' B='.$ad_interter_globals [AI_LOOP_BEFORE_COUNTER_NAME];
796
+ $title .= ' B = Before post, ';
797
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798
 
799
+ if (isset ($ad_interter_globals [AI_LOOP_AFTER_COUNTER_NAME]) && $ai_wp_data [AI_CONTEXT] == AI_CONTEXT_AFTER_POST) {
800
+ $counters .= ' A='.$ad_interter_globals [AI_LOOP_AFTER_COUNTER_NAME];
801
+ $title .= ' A = After post, ';
802
+ }
803
 
804
+ if (isset ($ad_interter_globals [AI_WIDGET_COUNTER_NAME . $this->number]) && $ai_wp_data [AI_CONTEXT] == AI_CONTEXT_WIDGET) {
805
+ $counters .= ' W='.$ad_interter_globals [AI_WIDGET_COUNTER_NAME . $this->number];
806
+ $title .= ' W = Widget, ';
807
+ }
808
 
809
+ if (isset ($ad_interter_globals [AI_PHP_FUNCTION_CALL_COUNTER_NAME . $this->number])) {
810
+ $counters .= ' P='.$ad_interter_globals [AI_PHP_FUNCTION_CALL_COUNTER_NAME . $this->number];
811
+ $title .= ' P = PHP function call, ';
812
+ }
813
 
814
+ if (isset ($ad_interter_globals [AI_BLOCK_COUNTER_NAME . $this->number])) {
815
+ $counters .= ' N='.$ad_interter_globals [AI_BLOCK_COUNTER_NAME . $this->number];
816
+ $title .= ' N = Block';
817
+ }
818
 
819
+ return $counters;
820
+ }
 
 
 
821
 
822
+ public function ai_getProcessedCode ($hide_label = false){
823
+ global $ai_wp_data, $ad_interter_globals;
824
 
825
+ $ad_code = $this->ai_getCode ();
826
 
827
+ if (strpos ($ad_code, AD_SEPARATOR) !== false) {
828
+ $ads = explode (AD_SEPARATOR, $ad_code);
829
+ $ad_code = $ads [rand (0, count ($ads) - 1)];
830
+ }
831
 
832
+ $title = '';
833
+ $counters = $this->ai_get_counters ($title);
 
 
834
 
835
+ $ad_code = do_shortcode ($this->replace_ai_tags ($ad_code));
 
 
 
836
 
837
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0 && !$hide_label) {
838
+ if (function_exists ('ai_settings_url_parameters')) $url_parameters = ai_settings_url_parameters ($this->number); else $url_parameters = "";
839
+ $url = admin_url ('options-general.php?page=ad-inserter.php') . $url_parameters . '&tab=' . $this->number;
840
 
841
+ $ad_code = '<section style="border: 1px solid red;"><section style="padding: 1px 0 1px 5px; background: #e00; color: white; font-size: 12px; text-align: left;"><a style="text-decoration: none; color: white;" title="Click to go to block settings" href="'
842
+ . $url . '"><kbd style="display: none">[AI]</kbd>' . $this->number . ' &nbsp; ' . $this->get_ad_name () .'</a><a style="float: right; text-decoration: none; color: white; padding: 0px 10px 0 0;"><kbd title="'.$title.'">'.$counters.'</kbd><kbd style="display: none">[/AI]</kbd></a></section>' . $ad_code . '</section>';
843
+ }
 
 
844
 
845
+ return $ad_code;
846
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
847
 
848
  public function get_ad_general_tag(){
849
  $option = isset ($this->wp_options [AI_OPTION_GENERAL_TAG]) ? $this->wp_options [AI_OPTION_GENERAL_TAG] : "";
859
 
860
  public function get_maximum_insertions (){
861
  $option = isset ($this->wp_options [AI_OPTION_MAXIMUM_INSERTIONS]) ? $this->wp_options [AI_OPTION_MAXIMUM_INSERTIONS] : "";
862
+ return $option;
863
+ }
864
+
865
+ public function get_id_list(){
866
+ $option = isset ($this->wp_options [AI_OPTION_ID_LIST]) ? $this->wp_options [AI_OPTION_ID_LIST] : "";
867
+ return $option;
868
+ }
869
+
870
+ public function get_id_list_type (){
871
+ $option = isset ($this->wp_options [AI_OPTION_ID_LIST_TYPE]) ? $this->wp_options [AI_OPTION_ID_LIST_TYPE] : "";
872
+ if ($option == '') $option = AD_BLACK_LIST;
873
  return $option;
874
  }
875
 
884
  return $option;
885
  }
886
 
887
+ public function get_url_parameter_list(){
888
+ $option = isset ($this->wp_options [AI_OPTION_URL_PARAMETER_LIST]) ? $this->wp_options [AI_OPTION_URL_PARAMETER_LIST] : "";
889
+ return $option;
890
+ }
891
+
892
+ public function get_url_parameter_list_type (){
893
+ $option = isset ($this->wp_options [AI_OPTION_URL_PARAMETER_LIST_TYPE]) ? $this->wp_options [AI_OPTION_URL_PARAMETER_LIST_TYPE] : "";
894
+ if ($option == '') $option = AD_BLACK_LIST;
895
+ return $option;
896
+ }
897
+
898
  public function get_ad_domain_list(){
899
  $option = isset ($this->wp_options [AI_OPTION_DOMAIN_LIST]) ? $this->wp_options [AI_OPTION_DOMAIN_LIST] : "";
900
  return $option;
969
  return ($viewport_classes);
970
  }
971
 
972
+ public function get_code_for_insertion ($viewport_classes = true, $hidden_widgets = false) {
973
+ global $ai_wp_data;
974
+
975
+ if ($this->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) return $this->ai_getProcessedCode ();
976
+
977
+ $block_class_name = get_block_class_name ();
978
+
979
+ $hidden_blocks = '';
980
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0 && $this->get_detection_client_side()) {
981
+
982
+ $title = '';
983
+ $counters = $this->ai_get_counters ($title);
984
+
985
+ if (function_exists ('ai_settings_url_parameters')) $url_parameters = ai_settings_url_parameters ($this->number); else $url_parameters = "";
986
+ $url = admin_url ('options-general.php?page=ad-inserter.php') . $url_parameters . '&tab=' . $this->number;
987
+
988
+ $hidden_block_text = '<section style="text-align: center; font-weight: bold;">'.($hidden_widgets ? 'WIDGET':'BLOCK').' INSERTED BUT NOT VISIBLE</section>';
989
+
990
+ $visible_blocks = '';
991
+ for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
992
+ $viewport_name = get_viewport_name ($viewport);
993
+ if ($viewport_name != '') {
994
+ if ($this->get_detection_viewport ($viewport))
995
+ $visible_blocks .= '<section class="ai-viewport-' . $viewport .'" style=""><section style="padding: 1px 0 1px 5px; text-align: center; background: red; color: white; font-size: 12px;"><a style="float: left; text-decoration: none; color: white;" title="Click to go to block settings" href="' . $url . '"><kbd style="display: none">[AI]</kbd>' . $this->number . ' ' . $this->get_ad_name () .'</a><a style="text-decoration: none; color: white;">'.$viewport_name.'</a><a style="float: right; text-decoration: none; color: white; padding-right: 5px;" title="'.$title.'">'.$counters.'<kbd style="display: none">[/AI]</kbd></a></section><section>'; else
996
+ $hidden_blocks .= '<section class="ai-viewport-' . $viewport .'" style="' . $this->get_alignmet_style() . '; border: 1px solid blue;"><section style="padding: 1px 0 1px 5px; text-align: center; background: blue; color: white; font-size: 12px;"><a style="float: left; text-decoration: none; color: white;" title="Click to go to block settings" href="' . $url . '"><kbd style="display: none">[AI]</kbd>' . $this->number . ' ' . $this->get_ad_name () .'</a><a style="text-decoration: none; color: white;">'.$viewport_name.'</a><a style="float: right; text-decoration: none; color: white; padding-right: 5px;" title="'.$title.'">'.$counters.'<kbd style="display: none">[/AI]</kbd></a></section>' . $hidden_block_text . '</section>';
997
+ }
998
+ }
999
+
1000
+ $code = "<div style='border: 1px solid red;'>".$visible_blocks.$this->ai_getProcessedCode (true).'</div>';
1001
+ } else $code = $this->ai_getProcessedCode ();
1002
+
1003
+ if ($hidden_widgets) return $hidden_blocks; else
1004
+ return $hidden_blocks . "<div class='" . $block_class_name . " " . $block_class_name . "-" . $this->number . ($viewport_classes ? $this->get_viewport_classes () : "") . "' style='" . $this->get_alignmet_style() . "'>" . $code . "</div>";
1005
+ }
1006
+
1007
+ public function before_paragraph ($content, $position_preview = false) {
1008
+ global $ai_wp_data, $ai_last_check;
1009
 
1010
  $paragraph_positions = array ();
1011
 
1014
 
1015
  $paragraph_start_strings = explode (",", $paragraph_tags);
1016
 
1017
+ $ai_last_check = AI_CHECK_PARAGRAPH_TAGS;
1018
  if (count ($paragraph_start_strings) == 0) return $content;
1019
 
1020
  foreach ($paragraph_start_strings as $paragraph_start_string) {
1032
 
1033
  while (stripos ($content, $paragraph_start, $last_position + 1) !== false) {
1034
  $last_position = stripos ($content, $paragraph_start, $last_position + 1);
1035
+ if ($paragraph_start_string == "#") $paragraph_positions [] = $last_position + 4; else
1036
+ if ($content [$last_position + $paragraph_start_len] == ">" || $content [$last_position + $paragraph_start_len] == " ")
1037
  $paragraph_positions [] = $last_position;
1038
  }
1039
  }
1040
 
1041
  // Nothing to do
1042
+ $ai_last_check = AI_CHECK_PARAGRAPHS_WITH_TAGS;
1043
+ if (count ($paragraph_positions) == 0) return $content;
1044
 
1045
  sort ($paragraph_positions);
1046
 
1047
+ if (!$this->get_count_inside_blockquote ()) {
1048
+ preg_match_all ('/<\/?blockquote/i', $content, $blockquotes, PREG_OFFSET_CAPTURE);
1049
+
1050
+ $blockquote_offsets = array ();
1051
+ $blockquotes = $blockquotes [0];
1052
+ foreach ($blockquotes as $index => $blockquote) {
1053
+ if (strtolower ($blockquote [0]) == '<blockquote' && isset ($blockquotes [$index + 1][0]) && strtolower ($blockquotes [$index + 1][0]) == '</blockquote') {
1054
+ $blockquote_offsets []= array ($blockquote [1] + 11, $blockquotes [$index + 1][1]);
1055
+ }
1056
+ }
1057
+
1058
+ if (count ($blockquote_offsets) != 0) {
1059
+ $filtered_paragraph_positions = array ();
1060
+ foreach ($blockquote_offsets as $blockquote_offset) {
1061
+ foreach ($paragraph_positions as $paragraph_position) {
1062
+ if ($paragraph_position >= $blockquote_offset [0] && $paragraph_position <= $blockquote_offset [1]) continue;
1063
+ $filtered_paragraph_positions []= $paragraph_position;
1064
+ }
1065
+ }
1066
+ $paragraph_positions = $filtered_paragraph_positions;
1067
+ }
1068
+ }
1069
+
1070
+ $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_BLOCKQUOTE;
1071
+ if (count ($paragraph_positions) == 0) return $content;
1072
+
1073
+ $paragraph_min_words = intval ($this->get_minimum_paragraph_words());
1074
+ $paragraph_max_words = intval ($this->get_maximum_paragraph_words());
1075
+
1076
+ if ($paragraph_min_words != 0 || $paragraph_max_words != 0) {
1077
  $filtered_paragraph_positions = array ();
1078
  foreach ($paragraph_positions as $index => $paragraph_position) {
1079
  $paragraph_code = $index == count ($paragraph_positions) - 1 ? substr ($content, $paragraph_position) : substr ($content, $paragraph_position, $paragraph_positions [$index + 1] - $paragraph_position);
1080
+ if ($this->check_number_of_words_in_paragraph ($paragraph_code, $paragraph_min_words, $paragraph_max_words)) $filtered_paragraph_positions [] = $paragraph_position;
 
1081
  }
1082
  $paragraph_positions = $filtered_paragraph_positions;
1083
  }
1084
 
1085
+ // Nothing to do
1086
+ $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS;
1087
+ if (count ($paragraph_positions) == 0) return $content;
1088
+
1089
+
1090
  $paragraph_texts = explode (",", html_entity_decode ($this->get_paragraph_text()));
1091
+ if ($this->get_paragraph_text() != "" && count ($paragraph_texts) != 0) {
1092
 
1093
  $filtered_paragraph_positions = array ();
1094
  $paragraph_text_type = $this->get_paragraph_text_type ();
1121
  }
1122
 
1123
  // Nothing to do
1124
+ $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_TEXT;
1125
+ if (count ($paragraph_positions) == 0) return $content;
1126
+
1127
 
1128
  $position = $this->get_paragraph_number();
1129
 
1130
  if ($position > 0 && $position < 1) {
1131
+ $position = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
1132
  }
1133
  elseif ($position <= 0) {
1134
+ $position = rand (0, count ($paragraph_positions) - 1);
1135
  } else $position --;
1136
 
1137
  if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
1138
  $paragraph_positions = array_reverse ($paragraph_positions);
1139
  }
1140
 
 
 
 
 
 
1141
 
1142
+ $avoid_paragraphs_above = intval ($this->get_avoid_paragraphs_above());
1143
+ $avoid_paragraphs_below = intval ($this->get_avoid_paragraphs_below());
1144
+
1145
+ if (($avoid_paragraphs_above != 0 || $avoid_paragraphs_below != 0) && count ($paragraph_positions) > $position) {
1146
+ $avoid_text_above = $this->get_avoid_text_above();
1147
+ $avoid_text_below = $this->get_avoid_text_below();
1148
+ $avoid_paragraph_texts_above = explode (",", html_entity_decode (trim ($avoid_text_above)));
1149
+ $avoid_paragraph_texts_below = explode (",", html_entity_decode (trim ($avoid_text_below)));
1150
+
1151
+ $direction = $this->get_avoid_direction();
1152
+ $max_checks = $this->get_avoid_try_limit();
1153
+
1154
+ $checks = $max_checks;
1155
+ $saved_position = $position;
1156
+ do {
1157
+ $found_above = false;
1158
+ if ($position != 0 && $avoid_paragraphs_above != 0 && $avoid_text_above != "" && is_array ($avoid_paragraph_texts_above) && count ($avoid_paragraph_texts_above) != 0) {
1159
+ $paragraph_position_above = $position - $avoid_paragraphs_above;
1160
+ if ($paragraph_position_above < 0) $paragraph_position_above = 0;
1161
+ $paragraph_code = substr ($content, $paragraph_positions [$paragraph_position_above], $paragraph_positions [$position] - $paragraph_positions [$paragraph_position_above]);
1162
+ foreach ($avoid_paragraph_texts_above as $paragraph_text_above) {
1163
+ if (stripos ($paragraph_code, trim ($paragraph_text_above)) !== false) {
1164
+ $found_above = true;
1165
+ break;
1166
+ }
1167
+ }
1168
+ }
1169
 
1170
+ $found_below = false;
1171
+ if ($avoid_paragraphs_below != 0 && $avoid_text_below != "" && is_array ($avoid_paragraph_texts_below) && count ($avoid_paragraph_texts_below) != 0) {
1172
+ $paragraph_position_below = $position + $avoid_paragraphs_below;
1173
+ if ($paragraph_position_below > count ($paragraph_positions) - 1)
1174
+ $content_position_below = strlen ($content); else
1175
+ $content_position_below = $paragraph_positions [$paragraph_position_below];
1176
+ $paragraph_code = substr ($content, $paragraph_positions [$position], $content_position_below - $paragraph_positions [$position]);
1177
+ foreach ($avoid_paragraph_texts_below as $paragraph_text_below) {
1178
+ if (stripos ($paragraph_code, trim ($paragraph_text_below)) !== false) {
1179
+ $found_below = true;
1180
+ break;
1181
+ }
1182
+ }
1183
+ }
1184
 
 
1185
 
1186
+ // echo "position: $position = before #", $position + 1, "<br />\n";
1187
+ // echo "checks: $checks<br />\n";
1188
+ // echo "direction: $direction<br />\n";
1189
+ // if ($found_above)
1190
+ // echo "found_above<br />\n";
1191
+ // if ($found_below)
1192
+ // echo "found_below<br />\n";
1193
+ // echo "=================<br />\n";
1194
+
1195
+
1196
+ if ($found_above || $found_below) {
1197
+ $ai_last_check = AI_CHECK_DO_NOT_INSERT;
1198
+ if ($this->get_avoid_action() == AD_DO_NOT_INSERT) return $content;
1199
+
1200
+ switch ($direction) {
1201
+ case AD_ABOVE: // Try above
1202
+ $ai_last_check = AI_CHECK_AD_ABOVE;
1203
+ if ($position == 0) return $content; // Already at the top - do not insert
1204
+ $position --;
1205
+ break;
1206
+ case AD_BELOW: // Try below
1207
+ $ai_last_check = AI_CHECK_AD_BELOW;
1208
+ if ($position >= count ($paragraph_positions) - 1) return $content; // Already at the bottom - do not insert
1209
+ $position ++;
1210
+ break;
1211
+ case AD_ABOVE_AND_THEN_BELOW: // Try first above and then below
1212
+ if ($position == 0 || $checks == 0) {
1213
+ // Try below
1214
+ $direction = AD_BELOW;
1215
+ $checks = $max_checks;
1216
+ $position = $saved_position;
1217
+ $ai_last_check = AI_CHECK_AD_BELOW;
1218
+ if ($position >= count ($paragraph_positions) - 1) return $content; // Already at the bottom - do not insert
1219
+ $position ++;
1220
+ } else $position --;
1221
+ break;
1222
+ case AD_BELOW_AND_THEN_ABOVE: // Try first below and then above
1223
+ if ($position >= count ($paragraph_positions) - 1 || $checks == 0) {
1224
+ // Try above
1225
+ $direction = AD_ABOVE;
1226
+ $checks = $max_checks;
1227
+ $position = $saved_position;
1228
+ $ai_last_check = AI_CHECK_AD_ABOVE;
1229
+ if ($position == 0) return $content; // Already at the top - do not insert
1230
+ $position --;
1231
+ } else $position ++;
1232
+ break;
1233
+ }
1234
+ } else break; // Text not found - insert
1235
+
1236
+ // Try next position
1237
+ if ($checks <= 0) return $content; // Suitable position not found - do not insert
1238
+ $checks --;
1239
+ } while (true);
1240
+ }
1241
+
1242
+ // Nothing to do
1243
+ $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_CLEARANCE;
1244
+ if (count ($paragraph_positions) == 0) return $content;
1245
+
1246
+ if ($position_preview) {
1247
+ $offset = 0;
1248
+ foreach ($paragraph_positions as $counter => $paragraph_position) {
1249
+ $inserted_code = "[[AI_BP".($counter + 1)."]]";
1250
+ if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
1251
+ $content = substr_replace ($content, $inserted_code, $paragraph_position, 0);
1252
+ } else {
1253
+ $content = substr_replace ($content, $inserted_code, $paragraph_position + $offset, 0);
1254
+ $offset += strlen ($inserted_code);
1255
+ }
1256
+ }
1257
+ return $content;
1258
+ }
1259
 
1260
+ $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
1261
+ if (count ($paragraph_positions) > $position && count ($paragraph_positions) >= intval ($this->get_paragraph_number_minimum())) {
1262
+ $this->increment_block_counter ();
1263
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
1264
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
1265
+ $content_position = $paragraph_positions [$position];
1266
+ $content = substr_replace ($content, $this->get_code_for_insertion (), $content_position, 0);
1267
+ $ai_last_check = AI_CHECK_INSERTED;
1268
+ }
1269
  }
1270
 
1271
  return $content;
1272
  }
1273
 
1274
+ public function after_paragraph ($content, $position_preview = false) {
1275
+ global $ai_wp_data, $ai_last_check;
1276
 
1277
  $paragraph_positions = array ();
1278
  $last_content_position = strlen ($content) - 1;
1282
 
1283
  $paragraph_end_strings = explode (",", $paragraph_tags);
1284
 
1285
+ $ai_last_check = AI_CHECK_PARAGRAPH_TAGS;
1286
  if (count ($paragraph_end_strings) == 0) return $content;
1287
 
1288
  foreach ($paragraph_end_strings as $paragraph_end_string) {
1298
 
1299
  while (stripos ($content, $paragraph_end, $last_position + 1) !== false) {
1300
  $last_position = stripos ($content, $paragraph_end, $last_position + 1) + strlen ($paragraph_end) - 1;
1301
+ if ($paragraph_end_string == "#") $paragraph_positions [] = $last_position - 4; else
1302
+ $paragraph_positions [] = $last_position;
1303
  }
1304
  }
1305
 
1306
  // Nothing to do
1307
+ $ai_last_check = AI_CHECK_PARAGRAPHS_WITH_TAGS;
1308
+ if (count ($paragraph_positions) == 0) return $content;
1309
 
1310
  sort ($paragraph_positions);
1311
 
1312
+ if (!$this->get_count_inside_blockquote ()) {
1313
+ preg_match_all ('/<\/?blockquote/i', $content, $blockquotes, PREG_OFFSET_CAPTURE);
1314
+
1315
+ $blockquote_offsets = array ();
1316
+ $blockquotes = $blockquotes [0];
1317
+ foreach ($blockquotes as $index => $blockquote) {
1318
+ if (strtolower ($blockquote [0]) == '<blockquote' && isset ($blockquotes [$index + 1][0]) && strtolower ($blockquotes [$index + 1][0]) == '</blockquote') {
1319
+ $blockquote_offsets []= array ($blockquote [1] + 11, $blockquotes [$index + 1][1]);
1320
+ }
1321
+ }
1322
+
1323
+ if (count ($blockquote_offsets) != 0) {
1324
+ $filtered_paragraph_positions = array ();
1325
+ foreach ($blockquote_offsets as $blockquote_offset) {
1326
+ foreach ($paragraph_positions as $paragraph_position) {
1327
+ if ($paragraph_position >= $blockquote_offset [0] && $paragraph_position <= $blockquote_offset [1]) continue;
1328
+ $filtered_paragraph_positions []= $paragraph_position;
1329
+ }
1330
+ }
1331
+ $paragraph_positions = $filtered_paragraph_positions;
1332
+ }
1333
+ }
1334
+
1335
+ $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_BLOCKQUOTE;
1336
+ if (count ($paragraph_positions) == 0) return $content;
1337
+
1338
+ $paragraph_min_words = intval ($this->get_minimum_paragraph_words());
1339
+ $paragraph_max_words = intval ($this->get_maximum_paragraph_words());
1340
+
1341
+ if ($paragraph_min_words != 0 || $paragraph_max_words != 0) {
1342
  $filtered_paragraph_positions = array ();
1343
  foreach ($paragraph_positions as $index => $paragraph_position) {
1344
  $paragraph_code = $index == 0 ? substr ($content, 0, $paragraph_position + 1) : substr ($content, $paragraph_positions [$index - 1] + 1, $paragraph_position - $paragraph_positions [$index - 1]);
1345
+ if ($this->check_number_of_words_in_paragraph ($paragraph_code, $paragraph_min_words, $paragraph_max_words)) $filtered_paragraph_positions [] = $paragraph_position;
 
1346
  }
1347
  $paragraph_positions = $filtered_paragraph_positions;
1348
  }
1349
 
1350
+ // Nothing to do
1351
+ $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS;
1352
+ if (count ($paragraph_positions) == 0) return $content;
1353
+
1354
+
1355
  $paragraph_texts = explode (",", html_entity_decode ($this->get_paragraph_text()));
1356
+ if ($this->get_paragraph_text() != "" && count ($paragraph_texts) != 0) {
1357
 
1358
  $filtered_paragraph_positions = array ();
1359
  $paragraph_text_type = $this->get_paragraph_text_type ();
1386
  }
1387
 
1388
  // Nothing to do
1389
+ $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_TEXT;
1390
+ if (count ($paragraph_positions) == 0) return $content;
1391
+
1392
 
1393
  $position = $this->get_paragraph_number();
1394
 
1395
  if ($position > 0 && $position < 1) {
1396
+ $position = intval ($position * (count ($paragraph_positions) - 1) + 0.5);
1397
  }
1398
  elseif ($position <= 0) {
1399
+ $position = rand (0, count ($paragraph_positions) - 1);
1400
  } else $position --;
1401
 
1402
  if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
1403
  $paragraph_positions = array_reverse ($paragraph_positions);
1404
  }
1405
 
 
 
 
 
 
1406
 
1407
+ $avoid_paragraphs_above = intval ($this->get_avoid_paragraphs_above());
1408
+ $avoid_paragraphs_below = intval ($this->get_avoid_paragraphs_below());
1409
 
1410
+ if (($avoid_paragraphs_above != 0 || $avoid_paragraphs_below != 0) && count ($paragraph_positions) > $position) {
1411
+ $avoid_text_above = $this->get_avoid_text_above();
1412
+ $avoid_text_below = $this->get_avoid_text_below();
1413
+ $avoid_paragraph_texts_above = explode (",", html_entity_decode (trim ($avoid_text_above)));
1414
+ $avoid_paragraph_texts_below = explode (",", html_entity_decode (trim ($avoid_text_below)));
1415
 
1416
+ $direction = $this->get_avoid_direction();
1417
+ $max_checks = $this->get_avoid_try_limit();
1418
+
1419
+ $checks = $max_checks;
1420
+ $saved_position = $position;
1421
+ do {
1422
+ $found_above = false;
1423
+ if ($avoid_paragraphs_above != 0 && $avoid_text_above != "" && is_array ($avoid_paragraph_texts_above) && count ($avoid_paragraph_texts_above) != 0) {
1424
+ $paragraph_position_above = $position - $avoid_paragraphs_above;
1425
+ if ($paragraph_position_above <= 0)
1426
+ $content_position_above = 0; else
1427
+ $content_position_above = $paragraph_positions [$paragraph_position_above] + 1;
1428
 
1429
+ $paragraph_code = substr ($content, $content_position_above, $paragraph_positions [$position] - $content_position_above);
1430
+
1431
+ foreach ($avoid_paragraph_texts_above as $paragraph_text_above) {
1432
+ if (stripos ($paragraph_code, trim ($paragraph_text_above)) !== false) {
1433
+ $found_above = true;
1434
+ break;
1435
+ }
1436
+ }
1437
  }
1438
 
1439
+ $found_below = false;
1440
+ if ($avoid_paragraphs_below != 0 && $position != count ($paragraph_positions) - 1 && $avoid_text_below != "" && is_array ($avoid_paragraph_texts_below) && count ($avoid_paragraph_texts_below) != 0) {
1441
+ $paragraph_position_below = $position + $avoid_paragraphs_below;
1442
+ if ($paragraph_position_below > count ($paragraph_positions) - 1) $paragraph_position_below = count ($paragraph_positions) - 1;
1443
+ $paragraph_code = substr ($content, $paragraph_positions [$position] + 1, $paragraph_positions [$paragraph_position_below] - $paragraph_positions [$position]);
1444
+ foreach ($avoid_paragraph_texts_below as $paragraph_text_below) {
1445
+ if (stripos ($paragraph_code, trim ($paragraph_text_below)) !== false) {
1446
+ $found_below = true;
1447
+ break;
1448
+ }
1449
+ }
1450
+ }
1451
 
 
 
1452
 
1453
+ // echo "position: $position = after #", $position + 1, "<br />\n";
1454
+ // echo "checks: $checks<br />\n";
1455
+ // echo "direction: $direction<br />\n";
1456
+ // if ($found_above)
1457
+ // echo "found_above<br />\n";
1458
+ // if ($found_below)
1459
+ // echo "found_below<br />\n";
1460
+ // echo "=================<br />\n";
1461
 
 
1462
 
1463
+ if ($found_above || $found_below) {
1464
+ $ai_last_check = AI_CHECK_DO_NOT_INSERT;
1465
+ if ($this->get_avoid_action() == AD_DO_NOT_INSERT) return $content;
1466
 
1467
+ switch ($direction) {
1468
+ case AD_ABOVE: // Try above
1469
+ $ai_last_check = AI_CHECK_AD_ABOVE;
1470
+ if ($position == 0) return $content; // Already at the top - do not insert
1471
+ $position --;
1472
+ break;
1473
+ case AD_BELOW: // Try below
1474
+ $ai_last_check = AI_CHECK_AD_BELOW;
1475
+ if ($position >= count ($paragraph_positions) - 1) return $content; // Already at the bottom - do not insert
1476
+ $position ++;
1477
+ break;
1478
+ case AD_ABOVE_AND_THEN_BELOW: // Try first above and then below
1479
+ if ($position == 0 || $checks == 0) {
1480
+ // Try below
1481
+ $direction = AD_BELOW;
1482
+ $checks = $max_checks;
1483
+ $position = $saved_position;
1484
+ $ai_last_check = AI_CHECK_AD_BELOW;
1485
+ if ($position >= count ($paragraph_positions) - 1) return $content; // Already at the bottom - do not insert
1486
+ $position ++;
1487
+ } else $position --;
1488
+ break;
1489
+ case AD_BELOW_AND_THEN_ABOVE: // Try first below and then above
1490
+ if ($position >= count ($paragraph_positions) - 1 || $checks == 0) {
1491
+ // Try above
1492
+ $direction = AD_ABOVE;
1493
+ $checks = $max_checks;
1494
+ $position = $saved_position;
1495
+ $ai_last_check = AI_CHECK_AD_ABOVE;
1496
+ if ($position == 0) return $content; // Already at the top - do not insert
1497
+ $position --;
1498
+ } else $position ++;
1499
+ break;
1500
+ }
1501
+ } else break; // Text not found - insert
1502
 
1503
+ // Try next position
1504
+ if ($checks <= 0) return $content; // Suitable position not found - do not insert
1505
+ $checks --;
1506
+ } while (true);
1507
+ }
1508
 
1509
+ // Nothing to do
1510
+ $ai_last_check = AI_CHECK_PARAGRAPHS_AFTER_CLEARANCE;
1511
+ if (count ($paragraph_positions) == 0) return $content;
1512
 
 
1513
 
1514
+ if ($position_preview) {
1515
+ $offset = 0;
1516
+ foreach ($paragraph_positions as $counter => $paragraph_position) {
1517
+ $inserted_code = "[[AI_AP".($counter + 1)."]]";
1518
+ if ($this->get_direction_type() == AD_DIRECTION_FROM_BOTTOM) {
1519
+ $content = substr_replace ($content, $inserted_code, $paragraph_position + 1, 0);
1520
+ } else {
1521
+ $content = substr_replace ($content, $inserted_code, $paragraph_position + $offset + 1, 0);
1522
+ $offset += strlen ($inserted_code);
1523
+ }
1524
+ }
1525
+ return $content;
1526
+ }
1527
 
1528
+ $ai_last_check = AI_CHECK_PARAGRAPHS_MIN_NUMBER;
1529
+ if (count ($paragraph_positions) > $position && count ($paragraph_positions) >= intval ($this->get_paragraph_number_minimum())) {
1530
+ $this->increment_block_counter ();
1531
+ $ai_last_check = AI_CHECK_DEBUG_NO_INSERTION;
1532
+ if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_NO_INSERTION) == 0) {
1533
+ $content_position = $paragraph_positions [$position];
1534
+ if ($content_position >= strlen ($content) - 1)
1535
+ $content = $content . $this->get_code_for_insertion (); else
1536
+ $content = substr_replace ($content, $this->get_code_for_insertion (), $content_position + 1, 0);
1537
+ $ai_last_check = AI_CHECK_INSERTED;
1538
+ }
1539
+ }
1540
 
1541
+ return $content;
 
1542
  }
1543
 
1544
  // Deprecated
1554
  $ad_tag = strtolower (trim ($tag));
1555
  $ad_name = strtolower (trim ($this->get_ad_name()));
1556
  if ($ad_tag == $ad_name || $ad_tag == $this->number) {
1557
+ if ($this->get_alignment_type() == AD_ALIGNMENT_NO_WRAPPING) $ad_code = $this->ai_getProcessedCode (); else
1558
+ $ad_code = "<div class='" . $block_class_name . " " . $block_class_name . "-" . $this->number . $this->get_viewport_classes () . "' style='" . $this->get_alignmet_style() . "'>" . $this->ai_getProcessedCode () . "</div>";
1559
  $content = preg_replace ("/{adinserter " . $tag . "}/", $ad_code, $content);
1560
  }
1561
  }
1585
  $categories = trim (strtolower ($this->get_ad_block_cat()));
1586
  $cat_type = $this->get_ad_block_cat_type();
1587
 
 
 
1588
  if ($cat_type == AD_BLACK_LIST) {
1589
 
1590
  if($categories == AD_EMPTY_DATA) return true;
1593
 
1594
  foreach (get_the_category() as $post_category) {
1595
 
 
 
1596
  foreach ($cats_listed as $cat_disabled){
1597
 
1598
  $cat_disabled = trim ($cat_disabled);
1600
  $post_category_name = strtolower ($post_category->cat_name);
1601
  $post_category_slug = strtolower ($post_category->slug);
1602
 
 
 
1603
  if ($post_category_name == $cat_disabled || $post_category_slug == $cat_disabled) {
 
1604
  return false;
1605
+ } else {
1606
+ }
 
1607
  }
1608
  }
1609
  return true;
1616
 
1617
  foreach (get_the_category() as $post_category) {
1618
 
 
 
1619
  foreach ($cats_listed as $cat_enabled) {
1620
 
1621
  $cat_enabled = trim ($cat_enabled);
1623
  $post_category_name = strtolower ($post_category->cat_name);
1624
  $post_category_slug = strtolower ($post_category->slug);
1625
 
 
 
1626
  if ($post_category_name == $cat_enabled || $post_category_slug == $cat_enabled) {
 
1627
  return true;
1628
+ } else {
1629
+ }
 
1630
  }
1631
  }
1632
  return false;
1645
  }
1646
  $has_any_of_the_given_tags = has_tag ($tags_listed);
1647
 
 
 
1648
  if ($tag_type == AD_BLACK_LIST) {
1649
 
1650
  if ($tags == AD_EMPTY_DATA) return true;
1673
  }
1674
  }
1675
 
1676
+ function check_id () {
1677
+ global $ai_wp_data;
1678
+
1679
+ $page_id = get_the_ID();
1680
+
1681
+ $ids = trim ($this->get_id_list());
1682
+ $id_type = $this->get_id_list_type();
1683
+
1684
+ if ($id_type == AD_BLACK_LIST) $return = false; else $return = true;
1685
+
1686
+ if ($ids == AD_EMPTY_DATA || $page_id === false) {
1687
+ return !$return;
1688
+ }
1689
+
1690
+ $ids_listed = explode (",", $ids);
1691
+ foreach ($ids_listed as $index => $id_listed) {
1692
+ if (trim ($id_listed) == "") unset ($ids_listed [$index]); else
1693
+ $ids_listed [$index] = trim ($id_listed);
1694
+ }
1695
+
1696
+ // print_r ($ids_listed);
1697
+ // echo "<br />\n";
1698
+ // echo ' page id: ' . $page_id, "<br />\n";
1699
+ // echo ' listed ids: ' . $ids, "\n";
1700
+ // echo "<br />\n";
1701
+
1702
+ if (in_array ($page_id, $ids_listed)) return $return;
1703
+
1704
+ return !$return;
1705
+ }
1706
+
1707
  function check_url () {
1708
+ global $ai_wp_data;
1709
+
1710
+ $page_url = $ai_wp_data [AI_WP_URL];
1711
 
1712
+ $urls = trim ($this->get_ad_url_list());
1713
  $url_type = $this->get_ad_url_list_type();
1714
 
1715
+ if ($url_type == AD_BLACK_LIST) $return = false; else $return = true;
1716
+
1717
+ if ($urls == AD_EMPTY_DATA) {
1718
+ return !$return;
1719
+ }
1720
 
 
1721
  $urls_listed = explode (" ", $urls);
1722
  foreach ($urls_listed as $index => $url_listed) {
1723
+ if (trim ($url_listed) == "") unset ($urls_listed [$index]); else
1724
  $urls_listed [$index] = trim ($url_listed);
1725
  }
1726
 
1730
  // echo ' listed urls: ' . $urls, "\n";
1731
  // echo "<br />\n";
1732
 
 
 
 
 
 
 
1733
  foreach ($urls_listed as $url_listed) {
 
1734
  if ($url_listed == '*') return $return;
1735
 
1736
  if ($url_listed [0] == '*') {
1746
  $url_listed = substr ($url_listed, 0, strlen ($url_listed) - 1);
1747
  if (strpos ($page_url, $url_listed) === 0) return $return;
1748
  }
1749
+ elseif ($url_listed == $page_url) return $return;
1750
  }
1751
  return !$return;
1752
  }
1753
 
1754
+ function check_url_parameters () {
1755
+ global $ai_wp_data;
1756
+
1757
+ $parameter_list = trim ($this->get_url_parameter_list());
1758
+ $parameter_list_type = $this->get_url_parameter_list_type();
1759
+
1760
+ if ($parameter_list_type == AD_BLACK_LIST) $return = false; else $return = true;
1761
+
1762
+ if ($parameter_list == AD_EMPTY_DATA || count ($_GET) == 0) {
1763
+ return !$return;
1764
+ }
1765
+
1766
+ $parameters_listed = explode (",", $parameter_list);
1767
+ foreach ($parameters_listed as $index => $parameter_listed) {
1768
+ if (trim ($parameter_listed) == "") unset ($parameters_listed [$index]); else
1769
+ $parameters_listed [$index] = trim ($parameter_listed);
1770
+ }
1771
+
1772
+ // print_r ($parameter_listed);
1773
+ // echo "<br />\n";
1774
+ // echo " parameters: <br />\n";
1775
+ // print_r ($_GET);
1776
+ // echo ' listed parameters: ' . $parameter_list, "\n";
1777
+ // echo "<br />\n";
1778
+
1779
+ foreach ($parameters_listed as $parameter) {
1780
+ if (strpos ($parameter, "=") !== false) {
1781
+ $parameter_value = explode ("=", $parameter);
1782
+ if (array_key_exists ($parameter_value [0], $_GET) && $_GET [$parameter_value [0]] == $parameter_value [1]) return $return;
1783
+ } else if (array_key_exists ($parameter, $_GET)) return $return;
1784
+ }
1785
+
1786
+ return !$return;
1787
+ }
1788
+
1789
  function check_date () {
1790
 
1791
+ $after_days = intval ($this->get_ad_after_day());
1792
+ if ($after_days == AD_ZERO) return true;
1793
 
1794
+ $post_date = get_the_date ('U');
1795
+ if ($post_date === false) return true;
1796
 
1797
+ return (date ('U', time ()) >= $post_date + $after_days * 86400);
1798
  }
1799
 
1800
  function check_referer () {
1808
  if ($domain_list_type == AD_BLACK_LIST) $return = false; else $return = true;
1809
 
1810
  $domains = trim ($this->get_ad_domain_list ());
1811
+ if ($domains == AD_EMPTY_DATA) return !$return;
1812
  $domains = explode (",", $domains);
1813
 
1814
  foreach ($domains as $domain) {
1822
  return !$return;
1823
  }
1824
 
1825
+ function check_number_of_words (&$content) {
1826
+ global $ai_last_check;
1827
+
1828
+ $number_of_words = number_of_words ($content);
1829
+
1830
+ $maximum_words = intval ($this->get_maximum_words());
1831
+ if ($maximum_words <= 0) $maximum_words = 1000000;
1832
+
1833
+ $ai_last_check = AI_CHECK_NUMBER_OF_WORDS;
1834
+ if ($number_of_words < intval ($this->get_minimum_words()) || $number_of_words > $maximum_words) return false;
1835
+ return true;
1836
+ }
1837
+
1838
+ function check_number_of_words_in_paragraph ($content, $min, $max) {
1839
+
1840
+ $number_of_words = number_of_words ($content);
1841
+
1842
+ if ($max <= 0) $max = 1000000;
1843
+
1844
+ if ($number_of_words < $min || $number_of_words > $max) return false;
1845
+
1846
+ return true;
1847
+ }
1848
+
1849
+ function check_page_types_lists_users ($ignore_page_types = false) {
1850
+ global $ai_last_check, $ai_wp_data;
1851
+
1852
+ if (!$ignore_page_types) {
1853
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_HOMEPAGE){
1854
+ $ai_last_check = AI_CHECK_PAGE_TYPE_FRONT_PAGE;
1855
+ if (!$this->get_display_settings_home()) return false;
1856
+ }
1857
+ elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_STATIC){
1858
+ $ai_last_check = AI_CHECK_PAGE_TYPE_STATIC_PAGE;
1859
+ if (!$this->get_display_settings_page()) return false;
1860
+ }
1861
+ elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_POST){
1862
+ $ai_last_check = AI_CHECK_PAGE_TYPE_POST;
1863
+ if (!$this->get_display_settings_post()) return false;
1864
+ }
1865
+ elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_CATEGORY){
1866
+ $ai_last_check = AI_CHECK_PAGE_TYPE_CATEGORY;
1867
+ if (!$this->get_display_settings_category()) return false;
1868
+ }
1869
+ elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_SEARCH){
1870
+ $ai_last_check = AI_CHECK_PAGE_TYPE_SEARCH;
1871
+ if (!$this->get_display_settings_search()) return false;
1872
+ }
1873
+ elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_ARCHIVE){
1874
+ $ai_last_check = AI_CHECK_PAGE_TYPE_ARCHIVE;
1875
+ if (!$this->get_display_settings_archive()) return false;
1876
+ }
1877
+ elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_FEED){
1878
+ $ai_last_check = AI_CHECK_PAGE_TYPE_FEED;
1879
+ if (!$this->get_enable_feed()) return false;
1880
+ }
1881
+ elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_404){
1882
+ $ai_last_check = AI_CHECK_PAGE_TYPE_404;
1883
+ if (!$this->get_enable_404()) return false;
1884
+ }
1885
+ }
1886
+
1887
+ $ai_last_check = AI_CHECK_CATEGORY;
1888
+ if (!$this->check_category ()) return false;
1889
+
1890
+ $ai_last_check = AI_CHECK_TAG;
1891
+ if (!$this->check_tag ()) return false;
1892
+
1893
+ $ai_last_check = AI_CHECK_ID;
1894
+ if (!$this->check_id ()) return false;
1895
+
1896
+ $ai_last_check = AI_CHECK_URL;
1897
+ if (!$this->check_url ()) return false;
1898
+
1899
+ $ai_last_check = AI_CHECK_URL_PARAMETER;
1900
+ if (!$this->check_url_parameters ()) return false;
1901
+
1902
+ $ai_last_check = AI_CHECK_REFERER;
1903
+ if (!$this->check_referer ()) return false;
1904
+
1905
+ $ai_last_check = AI_CHECK_DATE;
1906
+ if (!$this->check_date ()) return false;
1907
+
1908
+ $ai_last_check = AI_CHECK_CODE;
1909
+ if ($this->ai_getCode () == '') return false;
1910
+
1911
+ $display_for_users = $this->get_display_for_users ();
1912
+
1913
+ $ai_last_check = AI_CHECK_LOGGED_IN_USER;
1914
+ if ($display_for_users == AD_DISPLAY_LOGGED_IN_USERS && ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != AI_USER_LOGGED_IN) return "";
1915
+ $ai_last_check = AI_CHECK_NOT_LOGGED_IN_USER;
1916
+ if ($display_for_users == AD_DISPLAY_NOT_LOGGED_IN_USERS && ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) == AI_USER_LOGGED_IN) return "";
1917
+ $ai_last_check = AI_CHECK_ADMINISTRATOR;
1918
+ if ($display_for_users == AD_DISPLAY_ADMINISTRATORS && ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != AI_USER_ADMINISTRATOR) return "";
1919
+
1920
+ return true;
1921
+ }
1922
+
1923
+ function check_post_page_exceptions ($selected_blocks) {
1924
+ global $ai_last_check, $ai_wp_data;
1925
+
1926
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_POST) {
1927
+ $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1928
+ $selected_blocks = explode (",", $meta_value);
1929
+
1930
+ $enabled_on_text = $this->get_ad_enabled_on_which_posts ();
1931
+ if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1932
+ $ai_last_check = AI_CHECK_ENABLED_ON_ALL_EXCEPT_ON_SELECTED;
1933
+ if (in_array ($this->number, $selected_blocks)) return false;
1934
+ }
1935
+ elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1936
+ $ai_last_check = AI_CHECK_ENABLED_ONLY_ON_SELECTED;
1937
+ if (!in_array ($this->number, $selected_blocks)) return false;
1938
+ }
1939
+ } elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_STATIC) {
1940
+ $meta_value = get_post_meta (get_the_ID (), '_adinserter_block_exceptions', true);
1941
+ $selected_blocks = explode (",", $meta_value);
1942
+
1943
+ $enabled_on_text = $this->get_ad_enabled_on_which_pages ();
1944
+ if ($enabled_on_text == AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) {
1945
+ $ai_last_check = AI_CHECK_ENABLED_ON_ALL_EXCEPT_ON_SELECTED;
1946
+ if (in_array ($this->number, $selected_blocks)) return false;
1947
+ }
1948
+ elseif ($enabled_on_text == AD_ENABLED_ONLY_ON_SELECTED) {
1949
+ $ai_last_check = AI_CHECK_ENABLED_ONLY_ON_SELECTED;
1950
+ if (!in_array ($this->number, $selected_blocks)) return false;
1951
+ }
1952
+ }
1953
+ return true;
1954
+ }
1955
+
1956
+ function check_filter ($counter_for_filter) {
1957
+ global $ai_last_check, $ad_interter_globals;
1958
+
1959
+ $ai_last_check = AI_CHECK_FILTER;
1960
+ $filter_settings = trim ($this->get_call_filter());
1961
+ if ($filter_settings == 0 || $filter_settings == '') return true;
1962
+
1963
+ switch ($this->get_filter_type ()) {
1964
+ case AI_OPTION_FILTER_PHP_FUNCTION_CALLS:
1965
+ if (isset ($ad_interter_globals [AI_PHP_FUNCTION_CALL_COUNTER_NAME . $this->number]))
1966
+ $counter_for_filter = $ad_interter_globals [AI_PHP_FUNCTION_CALL_COUNTER_NAME . $this->number]; else return false;
1967
+ break;
1968
+ case AI_OPTION_FILTER_CONTENT_PROCESSING:
1969
+ if (isset ($ad_interter_globals [AI_CONTENT_COUNTER_NAME]))
1970
+ $counter_for_filter = $ad_interter_globals [AI_CONTENT_COUNTER_NAME]; else return false;
1971
+ break;
1972
+ case AI_OPTION_FILTER_EXCERPT_PROCESSING:
1973
+ if (isset ($ad_interter_globals [AI_EXCERPT_COUNTER_NAME]))
1974
+ $counter_for_filter = $ad_interter_globals [AI_EXCERPT_COUNTER_NAME]; else return false;
1975
+ break;
1976
+ case AI_OPTION_FILTER_BEFORE_POST_PROCESSING:
1977
+ if (isset ($ad_interter_globals [AI_LOOP_BEFORE_COUNTER_NAME]))
1978
+ $counter_for_filter = $ad_interter_globals [AI_LOOP_BEFORE_COUNTER_NAME]; else return false;
1979
+ break;
1980
+ case AI_OPTION_FILTER_AFTER_POST_PROCESSING:
1981
+ if (isset ($ad_interter_globals [AI_LOOP_AFTER_COUNTER_NAME]))
1982
+ $counter_for_filter = $ad_interter_globals [AI_LOOP_AFTER_COUNTER_NAME]; else return false;
1983
+ break;
1984
+ case AI_OPTION_FILTER_WIDGET_DRAWING:
1985
+ if (isset ($ad_interter_globals [AI_WIDGET_COUNTER_NAME . $this->number]))
1986
+ $counter_for_filter = $ad_interter_globals [AI_WIDGET_COUNTER_NAME . $this->number]; else return false;
1987
+ break;
1988
+ }
1989
+
1990
+ $filter_values = array ();
1991
+ if (strpos ($filter_settings, ",") !== false) {
1992
+ $filter_values = explode (",", $filter_settings);
1993
+ } else $filter_values []= $filter_settings;
1994
+
1995
+ return in_array ($counter_for_filter, $filter_values);
1996
+ }
1997
+
1998
  function check_and_increment_block_counter () {
1999
+ global $ad_interter_globals, $ai_last_check;
2000
 
2001
+ $global_name = AI_BLOCK_COUNTER_NAME . $this->number;
2002
+ $max_insertions = intval ($this->get_maximum_insertions ());
2003
  if (!isset ($ad_interter_globals [$global_name])) {
2004
  $ad_interter_globals [$global_name] = 0;
2005
  }
2006
+ $ai_last_check = AI_CHECK_MAX_INSERTIONS;
2007
  if ($max_insertions != 0 && $ad_interter_globals [$global_name] >= $max_insertions) return false;
2008
  $ad_interter_globals [$global_name] ++;
2009
+
2010
  return true;
2011
  }
2012
 
2013
  function check_block_counter () {
2014
  global $ad_interter_globals;
2015
 
2016
+ $global_name = AI_BLOCK_COUNTER_NAME . $this->number;
2017
+ $max_insertions = intval ($this->get_maximum_insertions ());
2018
  if (!isset ($ad_interter_globals [$global_name])) {
2019
  $ad_interter_globals [$global_name] = 0;
2020
  }
2021
+ $ai_last_check = AI_CHECK_MAX_INSERTIONS;
2022
  if ($max_insertions != 0 && $ad_interter_globals [$global_name] >= $max_insertions) return false;
2023
  return true;
2024
  }
2026
  function increment_block_counter () {
2027
  global $ad_interter_globals;
2028
 
2029
+ if ($this->number == 0) return;
2030
+
2031
+ $global_name = AI_BLOCK_COUNTER_NAME . $this->number;
2032
  if (!isset ($ad_interter_globals [$global_name])) {
2033
  $ad_interter_globals [$global_name] = 0;
2034
  }
2036
  return;
2037
  }
2038
 
2039
+
2040
+ function replace_ai_tags ($content){
2041
+ global $ai_wp_data;
2042
+
2043
+ $general_tag = str_replace ("&amp;", " and ", $this->get_ad_general_tag());
2044
+ $title = $general_tag;
2045
+ $short_title = $general_tag;
2046
+ $category = $general_tag;
2047
+ $short_category = $general_tag;
2048
+ $tag = $general_tag;
2049
+ $smart_tag = $general_tag;
2050
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_CATEGORY) {
2051
+ $categories = get_the_category();
2052
+ if (!empty ($categories)) {
2053
+ $first_category = reset ($categories);
2054
+ $category = str_replace ("&amp;", "and", $first_category->name);
2055
+ if ($category == "Uncategorized") $category = $general_tag;
2056
+ } else {
2057
+ $category = $general_tag;
2058
+ }
2059
+ if (strpos ($category, ",") !== false) {
2060
+ $short_category = trim (substr ($category, 0, strpos ($category, ",")));
2061
+ } else $short_category = $category;
2062
+ if (strpos ($short_category, "and") !== false) {
2063
+ $short_category = trim (substr ($short_category, 0, strpos ($short_category, "and")));
2064
+ }
2065
+
2066
+ $title = $category;
2067
+ $title = str_replace ("&amp;", "and", $title);
2068
+ $short_title = implode (" ", array_slice (explode (" ", $title), 0, 3));
2069
+ $tag = $short_title;
2070
+ $smart_tag = $short_title;
2071
+ } elseif (is_tag ()) {
2072
+ $title = single_tag_title('', false);
2073
+ $title = str_replace (array ("&amp;", "#"), array ("and", ""), $title);
2074
+ $short_title = implode (" ", array_slice (explode (" ", $title), 0, 3));
2075
+ $category = $short_title;
2076
+ if (strpos ($category, ",") !== false) {
2077
+ $short_category = trim (substr ($category, 0, strpos ($category, ",")));
2078
+ } else $short_category = $category;
2079
+ if (strpos ($short_category, "and") !== false) {
2080
+ $short_category = trim (substr ($short_category, 0, strpos ($short_category, "and")));
2081
+ }
2082
+ $tag = $short_title;
2083
+ $smart_tag = $short_title;
2084
+ } elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_SEARCH) {
2085
+ $title = get_search_query();
2086
+ $title = str_replace ("&amp;", "and", $title);
2087
+ $short_title = implode (" ", array_slice (explode (" ", $title), 0, 3));
2088
+ $category = $short_title;
2089
+ if (strpos ($category, ",") !== false) {
2090
+ $short_category = trim (substr ($category, 0, strpos ($category, ",")));
2091
+ } else $short_category = $category;
2092
+ if (strpos ($short_category, "and") !== false) {
2093
+ $short_category = trim (substr ($short_category, 0, strpos ($short_category, "and")));
2094
+ }
2095
+ $tag = $short_title;
2096
+ $smart_tag = $short_title;
2097
+ } elseif ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_STATIC || $ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_POST) {
2098
+ $title = get_the_title();
2099
+ $title = str_replace ("&amp;", "and", $title);
2100
+
2101
+ $short_title = implode (" ", array_slice (explode (" ", $title), 0, 3));
2102
+
2103
+ $categories = get_the_category();
2104
+ if (!empty ($categories)) {
2105
+ $first_category = reset ($categories);
2106
+ $category = str_replace ("&amp;", "and", $first_category->name);
2107
+ if ($category == "Uncategorized") $category = $general_tag;
2108
+ } else {
2109
+ $category = $short_title;
2110
+ }
2111
+ if (strpos ($category, ",") !== false) {
2112
+ $short_category = trim (substr ($category, 0, strpos ($category, ",")));
2113
+ } else $short_category = $category;
2114
+ if (strpos ($short_category, "and") !== false) {
2115
+ $short_category = trim (substr ($short_category, 0, strpos ($short_category, "and")));
2116
+ }
2117
+
2118
+ $tags = get_the_tags();
2119
+ if (!empty ($tags)) {
2120
+
2121
+ $first_tag = reset ($tags);
2122
+ $tag = str_replace (array ("&amp;", "#"), array ("and", ""), $first_tag->name);
2123
+
2124
+ $tag_array = array ();
2125
+ foreach ($tags as $tag_data) {
2126
+ $tag_array [] = explode (" ", $tag_data->name);
2127
+ }
2128
+
2129
+ $selected_tag = '';
2130
+
2131
+ if (count ($tag_array [0]) == 2) $selected_tag = $tag_array [0];
2132
+ elseif (count ($tag_array) > 1 && count ($tag_array [1]) == 2) $selected_tag = $tag_array [1];
2133
+ elseif (count ($tag_array) > 2 && count ($tag_array [2]) == 2) $selected_tag = $tag_array [2];
2134
+ elseif (count ($tag_array) > 3 && count ($tag_array [3]) == 2) $selected_tag = $tag_array [3];
2135
+ elseif (count ($tag_array) > 4 && count ($tag_array [4]) == 2) $selected_tag = $tag_array [4];
2136
+
2137
+
2138
+ if ($selected_tag == '' && count ($tag_array) >= 2 && count ($tag_array [0]) == 1 && count ($tag_array [1]) == 1) {
2139
+
2140
+ if (strpos ($tag_array [0][0], $tag_array [1][0]) !== false) $tag_array = array_slice ($tag_array, 1, count ($tag_array) - 1);
2141
+ if (strpos ($tag_array [1][0], $tag_array [0][0]) !== false) $tag_array = array_slice ($tag_array, 1, count ($tag_array) - 1);
2142
+
2143
+ if (count ($tag_array) >= 2 && count ($tag_array [0]) == 1 && count ($tag_array [1]) == 1) {
2144
+ $selected_tag = array ($tag_array [0][0], $tag_array [1][0]);
2145
+ }
2146
+ }
2147
+
2148
+ if ($selected_tag == '') {
2149
+ $first_tag = reset ($tags);
2150
+ $smart_tag = implode (" ", array_slice (explode (" ", $first_tag->name), 0, 3));
2151
+ } else $smart_tag = implode (" ", $selected_tag);
2152
+
2153
+ $smart_tag = str_replace (array ("&amp;", "#"), array ("and", ""), $smart_tag);
2154
+
2155
+ } else {
2156
+ $tag = $category;
2157
+ $smart_tag = $category;
2158
+ }
2159
+ }
2160
+
2161
+ $title = str_replace (array ("'", '"'), array ("&#8217;", "&#8221;"), $title);
2162
+ $title = html_entity_decode ($title, ENT_QUOTES, "utf-8");
2163
+
2164
+ $short_title = str_replace (array ("'", '"'), array ("&#8217;", "&#8221;"), $short_title);
2165
+ $short_title = html_entity_decode ($short_title, ENT_QUOTES, "utf-8");
2166
+
2167
+ $search_query = "";
2168
+ if (isset ($_SERVER['HTTP_REFERER'])) {
2169
+ $referrer = $_SERVER['HTTP_REFERER'];
2170
+ } else $referrer = '';
2171
+ if (preg_match ("/[\.\/](google|yahoo|bing|ask)\.[a-z\.]{2,5}[\/]/i", $referrer, $search_engine)){
2172
+ $referrer_query = parse_url ($referrer);
2173
+ $referrer_query = isset ($referrer_query ["query"]) ? $referrer_query ["query"] : "";
2174
+ parse_str ($referrer_query, $value);
2175
+ $search_query = isset ($value ["q"]) ? $value ["q"] : "";
2176
+ if ($search_query == "") {
2177
+ $search_query = isset ($value ["p"]) ? $value ["p"] : "";
2178
+ }
2179
+ }
2180
+ if ($search_query == "") $search_query = $smart_tag;
2181
+
2182
+ $author = get_the_author_meta ('display_name');
2183
+ $author_name = get_the_author_meta ('first_name') . " " . get_the_author_meta ('last_name');
2184
+ if ($author_name == '') $author_name = $author;
2185
+
2186
+ $ad_data = preg_replace ("/{title}/i", $title, $content);
2187
+ $ad_data = preg_replace ("/{short_title}/i", $short_title, $ad_data);
2188
+ $ad_data = preg_replace ("/{category}/i", $category, $ad_data);
2189
+ $ad_data = preg_replace ("/{short_category}/i", $short_category, $ad_data);
2190
+ $ad_data = preg_replace ("/{tag}/i", $tag, $ad_data);
2191
+ $ad_data = preg_replace ("/{smart_tag}/i", $smart_tag, $ad_data);
2192
+ $ad_data = preg_replace ("/{search_query}/i", $search_query, $ad_data);
2193
+ $ad_data = preg_replace ("/{author}/i", $author, $ad_data);
2194
+ $ad_data = preg_replace ("/{author_name}/i", $author_name, $ad_data);
2195
+
2196
+ return $ad_data;
2197
+ }
2198
  }
2199
 
2200
 
constants.php CHANGED
@@ -7,11 +7,11 @@ if (file_exists (AD_INSERTER_PLUGIN_DIR.'functions.php')) {
7
  include_once AD_INSERTER_PLUGIN_DIR.'functions.php';
8
  }
9
 
10
- if (!defined( 'AD_INSERTER_TITLE'))
11
- define ('AD_INSERTER_TITLE', 'Ad Inserter');
12
 
13
  if (!defined( 'AD_INSERTER_VERSION'))
14
- define ('AD_INSERTER_VERSION', '1.7.0');
15
 
16
  if (!defined ('AD_INSERTER_BLOCKS'))
17
  define ('AD_INSERTER_BLOCKS', 16);
@@ -49,6 +49,7 @@ if (!defined ('WP_PLUGIN_DIR'))
49
  define ('AD_EMPTY_DATA', '');
50
  define ('AD_ZERO', '0');
51
  define ('AD_ONE', '1');
 
52
  define ('AD_GENERAL_TAG', 'wordpress');
53
  define ('AD_NAME', 'Block');
54
 
@@ -58,8 +59,9 @@ define ('AD_ADx_OPTIONS', 'AdInserter#Options');
58
 
59
  // Options
60
  define ('WP_OPTION_NAME', 'ad_inserter');
61
- define ('WP_FORM_FIELD_POSTFIX', '_block_');
62
  define ('AI_GLOBAL_OPTION_NAME', 'global');
 
 
63
  define ('AI_HEADER_OPTION_NAME', 'h');
64
  define ('AI_FOOTER_OPTION_NAME', 'f');
65
 
@@ -67,23 +69,38 @@ define ('AI_OPTION_CODE', 'code');
67
  define ('AI_OPTION_ENABLE_MANUAL', 'enable_manual');
68
  define ('AI_OPTION_ENABLE_WIDGET', 'enable_widget');
69
  define ('AI_OPTION_PROCESS_PHP', 'process_php');
 
70
  define ('AI_OPTION_ENABLE_404', 'enable_404');
71
-
72
  define ('AI_OPTION_NAME', 'name');
73
  define ('AI_OPTION_DISPLAY_TYPE', 'display_type');
74
  define ('AI_OPTION_PARAGRAPH_NUMBER', 'paragraph_number');
75
  define ('AI_OPTION_MIN_PARAGRAPHS', 'min_paragraphs');
 
76
  define ('AI_OPTION_MIN_WORDS', 'min_words');
 
77
  define ('AI_OPTION_MIN_PARAGRAPH_WORDS', 'min_paragraph_words');
 
78
  define ('AI_OPTION_PARAGRAPH_TAGS', 'paragraph_tags');
79
- define ('AI_OPTION_EXCERPT_NUMBER', 'excerpt_number');
 
 
 
 
 
 
 
 
80
  define ('AI_OPTION_DIRECTION_TYPE', 'direction_type');
81
  define ('AI_OPTION_ALIGNMENT_TYPE', 'alignment_type');
82
  define ('AI_OPTION_GENERAL_TAG', 'general_tag');
83
  define ('AI_OPTION_AFTER_DAYS', 'after_days');
84
  define ('AI_OPTION_MAXIMUM_INSERTIONS', 'maximum_insertions');
 
 
85
  define ('AI_OPTION_URL_LIST', 'url_list');
86
  define ('AI_OPTION_URL_LIST_TYPE', 'url_list_type');
 
 
87
  define ('AI_OPTION_DOMAIN_LIST', 'domain_list');
88
  define ('AI_OPTION_DOMAIN_LIST_TYPE', 'domain_list_type');
89
  define ('AI_OPTION_CATEGORY_LIST', 'category_list');
@@ -107,12 +124,11 @@ define ('AI_OPTION_DISPLAY_FOR_DEVICES', 'display_for_devices');
107
  define ('AI_OPTION_DETECT_SERVER_SIDE', 'detect_server_side');
108
  define ('AI_OPTION_DETECT_CLIENT_SIDE', 'detect_client_side');
109
  define ('AI_OPTION_DETECT_VIEWPORT', 'detect_viewport');
110
- define ('AI_OPTION_BEFORE_PROCESSING', 'before_processing');
111
- define ('AI_OPTION_AFTER_PROCESSING', 'after_processing');
112
  define ('AI_OPTION_DISABLED', 'disabled');
113
 
114
  define ('AI_OPTION_IMPORT', 'import');
115
 
 
116
  //misc
117
  define('AD_EMPTY_VALUE','');
118
 
@@ -142,9 +158,10 @@ define('AD_SELECT_BEFORE_TITLE','Before Title'); // Deprecated
142
  define('AD_SELECT_MANUAL','Manual'); // Deprecated
143
 
144
  //Display options
145
- define('AD_DISPLAY_ALL_USERS','all');
146
- define('AD_DISPLAY_LOGGED_IN_USERS','logged in');
147
- define('AD_DISPLAY_NOT_LOGGED_IN_USERS','not logged in');
 
148
 
149
  define('AD_DISPLAY_ALL_DEVICES','all');
150
  define('AD_DISPLAY_DESKTOP_DEVICES','desktop');
@@ -177,12 +194,39 @@ define('AD_ALIGNMENT_FLOAT_RIGHT','Float Right');
177
  define('AD_BLACK_LIST','Black List');
178
  define('AD_WHITE_LIST','White List');
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  //Text List Type
181
  define('AD_CONTAIN','contain');
182
  define('AD_DO_NOT_CONTAIN','do not contain');
183
 
 
 
 
 
 
 
 
 
 
184
  //Settings
185
- define('AD_SETTINGS_CHECKED', '1');
186
  define('AD_SETTINGS_NOT_CHECKED', '0');
187
 
188
  define('DEFAULT_MARGIN', 8);
@@ -192,7 +236,11 @@ define ('DEFAULT_BLOCK_CLASS_NAME', 'code-block');
192
  define ('DEFAULT_MINIMUM_USER_ROLE', 'administrator');
193
  define ('DEFAULT_PLUGIN_PRIORITY', 99999);
194
  define ('DEFAULT_PARAGRAPH_TAGS', 'p');
195
- define ('DEFAULT_TAG_DEBUGGING', AI_OPTION_DISABLED);
 
 
 
 
196
 
197
  define ('DEFAULT_VIEWPORT_NAME_1', "Desktop");
198
  define ('DEFAULT_VIEWPORT_NAME_2', "Tablet");
@@ -201,3 +249,116 @@ define ('DEFAULT_VIEWPORT_NAME_3', "Phone");
201
  define ('DEFAULT_VIEWPORT_WIDTH_1', 980);
202
  define ('DEFAULT_VIEWPORT_WIDTH_2', 768);
203
  define ('DEFAULT_VIEWPORT_WIDTH_3', 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  include_once AD_INSERTER_PLUGIN_DIR.'functions.php';
8
  }
9
 
10
+ if (!defined( 'AD_INSERTER_NAME'))
11
+ define ('AD_INSERTER_NAME', 'Ad Inserter');
12
 
13
  if (!defined( 'AD_INSERTER_VERSION'))
14
+ define ('AD_INSERTER_VERSION', '2.0.0');
15
 
16
  if (!defined ('AD_INSERTER_BLOCKS'))
17
  define ('AD_INSERTER_BLOCKS', 16);
49
  define ('AD_EMPTY_DATA', '');
50
  define ('AD_ZERO', '0');
51
  define ('AD_ONE', '1');
52
+ define ('AD_TWO', '2');
53
  define ('AD_GENERAL_TAG', 'wordpress');
54
  define ('AD_NAME', 'Block');
55
 
59
 
60
  // Options
61
  define ('WP_OPTION_NAME', 'ad_inserter');
 
62
  define ('AI_GLOBAL_OPTION_NAME', 'global');
63
+ define ('AI_EXTRACT_OPTION_NAME', 'extract');
64
+ define ('WP_FORM_FIELD_POSTFIX', '_block_');
65
  define ('AI_HEADER_OPTION_NAME', 'h');
66
  define ('AI_FOOTER_OPTION_NAME', 'f');
67
 
69
  define ('AI_OPTION_ENABLE_MANUAL', 'enable_manual');
70
  define ('AI_OPTION_ENABLE_WIDGET', 'enable_widget');
71
  define ('AI_OPTION_PROCESS_PHP', 'process_php');
72
+ define ('AI_OPTION_ENABLE_FEED', 'enable_feed');
73
  define ('AI_OPTION_ENABLE_404', 'enable_404');
 
74
  define ('AI_OPTION_NAME', 'name');
75
  define ('AI_OPTION_DISPLAY_TYPE', 'display_type');
76
  define ('AI_OPTION_PARAGRAPH_NUMBER', 'paragraph_number');
77
  define ('AI_OPTION_MIN_PARAGRAPHS', 'min_paragraphs');
78
+ define ('AI_OPTION_COUNT_INSIDE_BLOCKQUOTE', 'count_inside_blockquote');
79
  define ('AI_OPTION_MIN_WORDS', 'min_words');
80
+ define ('AI_OPTION_MAX_WORDS', 'max_words');
81
  define ('AI_OPTION_MIN_PARAGRAPH_WORDS', 'min_paragraph_words');
82
+ define ('AI_OPTION_MAX_PARAGRAPH_WORDS', 'max_paragraph_words');
83
  define ('AI_OPTION_PARAGRAPH_TAGS', 'paragraph_tags');
84
+ define ('AI_OPTION_AVOID_PARAGRAPHS_ABOVE', 'avoid_paragraphs_above');
85
+ define ('AI_OPTION_AVOID_PARAGRAPHS_BELOW', 'avoid_paragraphs_below');
86
+ define ('AI_OPTION_AVOID_TEXT_ABOVE', 'avoid_text_above');
87
+ define ('AI_OPTION_AVOID_TEXT_BELOW', 'avoid_text_below');
88
+ define ('AI_OPTION_AVOID_ACTION', 'avoid_action');
89
+ define ('AI_OPTION_AVOID_TRY_LIMIT', 'avoid_try_limit');
90
+ define ('AI_OPTION_AVOID_DIRECTION', 'avoid_direction');
91
+ define ('AI_OPTION_EXCERPT_NUMBER', 'excerpt_number'); // needs to be renamed
92
+ define ('AI_OPTION_FILTER_TYPE', 'filter_type');
93
  define ('AI_OPTION_DIRECTION_TYPE', 'direction_type');
94
  define ('AI_OPTION_ALIGNMENT_TYPE', 'alignment_type');
95
  define ('AI_OPTION_GENERAL_TAG', 'general_tag');
96
  define ('AI_OPTION_AFTER_DAYS', 'after_days');
97
  define ('AI_OPTION_MAXIMUM_INSERTIONS', 'maximum_insertions');
98
+ define ('AI_OPTION_ID_LIST', 'id_list');
99
+ define ('AI_OPTION_ID_LIST_TYPE', 'id_list_type');
100
  define ('AI_OPTION_URL_LIST', 'url_list');
101
  define ('AI_OPTION_URL_LIST_TYPE', 'url_list_type');
102
+ define ('AI_OPTION_URL_PARAMETER_LIST', 'url_parameter_list');
103
+ define ('AI_OPTION_URL_PARAMETER_LIST_TYPE', 'url_parameter_list_type');
104
  define ('AI_OPTION_DOMAIN_LIST', 'domain_list');
105
  define ('AI_OPTION_DOMAIN_LIST_TYPE', 'domain_list_type');
106
  define ('AI_OPTION_CATEGORY_LIST', 'category_list');
124
  define ('AI_OPTION_DETECT_SERVER_SIDE', 'detect_server_side');
125
  define ('AI_OPTION_DETECT_CLIENT_SIDE', 'detect_client_side');
126
  define ('AI_OPTION_DETECT_VIEWPORT', 'detect_viewport');
 
 
127
  define ('AI_OPTION_DISABLED', 'disabled');
128
 
129
  define ('AI_OPTION_IMPORT', 'import');
130
 
131
+
132
  //misc
133
  define('AD_EMPTY_VALUE','');
134
 
158
  define('AD_SELECT_MANUAL','Manual'); // Deprecated
159
 
160
  //Display options
161
+ define('AD_DISPLAY_ALL_USERS','all users');
162
+ define('AD_DISPLAY_LOGGED_IN_USERS','logged in users');
163
+ define('AD_DISPLAY_NOT_LOGGED_IN_USERS','not logged in users');
164
+ define('AD_DISPLAY_ADMINISTRATORS','administrators');
165
 
166
  define('AD_DISPLAY_ALL_DEVICES','all');
167
  define('AD_DISPLAY_DESKTOP_DEVICES','desktop');
194
  define('AD_BLACK_LIST','Black List');
195
  define('AD_WHITE_LIST','White List');
196
 
197
+ //Filter Type
198
+ define ('AI_OPTION_FILTER_AUTO', 'Auto');
199
+ define ('AI_OPTION_FILTER_PHP_FUNCTION_CALLS', 'PHP function calls');
200
+ define ('AI_OPTION_FILTER_CONTENT_PROCESSING', 'Content processing');
201
+ define ('AI_OPTION_FILTER_EXCERPT_PROCESSING', 'Excerpt processing');
202
+ define ('AI_OPTION_FILTER_BEFORE_POST_PROCESSING', 'Before post processing');
203
+ define ('AI_OPTION_FILTER_AFTER_POST_PROCESSING', 'After post processing');
204
+ define ('AI_OPTION_FILTER_WIDGET_DRAWING', 'Widget drawing');
205
+
206
+ //Counter names
207
+ define ('AI_BLOCK_COUNTER_NAME', 'AI_BLOCK_COUNTER_');
208
+ define ('AI_PHP_FUNCTION_CALL_COUNTER_NAME', 'AI_PHP_FUNCTION_CALL_COUNTER_');
209
+ define ('AI_CONTENT_COUNTER_NAME', 'AI_CONTENT_COUNTER');
210
+ define ('AI_EXCERPT_COUNTER_NAME', 'AI_EXCERPT_COUNTER');
211
+ define ('AI_LOOP_BEFORE_COUNTER_NAME', 'AI_LOOP_BEFORE_COUNTER');
212
+ define ('AI_LOOP_AFTER_COUNTER_NAME', 'AI_LOOP_AFTER_COUNTER');
213
+ define ('AI_WIDGET_COUNTER_NAME', 'AI_WIDGET_COUNTER_');
214
+
215
  //Text List Type
216
  define('AD_CONTAIN','contain');
217
  define('AD_DO_NOT_CONTAIN','do not contain');
218
 
219
+ //Avoid text action
220
+ define('AD_DO_NOT_INSERT','do not insert');
221
+ define('AD_TRY_TO_SHIFT_POSITION','try to shift position');
222
+
223
+ define('AD_ABOVE','above');
224
+ define('AD_BELOW','below');
225
+ define('AD_ABOVE_AND_THEN_BELOW','above and then below');
226
+ define('AD_BELOW_AND_THEN_ABOVE','below and then above');
227
+
228
  //Settings
229
+ define('AD_SETTINGS_CHECKED', '1');
230
  define('AD_SETTINGS_NOT_CHECKED', '0');
231
 
232
  define('DEFAULT_MARGIN', 8);
236
  define ('DEFAULT_MINIMUM_USER_ROLE', 'administrator');
237
  define ('DEFAULT_PLUGIN_PRIORITY', 99999);
238
  define ('DEFAULT_PARAGRAPH_TAGS', 'p');
239
+ define ('DEFAULT_REMOTE_DEBUGGING', AD_SETTINGS_NOT_CHECKED);
240
+ define ('DEFAULT_JAVASCRIPT_DEBUGGING', AD_SETTINGS_NOT_CHECKED);
241
+ define ('DEFAULT_MULTISITE_SETTINGS_PAGE', AD_SETTINGS_CHECKED);
242
+ define ('DEFAULT_MULTISITE_WIDGETS', AD_SETTINGS_CHECKED);
243
+ define ('DEFAULT_MULTISITE_EXCEPTIONS', AD_SETTINGS_CHECKED);
244
 
245
  define ('DEFAULT_VIEWPORT_NAME_1', "Desktop");
246
  define ('DEFAULT_VIEWPORT_NAME_2', "Tablet");
249
  define ('DEFAULT_VIEWPORT_WIDTH_1', 980);
250
  define ('DEFAULT_VIEWPORT_WIDTH_2', 768);
251
  define ('DEFAULT_VIEWPORT_WIDTH_3', 0);
252
+
253
+ define ('CONTENT_HOOK_BLOCKS', 'content_hook');
254
+ define ('EXCERPT_HOOK_BLOCKS', 'excerpt_hook');
255
+ define ('LOOP_START_HOOK_BLOCKS', 'loop_start_hook');
256
+ define ('LOOP_END_HOOK_BLOCKS', 'loop_end_hook');
257
+
258
+ define ('AI_CHECK_NONE', - 1);
259
+ define ('AI_CHECK_INSERTED', 0);
260
+
261
+ define ('AI_CHECK_PAGE_TYPE_FRONT_PAGE', 1);
262
+ define ('AI_CHECK_PAGE_TYPE_STATIC_PAGE', 2);
263
+ define ('AI_CHECK_PAGE_TYPE_POST', 3);
264
+ define ('AI_CHECK_PAGE_TYPE_CATEGORY', 4);
265
+ define ('AI_CHECK_PAGE_TYPE_SEARCH', 5);
266
+ define ('AI_CHECK_PAGE_TYPE_ARCHIVE', 6);
267
+ define ('AI_CHECK_PAGE_TYPE_FEED', 7);
268
+ define ('AI_CHECK_PAGE_TYPE_404', 8);
269
+
270
+ define ('AI_CHECK_DESKTOP_DEVICES', 9);
271
+ define ('AI_CHECK_MOBILE_DEVICES', 10);
272
+ define ('AI_CHECK_TABLET_DEVICES', 11);
273
+ define ('AI_CHECK_PHONE_DEVICES', 12);
274
+ define ('AI_CHECK_DESKTOP_TABLET_DEVICES',13);
275
+ define ('AI_CHECK_DESKTOP_PHONE_DEVICES', 14);
276
+
277
+ define ('AI_CHECK_CATEGORY', 15);
278
+ define ('AI_CHECK_TAG', 16);
279
+ define ('AI_CHECK_URL', 17);
280
+ define ('AI_CHECK_REFERER', 18);
281
+ define ('AI_CHECK_DATE', 19);
282
+ define ('AI_CHECK_CODE', 20);
283
+ define ('AI_CHECK_LOGGED_IN_USER', 21);
284
+ define ('AI_CHECK_NOT_LOGGED_IN_USER', 22);
285
+ define ('AI_CHECK_ADMINISTRATOR', 23);
286
+
287
+ define ('AI_CHECK_ENABLED_ON_ALL_EXCEPT_ON_SELECTED', 24);
288
+ define ('AI_CHECK_ENABLED_ONLY_ON_SELECTED', 25);
289
+ define ('AI_CHECK_DISABLED_MANUALLY', 26);
290
+ define ('AI_CHECK_MAX_INSERTIONS', 27);
291
+ define ('AI_CHECK_FILTER', 28);
292
+ define ('AI_CHECK_PARAGRAPH_COUNTING', 29);
293
+ define ('AI_CHECK_ENABLED', 30);
294
+ define ('AI_CHECK_PARAGRAPHS_MIN_NUMBER', 31);
295
+ define ('AI_CHECK_NUMBER_OF_WORDS', 32);
296
+ define ('AI_CHECK_DEBUG_NO_INSERTION', 33);
297
+ define ('AI_CHECK_PARAGRAPH_TAGS', 34);
298
+ define ('AI_CHECK_PARAGRAPHS_WITH_TAGS', 35);
299
+ define ('AI_CHECK_PARAGRAPHS_AFTER_BLOCKQUOTE', 36);
300
+ define ('AI_CHECK_PARAGRAPHS_AFTER_MIN_MAX_WORDS', 37);
301
+ define ('AI_CHECK_PARAGRAPHS_AFTER_TEXT', 38);
302
+ define ('AI_CHECK_PARAGRAPHS_AFTER_CLEARANCE', 39);
303
+ define ('AI_CHECK_ID', 40);
304
+ define ('AI_CHECK_URL_PARAMETER', 41);
305
+ define ('AI_CHECK_DO_NOT_INSERT', 42);
306
+ define ('AI_CHECK_AD_ABOVE', 43);
307
+ define ('AI_CHECK_AD_BELOW', 44);
308
+
309
+ define ('AI_PT_NONE', - 1);
310
+ define ('AI_PT_ANY', 0);
311
+ define ('AI_PT_STATIC', 1);
312
+ define ('AI_PT_POST', 2);
313
+ define ('AI_PT_HOMEPAGE', 3);
314
+ define ('AI_PT_CATEGORY', 4);
315
+ define ('AI_PT_ARCHIVE', 5);
316
+ define ('AI_PT_SEARCH', 6);
317
+ define ('AI_PT_404', 7);
318
+ define ('AI_PT_FEED', 8);
319
+ define ('AI_PT_ADMIN', 9);
320
+
321
+ define ('AI_USER_NOT_SET', - 1);
322
+ define ('AI_USER_NOT_LOGGED_IN', 0);
323
+ define ('AI_USER_LOGGED_IN', 1);
324
+ define ('AI_USER_ADMINISTRATOR', 2);
325
+
326
+ define ('AI_WP_PAGE_TYPE', 0);
327
+ define ('AI_WP_USER', 1);
328
+ define ('AI_WP_DEBUGGING', 2);
329
+ define ('AI_WP_DEBUG_BLOCK', 3);
330
+ define ('AI_WP_URL', 4);
331
+ define ('SERVER_SIDE_DETECTION', 5);
332
+ define ('CLIENT_SIDE_DETECTION', 6);
333
+ define ('AI_CONTEXT', 7);
334
+
335
+ define ('AI_CONTEXT_NONE', 0);
336
+ define ('AI_CONTEXT_CONTENT', 1);
337
+ define ('AI_CONTEXT_EXCERPT', 2);
338
+ define ('AI_CONTEXT_BEFORE_POST', 3);
339
+ define ('AI_CONTEXT_AFTER_POST', 4);
340
+ define ('AI_CONTEXT_WIDGET', 5);
341
+ define ('AI_CONTEXT_PHP_FUNCTION', 6);
342
+ define ('AI_CONTEXT_SHORTCODE', 7);
343
+ define ('AI_CONTEXT_HEADER', 8);
344
+ define ('AI_CONTEXT_FOOTER', 9);
345
+
346
+ define ('AI_URL_DEBUG', 'ai-debug');
347
+ define ('AI_URL_DEBUG_PROCESSING', 'ai-debug-processing');
348
+ define ('AI_URL_DEBUG_BLOCKS', 'ai-debug-blocks');
349
+ define ('AI_URL_DEBUG_USER', 'ai-debug-user');
350
+ define ('AI_URL_DEBUG_TAGS', 'ai-debug-tags');
351
+ define ('AI_URL_DEBUG_POSITIONS', 'ai-debug-positions');
352
+ define ('AI_URL_DEBUG_NO_INSERTION', 'ai-debug-no-insertion');
353
+ define ('AI_URL_DEBUG_PHP', 'ai-debug-php');
354
+
355
+ define ('AI_DEBUG_PROCESSING', 0x01);
356
+ define ('AI_DEBUG_BLOCKS', 0x02);
357
+ define ('AI_DEBUG_TAGS', 0x04);
358
+ define ('AI_DEBUG_POSITIONS', 0x08);
359
+ define ('AI_DEBUG_NO_INSERTION', 0x10);
360
+
361
+ define ('AI_DEBUG_TAGS_STYLE', 'font-weight: bold; color: white; padding: 2px;');
362
+ define ('AI_DEBUG_POSITIONS_STYLE', 'text-align: center; padding: 10px 0; font-weight: bold; border: 1px solid blue; color: blue; background: #eef;');
363
+ define ('AI_DEBUG_WIDGET_STYLE', 'margin: 0; padding: 0 5px; font-size: 10px; white-space: pre; overflow-x: auto; overflow-y: hidden;');
364
+
css/ad-inserter.css CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  .ui-widget {
2
  font-family: sans-serif,Arial,Verdana;
3
  font-size: 12px;
@@ -12,3 +16,136 @@
12
  border: 1px solid #ddd;
13
  border-radius: 4px;
14
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #blocked-warning {
2
+ display: none;
3
+ }
4
+
5
  .ui-widget {
6
  font-family: sans-serif,Arial,Verdana;
7
  font-size: 12px;
16
  border: 1px solid #ddd;
17
  border-radius: 4px;
18
  }
19
+
20
+ .ai-icon-gear {
21
+ width: 16px;
22
+ height: 16px;
23
+ background-image: url(images/icon-gear.png);
24
+ background-repeat: no-repeat;
25
+ }
26
+
27
+ .ai-icon-gear.on {
28
+ background-image: url(images/icon-gear-blue.png);
29
+ }
30
+
31
+ /*#editor-1 {*/
32
+ /* font-family: Courier, 'Courier New', monospace, tahoma;*/
33
+ /* font-family: tahoma;*/
34
+ /* font-size: 10px";*/
35
+ /*}*/
36
+
37
+ .nav-tab {
38
+ border-top-left-radius: 5px;
39
+ border-top-right-radius: 5px;
40
+ }
41
+ .nav-tab-active, .nav-tab-active:hover {
42
+ background: #fff;
43
+ }
44
+ .exceptions a {
45
+ text-decoration: none;
46
+ }
47
+ .exceptions th.page {
48
+ text-align: left;
49
+ }
50
+ .exceptions td.page {
51
+ padding-right: 20px;
52
+ }
53
+ .exceptions td.id {
54
+ padding-right: 10px;
55
+ text-align: right;
56
+ }
57
+ .exceptions th.block, .exceptions td.block {
58
+ text-align: center;
59
+ width: 20px;
60
+ }
61
+
62
+ .small-button .ui-button-text-only .ui-button-text {
63
+ padding: 0px;
64
+ }
65
+ .responsive-table td {
66
+ white-space: nowrap;
67
+ padding: 0;
68
+ }
69
+ .no-select {
70
+ -webkit-user-select: none; /* Chrome all / Safari all */
71
+ -moz-user-select: none; /* Firefox all */
72
+ -ms-user-select: none; /* IE 10+ */
73
+ user-select: none; /* Likely future */
74
+ }
75
+ .select {
76
+ -webkit-user-select: all; /* Chrome all / Safari all */
77
+ -moz-user-select: all; /* Firefox all */
78
+ -ms-user-select: all; /* IE 10+ */
79
+ user-select: all; /* Likely future */
80
+ }
81
+
82
+ .ui-dialog {
83
+ z-index: 10000 !important;
84
+ }
85
+ .ui-dialog .ui-dialog-titlebar-close {
86
+ outline-color: transparent;
87
+ }
88
+ .no-title .ui-dialog-titlebar {
89
+ display:none
90
+ }
91
+
92
+ .ai-form {
93
+ width: 735px;
94
+ }
95
+
96
+ #ai-settings {
97
+ margin-right: 24px;
98
+ }
99
+
100
+ #ai-tabs a {
101
+ width: 14px;
102
+ text-align: center;
103
+ }
104
+ #ai-tabs {
105
+ padding: .2em 0 0 .6em;
106
+ }
107
+
108
+
109
+ #ai-scroll-tabs {
110
+ height: 42px;
111
+ }
112
+
113
+ #header-buttons {
114
+ min-height: 26px;
115
+ margin: 10px 0;
116
+ float: right;
117
+ }
118
+
119
+ .max-input {
120
+ display: table;
121
+ width: 100%;
122
+ }
123
+
124
+ .simple-editor {
125
+ width: 733px;
126
+ min-width: 370px;
127
+ height: 386px;
128
+ }
129
+
130
+ @media (min-width: 783px) and (max-width: 828px) {
131
+ .auto-fold #wpcontent, .auto-fold #wpfooter {
132
+ margin-left: 20px;
133
+ }
134
+ }
135
+ @media (max-width: 782px) {
136
+ .auto-fold #wpcontent {
137
+ padding-left: 8px;
138
+ }
139
+ }
140
+
141
+ @media screen and (max-width: 782px){
142
+ #wpbody .small-select select {
143
+ height: 32px;
144
+ font-size: 14px;
145
+ }
146
+
147
+ #wpbody span.small-input-tags {
148
+ width: 22%;
149
+ }
150
+ }
151
+
css/devices.css DELETED
@@ -1,28 +0,0 @@
1
- /* Ad Inserter Device Classes */
2
-
3
- /* Desktop */
4
-
5
- .ai-desktop { display: inherit !important; }
6
- .ai-tablet { display: none !important; }
7
- .ai-phone { display: none !important; }
8
- .ai-desktop-tablet { }
9
- .ai-desktop-phone { }
10
- .ai-tablet-phone { display: none !important; }
11
-
12
- /* Tablet */
13
-
14
- @media (min-width: 768px) and (max-width: 979px) {
15
- .ai-desktop { display: none !important ; }
16
- .ai-tablet { display: inherit !important; }
17
- .ai-desktop-phone { display: none !important; }
18
- .ai-tablet-phone { display: inherit !important; }
19
- }
20
-
21
- /* Phone */
22
-
23
- @media (max-width: 767px) {
24
- .ai-desktop { display: none !important; }
25
- .ai-phone { display: inherit !important; }
26
- .ai-desktop-tablet { display: none !important; }
27
- .ai-tablet-phone { display: inherit !important; }
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/dummy.css ADDED
File without changes
css/images/icon-gear-blue.png ADDED
Binary file
css/images/icon-gear-red.png ADDED
Binary file
css/images/icon-gear.png ADDED
Binary file
css/jquery.ui.spinner.css ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery UI Spinner @VERSION
3
+ * http://jqueryui.com
4
+ *
5
+ * Copyright 2013 jQuery Foundation and other contributors
6
+ * Released under the MIT license.
7
+ * http://jquery.org/license
8
+ *
9
+ * http://api.jqueryui.com/spinner/#theming
10
+ */
11
+ .ui-spinner {
12
+ position: relative;
13
+ display: inline-block;
14
+ overflow: hidden;
15
+ padding: 0;
16
+ vertical-align: middle;
17
+ }
18
+ .ui-spinner-input {
19
+ border: none;
20
+ background: none;
21
+ color: inherit;
22
+ padding: 0;
23
+ margin: .2em 0;
24
+ vertical-align: middle;
25
+ margin-left: .4em;
26
+ margin-right: 22px;
27
+ }
28
+ .ui-spinner-right .ui-spinner-input {
29
+ margin: .2em 0;
30
+ margin-left: .4em;
31
+ margin-right: 22px;
32
+ }
33
+ .ui-spinner-left .ui-spinner-input {
34
+ margin: .2em 0;
35
+ margin-right: .4em;
36
+ margin-left: 22px;
37
+ text-align: right;
38
+ }
39
+ .ui-spinner-vertical .ui-spinner-input {
40
+ margin: 0 .2em;
41
+ margin-top: 12px;
42
+ margin-bottom: 12px;
43
+ text-align: center;
44
+ }
45
+ .ui-spinner-horizontal .ui-spinner-input {
46
+ margin: .2em 0;
47
+ margin-left: 12px;
48
+ margin-right: 12px;
49
+ text-align: center;
50
+ }
51
+ .ui-spinner-button {
52
+ font-size: .5em;
53
+ padding: 0;
54
+ margin: 0;
55
+ text-align: center;
56
+ position: absolute;
57
+ cursor: default;
58
+ display: block;
59
+ overflow: hidden;
60
+ }
61
+ .ui-spinner-right .ui-spinner-button {
62
+ width: 16px;
63
+ height: 50%;
64
+ right: 0;
65
+ }
66
+ .ui-spinner-left .ui-spinner-button {
67
+ width: 16px;
68
+ height: 50%;
69
+ left: 0;
70
+ }
71
+ .ui-spinner-vertical .ui-spinner-button {
72
+ width: 100%;
73
+ height: 10px;
74
+ left: 0;
75
+ }
76
+ .ui-spinner-horizontal .ui-spinner-button {
77
+ width: 10px;
78
+ height: 100%;
79
+ top: 0;
80
+ }
81
+ /* more specificity required here to overide default borders */
82
+ .ui-spinner a.ui-spinner-button {
83
+ border: none;
84
+ }
85
+ .ui-spinner .ui-icon {
86
+ position: absolute;
87
+ }
88
+ /* vertical centre icon */
89
+ .ui-spinner-right .ui-icon {
90
+ margin-top: -8px;
91
+ top: 50%;
92
+ left: 0;
93
+ }
94
+ /* vertical centre icon */
95
+ .ui-spinner-left .ui-icon {
96
+ margin-top: -8px;
97
+ top: 50%;
98
+ left: 0;
99
+ }
100
+ .ui-spinner-vertical .ui-icon {
101
+ margin-top: -3px;
102
+ margin-left: -7px;
103
+ top: 0;
104
+ left: 50%;
105
+ }
106
+ .ui-spinner-horizontal .ui-icon {
107
+ margin-top: -8.5px;
108
+ margin-left: -3px;
109
+ top: 50%;
110
+ left: 0;
111
+ }
112
+ .ui-spinner-up {
113
+ top: 0;
114
+ }
115
+ .ui-spinner-down {
116
+ bottom: 0;
117
+ }
118
+ .ui-spinner-horizontal .ui-spinner-up {
119
+ right: 0;
120
+ }
121
+ .ui-spinner-horizontal .ui-spinner-down {
122
+ left: 0;
123
+ }
124
+ /* TR overrides */
125
+ .ui-spinner .ui-icon-triangle-1-s {
126
+ /* need to fix icons sprite */
127
+ background-position: -65px -16px;
128
+ }
css/viewports.css DELETED
@@ -1,25 +0,0 @@
1
- /* Ad Inserter version 1.6.5 - viewport classes */
2
-
3
- /* DO NOT MODIFY - This file is automatically generated when you save Ad Inserter settings */
4
-
5
- /* Desktop */
6
-
7
- .ai-viewport-3 { display: none !important;}
8
- .ai-viewport-2 { display: none !important;}
9
- .ai-viewport-1 { display: inherit !important;}
10
- .ai-viewport-0 { display: none !important;}
11
-
12
- /* Tablet */
13
-
14
- @media (min-width: 768px) and (max-width: 979px) {
15
- .ai-viewport-1 { display: none !important;}
16
- .ai-viewport-2 { display: inherit !important;}
17
- }
18
-
19
- /* Phone */
20
-
21
- @media (max-width: 767px) {
22
- .ai-viewport-1 { display: none !important;}
23
- .ai-viewport-3 { display: inherit !important;}
24
- }
25
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
images/domain-monitor.png CHANGED
Binary file
images/monitors.png ADDED
Binary file
images/tiny-monitor.png DELETED
Binary file
images/tinymonitor-logo.png DELETED
Binary file
index.php CHANGED
@@ -21,10 +21,12 @@
21
  <div style="width: 800px; padding: 2px 8px 6px 8px; margin: 8px 30px 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
22
  <h1 style="text-align: center;">Ad Inserter</h1>
23
  <p>
24
- A simple solution to insert any code into Wordpress. Perfect for AdSense or contextual Amazon ads. Simply enter any HTML/Javascript/PHP code and select where and how you want to display it.
 
 
25
  </p>
26
  <div>
27
- <img style="display: block;margin: 0 auto;" src="screenshot-1.jpg" />
28
  </div>
29
  <p>
30
  Settings for one code block. Up to 16 blocks can be configured.
@@ -34,21 +36,21 @@
34
  <img style="display: block;margin: 0 auto;" src="screenshot-2.jpg" />
35
  </div>
36
  <p>
37
- Settings for header code
38
  </p>
39
  <hr />
40
  <div>
41
- <img style="display: block;margin: 0 auto;" src="screenshot-3.jpg" />
42
  </div>
43
  <p>
44
- Ad Inserter settings
45
  </p>
46
  <hr />
47
  <div>
48
- <img style="display: block;margin: 0 auto;" src="screenshot-4.jpg" width="800"/>
49
  </div>
50
  <p>
51
- Post / Page Ad Inserter Exceptions
52
  </p>
53
  </div>
54
  </div>
@@ -56,7 +58,7 @@
56
  <div style="float: left;">
57
  <div style="width: 800px; padding: 2px 8px 6px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
58
  <h1 style="text-align: center;">Tiny Monitor</h1>
59
- <h2 style="text-align: center;">Monitor Google AdSense and Amazon Associates earnings</h2>
60
  <p style="text-align: justify;">
61
  Tiny Monitor for
62
  <a href="http://tinymonitor.com/adsense-monitor-documentation" target="_blank" rel="nofollow">AdSense</a>,
@@ -69,13 +71,18 @@
69
  Tiny Monitor automatically downloads data from Google, Amazon or PayPal and presents it in a simple single-page form.
70
  This way you can have all the data easily accessible without the need to log into many websites just to check today's earnings.
71
  </p>
72
- <a href="http://tinymonitor.com/" target="_blank" rel="nofollow"><img style="display: block;margin: 0 auto;" src="images/tinymonitor-logo.png" alt="Tiny Monitor"></a>
73
- <a href="http://tinymonitor.com/" target="_blank" rel="nofollow"><img style="display: block;margin: 0 auto;" src="images/tiny-monitor.png" alt="Amazon Associates"></a>
74
  <p style="text-align: justify;">
75
  And if you have more than one domain then you can monitor them with <a href="http://tinymonitor.com/domain-monitor-documentation" target="_blank" rel="nofollow">Tiny Domain Monitor</a>.
76
  This PHP script is a simple yet effective solution to track expiration dates of your own domains or any other domains you would like to register as soon as they expire.
77
  </p>
78
  <a href="http://tinymonitor.com/domainmonitor/" target="_blank" rel="nofollow"><img style="display: block;margin: 0 auto;" src="images/domain-monitor.png" alt="Domain Monitor Script"></a>
 
 
 
 
 
 
79
  </div>
80
  </div>
81
  <body>
21
  <div style="width: 800px; padding: 2px 8px 6px 8px; margin: 8px 30px 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
22
  <h1 style="text-align: center;">Ad Inserter</h1>
23
  <p>
24
+ Insert any ad or HTML/Javascript/PHP code into Wordpress. Perfect for all kinds of ads. 16 code blocks, many display options and features.
25
+ Need more than 64 code blocks? <a href="http://tinymonitor.com/ad-inserter-pro" target="_blank" rel="nofollow">Ad Inserter Pro</a> supports
26
+ 64 blocks, 6 viewports, import/export settings and has additional multisite support.
27
  </p>
28
  <div>
29
+ <a href="http://tinymonitor.com/ad-inserter" target="_blank" rel="nofollow"><img style="display: block;margin: 0 auto;" src="screenshot-1.jpg" /></a>
30
  </div>
31
  <p>
32
  Settings for one code block. Up to 16 blocks can be configured.
36
  <img style="display: block;margin: 0 auto;" src="screenshot-2.jpg" />
37
  </div>
38
  <p>
39
+ Complete settings for one code block (Before Paragraph)
40
  </p>
41
  <hr />
42
  <div>
43
+ <img style="display: block;margin: 0 auto;" src="screenshot-12.jpg" />
44
  </div>
45
  <p>
46
+ Code preview with visual CSS editor
47
  </p>
48
  <hr />
49
  <div>
50
+ <img style="display: block;margin: 0 auto;" src="screenshot-13.jpg" width="800"/>
51
  </div>
52
  <p>
53
+ Code preview with visual CSS editor - highlighted code
54
  </p>
55
  </div>
56
  </div>
58
  <div style="float: left;">
59
  <div style="width: 800px; padding: 2px 8px 6px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
60
  <h1 style="text-align: center;">Tiny Monitor</h1>
61
+ <h2 style="text-align: center;">Monitor Google AdSense, Amazon Associates and PayPal earnings</h2>
62
  <p style="text-align: justify;">
63
  Tiny Monitor for
64
  <a href="http://tinymonitor.com/adsense-monitor-documentation" target="_blank" rel="nofollow">AdSense</a>,
71
  Tiny Monitor automatically downloads data from Google, Amazon or PayPal and presents it in a simple single-page form.
72
  This way you can have all the data easily accessible without the need to log into many websites just to check today's earnings.
73
  </p>
74
+ <a href="http://tinymonitor.com/" target="_blank" rel="nofollow"><img style="display: block;margin: 0 auto;" src="images/monitors.png" alt="Tiny Monitor"></a>
 
75
  <p style="text-align: justify;">
76
  And if you have more than one domain then you can monitor them with <a href="http://tinymonitor.com/domain-monitor-documentation" target="_blank" rel="nofollow">Tiny Domain Monitor</a>.
77
  This PHP script is a simple yet effective solution to track expiration dates of your own domains or any other domains you would like to register as soon as they expire.
78
  </p>
79
  <a href="http://tinymonitor.com/domainmonitor/" target="_blank" rel="nofollow"><img style="display: block;margin: 0 auto;" src="images/domain-monitor.png" alt="Domain Monitor Script"></a>
80
+ <div>
81
+ <p style="text-align: justify;"><a href="http://tinymonitor.com/domain-monitor" target="_blank" rel="nofollow">Tiny Domain Monitor</a> is a simple standalone PHP script for automatic
82
+ domain monitoring. It supports most top level domains including country domains. It can be used to monitor own domains and other registered domains in order to be
83
+ informed when they expire or become again available for registration. With the help of a cron job the domain data is automatically updated. Tiny Domain Monitor can
84
+ send an email when a domain data change occurs and it also generates RSS feed to track domain changes in any feed reader.</p>
85
+ </div>
86
  </div>
87
  </div>
88
  <body>
js/ad-inserter.js CHANGED
@@ -1,3 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  var shSettings = {
2
  "tab_size":"4",
3
  "use_soft_tabs":"1",
@@ -21,10 +34,10 @@ function SyntaxHighlight (id, block, settings) {
21
  this.valid = true;
22
  editDiv = jQuery('<div>', {
23
  position: 'absolute',
24
- // width: textarea.width(),
25
- width: 719,
26
- // height: textarea.height(),
27
- height: 384,
28
  'class': textarea.attr('class'),
29
  'id': 'editor-' + block
30
  }).insertBefore (textarea);
@@ -42,6 +55,11 @@ function SyntaxHighlight (id, block, settings) {
42
  if (!editor_disabled) {
43
  textarea.val (session.getValue());
44
  }
 
 
 
 
 
45
  });
46
 
47
  session.setMode ("ace/mode/html");
@@ -63,10 +81,111 @@ SyntaxHighlight.prototype.applySettings = function () {
63
  session.setUseSoftTabs(settings['use_soft_tabs'] == 1);
64
  };
65
 
 
 
 
 
66
  jQuery(document).ready(function($) {
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  var header = $('#ai-settings-' + 'header').length != 0;
69
  var header_id = 'name';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  function configure_editor_language (block) {
72
 
@@ -80,18 +199,27 @@ jQuery(document).ready(function($) {
80
  function process_display_elements (block) {
81
 
82
  $("#paragraph-settings-"+block).hide();
 
83
 
84
- var display_type = '';
85
- $("select#display-type-"+block+" option:selected").each(function() {
86
- display_type += $(this).text();
87
- });
 
88
 
89
  if (display_type == "Before Paragraph" || display_type == "After Paragraph") {
90
  $("#paragraph-settings-"+block).show();
 
 
 
 
 
 
 
91
  }
92
 
93
- $("#css-label-"+block).css('display', 'inline-block');
94
- $("#edit-css-button-"+block).css('display', 'inline-block');
95
 
96
  $("#css-none-"+block).hide();
97
  $("#custom-css-"+block).hide();
@@ -104,12 +232,10 @@ jQuery(document).ready(function($) {
104
 
105
  $("#no-wrapping-warning-"+block).hide();
106
 
107
- var alignment = '';
108
- $("select#block-alignment-"+block+" option:selected").each(function() {
109
- alignment += $(this).text();
110
- });
111
  if (alignment == "No Wrapping") {
112
- $("#css-no-wrapping-"+block).css('display', 'inline-block');
113
  $("#css-label-"+block).hide();
114
  $("#edit-css-button-"+block).hide();
115
  if ($("#client-side-detection-"+block).is(":checked")) {
@@ -117,177 +243,223 @@ jQuery(document).ready(function($) {
117
  }
118
  } else
119
  if (alignment == "None") {
120
- $("#css-none-"+block).css('display', 'inline-block');
121
  } else
122
  if (alignment == "Custom CSS") {
123
  $("#css-code-" + block).show();
124
  $("#custom-css-"+block).show();
125
  } else
126
  if (alignment == "Align Left") {
127
- $("#css-left-"+block).css('display', 'inline-block');
128
  } else
129
  if (alignment == "Align Right") {
130
- $("#css-right-"+block).css('display', 'inline-block');
131
  } else
132
  if (alignment == "Center") {
133
- $("#css-center-"+block).css('display', 'inline-block');
134
  } else
135
  if (alignment == "Float Left") {
136
- $("#css-float-left-"+block).css('display', 'inline-block');
137
  } else
138
  if (alignment == "Float Right") {
139
- $("#css-float-right-"+block).css('display', 'inline-block');
140
  }
141
 
142
- configure_editor_language (block);
 
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
 
145
  function configure_editor (block) {
146
- syntax_highlighter = new SyntaxHighlight ('#block-' + block, block, shSettings);
147
- syntax_highlighter.editor.setPrintMarginColumn (1000);
148
 
149
- if (!header && (block - 1) >> 4) {
150
- $('#block' + '-' + block).removeAttr(header_id);
151
- $('#display' + '-type-' + block).removeAttr(header_id);
152
- }
153
-
154
- if (!header && block >> 2) {
155
- $('#option' + '-name-' + block).removeAttr(header_id);
156
- $('#option' + '-length-' + block).removeAttr(header_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  }
158
 
159
- $('input#simple-editor-' + block).change (function () {
160
-
161
- block = $(this).attr ("id").replace ("simple-editor-","");
162
- var editor_disabled = $(this).is(":checked");
163
- var editor = ace.edit ("editor-" + block);
164
- var textarea = $("#block-" + block);
165
- var ace_editor = $("#editor-" + block);
166
 
167
- if (editor_disabled) {
168
- textarea.val (editor.session.getValue());
169
- textarea.css ('display', 'block');
170
- ace_editor.css ('display', 'none');
171
- } else {
172
- editor.session.setValue (textarea.val ())
173
- editor.renderer.updateFull();
174
- ace_editor.css ('display', 'block');
175
- textarea.css ('display', 'none');
176
- }
177
- });
178
  }
179
 
180
- var start = parseInt ($('#ai-form').attr('start'));
181
- var end = parseInt ($('#ai-form').attr('end'));
182
 
183
- for (block = start; block <= end; block ++) {
184
- configure_editor (block);
185
- }
186
 
187
- configure_editor ('h');
188
- configure_editor ('f');
189
 
190
- $('#ai-tab-container').tabs();
 
191
 
192
- $('#ai-tab-container a').css ("width", "14px").css ("text-align", "center");
193
- $('#ai-tabs').css ("padding", ".2em 0 0 .6em");
194
 
195
- var active_tab = parseInt ($("#ai-active-tab").attr ("value"));
196
- var tab_index = $('#ai-tab-container a[href="#tab-'+active_tab+'"]').parent().index();
197
- $("#ai-tab-container").tabs("option", "active", tab_index);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
 
199
- $('.ai-tab').click (function () {
200
- tab_block = $(this).attr ("id");
201
- tab_block = tab_block.replace ("ai-tab","");
202
- $("#ai-active-tab").attr ("value", tab_block);
203
 
204
- if (tab_block != 0) {
205
- var editor = ace.edit ("editor-" + tab_block);
206
- editor.getSession ().highlightLines (10000000);
207
- }
208
- });
209
 
210
- //hover states on the static widgets
211
- $('#dialog_link, ul#icons li').hover(
212
- function() {$(this).addClass ('ui-state-hover');},
213
- function() {$(this).removeClass ('ui-state-hover');}
214
- );
215
 
216
- $('#ai-settings').tooltip();
217
 
218
- $('#dummy-ranges').hide();
219
- $('#ai-ranges').show();
220
 
221
- $('#dummy-tabs').hide();
222
- $('#ai-tabs').show();
223
 
224
- $('#ai-settings input[type=submit], #ai-settings button').button().show ();
225
 
226
- for (ad_block = start; ad_block <= end; ad_block++) {
227
- $("select#display-type-"+ad_block).change (function() {
228
- block = $(this).attr('id').replace ("display-type-", "");
229
  process_display_elements (block);
230
  });
231
- $("select#block-alignment-"+ad_block).change (function() {
232
- block = $(this).attr('id').replace ("block-alignment-", "");
233
  process_display_elements (block);
234
  });
235
- $("input#process-php-"+ad_block).change (function() {
236
- block = $(this).attr('id').replace ("process-php-", "");
237
  process_display_elements (block);
238
  });
239
- $("#enable-shortcode-"+ad_block).change (function() {
240
- block = $(this).attr('id').replace ("enable-shortcode-", "");
241
  process_display_elements (block);
242
  });
243
- $("#enable-php-call-"+ad_block).change (function() {
244
- block = $(this).attr('id').replace ("enable-php-call-", "");
245
  process_display_elements (block);
246
  });
247
- $("select#display-for-devices-"+ad_block).change (function() {
248
- block = $(this).attr('id').replace ("display-for-devices-", "");
249
  process_display_elements (block);
250
  });
251
 
252
- $("#display-homepage-"+ad_block).change (function() {
253
- block = $(this).attr('id').replace ("display-homepage-", "");
 
 
 
 
254
  process_display_elements (block);
255
  });
256
- $("#display-category-"+ad_block).change (function() {
257
- block = $(this).attr('id').replace ("display-category-", "");
258
  process_display_elements (block);
259
  });
260
- $("#display-search-"+ad_block).change (function() {
261
- block = $(this).attr('id').replace ("display-search-", "");
262
  process_display_elements (block);
263
  });
264
- $("#display-archive-"+ad_block).change (function() {
265
- block = $(this).attr('id').replace ("display-archive-", "");
 
266
  process_display_elements (block);
267
  });
268
 
269
- $("#client-side-detection-"+ad_block).change (function() {
270
- block = $(this).attr('id').replace ("client-side-detection-", "");
271
  process_display_elements (block);
272
  });
273
 
274
- process_display_elements (ad_block);
275
 
276
- $("#widgets-button-"+ad_block).button ({
277
  }).click (function () {
278
  window.location.href = "widgets.php";
279
  });
280
 
281
- $("#show-css-button-"+ad_block).button ({
282
  }).show ().click (function () {
283
- block = $(this).attr ("id");
284
- block = block.replace ("show-css-button-","");
285
  $("#css-code-" + block).toggle ();
 
 
 
 
 
 
286
  });
287
 
288
- $("#edit-css-button-"+ad_block).button ({
 
 
 
 
 
 
 
 
 
 
 
 
289
  }).click (function () {
290
- block = $(this).attr('id').replace ("edit-css-button-", "");
291
 
292
  $("#css-left-"+block).hide();
293
  $("#css-right-"+block).hide();
@@ -295,113 +467,308 @@ jQuery(document).ready(function($) {
295
  $("#css-float-left-"+block).hide();
296
  $("#css-float-right-"+block).hide();
297
 
298
- var alignment = '';
299
- $("select#block-alignment-"+block+" option:selected").each(function() {
300
- alignment += $(this).text();
301
- });
302
  if (alignment == "None") {
303
  $("#css-none-"+block).hide();
304
  $("#custom-css-"+block).show().val ($("#css-none-"+block).text ());
305
- $("select#block-alignment-"+block+"").val ("Custom CSS").change();
306
  } else
307
  if (alignment == "Align Left") {
308
  $("#css-left-"+block).hide();
309
  $("#custom-css-"+block).show().val ($("#css-left-"+block).text ());
310
- $("select#block-alignment-"+block+"").val ("Custom CSS").change();
311
  } else
312
  if (alignment == "Align Right") {
313
  $("#css-right-"+block).hide();
314
  $("#custom-css-"+block).show().val ($("#css-right-"+block).text ());
315
- $("select#block-alignment-"+block+"").val ("Custom CSS").change();
316
  } else
317
  if (alignment == "Center") {
318
  $("#css-center-"+block).hide();
319
  $("#custom-css-"+block).show().val ($("#css-center-"+block).text ());
320
- $("select#block-alignment-"+block+"").val ("Custom CSS").change();
321
  } else
322
  if (alignment == "Float Left") {
323
  $("#css-float-left-"+block).hide();
324
  $("#custom-css-"+block).show().val ($("#css-float-left-"+block).text ());
325
- $("select#block-alignment-"+block+"").val ("Custom CSS").change();
326
  } else
327
  if (alignment == "Float Right") {
328
  $("#css-float-right-"+block).hide();
329
  $("#custom-css-"+block).show().val ($("#css-float-right-"+block).text ());
330
- $("select#block-alignment-"+block+"").val ("Custom CSS").change();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  }
 
 
 
 
 
 
 
332
  });
333
 
334
- $("#export-switch-"+ad_block).button ({
335
  icons: {
336
- primary: "ui-icon-gear",
337
  secondary: "ui-icon-triangle-1-s"
338
  },
339
  text: false
340
  }).show ().click (function () {
341
- block = $(this).attr ("id");
342
  block = block.replace ("export-switch-","");
343
  $("#export-container-" + block).toggle ();
 
 
 
 
 
 
 
 
344
  });
345
 
346
- $("#device-detection-button-"+ad_block).button ({
347
  }).show ().click (function () {
348
- block = $(this).attr ("id");
349
  block = block.replace ("device-detection-button-","");
350
  $("#device-detection-settings-" + block).toggle ();
351
  });
352
 
353
- $("#lists-button-"+ad_block).button ({
354
  }).show ().click (function () {
355
- block = $(this).attr ("id");
356
  block = block.replace ("lists-button-","");
357
  $("#list-settings-" + block).toggle ();
358
  });
359
 
360
- $("#manual-button-"+ad_block).button ({
361
  }).show ().click (function () {
362
- block = $(this).attr ("id");
363
  block = block.replace ("manual-button-","");
364
  $("#manual-settings-" + block).toggle ();
365
  });
366
 
367
- $("#misc-button-"+ad_block).button ({
368
  }).show ().click (function () {
369
- block = $(this).attr ("id");
370
  block = block.replace ("misc-button-","");
371
  $("#misc-settings-" + block).toggle ();
372
  });
373
 
374
- $("#preview-button-"+ad_block).button ({
375
  }).show ().click (function () {
376
- block = $(this).attr ("id");
377
  block = block.replace ("preview-button-","");
378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  var window_width = 820;
380
  var window_height = 820;
381
  var nonce = $(this).attr ('nonce');
382
- var page = "/wp-admin/admin-ajax.php?action=ai_preview&ai_code=" + block + "&ai_check=" + nonce;
383
- var window_left = (screen.width / 3) - (820 / 2);
384
  var window_top = (screen.height / 2) - (820 / 2);
385
- var preview_window = window.open (page, 'toswindow','width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no');
386
  });
387
  }
388
 
389
- $("#export-switch-0").button ({
390
- icons: {
391
- primary: "ui-icon-gear",
392
- secondary: "ui-icon-triangle-1-s"
393
- },
394
- text: false
395
- }).show ().click (function () {
396
- $("#export-container-0").toggle ();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  });
398
 
399
- $("input#process-php-h").change (function() {
400
- configure_editor_language ('h')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
  });
402
 
403
- $("input#process-php-f").change (function() {
404
- configure_editor_language ('f')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
405
  });
406
 
 
 
 
 
 
 
407
  });
1
+ var javascript_version = "2.0.0";
2
+ var ignore_key = true;
3
+ var start = 1;
4
+ var end = 16;
5
+ var active_tab = 1;
6
+ var tabs_to_configure = new Array();
7
+
8
+ var current_tab = 0;
9
+ var next_tab = 0;
10
+
11
+ var syntax_highlighting = false;
12
+ var settings_page = "";
13
+
14
  var shSettings = {
15
  "tab_size":"4",
16
  "use_soft_tabs":"1",
34
  this.valid = true;
35
  editDiv = jQuery('<div>', {
36
  position: 'absolute',
37
+ // width: textarea.width() + 14,
38
+ // width: 733,
39
+ // height: textarea.height() + 4,
40
+ // height: 384,
41
  'class': textarea.attr('class'),
42
  'id': 'editor-' + block
43
  }).insertBefore (textarea);
55
  if (!editor_disabled) {
56
  textarea.val (session.getValue());
57
  }
58
+ if (textarea.val () == "") {
59
+ textarea.removeAttr ("name");
60
+ }
61
+
62
+ jQuery("#ai-active-tab").attr ("value", active_tab);
63
  });
64
 
65
  session.setMode ("ace/mode/html");
81
  session.setUseSoftTabs(settings['use_soft_tabs'] == 1);
82
  };
83
 
84
+ function change_block_alignment (block) {
85
+ jQuery("select#block-alignment-" + block).change ();
86
+ }
87
+
88
  jQuery(document).ready(function($) {
89
 
90
+ shSettings ['theme'] = $('#data').attr ('theme');
91
+
92
+ var debug = parseInt ($('#data').attr ('javascript_debugging'));
93
+ var debug_title = false;
94
+
95
+ if (debug) {
96
+ var start_time = new Date().getTime();
97
+ var last_time = start_time;
98
+ debug_title = true;
99
+ }
100
+
101
+ syntax_highlighting = typeof shSettings ['theme'] != 'undefined' && shSettings ['theme'] != 'disabled';
102
+
103
  var header = $('#ai-settings-' + 'header').length != 0;
104
  var header_id = 'name';
105
+ var preview_top = (screen.height / 2) - (820 / 2);
106
+
107
+ function remove_default_values (block) {
108
+ $("#tab-" + block + " input:checkbox").each (function() {
109
+ var default_value = $(this).attr ("default");
110
+ var current_value = $(this).is (':checked');
111
+
112
+ if (typeof default_value != 'undefined') {
113
+ default_value = Boolean (parseInt (default_value));
114
+ // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
115
+
116
+ if (current_value == default_value) {
117
+ var name = $(this).attr ("name");
118
+ $(this).removeAttr ("name");
119
+ $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
120
+ // console.log ("REMOVED: ", name);
121
+ }
122
+ }
123
+ // else console.log ("NO DEFAULT VALUE:", $(this).attr ("name"));
124
+ });
125
+
126
+ $("#tab-" + block + " input:text").each (function() {
127
+ var default_value = $(this).attr ("default");
128
+ var current_value = $(this).val ();
129
+
130
+ if (typeof default_value != 'undefined') {
131
+ // console.log ($(this).attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
132
+
133
+ if (current_value == default_value) {
134
+ var name = $(this).attr ("name");
135
+ $(this).removeAttr ("name");
136
+ // console.log ("REMOVED: ", name);
137
+ }
138
+ }
139
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
140
+ });
141
+
142
+ $("#tab-" + block + " select").each (function() {
143
+ var default_value = $(this).attr ("default");
144
+ var current_value = $(this).children ("option:selected");
145
+
146
+ var childern = $(this).children ();
147
+ if (childern.prop ("tagName") == "OPTGROUP") {
148
+ var current_value = "";
149
+ childern.each (function() {
150
+ var selected = $(this).children ("option:selected");
151
+ if (selected.length != 0) {
152
+ current_value = selected;
153
+ return false;
154
+ }
155
+ });
156
+ }
157
+
158
+ if ($(this).attr ("selected-value") == 1) current_value = current_value.attr("value"); else current_value = current_value.text();
159
+
160
+ if (typeof default_value != 'undefined') {
161
+ // console.log ($(this).attr ("name"), ": default_value: ", default_value, ", current_value: ", current_value);
162
+
163
+ if (current_value == default_value) {
164
+ var name = $(this).attr ("name");
165
+ $(this).removeAttr ("name");
166
+ // console.log ("REMOVED: ", name);
167
+ }
168
+ }
169
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
170
+ });
171
+
172
+ $("#tab-" + block + " input:radio:checked").each (function() {
173
+ var default_value = $(this).attr ("default");
174
+ var current_value = $(this).is (':checked');
175
+
176
+ if (typeof default_value != 'undefined') {
177
+ default_value = Boolean (parseInt (default_value));
178
+ // console.log ($(this).attr ("name"), ": default_value: ", $(this).attr ("default"), " = ", default_value, ", current_value: ", current_value);
179
+
180
+ if (current_value == default_value) {
181
+ var name = $(this).attr ("name");
182
+ $("#tab-" + block + " [name='" + name + "']").removeAttr ("name");
183
+ // console.log ("REMOVED: ", name);
184
+ }
185
+ }
186
+ // else console.log ("NO DEFAULT VALUE: ", $(this).attr ("name"));
187
+ });
188
+ }
189
 
190
  function configure_editor_language (block) {
191
 
199
  function process_display_elements (block) {
200
 
201
  $("#paragraph-settings-"+block).hide();
202
+ $("#content-settings-"+block).hide();
203
 
204
+ // var display_type = '';
205
+ // $("select#display-type-"+block+" option:selected").each(function() {
206
+ // display_type += $(this).text();
207
+ // });
208
+ var display_type = $("select#display-type-"+block+" option:selected").text();
209
 
210
  if (display_type == "Before Paragraph" || display_type == "After Paragraph") {
211
  $("#paragraph-settings-"+block).show();
212
+ } else {
213
+ $("#paragraph-counting-"+block).hide();
214
+ $("#paragraph-clearance-"+block).hide();
215
+ }
216
+
217
+ if (display_type == "Before Paragraph" || display_type == "After Paragraph" || display_type == "Before Content" || display_type == "After Content") {
218
+ $("#content-settings-"+block).show();
219
  }
220
 
221
+ $("#css-label-"+block).css('display', 'table-cell');
222
+ $("#edit-css-button-"+block).css('display', 'table-cell');
223
 
224
  $("#css-none-"+block).hide();
225
  $("#custom-css-"+block).hide();
232
 
233
  $("#no-wrapping-warning-"+block).hide();
234
 
235
+ var alignment = $("select#block-alignment-"+block+" option:selected").text();
236
+
 
 
237
  if (alignment == "No Wrapping") {
238
+ $("#css-no-wrapping-"+block).css('display', 'table-cell');
239
  $("#css-label-"+block).hide();
240
  $("#edit-css-button-"+block).hide();
241
  if ($("#client-side-detection-"+block).is(":checked")) {
243
  }
244
  } else
245
  if (alignment == "None") {
246
+ $("#css-none-"+block).css('display', 'table-cell');
247
  } else
248
  if (alignment == "Custom CSS") {
249
  $("#css-code-" + block).show();
250
  $("#custom-css-"+block).show();
251
  } else
252
  if (alignment == "Align Left") {
253
+ $("#css-left-"+block).css('display', 'table-cell');
254
  } else
255
  if (alignment == "Align Right") {
256
+ $("#css-right-"+block).css('display', 'table-cell');
257
  } else
258
  if (alignment == "Center") {
259
+ $("#css-center-"+block).css('display', 'table-cell');
260
  } else
261
  if (alignment == "Float Left") {
262
+ $("#css-float-left-"+block).css('display', 'table-cell');
263
  } else
264
  if (alignment == "Float Right") {
265
+ $("#css-float-right-"+block).css('display', 'table-cell');
266
  }
267
 
268
+ if ($('#css-code-'+block).is(':visible')) {
269
+ $("#show-css-button-"+block+" span").text ("Hide CSS");
270
+ } else {
271
+ $("#show-css-button-"+block+" span").text ("Show CSS");
272
+ }
273
+
274
+ var avoid_action = $("select#avoid-action-"+block+" option:selected").text();
275
+
276
+ if (avoid_action == "do not insert")
277
+ $("#check-up-to-"+block).hide (); else
278
+ $("#check-up-to-"+block).show ();
279
+
280
+ if (syntax_highlighting) configure_editor_language (block);
281
  }
282
 
283
  function configure_editor (block) {
 
 
284
 
285
+ if (debug) console.log ("configure_editor: " + block);
286
+
287
+ if (syntax_highlighting) {
288
+ var syntax_highlighter = new SyntaxHighlight ('#block-' + block, block, shSettings);
289
+ syntax_highlighter.editor.setPrintMarginColumn (1000);
290
+
291
+ $('input#simple-editor-' + block).change (function () {
292
+
293
+ var block = $(this).attr ("id").replace ("simple-editor-","");
294
+ var editor_disabled = $(this).is(":checked");
295
+ var editor = ace.edit ("editor-" + block);
296
+ var textarea = $("#block-" + block);
297
+ var ace_editor = $("#editor-" + block);
298
+
299
+ if (editor_disabled) {
300
+ textarea.val (editor.session.getValue());
301
+ textarea.css ('display', 'block');
302
+ ace_editor.css ('display', 'none');
303
+ } else {
304
+ editor.session.setValue (textarea.val ())
305
+ editor.renderer.updateFull();
306
+ ace_editor.css ('display', 'block');
307
+ textarea.css ('display', 'none');
308
+ }
309
+ });
310
  }
311
 
312
+ if (block != 'h' && block != 'f' && !header) {
313
+ if ((block - 1) >> 4) {
314
+ $('#block' + '-' + block).removeAttr(header_id);
315
+ $('#display' + '-type-' + block).removeAttr(header_id);
316
+ }
 
 
317
 
318
+ if (block >> 2) {
319
+ $('#option' + '-name-' + block).removeAttr(header_id);
320
+ $('#option' + '-length-' + block).removeAttr(header_id);
321
+ }
322
+ }
 
 
 
 
 
 
323
  }
324
 
325
+ function configure_tab_0 () {
 
326
 
327
+ if (debug) console.log ("configure_tab_0");
328
+
329
+ $('#tab-0').addClass ('configured');
330
 
331
+ $('#tab-0 input[type=submit], #tab-0 button').button().show ();
 
332
 
333
+ configure_editor ('h');
334
+ configure_editor ('f');
335
 
336
+ $('#ai-plugin-settings-tab-container').tabs();
337
+ $('#ai-plugin-settings-tabs').show();
338
 
339
+ $("#export-switch-0").button ({
340
+ icons: {
341
+ primary: "ui-icon-gear",
342
+ secondary: "ui-icon-triangle-1-s"
343
+ },
344
+ text: false
345
+ }).show ().click (function () {
346
+ $("#export-container-0").toggle ();
347
+
348
+ if ($("#export-container-0").is(':visible') && !$(this).hasClass ("loaded")) {
349
+ var nonce = $(this).attr ('nonce');
350
+ $("#export_settings_0").load ("/wp-admin/admin-ajax.php?action=ai_preview&export=0&ai_check=" + nonce, function() {
351
+ $("#export_settings_0").attr ("name", "export_settings_0");
352
+ $("#export-switch-0").addClass ("loaded");
353
+ });
354
+ }
355
+ });
356
 
357
+ $("input#process-php-h").change (function() {
358
+ if (syntax_highlighting) configure_editor_language ('h');
359
+ });
 
360
 
361
+ $("input#process-php-f").change (function() {
362
+ if (syntax_highlighting) configure_editor_language ('f')
363
+ });
 
 
364
 
365
+ if (syntax_highlighting) configure_editor_language ('h');
366
+ if (syntax_highlighting) configure_editor_language ('f');
367
+ }
 
 
368
 
369
+ function configure_tab (tab) {
370
 
371
+ $('#tab-' + tab).addClass ('configured');
 
372
 
373
+ $('#tab-' + tab + ' input[type=submit], #tab-' + tab + ' button').button().show ();
 
374
 
375
+ configure_editor (tab);
376
 
377
+ $("select#display-type-"+tab).change (function() {
378
+ var block = $(this).attr('id').replace ("display-type-", "");
 
379
  process_display_elements (block);
380
  });
381
+ $("select#block-alignment-"+tab).change (function() {
382
+ var block = $(this).attr('id').replace ("block-alignment-", "");
383
  process_display_elements (block);
384
  });
385
+ $("input#process-php-"+tab).change (function() {
386
+ var block = $(this).attr('id').replace ("process-php-", "");
387
  process_display_elements (block);
388
  });
389
+ $("#enable-shortcode-"+tab).change (function() {
390
+ var block = $(this).attr('id').replace ("enable-shortcode-", "");
391
  process_display_elements (block);
392
  });
393
+ $("#enable-php-call-"+tab).change (function() {
394
+ var block = $(this).attr('id').replace ("enable-php-call-", "");
395
  process_display_elements (block);
396
  });
397
+ $("select#display-for-devices-"+tab).change (function() {
398
+ var block = $(this).attr('id').replace ("display-for-devices-", "");
399
  process_display_elements (block);
400
  });
401
 
402
+ $("#display-homepage-"+tab).change (function() {
403
+ var block = $(this).attr('id').replace ("display-homepage-", "");
404
+ process_display_elements (block);
405
+ });
406
+ $("#display-category-"+tab).change (function() {
407
+ var block = $(this).attr('id').replace ("display-category-", "");
408
  process_display_elements (block);
409
  });
410
+ $("#display-search-"+tab).change (function() {
411
+ var block = $(this).attr('id').replace ("display-search-", "");
412
  process_display_elements (block);
413
  });
414
+ $("#display-archive-"+tab).change (function() {
415
+ var block = $(this).attr('id').replace ("display-archive-", "");
416
  process_display_elements (block);
417
  });
418
+
419
+ $("#client-side-detection-"+tab).change (function() {
420
+ var block = $(this).attr('id').replace ("client-side-detection-", "");
421
  process_display_elements (block);
422
  });
423
 
424
+ $("select#avoid-action-"+tab).change (function() {
425
+ var block = $(this).attr('id').replace ("avoid-action-", "");
426
  process_display_elements (block);
427
  });
428
 
429
+ process_display_elements (tab);
430
 
431
+ $("#widgets-button-"+tab).button ({
432
  }).click (function () {
433
  window.location.href = "widgets.php";
434
  });
435
 
436
+ $("#show-css-button-"+tab).button ({
437
  }).show ().click (function () {
438
+ var block = $(this).attr ("id").replace ("show-css-button-","");
 
439
  $("#css-code-" + block).toggle ();
440
+
441
+ if ($('#css-code-'+block).is(':visible')) {
442
+ $("#show-css-button-"+block+" span").text ("Hide CSS");
443
+ } else {
444
+ $("#show-css-button-"+block+" span").text ("Show CSS");
445
+ }
446
  });
447
 
448
+ $("#counting-button-"+tab).button ({
449
+ }).show ().click (function () {
450
+ var block = $(this).attr ("id").replace ("counting-button-","");
451
+ $("#paragraph-counting-" + block).toggle ();
452
+ });
453
+
454
+ $("#clearance-button-"+tab).button ({
455
+ }).show ().click (function () {
456
+ var block = $(this).attr ("id").replace ("clearance-button-","");
457
+ $("#paragraph-clearance-" + block).toggle ();
458
+ });
459
+
460
+ $("#edit-css-button-"+tab).button ({
461
  }).click (function () {
462
+ var block = $(this).attr('id').replace ("edit-css-button-", "");
463
 
464
  $("#css-left-"+block).hide();
465
  $("#css-right-"+block).hide();
467
  $("#css-float-left-"+block).hide();
468
  $("#css-float-right-"+block).hide();
469
 
470
+ var alignment = $("select#block-alignment-"+block+" option:selected").text();
471
+
 
 
472
  if (alignment == "None") {
473
  $("#css-none-"+block).hide();
474
  $("#custom-css-"+block).show().val ($("#css-none-"+block).text ());
475
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
476
  } else
477
  if (alignment == "Align Left") {
478
  $("#css-left-"+block).hide();
479
  $("#custom-css-"+block).show().val ($("#css-left-"+block).text ());
480
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
481
  } else
482
  if (alignment == "Align Right") {
483
  $("#css-right-"+block).hide();
484
  $("#custom-css-"+block).show().val ($("#css-right-"+block).text ());
485
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
486
  } else
487
  if (alignment == "Center") {
488
  $("#css-center-"+block).hide();
489
  $("#custom-css-"+block).show().val ($("#css-center-"+block).text ());
490
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
491
  } else
492
  if (alignment == "Float Left") {
493
  $("#css-float-left-"+block).hide();
494
  $("#custom-css-"+block).show().val ($("#css-float-left-"+block).text ());
495
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
496
  } else
497
  if (alignment == "Float Right") {
498
  $("#css-float-right-"+block).hide();
499
  $("#custom-css-"+block).show().val ($("#css-float-right-"+block).text ());
500
+ $("select#block-alignment-"+block).val ("Custom CSS").change();
501
+ }
502
+ });
503
+
504
+ $("#name-label-"+tab).click (function () {
505
+ var block = $(this).attr('id').replace ("name-label-", "");
506
+ $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
507
+ $("#name-label-"+block).hide();
508
+ });
509
+
510
+ $("#name-label-container-"+tab).click (function () {
511
+ var block = $(this).attr('id').replace ("name-label-container-", "");
512
+ $("#name-edit-"+block).css('display', 'table-cell').val ($("#name-label-"+block).text ()).focus ();
513
+ $("#name-label-"+block).hide();
514
+ });
515
+
516
+ $("#name-edit-"+tab).on('keyup keypress', function (e) {
517
+ var keyCode = e.keyCode || e.which;
518
+ ignore_key = true;
519
+ if (keyCode == 27) {
520
+ var block = $(this).attr('id').replace ("name-edit-", "");
521
+ $("#name-label-"+block).show();
522
+ $("#name-edit-"+block).hide();
523
+ ignore_key = false;
524
+ } else if (keyCode == 13) {
525
+ var block = $(this).attr('id').replace ("name-edit-", "");
526
+ $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
527
+ $("#name-edit-"+block).hide();
528
+ ignore_key = false;
529
+ e.preventDefault();
530
+ return false;
531
  }
532
+ }).focusout (function() {
533
+ if (ignore_key) {
534
+ var block = $(this).attr('id').replace ("name-edit-", "");
535
+ $("#name-label-"+block).show().text ($("#name-edit-"+block).val ());
536
+ $("#name-edit-"+block).hide();
537
+ }
538
+ ignore_key = true;
539
  });
540
 
541
+ $("#export-switch-"+tab).button ({
542
  icons: {
 
543
  secondary: "ui-icon-triangle-1-s"
544
  },
545
  text: false
546
  }).show ().click (function () {
547
+ var block = $(this).attr ("id");
548
  block = block.replace ("export-switch-","");
549
  $("#export-container-" + block).toggle ();
550
+
551
+ if ($("#export-container-" + block).is(':visible') && !$(this).hasClass ("loaded")) {
552
+ var nonce = $(this).attr ('nonce');
553
+ $("#export_settings_" + block).load ("/wp-admin/admin-ajax.php?action=ai_preview&export=" + block + "&ai_check=" + nonce, function() {
554
+ $("#export_settings_" + block).attr ("name", "export_settings_" + block);
555
+ $("#export-switch-"+block).addClass ("loaded");
556
+ });
557
+ }
558
  });
559
 
560
+ $("#device-detection-button-"+tab).button ({
561
  }).show ().click (function () {
562
+ var block = $(this).attr ("id");
563
  block = block.replace ("device-detection-button-","");
564
  $("#device-detection-settings-" + block).toggle ();
565
  });
566
 
567
+ $("#lists-button-"+tab).button ({
568
  }).show ().click (function () {
569
+ var block = $(this).attr ("id");
570
  block = block.replace ("lists-button-","");
571
  $("#list-settings-" + block).toggle ();
572
  });
573
 
574
+ $("#manual-button-"+tab).button ({
575
  }).show ().click (function () {
576
+ var block = $(this).attr ("id");
577
  block = block.replace ("manual-button-","");
578
  $("#manual-settings-" + block).toggle ();
579
  });
580
 
581
+ $("#misc-button-"+tab).button ({
582
  }).show ().click (function () {
583
+ var block = $(this).attr ("id");
584
  block = block.replace ("misc-button-","");
585
  $("#misc-settings-" + block).toggle ();
586
  });
587
 
588
+ $("#preview-button-"+tab).button ({
589
  }).show ().click (function () {
590
+ var block = $(this).attr ("id");
591
  block = block.replace ("preview-button-","");
592
 
593
+ $(this).blur ();
594
+
595
+
596
+ var alignment = $("select#block-alignment-"+block+" option:selected").text();
597
+
598
+ var css = "";
599
+ if (alignment == "None") {
600
+ css = $("#css-none-"+block).text ();
601
+ } else
602
+ if (alignment == "Custom CSS") {
603
+ css = $("#custom-css-"+block).val();
604
+ } else
605
+ if (alignment == "Align Left") {
606
+ css = $("#css-left-"+block).text ();
607
+ } else
608
+ if (alignment == "Align Right") {
609
+ css = $("#css-right-"+block).text ();
610
+ } else
611
+ if (alignment == "Center") {
612
+ css = $("#css-center-"+block).text ();
613
+ } else
614
+ if (alignment == "Float Left") {
615
+ css = $("#css-float-left-"+block).text ();
616
+ } else
617
+ if (alignment == "Float Right") {
618
+ css = $("#css-float-right-"+block).text ();
619
+ }
620
+
621
+ var name = $("#name-label-"+block).text ();
622
+
623
  var window_width = 820;
624
  var window_height = 820;
625
  var nonce = $(this).attr ('nonce');
626
+ var page = "/wp-admin/admin-ajax.php?action=ai_preview&preview=" + block + "&ai_check=" + nonce + "&alignment=" + encodeURI (alignment) + "&css=" + encodeURI (css) + "&name=" + encodeURI (name);
627
+ var window_left = 120;
628
  var window_top = (screen.height / 2) - (820 / 2);
629
+ var preview_window = window.open (page, 'preview','width='+window_width+',height='+window_height+',top='+window_top+',left='+window_left+',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no');
630
  });
631
  }
632
 
633
+ function configure_hidden_tab () {
634
+ var current_tab;
635
+ var tab;
636
+
637
+ if (debug) console.log ("");
638
+ if (debug) {
639
+ var current_time_start = new Date().getTime();
640
+ console.log ("since last time: " + ((current_time_start - last_time) / 1000).toFixed (3));
641
+ }
642
+ if (debug) console.log ("configure_hidden_tab");
643
+ if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
644
+
645
+ do {
646
+ if (tabs_to_configure.length == 0) {
647
+ if (debug_title) $("#plugin_name").css ("color", "#000");
648
+ if (debug) console.log ("configure_hidden_tab: DONE");
649
+ return;
650
+ }
651
+ current_tab = tabs_to_configure.pop();
652
+ tab = $("#tab-" + current_tab);
653
+ } while (tab.hasClass ('configured'));
654
+
655
+ if (debug) console.log ("Configuring tab: " + current_tab);
656
+
657
+ if (current_tab != 0) configure_tab (current_tab); else configure_tab_0 ();
658
+
659
+ if (debug) {
660
+ var current_time = new Date().getTime();
661
+ console.log ("time: " + ((current_time - current_time_start) / 1000).toFixed (3));
662
+ console.log ("TIME: " + ((current_time - start_time) / 1000).toFixed (3));
663
+ last_time = current_time;
664
+ }
665
+
666
+ if (tabs_to_configure.length != 0) setTimeout (configure_hidden_tab, 10); else if (debug_title) $("#plugin_name").css ("color", "#000");
667
+ }
668
+
669
+
670
+
671
+ if (debug) console.log ("READY");
672
+ if (debug_title) $("#plugin_name").css ("color", "#f00");
673
+ if (debug) {
674
+ var current_time_ready = new Date().getTime();
675
+ console.log ("TIME: " + ((current_time_ready - start_time) / 1000).toFixed (3));
676
+ }
677
+
678
+ $("#blocked-warning.warning-enabled").removeClass ('warning-enabled');
679
+ $("#blocked-warning").hide ();
680
+
681
+ start = parseInt ($('#ai-form').attr('start'));
682
+ end = parseInt ($('#ai-form').attr('end'));
683
+ active_tab = parseInt ($("#ai-active-tab").attr ("value"));
684
+
685
+ if (debug) console.log ("active_tab: " + active_tab);
686
+
687
+ var tabs_array = new Array ();
688
+ if (active_tab != 0) tabs_array.push (0);
689
+ for (var tab = end; tab >= start; tab --) {
690
+ if (tab != active_tab) tabs_array.push (tab);
691
+ }
692
+ // Concate existing tabs_to_configure (if tab was clicked before page was loaded)
693
+ tabs_to_configure = tabs_array.concat (tabs_to_configure);
694
+
695
+ setTimeout (configure_hidden_tab, 700);
696
+
697
+ var plugin_version = $("script[src*='ad-inserter.js']").attr('src').split('=')[1];
698
+ if (javascript_version != plugin_version) {
699
+ $("#javascript-version").html ("&nbsp;javascript " + javascript_version);
700
+ $("#javascript-warning").show ();
701
+ }
702
+
703
+ var index = 16;
704
+ if (active_tab != 0) index = active_tab - start;
705
+ var block_tabs = $("#ai-tab-container").tabs ({active: index});
706
+
707
+ $('#ai-settings').tooltip({
708
+ show: {effect: "blind",
709
+ delay: 400,
710
+ duration: 100}
711
  });
712
 
713
+ if (debug_title) $("#plugin_name").css ("color", "#00f");
714
+
715
+ if (active_tab == 0) configure_tab_0 (); else configure_tab (active_tab);
716
+
717
+ $('#dummy-ranges').hide();
718
+ $('#ai-ranges').show();
719
+
720
+ $('#dummy-tabs').hide();
721
+ $('#ai-tabs').show();
722
+
723
+ $('.header button').button().show ();
724
+
725
+ $("#ai-form").submit (function (event) {
726
+ for (var tab = start; tab <= end; tab ++) {
727
+ remove_default_values (tab);
728
+ }
729
  });
730
 
731
+ if (syntax_highlighting) {
732
+ $('.ai-tab').click (function () {
733
+ tab_block = $(this).attr ("id");
734
+ tab_block = tab_block.replace ("ai-tab","");
735
+ active_tab = tab_block;
736
+
737
+ if (!$("#tab-" + tab_block).hasClass ('configured')) {
738
+ if (debug) console.log ("");
739
+ if (debug) console.log ("Empty tab: " + tab_block);
740
+ tabs_to_configure.push (tab_block);
741
+ setTimeout (configure_hidden_tab, 10);
742
+ if (debug) console.log ("tabs_to_configure: " + tabs_to_configure);
743
+ } else if (tab_block != 0) {
744
+ var editor = ace.edit ("editor-" + tab_block);
745
+ editor.getSession ().highlightLines (10000000);
746
+ }
747
+ });
748
+
749
+ $('.ai-plugin-tab').click (function () {
750
+ tab_block = $(this).attr ("id");
751
+ tab_block = tab_block.replace ("ai-","");
752
+
753
+ if (tab_block == 'h') {
754
+ var editor = ace.edit ("editor-h");
755
+ editor.getSession ().highlightLines (10000000);
756
+ } else
757
+ if (tab_block == 'f') {
758
+ editor = ace.edit ("editor-f");
759
+ editor.getSession ().highlightLines (10000000);
760
+ }
761
+ });
762
+ }
763
+
764
+ $('#plugin_name').dblclick (function () {
765
+ $("#system-debugging").toggle();
766
  });
767
 
768
+ if (debug) console.log ("");
769
+ if (debug) console.log ("READY END");
770
+ if (debug) {
771
+ var current_time = new Date().getTime();
772
+ console.log ("main time: " + ((current_time - current_time_ready) / 1000).toFixed (3));
773
+ }
774
  });
js/jquery.mousewheel.js ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery Mousewheel 3.1.13
3
+ *
4
+ * Copyright jQuery Foundation and other contributors
5
+ * Released under the MIT license
6
+ * http://jquery.org/license
7
+ */
8
+
9
+ (function (factory) {
10
+ if ( typeof define === 'function' && define.amd ) {
11
+ // AMD. Register as an anonymous module.
12
+ define(['jquery'], factory);
13
+ } else if (typeof exports === 'object') {
14
+ // Node/CommonJS style for Browserify
15
+ module.exports = factory;
16
+ } else {
17
+ // Browser globals
18
+ factory(jQuery);
19
+ }
20
+ }(function ($) {
21
+
22
+ var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],
23
+ toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
24
+ ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
25
+ slice = Array.prototype.slice,
26
+ nullLowestDeltaTimeout, lowestDelta;
27
+
28
+ if ( $.event.fixHooks ) {
29
+ for ( var i = toFix.length; i; ) {
30
+ $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
31
+ }
32
+ }
33
+
34
+ var special = $.event.special.mousewheel = {
35
+ version: '3.1.12',
36
+
37
+ setup: function() {
38
+ if ( this.addEventListener ) {
39
+ for ( var i = toBind.length; i; ) {
40
+ this.addEventListener( toBind[--i], handler, false );
41
+ }
42
+ } else {
43
+ this.onmousewheel = handler;
44
+ }
45
+ // Store the line height and page height for this particular element
46
+ $.data(this, 'mousewheel-line-height', special.getLineHeight(this));
47
+ $.data(this, 'mousewheel-page-height', special.getPageHeight(this));
48
+ },
49
+
50
+ teardown: function() {
51
+ if ( this.removeEventListener ) {
52
+ for ( var i = toBind.length; i; ) {
53
+ this.removeEventListener( toBind[--i], handler, false );
54
+ }
55
+ } else {
56
+ this.onmousewheel = null;
57
+ }
58
+ // Clean up the data we added to the element
59
+ $.removeData(this, 'mousewheel-line-height');
60
+ $.removeData(this, 'mousewheel-page-height');
61
+ },
62
+
63
+ getLineHeight: function(elem) {
64
+ var $elem = $(elem),
65
+ $parent = $elem['offsetParent' in $.fn ? 'offsetParent' : 'parent']();
66
+ if (!$parent.length) {
67
+ $parent = $('body');
68
+ }
69
+ return parseInt($parent.css('fontSize'), 10) || parseInt($elem.css('fontSize'), 10) || 16;
70
+ },
71
+
72
+ getPageHeight: function(elem) {
73
+ return $(elem).height();
74
+ },
75
+
76
+ settings: {
77
+ adjustOldDeltas: true, // see shouldAdjustOldDeltas() below
78
+ normalizeOffset: true // calls getBoundingClientRect for each event
79
+ }
80
+ };
81
+
82
+ $.fn.extend({
83
+ mousewheel: function(fn) {
84
+ return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');
85
+ },
86
+
87
+ unmousewheel: function(fn) {
88
+ return this.unbind('mousewheel', fn);
89
+ }
90
+ });
91
+
92
+
93
+ function handler(event) {
94
+ var orgEvent = event || window.event,
95
+ args = slice.call(arguments, 1),
96
+ delta = 0,
97
+ deltaX = 0,
98
+ deltaY = 0,
99
+ absDelta = 0,
100
+ offsetX = 0,
101
+ offsetY = 0;
102
+ event = $.event.fix(orgEvent);
103
+ event.type = 'mousewheel';
104
+
105
+ // Old school scrollwheel delta
106
+ if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
107
+ if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
108
+ if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
109
+ if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
110
+
111
+ // Firefox < 17 horizontal scrolling related to DOMMouseScroll event
112
+ if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
113
+ deltaX = deltaY * -1;
114
+ deltaY = 0;
115
+ }
116
+
117
+ // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
118
+ delta = deltaY === 0 ? deltaX : deltaY;
119
+
120
+ // New school wheel delta (wheel event)
121
+ if ( 'deltaY' in orgEvent ) {
122
+ deltaY = orgEvent.deltaY * -1;
123
+ delta = deltaY;
124
+ }
125
+ if ( 'deltaX' in orgEvent ) {
126
+ deltaX = orgEvent.deltaX;
127
+ if ( deltaY === 0 ) { delta = deltaX * -1; }
128
+ }
129
+
130
+ // No change actually happened, no reason to go any further
131
+ if ( deltaY === 0 && deltaX === 0 ) { return; }
132
+
133
+ // Need to convert lines and pages to pixels if we aren't already in pixels
134
+ // There are three delta modes:
135
+ // * deltaMode 0 is by pixels, nothing to do
136
+ // * deltaMode 1 is by lines
137
+ // * deltaMode 2 is by pages
138
+ if ( orgEvent.deltaMode === 1 ) {
139
+ var lineHeight = $.data(this, 'mousewheel-line-height');
140
+ delta *= lineHeight;
141
+ deltaY *= lineHeight;
142
+ deltaX *= lineHeight;
143
+ } else if ( orgEvent.deltaMode === 2 ) {
144
+ var pageHeight = $.data(this, 'mousewheel-page-height');
145
+ delta *= pageHeight;
146
+ deltaY *= pageHeight;
147
+ deltaX *= pageHeight;
148
+ }
149
+
150
+ // Store lowest absolute delta to normalize the delta values
151
+ absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
152
+
153
+ if ( !lowestDelta || absDelta < lowestDelta ) {
154
+ lowestDelta = absDelta;
155
+
156
+ // Adjust older deltas if necessary
157
+ if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
158
+ lowestDelta /= 40;
159
+ }
160
+ }
161
+
162
+ // Adjust older deltas if necessary
163
+ if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
164
+ // Divide all the things by 40!
165
+ delta /= 40;
166
+ deltaX /= 40;
167
+ deltaY /= 40;
168
+ }
169
+
170
+ // Get a whole, normalized value for the deltas
171
+ delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
172
+ deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
173
+ deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
174
+
175
+ // Normalise offsetX and offsetY properties
176
+ if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
177
+ var boundingRect = this.getBoundingClientRect();
178
+ offsetX = event.clientX - boundingRect.left;
179
+ offsetY = event.clientY - boundingRect.top;
180
+ }
181
+
182
+ // Add information to the event object
183
+ event.deltaX = deltaX;
184
+ event.deltaY = deltaY;
185
+ event.deltaFactor = lowestDelta;
186
+ event.offsetX = offsetX;
187
+ event.offsetY = offsetY;
188
+ // Go ahead and set deltaMode to 0 since we converted to pixels
189
+ // Although this is a little odd since we overwrite the deltaX/Y
190
+ // properties with normalized deltas.
191
+ event.deltaMode = 0;
192
+
193
+ // Add event and delta to the front of the arguments
194
+ args.unshift(event, delta, deltaX, deltaY);
195
+
196
+ // Clearout lowestDelta after sometime to better
197
+ // handle multiple device types that give different
198
+ // a different lowestDelta
199
+ // Ex: trackpad = 3 and mouse wheel = 120
200
+ if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
201
+ nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
202
+
203
+ return ($.event.dispatch || $.event.handle).apply(this, args);
204
+ }
205
+
206
+ function nullLowestDelta() {
207
+ lowestDelta = null;
208
+ }
209
+
210
+ function shouldAdjustOldDeltas(orgEvent, absDelta) {
211
+ // If this is an older event and the delta is divisable by 120,
212
+ // then we are assuming that the browser is treating this as an
213
+ // older mouse wheel event and that we should divide the deltas
214
+ // by 40 to try and get a more usable deltaFactor.
215
+ // Side note, this actually impacts the reported scroll distance
216
+ // in older browsers and can cause scrolling to be slower than native.
217
+ // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
218
+ return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
219
+ }
220
+
221
+ }));
js/jquery.mousewheel.min.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery Mousewheel 3.1.13
3
+ *
4
+ * Copyright 2015 jQuery Foundation and other contributors
5
+ * Released under the MIT license.
6
+ * http://jquery.org/license
7
+ */
8
+ !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a:a(jQuery)}(function(a){function b(b){var g=b||window.event,h=i.call(arguments,1),j=0,l=0,m=0,n=0,o=0,p=0;if(b=a.event.fix(g),b.type="mousewheel","detail"in g&&(m=-1*g.detail),"wheelDelta"in g&&(m=g.wheelDelta),"wheelDeltaY"in g&&(m=g.wheelDeltaY),"wheelDeltaX"in g&&(l=-1*g.wheelDeltaX),"axis"in g&&g.axis===g.HORIZONTAL_AXIS&&(l=-1*m,m=0),j=0===m?l:m,"deltaY"in g&&(m=-1*g.deltaY,j=m),"deltaX"in g&&(l=g.deltaX,0===m&&(j=-1*l)),0!==m||0!==l){if(1===g.deltaMode){var q=a.data(this,"mousewheel-line-height");j*=q,m*=q,l*=q}else if(2===g.deltaMode){var r=a.data(this,"mousewheel-page-height");j*=r,m*=r,l*=r}if(n=Math.max(Math.abs(m),Math.abs(l)),(!f||f>n)&&(f=n,d(g,n)&&(f/=40)),d(g,n)&&(j/=40,l/=40,m/=40),j=Math[j>=1?"floor":"ceil"](j/f),l=Math[l>=1?"floor":"ceil"](l/f),m=Math[m>=1?"floor":"ceil"](m/f),k.settings.normalizeOffset&&this.getBoundingClientRect){var s=this.getBoundingClientRect();o=b.clientX-s.left,p=b.clientY-s.top}return b.deltaX=l,b.deltaY=m,b.deltaFactor=f,b.offsetX=o,b.offsetY=p,b.deltaMode=0,h.unshift(b,j,l,m),e&&clearTimeout(e),e=setTimeout(c,200),(a.event.dispatch||a.event.handle).apply(this,h)}}function c(){f=null}function d(a,b){return k.settings.adjustOldDeltas&&"mousewheel"===a.type&&b%120===0}var e,f,g=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],h="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],i=Array.prototype.slice;if(a.event.fixHooks)for(var j=g.length;j;)a.event.fixHooks[g[--j]]=a.event.mouseHooks;var k=a.event.special.mousewheel={version:"3.1.12",setup:function(){if(this.addEventListener)for(var c=h.length;c;)this.addEventListener(h[--c],b,!1);else this.onmousewheel=b;a.data(this,"mousewheel-line-height",k.getLineHeight(this)),a.data(this,"mousewheel-page-height",k.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var c=h.length;c;)this.removeEventListener(h[--c],b,!1);else this.onmousewheel=null;a.removeData(this,"mousewheel-line-height"),a.removeData(this,"mousewheel-page-height")},getLineHeight:function(b){var c=a(b),d=c["offsetParent"in a.fn?"offsetParent":"parent"]();return d.length||(d=a("body")),parseInt(d.css("fontSize"),10)||parseInt(c.css("fontSize"),10)||16},getPageHeight:function(b){return a(b).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})});
js/jquery.ui.spinner.js ADDED
@@ -0,0 +1,534 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery UI Spinner @VERSION
3
+ * http://jqueryui.com
4
+ *
5
+ * Copyright 2013 jQuery Foundation and other contributors
6
+ * Released under the MIT license.
7
+ * http://jquery.org/license
8
+ *
9
+ * http://api.jqueryui.com/spinner/
10
+ *
11
+ * Depends:
12
+ * jquery.ui.core.js
13
+ * jquery.ui.widget.js
14
+ * jquery.ui.button.js
15
+ */
16
+ (function( $ ) {
17
+
18
+ function modifier( fn ) {
19
+ return function() {
20
+ var previous = this.element.val();
21
+ fn.apply( this, arguments );
22
+ this._refresh();
23
+ if ( previous !== this.element.val() ) {
24
+ this._trigger( "change" );
25
+ }
26
+ };
27
+ }
28
+
29
+ $.widget( "ui.spinner", {
30
+ version: "@VERSION",
31
+ defaultElement: "<input>",
32
+ widgetEventPrefix: "spin",
33
+ options: {
34
+ culture: null,
35
+ alignment: 'right',
36
+ icons: {
37
+ down: "ui-icon-triangle-1-s",
38
+ up: "ui-icon-triangle-1-n",
39
+ left: "ui-icon-triangle-1-w",
40
+ right: "ui-icon-triangle-1-e"
41
+ },
42
+ incremental: true,
43
+ max: null,
44
+ min: null,
45
+ numberFormat: null,
46
+ page: 10,
47
+ step: 1,
48
+
49
+ change: null,
50
+ spin: null,
51
+ start: null,
52
+ stop: null
53
+ },
54
+
55
+ _create: function() {
56
+ // handle string values that need to be parsed
57
+ this._setOption( "max", this.options.max );
58
+ this._setOption( "min", this.options.min );
59
+ this._setOption( "step", this.options.step );
60
+
61
+ // format the value, but don't constrain
62
+ this._value( this.element.val(), true );
63
+
64
+ this._draw();
65
+ this._on( this._events );
66
+ this._refresh();
67
+
68
+ // turning off autocomplete prevents the browser from remembering the
69
+ // value when navigating through history, so we re-enable autocomplete
70
+ // if the page is unloaded before the widget is destroyed. #7790
71
+ this._on( this.window, {
72
+ beforeunload: function() {
73
+ this.element.removeAttr( "autocomplete" );
74
+ }
75
+ });
76
+ },
77
+
78
+ _getCreateOptions: function() {
79
+ var options = {},
80
+ element = this.element;
81
+
82
+ $.each( [ "min", "max", "step" ], function( i, option ) {
83
+ var value = element.attr( option );
84
+ if ( value !== undefined && value.length ) {
85
+ options[ option ] = value;
86
+ }
87
+ });
88
+
89
+ return options;
90
+ },
91
+
92
+ _events: {
93
+ keydown: function( event ) {
94
+ if ( this._start( event ) && this._keydown( event ) ) {
95
+ event.preventDefault();
96
+ }
97
+ },
98
+ keyup: "_stop",
99
+ focus: function() {
100
+ this.previous = this.element.val();
101
+ },
102
+ blur: function( event ) {
103
+ if ( this.cancelBlur ) {
104
+ delete this.cancelBlur;
105
+ return;
106
+ }
107
+
108
+ this._stop();
109
+ this._refresh();
110
+ if ( this.previous !== this.element.val() ) {
111
+ this._trigger( "change", event );
112
+ }
113
+ },
114
+ mousewheel: function( event, delta ) {
115
+ if ( !delta ) {
116
+ return;
117
+ }
118
+ if ( !this.spinning && !this._start( event ) ) {
119
+ return false;
120
+ }
121
+
122
+ this._spin( (delta > 0 ? 1 : -1) * this.options.step, event );
123
+ clearTimeout( this.mousewheelTimer );
124
+ this.mousewheelTimer = this._delay(function() {
125
+ if ( this.spinning ) {
126
+ this._stop( event );
127
+ }
128
+ }, 100 );
129
+ event.preventDefault();
130
+ },
131
+ "mousedown .ui-spinner-button": function( event ) {
132
+ var previous;
133
+
134
+ // We never want the buttons to have focus; whenever the user is
135
+ // interacting with the spinner, the focus should be on the input.
136
+ // If the input is focused then this.previous is properly set from
137
+ // when the input first received focus. If the input is not focused
138
+ // then we need to set this.previous based on the value before spinning.
139
+ previous = this.element[0] === this.document[0].activeElement ?
140
+ this.previous : this.element.val();
141
+ function checkFocus() {
142
+ var isActive = this.element[0] === this.document[0].activeElement;
143
+ if ( !isActive ) {
144
+ this.element.focus();
145
+ this.previous = previous;
146
+ // support: IE
147
+ // IE sets focus asynchronously, so we need to check if focus
148
+ // moved off of the input because the user clicked on the button.
149
+ this._delay(function() {
150
+ this.previous = previous;
151
+ });
152
+ }
153
+ }
154
+
155
+ // ensure focus is on (or stays on) the text field
156
+ event.preventDefault();
157
+ checkFocus.call( this );
158
+
159
+ // support: IE
160
+ // IE doesn't prevent moving focus even with event.preventDefault()
161
+ // so we set a flag to know when we should ignore the blur event
162
+ // and check (again) if focus moved off of the input.
163
+ this.cancelBlur = true;
164
+ this._delay(function() {
165
+ delete this.cancelBlur;
166
+ checkFocus.call( this );
167
+ });
168
+
169
+ if ( this._start( event ) === false ) {
170
+ return;
171
+ }
172
+
173
+ this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event );
174
+ },
175
+ "mouseup .ui-spinner-button": "_stop",
176
+ "mouseenter .ui-spinner-button": function( event ) {
177
+ // button will add ui-state-active if mouse was down while mouseleave and kept down
178
+ if ( !$( event.currentTarget ).hasClass( "ui-state-active" ) ) {
179
+ return;
180
+ }
181
+
182
+ if ( this._start( event ) === false ) {
183
+ return false;
184
+ }
185
+ this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event );
186
+ },
187
+ // TODO: do we really want to consider this a stop?
188
+ // shouldn't we just stop the repeater and wait until mouseup before
189
+ // we trigger the stop event?
190
+ "mouseleave .ui-spinner-button": "_stop"
191
+ },
192
+
193
+ _draw: function() {
194
+ var uiSpinner = this.uiSpinner = this.element
195
+ .addClass( "ui-spinner-input" )
196
+ .attr( "autocomplete", "off" )
197
+ .wrap( this._uiSpinnerHtml() )
198
+ .parent()
199
+ .addClass( "ui-spinner-" + this.options.alignment )
200
+ // add buttons
201
+ .append( this._buttonHtml() );
202
+
203
+ this.element.attr( "role", "spinbutton" );
204
+
205
+ // button bindings
206
+ this.buttons = uiSpinner.find( ".ui-spinner-button" )
207
+ .attr( "tabIndex", -1 )
208
+ .button()
209
+ .removeClass( "ui-corner-all" );
210
+
211
+ // IE 6 doesn't understand height: 50% for the buttons
212
+ // unless the wrapper has an explicit height
213
+ if ( this.buttons.height() > Math.ceil( uiSpinner.height() * 0.5 ) &&
214
+ uiSpinner.height() > 0 ) {
215
+ uiSpinner.height( uiSpinner.height() );
216
+ }
217
+
218
+ // disable spinner if element was already disabled
219
+ if ( this.options.disabled ) {
220
+ this.disable();
221
+ }
222
+ },
223
+
224
+ _keydown: function( event ) {
225
+ var options = this.options,
226
+ keyCode = $.ui.keyCode;
227
+
228
+ switch ( event.keyCode ) {
229
+ case keyCode.UP:
230
+ this._repeat( null, 1, event );
231
+ return true;
232
+ case keyCode.DOWN:
233
+ this._repeat( null, -1, event );
234
+ return true;
235
+ case keyCode.PAGE_UP:
236
+ this._repeat( null, options.page, event );
237
+ return true;
238
+ case keyCode.PAGE_DOWN:
239
+ this._repeat( null, -options.page, event );
240
+ return true;
241
+ }
242
+
243
+ return false;
244
+ },
245
+
246
+ _uiSpinnerHtml: function() {
247
+ return "<span class='ui-spinner ui-widget ui-widget-content ui-corner-all'></span>";
248
+ },
249
+
250
+ _buttonHtml: function() {
251
+
252
+ switch (this.options.alignment) {
253
+ case 'right':
254
+ return "" +
255
+ "<a class='ui-spinner-button ui-spinner-up ui-corner-tr'>" +
256
+ "<span class='ui-icon " + this.options.icons.up + "'>&#9650;</span>" +
257
+ "</a>" +
258
+ "<a class='ui-spinner-button ui-spinner-down ui-corner-br'>" +
259
+ "<span class='ui-icon " + this.options.icons.down + "'>&#9660;</span>" +
260
+ "</a>";
261
+ case 'left':
262
+ return "" +
263
+ "<a class='ui-spinner-button ui-spinner-up ui-corner-tl'>" +
264
+ "<span class='ui-icon " + this.options.icons.up + "'>&#9650;</span>" +
265
+ "</a>" +
266
+ "<a class='ui-spinner-button ui-spinner-down ui-corner-bl'>" +
267
+ "<span class='ui-icon " + this.options.icons.down + "'>&#9660;</span>" +
268
+ "</a>";
269
+ case 'vertical':
270
+ return "" +
271
+ "<a class='ui-spinner-button ui-spinner-up ui-corner-top'>" +
272
+ "<span class='ui-icon " + this.options.icons.up + "'>&#9650;</span>" +
273
+ "</a>" +
274
+ "<a class='ui-spinner-button ui-spinner-down ui-corner-bottom'>" +
275
+ "<span class='ui-icon " + this.options.icons.down + "'>&#9660;</span>" +
276
+ "</a>";
277
+ case 'horizontal':
278
+ return "" +
279
+ "<a class='ui-spinner-button ui-spinner-up ui-corner-right'>" +
280
+ "<span class='ui-icon " + this.options.icons.right + "'>&#9658;</span>" +
281
+ "</a>" +
282
+ "<a class='ui-spinner-button ui-spinner-down ui-corner-left'>" +
283
+ "<span class='ui-icon " + this.options.icons.left + "'>&#9668;</span>" +
284
+ "</a>";
285
+ }
286
+ },
287
+
288
+ _start: function( event ) {
289
+ if ( !this.spinning && this._trigger( "start", event ) === false ) {
290
+ return false;
291
+ }
292
+
293
+ if ( !this.counter ) {
294
+ this.counter = 1;
295
+ }
296
+ this.spinning = true;
297
+ return true;
298
+ },
299
+
300
+ _repeat: function( i, steps, event ) {
301
+ i = i || 500;
302
+
303
+ clearTimeout( this.timer );
304
+ this.timer = this._delay(function() {
305
+ this._repeat( 40, steps, event );
306
+ }, i );
307
+
308
+ this._spin( steps * this.options.step, event );
309
+ },
310
+
311
+ _spin: function( step, event ) {
312
+ var value = this.value() || 0;
313
+
314
+ if ( !this.counter ) {
315
+ this.counter = 1;
316
+ }
317
+
318
+ value = this._adjustValue( value + step * this._increment( this.counter ) );
319
+
320
+ if ( !this.spinning || this._trigger( "spin", event, { value: value } ) !== false) {
321
+ this._value( value );
322
+ this.counter++;
323
+ }
324
+ },
325
+
326
+ _increment: function( i ) {
327
+ var incremental = this.options.incremental;
328
+
329
+ if ( incremental ) {
330
+ return $.isFunction( incremental ) ?
331
+ incremental( i ) :
332
+ Math.floor( i*i*i/50000 - i*i/500 + 17*i/200 + 1 );
333
+ }
334
+
335
+ return 1;
336
+ },
337
+
338
+ _precision: function() {
339
+ var precision = this._precisionOf( this.options.step );
340
+ if ( this.options.min !== null ) {
341
+ precision = Math.max( precision, this._precisionOf( this.options.min ) );
342
+ }
343
+ return precision;
344
+ },
345
+
346
+ _precisionOf: function( num ) {
347
+ var str = num.toString(),
348
+ decimal = str.indexOf( "." );
349
+ return decimal === -1 ? 0 : str.length - decimal - 1;
350
+ },
351
+
352
+ _adjustValue: function( value ) {
353
+ var base, aboveMin,
354
+ options = this.options;
355
+
356
+ // make sure we're at a valid step
357
+ // - find out where we are relative to the base (min or 0)
358
+ base = options.min !== null ? options.min : 0;
359
+ aboveMin = value - base;
360
+ // - round to the nearest step
361
+ aboveMin = Math.round(aboveMin / options.step) * options.step;
362
+ // - rounding is based on 0, so adjust back to our base
363
+ value = base + aboveMin;
364
+
365
+ // fix precision from bad JS floating point math
366
+ value = parseFloat( value.toFixed( this._precision() ) );
367
+
368
+ // clamp the value
369
+ if ( options.max !== null && value > options.max) {
370
+ return options.max;
371
+ }
372
+ if ( options.min !== null && value < options.min ) {
373
+ return options.min;
374
+ }
375
+
376
+ return value;
377
+ },
378
+
379
+ _stop: function( event ) {
380
+ if ( !this.spinning ) {
381
+ return;
382
+ }
383
+
384
+ clearTimeout( this.timer );
385
+ clearTimeout( this.mousewheelTimer );
386
+ this.counter = 0;
387
+ this.spinning = false;
388
+ this._trigger( "stop", event );
389
+ },
390
+
391
+ _setOption: function( key, value ) {
392
+ if ( key === "culture" || key === "numberFormat" ) {
393
+ var prevValue = this._parse( this.element.val() );
394
+ this.options[ key ] = value;
395
+ this.element.val( this._format( prevValue ) );
396
+ return;
397
+ }
398
+
399
+ if ( key === "max" || key === "min" || key === "step" ) {
400
+ if ( typeof value === "string" ) {
401
+ value = this._parse( value );
402
+ }
403
+ }
404
+ if ( key === "icons" ) {
405
+ if ( this.options.alignment == 'horizontal' ) {
406
+
407
+ this.buttons.first().find( ".ui-icon" )
408
+ .removeClass( this.options.icons.left )
409
+ .addClass( value.left );
410
+ this.buttons.last().find( ".ui-icon" )
411
+ .removeClass( this.options.icons.right )
412
+ .addClass( value.right );
413
+
414
+ } else {
415
+
416
+ this.buttons.first().find( ".ui-icon" )
417
+ .removeClass( this.options.icons.up )
418
+ .addClass( value.up );
419
+ this.buttons.last().find( ".ui-icon" )
420
+ .removeClass( this.options.icons.down )
421
+ .addClass( value.down );
422
+
423
+ }
424
+ }
425
+
426
+ this._super( key, value );
427
+
428
+ if ( key === "disabled" ) {
429
+ this.widget().toggleClass( "ui-state-disabled", !!value );
430
+ this.element.prop( "disabled", !!value );
431
+ this.buttons.button( value ? "disable" : "enable" );
432
+ }
433
+ },
434
+
435
+ _setOptions: modifier(function( options ) {
436
+ this._super( options );
437
+ this._value( this.element.val() );
438
+ }),
439
+
440
+ _parse: function( val ) {
441
+ if ( typeof val === "string" && val !== "" ) {
442
+ val = window.Globalize && this.options.numberFormat ?
443
+ Globalize.parseFloat( val, 10, this.options.culture ) : +val;
444
+ }
445
+ return val === "" || isNaN( val ) ? null : val;
446
+ },
447
+
448
+ _format: function( value ) {
449
+ if ( value === "" ) {
450
+ return "";
451
+ }
452
+ return window.Globalize && this.options.numberFormat ?
453
+ Globalize.format( value, this.options.numberFormat, this.options.culture ) :
454
+ value;
455
+ },
456
+
457
+ _refresh: function() {
458
+ this.element.attr({
459
+ "aria-valuemin": this.options.min,
460
+ "aria-valuemax": this.options.max,
461
+ // TODO: what should we do with values that can't be parsed?
462
+ "aria-valuenow": this._parse( this.element.val() )
463
+ });
464
+ },
465
+
466
+ // update the value without triggering change
467
+ _value: function( value, allowAny ) {
468
+ var parsed;
469
+ if ( value !== "" ) {
470
+ parsed = this._parse( value );
471
+ if ( parsed !== null ) {
472
+ if ( !allowAny ) {
473
+ parsed = this._adjustValue( parsed );
474
+ }
475
+ value = this._format( parsed );
476
+ }
477
+ }
478
+ this.element.val( value );
479
+ this._refresh();
480
+ },
481
+
482
+ _destroy: function() {
483
+ this.element
484
+ .removeClass( "ui-spinner-input" )
485
+ .prop( "disabled", false )
486
+ .removeAttr( "autocomplete" )
487
+ .removeAttr( "role" )
488
+ .removeAttr( "aria-valuemin" )
489
+ .removeAttr( "aria-valuemax" )
490
+ .removeAttr( "aria-valuenow" );
491
+ this.uiSpinner.replaceWith( this.element );
492
+ },
493
+
494
+ stepUp: modifier(function( steps ) {
495
+ this._stepUp( steps );
496
+ }),
497
+ _stepUp: function( steps ) {
498
+ if ( this._start() ) {
499
+ this._spin( (steps || 1) * this.options.step );
500
+ this._stop();
501
+ }
502
+ },
503
+
504
+ stepDown: modifier(function( steps ) {
505
+ this._stepDown( steps );
506
+ }),
507
+ _stepDown: function( steps ) {
508
+ if ( this._start() ) {
509
+ this._spin( (steps || 1) * -this.options.step );
510
+ this._stop();
511
+ }
512
+ },
513
+
514
+ pageUp: modifier(function( pages ) {
515
+ this._stepUp( (pages || 1) * this.options.page );
516
+ }),
517
+
518
+ pageDown: modifier(function( pages ) {
519
+ this._stepDown( (pages || 1) * this.options.page );
520
+ }),
521
+
522
+ value: function( newVal ) {
523
+ if ( !arguments.length ) {
524
+ return this._parse( this.element.val() );
525
+ }
526
+ modifier( this._value ).call( this, newVal );
527
+ },
528
+
529
+ widget: function() {
530
+ return this.uiSpinner;
531
+ }
532
+ });
533
+
534
+ }( jQuery ) );
preview.php CHANGED
@@ -4,316 +4,807 @@ function generate_code_preview ($block) {
4
 
5
  global $block_object;
6
 
7
- function margin_css ($style) {
8
- $style .= ";";
9
- $clean_style = "border-width: 0; ";
10
- if (preg_match_all ("/(margin|float)([^;]+)/", strtolower ($style).";", $css)) {
11
- $clean_style .= implode ("; ", $css [0]) .";";
12
- }
13
- $clean_style = str_replace (array ("margin", "auto"), array ("border-width", "0"), $clean_style);
14
- $clean_style = str_replace (array ("border-width-top", "border-width-right", "border-width-bottom", "border-width-left"),
15
- array ("border-top-width", "border-right-width", "border-bottom-width", "border-left-width"), $clean_style);
16
- return trim ($clean_style);
17
- }
18
-
19
- function no_margin_css ($style) {
20
- $clean_style = preg_replace ("/margin([^;]+;?)/", "", $style);
21
- return trim ($clean_style);
22
- }
23
-
24
-
25
-
26
- // $style = "padding-top: 15px; margin-bottom: 25px; margin-top: 10px;";
27
- // echo $style, "\n";
28
- // echo no_margin_css ($style), "\n";
29
-
30
  $obj = $block_object [$block];
31
 
 
 
 
 
 
 
32
  ?><html>
33
  <head>
34
- <title><?php echo AD_INSERTER_TITLE; ?> Code Preview</title>
 
 
35
  <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
36
  <script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'></script>
37
  <link rel='stylesheet' href='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'>
 
 
 
38
  <script>
 
 
 
39
  window.onkeydown = function( event ) {
40
  if (event.keyCode === 27 ) {
41
  window.close();
42
  }
43
  }
44
 
45
- jQuery(document).ready(function($) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- $("#highlight-button").button ({
48
- }).click (function () {
 
 
49
 
50
- // $('#margin').toggleClass ("highlighted");
51
- // $('#code-overlay-background').toggleClass ("highlighted");
52
- // $('#code-overlay').toggleClass ("highlighted");
53
- // $('#demo-box').toggle ();
 
 
 
 
54
 
55
- $('body').toggleClass ("highlighted");
56
- $('#demo-box').toggle ();
 
 
 
57
 
58
- if (!$('body').hasClass ("highlighted")) return;
59
 
60
- console.log ("highlighting");
 
61
 
62
 
63
- var code_overlay_left = 100000;
64
- var code_overlay_top = 100000;
65
- var code_overlay_right = 0;
66
- var code_overlay_bottom = 0;
 
 
67
 
68
- var code_overlay_width = 0;
69
- var code_overlay_height = 0;
 
 
 
 
 
70
 
71
- // var wrapper = $("#wrapper");
72
- // var wrapper_offset = {top: 0, left: 0};
73
- // var wrapper_margin_top = 0;
74
- // var wrapper_margin_left = 0;
75
- // var wrapper_border_top = 0;
76
- // var wrapper_border_left = 0;
77
- // if (wrapper.length) {
78
- // wrapper_offset = wrapper.offset ();
79
- // wrapper_margin_top = parseInt (wrapper.css ('marginTop'));
80
- // wrapper_margin_left = parseInt (wrapper.css ('marginLeft'));
81
- // wrapper_border_top = parseInt (wrapper.css ('borderTop'));
82
- // wrapper_border_left = parseInt (wrapper.css ('borderLeft'));
83
- // }
84
 
85
- var code_offset = $('#code').offset ();
86
 
87
- var code_left = code_offset.left;
88
- var code_top = code_offset.top;
89
- var code_width = $('#code').outerWidth (true);
90
- var code_height = $('#code').outerHeight (true);
91
 
 
 
 
92
 
93
- // console.log ("wrapper_offset: top: " + wrapper_offset.top + ", left: " + wrapper_offset.left);
94
- console.log ("code_left: " + code_left);
95
- console.log ("code_top: " + code_top);
96
- console.log ("code_width: " + code_width);
97
- console.log ("code_height: " + code_height);
98
 
99
- $('#code').children ().each (function () {
 
 
 
 
100
 
101
- var element_tag = $(this).prop("tagName").toLowerCase();
 
 
 
 
 
 
 
 
 
102
 
103
- if (element_tag != 'script') {
104
 
105
- var element_offset = $(this).offset ();
 
 
106
 
107
- console.log ("");
108
- console.log ("tag: " + $(this).prop("tagName"));
109
- console.log ("top: " + element_offset.top);
110
- console.log ("marginTop: " + $(this).css ('marginTop'));
111
- console.log ("left: " + element_offset.left);
112
- console.log ("marginLeft: " + $(this).css ('marginLeft'));
113
- console.log ("outerWidth: " + $(this).outerWidth (true));
114
- console.log ("outerHeight: " + $(this).outerHeight (true));
115
-
116
- var element_left = element_offset.left - parseInt ($(this).css ('marginLeft'));
117
- var element_width = $(this).outerWidth (true);
118
- var element_right = element_left + element_width;
119
-
120
- if (element_left < code_overlay_left) {
121
- code_overlay_left = element_left;
122
- }
123
 
124
- if (element_right > code_overlay_right) {
125
- code_overlay_right = element_right;
 
 
 
 
 
 
126
  }
 
 
 
 
 
 
 
 
 
127
 
128
- var element_top = element_offset.top - parseInt ($(this).css ('marginTop'));
129
- var element_height = $(this).outerHeight (true);
130
- var element_bottom = element_top + element_height;
131
 
132
- if (element_top < code_overlay_top) {
133
- code_overlay_top = element_top;
134
- }
135
 
136
- if (element_bottom > code_overlay_bottom) {
137
- code_overlay_bottom = element_bottom;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
139
 
140
- console.log ("==============");
141
- console.log ("code_overlay_top: " + code_overlay_top);
142
- console.log ("code_overlay_left: " + code_overlay_left);
143
- console.log ("code_overlay_right: " + code_overlay_right);
144
- console.log ("code_overlay_bottom: " + code_overlay_bottom);
 
 
145
  }
146
  });
 
 
147
 
148
- if (code_overlay_left < code_left) code_overlay_left = code_left;
149
- if (code_overlay_top < code_top) code_overlay_top = code_top;
 
 
 
150
 
151
- code_overlay_width = code_overlay_right - code_overlay_left;
152
- code_overlay_height = code_overlay_bottom - code_overlay_top;
 
 
153
 
154
- if (code_overlay_width > code_width) code_overlay_width = code_width;
155
- if (code_overlay_height > code_height) code_overlay_height = code_height;
 
 
156
 
157
- $('#code-overlay').offset ({top: code_overlay_top, left: code_overlay_left});
158
- $('#code-overlay').css ('width', code_overlay_width);
159
- $('#code-overlay').css ('height', code_overlay_height);
 
 
 
 
 
 
160
 
161
- console.log ("");
162
- console.log ("==============");
163
- console.log ('code-overlay: top: ' + $('#code-overlay').offset ().top + ", left: " + $('#code-overlay').offset ().left);
164
- console.log ("code_overlay_width: " + code_overlay_width);
165
- console.log ("code_overlay_height: " + code_overlay_height);
166
 
167
- // $('#code-overlay-background').offset ({top: code_overlay_top - wrapper_offset.top - wrapper_border_top - wrapper_margin_top, left: code_overlay_left - wrapper_offset.left - wrapper_border_left - wrapper_margin_left});
168
- $('#code-overlay-background').offset ({top: code_overlay_top, left: code_overlay_left});
169
- $('#code-overlay-background').css ('width', code_overlay_width);
170
- $('#code-overlay-background').css ('height', code_overlay_height);
171
 
172
- console.log ("");
173
- console.log ("--------------");
174
- console.log ("code-overlay-background: top: " + $('#code-overlay-background').offset ().top + ", left: " + $('#code-overlay-background').offset ().left);
175
- console.log ("code-overlay-background width: " + code_overlay_width);
176
- console.log ("code-overlay-background height: " + code_overlay_height);
177
- });
178
 
179
- });
 
 
180
 
181
- $(window).resize(function() {
182
- if ($('body').hasClass ("highlighted"))
183
- $("#highlight-button").click ();
184
  });
 
185
  </script>
186
  <style>
 
 
 
187
  .small-button .ui-button-text-only .ui-button-text {
188
  padding: 0;
189
  }
190
- #margin {
191
- z-index: 1;
192
- position: relative;
193
- border-style: solid;
194
- border-color: transparent;
195
  }
196
- .highlighted #margin {
197
- border-color: rgba(255, 145, 0, 0.5);
 
198
  }
199
- #wrapper {
200
- z-index: 1;
201
- position: relative;
 
 
 
 
202
  }
203
- .highlighted #wrapper {
204
- background: rgba(50, 220, 140, 0.5);
205
  }
206
- #code-overlay-background {
207
- z-index: 2;
208
  position: absolute;
209
- background: #fff;
210
  display: none;
211
  }
212
- .highlighted #code-overlay-background {
213
- display: inline-block;
 
214
  }
215
- #code {
216
- z-index: 3;
217
- display: inline-block;
218
- width: 100%;
219
  position: relative;
 
220
  }
221
- #code-overlay {
222
- z-index: 999999;
223
- display: inline-block;
224
  position: absolute;
 
 
 
 
 
 
 
 
 
 
 
 
225
  }
226
- .highlighted #code-overlay {
227
- /* background: rgba(255, 0, 0, 0.5);*/
228
  background: rgba(50, 140, 220, 0.5);
 
229
  }
230
- table#demo-box {
231
- width: 180px;
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  display: none;
233
  }
234
- #demo-box td {
235
- font-size: 10px;
 
236
  }
237
- td.demo-wrapper-margin {
238
- width: 100%;
239
- height: 12px;
240
  text-align: center;
 
 
 
 
 
 
 
241
  background: rgba(255, 145, 0, 0.5);
242
  }
 
 
 
 
 
 
 
243
  td.demo-code {
244
- width: 60%;
245
- height: 70px;
246
  text-align: center;
 
 
 
 
 
247
  background: rgba(50, 140, 220, 0.5);
248
  }
249
  td.demo-wrapper-background {
 
250
  text-align: center;
 
 
 
 
251
  background: rgba(50, 220, 140, 0.5);
252
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  </style>
254
- <?php echo ai_wp_head_hook (); ?>
 
255
  </head>
256
- <body style='font-family: arial; text-align: justify;'>
257
- <div style="float: right;">
258
- <button id="highlight-button" type="button" style="margin-left: 20px; font-size: 12px;" title="Highlight inserted code" >Highlight</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  </div>
260
- <div style="float: right;">
261
- <table id="demo-box" cellspacing=0 cellspacing="0">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  <tr>
263
- <td class="demo-wrapper-margin" colspan="2">wrapper margin</td>
 
 
 
 
 
264
  </tr>
265
- <td class="demo-code">Code block</td>
266
- <td class="demo-wrapper-background">wrapper background</td>
267
  <tr>
 
 
 
 
 
 
 
 
268
  </tr>
269
- <td class="demo-wrapper-margin" colspan="2">wrapper margin</td>
270
  <tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  </tr>
272
  </table>
273
  </div>
274
- <h1><?php echo AD_INSERTER_TITLE; ?> Code Preview</h1>
275
- <h2>Block <?php echo $block; ?></h2>
276
- <h3><?php echo $obj->get_ad_name(); ?></h3>
277
- <p>Need to install ads or widgets on Wordpress website? Ad Inserter is a simple yet powerful solution to insert any code into Wordpress.
278
- You can install it from Wordpress (Plugins / Add New / search for Ad Inserter). <strong>Perfect for AdSense or contextual Amazon ads</strong>.
279
- Simply enter any HTML/Javascript/PHP code and select where and how you want to display it.
280
- Ad Inserter supports up to 16 code blocks. Code block is any code (for example AdSense ad) that has to be inserted (displayed) at some position.
281
- Each code block can be configured to insert code at almost any position supported by Wordpress. It Features 16 code blocks; Syntax highlighting editor;
282
- Automatic positions: before/after post, content, paragraph or excerpt; Manual positions: widgets, shortcodes, PHP function call; Block alignment and style:
283
- left, center, right, float left, float right, custom CSS, no wrapping; PHP code processing: Server-side and client-side device detection (3 custom viewports);
284
- Black/White-list categories, tags, urls, referers.</p>
285
- <?php if ($obj->get_alignment_type() != AD_ALIGNMENT_NO_WRAPPING) : ?>
286
- <div id='margin' style='<?php echo margin_css ($obj->get_alignmet_style ()); ?>'>
287
- <div id='wrapper' style='<?php echo no_margin_css ($obj->get_alignmet_style (0)); ?>'>
288
- <div id='code-overlay-background'></div>
289
- <?php endif; ?>
290
- <span id='code'>
291
- <?php echo $obj->get_ad_data(); ?>
292
- </span>
293
- <?php if ($obj->get_alignment_type() != AD_ALIGNMENT_NO_WRAPPING) : ?>
294
- </div>
295
- <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  </div>
297
- <div id='code-overlay'></div>
298
- <p>Few very important things you need to know in order to insert code and display some ad:
299
- Enable and use at least one display option (Automatic Display, Widget, Shortcode, PHP function call)
300
- Enable display on at least one Wordpress page type (Posts, Static pages, Homepage, Category pages, Search Pages, Archive pages)
301
- For Posts and static pages select default value On all Posts / On all Static pages unless you really know what are you doing
302
- Each code block has 4 independent display options: Automatic Display, Widget, Shortcode and PHP function call.
303
- To display code block (ad) at some position you need to enable and use at least one display option.
304
- For single posts or static pages display position Before Post usually means position above the post/page title, for blog pages Before Post position means position above all the posts on the blog page.
305
- For single posts or static pages display position After Post means position below the post/page after all the content, for blog pages After Post position means position below all the posts on the blog page.
306
- <a href='http://tinymonitor.com/ad-inserter-pro' style='text-decoration: none;' target='_blank'><strong>Ad Inserter Pro</strong></a> is an upgraded version of the freely available Ad Inserter.
307
- In addition to all the features in the free version it offers 64 code blocks, 6 custom viewports, export and import of settings and support via email.
308
- For a complete description of features, screenshots and FAQ please check Ad Inserter page.
309
- If you are using free Ad Inserter simply uninstall it. The Pro version will automatically import existing settings from the free version.
310
- After you receive the email with download link for the Ad Inserter Pro plugin, download it, go to Wordpress Plugins, Add New, Upload Plugin,
311
- Choose file, click on Install Now, activate it and then click 'Enter License Key' and enter license key you got in the email.</p>
312
- <?php echo ai_wp_footer_hook (); ?>
313
  </body>
314
  </html>
315
  <?php
316
-
317
  }
318
 
319
-
4
 
5
  global $block_object;
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  $obj = $block_object [$block];
8
 
9
+ $block_name = isset ($_GET ["name"]) ? $_GET ["name"] : $obj->get_ad_name();
10
+ $custom_css = $obj->get_custom_css();
11
+ $alignment_type = isset ($_GET ["alignment"]) ? $_GET ["alignment"] : $obj->get_alignment_type();
12
+ $wrapper_css = isset ($_GET ["css"]) ? $_GET ["css"] : $obj->get_alignmet_style ();
13
+ $block_code = $obj->ai_getProcessedCode (true);
14
+
15
  ?><html>
16
  <head>
17
+ <title><?php echo AD_INSERTER_NAME; ?> Code Preview</title>
18
+ <meta name="viewport" content="width=device-width,initial-scale=1.0">
19
+ <link rel='stylesheet' href='/wp-content/plugins/ad-inserter/css/ad-inserter.css'>
20
  <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
21
  <script src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js'></script>
22
  <link rel='stylesheet' href='https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css'>
23
+ <script src='/wp-content/plugins/ad-inserter/js/jquery.mousewheel.min.js'></script>
24
+ <script src='/wp-content/plugins/ad-inserter/js/jquery.ui.spinner.js'></script>
25
+ <link rel='stylesheet' href='/wp-content/plugins/ad-inserter/css/jquery.ui.spinner.css'>
26
  <script>
27
+
28
+ // initialize_preview ();
29
+
30
  window.onkeydown = function( event ) {
31
  if (event.keyCode === 27 ) {
32
  window.close();
33
  }
34
  }
35
 
36
+ function initialize_preview () {
37
+
38
+ var debug = <?php echo get_javascript_debugging () ? 'true' : 'false'; ?>;
39
+ var block = <?php echo $block; ?>;
40
+ var code_blocks;
41
+ var spinning = false;
42
+
43
+ var wrapper = $('#wrapper');
44
+ var wrapping = $("#wrapper").attr ("style") != "";
45
+
46
+ var spinner_margin_top;
47
+ var spinner_margin_bottom;
48
+ var spinner_margin_left;
49
+ var spinner_margin_right;
50
+ var spinner_padding_top;
51
+ var spinner_padding_bottom;
52
+ var spinner_padding_left;
53
+ var spinner_padding_right;
54
+
55
+ function update_highlighting () {
56
+ if ($('body').hasClass ("highlighted")) {
57
+ $("#highlight-button").click ();
58
+ $("#highlight-button").click ();
59
+ }
60
+ }
61
 
62
+ function update_width () {
63
+ $("#screen-width").text (window.innerWidth + " px");
64
+ if (window.innerWidth != $(window).width()) $("#right-arrow").hide (); else $("#right-arrow").show ();
65
+ }
66
 
67
+ function update_wrapper_size () {
68
+ if (typeof wrapper.width () != 'undefined' && typeof wrapper.height () != 'undefined') {
69
+ var width = parseInt (wrapper.width ());
70
+ var height = parseInt (wrapper.height ());
71
+ $(".wrapper-size").html (width + "px &nbsp;&times;&nbsp; " + height + "px").show ();
72
+ if (width * height != 0) $(".wrapper-size").css ("color", "#333"); else $(".wrapper-size").css ("color", "#c00");
73
+ }
74
+ }
75
 
76
+ $(window).resize(function() {
77
+ update_highlighting ();
78
+ update_width ();
79
+ update_wrapper_size ();
80
+ });
81
 
82
+ function load_from_settings () {
83
 
84
+ if (window.opener != null && !window.opener.closed) {
85
+ var settings = $(window.opener.document).contents();
86
 
87
 
88
+ // // Replace document.write for old code that uses document.write
89
+ // // Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
90
+ // var oldDocumentWrite = document.write;
91
+ // document.write = function(node){
92
+ // $("#wrapper").append (node)
93
+ // }
94
 
95
+ // var simple_editor_switch = settings.find ('input#simple-editor-' + block);
96
+ // if (!simple_editor_switch.is(":checked")) {
97
+ // settings.find ('input#simple-editor-' + block).click ();
98
+ // settings.find ('input#simple-editor-' + block).click ();
99
+ // }
100
+ // var code = settings.find ("#block-" + block).val();
101
+ // wrapper.html (code);
102
 
103
+ // // Restore document.write
104
+ // setTimeout (function() {
105
+ // document.write = oldDocumentWrite
106
+ // }, 1000);
 
 
 
 
 
 
 
 
 
107
 
 
108
 
109
+ $("select#block-alignment").val (settings.find ("select#block-alignment-" + block + " option:selected").text()).change();
110
+ $("#custom-css").val (settings.find ("#custom-css-" + block).val ());
111
+ $("#block-name").text (settings.find ("#name-label-" + block).text ());
 
112
 
113
+ process_display_elements ();
114
+ }
115
+ }
116
 
117
+ function apply_to_settings () {
118
+ if (window.opener != null && !window.opener.closed) {
119
+ var settings = $(window.opener.document).contents ();
 
 
120
 
121
+ settings.find ("select#block-alignment-" + block).val ($("select#block-alignment option:selected").text()).change ();
122
+ settings.find ("#custom-css-" + block).val ($("#custom-css").val ());
123
+ window.opener.change_block_alignment (block);
124
+ }
125
+ }
126
 
127
+ function update_focused_spinner (event) {
128
+ if (spinner_margin_top.is (":focus")) spinner_margin_top.spinner( "stepUp", event.deltaY); else
129
+ if (spinner_margin_bottom.is (":focus")) spinner_margin_bottom.spinner( "stepUp", event.deltaY); else
130
+ if (spinner_margin_left.is (":focus")) spinner_margin_left.spinner( "stepUp", event.deltaY); else
131
+ if (spinner_margin_right.is (":focus")) spinner_margin_right.spinner( "stepUp", event.deltaY); else
132
+ if (spinner_padding_top.is (":focus")) spinner_padding_top.spinner( "stepUp", event.deltaY); else
133
+ if (spinner_padding_bottom.is (":focus")) spinner_padding_bottom.spinner( "stepUp", event.deltaY); else
134
+ if (spinner_padding_left.is (":focus")) spinner_padding_left.spinner( "stepUp", event.deltaY); else
135
+ if (spinner_padding_right.is (":focus")) spinner_padding_right.spinner( "stepUp", event.deltaY);
136
+ }
137
 
 
138
 
139
+ $(window).on ('mousewheel', function (event) {
140
+ if (!spinning) update_focused_spinner (event);
141
+ });
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
+ function create_spinner (selector, css_parameter, alignment) {
145
+ var spinner_element = $(selector).spinner ({
146
+ alignment: alignment,
147
+ start: function (event, ui) {
148
+ spinning = true;
149
+ if (!$(this).is (":focus")) {
150
+ update_focused_spinner (event)
151
+ event.preventDefault();
152
  }
153
+ },
154
+ stop: function (event, ui) {
155
+ spinning = false;
156
+ wrapper.css (css_parameter, $(this).spinner ("value") + "px");
157
+ update_custom_css ();
158
+ update_highlighting ();
159
+ update_wrapper_size ();
160
+ }
161
+ }).spinner ("option", "mouseWheel", true).spinner ("option", "min", 0).spinner ("option", "max", 200).spinner ("value", parseInt (wrapper.css (css_parameter))).show ();
162
 
163
+ return spinner_element;
164
+ }
 
165
 
 
 
 
166
 
167
+ function process_display_elements () {
168
+
169
+ var style = "";
170
+ $("#css-label").css('display', 'inline-block');
171
+ $("#edit-css-button").css('display', 'inline-block');
172
+
173
+ $("#css-none").hide();
174
+ $("#custom-css").hide();
175
+ $("#css-left").hide();
176
+ $("#css-right").hide();
177
+ $("#css-center").hide();
178
+ $("#css-float-left").hide();
179
+ $("#css-float-right").hide();
180
+ $("#css-no-wrapping").hide();
181
+
182
+ $("#demo-box").show ();
183
+ $("#demo-box-no-wrapping").hide ();
184
+ wrapping = true;
185
+
186
+ var alignment = $("select#block-alignment option:selected").text();
187
+
188
+ if (alignment == "No Wrapping") {
189
+ $("#css-no-wrapping").css('display', 'inline-block');
190
+ $("#css-label").hide();
191
+ $("#edit-css-button").hide();
192
+
193
+ wrapping = false;
194
+ style = "";
195
+
196
+ $("#demo-box").hide ();
197
+ $("#demo-box-no-wrapping").show ();
198
+
199
+ } else
200
+ if (alignment == "None") {
201
+ $("#css-none").css('display', 'inline-block');
202
+ style = $("#css-none").text ();
203
+ } else
204
+ if (alignment == "Custom CSS") {
205
+ $("#css-code").show();
206
+ $("#custom-css").show();
207
+ style = $("#custom-css").val ();
208
+ } else
209
+ if (alignment == "Align Left") {
210
+ $("#css-left").css('display', 'inline-block');
211
+ style = $("#css-left").text ();
212
+ } else
213
+ if (alignment == "Align Right") {
214
+ $("#css-right").css('display', 'inline-block');
215
+ style = $("#css-right").text ();
216
+ } else
217
+ if (alignment == "Center") {
218
+ $("#css-center").css('display', 'inline-block');
219
+ style = $("#css-center").text ();
220
+ } else
221
+ if (alignment == "Float Left") {
222
+ $("#css-float-left").css('display', 'inline-block');
223
+ style = $("#css-float-left").text ();
224
+ } else
225
+ if (alignment == "Float Right") {
226
+ $("#css-float-right").css('display', 'inline-block');
227
+ style = $("#css-float-right").text ();
228
+ }
229
+
230
+ $("#wrapper").attr ("style", style);
231
+ if (wrapping) update_margin_padding ();
232
+ update_highlighting ();
233
+ update_wrapper_size ();
234
+ }
235
+
236
+ function update_custom_css () {
237
+ $("#custom-css").val ($("#wrapper").attr ("style"));
238
+ $("select#block-alignment").val ("Custom CSS").change();
239
+ $("#edit-css-button").click ();
240
+ }
241
+
242
+ function update_margin_padding () {
243
+ if (wrapping) {
244
+ spinner_margin_top.spinner ("value", parseInt (wrapper.css ("margin-top")));
245
+ spinner_margin_bottom.spinner ("value", parseInt (wrapper.css ("margin-bottom")));
246
+ spinner_margin_left.spinner ("value", parseInt (wrapper.css ("margin-left")));
247
+ spinner_margin_right.spinner ("value", parseInt (wrapper.css ("margin-right")));
248
+ spinner_padding_top.spinner ("value", parseInt (wrapper.css ("padding-top")));
249
+ spinner_padding_bottom.spinner ("value", parseInt (wrapper.css ("padding-bottom")));
250
+ spinner_padding_left.spinner ("value", parseInt (wrapper.css ("padding-left")));
251
+ spinner_padding_right.spinner ("value", parseInt (wrapper.css ("padding-right")));
252
+ }
253
+ }
254
+
255
+ var start_time = new Date().getTime();
256
+
257
+ spinner_margin_top = create_spinner ("#spinner-margin-top", "margin-top", "horizontal").spinner ("option", "min", - $("#p1").outerHeight (true));
258
+ spinner_margin_bottom = create_spinner ("#spinner-margin-bottom", "margin-bottom", "horizontal").spinner ("option", "min", - $("#p1").outerHeight (true));
259
+ spinner_margin_left = create_spinner ("#spinner-margin-left", "margin-left", "vertical").spinner ("option", "min", - 200);
260
+ spinner_margin_right = create_spinner ("#spinner-margin-right", "margin-right", "vertical").spinner ("option", "min", - 200);
261
+ spinner_padding_top = create_spinner ("#spinner-padding-top", "padding-top", "horizontal");
262
+ spinner_padding_bottom = create_spinner ("#spinner-padding-bottom", "padding-bottom", "horizontal");
263
+ spinner_padding_left = create_spinner ("#spinner-padding-left", "padding-left", "vertical");
264
+ spinner_padding_right = create_spinner ("#spinner-padding-right", "padding-right", "vertical");
265
+
266
+ $("select#block-alignment").change (function() {
267
+ process_display_elements ();
268
+ });
269
+
270
+ $("#edit-css-button").button ({
271
+ }).click (function () {
272
+
273
+ $("#css-left").hide();
274
+ $("#css-right").hide();
275
+ $("#css-center").hide();
276
+ $("#css-float-left").hide();
277
+ $("#css-float-right").hide();
278
+
279
+ var alignment = '';
280
+ $("select#block-alignment"+" option:selected").each(function() {
281
+ alignment += $(this).text();
282
+ });
283
+
284
+ if (alignment == "None") {
285
+ $("#css-none").hide();
286
+ $("#custom-css").show().val ($("#css-none").text ());
287
+ $("select#block-alignment").val ("Custom CSS").change();
288
+ } else
289
+ if (alignment == "Align Left") {
290
+ $("#css-left").hide();
291
+ $("#custom-css").show().val ($("#css-left").text ());
292
+ $("select#block-alignment").val ("Custom CSS").change();
293
+ } else
294
+ if (alignment == "Align Right") {
295
+ $("#css-right").hide();
296
+ $("#custom-css").show().val ($("#css-right").text ());
297
+ $("select#block-alignment").val ("Custom CSS").change();
298
+ } else
299
+ if (alignment == "Center") {
300
+ $("#css-center").hide();
301
+ $("#custom-css").show().val ($("#css-center").text ());
302
+ $("select#block-alignment").val ("Custom CSS").change();
303
+ } else
304
+ if (alignment == "Float Left") {
305
+ $("#css-float-left").hide();
306
+ $("#custom-css").show().val ($("#css-float-left").text ());
307
+ $("select#block-alignment").val ("Custom CSS").change();
308
+ } else
309
+ if (alignment == "Float Right") {
310
+ $("#css-float-right").hide();
311
+ $("#custom-css").show().val ($("#css-float-right").text ());
312
+ $("select#block-alignment").val ("Custom CSS").change();
313
+ }
314
+ });
315
+
316
+ $("#custom-css").on ('input', function() {
317
+ if (wrapping) $("#wrapper").attr ("style", $("#custom-css").val ());
318
+ update_margin_padding ();
319
+ update_highlighting ();
320
+ update_wrapper_size ();
321
+ });;
322
+
323
+ $("#highlight-button").button ({
324
+ }).click (function () {
325
+ $('body').toggleClass ("highlighted");
326
+
327
+ if (!$('body').hasClass ("highlighted")) {
328
+ $(".highlighting").remove ();
329
+ return;
330
+ }
331
+
332
+ if (wrapping) {
333
+ var wrapper_offset = wrapper.offset ();
334
+ var wrapper_left = wrapper_offset.left;
335
+ var wrapper_top = wrapper_offset.top;
336
+ var wrapper_width = wrapper.outerWidth (true);
337
+ var wrapper_height = wrapper.outerHeight (true);
338
+ var wrapper_outer_width = wrapper.outerWidth ();
339
+ var wrapper_outer_height = wrapper.outerHeight ();
340
+ var code_width = wrapper.width ();
341
+ var code_height = wrapper.height ();
342
+
343
+ var wrapper_margin_width = wrapper_width - wrapper_outer_width;
344
+ var wrapper_margin_height = wrapper_height - wrapper_outer_height;
345
+ var wrapper_margin_top = parseInt (wrapper.css ('margin-top'));
346
+ var wrapper_margin_left = parseInt (wrapper.css ('margin-left'));
347
+ var wrapper_border_width = wrapper.outerWidth () - wrapper.innerWidth ();
348
+ var wrapper_border_height = wrapper.outerHeight () - wrapper.innerHeight ();
349
+ var wrapper_border_top = parseInt (wrapper.css ('border-top-width'));
350
+ var wrapper_border_left = parseInt (wrapper.css ('border-left-width'));
351
+ var wrapper_padding_width = wrapper.innerWidth () - code_width;
352
+ var wrapper_padding_height = wrapper.innerHeight () - code_height;
353
+
354
+ if (debug) {
355
+ console.log ("wrapper_left: " + wrapper_left);
356
+ console.log ("wrapper_top: " + wrapper_top);
357
+ console.log ("wrapper_width: " + wrapper_width);
358
+ console.log ("wrapper_height: " + wrapper_height);
359
+ console.log ("wrapper_outer_width: " + wrapper_outer_width);
360
+ console.log ("wrapper_margin_height: " + wrapper_margin_height);
361
+ console.log ("wrapper_margin_width: " + wrapper_margin_width);
362
+ console.log ("wrapper_margin_height: " + wrapper_margin_height);
363
+ console.log ("wrapper_border_width: " + wrapper_border_width);
364
+ console.log ("wrapper_border_height: " + wrapper_border_height);
365
+ console.log ("wrapper_padding_width: " + wrapper_padding_width);
366
+ console.log ("wrapper_padding_height: " + wrapper_padding_height);
367
+ console.log ("code_width: " + code_width);
368
+ console.log ("code_height: " + code_height);
369
+ }
370
+
371
+ $('#margin-background').show ();
372
+ $("#padding-background-white").show ();
373
+
374
+ $("#margin-background").offset ({top: wrapper_top - wrapper_margin_top, left: wrapper_left - wrapper_margin_left});
375
+ $('#margin-background').css ('width', wrapper_width).css ('height', wrapper_height);
376
+
377
+ $("#padding-background").offset ({top: wrapper_top + wrapper_border_top, left: wrapper_left + wrapper_border_left});
378
+ $('#padding-background').css ('width', wrapper_outer_width - wrapper_border_width).css ('height', wrapper_outer_height - wrapper_border_height);
379
+
380
+ $("#padding-background-white").offset ({top: wrapper_top + wrapper_border_top, left: wrapper_left + wrapper_border_left});
381
+ $('#padding-background-white').css ('width', wrapper_outer_width - wrapper_border_width).css ('height', wrapper_outer_height - wrapper_border_height);
382
+
383
+ code_blocks = wrapper.children ();
384
+ } else {
385
+ $('#margin-background').hide ();
386
+ $("#padding-background-white").hide ();
387
+
388
+ $("#padding-background").offset ({top: $('#wrapper').offset ().top, left: $('#wrapper').offset ().left});
389
+ $('#padding-background').css ('width', $('#wrapper').outerWidth ()).css ('height', $('#wrapper').outerHeight ());
390
+
391
+ code_blocks = wrapper.children ();
392
+ }
393
+
394
+ var code_index = 0;
395
+ var overlay_div = $("#code-overlay");
396
+ var overlay_background_div = $("#code-background-white");
397
+ var last_code_div = "code-overlay";
398
+ var last_bkg_div = "code-background-white";
399
+ var invalid_tags = ['script', 'style'];
400
+
401
+ code_blocks.each (function () {
402
+ var element_tag = $(this).prop("tagName").toLowerCase();
403
+
404
+ if (invalid_tags.indexOf (element_tag) < 0) {
405
+ code_index ++;
406
+ var element_offset = $(this).offset ();
407
+
408
+ var element_left = element_offset.left;
409
+ var element_top = element_offset.top;
410
+ var element_outer_width = $(this).outerWidth ();
411
+ var element_outer_height = $(this).outerHeight ();
412
+
413
+ if (debug) {
414
+ console.log ("");
415
+ console.log ("element " + code_index + ": " + element_tag);
416
+
417
+ console.log ("element_left: " + element_left);
418
+ console.log ("element_top: " + element_top);
419
+ console.log ("element_outer_width: " + element_outer_width);
420
+ console.log ("element_outer_height: " + element_outer_height);
421
  }
422
 
423
+ var new_id = "code-" + code_index;
424
+ $("#" + last_code_div).after (overlay_div.clone ().offset ({top: element_top, left: element_left}).css ('width', element_outer_width).css ('height', element_outer_height).attr ("id", new_id).addClass ("highlighting"));
425
+ last_code_div = new_id;
426
+
427
+ var new_bkg_id = "code-background-" + code_index;
428
+ $("#" + last_bkg_div).after (overlay_background_div.clone ().offset ({top: element_top, left: element_left}).css ('width', element_outer_width).css ('height', element_outer_height).attr ("id", new_bkg_id).addClass ("highlighting"));
429
+ last_bkg_div = new_bkg_id;
430
  }
431
  });
432
+ if (debug) console.log ("");
433
+ });
434
 
435
+ $("#use-button").button ({
436
+ }).click (function () {
437
+ apply_to_settings ();
438
+ window.close();
439
+ });
440
 
441
+ $("#reset-button").button ({
442
+ }).click (function () {
443
+ load_from_settings ();
444
+ });
445
 
446
+ $("#cancel-button").button ({
447
+ }).click (function () {
448
+ window.close();
449
+ });
450
 
451
+ $(".viewport-box").click (function () {
452
+ var new_width = parseInt ($(this).attr ("data")) - 1;
453
+ if (window.innerWidth == new_width) {
454
+ window.resizeTo (836, $(window).height());
455
+ } else {
456
+ // Add body margin
457
+ window.resizeTo (new_width + 16, $(window).height());
458
+ }
459
+ });
460
 
461
+ update_width ();
 
 
 
 
462
 
463
+ load_from_settings ();
 
 
 
464
 
465
+ setTimeout (update_wrapper_size, 500);
 
 
 
 
 
466
 
467
+ var current_time = new Date().getTime();
468
+ if (debug) console.log ("TIME: " + ((current_time - start_time) / 1000).toFixed (3));
469
+ }
470
 
471
+ jQuery(document).ready(function($) {
472
+ initialize_preview ();
 
473
  });
474
+
475
  </script>
476
  <style>
477
+ .responsive-table td {
478
+ white-space: nowrap;
479
+ }
480
  .small-button .ui-button-text-only .ui-button-text {
481
  padding: 0;
482
  }
483
+ #margin-background {
484
+ z-index: 2;
485
+ position: absolute;
486
+ display: none;
 
487
  }
488
+ .highlighted #margin-background {
489
+ background: rgba(255, 145, 0, 0.5);
490
+ display: block;
491
  }
492
+ #padding-background-white {
493
+ z-index: 3;
494
+ position: absolute;
495
+ background: #fff;
496
+ width: 0px;
497
+ height: 0px;
498
+ display: none;
499
  }
500
+ .highlighted #padding-background-white {
501
+ display: block;
502
  }
503
+ #padding-background {
504
+ z-index: 4;
505
  position: absolute;
 
506
  display: none;
507
  }
508
+ .highlighted #padding-background {
509
+ background: rgba(50, 220, 140, 0.5);
510
+ display: block;
511
  }
512
+ #wrapper {
513
+ z-index: 6;
 
 
514
  position: relative;
515
+ border: 0;
516
  }
517
+ .code-background-white {
518
+ z-index: 5;
 
519
  position: absolute;
520
+ background: #fff;
521
+ width: 0px;
522
+ height: 0px;
523
+ display: none;
524
+ }
525
+ .highlighted .code-background-white {
526
+ display: block;
527
+ }
528
+ .code-overlay {
529
+ z-index: 7;
530
+ position: absolute;
531
+ display: none;
532
  }
533
+ .highlighted .code-overlay {
 
534
  background: rgba(50, 140, 220, 0.5);
535
+ display: block;
536
  }
537
+
538
+ table.screen td {
539
+ padding: 0;
540
+ font-size: 12px;
541
+ }
542
+
543
+ table.demo-box {
544
+ width: 300px;
545
+ margin: 0 auto;
546
+ border: 1px solid #ccc;
547
+ }
548
+ #demo-box-no-wrapping {
549
+ height: 200px;
550
+ }
551
+ table.demo-box input {
552
  display: none;
553
  }
554
+ .demo-box td {
555
+ font-size: 12px;
556
+ padding: 0;
557
  }
558
+ td.demo-wrapper-margin-lr, td.demo-wrapper-margin {
559
+ width: 22px;
560
+ height: 22px;
561
  text-align: center;
562
+ }
563
+ td.demo-wrapper-margin-tb {
564
+ width: 300px;
565
+ height: 22px;
566
+ text-align: center;
567
+ }
568
+ .highlighted td.demo-wrapper-margin-tb, .highlighted td.demo-wrapper-margin-lr, .highlighted td.demo-wrapper-margin {
569
  background: rgba(255, 145, 0, 0.5);
570
  }
571
+ td.demo-code-padding-tb {
572
+ text-align: center;
573
+ }
574
+ td.demo-code-padding-lr {
575
+ width: 22px;
576
+ text-align: center;
577
+ }
578
  td.demo-code {
 
 
579
  text-align: center;
580
+ }
581
+ #demo-box td.demo-code {
582
+ height: 110px;
583
+ }
584
+ .highlighted td.demo-code, .highlighted td.demo-code-padding-lr, .highlighted td.demo-code-padding-tb {
585
  background: rgba(50, 140, 220, 0.5);
586
  }
587
  td.demo-wrapper-background {
588
+ width: 80px;
589
  text-align: center;
590
+ word-wrap: break-word;
591
+ white-space: normal;
592
+ }
593
+ .highlighted td.demo-wrapper-background {
594
  background: rgba(50, 220, 140, 0.5);
595
  }
596
+ .ui-widget-content {
597
+ background: transparent;
598
+ }
599
+ .ui-spinner {
600
+ border: 0;
601
+ }
602
+ .ui-spinner-horizontal, .ui-spinner-horizontal .ui-spinner-input {
603
+ height: 14px;
604
+ }
605
+ .ui-spinner-horizontal .ui-spinner-input {
606
+ width: 23px;
607
+ outline: 0;
608
+ margin: -1px 12px 0 12px;
609
+ }
610
+ .ui-spinner-vertical, .ui-spinner-vertical .ui-spinner-input {
611
+ width: 18px;
612
+ }
613
+ .ui-spinner-vertical .ui-spinner-input {
614
+ height: 11px;
615
+ outline: 0;
616
+ margin: 12px 0 12px 0;
617
+ font-size: 11px;
618
+ }
619
+
620
  </style>
621
+ <?php ai_wp_head_hook (); ?>
622
+
623
  </head>
624
+ <body style='font-family: arial; text-align: justify; overflow-x: hidden;'>
625
+ <div style="margin: 0 -8px 10px; display: none;">
626
+ <table class="screen" cellspacing=0 cellpadding=0>
627
+ <tr>
628
+ <?php
629
+ $previous_width = 0;
630
+ for ($viewport = AD_INSERTER_VIEWPORTS - 1; $viewport > 0; $viewport --) {
631
+ $viewport_name = get_viewport_name ($viewport);
632
+ $viewport_width = get_viewport_width ($viewport);
633
+ if ($viewport_name != '' && $viewport_width != 0) {
634
+ echo "<td class='viewport-box' data='", $viewport_width, "' style='background: #eee; text-align: center; border: 1px solid #888; border-left-width: 0; min-width: ", $viewport_width - $previous_width - 1, "px'>",
635
+ $previous_name, "<span style='float: left; margin-left: 5px;'>", $previous_width != 0 ? $previous_width . "px" : "", "</span></td>";
636
+ }
637
+ $previous_name = $viewport_name;
638
+ $previous_width = $viewport_width;
639
+ }
640
+ echo "<td style='background: #eee; text-align: left; border: 1px solid #888; border-left-width: 0; min-width: 2000px'><span style='margin-left: 30px;'>", get_viewport_name (1), "</span><span style='float: left; margin-left: 5px;'>", $previous_width != 0 ? $previous_width . "px" : "", "</span></td>";
641
+ ?>
642
+ </tr>
643
+ </table>
644
+ </div>
645
+
646
+ <div id="blocked-warning" class="warning-enabled" style="padding: 2px 8px 2px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
647
+ <div style="float: right; text-align: right; margin: 20px 18px 0px 0;">
648
+ Please check browser, plugins and ad blockers that may block this page.
649
+ </div>
650
+ <h3 style="color: red;" title="Error loading page">PAGE BLOCKED</h3>
651
+
652
+ <div style="clear: both;"></div>
653
+
654
+ </div>
655
+
656
+ <div style="margin: 10px -8px">
657
+ <table class="screen" cellspacing=0 cellspacing="0">
658
+ <tr>
659
+ <td><span>&#9667;</span></td>
660
+ <td style="width: 50%;"><div style="height: 2px; width: 100%; border-bottom: 1px solid #ddd;"></div></td>
661
+ <td id="screen-width" style="min-width: 45px; text-align: center; font-size: 12px;">820 px</td>
662
+ <td style="width: 50%;"><div style="height: 2px; width: 100%; border-bottom: 1px solid #ddd;"></div></td>
663
+ <td><span id="right-arrow" >&#9657;</span></td>
664
+ </tr>
665
+ </table>
666
  </div>
667
+
668
+ <div style="float: left; max-width: 300px; margin-right: 20px">
669
+ <h1 style="margin: 0;">Preview</h1>
670
+ <h2>Block <?php echo $block; ?></h2>
671
+ <h3 id="block-name" style="text-align: left;"><?php echo $block_name; ?></h3>
672
+ </div>
673
+
674
+ <div style="float: right; width: 90px; margin-left: 20px;">
675
+ <button id="highlight-button" type="button" style="margin: 0 0 10px 0; font-size: 12px; width: 90; height: 35px; float: right;" title="Highlight inserted code" >Highlight</button>
676
+ <button id="use-button" type="button" style="margin: 0 0 10px 0; font-size: 12px; width: 90; height: 35px; float: right;" title="Highlight inserted code" >Use</button>
677
+ <button id="reset-button" type="button" style="margin: 0 0 10px 0; font-size: 12px; width: 90; height: 35px; float: right;" title="Highlight inserted code" >Reset</button>
678
+ <button id="cancel-button" type="button" style="margin: 0 0 10px 0; font-size: 12px; width: 90; height: 35px; float: right;" title="Highlight inserted code" >Cancel</button>
679
+ </div>
680
+
681
+ <div style="float: left; min-height: 200px; margin: 0 auto;">
682
+ <table id="demo-box" class="demo-box" style="display: none;" cellspacing=0 cellspacing="0">
683
  <tr>
684
+ <td class="demo-wrapper-margin-tb" style="border-right: 1px solid #ccc;" colspan="5">
685
+ <span style="float: left; margin-left: 43px;">margin</span>
686
+ <span style="float: right; margin-right: 70px">px</span>
687
+ <input id="spinner-margin-top" class=" spinner" name="value">
688
+ </td>
689
+ <td class="demo-wrapper-background"></td>
690
  </tr>
 
 
691
  <tr>
692
+ <td class="demo-wrapper-margin"></td>
693
+ <td class="demo-code-padding-tb" style="border-top:1px solid #ccc; border-left: 1px solid #ccc; border-right: 1px solid #ccc;" colspan="3">
694
+ <span style="float: left; margin-left: 14px;">padding</span>
695
+ <span style="float: right; margin-right: 48px">px</span>
696
+ <input id="spinner-padding-top" class=" spinner" name="value">
697
+ </td>
698
+ <td class="demo-wrapper-margin" style="border-right: 1px solid #ccc;"></td>
699
+ <td class="demo-wrapper-background"></td>
700
  </tr>
 
701
  <tr>
702
+ <td class="demo-wrapper-margin-lr">
703
+ <input id="spinner-margin-left" class=" spinner" name="value">
704
+ </td>
705
+ <td class="demo-code-padding-lr" style="border-left: 1px solid #ccc;">
706
+ <input id="spinner-padding-left" class=" spinner" name="value">
707
+ </td>
708
+ <td class="demo-code"><p>Code block</p><p class="wrapper-size">&nbsp;</p></td>
709
+ <td class="demo-code-padding-lr" style="border-right: 1px solid #ccc;">
710
+ <input id="spinner-padding-right" class=" spinner" name="value">
711
+ </td>
712
+ <td class="demo-wrapper-margin-lr" style="border-right: 1px solid #ccc;">
713
+ <input id="spinner-margin-right" class=" spinner" name="value">
714
+ </td>
715
+ <td class="demo-wrapper-background"></td>
716
+ </tr>
717
+ <tr>
718
+ <td class="demo-wrapper-margin"></td>
719
+ <td class="demo-code-padding-tb" style="border-bottom:1px solid #ccc; border-left: 1px solid #ccc; border-right: 1px solid #ccc;" colspan="3">
720
+ <input id="spinner-padding-bottom" class=" spinner" name="value">
721
+ </td>
722
+ <td class="demo-wrapper-margin" style="border-right: 1px solid #ccc;"></td>
723
+ <td class="demo-wrapper-background"></td>
724
+ </tr>
725
+ <tr>
726
+ <td class="demo-wrapper-margin-tb" style="border-right: 1px solid #ccc;" colspan="5">
727
+ <span style="float: left; margin-left: 6px;">wrapping div</span>
728
+ <span style="float: right; margin-right: 72px">&nbsp;</span>
729
+ <input id="spinner-margin-bottom" class=" spinner" name="value">
730
+ </td>
731
+ <td class="demo-wrapper-background">background</td>
732
+ </tr>
733
+ </table>
734
+
735
+ <table id="demo-box-no-wrapping" class="demo-box" style="display: none;" cellspacing=0 cellspacing="0">
736
+ <tr>
737
+ <td class="demo-code" style="border-right: 1px solid #ccc;"><p>Code block</p><p class="wrapper-size">&nbsp;</p></td>
738
+ <td class="demo-wrapper-background">background</td>
739
  </tr>
740
  </table>
741
  </div>
742
+
743
+ <div style="clear: both;"></div>
744
+
745
+ <div id="css-code" style="margin: 20px 0;">
746
+ <table class="responsive-table">
747
+ <tr>
748
+ <td style="vertical-align: middle; padding:0;">
749
+ <span id="css-label" style="vertical-align: middle; margin: 4px 0 0 0; font-size: 12px; display: none;">CSS &nbsp;</span>
750
+ </td>
751
+ <td style="width: 100%; height: 32px; padding:0;">
752
+ <input id="custom-css" style="width: 100%; display: inline-block; padding: 5px 0 0 0; border-radius: 4px; display: none; font-size: 12px; font-family: Courier, 'Courier New', monospace; font-weight: bold;" type="text" value="<?php echo $custom_css; ?>" size="70" maxlength="160" title="Custom CSS code for wrapping div" />
753
+ <span style="width: 100%; display: inline-block; padding: 5px 0 0 2px; font-family: Courier, 'Courier New', monospace; font-size: 12px; font-weight: bold;">
754
+ <span id="css-no-wrapping" style="vertical-align: middle; display: none;"></span>
755
+ <span id="css-none" style="vertical-align: middle; display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_NONE); ?></span>
756
+ <span id="css-left" style="vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_LEFT); ?></span>
757
+ <span id="css-right" style="vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_RIGHT); ?></span>
758
+ <span id="css-center" style="vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_CENTER); ?></span>
759
+ <span id="css-float-left" style="vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_FLOAT_LEFT); ?></span>
760
+ <span id="css-float-right" style="vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_FLOAT_RIGHT); ?></span>
761
+ </span>
762
+ </td>
763
+ <td padding:0;>
764
+ <button id="edit-css-button" type="button" style="margin: 0 0 0 10px; height: 30px; font-size: 12px; display: none;">Edit</button>
765
+ </td>
766
+ </tr>
767
+ </table>
768
+
769
+ <div style="margin: 20px 0;">
770
+ Block Alignment and Style:&nbsp;&nbsp;&nbsp;
771
+ <select style="border-radius: 5px; width:120px; height: 25px;" id="block-alignment">
772
+ <option value="<?php echo AD_ALIGNMENT_NO_WRAPPING; ?>" <?php echo ($alignment_type==AD_ALIGNMENT_NO_WRAPPING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_NO_WRAPPING; ?></option>
773
+ <option value="<?php echo AD_ALIGNMENT_CUSTOM_CSS; ?>" <?php echo ($alignment_type==AD_ALIGNMENT_CUSTOM_CSS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_CUSTOM_CSS; ?></option>
774
+ <option value="<?php echo AD_ALIGNMENT_NONE; ?>" <?php echo ($alignment_type==AD_ALIGNMENT_NONE) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_NONE; ?></option>
775
+ <option value="<?php echo AD_ALIGNMENT_LEFT; ?>" <?php echo ($alignment_type==AD_ALIGNMENT_LEFT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_LEFT; ?></option>
776
+ <option value="<?php echo AD_ALIGNMENT_RIGHT; ?>" <?php echo ($alignment_type==AD_ALIGNMENT_RIGHT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_RIGHT; ?></option>
777
+ <option value="<?php echo AD_ALIGNMENT_CENTER; ?>" <?php echo ($alignment_type==AD_ALIGNMENT_CENTER) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_CENTER; ?></option>
778
+ <option value="<?php echo AD_ALIGNMENT_FLOAT_LEFT; ?>" <?php echo ($alignment_type==AD_ALIGNMENT_FLOAT_LEFT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_FLOAT_LEFT; ?></option>
779
+ <option value="<?php echo AD_ALIGNMENT_FLOAT_RIGHT; ?>" <?php echo ($alignment_type==AD_ALIGNMENT_FLOAT_RIGHT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_FLOAT_RIGHT; ?></option>
780
+ </select>
781
+ </div>
782
+ </div>
783
+
784
+ <p id="p1">This is a preview of the saved code between two dummy paragraphs. Here you can test various block alignments, visually edit margin and padding values of the wrapping div
785
+ or write CSS code directly and watch live preview. Highlight button highlights background, wrapping div margin and code area, while Reset button restores all the values to those of the current block.</p>
786
+
787
+ <div id='padding-background'></div>
788
+ <div id='margin-background'></div>
789
+ <div id='padding-background-white'></div>
790
+ <div id='wrapper' style='<?php echo $wrapper_css; ?>'>
791
+ <?php echo $block_code; ?>
792
  </div>
793
+ <!-- IE bug: use inline CSS: position: absolute;-->
794
+ <div id='code-background-white' class= "code-background-white" style="position: absolute;"></div>
795
+ <div id='code-overlay' class="code-overlay" style="position: absolute;"></div>
796
+ <p id="p2">You can resize the window (and refresh the page to reload ads) to check display with different screen widths.
797
+ Once you are satisfied with alignment click on the Use button and the settings will be copied to the active block.</p>
798
+ <p id="p3">Please note that the code displayed here is the code that is saved for this block, while block name, alignment and style are taken from the current block settings (may not be saved).
799
+ No Wrapping style inserts the code as it is so margin and padding can't be set. However, you can use own HTML code for the block.</p>
800
+ <p id="p4">Few very important things you need to know in order to insert code and display some ad:
801
+ Enable and use at least one display option (Automatic Display, Widget, Shortcode, PHP function call).
802
+ Enable display on at least one Wordpress page type (Posts, Static pages, Homepage, Category pages, Search Pages, Archive pages).
803
+ For Posts and static pages select default value On all Posts / On all Static pages unless you really know what are you doing.</p>
804
+ <?php ai_wp_footer_hook (); ?>
805
+
 
 
 
806
  </body>
807
  </html>
808
  <?php
 
809
  }
810
 
 
readme.txt CHANGED
@@ -1,21 +1,17 @@
1
  === Ad Inserter ===
2
  Contributors: spacetime
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4
4
- Tags: adsense, amazon, clickbank, cj, ad, ads, html, javascript, php, code, widget, sidebar, responsive, viewport, rotating, banner, banner rotation, contextual, shortcodes, widgets, header, footer, users, logged in, not logged in, mobile, desktop, phone, tablet, custom css, category, tag, filter, url, skip
5
  Requires at least: 4.0
6
- Tested up to: 4.6.0
7
- Stable tag: 1.6.7
8
  License: GPLv3
9
 
10
- Insert any HTML/Javascript/PHP code into Wordpress. Perfect for AdSense or contextual Amazon ads. 16 code blocks, many display options.
11
 
12
  == Description ==
13
 
14
- **Ad Inserter**
15
-
16
- Need to install ads or widgets on Wordpress website?
17
-
18
- Ad Inserter is a simple yet powerful plugin to insert any code into Wordpress. **Perfect for AdSense or contextual Amazon ads.** Simply enter any HTML/Javascript/PHP code and select where and how you want to display it.
19
 
20
  Ad Inserter supports up to 16 code blocks. Code block is any code (for example AdSense ad) that has to be inserted (displayed) at some position.
21
  Each code block can be configured to insert code at almost any position supported by Wordpress.
@@ -24,14 +20,17 @@ Each code block can be configured to insert code at almost any position supporte
24
 
25
  * 16 code blocks
26
  * Syntax highlighting editor
 
27
  * Automatic positions: before/after post, content, paragraph or excerpt
28
- * Manual positions: shortcodes, PHP function call
29
- * Block alignment and style: left, center, right, float left, float right, custom CSS, no wrapping
 
30
  * PHP code processing
31
  * Server-side and client-side device detection (3 custom viewports)
32
- * Black/White-list categories, tags, urls, referers
 
33
 
34
- And there is also <a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a> if you need more than 16 code blocks or more than 3 viewports.
35
 
36
  **Quick Start**
37
 
@@ -40,8 +39,9 @@ Few very important things you need to know in order to insert code and display s
40
  * **Enable and use at least one display option** (Automatic Display, Widget, Shortcode, PHP function call)
41
  * **Enable display on at least one Wordpress page type** (Posts, Static pages, Homepage, Category pages, Search Pages, Archive pages)
42
  * For Posts and static pages **select default value On all Posts / On all Static pages** unless you really know what are you doing
 
43
 
44
- Few typical settings are described on the <a href="https://wordpress.org/plugins/ad-inserter/faq/">FAQ</a> page. Please make sure you have also read **WARNINGS** on the bottom of this page!
45
 
46
  **Settings**
47
 
@@ -52,7 +52,7 @@ Each code block has 4 independent display options:
52
  * Shortcode
53
  * PHP function call
54
 
55
- To display code block (ad) at some position **you need to enable and use at least one display option**.
56
 
57
  Automatic Display Options:
58
 
@@ -84,7 +84,9 @@ Order of display positions in a typical post is the following:
84
  * Output of some other plugins
85
  * [After Post]
86
 
87
- Of course, the final order of items depends also on other plugins. Ad Inserter is by default called as one of the last plugins. You can change Plugin priority on the settings page (tab #).
 
 
88
 
89
  Block Alignment and Style:
90
 
@@ -97,6 +99,21 @@ Block Alignment and Style:
97
  * Float Left (ad on left with wrapped text on right)
98
  * Float Right (ad on right with wrapped text on left)
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  Check <a href="https://wordpress.org/plugins/ad-inserter/screenshots/">screenshots</a> for explanation on alignment.
101
 
102
  **PLEASE NOTE:** If you are using **No Wrapping** style and need to hide code on some devices using client-side detection (CSS Media Queries) then you need to add appropriate class to your CSS code (ai-viewport-1, ai-viewport-2, ai-viewport-3).
@@ -108,7 +125,6 @@ Single pages:
108
 
109
  * Posts
110
  * Static pages
111
- * 404 page (Error 404: Page not found)
112
 
113
  Blog pages:
114
 
@@ -117,32 +133,56 @@ Blog pages:
117
  * Search Pages
118
  * Tag / Archive pages
119
 
 
 
 
 
 
 
 
120
  You can also disable ads on certain posts or static pages. For each code block on posts or static pages you first define default display settings for posts/pages page type. Then you can define post/page exceptions on the post/page editor page (check Ad Inserter Exceptions meta box below). Exceptions work only on page/post content (positions Before Content, Before Paragraph, After Paragraph, After Content). For one or few exceptions it is easier to first enable ads on All Posts/Static pages page types and then either white or black-list single url or few space-separated urls (click on the Lists button).
121
 
 
 
122
  Paragraph number for Automatic Display options Before and After Paragraph:
123
 
124
  * 0 means random paragraph position
125
  * value between 0 and 1 means relative position in post or page (e.g. 0.3 means paragraph 30% from top or bottom)
126
  * 1 or more means paragraph number
127
 
128
- Paragraphs can be counted from top or from bottom. It is also possible to count only paragraphs that contain/do not contain certain text or count only paragraphs that have some minimum number of words. If more than one text is defined (comma separated) and "contain" is selected then the paragraph must contain ALL texts.
 
 
 
 
 
129
 
130
  **Please Note** Paragraph processing works on **every** post or page according to settings. Therefore, if you enable display also on blog pages (home, category, archive, search pages) and your theme does not display post excerpts but complete posts,
131
  Ad Inserter will by default insert code blocks into ALL posts on the blog page (according to settings). To enable insertion only into specific post(s) on blog pages define Filter. You can also leave Filter (click Misc button) to 0 (means all posts on the blog page) and define maximum number of insertions.
132
 
133
  You can also define paragraph HTML tags. Normally only `<p>` tags are used. If your post contains also `<div>` or header tags, you can define comma separated list of tags used to count paragraphs (e.g. **p, div, h2, h3**).
 
134
  **WARNING:** Each code block you insert in post adds one `<div>` block unelss you use **No wrapping** style. **Before Paragraph** will insert code before `<tag>`, **After Paragraph** will insert code after closing `</tag>`.
135
  **After Paragraph** will not work if you specify tag names that have no closing tags! Use # as tag if paragraphs have no tags and are separated with the `\r\n\r\n` characters.
136
 
137
- Minimum number of paragraphs / Minimum page/post words: do not display ad if the number of paragraphs or the number of words is below limit (used only for position Before or After selected paragraph).
 
 
 
 
 
 
138
 
139
  Display only for posts published after N days checks the date when the post was published.
140
 
141
- On the Ad Inserter settings page (tab #) you also have option Tag Debugging. If enabled, it displays paragraph tags surrounded with a border. This way you can check where your code will be inserted. You can select to show paragraph tags before or after plugin processing. If Before Processing is selected Ad Inserter WILL NOT insert any code!
 
 
 
142
 
143
  Additional Options for code blocks:
144
 
145
- PHP processing: Enabled or Disabled - Enable processing of PHP code. If there is an error in the PHP code, it will not break the website.
146
 
147
  * Use {category}, {short_category}, {title}, {short_title}, {tag}, {smart_tag} or {search_query} tags to insert actual post data into code blocks
148
  * Use {author} for post author username or {author_name} for post author name to insert post author data into code blocks (**works only inside posts**)
@@ -164,20 +204,21 @@ For each code block you can also limit how many times on the page the code (or a
164
  This is **useful in many cases where you can't remove unwanted insertions** of the code with other settings:
165
 
166
  * If you need to insert ad before the first, third and fith excerpt on the homepage you simply specify `1, 3, 5` for the filter.
167
- * In some WP themes hooks (that call Ad Inserter insertion functions) are called more than once. In such case you might get unwanted insertions. Simply set the filter to the number of the wanted call(s).
168
  * If you use adinserter PHP function and you don't want that for each time the functon is called on the page the code is inserted, you can simply filter calls.
169
  * If you oly need the first N calls (insertions) then leave filter to 0 and use Max N insertions instead.
170
 
171
  **Please Note** Paragraph processing works on **every** post or page according to settings. Therefore, if you enable display also on blog pages (home, category, archive, search pages) and your theme does not display post excerpts but complete posts,
172
  Ad Inserter will by default insert code blocks into ALL posts on the blog page (according to settings). To enable insertion only into specific post(s) on blog pages define Filter. You can also leave Filter to 0 (means all posts on the blog page) and define maximum number of insertions.
173
 
174
- General tag: text used for {tag} and {smart_tag} if the post has no tags - useful for contextual ads - **works only inside posts!**
175
 
176
  Display Block to:
177
 
178
  * All users (default)
179
  * Logged in users
180
  * Not logged in users
 
181
 
182
  **WARNING:** If you are using caching this may not work as expected. The check works only when the page is generated and Ad Inserter is called. Make sure you have disabled caching when you are using such settings.
183
 
@@ -185,15 +226,22 @@ Display Block to:
185
 
186
  Do not display ads in certain caregories e.g sport, news, science,... (black list) or display ads only in certain categories (white list):
187
  leave category list empty and set it to Black list to show ads in all categories.
188
- **WARNING:** If category name contains commas use category slug instead. Also make sure you have enabled display on **Category pages**.
 
189
 
190
  Do not display ads in posts with certain tags (black list) or display ads only in posts with certain tags (white list). Leave tag list empty and set it to Black list to show ads for all tags. Also make sure you have enabled display on **Tag / Archive pages**.
191
 
192
- Do not display ads on pages with certain urls (black list) or display ads only pages with certain urls (white list): leave url list empty and set it to Black list to show ads on all urls.
 
 
193
  Url used here is everything starting form the `/` after the domain name. For example: if web address is `http://domain.com/lorem-ipsum`, url to white/black-list is `/lorem-ipsum`
194
  You can also use partial urls with *. To filter all urls starting with /url-start use `/url-start*`, to filter all urls that contain url-pattern use `*url-pattern*`, to filter all urls ending with url-end use `*url-end`.
195
  **WARNING:** Separate urls with SPACES.
196
 
 
 
 
 
197
  Do not display ads to users from certain referers (domains) e.g technorati.com, facebook.com,... (black list) or display ads only for certain referrers (white list): use # for no referer (direct visit),
198
  leave referrers list empty and set it to Black list to show ads for all referrers.
199
 
@@ -215,7 +263,7 @@ leave referrers list empty and set it to Black list to show ads for all referrer
215
 
216
  **BUT BE CAREFUL:** Some ad networks (like AdSense) limit ads per page. The ads are still inserted (loaded and counted) for all devices, but for unwanted devices they are hidden by the browser using CSS media queries based on viewport widths.
217
 
218
- Up to 3 viewport names and widths can be defined on the Ad Inserter Settings tab # (<a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a> supports up to 6 viewports). Default values are:
219
 
220
  * Desktop: 980 pixels or more
221
  * Tablet: from 768 pixels to 979 pixels
@@ -242,25 +290,23 @@ Server-side detection uses User-Agent string combined with specific HTTP headers
242
  There are 3 independent types of manual insertion of code block:
243
 
244
  * Widget - Widgets for all code blocks are enabled by default - simply drag **Ad Inserter** widget to any widget postition (e.g. Sidebar), select code block, save and you're done.
245
- * Shortcode - Insert shortcode `[adinserter block="BLOCK_NUMBER"]` or `[adinserter name="BLOCK_NAME"]` into post or page HTML code to display block with BLOCK_NAME name or BLOCK_NUMBER number at this position. **PLEASE NOTE:** Shortcodes IGNORE post/static page exception settings!
246
- * PHP function call `<?php if (function_exists ('adinserter')) echo adinserter (BLOCK_NUMBER); ?>` - Insert code block BLOCK_NUMBER at any position in template file. You can also define Filter for PHP function - define which call(s) to the function will actually insert code. This is useful if you put a call to the `adinserter` function inside a loop in a template file (e.g. for homepage) and you need to insert ads only few times between posts.
247
 
248
  **OTHER NOTES**
249
 
250
- By default code blocks will not be inserted on Error 404 page (Page Not Found). Check '404 Page' checkbox to enable code block on error 404 page.
251
 
252
- **Ad Inserter Settings - Tab #**
253
 
254
  Wrapping divs for code blocks have 'code-block' and 'code-block-N' classes which can be used for custom styles. Class name 'code-block' can be changed in Ad Inserter settings. If you are using client-side device detection (CSS media queries) then the wrapping div for the code block will have also some of the following classes: ai-viewport-1, ai-viewport-2, ai-viewport-3.
255
 
256
  You can choose between many syntax highlighting themes.
257
 
258
- By default Ad Inserter exceptions on posts/static pages are enabled only for administrators. You can define minimum user role for page/post Ad Inserter exceptions editing in Ad Inserter Settings (tab #).
259
 
260
  Default Ad Inserter plugin processing order is 99999. It is used to specify the order in which the plugin functions are executed. Lower numbers correspond with earlier execution. You can change this value if you have problems with the processing order of other plugins.
261
 
262
- If Paragraph Tag Debugging is enabled, it displays paragraph tags surrounded with a border. This way you can check where your code will be inserted. You can select to show paragraph tags before or after plugin processing. If Before Processing is selected Ad Inserter WILL NOT insert any code!
263
-
264
  Support for Special Code Blocks:
265
 
266
  * Header scripts (scripts in the `<header>` section)
@@ -268,35 +314,71 @@ Support for Special Code Blocks:
268
 
269
  **WARNING:** Text selection, Copy and Paste functions with the syntax highlighting editor do not work on mobile devices. If you need these functions you can temporarily swich to **Simple editor** using the checkbox above the code box.
270
 
271
- **WARNING:** Some adblockers may block Ad Inserter settings page. If you don't see normal tabs for code blocks or there is no save button, make sure you have whitelisted Ad Inserter settings page.
 
 
272
 
273
  **WARNING:** If you are using caching the inserted code may not appear imemdiately on the page. Make sure you have disabled caching when you are testing or debugging.
274
  Some caching plugins like <a href="https://wordpress.org/plugins/wp-super-cache/" target="_blank">WP Super Cache</a> have an option to disable caching for known users.
275
 
276
- **WARNING:** If you are using caching some settings may not work as expected. For example, ad rotation, referer check and server-side detection works only when the page is generated and Ad Inserter is called.
277
- In such cases please make sure you have disabled caching when you are using such settings.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
 
279
  **SUPPORT**
280
 
281
  If you experience problems with the Ad Inserter plugin you can ask for help on the <a href ="https://wordpress.org/support/plugin/ad-inserter">support forum</a>.
282
- However, in order to be able to diagnose the problem and suggest actions or fix a bug, please do the following:
 
 
283
 
284
- Check source code of the page. Some code for ads may not display anything, either because of errors in the ad code or because of ad network issues.
285
- Before you report problem please check source code of the page and make sure the code is not inserted where it should be. The code may be inserted properly but you won't see anything.
286
- Try to add some text after the ad code to check if it appears at the expected ad position. If you are sure that there is something wrong **you need to provide the following**:
287
 
288
- 1. Clear description of the problem. Describe what does not work as expected.
289
 
290
- 2. Screenshot(s) of the settings
291
 
292
- 3. Web addresses (links) of the pages where the code from the settings above is not inserted properly.
293
 
294
- Unless you provide the items listed above nobody can check your website, can't reproduce the problem and consequently can't help.
295
  Thank you very much for understanding.
296
 
297
  Please **support the plugin** if you like it:
298
 
299
- * Write a nice <a href="http://wordpress.org/support/view/plugin-reviews/ad-inserter">review</a>
300
  * <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4">Donate</a>
301
 
302
 
@@ -311,12 +393,15 @@ Please **support the plugin** if you like it:
311
  3. Choose file, click on Install Now, activate it
312
  3. Go to Settings / Ad Inserter to configure it
313
 
314
- **WARNING:** Some adblockers may block Ad Inserter settings page. If you don't see normal tabs for code blocks or there is no save button, make sure you have whitelisted Ad Inserter settings page.
 
 
 
315
 
316
  **WARNING:** If you are using caching the inserted code may not appear imemdiately on the page. Make sure you have disabled caching when you are testing or debugging.
317
  Some caching plugins like <a href="https://wordpress.org/plugins/wp-super-cache/" target="_blank">WP Super Cache</a> have an option to disable caching for known users.
318
 
319
- **WARNING:** If you are using caching some settings may not work as expected. For example, ad rotation, referer check and server-side detection works only when the page is generated and Ad Inserter is called.
320
  In such cases please make sure you have disabled caching when you are using such settings.
321
 
322
  **WARNING:** Some code for ads may not display anything, either because of erros in the ad code or because of ad network issues.
@@ -326,20 +411,29 @@ The code may be inserted properly but you won't see anything. Try to add some te
326
  **Ad Inserter Pro Installation**
327
 
328
  <a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a> is an upgraded version of the freely available Ad Inserter.
329
- In addition to all the features in the free version it offers 64 code blocks, 6 custom viewports, export and import of settings and support via email.
330
 
331
  If you are using free Ad Inserter simply uninstall it. The Pro version will automatically import existing settings from the free version.
332
  After you receive the email with download link for the Ad Inserter Pro plugin, download it, go to Wordpress Plugins, Add New, Upload Plugin, Choose file, click on Install Now,
333
- activate it and then click "Enter License Key" and enter license key you got in the email. If you need to edit license key go to Ad Inserter settings (tab #).
 
 
 
 
 
 
 
 
334
 
335
  == Frequently Asked Questions ==
336
 
337
  = I have activated Ad Inserter. How can I use it? =
338
 
339
- 1. After activation, click "Settings / Ad Inserter" to access the setup page.
340
- 2. Put ad (or any other HTML/Javascript/PHP) code into the ad box.
341
- 3. Set display options.
342
- 4. Save settings.
 
343
 
344
 
345
  = Settings for **widget** =
@@ -418,6 +512,13 @@ Configure block 3 with
418
  Use block 3 to display ads and make sure all 3 blocks are enabled for the same page types (Posts, Pages, Homepage, etc.).
419
 
420
 
 
 
 
 
 
 
 
421
  = How can I replace deprecated tags {adinserter n} for manual insertion with new ones [adinserter block="n"] in all posts? =
422
 
423
  Use <a href="https://wordpress.org/plugins/search-regex/" target="_blank">Search Regex</a> plugin to replace tags in all posts with few clicks. If you are not familiar with regular expressions simply use search and replace text for each code block. Use **Replace** to test replacements and when it works as expected use **Replace & Save**.
@@ -600,7 +701,7 @@ Sign in to Amazon Associates, go to Widgets/Widget Source, choose ad type and se
600
  For titles and search terms use tags. For example, the code below would display amazon products related to the post tags - check above for all possible tags.
601
 
602
 
603
- Example for Amazon Native Shopping Ads:
604
 
605
  `<script type="text/javascript">
606
  amzn_assoc_placement = "adunit0";
@@ -646,8 +747,8 @@ AD CODE RIGHT
646
 
647
  == Screenshots ==
648
 
649
- 1. Settings for one code block (Widget). Up to 16 blocks can be configured (up to 64 in <a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a>)
650
- 2. Settings for one code block (Before Paragraph)
651
  3. Alignment **Left**, **None** - None means default (usually left) aligned ad block with thin margin around
652
  4. Alignment **Right** - Right aligned ad block with thin margin around
653
  5. Alignment **Center** - Center aligned ad block with thin margin around
@@ -655,12 +756,43 @@ AD CODE RIGHT
655
  7. Alignment **Custom CSS** - Ad block with custom CSS (no margin around). You can use it for special effects (border, background, padding, margin, floating, etc.)
656
  8. Alignment **Float Left** - Left aligned ad block with thin margin around wrapped with text on the right
657
  9. Alignment **Float Right** - Right aligned ad block with thin margin around wrapped with text on the left
658
- 10. Ad Inserter settings + Header and Footer Scripts
659
  11. Post / Page Ad Inserter Exceptions
 
 
660
 
661
 
662
  == Changelog ==
663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664
  = 1.7.0 =
665
  - Bug fix: Shortcodes did not ignore post/static page exceptions
666
  - Slightly redesigned user interface
@@ -741,7 +873,7 @@ AD CODE RIGHT
741
 
742
  = 1.5.4 =
743
  * Many code optimizations and cosmetic changes
744
- * Header and Footer code blocks moved to settings tab (#)
745
  * Added support to process shortcodes of other plugins used in Ad Inserter code blocks
746
  * Added support to white-list or black-list individual urls
747
  * Added support to export and import settings for code blocks
@@ -867,6 +999,35 @@ AD CODE RIGHT
867
 
868
  == Upgrade Notice ==
869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870
  = 1.7.0 =
871
  Bug fix: Shortcodes did not ignore post/static page exceptions;
872
  Slightly redesigned user interface;
@@ -947,7 +1108,7 @@ Added support to export and import all Ad Inserter settings
947
 
948
  = 1.5.4 =
949
  Many code optimizations and cosmetic changes;
950
- Header and Footer code blocks moved to settings tab (#);
951
  Added support to process shortcodes of other plugins used in Ad Inserter code blocks;
952
  Added support to white-list or black-list individual urls;
953
  Added support to export and import settings for code blocks;
1
  === Ad Inserter ===
2
  Contributors: spacetime
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4
4
+ Tags: adsense, amazon, clickbank, cj, ad, ads, html, javascript, php, code, widget, sidebar, responsive, viewport, rotating, banner, banner rotation, multisite, contextual, shortcodes, widgets, header, footer, users, logged in, not logged in, mobile, desktop, phone, tablet, custom css, category, tag, filter, url, skip
5
  Requires at least: 4.0
6
+ Tested up to: 4.6.1
7
+ Stable tag: 1.7.0
8
  License: GPLv3
9
 
10
+ Insert any ad or HTML/Javascript/PHP code into Wordpress. Perfect for all kinds of ads. 16 code blocks, many display options and features.
11
 
12
  == Description ==
13
 
14
+ A simple yet powerful plugin to insert any ad or code into Wordpress. **Perfect for all kinds of ads.** Simply enter any ad or HTML/Javascript/PHP code and select where and how you want to display it.
 
 
 
 
15
 
16
  Ad Inserter supports up to 16 code blocks. Code block is any code (for example AdSense ad) that has to be inserted (displayed) at some position.
17
  Each code block can be configured to insert code at almost any position supported by Wordpress.
20
 
21
  * 16 code blocks
22
  * Syntax highlighting editor
23
+ * Code preview with visual CSS editor
24
  * Automatic positions: before/after post, content, paragraph or excerpt
25
+ * Manual positions: widgets, shortcodes, PHP function call
26
+ * Block alignment and style: left, center, right, float left, float right, custom CSS, no wrapping (leaves ad code as it is, otherwise it is wrapped by a div)
27
+ * Clearance options to avoid insertion near images or headers
28
  * PHP code processing
29
  * Server-side and client-side device detection (3 custom viewports)
30
+ * Black/White-list categories, tags, post IDs, urls, url parameters, referers
31
+ * Simple troubleshooting with many debugging functions to visualize inserted code blocks, available insertion positions, HTML tags, etc.
32
 
33
+ And there is also <a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a> if you need more than 16 code blocks, more than 3 viewports, export/import settings or additional multisite options.
34
 
35
  **Quick Start**
36
 
39
  * **Enable and use at least one display option** (Automatic Display, Widget, Shortcode, PHP function call)
40
  * **Enable display on at least one Wordpress page type** (Posts, Static pages, Homepage, Category pages, Search Pages, Archive pages)
41
  * For Posts and static pages **select default value On all Posts / On all Static pages** unless you really know what are you doing
42
+ * If you don't see inserted code block turn on **debuging functions**: Label inserted blocks, Show available positions for automatic display (Ad Inserter menu item in the Wordpress toolbar on the top of every post/page)
43
 
44
+ Few typical settings are described on the <a href="https://wordpress.org/plugins/ad-inserter/faq/">FAQ</a> page. Please make sure you have also read **WARNINGS** on the bottom of this page and instructions for **Debugging**.
45
 
46
  **Settings**
47
 
52
  * Shortcode
53
  * PHP function call
54
 
55
+ To rename code block click on the block name. To display code block (ad) at some position **you need to enable and use at least one display option**.
56
 
57
  Automatic Display Options:
58
 
84
  * Output of some other plugins
85
  * [After Post]
86
 
87
+ Of course, the final order of items depends also on other plugins. Ad Inserter is by default called as one of the last plugins. You can change Plugin priority on the settings page (tab *).
88
+
89
+ Please use **Show positions** function to see available positions for automatic display (Ad Inserter menu item in the Wordpress toolbar on the top of every post/page).
90
 
91
  Block Alignment and Style:
92
 
99
  * Float Left (ad on left with wrapped text on right)
100
  * Float Right (ad on right with wrapped text on left)
101
 
102
+ **[ Preview ]**
103
+
104
+ Ad Inserter has a very useful function that can help you to check if the ad code is working and to see how it will look like when it will be inserted. Click on the **Preview** button to open Preview window.
105
+ WARNING: Some adblockers may block code on the Ad Inserter preview window. If you see warning PAGE BLOCKED or you don't see your code and the widow elements are distorted, make sure you have disabled ad blockers.
106
+ On the top of the window there is visual CSS editor and four buttons and below there is CSS code of the wrapping div (which can be edited manually) and 'Block Alignment and Style' selection.
107
+
108
+ Below the settings there is a **preview of the saved code** between two dummy paragraphs. Here you can test various block alignments, visually edit margin and padding values of the wrapping div or write CSS code directly
109
+ and watch live preview. Highlight button highlights background, wrapping div margin and code area, while Reset button restores all the values to those of the current block.
110
+ You can resize the window (and refresh the page to reload ads) to check display with different screen widths. Once you are satisfied with alignment click on the Use button and the settings will be copied to the active block.
111
+
112
+ **Please note** that the code displayed here is the code that is saved for this block, while block name, alignment and style are taken from the current block settings (may not be saved).
113
+ No Wrapping style inserts the code as it is so margin and padding can't be set. However, you can use own HTML code for the block.
114
+
115
+ **Please note** that Preview window uses also Header and Footer code.
116
+
117
  Check <a href="https://wordpress.org/plugins/ad-inserter/screenshots/">screenshots</a> for explanation on alignment.
118
 
119
  **PLEASE NOTE:** If you are using **No Wrapping** style and need to hide code on some devices using client-side detection (CSS Media Queries) then you need to add appropriate class to your CSS code (ai-viewport-1, ai-viewport-2, ai-viewport-3).
125
 
126
  * Posts
127
  * Static pages
 
128
 
129
  Blog pages:
130
 
133
  * Search Pages
134
  * Tag / Archive pages
135
 
136
+ Insertion (located in the Misc section) is possible also for:
137
+
138
+ * 404 page (Error 404: Page not found)
139
+ * Feed
140
+
141
+ **Please Note** For shortcodes and PHP function calls it is possible to ignore enabled page types and use them on any page. See down for details.
142
+
143
  You can also disable ads on certain posts or static pages. For each code block on posts or static pages you first define default display settings for posts/pages page type. Then you can define post/page exceptions on the post/page editor page (check Ad Inserter Exceptions meta box below). Exceptions work only on page/post content (positions Before Content, Before Paragraph, After Paragraph, After Content). For one or few exceptions it is easier to first enable ads on All Posts/Static pages page types and then either white or black-list single url or few space-separated urls (click on the Lists button).
144
 
145
+ **PARAGRAPHS**
146
+
147
  Paragraph number for Automatic Display options Before and After Paragraph:
148
 
149
  * 0 means random paragraph position
150
  * value between 0 and 1 means relative position in post or page (e.g. 0.3 means paragraph 30% from top or bottom)
151
  * 1 or more means paragraph number
152
 
153
+ **[ Counting ]**
154
+
155
+ Paragraphs can be counted from top or from bottom. It is also possible to count only paragraphs that contain/do not contain certain text or count only paragraphs that have some minimum or maximum number of words.
156
+ If more than one text is defined (comma separated) and "contain" is selected then the paragraph must contain ALL texts.
157
+
158
+ Paragraphs are not counted inside `<blockquote>` elements. Of course, there is an option to enable counting also inside `<blockquote>`.
159
 
160
  **Please Note** Paragraph processing works on **every** post or page according to settings. Therefore, if you enable display also on blog pages (home, category, archive, search pages) and your theme does not display post excerpts but complete posts,
161
  Ad Inserter will by default insert code blocks into ALL posts on the blog page (according to settings). To enable insertion only into specific post(s) on blog pages define Filter. You can also leave Filter (click Misc button) to 0 (means all posts on the blog page) and define maximum number of insertions.
162
 
163
  You can also define paragraph HTML tags. Normally only `<p>` tags are used. If your post contains also `<div>` or header tags, you can define comma separated list of tags used to count paragraphs (e.g. **p, div, h2, h3**).
164
+
165
  **WARNING:** Each code block you insert in post adds one `<div>` block unelss you use **No wrapping** style. **Before Paragraph** will insert code before `<tag>`, **After Paragraph** will insert code after closing `</tag>`.
166
  **After Paragraph** will not work if you specify tag names that have no closing tags! Use # as tag if paragraphs have no tags and are separated with the `\r\n\r\n` characters.
167
 
168
+ Minimum number of paragraphs / Minimum/Maximum page/post words: do not display ad if the number of paragraphs or the number of words is below or above limit (used only for position Before or After selected paragraph).
169
+
170
+ **[ Clearance ]**
171
+
172
+ You can define parameters to avoid insertion at paragraph positions where above or below is some unwanted element (heading, image, title). This is useful to avoid inserting ads where they may not look good or where it is not allowed.
173
+
174
+ You can define in how many paragraphs above and below should specified text be avoided. And if the text is found you can choose to either skip insertion or try to shift insertion position up or down up to the specified number of paragraphs.
175
 
176
  Display only for posts published after N days checks the date when the post was published.
177
 
178
+ On every post/page there is a toolbar on the top. Ad Inserter menu item has few functions to visualize tags and positions for automatic insertion:
179
+
180
+ * Show HTML tags: visualizes HTML tags
181
+ * Show positions: shows available positions for automatic insertion. It uses paragraph tags for blocks configured for After or Before paragraph.
182
 
183
  Additional Options for code blocks:
184
 
185
+ PHP processing: Enabled or Disabled - Enable processing of PHP code. If there is a non-fatal error in the PHP code, it will not break the website.
186
 
187
  * Use {category}, {short_category}, {title}, {short_title}, {tag}, {smart_tag} or {search_query} tags to insert actual post data into code blocks
188
  * Use {author} for post author username or {author_name} for post author name to insert post author data into code blocks (**works only inside posts**)
204
  This is **useful in many cases where you can't remove unwanted insertions** of the code with other settings:
205
 
206
  * If you need to insert ad before the first, third and fith excerpt on the homepage you simply specify `1, 3, 5` for the filter.
207
+ * In some WP themes hooks (that call Ad Inserter insertion functions) are called more than once. In such case you might get unwanted insertions. Simply set the filter to the number of the wanted call(s). Use debugging function **Show positions** on every post/page to show available positions for automatic insertion with counters.
208
  * If you use adinserter PHP function and you don't want that for each time the functon is called on the page the code is inserted, you can simply filter calls.
209
  * If you oly need the first N calls (insertions) then leave filter to 0 and use Max N insertions instead.
210
 
211
  **Please Note** Paragraph processing works on **every** post or page according to settings. Therefore, if you enable display also on blog pages (home, category, archive, search pages) and your theme does not display post excerpts but complete posts,
212
  Ad Inserter will by default insert code blocks into ALL posts on the blog page (according to settings). To enable insertion only into specific post(s) on blog pages define Filter. You can also leave Filter to 0 (means all posts on the blog page) and define maximum number of insertions.
213
 
214
+ General tag: text used for {tag} and {smart_tag} if the post has no tags - useful for contextual ads - **works only inside posts/static pages!**
215
 
216
  Display Block to:
217
 
218
  * All users (default)
219
  * Logged in users
220
  * Not logged in users
221
+ * Administrators (usefull for testing/debugging)
222
 
223
  **WARNING:** If you are using caching this may not work as expected. The check works only when the page is generated and Ad Inserter is called. Make sure you have disabled caching when you are using such settings.
224
 
226
 
227
  Do not display ads in certain caregories e.g sport, news, science,... (black list) or display ads only in certain categories (white list):
228
  leave category list empty and set it to Black list to show ads in all categories.
229
+
230
+ **WARNING:** If category name contains commas or spaces, use category slug instead. Also make sure you have enabled display on **Category pages**.
231
 
232
  Do not display ads in posts with certain tags (black list) or display ads only in posts with certain tags (white list). Leave tag list empty and set it to Black list to show ads for all tags. Also make sure you have enabled display on **Tag / Archive pages**.
233
 
234
+ Do not display ads in posts/pages with certain post IDs (black list) or display ads only in posts with certain IDs (white list). Leave Post ID list empty and set it to Black list to show ads for all IDs.
235
+
236
+ Do not display ads on pages with certain urls (black list) or display ads only on pages with certain urls (white list): leave url list empty and set it to Black list to show ads for all urls.
237
  Url used here is everything starting form the `/` after the domain name. For example: if web address is `http://domain.com/lorem-ipsum`, url to white/black-list is `/lorem-ipsum`
238
  You can also use partial urls with *. To filter all urls starting with /url-start use `/url-start*`, to filter all urls that contain url-pattern use `*url-pattern*`, to filter all urls ending with url-end use `*url-end`.
239
  **WARNING:** Separate urls with SPACES.
240
 
241
+ Do not display ads on pages with certain url query parameters (black list) or display ads only on pages with certain url parameters (white list): leave url parameter list empty and set it to Black list to show ads for all url.
242
+ You can specifiy either parameters or parameters with values. For example for url `http://example.com?data=2&customer-id=22&device=0` you can define url parameters '`data, customer-id=22`' to display ad only for urls where there is `data` paramteter and `customer-id` parameter with value 22.
243
+ Separate parameters with comma.
244
+
245
  Do not display ads to users from certain referers (domains) e.g technorati.com, facebook.com,... (black list) or display ads only for certain referrers (white list): use # for no referer (direct visit),
246
  leave referrers list empty and set it to Black list to show ads for all referrers.
247
 
263
 
264
  **BUT BE CAREFUL:** Some ad networks (like AdSense) limit ads per page. The ads are still inserted (loaded and counted) for all devices, but for unwanted devices they are hidden by the browser using CSS media queries based on viewport widths.
265
 
266
+ Up to 3 viewport names and widths can be defined on the Ad Inserter Settings tab * (<a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a> supports up to 6 viewports). Default values are:
267
 
268
  * Desktop: 980 pixels or more
269
  * Tablet: from 768 pixels to 979 pixels
290
  There are 3 independent types of manual insertion of code block:
291
 
292
  * Widget - Widgets for all code blocks are enabled by default - simply drag **Ad Inserter** widget to any widget postition (e.g. Sidebar), select code block, save and you're done.
293
+ * Shortcode - Insert shortcode `[adinserter block="BLOCK_NUMBER"]` or `[adinserter name="BLOCK_NAME"]` into post or page HTML code to display block with BLOCK_NAME name or BLOCK_NUMBER number at this position. **PLEASE NOTE:** Shortcodes IGNORE post/static page exception settings! You can also insert shortcode that ignores enabled page types with `[adinserter block="BLOCK_NUMBER" ignore="page_type"]`
294
+ * PHP function call `<?php if (function_exists ('adinserter')) echo adinserter (BLOCK_NUMBER); ?>` - Insert code block BLOCK_NUMBER at any position in template file. You can also define Filter for PHP function - define which call(s) to the function will actually insert code. This is useful if you put a call to the `adinserter` function inside a loop in a template file (e.g. for homepage) and you need to insert ads only few times between posts. You can also use PHP function calls that ignore enabled page types `<?php if (function_exists ('adinserter')) echo adinserter (BLOCK_NUMBER, 'page_type'); ?>`
295
 
296
  **OTHER NOTES**
297
 
298
+ By default code blocks will not be inserted on Error 404 page (Page Not Found) and in feeds. Check '404 Page' or 'Feed' checkbox to enable code block on error 404 page or in feed.
299
 
300
+ **Ad Inserter general Settings - last tab**
301
 
302
  Wrapping divs for code blocks have 'code-block' and 'code-block-N' classes which can be used for custom styles. Class name 'code-block' can be changed in Ad Inserter settings. If you are using client-side device detection (CSS media queries) then the wrapping div for the code block will have also some of the following classes: ai-viewport-1, ai-viewport-2, ai-viewport-3.
303
 
304
  You can choose between many syntax highlighting themes.
305
 
306
+ By default Ad Inserter exceptions on posts/static pages are enabled only for administrators. You can define minimum user role for page/post Ad Inserter exceptions editing in Ad Inserter Settings (tab *).
307
 
308
  Default Ad Inserter plugin processing order is 99999. It is used to specify the order in which the plugin functions are executed. Lower numbers correspond with earlier execution. You can change this value if you have problems with the processing order of other plugins.
309
 
 
 
310
  Support for Special Code Blocks:
311
 
312
  * Header scripts (scripts in the `<header>` section)
314
 
315
  **WARNING:** Text selection, Copy and Paste functions with the syntax highlighting editor do not work on mobile devices. If you need these functions you can temporarily swich to **Simple editor** using the checkbox above the code box.
316
 
317
+ **WARNING:** Some adblockers may block Ad Inserter settings page. If you don't see normal tabs for code blocks or there is no save button, make sure you have whitelisted Ad Inserter settings page (select "Disable on this page" or "Don't run on this page").
318
+ However, since you are dealing with ads, it may make sense to temporarily disable adblockers in order to check and debug inserted ad codes.
319
+ Some security plugins like WP Security or Wordfence may also detect Ad Inserter page as problematic and prevent it from loading. Please be assured that this is false positive.
320
 
321
  **WARNING:** If you are using caching the inserted code may not appear imemdiately on the page. Make sure you have disabled caching when you are testing or debugging.
322
  Some caching plugins like <a href="https://wordpress.org/plugins/wp-super-cache/" target="_blank">WP Super Cache</a> have an option to disable caching for known users.
323
 
324
+ **WARNING:** If you are using caching some settings may not work as expected. For example, ad rotation, referer check, user check and server-side detection work only when the page is generated and Ad Inserter is called.
325
+ In such cases please make sure you have disabled caching.
326
+
327
+ **DEBUGGING**
328
+
329
+ Ad Inserter has many debugging functions that can help you to diagnose the problem when you don't see your ads at expected positions.
330
+
331
+ * Code preview: click on the Preview button for each code block to see how the ad or code will look like. On the Preview window click on the Highlight button to highlight code. If you don't see display of the code here it is very likely that the code is not working properly.
332
+ * Debugger Widget: Place Debugger widget in some widget area to see basic Wordpress page and Ad Inserter data (User status, Page Type, Post ID, Url, Referer, etc). With this widget you can also check saved block settings and client-side viewport name.
333
+
334
+ Each post/page has a Wordpress toolbar on the top. Ad Inserter menu item has the following debugging functions:
335
+
336
+ * Label Blocks: Each inserted block is labeled with a thin red border and red bar with block number, name and counters. Blocks that use client-side detection and are hidden are shown with blue bar and viewport name - resize the broswer to check display for other devices (or screen widths). If you see only red bar then this means that the block with your **code is inserted** but the code doesn't display anything.
337
+ * Show Positions: Enable this function to show available positions for automatic display. Displayed positions are based on the theme layout and configured paragraph counting. You can choose between all paragraph tag lists (or counting parameters) used for blocks configured for Before or After paragraph. If you click on the Show Positions menu item you'll see default paragraph positions for p tags.
338
+ * Show HTML tags: Enable this function to see HTML tags used in the post. Use this function to determine post structure in order to configure paragraph counting.
339
+ * Disable insertion: Use this function to temporarily disable insertion of code blocks - everything else on the page will look like the code blocks were processed and inserted.
340
+ * Log Processing: Use this function to log insertion process in order to determine why some code block was not inserted. The log is added as HTML comment at the end of the page - check page source
341
+
342
+ **WARNING:** Make sure **caching is disabled while debugging**! All debugging functions you enable will be visible only to you! Post/page debugging works by adding url parameters to the url (web address):
343
+
344
+ * Label Blocks: `ai-debug-blocks=1` (use `ai-debug-blocks=0` to turn it off)
345
+ * Show Positions: `ai-debug-positions=BLOCK_NUMBER`, 0 means default counting of paragraphs with p tags, numbers between 1 and 16 use paragraph counting as configured for the block (use `ai-debug-positions=` to turn it off)
346
+ * Show HTML tags: `ai-debug-tags=1` (use `ai-debug-tags=0` to turn it off)
347
+ * Disable insertion: `ai-debug-no-insertion=1` (use `ai-debug-no-insertion=0` to turn it off)
348
+ * Log Processing: `ai-debug-processing=1` (use `ai-debug-processing=0` to turn it off)
349
+
350
+ When browsing other pages on the website debuggins settings are temporarily saved (for the session). To disable all debugging functions click on the 'Ad Inserter' top menu item in the toolbar (or use `ai-debug=0`)
351
+
352
+ If you enable **Remote debugging** you can also allow other people using url parameters to see post/page with debugging data. Remote debugging option is located on the Ad Inserter Settings tab - Debugging tab below.
353
+ **Remote debugging** enables other, non-logged in users by using url parameters to see Debugger widget and code insertion debugging (blocks, positions, tags, processing).
354
+ Enable this option to allow other people to see Debugger widget, labeled blocks and positions in order to help you to diagnose problems. For logged in users debugging is always enabled.
355
+
356
+ **MULTISITE**
357
+
358
+ Ad Inserter supports multisite Wordpress installations. Normally, the plugin is available with settings and widgets to all the sites on the network.
359
+ <a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a> supports options to disable Setings page, widgets and post/page exceptions for sites (except the main one).
360
 
361
  **SUPPORT**
362
 
363
  If you experience problems with the Ad Inserter plugin you can ask for help on the <a href ="https://wordpress.org/support/plugin/ad-inserter">support forum</a>.
364
+ However, before you ask please use debugging functions described above. In almost all cases it is possible to determine the nature of the problem just by checking the debugging data.
365
+ Check also source code of the page. Some code for ads may not display anything, either because of errors in the ad code or because of ad network issues.
366
+ In order to be able to diagnose the problem and suggest actions or fix a bug, please do the following:
367
 
368
+ 1. Enable Remote debugging (located on the Ad Inserter Settings tab - Debugging).
 
 
369
 
370
+ 2. Clearly describe the problem. Describe what does not work as expected.
371
 
372
+ 3. Describe the settings and code blocks used.
373
 
374
+ 4. Provide web addresses (links) of the pages where the code from the settings above is not inserted properly.
375
 
376
+ Unless you provide the items listed above nobody can check your website, can't reproduce the problem and consequently can't help. Once the problem is fixed you can disable Remote debugging.
377
  Thank you very much for understanding.
378
 
379
  Please **support the plugin** if you like it:
380
 
381
+ * Write a nice <a href="https://wordpress.org/support/plugin/ad-inserter/reviews/">review</a>
382
  * <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4">Donate</a>
383
 
384
 
393
  3. Choose file, click on Install Now, activate it
394
  3. Go to Settings / Ad Inserter to configure it
395
 
396
+ **WARNING:** Some adblockers may block Ad Inserter settings page. If you don't see normal tabs for code blocks or there is no save button,
397
+ make sure you have whitelisted Ad Inserter settings page (select "Disable on this page" or "Don't run on this page").
398
+ However, since you are dealing with ads, it may make sense to temporarily disable adblockers in order to check and debug inserted ad codes.
399
+ Some security plugins like WP Security or Wordfence may also detect Ad Inserter page as problematic and prevent it from loading. Please be assured that this is false positive.
400
 
401
  **WARNING:** If you are using caching the inserted code may not appear imemdiately on the page. Make sure you have disabled caching when you are testing or debugging.
402
  Some caching plugins like <a href="https://wordpress.org/plugins/wp-super-cache/" target="_blank">WP Super Cache</a> have an option to disable caching for known users.
403
 
404
+ **WARNING:** If you are using caching some settings may not work as expected. For example, ad rotation, referer check, user check and server-side detection work only when the page is generated and Ad Inserter is called.
405
  In such cases please make sure you have disabled caching when you are using such settings.
406
 
407
  **WARNING:** Some code for ads may not display anything, either because of erros in the ad code or because of ad network issues.
411
  **Ad Inserter Pro Installation**
412
 
413
  <a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a> is an upgraded version of the freely available Ad Inserter.
414
+ In addition to all the features in the free version it offers 64 code blocks, 6 custom viewports, export and import of settings, additional multisite options and support via email.
415
 
416
  If you are using free Ad Inserter simply uninstall it. The Pro version will automatically import existing settings from the free version.
417
  After you receive the email with download link for the Ad Inserter Pro plugin, download it, go to Wordpress Plugins, Add New, Upload Plugin, Choose file, click on Install Now,
418
+ activate it and then click "Enter License Key" and enter license key you got in the email. If you need to edit license key go to Ad Inserter settings (tab *).
419
+
420
+ **Uninstall**:
421
+
422
+ If you deactivate and delete Ad Inserter the settings will stay in the database. To completely remove the plugin and settings do the following:
423
+
424
+ 1. Go to Ad Inserter Settings (tab *) and click on Reset All Settings
425
+ 2. Deactivate Ad Inserter
426
+ 3. Delete Ad Inserter plugin
427
 
428
  == Frequently Asked Questions ==
429
 
430
  = I have activated Ad Inserter. How can I use it? =
431
 
432
+ 1. After activation, click "Settings / Ad Inserter" to access the settings page
433
+ 2. Put ad (or any other HTML/Javascript/PHP) code into the ad box
434
+ 3. Set automatic display option
435
+ 5. Enable at least one page type: Posts, Static pages, Homepage, Category pages, Search Pages, Archive pages (some display options don't work on all page types)
436
+ 4. Save settings
437
 
438
 
439
  = Settings for **widget** =
512
  Use block 3 to display ads and make sure all 3 blocks are enabled for the same page types (Posts, Pages, Homepage, etc.).
513
 
514
 
515
+ = I use After Content display position but the code is inserted after the stuff provided by other plugins. How can I insert directly after post content?
516
+
517
+ This happens because Ad Inserter processes posts last and therefore "sees" also content added by other plugins.
518
+
519
+ Try to set Ad Inserter plugin priority to 10 (early processing, Ad Inserter settings - tab *).
520
+
521
+
522
  = How can I replace deprecated tags {adinserter n} for manual insertion with new ones [adinserter block="n"] in all posts? =
523
 
524
  Use <a href="https://wordpress.org/plugins/search-regex/" target="_blank">Search Regex</a> plugin to replace tags in all posts with few clicks. If you are not familiar with regular expressions simply use search and replace text for each code block. Use **Replace** to test replacements and when it works as expected use **Replace & Save**.
701
  For titles and search terms use tags. For example, the code below would display amazon products related to the post tags - check above for all possible tags.
702
 
703
 
704
+ Example for Amazon Native Shopping Ads (use your own tracking id):
705
 
706
  `<script type="text/javascript">
707
  amzn_assoc_placement = "adunit0";
747
 
748
  == Screenshots ==
749
 
750
+ 1. Settings for one code block (Before post). Up to 16 blocks can be configured (up to 64 in <a href="http://tinymonitor.com/ad-inserter-pro" target="_blank">Ad Inserter Pro</a>)
751
+ 2. Complete settings for one code block (Before Paragraph)
752
  3. Alignment **Left**, **None** - None means default (usually left) aligned ad block with thin margin around
753
  4. Alignment **Right** - Right aligned ad block with thin margin around
754
  5. Alignment **Center** - Center aligned ad block with thin margin around
756
  7. Alignment **Custom CSS** - Ad block with custom CSS (no margin around). You can use it for special effects (border, background, padding, margin, floating, etc.)
757
  8. Alignment **Float Left** - Left aligned ad block with thin margin around wrapped with text on the right
758
  9. Alignment **Float Right** - Right aligned ad block with thin margin around wrapped with text on the left
759
+ 10. Ad Inserter settings
760
  11. Post / Page Ad Inserter Exceptions
761
+ 12. Code preview with visual CSS editor
762
+ 13. Code preview with visual CSS editor - highlighted code
763
 
764
 
765
  == Changelog ==
766
 
767
+ = 2.0.0 =
768
+ - Redesigned user interface
769
+ - Added many debugging tools for easier troubleshooting
770
+ - New feature: Code preview tool with visual CSS editor
771
+ - New feature: Label inserted blocks
772
+ - New feature: Show available positions for automatic insertion
773
+ - New feature: Show HTML tags in posts/static pages
774
+ - New feature: Log Ad Inserter processing
775
+ - Improved loading speed of the settings page
776
+ - Improved block insertion processing speed
777
+ - Added support to avoid inserion near images, headers and other elements
778
+ - Added option to avoid insertion in feeds
779
+ - Added option to display code blocks only to administrators
780
+ - Added option for publishig date check for display positions Before/After Content
781
+ - Added option for server-side device check for header and footer code
782
+ - Added option for maximum page/post words
783
+ - Added option for maximum paragraph words
784
+ - Added option to black/white-list post IDs
785
+ - Added option to black/white-list url query parameters
786
+ - Added warning if the settings page is blocked by ad blocker
787
+ - Added warning if old cached version of javascript is loaded on the settings page
788
+ - Added support for multisite installations to disable settings, widgets and exceptions on network sites (Pro only)
789
+ - Block names can be edited by clicking on the name
790
+ - Filters now work also on posts and single pages
791
+ - CSS code for client-side detection moved to inline CSS
792
+ - Bug fix: Minimum user roles for exception editing was not calculated properly
793
+ - Bug fix: Server-side detection checkbox was not saved properly
794
+ - Many other minor bug fixes, code improvements and cosmetic changes
795
+
796
  = 1.7.0 =
797
  - Bug fix: Shortcodes did not ignore post/static page exceptions
798
  - Slightly redesigned user interface
873
 
874
  = 1.5.4 =
875
  * Many code optimizations and cosmetic changes
876
+ * Header and Footer code blocks moved to settings tab (*)
877
  * Added support to process shortcodes of other plugins used in Ad Inserter code blocks
878
  * Added support to white-list or black-list individual urls
879
  * Added support to export and import settings for code blocks
999
 
1000
  == Upgrade Notice ==
1001
 
1002
+ = 2.0.0 =
1003
+ Redesigned user interface;
1004
+ Added many debugging tools for easier troubleshooting;
1005
+ New feature: Code preview tool with visual CSS editor;
1006
+ New feature: Label inserted blocks;
1007
+ New feature: Show available positions for automatic insertion;
1008
+ New feature: Show HTML tags in posts/static pages;
1009
+ New feature: Log Ad Inserter processing;
1010
+ Improved loading speed of the settings page;
1011
+ Improved block insertion processing speed;
1012
+ Added support to avoid inserion near images, headers and other elements;
1013
+ Added option to avoid insertion in feeds;
1014
+ Added option to display code blocks only to administrators;
1015
+ Added option for publishig date check for display positions Before/After Content;
1016
+ Added option for server-side device check for header and footer code;
1017
+ Added option for maximum page/post words;
1018
+ Added option for maximum paragraph words;
1019
+ Added option to black/white-list post IDs;
1020
+ Added option to black/white-list url query parameters;
1021
+ Added warning if the settings page is blocked by ad blocker;
1022
+ Added warning if old cached version of javascript is loaded on the settings page;
1023
+ Added support for multisite installations to disable settings, widgets and exceptions on network sites (Pro only);
1024
+ Block names can be edited by clicking on the name;
1025
+ Filters now work also on posts and single pages;
1026
+ CSS code for client-side detection moved to inline CSS;
1027
+ Bug fix: Minimum user roles for exception editing was not calculated properly;
1028
+ Bug fix: Server-side detection checkbox was not saved properly;
1029
+ Many other minor bug fixes, code improvements and cosmetic changes;
1030
+
1031
  = 1.7.0 =
1032
  Bug fix: Shortcodes did not ignore post/static page exceptions;
1033
  Slightly redesigned user interface;
1108
 
1109
  = 1.5.4 =
1110
  Many code optimizations and cosmetic changes;
1111
+ Header and Footer code blocks moved to settings tab (*);
1112
  Added support to process shortcodes of other plugins used in Ad Inserter code blocks;
1113
  Added support to white-list or black-list individual urls;
1114
  Added support to export and import settings for code blocks;
screenshot-1.jpg CHANGED
Binary file
screenshot-10.jpg CHANGED
Binary file
screenshot-12.jpg ADDED
Binary file
screenshot-13.jpg ADDED
Binary file
screenshot-2.jpg CHANGED
Binary file
settings.php CHANGED
@@ -10,6 +10,11 @@ function generate_settings_form (){
10
  $save_url = preg_replace ("/&tab=\d+/", "", $save_url);
11
  }
12
 
 
 
 
 
 
13
  $subpage = 'main';
14
  $start = 1;
15
  $end = 16;
@@ -21,73 +26,65 @@ function generate_settings_form (){
21
  if ($active_tab != 0)
22
  if ($active_tab < $start || $active_tab > $end) $active_tab = $start;
23
 
24
- $adH = new ai_AdH();
25
- $adF = new ai_AdF();
26
-
27
- $adH->load_options (AI_HEADER_OPTION_NAME);
28
- $adF->load_options (AI_FOOTER_OPTION_NAME);
29
 
30
  $syntax_highlighter_theme = get_syntax_highlighter_theme ();
31
  $block_class_name = get_block_class_name ();
32
- $tag_debugging = get_tag_debugging ();
 
33
 
34
  ?>
35
- <style>
36
- .nav-tab {
37
- border-top-left-radius: 5px;
38
- border-top-right-radius: 5px;
39
- }
40
- .nav-tab-active, .nav-tab-active:hover {
41
- background: #fff;
42
- }
43
- .exceptions a {
44
- text-decoration: none;
45
- }
46
- .exceptions th.page {
47
- text-align: left;
48
- }
49
- .exceptions td.page {
50
- padding-right: 20px;
51
- }
52
- .exceptions td.id {
53
- padding-right: 10px;
54
- text-align: right;
55
- }
56
- .exceptions th.block, .exceptions td.block {
57
- text-align: center;
58
- width: 20px;
59
- }
60
-
61
- .small-button .ui-button-text-only .ui-button-text {
62
- padding: 0;
63
- }
64
- .responsive-table td {
65
- white-space: nowrap;
66
- }
67
- </style>
68
-
69
- <div id="ai-settings" style="margin-right: 16px; float: left; ">
70
-
71
- <div style="width: 735px; padding: 2px 8px 2px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
72
  <?php
73
- if (function_exists ('ai_settings_header')) ai_settings_header (); else { ?>
74
- <div style="float: right; text-align: right; margin: 8px 18px 0px 0;">
75
- <a style="text-decoration: none;" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4" target="_blank">Donate</a> to support free Ad Inserter development
76
- or <a style="text-decoration: none;" href="http://tinymonitor.com/ad-inserter-pro" target="_blank"><span style="font-weight: bold; color: #80f;">Go Pro</span></a> to get more than 16 blocks.
77
  </div>
78
- <div style="float: right; text-align: right; margin: 0px 18px 0px 0;">
79
- <a style="text-decoration: none;" href="http://tinymonitor.com/ad-inserter" target="_blank">Documentation</a> :: If you like Ad Inserter please write a nice review on the <a style="text-decoration: none;" href="https://wordpress.org/support/view/plugin-reviews/ad-inserter" target="_blank">Reviews</a> page.
 
 
 
80
  </div>
81
- <h2><?php echo AD_INSERTER_TITLE . ' ' . AD_INSERTER_VERSION ?></h2>
 
82
  <?php
83
  }
84
  ?>
85
  </div>
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  <?php
88
  if ($subpage == 'exceptions') {
89
  ?>
90
- <form action="<?php echo $save_url; ?>" method="post" id="ai-form" name="ai_form" style="float: left;" blocks="<?php echo AD_INSERTER_BLOCKS; ?>">
91
  <div id="ai-exceptions" style="padding: 8px 8px 8px 8px; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
92
 
93
  <table class="exceptions">
@@ -145,15 +142,22 @@ function generate_settings_form (){
145
  </table>
146
 
147
  </div>
148
- <?php wp_nonce_field ('save_adinserter_settings'); ?>
149
- </form>
150
  <?php
151
  } else {
152
- if (function_exists ('ai_settings_ranges')) ai_settings_ranges ($active_tab);
153
  ?>
154
- <form action="<?php echo $save_url; ?>" method="post" id="ai-form" name="ai_form" style="float: left;" start="<?php echo $start; ?>" end="<?php echo $end; ?>">
155
- <div id="ai-tab-container" style="width: 735px; padding: 8px 8px 8px 8px; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
156
- <div id="dummy-tabs" style="height: <?php echo 29; ?>px; padding: .2em .2em 0;"></div>
 
 
 
 
 
 
 
 
 
 
157
  <ul id="ai-tabs" style="display: none;">
158
  <?php
159
 
@@ -247,15 +251,21 @@ function generate_settings_form (){
247
  if ($adH->get_enable_manual () && $adH->get_ad_data() != "") $title_hf .= ", Header code";
248
  if ($adF->get_enable_manual () && $adF->get_ad_data() != "") $title_hf .= ", Footer code";
249
 
250
- if (($adH->get_enable_manual () && $adH->get_ad_data() != "") ||
251
- ($adF->get_enable_manual () && $adF->get_ad_data() != ""))
252
- $style_hf = "font-weight: bold; color: #e44;"; else $style_hf = "";
253
  ?>
254
- <li id="ai-tab0" class="ai-tab" title="Ad Inserter Settings<?php echo $title_hf ?>"><a href="#tab-0"><span style="<?php echo $style_hf ?>">#</span></a></li>
255
  </ul>
256
 
257
  <?php
258
  for ($ad_number = $start; $ad_number <= $end; $ad_number ++){
 
 
 
 
 
 
259
  $obj = $block_object [$ad_number];
260
 
261
  $show_devices = $obj->get_detection_client_side () == AD_SETTINGS_CHECKED || $obj->get_detection_server_side () == AD_SETTINGS_CHECKED;
@@ -263,72 +273,85 @@ function generate_settings_form (){
263
 
264
  $cat_list = $obj->get_ad_block_cat();
265
  $tag_list = $obj->get_ad_block_tag();
 
266
  $url_list = $obj->get_ad_url_list();
 
267
  $domain_list = $obj->get_ad_domain_list();
268
- $show_lists = $cat_list != '' || $tag_list != '' || $url_list != '' || $domain_list != '';
269
  if ($show_lists) $lists_style = "font-weight: bold; color: #66f;"; else $lists_style = "";
270
 
271
  $show_manual = $manual [$ad_number];
272
  if ($show_manual) $manual_style = "font-weight: bold; color: " . ($manual_widget [$ad_number] || empty ($sidebars_with_widget [$ad_number]) ? "#66f;" : "#e44;"); else $manual_style = "";
273
 
274
- $show_misc = $obj->get_maximum_insertions () != 0 || $obj->get_call_filter() != 0 || $obj->get_display_for_users() != AD_DISPLAY_ALL_USERS;
275
  if ($show_misc) $misc_style = "font-weight: bold; color: #66f;"; else $misc_style = "";
276
 
277
- $save_button_text = "Save All Settings";
278
- ?>
279
-
280
- <div id="tab-<?php echo $ad_number; ?>" style="padding: 0;">
281
- <div style="padding: 10px 0 0 4px;">
282
- <h3><?php echo $ad_number, ". ", $obj->get_ad_name(); ?></h3>
283
- </div>
284
-
285
- <div style="float: right; padding: 1px 5px;">
286
- <?php if (function_exists ('ai_settings_buttons')) ai_settings_buttons ($ad_number, $save_button_text, $start, $end); ?>
287
- <input style="display: none; border-radius: 5px; font-weight: bold;" name="<?php echo AI_FORM_SAVE; ?>" value="<?php echo $save_button_text; ?>" type="submit" />
288
- </div>
289
 
290
- <div style="padding:0px 8px 16px 16px;">
291
- Block Name: <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_NAME, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_ad_name() ?>" size="56" maxlength="100" />
292
- </div>
293
 
294
- <?php if (function_exists ('ai_settings_container')) ai_settings_container ($ad_number, $obj); ?>
 
 
 
 
 
 
 
 
295
 
296
- <div style="display: inline-block; padding: 1px 10px; float: right;">
297
- <input type="hidden" style="border-radius: 5px;" name="<?php echo AI_OPTION_PROCESS_PHP, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
298
- <input type="checkbox" style="border-radius: 5px;" name="<?php echo AI_OPTION_PROCESS_PHP, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" id="process-php-<?php echo $ad_number; ?>" <?php if ($obj->get_process_php () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
299
- <label for="process-php-<?php echo $ad_number; ?>" title="Process PHP code in block">Process PHP</label>
300
- </div>
301
 
302
- <div style="display: inline-block; padding: 1px 10px; float: right;">
303
- <input type="checkbox" style="border-radius: 5px;" value="0" id="simple-editor-<?php echo $ad_number; ?>" />
304
- <label for="simple-editor-<?php echo $ad_number; ?>" title="Toggle Syntax Highlighting / Simple editor for mobile devices">Simple editor</label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  </div>
306
 
307
- <div style="padding-left:16px;">
308
- HTML / Javascript / PHP code (separate rotating versions with |rotate| )
309
- </div>
310
 
311
- <div style="padding:8px;">
312
- <textarea id="block-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_CODE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" style="background-color:#F9F9F9; font-family: Courier, 'Courier New', monospace; font-weight: bold; width: 719px; height: 384px;"><?php echo esc_textarea ($obj->get_ad_data()); ?></textarea>
313
  </div>
314
 
315
- <div style="padding:8px 8px 8px 8px;">
316
- <!-- <div style="float: left;">-->
317
- <!-- <button id="preview-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 0px;" title="Preview saved code above" nonce="<?php echo wp_create_nonce ("adinserter_preview"); ?>">Preview</button>-->
318
- <!-- </div>-->
 
 
 
 
319
  <div style="float: right;">
320
- <button id="misc-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 0px;" title="Limit / filter insertions, general tag, check for logged-in users"><span style="<?php echo $misc_style; ?>">Misc</span></button>
321
- <button id="device-detection-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 0px;" title="Client/Server-side Device Detection (Desktop, Tablet, Phone,...)"><span style="<?php echo $devices_style; ?>">Devices</span></button>
322
- <button id="lists-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 0px;" title="White/Black-list Category, Tag, Url or Referer (domain)"><span style="<?php echo $lists_style; ?>">Lists</span></button>
323
- <button id="manual-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 0px;" title="Widget, Shortcode and PHP function call"><span style="<?php echo $manual_style; ?>">Manual Display</span></button>
324
  </div>
325
  <div style="clear: both;"></div>
326
  </div>
327
 
328
- <div style="padding:8px 8px 8px 8px;">
329
  <div style="float: left;">
330
  Automatic Display:
331
- <select style="border-radius: 5px; margin-bottom: 3px;" id="display-type-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_DISPLAY_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" style="width:200px">
332
  <option value="<?php echo AD_SELECT_NONE; ?>" <?php echo ($obj->get_display_type()==AD_SELECT_NONE) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_SELECT_NONE; ?></option>
333
  <option value="<?php echo AD_SELECT_BEFORE_POST; ?>" <?php echo ($obj->get_display_type()==AD_SELECT_BEFORE_POST) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_SELECT_BEFORE_POST; ?></option>
334
  <option value="<?php echo AD_SELECT_BEFORE_CONTENT; ?>" <?php echo ($obj->get_display_type()==AD_SELECT_BEFORE_CONTENT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_SELECT_BEFORE_CONTENT; ?></option>
@@ -343,7 +366,7 @@ function generate_settings_form (){
343
 
344
  <div style="float: right;">
345
  Block Alignment and Style:&nbsp;&nbsp;&nbsp;
346
- <select style="border-radius: 5px;" id="block-alignment-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_ALIGNMENT_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" style="width:120px">
347
  <option value="<?php echo AD_ALIGNMENT_NO_WRAPPING; ?>" <?php echo ($obj->get_alignment_type()==AD_ALIGNMENT_NO_WRAPPING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_NO_WRAPPING; ?></option>
348
  <option value="<?php echo AD_ALIGNMENT_CUSTOM_CSS; ?>" <?php echo ($obj->get_alignment_type()==AD_ALIGNMENT_CUSTOM_CSS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_CUSTOM_CSS; ?></option>
349
  <option value="<?php echo AD_ALIGNMENT_NONE; ?>" <?php echo ($obj->get_alignment_type()==AD_ALIGNMENT_NONE) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_NONE; ?></option>
@@ -354,44 +377,36 @@ function generate_settings_form (){
354
  <option value="<?php echo AD_ALIGNMENT_FLOAT_RIGHT; ?>" <?php echo ($obj->get_alignment_type()==AD_ALIGNMENT_FLOAT_RIGHT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_FLOAT_RIGHT; ?></option>
355
  </select>
356
  &nbsp;
357
- <button id="show-css-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 0px;" title="Show CSS code">Show CSS</button>
358
  </div>
359
  <div style="clear: both;"></div>
360
- </div>
361
 
362
- <div class="responsive-table" id="css-code-<?php echo $ad_number; ?>" style="min-height: 31px; padding:8px 8px 8px 8px; margin: 8px 0 0 5px; height: 24px; display: none;">
363
- <table>
364
- <tr>
365
- <td style="vertical-align: middle;">
366
- <span id="css-label-<?php echo $ad_number; ?>" style="height: 22px; vertical-align: middle; margin: 4px 0 0 0;">CSS &nbsp;</span>
367
- </td>
368
- <td style="width: 100%;">
369
- <input id="custom-css-<?php echo $ad_number; ?>" style="width: 100%; vertical-align: middle; border-radius: 4px; display: none; font-family: Courier, 'Courier New', monospace; font-weight: bold;" type="text" name="<?php echo AI_OPTION_CUSTOM_CSS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_custom_css(); ?>" size="70" maxlength="160" title="Custom CSS code for wrapping div" />
370
- <span style="width: 100%; vertical-align: middle; margin: 3px 0 0 7px; font-family: Courier, 'Courier New', monospace; font-size: 12px; font-weight: bold;">
371
- <span id="css-no-wrapping-<?php echo $ad_number; ?>" style="height: 18px; vertical-align: middle; display: none;"></span>
372
- <span id="css-none-<?php echo $ad_number; ?>" style="height: 18px; vertical-align: middle; display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_NONE); ?></span>
373
- <span id="css-left-<?php echo $ad_number; ?>" style="height: 18px; vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_LEFT); ?></span>
374
- <span id="css-right-<?php echo $ad_number; ?>" style="height: 18px; vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_RIGHT); ?></span>
375
- <span id="css-center-<?php echo $ad_number; ?>" style="height: 18px; vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_CENTER); ?></span>
376
- <span id="css-float-left-<?php echo $ad_number; ?>" style="height: 18px; vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_FLOAT_LEFT); ?></span>
377
- <span id="css-float-right-<?php echo $ad_number; ?>" style="height: 18px; vertical-align: middle;display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_FLOAT_RIGHT); ?></span>
378
- </span>
379
- </td>
380
- <td>
381
- <button id="edit-css-button-<?php echo $ad_number; ?>" type="button" style="float: right; margin-left: 7px;" title="Edit CSS code">Edit</button>
382
- </td>
383
- </tr>
384
- </table>
385
  </div>
386
 
387
- <div class="responsive-table" style="padding:8px 8px 8px 8px; margin: 8px 0 0 5px; border: 1px solid #ddd; border-radius: 5px;">
388
  <table>
389
  <tr>
390
  <td style="width: 70%">
391
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_POSTS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
392
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_POSTS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" id="display-posts-<?php echo $ad_number; ?>" title="Enable or disable display on posts" <?php if ($obj->get_display_settings_post()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
393
 
394
- <select style="border-radius: 5px; margin: 0 0 3px 10px;" title="Default display for posts - exceptions can be configured on individual post editor pages" id="enabled-on-which-posts-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_ENABLED_ON_WHICH_POSTS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" style="width:160px">
395
  <option value="<?php echo AD_ENABLED_ON_ALL; ?>" <?php echo ($obj->get_ad_enabled_on_which_posts()==AD_ENABLED_ON_ALL) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ON_ALL; ?></option>
396
  <option value="<?php echo AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED; ?>" <?php echo ($obj->get_ad_enabled_on_which_posts()==AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED; ?></option>
397
  <option value="<?php echo AD_ENABLED_ONLY_ON_SELECTED; ?>" <?php echo ($obj->get_ad_enabled_on_which_posts()==AD_ENABLED_ONLY_ON_SELECTED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ONLY_ON_SELECTED; ?></option>
@@ -403,12 +418,12 @@ function generate_settings_form (){
403
  </td>
404
  <td style="padding-left: 8px;">
405
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_HOMEPAGE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
406
- <input id= "display-homepage-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_HOMEPAGE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_display_settings_home()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
407
  <label for="display-homepage-<?php echo $ad_number; ?>" title="Enable or disable display on homepage: latest posts (including sub-pages), static page or theme homepage">Homepage</label>
408
  </td>
409
  <td style="padding-left: 8px;">
410
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_CATEGORY_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
411
- <input id= "display-category-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_CATEGORY_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_display_settings_category()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
412
  <label for="display-category-<?php echo $ad_number; ?>" title="Enable or disable display on category blog pages (including sub-pages)">Category pages</label>
413
  </td>
414
  </tr>
@@ -416,9 +431,9 @@ function generate_settings_form (){
416
  <tr>
417
  <td style="width: 70%">
418
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
419
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" id="display-pages-<?php echo $ad_number; ?>" title="Enable or disable display on static pages" <?php if ($obj->get_display_settings_page()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
420
 
421
- <select style="border-radius: 5px; margin: 0 0 3px 10px;" title="Default display for pages - exceptions can be configured on individual page editor pages" id="enabled-on-which-pages-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_ENABLED_ON_WHICH_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" style="width:160px">
422
  <option value="<?php echo AD_ENABLED_ON_ALL; ?>" <?php echo ($obj->get_ad_enabled_on_which_pages()==AD_ENABLED_ON_ALL) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ON_ALL; ?></option>
423
  <option value="<?php echo AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED; ?>" <?php echo ($obj->get_ad_enabled_on_which_pages()==AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED; ?></option>
424
  <option value="<?php echo AD_ENABLED_ONLY_ON_SELECTED; ?>" <?php echo ($obj->get_ad_enabled_on_which_pages()==AD_ENABLED_ONLY_ON_SELECTED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ONLY_ON_SELECTED; ?></option>
@@ -427,69 +442,235 @@ function generate_settings_form (){
427
  <label for="display-pages-<?php echo $ad_number; ?>">Static pages</label>
428
  </td>
429
  <td style="padding-left: 8px;">
430
- <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_404, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
431
- <input style="border-radius: 5px;" id="enable-404-<?php echo $ad_number; ?>" type="checkbox" name="<?php echo AI_OPTION_ENABLE_404, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_enable_404 () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
432
- <label for="enable-404-<?php echo $ad_number; ?>" title="Enable or disable display on page for Error 404: Page not found">404 page</label>
433
  </td>
434
  <td style="padding-left: 8px;">
435
  <input style="border-radius: 5px;;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_SEARCH_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
436
- <input id= "display-search-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_SEARCH_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_display_settings_search()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
437
  <label for="display-search-<?php echo $ad_number; ?>" title="Enable or disable display on search blog pages">Search pages</label>
438
  </td>
439
  <td style="padding-left: 8px;">
440
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
441
- <input id= "display-archive-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_display_settings_archive()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
442
  <label for="display-archive-<?php echo $ad_number; ?>" title="Enable or disable display on tag or archive blog pages">Tag / Archive pages</label>
443
  </td>
444
  </tr>
445
  </table>
446
  </div>
447
 
448
- <div id="paragraph-settings-<?php echo $ad_number; ?>" style="padding:8px 8px 0 8px; margin: 8px 0 8px 5px; border: 1px solid #ddd; border-radius: 5px;">
449
- <div style="margin: 4px 0 8px 0;">
450
- Paragraph number <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_PARAGRAPH_NUMBER, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_paragraph_number() ?>" size="2" maxlength="4" /> &nbsp; 0 means random paragraph, <span title="0.2 means paragraph at 20% of page height, 0.5 means paragraph halfway down the page, 0.9 means paragraph at 90% of page height, etc.">value between 0 and 1 means relative position on page.</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  </div>
452
- <div style="margin: 4px 0 8px 0; ">
453
- Count
454
- <select style="border-radius: 5px;" name="<?php echo AI_OPTION_DIRECTION_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>">
455
- <option value="<?php echo AD_DIRECTION_FROM_TOP; ?>" <?php echo ($obj->get_direction_type()==AD_DIRECTION_FROM_TOP) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DIRECTION_FROM_TOP; ?></option>
456
- <option value="<?php echo AD_DIRECTION_FROM_BOTTOM; ?>" <?php echo ($obj->get_direction_type()==AD_DIRECTION_FROM_BOTTOM) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DIRECTION_FROM_BOTTOM; ?></option>
457
- </select>
458
- paragraphs with tags
459
- <input style="border-radius: 5px;" title="Comma separated HTML tags, usually only 'p' tags are used" type="text" name="<?php echo AI_OPTION_PARAGRAPH_TAGS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_paragraph_tags(); ?>" size="14" maxlength="50"/>&nbsp;&nbsp;&nbsp;
460
- Minimum number of paragraphs <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_MIN_PARAGRAPHS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_paragraph_number_minimum() ?>" size="2" maxlength="3" />&nbsp;&nbsp;&nbsp;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
  </div>
462
- <div style="margin: 4px 0 8px 0; ">
463
- Count only paragraphs that
464
- <select style="border-radius: 5px; margin-bottom: 3px;" name="<?php echo AI_OPTION_PARAGRAPH_TEXT_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>">
465
- <option value="<?php echo AD_CONTAIN; ?>" <?php echo ($obj->get_paragraph_text_type() == AD_CONTAIN) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_CONTAIN; ?></option>
466
- <option value="<?php echo AD_DO_NOT_CONTAIN; ?>" <?php echo ($obj->get_paragraph_text_type() == AD_DO_NOT_CONTAIN) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DO_NOT_CONTAIN; ?></option>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
467
  </select>
468
- <input style="border-radius: 5px;" title="Comma separated text" type="text" name="<?php echo AI_OPTION_PARAGRAPH_TEXT, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_paragraph_text() ?>" size="26" maxlength="200" />
469
- with at least <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_MIN_PARAGRAPH_WORDS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_minimum_paragraph_words() ?>" size="4" maxlength="5" /> words
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  </div>
471
- <div id="post-settings-<?php echo $ad_number; ?>" style="margin: 4px 0 8px 0;">
472
- Minimum page/post words <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_MIN_WORDS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_minimum_words() ?>" size="4" maxlength="6" /> &nbsp;&nbsp;&nbsp;
473
- Display <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_AFTER_DAYS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_ad_after_day() ?>" size="2" maxlength="3" title="0 means publish immediately" /> days after post is published &nbsp;&nbsp;&nbsp;
 
 
 
 
 
 
 
 
474
  </div>
475
  </div>
476
 
477
- <div class="responsive-table" id="list-settings-<?php echo $ad_number; ?>" style="padding:8px 8px 8px 8px; margin: 8px 0 8px 5px; border: 1px solid #ddd; border-radius: 5px; <?php if (!$show_lists) echo 'display: none;'; ?>">
478
- <table style="padding:8px 8px 10px 8px;">
479
  <tbody>
480
  <tr>
481
  <td style="padding-right: 7px;">
482
  Categories
483
  </td>
484
  <td style="padding-right: 7px; width: 70%;">
485
- <input style="border-radius: 5px; width: 100%;" title="Comma separated category names - if category name contains commas use category slug instead" type="text" name="<?php echo AI_OPTION_CATEGORY_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $cat_list; ?>" size="54" maxlength="500" />
486
  </td>
487
  <td style="padding-right: 7px;">
488
- <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_CATEGORY_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="category-blacklist-<?php echo $ad_number; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_ad_block_cat_type() == AD_BLACK_LIST) echo 'checked '; ?> />
489
  <label for="category-blacklist-<?php echo $ad_number; ?>" title="Blacklist categories"><?php echo AD_BLACK_LIST; ?></label>
490
  </td>
491
  <td>
492
- <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_CATEGORY_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="category-whitelist-<?php echo $ad_number; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_ad_block_cat_type() == AD_WHITE_LIST) echo 'checked '; ?> />
493
  <label for="category-whitelist-<?php echo $ad_number; ?>" title="Whitelist categories"><?php echo AD_WHITE_LIST; ?></label>
494
  </td>
495
  </tr>
@@ -497,47 +678,79 @@ function generate_settings_form (){
497
  <td style="padding-right: 7px;">
498
  Tags
499
  </td>
500
- <td style="padding-right: 7px; width: 70%;">
501
- <input style="border-radius: 5px; width: 100%;" title="Comma separated tags" type="text" name="<?php echo AI_OPTION_TAG_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $tag_list; ?>" size="54" maxlength="500"/>
502
  </td>
503
  <td style="padding-right: 7px;">
504
- <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_TAG_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="tag-blacklist-<?php echo $ad_number; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_ad_block_tag_type() == AD_BLACK_LIST) echo 'checked '; ?> />
505
  <label for="tag-blacklist-<?php echo $ad_number; ?>" title="Blacklist tags"><?php echo AD_BLACK_LIST; ?></label>
506
  </td>
507
  <td>
508
- <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_TAG_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="tag-whitelist-<?php echo $ad_number; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_ad_block_tag_type() == AD_WHITE_LIST) echo 'checked '; ?> />
509
  <label for="tag-whitelist-<?php echo $ad_number; ?>" title="Whitelist tags"><?php echo AD_WHITE_LIST; ?></label>
510
  </td>
511
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
512
  <tr>
513
  <td style="padding-right: 7px;">
514
  Urls
515
  </td>
516
- <td style="padding-right: 7px;" width: 70%;>
517
- <input style="border-radius: 5px; width: 100%;" title="SPACE separated urls (page addresses) starting with / after domain name (e.g. /permalink-url, use only when you need to taget a specific url not accessible by other means). You can also use partial urls with * (/url-start*. *url-pattern*, *url-end)" type="text" name="<?php echo AI_OPTION_URL_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $url_list; ?>" size="54" maxlength="500"/>
518
  </td>
519
  <td style="padding-right: 7px;">
520
- <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_URL_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="url-blacklist-<?php echo $ad_number; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_ad_url_list_type() == AD_BLACK_LIST) echo 'checked '; ?> />
521
  <label for="url-blacklist-<?php echo $ad_number; ?>" title="Blacklist urls"><?php echo AD_BLACK_LIST; ?></label>
522
  </td>
523
  <td>
524
- <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_URL_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="url-whitelist-<?php echo $ad_number; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_ad_url_list_type() == AD_WHITE_LIST) echo 'checked '; ?> />
525
  <label for="url-whitelist-<?php echo $ad_number; ?>" title="Whitelist urls"><?php echo AD_WHITE_LIST; ?></label>
526
  </td>
527
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
  <tr>
529
  <td style="padding-right: 7px;">
530
  Referers
531
  </td>
532
- <td style="padding-right: 7px;" width: 70%;>
533
- <input style="border-radius: 5px; width: 100%;" title="Comma separated domains, use # for no referer" type="text" name="<?php echo AI_OPTION_DOMAIN_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $domain_list; ?>" size="54" maxlength="500"/>
534
  </td>
535
  <td style="padding-right: 7px;">
536
- <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_DOMAIN_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="referer-blacklist-<?php echo $ad_number; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_ad_domain_list_type() == AD_BLACK_LIST) echo 'checked '; ?> />
537
  <label for="referer-blacklist-<?php echo $ad_number; ?>" title="Blacklist referers"><?php echo AD_BLACK_LIST; ?></label>
538
  </td>
539
  <td>
540
- <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_DOMAIN_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="referer-whitelist-<?php echo $ad_number; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_ad_domain_list_type() == AD_WHITE_LIST) echo 'checked '; ?> />
541
  <label for="referer-whitelist-<?php echo $ad_number; ?>" title="Whitelist referers"><?php echo AD_WHITE_LIST; ?></label>
542
  </td>
543
  </tr>
@@ -545,12 +758,12 @@ function generate_settings_form (){
545
  </table>
546
  </div>
547
 
548
- <div id="manual-settings-<?php echo $ad_number; ?>" class="small-button" style="padding:7px; margin: 8px 0 8px 5px; text-align: left; border: 1px solid #ddd; border-radius: 5px; <?php if (!$show_manual) echo 'display: none;'; ?>">
549
  <table>
550
  <tr>
551
  <td style="padding: 4px 10px 4px 0;">
552
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_WIDGET, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
553
- <input style="border-radius: 5px;" id="enable-widget-<?php echo $ad_number; ?>" type="checkbox" name="<?php echo AI_OPTION_ENABLE_WIDGET, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_enable_widget () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
554
  <label for="enable-widget-<?php echo $ad_number; ?>" title="Enable or disable widget for this code block">
555
  Widget
556
  </label>
@@ -563,12 +776,12 @@ function generate_settings_form (){
563
  <tr>
564
  <td style="padding: 4px 10px 4px 0;">
565
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_MANUAL, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
566
- <input style="border-radius: 5px;" type="checkbox" id="enable-shortcode-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_ENABLE_MANUAL, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_enable_manual () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
567
  <label for="enable-shortcode-<?php echo $ad_number; ?>" title="Enable or disable shortcode for manual insertion of this code block in posts and pages">
568
  Shortcode
569
  </label>
570
  </td>
571
- <td>
572
  <pre style= "margin: 0; display: inline; color: blue; font-size: 11px;">[adinserter block="<?php echo $ad_number; ?>"]</pre>
573
  or <pre style= "margin: 0; display: inline; color: blue;">[adinserter name="<?php echo $obj->get_ad_name(); ?>"]</pre>
574
  </td>
@@ -576,43 +789,82 @@ function generate_settings_form (){
576
  <tr>
577
  <td style="padding: 4px 10px 4px 0;">
578
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_PHP_CALL, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
579
- <input style="border-radius: 5px;" id="enable-php-call-<?php echo $ad_number; ?>" type="checkbox" name="<?php echo AI_OPTION_ENABLE_PHP_CALL, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_enable_php_call () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
580
  <label for="enable-php-call-<?php echo $ad_number; ?>" title="Enable or disable PHP function call to insert this code block at any position in template file. If function is disabled for block it will return empty string.">
581
  PHP function
582
  </label>
583
  </td>
584
- <td>
585
- <pre style= "margin: 0; display: inline; color: blue; font-size: 11px;">&lt;?php if (function_exists ('adinserter')) echo adinserter (<?php echo $ad_number; ?>); ?&gt;</pre>
586
  </td>
587
  </tr>
588
  </table>
589
  </div>
590
 
591
- <div id="misc-settings-<?php echo $ad_number; ?>" style="margin: 8px 0 8px 5px; padding:8px; border: 1px solid #ddd; border-radius: 5px; <?php if (!$show_misc) echo 'display: none;'; ?>">
592
- Max <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_MAXIMUM_INSERTIONS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_maximum_insertions () ?>" size="2" maxlength="3" title="0 means no limit" /> insertions &nbsp;&nbsp;
593
- Filter <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_EXCERPT_NUMBER, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_call_filter() ?>" title= "Filter insertions by specifying wanted calls for this block - single number or comma separated numbers, 0 means all / no limits" size="6" maxlength="20" /> &nbsp;&nbsp;
594
- General tag <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_GENERAL_TAG, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="<?php echo $obj->get_ad_general_tag() ?>" size="10" maxlength="40" title="Used for {tags} when no page data is found" /> &nbsp;&nbsp;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
595
 
596
- <div style="float: right;">
597
- Display for
598
- <select style="border-radius: 5px; margin-bottom: 3px;" id="display-for-users-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_DISPLAY_FOR_USERS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" style="width:160px">
599
- <option value="<?php echo AD_DISPLAY_ALL_USERS; ?>" <?php echo ($obj->get_display_for_users()==AD_DISPLAY_ALL_USERS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_ALL_USERS; ?></option>
600
- <option value="<?php echo AD_DISPLAY_LOGGED_IN_USERS; ?>" <?php echo ($obj->get_display_for_users()==AD_DISPLAY_LOGGED_IN_USERS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_LOGGED_IN_USERS; ?></option>
601
- <option value="<?php echo AD_DISPLAY_NOT_LOGGED_IN_USERS; ?>" <?php echo ($obj->get_display_for_users()==AD_DISPLAY_NOT_LOGGED_IN_USERS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_NOT_LOGGED_IN_USERS; ?></option>
602
- </select>
603
- users
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  </div>
605
 
606
- <div style="clear: both;"></div>
607
  </div>
608
 
609
- <div id="device-detection-settings-<?php echo $ad_number; ?>" style="padding:8px 8px 8px 8px; margin: 8px 0 8px 5px; border: 1px solid #ddd; border-radius: 5px; <?php if (!$show_devices) echo 'display: none;'; ?>">
610
  <table>
611
  <tr>
612
  <td>
613
  <div style="margin-bottom: 5px;">
614
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DETECT_CLIENT_SIDE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
615
- <input id="client-side-detection-<?php echo $ad_number; ?>" style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DETECT_CLIENT_SIDE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" <?php if ($obj->get_detection_client_side ()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
616
  <label for="client-side-detection-<?php echo $ad_number; ?>">Use client-side detection to display only on:</label>
617
  </div>
618
 
@@ -625,7 +877,7 @@ function generate_settings_form (){
625
  ?>
626
  <div style="margin: 8px 0;">
627
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DETECT_VIEWPORT, '_', $viewport, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
628
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DETECT_VIEWPORT, '_', $viewport, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="viewport-<?php echo $viewport, "-", $ad_number; ?>" value="1" <?php if ($obj->get_detection_viewport ($viewport)==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
629
  <label for="viewport-<?php echo $viewport, "-", $ad_number; ?>" title="Device min width <?php echo get_viewport_width ($viewport); ?> px"><?php echo $viewport_name; ?></label>
630
  </div>
631
  <?php
@@ -635,11 +887,11 @@ function generate_settings_form (){
635
  </div>
636
  </td><td style="padding-left: 40px; vertical-align: top;">
637
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DETECT_SERVER_SIDE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
638
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DETECT_SERVER_SIDE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="server-side-detection-<?php echo $viewport_name; ?>" value="1" <?php if ($obj->get_detection_server_side ()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
639
- <label for="server-side-detection-<?php echo $viewport_name; ?>">Use server-side detection to display only on </label>
640
 
641
- <div style="margin: 0 0 10px 40px;">
642
- <select style="border-radius: 5px; margin-bottom: 3px;" id="display-for-devices-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_DISPLAY_FOR_DEVICES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" style="width:160px">
643
  <option value="<?php echo AD_DISPLAY_DESKTOP_DEVICES; ?>" <?php echo ($obj->get_display_for_devices() == AD_DISPLAY_DESKTOP_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_DESKTOP_DEVICES; ?></option>
644
  <option value="<?php echo AD_DISPLAY_MOBILE_DEVICES; ?>" <?php echo ($obj->get_display_for_devices() == AD_DISPLAY_MOBILE_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_MOBILE_DEVICES; ?></option>
645
  <option value="<?php echo AD_DISPLAY_TABLET_DEVICES; ?>" <?php echo ($obj->get_display_for_devices() == AD_DISPLAY_TABLET_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_TABLET_DEVICES; ?></option>
@@ -657,243 +909,278 @@ function generate_settings_form (){
657
  <div id="no-wrapping-warning-<?php echo $ad_number; ?>" style="padding:8px; margin: 8px 0 8px 5px; border: 1px solid #ddd; border-radius: 5px; display: none;">
658
  <span id="" style="margin-top: 5px;"><strong><span style="color: red;">WARNING:</span> No Wrapping</strong> style has no HTML code for client-side device detection!</span>
659
  </div>
660
-
661
  </div>
662
-
663
  <?php
664
  }
665
  ?>
666
-
667
- <div id="tab-0" style="padding: 0 0 30px 0;">
668
- <div style="padding: 10px 0 0 4px;">
669
- <h3>Ad Inserter Settings <?php echo (int) ($ai_db_options ['global']['VERSION'][0].$ai_db_options ['global']['VERSION'][1]), '.',
670
  (int) ($ai_db_options ['global']['VERSION'][2].$ai_db_options ['global']['VERSION'][3]), '.',
671
- (int) ($ai_db_options ['global']['VERSION'][4].$ai_db_options ['global']['VERSION'][5]);
672
- echo isset ($ai_db_options ['global']['TIMESTAMP']) ? " saved on ".date ("Y-m-d H:i:s", $ai_db_options ['global']['TIMESTAMP'] + get_option ('gmt_offset') * 3600) : ""; ?></h3>
 
673
  </div>
674
 
675
- <div style="float: right; padding: 1px 5px;">
 
676
  <?php if (function_exists ('ai_settings_global_buttons')) ai_settings_global_buttons (); ?>
677
- <input style="display: none; border-radius: 5px; font-weight: bold;" name="<?php echo AI_FORM_SAVE; ?>" value="Save Settings" type="submit" style="width:120px; font-weight: bold;" />
678
- </div>
679
-
680
- <div style="clear: both;"></div>
681
-
682
- <?php if (function_exists ('ai_global_settings')) ai_global_settings (); ?>
683
-
684
- <div style="padding:0px 0px 8px 16px;">
685
- Syntax Highlighter Theme:&nbsp;&nbsp;&nbsp;
686
-
687
- <select
688
- style="border-radius: 5px; width:220px"
689
- id="syntax-highlighter-theme"
690
- name="syntax-highlighter-theme"
691
- value="Value">
692
- <optgroup label="Light">
693
- <option value="disabled" <?php echo ($syntax_highlighter_theme == 'disabled') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>No Syntax Highlighting</option>
694
- <option value="chrome" <?php echo ($syntax_highlighter_theme == 'chrome') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Chrome</option>
695
- <option value="clouds" <?php echo ($syntax_highlighter_theme == 'clouds') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Clouds</option>
696
- <option value="crimson_editor" <?php echo ($syntax_highlighter_theme == 'crimson_editor') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Crimson Editor</option>
697
- <option value="dawn" <?php echo ($syntax_highlighter_theme == 'dawn') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Dawn</option>
698
- <option value="dreamweaver" <?php echo ($syntax_highlighter_theme == 'dreamweaver') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Dreamweaver</option>
699
- <option value="eclipse" <?php echo ($syntax_highlighter_theme == 'eclipse') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Eclipse</option>
700
- <option value="github" <?php echo ($syntax_highlighter_theme == 'github') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>GitHub</option>
701
- <option value="katzenmilch" <?php echo ($syntax_highlighter_theme == 'katzenmilch') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Katzenmilch</option>
702
- <option value="kuroir" <?php echo ($syntax_highlighter_theme == 'kuroir') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Kuroir</option>
703
- <option value="solarized_light" <?php echo ($syntax_highlighter_theme == 'solarized_light') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Solarized Light</option>
704
- <option value="textmate" <?php echo ($syntax_highlighter_theme == 'textmate') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Textmate</option>
705
- <option value="tomorrow" <?php echo ($syntax_highlighter_theme == 'tomorrow') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow</option>
706
- <option value="xcode" <?php echo ($syntax_highlighter_theme == 'xcode') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>XCode</option>
707
- </optgroup>
708
- <optgroup label="Dark">
709
- <option value="ad_inserter" <?php echo ($syntax_highlighter_theme == 'ad_inserter') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Ad Inserter</option>
710
- <option value="chaos" <?php echo ($syntax_highlighter_theme == 'chaos') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Chaos</option>
711
- <option value="clouds_midnight" <?php echo ($syntax_highlighter_theme == 'clouds_midnight') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Clouds Midnight</option>
712
- <option value="cobalt" <?php echo ($syntax_highlighter_theme == 'cobalt') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Cobalt</option>
713
- <option value="idle_fingers" <?php echo ($syntax_highlighter_theme == 'idle_fingers') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Idle Fingers</option>
714
- <option value="kr_theme" <?php echo ($syntax_highlighter_theme == 'kr_theme') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>krTheme</option>
715
- <option value="merbivore" <?php echo ($syntax_highlighter_theme == 'merbivore') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Merbivore</option>
716
- <option value="merbivore_soft" <?php echo ($syntax_highlighter_theme == 'merbivore_soft') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Merbivore Soft</option>
717
- <option value="mono_industrial" <?php echo ($syntax_highlighter_theme == 'mono_industrial') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Mono Industrial</option>
718
- <option value="monokai" <?php echo ($syntax_highlighter_theme == 'monokai') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Monokai</option>
719
- <option value="pastel_on_dark" <?php echo ($syntax_highlighter_theme == 'pastel_on_dark') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Pastel on Dark</option>
720
- <option value="solarized_dark" <?php echo ($syntax_highlighter_theme == 'solarized_dark') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Solarized Dark</option>
721
- <option value="terminal" <?php echo ($syntax_highlighter_theme == 'terminal') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Terminal</option>
722
- <option value="tomorrow_night" <?php echo ($syntax_highlighter_theme == 'tomorrow_night') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow Night</option>
723
- <option value="tomorrow_night_blue" <?php echo ($syntax_highlighter_theme == 'tomorrow_night_blue') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow Night Blue</option>
724
- <option value="tomorrow_night_bright" <?php echo ($syntax_highlighter_theme == 'tomorrow_night_bright') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow Night Bright</option>
725
- <option value="tomorrow_night_eighties" <?php echo ($syntax_highlighter_theme == 'tomorrow_night_eighties') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow Night 80s</option>
726
- <option value="twilight" <?php echo ($syntax_highlighter_theme == 'twilight') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Twilight</option>
727
- <option value="vibrant_ink" <?php echo ($syntax_highlighter_theme == 'vibrant_ink') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Vibrant Ink</option>
728
- </optgroup>
729
- </select>
730
- </div>
731
 
732
- <div style="clear: both;"></div>
 
 
733
 
734
- <div style="padding:0px 0px 8px 16px;">
735
- Block Class Name:&nbsp;&nbsp;&nbsp;
736
- <input style="border-radius: 5px; margin-left: 0px;" title="CSS Class Name" type="text" id="block-class-name" name="block-class-name" value="<?php echo $block_class_name; ?>" size="15" maxlength="40" /> <span style= "margin: 3px 10px 0 0; display: inline; float: right;">Example: &nbsp;&nbsp; <pre style= "display: inline; color: blue;">&lt;div class="<?php echo $block_class_name; ?> <?php echo $block_class_name; ?>-n"&gt;<span style= "color: black;">BlockCode</span>&lt;/div&gt;</pre></span>
737
  </div>
738
 
739
- <div style="clear: both;"></div>
740
-
741
- <div style="padding:0px 0px 8px 16px;">
742
- Minimum User Role for Page/Post Ad Inserter Exceptions Editing
743
- <select style="border-radius: 5px; margin-bottom: 3px;" id="minimum-user-role" name="minimum-user-role" style="width:300px">
744
- <?php wp_dropdown_roles (get_minimum_user_role ()); ?>
745
- </select>
746
- </div>
747
 
748
- <div style="clear: both;"></div>
 
 
 
749
 
750
- <div style="padding:0px 0px 8px 16px;">
751
- Plugin priority <input style="border-radius: 5px;" type="text" name="plugin_priority" value="<?php echo get_plugin_priority (); ?>" size="6" maxlength="6" />
752
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
753
 
754
- <div style="clear: both;"></div>
755
-
756
- <div style="padding:0px 0px 8px 16px;">
757
- Paragraph Tag Debugging:&nbsp;&nbsp;&nbsp;
758
-
759
- <select
760
- style="border-radius: 5px; width:150px"
761
- title="When enabled, individual post paragraphs will be surrounded with a border for easier identification and ad placement."
762
- id="tag_debugging"
763
- name="tag_debugging"
764
- value="Value">
765
- <option value="disabled" <?php echo ($tag_debugging == AI_OPTION_DISABLED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Disabled</option>
766
- <option value="before_processing" <?php echo ($tag_debugging == AI_OPTION_BEFORE_PROCESSING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Before Processing</option>
767
- <option value="after_processing" <?php echo ($tag_debugging == AI_OPTION_AFTER_PROCESSING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>After Processing</option>
768
- </select>
769
- </div>
770
 
771
- <hr />
 
 
 
 
 
772
 
773
- <div style="padding:0px 0px 8px 16px;">
774
- Viewport Settings used for client-side device detection
775
- </div>
 
776
 
 
 
 
 
777
  <?php
778
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
779
  ?>
780
-
781
- <div style="padding:0px 0px 8px 16px;">
782
- Viewport <?php echo $viewport; ?> name:&nbsp;&nbsp;&nbsp;
783
- <input style="border-radius: 5px; margin-left: 0px;" type="text" id="option-name-<?php echo $viewport; ?>" name="viewport-name-<?php echo $viewport; ?>" value="<?php echo get_viewport_name ($viewport); ?>" size="15" maxlength="40" />
784
- <?php if ($viewport == AD_INSERTER_VIEWPORTS) echo '<span style="display: none;">' ?>
785
- &nbsp;&nbsp; min width
786
- <input style="border-radius: 5px;" type="text" id="option-length-<?php echo $viewport; ?>" name="viewport-width-<?php echo $viewport; ?>" value="<?php echo get_viewport_width ($viewport); ?>" size="4" maxlength="4" /> px
787
- <?php if ($viewport == AD_INSERTER_VIEWPORTS) echo '</span>' ?>
788
- </div>
789
-
790
  <?php
791
  }
792
  ?>
793
-
794
- <hr />
795
-
796
- <div style="padding: 0;">
797
- <div style="float: right; padding-top: 5px; margin-right: 15px;">
798
- <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_MANUAL, '_block_h'; ?>" value="0" />
799
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_ENABLE_MANUAL, '_block_h'; ?>" id="enable-header" value="1" <?php if ($adH->get_enable_manual () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
800
- <label for="enable-header" title="Enable or disable insertion of this code into HTML page header">Enable</label> &nbsp;&nbsp;
801
-
802
- <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_404, '_block_h'; ?>" value="0" />
803
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_ENABLE_404, '_block_h'; ?>" id="enable-header-404" value="1" <?php if ($adH->get_enable_404 () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
804
- <label for="enable-header-404" title="Enable or disable insertion of this code into HTML page header on page for Error 404: Page not found">Error 404 Page</label>
805
  </div>
806
 
807
- <div style="padding-left:4px;">
808
- <h3>HTML Page Header Code</h3>
809
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810
 
811
- <div style="padding:0px 8px 22px 16px;">
812
- Code will be placed within the <pre style="display: inline; color: blue;">&lt;head&gt;&lt;/head&gt;</pre> section of the theme (theme-dependent)
813
- </div>
 
814
 
815
- <div style="display: inline-block; padding: 1px 10px; float: right;">
816
- <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_PROCESS_PHP, '_block_h'; ?>" value="0" />
817
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_PROCESS_PHP, '_block_h'; ?>" value="1" id="process-php-h" <?php if ($adH->get_process_php () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
818
- <label for="process-php-h" title="Process PHP code">Process PHP</label>
819
- </div>
820
 
821
- <div style="display: inline-block; padding: 1px 10px; float: right;">
822
- <input type="checkbox" style="border-radius: 5px;" value="0" id="simple-editor-h" />
823
- <label for="simple-editor-h" title="Simple editor">Simple editor</label>
824
- </div>
825
 
826
- <div style="padding-left:16px;">
827
- HTML / Javascript / CSS / PHP code
828
- </div>
829
- <div style="padding: 8px;">
830
- <textarea id="block-h" name="<?php echo AI_OPTION_CODE, '_block_h'; ?>" rows="36" cols="98" style="background-color:#F9F9F9; font-family: Courier, 'Courier New', monospace; font-weight: bold; width: 719px; height: 384px;"><?php echo esc_textarea ($adH->get_ad_data()); ?></textarea>
 
 
 
 
 
 
 
 
 
831
  </div>
832
- </div>
833
 
834
- <hr />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
835
 
836
- <div style="padding: 0;">
837
- <div style="float: right; padding-top: 5px; margin-right: 15px;">
838
- <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_MANUAL, '_block_f'; ?>" value="0" />
839
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_ENABLE_MANUAL, '_block_f'; ?>" id="enable-footer" value="1" <?php if ($adF->get_enable_manual () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
840
- <label for="enable-footer" title="Enable or disable insertion of this code into HTML page footer">Enable</label> &nbsp;&nbsp;
841
 
842
- <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_404, '_block_f'; ?>" value="0" />
843
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_ENABLE_404, '_block_f'; ?>" id="enable-footer-404" value="1" <?php if ($adF->get_enable_404 () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
844
- <label for="enable-footer-404" title="Enable or disable insertion of this code into HTML page footer on page for Error 404: Page not found">Error 404 Page</label>
845
- </div>
846
 
847
- <div style="padding-left:4px;">
848
- <h3>HTML Page Footer Code</h3>
849
- </div>
850
 
851
- <div style="padding:0px 8px 22px 16px;">
852
- Code will be placed near the <pre style="display: inline; color: blue;">&lt;/body&gt;</pre> tag of the theme (theme-dependent)
 
 
 
 
 
 
 
 
 
 
 
 
853
  </div>
854
 
855
- <div style="display: inline-block; padding: 1px 10px; float: right;">
856
- <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_PROCESS_PHP, '_block_f'; ?>" value="0" />
857
- <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_PROCESS_PHP, '_block_f'; ?>" value="1" id="process-php-f" <?php if ($adF->get_process_php () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
858
- <label for="process-php-f" title="Process PHP code">Process PHP</label>
859
- </div>
860
 
861
- <div style="display: inline-block; padding: 1px 10px; float: right;">
862
- <input type="checkbox" style="border-radius: 5px;" value="0" id="simple-editor-f" />
863
- <label for="simple-editor-f" title="Simple editor">Simple editor</label>
864
- </div>
 
 
865
 
866
- <div style="padding-left:16px;">
867
- HTML / Javascript / PHP code
868
- </div>
869
- <div style="padding:8px;">
870
- <textarea id="block-f" name="<?php echo AI_OPTION_CODE, '_block_f'; ?>" rows="36" cols="98" style="background-color:#F9F9F9; font-family: Courier, 'Courier New', monospace; font-weight: bold; width: 719px; height: 384px;"><?php echo esc_textarea ($adF->get_ad_data()); ?></textarea>
871
  </div>
872
- </div>
873
-
874
- </div>
875
-
876
 
 
877
  </div>
878
 
879
- <div style="height: 30px; margin: 8px 0 0 0;">
880
- <div style="float: left; padding: 1px 1px; color: red;">
881
- <input onclick="if (confirm('Are you sure you want to reset all settings?')) return true; return false" name="<?php echo AI_FORM_CLEAR; ?>" value="Reset All Settings" type="submit" style="display: none; width:120px; font-weight: bold; color: #e44;" />
882
- </div>
883
- <div style="float: right; padding: 1px 1px;">
884
- <input name="<?php echo AI_FORM_SAVE; ?>" value="<?php echo $save_button_text; ?>" type="submit" style="display: none; border-radius: 5px; font-weight: bold;" />
885
- </div>
886
  </div>
887
 
888
  <input id="ai-active-tab" type="hidden" name="ai-active-tab" value="<?php echo $active_tab; ?>" />
889
 
890
- <?php wp_nonce_field ('save_adinserter_settings'); ?>
891
-
892
- </form>
893
-
894
  <?php
895
  } // Main subpage
 
896
  ?>
 
897
 
898
  </div>
899
 
@@ -901,23 +1188,37 @@ function generate_settings_form (){
901
  if ($subpage == 'main') {
902
  if (function_exists ('ai_settings_side')) ai_settings_side (); else { ?>
903
  <div style="float: left;">
904
- <div style="width: 735px; padding: 2px 8px 6px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
905
- <h2>Monitor Google AdSense and Amazon Associates earnings with <a href="http://tinymonitor.com/" target="_blank">Tiny Monitor</a></h2>
906
- <a href="http://tinymonitor.com/" target="_blank"><img src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>tinymonitor-logo.png" alt="Tiny Monitor" /></a>
907
- <a href="http://tinymonitor.com/" target="_blank"><img src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>tiny-monitor.png" alt="Amazon Associates" /></a>
908
- <p style="text-align: justify;">TinyMonitor is a PHP application that can monitor your Google AdSense earnings, Amazon Associates earnings and PayPal transactions.
909
- The purpose of TinyMonitor is to download data from original sources and present them in a compact way on a single web page.
910
- With TinyMonitor you have all the data at one place so you dont have to log in to various pages just to check earnings.
911
- TinyMonitor displays some data also in the page title and favicon so you still have simple access to current monitor status while you work with other applications.</p>
 
 
 
 
 
 
 
 
 
 
912
  </div>
913
  </div>
914
  <?php
915
  }
916
  }
917
  ?>
918
-
919
  <script type="text/javascript">
920
- shSettings ['theme'] = '<?php echo $syntax_highlighter_theme; ?>';
 
 
 
 
 
921
  </script>
922
 
923
  <?php
10
  $save_url = preg_replace ("/&tab=\d+/", "", $save_url);
11
  }
12
 
13
+ $generate_all = false;
14
+ if (isset ($_GET ['generate-all']) && $_GET ['generate-all'] == 1) {
15
+ $generate_all = true;
16
+ }
17
+
18
  $subpage = 'main';
19
  $start = 1;
20
  $end = 16;
26
  if ($active_tab != 0)
27
  if ($active_tab < $start || $active_tab > $end) $active_tab = $start;
28
 
29
+ $adH = $block_object [AI_HEADER_OPTION_NAME];
30
+ $adF = $block_object [AI_FOOTER_OPTION_NAME];
 
 
 
31
 
32
  $syntax_highlighter_theme = get_syntax_highlighter_theme ();
33
  $block_class_name = get_block_class_name ();
34
+
35
+ $default = $block_object [0];
36
 
37
  ?>
38
+
39
+ <div id="data" style="display: none;" theme="<?php echo $syntax_highlighter_theme; ?>" javascript_debugging="<?php echo get_javascript_debugging () ? '1' : '0'; ?>" ></div>
40
+
41
+ <div id="ai-settings" style="float: left;">
42
+
43
+ <form id="ai-form" class="ai-form no-select" action="<?php echo $save_url; ?>" method="post" id="ai-form" name="ai_form" style="float: left;" start="<?php echo $start; ?>" end="<?php echo $end; ?>">
44
+
45
+ <div id="header" class="ai-form header" style="margin: 8px 0; padding: 0 8px; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  <?php
47
+ if (function_exists ('ai_settings_header')) ai_settings_header ($start, $active_tab); else { ?>
48
+
49
+ <div style="float: left;">
50
+ <h2 id="plugin_name" style="display: inline-block; margin: 13px 0;"><?php echo AD_INSERTER_NAME . ' ' . AD_INSERTER_VERSION ?></h2>
51
  </div>
52
+ <div id="header-buttons">
53
+ <a style="text-decoration: none;" href="http://tinymonitor.com/ad-inserter" target="_blank"><button type="button" style="display: none; margin: 0 10px 0 0; width: 62px;">Doc</button></a>
54
+ <a style="text-decoration: none;" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4" target="_blank"><button type="button" style="display: none; margin: 0 10px 0 0; width: 62px;">Donate</button></a>
55
+ <a style="text-decoration: none;" href="http://tinymonitor.com/ad-inserter-pro" target="_blank"><button type="button" title="If you need more than 16 blocks, more viewports, import/export settings, multisite support" style="display: none; margin: 0 10px 0 0; width: 62px;">Go&nbsp;Pro</button></a>
56
+ <a style="text-decoration: none;" href="https://wordpress.org/support/plugin/ad-inserter/reviews/" target="_blank"><button type="button" title="If you like Ad Inserter please write a nice review" style="display: none; margin: 0 10px 0 0; width: 62px;">Review</button></a>
57
  </div>
58
+
59
+ <div style="clear: both;"></div>
60
  <?php
61
  }
62
  ?>
63
  </div>
64
 
65
+ <div id="javascript-warning" class="ai-form" style="width: 735px; padding: 2px 8px 2px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; display: none;">
66
+ <div style="float: right; text-align: right; margin: 8px 18px 0px 0;">
67
+ Incompatible javscript file loaded, probably due to caching. Please try to delete
68
+ </div>
69
+ <div style="float: right; text-align: right; margin: 0px 18px 0px 0;">
70
+ browser's cache and reload this page to see if this warning will disappear.
71
+ </div>
72
+ <h2 id="javascript-version" style="color: red;" title="Plugin javascript version">&nbsp;</h2>
73
+ </div>
74
+
75
+ <div id="blocked-warning" class="ai-form warning-enabled" style="width: 735px; padding: 2px 8px 2px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
76
+ <div style="float: right; text-align: right; margin: 8px 18px 0px 0;">
77
+ This page was not loaded properly. Please check browser and plugins that may block this page.
78
+ </div>
79
+ <div style="float: right; text-align: right; margin: 0px 18px 0px 0;">
80
+ If you are using <strong>Ad Blocker</strong> please select "Disable on this page" or "Don't run on this page".
81
+ </div>
82
+ <h2 style="color: red;" title="Error loading page">PAGE BLOCKED</h2>
83
+ </div>
84
+
85
  <?php
86
  if ($subpage == 'exceptions') {
87
  ?>
 
88
  <div id="ai-exceptions" style="padding: 8px 8px 8px 8px; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
89
 
90
  <table class="exceptions">
142
  </table>
143
 
144
  </div>
 
 
145
  <?php
146
  } else {
 
147
  ?>
148
+ <div id="ai-tab-container" class="ai-form" style="padding: 8px 8px 1px 8px; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
149
+ <div id="dummy-tabs" style="height: 29px; padding: .2em .2em 0;"></div>
150
+
151
+ <div id="ai-scroll-tabs" class="scroll_tabs_theme_light" style="display: none;">
152
+ <?php
153
+
154
+ for ($ad_number = $start; $ad_number <= $end; $ad_number ++){
155
+ echo " <span id='ai-scroll-tab-$ad_number' rel='$ad_number'>$ad_number</span>";
156
+ }
157
+ ?>
158
+ <span rel='0'>0</span>
159
+ </div>
160
+
161
  <ul id="ai-tabs" style="display: none;">
162
  <?php
163
 
251
  if ($adH->get_enable_manual () && $adH->get_ad_data() != "") $title_hf .= ", Header code";
252
  if ($adF->get_enable_manual () && $adF->get_ad_data() != "") $title_hf .= ", Footer code";
253
 
254
+ $enabled_h = $adH->get_enable_manual () && $adH->get_ad_data() != "";
255
+ $enabled_f = $adF->get_enable_manual () && $adF->get_ad_data() != "";
256
+ if ($enabled_h || $enabled_f) $class_hf = " on"; else $class_hf = "";
257
  ?>
258
+ <li id="ai-tab0" class="ai-tab" title="<?php echo AD_INSERTER_NAME ?> Settings<?php echo $title_hf ?>"><a href="#tab-0" style="padding: 5px 14px 6px 12px;"><div class="ai-icon-gear<?php echo $class_hf ?>" /></div></a></li>
259
  </ul>
260
 
261
  <?php
262
  for ($ad_number = $start; $ad_number <= $end; $ad_number ++){
263
+
264
+ $default->number = $ad_number;
265
+ $default->wp_options [AI_OPTION_NAME] = AD_NAME." ".$ad_number;
266
+
267
+ $tab_visible = $ad_number == $active_tab || $generate_all;
268
+
269
  $obj = $block_object [$ad_number];
270
 
271
  $show_devices = $obj->get_detection_client_side () == AD_SETTINGS_CHECKED || $obj->get_detection_server_side () == AD_SETTINGS_CHECKED;
273
 
274
  $cat_list = $obj->get_ad_block_cat();
275
  $tag_list = $obj->get_ad_block_tag();
276
+ $id_list = $obj->get_id_list();
277
  $url_list = $obj->get_ad_url_list();
278
+ $url_parameter_list = $obj->get_url_parameter_list();
279
  $domain_list = $obj->get_ad_domain_list();
280
+ $show_lists = $cat_list != '' || $tag_list != '' || $id_list != '' || $url_list != '' || $url_parameter_list != '' || $domain_list != '';
281
  if ($show_lists) $lists_style = "font-weight: bold; color: #66f;"; else $lists_style = "";
282
 
283
  $show_manual = $manual [$ad_number];
284
  if ($show_manual) $manual_style = "font-weight: bold; color: " . ($manual_widget [$ad_number] || empty ($sidebars_with_widget [$ad_number]) ? "#66f;" : "#e44;"); else $manual_style = "";
285
 
286
+ $show_misc = intval ($obj->get_maximum_insertions ()) != 0 || intval ($obj->get_call_filter()) != 0 || $obj->get_display_for_users() != AD_DISPLAY_ALL_USERS || $obj->get_enable_404 () == AD_SETTINGS_CHECKED || $obj->get_enable_feed () == AD_SETTINGS_CHECKED;
287
  if ($show_misc) $misc_style = "font-weight: bold; color: #66f;"; else $misc_style = "";
288
 
289
+ $get_display_type = $obj->get_display_type();
 
 
 
 
 
 
 
 
 
 
 
290
 
291
+ $paragraph_settings = $get_display_type == AD_SELECT_BEFORE_PARAGRAPH || $get_display_type == AD_SELECT_AFTER_PARAGRAPH;
292
+ $content_settings = $get_display_type == AD_SELECT_BEFORE_PARAGRAPH || $get_display_type == AD_SELECT_AFTER_PARAGRAPH || $get_display_type == AD_SELECT_BEFORE_CONTENT || $get_display_type == AD_SELECT_AFTER_CONTENT;
 
293
 
294
+ $paragraph_counting =
295
+ $obj->get_direction_type() != $default->get_direction_type() ||
296
+ $obj->get_paragraph_tags() != $default->get_paragraph_tags() ||
297
+ $obj->get_minimum_paragraph_words() != $default->get_minimum_paragraph_words() ||
298
+ $obj->get_maximum_paragraph_words() != $default->get_maximum_paragraph_words() ||
299
+ $obj->get_paragraph_text_type() != $default->get_paragraph_text_type() ||
300
+ $obj->get_paragraph_text() != $default->get_paragraph_text() ||
301
+ $obj->get_paragraph_number_minimum() != $default->get_paragraph_number_minimum() ||
302
+ $obj->get_count_inside_blockquote() != $default->get_count_inside_blockquote();
303
 
304
+ $paragraph_clearance =
305
+ ($obj->get_avoid_text_above() != $default->get_avoid_text_above() && intval ($obj->get_avoid_paragraphs_above()) != 0) ||
306
+ ($obj->get_avoid_text_below() != $default->get_avoid_text_below() && intval ($obj->get_avoid_paragraphs_below()) != 0);
 
 
307
 
308
+ ?>
309
+ <div id="tab-<?php echo $ad_number; ?>" style="padding: 0;<?php echo $tab_visible ? "" : " display: none;" ?>">
310
+ <div class="max-input" style="margin: 8px 0; height: 28px; margin-bottom: 2px;">
311
+ <span id="name-label-container-<?php echo $ad_number; ?>" style="display: table-cell; padding: 0; font-weight: bold; cursor: pointer;">
312
+ <input id="name-edit-<?php echo $ad_number; ?>" style="width: 100%; vertical-align: middle; font-size: 14px; border-radius: 4px; display: none;" type="text" name="<?php echo AI_OPTION_NAME, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_name(); ?>" value="<?php echo $obj->get_ad_name() ?>" size="56" maxlength="120" />
313
+ <span id="name-label-<?php echo $ad_number; ?>" class="select" style="width: 100%; max-width: 440px; vertical-align: middle; font-size: 14px; display: inline-block; margin-top: 4px; margin-left: 7px; white-space: nowrap; overflow: hidden;"><?php echo $obj->get_ad_name() ?></span>
314
+ </span>
315
+ <?php if (function_exists ('ai_settings_top_buttons')) ai_settings_top_buttons ($ad_number); ?>
316
+ <?php if (AI_SYNTAX_HIGHLIGHTING) : ?>
317
+ <span style="display: table-cell; vertical-align: middle; width: 110px; padding: 2px 0 0 10px;">
318
+ <input type="checkbox" style="border-radius: 5px;" value="0" id="simple-editor-<?php echo $ad_number; ?>" />
319
+ <label for="simple-editor-<?php echo $ad_number; ?>" title="Toggle Syntax Highlighting / Simple editor for mobile devices">Simple editor</label>
320
+ </span>
321
+ <?php endif; ?>
322
+ <span style="display: table-cell; vertical-align: middle; width: 110px; padding: 2px 0 0 10px;">
323
+ <input type="hidden" style="border-radius: 5px;" name="<?php echo AI_OPTION_PROCESS_PHP, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
324
+ <input type="checkbox" style="border-radius: 5px;" name="<?php echo AI_OPTION_PROCESS_PHP, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_process_php (); ?>" id="process-php-<?php echo $ad_number; ?>" <?php if ($obj->get_process_php () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
325
+ <label for="process-php-<?php echo $ad_number; ?>" title="Process PHP code in block">Process PHP</label>
326
+ </span>
327
  </div>
328
 
329
+ <?php if (function_exists ('ai_settings_container')) ai_settings_container ($ad_number, $obj); ?>
 
 
330
 
331
+ <div style="margin: 8px 0;">
332
+ <textarea id="block-<?php echo $ad_number; ?>" class="simple-editor" style="background-color:#F9F9F9; font-family: Courier, 'Courier New', monospace; font-weight: bold;" name="<?php echo AI_OPTION_CODE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"><?php echo esc_textarea ($obj->get_ad_data()); ?></textarea>
333
  </div>
334
 
335
+ <div style="padding: 0; min-height: 28px;">
336
+ <div style="float: left;">
337
+ <button id="misc-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 4px;" title="Limit / filter insertions, general tag, check for users, display on error 404 page or in feeds"><span style="<?php echo $misc_style; ?>">Misc</span></button>
338
+ <button id="device-detection-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 4px;" title="Client/Server-side Device Detection (Desktop, Tablet, Phone,...)"><span style="<?php echo $devices_style; ?>">Devices</span></button>
339
+ <button id="lists-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 4px;" title="White/Black-list Category, Tag, Url or Referer (domain)"><span style="<?php echo $lists_style; ?>">Lists</span></button>
340
+ <button id="manual-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 4px;" title="Widget, Shortcode and PHP function call"><span style="<?php echo $manual_style; ?>">Manual</span></button>
341
+ <button id="preview-button-<?php echo $ad_number; ?>" type="button" style="display: none; margin-right: 4px;" title="Preview saved code above" nonce="<?php echo wp_create_nonce ("adinserter_data"); ?>">Preview</button>
342
+ </div>
343
  <div style="float: right;">
344
+ <?php if (function_exists ('ai_settings_bottom_buttons')) ai_settings_bottom_buttons ($start, $end); else { ?>
345
+ <input style="display: none; border-radius: 5px; font-weight: bold;" name="<?php echo AI_FORM_SAVE; ?>" value="Save All Settings" type="submit" />
346
+ <?php } ?>
 
347
  </div>
348
  <div style="clear: both;"></div>
349
  </div>
350
 
351
+ <div style="padding:8px 8px 6px 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px;">
352
  <div style="float: left;">
353
  Automatic Display:
354
+ <select style="border-radius: 5px; margin-bottom: 3px;" id="display-type-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_DISPLAY_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_display_type(); ?>" style="width:200px;">
355
  <option value="<?php echo AD_SELECT_NONE; ?>" <?php echo ($obj->get_display_type()==AD_SELECT_NONE) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_SELECT_NONE; ?></option>
356
  <option value="<?php echo AD_SELECT_BEFORE_POST; ?>" <?php echo ($obj->get_display_type()==AD_SELECT_BEFORE_POST) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_SELECT_BEFORE_POST; ?></option>
357
  <option value="<?php echo AD_SELECT_BEFORE_CONTENT; ?>" <?php echo ($obj->get_display_type()==AD_SELECT_BEFORE_CONTENT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_SELECT_BEFORE_CONTENT; ?></option>
366
 
367
  <div style="float: right;">
368
  Block Alignment and Style:&nbsp;&nbsp;&nbsp;
369
+ <select style="border-radius: 5px; width:120px;" id="block-alignment-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_ALIGNMENT_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_alignment_type(); ?>">
370
  <option value="<?php echo AD_ALIGNMENT_NO_WRAPPING; ?>" <?php echo ($obj->get_alignment_type()==AD_ALIGNMENT_NO_WRAPPING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_NO_WRAPPING; ?></option>
371
  <option value="<?php echo AD_ALIGNMENT_CUSTOM_CSS; ?>" <?php echo ($obj->get_alignment_type()==AD_ALIGNMENT_CUSTOM_CSS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_CUSTOM_CSS; ?></option>
372
  <option value="<?php echo AD_ALIGNMENT_NONE; ?>" <?php echo ($obj->get_alignment_type()==AD_ALIGNMENT_NONE) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_NONE; ?></option>
377
  <option value="<?php echo AD_ALIGNMENT_FLOAT_RIGHT; ?>" <?php echo ($obj->get_alignment_type()==AD_ALIGNMENT_FLOAT_RIGHT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ALIGNMENT_FLOAT_RIGHT; ?></option>
378
  </select>
379
  &nbsp;
380
+ <button id="show-css-button-<?php echo $ad_number; ?>" type="button" style="min-width: 85px; margin-right: 0px;">Show CSS</button>
381
  </div>
382
  <div style="clear: both;"></div>
 
383
 
384
+ <div id="css-code-<?php echo $ad_number; ?>" style="height: 26px; margin: 4px 0 2px; display: none;">
385
+ <div class="max-input">
386
+ <span id="css-label-<?php echo $ad_number; ?>" style="display: table-cell; width: 34px; padding: 0; height: 26px; vertical-align: middle; margin: 4px 0 0 0;">CSS &nbsp;</span>
387
+ <input id="custom-css-<?php echo $ad_number; ?>" style="width: 100%; border-radius: 4px; display: none; font-family: Courier, 'Courier New', monospace; font-weight: bold;" type="text" name="<?php echo AI_OPTION_CUSTOM_CSS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_custom_css(); ?>" value="<?php echo $obj->get_custom_css(); ?>" maxlength="160" title="Custom CSS code for wrapping div" />
388
+ <span style="display: table-cell; vertical-align: middle; font-family: Courier, 'Courier New', monospace; font-size: 12px; font-weight: bold;">
389
+ <span id="css-no-wrapping-<?php echo $ad_number; ?>" style="height: 18px; padding-left: 7px; display: none;"></span>
390
+ <span id="css-none-<?php echo $ad_number; ?>" style="height: 18px; padding-left: 7px; display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_NONE); ?></span>
391
+ <span id="css-left-<?php echo $ad_number; ?>" style="height: 18px; padding-left: 7px; display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_LEFT); ?></span>
392
+ <span id="css-right-<?php echo $ad_number; ?>" style="height: 18px; padding-left: 7px; display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_RIGHT); ?></span>
393
+ <span id="css-center-<?php echo $ad_number; ?>" style="height: 18px; padding-left: 7px; display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_CENTER); ?></span>
394
+ <span id="css-float-left-<?php echo $ad_number; ?>" style="height: 18px; padding-left: 7px; display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_FLOAT_LEFT); ?></span>
395
+ <span id="css-float-right-<?php echo $ad_number; ?>" style="height: 18px; padding-right: 7px; display: none;" title="CSS code for wrapping div"><?php echo $obj->alignmet_style (AD_ALIGNMENT_FLOAT_RIGHT); ?></span>
396
+ </span>
397
+ <span style="display:table-cell; width: 46px;" ><button id="edit-css-button-<?php echo $ad_number; ?>" type="button" style="display: table-cell; padding: 0; margin: 0 0 0 8px;">Edit</button></span>
398
+ </div>
399
+ </div>
 
 
 
 
 
 
 
400
  </div>
401
 
402
+ <div class="responsive-table" style="padding: 7px 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px;">
403
  <table>
404
  <tr>
405
  <td style="width: 70%">
406
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_POSTS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
407
+ <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_POSTS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_display_settings_post(); ?>" id="display-posts-<?php echo $ad_number; ?>" title="Enable or disable display on posts" <?php if ($obj->get_display_settings_post()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
408
 
409
+ <select style="border-radius: 5px; margin: 0 0 3px 10px;" title="Default display for posts - exceptions can be configured on individual post editor pages" id="enabled-on-which-posts-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_ENABLED_ON_WHICH_POSTS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_enabled_on_which_posts(); ?>" style="width:160px">
410
  <option value="<?php echo AD_ENABLED_ON_ALL; ?>" <?php echo ($obj->get_ad_enabled_on_which_posts()==AD_ENABLED_ON_ALL) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ON_ALL; ?></option>
411
  <option value="<?php echo AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED; ?>" <?php echo ($obj->get_ad_enabled_on_which_posts()==AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED; ?></option>
412
  <option value="<?php echo AD_ENABLED_ONLY_ON_SELECTED; ?>" <?php echo ($obj->get_ad_enabled_on_which_posts()==AD_ENABLED_ONLY_ON_SELECTED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ONLY_ON_SELECTED; ?></option>
418
  </td>
419
  <td style="padding-left: 8px;">
420
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_HOMEPAGE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
421
+ <input id= "display-homepage-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_HOMEPAGE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_display_settings_home(); ?>" <?php if ($obj->get_display_settings_home()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
422
  <label for="display-homepage-<?php echo $ad_number; ?>" title="Enable or disable display on homepage: latest posts (including sub-pages), static page or theme homepage">Homepage</label>
423
  </td>
424
  <td style="padding-left: 8px;">
425
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_CATEGORY_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
426
+ <input id= "display-category-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_CATEGORY_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_display_settings_category(); ?>" <?php if ($obj->get_display_settings_category()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
427
  <label for="display-category-<?php echo $ad_number; ?>" title="Enable or disable display on category blog pages (including sub-pages)">Category pages</label>
428
  </td>
429
  </tr>
431
  <tr>
432
  <td style="width: 70%">
433
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
434
+ <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_display_settings_page(); ?>" id="display-pages-<?php echo $ad_number; ?>" title="Enable or disable display on static pages" <?php if ($obj->get_display_settings_page()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
435
 
436
+ <select style="border-radius: 5px; margin: 0 0 3px 10px;" title="Default display for pages - exceptions can be configured on individual page editor pages" id="enabled-on-which-pages-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_ENABLED_ON_WHICH_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_enabled_on_which_pages(); ?>" style="width:160px">
437
  <option value="<?php echo AD_ENABLED_ON_ALL; ?>" <?php echo ($obj->get_ad_enabled_on_which_pages()==AD_ENABLED_ON_ALL) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ON_ALL; ?></option>
438
  <option value="<?php echo AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED; ?>" <?php echo ($obj->get_ad_enabled_on_which_pages()==AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ON_ALL_EXCEPT_ON_SELECTED; ?></option>
439
  <option value="<?php echo AD_ENABLED_ONLY_ON_SELECTED; ?>" <?php echo ($obj->get_ad_enabled_on_which_pages()==AD_ENABLED_ONLY_ON_SELECTED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ENABLED_ONLY_ON_SELECTED; ?></option>
442
  <label for="display-pages-<?php echo $ad_number; ?>">Static pages</label>
443
  </td>
444
  <td style="padding-left: 8px;">
 
 
 
445
  </td>
446
  <td style="padding-left: 8px;">
447
  <input style="border-radius: 5px;;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_SEARCH_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
448
+ <input id= "display-search-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_SEARCH_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_display_settings_search(); ?>" <?php if ($obj->get_display_settings_search()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
449
  <label for="display-search-<?php echo $ad_number; ?>" title="Enable or disable display on search blog pages">Search pages</label>
450
  </td>
451
  <td style="padding-left: 8px;">
452
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
453
+ <input id= "display-archive-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_DISPLAY_ON_ARCHIVE_PAGES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_display_settings_archive(); ?>" <?php if ($obj->get_display_settings_archive()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
454
  <label for="display-archive-<?php echo $ad_number; ?>" title="Enable or disable display on tag or archive blog pages">Tag / Archive pages</label>
455
  </td>
456
  </tr>
457
  </table>
458
  </div>
459
 
460
+ <div id="paragraph-settings-<?php echo $ad_number; ?>" style="padding:4px 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px;<?php echo $paragraph_settings ? "" : " display: none;" ?>">
461
+ <div style="margin: 4px 0; height: 26px;">
462
+ <div style="float: left; margin-top: 1px;">
463
+ Paragraph number
464
+ <input style="border-radius: 5px;" type="text"
465
+ name="<?php echo AI_OPTION_PARAGRAPH_NUMBER, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
466
+ default="<?php echo $default->get_paragraph_number(); ?>"
467
+ value="<?php echo $obj->get_paragraph_number(); ?>"
468
+ title="0 means random paragraph, value between 0 and 1 means relative position on page: 0.2 means paragraph at 20% of page height, 0.5 means paragraph halfway down the page, 0.9 means paragraph at 90% of page paragraphs, etc."
469
+ size="2"
470
+ maxlength="4" />
471
+ </div>
472
+
473
+ <div style="float: right;">
474
+ <button id="counting-button-<?php echo $ad_number; ?>" type="button" style="min-width: 85px; margin-right: 8px; display: none;">Counting</button>
475
+ <button id="clearance-button-<?php echo $ad_number; ?>" type="button" style="min-width: 85px; margin-right: 0px; display: none;">Clearance</button>
476
+ </div>
477
+ </div>
478
+ </div>
479
+
480
+ <div id="paragraph-counting-<?php echo $ad_number; ?>" style="padding:4px 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px;<?php echo $paragraph_counting ? "" : " display: none;" ?>">
481
+ <div class="max-input" style="margin: 4px 0 8px 0;">
482
+ <span style="display: table-cell; width: 1px; white-space: nowrap;">
483
+ Count&nbsp;
484
+ <select style="border-radius: 5px;" name="<?php echo AI_OPTION_DIRECTION_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_direction_type(); ?>">
485
+ <option value="<?php echo AD_DIRECTION_FROM_TOP; ?>" <?php echo ($obj->get_direction_type()==AD_DIRECTION_FROM_TOP) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DIRECTION_FROM_TOP; ?></option>
486
+ <option value="<?php echo AD_DIRECTION_FROM_BOTTOM; ?>" <?php echo ($obj->get_direction_type()==AD_DIRECTION_FROM_BOTTOM) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DIRECTION_FROM_BOTTOM; ?></option>
487
+ </select>
488
+ paragraphs with tags&nbsp;
489
+ </span>
490
+ <span style="display: table-cell;">
491
+ <input
492
+ style="border-radius: 5px; width: 100%;"
493
+ title="Comma separated HTML tags, usually only 'p' tags are used"
494
+ type="text" name="<?php echo AI_OPTION_PARAGRAPH_TAGS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
495
+ default="<?php echo $default->get_paragraph_tags(); ?>"
496
+ value="<?php echo $obj->get_paragraph_tags(); ?>"
497
+ size="12"
498
+ maxlength="50"/>
499
+ </span>
500
+ <span style="display: table-cell; width: 1px; white-space: nowrap;">
501
+ &nbsp;
502
+ that have between
503
+ <input
504
+ style="border-radius: 5px;"
505
+ type="text"
506
+ name="<?php echo AI_OPTION_MIN_PARAGRAPH_WORDS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
507
+ default="<?php echo $default->get_minimum_paragraph_words(); ?>"
508
+ value="<?php echo $obj->get_minimum_paragraph_words(); ?>"
509
+ size="4"
510
+ maxlength="5" />
511
+ and
512
+ <input
513
+ style="border-radius: 5px;"
514
+ type="text"
515
+ name="<?php echo AI_OPTION_MAX_PARAGRAPH_WORDS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
516
+ default="<?php echo $default->get_maximum_paragraph_words(); ?>"
517
+ value="<?php echo $obj->get_maximum_paragraph_words(); ?>"
518
+ title="Maximum number of paragraph words, leave empty for no limit"
519
+ size="4"
520
+ maxlength="5" />
521
+ words
522
+ </span>
523
  </div>
524
+
525
+ <div class="max-input" style="margin: 8px 0 8px 0;">
526
+ <span style="display: table-cell; width: 1px; white-space: nowrap;">
527
+ and
528
+ <select style="border-radius: 5px; margin-bottom: 3px;" name="<?php echo AI_OPTION_PARAGRAPH_TEXT_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_paragraph_text_type(); ?>">
529
+ <option value="<?php echo AD_CONTAIN; ?>" <?php echo ($obj->get_paragraph_text_type() == AD_CONTAIN) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_CONTAIN; ?></option>
530
+ <option value="<?php echo AD_DO_NOT_CONTAIN; ?>" <?php echo ($obj->get_paragraph_text_type() == AD_DO_NOT_CONTAIN) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DO_NOT_CONTAIN; ?></option>
531
+ </select>
532
+ </span>
533
+ <span class="small-input-tags" style="display: table-cell;">
534
+ <input
535
+ style="border-radius: 5px; width: 100%;"
536
+ title="Comma separated text"
537
+ type="text"
538
+ name="<?php echo AI_OPTION_PARAGRAPH_TEXT, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
539
+ default="<?php echo $default->get_paragraph_text(); ?>"
540
+ value="<?php echo $obj->get_paragraph_text(); ?>"
541
+ maxlength="200" />
542
+ </span>
543
+ <span style="display: table-cell; width: 1px; white-space: nowrap; padding-left: 20px;">
544
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_COUNT_INSIDE_BLOCKQUOTE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
545
+ <input id= "ignore_blockquote-<?php echo $ad_number; ?>" style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_COUNT_INSIDE_BLOCKQUOTE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_count_inside_blockquote(); ?>" <?php if ($obj->get_count_inside_blockquote()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
546
+ <label for="ignore_blockquote-<?php echo $ad_number; ?>" title="Count also paragraphs inside &lt;blockquote&gt;...&lt;/blockquote&gt; elements">Count also inside <pre style="margin: 0; display: inline; color: blue; font-size: 11px;">&lt;blockquote&gt;</pre> elements</label>
547
+ </span>
548
  </div>
549
+
550
+ <div style="margin: 8px 0 4px 0;">
551
+ Minimum number of paragraphs
552
+ <input
553
+ style="border-radius: 5px;"
554
+ type="text"
555
+ name="<?php echo AI_OPTION_MIN_PARAGRAPHS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
556
+ default="<?php echo $default->get_paragraph_number_minimum(); ?>"
557
+ value="<?php echo $obj->get_paragraph_number_minimum() ?>"
558
+ size="2"
559
+ maxlength="3" />
560
+ <div style="float: right;">
561
+ </div>
562
+ <div style="clear: both;"></div>
563
+ </div>
564
+ </div>
565
+
566
+ <div id="paragraph-clearance-<?php echo $ad_number; ?>" style="padding:4px 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px;<?php echo $paragraph_clearance ? "" : " display: none;" ?>">
567
+ <div class="max-input" style="margin: 4px 0 8px 0;">
568
+ <span style="display: table-cell; width: 1px; white-space: nowrap;">
569
+ In
570
+ <input
571
+ style="border-radius: 5px;"
572
+ type="text"
573
+ name="<?php echo AI_OPTION_AVOID_PARAGRAPHS_ABOVE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
574
+ default="<?php echo $default->get_avoid_paragraphs_above(); ?>"
575
+ value="<?php echo $obj->get_avoid_paragraphs_above(); ?>"
576
+ title="Number of paragraphs above to check, leave empty to disable checking"
577
+ size="2"
578
+ maxlength="3" />
579
+ paragraphs above avoid&nbsp;
580
+ </span>
581
+ <span style="display: table-cell;">
582
+ <input
583
+ style="border-radius: 5px; width: 100%;"
584
+ title="Comma separated text"
585
+ type="text"
586
+ name="<?php echo AI_OPTION_AVOID_TEXT_ABOVE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
587
+ default="<?php echo $default->get_avoid_text_above(); ?>"
588
+ value="<?php echo $obj->get_avoid_text_above(); ?>"
589
+ maxlength="100" />
590
+ </span>
591
+ </div>
592
+
593
+ <div class="max-input" style="margin: 4px 0 8px 0;">
594
+ <span style="display: table-cell; width: 1px; white-space: nowrap;">
595
+ In
596
+ <input
597
+ style="border-radius: 5px;"
598
+ type="text"
599
+ name="<?php echo AI_OPTION_AVOID_PARAGRAPHS_BELOW, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
600
+ default="<?php echo $default->get_avoid_paragraphs_below(); ?>"
601
+ value="<?php echo $obj->get_avoid_paragraphs_below(); ?>"
602
+ title="Number of paragraphs below to check, leave empty to disable checking"
603
+ size="2"
604
+ maxlength="3" />
605
+ paragraphs below avoid&nbsp;
606
+ </span>
607
+ <span style="display: table-cell;">
608
+ <input
609
+ style="border-radius: 5px; width: 100%;"
610
+ title="Comma separated text"
611
+ type="text"
612
+ name="<?php echo AI_OPTION_AVOID_TEXT_BELOW, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
613
+ default="<?php echo $default->get_avoid_text_below(); ?>"
614
+ value="<?php echo $obj->get_avoid_text_below(); ?>"
615
+ maxlength="100" />
616
+ </span>
617
+ </div>
618
+
619
+ <div style="margin: 8px 0 4px 0;">
620
+ If text is found
621
+ <select id="avoid-action-<?php echo $ad_number; ?>" style="border-radius: 5px; margin-bottom: 3px;" name="<?php echo AI_OPTION_AVOID_ACTION, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_avoid_action(); ?>">
622
+ <option value="<?php echo AD_DO_NOT_INSERT; ?>" <?php echo ($obj->get_avoid_action() == AD_DO_NOT_INSERT) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DO_NOT_INSERT; ?></option>
623
+ <option value="<?php echo AD_TRY_TO_SHIFT_POSITION; ?>" <?php echo ($obj->get_avoid_action() == AD_TRY_TO_SHIFT_POSITION) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_TRY_TO_SHIFT_POSITION; ?></option>
624
  </select>
625
+ <span id="check-up-to-<?php echo $ad_number; ?>">
626
+ &mdash; check up to
627
+ <input
628
+ style="border-radius: 5px;"
629
+ type="text"
630
+ name="<?php echo AI_OPTION_AVOID_TRY_LIMIT, WP_FORM_FIELD_POSTFIX, $ad_number; ?>"
631
+ default="<?php echo $default->get_avoid_try_limit(); ?>"
632
+ value="<?php echo $obj->get_avoid_try_limit(); ?>"
633
+ size="2"
634
+ maxlength="3" />
635
+ paragraphs
636
+ <select style="border-radius: 5px; margin-bottom: 3px;" name="<?php echo AI_OPTION_AVOID_DIRECTION, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_avoid_direction(); ?>">
637
+ <option value="<?php echo AD_ABOVE; ?>" <?php echo ($obj->get_avoid_direction() == AD_ABOVE) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ABOVE; ?></option>
638
+ <option value="<?php echo AD_BELOW; ?>" <?php echo ($obj->get_avoid_direction() == AD_BELOW) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_BELOW; ?></option>
639
+ <option value="<?php echo AD_ABOVE_AND_THEN_BELOW; ?>" <?php echo ($obj->get_avoid_direction() == AD_ABOVE_AND_THEN_BELOW) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_ABOVE_AND_THEN_BELOW; ?></option>
640
+ <option value="<?php echo AD_BELOW_AND_THEN_ABOVE; ?>" <?php echo ($obj->get_avoid_direction() == AD_BELOW_AND_THEN_ABOVE) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_BELOW_AND_THEN_ABOVE; ?></option>
641
+ </select>
642
+ </span>
643
  </div>
644
+ </div>
645
+
646
+ <div id="content-settings-<?php echo $ad_number; ?>" style="padding: 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px;<?php echo $content_settings ? "" : " display: none;" ?>">
647
+ Post/Static page must have between
648
+ <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_MIN_WORDS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_minimum_words(); ?>" value="<?php echo $obj->get_minimum_words() ?>" size="4" maxlength="6" />
649
+ and
650
+ <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_MAX_WORDS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" title="Maximum number of post/static page words, leave empty for no limit" default="<?php echo $default->get_maximum_words(); ?>" value="<?php echo $obj->get_maximum_words() ?>" size="4" maxlength="6" />
651
+ words
652
+
653
+ <div style="float: right;">
654
+ Display <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_AFTER_DAYS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_after_day(); ?>" value="<?php echo $obj->get_ad_after_day(); ?>" size="2" maxlength="3" title="0 means publish immediately" /> days after publishing
655
  </div>
656
  </div>
657
 
658
+ <div class="responsive-table" id="list-settings-<?php echo $ad_number; ?>" style="margin: 8px 0; border: 1px solid #ddd; border-radius: 5px; <?php if (!$show_lists) echo 'display: none;'; ?>">
659
+ <table style="padding: 8px 8px 10px 8px;">
660
  <tbody>
661
  <tr>
662
  <td style="padding-right: 7px;">
663
  Categories
664
  </td>
665
  <td style="padding-right: 7px; width: 70%;">
666
+ <input style="border-radius: 5px; width: 100%;" title="Comma separated category slugs" type="text" name="<?php echo AI_OPTION_CATEGORY_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_block_cat(); ?>" value="<?php echo $cat_list; ?>" size="54" maxlength="500" />
667
  </td>
668
  <td style="padding-right: 7px;">
669
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_CATEGORY_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="category-blacklist-<?php echo $ad_number; ?>" default="<?php echo $default->get_ad_block_cat_type() == AD_BLACK_LIST; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_ad_block_cat_type() == AD_BLACK_LIST) echo 'checked '; ?> />
670
  <label for="category-blacklist-<?php echo $ad_number; ?>" title="Blacklist categories"><?php echo AD_BLACK_LIST; ?></label>
671
  </td>
672
  <td>
673
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_CATEGORY_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="category-whitelist-<?php echo $ad_number; ?>" default="<?php echo $default->get_ad_block_cat_type() == AD_WHITE_LIST; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_ad_block_cat_type() == AD_WHITE_LIST) echo 'checked '; ?> />
674
  <label for="category-whitelist-<?php echo $ad_number; ?>" title="Whitelist categories"><?php echo AD_WHITE_LIST; ?></label>
675
  </td>
676
  </tr>
678
  <td style="padding-right: 7px;">
679
  Tags
680
  </td>
681
+ <td style="padding-right: 7px;">
682
+ <input style="border-radius: 5px; width: 100%;" title="Comma separated tags" type="text" name="<?php echo AI_OPTION_TAG_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_block_tag(); ?>" value="<?php echo $tag_list; ?>" size="54" maxlength="500"/>
683
  </td>
684
  <td style="padding-right: 7px;">
685
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_TAG_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="tag-blacklist-<?php echo $ad_number; ?>" default="<?php echo $default->get_ad_block_tag_type() == AD_BLACK_LIST; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_ad_block_tag_type() == AD_BLACK_LIST) echo 'checked '; ?> />
686
  <label for="tag-blacklist-<?php echo $ad_number; ?>" title="Blacklist tags"><?php echo AD_BLACK_LIST; ?></label>
687
  </td>
688
  <td>
689
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_TAG_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="tag-whitelist-<?php echo $ad_number; ?>" default="<?php echo $default->get_ad_block_tag_type() == AD_WHITE_LIST; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_ad_block_tag_type() == AD_WHITE_LIST) echo 'checked '; ?> />
690
  <label for="tag-whitelist-<?php echo $ad_number; ?>" title="Whitelist tags"><?php echo AD_WHITE_LIST; ?></label>
691
  </td>
692
  </tr>
693
+ <tr>
694
+ <td style="padding-right: 7px;">
695
+ Post IDs
696
+ </td>
697
+ <td style="padding-right: 7px;">
698
+ <input style="border-radius: 5px; width: 100%;" title="Comma separated post/page IDs" type="text" name="<?php echo AI_OPTION_ID_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_id_list(); ?>" value="<?php echo $id_list; ?>" size="54" maxlength="500"/>
699
+ </td>
700
+ <td style="padding-right: 7px;">
701
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_ID_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="id-blacklist-<?php echo $ad_number; ?>" default="<?php echo $default->get_id_list_type() == AD_BLACK_LIST; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_id_list_type() == AD_BLACK_LIST) echo 'checked '; ?> />
702
+ <label for="id-blacklist-<?php echo $ad_number; ?>" title="Blacklist IDs"><?php echo AD_BLACK_LIST; ?></label>
703
+ </td>
704
+ <td>
705
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_ID_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="id-whitelist-<?php echo $ad_number; ?>" default="<?php echo $default->get_id_list_type() == AD_WHITE_LIST; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_id_list_type() == AD_WHITE_LIST) echo 'checked '; ?> />
706
+ <label for="id-whitelist-<?php echo $ad_number; ?>" title="Whitelist IDs"><?php echo AD_WHITE_LIST; ?></label>
707
+ </td>
708
+ </tr>
709
  <tr>
710
  <td style="padding-right: 7px;">
711
  Urls
712
  </td>
713
+ <td style="padding-right: 7px;">
714
+ <input style="border-radius: 5px; width: 100%;" title="SPACE separated urls (page addresses) starting with / after domain name (e.g. /permalink-url, use only when you need to taget a specific url not accessible by other means). You can also use partial urls with * (/url-start*. *url-pattern*, *url-end)" type="text" name="<?php echo AI_OPTION_URL_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_url_list(); ?>" value="<?php echo $url_list; ?>" size="54" maxlength="500"/>
715
  </td>
716
  <td style="padding-right: 7px;">
717
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_URL_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="url-blacklist-<?php echo $ad_number; ?>" default="<?php echo $default->get_ad_url_list_type() == AD_BLACK_LIST; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_ad_url_list_type() == AD_BLACK_LIST) echo 'checked '; ?> />
718
  <label for="url-blacklist-<?php echo $ad_number; ?>" title="Blacklist urls"><?php echo AD_BLACK_LIST; ?></label>
719
  </td>
720
  <td>
721
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_URL_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="url-whitelist-<?php echo $ad_number; ?>" default="<?php echo $default->get_ad_url_list_type() == AD_WHITE_LIST; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_ad_url_list_type() == AD_WHITE_LIST) echo 'checked '; ?> />
722
  <label for="url-whitelist-<?php echo $ad_number; ?>" title="Whitelist urls"><?php echo AD_WHITE_LIST; ?></label>
723
  </td>
724
  </tr>
725
+ <tr>
726
+ <td style="padding-right: 7px;">
727
+ Url parameters
728
+ </td>
729
+ <td style="padding-right: 7px;">
730
+ <input style="border-radius: 5px; width: 100%;" title="Comma separated url query parameters with optional values (use either 'prameter' or 'prameter=value')" type="text" name="<?php echo AI_OPTION_URL_PARAMETER_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_url_parameter_list(); ?>" value="<?php echo $url_parameter_list; ?>" size="54" maxlength="500"/>
731
+ </td>
732
+ <td style="padding-right: 7px;">
733
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_URL_PARAMETER_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="url-parameter-blacklist-<?php echo $ad_number; ?>" default="<?php echo $default->get_url_parameter_list_type() == AD_BLACK_LIST; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_url_parameter_list_type() == AD_BLACK_LIST) echo 'checked '; ?> />
734
+ <label for="url-parameter-blacklist-<?php echo $ad_number; ?>" title="Blacklist url parameters"><?php echo AD_BLACK_LIST; ?></label>
735
+ </td>
736
+ <td>
737
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_URL_PARAMETER_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="url-parameter-whitelist-<?php echo $ad_number; ?>" default="<?php echo $default->get_url_parameter_list_type() == AD_WHITE_LIST; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_url_parameter_list_type() == AD_WHITE_LIST) echo 'checked '; ?> />
738
+ <label for="url-parameter-whitelist-<?php echo $ad_number; ?>" title="Whitelist url parameters"><?php echo AD_WHITE_LIST; ?></label>
739
+ </td>
740
+ </tr>
741
  <tr>
742
  <td style="padding-right: 7px;">
743
  Referers
744
  </td>
745
+ <td style="padding-right: 7px;">
746
+ <input style="border-radius: 5px; width: 100%;" title="Comma separated domains, use # for no referer" type="text" name="<?php echo AI_OPTION_DOMAIN_LIST, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_domain_list(); ?>" value="<?php echo $domain_list; ?>" size="54" maxlength="500"/>
747
  </td>
748
  <td style="padding-right: 7px;">
749
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_DOMAIN_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="referer-blacklist-<?php echo $ad_number; ?>" default="<?php echo $default->get_ad_domain_list_type() == AD_BLACK_LIST; ?>" value="<?php echo AD_BLACK_LIST; ?>" <?php if ($obj->get_ad_domain_list_type() == AD_BLACK_LIST) echo 'checked '; ?> />
750
  <label for="referer-blacklist-<?php echo $ad_number; ?>" title="Blacklist referers"><?php echo AD_BLACK_LIST; ?></label>
751
  </td>
752
  <td>
753
+ <input style="border-radius: 5px;" type="radio" name="<?php echo AI_OPTION_DOMAIN_LIST_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="referer-whitelist-<?php echo $ad_number; ?>" default="<?php echo $default->get_ad_domain_list_type() == AD_WHITE_LIST; ?>" value="<?php echo AD_WHITE_LIST; ?>" <?php if ($obj->get_ad_domain_list_type() == AD_WHITE_LIST) echo 'checked '; ?> />
754
  <label for="referer-whitelist-<?php echo $ad_number; ?>" title="Whitelist referers"><?php echo AD_WHITE_LIST; ?></label>
755
  </td>
756
  </tr>
758
  </table>
759
  </div>
760
 
761
+ <div id="manual-settings-<?php echo $ad_number; ?>" class="small-button" style="padding:7px; margin: 8px 0; text-align: left; border: 1px solid #ddd; border-radius: 5px; <?php if (!$show_manual) echo 'display: none;'; ?>">
762
  <table>
763
  <tr>
764
  <td style="padding: 4px 10px 4px 0;">
765
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_WIDGET, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
766
+ <input style="border-radius: 5px;" id="enable-widget-<?php echo $ad_number; ?>" type="checkbox" name="<?php echo AI_OPTION_ENABLE_WIDGET, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_enable_widget(); ?>" <?php if ($obj->get_enable_widget () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
767
  <label for="enable-widget-<?php echo $ad_number; ?>" title="Enable or disable widget for this code block">
768
  Widget
769
  </label>
776
  <tr>
777
  <td style="padding: 4px 10px 4px 0;">
778
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_MANUAL, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
779
+ <input style="border-radius: 5px;" type="checkbox" id="enable-shortcode-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_ENABLE_MANUAL, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_enable_manual(); ?>" <?php if ($obj->get_enable_manual () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
780
  <label for="enable-shortcode-<?php echo $ad_number; ?>" title="Enable or disable shortcode for manual insertion of this code block in posts and pages">
781
  Shortcode
782
  </label>
783
  </td>
784
+ <td class="select">
785
  <pre style= "margin: 0; display: inline; color: blue; font-size: 11px;">[adinserter block="<?php echo $ad_number; ?>"]</pre>
786
  or <pre style= "margin: 0; display: inline; color: blue;">[adinserter name="<?php echo $obj->get_ad_name(); ?>"]</pre>
787
  </td>
789
  <tr>
790
  <td style="padding: 4px 10px 4px 0;">
791
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_PHP_CALL, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
792
+ <input style="border-radius: 5px;" id="enable-php-call-<?php echo $ad_number; ?>" type="checkbox" name="<?php echo AI_OPTION_ENABLE_PHP_CALL, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_enable_php_call(); ?>" <?php if ($obj->get_enable_php_call () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
793
  <label for="enable-php-call-<?php echo $ad_number; ?>" title="Enable or disable PHP function call to insert this code block at any position in template file. If function is disabled for block it will return empty string.">
794
  PHP function
795
  </label>
796
  </td>
797
+ <td class="select">
798
+ <pre style="margin: 0; display: inline; color: blue; font-size: 11px;">&lt;?php if (function_exists ('adinserter')) echo adinserter (<?php echo $ad_number; ?>); ?&gt;</pre>
799
  </td>
800
  </tr>
801
  </table>
802
  </div>
803
 
804
+ <div id="misc-settings-<?php echo $ad_number; ?>" style="margin: 8px 0; padding: 0 8px; border: 1px solid #ddd; border-radius: 5px; <?php if (!$show_misc) echo 'display: none;'; ?>">
805
+ <div class="max-input" style="margin: 8px 0;">
806
+ <span style="display: table-cell;">
807
+ Display for
808
+ <select style="border-radius: 5px; margin-bottom: 3px;" id="display-for-users-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_DISPLAY_FOR_USERS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_display_for_users(); ?>" style="width:160px">
809
+ <option value="<?php echo AD_DISPLAY_ALL_USERS; ?>" <?php echo ($obj->get_display_for_users()==AD_DISPLAY_ALL_USERS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_ALL_USERS; ?></option>
810
+ <option value="<?php echo AD_DISPLAY_LOGGED_IN_USERS; ?>" <?php echo ($obj->get_display_for_users()==AD_DISPLAY_LOGGED_IN_USERS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_LOGGED_IN_USERS; ?></option>
811
+ <option value="<?php echo AD_DISPLAY_NOT_LOGGED_IN_USERS; ?>" <?php echo ($obj->get_display_for_users()==AD_DISPLAY_NOT_LOGGED_IN_USERS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_NOT_LOGGED_IN_USERS; ?></option>
812
+ <option value="<?php echo AD_DISPLAY_ADMINISTRATORS; ?>" <?php echo ($obj->get_display_for_users()==AD_DISPLAY_ADMINISTRATORS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_ADMINISTRATORS; ?></option>
813
+ </select>
814
+ </span>
815
+ <span style="display: table-cell;">
816
+ Max <input style="border-radius: 5px;" type="text" name="<?php echo AI_OPTION_MAXIMUM_INSERTIONS, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_maximum_insertions (); ?>" value="<?php echo $obj->get_maximum_insertions (); ?>" size="2" maxlength="3" title="Empty or 0 means no limit" /> insertions
817
+ </span>
818
+ <span style="display: table-cell;">
819
+ General tag
820
+ </span>
821
+ <span style="display: table-cell;">
822
+ <input style="border-radius: 5px; width: 100%;" type="text" name="<?php echo AI_OPTION_GENERAL_TAG, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_ad_general_tag(); ?>" value="<?php echo $obj->get_ad_general_tag(); ?>" maxlength="40" title="Used for {tags} when no page data is found" />
823
+ </span>
824
+ </div>
825
 
826
+ <div style="margin: 8px 0;">
827
+ <div class="max-input" style="margin: 8px 0;">
828
+ <span style="display: table-cell;">
829
+ Filter insertions
830
+ </span>
831
+ <span style="display: table-cell;">
832
+ <input style="border-radius: 5px; width: 100%; padding-right: 10px;" type="text" name="<?php echo AI_OPTION_EXCERPT_NUMBER, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_call_filter(); ?>" value="<?php echo $obj->get_call_filter(); ?>" title= "Filter insertions by specifying wanted calls for this block - single number or comma separated numbers, empty 0 means all / no limits. Set Counter for filter to Auto if you are using only one display type." size="16" maxlength="20" />
833
+ </span>
834
+ <span style="display: table-cell;">
835
+ &nbsp;&nbsp;&nbsp;Counter for filter
836
+ <select style="border-radius: 5px; margin-bottom: 3px;" id="filter-type-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_FILTER_TYPE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_filter_type(); ?>" style="width:160px">
837
+ <option value="<?php echo AI_OPTION_FILTER_AUTO; ?>" <?php echo ($obj->get_filter_type()==AI_OPTION_FILTER_AUTO) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AI_OPTION_FILTER_AUTO; ?></option>
838
+ <option value="<?php echo AI_OPTION_FILTER_PHP_FUNCTION_CALLS; ?>" <?php echo ($obj->get_filter_type()==AI_OPTION_FILTER_PHP_FUNCTION_CALLS) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AI_OPTION_FILTER_PHP_FUNCTION_CALLS; ?></option>
839
+ <option value="<?php echo AI_OPTION_FILTER_CONTENT_PROCESSING; ?>" <?php echo ($obj->get_filter_type()==AI_OPTION_FILTER_CONTENT_PROCESSING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AI_OPTION_FILTER_CONTENT_PROCESSING; ?></option>
840
+ <option value="<?php echo AI_OPTION_FILTER_EXCERPT_PROCESSING; ?>" <?php echo ($obj->get_filter_type()==AI_OPTION_FILTER_EXCERPT_PROCESSING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AI_OPTION_FILTER_EXCERPT_PROCESSING; ?></option>
841
+ <option value="<?php echo AI_OPTION_FILTER_BEFORE_POST_PROCESSING; ?>" <?php echo ($obj->get_filter_type()==AI_OPTION_FILTER_BEFORE_POST_PROCESSING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AI_OPTION_FILTER_BEFORE_POST_PROCESSING; ?></option>
842
+ <option value="<?php echo AI_OPTION_FILTER_AFTER_POST_PROCESSING; ?>" <?php echo ($obj->get_filter_type()==AI_OPTION_FILTER_AFTER_POST_PROCESSING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AI_OPTION_FILTER_AFTER_POST_PROCESSING; ?></option>
843
+ <option value="<?php echo AI_OPTION_FILTER_WIDGET_DRAWING; ?>" <?php echo ($obj->get_filter_type()==AI_OPTION_FILTER_WIDGET_DRAWING) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AI_OPTION_FILTER_WIDGET_DRAWING; ?></option>
844
+ </select>
845
+ </span>
846
+ <span style="display: table-cell;">
847
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_FEED, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
848
+ <input style="border-radius: 5px; margin-left: 10px;" id="enable-feed-<?php echo $ad_number; ?>" type="checkbox" name="<?php echo AI_OPTION_ENABLE_FEED, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_enable_feed(); ?>" <?php if ($obj->get_enable_feed () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
849
+ <label for="enable-feed-<?php echo $ad_number; ?>" title="Enable or disable insertion in feeds">Feed</label>
850
+ </span>
851
+ <span style="display: table-cell;">
852
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_404, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
853
+ <input style="border-radius: 5px; margin-left: 10px;" id="enable-404-<?php echo $ad_number; ?>" type="checkbox" name="<?php echo AI_OPTION_ENABLE_404, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_enable_404(); ?>" <?php if ($obj->get_enable_404 () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
854
+ <label for="enable-404-<?php echo $ad_number; ?>" title="Enable or disable display on page for Error 404: Page not found">404 page</label>
855
+ </span>
856
+ </div>
857
  </div>
858
 
 
859
  </div>
860
 
861
+ <div id="device-detection-settings-<?php echo $ad_number; ?>" style="padding:8px 8px 8px 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px; <?php if (!$show_devices) echo 'display: none;'; ?>">
862
  <table>
863
  <tr>
864
  <td>
865
  <div style="margin-bottom: 5px;">
866
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DETECT_CLIENT_SIDE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
867
+ <input id="client-side-detection-<?php echo $ad_number; ?>" style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DETECT_CLIENT_SIDE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="1" default="<?php echo $default->get_detection_client_side(); ?>" <?php if ($obj->get_detection_client_side ()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
868
  <label for="client-side-detection-<?php echo $ad_number; ?>">Use client-side detection to display only on:</label>
869
  </div>
870
 
877
  ?>
878
  <div style="margin: 8px 0;">
879
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DETECT_VIEWPORT, '_', $viewport, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
880
+ <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DETECT_VIEWPORT, '_', $viewport, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="viewport-<?php echo $viewport, "-", $ad_number; ?>" value="1" default="<?php echo $default->get_detection_viewport ($viewport); ?>" <?php if ($obj->get_detection_viewport ($viewport)==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
881
  <label for="viewport-<?php echo $viewport, "-", $ad_number; ?>" title="Device min width <?php echo get_viewport_width ($viewport); ?> px"><?php echo $viewport_name; ?></label>
882
  </div>
883
  <?php
887
  </div>
888
  </td><td style="padding-left: 40px; vertical-align: top;">
889
  <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DETECT_SERVER_SIDE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" value="0" />
890
+ <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DETECT_SERVER_SIDE, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" id="server-side-detection-<?php echo $ad_number; ?>" value="1" default="<?php echo $default->get_detection_server_side(); ?>" <?php if ($obj->get_detection_server_side ()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
891
+ <label for="server-side-detection-<?php echo $ad_number; ?>">Use server-side detection to insert code only for </label>
892
 
893
+ <div style="margin: 10px 0 10px 40px;">
894
+ <select style="border-radius: 5px; margin-bottom: 3px;" id="display-for-devices-<?php echo $ad_number; ?>" name="<?php echo AI_OPTION_DISPLAY_FOR_DEVICES, WP_FORM_FIELD_POSTFIX, $ad_number; ?>" default="<?php echo $default->get_display_for_devices(); ?>" style="width:160px">
895
  <option value="<?php echo AD_DISPLAY_DESKTOP_DEVICES; ?>" <?php echo ($obj->get_display_for_devices() == AD_DISPLAY_DESKTOP_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_DESKTOP_DEVICES; ?></option>
896
  <option value="<?php echo AD_DISPLAY_MOBILE_DEVICES; ?>" <?php echo ($obj->get_display_for_devices() == AD_DISPLAY_MOBILE_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_MOBILE_DEVICES; ?></option>
897
  <option value="<?php echo AD_DISPLAY_TABLET_DEVICES; ?>" <?php echo ($obj->get_display_for_devices() == AD_DISPLAY_TABLET_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_TABLET_DEVICES; ?></option>
909
  <div id="no-wrapping-warning-<?php echo $ad_number; ?>" style="padding:8px; margin: 8px 0 8px 5px; border: 1px solid #ddd; border-radius: 5px; display: none;">
910
  <span id="" style="margin-top: 5px;"><strong><span style="color: red;">WARNING:</span> No Wrapping</strong> style has no HTML code for client-side device detection!</span>
911
  </div>
 
912
  </div>
 
913
  <?php
914
  }
915
  ?>
916
+ <div id="tab-0" style="padding: 0;<?php echo $tab_visible ? "" : " display: none;" ?>">
917
+ <div style="margin: 16px 0 16px 4px;">
918
+ <h3 style="margin: 0; float: left;"><?php echo AD_INSERTER_NAME ?> Settings <?php if (isset ($ai_db_options ['global']['VERSION'])) echo (int) ($ai_db_options ['global']['VERSION'][0].$ai_db_options ['global']['VERSION'][1]), '.',
 
919
  (int) ($ai_db_options ['global']['VERSION'][2].$ai_db_options ['global']['VERSION'][3]), '.',
920
+ (int) ($ai_db_options ['global']['VERSION'][4].$ai_db_options ['global']['VERSION'][5]); ?></h3>
921
+ <h4 style="margin: 0px; float: right;" title="Settings timestamp"><?php echo isset ($ai_db_options ['global']['TIMESTAMP']) ? date ("Y-m-d H:i:s", $ai_db_options ['global']['TIMESTAMP'] + get_option ('gmt_offset') * 3600) : ""; ?></h4>
922
+ <div style="clear: both;"></div>
923
  </div>
924
 
925
+ <div style="margin: 16px 0;">
926
+ <div style="float: right;">
927
  <?php if (function_exists ('ai_settings_global_buttons')) ai_settings_global_buttons (); ?>
928
+ <input style="display: none; border-radius: 5px; font-weight: bold;" name="<?php echo AI_FORM_SAVE; ?>" value="Save Settings" type="submit" style="width:120px; font-weight: bold;" />
929
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
930
 
931
+ <div style="float: left; color: red;">
932
+ <input onclick="if (confirm('Are you sure you want to reset all settings?')) return true; return false" name="<?php echo AI_FORM_CLEAR; ?>" value="Reset All Settings" type="submit" style="display: none; width:120px; font-weight: bold; color: #e44;" />
933
+ </div>
934
 
935
+ <div style="clear: both;"></div>
 
 
936
  </div>
937
 
938
+ <?php
939
+ if (function_exists ('ai_global_settings')) ai_global_settings ();
 
 
 
 
 
 
940
 
941
+ if ($enabled_h) $style_h = "font-weight: bold; color: #66f;"; else $style_h = "";
942
+ if ($enabled_f) $style_f = "font-weight: bold; color: #66f;"; else $style_f = "";
943
+ if (false) $style_d = "font-weight: bold; color: #e44;"; else $style_d = "";
944
+ ?>
945
 
946
+ <div id="ai-plugin-settings-tab-container" style="padding: 0; margin 8px 0 0 0; border: 0;">
947
+ <ul id="ai-plugin-settings-tabs" style="display: none;">
948
+ <li id="ai-g" class="ai-plugin-tab"><a href="#tab-general">General</a></li>
949
+ <li id="ai-v" class="ai-plugin-tab"><a href="#tab-viewports">Viewports</a></li>
950
+ <li id="ai-h" class="ai-plugin-tab"><a href="#tab-header"><span style="<?php echo $style_h ?>">Header</span></a></li>
951
+ <li id="ai-f" class="ai-plugin-tab"><a href="#tab-footer"><span style="<?php echo $style_f ?>">Footer</span></a></li>
952
+ <?php if (function_exists ('ai_multisite_settings_tab')) ai_multisite_settings_tab (); ?>
953
+ <li id="ai-d" class="ai-plugin-tab"><a href="#tab-debugging"><span style="<?php echo $style_d ?>">Debugging</span></a></li>
954
+ </ul>
955
+
956
+ <div id="tab-general" style="margin: 8px 0; padding: 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
957
+
958
+ <?php if (function_exists ('ai_general_settings')) ai_general_settings (); ?>
959
+
960
+ <div style="margin: 8px;">
961
+ Syntax Highlighter Theme &nbsp;&nbsp;&nbsp;
962
+
963
+ <select
964
+ style="border-radius: 5px; width:220px"
965
+ id="syntax-highlighter-theme"
966
+ name="syntax-highlighter-theme"
967
+ value="Value">
968
+ <optgroup label="None">
969
+ <option value="<?php echo AI_OPTION_DISABLED; ?>" <?php echo ($syntax_highlighter_theme == AI_OPTION_DISABLED) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>No Syntax Highlighting</option>
970
+ </optgroup>
971
+ <optgroup label="Light">
972
+ <option value="chrome" <?php echo ($syntax_highlighter_theme == 'chrome') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Chrome</option>
973
+ <option value="clouds" <?php echo ($syntax_highlighter_theme == 'clouds') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Clouds</option>
974
+ <option value="crimson_editor" <?php echo ($syntax_highlighter_theme == 'crimson_editor') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Crimson Editor</option>
975
+ <option value="dawn" <?php echo ($syntax_highlighter_theme == 'dawn') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Dawn</option>
976
+ <option value="dreamweaver" <?php echo ($syntax_highlighter_theme == 'dreamweaver') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Dreamweaver</option>
977
+ <option value="eclipse" <?php echo ($syntax_highlighter_theme == 'eclipse') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Eclipse</option>
978
+ <option value="github" <?php echo ($syntax_highlighter_theme == 'github') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>GitHub</option>
979
+ <option value="katzenmilch" <?php echo ($syntax_highlighter_theme == 'katzenmilch') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Katzenmilch</option>
980
+ <option value="kuroir" <?php echo ($syntax_highlighter_theme == 'kuroir') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Kuroir</option>
981
+ <option value="solarized_light" <?php echo ($syntax_highlighter_theme == 'solarized_light') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Solarized Light</option>
982
+ <option value="textmate" <?php echo ($syntax_highlighter_theme == 'textmate') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Textmate</option>
983
+ <option value="tomorrow" <?php echo ($syntax_highlighter_theme == 'tomorrow') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow</option>
984
+ <option value="xcode" <?php echo ($syntax_highlighter_theme == 'xcode') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>XCode</option>
985
+ </optgroup>
986
+ <optgroup label="Dark">
987
+ <option value="ad_inserter" <?php echo ($syntax_highlighter_theme == 'ad_inserter') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Ad Inserter</option>
988
+ <option value="chaos" <?php echo ($syntax_highlighter_theme == 'chaos') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Chaos</option>
989
+ <option value="clouds_midnight" <?php echo ($syntax_highlighter_theme == 'clouds_midnight') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Clouds Midnight</option>
990
+ <option value="cobalt" <?php echo ($syntax_highlighter_theme == 'cobalt') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Cobalt</option>
991
+ <option value="idle_fingers" <?php echo ($syntax_highlighter_theme == 'idle_fingers') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Idle Fingers</option>
992
+ <option value="kr_theme" <?php echo ($syntax_highlighter_theme == 'kr_theme') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>krTheme</option>
993
+ <option value="merbivore" <?php echo ($syntax_highlighter_theme == 'merbivore') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Merbivore</option>
994
+ <option value="merbivore_soft" <?php echo ($syntax_highlighter_theme == 'merbivore_soft') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Merbivore Soft</option>
995
+ <option value="mono_industrial" <?php echo ($syntax_highlighter_theme == 'mono_industrial') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Mono Industrial</option>
996
+ <option value="monokai" <?php echo ($syntax_highlighter_theme == 'monokai') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Monokai</option>
997
+ <option value="pastel_on_dark" <?php echo ($syntax_highlighter_theme == 'pastel_on_dark') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Pastel on Dark</option>
998
+ <option value="solarized_dark" <?php echo ($syntax_highlighter_theme == 'solarized_dark') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Solarized Dark</option>
999
+ <option value="terminal" <?php echo ($syntax_highlighter_theme == 'terminal') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Terminal</option>
1000
+ <option value="tomorrow_night" <?php echo ($syntax_highlighter_theme == 'tomorrow_night') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow Night</option>
1001
+ <option value="tomorrow_night_blue" <?php echo ($syntax_highlighter_theme == 'tomorrow_night_blue') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow Night Blue</option>
1002
+ <option value="tomorrow_night_bright" <?php echo ($syntax_highlighter_theme == 'tomorrow_night_bright') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow Night Bright</option>
1003
+ <option value="tomorrow_night_eighties" <?php echo ($syntax_highlighter_theme == 'tomorrow_night_eighties') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Tomorrow Night 80s</option>
1004
+ <option value="twilight" <?php echo ($syntax_highlighter_theme == 'twilight') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Twilight</option>
1005
+ <option value="vibrant_ink" <?php echo ($syntax_highlighter_theme == 'vibrant_ink') ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>>Vibrant Ink</option>
1006
+ </optgroup>
1007
+ </select>
1008
+ </div>
1009
 
1010
+ <div style="margin: 8px;">
1011
+ Block Class Name &nbsp;&nbsp;&nbsp;
1012
+ <input style="border-radius: 5px; margin-left: 0px;" title="CSS Class Name" type="text" id="block-class-name" name="block-class-name" value="<?php echo $block_class_name; ?>" size="15" maxlength="40" />
1013
+ <span style= "margin: 3px 10px 0 0; display: inline; float: right;">Example: &nbsp;&nbsp; <pre style= "display: inline; color: blue;">&lt;div class="<?php echo $block_class_name; ?> <?php echo $block_class_name; ?>-n"&gt;<span style= "color: black;">...</span>&lt;/div&gt;</pre></span>
1014
+ </div>
 
 
 
 
 
 
 
 
 
 
 
1015
 
1016
+ <div style="margin: 8px;">
1017
+ Minimum User Role for Page/Post Ad Inserter Exceptions Editing
1018
+ <select style="border-radius: 5px; margin-bottom: 3px;" id="minimum-user-role" name="minimum-user-role" selected-value="1" style="width:300px">
1019
+ <?php wp_dropdown_roles (get_minimum_user_role ()); ?>
1020
+ </select>
1021
+ </div>
1022
 
1023
+ <div style="margin: 8px;">
1024
+ Plugin priority <input style="border-radius: 5px;" type="text" name="plugin_priority" value="<?php echo get_plugin_priority (); ?>" size="6" maxlength="6" />
1025
+ </div>
1026
+ </div>
1027
 
1028
+ <div id="tab-viewports" style="margin: 8px 0; padding: 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
1029
+ <div style="margin: 8px;">
1030
+ Viewport Settings used for client-side device detection
1031
+ </div>
1032
  <?php
1033
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
1034
  ?>
1035
+ <div style="margin: 8px;">
1036
+ Viewport <?php echo $viewport; ?> name:&nbsp;&nbsp;&nbsp;
1037
+ <input style="border-radius: 5px; margin-left: 0px;" type="text" id="option-name-<?php echo $viewport; ?>" name="viewport-name-<?php echo $viewport; ?>" value="<?php echo get_viewport_name ($viewport); ?>" size="15" maxlength="40" />
1038
+ <?php if ($viewport == AD_INSERTER_VIEWPORTS) echo '<span style="display: none;">' ?>
1039
+ &nbsp;&nbsp; min width
1040
+ <input style="border-radius: 5px;" type="text" id="option-length-<?php echo $viewport; ?>" name="viewport-width-<?php echo $viewport; ?>" value="<?php echo get_viewport_width ($viewport); ?>" size="4" maxlength="4" /> px
1041
+ <?php if ($viewport == AD_INSERTER_VIEWPORTS) echo '</span>' ?>
1042
+ </div>
 
 
1043
  <?php
1044
  }
1045
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
1046
  </div>
1047
 
1048
+ <div id="tab-header" style="margin: 0px 0; padding: 0; ">
1049
+ <div style="margin: 8px 0;">
1050
+ <div style="float: right;">
1051
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_MANUAL, '_block_h'; ?>" value="0" />
1052
+ <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_ENABLE_MANUAL, '_block_h'; ?>" id="enable-header" value="1" <?php if ($adH->get_enable_manual () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1053
+ <label for="enable-header" title="Enable or disable insertion of this code into HTML page header">Enable</label>
1054
+
1055
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_404, '_block_h'; ?>" value="0" />
1056
+ <input style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_ENABLE_404, '_block_h'; ?>" id="enable-header-404" value="1" <?php if ($adH->get_enable_404 () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1057
+ <label for="enable-header-404" title="Enable or disable insertion of this code into HTML page header on page for Error 404: Page not found">Insert on Error 404 page</label>
1058
+
1059
+ <?php if (AI_SYNTAX_HIGHLIGHTING) : ?>
1060
+ <input type="checkbox" style="border-radius: 5px; margin-left: 10px;" value="0" id="simple-editor-h" />
1061
+ <label for="simple-editor-h" title="Simple editor">Simple editor</label>
1062
+ <?php endif; ?>
1063
+
1064
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_PROCESS_PHP, '_block_h'; ?>" value="0" />
1065
+ <input style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_PROCESS_PHP, '_block_h'; ?>" value="1" id="process-php-h" <?php if ($adH->get_process_php () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1066
+ <label for="process-php-h" title="Process PHP code">Process PHP</label>
1067
+ </div>
1068
+
1069
+ <div>
1070
+ <h3 style="margin: 8px 0 8px 2px;">HTML Page Header Code</h3>
1071
+ </div>
1072
+ </div>
1073
 
1074
+ <div style="margin: 8px 0; width: 100%;">
1075
+ <div style="float: left;">
1076
+ Code in the <pre style="display: inline; color: blue;">&lt;head&gt;&lt;/head&gt;</pre> section of the HTML page
1077
+ </div>
1078
 
1079
+ <div style="clear: both;"></div>
1080
+ </div>
 
 
 
1081
 
1082
+ <div style="margin: 8px 0;">
1083
+ <textarea id="block-h" name="<?php echo AI_OPTION_CODE, '_block_h'; ?>" class="simple-editor" style="background-color:#F9F9F9; font-family: Courier, 'Courier New', monospace; font-weight: bold;"><?php echo esc_textarea ($adH->get_ad_data()); ?></textarea>
1084
+ </div>
 
1085
 
1086
+ <div id="device-detection-settings-h" style="padding:8px 8px 8px 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px;">
1087
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DETECT_SERVER_SIDE, WP_FORM_FIELD_POSTFIX, AI_HEADER_OPTION_NAME; ?>" value="0" />
1088
+ <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DETECT_SERVER_SIDE, WP_FORM_FIELD_POSTFIX, AI_HEADER_OPTION_NAME; ?>" id="server-side-detection-h" value="1" <?php if ($adH->get_detection_server_side ()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1089
+ <label for="server-side-detection-h">Use server-side detection to insert code only for </label>
1090
+ <select style="border-radius: 5px; margin-bottom: 3px;" id="display-for-devices-h" name="<?php echo AI_OPTION_DISPLAY_FOR_DEVICES, WP_FORM_FIELD_POSTFIX, AI_HEADER_OPTION_NAME; ?>" >
1091
+ <option value="<?php echo AD_DISPLAY_DESKTOP_DEVICES; ?>" <?php echo ($adH->get_display_for_devices() == AD_DISPLAY_DESKTOP_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_DESKTOP_DEVICES; ?></option>
1092
+ <option value="<?php echo AD_DISPLAY_MOBILE_DEVICES; ?>" <?php echo ($adH->get_display_for_devices() == AD_DISPLAY_MOBILE_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_MOBILE_DEVICES; ?></option>
1093
+ <option value="<?php echo AD_DISPLAY_TABLET_DEVICES; ?>" <?php echo ($adH->get_display_for_devices() == AD_DISPLAY_TABLET_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_TABLET_DEVICES; ?></option>
1094
+ <option value="<?php echo AD_DISPLAY_PHONE_DEVICES; ?>" <?php echo ($adH->get_display_for_devices() == AD_DISPLAY_PHONE_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_PHONE_DEVICES; ?></option>
1095
+ <option value="<?php echo AD_DISPLAY_DESKTOP_TABLET_DEVICES; ?>" <?php echo ($adH->get_display_for_devices() == AD_DISPLAY_DESKTOP_TABLET_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_DESKTOP_TABLET_DEVICES; ?></option>
1096
+ <option value="<?php echo AD_DISPLAY_DESKTOP_PHONE_DEVICES; ?>" <?php echo ($adH->get_display_for_devices() == AD_DISPLAY_DESKTOP_PHONE_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_DESKTOP_PHONE_DEVICES; ?></option>
1097
+ </select>
1098
+ devices
1099
+ </div>
1100
  </div>
 
1101
 
1102
+ <div id="tab-footer" style="margin: 0px 0; padding: 0; ">
1103
+ <div style="margin: 8px 0;">
1104
+ <div style="float: right;">
1105
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_MANUAL, '_block_f'; ?>" value="0" />
1106
+ <input style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_ENABLE_MANUAL, '_block_f'; ?>" id="enable-footer" value="1" <?php if ($adF->get_enable_manual () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1107
+ <label for="enable-footer" title="Enable or disable insertion of this code into HTML page footer">Enable</label>
1108
+
1109
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_ENABLE_404, '_block_f'; ?>" value="0" />
1110
+ <input style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_ENABLE_404, '_block_f'; ?>" id="enable-footer-404" value="1" <?php if ($adF->get_enable_404 () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1111
+ <label for="enable-footer-404" title="Enable or disable insertion of this code into HTML page footer on page for Error 404: Page not found">Insert on Error 404 page</label>
1112
+
1113
+ <?php if (AI_SYNTAX_HIGHLIGHTING) : ?>
1114
+ <input type="checkbox" style="border-radius: 5px; margin-left: 10px;" value="0" id="simple-editor-f" />
1115
+ <label for="simple-editor-f" title="Simple editor">Simple editor</label>
1116
+ <?php endif; ?>
1117
+
1118
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_PROCESS_PHP, '_block_f'; ?>" value="0" />
1119
+ <input style="border-radius: 5px; margin-left: 10px;" type="checkbox" name="<?php echo AI_OPTION_PROCESS_PHP, '_block_f'; ?>" value="1" id="process-php-f" <?php if ($adF->get_process_php () == AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1120
+ <label for="process-php-f" title="Process PHP code">Process PHP</label>
1121
+ </div>
1122
+
1123
+ <div>
1124
+ <h3 style="margin: 8px 0 8px 2px;">HTML Page Footer Code</h3>
1125
+ </div>
1126
+ </div>
1127
 
1128
+ <div style="margin: 8px 0; width: 100%;">
1129
+ <div style="float: left;">
1130
+ Code before the <pre style="display: inline; color: blue;">&lt;/body&gt;</pre> tag of the the HTML page
1131
+ </div>
 
1132
 
1133
+ <div style="clear: both;"></div>
1134
+ </div>
 
 
1135
 
1136
+ <div style="margin: 8px 0;">
1137
+ <textarea id="block-f" name="<?php echo AI_OPTION_CODE, '_block_f'; ?>" class="simple-editor" style="background-color:#F9F9F9; font-family: Courier, 'Courier New', monospace; font-weight: bold;"><?php echo esc_textarea ($adF->get_ad_data()); ?></textarea>
1138
+ </div>
1139
 
1140
+ <div id="device-detection-settings-f" style="padding:8px 8px 8px 8px; margin: 8px 0; border: 1px solid #ddd; border-radius: 5px;">
1141
+ <input style="border-radius: 5px;" type="hidden" name="<?php echo AI_OPTION_DETECT_SERVER_SIDE, WP_FORM_FIELD_POSTFIX, AI_FOOTER_OPTION_NAME; ?>" value="0" />
1142
+ <input style="border-radius: 5px;" type="checkbox" name="<?php echo AI_OPTION_DETECT_SERVER_SIDE, WP_FORM_FIELD_POSTFIX, AI_FOOTER_OPTION_NAME; ?>" id="server-side-detection-f" value="1" <?php if ($adF->get_detection_server_side ()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1143
+ <label for="server-side-detection-f">Use server-side detection to insert code only for </label>
1144
+ <select style="border-radius: 5px; margin-bottom: 3px;" id="display-for-devices-f" name="<?php echo AI_OPTION_DISPLAY_FOR_DEVICES, WP_FORM_FIELD_POSTFIX, AI_FOOTER_OPTION_NAME; ?>" >
1145
+ <option value="<?php echo AD_DISPLAY_DESKTOP_DEVICES; ?>" <?php echo ($adF->get_display_for_devices() == AD_DISPLAY_DESKTOP_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_DESKTOP_DEVICES; ?></option>
1146
+ <option value="<?php echo AD_DISPLAY_MOBILE_DEVICES; ?>" <?php echo ($adF->get_display_for_devices() == AD_DISPLAY_MOBILE_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_MOBILE_DEVICES; ?></option>
1147
+ <option value="<?php echo AD_DISPLAY_TABLET_DEVICES; ?>" <?php echo ($adF->get_display_for_devices() == AD_DISPLAY_TABLET_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_TABLET_DEVICES; ?></option>
1148
+ <option value="<?php echo AD_DISPLAY_PHONE_DEVICES; ?>" <?php echo ($adF->get_display_for_devices() == AD_DISPLAY_PHONE_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_PHONE_DEVICES; ?></option>
1149
+ <option value="<?php echo AD_DISPLAY_DESKTOP_TABLET_DEVICES; ?>" <?php echo ($adF->get_display_for_devices() == AD_DISPLAY_DESKTOP_TABLET_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_DESKTOP_TABLET_DEVICES; ?></option>
1150
+ <option value="<?php echo AD_DISPLAY_DESKTOP_PHONE_DEVICES; ?>" <?php echo ($adF->get_display_for_devices() == AD_DISPLAY_DESKTOP_PHONE_DEVICES) ? AD_SELECT_SELECTED : AD_EMPTY_VALUE; ?>><?php echo AD_DISPLAY_DESKTOP_PHONE_DEVICES; ?></option>
1151
+ </select>
1152
+ devices
1153
+ </div>
1154
  </div>
1155
 
1156
+ <?php if (function_exists ('ai_multisite_settings')) ai_multisite_settings (); ?>
 
 
 
 
1157
 
1158
+ <div id="tab-debugging" style="margin: 8px 0; padding: 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
1159
+ <div style="margin: 8px;">
1160
+ <input style="border-radius: 5px;" type="hidden" name="remote_debugging" value="0" />
1161
+ <input style="border-radius: 5px;" type="checkbox" name="remote_debugging"id="remote-debugging" value="1" default="<?php echo DEFAULT_REMOTE_DEBUGGING; ?>" <?php if (get_remote_debugging ()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1162
+ <label for="remote-debugging" title="Enable Debugger widget and code insertion debugging (blocks, positions, tags, processing) by url parameters for non-logged in users. Enable this option to allow other people to see Debugger widget, labeled blocks and positions in order to help you to diagnose problems. For logged in users debugging is always enabled.">Remote debugging</label>
1163
+ </div>
1164
 
1165
+ <div id="system-debugging" style="margin: 8px; display: none;">
1166
+ <input style="border-radius: 5px;" type="hidden" name="javascript_debugging" value="0" />
1167
+ <input style="border-radius: 5px;" type="checkbox" name="javascript_debugging"id="javascript-debugging" value="1" default="<?php echo DEFAULT_JAVASCRIPT_DEBUGGING; ?>" <?php if (get_javascript_debugging ()==AD_SETTINGS_CHECKED) echo 'checked '; ?> />
1168
+ <label for="javascript-debugging" title="Enable Javascript console output">Javascript debugging</label>
1169
+ </div>
1170
  </div>
 
 
 
 
1171
 
1172
+ </div>
1173
  </div>
1174
 
 
 
 
 
 
 
 
1175
  </div>
1176
 
1177
  <input id="ai-active-tab" type="hidden" name="ai-active-tab" value="<?php echo $active_tab; ?>" />
1178
 
 
 
 
 
1179
  <?php
1180
  } // Main subpage
1181
+ wp_nonce_field ('save_adinserter_settings');
1182
  ?>
1183
+ </form>
1184
 
1185
  </div>
1186
 
1188
  if ($subpage == 'main') {
1189
  if (function_exists ('ai_settings_side')) ai_settings_side (); else { ?>
1190
  <div style="float: left;">
1191
+ <div class="ai-form header" style="margin: 8px 0; padding: 0 8px; border: 1px solid rgb(221, 221, 221); border-radius: 5px;">
1192
+ <div style="float: left;">
1193
+ <h2 style="display: inline-block; margin: 13px 0;">Ad Inserter Pro - 64 blocks, 6 viewports, import/export settings, multisite support</h2>
1194
+ </div>
1195
+
1196
+ <div id="header-buttons">
1197
+ <a style="text-decoration: none;" href="http://tinymonitor.com/ad-inserter-pro" target="_blank"><button type="button" style="display: none; margin: 0 10px 0 0; width: 62px;">Go&nbsp;Pro</button></a>
1198
+ </div>
1199
+
1200
+ <div style="clear: both;"></div>
1201
+ </div>
1202
+
1203
+ <div class="ai-form" style="padding: 2px 8px 6px 8px; margin: 8px 0 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
1204
+ <a href="http://tinymonitor.com/" target="_blank"><img src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>monitors.png" alt="Tiny Monitor" /></a>
1205
+ <p style="text-align: justify;"><a href="http://tinymonitor.com/" target="_blank">Tiny Monitor</a> is a PHP application that can monitor your Google AdSense earnings,
1206
+ CJ earnings and PayPal transactions. The purpose of Tiny Monitor is to download data from original sources and present them in a compact way on a single web page.
1207
+ With Tiny Monitor you have all the data at one place so you dont have to log in to various pages just to check earnings.
1208
+ Tiny Monitor displays some data also in the page title and favicon so you still have simple access to current monitor status while you work with other applications.</p>
1209
  </div>
1210
  </div>
1211
  <?php
1212
  }
1213
  }
1214
  ?>
 
1215
  <script type="text/javascript">
1216
+ setTimeout (show_blocked_warning, 3000);
1217
+
1218
+ function show_blocked_warning () {
1219
+ jQuery("#blocked-warning.warning-enabled").show ();
1220
+ }
1221
+
1222
  </script>
1223
 
1224
  <?php