Ad Injection - Version 0.9.6.4

Version Description

  • Can choose between page lengths based on viewable characters or all characters (includes HTML markup).
  • Fixes for widget padding options.
  • Enable alt content for random ads.
Download this release

Release Info

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

Code changes from version 0.9.6.3 to 0.9.6.4

ad-injection-admin.php CHANGED
@@ -132,9 +132,11 @@ function adinj_write_config_file(){
132
  $debug_mode = adinj_ticked('debug_mode')?'true':'false';
133
 
134
  // TODO remove these from config file later...
135
- $rnd_func = adinj_add_tags(NULL, 'rnd_', 'adinj_config_add_tags_rnd');
136
- $top_func = adinj_add_tags(NULL, 'top_', 'adinj_config_add_tags_top');
137
- $bottom_func = adinj_add_tags(NULL, 'bottom_', 'adinj_config_add_tags_bottom');
 
 
138
 
139
  $config = <<<CONFIG
140
  <?php
@@ -156,9 +158,8 @@ function adinj_config_blocked_keywords() { return array($blocked_keywords); }
156
 
157
  function adinj_config_debug_mode() { return $debug_mode; }
158
 
159
- $rnd_func
160
- $top_func
161
- $bottom_func
162
 
163
  ?>
164
  CONFIG;
@@ -288,7 +289,7 @@ function adinj_top_message_box(){
288
 
289
  } else {
290
  echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
291
- echo "24th January 2011: Added separate option for enabling/disabling front page as well as home page (they can be different!). 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>.';
292
  echo '</strong></p></div>';
293
  }
294
  }
@@ -575,32 +576,32 @@ function adinj_dot($colour){
575
  return '<span style="color:'.$colour.'">&#x25cf;</span>';
576
  }
577
 
