Ad Injection - Version 1.1.0.5

Version Description

  • New block ads by referring keyword/URL feature.
  • Load tags in batches to reduce memory used when displaying main settings screen. Will help people with lots of tags.
  • Fix for <!--randomad--> tag.
  • Move tags/categories/authors/ids filters to separate area of UI.
Download this release

Release Info

Developer reviewmylife
Plugin Icon wp plugin Ad Injection
Version 1.1.0.5
Comparing to
See all releases

Code changes from version 1.1.0.4 to 1.1.0.5

Files changed (6) hide show
  1. ad-injection-admin.php +39 -24
  2. ad-injection.php +29 -19
  3. adinj-sev.js +56 -6
  4. adshow.php +47 -12
  5. readme.txt +14 -1
  6. ui-tab-main.php +72 -34
ad-injection-admin.php CHANGED
@@ -121,7 +121,6 @@ function extract_text_args($name, &$ops, $start=NULL, $end=NULL, $save_path_stem
121
  // so be careful if adding any new ones - they might not exist yet, but could
122
  // still be referenced by adshow.
123
  function adinj_write_config_file(){
124
- $ops = adinj_options();
125
  if (!adinj_mfunc_mode()) return;
126
 
127
  $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false';
@@ -130,19 +129,11 @@ function adinj_write_config_file(){
130
  $block_ips = adinj_ticked('block_ips')?'true':'false';
131
  $ip_list = adinj_quote_list('blocked_ips');
132
 
133
- // TODO
134
  $block_keywords = adinj_ticked('block_keywords')?'true':'false';
135
  $keyword_list = adinj_quote_list('blocked_keywords');
136
 
137
  $debug_mode = adinj_ticked('debug_mode')?'true':'false';
138
 
139
- // TODO remove these from config file later...
140
- $legacy_funcs = '
141
- function adinj_config_add_tags_rnd($ad) { return ""; }
142
- function adinj_config_add_tags_top($ad) { return ""; }
143
- function adinj_config_add_tags_bottom($ad) { return ""; }
144
- ';
145
-
146
  $config = <<<CONFIG
147
  <?php
148
  /*
@@ -157,15 +148,11 @@ function adinj_config_search_engine_referrers() { return array($referrer_list);
157
  function adinj_config_block_ips() { return $block_ips; }
158
  function adinj_config_blocked_ips() { return array($ip_list); }
159
 
160
- //TODO not yet implemented
161
  function adinj_config_block_keywords() { return $block_keywords; }
162
  function adinj_config_blocked_keywords() { return array($blocked_keywords); }
163
 
164
  function adinj_config_debug_mode() { return $debug_mode; }
165
 
166
- // Don't use these - they will be deleted soon
167
- $legacy_funcs
168
-
169
  ?>
170
  CONFIG;
171
 
@@ -348,7 +335,7 @@ function adinj_top_message_box(){
348
 
349
  } else if (!isset($_GET['tab'])){
350
  echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
351
- echo "29th August 2011: Lots of small new features and fixes in this update. I've added more options for selecting where random ads start; tags to allow ad positions to be hardcoded in selected posts; a separate 'older than' option for the widget ads; and more. See the changelog for more details. Please contact me ASAP if you spot any bugs, or odd behaviour via the ".'<a href="'.adinj_feedback_url().'" target="_new">quick feedback form</a>.';
352
  echo '</strong></p></div>';
353
  }
354
  }
@@ -788,24 +775,35 @@ function adinj_condition_table($name, $description, $type, $ops, $dropdown_field
788
 
789
  <?php
790
  if ($type == 'category') {
791
- $categories = get_categories();
792
- foreach ($categories as $cat) {
 
793
  $nicename = rawurldecode($cat->category_nicename);
794
  echo '<option value="'.$nicename.'">'.$nicename.' ('.$cat->category_count.')</option>';
795
  }
796
- } else if ($type == 'tag') {
797
- $tags = get_tags();
798
- foreach ($tags as $tag) {
799
- $slug = rawurldecode($tag->slug);
800
- echo '<option value="'.$slug.'">'.$slug.' ('.$tag->count.')</option>';
 
 
 
 
 
 
 
 
801
  }
802
  } else if ($type == 'author') {
803
  $authors = adinj_get_authors();
804
- foreach ($authors as $author) {
 
805
  $login = $author->user_login;
806
  $displayname = $author->display_name;
807
  echo '<option value="'.$login.'">'.$login.' ('.$displayname.')</option>';
808
  }
 
809
  } else {
810
  echo 'ADINJ DEBUG Type not defined: ' . $type;
811
  }?>
@@ -823,6 +821,21 @@ function adinj_condition_table($name, $description, $type, $ops, $dropdown_field
823
  <?php
824
  }
825
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
826
  // TODO Currently gets all users
827
  function adinj_get_authors(){
828
  global $wpdb;
@@ -1548,14 +1561,16 @@ function adinj_default_options(){
1548
  'ad_insertion_mode' => 'mfunc',
1549
  'sevisitors_only' => 'off',
1550
  'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search.',
1551
- 'block_keywords' => 'off', //TODO change to blocked referrers?
1552
- 'blocked_keywords' => '', //TODO
 
1553
  'block_ips' => 'off',
1554
  'blocked_ips' => '',
1555
  // ui main tab
1556
  'ui_global_hide' => 'false',
1557
  'ui_adsettings_hide' => 'false',
1558
  'ui_adverts_hide' => 'false',
 
1559
  'ui_restrictions_hide' => 'false',
1560
  'ui_docsquickstart_hide' => 'false',
1561
  'ui_testads_hide' => 'false',
121
  // so be careful if adding any new ones - they might not exist yet, but could
122
  // still be referenced by adshow.
123
  function adinj_write_config_file(){
 
124
  if (!adinj_mfunc_mode()) return;
125
 
126
  $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false';
129
  $block_ips = adinj_ticked('block_ips')?'true':'false';
130
  $ip_list = adinj_quote_list('blocked_ips');
131
 
 
132
  $block_keywords = adinj_ticked('block_keywords')?'true':'false';
133
  $keyword_list = adinj_quote_list('blocked_keywords');
134
 
135
  $debug_mode = adinj_ticked('debug_mode')?'true':'false';
136
 
 
 
 
 
 
 
 
137
  $config = <<<CONFIG
138
  <?php
139
  /*
148
  function adinj_config_block_ips() { return $block_ips; }
149
  function adinj_config_blocked_ips() { return array($ip_list); }
150
 
 
151
  function adinj_config_block_keywords() { return $block_keywords; }
152
  function adinj_config_blocked_keywords() { return array($blocked_keywords); }
153
 
154
  function adinj_config_debug_mode() { return $debug_mode; }
155
 
 
 
 
156
  ?>
157
  CONFIG;
158
 
335
 
336
  } else if (!isset($_GET['tab'])){
337
  echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
338
+ echo "5th September 2011: New block ads by referrer feature - an example use would be to treat people who arrive at your site after searching for your site by name as direct visitors and block them from seeing ads. Load tags in batches to reduce memory usage for blogs with lots of tags. Plus other minor fixes. <font color='red'>Beta testers for 1.2.0.0 release</font> - If you are interested in testing the new 1.2.0.0 release a few days early contact me via the link at the end of this paragraph and I'll send you a zip when it is ready for testing. Thanks! Please contact me ASAP if you spot any bugs, or odd behaviour via the ".'<a href="'.adinj_feedback_url().'" target="_new">quick feedback form</a>.';
339
  echo '</strong></p></div>';
340
  }
341
  }
775
 
776
  <?php
777
  if ($type == 'category') {
778
+ $categories = get_categories();
779
+ $cat = NULL;
780
+ foreach ($categories as &$cat) {
781
  $nicename = rawurldecode($cat->category_nicename);
782
  echo '<option value="'.$nicename.'">'.$nicename.' ('.$cat->category_count.')</option>';
783
  }
784
+ unset ($cat);
785
+ } else if ($type == 'tag') {
786
+ /*s$testarray = array();
787
+ for ($i=0;$i<549999;++$i){ $testarray[$i] = 'test'; }*/
788
+
789
+ // A lot of blogs have large (1000+) tags. Loading this many tags at once can cause an OOM
790
+ // error. Break up tag loading into chunks to reduce memory usage.
791
+ $tagcount = 0;
792
+ $tagquantity = 100;
793
+ while (true){
794
+ $more = adinj_print_tags($tagquantity, $tagcount);
795
+ $tagcount += $tagquantity;
796
+ if (!$more) break;
797
  }
798
  } else if ($type == 'author') {
799
  $authors = adinj_get_authors();
800
+ $author = NULL;
801
+ foreach ($authors as &$author) {
802
  $login = $author->user_login;
803
  $displayname = $author->display_name;
804
  echo '<option value="'.$login.'">'.$login.' ('.$displayname.')</option>';
805
  }
806
+ unset ($authors);
807
  } else {
808
  echo 'ADINJ DEBUG Type not defined: ' . $type;
809
  }?>
821
  <?php
822
  }
823
 
824
+ function adinj_print_tags($quantity, $offset){
825
+ $tags = get_tags(array('number' => $quantity, 'offset' => $offset));
826
+ if (count($tags) == 0) return false;
827
+ $tag = NULL;
828
+ foreach ($tags as &$tag) {
829
+ $slug = rawurldecode($tag->slug);
830
+ echo '<option value="'.$slug.'">'.$slug.' ('.$tag->count.')</option>';
831
+ }
832
+ unset ($tag);
833
+ if (count($tags) < $quantity) {
834
+ return false;
835
+ }
836
+ return true;
837
+ }
838
+
839
  // TODO Currently gets all users
840
  function adinj_get_authors(){
841
  global $wpdb;
1561
  'ad_insertion_mode' => 'mfunc',
1562
  'sevisitors_only' => 'off',
1563
  'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search.',
1564
+ 'block_keywords' => 'off',
1565
+ 'blocked_keywords' => '',
1566
+ 'block_ads_for_hours' => '24',
1567
  'block_ips' => 'off',
1568
  'blocked_ips' => '',
1569
  // ui main tab
1570
  'ui_global_hide' => 'false',
1571
  'ui_adsettings_hide' => 'false',
1572
  'ui_adverts_hide' => 'false',
1573
+ 'ui_filters_hide' => 'false',
1574
  'ui_restrictions_hide' => 'false',
1575
  'ui_docsquickstart_hide' => 'false',
1576
  'ui_testads_hide' => 'false',
ad-injection.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Ad Injection
4
  Plugin URI: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
5
  Description: Injects any advert (e.g. AdSense) into your WordPress posts or widget area. Restrict who sees the ads by post length, age, referrer or IP. Cache compatible.
6
- Version: 1.1.0.4
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
@@ -32,7 +32,8 @@ define('ADINJ_NO_CONFIG_FILE', 1);
32
  // 14 = template ads
33
  // 15 = remove duplicate 'Disabled' option from top/bottom ad section
34
  // 16 = after paragraph options, older option for widget
35
- define('ADINJ_DB_VERSION', 16);
 
36
 
37
  // Files
38
  // TODO will these paths work on windows?
@@ -97,17 +98,26 @@ function adinj_option($option){
97
  function adinj_print_referrers_hook(){
98
  // TODO can re-enable this check once the widget ads are factored in.
99
  //if (adinj_ads_completely_disabled_from_page()) return;
100
- if (adinj_ticked('sevisitors_only')){
101
- $referrer_list = adinj_quote_list('ad_referrers');
 
 
102
  echo <<<SCRIPT
 
103
  <script type="text/javascript">
104
  // Ad Injection plugin
105
- var adinj_referrers = new Array($referrer_list);
106
- adinj_searchenginevisitor();
107
- </script>
108
 
109
  SCRIPT;
110
- }
 
 
 
 
 
 
 
 
 
111
  }
112
 
113
  function adinj_quote_list($option){
@@ -134,7 +144,7 @@ function adinj_quote_list($option){
134
  function adinj_addsevjs_hook(){
135
  // TODO can re-enable this check once the widget ads are factored in.
136
  //if (adinj_ads_completely_disabled_from_page()) return;
137
- if (!adinj_ticked('sevisitors_only')) return;
138
  // Put the search engine detection / cookie setting script in the footer
139
  wp_enqueue_script('adinj_sev', WP_PLUGIN_URL.'/ad-injection/adinj-sev.js', NULL, NULL, true);
140
  }
@@ -412,7 +422,7 @@ function adinj($content, $message){
412
  }
413
  return $content."
414
  <!--
415
- [ADINJ DEBUG]
416
  $message
417
  \$adinj_total_top_ads_used=$adinj_total_top_ads_used
418
  \$adinj_total_random_ads_used=$adinj_total_random_ads_used
@@ -424,7 +434,7 @@ posttype=$posttype
424
  currentdate=$currentdate ($currentday)
425
  postdate=$postdate ($postday)
426
  injection mode=$mode
427
- //-->\n";
428
  }
429
 
430
  function adinj_excluded_by_tick_box($prefix){
@@ -678,8 +688,8 @@ function adinj_content_hook($content){
678
 
679
  # Ad sandwich mode
680
  if(is_page() || is_single()){
681
- if(stripos($content, "<!--adsandwich-->") !== false) return adinj($ad_include.adinj_ad_code_top().$content.adinj_ad_code_bottom(), "Ads=adsandwich");
682
- if(stripos($content, "<!--adfooter-->") !== false) return adinj($content.$ad_include.adinj_ad_code_bottom(), "Ads=adfooter");
683
  }
684
 
685
  $length = 0;
@@ -721,17 +731,17 @@ function adinj_content_hook($content){
721
 
722
  if ($ad_include !== "") $content = $ad_include.$content;
723
 
724
- $num_rand_ads_to_insert = adinj_num_rand_ads_to_insert($length);
725
- if ($num_rand_ads_to_insert <= 0) return adinj($content, "no random ads on this post");
726
- $ad = adinj_ad_code_random();
727
- if (empty($ad)) return adinj($content, "no random ad defined");
728
-
729
  if(stripos($content, "<!--randomad-->") !== false){
730
  if ($debug_on) $debug .= "\nrandom ad position(s) fixed by 'randomad' tag";
731
- $content = str_replace('<!--randomad-->', $ad, $content);
732
  return adinj($content, "Fixed random ads" . $debug);
733
  }
734
 
 
 
 
 
 
735
  if (!$debug_on) $debugtags=false;
736
 
737
  $adstart_override = false;
3
  Plugin Name: Ad Injection
4
  Plugin URI: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
5
  Description: Injects any advert (e.g. AdSense) into your WordPress posts or widget area. Restrict who sees the ads by post length, age, referrer or IP. Cache compatible.
6
+ Version: 1.1.0.5
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
32
  // 14 = template ads
33
  // 15 = remove duplicate 'Disabled' option from top/bottom ad section
34
  // 16 = after paragraph options, older option for widget
35
+ // 17 = block ads for days
36
+ define('ADINJ_DB_VERSION', 17);
37
 
38
  // Files
39
  // TODO will these paths work on windows?
98
  function adinj_print_referrers_hook(){
99
  // TODO can re-enable this check once the widget ads are factored in.
100
  //if (adinj_ads_completely_disabled_from_page()) return;
101
+ $sevisitors = adinj_ticked('sevisitors_only');
102
+ $block = adinj_ticked('block_keywords');
103
+ if (!$sevisitors && !$block) return;
104
+
105
  echo <<<SCRIPT
106
+
107
  <script type="text/javascript">
108
  // Ad Injection plugin
 
 
 
109
 
110
  SCRIPT;
111
+
112
+ $ops = adinj_options();
113
+ $referrer_list = adinj_quote_list('ad_referrers');
114
+ $blocked_list = adinj_quote_list('blocked_keywords');
115
+ $blocked_hours = $ops['block_ads_for_hours'];
116
+ if ($sevisitors) echo "var adinj_referrers = new Array($referrer_list);\n";
117
+ if ($block) echo "var adinj_blocked_referrers = new Array($blocked_list);\n";
118
+ if ($block) echo "var adinj_blocked_hours = $blocked_hours;\n";
119
+ echo "adinj_check_referrer();\n";
120
+ echo "</script>\n";
121
  }
122
 
123
  function adinj_quote_list($option){
144
  function adinj_addsevjs_hook(){
145
  // TODO can re-enable this check once the widget ads are factored in.
146
  //if (adinj_ads_completely_disabled_from_page()) return;
147
+ if (!adinj_ticked('sevisitors_only') && !adinj_ticked('block_keywords')) return;
148
  // Put the search engine detection / cookie setting script in the footer
149
  wp_enqueue_script('adinj_sev', WP_PLUGIN_URL.'/ad-injection/adinj-sev.js', NULL, NULL, true);
150
  }
422
  }
423
  return $content."
424
  <!--
425
+ ADINJ DEBUG
426
  $message
427
  \$adinj_total_top_ads_used=$adinj_total_top_ads_used
428
  \$adinj_total_random_ads_used=$adinj_total_random_ads_used
434
  currentdate=$currentdate ($currentday)
435
  postdate=$postdate ($postday)
436
  injection mode=$mode
437
+ -->\n";
438
  }
439
 
440
  function adinj_excluded_by_tick_box($prefix){
688
 
689
  # Ad sandwich mode
690
  if(is_page() || is_single()){
691
+ if(stripos($content, "<!--adsandwich-->") !== false) return adinj($ad_include.adinj_ad_code_top().$content.adinj_ad_code_bottom(), "Ads=adsandwich" . $debug);
692
+ if(stripos($content, "<!--adfooter-->") !== false) return adinj($content.$ad_include.adinj_ad_code_bottom(), "Ads=adfooter" . $debug);
693
  }
694
 
695
  $length = 0;
731
 
732
  if ($ad_include !== "") $content = $ad_include.$content;
733
 
 
 
 
 
 
734
  if(stripos($content, "<!--randomad-->") !== false){
735
  if ($debug_on) $debug .= "\nrandom ad position(s) fixed by 'randomad' tag";
736
+ $content = str_replace('<!--randomad-->', adinj_ad_code_random(), $content);
737
  return adinj($content, "Fixed random ads" . $debug);
738
  }
739
 
740
+ $num_rand_ads_to_insert = adinj_num_rand_ads_to_insert($length);
741
+ if ($num_rand_ads_to_insert <= 0) return adinj($content, "no random ads on this post" . $debug);
742
+ $ad = adinj_ad_code_random();
743
+ if (empty($ad)) return adinj($content, "no random ad defined" . $debug);
744
+
745
  if (!$debug_on) $debugtags=false;
746
 
747
  $adstart_override = false;
adinj-sev.js CHANGED
@@ -3,15 +3,23 @@ Part of the Ad Injection plugin for WordPress
3
  http://www.reviewmylife.co.uk/blog/
4
  */
5
 
 
 
 
 
 
 
 
6
  // Based on code from
7
  // http://www.scratch99.com/2008/09/avoid-smart-pricing-show-adsense-only-to-search-engine-visitors/
8
  function adinj_searchenginevisitor(){
9
  if (adinj_searchEngineCookieSet()){
10
  return true;
11
  }
12
- var searchengines = adinj_searchengines();
13
- for (var i = 0; i <= searchengines.length-1; i++) {
14
- if (document.referrer.indexOf(searchengines[i])!== -1) {
 
15
  var expiry = new Date();
16
  expiry.setTime(expiry.getTime() + 1000*60*60); // 1 hour
17
  document.cookie = "adinj=1; expires=" + expiry.toGMTString() + "; path=/; ";
@@ -21,12 +29,47 @@ function adinj_searchenginevisitor(){
21
  return false;
22
  }
23
 
24
- function adinj_searchengines(){
25
  if (typeof adinj_referrers != 'undefined'){
26
  return adinj_referrers;
27
  } else {
28
- document.write("<!--ADINJ DEBUG: couldn't find adinj_referrers value. Using defaults.//-->");
29
- return new Array('.google.', '.bing.', '.yahoo.', '.ask.', 'search?', 'search.', '/search/');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
  }
32
 
@@ -38,3 +81,10 @@ function adinj_searchEngineCookieSet() {
38
  return false;
39
  }
40
 
 
 
 
 
 
 
 
3
  http://www.reviewmylife.co.uk/blog/
4
  */
5
 
6
+ function adinj_check_referrer(){
7
+ if (adinj_blocked()){
8
+ return;
9
+ }
10
+ adinj_searchenginevisitor();
11
+ }
12
+
13
  // Based on code from
14
  // http://www.scratch99.com/2008/09/avoid-smart-pricing-show-adsense-only-to-search-engine-visitors/
15
  function adinj_searchenginevisitor(){
16
  if (adinj_searchEngineCookieSet()){
17
  return true;
18
  }
19
+ var referrers = adinj_allowed_referrers_setting();
20
+ var length = referrers.length;
21
+ for (var i=0; i<length; ++i) {
22
+ if (document.referrer.indexOf(referrers[i])!==-1) {
23
  var expiry = new Date();
24
  expiry.setTime(expiry.getTime() + 1000*60*60); // 1 hour
25
  document.cookie = "adinj=1; expires=" + expiry.toGMTString() + "; path=/; ";
29
  return false;
30
  }
31
 
32
+ function adinj_allowed_referrers_setting(){
33
  if (typeof adinj_referrers != 'undefined'){
34
  return adinj_referrers;
35
  } else {
36
+ document.write("<!--ADINJ DEBUG: couldn't find adinj_referrers value. Using defaults.-->");
37
+ return new Array('.google.', '.bing.', '.yahoo.', '.ask.', 'search?', 'search.');
38
+ }
39
+ }
40
+
41
+ function adinj_blocked(){
42
+ if (adinj_blockedCookieSet()){
43
+ return true;
44
+ }
45
+ var blocked = adinj_blocked_referrers_setting();
46
+ var length = blocked.length;
47
+ for (var i=0; i<length; ++i) {
48
+ if (document.referrer.indexOf(blocked[i])!==-1){
49
+ var expiry = new Date();
50
+ expiry.setTime(expiry.getTime() + 1000*60*60*adinj_blocked_hours_setting());
51
+ document.cookie = "adinjblocked=1; expires=" + expiry.toGMTString() + "; path=/; ";
52
+ return true;
53
+ }
54
+ }
55
+ return false;
56
+ }
57
+
58
+ function adinj_blocked_referrers_setting(){
59
+ if (typeof adinj_blocked_referrers != 'undefined'){
60
+ return adinj_blocked_referrers;
61
+ } else {
62
+ document.write("<!--ADINJ DEBUG: couldn't find adinj_blocked_referrers value. Using default empty array.-->");
63
+ return new Array();
64
+ }
65
+ }
66
+
67
+ function adinj_blocked_hours_setting(){
68
+ if (typeof adinj_blocked_hours != 'undefined'){
69
+ return adinj_blocked_hours;
70
+ } else {
71
+ document.write("<!--ADINJ DEBUG: couldn't find adinj_blocked_hours value. Using default value.-->");
72
+ return 24; //hours
73
  }
74
  }
75
 
81
  return false;
82
  }
83
 
84
+ function adinj_blockedCookieSet() {
85
+ var results = document.cookie.match('(^|;) ?adinjblocked=([^;]*)(;|$)');
86
+ if(results){
87
+ return true;
88
+ }
89
+ return false;
90
+ }
adshow.php CHANGED
@@ -22,13 +22,13 @@ if (!function_exists('adshow_functions_exist')){
22
  // and so that a problem doesn't disable the whole website.
23
  function adshow_functions_exist(){
24
  if (!defined('ADINJ_NO_CONFIG_FILE')){
25
- if (!adshow_functions_exist_impl('adinj_config_add_tags_rnd')){ return false; } //TODO delete
26
- if (!adshow_functions_exist_impl('adinj_config_add_tags_top')){ return false; } //TODO delete
27
- if (!adshow_functions_exist_impl('adinj_config_add_tags_bottom')){ return false; } //TODO delete
28
  if (!adshow_functions_exist_impl('adinj_config_sevisitors_only')){ return false; }
29
  if (!adshow_functions_exist_impl('adinj_config_search_engine_referrers')){ return false; }
30
- //if (!adshow_functions_exist_impl('adinj_config_block_ips')){ return false; } // TODO enable
31
  if (!adshow_functions_exist_impl('adinj_config_blocked_ips')){ return false; }
 
 
 
32
  if (!adshow_functions_exist_impl('adinj_config_debug_mode')){ return false; }
33
  }
34
  return true;
@@ -52,7 +52,7 @@ function adinj_config_search_engine_referrers() {
52
  return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
53
  }
54
 
55
- function adinj_config_block_ips() { // TODO use this
56
  return adinj_ticked('block_ips');
57
  }
58
 
@@ -61,6 +61,20 @@ function adinj_config_blocked_ips() {
61
  return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
62
  }
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  function adinj_config_debug_mode() {
65
  return adinj_ticked('debug_mode');
66
  }
@@ -215,6 +229,10 @@ if (!function_exists('adshow_fromasearchengine')){
215
  function adshow_fromasearchengine(){
216
  if (!adshow_functions_exist()){ return false; }
217
 
 
 
 
 
218
  $referrer = $_SERVER['HTTP_REFERER'];
219
  $searchengines = adinj_config_search_engine_referrers();
220
  foreach ($searchengines as $se) {
@@ -222,9 +240,25 @@ function adshow_fromasearchengine(){
222
  return true;
223
  }
224
  }
225
- // Also return true if the visitor has recently come from a search engine
226
- // and has the adinj cookie set.
227
- return ($_COOKIE["adinj"]==1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
  }
230
 
@@ -241,10 +275,11 @@ if (!function_exists('adshow_show_adverts')){
241
  function adshow_show_adverts(){
242
  if (!adshow_functions_exist()){ return false; }
243
 
244
- if (adshow_blocked_ip()) return "blockedip";
245
- if (adinj_config_sevisitors_only()){
246
- if (!adshow_fromasearchengine()) return "referrer";
247
- }
 
248
  return true;
249
  }
250
  }
22
  // and so that a problem doesn't disable the whole website.
23
  function adshow_functions_exist(){
24
  if (!defined('ADINJ_NO_CONFIG_FILE')){
 
 
 
25
  if (!adshow_functions_exist_impl('adinj_config_sevisitors_only')){ return false; }
26
  if (!adshow_functions_exist_impl('adinj_config_search_engine_referrers')){ return false; }
27
+ if (!adshow_functions_exist_impl('adinj_config_block_ips')){ return false; }
28
  if (!adshow_functions_exist_impl('adinj_config_blocked_ips')){ return false; }
29
+ if (!adshow_functions_exist_impl('adinj_config_block_keywords')){ return false; }
30
+ if (!adshow_functions_exist_impl('adinj_config_blocked_keywords')){ return false; }
31
+ //if (!adshow_functions_exist_impl('adinj_config_block_hours')){ return false; }
32
  if (!adshow_functions_exist_impl('adinj_config_debug_mode')){ return false; }
33
  }
34
  return true;
52
  return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
53
  }
54
 
55
+ function adinj_config_block_ips() {
56
  return adinj_ticked('block_ips');
57
  }
58
 
61
  return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
62
  }
63
 
64
+ function adinj_config_block_keywords() {
65
+ return adinj_ticked('block_keywords');
66
+ }
67
+
68
+ function adinj_config_blocked_keywords() {
69
+ $list = adinj_quote_list('blocked_keywords');
70
+ return preg_split("/[,'\s]+/", $list, -1, PREG_SPLIT_NO_EMPTY);
71
+ }
72
+
73
+ function adinj_config_block_hours() {
74
+ $ops = adinj_options();
75
+ return $ops['block_ads_for_hours'];
76
+ }
77
+
78
  function adinj_config_debug_mode() {
79
  return adinj_ticked('debug_mode');
80
  }
229
  function adshow_fromasearchengine(){
230
  if (!adshow_functions_exist()){ return false; }
231
 
232
+ // return true if the visitor has recently come from a search engine
233
+ // and has the adinj cookie set.
234
+ if ($_COOKIE["adinj"]==1) return true;
235
+
236
  $referrer = $_SERVER['HTTP_REFERER'];
237
  $searchengines = adinj_config_search_engine_referrers();
238
  foreach ($searchengines as $se) {
240
  return true;
241
  }
242
  }
243
+ return false;
244
+ }
245
+ }
246
+
247
+ if (!function_exists('adshow_blocked_referrer')){
248
+ function adshow_blocked_referrer(){
249
+ if (!adshow_functions_exist()){ return false; }
250
+
251
+ // true if blocked cookie is set
252
+ if ($_COOKIE["adinjblocked"]==1) return true;
253
+
254
+ $referrer = $_SERVER['HTTP_REFERER'];
255
+ $blocked = adinj_config_blocked_keywords();
256
+ foreach ($blocked as $bl) {
257
+ if (stripos($referrer, $bl) !== false) {
258
+ return true;
259
+ }
260
+ }
261
+ return false;
262
  }
263
  }
264
 
275
  function adshow_show_adverts(){
276
  if (!adshow_functions_exist()){ return false; }
277
 
278
+ //echo 'ref:'.$_SERVER['HTTP_REFERER'];
279
+ if (adinj_config_block_ips() && adshow_blocked_ip()) return "blockedip";
280
+ if (adinj_config_sevisitors_only()&& !adshow_fromasearchengine()) return "referrer";
281
+ if (adinj_config_block_keywords() && adshow_blocked_referrer()) return "blockedreferrer";
282
+
283
  return true;
284
  }
285
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-w
4
  Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, widgets, sidebar, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free, blog, ad rotation, A:B testing, split testing, WP Super Cache, W3 Total Cache, WP Cache
5
  Requires at least: 2.8.6
6
  Tested up to: 3.2.1
7
- Stable tag: 1.1.0.4
8
 
9
  Injects any adverts (e.g. AdSense) into the WordPress posts or widget area. Restrict who sees ads by post length/age/referrer or IP. Cache compatible.
10
 
@@ -54,6 +54,10 @@ The number of adverts can be set based on the length of the post. It is a good i
54
 
55
  You can specify that ads should only be shown to search engine visitors, or to visitors from defined referring websites - e.g. Facebook, Wikipedia, Twitter, etc. This will give your regular visitors (who are unlikely to click your ads) a better experience of your site. You can define which search engines or referring sites see your adverts. A visitor who enters the site by one of these referrers will see ads for the next hour.
56
 
 
 
 
 
57
  = Ads on old posts only =
58
 
59
  Adverts can be restricted to posts that are more than a defined numbers of days old. This prevents your regular visitors from having to see your ads.
@@ -514,6 +518,12 @@ If you do get any errors please use the 'Report a bug or give feedback' link on
514
 
515
  == Changelog ==
516
 
 
 
 
 
 
 
517
  = 1.1.0.4 =
518
  * First ad can now be started at or after a paragraph or character position.
519
  * Override ad positions on individual posts using &lt;!--topad--&gt; &lt;!--randomad--&gt; &lt;!--bottomad--&gt;
@@ -704,6 +714,9 @@ Fix 'Something badly wrong in num_rand_ads_to_insert' message that occurs on pag
704
 
705
  == Upgrade Notice ==
706
 
 
 
 
707
  = 1.1.0.4 =
708
  * First ad can now be started at or after a paragraph or character position. Position override tags. Separate old post restriction for widget ads. Template ad examples in the 'Test ads' section. Warning message improvements. Other fixes.
709
 
4
  Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, widgets, sidebar, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free, blog, ad rotation, A:B testing, split testing, WP Super Cache, W3 Total Cache, WP Cache
5
  Requires at least: 2.8.6
6
  Tested up to: 3.2.1
7
+ Stable tag: 1.1.0.5
8
 
9
  Injects any adverts (e.g. AdSense) into the WordPress posts or widget area. Restrict who sees ads by post length/age/referrer or IP. Cache compatible.
10
 
54
 
55
  You can specify that ads should only be shown to search engine visitors, or to visitors from defined referring websites - e.g. Facebook, Wikipedia, Twitter, etc. This will give your regular visitors (who are unlikely to click your ads) a better experience of your site. You can define which search engines or referring sites see your adverts. A visitor who enters the site by one of these referrers will see ads for the next hour.
56
 
57
+ = Block by referrer =
58
+
59
+ Block ads to people coming from certain referring URLs. e.g. you may wish to treat people who arrive at your site after searching for your site name as direct visitors and disable the ads for them.
60
+
61
  = Ads on old posts only =
62
 
63
  Adverts can be restricted to posts that are more than a defined numbers of days old. This prevents your regular visitors from having to see your ads.
518
 
519
  == Changelog ==
520
 
521
+ = 1.1.0.5 =
522
+ * New block ads by referring keyword/URL feature.
523
+ * Load tags in batches to reduce memory used when displaying main settings screen. Will help people with lots of tags.
524
+ * Fix for &lt;!--randomad--&gt; tag.
525
+ * Move tags/categories/authors/ids filters to separate area of UI.
526
+
527
  = 1.1.0.4 =
528
  * First ad can now be started at or after a paragraph or character position.
529
  * Override ad positions on individual posts using &lt;!--topad--&gt; &lt;!--randomad--&gt; &lt;!--bottomad--&gt;
714
 
715
  == Upgrade Notice ==
716
 
717
+ = 1.1.0.5 =
718
+ * New block ads by referrer feature. Reduce UI memory usage for people with lots of tags. Fix randomad override tag.
719
+
720
  = 1.1.0.4 =
721
  * First ad can now be started at or after a paragraph or character position. Position override tags. Separate old post restriction for widget ads. Template ad examples in the 'Test ads' section. Warning message improvements. Other fixes.
722
 
ui-tab-main.php CHANGED
@@ -10,7 +10,7 @@ function adinj_tab_main(){
10
  $ops = adinj_options();
11
  ?>
12
 
13
- <p><a href="#adsettings">Ad Placement settings</a> | <a href="#adverts">Adverts</a> | <a href="#restrictions">Ad insert mode/dynamic restrictions</a> | <a href="#docsquickstart">Quick Start</a> | <a href="#testads">Test ads</a></p>
14
 
15
  <?php adinj_global_settings_box($ops); ?>
16
 
@@ -45,11 +45,6 @@ function adinj_tab_main(){
45
  </div></td></tr>
46
 
47
 
48
- <tr><td colspan="4">
49
- <b>|_</b><?php adinj_condition_tables('top_', 'ui_top_conditions_show'); ?>
50
- <p></p>
51
- </td></tr>
52
-
53
  <tr><td colspan="4"><h3><a name="randomadplacement"></a>Random ads [<a href="#randomadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
54
  <tr><td>Max num of ads on whole page:</td><td>
55
  n/a
@@ -110,11 +105,6 @@ function adinj_tab_main(){
110
  <div id="random_ads_after_warning"><span style="font-size:10px;color:red;">Note: If starting 'at character x', the start point will be the next paragraph.</span><br /></div>
111
 
112
  </td></tr>
113
- <tr><td colspan="4">
114
- <br />
115
- <?php adinj_condition_tables('random_', 'ui_random_conditions_show'); ?>
116
- <p></p>
117
- </td></tr>
118
 
119
  <tr><td colspan="4"><h3><a name="bottomadplacement"></a>Bottom ad [<a href="#bottomadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
120
 
@@ -136,17 +126,7 @@ function adinj_tab_main(){
136
  ?>
137
  </div></td></tr>
138
 
139
- <tr><td colspan="4">
140
- <b>|_ </b><?php adinj_condition_tables('bottom_', 'ui_bottom_conditions_show'); ?>
141
- <p></p>
142
- </td></tr>
143
 
144
- <tr><td colspan="4"><h3><a name="footeradplacement"></a>Footer ad [<a href="#footeradcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
145
- <tr><td colspan="4">
146
- <?php adinj_condition_tables('footer_', 'ui_footer_conditions_show'); ?>
147
- <p></p>
148
-
149
- </td></tr>
150
 
151
  </table>
152
 
@@ -160,7 +140,7 @@ function adinj_tab_main(){
160
  <h3><a name="topadcode"></a>Top ad (below post title - this is not a 'header' ad) [<a href="#topadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_top'>pool</a>]--></h3>
161
  <table border="0" class="adinjtable" width="95%">
162
  <tr><td>
163
- <textarea name="ad_code_top_1" rows="10" cols="70"><?php echo $ops['ad_code_top_1']; ?></textarea>
164
  <br />
165
  <p><span style="font-size:10px;"><b>Docs:</b> Try a <a href="#468x15">468x15</a> or <a href="#336x280">336x280</a> advert.</span></p>
166
  </td><td>
@@ -175,7 +155,7 @@ function adinj_tab_main(){
175
  <h3><a name="randomadcode"></a>Random ad (inserted randomly between paragraphs) [<a href="#randomadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_random'>pool</a>]--></h3>
176
  <table border="0" class="adinjtable" width="95%">
177
  <tr><td>
178
- <textarea name="ad_code_random_1" rows="10" cols="70"><?php echo $ops['ad_code_random_1']; ?></textarea>
179
  <br />
180
  <p><span style="font-size:10px;"><b>Docs:</b> Try a <a href="#468x60">468x60</a> or <a href="#728x90">728x90</a> banner.</span></p>
181
  </td><td>
@@ -189,7 +169,7 @@ function adinj_tab_main(){
189
  <h3><a name="bottomadcode"></a>Bottom ad (below the post content) [<a href="#bottomadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_bottom'>pool</a>]--></h3>
190
  <table border="0" class="adinjtable" width="95%">
191
  <tr><td>
192
- <textarea name="ad_code_bottom_1" rows="10" cols="70"><?php echo $ops['ad_code_bottom_1']; ?></textarea>
193
  <br />
194
  <p><span style="font-size:10px;"><b>Docs:</b> Try a <a href="#336x280">336x280</a> advert.</span></p>
195
  </td><td>
@@ -204,7 +184,7 @@ function adinj_tab_main(){
204
  <h3><a name="footeradcode"></a>Footer ad (put into 'the_footer' hook - not supported by all themes) [<a href="#footeradplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_footer'>pool</a>]--></h3>
205
  <table border="0" class="adinjtable" width="95%">
206
  <tr><td>
207
- <textarea name="ad_code_footer_1" rows="10" cols="70"><?php echo $ops['ad_code_footer_1']; ?></textarea>
208
  <br />
209
  Docs: footer ad information and troubleshooting
210
  <?php adinj_add_show_hide_section('footer_docs_'.uniqid(''), 'ui_footer_docs_show', 'ui_footer_docs_show', $ops); ?>
@@ -225,6 +205,8 @@ function adinj_tab_main(){
225
 
226
  <?php adinj_postbox_end(); ?>
227
 
 
 
228
  <?php adinj_insertion_mode_box($ops); ?>
229
 
230
  <br clear="all" />
@@ -243,6 +225,25 @@ function adinj_tab_main(){
243
  }
244
  }
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  function adinj_global_settings_box($ops){
247
  adinj_postbox_start(__("Global settings (apply to all ads)", 'adinj'), 'global'); ?>
248
 
@@ -267,16 +268,16 @@ function adinj_global_settings_box($ops){
267
  </script>
268
  <div id="test_mode_warning"><span style="font-size:10px;color:red;">Warning: Turn any caching plugin *off* before using test mode. If you leave the caching plugin on, the test adverts will be cached and shown to your real visitors.</span><br /></div>
269
 
270
- <p><b><a name="pagetypefilters"></a>Exclude ads from page types (tick to remove ads)</b></p>
271
  <?php
272
  $count_pages = wp_count_posts('page', 'readable');
273
  $count_posts = wp_count_posts('post', 'readable');
274
  ?>
275
 
276
-
277
  <table class="adinjstatustable">
278
  <tr>
279
- <td></td>
280
  <td><b>Single(<?php echo $count_posts->publish; ?>)</b></td>
281
  <td><b>Page(<?php echo $count_pages->publish; ?>)</b></td>
282
  <td><b>Home</b></td>
@@ -341,8 +342,23 @@ function adinj_global_settings_box($ops){
341
  <p></p>
342
 
343
  <?php
344
- adinj_condition_tables('global_', 'ui_conditions_show');
345
- //TODO sometimes OOM here - just before drop down list is loaded
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  adinj_postbox_end();
347
  }
348
 
@@ -396,25 +412,38 @@ function adinj_insertion_mode_box($ops){
396
  </script>
397
 
398
 
399
- <h4><a name="dynamic"></a>Show ads only to visitors from these websites (dynamic feature)</h4>
400
 
401
  <blockquote>
402
  <?php adinj_add_checkbox('sevisitors_only') ?><?php _e("Only show ads to visitors from these websites (customise search engine or website referrers below). When a user visits from one of these referrers they will see ads <b>for the next hour</b> (sets a 1 hour cookie).", 'adinj') ?><br />
403
- <textarea name="ad_referrers" rows="2" cols="70"><?php echo $ops['ad_referrers']; ?></textarea>
404
  <p>Comma separated list e.g.: <br /><code>.google., .bing., .yahoo., .ask., search?, search., facebook.com, t.co</code></p>
405
  </blockquote>
 
 
 
 
 
 
 
 
 
 
406
 
407
  <h4>Blocked IP addresses (dynamic feature)</h4>
408
 
409
  <blockquote>
410
  <?php adinj_add_checkbox('block_ips') ?><?php _e("Exclude ads from these IP addresses.", 'adinj') ?><br />
411
- <textarea name="blocked_ips" rows="4" cols="70"><?php echo $ops['blocked_ips']; ?></textarea>
412
  <p>Comma separated list e.g.: <br /><code>0.0.0.1, 0.0.0.2</code></p>
413
  <p>Or you can list one IP per line with optional comments e.g.</p>
414
  <code style="padding:0px 0px">192.168.0.1<br />0.0.0.2<br /><?php echo $_SERVER['REMOTE_ADDR'] ?> //my ip<br />0.0.0.3</code>
415
 
416
  <p>For reference your current IP address is <code><?php echo $_SERVER['REMOTE_ADDR'] ?></code></p>
417
  </blockquote>
 
 
 
418
 
419
  <?php adinj_postbox_end();
420
  }
@@ -580,7 +609,7 @@ function adinj_side_status_box(){
580
 
581
  <tr><td colspan="2">
582
  <p></p>
583
- <b>Ad summary</b><br />
584
  <table class="adinjstatustable">
585
  <tr>
586
  <td></td>
@@ -636,6 +665,15 @@ function adinj_side_status_box(){
636
  <td><?php adinj_print_ad_dot('widget', 'home') ?></td>
637
  <td><?php adinj_print_ad_dot('widget', 'archive') ?></td>
638
  </tr>
 
 
 
 
 
 
 
 
 
639
  </table>
640
  <p>S=single post<br />
641
  P=single page<br />
10
  $ops = adinj_options();
11
  ?>
12
 
13
+ <p><a href="#adsettings">Ad Placement settings</a> | <a href="#adverts">Ads</a> | <a href="#restrictions">Ad insert mode/dynamic restrictions</a> | <a href="#filters">Filters</a> | <a href="#docsquickstart">Quick Start</a> | <a href="#testads">Test ads</a></p>
14
 
15
  <?php adinj_global_settings_box($ops); ?>
16
 
45
  </div></td></tr>
46
 
47
 
 
 
 
 
 
48
  <tr><td colspan="4"><h3><a name="randomadplacement"></a>Random ads [<a href="#randomadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
49
  <tr><td>Max num of ads on whole page:</td><td>
50
  n/a
105
  <div id="random_ads_after_warning"><span style="font-size:10px;color:red;">Note: If starting 'at character x', the start point will be the next paragraph.</span><br /></div>
106
 
107
  </td></tr>
 
 
 
 
 
108
 
109
  <tr><td colspan="4"><h3><a name="bottomadplacement"></a>Bottom ad [<a href="#bottomadcode">code</a>] [<a href="#pagetypefilters">page type filters</a>]</h3></td></tr>
110
 
126
  ?>
127
  </div></td></tr>
128
 
 
 
 
 
129
 
 
 
 
 
 
 
130
 
131
  </table>
132
 
140
  <h3><a name="topadcode"></a>Top ad (below post title - this is not a 'header' ad) [<a href="#topadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_top'>pool</a>]--></h3>
141
  <table border="0" class="adinjtable" width="95%">
142
  <tr><td>
143
+ <textarea name="ad_code_top_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_top_1']; ?></textarea>
144
  <br />
145
  <p><span style="font-size:10px;"><b>Docs:</b> Try a <a href="#468x15">468x15</a> or <a href="#336x280">336x280</a> advert.</span></p>
146
  </td><td>
155
  <h3><a name="randomadcode"></a>Random ad (inserted randomly between paragraphs) [<a href="#randomadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_random'>pool</a>]--></h3>
156
  <table border="0" class="adinjtable" width="95%">
157
  <tr><td>
158
+ <textarea name="ad_code_random_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_random_1']; ?></textarea>
159
  <br />
160
  <p><span style="font-size:10px;"><b>Docs:</b> Try a <a href="#468x60">468x60</a> or <a href="#728x90">728x90</a> banner.</span></p>
161
  </td><td>
169
  <h3><a name="bottomadcode"></a>Bottom ad (below the post content) [<a href="#bottomadplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_bottom'>pool</a>]--></h3>
170
  <table border="0" class="adinjtable" width="95%">
171
  <tr><td>
172
+ <textarea name="ad_code_bottom_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_bottom_1']; ?></textarea>
173
  <br />
174
  <p><span style="font-size:10px;"><b>Docs:</b> Try a <a href="#336x280">336x280</a> advert.</span></p>
175
  </td><td>
184
  <h3><a name="footeradcode"></a>Footer ad (put into 'the_footer' hook - not supported by all themes) [<a href="#footeradplacement">placement</a>] <!--[<a href='?page=ad-injection&amp;tab=adrotation#multiple_footer'>pool</a>]--></h3>
185
  <table border="0" class="adinjtable" width="95%">
186
  <tr><td>
187
+ <textarea name="ad_code_footer_1" rows="10" cols="<?php adinj_table_width('ad'); ?>"><?php echo $ops['ad_code_footer_1']; ?></textarea>
188
  <br />
189
  Docs: footer ad information and troubleshooting
190
  <?php adinj_add_show_hide_section('footer_docs_'.uniqid(''), 'ui_footer_docs_show', 'ui_footer_docs_show', $ops); ?>
205
 
206
  <?php adinj_postbox_end(); ?>
207
 
208
+ <?php adinj_filters_box($ops); ?>
209
+
210
  <?php adinj_insertion_mode_box($ops); ?>
211
 
212
  <br clear="all" />
225
  }
226
  }
227
 
228
+ function adinj_table_width($table){
229
+ global $wp_db_version;
230
+ if ($table == 'ad'){
231
+ if ($wp_db_version < 18226){
232
+ echo '60';
233
+ } else { //WP3.2+
234
+ echo '70';
235
+ }
236
+ } else if ($table == 'dynamic'){
237
+ if ($wp_db_version < 18226){
238
+ echo '70';
239
+ } else { //WP3.2+
240
+ echo '80';
241
+ }
242
+ } else {
243
+ echo '61';
244
+ }
245
+ }
246
+
247
  function adinj_global_settings_box($ops){
248
  adinj_postbox_start(__("Global settings (apply to all ads)", 'adinj'), 'global'); ?>
249
 
268
  </script>
269
  <div id="test_mode_warning"><span style="font-size:10px;color:red;">Warning: Turn any caching plugin *off* before using test mode. If you leave the caching plugin on, the test adverts will be cached and shown to your real visitors.</span><br /></div>
270
 
271
+ <p></p>
272
  <?php
273
  $count_pages = wp_count_posts('page', 'readable');
274
  $count_posts = wp_count_posts('post', 'readable');
275
  ?>
276
 
277
+ <a name="pagetypefilters"></a>
278
  <table class="adinjstatustable">
279
  <tr>
280
+ <td><b><font color="red">Tick to disable ads:</font></b></td>
281
  <td><b>Single(<?php echo $count_posts->publish; ?>)</b></td>
282
  <td><b>Page(<?php echo $count_pages->publish; ?>)</b></td>
283
  <td><b>Home</b></td>
342
  <p></p>
343
 
344
  <?php
345
+ adinj_postbox_end();
346
+ }
347
+
348
+ function adinj_filters_box($ops){
349
+ adinj_postbox_start(__("Tag, category, author and post id filters", 'adinj'), 'filters'); ?>
350
+ <h4>Global filters</h4>
351
+ <?php adinj_condition_tables('global_', 'ui_conditions_show'); ?>
352
+ <p>The global filter apply to all ads, and are processed before the ad type specific filters.</p>
353
+ <h4>Top ad filters</h4>
354
+ <?php adinj_condition_tables('top_', 'ui_top_conditions_show'); ?>
355
+ <h4>Random ad filters</h4>
356
+ <?php adinj_condition_tables('random_', 'ui_top_conditions_show'); ?>
357
+ <h4>Bottom ad filters</h4>
358
+ <?php adinj_condition_tables('bottom_', 'ui_top_conditions_show'); ?>
359
+ <h4>Footer ad filters</h4>
360
+ <?php adinj_condition_tables('footer_', 'ui_top_conditions_show'); ?>
361
+ <?php
362
  adinj_postbox_end();
363
  }
364
 
412
  </script>
413
 
414
 
415
+ <h4><a name="dynamic"></a>Show ads only to visitors from these search engines or websites (dynamic feature)</h4>
416
 
417
  <blockquote>
418
  <?php adinj_add_checkbox('sevisitors_only') ?><?php _e("Only show ads to visitors from these websites (customise search engine or website referrers below). When a user visits from one of these referrers they will see ads <b>for the next hour</b> (sets a 1 hour cookie).", 'adinj') ?><br />
419
+ <textarea name="ad_referrers" rows="2" cols="<?php adinj_table_width('dynamic'); ?>"><?php echo $ops['ad_referrers']; ?></textarea>
420
  <p>Comma separated list e.g.: <br /><code>.google., .bing., .yahoo., .ask., search?, search., facebook.com, t.co</code></p>
421
  </blockquote>
422
+
423
+
424
+ <h4>Blocked referrer keywords (dynamic feature)</h4>
425
+
426
+ <blockquote>
427
+ <?php adinj_add_checkbox('block_keywords') ?><?php _e("Don't show ads to visitors from external sites if the referrer contains one of these keywords or substrings.", 'adinj') ?> If a blocked string is found block ads for: <?php adinj_selection_box("block_ads_for_hours", array('1'=>'1 hour', '2'=>'2 hours', '3'=>'3 hours', '6'=>'6 hours', '24'=>'1 day', '48'=>'2 days', '72'=>'3 days', '168'=>'1 week', '720'=>'30 days', '8760'=>'1 year')); ?><br />
428
+ <textarea name="blocked_keywords" rows="2" cols="<?php adinj_table_width('dynamic'); ?>"><?php echo $ops['blocked_keywords']; ?></textarea>
429
+ <p>Comma separated list e.g.: <br /><code>myblogname.com, .ru, .in, james+bond</code></p>
430
+ </blockquote>
431
+
432
 
433
  <h4>Blocked IP addresses (dynamic feature)</h4>
434
 
435
  <blockquote>
436
  <?php adinj_add_checkbox('block_ips') ?><?php _e("Exclude ads from these IP addresses.", 'adinj') ?><br />
437
+ <textarea name="blocked_ips" rows="4" cols="<?php adinj_table_width('dynamic'); ?>"><?php echo $ops['blocked_ips']; ?></textarea>
438
  <p>Comma separated list e.g.: <br /><code>0.0.0.1, 0.0.0.2</code></p>
439
  <p>Or you can list one IP per line with optional comments e.g.</p>
440
  <code style="padding:0px 0px">192.168.0.1<br />0.0.0.2<br /><?php echo $_SERVER['REMOTE_ADDR'] ?> //my ip<br />0.0.0.3</code>
441
 
442
  <p>For reference your current IP address is <code><?php echo $_SERVER['REMOTE_ADDR'] ?></code></p>
443
  </blockquote>
444
+
445
+
446
+
447
 
448
  <?php adinj_postbox_end();
449
  }
609
 
610
  <tr><td colspan="2">
611
  <p></p>
612
+ <b>Ads on/off summary</b><br />
613
  <table class="adinjstatustable">
614
  <tr>
615
  <td></td>
665
  <td><?php adinj_print_ad_dot('widget', 'home') ?></td>
666
  <td><?php adinj_print_ad_dot('widget', 'archive') ?></td>
667
  </tr>
668
+ <tr>
669
+ <td style="text-align:right"><b>Template</b></td>
670
+ <td></td>
671
+ <td></td>
672
+ <td><?php adinj_print_ad_dot('template', 'single') ?></td>
673
+ <td><?php adinj_print_ad_dot('template', 'page') ?></td>
674
+ <td><?php adinj_print_ad_dot('template', 'home') ?></td>
675
+ <td><?php adinj_print_ad_dot('template', 'archive') ?></td>
676
+ </tr>
677
  </table>
678
  <p>S=single post<br />
679
  P=single page<br />