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

Version Description

  • Added widget for debugging tools
  • Fix for AdSense ad overlays not displayed with some themes
  • 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.6
Comparing to
See all releases

Code changes from version 2.3.5 to 2.3.6

ad-inserter.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
- Version: 2.3.5
6
  Description: Ad management plugin with advanced advertising options to automatically insert ad codes on your website
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
@@ -13,7 +13,12 @@ Plugin URI: http://adinserter.pro/documentation
13
 
14
  Change Log
15
 
16
- Ad Inserter 2.3.5 - 2018-03-10
 
 
 
 
 
17
  - Added display of header and footer code in Label blocks debugging function
18
  - Added AdSense ad overlays in Label blocks debugging function (experimental)
19
  - Fixed bug for removed square brackets in HTML element selectors
@@ -780,9 +785,13 @@ function ai_disable_caching () {
780
  }
781
  }
782
 
783
- function ai_toolbar ($wp_admin_bar) {
784
  global $block_object, $ai_wp_data;
785
 
 
 
 
 
786
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) == 0) $debug_blocks = 1; else $debug_blocks = 0;
787
  $debug_blocks_class = $debug_blocks == 0 ? ' on' : '';
788
 
@@ -808,30 +817,33 @@ function ai_toolbar ($wp_admin_bar) {
808
 
809
  $debug_settings_class = $debug_settings_on ? ' on' : '';
810
  $top_menu_url = $debug_settings_on ? add_query_arg (AI_URL_DEBUG, '0', remove_debug_parameters_from_url ()) :
811
- add_query_arg (array (AI_URL_DEBUG_BLOCKS => '1', AI_URL_DEBUG_POSITIONS => '0', AI_URL_DEBUG_TAGS => '1'), remove_debug_parameters_from_url ());
812
 
813
- $wp_admin_bar->add_node (array (
814
  'id' => 'ai-toolbar',
815
  'group' => true
816
- ));
817
- $wp_admin_bar->add_node (array (
 
818
  'id' => 'ai-toolbar-settings',
819
  // 'parent' => 'ai-toolbar',
820
  'title' => '<span class="ab-icon'.$debug_settings_class.'"></span>'.AD_INSERTER_NAME,
821
  'href' => $top_menu_url,
822
- ));
823
- $wp_admin_bar->add_node (array (
 
824
  'id' => 'ai-toolbar-blocks',
825
  'parent' => 'ai-toolbar-settings',
826
  'title' => '<span class="ab-icon'.$debug_blocks_class.'"></span>Label Blocks',
827
  'href' => set_url_parameter (AI_URL_DEBUG_BLOCKS, $debug_blocks),
828
- ));
829
- $wp_admin_bar->add_node (array (
 
830
  'id' => 'ai-toolbar-positions',
831
  'parent' => 'ai-toolbar-settings',
832
  'title' => '<span class="ab-icon'.$debug_positions_class.'"></span>Show Positions',
833
  'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $debug_positions),
834
- ));
835
 
836
  $paragraph_blocks = array ();
837
  for ($block = 0; $block <= AD_INSERTER_BLOCKS; $block ++) {
@@ -880,7 +892,7 @@ function ai_toolbar ($wp_admin_bar) {
880
 
881
  foreach ($paragraph_blocks as $index => $paragraph_block) {
882
  $block_class = $debug_positions === '' && in_array ($ai_wp_data [AI_WP_DEBUG_BLOCK], $paragraph_block ['blocks']) ? ' on' : '';
883
- $wp_admin_bar->add_node (array (
884
  'id' => 'ai-toolbar-positions-'.$index,
885
  'parent' => 'ai-toolbar-positions',
886
  'title' => '<span class="ab-icon'.$block_class.'"></span>'.
@@ -891,43 +903,57 @@ function ai_toolbar ($wp_admin_bar) {
891
  ($paragraph_block ['blockquote'] ? ' +[' . $no_paragraph_counting_inside . '] ' : '').
892
  ($paragraph_block ['text'] != '' ? ($paragraph_block ['text_type'] == AD_DO_NOT_CONTAIN ? ' NC ' : ' C ').' ['.htmlentities ($paragraph_block ['text']).']' : ''),
893
  'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $paragraph_block ['blocks'][0]),
894
- ));
895
  }
896
 
897
- $wp_admin_bar->add_node (array (
898
  'id' => 'ai-toolbar-tags',
899
  'parent' => 'ai-toolbar-settings',
900
  'title' => '<span class="ab-icon'.$debug_tags_class.'"></span>Show HTML Tags',
901
  'href' => set_url_parameter (AI_URL_DEBUG_TAGS, $debug_tags),
902
- ));
903
- $wp_admin_bar->add_node (array (
 
904
  'id' => 'ai-toolbar-no-insertion',
905
  'parent' => 'ai-toolbar-settings',
906
  'title' => '<span class="ab-icon'.$debug_no_insertion_class.'"></span>Disable Insertion',
907
  'href' => set_url_parameter (AI_URL_DEBUG_NO_INSERTION, $debug_no_insertion),
908
- ));
 
909
  if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
910
  if ($ai_wp_data [AI_ADB_DETECTION]) {
911
- $wp_admin_bar->add_node (array (
912
  'id' => 'ai-toolbar-adb-status',
913
  'parent' => 'ai-toolbar-settings',
914
  'title' => '<span class="ab-icon'.$debug_ad_blocking_status_class.'"></span>Ad Blocking Status',
915
  'href' => set_url_parameter (AI_URL_DEBUG_AD_BLOCKING_STATUS, $debug_ad_blocking_status),
916
- ));
917
- $wp_admin_bar->add_node (array (
 
918
  'id' => 'ai-toolbar-adb',
919
  'parent' => 'ai-toolbar-settings',
920
  'title' => '<span class="ab-icon'.$debug_ad_blocking_class.'"></span>Simulate Ad Blocking',
921
  'href' => set_url_parameter (AI_URL_DEBUG_AD_BLOCKING, $debug_ad_blocking),
922
- ));
923
  }
924
  }
925
- $wp_admin_bar->add_node (array (
 
926
  'id' => 'ai-toolbar-processing',
927
  'parent' => 'ai-toolbar-settings',
928
  'title' => '<span class="ab-icon'.$debug_processing_class.'"></span>Log Processing',
929
  'href' => set_url_parameter (AI_URL_DEBUG_PROCESSING, $debug_processing),
930
- ));
 
 
 
 
 
 
 
 
 
 
931
  }
932
 
933
  function set_user () {
@@ -1691,6 +1717,10 @@ function ai_wp_enqueue_scripts_hook () {
1691
  if ($ai_wp_data [AI_CLIENT_SIDE_INSERTION]) {
1692
  wp_add_inline_script ('ai-jquery-js', ai_get_js ('ai-insert', false));
1693
  }
 
 
 
 
1694
  }
1695
  }
1696
 
@@ -1890,6 +1920,7 @@ function ai_replace_js_data ($js) {
1890
  }
1891
 
1892
  $js = str_replace ('AI_NONCE', wp_create_nonce ("adinserter_data"), $js);
 
1893
  $js = str_replace ('AI_SITE_URL', wp_make_link_relative (get_site_url()), $js);
1894
  if (defined ('AI_STATISTICS') && AI_STATISTICS) {
1895
  $js = str_replace ('AI_INTERNAL_TRACKING', get_internal_tracking () == AI_ENABLED ? 1 : 0, $js);
@@ -2019,17 +2050,17 @@ function ai_admin_notice_hook () {
2019
  // }
2020
 
2021
  if (function_exists ('ai_admin_notices')) ai_admin_notices (); else {
2022
- if ($hook_suffix == $ai_settings_page && is_super_admin () && !wp_is_mobile () && isset ($ai_wp_data [AI_DAYS_SINCE_INSTAL])) {
2023
 
2024
  $used_blocks = count (unserialize ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]));
2025
 
2026
  $notice_option = get_option ('ai-notice-review');
2027
  if ($notice_option === false && $ai_wp_data [AI_DAYS_SINCE_INSTAL] >= 40) $notice_option = 'later';
2028
 
2029
- if (($notice_option === false && $used_blocks >= 3 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 20 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] < 40) ||
2030
 
2031
  ($notice_option == 'later' && ($used_blocks >= 5 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 50 ||
2032
- $used_blocks >= 3 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 60))) {
2033
 
2034
  if ($notice_option == 'later') {
2035
  $message = "Hey, you are now using <strong>{$used_blocks} Ad Inserter</strong> code blocks.";
@@ -2449,15 +2480,18 @@ function ai_wp_head_hook () {
2449
 
2450
  if ($header_code !== null && ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
2451
  echo "<script>\n";
2452
- if (defined ('AI_ADSENSE_OVERLAY')) {
2453
- echo ai_get_js ('ai-ads');
2454
- }
2455
  echo " jQuery(document).ready(function($) {
2456
  $('body').prepend (\"" . get_header_footer_debug_block (' Header code ', '&lt;head&gt;...&lt;/head&gt;', $header_code, true) . "\");
2457
  });
2458
  </script>\n";
2459
  }
2460
 
 
 
 
 
 
 
2461
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
2462
  echo "<script>
2463
  jQuery(document).ready(function($) {
@@ -4529,14 +4563,18 @@ a.ai-debug-center {text-align: center; font-size: 10px; text-decoration: none; c
4529
  .ai-debug-ad-overlay {position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #8f8; opacity: 0.6; z-index': '999999990}
4530
  .ai-auto-ads {background-color: #84f;}
4531
  .ai-no-slot {background-color: #48f;}
4532
- .ai-debug-ad-info {position: absolute; top: 0; left: 0; overflow: hidden; width: auto; height: auto; font-size: 11px; line-height: 11px; text-align: left; z-index: 999999991;}
4533
  .ai-info {display: inline-block; padding: 2px 4px;}
4534
  .ai-info-1 {background: #000; color: #fff;}
4535
  .ai-info-2 {background: #fff; color: #000;}
4536
 
 
 
 
 
4537
  .ai-debug-code {margin: 0; padding: 0; border: 0; font-family: monospace; font-size: 12px; line-height: 13px;}
4538
 
4539
- .ai-debug-block {border: 1px solid;}
4540
 
4541
  .ai-debug-block.ai-debug-default {border-color: #e00;}
4542
  .ai-debug-bar.ai-debug-default {background: #e00;}
@@ -4569,9 +4607,9 @@ a.ai-debug-center {text-align: center; font-size: 10px; text-decoration: none; c
4569
  .ai-debug-bar.ai-debug-ip {background: #00c5be;}
4570
 
4571
  .ai-debug-adb-hidden {visibility: hidden; display: none;}
4572
- .ai-debug-adb-center {text-align: center; font-weight: bold; padding: 4px 0;}
4573
 
4574
- .ai-debug-bar {padding: 1px 0 1px 5px; color: white; font-size: 12px; font-family: arial; font-weight: normal; line-height: 20px; text-align: center;}
4575
 
4576
  .ai-debug-bar .ai-debug-text-left {float: left;}
4577
  .ai-debug-bar .ai-debug-text-right {float: right; padding-right: 3px;}
@@ -5676,7 +5714,7 @@ function ai_process_shortcode (&$block, $atts) {
5676
  "name" => "",
5677
  "ignore" => "",
5678
  "check" => "",
5679
- "debugger" => "",
5680
  "adb" => "",
5681
  "css" => "",
5682
  "text" => "",
@@ -5728,14 +5766,12 @@ function ai_process_shortcode (&$block, $atts) {
5728
  $block = intval ($parameters ['block']);
5729
  } elseif ($parameters ['name'] != '') {
5730
  $shortcode_name = strtolower ($parameters ['name']);
5731
- if ($shortcode_name == 'debugger') $block = 0; else {
5732
- for ($counter = 1; $counter <= AD_INSERTER_BLOCKS; $counter ++) {
5733
- $obj = $block_object [$counter];
5734
- $ad_name = strtolower (trim ($obj->get_ad_name()));
5735
- if ($shortcode_name == $ad_name) {
5736
- $block = $counter;
5737
- break;
5738
- }
5739
  }
5740
  }
5741
  }
@@ -5767,18 +5803,24 @@ function ai_process_shortcode (&$block, $atts) {
5767
  if ($parameters ['data'] != '') {
5768
  return '{'.$parameters ['data'].'}';
5769
  }
5770
-
5771
- }
5772
-
5773
- if ($block == 0) {
5774
- if (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0) {
5775
- ob_start ();
5776
- echo "<pre style='", AI_DEBUG_WIDGET_STYLE, "'>\n";
5777
- ai_write_debug_info ();
5778
- echo "</pre>";
5779
- return ob_get_clean ();
 
 
 
 
 
 
 
5780
  }
5781
- return "";
5782
  }
5783
 
5784
  $ai_last_check = AI_CHECK_SHORTCODE_ATTRIBUTES;
@@ -5899,8 +5941,9 @@ class ai_widget extends WP_Widget {
5899
  if ($block > AD_INSERTER_BLOCKS) $block = 1;
5900
  $sticky = isset ($instance ['sticky']) ? $instance ['sticky'] : 0;
5901
 
5902
- if ($block == 0) $title = 'Debugger';
5903
  elseif ($block == - 1) $title = 'Dummy Widget';
 
5904
  elseif ($block >= 1) {
5905
  $obj = $block_object [$block];
5906
 
@@ -5929,7 +5972,8 @@ class ai_widget extends WP_Widget {
5929
  ?>
5930
  <option value='<?php echo $block_index; ?>' <?php if ($block_index == $block) echo 'selected="selected"'; ?>><?php echo $block_index, ' - ', $obj->get_ad_name(), !$obj->get_enable_widget ()? ' - DISABLED' : ''; ?></option>
5931
  <?php } ?>
5932
- <option value='0' <?php if ($block == 0) echo 'selected="selected"'; ?>>Debugger</option>
 
5933
  <option value='-1' <?php if ($block == - 1) echo 'selected="selected"'; ?>>Dummy Widget</option>
5934
  </select>
5935
  </p>
@@ -5996,9 +6040,10 @@ function ai_widget_draw ($args, $instance, &$block) {
5996
  $block = isset ($instance ['block']) ? $instance ['block'] : 1;
5997
  $sticky = isset ($instance ['sticky']) ? $instance ['sticky'] : 0;
5998
 
5999
- if ($block == 0) {
6000
- if (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0)
6001
- ai_widget_draw_debugger ($args, $instance, $block);
 
6002
  return;
6003
  }
6004
 
@@ -6089,14 +6134,130 @@ function ai_widget_draw ($args, $instance, &$block) {
6089
  }
6090
  }
6091
 
6092
- function ai_widget_draw_debugger ($args, $instance, &$block) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6093
  global $ai_wp_data, $ai_db_options, $block_object;
6094
 
6095
  $sticky = isset ($instance ['sticky']) ? $instance ['sticky'] : 0;
6096
 
6097
  if ($sticky) {
6098
  $ai_wp_data [AI_STICKY_WIDGETS] = true;
6099
- echo ai_add_attr_data ($args ['before_widget'], 'class', 'ai-sticky-widget');
 
6100
  } else echo $args ['before_widget'];
6101
 
6102
  $title = !empty ($instance ['widget-title']) ? $instance ['widget-title'] : '';
@@ -6105,21 +6266,27 @@ function ai_widget_draw_debugger ($args, $instance, &$block) {
6105
  echo $args ['before_title'], apply_filters ('widget_title', $title), $args ['after_title'];
6106
  }
6107
 
6108
- echo "<pre style='", AI_DEBUG_WIDGET_STYLE, "'>\n";
6109
- ai_write_debug_info ();
6110
- echo "</pre>";
 
 
6111
 
6112
- if ($ai_wp_data [AI_CLIENT_SIDE_DETECTION]) {
6113
- for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
6114
- $viewport_name = get_viewport_name ($viewport);
6115
- if ($viewport_name != '') {
6116
- echo "<pre class='ai-viewport-" . $viewport ."' style='", AI_DEBUG_WIDGET_STYLE, "'>\n";
6117
- echo "CLIENT-SIDE DEVICE: ", $viewport_name;
6118
- echo "</pre>";
 
 
6119
  }
6120
- }
 
 
 
6121
  }
6122
 
6123
  echo $args ['after_widget'];
6124
  }
6125
-
2
 
3
  /*
4
  Plugin Name: Ad Inserter
5
+ Version: 2.3.6
6
  Description: Ad management plugin with advanced advertising options to automatically insert ad codes on your website
7
  Author: Igor Funa
8
  Author URI: http://igorfuna.com/
13
 
14
  Change Log
15
 
16
+ Ad Inserter 2.3.6 - 2018-03-20
17
+ - Added widget for debugging tools
18
+ - Fix for AdSense ad overlays not displayed with some themes
19
+ - Few minor bug fixes, cosmetic changes and code improvements
20
+
21
+ Ad Inserter 2.3.5 - 2018-03-13
22
  - Added display of header and footer code in Label blocks debugging function
23
  - Added AdSense ad overlays in Label blocks debugging function (experimental)
24
  - Fixed bug for removed square brackets in HTML element selectors
785
  }
786
  }
787
 
788
+ function ai_toolbar_menu_items () {
789
  global $block_object, $ai_wp_data;
790
 
791
+ if (isset ($ai_wp_data [AI_DEBUG_MENU_ITEMS])) return;
792
+
793
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS] = array ();
794
+
795
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) == 0) $debug_blocks = 1; else $debug_blocks = 0;
796
  $debug_blocks_class = $debug_blocks == 0 ? ' on' : '';
797
 
817
 
818
  $debug_settings_class = $debug_settings_on ? ' on' : '';
819
  $top_menu_url = $debug_settings_on ? add_query_arg (AI_URL_DEBUG, '0', remove_debug_parameters_from_url ()) :
820
+ add_query_arg (array (AI_URL_DEBUG_BLOCKS => '1', AI_URL_DEBUG_POSITIONS => '0'), remove_debug_parameters_from_url ());
821
 
822
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
823
  'id' => 'ai-toolbar',
824
  'group' => true
825
+ );
826
+
827
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
828
  'id' => 'ai-toolbar-settings',
829
  // 'parent' => 'ai-toolbar',
830
  'title' => '<span class="ab-icon'.$debug_settings_class.'"></span>'.AD_INSERTER_NAME,
831
  'href' => $top_menu_url,
832
+ );
833
+
834
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
835
  'id' => 'ai-toolbar-blocks',
836
  'parent' => 'ai-toolbar-settings',
837
  'title' => '<span class="ab-icon'.$debug_blocks_class.'"></span>Label Blocks',
838
  'href' => set_url_parameter (AI_URL_DEBUG_BLOCKS, $debug_blocks),
839
+ );
840
+
841
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
842
  'id' => 'ai-toolbar-positions',
843
  'parent' => 'ai-toolbar-settings',
844
  'title' => '<span class="ab-icon'.$debug_positions_class.'"></span>Show Positions',
845
  'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $debug_positions),
846
+ );
847
 
848
  $paragraph_blocks = array ();
849
  for ($block = 0; $block <= AD_INSERTER_BLOCKS; $block ++) {
892
 
893
  foreach ($paragraph_blocks as $index => $paragraph_block) {
894
  $block_class = $debug_positions === '' && in_array ($ai_wp_data [AI_WP_DEBUG_BLOCK], $paragraph_block ['blocks']) ? ' on' : '';
895
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
896
  'id' => 'ai-toolbar-positions-'.$index,
897
  'parent' => 'ai-toolbar-positions',
898
  'title' => '<span class="ab-icon'.$block_class.'"></span>'.
903
  ($paragraph_block ['blockquote'] ? ' +[' . $no_paragraph_counting_inside . '] ' : '').
904
  ($paragraph_block ['text'] != '' ? ($paragraph_block ['text_type'] == AD_DO_NOT_CONTAIN ? ' NC ' : ' C ').' ['.htmlentities ($paragraph_block ['text']).']' : ''),
905
  'href' => set_url_parameter (AI_URL_DEBUG_POSITIONS, $paragraph_block ['blocks'][0]),
906
+ );
907
  }
908
 
909
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
910
  'id' => 'ai-toolbar-tags',
911
  'parent' => 'ai-toolbar-settings',
912
  'title' => '<span class="ab-icon'.$debug_tags_class.'"></span>Show HTML Tags',
913
  'href' => set_url_parameter (AI_URL_DEBUG_TAGS, $debug_tags),
914
+ );
915
+
916
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
917
  'id' => 'ai-toolbar-no-insertion',
918
  'parent' => 'ai-toolbar-settings',
919
  'title' => '<span class="ab-icon'.$debug_no_insertion_class.'"></span>Disable Insertion',
920
  'href' => set_url_parameter (AI_URL_DEBUG_NO_INSERTION, $debug_no_insertion),
921
+ );
922
+
923
  if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
924
  if ($ai_wp_data [AI_ADB_DETECTION]) {
925
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
926
  'id' => 'ai-toolbar-adb-status',
927
  'parent' => 'ai-toolbar-settings',
928
  'title' => '<span class="ab-icon'.$debug_ad_blocking_status_class.'"></span>Ad Blocking Status',
929
  'href' => set_url_parameter (AI_URL_DEBUG_AD_BLOCKING_STATUS, $debug_ad_blocking_status),
930
+ );
931
+
932
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
933
  'id' => 'ai-toolbar-adb',
934
  'parent' => 'ai-toolbar-settings',
935
  'title' => '<span class="ab-icon'.$debug_ad_blocking_class.'"></span>Simulate Ad Blocking',
936
  'href' => set_url_parameter (AI_URL_DEBUG_AD_BLOCKING, $debug_ad_blocking),
937
+ );
938
  }
939
  }
940
+
941
+ $ai_wp_data [AI_DEBUG_MENU_ITEMS][] = array (
942
  'id' => 'ai-toolbar-processing',
943
  'parent' => 'ai-toolbar-settings',
944
  'title' => '<span class="ab-icon'.$debug_processing_class.'"></span>Log Processing',
945
  'href' => set_url_parameter (AI_URL_DEBUG_PROCESSING, $debug_processing),
946
+ );
947
+ }
948
+
949
+ function ai_toolbar ($wp_admin_bar) {
950
+ global $ai_wp_data;
951
+
952
+ ai_toolbar_menu_items ();
953
+
954
+ foreach ($ai_wp_data [AI_DEBUG_MENU_ITEMS] as $menu_item) {
955
+ $wp_admin_bar->add_node ($menu_item);
956
+ }
957
  }
958
 
959
  function set_user () {
1717
  if ($ai_wp_data [AI_CLIENT_SIDE_INSERTION]) {
1718
  wp_add_inline_script ('ai-jquery-js', ai_get_js ('ai-insert', false));
1719
  }
1720
+
1721
+ if (get_remote_debugging () || ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0) {
1722
+ wp_enqueue_style ('dashicons');
1723
+ }
1724
  }
1725
  }
1726
 
1920
  }
1921
 
1922
  $js = str_replace ('AI_NONCE', wp_create_nonce ("adinserter_data"), $js);
1923
+ $js = str_replace ('AI_AJAXURL', admin_url ('admin-ajax.php'), $js);
1924
  $js = str_replace ('AI_SITE_URL', wp_make_link_relative (get_site_url()), $js);
1925
  if (defined ('AI_STATISTICS') && AI_STATISTICS) {
1926
  $js = str_replace ('AI_INTERNAL_TRACKING', get_internal_tracking () == AI_ENABLED ? 1 : 0, $js);
2050
  // }
2051
 
2052
  if (function_exists ('ai_admin_notices')) ai_admin_notices (); else {
2053
+ if (/*$hook_suffix == $ai_settings_page &&*/ is_super_admin () && !wp_is_mobile () && isset ($ai_wp_data [AI_DAYS_SINCE_INSTAL])) {
2054
 
2055
  $used_blocks = count (unserialize ($ai_db_options_extract [AI_EXTRACT_USED_BLOCKS]));
2056
 
2057
  $notice_option = get_option ('ai-notice-review');
2058
  if ($notice_option === false && $ai_wp_data [AI_DAYS_SINCE_INSTAL] >= 40) $notice_option = 'later';
2059
 
2060
+ if (($notice_option === false && $used_blocks >= 2 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 20 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] < 40) ||
2061
 
2062
  ($notice_option == 'later' && ($used_blocks >= 5 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 50 ||
2063
+ $used_blocks >= 2 && $ai_wp_data [AI_DAYS_SINCE_INSTAL] > 70))) {
2064
 
2065
  if ($notice_option == 'later') {
2066
  $message = "Hey, you are now using <strong>{$used_blocks} Ad Inserter</strong> code blocks.";
2480
 
2481
  if ($header_code !== null && ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
2482
  echo "<script>\n";
 
 
 
2483
  echo " jQuery(document).ready(function($) {
2484
  $('body').prepend (\"" . get_header_footer_debug_block (' Header code ', '&lt;head&gt;...&lt;/head&gt;', $header_code, true) . "\");
2485
  });
2486
  </script>\n";
2487
  }
2488
 
2489
+ if (defined ('AI_ADSENSE_OVERLAY') && ($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
2490
+ echo "<script>\n";
2491
+ echo ai_get_js ('ai-ads');
2492
+ echo "</script>\n";
2493
+ }
2494
+
2495
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_BLOCKS) != 0) {
2496
  echo "<script>
2497
  jQuery(document).ready(function($) {
4563
  .ai-debug-ad-overlay {position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #8f8; opacity: 0.6; z-index': '999999990}
4564
  .ai-auto-ads {background-color: #84f;}
4565
  .ai-no-slot {background-color: #48f;}
4566
+ .ai-debug-ad-info {position: absolute; top: 0; left: 0; overflow: hidden; width: auto; height: auto; font-family: arial; font-size: 11px; line-height: 11px; text-align: left; z-index: 999999991;}
4567
  .ai-info {display: inline-block; padding: 2px 4px;}
4568
  .ai-info-1 {background: #000; color: #fff;}
4569
  .ai-info-2 {background: #fff; color: #000;}
4570
 
4571
+ section.ai-debug-block, .ai-debug-block section {
4572
+ padding: 0;
4573
+ margin: 0;
4574
+ }
4575
  .ai-debug-code {margin: 0; padding: 0; border: 0; font-family: monospace; font-size: 12px; line-height: 13px;}
4576
 
4577
+ .ai-debug-block {border: 1px solid; line-height: 10px;}
4578
 
4579
  .ai-debug-block.ai-debug-default {border-color: #e00;}
4580
  .ai-debug-bar.ai-debug-default {background: #e00;}
4607
  .ai-debug-bar.ai-debug-ip {background: #00c5be;}
4608
 
4609
  .ai-debug-adb-hidden {visibility: hidden; display: none;}
4610
+ .ai-debug-adb-center {text-align: center; font-weight: bold; margin: 0; padding: 4px 0;}
4611
 
4612
+ .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;}
4613
 
4614
  .ai-debug-bar .ai-debug-text-left {float: left;}
4615
  .ai-debug-bar .ai-debug-text-right {float: right; padding-right: 3px;}
5714
  "name" => "",
5715
  "ignore" => "",
5716
  "check" => "",
5717
+ // "debugger" => "",
5718
  "adb" => "",
5719
  "css" => "",
5720
  "text" => "",
5766
  $block = intval ($parameters ['block']);
5767
  } elseif ($parameters ['name'] != '') {
5768
  $shortcode_name = strtolower ($parameters ['name']);
5769
+ for ($counter = 1; $counter <= AD_INSERTER_BLOCKS; $counter ++) {
5770
+ $obj = $block_object [$counter];
5771
+ $ad_name = strtolower (trim ($obj->get_ad_name()));
5772
+ if ($shortcode_name == $ad_name) {
5773
+ $block = $counter;
5774
+ break;
 
 
5775
  }
5776
  }
5777
  }
5803
  if ($parameters ['data'] != '') {
5804
  return '{'.$parameters ['data'].'}';
5805
  }
5806
+ if ($parameters ['name'] != '') {
5807
+ switch (strtolower ($parameters ['name'])) {
5808
+ case 'processing-log':
5809
+ if (/*get_remote_debugging () ||*/ ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0) {
5810
+ ob_start ();
5811
+ echo "<pre style='", AI_DEBUG_WIDGET_STYLE, "'>\n";
5812
+ ai_write_debug_info ();
5813
+ echo "</pre>";
5814
+ return ob_get_clean ();
5815
+ }
5816
+ return "";
5817
+ case 'debugging-tools':
5818
+ if (/*get_remote_debugging () ||*/ ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0) {
5819
+ ai_write_debugging_tools ();
5820
+ }
5821
+ return "";
5822
+ }
5823
  }
 
5824
  }
5825
 
5826
  $ai_last_check = AI_CHECK_SHORTCODE_ATTRIBUTES;
5941
  if ($block > AD_INSERTER_BLOCKS) $block = 1;
5942
  $sticky = isset ($instance ['sticky']) ? $instance ['sticky'] : 0;
5943
 
5944
+ if ($block == 0) $title = 'Processing Log';
5945
  elseif ($block == - 1) $title = 'Dummy Widget';
5946
+ elseif ($block == - 2) $title = 'Debugging Tools';
5947
  elseif ($block >= 1) {
5948
  $obj = $block_object [$block];
5949
 
5972
  ?>
5973
  <option value='<?php echo $block_index; ?>' <?php if ($block_index == $block) echo 'selected="selected"'; ?>><?php echo $block_index, ' - ', $obj->get_ad_name(), !$obj->get_enable_widget ()? ' - DISABLED' : ''; ?></option>
5974
  <?php } ?>
5975
+ <option value='-2' <?php if ($block == - 2) echo 'selected="selected"'; ?>>Debugging Tools</option>
5976
+ <option value='0' <?php if ($block == 0) echo 'selected="selected"'; ?>>Processing Log</option>
5977
  <option value='-1' <?php if ($block == - 1) echo 'selected="selected"'; ?>>Dummy Widget</option>
5978
  </select>
5979
  </p>
6040
  $block = isset ($instance ['block']) ? $instance ['block'] : 1;
6041
  $sticky = isset ($instance ['sticky']) ? $instance ['sticky'] : 0;
6042
 
6043
+ if ($block == 0 || $block == - 2) {
6044
+ if (/*get_remote_debugging () ||*/ ($ai_wp_data [AI_WP_USER] & AI_USER_ADMINISTRATOR) != 0) {
6045
+ ai_special_widget ($args, $instance, $block);
6046
+ }
6047
  return;
6048
  }
6049
 
6134
  }
6135
  }
6136
 
6137
+ function ai_write_debugging_tools () {
6138
+ global $ai_wp_data;
6139
+
6140
+ ai_toolbar_menu_items ();
6141
+
6142
+
6143
+ echo "<style>
6144
+
6145
+ ul.ai-debug-tools {
6146
+ list-style: none;
6147
+ background: #000;
6148
+ color: #eee;
6149
+ margin: 0;
6150
+ padding: 10px;
6151
+ font-family: -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',sans-serif;
6152
+ font-size: 14px;
6153
+ line-height: 22px;
6154
+ }
6155
+
6156
+ ul.ai-debug-tools li {
6157
+ margin: 0;
6158
+ padding: 0;
6159
+ border: 0;
6160
+ }
6161
+
6162
+ ul.ai-debug-tools a, ul.ai-debug-tools a:link, ul.ai-debug-tools a:visited {
6163
+ text-decoration: none;
6164
+ color: #aaa;
6165
+ }
6166
+
6167
+ ul.ai-debug-tools a:hover {
6168
+ color: #2d8ae0!important;
6169
+ }
6170
+
6171
+ ul.ai-debug-tools .ab-icon {
6172
+ position: relative;
6173
+ font: 400 20px/1 dashicons;
6174
+ speak: none;
6175
+ padding: 4px 0;
6176
+ -webkit-font-smoothing: antialiased;
6177
+ -moz-osx-font-smoothing: grayscale;
6178
+ background-image: none!important;
6179
+ margin-right: 6px;
6180
+ vertical-align: text-top;
6181
+ }
6182
+
6183
+ ul.ai-debug-tools .ai-debug-tools-title {
6184
+ padding-bottom: 10px;
6185
+ }
6186
+
6187
+ .ai-debug-tools-title .ab-icon:before {
6188
+ content: '\\f111';
6189
+ top: 2px;
6190
+ color: rgba(240,245,250,.6)!important;
6191
+ }
6192
+ ul.ai-debug-tools .ab-icon.on:before {
6193
+ color: #00f200!important;
6194
+ }
6195
+ .ai-debug-ai-toolbar-blocks .ab-icon:before {
6196
+ content: '\\f135';
6197
+ }
6198
+ .ai-debug-ai-toolbar-positions .ab-icon:before {
6199
+ content: '\\f207';
6200
+ }
6201
+ ul.ai-debug-tools .ai-debug-tools-positions {
6202
+ margin-left: 22px;
6203
+ }
6204
+ .ai-debug-tools-positions .ab-icon:before {
6205
+ content: '\\f522';
6206
+ }
6207
+ .ai-debug-ai-toolbar-tags .ab-icon:before {
6208
+ content: '\\f475';
6209
+ }
6210
+ .ai-debug-ai-toolbar-no-insertion .ab-icon:before {
6211
+ content: '\\f214';
6212
+ }
6213
+ .ai-debug-ai-toolbar-adb-status .ab-icon:before {
6214
+ content: '\\f223';
6215
+ }
6216
+ .ai-debug-ai-toolbar-adb .ab-icon:before {
6217
+ content: '\\f160';
6218
+ }
6219
+ .ai-debug-ai-toolbar-processing .ab-icon:before {
6220
+ content: '\\f464';
6221
+ }
6222
+ </style>
6223
+ ";
6224
+ echo '
6225
+ <ul class="ai-debug-tools">
6226
+ ';
6227
+ foreach ($ai_wp_data [AI_DEBUG_MENU_ITEMS] as $menu_item) {
6228
+ if (isset ($menu_item ['parent'])) {
6229
+ if ($menu_item ['parent'] == 'ai-toolbar-settings') {
6230
+ echo ' <li class="ai-debug-', $menu_item ['id'], '">';
6231
+ echo '<a href="', $menu_item ['href'], '">', $menu_item ['title'], '</a>';
6232
+ echo "</li>\n";
6233
+ }
6234
+ elseif ($menu_item ['parent'] == 'ai-toolbar-positions') {
6235
+ echo ' <li class="ai-debug-', $menu_item ['id'], ' ai-debug-tools-positions">';
6236
+ echo '<a href="', $menu_item ['href'], '">', $menu_item ['title'], '</a>';
6237
+ echo "</li>\n";
6238
+ }
6239
+ } else if ($menu_item ['id'] == 'ai-toolbar-settings') {
6240
+ echo ' <li class="ai-debug-', $menu_item ['id'], ' ai-debug-tools-title">';
6241
+ // echo '<a href="', $menu_item ['href'], '">', $menu_item ['title'], '</a>';
6242
+ // echo '<a href="', $menu_item ['href'], '">', str_replace (AD_INSERTER_NAME, 'Debugging', $menu_item ['title']), '</a>';
6243
+ echo '<a href="', $menu_item ['href'], '">', $menu_item ['title'], ' Debugging</a>';
6244
+ echo "</li>\n";
6245
+ }
6246
+ }
6247
+
6248
+ echo '</ul>
6249
+ ';
6250
+ }
6251
+
6252
+ function ai_special_widget ($args, $instance, $block) {
6253
  global $ai_wp_data, $ai_db_options, $block_object;
6254
 
6255
  $sticky = isset ($instance ['sticky']) ? $instance ['sticky'] : 0;
6256
 
6257
  if ($sticky) {
6258
  $ai_wp_data [AI_STICKY_WIDGETS] = true;
6259
+ ai_add_attr_data ($args ['before_widget'], 'class', 'ai-sticky-widget');
6260
+ echo $args ['before_widget'];
6261
  } else echo $args ['before_widget'];
6262
 
6263
  $title = !empty ($instance ['widget-title']) ? $instance ['widget-title'] : '';
6266
  echo $args ['before_title'], apply_filters ('widget_title', $title), $args ['after_title'];
6267
  }
6268
 
6269
+ switch ($block) {
6270
+ case 0:
6271
+ echo "<pre style='", AI_DEBUG_WIDGET_STYLE, "'>\n";
6272
+ ai_write_debug_info ();
6273
+ echo "</pre>";
6274
 
6275
+ if ($ai_wp_data [AI_CLIENT_SIDE_DETECTION]) {
6276
+ for ($viewport = 1; $viewport <= AD_INSERTER_VIEWPORTS; $viewport ++) {
6277
+ $viewport_name = get_viewport_name ($viewport);
6278
+ if ($viewport_name != '') {
6279
+ echo "<pre class='ai-viewport-" . $viewport ."' style='", AI_DEBUG_WIDGET_STYLE, "'>\n";
6280
+ echo "CLIENT-SIDE DEVICE: ", $viewport_name;
6281
+ echo "</pre>";
6282
+ }
6283
+ }
6284
  }
6285
+ break;
6286
+ case - 2:
6287
+ ai_write_debugging_tools ();
6288
+ break;
6289
  }
6290
 
6291
  echo $args ['after_widget'];
6292
  }
 
constants.php CHANGED
@@ -24,7 +24,7 @@ if (!defined( 'AD_INSERTER_NAME'))
24
  define ('AD_INSERTER_NAME', 'Ad Inserter');
25
 
26
  if (!defined( 'AD_INSERTER_VERSION'))
27
- define ('AD_INSERTER_VERSION', '2.3.5');
28
 
29
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
30
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
@@ -753,6 +753,7 @@ define ('AI_COUNT', 28);
753
  define ('AI_CLIENT_SIDE_INSERTION', 29);
754
  define ('AI_USER_AGENT', 30);
755
  define ('AI_STICK_TO_THE_CONTENT', 31);
 
756
 
757
  define ('AI_CONTEXT_NONE', 0);
758
  define ('AI_CONTEXT_CONTENT', 1);
24
  define ('AD_INSERTER_NAME', 'Ad Inserter');
25
 
26
  if (!defined( 'AD_INSERTER_VERSION'))
27
+ define ('AD_INSERTER_VERSION', '2.3.6');
28
 
29
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
30
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
753
  define ('AI_CLIENT_SIDE_INSERTION', 29);
754
  define ('AI_USER_AGENT', 30);
755
  define ('AI_STICK_TO_THE_CONTENT', 31);
756
+ define ('AI_DEBUG_MENU_ITEMS', 32);
757
 
758
  define ('AI_CONTEXT_NONE', 0);
759
  define ('AI_CONTEXT_CONTENT', 1);
css/ad-inserter.css CHANGED
@@ -1,5 +1,5 @@
1
  #ai-data {
2
- font-family: "2.3.5"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
1
  #ai-data {
2
+ font-family: "2.3.6"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
css/index.html CHANGED
@@ -1,23 +1,22 @@
1
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
  <head>
4
- <title>Ad Inserter - WordPress plugin for ad management</title>
5
  <meta name="description" content="WordPress ad management plugin for all advertising needs: AdSense, Amazon, banner rotation, sticky widgets, contextual ads, AMP, header/footer code" />
6
  </head>
7
  <body style="font-family: arial, helvetica;">
8
  <div style="width: 800px; padding: 2px 8px 6px 8px; margin: 8px 30px 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
9
  <h1 style="text-align: center;">Ad Inserter</h1>
10
- <h2 style="text-align: center;">Insert Any Code on Any WordPress Page</h2>
11
  <p style="text-align: justify;">
12
  <a href="https://wordpress.org/plugins/ad-inserter/" target="_blank">Free Ad Inserter</a> - Insert any ad or HTML/Javascript/PHP code into Wordpress. Perfect for all kinds of ads. 16 code blocks, many display options and features.
13
- Need a powerful <a href="https://adinserter.pro/" target="_blank">WordPress ad management plugin</a> and more than 64 code blocks - Ad Inserter Pro supports
14
- 64 blocks, impression and click tracking (supports also Javascript ads like AdSense), A/B testing, sticky positions, 6 viewports, import/export of plugin settings and has additional multisite support.
15
  </p>
16
  <div>
17
- <img style="display: block;margin: 0 auto;" src="https://ps.w.org/ad-inserter/assets/screenshot-5.jpg" />
18
  </div>
19
  <p>
20
- Some Ad Inserter Pro features: IP address and country lists, Scheduling between dates with fallback
21
  </p>
22
  </div>
23
  <body>
1
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
  <head>
4
+ <title>Ad Inserter - WordPress plugin for ads</title>
5
  <meta name="description" content="WordPress ad management plugin for all advertising needs: AdSense, Amazon, banner rotation, sticky widgets, contextual ads, AMP, header/footer code" />
6
  </head>
7
  <body style="font-family: arial, helvetica;">
8
  <div style="width: 800px; padding: 2px 8px 6px 8px; margin: 8px 30px 8px 0; border: 1px solid rgb(221, 221, 221); border-radius: 5px; background: #fff;">
9
  <h1 style="text-align: center;">Ad Inserter</h1>
10
+ <h2 style="text-align: center;">Insert Any Code Anywhere on Any WordPress Page</h2>
11
  <p style="text-align: justify;">
12
  <a href="https://wordpress.org/plugins/ad-inserter/" target="_blank">Free Ad Inserter</a> - Insert any ad or HTML/Javascript/PHP code into Wordpress. Perfect for all kinds of ads. 16 code blocks, many display options and features.
13
+ Ad Inserter is also a perfect <a href="https://adinserter.pro/adsense-ads" target="_blank">WordPress AdSense plugin</a> that can insert ads where other plugins fail.
 
14
  </p>
15
  <div>
16
+ <img style="display: block;margin: 0 auto;" src="https://adinserter.pro/images/pages/ad-inserter/ad-inserter-adsense-code-generator.png" />
17
  </div>
18
  <p>
19
+ AdSense code generator/editor
20
  </p>
21
  </div>
22
  <body>
includes/adsense-api.php CHANGED
@@ -1,19 +1,19 @@
1
- <?php
2
-
3
- //ini_set ('display_errors', 1);
4
- //error_reporting (E_ALL);
5
-
6
- if (($adsense_client_ids = get_option (AI_ADSENSE_CLIENT_IDS)) !== false) {
7
- define ('AI_ADSENSE_CLIENT_ID', $adsense_client_ids ['ID']);
8
- define ('AI_ADSENSE_CLIENT_SECRET', $adsense_client_ids ['SECRET']);
9
- }
10
-
11
- if (($adsense_auth_code = get_option (AI_ADSENSE_AUTH_CODE)) !== false) {
12
- define ('AI_ADSENSE_AUTHORIZATION_CODE', $adsense_auth_code);
13
- }
14
-
15
- require_once AD_INSERTER_PLUGIN_DIR.'includes/google-api/autoload.php';
16
-
17
 
18
  /**
19
  * Handles authentication and Oauth token storing.
@@ -23,8 +23,8 @@ require_once AD_INSERTER_PLUGIN_DIR.'includes/google-api/autoload.php';
23
  class adsense_api {
24
  protected $apiClient;
25
  protected $adSenseService;
26
- protected $publisherID;
27
- protected $error;
28
 
29
  public function __construct() {
30
  $this->apiClient = new Google_Client();
@@ -36,19 +36,19 @@ class adsense_api {
36
  $this->adSenseService = new Google_Service_AdSense ($this->apiClient);
37
  }
38
 
39
- public function getAuthUrl () {
40
- $this->apiClient = new Google_Client();
41
-
42
- $this->apiClient->setClientId (AI_ADSENSE_CLIENT_ID);
43
- $this->apiClient->setClientSecret (AI_ADSENSE_CLIENT_SECRET);
44
- $this->apiClient->setRedirectUri ('urn:ietf:wg:oauth:2.0:oob');
45
- $this->apiClient->setScopes (array ('https://www.googleapis.com/auth/adsense'));
46
- $this->apiClient->setAccessType ('offline');
47
-
48
- return ($this->apiClient->createAuthUrl ());
49
- }
50
-
51
-
52
  /**
53
  * Check if a token for the user is already in the db, otherwise perform
54
  * authentication.
@@ -71,23 +71,23 @@ class adsense_api {
71
  * Return the AdsenseService instance (to be used to retrieve data).
72
  * @return apiAdsenseService the authenticated apiAdsenseService instance
73
  */
74
- public function getAdSenseService () {
75
- return $this->adSenseService;
76
- }
77
-
78
- public function getAdSensePublisherID () {
79
- return $this->publisherID;
80
- }
81
-
82
- public function getError () {
83
- return $this->error;
84
- }
85
-
86
- public function isTokenValid () {
87
- $token = $this->getToken();
88
- return isset ($token);
89
- }
90
-
91
  /**
92
  * During the request, the access code might have been changed for another.
93
  * This function updates the saved token.
@@ -97,129 +97,129 @@ class adsense_api {
97
  $this->saveToken ($this->apiClient->getAccessToken());
98
  }
99
  }
100
-
101
- public function getAdUnits() {
102
- $adsense_table_data = array ();
103
- $this->error = '';
104
-
105
- try {
106
- $this->authenticate();
107
-
108
- if ($this->isTokenValid ()) {
109
-
110
- $adsense_service = $this->getAdSenseService();
111
-
112
- $adsense_adsense_accounts = $adsense_service->accounts;
113
- $adsense_adsense_adclients = $adsense_service->adclients;
114
- $adsense_adsense_adunits = $adsense_service->adunits;
115
-
116
- try {
117
- $adsense_list_accounts = $adsense_adsense_accounts->listAccounts()->getItems();
118
- $this->publisherID = $adsense_list_accounts[0]['id'];
119
-
120
- try {
121
- $adsense_list_adclients = $adsense_adsense_adclients->listAdclients()->getItems();
122
- $adsense_ad_client = NULL;
123
- foreach ($adsense_list_adclients as $adsense_list_adclient) {
124
- if ($adsense_list_adclient ['productCode'] == 'AFC') {
125
- $adsense_ad_client = $adsense_list_adclient ['id'];
126
- }
127
- }
128
-
129
- if ($adsense_ad_client) {
130
- try {
131
- $adsense_adunits = $adsense_adsense_adunits->listAdunits ($adsense_ad_client)->getItems();
132
- foreach ($adsense_adunits as $adsense_adunit) {
133
- $adsense_table_data [] = array (
134
- 'id' => $adsense_adunit->getId(),
135
- 'name' => $adsense_adunit->getName(),
136
- 'code' => $adsense_adunit->getCode(),
137
- 'type' => $adsense_adunit->getContentAdsSettings()->getType(),
138
- 'size' => preg_replace( '/SIZE_([\d]+)_([\d]+)/', '$1x$2', $adsense_adunit->getContentAdsSettings()->getSize()),
139
- 'active' => $adsense_adunit->getStatus() == 'ACTIVE',
140
- );
141
- }
142
- } catch ( Google_Service_Exception $e ) {
143
- $adsense_err = $e->getErrors();
144
- $this->error = 'AdUnits Error: ' . $adsense_err [0]['message'];
145
- }
146
- }
147
- } catch ( Google_Service_Exception $e ) {
148
- $adsense_err = $e->getErrors();
149
- $this->error = 'AdClient Error: ' . $adsense_err [0]['message'];
150
- }
151
- } catch ( Google_Service_Exception $e ) {
152
- $adsense_err = $e->getErrors();
153
- $this->error = 'Account Error: ' . $adsense_err [0]['message'];
154
- } catch ( Exception $e ) {
155
- $this->error = 'Error: ' . strip_tags ($e->getMessage());
156
- }
157
- } else {
158
- }
159
-
160
- } catch (Exception $e) {
161
- $this->error = 'AdSense Authentication failed: ' . strip_tags ($e->getMessage());
162
- }
163
-
164
- if ($this->error != '') return array ();
165
-
166
- return $adsense_table_data;
167
- }
168
-
169
- public function getAdCode ($adUnitId) {
170
- $code = '';
171
- $this->error = '';
172
-
173
- try {
174
- $this->authenticate();
175
-
176
- if ($this->isTokenValid ()) {
177
-
178
- $adsense_service = $this->getAdSenseService();
179
-
180
- $adsense_adsense_accounts = $adsense_service->accounts;
181
-
182
- try {
183
- $adsense_list_accounts = $adsense_adsense_accounts->listAccounts()->getItems();
184
- $this->publisherID = $adsense_list_accounts[0]['id'];
185
-
186
- try {
187
- $ad_code = $adsense_service->accounts_adunits->getAdCode ($this->publisherID, 'ca-'.$this->publisherID, $adUnitId);
188
- } catch ( Google_Service_Exception $e ) {
189
- $adsense_err = $e->getErrors();
190
- $this->error = 'getAdCode Error: ' . $adsense_err [0]['message'];
191
- }
192
-
193
- } catch ( Google_Service_Exception $e ) {
194
- $adsense_err = $e->getErrors();
195
- $this->error = 'Account Error: ' . $adsense_err [0]['message'];
196
- } catch ( Exception $e ) {
197
- $this->error = 'Error: ' . strip_tags ($e->getMessage());
198
- }
199
-
200
- if (isset ($ad_code->adCode)) {
201
- $code = $ad_code->adCode;
202
- }
203
-
204
- } else {
205
- }
206
-
207
- } catch (Exception $e) {
208
- $this->error = 'AdSense Authentication failed: ' . strip_tags ($e->getMessage());
209
- }
210
-
211
- if ($this->error != '') return '';
212
-
213
- return $code;
214
- }
215
-
216
  private function saveToken ($token) {
217
- if ($token != null) set_transient (AI_TRANSIENT_ADSENSE_TOKEN, $token);
218
  }
219
 
220
  private function getToken () {
221
- $token = get_transient (AI_TRANSIENT_ADSENSE_TOKEN);
222
- if ($token === false) return null; else return $token;
223
  }
224
  }
225
 
1
+ <?php
2
+
3
+ //ini_set ('display_errors', 1);
4
+ //error_reporting (E_ALL);
5
+
6
+ if (($adsense_client_ids = get_option (AI_ADSENSE_CLIENT_IDS)) !== false) {
7
+ define ('AI_ADSENSE_CLIENT_ID', $adsense_client_ids ['ID']);
8
+ define ('AI_ADSENSE_CLIENT_SECRET', $adsense_client_ids ['SECRET']);
9
+ }
10
+
11
+ if (($adsense_auth_code = get_option (AI_ADSENSE_AUTH_CODE)) !== false) {
12
+ define ('AI_ADSENSE_AUTHORIZATION_CODE', $adsense_auth_code);
13
+ }
14
+
15
+ require_once AD_INSERTER_PLUGIN_DIR.'includes/google-api/autoload.php';
16
+
17
 
18
  /**
19
  * Handles authentication and Oauth token storing.
23
  class adsense_api {
24
  protected $apiClient;
25
  protected $adSenseService;
26
+ protected $publisherID;
27
+ protected $error;
28
 
29
  public function __construct() {
30
  $this->apiClient = new Google_Client();
36
  $this->adSenseService = new Google_Service_AdSense ($this->apiClient);
37
  }
38
 
39
+ public function getAuthUrl () {
40
+ $this->apiClient = new Google_Client();
41
+
42
+ $this->apiClient->setClientId (AI_ADSENSE_CLIENT_ID);
43
+ $this->apiClient->setClientSecret (AI_ADSENSE_CLIENT_SECRET);
44
+ $this->apiClient->setRedirectUri ('urn:ietf:wg:oauth:2.0:oob');
45
+ $this->apiClient->setScopes (array ('https://www.googleapis.com/auth/adsense'));
46
+ $this->apiClient->setAccessType ('offline');
47
+
48
+ return ($this->apiClient->createAuthUrl ());
49
+ }
50
+
51
+
52
  /**
53
  * Check if a token for the user is already in the db, otherwise perform
54
  * authentication.
71
  * Return the AdsenseService instance (to be used to retrieve data).
72
  * @return apiAdsenseService the authenticated apiAdsenseService instance
73
  */
74
+ public function getAdSenseService () {
75
+ return $this->adSenseService;
76
+ }
77
+
78
+ public function getAdSensePublisherID () {
79
+ return $this->publisherID;
80
+ }
81
+
82
+ public function getError () {
83
+ return $this->error;
84
+ }
85
+
86
+ public function isTokenValid () {
87
+ $token = $this->getToken();
88
+ return isset ($token);
89
+ }
90
+
91
  /**
92
  * During the request, the access code might have been changed for another.
93
  * This function updates the saved token.
97
  $this->saveToken ($this->apiClient->getAccessToken());
98
  }
99
  }
100
+
101
+ public function getAdUnits() {
102
+ $adsense_table_data = array ();
103
+ $this->error = '';
104
+
105
+ try {
106
+ $this->authenticate();
107
+
108
+ if ($this->isTokenValid ()) {
109
+
110
+ $adsense_service = $this->getAdSenseService();
111
+
112
+ $adsense_adsense_accounts = $adsense_service->accounts;
113
+ $adsense_adsense_adclients = $adsense_service->adclients;
114
+ $adsense_adsense_adunits = $adsense_service->adunits;
115
+
116
+ try {
117
+ $adsense_list_accounts = $adsense_adsense_accounts->listAccounts()->getItems();
118
+ $this->publisherID = $adsense_list_accounts[0]['id'];
119
+
120
+ try {
121
+ $adsense_list_adclients = $adsense_adsense_adclients->listAdclients()->getItems();
122
+ $adsense_ad_client = NULL;
123
+ foreach ($adsense_list_adclients as $adsense_list_adclient) {
124
+ if ($adsense_list_adclient ['productCode'] == 'AFC') {
125
+ $adsense_ad_client = $adsense_list_adclient ['id'];
126
+ }
127
+ }
128
+
129
+ if ($adsense_ad_client) {
130
+ try {
131
+ $adsense_adunits = $adsense_adsense_adunits->listAdunits ($adsense_ad_client)->getItems();
132
+ foreach ($adsense_adunits as $adsense_adunit) {
133
+ $adsense_table_data [] = array (
134
+ 'id' => $adsense_adunit->getId(),
135
+ 'name' => $adsense_adunit->getName(),
136
+ 'code' => $adsense_adunit->getCode(),
137
+ 'type' => $adsense_adunit->getContentAdsSettings()->getType(),
138
+ 'size' => preg_replace( '/SIZE_([\d]+)_([\d]+)/', '$1x$2', $adsense_adunit->getContentAdsSettings()->getSize()),
139
+ 'active' => $adsense_adunit->getStatus() == 'ACTIVE',
140
+ );
141
+ }
142
+ } catch ( Google_Service_Exception $e ) {
143
+ $adsense_err = $e->getErrors();
144
+ $this->error = 'AdUnits Error: ' . $adsense_err [0]['message'];
145
+ }
146
+ }
147
+ } catch ( Google_Service_Exception $e ) {
148
+ $adsense_err = $e->getErrors();
149
+ $this->error = 'AdClient Error: ' . $adsense_err [0]['message'];
150
+ }
151
+ } catch ( Google_Service_Exception $e ) {
152
+ $adsense_err = $e->getErrors();
153
+ $this->error = 'Account Error: ' . $adsense_err [0]['message'];
154
+ } catch ( Exception $e ) {
155
+ $this->error = 'Error: ' . strip_tags ($e->getMessage());
156
+ }
157
+ } else {
158
+ }
159
+
160
+ } catch (Exception $e) {
161
+ $this->error = 'AdSense Authentication failed: ' . strip_tags ($e->getMessage());
162
+ }
163
+
164
+ if ($this->error != '') return array ();
165
+
166
+ return $adsense_table_data;
167
+ }
168
+
169
+ public function getAdCode ($adUnitId) {
170
+ $code = '';
171
+ $this->error = '';
172
+
173
+ try {
174
+ $this->authenticate();
175
+
176
+ if ($this->isTokenValid ()) {
177
+
178
+ $adsense_service = $this->getAdSenseService();
179
+
180
+ $adsense_adsense_accounts = $adsense_service->accounts;
181
+
182
+ try {
183
+ $adsense_list_accounts = $adsense_adsense_accounts->listAccounts()->getItems();
184
+ $this->publisherID = $adsense_list_accounts[0]['id'];
185
+
186
+ try {
187
+ $ad_code = $adsense_service->accounts_adunits->getAdCode ($this->publisherID, 'ca-'.$this->publisherID, $adUnitId);
188
+ } catch ( Google_Service_Exception $e ) {
189
+ $adsense_err = $e->getErrors();
190
+ $this->error = 'getAdCode Error: ' . $adsense_err [0]['message'];
191
+ }
192
+
193
+ } catch ( Google_Service_Exception $e ) {
194
+ $adsense_err = $e->getErrors();
195
+ $this->error = 'Account Error: ' . $adsense_err [0]['message'];
196
+ } catch ( Exception $e ) {
197
+ $this->error = 'Error: ' . strip_tags ($e->getMessage());
198
+ }
199
+
200
+ if (isset ($ad_code->adCode)) {
201
+ $code = $ad_code->adCode;
202
+ }
203
+
204
+ } else {
205
+ }
206
+
207
+ } catch (Exception $e) {
208
+ $this->error = 'AdSense Authentication failed: ' . strip_tags ($e->getMessage());
209
+ }
210
+
211
+ if ($this->error != '') return '';
212
+
213
+ return $code;
214
+ }
215
+
216
  private function saveToken ($token) {
217
+ if ($token != null) set_transient (AI_TRANSIENT_ADSENSE_TOKEN, $token);
218
  }
219
 
220
  private function getToken () {
221
+ $token = get_transient (AI_TRANSIENT_ADSENSE_TOKEN);
222
+ if ($token === false) return null; else return $token;
223
  }
224
  }
225
 
includes/editor.php CHANGED
@@ -28,7 +28,7 @@ function generate_code_editor ($block, $client_code, $process_php) {
28
  $ai_wp_data [AI_WP_DEBUGGING] = 0;
29
 
30
  $obj = $block_object [$block];
31
- $code = $obj->ai_getCode ($client_code, $process_php);
32
 
33
  wp_enqueue_script ('ai-adb-js', plugins_url ('includes/js/ad-inserter-check.js', AD_INSERTER_FILE), array (
34
  'jquery',
@@ -400,10 +400,10 @@ input[type="button"] {
400
  $error_reporting = error_reporting ();
401
  error_reporting ($error_reporting & ~E_NOTICE);
402
 
403
- _WP_Editors::enqueue_scripts();
404
- print_footer_scripts ();
405
- _WP_Editors::editor_js();
406
-
407
  error_reporting ($error_reporting);
408
 
409
  ?>
28
  $ai_wp_data [AI_WP_DEBUGGING] = 0;
29
 
30
  $obj = $block_object [$block];
31
+ $code = $obj->ai_getCode ($client_code, $process_php);
32
 
33
  wp_enqueue_script ('ai-adb-js', plugins_url ('includes/js/ad-inserter-check.js', AD_INSERTER_FILE), array (
34
  'jquery',
400
  $error_reporting = error_reporting ();
401
  error_reporting ($error_reporting & ~E_NOTICE);
402
 
403
+ _WP_Editors::enqueue_scripts();
404
+ print_footer_scripts ();
405
+ _WP_Editors::editor_js();
406
+
407
  error_reporting ($error_reporting);
408
 
409
  ?>
includes/js/ai-ads.js CHANGED
@@ -1,138 +1,139 @@
1
- var adsense_ad_names = [];
2
- var ai_preview_window = typeof ai_preview !== 'undefined';
3
-
4
- function ai_process_adsense_ads ($) {
5
- var ai_debug = typeof ai_debugging !== 'undefined';
6
- $('ins ins iframe').each (function () {
7
- var adsense_iframe = $(this);
8
- var adsense_width = adsense_iframe.attr ('width');
9
- var adsense_height = adsense_iframe.attr ('height');
10
- var adsense_iframe2 = adsense_iframe.contents().find ('iframe[allowtransparency]');
11
- var url_parameters = getAllUrlParams (adsense_iframe2.attr ('src'))
12
-
13
- if (typeof url_parameters ['client'] !== 'undefined') {
14
- var adsense_ad_client = url_parameters ['client'];
15
- var adsense_publisher_id = adsense_ad_client.replace ('ca-', '');
16
- var adsense_ad_slot = url_parameters ['slotname'];
17
- var adsense_index = url_parameters ['ifi'];
18
-
19
- if (ai_debug) console.log ('AI ADSENSE', adsense_index, adsense_ad_client, adsense_ad_slot, url_parameters ['format'], url_parameters ['w'], url_parameters ['h']);
20
-
21
- var adsense_overlay = $('<div class="ai-debug-ad-overlay"></div>');
22
-
23
- var adsense_ad_info = '';
24
- if (typeof adsense_ad_slot !== 'undefined') {
25
- var adsense_ad_name = '';
26
- if (typeof adsense_ad_names ['publisher_id'] !== 'undefined' &&
27
- adsense_ad_names ['publisher_id'] == adsense_publisher_id &&
28
- typeof adsense_ad_names [adsense_ad_slot] !== 'undefined') {
29
- adsense_ad_name = '<div class="ai-info ai-info-2">' + adsense_ad_names [adsense_ad_slot] + '</div>';
30
- }
31
- adsense_ad_info = '<div class="ai-info ai-info-1">' + adsense_ad_slot + '</div>' + adsense_ad_name;
32
- } else {
33
- var adsense_auto_ads = adsense_iframe.closest ('div.google-auto-placed').length != 0;
34
- if (adsense_auto_ads) {
35
- adsense_overlay.addClass ('ai-auto-ads');
36
- adsense_ad_info = '<div class="ai-info ai-info-1">Auto ads</div>';
37
- } else adsense_overlay.addClass ('ai-no-slot');
38
- }
39
-
40
- var adsense_info = $('<div class="ai-debug-ad-info"><div class="ai-info ai-info-1">AdSense #' + adsense_index + '</div><div class="ai-info ai-info-2">' + adsense_width + 'x' + adsense_height + '</div>' + adsense_ad_info + '</div>');
41
-
42
- adsense_iframe.after (adsense_info);
43
-
44
- if (!ai_preview_window) {
45
- adsense_iframe.after (adsense_overlay);
46
- }
47
- }
48
- });
49
- }
50
-
51
- jQuery(document).ready(function($) {
52
- var ai_debug = typeof ai_debugging !== 'undefined';
53
- var nonce = 'AI_NONCE';
54
- var adsense_data = {'ai': 1}; // dummy
55
-
56
- $.post (ajaxurl, {'action': 'ai_ajax', 'ai_check': nonce, 'adsense-ad-units': adsense_data}
57
- ).done (function (data) {
58
- if (data != '') {
59
- try {
60
- adsense_ad_names = JSON.parse (data);
61
-
62
- if (ai_debug) console.log ("AI ADSENSE DATA:", Object.keys (adsense_ad_names).length - 1, 'ad units');
63
-
64
- } catch (error) {
65
- if (ai_debug) console.log ("AI ADSENSE DATA ERROR:", data);
66
- }
67
- }
68
- }).fail (function (xhr, status, error) {
69
- if (ai_debug) console.log ("AI ADSENSE DATA ERROR:", xhr.status, xhr.statusText);
70
- }).always (function (data) {
71
- if (ai_debug) console.log ('AI ADSENSE DATA', 'END');
72
- });
73
-
74
- if (!ai_preview_window) setTimeout (function() {ai_process_adsense_ads (jQuery);}, 2000);
75
- });
76
-
77
- function getAllUrlParams (url) {
78
-
79
- // get query string from url (optional) or window
80
- var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
81
-
82
- // we'll store the parameters here
83
- var obj = {};
84
-
85
- // if query string exists
86
- if (queryString) {
87
-
88
- // stuff after # is not part of query string, so get rid of it
89
- queryString = queryString.split('#')[0];
90
-
91
- // split our query string into its component parts
92
- var arr = queryString.split('&');
93
-
94
- for (var i=0; i<arr.length; i++) {
95
- // separate the keys and the values
96
- var a = arr[i].split('=');
97
-
98
- // in case params look like: list[]=thing1&list[]=thing2
99
- var paramNum = undefined;
100
- var paramName = a[0].replace(/\[\d*\]/, function(v) {
101
- paramNum = v.slice(1,-1);
102
- return '';
103
- });
104
-
105
- // set parameter value (use 'true' if empty)
106
- var paramValue = typeof(a[1])==='undefined' ? true : a[1];
107
-
108
- // (optional) keep case consistent
109
- paramName = paramName.toLowerCase();
110
- paramValue = paramValue.toLowerCase();
111
-
112
- // if parameter name already exists
113
- if (obj[paramName]) {
114
- // convert value to array (if still string)
115
- if (typeof obj[paramName] === 'string') {
116
- obj[paramName] = [obj[paramName]];
117
- }
118
- // if no array index number specified...
119
- if (typeof paramNum === 'undefined') {
120
- // put the value on the end of the array
121
- obj[paramName].push(paramValue);
122
- }
123
- // if array index number specified...
124
- else {
125
- // put the value at that index number
126
- obj[paramName][paramNum] = paramValue;
127
- }
128
- }
129
- // if param name doesn't exist yet, set it
130
- else {
131
- obj[paramName] = paramValue;
132
- }
133
- }
134
- }
135
-
136
- return obj;
137
- }
138
-
 
1
+ var adsense_ad_names = [];
2
+ var ai_preview_window = typeof ai_preview !== 'undefined';
3
+
4
+ function ai_process_adsense_ads ($) {
5
+ var ai_debug = typeof ai_debugging !== 'undefined';
6
+ $('ins ins iframe').each (function () {
7
+ var adsense_iframe = $(this);
8
+ var adsense_width = adsense_iframe.attr ('width');
9
+ var adsense_height = adsense_iframe.attr ('height');
10
+ var adsense_iframe2 = adsense_iframe.contents().find ('iframe[allowtransparency]');
11
+ var url_parameters = getAllUrlParams (adsense_iframe2.attr ('src'))
12
+
13
+ if (typeof url_parameters ['client'] !== 'undefined') {
14
+ var adsense_ad_client = url_parameters ['client'];
15
+ var adsense_publisher_id = adsense_ad_client.replace ('ca-', '');
16
+ var adsense_ad_slot = url_parameters ['slotname'];
17
+ var adsense_index = url_parameters ['ifi'];
18
+
19
+ if (ai_debug) console.log ('AI ADSENSE', adsense_index, adsense_ad_client, adsense_ad_slot, url_parameters ['format'], url_parameters ['w'], url_parameters ['h']);
20
+
21
+ var adsense_overlay = $('<div class="ai-debug-ad-overlay"></div>');
22
+
23
+ var adsense_ad_info = '';
24
+ if (typeof adsense_ad_slot !== 'undefined') {
25
+ var adsense_ad_name = '';
26
+ if (typeof adsense_ad_names ['publisher_id'] !== 'undefined' &&
27
+ adsense_ad_names ['publisher_id'] == adsense_publisher_id &&
28
+ typeof adsense_ad_names [adsense_ad_slot] !== 'undefined') {
29
+ adsense_ad_name = '<div class="ai-info ai-info-2">' + adsense_ad_names [adsense_ad_slot] + '</div>';
30
+ }
31
+ adsense_ad_info = '<div class="ai-info ai-info-1">' + adsense_ad_slot + '</div>' + adsense_ad_name;
32
+ } else {
33
+ var adsense_auto_ads = adsense_iframe.closest ('div.google-auto-placed').length != 0;
34
+ if (adsense_auto_ads) {
35
+ adsense_overlay.addClass ('ai-auto-ads');
36
+ adsense_ad_info = '<div class="ai-info ai-info-1">Auto ads</div>';
37
+ } else adsense_overlay.addClass ('ai-no-slot');
38
+ }
39
+
40
+ var adsense_info = $('<div class="ai-debug-ad-info"><div class="ai-info ai-info-1">AdSense #' + adsense_index + '</div><div class="ai-info ai-info-2">' + adsense_width + 'x' + adsense_height + '</div>' + adsense_ad_info + '</div>');
41
+
42
+ adsense_iframe.after (adsense_info);
43
+
44
+ if (!ai_preview_window) {
45
+ adsense_iframe.after (adsense_overlay);
46
+ }
47
+ }
48
+ });
49
+ }
50
+
51
+ jQuery(document).ready(function($) {
52
+ var ai_debug = typeof ai_debugging !== 'undefined';
53
+ var ajaxurl = 'AI_AJAXURL';
54
+ var nonce = 'AI_NONCE';
55
+ var adsense_data = {'ai': 1}; // dummy
56
+
57
+ $.post (ajaxurl, {'action': 'ai_ajax', 'ai_check': nonce, 'adsense-ad-units': adsense_data}
58
+ ).done (function (data) {
59
+ if (data != '') {
60
+ try {
61
+ adsense_ad_names = JSON.parse (data);
62
+
63
+ if (ai_debug) console.log ("AI ADSENSE DATA:", Object.keys (adsense_ad_names).length - 1, 'ad units');
64
+
65
+ } catch (error) {
66
+ if (ai_debug) console.log ("AI ADSENSE DATA ERROR:", data);
67
+ }
68
+ }
69
+ }).fail (function (xhr, status, error) {
70
+ if (ai_debug) console.log ("AI ADSENSE DATA ERROR:", xhr.status, xhr.statusText);
71
+ }).always (function (data) {
72
+ if (ai_debug) console.log ('AI ADSENSE DATA', 'END');
73
+ });
74
+
75
+ if (!ai_preview_window) setTimeout (function() {ai_process_adsense_ads (jQuery);}, 2000);
76
+ });
77
+
78
+ function getAllUrlParams (url) {
79
+
80
+ // get query string from url (optional) or window
81
+ var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
82
+
83
+ // we'll store the parameters here
84
+ var obj = {};
85
+
86
+ // if query string exists
87
+ if (queryString) {
88
+
89
+ // stuff after # is not part of query string, so get rid of it
90
+ queryString = queryString.split('#')[0];
91
+
92
+ // split our query string into its component parts
93
+ var arr = queryString.split('&');
94
+
95
+ for (var i=0; i<arr.length; i++) {
96
+ // separate the keys and the values
97
+ var a = arr[i].split('=');
98
+
99
+ // in case params look like: list[]=thing1&list[]=thing2
100
+ var paramNum = undefined;
101
+ var paramName = a[0].replace(/\[\d*\]/, function(v) {
102
+ paramNum = v.slice(1,-1);
103
+ return '';
104
+ });
105
+
106
+ // set parameter value (use 'true' if empty)
107
+ var paramValue = typeof(a[1])==='undefined' ? true : a[1];
108
+
109
+ // (optional) keep case consistent
110
+ paramName = paramName.toLowerCase();
111
+ paramValue = paramValue.toLowerCase();
112
+
113
+ // if parameter name already exists
114
+ if (obj[paramName]) {
115
+ // convert value to array (if still string)
116
+ if (typeof obj[paramName] === 'string') {
117
+ obj[paramName] = [obj[paramName]];
118
+ }
119
+ // if no array index number specified...
120
+ if (typeof paramNum === 'undefined') {
121
+ // put the value on the end of the array
122
+ obj[paramName].push(paramValue);
123
+ }
124
+ // if array index number specified...
125
+ else {
126
+ // put the value at that index number
127
+ obj[paramName][paramNum] = paramValue;
128
+ }
129
+ }
130
+ // if param name doesn't exist yet, set it
131
+ else {
132
+ obj[paramName] = paramValue;
133
+ }
134
+ }
135
+ }
136
+
137
+ return obj;
138
+ }
139
+
includes/js/ai-ads.min.js CHANGED
@@ -3,7 +3,7 @@ function ai_process_adsense_ads($){var ai_debug=typeof ai_debugging!=="undefined
3
  adsense_ad_client.replace("ca-","");var adsense_ad_slot=url_parameters["slotname"];var adsense_index=url_parameters["ifi"];if(ai_debug)console.log("AI ADSENSE",adsense_index,adsense_ad_client,adsense_ad_slot,url_parameters["format"],url_parameters["w"],url_parameters["h"]);var adsense_overlay=$('<div class="ai-debug-ad-overlay"></div>');var adsense_ad_info="";if(typeof adsense_ad_slot!=="undefined"){var adsense_ad_name="";if(typeof adsense_ad_names["publisher_id"]!=="undefined"&&adsense_ad_names["publisher_id"]==
4
  adsense_publisher_id&&typeof adsense_ad_names[adsense_ad_slot]!=="undefined")adsense_ad_name='<div class="ai-info ai-info-2">'+adsense_ad_names[adsense_ad_slot]+"</div>";adsense_ad_info='<div class="ai-info ai-info-1">'+adsense_ad_slot+"</div>"+adsense_ad_name}else{var adsense_auto_ads=adsense_iframe.closest("div.google-auto-placed").length!=0;if(adsense_auto_ads){adsense_overlay.addClass("ai-auto-ads");adsense_ad_info='<div class="ai-info ai-info-1">Auto ads</div>'}else adsense_overlay.addClass("ai-no-slot")}var adsense_info=
5
  $('<div class="ai-debug-ad-info"><div class="ai-info ai-info-1">AdSense #'+adsense_index+'</div><div class="ai-info ai-info-2">'+adsense_width+"x"+adsense_height+"</div>"+adsense_ad_info+"</div>");adsense_iframe.after(adsense_info);if(!ai_preview_window)adsense_iframe.after(adsense_overlay)}})}
6
- jQuery(document).ready(function($){var ai_debug=typeof ai_debugging!=="undefined";var nonce="AI_NONCE";var adsense_data={"ai":1};$.post(ajaxurl,{"action":"ai_ajax","ai_check":nonce,"adsense-ad-units":adsense_data}).done(function(data){if(data!="")try{adsense_ad_names=JSON.parse(data);if(ai_debug)console.log("AI ADSENSE DATA:",Object.keys(adsense_ad_names).length-1,"ad units")}catch(error){if(ai_debug)console.log("AI ADSENSE DATA ERROR:",data)}}).fail(function(xhr,status,error){if(ai_debug)console.log("AI ADSENSE DATA ERROR:",
7
  xhr.status,xhr.statusText)}).always(function(data){if(ai_debug)console.log("AI ADSENSE DATA","END")});if(!ai_preview_window)setTimeout(function(){ai_process_adsense_ads(jQuery)},2E3)});
8
  function getAllUrlParams(url){var queryString=url?url.split("?")[1]:window.location.search.slice(1);var obj={};if(queryString){queryString=queryString.split("#")[0];var arr=queryString.split("&");for(var i=0;i<arr.length;i++){var a=arr[i].split("=");var paramNum=undefined;var paramName=a[0].replace(/\[\d*\]/,function(v){paramNum=v.slice(1,-1);return""});var paramValue=typeof a[1]==="undefined"?true:a[1];paramName=paramName.toLowerCase();paramValue=paramValue.toLowerCase();if(obj[paramName]){if(typeof obj[paramName]===
9
  "string")obj[paramName]=[obj[paramName]];if(typeof paramNum==="undefined")obj[paramName].push(paramValue);else obj[paramName][paramNum]=paramValue}else obj[paramName]=paramValue}}return obj};
3
  adsense_ad_client.replace("ca-","");var adsense_ad_slot=url_parameters["slotname"];var adsense_index=url_parameters["ifi"];if(ai_debug)console.log("AI ADSENSE",adsense_index,adsense_ad_client,adsense_ad_slot,url_parameters["format"],url_parameters["w"],url_parameters["h"]);var adsense_overlay=$('<div class="ai-debug-ad-overlay"></div>');var adsense_ad_info="";if(typeof adsense_ad_slot!=="undefined"){var adsense_ad_name="";if(typeof adsense_ad_names["publisher_id"]!=="undefined"&&adsense_ad_names["publisher_id"]==
4
  adsense_publisher_id&&typeof adsense_ad_names[adsense_ad_slot]!=="undefined")adsense_ad_name='<div class="ai-info ai-info-2">'+adsense_ad_names[adsense_ad_slot]+"</div>";adsense_ad_info='<div class="ai-info ai-info-1">'+adsense_ad_slot+"</div>"+adsense_ad_name}else{var adsense_auto_ads=adsense_iframe.closest("div.google-auto-placed").length!=0;if(adsense_auto_ads){adsense_overlay.addClass("ai-auto-ads");adsense_ad_info='<div class="ai-info ai-info-1">Auto ads</div>'}else adsense_overlay.addClass("ai-no-slot")}var adsense_info=
5
  $('<div class="ai-debug-ad-info"><div class="ai-info ai-info-1">AdSense #'+adsense_index+'</div><div class="ai-info ai-info-2">'+adsense_width+"x"+adsense_height+"</div>"+adsense_ad_info+"</div>");adsense_iframe.after(adsense_info);if(!ai_preview_window)adsense_iframe.after(adsense_overlay)}})}
6
+ jQuery(document).ready(function($){var ai_debug=typeof ai_debugging!=="undefined";var ajaxurl="AI_AJAXURL";var nonce="AI_NONCE";var adsense_data={"ai":1};$.post(ajaxurl,{"action":"ai_ajax","ai_check":nonce,"adsense-ad-units":adsense_data}).done(function(data){if(data!="")try{adsense_ad_names=JSON.parse(data);if(ai_debug)console.log("AI ADSENSE DATA:",Object.keys(adsense_ad_names).length-1,"ad units")}catch(error){if(ai_debug)console.log("AI ADSENSE DATA ERROR:",data)}}).fail(function(xhr,status,error){if(ai_debug)console.log("AI ADSENSE DATA ERROR:",
7
  xhr.status,xhr.statusText)}).always(function(data){if(ai_debug)console.log("AI ADSENSE DATA","END")});if(!ai_preview_window)setTimeout(function(){ai_process_adsense_ads(jQuery)},2E3)});
8
  function getAllUrlParams(url){var queryString=url?url.split("?")[1]:window.location.search.slice(1);var obj={};if(queryString){queryString=queryString.split("#")[0];var arr=queryString.split("&");for(var i=0;i<arr.length;i++){var a=arr[i].split("=");var paramNum=undefined;var paramName=a[0].replace(/\[\d*\]/,function(v){paramNum=v.slice(1,-1);return""});var paramValue=typeof a[1]==="undefined"?true:a[1];paramName=paramName.toLowerCase();paramValue=paramValue.toLowerCase();if(obj[paramName]){if(typeof obj[paramName]===
9
  "string")obj[paramName]=[obj[paramName]];if(typeof paramNum==="undefined")obj[paramName].push(paramValue);else obj[paramName][paramNum]=paramValue}else obj[paramName]=paramValue}}return obj};
includes/phpQuery.php CHANGED
@@ -280,7 +280,7 @@ class DOMDocumentWrapper {
280
  // @see http://www.w3.org/International/O-HTTP-charset
281
  if (! $documentCharset) {
282
  $documentCharset = 'ISO-8859-1';
283
- $addDocumentCharset = true;
284
  }
285
  // Should be careful here, still need 'magic encoding detection' since lots of pages have other 'default encoding'
286
  // Worse, some pages can have mixed encodings... we'll try not to worry about that
@@ -567,7 +567,7 @@ class DOMDocumentWrapper {
567
  // if ($fake === false)
568
  // throw new Exception("Error loading documentFragment markup");
569
  // else
570
- // $return = array_merge($return,
571
  // $this->import($fake->root->childNodes)
572
  // );
573
  // } else {
@@ -650,7 +650,7 @@ class DOMDocumentWrapper {
650
  .'<fake xmlns="http://www.w3.org/1999/xhtml">'.$markup.'</fake>');
651
  $fragment->root = $fragment->document->firstChild->nextSibling;
652
  } else {
653
- $fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?><fake>'.$markup.'</fake>');
654
  $fragment->root = $fragment->document->firstChild;
655
  }
656
  } else {
@@ -969,24 +969,24 @@ interface ICallbackNamed {
969
  }
970
  /**
971
  * Callback class introduces currying-like pattern.
972
- *
973
  * Example:
974
  * function foo($param1, $param2, $param3) {
975
  * var_dump($param1, $param2, $param3);
976
  * }
977
- * $fooCurried = new Callback('foo',
978
- * 'param1 is now statically set',
979
  * new CallbackParam, new CallbackParam
980
  * );
981
  * phpQuery::callbackRun($fooCurried,
982
  * array('param2 value', 'param3 value'
983
  * );
984
- *
985
- * Callback class is supported in all phpQuery methods which accepts callbacks.
986
  *
987
  * @link http://code.google.com/p/phpquery/wiki/Callbacks#Param_Structures
988
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
989
- *
990
  * @TODO??? return fake forwarding function created via create_function
991
  * @TODO honor paramStructure
992
  */
@@ -995,7 +995,7 @@ class Callback
995
  public $callback = null;
996
  public $params = null;
997
  protected $name;
998
- public function __construct($callback, $param1 = null, $param2 = null,
999
  $param3 = null) {
1000
  $params = func_get_args();
1001
  $params = array_slice($params, 1);
@@ -1024,11 +1024,11 @@ class Callback
1024
  }
1025
  /**
1026
  * Shorthand for new Callback(create_function(...), ...);
1027
- *
1028
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
1029
  */
1030
  class CallbackBody extends Callback {
1031
- public function __construct($paramList, $code, $param1 = null, $param2 = null,
1032
  $param3 = null) {
1033
  $params = func_get_args();
1034
  $params = array_slice($params, 2);
@@ -1038,7 +1038,7 @@ class CallbackBody extends Callback {
1038
  }
1039
  /**
1040
  * Callback type which on execution returns reference passed during creation.
1041
- *
1042
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
1043
  */
1044
  class CallbackReturnReference extends Callback
@@ -1060,7 +1060,7 @@ class CallbackReturnReference extends Callback
1060
  }
1061
  /**
1062
  * Callback type which on execution returns value passed during creation.
1063
- *
1064
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
1065
  */
1066
  class CallbackReturnValue extends Callback
@@ -1087,7 +1087,7 @@ class CallbackReturnValue extends Callback
1087
  }
1088
  /**
1089
  * CallbackParameterToReference can be used when we don't really want a callback,
1090
- * only parameter passed to it. CallbackParameterToReference takes first
1091
  * parameter's value and passes it to reference.
1092
  *
1093
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
@@ -1095,7 +1095,7 @@ class CallbackReturnValue extends Callback
1095
  class CallbackParameterToReference extends Callback {
1096
  /**
1097
  * @param $reference
1098
- * @TODO implement $paramIndex;
1099
  * param index choose which callback param will be passed to reference
1100
  */
1101
  public function __construct(&$reference){
@@ -2230,7 +2230,8 @@ class phpQueryObject
2230
  /**
2231
  * @access private
2232
  */
2233
- protected function __pseudoClassParam($paramsString) {
 
2234
  // TODO;
2235
  }
2236
  /**
@@ -2456,7 +2457,8 @@ class phpQueryObject
2456
  'type' => $data ? 'POST' : 'GET',
2457
  'data' => $data,
2458
  'complete' => $callback,
2459
- 'success' => array($this, '__loadSuccess')
 
2460
  );
2461
  phpQuery::ajax($ajax);
2462
  return $this;
@@ -2466,7 +2468,8 @@ class phpQueryObject
2466
  * @param $html
2467
  * @return unknown_type
2468
  */
2469
- public function __loadSuccess($html) {
 
2470
  if ($this->_loadSelector) {
2471
  $html = phpQuery::newDocument($html)->find($this->_loadSelector);
2472
  unset($this->_loadSelector);
@@ -2994,7 +2997,7 @@ class phpQueryObject
2994
  }
2995
  /**
2996
  * Enter description here...
2997
- *
2998
  * @param $code
2999
  * @return unknown_type
3000
  */
@@ -3005,7 +3008,7 @@ class phpQueryObject
3005
  }
3006
  /**
3007
  * Enter description here...
3008
- *
3009
  * @param $code
3010
  * @return unknown_type
3011
  */
@@ -4034,7 +4037,7 @@ class phpQueryObject
4034
  }
4035
  /**
4036
  * Enter description here...
4037
- *
4038
  * @param <type> $key
4039
  * @param <type> $value
4040
  */
@@ -4051,7 +4054,7 @@ class phpQueryObject
4051
  }
4052
  /**
4053
  * Enter description here...
4054
- *
4055
  * @param <type> $key
4056
  */
4057
  public function removeData($key) {
@@ -4206,7 +4209,8 @@ class phpQueryObject
4206
  .($node->getAttribute('id')
4207
  ? '#'.$node->getAttribute('id'):'')
4208
  .($node->getAttribute('class')
4209
- ? '.'.join('.', split(' ', $node->getAttribute('class'))):'')
 
4210
  .($node->getAttribute('name')
4211
  ? '[name="'.$node->getAttribute('name').'"]':'')
4212
  .($node->getAttribute('value') && strpos($node->getAttribute('value'), '<'.'?php') === false
@@ -4267,21 +4271,24 @@ class phpQueryObject
4267
  $debug = phpQuery::$debug;
4268
  phpQuery::$debug = false;
4269
  foreach($this->stack() as $node)
4270
- $output .= $this->__dumpTree($node);
 
4271
  phpQuery::$debug = $debug;
4272
  print $html
4273
  ? nl2br(str_replace(' ', '&nbsp;', $output))
4274
  : $output;
4275
  return $this;
4276
  }
4277
- private function __dumpTree($node, $intend = 0) {
 
4278
  $whois = $this->whois($node);
4279
  $return = '';
4280
  if ($whois)
4281
  $return .= str_repeat(' - ', $intend).$whois."\n";
4282
  if (isset($node->childNodes))
4283
  foreach($node->childNodes as $chNode)
4284
- $return .= $this->__dumpTree($chNode, $intend+1);
 
4285
  return $return;
4286
  }
4287
  /**
@@ -4392,8 +4399,8 @@ if (!function_exists('mb_substr_count'))
4392
  */
4393
  abstract class phpQuery {
4394
  /**
4395
- * XXX: Workaround for mbstring problems
4396
- *
4397
  * @var bool
4398
  */
4399
  public static $mbstringSupport = true;
@@ -4743,13 +4750,13 @@ abstract class phpQuery {
4743
  $content = preg_replace_callback(
4744
  $regex,
4745
  create_function('$m',
4746
- 'return $m[1].$m[2].$m[3]."<?php "
4747
  .str_replace(
4748
  array("%20", "%3E", "%09", "&#10;", "&#9;", "%7B", "%24", "%7D", "%22", "%5B", "%5D"),
4749
  array(" ", ">", " ", "\n", " ", "{", "$", "}", \'"\', "[", "]"),
4750
  htmlspecialchars_decode($m[4])
4751
  )
4752
- ." ?>".$m[5].$m[2];'
4753
  ),
4754
  $content
4755
  );
@@ -5635,8 +5642,11 @@ abstract class phpQuery {
5635
  if (isset($document->data[$id][$name]))
5636
  unset($document->data[$id][$name]);
5637
  $name = null;
5638
- foreach($document->data[$id] as $name)
5639
- break;
 
 
 
5640
  if (! $name)
5641
  self::removeData($node, $name, $documentID);
5642
  } else {
@@ -5699,4 +5709,4 @@ set_include_path(
5699
  phpQuery::$plugins = new phpQueryPlugins();
5700
  // include bootstrap file (personal library config)
5701
  if (file_exists(dirname(__FILE__).'/phpQuery/bootstrap.php'))
5702
- require_once dirname(__FILE__).'/phpQuery/bootstrap.php';
280
  // @see http://www.w3.org/International/O-HTTP-charset
281
  if (! $documentCharset) {
282
  $documentCharset = 'ISO-8859-1';
283
+ $addDocumentCharset = true;
284
  }
285
  // Should be careful here, still need 'magic encoding detection' since lots of pages have other 'default encoding'
286
  // Worse, some pages can have mixed encodings... we'll try not to worry about that
567
  // if ($fake === false)
568
  // throw new Exception("Error loading documentFragment markup");
569
  // else
570
+ // $return = array_merge($return,
571
  // $this->import($fake->root->childNodes)
572
  // );
573
  // } else {
650
  .'<fake xmlns="http://www.w3.org/1999/xhtml">'.$markup.'</fake>');
651
  $fragment->root = $fragment->document->firstChild->nextSibling;
652
  } else {
653
+ $fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?'.'><fake>'.$markup.'</fake>');
654
  $fragment->root = $fragment->document->firstChild;
655
  }
656
  } else {
969
  }
970
  /**
971
  * Callback class introduces currying-like pattern.
972
+ *
973
  * Example:
974
  * function foo($param1, $param2, $param3) {
975
  * var_dump($param1, $param2, $param3);
976
  * }
977
+ * $fooCurried = new Callback('foo',
978
+ * 'param1 is now statically set',
979
  * new CallbackParam, new CallbackParam
980
  * );
981
  * phpQuery::callbackRun($fooCurried,
982
  * array('param2 value', 'param3 value'
983
  * );
984
+ *
985
+ * Callback class is supported in all phpQuery methods which accepts callbacks.
986
  *
987
  * @link http://code.google.com/p/phpquery/wiki/Callbacks#Param_Structures
988
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
989
+ *
990
  * @TODO??? return fake forwarding function created via create_function
991
  * @TODO honor paramStructure
992
  */
995
  public $callback = null;
996
  public $params = null;
997
  protected $name;
998
+ public function __construct($callback, $param1 = null, $param2 = null,
999
  $param3 = null) {
1000
  $params = func_get_args();
1001
  $params = array_slice($params, 1);
1024
  }
1025
  /**
1026
  * Shorthand for new Callback(create_function(...), ...);
1027
+ *
1028
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
1029
  */
1030
  class CallbackBody extends Callback {
1031
+ public function __construct($paramList, $code, $param1 = null, $param2 = null,
1032
  $param3 = null) {
1033
  $params = func_get_args();
1034
  $params = array_slice($params, 2);
1038
  }
1039
  /**
1040
  * Callback type which on execution returns reference passed during creation.
1041
+ *
1042
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
1043
  */
1044
  class CallbackReturnReference extends Callback
1060
  }
1061
  /**
1062
  * Callback type which on execution returns value passed during creation.
1063
+ *
1064
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
1065
  */
1066
  class CallbackReturnValue extends Callback
1087
  }
1088
  /**
1089
  * CallbackParameterToReference can be used when we don't really want a callback,
1090
+ * only parameter passed to it. CallbackParameterToReference takes first
1091
  * parameter's value and passes it to reference.
1092
  *
1093
  * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
1095
  class CallbackParameterToReference extends Callback {
1096
  /**
1097
  * @param $reference
1098
+ * @TODO implement $paramIndex;
1099
  * param index choose which callback param will be passed to reference
1100
  */
1101
  public function __construct(&$reference){
2230
  /**
2231
  * @access private
2232
  */
2233
+ // protected function __pseudoClassParam($paramsString) {
2234
+ protected function ai_pseudoClassParam($paramsString) {
2235
  // TODO;
2236
  }
2237
  /**
2457
  'type' => $data ? 'POST' : 'GET',
2458
  'data' => $data,
2459
  'complete' => $callback,
2460
+ // 'success' => array($this, '__loadSuccess')
2461
+ 'success' => array($this, 'ai_loadSuccess')
2462
  );
2463
  phpQuery::ajax($ajax);
2464
  return $this;
2468
  * @param $html
2469
  * @return unknown_type
2470
  */
2471
+ // public function __loadSuccess($html) {
2472
+ public function ai_loadSuccess($html) {
2473
  if ($this->_loadSelector) {
2474
  $html = phpQuery::newDocument($html)->find($this->_loadSelector);
2475
  unset($this->_loadSelector);
2997
  }
2998
  /**
2999
  * Enter description here...
3000
+ *
3001
  * @param $code
3002
  * @return unknown_type
3003
  */
3008
  }
3009
  /**
3010
  * Enter description here...
3011
+ *
3012
  * @param $code
3013
  * @return unknown_type
3014
  */
4037
  }
4038
  /**
4039
  * Enter description here...
4040
+ *
4041
  * @param <type> $key
4042
  * @param <type> $value
4043
  */
4054
  }
4055
  /**
4056
  * Enter description here...
4057
+ *
4058
  * @param <type> $key
4059
  */
4060
  public function removeData($key) {
4209
  .($node->getAttribute('id')
4210
  ? '#'.$node->getAttribute('id'):'')
4211
  .($node->getAttribute('class')
4212
+ // ? '.'.join('.', split(' ', $node->getAttribute('class'))):'')
4213
+ ? '.'.join('.', preg_split('/ /', $node->getAttribute('class'))):'')
4214
  .($node->getAttribute('name')
4215
  ? '[name="'.$node->getAttribute('name').'"]':'')
4216
  .($node->getAttribute('value') && strpos($node->getAttribute('value'), '<'.'?php') === false
4271
  $debug = phpQuery::$debug;
4272
  phpQuery::$debug = false;
4273
  foreach($this->stack() as $node)
4274
+ // $output .= $this->__dumpTree($node);
4275
+ $output .= $this->ai_dumpTree($node);
4276
  phpQuery::$debug = $debug;
4277
  print $html
4278
  ? nl2br(str_replace(' ', '&nbsp;', $output))
4279
  : $output;
4280
  return $this;
4281
  }
4282
+ // private function __dumpTree($node, $intend = 0) {
4283
+ private function ai_dumpTree($node, $intend = 0) {
4284
  $whois = $this->whois($node);
4285
  $return = '';
4286
  if ($whois)
4287
  $return .= str_repeat(' - ', $intend).$whois."\n";
4288
  if (isset($node->childNodes))
4289
  foreach($node->childNodes as $chNode)
4290
+ // $return .= $this->__dumpTree($chNode, $intend+1);
4291
+ $return .= $this->ai_dumpTree($chNode, $intend+1);
4292
  return $return;
4293
  }
4294
  /**
4399
  */
4400
  abstract class phpQuery {
4401
  /**
4402
+ * XXX: Workaround for mbstring problems
4403
+ *
4404
  * @var bool
4405
  */
4406
  public static $mbstringSupport = true;
4750
  $content = preg_replace_callback(
4751
  $regex,
4752
  create_function('$m',
4753
+ 'return $m[1].$m[2].$m[3]."<?php "
4754
  .str_replace(
4755
  array("%20", "%3E", "%09", "&#10;", "&#9;", "%7B", "%24", "%7D", "%22", "%5B", "%5D"),
4756
  array(" ", ">", " ", "\n", " ", "{", "$", "}", \'"\', "[", "]"),
4757
  htmlspecialchars_decode($m[4])
4758
  )
4759
+ ." ?".">".$m[5].$m[2];'
4760
  ),
4761
  $content
4762
  );
5642
  if (isset($document->data[$id][$name]))
5643
  unset($document->data[$id][$name]);
5644
  $name = null;
5645
+ // foreach($document->data[$id] as $name)
5646
+ // break;
5647
+ foreach($document->data[$id] as $name) {
5648
+ break;
5649
+ }
5650
  if (! $name)
5651
  self::removeData($node, $name, $documentID);
5652
  } else {
5709
  phpQuery::$plugins = new phpQueryPlugins();
5710
  // include bootstrap file (personal library config)
5711
  if (file_exists(dirname(__FILE__).'/phpQuery/bootstrap.php'))
5712
+ require_once dirname(__FILE__).'/phpQuery/bootstrap.php';
includes/preview.php CHANGED
@@ -1579,7 +1579,7 @@ select {
1579
  <?php elseif ($block != 0) : ?>
1580
  <p id="p1">This is a preview of the saved code block between dummy paragraphs. It shows the code with the alignment and style as it is set for this code block. Highlight button highlights background, wrapping div margin and code area.</p>
1581
  <?php else : ?>
1582
- <p id="p1">This is a preview of AdSense ad block between dummy paragraphs. AdSense ad code was loaded from your AdSense account. The ad block is displayed on a dummy page so it may be blank (no ads).</p>
1583
  <?php endif; ?>
1584
 
1585
  <?php if (!$sticky) padding_margin_code ($close_button, $class, $wrapper_css, $block_code); ?>
1579
  <?php elseif ($block != 0) : ?>
1580
  <p id="p1">This is a preview of the saved code block between dummy paragraphs. It shows the code with the alignment and style as it is set for this code block. Highlight button highlights background, wrapping div margin and code area.</p>
1581
  <?php else : ?>
1582
+ <p id="p1">This is a preview of AdSense ad block between dummy paragraphs. AdSense ad code was loaded from your AdSense account. The ad block is displayed on a dummy page so it may be blank (no ads). Click on the Highlight button to highlight ad block.</p>
1583
  <?php endif; ?>
1584
 
1585
  <?php if (!$sticky) padding_margin_code ($close_button, $class, $wrapper_css, $block_code); ?>
js/ad-inserter.js CHANGED
@@ -1,4 +1,4 @@
1
- var javascript_version = "2.3.5";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
1
+ var javascript_version = "2.3.6";
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.3
9
- Stable tag: 2.3.4
10
  License: GPLv3
11
 
12
  Insert and manage ads: AdSense, Amazon, banners, ad rotation, sticky ad widgets, shortcodes, AMP, PHP, HTML, CSS, form, tracking, header, footer code
@@ -49,7 +49,7 @@ Check <a href="https://affiliate-program.amazon.com/help/topic/t405" target="_bl
49
 
50
  * 16 code (ad) blocks
51
  * [AdSense](https://adinserter.pro/adsense-ads) integration
52
- * Syntax highlighting editor
53
  * Code preview with visual CSS editor
54
  * Automatically inserts ads on posts and pages
55
  * Insert before or after post
@@ -87,7 +87,7 @@ Check <a href="https://affiliate-program.amazon.com/help/topic/t405" target="_bl
87
  * Ad rotation (server-side and client-side - works with caching)
88
  * Ad blocking detection - popup message, page redirection
89
  * Desktop/mobile device detection (server-side and client-side - works with caching)
90
- * Black/White-list categories, tags, taxonomies, post IDs, urls, url query parameters, cookies, referers
91
  * Easy copying and pasting code blocks or settings using internal clipboard
92
  * Simple troubleshooting with many debugging functions
93
  * Function to visualize inserted code blocks
@@ -245,10 +245,24 @@ activate it and then click "Enter License Key" and enter license key you got in
245
  If you deactivate and delete Ad Inserter, the settings will stay in the database. To completely remove the plugin and settings do the following:
246
 
247
  1. Go to Ad Inserter general settings (tab *) and click on Reset All Settings
248
- 1. Go to Ad Inserter general settings (tab *) and click on Clear All Statistics Data
249
  2. Deactivate Ad Inserter
250
  3. Delete Ad Inserter plugin
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
 
253
  **Online Documentation**
254
 
@@ -273,7 +287,7 @@ Positive reviews are a great way to show your appreciation for my work. Besides
273
 
274
  Support the advancement of this plugin:
275
 
276
- * Write a nice <a href="https://wordpress.org/support/plugin/ad-inserter/reviews/">review</a>
277
  * <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4">Donate</a>
278
  * Buy license for <a href="http://adinserter.pro/" target="_blank">Ad Inserter Pro</a>
279
 
@@ -416,7 +430,7 @@ Change the title tag according to the theme style.
416
 
417
  = I like the plugin. How can I support it? =
418
 
419
- * Write a nice <a href="https://wordpress.org/support/plugin/ad-inserter/reviews/">review</a>
420
  * <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4">Donate</a>
421
  * Buy the license for <a href="http://adinserter.pro/" target="_blank">Ad Inserter Pro</a>
422
 
@@ -623,6 +637,11 @@ AD CODE RIGHT
623
 
624
  == Changelog ==
625
 
 
 
 
 
 
626
  = 2.3.5 =
627
  - Added display of header and footer code in Label blocks debugging function
628
  - Added AdSense ad overlays in Label blocks debugging function (experimental)
@@ -700,6 +719,11 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
700
 
701
  == Upgrade Notice ==
702
 
 
 
 
 
 
703
  = 2.3.5 =
704
  Added display of header and footer code in Label blocks debugging function;
705
  Added AdSense ad overlays in Label blocks debugging function (experimental);
6
  Requires at least: 4.0
7
  Tested up to: 4.9
8
  Requires PHP: 5.3
9
+ Stable tag: 2.3.5
10
  License: GPLv3
11
 
12
  Insert and manage ads: AdSense, Amazon, banners, ad rotation, sticky ad widgets, shortcodes, AMP, PHP, HTML, CSS, form, tracking, header, footer code
49
 
50
  * 16 code (ad) blocks
51
  * [AdSense](https://adinserter.pro/adsense-ads) integration
52
+ * Syntax highlighting [editor](https://adinserter.pro/code-editing)
53
  * Code preview with visual CSS editor
54
  * Automatically inserts ads on posts and pages
55
  * Insert before or after post
87
  * Ad rotation (server-side and client-side - works with caching)
88
  * Ad blocking detection - popup message, page redirection
89
  * Desktop/mobile device detection (server-side and client-side - works with caching)
90
+ * [Black/White-list](https://adinserter.pro/lists) categories, tags, taxonomies, post IDs, urls, url query parameters, cookies, referers
91
  * Easy copying and pasting code blocks or settings using internal clipboard
92
  * Simple troubleshooting with many debugging functions
93
  * Function to visualize inserted code blocks
245
  If you deactivate and delete Ad Inserter, the settings will stay in the database. To completely remove the plugin and settings do the following:
246
 
247
  1. Go to Ad Inserter general settings (tab *) and click on Reset All Settings
248
+ 1. Go to Ad Inserter general settings (tab *) and click on Clear All Statistics Data (Pro only)
249
  2. Deactivate Ad Inserter
250
  3. Delete Ad Inserter plugin
251
 
252
+ *Please Note*
253
+
254
+ Ad Inserter inserts only the code you configure (blocks 1 - 16, Header, Footer). The code you see is the code that will be inserted (+ some internal scripts for plugin features).
255
+ When you deactivate Ad Inserter it can�t insert anything as WordPress doesn't call it. Please check page source code before you make any conclusion.
256
+ Of course, if you configure code block with some javacript ad code, then this code may generate ads. But please, don't blame the plugin for this.
257
+ You can also use Ad Inserter to insert code for AdSense Auto ads on each page (usually in the header). However, **the exact placement of ads will be done by the ad code, not Ad Inserter!**
258
+ [https://adinserter.pro/adsense-ads#auto-ads](https://adinserter.pro/adsense-ads#auto-ads)
259
+
260
+ The easiest way to check Ad Inserter code blocks is to use **Label blocks** debugging function:
261
+ [https://adinserter.pro/documentation#debugging](https://adinserter.pro/documentation#debugging)
262
+
263
+ When you deactivate Ad Inserter it can�t insert anything - WordPress doesn't call it. If you still see some ads that were inserted by Ad Inserter, make sure you have cleared all the caches.
264
+ If you still see those ads after you have disabled Ad Inserter and cleared all the caches, then the ads were not inserted by Ad Inserter.
265
+
266
 
267
  **Online Documentation**
268
 
287
 
288
  Support the advancement of this plugin:
289
 
290
+ * Write a short <a href="https://wordpress.org/support/plugin/ad-inserter/reviews/">review</a>
291
  * <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4">Donate</a>
292
  * Buy license for <a href="http://adinserter.pro/" target="_blank">Ad Inserter Pro</a>
293
 
430
 
431
  = I like the plugin. How can I support it? =
432
 
433
+ * Write a short <a href="https://wordpress.org/support/plugin/ad-inserter/reviews/">review</a>
434
  * <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LHGZEMRTR7WB4">Donate</a>
435
  * Buy the license for <a href="http://adinserter.pro/" target="_blank">Ad Inserter Pro</a>
436
 
637
 
638
  == Changelog ==
639
 
640
+ = 2.3.6 =
641
+ - Added widget for debugging tools
642
+ - Fix for AdSense ad overlays not displayed with some themes
643
+ - Few minor bug fixes, cosmetic changes and code improvements
644
+
645
  = 2.3.5 =
646
  - Added display of header and footer code in Label blocks debugging function
647
  - Added AdSense ad overlays in Label blocks debugging function (experimental)
719
 
720
  == Upgrade Notice ==
721
 
722
+ = 2.3.6 =
723
+ Added widget for debugging tools;
724
+ Fix for AdSense ad overlays not displayed with some themes;
725
+ Few minor bug fixes, cosmetic changes and code improvements;
726
+
727
  = 2.3.5 =
728
  Added display of header and footer code in Label blocks debugging function;
729
  Added AdSense ad overlays in Label blocks debugging function (experimental);
settings.php CHANGED
@@ -2661,11 +2661,9 @@ function code_block_list () {
2661
  $new_options = $current_options;
2662
 
2663
  $error = false;
2664
- $block_indexes = array ();
2665
  foreach ($blocks_org as $index => $block) {
2666
  $new_block = $blocks_new [$index];
2667
  if ($block >= 1 && $block <= AD_INSERTER_BLOCKS && $new_block >= 1 && $new_block <= AD_INSERTER_BLOCKS) {
2668
- $block_indexes [$block] = $index;
2669
  $new_options [$block] = $current_options [$new_block];
2670
  } else $error = true;
2671
  }
@@ -2676,9 +2674,9 @@ function code_block_list () {
2676
  if (isset ($new_options [$block][AI_OPTION_FALLBACK])) {
2677
  $ai_option_fallback = $new_options [$block][AI_OPTION_FALLBACK];
2678
  if ($ai_option_fallback != '')
2679
- foreach ($blocks_org as $index => $org_block) {
2680
  if ($ai_option_fallback == $org_block) {
2681
- $new_options [$block][AI_OPTION_FALLBACK] = $blocks_new [$index];
2682
  }
2683
  }
2684
  }
@@ -2686,9 +2684,9 @@ function code_block_list () {
2686
  if (isset ($new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT])) {
2687
  $ai_option_adb_block_replacement = $new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT];
2688
  if ($ai_option_adb_block_replacement != '')
2689
- foreach ($blocks_org as $index => $org_block) {
2690
  if ($ai_option_adb_block_replacement == $org_block) {
2691
- $new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT] = $blocks_new [$index];
2692
  }
2693
  }
2694
  }
@@ -2703,25 +2701,43 @@ function code_block_list () {
2703
  if (isset ($ai_widget ['block'])) {
2704
  $widget_block = $ai_widget ['block'];
2705
  if ($widget_block >= 1 && $widget_block <= AD_INSERTER_BLOCKS) {
2706
- if (isset ($blocks_org [$block_indexes [$widget_block]])) {
2707
- $new_block = $blocks_new [$block_indexes [$widget_block]];
2708
- $ai_widgets [$widget_index]['block'] = $new_block;
 
 
2709
  }
2710
  }
2711
  }
2712
  }
2713
  update_option ('widget_ai_widget', $ai_widgets);
2714
 
2715
- // Update statistics
2716
- $query = 'UPDATE ' . AI_STATISTICS_DB_TABLE . ' SET block= CASE ';
2717
 
2718
- foreach ($blocks_org as $index => $block) {
2719
- $new_block = $blocks_new [$index];
2720
- $query .= "WHEN block= $block THEN $new_block ";
2721
- }
2722
- $query .= 'ELSE block END';
 
 
 
 
 
 
 
 
 
 
 
 
 
2723
 
2724
- $update = $wpdb->query ($query);
 
 
 
2725
  }
2726
  }
2727
  }
@@ -3331,7 +3347,7 @@ function sidebar_pro () {
3331
  <ul>
3332
  <li>64 code (ad) blocks</li>
3333
  <li><a href="https://adinserter.pro/adsense-ads#integration" class="simple-link" target="_blank">AdSense Integration</a></li>
3334
- <li>Syntax highlighting editor</li>
3335
  <li><a href="http://adinserter.pro/documentation#code-preview" class="simple-link" target="_blank">Code preview</a> with visual CSS editor</li>
3336
  <li>Simple user interface - all settings on a single page</li>
3337
  <li><a href="http://adinserter.pro/documentation#automatic-insertion" class="simple-link" target="_blank">Automatic insertion</a> before or after post / content / <a href="http://adinserter.pro/documentation#paragraphs" class="simple-link" target="_blank">paragraph</a> / excerpt</li>
2661
  $new_options = $current_options;
2662
 
2663
  $error = false;
 
2664
  foreach ($blocks_org as $index => $block) {
2665
  $new_block = $blocks_new [$index];
2666
  if ($block >= 1 && $block <= AD_INSERTER_BLOCKS && $new_block >= 1 && $new_block <= AD_INSERTER_BLOCKS) {
 
2667
  $new_options [$block] = $current_options [$new_block];
2668
  } else $error = true;
2669
  }
2674
  if (isset ($new_options [$block][AI_OPTION_FALLBACK])) {
2675
  $ai_option_fallback = $new_options [$block][AI_OPTION_FALLBACK];
2676
  if ($ai_option_fallback != '')
2677
+ foreach ($blocks_new as $index => $org_block) {
2678
  if ($ai_option_fallback == $org_block) {
2679
+ $new_options [$block][AI_OPTION_FALLBACK] = $blocks_org [$index];
2680
  }
2681
  }
2682
  }
2684
  if (isset ($new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT])) {
2685
  $ai_option_adb_block_replacement = $new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT];
2686
  if ($ai_option_adb_block_replacement != '')
2687
+ foreach ($blocks_new as $index => $org_block) {
2688
  if ($ai_option_adb_block_replacement == $org_block) {
2689
+ $new_options [$block][AI_OPTION_ADB_BLOCK_REPLACEMENT] = $blocks_org [$index];
2690
  }
2691
  }
2692
  }
2701
  if (isset ($ai_widget ['block'])) {
2702
  $widget_block = $ai_widget ['block'];
2703
  if ($widget_block >= 1 && $widget_block <= AD_INSERTER_BLOCKS) {
2704
+ foreach ($blocks_new as $index => $org_block) {
2705
+ if ($widget_block == $org_block) {
2706
+ $ai_widgets [$widget_index]['block'] = $blocks_org [$index];
2707
+ break;
2708
+ }
2709
  }
2710
  }
2711
  }
2712
  }
2713
  update_option ('widget_ai_widget', $ai_widgets);
2714
 
2715
+ if (defined ('AI_STATISTICS') && AI_STATISTICS) {
2716
+ // Update statistics - two passes to avoid duplicate entries
2717
 
2718
+ $offset = 1000;
2719
+
2720
+ // Lock table to prevent updates of old blocks
2721
+ $query = 'LOCK TABLES ' . AI_STATISTICS_DB_TABLE . ' WRITE;';
2722
+ $update = $wpdb->query ($query);
2723
+
2724
+ // Pass 1 - new blocks with offset
2725
+ $query = 'UPDATE ' . AI_STATISTICS_DB_TABLE . ' SET block= CASE ';
2726
+ foreach ($blocks_new as $index => $org_block) {
2727
+ $new_block = $blocks_org [$index] + $offset;
2728
+ $query .= "WHEN block= $org_block THEN $new_block ";
2729
+ }
2730
+ $query .= 'ELSE block END;';
2731
+ $update = $wpdb->query ($query);
2732
+
2733
+ // Pass 2 - remove offset
2734
+ $query = 'UPDATE ' . AI_STATISTICS_DB_TABLE . " SET block = block - $offset WHERE block >= $offset;";
2735
+ $update = $wpdb->query ($query);
2736
 
2737
+ // Unlock table
2738
+ $query = 'UNLOCK TABLES;';
2739
+ $update = $wpdb->query ($query);
2740
+ }
2741
  }
2742
  }
2743
  }
3347
  <ul>
3348
  <li>64 code (ad) blocks</li>
3349
  <li><a href="https://adinserter.pro/adsense-ads#integration" class="simple-link" target="_blank">AdSense Integration</a></li>
3350
+ <li>Syntax highlighting <a href="https://adinserter.pro/code-editing" class="simple-link" target="_blank">editor</a></li>
3351
  <li><a href="http://adinserter.pro/documentation#code-preview" class="simple-link" target="_blank">Code preview</a> with visual CSS editor</li>
3352
  <li>Simple user interface - all settings on a single page</li>
3353
  <li><a href="http://adinserter.pro/documentation#automatic-insertion" class="simple-link" target="_blank">Automatic insertion</a> before or after post / content / <a href="http://adinserter.pro/documentation#paragraphs" class="simple-link" target="_blank">paragraph</a> / excerpt</li>