578
- function adinj_selection_box($name, $values, $type=NULL, $options=NULL, $selected_value_name=NULL){
579
- echo "<select name='$name'>";
580
-
581
- $ops = "";
582
- if ($options != NULL){
583
- $ops = $options;
584
- } else {
585
- $ops = adinj_options();
586
  }
587
-
588
- $selected_value = "";
589
- if ($selected_value_name != NULL){
590
- $selected_value = $ops[$selected_value_name];
591
- } else {
592
  $selected_value = $ops[$name];
593
  }
594
 
595
- foreach ($values as $value){
596
- echo "<option value=\"$value\" ";
597
- if($selected_value == "$value") echo 'selected="selected"';
598
- if ($type==NULL && is_numeric($value)){
 
 
 
 
 
599
  $typetxt = "(chars)";
600
  } else {
601
  $typetxt = $type;
602
  }
603
- if (adinj_disabled($value)) $typetxt = "";
604
  echo ">$value $typetxt</option>";
605
  }
606
  echo "</select>";
@@ -614,7 +615,6 @@ function adinj_condition_table($name, $description, $type){
614
 
615
  <textarea name="<?php echo $name; ?>_condition_entries" rows="2" cols="40"><?php echo $options[$name.'_condition_entries']; ?></textarea>
616
 
617
-
618
  </td><td style="vertical-align:top">
619
 
620
  <?php
@@ -705,14 +705,14 @@ function adinj_add_margin_top_bottom_options($prefix, $options=NULL, $topname=NU
705
  _e("Margin top", 'adinj');
706
  echo "<br />";
707
  adinj_selection_box($tname,
708
- array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options, $tdefault);
709
 
710
  echo "<br />";
711
 
712
  _e("Margin bottom", 'adinj');
713
  echo "<br />";
714
  adinj_selection_box($bname,
715
- array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options, $bdefault);
716
  }
717
 
718
  function adinj_add_padding_top_bottom_options($prefix, $options=NULL, $topname=NULL, $bottomname=NULL){
@@ -732,14 +732,14 @@ function adinj_add_padding_top_bottom_options($prefix, $options=NULL, $topname=N
732
  _e("Padding top", 'adinj');
733
  echo "<br />";
734
  adinj_selection_box($tname,
735
- array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options, $tdefault);
736
 
737
  echo "<br />";
738
 
739
  _e("Padding bottom", 'adinj');
740
  echo "<br />";
741
  adinj_selection_box($bname,
742
- array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options, $bdefault);
743
  }
744
 
745
  function adinj_get_version(){
@@ -900,6 +900,11 @@ function adinj_upgrade_db(){
900
  $new_options['block_ips'] = 'on';
901
  }
902
 
 
 
 
 
 
903
  // 3. Bump up db version number.
904
  $new_options['db_version'] = $new_dbversion;
905
 
@@ -945,6 +950,7 @@ function adinj_default_options(){
945
  'global_category_condition_entries' => '',
946
  'global_tag_condition_mode' => ADINJ_ONLY_SHOW_IN,
947
  'global_tag_condition_entries' => '',
 
948
  // Random ads
949
  'ad_code_random_1' => '',
950
  'ad_code_random_2' => '',
@@ -1039,13 +1045,13 @@ function adinj_default_options(){
1039
  'widget_exclude_single' => '',
1040
  'widget_exclude_archive' => '',
1041
  // dynamic features
 
1042
  'sevisitors_only' => 'off',
1043
  'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search., /search/',
1044
- 'block_ips' => 'on', //TODO
1045
- 'blocked_ips' => '',
1046
  'block_keywords' => 'off', //TODO change to blocked referrers?
1047
  'blocked_keywords' => '', //TODO
1048
- 'ad_insertion_mode' => 'mfunc',
 
1049
  // ui main tab
1050
  'ui_global_hide' => 'false',
1051
  'ui_random_hide' => 'false',
132
  $debug_mode = adinj_ticked('debug_mode')?'true':'false';
133
 
134
  // TODO remove these from config file later...
135
+ $legacy_funcs = '
136
+ function adinj_config_add_tags_rnd($ad) { return ""; }
137
+ function adinj_config_add_tags_top($ad) { return ""; }
138
+ function adinj_config_add_tags_bottom($ad) { return ""; }
139
+ ';
140
 
141
  $config = <<<CONFIG
142
  <?php
158
 
159
  function adinj_config_debug_mode() { return $debug_mode; }
160
 
161
+ // Don't use these - they will be deleted soon
162
+ $legacy_funcs
 
163
 
164
  ?>
165
  CONFIG;
289
 
290
  } else {
291
  echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
292
+ echo "25th January 2011: Widget padding fixes, and a new option to specify how the page length is calculated. 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>.';
293
  echo '</strong></p></div>';
294
  }
295
  }
576
  return '<span style="color:'.$colour.'">&#x25cf;</span>';
577
  }
578
 
579
+ function adinj_selection_box($name, $values, $type=NULL, $selected_value=NULL){
580
+ $associative = false;
581
+ if (!array_key_exists(0, $values)){
582
+ // Very naive test but works for me.
583
+ $associative = true;
 
 
 
584
  }
585
+
586
+ if ($selected_value == NULL){
587
+ $ops = adinj_options();
 
 
588
  $selected_value = $ops[$name];
589
  }
590
 
591
+ echo "<select name='$name'>";
592
+ foreach ($values as $key=>$value){
593
+ $option_value = $value;
594
+ if ($associative){
595
+ $option_value = $key;
596
+ }
597
+ echo "<option value=\"$option_value\" ";
598
+ if($selected_value == "$option_value") echo 'selected="selected"';
599
+ if ($type==NULL && is_numeric($option_value)){
600
  $typetxt = "(chars)";
601
  } else {
602
  $typetxt = $type;
603
  }
604
+ if (adinj_disabled($option_value)) $typetxt = "";
605
  echo ">$value $typetxt</option>";
606
  }
607
  echo "</select>";
615
 
616
  <textarea name="<?php echo $name; ?>_condition_entries" rows="2" cols="40"><?php echo $options[$name.'_condition_entries']; ?></textarea>
617
 
 
618
  </td><td style="vertical-align:top">
619
 
620
  <?php
705
  _e("Margin top", 'adinj');
706
  echo "<br />";
707
  adinj_selection_box($tname,
708
+ array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options[$tdefault]);
709
 
710
  echo "<br />";
711
 
712
  _e("Margin bottom", 'adinj');
713
  echo "<br />";
714
  adinj_selection_box($bname,
715
+ array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options[$bdefault]);
716
  }
717
 
718
  function adinj_add_padding_top_bottom_options($prefix, $options=NULL, $topname=NULL, $bottomname=NULL){
732
  _e("Padding top", 'adinj');
733
  echo "<br />";
734
  adinj_selection_box($tname,
735
+ array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options[$tdefault]);
736
 
737
  echo "<br />";
738
 
739
  _e("Padding bottom", 'adinj');
740
  echo "<br />";
741
  adinj_selection_box($bname,
742
+ array(ADINJ_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)", $options[$bdefault]);
743
  }
744
 
745
  function adinj_get_version(){
900
  $new_options['block_ips'] = 'on';
901
  }
902
 
903
+ if ($stored_dbversion < 4){
904
+ // Maintain previous behaviour for users who upgrade
905
+ $new_options['content_length_unit'] = 'all';
906
+ }
907
+
908
  // 3. Bump up db version number.
909
  $new_options['db_version'] = $new_dbversion;
910
 
950
  'global_category_condition_entries' => '',
951
  'global_tag_condition_mode' => ADINJ_ONLY_SHOW_IN,
952
  'global_tag_condition_entries' => '',
953
+ 'content_length_unit' => 'viewable',
954
  // Random ads
955
  'ad_code_random_1' => '',
956
  'ad_code_random_2' => '',
1045
  'widget_exclude_single' => '',
1046
  'widget_exclude_archive' => '',
1047
  // dynamic features
1048
+ 'ad_insertion_mode' => 'mfunc',
1049
  'sevisitors_only' => 'off',
1050
  'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search., /search/',
 
 
1051
  'block_keywords' => 'off', //TODO change to blocked referrers?
1052
  'blocked_keywords' => '', //TODO
1053
+ 'block_ips' => 'on', //TODO
1054
+ 'blocked_ips' => '',
1055
  // ui main tab
1056
  'ui_global_hide' => 'false',
1057
  'ui_random_hide' => 'false',
ad-injection-widget.php CHANGED
@@ -4,6 +4,8 @@ Part of the Ad Injection plugin for WordPress
4
  http://www.reviewmylife.co.uk/
5
  */
6
 
 
 
7
  define('ADINJ_WIDGET_DB_VERSION', 2);
8
 
9
  class Ad_Injection_Widget extends WP_Widget {
4
  http://www.reviewmylife.co.uk/
5
  */
6
 
7
+ // 1 = original
8
+ // 2 = split testing / alt content
9
  define('ADINJ_WIDGET_DB_VERSION', 2);
10
 
11
  class Ad_Injection_Widget extends WP_Widget {
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: 0.9.6.3
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
@@ -20,15 +20,14 @@ define('ADINJ_NO_CONFIG_FILE', 1);
20
  // _ = before split testing
21
  // 2 = split testing support
22
  // 3 = added front options
23
- define('ADINJ_DB_VERSION', 3);
 
24
 
25
  // Files
 
26
  define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
27
- define('ADINJ_CONFIG_FILE', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
28
- define('ADINJ_AD_PATH', WP_PLUGIN_DIR.'/ad-injection-data'); // ad store from 0.9.2
29
- define('ADINJ_AD_RANDOM_FILE', 'ad_random_1.txt');
30
- define('ADINJ_AD_TOP_FILE', 'ad_top_1.txt');
31
- define('ADINJ_AD_BOTTOM_FILE', 'ad_bottom_1.txt');
32
 
33
  // Constants
34
  define('ADINJ_DISABLED', 'Disabled');
@@ -129,12 +128,13 @@ function adinj_get_ad_code($adtype, $ads_db){
129
  $ads_split = NULL;
130
  $alt_live = NULL;
131
  $alt_split = NULL;
 
132
  if ($ops['ad_insertion_mode'] == 'mfunc'){
133
  adinj_live_ads_array($adtype, $ads_db, $ads_live, $ads_split, 'string');
134
  if (adinj_db_version($ads_db) >= 2){
135
  adinj_live_ads_array($adtype.'_alt', $ads_db, $alt_live, $alt_split, 'string');
136
  }
137
- $formatting = adinj_formatting_options($adtype, 'string');
138
  } else {
139
  $ads_live = array();
140
  $ads_split = array();
@@ -144,9 +144,11 @@ function adinj_get_ad_code($adtype, $ads_db){
144
  if (adinj_db_version($ads_db) >= 2){
145
  adinj_live_ads_array($adtype.'_alt', $ads_db, $alt_live, $alt_split, 'array');
146
  }
147
- $formatting = adinj_formatting_options($adtype, 'array');
 
 
 
148
  }
149
- if (empty($ads_live) && empty($alt_live)) return "<!--ADINJ DEBUG: ads_live and alt_live are empty-->";
150
 
151
  if ($ops['ad_insertion_mode'] == 'mfunc'){
152
  return adinj_ad_code_eval("\n
@@ -162,8 +164,13 @@ function adinj_get_ad_code($adtype, $ads_db){
162
  } else {
163
  $adname = adshow_pick_value($ads_live, $ads_split);
164
  }
 
 
 
 
 
165
 
166
- $ad = adshow_add_formatting($ads_db[$adname], $formatting);
167
  return adinj_ad_code_eval($ad);
168
  }
169
 
@@ -249,7 +256,6 @@ function adinj_live_ads_array($type, $ads_option, &$ads, &$split, $output_type="
249
  $split_val = $ads_option[$ad_name.'_split'];
250
 
251
  if (!empty($ads_option[$ad_name]) && is_numeric($split_val) && $split_val > 0){
252
- //echo "<br />$ad_name $i size:".sizeof($ads_option[$ad_name]);
253
  if ($output_type == "string"){
254
  if (!empty($ads)) $ads .= ",";
255
  $ads .= "'".$file_stem."$i.txt'";
@@ -263,8 +269,7 @@ function adinj_live_ads_array($type, $ads_option, &$ads, &$split, $output_type="
263
  }
264
  }
265
 
266
- function adinj_formatting_options($adtype, $output_type="string", $options = array()){
267
- $ops = adinj_options();
268
  $align = "";
269
  $clear = "";
270
  $margin_top = "";
@@ -277,22 +282,22 @@ function adinj_formatting_options($adtype, $output_type="string", $options = arr
277
  $clear = $ops['rnd_clear'];
278
  $margin_top = $ops['rnd_margin_top'];
279
  $margin_bottom = $ops['rnd_margin_bottom'];
280
- $padding_top = $options['rnd_padding_top'];
281
- $padding_bottom = $options['rnd_padding_bottom'];
282
  } else if ($adtype == 'top' || $adtype == 'bottom'){
283
  $align = $ops[$adtype.'_align'];
284
  $clear = $ops[$adtype.'_clear'];
285
  $margin_top = $ops[$adtype.'_margin_top'];
286
  $margin_bottom = $ops[$adtype.'_margin_bottom'];
287
- $padding_top = $options[$adtype.'_padding_top'];
288
- $padding_bottom = $options[$adtype.'_padding_bottom'];
289
- } else if ($adtype == 'widget'){
290
- $align = $options['align'];
291
- $clear = $options['clear'];
292
- $margin_top = $options['margin_top'];
293
- $margin_bottom = $options['margin_bottom'];
294
- $padding_top = $options['padding_top'];
295
- $padding_bottom = $options['padding_bottom'];
296
  }
297
 
298
  if (adinj_disabled($align)) $align = "";
@@ -339,53 +344,6 @@ function adinj_ad_code_include(){
339
  return adinj_ad_code_eval($ad);
340
  }
341
 
342
- //TODO delete this
343
- function adinj_add_tags($ad, $prefix, $func=NULL){
344
- $ops = adinj_options();
345
- if (!adinj_disabled($ops[$prefix . 'align']) ||
346
- !adinj_disabled($ops[$prefix . 'clear']) ||
347
- !adinj_disabled($ops[$prefix . 'margin_top']) ||
348
- !adinj_disabled($ops[$prefix . 'margin_bottom']) ||
349
- !adinj_disabled($ops[$prefix . 'padding_top']) ||
350
- !adinj_disabled($ops[$prefix . 'padding_bottom'])) {
351
- $clear = "";
352
- $top = "";
353
- $bottom = "";
354
- $ptop = "";
355
- $pbottom = "";
356
- if (!adinj_disabled($ops[$prefix . 'clear'])) $clear="clear:" . $ops[$prefix . 'clear'] . ";";
357
- if (!adinj_disabled($ops[$prefix . 'margin_top'])) $top="margin-top:" . $ops[$prefix . 'margin_top'] . "px;";
358
- if (!adinj_disabled($ops[$prefix . 'margin_bottom'])) $bottom="margin-bottom:" . $ops[$prefix . 'margin_bottom'] . "px;";
359
- if (!adinj_disabled($ops[$prefix . 'padding_top'])) $ptop="padding-top:" . $ops[$prefix . 'padding_top'] . "px;";
360
- if (!adinj_disabled($ops[$prefix . 'padding_bottom'])) $pbottom="padding-bottom:" . $ops[$prefix . 'padding_bottom'] . "px;";
361
- $cssrules = $clear . $top . $bottom . $ptop . $pbottom;
362
-
363
- if ($ops[$prefix . 'align'] == 'left'){
364
- $div = "<div style='float:left;" . $cssrules . "'>ADCODE</div><br clear='all' />";
365
- } else if ($ops[$prefix . 'align'] == 'center'){
366
- $div = "<div style='" . $cssrules . "'><center>ADCODE</center></div>";
367
- } else if ($ops[$prefix . 'align'] == 'right'){
368
- $div = "<div style='float:right;" . $cssrules . "'>ADCODE</div><br clear='all' />";
369
- } else if ($ops[$prefix . 'align'] == 'float left'){
370
- $div = "<div style='float:left;" . $cssrules . "margin-right:5px;'>ADCODE</div>";
371
- } else if ($ops[$prefix . 'align'] == 'float right'){
372
- $div = "<div style='float:right;" . $cssrules . "margin-left:5px;'>ADCODE</div>";
373
- } else {
374
- $div = "<div style='" . $cssrules . "'>ADCODE</div>";
375
- }
376
- if (empty($func)){
377
- return str_replace("ADCODE", $ad, $div);
378
- } else {
379
- $ad = str_replace("ADCODE", "\$ad", $div);
380
- return "function $func(\$ad) { return \"$ad\"; }";
381
- }
382
- }
383
- if (!empty($func)){
384
- return "function $func(\$ad){return \$ad;}";
385
- }
386
- return $ad;
387
- }
388
-
389
  function read_ad_from_file($ad_path){
390
  $contents = "";
391
  if (file_exists($ad_path)){
@@ -434,7 +392,6 @@ function adinj($content, $message){
434
  <!--
435
  [ADINJ DEBUG]
436
  $message
437
- content length=".strlen($content)."
438
  \$adinj_total_rand_ads_used=$adinj_total_rand_ads_used
439
  \$adinj_total_all_ads_used=$adinj_total_all_ads_used
440
  paragraphtostartads=$para (fyi: -1 is disabled)
@@ -563,11 +520,12 @@ function adinj_inject_hook($content){
563
 
564
  $ops = adinj_options();
565
 
566
- if ($ops['ad_insertion_mode'] == 'direct_dynamic'){
 
 
567
  $showads = adshow_show_adverts();
568
  if ($showads !== true){
569
- return adinj($content, "NOADS: ad blocked at run time reason=$showads");
570
- // TODO alt content
571
  }
572
  }
573
 
@@ -579,8 +537,17 @@ function adinj_inject_hook($content){
579
  if(stripos($content, "<!--adfooter-->") !== false) return adinj($content.$ad_include.adinj_ad_code_bottom(), "Ads=adfooter");
580
  }
581
 
 
 
 
 
 
 
 
 
 
 
582
  # Insert top and bottom ads if necesary
583
- $length = strlen($content);
584
  if(is_page() || is_single()){
585
  if (adinj_do_rule_if($ops['top_ad_if_longer_than'], '<', $length)){
586
  $content = $ad_include.adinj_ad_code_top().$content;
@@ -598,7 +565,6 @@ function adinj_inject_hook($content){
598
 
599
  if ($ad_include !== false) $content = $ad_include.$content;
600
 
601
- $debug_on = $ops['debug_mode'];
602
  if (!$debug_on) $debugtags=false;
603
 
604
  $content_adfree_header = "";
@@ -639,7 +605,7 @@ function adinj_inject_hook($content){
639
  $paragraphmarker = "</p>";
640
  if(stripos($content, $paragraphmarker) === false) return adinj($content, "no &lt;/p&gt; tags");
641
 
642
- if ($debug_on) $debug = "\nTags=". htmlentities($debugtags);
643
 
644
  // Generate a list of all potential injection points
645
  if ($debug_on) $debug .= "\nPotential positions: ";
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: 0.9.6.4
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
20
  // _ = before split testing
21
  // 2 = split testing support
22
  // 3 = added front options
23
+ // 4 = new character counting option
24
+ define('ADINJ_DB_VERSION', 4);
25
 
26
  // Files
27
+ // TODO will these paths work on windows?
28
  define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
29
+ define('ADINJ_CONFIG_FILE', WP_CONTENT_DIR . '/ad-injection-config.php');
30
+ define('ADINJ_AD_PATH', WP_PLUGIN_DIR.'/ad-injection-data');
 
 
 
31
 
32
  // Constants
33
  define('ADINJ_DISABLED', 'Disabled');
128
  $ads_split = NULL;
129
  $alt_live = NULL;
130
  $alt_split = NULL;
131
+ $formatting = NULL;
132
  if ($ops['ad_insertion_mode'] == 'mfunc'){
133
  adinj_live_ads_array($adtype, $ads_db, $ads_live, $ads_split, 'string');
134
  if (adinj_db_version($ads_db) >= 2){
135
  adinj_live_ads_array($adtype.'_alt', $ads_db, $alt_live, $alt_split, 'string');
136
  }
137
+ $formatting = adinj_formatting_options($adtype, $ads_db, 'string');
138
  } else {
139
  $ads_live = array();
140
  $ads_split = array();
144
  if (adinj_db_version($ads_db) >= 2){
145
  adinj_live_ads_array($adtype.'_alt', $ads_db, $alt_live, $alt_split, 'array');
146
  }
147
+ $formatting = adinj_formatting_options($adtype, $ads_db, 'array');
148
+ }
149
+ if (empty($ads_live) && empty($alt_live)){
150
+ return "";
151
  }
 
152
 
153
  if ($ops['ad_insertion_mode'] == 'mfunc'){
154
  return adinj_ad_code_eval("\n
164
  } else {
165
  $adname = adshow_pick_value($ads_live, $ads_split);
166
  }
167
+ $ad = $ads_db[$adname];
168
+
169
+ if (empty($ad)){
170
+ return "";
171
+ }
172
 
173
+ $ad = adshow_add_formatting($ad, $formatting);
174
  return adinj_ad_code_eval($ad);
175
  }
176
 
256
  $split_val = $ads_option[$ad_name.'_split'];
257
 
258
  if (!empty($ads_option[$ad_name]) && is_numeric($split_val) && $split_val > 0){
 
259
  if ($output_type == "string"){
260
  if (!empty($ads)) $ads .= ",";
261
  $ads .= "'".$file_stem."$i.txt'";
269
  }
270
  }
271
 
272
+ function adinj_formatting_options($adtype, $ops, $output_type="string"){
 
273
  $align = "";
274
  $clear = "";
275
  $margin_top = "";
282
  $clear = $ops['rnd_clear'];
283
  $margin_top = $ops['rnd_margin_top'];
284
  $margin_bottom = $ops['rnd_margin_bottom'];
285
+ $padding_top = $ops['rnd_padding_top'];
286
+ $padding_bottom = $ops['rnd_padding_bottom'];
287
  } else if ($adtype == 'top' || $adtype == 'bottom'){
288
  $align = $ops[$adtype.'_align'];
289
  $clear = $ops[$adtype.'_clear'];
290
  $margin_top = $ops[$adtype.'_margin_top'];
291
  $margin_bottom = $ops[$adtype.'_margin_bottom'];
292
+ $padding_top = $ops[$adtype.'_padding_top'];
293
+ $padding_bottom = $ops[$adtype.'_padding_bottom'];
294
+ } else if (preg_match("/widget_[\d+]/i", $adtype)){
295
+ $align = $ops['align'];
296
+ $clear = $ops['clear'];
297
+ $margin_top = $ops['margin_top'];
298
+ $margin_bottom = $ops['margin_bottom'];
299
+ $padding_top = $ops['padding_top'];
300
+ $padding_bottom = $ops['padding_bottom'];
301
  }
302
 
303
  if (adinj_disabled($align)) $align = "";
344
  return adinj_ad_code_eval($ad);
345
  }
346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  function read_ad_from_file($ad_path){
348
  $contents = "";
349
  if (file_exists($ad_path)){
392
  <!--
393
  [ADINJ DEBUG]
394
  $message
 
395
  \$adinj_total_rand_ads_used=$adinj_total_rand_ads_used
396
  \$adinj_total_all_ads_used=$adinj_total_all_ads_used
397
  paragraphtostartads=$para (fyi: -1 is disabled)
520
 
521
  $ops = adinj_options();
522
 
523
+ $debug_on = $ops['debug_mode'];
524
+
525
+ if ($debug_on && $ops['ad_insertion_mode'] == 'direct_dynamic'){
526
  $showads = adshow_show_adverts();
527
  if ($showads !== true){
528
+ $debug .= "\nNOADS: ad blocked at run time reason=$showads";
 
529
  }
530
  }
531
 
537
  if(stripos($content, "<!--adfooter-->") !== false) return adinj($content.$ad_include.adinj_ad_code_bottom(), "Ads=adfooter");
538
  }
539
 
540
+
541
+
542
+ $length = 0;
543
+ if ($ops['content_length_unit'] == 'all'){
544
+ $length = strlen($content);
545
+ if ($debug_on) $debug .= "\nlength = $length (including HTML chars)";
546
+ } else {
547
+ $length = strlen(strip_tags($content));
548
+ if ($debug_on) $debug .= "\nlength = $length (viewable chars only)";
549
+ }
550
  # Insert top and bottom ads if necesary
 
551
  if(is_page() || is_single()){
552
  if (adinj_do_rule_if($ops['top_ad_if_longer_than'], '<', $length)){
553
  $content = $ad_include.adinj_ad_code_top().$content;
565
 
566
  if ($ad_include !== false) $content = $ad_include.$content;
567
 
 
568
  if (!$debug_on) $debugtags=false;
569
 
570
  $content_adfree_header = "";
605
  $paragraphmarker = "</p>";
606
  if(stripos($content, $paragraphmarker) === false) return adinj($content, "no &lt;/p&gt; tags");
607
 
608
+ if ($debug_on) $debug .= "\nTags=". htmlentities($debugtags);
609
 
610
  // Generate a list of all potential injection points
611
  if ($debug_on) $debug .= "\nPotential positions: ";
adshow.php CHANGED
@@ -68,6 +68,7 @@ function adinj_config_debug_mode() {
68
 
69
  //////////////////////////////////////////////////////////////////////////////
70
 
 
71
  if (!function_exists('adshow_display_ad_file')){
72
  function adshow_display_ad_file($adfile){
73
  if (!adshow_functions_exist()){ return false; }
@@ -96,6 +97,7 @@ If you have just upgraded you may need to re-save your ads to regenerate the ad
96
  }
97
  }
98
 
 
99
  if (!function_exists('adshow_display_ad_full_path')){
100
  function adshow_display_ad_full_path($ad_path){
101
  if (!adshow_functions_exist()){ return false; }
@@ -174,11 +176,14 @@ If you have just upgraded you may need to re-save your ads to regenerate the ad
174
 
175
  if (!function_exists('adshow_pick_value')){
176
  function adshow_pick_value($values, $frequency){
 
 
 
177
  if (!is_array($values)){
178
  // single value passed in
179
  return $values;
180
  }
181
- $val = NULL;
182
 
183
  // values is an array
184
  if (empty($frequency)){
@@ -189,7 +194,7 @@ function adshow_pick_value($values, $frequency){
189
  $count = sizeof($values);
190
  if ($count != sizeof($frequency)){
191
  echo "<!--ADINJ DEBUG: size of arrays don't match ".$count."!=".sizeof($frequency)."-->\n";
192
- return NULL;
193
  }
194
  $total = array_sum($frequency);
195
  $rand = rand(0, $total);
68
 
69
  //////////////////////////////////////////////////////////////////////////////
70
 
71
+ // TODO delete
72
  if (!function_exists('adshow_display_ad_file')){
73
  function adshow_display_ad_file($adfile){
74
  if (!adshow_functions_exist()){ return false; }
97
  }
98
  }
99
 
100
+ // TODO delete
101
  if (!function_exists('adshow_display_ad_full_path')){
102
  function adshow_display_ad_full_path($ad_path){
103
  if (!adshow_functions_exist()){ return false; }
176
 
177
  if (!function_exists('adshow_pick_value')){
178
  function adshow_pick_value($values, $frequency){
179
+ if (empty($values)){
180
+ return "";
181
+ }
182
  if (!is_array($values)){
183
  // single value passed in
184
  return $values;
185
  }
186
+ $val = "";
187
 
188
  // values is an array
189
  if (empty($frequency)){
194
  $count = sizeof($values);
195
  if ($count != sizeof($frequency)){
196
  echo "<!--ADINJ DEBUG: size of arrays don't match ".$count."!=".sizeof($frequency)."-->\n";
197
+ return "";
198
  }
199
  $total = array_sum($frequency);
200
  $rand = rand(0, $total);
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.1
7
- Stable tag: 0.9.6.3
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
 
@@ -305,6 +305,11 @@ If you do get any errors please use the 'Report a bug or give feedback' link on
305
 
306
  == Changelog ==
307
 
 
 
 
 
 
308
  = 0.9.6.3 =
309
  * Option to enable/disable front page ads in case your front and home pages are different.
310
 
@@ -412,8 +417,8 @@ Fix 'Something badly wrong in num_rand_ads_to_insert' message that occurs on pag
412
 
413
  == Upgrade Notice ==
414
 
415
- = 0.9.6.3 =
416
- New split testing, ad rotation and alternate content features. If you have any problems with disappearing ads re-save them to make them appear again.
417
 
418
  = 0.8.3 =
419
  First public release.
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.1
7
+ Stable tag: 0.9.6.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
 
305
 
306
  == Changelog ==
307
 
308
+ = 0.9.6.4 =
309
+ * Can choose between page lengths based on viewable characters or all characters (includes HTML markup).
310
+ * Fixes for widget padding options.
311
+ * Enable alt content for random ads.
312
+
313
  = 0.9.6.3 =
314
  * Option to enable/disable front page ads in case your front and home pages are different.
315
 
417
 
418
  == Upgrade Notice ==
419
 
420
+ = 0.9.6.4 =
421
+ Fixes for widget padding and enabling of random alt content. If you have any problems with disappearing ads re-save them to make them appear again.
422
 
423
  = 0.8.3 =
424
  First public release.
ui-tab-main.php CHANGED
@@ -32,12 +32,38 @@ function adinj_tab_main(){
32
  <input type="radio" name="ads_enabled" value="on" <?php if ($ops['ads_enabled']=='on') echo 'checked="checked"'; ?> /> <b>On: <?php _e('Ads enabled', 'adinj') ?></b><br />
33
  <input type="radio" name="ads_enabled" value="off" <?php if ($ops['ads_enabled']=='off' || $ops['ads_enabled']=='') echo 'checked="checked"'; ?> /> <b>Off</b><br />
34
  <input type="radio" name="ads_enabled" value="test" <?php if ($ops['ads_enabled']=='test') echo 'checked="checked"'; ?> /> <b>Test mode</b> - Only show ads to admin.<br />
35
- <span style="font-size:10px;color:red;">Warning: Turn any caching plugin *off* before using test mode. If you leave them on the test adverts will be cached and shown to your real visitors.</span><br />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- <table border="0">
38
- <tr><td>
39
- <p><?php _e("Only show ads on pages older than ", 'adinj') ?></p>
40
- </td><td>
 
 
 
 
 
 
41
  <p>
42
  <select name='ads_on_page_older_than'>
43
  <?php
@@ -50,9 +76,9 @@ function adinj_tab_main(){
50
  ?>
51
  </select><?php _e(" (days)", 'adinj') ?> - only for single posts and pages</p>
52
  </td></tr>
53
- <tr><td style="vertical-align:top">
54
- Don't show ads on these types:
55
- </td><td>
56
  <?php adinj_add_checkbox('exclude_front') ?>front - <?php echo get_bloginfo('url'); ?><br />
57
  <?php adinj_add_checkbox('exclude_home') ?>home - latest posts page (may be same as front)<br />
58
  <?php
@@ -64,9 +90,18 @@ function adinj_tab_main(){
64
  <?php adinj_add_checkbox('exclude_archive') ?>archive - only <a href="#widgets">widgets</a> currently appear on archives<br />
65
  </td></tr>
66
  <tr><td colspan="2"><p><span style="font-size:10px;">If you have <a href='options-reading.php'>set your front page</a> to be a static 'page' rather than your latest posts, the 'page' tick box will also apply to the front page.</span></p></td></tr>
 
 
 
 
 
 
 
 
 
67
  </table>
68
 
69
- <b>Category and tag conditions</b>
70
 
71
  <?php adinj_condition_table('global_category', 'category slugs. e.g: cat1, cat2, cat3', 'category'); ?>
72
 
@@ -106,7 +141,7 @@ function adinj_tab_main(){
106
  <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
107
  <h3><a name="random_single"></a><?php _e("Single posts and pages: Randomly Injected ad settings", 'adinj') ?></h3>
108
  <div class="inside" style="margin:10px">
109
- <p>These random ad injection settings are specific to single posts and pages.</p>
110
 
111
  <table border="0">
112
 
@@ -130,49 +165,53 @@ function adinj_tab_main(){
130
  </select> <?php echo adinj_getdefault('max_num_of_ads'); ?><br />
131
  </td></tr>
132
 
133
- <tr><td>
 
 
 
 
 
 
 
 
 
 
 
 
134
  <?php
135
- _e("No random ads if page shorter than: ", 'adinj');
136
- echo '</td><td>';
137
  adinj_selection_box("no_random_ads_if_shorter_than",
138
  array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000));
139
- echo adinj_getdefault('no_random_ads_if_shorter_than');
140
  ?>
141
- </td></tr>
142
-
143
- <tr><td>
144
  <?php
145
- _e("Limit of 1 ad if page shorter than: ", 'adinj');
146
- echo '</td><td>';
147
  adinj_selection_box("one_ad_if_shorter_than",
148
  array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000));
149
- echo adinj_getdefault('one_ad_if_shorter_than');
150
  ?>
151
- </td></tr>
152
-
153
- <tr><td>
154
  <?php
155
- _e("Limit of 2 ads if page shorter than: ", 'adinj');
156
- echo '</td><td>';
157
  adinj_selection_box("two_ads_if_shorter_than",
158
  array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000));
159
- echo adinj_getdefault('two_ads_if_shorter_than');
160
  ?>
161
- </td></tr>
162
-
163
- <tr><td>
164
  <?php
165
- _e("Limit of 3 ads if page shorter than: ", 'adinj');
166
- echo '</td><td>';
167
  adinj_selection_box("three_ads_if_shorter_than",
168
  array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
169
- echo adinj_getdefault('three_ads_if_shorter_than');
170
  ?>
171
- </td></tr>
 
172
  </table>
173
 
174
  <br clear="all" />
175
- <p><span style="font-size:10px;"><b>Docs:</b> The above directives are processed in order from top to bottom.</span></p>
 
 
 
 
 
 
176
 
177
 
178
  <p></p>
32
  <input type="radio" name="ads_enabled" value="on" <?php if ($ops['ads_enabled']=='on') echo 'checked="checked"'; ?> /> <b>On: <?php _e('Ads enabled', 'adinj') ?></b><br />
33
  <input type="radio" name="ads_enabled" value="off" <?php if ($ops['ads_enabled']=='off' || $ops['ads_enabled']=='') echo 'checked="checked"'; ?> /> <b>Off</b><br />
34
  <input type="radio" name="ads_enabled" value="test" <?php if ($ops['ads_enabled']=='test') echo 'checked="checked"'; ?> /> <b>Test mode</b> - Only show ads to admin.<br />
35
+
36
+ <script type="text/javascript">
37
+ jQuery(document).ready(function(){
38
+ jQuery('input[name=ads_enabled]:radio').change(function() {
39
+ if (jQuery('input[name=ads_enabled]:checked').val() == "test"){
40
+ jQuery('#test_mode_warning').slideDown(500);
41
+ } else {
42
+ jQuery('#test_mode_warning').slideUp(500);
43
+ }
44
+ return true;
45
+ });
46
+ });
47
+ </script>
48
+
49
+ <?php if ($ops['ads_enabled'] != 'test') { ?>
50
+ <script type="text/javascript">
51
+ document.write('<style type="text/css">#test_mode_warning { display: none; }</style>');
52
+ </script>
53
+ <?php } ?>
54
+
55
+ <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>
56
 
57
+ <p></p>
58
+
59
+ <style type="text/css">
60
+ .adinjtable td { vertical-align: top; }
61
+ </style>
62
+
63
+ <table border="0" class="adinjtable">
64
+ <tr>
65
+ <td><p><?php _e("Only show ads on pages older than ", 'adinj') ?></p></td>
66
+ <td>
67
  <p>
68
  <select name='ads_on_page_older_than'>
69
  <?php
76
  ?>
77
  </select><?php _e(" (days)", 'adinj') ?> - only for single posts and pages</p>
78
  </td></tr>
79
+ <tr>
80
+ <td>Don't show ads on these types:</td>
81
+ <td>
82
  <?php adinj_add_checkbox('exclude_front') ?>front - <?php echo get_bloginfo('url'); ?><br />
83
  <?php adinj_add_checkbox('exclude_home') ?>home - latest posts page (may be same as front)<br />
84
  <?php
90
  <?php adinj_add_checkbox('exclude_archive') ?>archive - only <a href="#widgets">widgets</a> currently appear on archives<br />
91
  </td></tr>
92
  <tr><td colspan="2"><p><span style="font-size:10px;">If you have <a href='options-reading.php'>set your front page</a> to be a static 'page' rather than your latest posts, the 'page' tick box will also apply to the front page.</span></p></td></tr>
93
+ <tr>
94
+ <td>Character counting method:</td>
95
+ <td>
96
+ <?php
97
+ adinj_selection_box("content_length_unit",
98
+ array('viewable' => 'viewable characters', 'all' => 'all characters'));
99
+ ?>
100
+ </td></tr>
101
+ <tr><td colspan="2"><p><span style="font-size:10px;">When defining conditions that refer to the length of the content; do you only want to only include viewable characters, or all characters (which includes HTML tags)?</span></p></td></tr>
102
  </table>
103
 
104
+ <p><b>Category and tag conditions</b></p>
105
 
106
  <?php adinj_condition_table('global_category', 'category slugs. e.g: cat1, cat2, cat3', 'category'); ?>
107
 
141
  <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
142
  <h3><a name="random_single"></a><?php _e("Single posts and pages: Randomly Injected ad settings", 'adinj') ?></h3>
143
  <div class="inside" style="margin:10px">
144
+ <p>These random ad injection settings are specific to single posts and pages only. To configure the number of home page ads go to the next section.</p>
145
 
146
  <table border="0">
147
 
165
  </select> <?php echo adinj_getdefault('max_num_of_ads'); ?><br />
166
  </td></tr>
167
 
168
+ <tr><td colspan="2">
169
+ <p></p>
170
+ <table>
171
+ <tr>
172
+ <td>Random ad limit:</td>
173
+ <td><center><b>0</b></center></td>
174
+ <td><center><b>1</b></center></td>
175
+ <td><center><b>2</b></center></td>
176
+ <td><center><b>3</b></center></td>
177
+ </tr>
178
+ <tr>
179
+ <td>If page shorter than:</td>
180
+ <td>
181
  <?php
 
 
182
  adinj_selection_box("no_random_ads_if_shorter_than",
183
  array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000));
 
184
  ?>
185
+ </td>
186
+ <td>
 
187
  <?php
 
 
188
  adinj_selection_box("one_ad_if_shorter_than",
189
  array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000));
 
190
  ?>
191
+ </td>
192
+ <td>
 
193
  <?php
 
 
194
  adinj_selection_box("two_ads_if_shorter_than",
195
  array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000));
 
196
  ?>
197
+ </td>
198
+ <td>
 
199
  <?php
 
 
200
  adinj_selection_box("three_ads_if_shorter_than",
201
  array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000));
 
202
  ?>
203
+ </td>
204
+ </tr>
205
  </table>
206
 
207
  <br clear="all" />
208
+ <p><span style="font-size:10px;"><b>Docs:</b> The 'random ad limit' rules are processed in order from left to right.</span></p>
209
+
210
+ </td></tr>
211
+
212
+ </table>
213
+
214
+
215
 
216
 
217
  <p></p>