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

Version Description

  • Added option to force showing admin toolbar when viewing site
  • Added additional debugging info for blocks in Ajax requests
  • Fix for viewport visibility detection
  • Fix for rotation with non-ASCII characters
  • Few minor bug fixes, cosmetic changes and code improvements
Download this release

Release Info

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

Code changes from version 2.3.20 to 2.3.21

ad-inserter.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
- Version: 2.3.20
6
  Description: Ad management plugin with many advanced advertising features to insert ads at optimal positions
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
@@ -13,6 +13,13 @@ Plugin URI: https://adinserter.pro/documentation
13
 
14
  Change Log
15
 
 
 
 
 
 
 
 
16
  Ad Inserter 2.3.20 - 2018-09-04
17
  - Improved loading of settings
18
  - Fix for content processing in some ajax calls
@@ -887,6 +894,24 @@ function ai_wp_hook () {
887
  }
888
  }
889
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
890
  $debug_positions = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0;
891
  $debug_tags_positions = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS)) != 0;
892
  $debug_tags_positions_blocks = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS | AI_DEBUG_BLOCKS)) != 0;
@@ -1035,6 +1060,10 @@ function ai_init_hook () {
1035
  add_shortcode ('adinserter', 'ai_process_shortcodes');
1036
  add_shortcode ('ADINSERTER', 'ai_process_shortcodes');
1037
 
 
 
 
 
1038
  add_filter ('pre_do_shortcode_tag', 'ai_pre_do_shortcode_tag', 10, 4);
1039
  }
1040
 
@@ -1130,16 +1159,16 @@ function ai_admin_menu_hook () {
1130
  $ai_settings_page = add_submenu_page ('options-general.php', AD_INSERTER_NAME.' Options', AD_INSERTER_NAME, 'manage_options', basename(__FILE__), 'ai_settings');
1131
  add_action ('admin_enqueue_scripts', 'ai_admin_enqueue_scripts');
1132
  add_action ('admin_enqueue_scripts', 'ai_admin_remove_scripts', 99999);
1133
- // add_action ('admin_head', 'ai_admin_head');
1134
  add_filter ('clean_url', 'ai_clean_url', 999999, 2);
1135
  }
1136
 
1137
  function ai_admin_head () {
1138
  global $ai_settings_page, $hook_suffix;
1139
 
1140
- // if ($hook_suffix == $ai_settings_page && wp_is_mobile()) {
1141
- // echo "<meta name='viewport' content='width=762'>\n";
1142
- // }
1143
  }
1144
 
1145
  function ai_admin_enqueue_scripts ($hook_suffix) {
@@ -1210,6 +1239,10 @@ function ai_admin_remove_scripts ($hook_suffix) {
1210
  }
1211
  }
1212
 
 
 
 
 
1213
  function ai_wp_enqueue_scripts_hook () {
1214
  global $ai_wp_data;
1215
 
@@ -1287,6 +1320,7 @@ function add_head_inline_styles_and_scripts () {
1287
  $ai_wp_data [AI_CLOSE_BUTTONS] ||
1288
  !get_inline_styles () ||
1289
  get_admin_toolbar_debugging () && (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) ||
 
1290
  $ai_wp_data [AI_WP_DEBUGGING] != 0) {
1291
 
1292
  echo "<style type='text/css'>\n";
@@ -1325,7 +1359,7 @@ function add_head_inline_styles_and_scripts () {
1325
 
1326
  if ($ai_wp_data [AI_WP_DEBUGGING] != 0) generate_debug_css ();
1327
 
1328
- if (get_admin_toolbar_debugging () && (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0))
1329
  echo "#wp-admin-bar-ai-toolbar-settings .ab-icon:before {
1330
  content: '\\f111';
1331
  top: 2px;
@@ -1372,6 +1406,24 @@ function add_head_inline_styles_and_scripts () {
1372
  font: 400 20px/1 dashicons;
1373
  }
1374
  ";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1375
 
1376
  echo "</style>\n";
1377
  // No scripts on AMP pages
@@ -1571,8 +1623,14 @@ function add_footer_inline_scripts () {
1571
 
1572
  $client_side_dynamic_blocks = get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT;
1573
 
1574
- if ($ai_wp_data [AI_LAZY_LOADING]) {
1575
- echo ai_get_js ('ai-load');
 
 
 
 
 
 
1576
  }
1577
 
1578
  if ($client_side_dynamic_blocks || isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION])) {
@@ -1587,10 +1645,6 @@ function add_footer_inline_scripts () {
1587
  echo ai_get_js ('ai-sidebar');
1588
  }
1589
 
1590
- if ($ai_wp_data [AI_STICK_TO_THE_CONTENT] || $ai_wp_data [AI_ANIMATION]) {
1591
- echo ai_get_js ('ai-sticky');
1592
- }
1593
-
1594
  if ($ai_wp_data [AI_CLOSE_BUTTONS]) {
1595
  echo ai_get_js ('ai-close');
1596
  }
@@ -3017,9 +3071,11 @@ function ai_check_plugin_options ($plugin_options = array ()) {
3017
  if (!isset ($plugin_options ['ADB_MESSAGE_CSS'])) $plugin_options ['ADB_MESSAGE_CSS'] = AI_DEFAULT_ADB_MESSAGE_CSS;
3018
  if (!isset ($plugin_options ['ADB_UNDISMISSIBLE_MESSAGE'])) $plugin_options ['ADB_UNDISMISSIBLE_MESSAGE'] = AI_DEFAULT_ADB_UNDISMISSIBLE_MESSAGE;
3019
  if (!isset ($plugin_options ['ADMIN_TOOLBAR_DEBUGGING'])) $plugin_options ['ADMIN_TOOLBAR_DEBUGGING'] = DEFAULT_ADMIN_TOOLBAR_DEBUGGING;
 
 
3020
  if (!isset ($plugin_options ['REMOTE_DEBUGGING'])) $plugin_options ['REMOTE_DEBUGGING'] = DEFAULT_REMOTE_DEBUGGING;
3021
  if (!isset ($plugin_options ['BACKEND_JS_DEBUGGING'])) $plugin_options ['BACKEND_JS_DEBUGGING'] = DEFAULT_BACKEND_JS_DEBUGGING;
3022
- if (!isset ($plugin_options ['FRONTEND_JS_DEBUGGING'])) $plugin_options ['FRONTEND_JS_DEBUGGING'] = DEFAULT_FRONTEND_JS_DEBUGGING;
3023
 
3024
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
3025
  $viewport_name_option_name = 'VIEWPORT_NAME_' . $viewport;
@@ -3278,6 +3334,14 @@ function get_main_content_element () {
3278
  return ($ai_db_options [AI_OPTION_GLOBAL]['MAIN_CONTENT_ELEMENT']);
3279
  }
3280
 
 
 
 
 
 
 
 
 
3281
  function get_admin_toolbar_debugging () {
3282
  global $ai_db_options;
3283
 
@@ -3286,6 +3350,14 @@ function get_admin_toolbar_debugging () {
3286
  return ($ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_DEBUGGING']);
3287
  }
3288
 
 
 
 
 
 
 
 
 
3289
  function get_remote_debugging () {
3290
  global $ai_db_options;
3291
 
@@ -4340,23 +4412,26 @@ function generate_alignment_css () {
4340
  case AI_ALIGNMENT_STICKY_TOP:
4341
  case AI_ALIGNMENT_STICKY_BOTTOM:
4342
  $alignment_name = strtolower ($styles [$alignment_type][0]);
4343
- if (in_array ($alignment_name, $alignments)) continue;
4344
- $alignments []= $alignment_name;
4345
- $alignment_css .= '.' . $block_class_name . str_replace (' ', '-', $alignment_name) .' {' . $styles [$alignment_type][1] . "}\n";
 
4346
  break;
4347
  case AI_ALIGNMENT_STICKY:
4348
  $sticky_css = $obj->alignment_style ($alignment_type);
4349
  $alignment_name = strtolower (md5 ($sticky_css));
4350
- if (in_array ($alignment_name, $alignments)) continue;
4351
- $alignments []= $alignment_name;
4352
- $alignment_css .= '.' . $block_class_name . str_replace (' ', '-', $alignment_name) .' {' . $sticky_css . "}\n";
 
4353
  break;
4354
  case AI_ALIGNMENT_CUSTOM_CSS:
4355
  $custom_css = $obj->get_custom_css ();
4356
  $alignment_name = strtolower (md5 ($custom_css));
4357
- if (in_array ($alignment_name, $alignments)) continue;
4358
- $alignments []= $alignment_name;
4359
- $alignment_css .= '.' . $block_class_name . str_replace (' ', '-', $alignment_name) .' {' . str_replace ('&#039;', "'", $custom_css) . "}\n";
 
4360
  break;
4361
  }
4362
  }
@@ -4426,6 +4501,10 @@ section.ai-debug-block {padding: 0; margin: 0;}
4426
  .ai-debug-block.ai-debug-adsense {border-color: #e0a;}
4427
  .ai-debug-bar.ai-debug-adsense {background: #e0a;}
4428
 
 
 
 
 
4429
  .ai-debug-adb-status.on kbd {color: #f00;}
4430
  .ai-debug-adb-status.off kbd {color: #0f0;}
4431
 
@@ -4437,7 +4516,7 @@ section.ai-debug-block {padding: 0; margin: 0;}
4437
 
4438
  .ai-debug-bar {margin: 0; padding: 1px 0 1px 5px; color: white; font-size: 12px; font-family: arial; font-weight: normal; line-height: 20px; text-align: center; overflow: hidden; word-break: break-word;}
4439
 
4440
- .ai-debug-bar .ai-debug-text-left {float: left;}
4441
  .ai-debug-bar .ai-debug-text-right {float: right; padding-right: 3px;}
4442
  .ai-debug-bar .ai-debug-text-center {text-align: center;}
4443
 
@@ -4625,7 +4704,9 @@ function ai_settings () {
4625
  if (isset ($_POST [AI_OPTION_ADB_MESSAGE_CSS])) $options ['ADB_MESSAGE_CSS'] = filter_option ('ADB_MESSAGE_CSS', $_POST [AI_OPTION_ADB_MESSAGE_CSS]);
4626
  if (isset ($_POST [AI_OPTION_ADB_OVERLAY_CSS])) $options ['ADB_OVERLAY_CSS'] = filter_option ('ADB_OVERLAY_CSS', $_POST [AI_OPTION_ADB_OVERLAY_CSS]);
4627
  if (isset ($_POST [AI_OPTION_ADB_UNDISMISSIBLE_MESSAGE])) $options ['ADB_UNDISMISSIBLE_MESSAGE'] = filter_option ('ADB_UNDISMISSIBLE_MESSAGE', $_POST [AI_OPTION_ADB_UNDISMISSIBLE_MESSAGE]);
 
4628
  if (isset ($_POST ['admin_toolbar_debugging'])) $options ['ADMIN_TOOLBAR_DEBUGGING'] = filter_option ('ADMIN_TOOLBAR_DEBUGGING', $_POST ['admin_toolbar_debugging']);
 
4629
  if (isset ($_POST ['remote_debugging'])) $options ['REMOTE_DEBUGGING'] = filter_option ('REMOTE_DEBUGGING', $_POST ['remote_debugging']);
4630
  if (isset ($_POST ['backend_js_debugging'])) $options ['BACKEND_JS_DEBUGGING'] = filter_option ('BACKEND_JS_DEBUGGING', $_POST ['backend_js_debugging']);
4631
  if (isset ($_POST ['frontend_js_debugging'])) $options ['FRONTEND_JS_DEBUGGING'] = filter_option ('FRONTEND_JS_DEBUGGING', $_POST ['frontend_js_debugging']);
@@ -6398,6 +6479,11 @@ function get_paragraph_end_positions ($content, $multibyte, $paragraph_start_pos
6398
  }
6399
  }
6400
 
 
 
 
 
 
6401
 
6402
  // ===========================================================================================
6403
 
@@ -6423,7 +6509,7 @@ if (isset ($_GET [AI_URL_DEBUG_PHP_]) && $_GET [AI_URL_DEBUG_PHP_] != '') {
6423
  $ai_wp_data [AI_WP_DEBUGGING_] = 0;
6424
 
6425
  if (!is_admin()) {
6426
- if (!isset ($_GET [AI_URL_DEBUG_]))
6427
  if (isset ($_GET [AI_URL_DEBUG_PROCESSING_]) || (isset ($_COOKIE ['AI_WP_DEBUGGING']) && ($_COOKIE ['AI_WP_DEBUGGING'] & AI_DEBUG_PROCESSING_) != 0)) {
6428
  if (!isset ($_GET [AI_URL_DEBUG_PROCESSING_]) || $_GET [AI_URL_DEBUG_PROCESSING_] == 1) {
6429
  $ai_wp_data [AI_WP_DEBUGGING_] |= AI_DEBUG_PROCESSING_;
@@ -6545,7 +6631,6 @@ if (get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_SERVER_SIDE_W3TC) {
6545
  }
6546
  }
6547
 
6548
-
6549
  if ($ai_wp_data [AI_SERVER_SIDE_DETECTION]) {
6550
  require_once AD_INSERTER_PLUGIN_DIR.'includes/Mobile_Detect.php';
6551
 
@@ -6587,7 +6672,8 @@ add_action ('save_post', 'ai_save_meta_box_data_hook');
6587
  if (function_exists ('ai_hooks')) ai_hooks ();
6588
 
6589
  add_filter ('plugin_action_links_'.plugin_basename (__FILE__), 'ai_plugin_action_links');
6590
- add_filter ('plugin_row_meta', 'ai_set_plugin_meta', 10, 2);
 
6591
 
6592
  if (is_admin () === true) {
6593
  add_action ('wp_ajax_ai_ajax_backend', 'ai_ajax_backend');
@@ -6595,19 +6681,73 @@ if (is_admin () === true) {
6595
  add_action ('wp_ajax_nopriv_ai_ajax', 'ai_ajax');
6596
  }
6597
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6598
 
 
 
 
 
 
6599
 
6600
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
6601
  $ai_total_plugin_time += microtime (true) - $start_time;
6602
  ai_log ("INITIALIZATION END\n");
6603
  }
6604
 
6605
- //add_filter ('the_generator', 'ai_the_generator');
6606
-
6607
- //function ai_the_generator ($generator) {
6608
- // return preg_replace ('/content="(.*?)"/', 'content="$1, '.AD_INSERTER_NAME.' '. AD_INSERTER_VERSION.'"', $generator);
6609
- //}
6610
-
6611
  // ===========================================================================================
6612
 
6613
  if (!class_exists ('ai_widget')) {
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
+ Version: 2.3.21
6
  Description: Ad management plugin with many advanced advertising features to insert ads at optimal positions
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
13
 
14
  Change Log
15
 
16
+ Ad Inserter 2.3.21 - 2018-09-20
17
+ - Added option to force showing admin toolbar when viewing site
18
+ - Added additional debugging info for blocks in Ajax requests
19
+ - Fix for viewport visibility detection
20
+ - Fix for rotation with non-ASCII characters
21
+ - Few minor bug fixes, cosmetic changes and code improvements
22
+
23
  Ad Inserter 2.3.20 - 2018-09-04
24
  - Improved loading of settings
25
  - Fix for content processing in some ajax calls
894
  }
895
  }
896
 
897
+ if (($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) == 0 &&
898
+ ((get_remote_debugging () && ($ai_wp_data [AI_WP_DEBUGGING] != 0 || (isset ($_GET [AI_URL_DEBUG]) && $_GET [AI_URL_DEBUG] == 1))) ||
899
+ defined ('AI_DEBUGGING_DEMO'))) {
900
+ function ai_login_adminbar ($wp_admin_bar) {
901
+ $wp_admin_bar->add_menu (array ('title' => __('Log In'), 'href' => wp_login_url()));
902
+ }
903
+
904
+ add_filter ('show_admin_bar', '__return_true', 999999);
905
+ add_action ('admin_bar_menu', 'ai_toolbar', 9920);
906
+ if (!defined ('AI_DEBUGGING_DEMO')) {
907
+ add_action ('admin_bar_menu', 'ai_login_adminbar' );
908
+ }
909
+ }
910
+
911
+ if (($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0 && get_force_admin_toolbar ()) {
912
+ add_filter ('show_admin_bar', '__return_true', 999999);
913
+ }
914
+
915
  $debug_positions = ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0;
916
  $debug_tags_positions = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS)) != 0;
917
  $debug_tags_positions_blocks = ($ai_wp_data [AI_WP_DEBUGGING] & (AI_DEBUG_POSITIONS | AI_DEBUG_TAGS | AI_DEBUG_BLOCKS)) != 0;
1060
  add_shortcode ('adinserter', 'ai_process_shortcodes');
1061
  add_shortcode ('ADINSERTER', 'ai_process_shortcodes');
1062
 
1063
+ if (isset ($_SERVER ['REQUEST_URI']) && strpos ($_SERVER ['REQUEST_URI'], 'page=ad-inserter.php') !== false) {
1064
+ add_filter ('admin_referrer_policy', 'ai_admin_referrer_policy', 99999);
1065
+ }
1066
+
1067
  add_filter ('pre_do_shortcode_tag', 'ai_pre_do_shortcode_tag', 10, 4);
1068
  }
1069
 
1159
  $ai_settings_page = add_submenu_page ('options-general.php', AD_INSERTER_NAME.' Options', AD_INSERTER_NAME, 'manage_options', basename(__FILE__), 'ai_settings');
1160
  add_action ('admin_enqueue_scripts', 'ai_admin_enqueue_scripts');
1161
  add_action ('admin_enqueue_scripts', 'ai_admin_remove_scripts', 99999);
1162
+ add_action ('admin_head', 'ai_admin_head');
1163
  add_filter ('clean_url', 'ai_clean_url', 999999, 2);
1164
  }
1165
 
1166
  function ai_admin_head () {
1167
  global $ai_settings_page, $hook_suffix;
1168
 
1169
+ if ($hook_suffix == $ai_settings_page && wp_is_mobile()) {
1170
+ echo '<meta name="viewport" content="width=762">', PHP_EOL;
1171
+ }
1172
  }
1173
 
1174
  function ai_admin_enqueue_scripts ($hook_suffix) {
1239
  }
1240
  }
1241
 
1242
+ function ai_admin_referrer_policy ($policy) {
1243
+ return 'no-referrer-when-downgrade';
1244
+ }
1245
+
1246
  function ai_wp_enqueue_scripts_hook () {
1247
  global $ai_wp_data;
1248
 
1320
  $ai_wp_data [AI_CLOSE_BUTTONS] ||
1321
  !get_inline_styles () ||
1322
  get_admin_toolbar_debugging () && (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0) ||
1323
+ defined ('AI_DEBUGGING_DEMO') ||
1324
  $ai_wp_data [AI_WP_DEBUGGING] != 0) {
1325
 
1326
  echo "<style type='text/css'>\n";
1359
 
1360
  if ($ai_wp_data [AI_WP_DEBUGGING] != 0) generate_debug_css ();
1361
 
1362
+ if ((get_admin_toolbar_debugging () && (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_LOGGED_IN) != 0)) || defined ('AI_DEBUGGING_DEMO'))
1363
  echo "#wp-admin-bar-ai-toolbar-settings .ab-icon:before {
1364
  content: '\\f111';
1365
  top: 2px;
1406
  font: 400 20px/1 dashicons;
1407
  }
1408
  ";
1409
+ if (get_admin_toolbar_mobile ()) {
1410
+ echo "@media screen and (max-width: 782px) {
1411
+ #wpadminbar #wp-admin-bar-ai-toolbar-settings {
1412
+ display: block;
1413
+ position: static;
1414
+ }
1415
+
1416
+ #wpadminbar #wp-admin-bar-ai-toolbar-settings > .ab-item {
1417
+ white-space: nowrap;
1418
+ overflow: hidden;
1419
+ width: 52px;
1420
+ padding: 0;
1421
+ color: #a0a5aa;
1422
+ position: relative;
1423
+ }
1424
+ }
1425
+ ";
1426
+ }
1427
 
1428
  echo "</style>\n";
1429
  // No scripts on AMP pages
1623
 
1624
  $client_side_dynamic_blocks = get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_SHOW || get_dynamic_blocks () == AI_DYNAMIC_BLOCKS_CLIENT_SIDE_INSERT;
1625
 
1626
+ if (function_exists ('add_footer_inline_scripts_2')) {
1627
+ if ($ai_wp_data [AI_LAZY_LOADING]) {
1628
+ echo ai_get_js ('ai-load');
1629
+ }
1630
+
1631
+ if ($ai_wp_data [AI_STICK_TO_THE_CONTENT] || $ai_wp_data [AI_ANIMATION]) {
1632
+ echo ai_get_js ('ai-sticky');
1633
+ }
1634
  }
1635
 
1636
  if ($client_side_dynamic_blocks || isset ($ai_wp_data [AI_CLIENT_SIDE_ROTATION])) {
1645
  echo ai_get_js ('ai-sidebar');
1646
  }
1647
 
 
 
 
 
1648
  if ($ai_wp_data [AI_CLOSE_BUTTONS]) {
1649
  echo ai_get_js ('ai-close');
1650
  }
3071
  if (!isset ($plugin_options ['ADB_MESSAGE_CSS'])) $plugin_options ['ADB_MESSAGE_CSS'] = AI_DEFAULT_ADB_MESSAGE_CSS;
3072
  if (!isset ($plugin_options ['ADB_UNDISMISSIBLE_MESSAGE'])) $plugin_options ['ADB_UNDISMISSIBLE_MESSAGE'] = AI_DEFAULT_ADB_UNDISMISSIBLE_MESSAGE;
3073
  if (!isset ($plugin_options ['ADMIN_TOOLBAR_DEBUGGING'])) $plugin_options ['ADMIN_TOOLBAR_DEBUGGING'] = DEFAULT_ADMIN_TOOLBAR_DEBUGGING;
3074
+ if (!isset ($plugin_options ['ADMIN_TOOLBAR_MOBILE'])) $plugin_options ['ADMIN_TOOLBAR_MOBILE'] = DEFAULT_ADMIN_TOOLBAR_MOBILE;
3075
+ if (!isset ($plugin_options ['FORCE_ADMIN_TOOLBAR'])) $plugin_options ['FORCE_ADMIN_TOOLBAR'] = DEFAULT_FORCE_ADMIN_TOOLBAR;
3076
  if (!isset ($plugin_options ['REMOTE_DEBUGGING'])) $plugin_options ['REMOTE_DEBUGGING'] = DEFAULT_REMOTE_DEBUGGING;
3077
  if (!isset ($plugin_options ['BACKEND_JS_DEBUGGING'])) $plugin_options ['BACKEND_JS_DEBUGGING'] = DEFAULT_BACKEND_JS_DEBUGGING;
3078
+ if (!isset ($plugin_options ['FRONTEND_JS_DEBUGGING'])) $plugin_options ['FRONTEND_JS_DEBUGGING'] = DEFAULT_FRONTEND_JS_DEBUGGING;
3079
 
3080
  for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
3081
  $viewport_name_option_name = 'VIEWPORT_NAME_' . $viewport;
3334
  return ($ai_db_options [AI_OPTION_GLOBAL]['MAIN_CONTENT_ELEMENT']);
3335
  }
3336
 
3337
+ function get_force_admin_toolbar () {
3338
+ global $ai_db_options;
3339
+
3340
+ if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['FORCE_ADMIN_TOOLBAR'])) $ai_db_options [AI_OPTION_GLOBAL]['FORCE_ADMIN_TOOLBAR'] = DEFAULT_FORCE_ADMIN_TOOLBAR;
3341
+
3342
+ return ($ai_db_options [AI_OPTION_GLOBAL]['FORCE_ADMIN_TOOLBAR']);
3343
+ }
3344
+
3345
  function get_admin_toolbar_debugging () {
3346
  global $ai_db_options;
3347
 
3350
  return ($ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_DEBUGGING']);
3351
  }
3352
 
3353
+ function get_admin_toolbar_mobile () {
3354
+ global $ai_db_options;
3355
+
3356
+ if (!isset ($ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_MOBILE'])) $ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_MOBILE'] = DEFAULT_ADMIN_TOOLBAR_MOBILE;
3357
+
3358
+ return ($ai_db_options [AI_OPTION_GLOBAL]['ADMIN_TOOLBAR_MOBILE']);
3359
+ }
3360
+
3361
  function get_remote_debugging () {
3362
  global $ai_db_options;
3363
 
4412
  case AI_ALIGNMENT_STICKY_TOP:
4413
  case AI_ALIGNMENT_STICKY_BOTTOM:
4414
  $alignment_name = strtolower ($styles [$alignment_type][0]);
4415
+ if (!in_array ($alignment_name, $alignments)) {
4416
+ $alignments []= $alignment_name;
4417
+ $alignment_css .= '.' . $block_class_name . str_replace (' ', '-', $alignment_name) .' {' . $styles [$alignment_type][1] . "}\n";
4418
+ }
4419
  break;
4420
  case AI_ALIGNMENT_STICKY:
4421
  $sticky_css = $obj->alignment_style ($alignment_type);
4422
  $alignment_name = strtolower (md5 ($sticky_css));
4423
+ if (!in_array ($alignment_name, $alignments)) {
4424
+ $alignments []= $alignment_name;
4425
+ $alignment_css .= '.' . $block_class_name . str_replace (' ', '-', $alignment_name) .' {' . $sticky_css . "}\n";
4426
+ }
4427
  break;
4428
  case AI_ALIGNMENT_CUSTOM_CSS:
4429
  $custom_css = $obj->get_custom_css ();
4430
  $alignment_name = strtolower (md5 ($custom_css));
4431
+ if (!in_array ($alignment_name, $alignments)) {
4432
+ $alignments []= $alignment_name;
4433
+ $alignment_css .= '.' . $block_class_name . str_replace (' ', '-', $alignment_name) .' {' . str_replace ('&#039;', "'", $custom_css) . "}\n";
4434
+ }
4435
  break;
4436
  }
4437
  }
4501
  .ai-debug-block.ai-debug-adsense {border-color: #e0a;}
4502
  .ai-debug-bar.ai-debug-adsense {background: #e0a;}
4503
 
4504
+ .ai-debug-block.ai-debug-ajax {border-color: #ffd600;}
4505
+ .ai-debug-bar.ai-debug-ajax {background: #ffd600;}
4506
+ .ai-debug-bar.ai-debug-ajax kbd {color: #000;}
4507
+
4508
  .ai-debug-adb-status.on kbd {color: #f00;}
4509
  .ai-debug-adb-status.off kbd {color: #0f0;}
4510
 
4516
 
4517
  .ai-debug-bar {margin: 0; padding: 1px 0 1px 5px; color: white; font-size: 12px; font-family: arial; font-weight: normal; line-height: 20px; text-align: center; overflow: hidden; word-break: break-word;}
4518
 
4519
+ .ai-debug-bar .ai-debug-text-left {float: left; text-align: left;}
4520
  .ai-debug-bar .ai-debug-text-right {float: right; padding-right: 3px;}
4521
  .ai-debug-bar .ai-debug-text-center {text-align: center;}
4522
 
4704
  if (isset ($_POST [AI_OPTION_ADB_MESSAGE_CSS])) $options ['ADB_MESSAGE_CSS'] = filter_option ('ADB_MESSAGE_CSS', $_POST [AI_OPTION_ADB_MESSAGE_CSS]);
4705
  if (isset ($_POST [AI_OPTION_ADB_OVERLAY_CSS])) $options ['ADB_OVERLAY_CSS'] = filter_option ('ADB_OVERLAY_CSS', $_POST [AI_OPTION_ADB_OVERLAY_CSS]);
4706
  if (isset ($_POST [AI_OPTION_ADB_UNDISMISSIBLE_MESSAGE])) $options ['ADB_UNDISMISSIBLE_MESSAGE'] = filter_option ('ADB_UNDISMISSIBLE_MESSAGE', $_POST [AI_OPTION_ADB_UNDISMISSIBLE_MESSAGE]);
4707
+ if (isset ($_POST ['force_admin_toolbar'])) $options ['FORCE_ADMIN_TOOLBAR'] = filter_option ('FORCE_ADMIN_TOOLBAR', $_POST ['force_admin_toolbar']);
4708
  if (isset ($_POST ['admin_toolbar_debugging'])) $options ['ADMIN_TOOLBAR_DEBUGGING'] = filter_option ('ADMIN_TOOLBAR_DEBUGGING', $_POST ['admin_toolbar_debugging']);
4709
+ if (isset ($_POST ['admin_toolbar_mobile'])) $options ['ADMIN_TOOLBAR_MOBILE'] = filter_option ('ADMIN_TOOLBAR_MOBILE', $_POST ['admin_toolbar_mobile']);
4710
  if (isset ($_POST ['remote_debugging'])) $options ['REMOTE_DEBUGGING'] = filter_option ('REMOTE_DEBUGGING', $_POST ['remote_debugging']);
4711
  if (isset ($_POST ['backend_js_debugging'])) $options ['BACKEND_JS_DEBUGGING'] = filter_option ('BACKEND_JS_DEBUGGING', $_POST ['backend_js_debugging']);
4712
  if (isset ($_POST ['frontend_js_debugging'])) $options ['FRONTEND_JS_DEBUGGING'] = filter_option ('FRONTEND_JS_DEBUGGING', $_POST ['frontend_js_debugging']);
6479
  }
6480
  }
6481
 
6482
+ //function ai_the_generator ($generator) {
6483
+ //// return preg_replace ('/content="(.*?)"/', 'content="$1, '.AD_INSERTER_NAME.' '. AD_INSERTER_VERSION.'"', $generator);
6484
+ // return $generator . PHP_EOL . '<meta name="generator" content="'.AD_INSERTER_NAME.' '.AD_INSERTER_VERSION.'" />';
6485
+ //}
6486
+
6487
 
6488
  // ===========================================================================================
6489
 
6509
  $ai_wp_data [AI_WP_DEBUGGING_] = 0;
6510
 
6511
  if (!is_admin()) {
6512
+ if (!isset ($_GET [AI_URL_DEBUG_]) || $_GET [AI_URL_DEBUG_] != 0)
6513
  if (isset ($_GET [AI_URL_DEBUG_PROCESSING_]) || (isset ($_COOKIE ['AI_WP_DEBUGGING']) && ($_COOKIE ['AI_WP_DEBUGGING'] & AI_DEBUG_PROCESSING_) != 0)) {
6514
  if (!isset ($_GET [AI_URL_DEBUG_PROCESSING_]) || $_GET [AI_URL_DEBUG_PROCESSING_] == 1) {
6515
  $ai_wp_data [AI_WP_DEBUGGING_] |= AI_DEBUG_PROCESSING_;
6631
  }
6632
  }
6633
 
 
6634
  if ($ai_wp_data [AI_SERVER_SIDE_DETECTION]) {
6635
  require_once AD_INSERTER_PLUGIN_DIR.'includes/Mobile_Detect.php';
6636
 
6672
  if (function_exists ('ai_hooks')) ai_hooks ();
6673
 
6674
  add_filter ('plugin_action_links_'.plugin_basename (__FILE__), 'ai_plugin_action_links');
6675
+ add_filter ('plugin_row_meta', 'ai_set_plugin_meta', 10, 2);
6676
+ //add_filter ('the_generator', 'ai_the_generator');
6677
 
6678
  if (is_admin () === true) {
6679
  add_action ('wp_ajax_ai_ajax_backend', 'ai_ajax_backend');
6681
  add_action ('wp_ajax_nopriv_ai_ajax', 'ai_ajax');
6682
  }
6683
 
6684
+ if (defined ('AI_PLUGIN_TRACKING') && AI_PLUGIN_TRACKING) {
6685
+ if (!class_exists ('DST_Client')) {
6686
+ require_once dirname (__FILE__) . '/includes/dst/dst.php';
6687
+ }
6688
+
6689
+ if (!function_exists ('ai_start_dst')) {
6690
+ function ai_start_dst () {
6691
+ global $ai_db_options, $ai_db_options_extract, $ai_dst;
6692
+
6693
+ if (isset ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS])) {
6694
+ $used_blocks = count (unserialize ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]));
6695
+ } else $used_blocks = '';
6696
+
6697
+ $install_timestamp = get_option (AI_INSTALL_NAME);
6698
+ if ($install_timestamp) {
6699
+ $install_date = date ("Y-m-d", $install_timestamp + get_option ('gmt_offset') * 3600);
6700
+ } else $install_date = '';
6701
+
6702
+ if (isset ($ai_db_options [AI_OPTION_GLOBAL]['TIMESTAMP'])) {
6703
+ $settings_date = date ("Y-m-d", $ai_db_options [AI_OPTION_GLOBAL]['TIMESTAMP'] + get_option ('gmt_offset') * 3600);
6704
+ } else $settings_date = '';
6705
+
6706
+ $count_posts = wp_count_posts ();
6707
+
6708
+ $dst_settings = array (
6709
+ 'main_file' => __FILE__,
6710
+ 'tracking_url' => 'https://analytics.adinserter.pro/',
6711
+ 'track_local' => true,
6712
+ 'tracking' => DST_Client::DST_TRACKING_OPTIN,
6713
+ 'use_email' => DST_Client::DST_USE_EMAIL_OFF,
6714
+ 'multisite_tracking' => DST_Client::DST_MULTISITE_SITES_TRACKING_WAIT_FOR_MAIN,
6715
+ 'deactivation_form' => true,
6716
+ 'admin_ip_tracking' => true,
6717
+ 'notice_icon' => AD_INSERTER_PLUGIN_IMAGES_URL.'icon-50x50.jpg',
6718
+ 'options' => array (
6719
+ 'posts' => $count_posts->publish,
6720
+ 'blocks' => $used_blocks,
6721
+ 'installation' => $install_date,
6722
+ 'settings' => $settings_date,
6723
+ 'notice_review' => ($review = get_option ('ai-notice-review')) ? $review : '',
6724
+ 'remote_debugging' => get_remote_debugging (),
6725
+ ),
6726
+ );
6727
+
6728
+ if (function_exists ('ai_dst_settings')) ai_dst_settings ($dst_settings);
6729
+
6730
+ $ai_dst = new DST_Client ($dst_settings);
6731
+ }
6732
+
6733
+ function ai_notice_text ($text) {
6734
+ $text = __('Thank you for installing [STRONG][NAME][/STRONG]. We would like to track its usage on your site. This is completely optional and can be disabled at any time.[P]
6735
+ We don\'t record any sensitive data, only information regarding the WordPress environment and %1$s usage, which will help us to make improvements to the %1$s', 'ad-inserter');
6736
+
6737
+ return $text;
6738
+ }
6739
 
6740
+ add_filter (DST_Client::DST_FILTER_OPTIN_NOTICE_TEXT . AD_INSERTER_SLUG, 'ai_notice_text');
6741
+
6742
+ ai_start_dst ();
6743
+ }
6744
+ }
6745
 
6746
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
6747
  $ai_total_plugin_time += microtime (true) - $start_time;
6748
  ai_log ("INITIALIZATION END\n");
6749
  }
6750
 
 
 
 
 
 
 
6751
  // ===========================================================================================
6752
 
6753
  if (!class_exists ('ai_widget')) {
class.php CHANGED
@@ -861,18 +861,29 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
861
  return implode (' ', $classes);
862
  }
863
 
864
- public function sticky_parameters (&$classes, $preview = false) {
865
- global $ai_wp_data;
866
-
867
- $sticky_parameters = '';
868
-
869
  $custom_sticky_css = false;
870
  if ($this->get_alignment_type () == AI_ALIGNMENT_CUSTOM_CSS) {
871
  $clean_custom_css_code = str_replace (' ', '', $this->get_custom_css ());
872
  if (strpos ($clean_custom_css_code, 'position:fixed') !== false && strpos ($clean_custom_css_code, 'z-index:') !== false) $custom_sticky_css = true;
873
  }
874
 
875
- if ($this->get_alignment_type () == AI_ALIGNMENT_STICKY || $custom_sticky_css) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
876
 
877
  $stick_to_the_content_class = $this->stick_to_the_content_class ();
878
 
@@ -2061,6 +2072,12 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2061
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0 && !$hide_debug_label) {
2062
  $title = '';
2063
  $fallback_block_name = '';
 
 
 
 
 
 
2064
 
2065
  if ($this->fallback != 0) {
2066
  $this->labels->class = 'ai-debug-fallback';
@@ -2072,9 +2089,14 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2072
  $version_name = $this->version_name == '' ? '' : ' - ' . $this->version_name;
2073
  $block_name = $this->number . ' &nbsp; ' . $this->get_ad_name () . '<kbd data-separator=" - " class="ai-option-name">' . $version_name . '</kbd>' . $fallback_block_name;
2074
 
 
 
 
 
2075
  $this->additional_code_before =
2076
  $this->labels->block_start () .
2077
- $this->labels->bar ($block_name, '', '<kbd class="ai-debug-name ai-main"></kbd>', $counters, $title) .
 
2078
  $this->additional_code_before;
2079
 
2080
  $this->additional_code_after .= $this->labels->block_end ();
@@ -2175,7 +2197,14 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
2175
 
2176
  if ($hidden_widgets) return $hidden_viewports; else {
2177
  if ($this->client_side_list_detection && !$ai_wp_data [AI_WP_AMP_PAGE]) {
2178
- $additional_block_style = 'visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999; ';
 
 
 
 
 
 
 
2179
  // if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
2180
  // $classes [] = 'ai-list-block';
2181
  // }
861
  return implode (' ', $classes);
862
  }
863
 
864
+ public function is_sticky () {
 
 
 
 
865
  $custom_sticky_css = false;
866
  if ($this->get_alignment_type () == AI_ALIGNMENT_CUSTOM_CSS) {
867
  $clean_custom_css_code = str_replace (' ', '', $this->get_custom_css ());
868
  if (strpos ($clean_custom_css_code, 'position:fixed') !== false && strpos ($clean_custom_css_code, 'z-index:') !== false) $custom_sticky_css = true;
869
  }
870
 
871
+ return ($custom_sticky_css || $this->get_alignment_type () == AI_ALIGNMENT_STICKY);
872
+ }
873
+
874
+ public function sticky_parameters (&$classes, $preview = false) {
875
+ global $ai_wp_data;
876
+
877
+ $sticky_parameters = '';
878
+
879
+ // $custom_sticky_css = false;
880
+ // if ($this->get_alignment_type () == AI_ALIGNMENT_CUSTOM_CSS) {
881
+ // $clean_custom_css_code = str_replace (' ', '', $this->get_custom_css ());
882
+ // if (strpos ($clean_custom_css_code, 'position:fixed') !== false && strpos ($clean_custom_css_code, 'z-index:') !== false) $custom_sticky_css = true;
883
+ // }
884
+
885
+ // if ($this->get_alignment_type () == AI_ALIGNMENT_STICKY || $custom_sticky_css) {
886
+ if ($this->is_sticky ()) {
887
 
888
  $stick_to_the_content_class = $this->stick_to_the_content_class ();
889
 
2072
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0 && !$hide_debug_label) {
2073
  $title = '';
2074
  $fallback_block_name = '';
2075
+ $ajax = '';
2076
+
2077
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_AJAX) {
2078
+ $this->labels->class = 'ai-debug-ajax';
2079
+ $ajax = 'AJAX REQUEST';
2080
+ }
2081
 
2082
  if ($this->fallback != 0) {
2083
  $this->labels->class = 'ai-debug-fallback';
2089
  $version_name = $this->version_name == '' ? '' : ' - ' . $this->version_name;
2090
  $block_name = $this->number . ' &nbsp; ' . $this->get_ad_name () . '<kbd data-separator=" - " class="ai-option-name">' . $version_name . '</kbd>' . $fallback_block_name;
2091
 
2092
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_AJAX) {
2093
+ $ajax_bar = $this->labels->bar ($_SERVER ['REQUEST_URI'], 'Ajax request url', '', 'IN THE LOOP: ' . (in_the_loop() ? 'YES' : 'NO'), 'in_the_loop ()');
2094
+ } else $ajax_bar = '';
2095
+
2096
  $this->additional_code_before =
2097
  $this->labels->block_start () .
2098
+ $this->labels->bar ($block_name, '', '<kbd class="ai-debug-name ai-main">' . $ajax . '</kbd>', $counters, $title) .
2099
+ $ajax_bar .
2100
  $this->additional_code_before;
2101
 
2102
  $this->additional_code_after .= $this->labels->block_end ();
2197
 
2198
  if ($hidden_widgets) return $hidden_viewports; else {
2199
  if ($this->client_side_list_detection && !$ai_wp_data [AI_WP_AMP_PAGE]) {
2200
+ if ($this->is_sticky ()) {
2201
+ $additional_block_style = 'visibility: hidden; ';
2202
+ } else {
2203
+ // $additional_block_style = 'visibility: hidden; position: absolute; width: 100%; height: 100%; z-index: -9999; ';
2204
+ $additional_block_style = 'visibility: hidden; position: absolute; ';
2205
+ $classes [] = 'ai-remove-position';
2206
+ }
2207
+
2208
  // if (defined ('AI_NORMAL_HEADER_STYLES') && AI_NORMAL_HEADER_STYLES && !get_inline_styles ()) {
2209
  // $classes [] = 'ai-list-block';
2210
  // }
constants.php CHANGED
@@ -19,6 +19,8 @@ if (!defined ('AD_INSERTER_PLUGIN_DIR'))
19
  if (!defined ('AD_INSERTER_FILE'))
20
  define ('AD_INSERTER_FILE', AD_INSERTER_PLUGIN_DIR.'ad-inserter.php');
21
 
 
 
22
  if (file_exists (AD_INSERTER_PLUGIN_DIR.'includes/functions.php')) {
23
  include_once AD_INSERTER_PLUGIN_DIR.'includes/functions.php';
24
  }
@@ -27,7 +29,7 @@ if (!defined( 'AD_INSERTER_NAME'))
27
  define ('AD_INSERTER_NAME', 'Ad Inserter');
28
 
29
  if (!defined( 'AD_INSERTER_VERSION'))
30
- define ('AD_INSERTER_VERSION', '2.3.20');
31
 
32
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
33
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
@@ -627,7 +629,9 @@ define ('DEFAULT_PARAGRAPH_COUNTING_FUNCTIONS', AI_STANDARD_PARAGRAPH_COUNTING_F
627
  define ('DEFAULT_NO_PARAGRAPH_COUNTING_INSIDE', 'blockquote, figure, li');
628
  define ('DEFAULT_AD_TITLE', 'Advertisements');
629
  define ('DEFAULT_PARAGRAPH_TAGS', 'p');
 
630
  define ('DEFAULT_ADMIN_TOOLBAR_DEBUGGING', AI_ENABLED);
 
631
  define ('DEFAULT_REMOTE_DEBUGGING', AI_DISABLED);
632
  define ('DEFAULT_BACKEND_JS_DEBUGGING', AI_DISABLED);
633
  define ('DEFAULT_FRONTEND_JS_DEBUGGING', AI_DISABLED);
19
  if (!defined ('AD_INSERTER_FILE'))
20
  define ('AD_INSERTER_FILE', AD_INSERTER_PLUGIN_DIR.'ad-inserter.php');
21
 
22
+ define ('AD_INSERTER_SLUG', str_replace ('/'.basename (AD_INSERTER_FILE), '', plugin_basename (AD_INSERTER_FILE)));
23
+
24
  if (file_exists (AD_INSERTER_PLUGIN_DIR.'includes/functions.php')) {
25
  include_once AD_INSERTER_PLUGIN_DIR.'includes/functions.php';
26
  }
29
  define ('AD_INSERTER_NAME', 'Ad Inserter');
30
 
31
  if (!defined( 'AD_INSERTER_VERSION'))
32
+ define ('AD_INSERTER_VERSION', '2.3.21');
33
 
34
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
35
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
629
  define ('DEFAULT_NO_PARAGRAPH_COUNTING_INSIDE', 'blockquote, figure, li');
630
  define ('DEFAULT_AD_TITLE', 'Advertisements');
631
  define ('DEFAULT_PARAGRAPH_TAGS', 'p');
632
+ define ('DEFAULT_FORCE_ADMIN_TOOLBAR', AI_DISABLED);
633
  define ('DEFAULT_ADMIN_TOOLBAR_DEBUGGING', AI_ENABLED);
634
+ define ('DEFAULT_ADMIN_TOOLBAR_MOBILE', AI_DISABLED);
635
  define ('DEFAULT_REMOTE_DEBUGGING', AI_DISABLED);
636
  define ('DEFAULT_BACKEND_JS_DEBUGGING', AI_DISABLED);
637
  define ('DEFAULT_FRONTEND_JS_DEBUGGING', AI_DISABLED);
css/ad-inserter.css CHANGED
@@ -1,5 +1,5 @@
1
  #ai-data {
2
- font-family: "2.3.20"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
@@ -1107,6 +1107,10 @@ img.automatic-insertion.preview {
1107
  }
1108
 
1109
  @media (max-width: 782px) {
 
 
 
 
1110
  .auto-fold #wpcontent {
1111
  padding-left: 4px;
1112
  }
1
  #ai-data {
2
+ font-family: "2.3.21"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
1107
  }
1108
 
1109
  @media (max-width: 782px) {
1110
+ #ai-settings {
1111
+ margin-right: 4px;
1112
+ }
1113
+
1114
  .auto-fold #wpcontent {
1115
  padding-left: 4px;
1116
  }
images/contextual-3.png ADDED
Binary file
images/contextual-4.gif ADDED
Binary file
images/contextual-5.png ADDED
Binary file
includes/dst/dst.php ADDED
@@ -0,0 +1,1325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * DST - WP theme and plugin usage tracking client
5
+ * Experimental
6
+ *
7
+ * @version 1.0.0
8
+ * @author Igor Funa <igor.funa/gmail.com>
9
+ */
10
+
11
+ /*
12
+
13
+ Change Log
14
+
15
+ DST 1.0.0 - 2018-09-13
16
+ - Initial release
17
+
18
+ */
19
+
20
+ if (!defined ('ABSPATH')) exit;
21
+
22
+ if (!class_exists ('DST_Client')) {
23
+
24
+ //define ('DST_DEBUG', true);
25
+
26
+ if (defined ('DST_DEBUG') && DST_DEBUG) {
27
+ // define ('DST_DEBUG_JS', true); // if defined, log Javascript debug messages
28
+ // define ('DST_DEBUG_ADMIN_TRACK', true); // if defined, tracking action is triggered on admin page load
29
+ // define ('DST_DEBUG_TIME_TO_TRACK', true); // if defined, it is the return value of is_time_to_track ()
30
+ // define ('DST_DEBUG_SCHEDULER', true); // if defined, tracking will be scheduled every minute
31
+ // define ('DST_DEBUG_LOG', true); // if defined, log file is written on each tracking action
32
+ }
33
+
34
+ class DST_Client {
35
+
36
+ const DST_TEXT_PLUGIN = 'plugin';
37
+ const DST_TEXT_THEME = 'theme';
38
+
39
+ const DST_DEFAULT_SCHEDULE = 'monthly'; // 'daily', 'weekly' or 'monthly' schedule (DST defines 'weekly', 'twicemonthly' and 'monthly')
40
+
41
+ const DST_PRODUCT_TYPE_PLUGIN = 1;
42
+ const DST_PRODUCT_TYPE_THEME = 2;
43
+
44
+ const DST_TRACKING_OFF = 0;
45
+ const DST_TRACKING_OPTIN = 1;
46
+ const DST_TRACKING_INITIALLY_DISABLED = 2;
47
+ const DST_TRACKING_NO_OPTIN = 3;
48
+
49
+ const DST_USE_EMAIL_OFF = 0;
50
+ const DST_USE_EMAIL_OPTIN_WITH_TRACKING = 1;
51
+ const DST_USE_EMAIL_OPTIN_AFTER_TRACKING = 2;
52
+ const DST_USE_EMAIL_INITIALLY_DISABLED = 3;
53
+ const DST_USE_EMAIL_NO_OPTIN = 4;
54
+
55
+ const DST_MULTISITE_SITES_TRACKING_OFF = 0;
56
+ const DST_MULTISITE_SITES_TRACKING_AS_MAIN = 1;
57
+ const DST_MULTISITE_SITES_TRACKING_WAIT_FOR_MAIN = 2;
58
+ const DST_MULTISITE_SITES_NO_OPTIN = 3;
59
+
60
+ const DST_TRACKING_URL_PARAMETER = 'dst';
61
+
62
+ const DST_THEME_MOD_ALLOW_TRACKING = 'dst-allow-tracking';
63
+
64
+ const DST_TRACKING_ACTION_HOOK = 'dst_update_';
65
+
66
+ const DST_TRANSIENT_THEME_ACTIVATED = 'dst_theme_activated_';
67
+ const DST_TRANSIENT_ADMIN_IP = 'dst_admin_ip';
68
+
69
+ const DST_OPTION_OPTIN_TRACKING = 'dst_optin_tracking';
70
+ const DST_OPTION_OPTIN_NEWSLETTER = 'dst_optin_newsletter';
71
+ const DST_OPTION_LAST_TRACK_TIMES = 'dst_last_track_times';
72
+ const DST_NOTIFICATION_TIMES = 'dst_notification_times';
73
+ const DST_OPTION_DEACTIVATION_REASON = 'dst_deactivation_reason';
74
+ const DST_OPTION_DEACTIVATION_DETAILS = 'dst_deactivation_details';
75
+
76
+ const DST_FILTER_IS_LOCAL = 'dst_is_local_';
77
+ const DST_FILTER_OPTIN_NOTICE_TEXT = 'dst_optin_notice_text_';
78
+ const DST_FILTER_EMAIL_NOTICE_TEXT = 'dst_email_notice_text_';
79
+ const DST_FILTER_FORM_TEXT = 'dst_deactivation_form_text_';
80
+ const DST_FILTER_SCHEDULE = 'dst_filter_schedule_';
81
+
82
+ const DST_ACTION_NONE = 0;
83
+ const DST_ACTION_START_TRACKING = 1;
84
+ const DST_ACTION_END_TRACKING = 2;
85
+ const DST_ACTION_UPGRADE = 3;
86
+ const DST_ACTION_OPTIN_TRACKING = 4;
87
+ const DST_ACTION_OPTIN_NEWSLETTER = 5;
88
+ const DST_ACTION_OPTIN_TRACKING_NEWSLETTER = 6;
89
+ const DST_ACTION_OPTIN_NO_NEWSLETTER = 7;
90
+ const DST_ACTION_SCHEDULE = 8;
91
+ const DST_ACTION_LIVE = 9;
92
+
93
+ private $dst_default_settings = array (
94
+ 'tracking_url' => '',
95
+ 'main_file' => '',
96
+ 'options' => array (),
97
+ 'tracking' => self::DST_TRACKING_OPTIN,
98
+ 'use_email' => self::DST_USE_EMAIL_OPTIN_WITH_TRACKING,
99
+ 'deactivation_form' => true,
100
+ 'track_local' => true,
101
+ 'product_type' => self::DST_PRODUCT_TYPE_PLUGIN,
102
+ 'theme_tracking' => false,
103
+ 'admin_ip_tracking' => true,
104
+ 'notice_icon' => '',
105
+ 'delay_notification' => 0,
106
+ 'multisite_tracking' => self::DST_MULTISITE_SITES_TRACKING_WAIT_FOR_MAIN,
107
+ 'remove' => false,
108
+ );
109
+
110
+ private $array_options = array (
111
+ self::DST_OPTION_OPTIN_TRACKING,
112
+ self::DST_OPTION_OPTIN_NEWSLETTER,
113
+ self::DST_OPTION_LAST_TRACK_TIMES,
114
+ self::DST_NOTIFICATION_TIMES,
115
+ self::DST_OPTION_DEACTIVATION_REASON,
116
+ self::DST_OPTION_DEACTIVATION_DETAILS,
117
+ );
118
+
119
+ private $version = '1.0.0';
120
+ private $tracking_url;
121
+ private $main_file;
122
+ private $slug;
123
+ private $options;
124
+ private $tracking;
125
+ private $deactivation_form;
126
+ private $use_email;
127
+ private $track_local;
128
+ private $product_type;
129
+ private $theme_tracking;
130
+ private $admin_ip_tracking;
131
+ private $notice_icon;
132
+ private $delay_notification;
133
+ private $action;
134
+
135
+ private $tracking_known;
136
+ private $use_email_known;
137
+
138
+ public function __construct ($_settings = array ()) {
139
+
140
+ if (!isset ($_settings ['main_file'])) {
141
+ $debug_backtrace = debug_backtrace (false, 1);
142
+ $_settings ['main_file'] = $debug_backtrace [0]['file'];
143
+ }
144
+
145
+ $settings = array_merge ($this->dst_default_settings, $_settings);
146
+
147
+ $this->tracking_url = $settings ['tracking_url'];
148
+ $this->main_file = $settings ['main_file'];
149
+ $this->options = $settings ['options'];
150
+ $this->tracking = $settings ['tracking'];
151
+ $this->deactivation_form = $settings ['deactivation_form'];
152
+ $this->use_email = $settings ['use_email'];
153
+ $this->track_local = $settings ['track_local'];
154
+ $this->product_type = $settings ['product_type'];
155
+ $this->theme_tracking = $settings ['theme_tracking'];
156
+ $this->admin_ip_tracking = $settings ['admin_ip_tracking'];
157
+ $this->notice_icon = $settings ['notice_icon'];
158
+ $this->delay_notification = $settings ['delay_notification'];
159
+ $this->multisite_tracking = $settings ['multisite_tracking'];
160
+ $this->action = self::DST_ACTION_NONE;
161
+
162
+ $this->slug = '';
163
+ if (basename ($this->main_file, '.php') != 'functions') {
164
+ $plugin_basename = plugin_basename ($this->main_file);
165
+ if (strpos ($plugin_basename, DIRECTORY_SEPARATOR)) {
166
+ $this->slug = str_replace (DIRECTORY_SEPARATOR.basename ($this->main_file), '', $plugin_basename);
167
+ } else $this->slug = basename ($this->main_file, '.php');
168
+ } else {
169
+ $this->product_type = self::DST_PRODUCT_TYPE_THEME;
170
+ $this->slug = get_option ('stylesheet');
171
+ }
172
+
173
+ if ($settings ['remove']) {
174
+ $this->delete_settings ();
175
+ return;
176
+ }
177
+
178
+ if ($this->use_email == self::DST_USE_EMAIL_INITIALLY_DISABLED) {
179
+ $use_email = get_option (self::DST_OPTION_OPTIN_NEWSLETTER);
180
+ if (!isset ($use_email [$this->slug])) set_use_email (false);
181
+ }
182
+
183
+ if (is_multisite () && !is_main_site ()) {
184
+ switch ($this->multisite_tracking) {
185
+ case self::DST_MULTISITE_SITES_TRACKING_OFF:
186
+ return;
187
+ break;
188
+ case self::DST_MULTISITE_SITES_TRACKING_WAIT_FOR_MAIN:
189
+ $this->tracking = self::DST_TRACKING_OFF;
190
+ $this->use_email = self::DST_USE_EMAIL_OFF;
191
+
192
+ if (defined ('BLOG_ID_CURRENT_SITE')) {
193
+ $optin_tracking = get_blog_option (BLOG_ID_CURRENT_SITE, self::DST_OPTION_OPTIN_TRACKING);
194
+ if (isset ($optin_tracking [$this->slug]) && $optin_tracking [$this->slug])
195
+ $this->tracking = self::DST_TRACKING_NO_OPTIN;
196
+
197
+ $optin_newsletter = get_blog_option (BLOG_ID_CURRENT_SITE, self::DST_OPTION_OPTIN_NEWSLETTER);
198
+ if (isset ($optin_newsletter [$this->slug]) && $optin_newsletter [$this->slug])
199
+ $this->use_email = self::DST_USE_EMAIL_NO_OPTIN;
200
+ }
201
+
202
+ break;
203
+ case self::DST_MULTISITE_SITES_NO_OPTIN:
204
+ $this->tracking = self::DST_TRACKING_NO_OPTIN;
205
+ $this->use_email = self::DST_USE_EMAIL_NO_OPTIN;
206
+ break;
207
+ }
208
+ }
209
+
210
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) {
211
+ $this->theme_tracking = get_theme_mod (self::DST_THEME_MOD_ALLOW_TRACKING, 0);
212
+ add_action ('after_switch_theme', array ($this, 'start_tracking_theme'));
213
+ add_action ('switch_theme', array ($this, 'end_tracking'));
214
+ add_action ('customize_save_after', array ($this, 'customize_save_after'));
215
+
216
+ } else {
217
+ register_activation_hook ($this->main_file, array ($this, 'start_tracking'));
218
+ register_deactivation_hook ($this->main_file, array ($this, 'end_tracking'));
219
+ }
220
+
221
+ $this->init();
222
+ }
223
+
224
+ public function init() {
225
+ add_filter ('cron_schedules', array ($this, 'dst_cron_schedules'));
226
+ add_action (self::DST_TRACKING_ACTION_HOOK . $this->slug, array ($this, 'update'));
227
+
228
+ if (defined ('DST_DEBUG_ADMIN_TRACK') && DST_DEBUG_ADMIN_TRACK) {
229
+ add_action ('admin_init', array ($this, 'update'));
230
+ }
231
+
232
+ add_action ('admin_init', array ($this, 'init_data'));
233
+ add_action ('admin_notices', array ($this, 'optin_notice'));
234
+ add_action ('admin_footer', array ($this, 'admin_footer'));
235
+
236
+ // Upgrade
237
+ add_action ('upgrader_process_complete', array ($this, 'dst_upgrader_process_complete'), 10, 2);
238
+
239
+ // Deactivation
240
+ add_filter ('plugin_action_links_' . plugin_basename ($this->main_file), array ($this, 'filter_action_links'));
241
+ add_action ('admin_footer-plugins.php', array ($this, 'deactivation_form'));
242
+ add_action ('wp_ajax_dst_ajax_' . $this->slug, array ($this, 'process_ajax'));
243
+
244
+ $this->check_schedule ();
245
+
246
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) {
247
+ if ($activation_time = get_transient (self::DST_TRANSIENT_THEME_ACTIVATED . $this->slug)) {
248
+ $this->log_event ('THEME ACTIVATED ' .(time () - $activation_time) . ' s ago');
249
+
250
+ delete_transient (self::DST_TRANSIENT_THEME_ACTIVATED . $this->slug);
251
+ $this->action = self::DST_ACTION_START_TRACKING;
252
+ $this->update ();
253
+ }
254
+ }
255
+ }
256
+
257
+ public function start_tracking () {
258
+ $this->action = self::DST_ACTION_START_TRACKING;
259
+ $this->update (true);
260
+ }
261
+
262
+ public function start_tracking_theme () {
263
+ $this->log_event ('after_switch_theme');
264
+
265
+ set_transient (self::DST_TRANSIENT_THEME_ACTIVATED . $this->slug, time (), 20);
266
+ }
267
+
268
+ function customize_save_after () {
269
+ if (get_theme_mod (self::DST_THEME_MOD_ALLOW_TRACKING, 0) && !$this->theme_tracking) {
270
+ $this->log_event ('THEME TRACKING ENABLED');
271
+
272
+ $this->theme_tracking = true;
273
+ $this->action = self::DST_ACTION_OPTIN_TRACKING;
274
+ $this->update (true);
275
+ }
276
+ }
277
+
278
+ public function dst_cron_schedules ($schedules) {
279
+ if (defined ('DST_DEBUG_SCHEDULER') && DST_DEBUG_SCHEDULER) {
280
+ $schedules ['everyminute'] = array (
281
+ 'interval' => 60,
282
+ 'display' => __('Every minute')
283
+ );
284
+ }
285
+ $schedules ['weekly'] = array (
286
+ 'interval' => 604800,
287
+ 'display' => __('Once Weekly')
288
+ );
289
+ $schedules ['monthly'] = array (
290
+ 'interval' => 2635200,
291
+ 'display' => __('Once Monthly')
292
+ );
293
+ $schedules ['twicemonthly'] = array (
294
+ 'interval' => 1317600,
295
+ 'display' => __('Twice Monthly')
296
+ );
297
+ return $schedules;
298
+ }
299
+
300
+ public function get_schedule () {
301
+ if (defined ('DST_DEBUG_SCHEDULER') && DST_DEBUG_SCHEDULER) {
302
+ return ('everyminute');
303
+ }
304
+
305
+ $schedule = apply_filters (self::DST_FILTER_SCHEDULE . $this->slug, self::DST_DEFAULT_SCHEDULE);
306
+
307
+ return $schedule;
308
+ }
309
+
310
+ public function check_schedule () {
311
+ $schedule = $this->get_schedule ();
312
+ $hook = self::DST_TRACKING_ACTION_HOOK . $this->slug;
313
+ if (!wp_next_scheduled ($hook) || wp_get_schedule ($hook) != $schedule) {
314
+ wp_clear_scheduled_hook ($hook);
315
+ wp_schedule_event (time (), $schedule, $hook);
316
+ }
317
+ }
318
+
319
+ public function delete_settings () {
320
+ foreach ($this->array_options as $array_option) {
321
+ $saved_option = get_option ($array_option);
322
+ if (isset ($saved_option [$this->slug])) {
323
+ unset ($saved_option [$this->slug]);
324
+ if (!empty ($saved_option)) {
325
+ update_option ($array_option, $saved_option);
326
+ } else delete_option ($array_option);
327
+ }
328
+ }
329
+
330
+ wp_clear_scheduled_hook (self::DST_TRACKING_ACTION_HOOK . $this->slug);
331
+ delete_transient (self::DST_TRANSIENT_THEME_ACTIVATED . $this->slug);
332
+ delete_transient (self::DST_TRANSIENT_ADMIN_IP);
333
+
334
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) {
335
+ remove_theme_mod (self::DST_THEME_MOD_ALLOW_TRACKING);
336
+ }
337
+ }
338
+
339
+ public function update ($force = false) {
340
+ if (!$this->tracking_url) return;
341
+
342
+ if (!$this->get_tracking ()) return;
343
+
344
+ if (!$force) {
345
+ if (!$this->is_time_to_track ()) return;
346
+ }
347
+
348
+ $data = $this->get_data ();
349
+
350
+ $this->send_data ($data);
351
+ }
352
+
353
+ function dst_upgrader_process_complete ($upgrader_object, $options) {
354
+ $this->log_event ('', serialize ($options));
355
+ if (is_array ($options) && array_key_exists ('action', $options) && $options ['action'] == 'update' && array_key_exists ('type', $options)) {
356
+ if ($options ['type'] == 'plugin' && array_key_exists ('plugins', $options) && is_array ($options ['plugins']) && !empty ($options ['plugins'])) {
357
+ $this_plugin = plugin_basename ($this->main_file);
358
+ foreach ($options ['plugins'] as $plugin) {
359
+ if ($plugin == $this_plugin) {
360
+ $this->action = self::DST_ACTION_UPGRADE;
361
+ $this->update (true);
362
+ break;
363
+ }
364
+ }
365
+ }
366
+ elseif ($options ['type'] == 'theme' && array_key_exists ('themes', $options) && is_array ($options ['themes']) && !empty ($options ['themes'])) {
367
+ foreach ($options ['themes'] as $theme) {
368
+
369
+ // if ($theme == 'dynamic-news-lite') $theme = 'dynamic-news-lite-child';
370
+
371
+ if ($theme == $this->slug) {
372
+ $this->action = self::DST_ACTION_UPGRADE;
373
+ $this->update (true);
374
+ break;
375
+ }
376
+ }
377
+ }
378
+ }
379
+ }
380
+
381
+ public function log_event ($event_data = '', $data = '') {
382
+ if (defined ('DST_DEBUG_LOG') && DST_DEBUG_LOG) {
383
+ $debug_backtrace = debug_backtrace (false, 7);
384
+ $backtrace = array ();
385
+ foreach ($debug_backtrace as $index => $debug_backtrace_data) {
386
+ if ($index == 0) continue;
387
+ if (isset ($debug_backtrace_data ['function'])) {
388
+ $backtrace []= $debug_backtrace_data ['function'];
389
+ }
390
+ }
391
+
392
+ if ($event_data != '') $event_data = '[' . $event_data . '] ';
393
+ $line = sprintf ('%s %02d % -30s %s%s %s', date ('Y-m-d H:i:s'), $this->action, $this->slug, $event_data, implode (' - ', $backtrace), $data) . PHP_EOL;
394
+ $file_path = __DIR__ . '/dst.log';
395
+
396
+ $file = fopen ($file_path, "a");
397
+ fwrite ($file, $line);
398
+ fclose ($file);
399
+ }
400
+ }
401
+
402
+ public function send_data ($data) {
403
+ if (!$this->tracking_url) return;
404
+
405
+ $this->log_event ('', serialize ($data));
406
+
407
+ $request = wp_remote_post (
408
+ esc_url ($this->tracking_url . '?' . self::DST_TRACKING_URL_PARAMETER . '=' . $this->slug),
409
+ array (
410
+ 'method' => 'POST',
411
+ 'timeout' => 20,
412
+ 'redirection' => 5,
413
+ 'httpversion' => '1.1',
414
+ 'blocking' => false,
415
+ 'body' => $data,
416
+ 'user-agent' => 'PUT/1.0.0; ' . home_url ()
417
+ )
418
+ );
419
+
420
+ $this->set_track_time ();
421
+
422
+ if (is_wp_error ($request)) {
423
+ return $request;
424
+ }
425
+ }
426
+
427
+ public function get_data () {
428
+ $data ['message'] = '';
429
+
430
+
431
+
432
+ $data = array (
433
+ 'slug' => sanitize_text_field ($this->slug),
434
+ 'url' => home_url (),
435
+ 'site_name' => get_bloginfo ('name'),
436
+ 'wp_version' => get_bloginfo ('version'),
437
+ 'language' => get_bloginfo ('language'),
438
+ 'charset' => get_bloginfo ('charset'),
439
+ 'client_location' => __FILE__,
440
+ 'client_version' => $this->version,
441
+ 'server' => isset ($_SERVER ['SERVER_SOFTWARE']) ? $_SERVER ['SERVER_SOFTWARE'] : '',
442
+ 'php_version' => phpversion (),
443
+ 'multisite' => is_multisite() ? (is_main_site () ? 1 : 2) : 0,
444
+ 'network_url' => rtrim (network_home_url (), '/'),
445
+ 'site_count' => is_multisite() ? get_blog_count() : '',
446
+ );
447
+
448
+ if ($this->admin_ip_tracking) {
449
+ $data ['admin_ip'] = get_transient (self::DST_TRANSIENT_ADMIN_IP) ? get_transient (self::DST_TRANSIENT_ADMIN_IP) : '';
450
+ }
451
+
452
+ $data ['use_email'] = $this->get_use_email ();
453
+
454
+ if ($this->get_use_email ()) {
455
+ $data ['email'] = get_bloginfo ('admin_email');
456
+ }
457
+
458
+ if (!function_exists ('get_plugins')) {
459
+ include ABSPATH . '/wp-admin/includes/plugin.php';
460
+ }
461
+
462
+ $all_plugins = array_keys (get_plugins());
463
+ $active_plugins = get_option ('active_plugins', array());
464
+
465
+ $plugins = array ();
466
+ foreach ($all_plugins as $key => $plugin) {
467
+ if (in_array ($plugin, $active_plugins))
468
+ $plugins [$plugin] = 1; else
469
+ $plugins [$plugin] = 0;
470
+ }
471
+
472
+ $data ['plugins'] = json_encode ($plugins);
473
+
474
+ $data ['text_direction'] = 'LTR';
475
+ if (function_exists ('is_rtl')) {
476
+ if (is_rtl ()) {
477
+ $data ['text_direction'] = 'RTL';
478
+ }
479
+ } else $data ['text_direction'] = '';
480
+
481
+ $data ['status'] = '1';
482
+ if ($this->product_type == self::DST_PRODUCT_TYPE_PLUGIN) {
483
+ $plugin = $this->plugin_data ();
484
+ if (empty ($plugin)) {
485
+ $data ['message'] .= __('No plugin data.', 'dst');
486
+ $data ['status'] = '-1';
487
+ } else {
488
+ if (isset ($plugin ['Name'])) {
489
+ $data ['plugin'] = sanitize_text_field ($plugin ['Name']);
490
+ }
491
+ if( isset( $plugin ['Version'] ) ) {
492
+ $data ['plugin_version'] = sanitize_text_field ($plugin ['Version']);
493
+ }
494
+ }
495
+ } else {
496
+ $data ['plugin'] = 'theme';
497
+ }
498
+
499
+ $data ['options'] = json_encode ($this->options);
500
+
501
+ $theme = wp_get_theme ();
502
+ if ($theme->Name) {
503
+ $data ['theme'] = sanitize_text_field ($theme->Name);
504
+ }
505
+ if ($theme->Version) {
506
+ $data ['theme_version'] = sanitize_text_field ($theme->Version);
507
+ }
508
+ if ($theme->Template) {
509
+ $data ['theme_parent'] = sanitize_text_field ($theme->Template);
510
+ }
511
+
512
+ if ($this->action == self::DST_ACTION_NONE) {
513
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME && $activation_time = get_transient (self::DST_TRANSIENT_THEME_ACTIVATED . $this->slug)) {
514
+ $this->action = self::DST_ACTION_START_TRACKING;
515
+ delete_transient (self::DST_TRANSIENT_THEME_ACTIVATED . $this->slug);
516
+ } else {
517
+ $debug_backtrace = debug_backtrace (false, 3);
518
+ // get_data - update - call_user_func_array
519
+
520
+ if ($debug_backtrace [1]['function'] == 'update' && $debug_backtrace [2]['function'] == 'call_user_func_array') {
521
+ $this->action = self::DST_ACTION_SCHEDULE;
522
+ }
523
+ }
524
+ }
525
+
526
+ $data ['action'] = $this->action;
527
+
528
+ return $data;
529
+ }
530
+
531
+ public function plugin_data () {
532
+ if ($this->product_type == self::DST_PRODUCT_TYPE_PLUGIN) {
533
+ if (!function_exists ('get_plugin_data')) {
534
+ include ABSPATH . '/wp-admin/includes/plugin.php';
535
+ }
536
+ $plugin = get_plugin_data ($this->main_file);
537
+ return $plugin;
538
+ }
539
+ }
540
+
541
+ public function end_tracking () {
542
+ if (!$this->tracking_url) return;
543
+
544
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) {
545
+ $allow_tracking = $this->theme_tracking;
546
+ } else {
547
+ $allow_tracking = $this->get_tracking ();
548
+ }
549
+
550
+ if (!$allow_tracking) return;
551
+
552
+ $this->action = self::DST_ACTION_END_TRACKING;
553
+
554
+ $data = $this->get_data ();
555
+
556
+ $data ['status'] = '0';
557
+
558
+ if ($deactivation_reason = $this->get_deactivation_reason ()) {
559
+ $data ['deactivation_reason'] = $deactivation_reason;
560
+ }
561
+ if ($deactivation_details = $this->get_deactivation_details ()) {
562
+ $data ['deactivation_details'] = $deactivation_details;
563
+ }
564
+
565
+ $this->send_data ($data);
566
+
567
+ wp_clear_scheduled_hook (self::DST_TRACKING_ACTION_HOOK . $this->slug);
568
+ delete_transient (self::DST_TRANSIENT_THEME_ACTIVATED . $this->slug);
569
+
570
+ $track_time = get_option (self::DST_OPTION_LAST_TRACK_TIMES);
571
+ if (isset ($track_time [$this->slug])) {
572
+ unset ($track_time [$this->slug]);
573
+ update_option (self::DST_OPTION_LAST_TRACK_TIMES, $track_time);
574
+ }
575
+ }
576
+
577
+ public function get_plugin_tracking () {
578
+ switch ($this->tracking) {
579
+ case self::DST_TRACKING_OFF:
580
+ case self::DST_TRACKING_NO_OPTIN:
581
+ return null;
582
+ break;
583
+ }
584
+
585
+ $allow_tracking = get_option (self::DST_OPTION_OPTIN_TRACKING);
586
+ if (!isset ($allow_tracking [$this->slug])) return null;
587
+ return $allow_tracking [$this->slug];
588
+ }
589
+
590
+ public function get_tracking () {
591
+ switch ($this->tracking) {
592
+ case self::DST_TRACKING_OFF:
593
+ return false;
594
+ break;
595
+ case self::DST_TRACKING_NO_OPTIN:
596
+ return true;
597
+ break;
598
+ }
599
+
600
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) {
601
+ return get_theme_mod (self::DST_THEME_MOD_ALLOW_TRACKING, 0);
602
+ } else {
603
+ $allow_tracking = get_option (self::DST_OPTION_OPTIN_TRACKING);
604
+ if (!isset ($allow_tracking [$this->slug])) return false;
605
+ return $allow_tracking [$this->slug];
606
+ }
607
+ }
608
+
609
+ public function set_tracking ($enabled) {
610
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) {
611
+ if ($enabled != $this->get_tracking ()) {
612
+ set_theme_mod (self::DST_THEME_MOD_ALLOW_TRACKING, $enabled);
613
+ if ($enabled) {
614
+ $this->action = self::DST_ACTION_OPTIN_TRACKING;
615
+ $this->update (true);
616
+ }
617
+ }
618
+ } else {
619
+ $allow_tracking = get_option (self::DST_OPTION_OPTIN_TRACKING);
620
+ if (!isset ($allow_tracking [$this->slug]) || $enabled != $this->get_tracking ()) {
621
+ if (empty ($allow_tracking) || !is_array ($allow_tracking)) {
622
+ $allow_tracking = array ($this->slug => (int) $enabled);
623
+ } else {
624
+ $allow_tracking [$this->slug] = (int) $enabled;
625
+ }
626
+ update_option (self::DST_OPTION_OPTIN_TRACKING, $allow_tracking);
627
+ if ($enabled) {
628
+ $this->action = self::DST_ACTION_OPTIN_TRACKING;
629
+ $this->update (true);
630
+ }
631
+ }
632
+ }
633
+ }
634
+
635
+ public function is_time_to_track () {
636
+ if (defined ('DST_DEBUG_TIME_TO_TRACK')) {
637
+ $this->log_event ('DST_DEBUG_TIME_TO_TRACK: ' . ((bool) DST_DEBUG_TIME_TO_TRACK));
638
+ return DST_DEBUG_TIME_TO_TRACK;
639
+ }
640
+
641
+ $track_times = get_option (self::DST_OPTION_LAST_TRACK_TIMES, array());
642
+
643
+ if (!isset ($track_times [$this->slug])) return true;
644
+
645
+ $schedule = $this->get_schedule ();
646
+
647
+ if (defined ('DST_DEBUG_SCHEDULER') && DST_DEBUG_SCHEDULER) {
648
+ $period = 'everyminute';
649
+ }
650
+ elseif ($schedule == 'hourly') $period = 'hour';
651
+ elseif ($schedule == 'daily') $period = 'day';
652
+ elseif ($schedule == 'weekly') $period = 'week';
653
+ elseif ($schedule == 'monthly') $period = 'month';
654
+ else {
655
+ $this->log_event ('UNKNOWN SCHEDULE: ' . $schedule);
656
+ $period = 'month';
657
+ }
658
+
659
+ if ($track_times [$this->slug] < strtotime ('-1 ' . $period)) return true;
660
+
661
+ if (defined ('DST_DEBUG_LOG') && DST_DEBUG_LOG) {
662
+ $difference = $track_times [$this->slug] - strtotime ('-1 ' . $period);
663
+ $days = floor ($difference / (3600 * 24));
664
+ $hours = floor (($difference - $days * (3600 * 24)) / 3600);
665
+ $minutes = floor (($difference - $days * (3600 * 24) - $hours * 3600) / 60);
666
+ $seconds = $difference - $days * (3600 * 24) - $hours * 3600 - $minutes * 60;
667
+ $this->log_event ("$schedule: " . sprintf ('%02d %02d:%02d:%02d', $days, $hours, $minutes, $seconds) . ' to go');
668
+ }
669
+
670
+ return false;
671
+ }
672
+
673
+ public function set_track_time () {
674
+ $track_times = get_option (self::DST_OPTION_LAST_TRACK_TIMES, array ());
675
+ $track_times [$this->slug] = time();
676
+ update_option (self::DST_OPTION_LAST_TRACK_TIMES, $track_times);
677
+ }
678
+
679
+ public function init_data () {
680
+ if ($this->admin_ip_tracking && current_user_can ('administrator')) {
681
+ $admin_ip_address = $this->get_client_ip_address ();
682
+ $saved_admin_ip_address = get_transient (self::DST_TRANSIENT_ADMIN_IP);
683
+ if (!$saved_admin_ip_address || $admin_ip_address != $saved_admin_ip_address) {
684
+ set_transient (self::DST_TRANSIENT_ADMIN_IP, $admin_ip_address, 365 * 24 * 3600);
685
+ }
686
+ }
687
+
688
+ $notification_times = get_option (self::DST_NOTIFICATION_TIMES, array ());
689
+ if (!isset ($notification_times [$this->slug])) {
690
+ $notification_time = time() + absint ($this->delay_notification);
691
+ $notification_times [$this->slug] = $notification_time;
692
+ update_option (self::DST_NOTIFICATION_TIMES, $notification_times);
693
+ }
694
+ }
695
+
696
+ public function get_is_notification_time () {
697
+ $notification_times = get_option (self::DST_NOTIFICATION_TIMES, array ());
698
+ $time = time();
699
+ if (isset ($notification_times [$this->slug])) {
700
+ $notification_time = $notification_times [$this->slug];
701
+ if ($notification_time <= $time) return true;
702
+ }
703
+ return false;
704
+ }
705
+
706
+ public function get_use_email () {
707
+ switch ($this->use_email) {
708
+ case self::DST_USE_EMAIL_OFF:
709
+ return false;
710
+ break;
711
+ case self::DST_USE_EMAIL_OPTIN_WITH_TRACKING:
712
+ case self::DST_USE_EMAIL_OPTIN_AFTER_TRACKING:
713
+ switch ($this->tracking) {
714
+ case self::DST_TRACKING_OFF:
715
+ return false;
716
+ break;
717
+ case self::DST_TRACKING_NO_OPTIN:
718
+ return true;
719
+ break;
720
+ }
721
+ break;
722
+ case self::DST_USE_EMAIL_NO_OPTIN:
723
+ return true;
724
+ break;
725
+ }
726
+
727
+ $use_email = get_option (self::DST_OPTION_OPTIN_NEWSLETTER);
728
+
729
+ if (!isset ($use_email [$this->slug])) return false;
730
+ return $use_email [$this->slug];
731
+ }
732
+
733
+ public function set_use_email ($enabled) {
734
+ $use_email = get_option (self::DST_OPTION_OPTIN_NEWSLETTER);
735
+ if (!isset ($use_email [$this->slug]) || $enabled != $this->get_use_email ()) {
736
+ if (empty ($use_email) || !is_array ($use_email)) {
737
+ $use_email = array ($this->slug => (int) $enabled);
738
+ } else {
739
+ $use_email [$this->slug] = (int) $enabled;
740
+ }
741
+ update_option (self::DST_OPTION_OPTIN_NEWSLETTER, $use_email);
742
+ }
743
+ }
744
+
745
+ public function get_deactivation_reason () {
746
+ $reasons = get_option (self::DST_OPTION_DEACTIVATION_REASON);
747
+ if (!isset ($reasons [$this->slug])) return '';
748
+ return $reasons [$this->slug];
749
+ }
750
+
751
+ public function set_deactivation_reason ($reason) {
752
+ $reasons = get_option (self::DST_OPTION_DEACTIVATION_REASON);
753
+ if (empty ($reasons) || !is_array ($reasons)) {
754
+ $reasons = array ($this->slug => $reason);
755
+ } else {
756
+ $reasons [$this->slug] = $reason;
757
+ }
758
+ update_option (self::DST_OPTION_DEACTIVATION_REASON, $reasons);
759
+ }
760
+
761
+ public function get_deactivation_details () {
762
+ $reasons = get_option (self::DST_OPTION_DEACTIVATION_DETAILS);
763
+ if (!isset ($reasons [$this->slug])) return '';
764
+ return $reasons [$this->slug];
765
+ }
766
+
767
+ public function set_deactivation_details ($detail) {
768
+ $details = get_option (self::DST_OPTION_DEACTIVATION_DETAILS);
769
+ if (empty ($details) || !is_array ($details)) {
770
+ $details = array ($this->slug => $detail);
771
+ } else {
772
+ $details [$this->slug] = $detail;
773
+ }
774
+ update_option (self::DST_OPTION_DEACTIVATION_DETAILS, $details);
775
+ }
776
+
777
+ public function notice_html ($notice_text, $action_yes, $action_no, $class = 'dst-notice') {
778
+ $name = '';
779
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) {
780
+ $theme = wp_get_theme ();
781
+ if ($theme->Name) {
782
+ $name = sanitize_text_field ($theme->Name);
783
+ }
784
+
785
+ } else {
786
+ $plugin = $this->plugin_data ();
787
+ $name = $plugin ['Name'];
788
+ }
789
+
790
+ $notice_text = sprintf (
791
+ $notice_text,
792
+ $this->product_type == self::DST_PRODUCT_TYPE_PLUGIN ? self::DST_TEXT_PLUGIN : self::DST_TEXT_THEME
793
+ );
794
+ ?>
795
+ <div class="notice notice-info <?php echo $class; ?> dst-no-phone" style="display: none;" data-slug="<?php echo $this->slug; ?>" nonce="<?php echo wp_create_nonce ("dst_data"); ?>" >
796
+ <?php
797
+ if ($this->notice_icon != '') {
798
+ ?>
799
+ <div class="dst-notice-element">
800
+ <img src="<?php echo $this->notice_icon; ?>" style="width: 50px; margin: 5px 10px 0px 10px;" />
801
+ </div>
802
+ <?php
803
+ }
804
+ ?>
805
+ <div class="dst-notice-element" style="width: 100%; padding: 0 10px 0;">
806
+ <?php
807
+ $notice = str_replace (array ('[BR]', '[STRONG]', '[/STRONG]', '[NAME]'), array ("<br />", '<strong>', '</strong>', esc_html ($name)), esc_html ($notice_text));
808
+ $paragraphs = explode ('[P]', $notice);
809
+ foreach ($paragraphs as $paragraph) {
810
+ echo '<p>',$paragraph, '</p>';
811
+ }
812
+ ?>
813
+ </div>
814
+ <div class="dst-notice-element dst-notice-buttons last">
815
+ <div class="dst-notice-text-button dst-notice-dismiss" data-action="<?php echo $action_yes; ?>">
816
+ <button class="button-primary">Allow</button>
817
+ </div>
818
+ <div class="dst-notice-text-button dst-notice-dismiss" data-action="<?php echo $action_no; ?>">Do not allow</div>
819
+ </div>
820
+ </div>
821
+ <?php
822
+ }
823
+
824
+ public function notice_needed () {
825
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) {
826
+
827
+ switch ($this->tracking) {
828
+ case self::DST_TRACKING_OPTIN:
829
+ $mod = get_theme_mod (self::DST_THEME_MOD_ALLOW_TRACKING, '#');
830
+ $this->tracking_known = $mod !== '#';
831
+ break;
832
+ default:
833
+ $this->tracking_known = true;
834
+ break;
835
+ }
836
+
837
+ } else {
838
+ switch ($this->tracking) {
839
+ case self::DST_TRACKING_OPTIN:
840
+ $allow_tracking = get_option (self::DST_OPTION_OPTIN_TRACKING);
841
+ $this->tracking_known = isset ($allow_tracking [$this->slug]);
842
+ break;
843
+ default:
844
+ $this->tracking_known = true;
845
+ break;
846
+ }
847
+ }
848
+
849
+
850
+ switch ($this->use_email) {
851
+ case self::DST_USE_EMAIL_OPTIN_WITH_TRACKING:
852
+ case self::DST_USE_EMAIL_OPTIN_AFTER_TRACKING:
853
+
854
+ switch ($this->tracking) {
855
+ case self::DST_TRACKING_OPTIN:
856
+ $use_email = get_option (self::DST_OPTION_OPTIN_NEWSLETTER);
857
+ $this->use_email_known = isset ($use_email [$this->slug]);
858
+ break;
859
+ default:
860
+ $this->use_email_known = true;
861
+ break;
862
+ }
863
+
864
+ break;
865
+ default:
866
+ $this->use_email_known = true;
867
+ break;
868
+ }
869
+
870
+ return (!$this->tracking_known || !$this->use_email_known);
871
+ }
872
+
873
+ public function admin_footer () {
874
+
875
+ if (!current_user_can ('manage_options')) return;
876
+
877
+ if (!$this->notice_needed ()) return;
878
+ ?>
879
+ <style>
880
+ .dst-notice {
881
+ vertical-align: middle;
882
+ padding: 0;
883
+ border-top: 1px solid #E5E5E5;
884
+ border-right: 1px solid #E5E5E5;
885
+ border-radius: 6px;
886
+ }
887
+ .dst-notice-hidden {
888
+ display: none;
889
+ }
890
+ .dst-notice img {
891
+ }
892
+ .dst-notice-element {
893
+ display: table-cell;
894
+ vertical-align: middle;
895
+ color: #444;
896
+ font-size: 13px;
897
+ font-family: 'Open Sans', sans-serif;
898
+ user-select: none;
899
+ }
900
+ .dst-notice-buttons {
901
+ border-left: 1px solid #E5E5E5;
902
+ padding: 0 15px;
903
+ background: #F8F8F8;
904
+ position: relative;
905
+ white-space: nowrap;
906
+ text-align: center;
907
+ }
908
+ .dst-notice-buttons.last {
909
+ border-top-right-radius: 6px;
910
+ border-bottom-right-radius: 6px;
911
+ }
912
+ .dst-notice-buttons button.button-primary {
913
+ margin: 10px;
914
+ line-height: 28px;
915
+ }
916
+ .dst-notice-buttons a {
917
+ text-decoration: none;
918
+ box-shadow: 0 0 0;
919
+ color: #fff;
920
+ }
921
+ .dst-notice-text-button {
922
+ display: inline-block;
923
+ color: #bbb;
924
+ cursor: pointer;
925
+ margin: 0px 10px 0px;
926
+ vertical-align: middle;
927
+ }
928
+
929
+ @media (max-width: 1200px) {
930
+ .dst-notice-text-button {
931
+ display: block;
932
+ }
933
+ }
934
+
935
+ @media (max-width: 768px) {
936
+ .dst-no-phone {
937
+ display: none!important;
938
+ }
939
+ }
940
+ </style>
941
+ <script>
942
+ jQuery (document).ready (function ($) {
943
+ var dst_debugging = <?php echo defined ('DST_DEBUG_JS') && DST_DEBUG_JS ? 'true' : 'false'; ?>;
944
+
945
+ $(document).on ('click', '.dst-notice[data-slug=<?php echo $this->slug; ?>] .dst-notice-dismiss', function () {
946
+ var notice_div = $(this).closest ('.dst-notice');
947
+ var nonce = notice_div.attr ('nonce');
948
+ var slug = '<?php echo $this->slug; ?>';
949
+ var action = $(this).data ('action');
950
+
951
+ if (dst_debugging) console.log ('DST NOTICE CLICK', slug, action);
952
+
953
+ notice_div.hide ();
954
+
955
+ $.ajax (ajaxurl, {
956
+ type: 'POST',
957
+ data: {
958
+ action: 'dst_ajax_' + slug,
959
+ dst_check: nonce,
960
+ slug: slug,
961
+ click: action,
962
+ }
963
+ }).done (function (data) {
964
+
965
+ if (dst_debugging) console.log ('DST NOTICE CLICK DONE');
966
+
967
+ if (action == 'yes-') {
968
+
969
+ if (dst_debugging) console.log ('DST NOTICE NEXT');
970
+
971
+ $('.dst-notice-hidden[data-slug=' + slug + ']').fadeIn ("fast", function() {
972
+ $(this).css ('display', 'table').removeClass ('dst-notice-hidden').addClass ('dst-notice');
973
+ });
974
+ }
975
+ });
976
+
977
+ });
978
+
979
+ function show_dst_notice (slug) {
980
+ $('.dst-notice[data-slug=' + slug + ']').fadeIn ("fast", function() {
981
+ $(this).css ('display', 'table');
982
+ });
983
+ }
984
+
985
+ if (typeof ajaxurl !== 'undefined') {
986
+ var notice_div = $('.dst-notice');
987
+ var nonce = notice_div.attr ('nonce');
988
+ var slug = '<?php echo $this->slug; ?>';
989
+
990
+ if (dst_debugging) console.log ('DST NOTICE ajaxurl', ajaxurl);
991
+ if (dst_debugging) console.log ('DST NOTICE ajax check', slug, nonce);
992
+
993
+ if (typeof nonce !== 'undefined') {
994
+ $.ajax (ajaxurl, {
995
+ type: 'POST',
996
+ data: {
997
+ action: 'dst_ajax_' + slug,
998
+ slug: slug,
999
+ dst_check: nonce,
1000
+ 'notice-check': nonce
1001
+ }
1002
+ }).done (function (data) {
1003
+ if (dst_debugging) console.log ('DST NOTICE CHECK RESPONSE for', slug + ':', data == nonce ? 'ok' : 'wrong data: ' + data);
1004
+
1005
+ if (data == nonce) {
1006
+ setTimeout (show_dst_notice, 500);
1007
+ setTimeout (function() {show_dst_notice (slug);}, 500);
1008
+ }
1009
+ });
1010
+ }
1011
+ }
1012
+ });
1013
+ </script>
1014
+ <?php
1015
+ }
1016
+
1017
+ public function optin_notice () {
1018
+
1019
+ if (!current_user_can ('manage_options')) return;
1020
+
1021
+ if (!$this->notice_needed ()) return;
1022
+
1023
+ if (!$this->get_is_notification_time ()) return;
1024
+
1025
+ if (defined ('DST_DEBUG') && DST_DEBUG) {
1026
+ $is_local = false;
1027
+ } elseif (!$this->track_local) {
1028
+ $is_local =
1029
+ stristr (network_site_url ( '/' ), '.dev' ) !== false ||
1030
+ stristr (network_site_url ('/'), 'localhost' ) !== false ||
1031
+ stristr (network_site_url ('/'), ':8888' ) !== false;
1032
+ } else $is_local = false;
1033
+
1034
+ $is_local = apply_filters (self::DST_FILTER_IS_LOCAL . $this->slug, $is_local);
1035
+
1036
+ if ($is_local) return;
1037
+
1038
+ if (!$this->tracking_known) {
1039
+ if ($this->use_email == self::DST_USE_EMAIL_OPTIN_WITH_TRACKING) {
1040
+ $notice_text = __('[STRONG][NAME][/STRONG][P]Thank you for installing our %1$s. We\'d like your permission to track its usage on your site and subscribe you to our newsletter. This is completely optional.[BR]We won\'t record any sensitive data, only information regarding the WordPress environment and %1$s settings, which will help us to make improvements to the %1$s.', 'dst');
1041
+ $notice_text = apply_filters (self::DST_FILTER_OPTIN_NOTICE_TEXT . esc_attr ($this->slug), $notice_text);
1042
+ $this->notice_html ($notice_text, 'yes-yes', 'no-no');
1043
+ } else {
1044
+ $notice_text = __('[STRONG][NAME][/STRONG][P]Thank you for installing our %1$s. We would like to track its usage on your site. This is completely optional.[BR]We don\'t record any sensitive data, only information regarding the WordPress environment and %1$s settings, which will help us to make improvements to the %1$s.', 'dst');
1045
+ $notice_text = apply_filters (self::DST_FILTER_OPTIN_NOTICE_TEXT . esc_attr ($this->slug), $notice_text);
1046
+ $this->notice_html ($notice_text, 'yes-', 'no-no');
1047
+ }
1048
+ }
1049
+
1050
+ if ($this->use_email == self::DST_USE_EMAIL_OPTIN_AFTER_TRACKING && !$this->use_email_known) {
1051
+ $notice_text = __('Thank you for opting in to tracking. Would you like to receive occasional news about this %s, including details of new features and special offers?', 'dst');
1052
+
1053
+ $notice_text = apply_filters (self::DST_FILTER_EMAIL_NOTICE_TEXT . esc_attr ($this->slug), $notice_text);
1054
+
1055
+ $this->notice_html ($notice_text, '-yes', '-no', $this->tracking_known ? 'dst-notice' : 'dst-notice-hidden');
1056
+ }
1057
+ }
1058
+
1059
+ public function filter_action_links ($links) {
1060
+ if (!$this->get_tracking ()) return $links;
1061
+
1062
+ if (isset ($links ['deactivate']) && $this->deactivation_form) {
1063
+ $deactivation_link = $links ['deactivate'];
1064
+ $deactivation_link = str_replace ( '<a ', '<span class="dst-deactivation-form-wrapper"><span class="dst-deactivation-form" id="dst-deactivation-form-' . esc_attr ($this->slug) . '"></span></span><a onclick="javascript:event.preventDefault();" id="dst-deactivation-link-' . esc_attr ($this->slug) . '" ', $deactivation_link);
1065
+ $links ['deactivate'] = $deactivation_link;
1066
+ }
1067
+ return $links;
1068
+ }
1069
+
1070
+ public function default_deactivation_form_text () {
1071
+ $form = array();
1072
+
1073
+ $form ['heading'] = __( 'Sorry to see you go', 'dst');
1074
+ $form ['body'] = __( 'Before you deactivate the plugin, would you quickly give us your reason for doing so?', 'dst');
1075
+ $form ['options'] = array (
1076
+ __( 'Set up is too difficult', 'dst'),
1077
+ __( 'Lack of documentation', 'dst'),
1078
+ __( 'Not the features I wanted', 'dst'),
1079
+ __( 'Found a better plugin', 'dst'),
1080
+ __( 'Installed by mistake', 'dst'),
1081
+ __( 'Didn\'t work', 'dst'),
1082
+ __( 'Just testing', 'dst'),
1083
+ __( 'Only required temporarily', 'dst'),
1084
+ );
1085
+ $form ['details'] = __('Details (optional)', 'dst' );
1086
+ $form ['info'] = __('This information will greatly help us to improve the plugin.', 'dst');
1087
+
1088
+ return $form;
1089
+ }
1090
+
1091
+ public function filtered_deactivation_form_text () {
1092
+ $form = $this->default_deactivation_form_text ();
1093
+ return apply_filters (self::DST_FILTER_FORM_TEXT . esc_attr ($this->slug), $form);
1094
+ }
1095
+
1096
+ public function deactivation_form () {
1097
+
1098
+ if ($this->product_type == self::DST_PRODUCT_TYPE_THEME) return;
1099
+
1100
+ $form = $this->filtered_deactivation_form_text ();
1101
+ if (!isset ($form ['heading']) || !isset( $form ['body']) || !isset ($form ['options']) || !is_array ($form ['options']) || !isset ($form ['info']) || !isset ($form ['details'])) {
1102
+ $form = $this->default_deactivation_form_text ();
1103
+ }
1104
+
1105
+ $html = '<div class="dst-deactivation-form-head"><strong>' . esc_html ($form ['heading']) . '</strong></div>';
1106
+ $html .= '<div class="dst-deactivation-form-body"><p>' . esc_html ($form['body']) . '</p>';
1107
+ if (is_array ($form ['options'])) {
1108
+ $html .= '<div class="dst-deactivation-options"><p>';
1109
+ foreach ($form ['options'] as $option) {
1110
+ $html .= '<input type="checkbox" name="dst-deactivation-options[]" id="' . str_replace( " ", "", esc_attr ($option )) . '" value="' . esc_attr ($option) . '"> <label for="' . str_replace (" ", "", esc_attr ($option)) . '">' . esc_attr ($option) . '</label><br>';
1111
+ }
1112
+ $html .= '</p><label for="dst-deactivation-reasons">' . esc_html ($form ['details'] ) .'</label><textarea name="dst-deactivation-reasons" id="dst-deactivation-reasons" rows="3" style="width:100%"></textarea><p>' . esc_html ($form['info']) . '</p>';
1113
+ $html .= '</div>';
1114
+ }
1115
+ $html .= '</div>';
1116
+ $html .= '<p class="deactivating-spinner"><span class="spinner"></span> ' . __( 'Submitting form', 'dst') . '</p>';
1117
+ ?>
1118
+ <div class="dst-deactivation-form-bg"></div>
1119
+ <style type="text/css">
1120
+ .dst-form-active .dst-deactivation-form-bg {
1121
+ background: rgba( 0, 0, 0, .7);
1122
+ position: fixed;
1123
+ top: 0;
1124
+ left: 0;
1125
+ width: 100%;
1126
+ height: 100%;
1127
+ }
1128
+ .dst-deactivation-form-wrapper {
1129
+ position: relative;
1130
+ z-index: 999;
1131
+ display: none;
1132
+ }
1133
+ .dst-form-active .dst-deactivation-form-wrapper {
1134
+ display: inline-block;
1135
+ }
1136
+ .dst-deactivation-form {
1137
+ display: none;
1138
+ }
1139
+ .dst-form-active .dst-deactivation-form {
1140
+ position: fixed;
1141
+ top: 10%;
1142
+ left: 18%;
1143
+ max-width: 400px;
1144
+ background: #fff;
1145
+ white-space: normal;
1146
+ border-radius: 6px;
1147
+ }
1148
+ .dst-deactivation-form-head {
1149
+ background: #716eef;
1150
+ color: #fff;
1151
+ padding: 8px 18px;
1152
+ border-top-left-radius: 6px;
1153
+ border-top-right-radius: 6px;
1154
+ }
1155
+ .dst-deactivation-form-body {
1156
+ padding: 8px 18px;
1157
+ color: #444;
1158
+ }
1159
+ .deactivating-spinner {
1160
+ width: 200px;
1161
+ height: 30px;
1162
+ display: none;
1163
+ }
1164
+ .deactivating-spinner .spinner {
1165
+ float: none;
1166
+ margin: 4px 4px 0 18px;
1167
+ vertical-align: bottom;
1168
+ visibility: visible;
1169
+ }
1170
+ .dst-deactivation-form-footer {
1171
+ padding: 8px 18px;
1172
+ }
1173
+ .dst-deactivation-form-footer .button.secondary {
1174
+ float: left;
1175
+ background: #fff;
1176
+ color: #000;
1177
+ }
1178
+ .dst-deactivation-form-footer .button.primary {
1179
+ float: right;
1180
+ background: #716eef;
1181
+ color: #fff;
1182
+ }
1183
+ @media (max-width: 500px) {
1184
+ .dst-form-active .dst-deactivation-form {
1185
+ width: 100%;
1186
+ top: 50%;
1187
+ left: 50%;
1188
+ transform: translate(-50%,-50%);
1189
+ }
1190
+ }
1191
+ </style>
1192
+ <script>
1193
+ jQuery(document).ready (function ($){
1194
+ var dst_debugging = <?php echo defined ('DST_DEBUG_JS') && DST_DEBUG_JS ? 'true' : 'false'; ?>;
1195
+
1196
+ $("#dst-deactivation-link-<?php echo esc_attr ($this->slug); ?>").on ("click",function() {
1197
+ var url = $("#dst-deactivation-link-<?php echo esc_attr ($this->slug); ?>").attr ('href');
1198
+
1199
+ if (dst_debugging) console.log ('DST DEACTIVATION url', url);
1200
+
1201
+ $('body').toggleClass ('dst-form-active');
1202
+ $("#dst-deactivation-form-<?php echo esc_attr ($this->slug); ?>").fadeIn();
1203
+ $("#dst-deactivation-form-<?php echo esc_attr ($this->slug); ?>").html ('<?php echo $html; ?>' +
1204
+ '<div class="dst-deactivation-form-footer"><p><a id="dst-just-deactivate" class="button secondary" href="'+url+'"><?php _e('Just Deactivate', 'dst'); ?></a>&nbsp;<a id="dst-submit-form" class="button primary" href="#"><?php _e( 'Submit and Deactivate', 'dst' ); ?></a></p></div>');
1205
+ $('#dst-submit-form').on ('click', function (e){
1206
+ $("#dst-deactivation-form-<?php echo esc_attr ($this->slug); ?> .dst-deactivation-form-body").hide();
1207
+ $("#dst-deactivation-form-<?php echo esc_attr ($this->slug); ?> .dst-deactivation-form-footer").hide();
1208
+ $("#dst-deactivation-form-<?php echo esc_attr ($this->slug); ?> .deactivating-spinner").show();
1209
+ e.preventDefault();
1210
+
1211
+ var values = new Array();
1212
+ $.each ($("input[name='dst-deactivation-options[]']:checked"), function(){
1213
+ values.push ($(this).val ());
1214
+ });
1215
+ var details = $('#dst-deactivation-reasons').val();
1216
+ var data = {
1217
+ 'action': 'dst_ajax_<?php echo $this->slug; ?>',
1218
+ 'slug': '<?php echo $this->slug; ?>',
1219
+ 'values': values,
1220
+ 'details': details,
1221
+ 'dst_check': "<?php echo wp_create_nonce ('dst_data'); ?>",
1222
+ 'dataType': "json"
1223
+ }
1224
+
1225
+ if (dst_debugging) console.log ('DST DEACTIVATION SUBMIT', data);
1226
+
1227
+ $.post(
1228
+ ajaxurl,
1229
+ data,
1230
+ function (response) {
1231
+ window.location.href = url;
1232
+ }
1233
+ );
1234
+ });
1235
+ $('#dst-just-deactivate').on ('click', function (e){
1236
+ e.preventDefault();
1237
+ $('.dst-deactivation-form-wrapper').hide ();
1238
+ $('.dst-deactivation-form-bg').hide ();
1239
+ window.location.href = $('#dst-just-deactivate').attr ('href');
1240
+ });
1241
+
1242
+ $('.dst-deactivation-form-bg').on ('click', function (){
1243
+ $("#dst-deactivation-form-<?php echo esc_attr ($this->slug); ?>").fadeOut();
1244
+ $('body').removeClass ('dst-form-active');
1245
+ });
1246
+
1247
+ window.onkeydown = function( event ) {
1248
+ if (event.keyCode === 27 ) {
1249
+ $('.dst-deactivation-form-bg').click ();
1250
+ }
1251
+ }
1252
+ });
1253
+ });
1254
+ </script>
1255
+ <?php }
1256
+
1257
+ public function process_ajax () {
1258
+ check_admin_referer ("dst_data", "dst_check");
1259
+
1260
+ if (isset ($_POST ["slug"]) && isset ($_POST ["click"])) {
1261
+ $action = sanitize_text_field ($_POST ["click"]);
1262
+ if ($action == 'yes-') {
1263
+ $this->set_tracking (true);
1264
+ $this->action = self::DST_ACTION_OPTIN_TRACKING;
1265
+ $this->update (true);
1266
+ } elseif ($action == 'no-no') {
1267
+ $this->set_tracking (false);
1268
+ $this->set_use_email (false);
1269
+ } elseif ($action == 'yes-yes') {
1270
+ $this->set_tracking (true);
1271
+ $this->set_use_email (true);
1272
+ $this->action = self::DST_ACTION_OPTIN_TRACKING_NEWSLETTER;
1273
+ $this->update (true);
1274
+ } elseif ($action == '-yes') {
1275
+ $this->set_use_email (true);
1276
+ $this->action = self::DST_ACTION_OPTIN_NEWSLETTER;
1277
+ $this->update (true);
1278
+ } elseif ($action == '-no') {
1279
+ $this->set_use_email (false);
1280
+ $this->action = self::DST_ACTION_OPTIN_NO_NEWSLETTER;
1281
+ $this->update (true);
1282
+ }
1283
+ }
1284
+
1285
+ elseif (isset ($_POST ["slug"]) && isset ($_POST ["notice-check"])) {
1286
+ echo $_POST ["notice-check"];
1287
+ }
1288
+
1289
+ elseif (isset ($_POST ["slug"]) && isset ($_POST ["values"]) && isset ($_POST ['details'])) {
1290
+ $values = json_encode (wp_unslash ($_POST ['values']));
1291
+ $this->set_deactivation_reason ($values);
1292
+
1293
+ $details = sanitize_text_field ($_POST ['details']);
1294
+ $this->set_deactivation_details ($details);
1295
+ }
1296
+
1297
+ wp_die();
1298
+ }
1299
+
1300
+ function get_client_ip_address (){
1301
+ $server_addr = isset ($_SERVER ['SERVER_ADDR']) ? $_SERVER ['SERVER_ADDR'] : '';
1302
+ foreach (array (
1303
+ 'HTTP_CF_CONNECTING_IP',
1304
+ 'HTTP_CLIENT_IP',
1305
+ 'HTTP_X_FORWARDED_FOR',
1306
+ 'HTTP_X_FORWARDED',
1307
+ 'HTTP_X_CLUSTER_CLIENT_IP',
1308
+ 'HTTP_FORWARDED_FOR',
1309
+ 'HTTP_FORWARDED',
1310
+ 'REMOTE_ADDR',
1311
+ ) as $key) {
1312
+ if (array_key_exists ($key, $_SERVER) === true) {
1313
+ foreach (explode (',', $_SERVER[$key]) as $ip) {
1314
+ $ip = str_replace ("for=", "", $ip);
1315
+ $ip = trim ($ip); // just to be safe
1316
+ if ($server_addr != '' && $ip == $server_addr) continue 2; // HTTP_X_FORWARDED_FOR may report server IP address
1317
+ return $ip;
1318
+ }
1319
+ }
1320
+ }
1321
+ return '';
1322
+ }
1323
+ }
1324
+
1325
+ }
includes/dst/index.html ADDED
@@ -0,0 +1 @@
 
1
+ <html><body bgcolor="#FFFFFF"></body></html>
includes/js/ai-insert.js CHANGED
@@ -46,16 +46,22 @@ function ai_insert (insertion, selector, insertion_code) {
46
  function ai_insert_viewport (element) {
47
 
48
  function hasClass (element, cls) {
 
 
49
  if (element.classList) return element.classList.contains (cls); else
50
  return (' ' + element.className + ' ').indexOf (' ' + cls + ' ') > - 1;
51
  }
52
 
53
  function addClass (element, cls) {
 
 
54
  if (element.classList) element.classList.add (cls); else
55
  element.className += ' ' + cls;
56
  }
57
 
58
  function removeClass (element, cls) {
 
 
59
  if (element.classList) element.classList.remove (cls); else
60
  element.className = element.className.replace (new RegExp ('(^|\\b)' + cls.split (' ').join ('|') + '(\\b|$)', 'gi'), ' ');
61
  }
@@ -64,7 +70,7 @@ function ai_insert_viewport (element) {
64
 
65
  if (ai_debug) console.log ('AI VIEWPORT INSERTION:', 'class=\'' + element.getAttribute ('class') + '\'');
66
 
67
- var visible = element.offsetWidth > 0 || element.offsetHeight > 0;
68
  var block = element.getAttribute ('data-block');
69
 
70
  if (visible) {
46
  function ai_insert_viewport (element) {
47
 
48
  function hasClass (element, cls) {
49
+ if (element == null) return false;
50
+
51
  if (element.classList) return element.classList.contains (cls); else
52
  return (' ' + element.className + ' ').indexOf (' ' + cls + ' ') > - 1;
53
  }
54
 
55
  function addClass (element, cls) {
56
+ if (element == null) return;
57
+
58
  if (element.classList) element.classList.add (cls); else
59
  element.className += ' ' + cls;
60
  }
61
 
62
  function removeClass (element, cls) {
63
+ if (element == null) return;
64
+
65
  if (element.classList) element.classList.remove (cls); else
66
  element.className = element.className.replace (new RegExp ('(^|\\b)' + cls.split (' ').join ('|') + '(\\b|$)', 'gi'), ' ');
67
  }
70
 
71
  if (ai_debug) console.log ('AI VIEWPORT INSERTION:', 'class=\'' + element.getAttribute ('class') + '\'');
72
 
73
+ var visible = !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
74
  var block = element.getAttribute ('data-block');
75
 
76
  if (visible) {
includes/js/ai-insert.min.js CHANGED
@@ -1,8 +1,8 @@
1
  function ai_insert(insertion,selector,insertion_code){Array.prototype.forEach.call(document.querySelectorAll(selector),function(element,index){var ai_debug=typeof ai_debugging!=="undefined";if(element.hasAttribute("id"))selector_string="#"+element.getAttribute("id");else if(element.hasAttribute("class"))selector_string="."+element.getAttribute("class").replace(new RegExp(" ","g"),".");else selector_string="";var template=document.createElement("div");template.innerHTML=insertion_code;var ai_selector_counter=
2
  template.getElementsByClassName("ai-selector-counter")[0];if(ai_selector_counter!=null)ai_selector_counter.innerText=index+1;var ai_debug_name_ai_main=template.getElementsByClassName("ai-debug-name ai-main")[0];if(ai_debug_name_ai_main!=null)ai_debug_name_ai_main.innerText=insertion.toUpperCase()+" "+selector+" ("+element.tagName.toLowerCase()+selector_string+")";var range=document.createRange();var fragment=range.createContextualFragment(template.innerHTML);if(insertion=="before")element.parentNode.insertBefore(fragment,
3
  element);else if(insertion=="after")element.parentNode.insertBefore(fragment,element.nextSibling);if(ai_debug)console.log("AI INSERT",insertion,selector,"("+element.tagName.toLowerCase()+selector_string+")")})}
4
- function ai_insert_viewport(element){function hasClass(element,cls){if(element.classList)return element.classList.contains(cls);else return(" "+element.className+" ").indexOf(" "+cls+" ")>-1}function addClass(element,cls){if(element.classList)element.classList.add(cls);else element.className+=" "+cls}function removeClass(element,cls){if(element.classList)element.classList.remove(cls);else element.className=element.className.replace(new RegExp("(^|\\b)"+cls.split(" ").join("|")+"(\\b|$)","gi")," ")}
5
- var ai_debug=typeof ai_debugging!=="undefined";if(ai_debug)console.log("AI VIEWPORT INSERTION:","class='"+element.getAttribute("class")+"'");var visible=element.offsetWidth>0||element.offsetHeight>0;var block=element.getAttribute("data-block");if(visible){var insertion_code=element.getAttribute("data-code");var insertion_type=element.getAttribute("data-insertion");var selector=element.getAttribute("data-selector");if(insertion_code!=null)if(insertion_type!=null&&selector!=null){var selector_exists=
6
- document.querySelectorAll(selector).length;if(ai_debug)console.log("AI VIEWPORT VISIBLE: block",block,insertion_type,selector,selector_exists?"":"NOT FOUND");if(selector_exists){ai_insert(insertion_type,selector,b64d(insertion_code));removeClass(element,"ai-viewports")}}else{if(ai_debug)console.log("AI VIEWPORT VISIBLE: block",block);var range=document.createRange();var fragment=range.createContextualFragment(b64d(insertion_code));element.parentNode.insertBefore(fragment,element.nextSibling);removeClass(element,
7
- "ai-viewports")}}else{if(ai_debug)console.log("AI VIEWPORT NOT VISIBLE: block",block);var debug_bar=element.previousElementSibling;if(hasClass(debug_bar,"ai-debug-bar")&&hasClass(debug_bar,"ai-debug-script")){removeClass(debug_bar,"ai-debug-script");addClass(debug_bar,"ai-debug-viewport-invisible")}removeClass(element,"ai-viewports")}}function b64e(str){return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,function toSolidBytes(match,p1){return String.fromCharCode("0x"+p1)}))}
8
- function b64d(str){return decodeURIComponent(atob(str).split("").map(function(c){return"%"+("00"+c.charCodeAt(0).toString(16)).slice(-2)}).join(""))};
1
  function ai_insert(insertion,selector,insertion_code){Array.prototype.forEach.call(document.querySelectorAll(selector),function(element,index){var ai_debug=typeof ai_debugging!=="undefined";if(element.hasAttribute("id"))selector_string="#"+element.getAttribute("id");else if(element.hasAttribute("class"))selector_string="."+element.getAttribute("class").replace(new RegExp(" ","g"),".");else selector_string="";var template=document.createElement("div");template.innerHTML=insertion_code;var ai_selector_counter=
2
  template.getElementsByClassName("ai-selector-counter")[0];if(ai_selector_counter!=null)ai_selector_counter.innerText=index+1;var ai_debug_name_ai_main=template.getElementsByClassName("ai-debug-name ai-main")[0];if(ai_debug_name_ai_main!=null)ai_debug_name_ai_main.innerText=insertion.toUpperCase()+" "+selector+" ("+element.tagName.toLowerCase()+selector_string+")";var range=document.createRange();var fragment=range.createContextualFragment(template.innerHTML);if(insertion=="before")element.parentNode.insertBefore(fragment,
3
  element);else if(insertion=="after")element.parentNode.insertBefore(fragment,element.nextSibling);if(ai_debug)console.log("AI INSERT",insertion,selector,"("+element.tagName.toLowerCase()+selector_string+")")})}
4
+ function ai_insert_viewport(element){function hasClass(element,cls){if(element==null)return false;if(element.classList)return element.classList.contains(cls);else return(" "+element.className+" ").indexOf(" "+cls+" ")>-1}function addClass(element,cls){if(element==null)return;if(element.classList)element.classList.add(cls);else element.className+=" "+cls}function removeClass(element,cls){if(element==null)return;if(element.classList)element.classList.remove(cls);else element.className=element.className.replace(new RegExp("(^|\\b)"+
5
+ cls.split(" ").join("|")+"(\\b|$)","gi")," ")}var ai_debug=typeof ai_debugging!=="undefined";if(ai_debug)console.log("AI VIEWPORT INSERTION:","class='"+element.getAttribute("class")+"'");var visible=!!(element.offsetWidth||element.offsetHeight||element.getClientRects().length);var block=element.getAttribute("data-block");if(visible){var insertion_code=element.getAttribute("data-code");var insertion_type=element.getAttribute("data-insertion");var selector=element.getAttribute("data-selector");if(insertion_code!=
6
+ null)if(insertion_type!=null&&selector!=null){var selector_exists=document.querySelectorAll(selector).length;if(ai_debug)console.log("AI VIEWPORT VISIBLE: block",block,insertion_type,selector,selector_exists?"":"NOT FOUND");if(selector_exists){ai_insert(insertion_type,selector,b64d(insertion_code));removeClass(element,"ai-viewports")}}else{if(ai_debug)console.log("AI VIEWPORT VISIBLE: block",block);var range=document.createRange();var fragment=range.createContextualFragment(b64d(insertion_code));
7
+ element.parentNode.insertBefore(fragment,element.nextSibling);removeClass(element,"ai-viewports")}}else{if(ai_debug)console.log("AI VIEWPORT NOT VISIBLE: block",block);var debug_bar=element.previousElementSibling;if(hasClass(debug_bar,"ai-debug-bar")&&hasClass(debug_bar,"ai-debug-script")){removeClass(debug_bar,"ai-debug-script");addClass(debug_bar,"ai-debug-viewport-invisible")}removeClass(element,"ai-viewports")}}
8
+ function b64e(str){return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,function toSolidBytes(match,p1){return String.fromCharCode("0x"+p1)}))}function b64d(str){return decodeURIComponent(atob(str).split("").map(function(c){return"%"+("00"+c.charCodeAt(0).toString(16)).slice(-2)}).join(""))};
includes/js/ai-lists.js CHANGED
@@ -1,143 +1,167 @@
1
- jQuery (function ($) {
2
- function getHostName (url) {
3
- var match = url.match (/:\/\/(.[^/:]+)/i);
4
- if (match != null && match.length > 1 && typeof match [1] === 'string' && match [1].length > 0) {
5
- return match [1];
6
- } else {
7
- return null;
8
- }
9
- }
10
-
11
- ai_process_lists = function () {
12
- var ai_debug = typeof ai_debugging !== 'undefined';
13
- var cookies = document.cookie.split (";");
14
- var referrer = document.referrer;
15
-
16
- cookies.forEach (function (cookie, index) {
17
- cookies [index] = cookie.trim();
18
- });
19
-
20
- if (referrer != '') referrer = getHostName (referrer);
21
-
22
- var ai_list_blocks = $("div.ai-list-data");
23
- if (ai_list_blocks.length) {
24
- ai_list_blocks.each (function () {
25
-
26
- var enable_block = true;
27
-
28
- var found = false;
29
-
30
- var referer_list = $(this).attr ("referer-list");
31
- if (typeof referer_list != "undefined") {
32
- var referer_list_array = atob (referer_list).split (",");
33
- var referers_list_type = $(this).attr ("referer-list-type");
34
-
35
- if (ai_debug) console.log ('');
36
- if (ai_debug) console.log ("AI LISTS referer: ", referrer);
37
- if (ai_debug) console.log ("AI LISTS referer list:", atob (referer_list), referers_list_type);
38
-
39
- $.each (referer_list_array, function (index, list_referer) {
40
- if (list_referer == '') return true;
41
-
42
- if (list_referer == '#') {
43
- if (referrer == "") {
44
- found = true;
45
- return false;
46
- }
47
- } else if (list_referer == referrer) {
48
- found = true;
49
- return false;
50
- }
51
- });
52
-
53
- switch (referers_list_type) {
54
- case "B":
55
- if (found) enable_block = false;
56
- break;
57
- case "W":
58
- if (!found) enable_block = false;
59
- break;
60
- }
61
-
62
- if (ai_debug) console.log ("AI LISTS list found", found);
63
- if (ai_debug) console.log ("AI LISTS list pass", enable_block);
64
- }
65
-
66
- if (enable_block) {
67
- var parameter_list = $(this).attr ("parameter-list");
68
- if (typeof parameter_list != "undefined") {
69
- var parameter_list_array = atob (parameter_list).split (",");
70
- var parameter_list_type = $(this).attr ("parameter-list-type");
71
-
72
- if (ai_debug) console.log ('');
73
- if (ai_debug) console.log ("AI LISTS cookies: ", cookies);
74
- if (ai_debug) console.log ("AI LISTS parameter list:", atob (parameter_list), parameter_list_type);
75
-
76
- var found = false;
77
-
78
- $.each (parameter_list_array, function (index, list_parameter) {
79
-
80
- if (list_parameter.indexOf ('=') != - 1) {
81
- if (cookies.indexOf (list_parameter) != - 1) {
82
- found = true;
83
- return false;
84
- }
85
- } else {
86
- cookies.forEach (function (cookie) {
87
- var cookie_data = cookie.split ("=");
88
- if (list_parameter == cookie_data [0]) {
89
- found = true;
90
- return false;
91
- }
92
- });
93
- }
94
- });
95
-
96
- switch (parameter_list_type) {
97
- case "B":
98
- if (found) enable_block = false;
99
- break;
100
- case "W":
101
- if (!found) enable_block = false;
102
- break;
103
- }
104
-
105
- if (ai_debug) console.log ("AI LISTS list found", found);
106
- if (ai_debug) console.log ("AI LISTS list pass", enable_block);
107
- }
108
- }
109
-
110
- $(this).css ({"visibility": "", "position": "", "width": "", "height": "", "z-index": ""}).removeClass ('ai-list-data');
111
- var block_wrapping_div = $(this).closest ('div.ai-list-block');
112
- block_wrapping_div.css ({"visibility": "", "position": "", "z-index": ""}).removeClass ('ai-list-block');
113
- block_wrapping_div.find ('.ai-debug-name.ai-list-info').text (referrer);
114
- block_wrapping_div.find ('.ai-debug-name.ai-list-status').text (enable_block ? 'VISIBLE' : 'HIDDEN');
115
- if (!enable_block) {
116
- $(this).hide ();
117
- block_wrapping_div.removeAttr ('data-ai');
118
- } else {
119
- if (typeof $(this).data ('code') != 'undefined') {
120
- var block_code = atob ($(this).data ('code'));
121
- $(this).append (block_code);
122
- if (!ai_debug) $(this).attr ('data-code', '');
123
-
124
- if (typeof aiLazyLoading == 'function') {
125
- $("div.ai-lazy", this).each (function (index, element) {
126
- aiLazyLoading ({
127
- lazyClass: 'ai-lazy',
128
- lazyElement: this.element,
129
- });
130
- });
131
- }
132
-
133
- // Doesn't process inserted code for rotation - it will be called with setTimeout 5 ms later
134
- }
135
- }
136
- });
137
- }
138
- }
139
-
140
- $(document).ready(function($) {
141
- setTimeout (function() {ai_process_lists ();}, 5);
142
- });
143
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery (function ($) {
2
+
3
+ function b64e (str) {
4
+ // first we use encodeURIComponent to get percent-encoded UTF-8,
5
+ // then we convert the percent encodings into raw bytes which
6
+ // can be fed into btoa.
7
+ return btoa (encodeURIComponent (str).replace (/%([0-9A-F]{2})/g,
8
+ function toSolidBytes (match, p1) {
9
+ return String.fromCharCode ('0x' + p1);
10
+ }));
11
+ }
12
+
13
+ function b64d (str) {
14
+ // Going backwards: from bytestream, to percent-encoding, to original string.
15
+ return decodeURIComponent (atob (str).split ('').map (function(c) {
16
+ return '%' + ('00' + c.charCodeAt (0).toString (16)).slice (-2);
17
+ }).join (''));
18
+ }
19
+
20
+ function getHostName (url) {
21
+ var match = url.match (/:\/\/(.[^/:]+)/i);
22
+ if (match != null && match.length > 1 && typeof match [1] === 'string' && match [1].length > 0) {
23
+ return match [1];
24
+ } else {
25
+ return null;
26
+ }
27
+ }
28
+
29
+ ai_process_lists = function () {
30
+ var ai_debug = typeof ai_debugging !== 'undefined';
31
+ var cookies = document.cookie.split (";");
32
+ var referrer = document.referrer;
33
+
34
+ cookies.forEach (function (cookie, index) {
35
+ cookies [index] = cookie.trim();
36
+ });
37
+
38
+ if (referrer != '') referrer = getHostName (referrer);
39
+
40
+ var ai_list_blocks = $("div.ai-list-data");
41
+ if (ai_list_blocks.length) {
42
+ ai_list_blocks.each (function () {
43
+
44
+ var enable_block = true;
45
+
46
+ var found = false;
47
+
48
+ var referer_list = $(this).attr ("referer-list");
49
+ if (typeof referer_list != "undefined") {
50
+ var referer_list_array = b64d (referer_list).split (",");
51
+ var referers_list_type = $(this).attr ("referer-list-type");
52
+
53
+ if (ai_debug) console.log ('');
54
+ if (ai_debug) console.log ("AI LISTS referer: ", referrer);
55
+ if (ai_debug) console.log ("AI LISTS referer list:", b64d (referer_list), referers_list_type);
56
+
57
+ $.each (referer_list_array, function (index, list_referer) {
58
+ if (list_referer == '') return true;
59
+
60
+ if (list_referer == '#') {
61
+ if (referrer == "") {
62
+ found = true;
63
+ return false;
64
+ }
65
+ } else if (list_referer == referrer) {
66
+ found = true;
67
+ return false;
68
+ }
69
+ });
70
+
71
+ switch (referers_list_type) {
72
+ case "B":
73
+ if (found) enable_block = false;
74
+ break;
75
+ case "W":
76
+ if (!found) enable_block = false;
77
+ break;
78
+ }
79
+
80
+ if (ai_debug) console.log ("AI LISTS list found", found);
81
+ if (ai_debug) console.log ("AI LISTS list pass", enable_block);
82
+ }
83
+
84
+ if (enable_block) {
85
+ var parameter_list = $(this).attr ("parameter-list");
86
+ if (typeof parameter_list != "undefined") {
87
+ var parameter_list_array = b64d (parameter_list).split (",");
88
+ var parameter_list_type = $(this).attr ("parameter-list-type");
89
+
90
+ if (ai_debug) console.log ('');
91
+ if (ai_debug) console.log ("AI LISTS cookies: ", cookies);
92
+ if (ai_debug) console.log ("AI LISTS parameter list:", b64d (parameter_list), parameter_list_type);
93
+
94
+ var found = false;
95
+
96
+ $.each (parameter_list_array, function (index, list_parameter) {
97
+
98
+ if (list_parameter.indexOf ('=') != - 1) {
99
+ if (cookies.indexOf (list_parameter) != - 1) {
100
+ found = true;
101
+ return false;
102
+ }
103
+ } else {
104
+ cookies.forEach (function (cookie) {
105
+ var cookie_data = cookie.split ("=");
106
+ if (list_parameter == cookie_data [0]) {
107
+ found = true;
108
+ return false;
109
+ }
110
+ });
111
+ }
112
+ });
113
+
114
+ switch (parameter_list_type) {
115
+ case "B":
116
+ if (found) enable_block = false;
117
+ break;
118
+ case "W":
119
+ if (!found) enable_block = false;
120
+ break;
121
+ }
122
+
123
+ if (ai_debug) console.log ("AI LISTS list found", found);
124
+ if (ai_debug) console.log ("AI LISTS list pass", enable_block);
125
+ }
126
+ }
127
+
128
+ $(this).css ({"visibility": "", "position": "", "width": "", "height": "", "z-index": ""}).removeClass ('ai-list-data');
129
+ var block_wrapping_div = $(this).closest ('div.ai-list-block');
130
+ // block_wrapping_div.css ({"visibility": "", "position": "", "z-index": ""}).removeClass ('ai-list-block');
131
+ block_wrapping_div.removeClass ('ai-list-block');
132
+ block_wrapping_div.find ('.ai-debug-name.ai-list-info').text (referrer);
133
+ block_wrapping_div.find ('.ai-debug-name.ai-list-status').text (enable_block ? 'VISIBLE' : 'HIDDEN');
134
+ if (!enable_block) {
135
+ $(this).hide ();
136
+ block_wrapping_div.removeAttr ('data-ai').hide ();
137
+ } else {
138
+ block_wrapping_div.css ({"visibility": ""});
139
+ if (block_wrapping_div.hasClass ('ai-remove-position')) {
140
+ block_wrapping_div.css ({"position": ""});
141
+ }
142
+
143
+ if (typeof $(this).data ('code') != 'undefined') {
144
+ var block_code = b64d ($(this).data ('code'));
145
+ $(this).append (block_code);
146
+ if (!ai_debug) $(this).attr ('data-code', '');
147
+
148
+ if (typeof aiLazyLoading == 'function') {
149
+ $("div.ai-lazy", this).each (function (index, element) {
150
+ aiLazyLoading ({
151
+ lazyClass: 'ai-lazy',
152
+ lazyElement: this.element,
153
+ });
154
+ });
155
+ }
156
+
157
+ // Doesn't process inserted code for rotation - it will be called with setTimeout 5 ms later
158
+ }
159
+ }
160
+ });
161
+ }
162
+ }
163
+
164
+ $(document).ready(function($) {
165
+ setTimeout (function() {ai_process_lists ();}, 5);
166
+ });
167
+ });
includes/js/ai-lists.min.js CHANGED
@@ -1,7 +1,7 @@
1
- jQuery(function($){function getHostName(url){var match=url.match(/:\/\/(.[^/:]+)/i);if(match!=null&&match.length>1&&typeof match[1]==="string"&&match[1].length>0)return match[1];else return null}ai_process_lists=function(){var ai_debug=typeof ai_debugging!=="undefined";var cookies=document.cookie.split(";");var referrer=document.referrer;cookies.forEach(function(cookie,index){cookies[index]=cookie.trim()});if(referrer!="")referrer=getHostName(referrer);var ai_list_blocks=$("div.ai-list-data");if(ai_list_blocks.length)ai_list_blocks.each(function(){var enable_block=
2
- true;var found=false;var referer_list=$(this).attr("referer-list");if(typeof referer_list!="undefined"){var referer_list_array=atob(referer_list).split(",");var referers_list_type=$(this).attr("referer-list-type");if(ai_debug)console.log("");if(ai_debug)console.log("AI LISTS referer: ",referrer);if(ai_debug)console.log("AI LISTS referer list:",atob(referer_list),referers_list_type);$.each(referer_list_array,function(index,list_referer){if(list_referer=="")return true;if(list_referer=="#"){if(referrer==
3
- ""){found=true;return false}}else if(list_referer==referrer){found=true;return false}});switch(referers_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block)}if(enable_block){var parameter_list=$(this).attr("parameter-list");if(typeof parameter_list!="undefined"){var parameter_list_array=atob(parameter_list).split(",");var parameter_list_type=
4
- $(this).attr("parameter-list-type");if(ai_debug)console.log("");if(ai_debug)console.log("AI LISTS cookies: ",cookies);if(ai_debug)console.log("AI LISTS parameter list:",atob(parameter_list),parameter_list_type);var found=false;$.each(parameter_list_array,function(index,list_parameter){if(list_parameter.indexOf("=")!=-1){if(cookies.indexOf(list_parameter)!=-1){found=true;return false}}else cookies.forEach(function(cookie){var cookie_data=cookie.split("=");if(list_parameter==cookie_data[0]){found=
5
- true;return false}})});switch(parameter_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block)}}$(this).css({"visibility":"","position":"","width":"","height":"","z-index":""}).removeClass("ai-list-data");var block_wrapping_div=$(this).closest("div.ai-list-block");block_wrapping_div.css({"visibility":"","position":"","z-index":""}).removeClass("ai-list-block");
6
- block_wrapping_div.find(".ai-debug-name.ai-list-info").text(referrer);block_wrapping_div.find(".ai-debug-name.ai-list-status").text(enable_block?"VISIBLE":"HIDDEN");if(!enable_block){$(this).hide();block_wrapping_div.removeAttr("data-ai")}else if(typeof $(this).data("code")!="undefined"){var block_code=atob($(this).data("code"));$(this).append(block_code);if(!ai_debug)$(this).attr("data-code","");if(typeof aiLazyLoading=="function")$("div.ai-lazy",this).each(function(index,element){aiLazyLoading({lazyClass:"ai-lazy",
7
- lazyElement:this.element})})}})};$(document).ready(function($){setTimeout(function(){ai_process_lists()},5)})});
1
+ jQuery(function($){function b64e(str){return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,function toSolidBytes(match,p1){return String.fromCharCode("0x"+p1)}))}function b64d(str){return decodeURIComponent(atob(str).split("").map(function(c){return"%"+("00"+c.charCodeAt(0).toString(16)).slice(-2)}).join(""))}function getHostName(url){var match=url.match(/:\/\/(.[^/:]+)/i);if(match!=null&&match.length>1&&typeof match[1]==="string"&&match[1].length>0)return match[1];else return null}ai_process_lists=
2
+ function(){var ai_debug=typeof ai_debugging!=="undefined";var cookies=document.cookie.split(";");var referrer=document.referrer;cookies.forEach(function(cookie,index){cookies[index]=cookie.trim()});if(referrer!="")referrer=getHostName(referrer);var ai_list_blocks=$("div.ai-list-data");if(ai_list_blocks.length)ai_list_blocks.each(function(){var enable_block=true;var found=false;var referer_list=$(this).attr("referer-list");if(typeof referer_list!="undefined"){var referer_list_array=b64d(referer_list).split(",");
3
+ var referers_list_type=$(this).attr("referer-list-type");if(ai_debug)console.log("");if(ai_debug)console.log("AI LISTS referer: ",referrer);if(ai_debug)console.log("AI LISTS referer list:",b64d(referer_list),referers_list_type);$.each(referer_list_array,function(index,list_referer){if(list_referer=="")return true;if(list_referer=="#"){if(referrer==""){found=true;return false}}else if(list_referer==referrer){found=true;return false}});switch(referers_list_type){case "B":if(found)enable_block=false;
4
+ break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",found);if(ai_debug)console.log("AI LISTS list pass",enable_block)}if(enable_block){var parameter_list=$(this).attr("parameter-list");if(typeof parameter_list!="undefined"){var parameter_list_array=b64d(parameter_list).split(",");var parameter_list_type=$(this).attr("parameter-list-type");if(ai_debug)console.log("");if(ai_debug)console.log("AI LISTS cookies: ",cookies);if(ai_debug)console.log("AI LISTS parameter list:",
5
+ b64d(parameter_list),parameter_list_type);var found=false;$.each(parameter_list_array,function(index,list_parameter){if(list_parameter.indexOf("=")!=-1){if(cookies.indexOf(list_parameter)!=-1){found=true;return false}}else cookies.forEach(function(cookie){var cookie_data=cookie.split("=");if(list_parameter==cookie_data[0]){found=true;return false}})});switch(parameter_list_type){case "B":if(found)enable_block=false;break;case "W":if(!found)enable_block=false;break}if(ai_debug)console.log("AI LISTS list found",
6
+ found);if(ai_debug)console.log("AI LISTS list pass",enable_block)}}$(this).css({"visibility":"","position":"","width":"","height":"","z-index":""}).removeClass("ai-list-data");var block_wrapping_div=$(this).closest("div.ai-list-block");block_wrapping_div.removeClass("ai-list-block");block_wrapping_div.find(".ai-debug-name.ai-list-info").text(referrer);block_wrapping_div.find(".ai-debug-name.ai-list-status").text(enable_block?"VISIBLE":"HIDDEN");if(!enable_block){$(this).hide();block_wrapping_div.removeAttr("data-ai").hide()}else{block_wrapping_div.css({"visibility":""});
7
+ if(block_wrapping_div.hasClass("ai-remove-position"))block_wrapping_div.css({"position":""});if(typeof $(this).data("code")!="undefined"){var block_code=b64d($(this).data("code"));$(this).append(block_code);if(!ai_debug)$(this).attr("data-code","");if(typeof aiLazyLoading=="function")$("div.ai-lazy",this).each(function(index,element){aiLazyLoading({lazyClass:"ai-lazy",lazyElement:this.element})})}}})};$(document).ready(function($){setTimeout(function(){ai_process_lists()},5)})});
includes/js/ai-rotate.js CHANGED
@@ -1,191 +1,240 @@
1
- jQuery (function ($) {
2
-
3
- ai_process_rotation = function (rotation_block) {
4
- var ai_debug = typeof ai_debugging !== 'undefined';
5
- var rotate_options = $(".ai-rotate-option", rotation_block);
6
-
7
- if (rotate_options.length == 0) return;
8
-
9
- if (ai_debug) console.log ('');
10
- if (ai_debug) console.log ('AI ROTATE process rotation:', rotate_options.length, 'options');
11
-
12
- rotate_options.hide ();
13
-
14
- // rotate_options.css ({"visibility": "hidden"});
15
-
16
- // rotate_options.animate ({
17
- // opacity: 0,
18
- // }, 500, function() {
19
- // });
20
-
21
- if (typeof $(rotation_block).data ('next') == 'undefined') {
22
- var thresholds_data = $(rotation_block).data ('shares');
23
- if (typeof thresholds_data === 'string') {
24
- var thresholds = JSON.parse (atob (thresholds_data));
25
- var random_threshold = Math.round (Math.random () * 100);
26
- for (var index = 0; index < thresholds.length; index ++) {
27
- var random_index = index;
28
- if (random_threshold <= thresholds [index]) break;
29
- }
30
- } else {
31
- var random_index = Math.floor (Math.random () * rotate_options.length);
32
- var d = new Date();
33
- var n = d.getMilliseconds();
34
- if (n % 2) random_index = rotate_options.length - random_index - 1;
35
- }
36
- } else {
37
- var random_index = parseInt ($(rotation_block).attr ('data-next'));
38
-
39
- if (ai_debug) console.log ('AI TIMED ROTATE next index: ', random_index);
40
- }
41
-
42
- var option = $(rotate_options [random_index]);
43
- var option_time_text = '';
44
-
45
- if (typeof option.data ('time') != 'undefined') {
46
- var rotation_time = atob (option.data ('time'));
47
-
48
- if (ai_debug) {
49
- var option_name = atob (option.data ('name'));
50
- console.log ('AI TIMED ROTATE index:', random_index, 'name:', option_name, 'time:', rotation_time);
51
- }
52
-
53
- if (rotation_time == 0 && rotate_options.length > 1) {
54
- var next_random_index = random_index;
55
- do {
56
- next_random_index++;
57
- if (next_random_index >= rotate_options.length) next_random_index = 0;
58
-
59
- var next_option = $(rotate_options [next_random_index]);
60
- if (typeof next_option.data ('time') == 'undefined') {
61
- random_index = next_random_index;
62
- option = $(rotate_options [random_index]);
63
- rotation_time = 0;
64
-
65
- if (ai_debug) console.log ('AI TIMED ROTATE next option has no time: ', next_random_index);
66
-
67
- break;
68
- }
69
- var next_rotation_time = atob (next_option.data ('time'));
70
-
71
- if (ai_debug) console.log ('AI TIMED ROTATE check:', next_random_index, 'time:', next_rotation_time);
72
- } while (next_rotation_time == 0 && next_random_index != random_index);
73
-
74
- if (rotation_time != 0) {
75
- random_index = next_random_index;
76
- option = $(rotate_options [random_index]);
77
- rotation_time = atob (option.data ('time'));
78
- }
79
-
80
- if (ai_debug) console.log ('AI TIMED ROTATE index:', random_index, 'time:', rotation_time);
81
- }
82
-
83
- if (rotation_time > 0) {
84
- var next_random_index = random_index + 1;
85
- if (next_random_index >= rotate_options.length) next_random_index = 0;
86
-
87
- if (typeof $(rotation_block).data ('info') != 'undefined') {
88
- var block_info = JSON.parse (atob ($(rotation_block).data ('info')));
89
- var rotation_id = block_info [0];
90
-
91
- $(rotation_block).attr ('data-next', next_random_index);
92
- setTimeout (function() {ai_process_rotation ($("div.ai-rotate.ai-" + rotation_id));}, rotation_time * 1000);
93
- option_time_text = ' (' + rotation_time + ' s)';
94
- }
95
- }
96
- } else {
97
- // Remove unused options
98
- if (!ai_debug) {
99
- rotate_options.each (function (index) {
100
- if (index != random_index) $(this).remove ();
101
- });
102
- }
103
-
104
- if (ai_debug) console.log ('AI ROTATE no time');
105
- if (ai_debug) console.log ('AI ROTATE index:', random_index);
106
- }
107
-
108
-
109
- option.css ({"display": "", "visibility": "", "position": "", "width": "", "height": "", "top": "", "left": ""}).removeClass ('ai-rotate-hidden').removeClass ('ai-rotate-hidden-2');
110
- // option.css ({"visibility": "", "position": "", "width": "", "height": "", "top": "", "left": ""}).removeClass ('ai-rotate-hidden').removeClass ('ai-rotate-hidden-2');
111
- // $(rotation_block).css ({"position": ""}).removeClass ('ai-rotate');
112
- $(rotation_block).css ({"position": ""});
113
-
114
- // option.css ({"visibility": "visible"});
115
-
116
- // option.stop ().animate ({
117
- // opacity: 1,
118
- // }, 500, function() {
119
- // });
120
-
121
- if (typeof option.data ('code') != 'undefined') {
122
- rotate_options.empty();
123
-
124
- var option_code = atob (option.data ('code'));
125
- option.append (option_code);
126
- }
127
-
128
- var option_name = '';
129
- var debug_block_frame = $(rotation_block).closest ('.ai-debug-block');
130
- if (typeof debug_block_frame != "undefined") {
131
- var option_name = atob (option.data ('name'));
132
- var name_tag = debug_block_frame.find ('kbd.ai-option-name');
133
- // Do not set option name in nested debug blocks
134
- var nested_debug_block = debug_block_frame.find ('.ai-debug-block');
135
- if (typeof nested_debug_block != 'undefined') {
136
- var name_tag2 = nested_debug_block.find ('kbd.ai-option-name');
137
- name_tag = name_tag.slice (0, name_tag.length - name_tag2.length);
138
- }
139
- if (typeof name_tag != 'undefined') {
140
- var separator = name_tag.first ().data ('separator');
141
- if (typeof separator == 'undefined') separator = '';
142
- name_tag.html (separator + option_name + option_time_text);
143
- }
144
- }
145
-
146
- var tracking_updated = false;
147
- var adb_show_wrapping_div = $(rotation_block).closest ('.ai-adb-show');
148
- if (typeof adb_show_wrapping_div != "undefined") {
149
- if (typeof adb_show_wrapping_div.data ("ai-tracking") != "undefined") {
150
- var data = JSON.parse (atob (adb_show_wrapping_div.data ("ai-tracking")));
151
- if (typeof data !== "undefined" && data.constructor === Array) {
152
- data [1] = random_index + 1;
153
- data [3] = option_name;
154
- adb_show_wrapping_div.data ("ai-tracking", btoa (JSON.stringify (data)))
155
- tracking_updated = true;
156
- }
157
- }
158
- }
159
-
160
- if (!tracking_updated) {
161
- var wrapping_div = $(rotation_block).closest ('div[data-ai]');
162
- if (typeof wrapping_div.data ("ai") != "undefined") {
163
- var data = JSON.parse (atob (wrapping_div.data ("ai")));
164
-
165
- if (typeof data !== "undefined" && data.constructor === Array) {
166
- data [1] = random_index + 1;
167
- data [3] = option_name;
168
- wrapping_div.data ("ai", btoa (JSON.stringify (data)))
169
- }
170
- }
171
- }
172
- }
173
-
174
- function ai_process_rotations () {
175
- $("div.ai-rotate").each (function (index, element) {
176
- ai_process_rotation (this);
177
- });
178
- }
179
-
180
- ai_process_rotations_in_element = function (el) {
181
- $("div.ai-rotate", el).each (function (index, element) {
182
- ai_process_rotation (this);
183
- });
184
- }
185
-
186
- $(document).ready(function($) {
187
- setTimeout (function() {ai_process_rotations ();}, 10);
188
- });
189
-
190
- });
191
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery (function ($) {
2
+
3
+ function b64e (str) {
4
+ // first we use encodeURIComponent to get percent-encoded UTF-8,
5
+ // then we convert the percent encodings into raw bytes which
6
+ // can be fed into btoa.
7
+ return btoa(encodeURIComponent (str).replace (/%([0-9A-F]{2})/g,
8
+ function toSolidBytes (match, p1) {
9
+ return String.fromCharCode ('0x' + p1);
10
+ }));
11
+ }
12
+
13
+ function b64d (str) {
14
+ // Going backwards: from bytestream, to percent-encoding, to original string.
15
+ return decodeURIComponent (atob (str).split ('').map (function(c) {
16
+ return '%' + ('00' + c.charCodeAt (0).toString (16)).slice (-2);
17
+ }).join (''));
18
+ }
19
+
20
+ ai_process_rotation = function (rotation_block) {
21
+ var ai_debug = typeof ai_debugging !== 'undefined';
22
+
23
+ if (ai_debug) console.log ('');
24
+
25
+ if (typeof rotation_block.length == 'number') {
26
+ if (ai_debug) console.log ('AI ROTATE process rotation:', rotation_block.length, 'rotation blocks');
27
+ for (var index = 0; index < rotation_block.length; index ++) {
28
+ if (ai_debug) console.log ('AI ROTATE process rotation block index:', index);
29
+
30
+ if (index == 0) ai_process_single_rotation (rotation_block [index], true); else ai_process_single_rotation (rotation_block [index], false);
31
+ }
32
+ } else {
33
+ if (ai_debug) console.log ('AI ROTATE process rotation: 1 rotation block');
34
+
35
+ ai_process_single_rotation (rotation_block, true);
36
+ }
37
+ }
38
+
39
+ ai_process_single_rotation = function (rotation_block, trigger_rotation) {
40
+ var ai_debug = typeof ai_debugging !== 'undefined';
41
+ var rotate_options = $(".ai-rotate-option", rotation_block);
42
+
43
+ if (rotate_options.length == 0) return;
44
+
45
+ if (ai_debug) console.log ('AI ROTATE process single rotation:', rotate_options.length, 'options');
46
+
47
+ rotate_options.hide ();
48
+
49
+ // rotate_options.css ({"visibility": "hidden"});
50
+
51
+ // rotate_options.animate ({
52
+ // opacity: 0,
53
+ // }, 500, function() {
54
+ // });
55
+
56
+ if (typeof $(rotation_block).data ('next') == 'undefined') {
57
+ var thresholds_data = $(rotation_block).data ('shares');
58
+ if (typeof thresholds_data === 'string') {
59
+ var thresholds = JSON.parse (atob (thresholds_data));
60
+ var random_threshold = Math.round (Math.random () * 100);
61
+ for (var index = 0; index < thresholds.length; index ++) {
62
+ var random_index = index;
63
+ if (random_threshold <= thresholds [index]) break;
64
+ }
65
+ } else {
66
+ var random_index = Math.floor (Math.random () * rotate_options.length);
67
+ var d = new Date();
68
+ var n = d.getMilliseconds();
69
+ if (n % 2) random_index = rotate_options.length - random_index - 1;
70
+ }
71
+ } else {
72
+ var random_index = parseInt ($(rotation_block).attr ('data-next'));
73
+
74
+ if (ai_debug) console.log ('AI TIMED ROTATE next index:', random_index);
75
+ }
76
+
77
+ var option = $(rotate_options [random_index]);
78
+ var option_time_text = '';
79
+
80
+ if (typeof option.data ('time') != 'undefined') {
81
+ var rotation_time = atob (option.data ('time'));
82
+
83
+ if (ai_debug) {
84
+ // var option_name = atob (option.data ('name'));
85
+ var option_name = b64d (option.data ('name'));
86
+ console.log ('AI TIMED ROTATE index:', random_index, 'name:', option_name, 'time:', rotation_time);
87
+ }
88
+
89
+ if (rotation_time == 0 && rotate_options.length > 1) {
90
+ var next_random_index = random_index;
91
+ do {
92
+ next_random_index++;
93
+ if (next_random_index >= rotate_options.length) next_random_index = 0;
94
+
95
+ var next_option = $(rotate_options [next_random_index]);
96
+ if (typeof next_option.data ('time') == 'undefined') {
97
+ random_index = next_random_index;
98
+ option = $(rotate_options [random_index]);
99
+ rotation_time = 0;
100
+
101
+ if (ai_debug) console.log ('AI TIMED ROTATE next option has no time: ', next_random_index);
102
+
103
+ break;
104
+ }
105
+ var next_rotation_time = atob (next_option.data ('time'));
106
+
107
+ if (ai_debug) console.log ('AI TIMED ROTATE check:', next_random_index, 'time:', next_rotation_time);
108
+ } while (next_rotation_time == 0 && next_random_index != random_index);
109
+
110
+ if (rotation_time != 0) {
111
+ random_index = next_random_index;
112
+ option = $(rotate_options [random_index]);
113
+ rotation_time = atob (option.data ('time'));
114
+ }
115
+
116
+ if (ai_debug) console.log ('AI TIMED ROTATE index:', random_index, 'time:', rotation_time);
117
+ }
118
+
119
+ if (rotation_time > 0) {
120
+ var next_random_index = random_index + 1;
121
+ if (next_random_index >= rotate_options.length) next_random_index = 0;
122
+
123
+ if (typeof $(rotation_block).data ('info') != 'undefined') {
124
+ var block_info = JSON.parse (atob ($(rotation_block).data ('info')));
125
+ var rotation_id = block_info [0];
126
+
127
+ $(rotation_block).attr ('data-next', next_random_index);
128
+ if (trigger_rotation) {
129
+ setTimeout (function() {ai_process_rotation ($("div.ai-rotate.ai-" + rotation_id));}, rotation_time * 1000);
130
+ // setTimeout (function() {ai_process_rotation ($(rotation_block));}, rotation_time * 1000);
131
+ }
132
+ option_time_text = ' (' + rotation_time + ' s)';
133
+ }
134
+ }
135
+ } else {
136
+ // Remove unused options
137
+ if (!ai_debug) {
138
+ rotate_options.each (function (index) {
139
+ if (index != random_index) $(this).remove ();
140
+ });
141
+ }
142
+
143
+ if (ai_debug) console.log ('AI ROTATE no time');
144
+ if (ai_debug) console.log ('AI ROTATE index:', random_index);
145
+ }
146
+
147
+
148
+ option.css ({"display": "", "visibility": "", "position": "", "width": "", "height": "", "top": "", "left": ""}).removeClass ('ai-rotate-hidden').removeClass ('ai-rotate-hidden-2');
149
+ // option.css ({"visibility": "", "position": "", "width": "", "height": "", "top": "", "left": ""}).removeClass ('ai-rotate-hidden').removeClass ('ai-rotate-hidden-2');
150
+ // $(rotation_block).css ({"position": ""}).removeClass ('ai-rotate');
151
+ $(rotation_block).css ({"position": ""});
152
+
153
+ // option.css ({"visibility": "visible"});
154
+
155
+ // option.stop ().animate ({
156
+ // opacity: 1,
157
+ // }, 500, function() {
158
+ // });
159
+
160
+ if (typeof option.data ('code') != 'undefined') {
161
+ rotate_options.empty();
162
+
163
+ // var option_code = atob (option.data ('code'));
164
+ var option_code = b64d (option.data ('code'));
165
+ option.append (option_code);
166
+ }
167
+
168
+ var option_name = '';
169
+ var debug_block_frame = $(rotation_block).closest ('.ai-debug-block');
170
+ // if (typeof debug_block_frame != "undefined") {
171
+ if (debug_block_frame.length != 0) {
172
+ // var option_name = atob (option.data ('name'));
173
+ var option_name = b64d (option.data ('name'));
174
+ var name_tag = debug_block_frame.find ('kbd.ai-option-name');
175
+ // Do not set option name in nested debug blocks
176
+ var nested_debug_block = debug_block_frame.find ('.ai-debug-block');
177
+ if (typeof nested_debug_block != 'undefined') {
178
+ var name_tag2 = nested_debug_block.find ('kbd.ai-option-name');
179
+ name_tag = name_tag.slice (0, name_tag.length - name_tag2.length);
180
+ }
181
+ if (typeof name_tag != 'undefined') {
182
+ var separator = name_tag.first ().data ('separator');
183
+ if (typeof separator == 'undefined') separator = '';
184
+ name_tag.html (separator + option_name + option_time_text);
185
+ }
186
+ }
187
+
188
+ var tracking_updated = false;
189
+ var adb_show_wrapping_div = $(rotation_block).closest ('.ai-adb-show');
190
+ // if (typeof adb_show_wrapping_div != "undefined") {
191
+ if (adb_show_wrapping_div.length != 0) {
192
+ // if (typeof adb_show_wrapping_div.data ("ai-tracking") != "undefined") {
193
+
194
+ // if (ai_debug) console.log ('adb_show_wrapping_div.data ("ai-tracking")', adb_show_wrapping_div.data ("ai-tracking"));
195
+
196
+ if (adb_show_wrapping_div.data ("ai-tracking")) {
197
+ var data = JSON.parse (atob (adb_show_wrapping_div.data ("ai-tracking")));
198
+ if (typeof data !== "undefined" && data.constructor === Array) {
199
+ data [1] = random_index + 1;
200
+ data [3] = option_name;
201
+ // adb_show_wrapping_div.data ("ai-tracking", btoa (JSON.stringify (data)))
202
+ adb_show_wrapping_div.data ("ai-tracking", b64e (JSON.stringify (data)))
203
+ tracking_updated = true;
204
+ }
205
+ }
206
+ }
207
+
208
+ if (!tracking_updated) {
209
+ var wrapping_div = $(rotation_block).closest ('div[data-ai]');
210
+ if (typeof wrapping_div.data ("ai") != "undefined") {
211
+ var data = JSON.parse (atob (wrapping_div.data ("ai")));
212
+
213
+ if (typeof data !== "undefined" && data.constructor === Array) {
214
+ data [1] = random_index + 1;
215
+ data [3] = option_name;
216
+ // wrapping_div.data ("ai", btoa (JSON.stringify (data)))
217
+ wrapping_div.data ("ai", b64e (JSON.stringify (data)))
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ function ai_process_rotations () {
224
+ $("div.ai-rotate").each (function (index, element) {
225
+ ai_process_rotation (this);
226
+ });
227
+ }
228
+
229
+ ai_process_rotations_in_element = function (el) {
230
+ $("div.ai-rotate", el).each (function (index, element) {
231
+ ai_process_rotation (this);
232
+ });
233
+ }
234
+
235
+ $(document).ready(function($) {
236
+ setTimeout (function() {ai_process_rotations ();}, 10);
237
+ });
238
+
239
+ });
240
+
includes/js/ai-rotate.min.js CHANGED
@@ -1,10 +1,12 @@
1
- jQuery(function($){ai_process_rotation=function(rotation_block){var ai_debug=typeof ai_debugging!=="undefined";var rotate_options=$(".ai-rotate-option",rotation_block);if(rotate_options.length==0)return;if(ai_debug)console.log("");if(ai_debug)console.log("AI ROTATE process rotation:",rotate_options.length,"options");rotate_options.hide();if(typeof $(rotation_block).data("next")=="undefined"){var thresholds_data=$(rotation_block).data("shares");if(typeof thresholds_data==="string"){var thresholds=
2
- JSON.parse(atob(thresholds_data));var random_threshold=Math.round(Math.random()*100);for(var index=0;index<thresholds.length;index++){var random_index=index;if(random_threshold<=thresholds[index])break}}else{var random_index=Math.floor(Math.random()*rotate_options.length);var d=new Date;var n=d.getMilliseconds();if(n%2)random_index=rotate_options.length-random_index-1}}else{var random_index=parseInt($(rotation_block).attr("data-next"));if(ai_debug)console.log("AI TIMED ROTATE next index: ",random_index)}var option=
3
- $(rotate_options[random_index]);var option_time_text="";if(typeof option.data("time")!="undefined"){var rotation_time=atob(option.data("time"));if(ai_debug){var option_name=atob(option.data("name"));console.log("AI TIMED ROTATE index:",random_index,"name:",option_name,"time:",rotation_time)}if(rotation_time==0&&rotate_options.length>1){var next_random_index=random_index;do{next_random_index++;if(next_random_index>=rotate_options.length)next_random_index=0;var next_option=$(rotate_options[next_random_index]);
4
- if(typeof next_option.data("time")=="undefined"){random_index=next_random_index;option=$(rotate_options[random_index]);rotation_time=0;if(ai_debug)console.log("AI TIMED ROTATE next option has no time: ",next_random_index);break}var next_rotation_time=atob(next_option.data("time"));if(ai_debug)console.log("AI TIMED ROTATE check:",next_random_index,"time:",next_rotation_time)}while(next_rotation_time==0&&next_random_index!=random_index);if(rotation_time!=0){random_index=next_random_index;option=$(rotate_options[random_index]);
5
- rotation_time=atob(option.data("time"))}if(ai_debug)console.log("AI TIMED ROTATE index:",random_index,"time:",rotation_time)}if(rotation_time>0){var next_random_index=random_index+1;if(next_random_index>=rotate_options.length)next_random_index=0;if(typeof $(rotation_block).data("info")!="undefined"){var block_info=JSON.parse(atob($(rotation_block).data("info")));var rotation_id=block_info[0];$(rotation_block).attr("data-next",next_random_index);setTimeout(function(){ai_process_rotation($("div.ai-rotate.ai-"+
6
- rotation_id))},rotation_time*1E3);option_time_text=" ("+rotation_time+" s)"}}}else{if(!ai_debug)rotate_options.each(function(index){if(index!=random_index)$(this).remove()});if(ai_debug)console.log("AI ROTATE no time");if(ai_debug)console.log("AI ROTATE index:",random_index)}option.css({"display":"","visibility":"","position":"","width":"","height":"","top":"","left":""}).removeClass("ai-rotate-hidden").removeClass("ai-rotate-hidden-2");$(rotation_block).css({"position":""});if(typeof option.data("code")!=
7
- "undefined"){rotate_options.empty();var option_code=atob(option.data("code"));option.append(option_code)}var option_name="";var debug_block_frame=$(rotation_block).closest(".ai-debug-block");if(typeof debug_block_frame!="undefined"){var option_name=atob(option.data("name"));var name_tag=debug_block_frame.find("kbd.ai-option-name");var nested_debug_block=debug_block_frame.find(".ai-debug-block");if(typeof nested_debug_block!="undefined"){var name_tag2=nested_debug_block.find("kbd.ai-option-name");
8
- name_tag=name_tag.slice(0,name_tag.length-name_tag2.length)}if(typeof name_tag!="undefined"){var separator=name_tag.first().data("separator");if(typeof separator=="undefined")separator="";name_tag.html(separator+option_name+option_time_text)}}var tracking_updated=false;var adb_show_wrapping_div=$(rotation_block).closest(".ai-adb-show");if(typeof adb_show_wrapping_div!="undefined")if(typeof adb_show_wrapping_div.data("ai-tracking")!="undefined"){var data=JSON.parse(atob(adb_show_wrapping_div.data("ai-tracking")));
9
- if(typeof data!=="undefined"&&data.constructor===Array){data[1]=random_index+1;data[3]=option_name;adb_show_wrapping_div.data("ai-tracking",btoa(JSON.stringify(data)));tracking_updated=true}}if(!tracking_updated){var wrapping_div=$(rotation_block).closest("div[data-ai]");if(typeof wrapping_div.data("ai")!="undefined"){var data=JSON.parse(atob(wrapping_div.data("ai")));if(typeof data!=="undefined"&&data.constructor===Array){data[1]=random_index+1;data[3]=option_name;wrapping_div.data("ai",btoa(JSON.stringify(data)))}}}};
10
- function ai_process_rotations(){$("div.ai-rotate").each(function(index,element){ai_process_rotation(this)})}ai_process_rotations_in_element=function(el){$("div.ai-rotate",el).each(function(index,element){ai_process_rotation(this)})};$(document).ready(function($){setTimeout(function(){ai_process_rotations()},10)})});
 
 
1
+ jQuery(function($){function b64e(str){return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,function toSolidBytes(match,p1){return String.fromCharCode("0x"+p1)}))}function b64d(str){return decodeURIComponent(atob(str).split("").map(function(c){return"%"+("00"+c.charCodeAt(0).toString(16)).slice(-2)}).join(""))}ai_process_rotation=function(rotation_block){var ai_debug=typeof ai_debugging!=="undefined";if(ai_debug)console.log("");if(typeof rotation_block.length=="number"){if(ai_debug)console.log("AI ROTATE process rotation:",
2
+ rotation_block.length,"rotation blocks");for(var index=0;index<rotation_block.length;index++){if(ai_debug)console.log("AI ROTATE process rotation block index:",index);if(index==0)ai_process_single_rotation(rotation_block[index],true);else ai_process_single_rotation(rotation_block[index],false)}}else{if(ai_debug)console.log("AI ROTATE process rotation: 1 rotation block");ai_process_single_rotation(rotation_block,true)}};ai_process_single_rotation=function(rotation_block,trigger_rotation){var ai_debug=
3
+ typeof ai_debugging!=="undefined";var rotate_options=$(".ai-rotate-option",rotation_block);if(rotate_options.length==0)return;if(ai_debug)console.log("AI ROTATE process single rotation:",rotate_options.length,"options");rotate_options.hide();if(typeof $(rotation_block).data("next")=="undefined"){var thresholds_data=$(rotation_block).data("shares");if(typeof thresholds_data==="string"){var thresholds=JSON.parse(atob(thresholds_data));var random_threshold=Math.round(Math.random()*100);for(var index=
4
+ 0;index<thresholds.length;index++){var random_index=index;if(random_threshold<=thresholds[index])break}}else{var random_index=Math.floor(Math.random()*rotate_options.length);var d=new Date;var n=d.getMilliseconds();if(n%2)random_index=rotate_options.length-random_index-1}}else{var random_index=parseInt($(rotation_block).attr("data-next"));if(ai_debug)console.log("AI TIMED ROTATE next index:",random_index)}var option=$(rotate_options[random_index]);var option_time_text="";if(typeof option.data("time")!=
5
+ "undefined"){var rotation_time=atob(option.data("time"));if(ai_debug){var option_name=b64d(option.data("name"));console.log("AI TIMED ROTATE index:",random_index,"name:",option_name,"time:",rotation_time)}if(rotation_time==0&&rotate_options.length>1){var next_random_index=random_index;do{next_random_index++;if(next_random_index>=rotate_options.length)next_random_index=0;var next_option=$(rotate_options[next_random_index]);if(typeof next_option.data("time")=="undefined"){random_index=next_random_index;
6
+ option=$(rotate_options[random_index]);rotation_time=0;if(ai_debug)console.log("AI TIMED ROTATE next option has no time: ",next_random_index);break}var next_rotation_time=atob(next_option.data("time"));if(ai_debug)console.log("AI TIMED ROTATE check:",next_random_index,"time:",next_rotation_time)}while(next_rotation_time==0&&next_random_index!=random_index);if(rotation_time!=0){random_index=next_random_index;option=$(rotate_options[random_index]);rotation_time=atob(option.data("time"))}if(ai_debug)console.log("AI TIMED ROTATE index:",
7
+ random_index,"time:",rotation_time)}if(rotation_time>0){var next_random_index=random_index+1;if(next_random_index>=rotate_options.length)next_random_index=0;if(typeof $(rotation_block).data("info")!="undefined"){var block_info=JSON.parse(atob($(rotation_block).data("info")));var rotation_id=block_info[0];$(rotation_block).attr("data-next",next_random_index);if(trigger_rotation)setTimeout(function(){ai_process_rotation($("div.ai-rotate.ai-"+rotation_id))},rotation_time*1E3);option_time_text=" ("+rotation_time+
8
+ " s)"}}}else{if(!ai_debug)rotate_options.each(function(index){if(index!=random_index)$(this).remove()});if(ai_debug)console.log("AI ROTATE no time");if(ai_debug)console.log("AI ROTATE index:",random_index)}option.css({"display":"","visibility":"","position":"","width":"","height":"","top":"","left":""}).removeClass("ai-rotate-hidden").removeClass("ai-rotate-hidden-2");$(rotation_block).css({"position":""});if(typeof option.data("code")!="undefined"){rotate_options.empty();var option_code=b64d(option.data("code"));
9
+ option.append(option_code)}var option_name="";var debug_block_frame=$(rotation_block).closest(".ai-debug-block");if(debug_block_frame.length!=0){var option_name=b64d(option.data("name"));var name_tag=debug_block_frame.find("kbd.ai-option-name");var nested_debug_block=debug_block_frame.find(".ai-debug-block");if(typeof nested_debug_block!="undefined"){var name_tag2=nested_debug_block.find("kbd.ai-option-name");name_tag=name_tag.slice(0,name_tag.length-name_tag2.length)}if(typeof name_tag!="undefined"){var separator=
10
+ name_tag.first().data("separator");if(typeof separator=="undefined")separator="";name_tag.html(separator+option_name+option_time_text)}}var tracking_updated=false;var adb_show_wrapping_div=$(rotation_block).closest(".ai-adb-show");if(adb_show_wrapping_div.length!=0)if(adb_show_wrapping_div.data("ai-tracking")){var data=JSON.parse(atob(adb_show_wrapping_div.data("ai-tracking")));if(typeof data!=="undefined"&&data.constructor===Array){data[1]=random_index+1;data[3]=option_name;adb_show_wrapping_div.data("ai-tracking",
11
+ b64e(JSON.stringify(data)));tracking_updated=true}}if(!tracking_updated){var wrapping_div=$(rotation_block).closest("div[data-ai]");if(typeof wrapping_div.data("ai")!="undefined"){var data=JSON.parse(atob(wrapping_div.data("ai")));if(typeof data!=="undefined"&&data.constructor===Array){data[1]=random_index+1;data[3]=option_name;wrapping_div.data("ai",b64e(JSON.stringify(data)))}}}};function ai_process_rotations(){$("div.ai-rotate").each(function(index,element){ai_process_rotation(this)})}ai_process_rotations_in_element=
12
+ function(el){$("div.ai-rotate",el).each(function(index,element){ai_process_rotation(this)})};$(document).ready(function($){setTimeout(function(){ai_process_rotations()},10)})});
includes/js/ai-sidebar.js CHANGED
@@ -1,59 +1,59 @@
1
- jQuery(document).ready(function($) {
2
- var sticky_widget_mode = AI_FUNC_GET_STICKY_WIDGET_MODE;
3
- var sticky_widget_margin = AI_FUNC_GET_STICKY_WIDGET_MARGIN;
4
- var document_width = $(document).width();
5
- var ai_debug = typeof ai_debugging !== 'undefined';
6
-
7
- $(".ai-sticky-widget").each (function () {
8
- var widget = $(this);
9
- var widget_width = widget.width();
10
-
11
- if (ai_debug) console.log ('');
12
- if (ai_debug) console.log ("WIDGET:", widget.width (), widget.prop ("tagName"), widget.attr ("id"));
13
-
14
- var already_sticky_js = false;
15
- var sidebar = widget.parent ();
16
- while (sidebar.prop ("tagName") != "BODY") {
17
-
18
- if (sidebar.hasClass ('theiaStickySidebar')) {
19
- already_sticky_js = true;
20
- break;
21
- }
22
-
23
- if (ai_debug) console.log ("SIDEBAR:", sidebar.width (), sidebar.prop ("tagName"), sidebar.attr ("id"));
24
-
25
- var parent_element = sidebar.parent ();
26
- var parent_element_width = parent_element.width();
27
- if (parent_element_width > widget_width * 1.2 || parent_element_width > document_width / 2) break;
28
- sidebar = parent_element;
29
- }
30
- if (already_sticky_js) {
31
- if (ai_debug) console.log ("JS STICKY SIDEBAR ALREADY SET");
32
- return;
33
- }
34
-
35
- var new_sidebar_top = sidebar.offset ().top - widget.offset ().top + sticky_widget_margin;
36
-
37
- if (ai_debug) console.log ("NEW SIDEBAR TOP:", new_sidebar_top);
38
-
39
- if (sticky_widget_mode == 0) {
40
- // CSS
41
- if (sidebar.css ("position") != "sticky" || isNaN (parseInt (sidebar.css ("top"))) || sidebar.css ("top") < new_sidebar_top) {
42
- sidebar.css ("position", "sticky").css ("top", new_sidebar_top);
43
-
44
- if (ai_debug) console.log ("CSS STICKY SIDEBAR, TOP:", new_sidebar_top);
45
- }
46
- else if (ai_debug) console.log ("CSS STICKY SIDEBAR ALREADY SET");
47
- } else {
48
- // Javascript
49
- sidebar.theiaStickySidebar({
50
- additionalMarginTop: new_sidebar_top,
51
- sidebarBehavior: 'stick-to-top',
52
- });
53
-
54
- if (ai_debug) console.log ("JS STICKY SIDEBAR, TOP:", new_sidebar_top);
55
- }
56
- });
57
-
58
- });
59
-
1
+ jQuery(document).ready(function($) {
2
+ var sticky_widget_mode = AI_FUNC_GET_STICKY_WIDGET_MODE;
3
+ var sticky_widget_margin = AI_FUNC_GET_STICKY_WIDGET_MARGIN;
4
+ var document_width = $(document).width();
5
+ var ai_debug = typeof ai_debugging !== 'undefined';
6
+
7
+ $(".ai-sticky-widget").each (function () {
8
+ var widget = $(this);
9
+ var widget_width = widget.width();
10
+
11
+ if (ai_debug) console.log ('');
12
+ if (ai_debug) console.log ("WIDGET:", widget.width (), widget.prop ("tagName"), widget.attr ("id"));
13
+
14
+ var already_sticky_js = false;
15
+ var sidebar = widget.parent ();
16
+ while (sidebar.prop ("tagName") != "BODY") {
17
+
18
+ if (sidebar.hasClass ('theiaStickySidebar')) {
19
+ already_sticky_js = true;
20
+ break;
21
+ }
22
+
23
+ if (ai_debug) console.log ("SIDEBAR:", sidebar.width (), sidebar.prop ("tagName"), sidebar.attr ("id"));
24
+
25
+ var parent_element = sidebar.parent ();
26
+ var parent_element_width = parent_element.width();
27
+ if (parent_element_width > widget_width * 1.2 || parent_element_width > document_width / 2) break;
28
+ sidebar = parent_element;
29
+ }
30
+ if (already_sticky_js) {
31
+ if (ai_debug) console.log ("JS STICKY SIDEBAR ALREADY SET");
32
+ return;
33
+ }
34
+
35
+ var new_sidebar_top = sidebar.offset ().top - widget.offset ().top + sticky_widget_margin;
36
+
37
+ if (ai_debug) console.log ("NEW SIDEBAR TOP:", new_sidebar_top);
38
+
39
+ if (sticky_widget_mode == 0) {
40
+ // CSS
41
+ if (sidebar.css ("position") != "sticky" || isNaN (parseInt (sidebar.css ("top"))) || sidebar.css ("top") < new_sidebar_top) {
42
+ sidebar.css ("position", "sticky").css ("position", "-webkit-sticky").css ("top", new_sidebar_top);
43
+
44
+ if (ai_debug) console.log ("CSS STICKY SIDEBAR, TOP:", new_sidebar_top);
45
+ }
46
+ else if (ai_debug) console.log ("CSS STICKY SIDEBAR ALREADY SET");
47
+ } else {
48
+ // Javascript
49
+ sidebar.theiaStickySidebar({
50
+ additionalMarginTop: new_sidebar_top,
51
+ sidebarBehavior: 'stick-to-top',
52
+ });
53
+
54
+ if (ai_debug) console.log ("JS STICKY SIDEBAR, TOP:", new_sidebar_top);
55
+ }
56
+ });
57
+
58
+ });
59
+
includes/js/ai-sidebar.min.js CHANGED
@@ -1,4 +1,4 @@
1
- jQuery(document).ready(function($){var sticky_widget_mode=AI_FUNC_GET_STICKY_WIDGET_MODE;var sticky_widget_margin=AI_FUNC_GET_STICKY_WIDGET_MARGIN;var document_width=$(document).width();var ai_debug=typeof ai_debugging!=="undefined";$(".ai-sticky-widget").each(function(){var widget=$(this);var widget_width=widget.width();if(ai_debug)console.log("");if(ai_debug)console.log("WIDGET:",widget.width(),widget.prop("tagName"),widget.attr("id"));var already_sticky_js=false;var sidebar=widget.parent();while(sidebar.prop("tagName")!=
2
- "BODY"){if(sidebar.hasClass("theiaStickySidebar")){already_sticky_js=true;break}if(ai_debug)console.log("SIDEBAR:",sidebar.width(),sidebar.prop("tagName"),sidebar.attr("id"));var parent_element=sidebar.parent();var parent_element_width=parent_element.width();if(parent_element_width>widget_width*1.2||parent_element_width>document_width/2)break;sidebar=parent_element}if(already_sticky_js){if(ai_debug)console.log("JS STICKY SIDEBAR ALREADY SET");return}var new_sidebar_top=sidebar.offset().top-widget.offset().top+
3
- sticky_widget_margin;if(ai_debug)console.log("NEW SIDEBAR TOP:",new_sidebar_top);if(sticky_widget_mode==0)if(sidebar.css("position")!="sticky"||isNaN(parseInt(sidebar.css("top")))||sidebar.css("top")<new_sidebar_top){sidebar.css("position","sticky").css("top",new_sidebar_top);if(ai_debug)console.log("CSS STICKY SIDEBAR, TOP:",new_sidebar_top)}else{if(ai_debug)console.log("CSS STICKY SIDEBAR ALREADY SET")}else{sidebar.theiaStickySidebar({additionalMarginTop:new_sidebar_top,sidebarBehavior:"stick-to-top"});
4
- if(ai_debug)console.log("JS STICKY SIDEBAR, TOP:",new_sidebar_top)}})});
1
+ jQuery(document).ready(function($){var sticky_widget_mode=AI_FUNC_GET_STICKY_WIDGET_MODE;var sticky_widget_margin=AI_FUNC_GET_STICKY_WIDGET_MARGIN;var document_width=$(document).width();var ai_debug=typeof ai_debugging!=="undefined";$(".ai-sticky-widget").each(function(){var widget=$(this);var widget_width=widget.width();if(ai_debug)console.log("");if(ai_debug)console.log("WIDGET:",widget.width(),widget.prop("tagName"),widget.attr("id"));var already_sticky_js=false;var sidebar=widget.parent();while(sidebar.prop("tagName")!=
2
+ "BODY"){if(sidebar.hasClass("theiaStickySidebar")){already_sticky_js=true;break}if(ai_debug)console.log("SIDEBAR:",sidebar.width(),sidebar.prop("tagName"),sidebar.attr("id"));var parent_element=sidebar.parent();var parent_element_width=parent_element.width();if(parent_element_width>widget_width*1.2||parent_element_width>document_width/2)break;sidebar=parent_element}if(already_sticky_js){if(ai_debug)console.log("JS STICKY SIDEBAR ALREADY SET");return}var new_sidebar_top=sidebar.offset().top-widget.offset().top+
3
+ sticky_widget_margin;if(ai_debug)console.log("NEW SIDEBAR TOP:",new_sidebar_top);if(sticky_widget_mode==0)if(sidebar.css("position")!="sticky"||isNaN(parseInt(sidebar.css("top")))||sidebar.css("top")<new_sidebar_top){sidebar.css("position","sticky").css("position","-webkit-sticky").css("top",new_sidebar_top);if(ai_debug)console.log("CSS STICKY SIDEBAR, TOP:",new_sidebar_top)}else{if(ai_debug)console.log("CSS STICKY SIDEBAR ALREADY SET")}else{sidebar.theiaStickySidebar({additionalMarginTop:new_sidebar_top,
4
+ sidebarBehavior:"stick-to-top"});if(ai_debug)console.log("JS STICKY SIDEBAR, TOP:",new_sidebar_top)}})});
js/ad-inserter.js CHANGED
@@ -1,4 +1,4 @@
1
- var javascript_version = "2.3.20";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
1
+ var javascript_version = "2.3.21";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
readme.txt CHANGED
@@ -6,7 +6,7 @@ Tags: ads, adsense, header footer code, ad management, sticky fixed widgets, adv
6
  Requires at least: 4.0
7
  Tested up to: 4.9
8
  Requires PHP: 5.6
9
- Stable tag: 2.3.19
10
  License: GPLv3
11
 
12
  Insert and manage ads: Amazon, Google AdSense ads, banner rotation, sticky widget ads, AMP, PHP, HTML, CSS, Javascript, tracking, footer, header code
@@ -679,6 +679,13 @@ AD CODE RIGHT
679
 
680
  == Changelog ==
681
 
 
 
 
 
 
 
 
682
  = 2.3.20 =
683
  - Improved loading of settings
684
  - Fix for content processing in some ajax calls
@@ -805,6 +812,13 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
805
 
806
  == Upgrade Notice ==
807
 
 
 
 
 
 
 
 
808
  = 2.3.20 =
809
  Improved loading of settings;
810
  Fix for content processing in some ajax calls;
6
  Requires at least: 4.0
7
  Tested up to: 4.9
8
  Requires PHP: 5.6
9
+ Stable tag: 2.3.21
10
  License: GPLv3
11
 
12
  Insert and manage ads: Amazon, Google AdSense ads, banner rotation, sticky widget ads, AMP, PHP, HTML, CSS, Javascript, tracking, footer, header code
679
 
680
  == Changelog ==
681
 
682
+ = 2.3.21 =
683
+ - Added option to force showing admin toolbar when viewing site
684
+ - Added additional debugging info for blocks in Ajax requests
685
+ - Fix for viewport visibility detection
686
+ - Fix for rotation with non-ASCII characters
687
+ - Few minor bug fixes, cosmetic changes and code improvements
688
+
689
  = 2.3.20 =
690
  - Improved loading of settings
691
  - Fix for content processing in some ajax calls
812
 
813
  == Upgrade Notice ==
814
 
815
+ = 2.3.21 =
816
+ Added option to force showing admin toolbar when viewing site;
817
+ Added additional debugging info for blocks in Ajax requests;
818
+ Fix for viewport visibility detection;
819
+ Fix for rotation with non-ASCII characters;
820
+ Few minor bug fixes, cosmetic changes and code improvements
821
+
822
  = 2.3.20 =
823
  Improved loading of settings;
824
  Fix for content processing in some ajax calls;
settings.php CHANGED
@@ -149,7 +149,7 @@ function generate_settings_form (){
149
  <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://adinserter.pro/documentation')" title="<?php echo AD_INSERTER_NAME; ?> Documentation">Doc</button>
150
  <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://wordpress.org/support/plugin/ad-inserter')" title="<?php echo AD_INSERTER_NAME; ?> support forum">Support</button>
151
  <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4')" title="Support Free Ad Inserter development. If you are making money with Ad Inserter consider donating some small amount. Even 1 dollar counts. Thank you!">Donate</button>
152
- <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://wordpress.org/support/plugin/ad-inserter/reviews/')" title="If you like Ad Inserter and have a moment, please help me spread the word by reviewing the plugin on WordPres">Review</button>
153
  <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://adinserter.pro/')" title="Need more code blocks, sticky ads, GEO targeting, impression and click tracking? Upgrade to Ad Inserter Pro">Go&nbsp;Pro</button>
154
  <button id="ai-list" type="button" class="ai-top-button" style="width: 62px; display: none; margin-right: 0px; outline-color: transparent;" title="Show list of all code blocks"><span>Blocks</span></button>
155
  </div>
@@ -2439,18 +2439,36 @@ function generate_settings_form (){
2439
 
2440
  <div id="tab-debugging" class="rounded">
2441
  <table class="ai-settings-table" style="width: 100%;">
2442
- <tr>
2443
- <td style="width: 30%;">
2444
- <label for="admin-toolbar-debugging" title="Enable debugging functions in admin toolbar">Debugging functions in admin toolbar</label>
 
 
 
 
 
 
 
 
 
2445
  </td>
2446
  <td>
2447
  <input type="hidden" name="admin_toolbar_debugging" value="0" />
2448
  <input type="checkbox" name="admin_toolbar_debugging" id="admin-toolbar-debugging" value="1" default="<?php echo DEFAULT_ADMIN_TOOLBAR_DEBUGGING; ?>" <?php if (get_admin_toolbar_debugging ()==AI_ENABLED) echo 'checked '; ?> />
2449
  </td>
2450
  </tr>
2451
- <tr>
 
 
 
 
 
 
 
 
 
2452
  <td>
2453
- <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 administrators debugging is always enabled.">Remote debugging</label>
2454
  </td>
2455
  <td>
2456
  <input type="hidden" name="remote_debugging" value="0" />
@@ -2646,6 +2664,9 @@ function generate_settings_form (){
2646
  var blocking_counter = 0;
2647
  replace_blocked_image ('ai-media-1', 'contextual-1.gif', 'block');
2648
  replace_blocked_image ('ai-media-2', 'contextual-2.jpg', 'block');
 
 
 
2649
  replace_blocked_image ('ai-info-1', 'info-1.jpg', 'block');
2650
  replace_blocked_image ('ai-info-2', 'info-2.jpg', 'block');
2651
  replace_blocked_image ('ai-info-3', 'info-3.jpg', 'block');
@@ -3394,7 +3415,7 @@ function generate_list_options ($options) {
3394
  function sidebar_addense_alternative () { ?>
3395
 
3396
  <?php
3397
- switch (rand (1, 2)) {
3398
  case 1:
3399
  ?>
3400
  <div class="ai-form header rounded">
@@ -3406,13 +3427,37 @@ function sidebar_addense_alternative () { ?>
3406
  <div class="ai-form rounded" style="height: 90px; padding: 8px 4px 8px 12px;">
3407
  <a href='http://bit.ly/Media-NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-1" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-1.gif" /></a>
3408
  </div>
3409
-
3410
- <!-- <div class="ai-form rounded" style="height: 90px; padding: 8px 4px 8px 12px;">-->
3411
- <!-- <a href='http://bit.ly/Info-links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-1" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-1.jpg" /></a>-->
3412
- <!-- </div>-->
3413
  <?php
3414
  break;
3415
  case 2:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3416
  ?>
3417
  <div class="ai-form header rounded">
3418
  <div style="float: left;">
@@ -3423,10 +3468,6 @@ function sidebar_addense_alternative () { ?>
3423
  <div class="ai-form rounded" style="height: 90px; padding: 8px 4px 8px 12px;">
3424
  <a href='http://bit.ly/Info-links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-1" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-1.jpg" /></a>
3425
  </div>
3426
-
3427
- <!-- <div class="ai-form rounded" style="height: 90px; padding: 8px 4px 8px 12px;">-->
3428
- <!-- <a href='http://bit.ly/Media-NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-1" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-1.gif" /></a>-->
3429
- <!-- </div>-->
3430
  <?php
3431
  break;
3432
  }
@@ -3456,6 +3497,7 @@ function sidebar_support_plugin () {
3456
  <div class="ai-form header rounded no-select">
3457
  <div style="float: left;">
3458
  <h2 style="display: inline-block; margin: 7px 0;">Support plugin development</h2>
 
3459
  </div>
3460
 
3461
  <div style="float: right;">
@@ -3476,6 +3518,7 @@ function sidebar_support_plugin () {
3476
  </a>
3477
  </div>
3478
  </div>
 
3479
  </div>
3480
 
3481
  <div style="clear: both;"></div>
@@ -3517,7 +3560,7 @@ function sidebar_help () { ?>
3517
  }
3518
 
3519
  function sidebar_pro () {
3520
- $version = rand (0, 1);
3521
  ?>
3522
 
3523
  <div class="ai-form rounded no-select feature-list" style="background: #fff;">
@@ -3528,15 +3571,24 @@ function sidebar_pro () {
3528
  <!-- <a href="https://adinserter.pro/" class="clear-link" title="Automate ad placement on posts and pages" target="_blank"><img id="ai-pro-1" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>icon-256x256.jpg" style="margin-top: 10px;" /></a>-->
3529
  <a href='http://bit.ly/info_links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-3.jpg" style="margin-top: 10px;" /></a>
3530
  <?php break; case 1: ?>
 
 
3531
  <a href='http://bit.ly/media_NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-2.jpg" style="margin-top: 10px;" /></a>
 
 
3532
  <?php break;
3533
  } ?>
3534
  </div>
3535
  <div>
3536
  <?php switch ($version) {
3537
- case 0: ?>
 
 
3538
  <a href="https://adinserter.pro/documentation/ad-impression-and-click-tracking" class="clear-link" title="A/B testing - Track ad impressions and clicks" target="_blank"><img id="ai-pro-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-charts-250.png" style="margin-top: 10px;" /></a>
3539
- <?php break; case 1: ?>
 
 
 
3540
  <a href='https://adinserter.pro/documentation/code-preview' class="clear-link" title="Code preview with visual CSS editor" target="_blank"><img id="ai-preview" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-preview-250.png" style="margin-top: 10px;" /></a>
3541
  <?php break;
3542
  } ?>
@@ -3544,8 +3596,14 @@ function sidebar_pro () {
3544
  <div>
3545
  <?php switch ($version) {
3546
  case 0: ?>
3547
- <a href='http://bit.ly/media_NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-2.jpg" style="margin-top: 10px;" /></a>
3548
  <?php break; case 1: ?>
 
 
 
 
 
 
3549
  <!-- <a href="https://adinserter.pro/documentation/black-and-white-lists#geo-targeting" class="clear-link" title="Geotargeting - black/white-list countries" target="_blank"><img id="ai-pro-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-countries-250.png" style="margin-top: 10px;" /></a>-->
3550
  <a href='http://bit.ly/info_links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-2.jpg" style="margin-top: 10px;" /></a>
3551
  <?php break;
@@ -3553,9 +3611,14 @@ function sidebar_pro () {
3553
  </div>
3554
  <div>
3555
  <?php switch ($version) {
3556
- case 0: ?>
 
 
3557
  <a href='https://adinserter.pro/documentation/code-preview' class="clear-link" title="Code preview with visual CSS editor" target="_blank"><img id="ai-preview" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-preview-250.png" style="margin-top: 10px;" /></a>
3558
- <?php break; case 1: ?>
 
 
 
3559
  <a href="https://adinserter.pro/documentation/ad-impression-and-click-tracking" class="clear-link" title="A/B testing - Track ad impressions and clicks" target="_blank"><img id="ai-pro-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-charts-250.png" style="margin-top: 10px;" /></a>
3560
  <?php break;
3561
  } ?>
149
  <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://adinserter.pro/documentation')" title="<?php echo AD_INSERTER_NAME; ?> Documentation">Doc</button>
150
  <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://wordpress.org/support/plugin/ad-inserter')" title="<?php echo AD_INSERTER_NAME; ?> support forum">Support</button>
151
  <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4')" title="Support Free Ad Inserter development. If you are making money with Ad Inserter consider donating some small amount. Even 1 dollar counts. Thank you!">Donate</button>
152
+ <!-- <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://wordpress.org/support/plugin/ad-inserter/reviews/')" title="If you like Ad Inserter and have a moment, please help me spread the word by reviewing the plugin on WordPres">Review</button>-->
153
  <button type="button" class="ai-top-button" style="display: none; margin: 0 10px 0 0; width: 62px; outline-color: transparent;" onclick="window.open('https://adinserter.pro/')" title="Need more code blocks, sticky ads, GEO targeting, impression and click tracking? Upgrade to Ad Inserter Pro">Go&nbsp;Pro</button>
154
  <button id="ai-list" type="button" class="ai-top-button" style="width: 62px; display: none; margin-right: 0px; outline-color: transparent;" title="Show list of all code blocks"><span>Blocks</span></button>
155
  </div>
2439
 
2440
  <div id="tab-debugging" class="rounded">
2441
  <table class="ai-settings-table" style="width: 100%;">
2442
+ <tr title="Force showing admin toolbar for administrators when viewing site. Enable this option when you are logged in as admin and you don't see admin toolbar.">
2443
+ <td style="width: 40%;">
2444
+ <label for="force-admin-toolbar">Force showing admin toolbar when viewing site</label>
2445
+ </td>
2446
+ <td>
2447
+ <input type="hidden" name="force_admin_toolbar" value="0" />
2448
+ <input type="checkbox" name="force_admin_toolbar" id="force-admin-toolbar" value="1" default="<?php echo DEFAULT_FORCE_ADMIN_TOOLBAR; ?>" <?php if (get_force_admin_toolbar () == AI_ENABLED) echo 'checked '; ?> />
2449
+ </td>
2450
+ </tr>
2451
+ <tr title="Enable debugging functions in admin toolbar">
2452
+ <td>
2453
+ <label for="admin-toolbar-debugging">Debugging functions in admin toolbar</label>
2454
  </td>
2455
  <td>
2456
  <input type="hidden" name="admin_toolbar_debugging" value="0" />
2457
  <input type="checkbox" name="admin_toolbar_debugging" id="admin-toolbar-debugging" value="1" default="<?php echo DEFAULT_ADMIN_TOOLBAR_DEBUGGING; ?>" <?php if (get_admin_toolbar_debugging ()==AI_ENABLED) echo 'checked '; ?> />
2458
  </td>
2459
  </tr>
2460
+ <tr title="Enable debugging functions in admin toolbar on mobile screens">
2461
+ <td>
2462
+ <label for="admin-toolbar-mobile">Debugging functions on mobile screens</label>
2463
+ </td>
2464
+ <td>
2465
+ <input type="hidden" name="admin_toolbar_mobile" value="0" />
2466
+ <input type="checkbox" name="admin_toolbar_mobile" id="admin-toolbar-mobile" value="1" default="<?php echo DEFAULT_ADMIN_TOOLBAR_MOBILE; ?>" <?php if (get_admin_toolbar_mobile ()==AI_ENABLED) echo 'checked '; ?> />
2467
+ </td>
2468
+ </tr>
2469
+ <tr 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 administrators debugging is always enabled.">
2470
  <td>
2471
+ <label for="remote-debugging">Remote debugging</label>
2472
  </td>
2473
  <td>
2474
  <input type="hidden" name="remote_debugging" value="0" />
2664
  var blocking_counter = 0;
2665
  replace_blocked_image ('ai-media-1', 'contextual-1.gif', 'block');
2666
  replace_blocked_image ('ai-media-2', 'contextual-2.jpg', 'block');
2667
+ replace_blocked_image ('ai-media-3', 'contextual-3.png', 'block');
2668
+ replace_blocked_image ('ai-media-4', 'contextual-4.gif', 'block');
2669
+ replace_blocked_image ('ai-media-5', 'contextual-5.png', 'block');
2670
  replace_blocked_image ('ai-info-1', 'info-1.jpg', 'block');
2671
  replace_blocked_image ('ai-info-2', 'info-2.jpg', 'block');
2672
  replace_blocked_image ('ai-info-3', 'info-3.jpg', 'block');
3415
  function sidebar_addense_alternative () { ?>
3416
 
3417
  <?php
3418
+ switch (rand (1, 6)) {
3419
  case 1:
3420
  ?>
3421
  <div class="ai-form header rounded">
3427
  <div class="ai-form rounded" style="height: 90px; padding: 8px 4px 8px 12px;">
3428
  <a href='http://bit.ly/Media-NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-1" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-1.gif" /></a>
3429
  </div>
 
 
 
 
3430
  <?php
3431
  break;
3432
  case 2:
3433
+ ?>
3434
+ <div class="ai-form header rounded">
3435
+ <div style="float: left;">
3436
+ <h2 style="display: inline-block; margin: 5px 0;">Blank Ad Blocks? Looking for AdSense alternative?</h2>
3437
+ </div>
3438
+ <div style="clear: both;"></div>
3439
+ </div>
3440
+ <div class="ai-form rounded" style="height: 90px; padding: 8px 4px 8px 12px;">
3441
+ <a href='http://bit.ly/Media-NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-4" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-4.gif" /></a>
3442
+ </div>
3443
+ <?php
3444
+ break;
3445
+ case 3:
3446
+ ?>
3447
+ <div class="ai-form header rounded">
3448
+ <div style="float: left;">
3449
+ <h2 style="display: inline-block; margin: 5px 0;">Blank Ad Blocks? Looking for AdSense alternative?</h2>
3450
+ </div>
3451
+ <div style="clear: both;"></div>
3452
+ </div>
3453
+ <div class="ai-form rounded" style="height: 90px; padding: 8px 4px 8px 12px;">
3454
+ <a href='http://bit.ly/Media-NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-5" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-5.png" /></a>
3455
+ </div>
3456
+ <?php
3457
+ break;
3458
+ case 4:
3459
+ case 5:
3460
+ case 6:
3461
  ?>
3462
  <div class="ai-form header rounded">
3463
  <div style="float: left;">
3468
  <div class="ai-form rounded" style="height: 90px; padding: 8px 4px 8px 12px;">
3469
  <a href='http://bit.ly/Info-links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-1" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-1.jpg" /></a>
3470
  </div>
 
 
 
 
3471
  <?php
3472
  break;
3473
  }
3497
  <div class="ai-form header rounded no-select">
3498
  <div style="float: left;">
3499
  <h2 style="display: inline-block; margin: 7px 0;">Support plugin development</h2>
3500
+ <button type="button" class="ai-top-button" style="display: none; margin: -5px 0px 0px 15px; min-width; 62px; width: 62px; outline-color: transparent;" onclick="window.open('https://wordpress.org/support/plugin/ad-inserter/reviews/')" title="If you like Ad Inserter and have a moment, please help me spread the word by reviewing the plugin on WordPres">Review</button>
3501
  </div>
3502
 
3503
  <div style="float: right;">
3518
  </a>
3519
  </div>
3520
  </div>
3521
+
3522
  </div>
3523
 
3524
  <div style="clear: both;"></div>
3560
  }
3561
 
3562
  function sidebar_pro () {
3563
+ $version = rand (0, 3);
3564
  ?>
3565
 
3566
  <div class="ai-form rounded no-select feature-list" style="background: #fff;">
3571
  <!-- <a href="https://adinserter.pro/" class="clear-link" title="Automate ad placement on posts and pages" target="_blank"><img id="ai-pro-1" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>icon-256x256.jpg" style="margin-top: 10px;" /></a>-->
3572
  <a href='http://bit.ly/info_links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-3.jpg" style="margin-top: 10px;" /></a>
3573
  <?php break; case 1: ?>
3574
+ <a href='http://bit.ly/info_links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-3.jpg" style="margin-top: 10px;" /></a>
3575
+ <?php break; case 2: ?>
3576
  <a href='http://bit.ly/media_NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-2.jpg" style="margin-top: 10px;" /></a>
3577
+ <?php break; case 3: ?>
3578
+ <a href='http://bit.ly/media_NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-3.png" style="margin-top: 10px;" /></a>
3579
  <?php break;
3580
  } ?>
3581
  </div>
3582
  <div>
3583
  <?php switch ($version) {
3584
+ case 0:
3585
+ case 1:
3586
+ ?>
3587
  <a href="https://adinserter.pro/documentation/ad-impression-and-click-tracking" class="clear-link" title="A/B testing - Track ad impressions and clicks" target="_blank"><img id="ai-pro-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-charts-250.png" style="margin-top: 10px;" /></a>
3588
+ <?php break;
3589
+ case 2:
3590
+ case 3:
3591
+ ?>
3592
  <a href='https://adinserter.pro/documentation/code-preview' class="clear-link" title="Code preview with visual CSS editor" target="_blank"><img id="ai-preview" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-preview-250.png" style="margin-top: 10px;" /></a>
3593
  <?php break;
3594
  } ?>
3596
  <div>
3597
  <?php switch ($version) {
3598
  case 0: ?>
3599
+ <a href='http://bit.ly/media_NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-3.png" style="margin-top: 10px;" /></a>
3600
  <?php break; case 1: ?>
3601
+ <!-- <a href="https://adinserter.pro/documentation/black-and-white-lists#geo-targeting" class="clear-link" title="Geotargeting - black/white-list countries" target="_blank"><img id="ai-pro-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-countries-250.png" style="margin-top: 10px;" /></a>-->
3602
+ <a href='http://bit.ly/media_NET' class="clear-link" title="Looking for AdSense alternative?" target="_blank"><img id="ai-media-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>contextual-2.jpg" style="margin-top: 10px;" /></a>
3603
+ <?php break; case 2: ?>
3604
+ <!-- <a href="https://adinserter.pro/documentation/black-and-white-lists#geo-targeting" class="clear-link" title="Geotargeting - black/white-list countries" target="_blank"><img id="ai-pro-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-countries-250.png" style="margin-top: 10px;" /></a>-->
3605
+ <a href='http://bit.ly/info_links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-2.jpg" style="margin-top: 10px;" /></a>
3606
+ <?php break; case 3: ?>
3607
  <!-- <a href="https://adinserter.pro/documentation/black-and-white-lists#geo-targeting" class="clear-link" title="Geotargeting - black/white-list countries" target="_blank"><img id="ai-pro-3" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-countries-250.png" style="margin-top: 10px;" /></a>-->
3608
  <a href='http://bit.ly/info_links' class="clear-link" title="Add Infolinks Ads with Adsense to earn More Money" target="_blank"><img id="ai-info-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>info-2.jpg" style="margin-top: 10px;" /></a>
3609
  <?php break;
3611
  </div>
3612
  <div>
3613
  <?php switch ($version) {
3614
+ case 0:
3615
+ case 1:
3616
+ ?>
3617
  <a href='https://adinserter.pro/documentation/code-preview' class="clear-link" title="Code preview with visual CSS editor" target="_blank"><img id="ai-preview" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-preview-250.png" style="margin-top: 10px;" /></a>
3618
+ <?php break;
3619
+ case 2:
3620
+ case 3:
3621
+ ?>
3622
  <a href="https://adinserter.pro/documentation/ad-impression-and-click-tracking" class="clear-link" title="A/B testing - Track ad impressions and clicks" target="_blank"><img id="ai-pro-2" src="<?php echo AD_INSERTER_PLUGIN_IMAGES_URL; ?>ai-charts-250.png" style="margin-top: 10px;" /></a>
3623
  <?php break;
3624
  } ?>