Ad Injection - Version 0.9.4.4

Version Description

New display option for defining CSS clear as left, right or both. Suppress file system warnings. Tested on WordPress 2.8.6 - it works!

Download this release

Release Info

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

Code changes from version 0.9.4.3 to 0.9.4.4

Files changed (4) hide show
  1. ad-injection-admin.php +51 -39
  2. ad-injection-widget.php +1 -1
  3. ad-injection.php +25 -23
  4. readme.txt +14 -2
ad-injection-admin.php CHANGED
@@ -78,14 +78,9 @@ case 'Save all settings':
78
  adinj_update_options($ops);
79
 
80
  if ($ops['ad_insertion_mode'] == 'mfunc') {
81
- global $adinj_warning_msg_filewrite;
82
- if (!file_exists(ADINJ_AD_PATH2)){
83
- mkdir(ADINJ_AD_PATH2, 0750) //TODO is this the right permission?
84
- or $adinj_warning_msg_filewrite .= "<br />Error: could not create dir: ".ADINJ_AD_PATH2.". Please create it manually and try again.";
85
- }
86
- write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH2.'/'.ADINJ_AD_RANDOM_FILE);
87
- write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH2.'/'.ADINJ_AD_TOP_FILE);
88
- write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH2.'/'.ADINJ_AD_BOTTOM_FILE);
89
  adinj_write_config_file();
90
  }
91
 
@@ -142,27 +137,37 @@ $bottom_func
142
  ?>
143
  CONFIG;
144
 
145
- adinj_write_file(ADINJ_CONFIG_FILE2, $config, 0640);
146
 
147
  }
148
 
149
  function adinj_write_file($path, $content, $permission){
150
  $ops = adinj_options();
151
  global $adinj_warning_msg_filewrite;
152
- $handle = fopen($path, "w");
 
 
 
 
 
 
 
 
153
  if (strlen($content) > 0){
154
- fwrite($handle, $content) or $adinj_warning_msg_filewrite .= "<br />Error: could not write to file: $path";
 
 
 
 
155
  }
156
- fclose($handle);
157
- adinj_chmod($path, $permission);
158
  }
159
 
160
  function adinj_chmod($path, $permission){
161
  global $adinj_warning_msg_chmod;
162
- $oldperm = substr(decoct(fileperms($path)), -3);
163
  $newperm = decoct($permission);
164
  if ($newperm == $oldperm) return;
165
- chmod($path, $permission) or $adinj_warning_msg_chmod .= "<br />Warning: chmod $permission " .
166
  "on $path failed. Current permissions: $oldperm<br /> Try manually updating the permission if problems occur.";
167
  }
168
 
@@ -178,7 +183,7 @@ function adinj_options_page(){
178
  }
179
  $ops = adinj_options(1);
180
  if ($ops['ad_insertion_mode'] == 'mfunc') {
181
- if (!file_exists(ADINJ_CONFIG_FILE2)){
182
  adinj_write_config_file();
183
  }
184
  }
@@ -218,11 +223,15 @@ function adinj_options_page(){
218
  }
219
  echo '</p></div>';
220
 
221
- }
222
-
 
 
 
223
  ?>
224
 
225
 
 
226
  <div style="width:258px; float:right;">
227
  <div class="postbox-container" style="width:258px;">
228
  <div class="metabox-holder">
@@ -314,15 +323,14 @@ function adinj_options_page(){
314
  <li><a href="http://wordpress.org/extend/plugins/ad-injection/" target="_new">Ad Injection at WordPress</a></li>
315
  <li><b><a href="https://spreadsheets.google.com/viewform?formkey=dFUwZzBYcG1HNzNKMmJZdWFDdFhkY0E6MQ" target="_new">Report a bug / give feedback</a></b></li>
316
  </ul>
317
- <h4>Coming soon</h4>
318
  <ul>
319
  <li>More precise control over which categories and tags the ads are shown in.</li>
320
  <li>Extra places where adverts can be inserted.</li>
321
- <li>Merry Christmas by the way!</li>
322
  </ul>
323
 
324
- <h4><font color="red">Be careful!</font></h4>
325
- <p>Make sure that the ad settings and positioning you define are in compliance with your ad provider's terms of service!</p>
326
 
327
  <h4><font color="red">Beta version</font></h4>
328
  <p>This plugin has only only recently been released. I'm actively listening to your feedback and fixing any problems, and adding new features that you request. Please let me know if you like the plugin too!</p>
@@ -784,7 +792,7 @@ function adinj_get_status($name){
784
  if ($val == 'on'){
785
  $status[0] = 'green';
786
  $status[1] = $val;
787
- } else if ($val == 'off'){
788
  $status[0] = 'red';
789
  $status[1] = $val;
790
  } else if ($val == 'test'){
@@ -991,6 +999,13 @@ function adinj_add_alignment_options($prefix){
991
 
992
  echo "<br />";
993
 
 
 
 
 
 
 
 
994
  _e("Margin top", 'adinj');
995
  echo "<br />";
996
  adinj_selection_box($prefix.'margin_top',
@@ -1037,9 +1052,8 @@ function adinj_debug_information(){
1037
  echo '<h4>Other settings</h4><blockquote>';
1038
 
1039
  echo 'ADINJ_PATH='.ADINJ_PATH.'<br />';
1040
- echo 'ADINJ_CONFIG_FILE2='.ADINJ_CONFIG_FILE2.'<br />';
1041
- echo 'ADINJ_AD_PATH='.ADINJ_AD_PATH.' (up to v0.9.1)<br />';
1042
- echo 'ADINJ_AD_PATH2='.ADINJ_AD_PATH2.' (v0.9.2+)<br />';
1043
 
1044
  echo 'Plugin version='.adinj_get_version();
1045
  echo '</blockquote>';
@@ -1114,28 +1128,23 @@ function adinj_activate_hook() {
1114
  }
1115
  }
1116
 
1117
- $random_file2 = ADINJ_AD_PATH2.'/'.ADINJ_AD_RANDOM_FILE;
1118
- $top_file2 = ADINJ_AD_PATH2.'/'.ADINJ_AD_TOP_FILE;
1119
- $bottom_file2 = ADINJ_AD_PATH2.'/'.ADINJ_AD_BOTTOM_FILE;
1120
  if ($pending_options['ad_insertion_mode'] == 'mfunc'){
1121
- if (!file_exists(ADINJ_AD_PATH2)){
1122
- mkdir(ADINJ_AD_PATH2, 0750) //TODO is this the right permission?
1123
- or $adinj_warning_msg_filewrite .= "<br />Error: could not create dir: ".ADINJ_AD_PATH2.". Please create it manually and try again.";
1124
- }
1125
-
1126
  // Restore data after automatic upgrade
1127
  // TODO could remove this code further down the line when everyone
1128
  // has moved to the new ad store location
1129
- if (!file_exists($random_file2) && !empty($pending_options['ad_code_random_1'])){
1130
  write_ad_to_file($pending_options['ad_code_random_1'], $random_file2);
1131
  }
1132
- if (!file_exists($top_file2) && !empty($pending_options['ad_code_top_1'])){
1133
  write_ad_to_file($pending_options['ad_code_top_1'], $top_file2);
1134
  }
1135
- if (!file_exists($bottom_file2) && !empty($pending_options['ad_code_bottom_1'])){
1136
  write_ad_to_file($pending_options['ad_code_bottom_1'], $bottom_file2);
1137
  }
1138
- if (!file_exists(ADINJ_CONFIG_FILE2)){
1139
  adinj_write_config_file();
1140
  }
1141
  }
@@ -1163,7 +1172,7 @@ function adinj_options_need_upgrading($stored_options){
1163
  function adinj_default_options(){
1164
  return array(
1165
  // Global settings
1166
- 'ads_enabled' => '',
1167
  'ads_on_page_older_than' => '10',
1168
  'exclude_home' => '',
1169
  'exclude_page' => '',
@@ -1183,6 +1192,7 @@ function adinj_default_options(){
1183
  'top_ad_if_longer_than' => ADINJ_RULE_DISABLED,
1184
  'bottom_ad_if_longer_than' => ADINJ_RULE_DISABLED,
1185
  'rnd_align' => ADINJ_RULE_DISABLED,
 
1186
  'rnd_margin_top' => '3',
1187
  'rnd_margin_bottom' => '3',
1188
  'first_paragraph_ad' => '',
@@ -1192,11 +1202,13 @@ function adinj_default_options(){
1192
  // top
1193
  'ad_code_top_1' => '',
1194
  'top_align' => ADINJ_RULE_DISABLED,
 
1195
  'top_margin_top' => '3',
1196
  'top_margin_bottom' => '3',
1197
  // bottom
1198
  'ad_code_bottom_1' => '',
1199
  'bottom_align' => ADINJ_RULE_DISABLED,
 
1200
  'bottom_margin_top' => '3',
1201
  'bottom_margin_bottom' => '3',
1202
  // widgets
78
  adinj_update_options($ops);
79
 
80
  if ($ops['ad_insertion_mode'] == 'mfunc') {
81
+ write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE);
82
+ write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE);
83
+ write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE);
 
 
 
 
 
84
  adinj_write_config_file();
85
  }
86
 
137
  ?>
138
  CONFIG;
139
 
140
+ adinj_write_file(ADINJ_CONFIG_FILE, $config, 0640);
141
 
142
  }
143
 
144
  function adinj_write_file($path, $content, $permission){
145
  $ops = adinj_options();
146
  global $adinj_warning_msg_filewrite;
147
+
148
+ $dir = dirname($path);
149
+ if (!@file_exists($dir)){
150
+ if (!@mkdir($dir, 0750)){
151
+ @mkdir($dir, 0755) or $adinj_warning_msg_filewrite .= "<br />Warning: could not create dir: ".$dir.". Please create it manually and try again.";
152
+ }
153
+ }
154
+
155
+ $handle = @fopen($path, "w");
156
  if (strlen($content) > 0){
157
+ @fwrite($handle, $content) or $adinj_warning_msg_filewrite .= "<br />Warning: could not write to file: $path";
158
+ }
159
+ @fclose($handle);
160
+ if (@file_exists($path)){
161
+ adinj_chmod($path, $permission);
162
  }
 
 
163
  }
164
 
165
  function adinj_chmod($path, $permission){
166
  global $adinj_warning_msg_chmod;
167
+ $oldperm = substr(decoct(@fileperms($path)), -3);
168
  $newperm = decoct($permission);
169
  if ($newperm == $oldperm) return;
170
+ @chmod($path, $permission) or $adinj_warning_msg_chmod .= "<br />Warning: chmod $permission " .
171
  "on $path failed. Current permissions: $oldperm<br /> Try manually updating the permission if problems occur.";
172
  }
173
 
183
  }
184
  $ops = adinj_options(1);
185
  if ($ops['ad_insertion_mode'] == 'mfunc') {
186
+ if (!@file_exists(ADINJ_CONFIG_FILE)){
187
  adinj_write_config_file();
188
  }
189
  }
223
  }
224
  echo '</p></div>';
225
 
226
+ } else {
227
+ echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
228
+ echo "24th December 2010: I'll be taking a break from updating Ad Injection over Christmas and the New Year. The next release will probably be on the 5th January. But please keep sending me any <a href='https://spreadsheets.google.com/viewform?formkey=dFUwZzBYcG1HNzNKMmJZdWFDdFhkY0E6MQ' target='_new'>feedback or bug reports</a>. I read and act on all feedback! Merry Christmas :)";
229
+ echo '</strong></p></div>';
230
+ }
231
  ?>
232
 
233
 
234
+
235
  <div style="width:258px; float:right;">
236
  <div class="postbox-container" style="width:258px;">
237
  <div class="metabox-holder">
323
  <li><a href="http://wordpress.org/extend/plugins/ad-injection/" target="_new">Ad Injection at WordPress</a></li>
324
  <li><b><a href="https://spreadsheets.google.com/viewform?formkey=dFUwZzBYcG1HNzNKMmJZdWFDdFhkY0E6MQ" target="_new">Report a bug / give feedback</a></b></li>
325
  </ul>
326
+ <h4>Coming in 2011</h4>
327
  <ul>
328
  <li>More precise control over which categories and tags the ads are shown in.</li>
329
  <li>Extra places where adverts can be inserted.</li>
 
330
  </ul>
331
 
332
+ <h4><font color="red">Important!</font></h4>
333
+ <p>You are responsible for making sure the ad settings and positioning you define are in compliance with your ad provider's terms of service! Failure to do so could get you banned by them!</p>
334
 
335
  <h4><font color="red">Beta version</font></h4>
336
  <p>This plugin has only only recently been released. I'm actively listening to your feedback and fixing any problems, and adding new features that you request. Please let me know if you like the plugin too!</p>
792
  if ($val == 'on'){
793
  $status[0] = 'green';
794
  $status[1] = $val;
795
+ } else if ($val == 'off' || $val == ''){
796
  $status[0] = 'red';
797
  $status[1] = $val;
798
  } else if ($val == 'test'){
999
 
1000
  echo "<br />";
1001
 
1002
+ _e("Clear (CSS)", 'adinj');
1003
+ echo "<br />";
1004
+ adinj_selection_box($prefix.'clear',
1005
+ array(ADINJ_RULE_DISABLED, 'left', 'right', 'both'));
1006
+
1007
+ echo "<br />";
1008
+
1009
  _e("Margin top", 'adinj');
1010
  echo "<br />";
1011
  adinj_selection_box($prefix.'margin_top',
1052
  echo '<h4>Other settings</h4><blockquote>';
1053
 
1054
  echo 'ADINJ_PATH='.ADINJ_PATH.'<br />';
1055
+ echo 'ADINJ_CONFIG_FILE='.ADINJ_CONFIG_FILE.'<br />';
1056
+ echo 'ADINJ_AD_PATH='.ADINJ_AD_PATH.'<br />';
 
1057
 
1058
  echo 'Plugin version='.adinj_get_version();
1059
  echo '</blockquote>';
1128
  }
1129
  }
1130
 
1131
+ $random_file2 = ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE;
1132
+ $top_file2 = ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE;
1133
+ $bottom_file2 = ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE;
1134
  if ($pending_options['ad_insertion_mode'] == 'mfunc'){
 
 
 
 
 
1135
  // Restore data after automatic upgrade
1136
  // TODO could remove this code further down the line when everyone
1137
  // has moved to the new ad store location
1138
+ if (!@file_exists($random_file2) && !empty($pending_options['ad_code_random_1'])){
1139
  write_ad_to_file($pending_options['ad_code_random_1'], $random_file2);
1140
  }
1141
+ if (!@file_exists($top_file2) && !empty($pending_options['ad_code_top_1'])){
1142
  write_ad_to_file($pending_options['ad_code_top_1'], $top_file2);
1143
  }
1144
+ if (!@file_exists($bottom_file2) && !empty($pending_options['ad_code_bottom_1'])){
1145
  write_ad_to_file($pending_options['ad_code_bottom_1'], $bottom_file2);
1146
  }
1147
+ if (!@file_exists(ADINJ_CONFIG_FILE)){
1148
  adinj_write_config_file();
1149
  }
1150
  }
1172
  function adinj_default_options(){
1173
  return array(
1174
  // Global settings
1175
+ 'ads_enabled' => 'off',
1176
  'ads_on_page_older_than' => '10',
1177
  'exclude_home' => '',
1178
  'exclude_page' => '',
1192
  'top_ad_if_longer_than' => ADINJ_RULE_DISABLED,
1193
  'bottom_ad_if_longer_than' => ADINJ_RULE_DISABLED,
1194
  'rnd_align' => ADINJ_RULE_DISABLED,
1195
+ 'rnd_clear' => ADINJ_RULE_DISABLED,
1196
  'rnd_margin_top' => '3',
1197
  'rnd_margin_bottom' => '3',
1198
  'first_paragraph_ad' => '',
1202
  // top
1203
  'ad_code_top_1' => '',
1204
  'top_align' => ADINJ_RULE_DISABLED,
1205
+ 'top_clear' => ADINJ_RULE_DISABLED,
1206
  'top_margin_top' => '3',
1207
  'top_margin_bottom' => '3',
1208
  // bottom
1209
  'ad_code_bottom_1' => '',
1210
  'bottom_align' => ADINJ_RULE_DISABLED,
1211
+ 'bottom_clear' => ADINJ_RULE_DISABLED,
1212
  'bottom_margin_top' => '3',
1213
  'bottom_margin_bottom' => '3',
1214
  // widgets
ad-injection-widget.php CHANGED
@@ -101,7 +101,7 @@ class Ad_Injection_Widget extends WP_Widget {
101
  }
102
 
103
  function get_ad_file_path2(){
104
- return ADINJ_AD_PATH2.'/'.$this->get_ad_file_name();
105
  }
106
 
107
  function get_ad_file_name(){
101
  }
102
 
103
  function get_ad_file_path2(){
104
+ return ADINJ_AD_PATH.'/'.$this->get_ad_file_name();
105
  }
106
 
107
  function get_ad_file_name(){
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.4.3
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
@@ -15,9 +15,8 @@ License: GPLv2
15
 
16
  // Files
17
  define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
18
- define('ADINJ_CONFIG_FILE2', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
19
- define('ADINJ_AD_PATH', ADINJ_PATH . '/ads'); // old ad store
20
- define('ADINJ_AD_PATH2', WP_PLUGIN_DIR.'/ad-injection-data'); // ad store from 0.9.2
21
  define('ADINJ_AD_RANDOM_FILE', 'ad_random_1.txt');
22
  define('ADINJ_AD_TOP_FILE', 'ad_top_1.txt');
23
  define('ADINJ_AD_BOTTOM_FILE', 'ad_bottom_1.txt');
@@ -148,25 +147,29 @@ function adinj_ad_code_include(){
148
  function adinj_add_tags($ad, $prefix, $func=NULL){
149
  $ops = adinj_options();
150
  if ($ops[$prefix . 'align'] !== ADINJ_RULE_DISABLED ||
 
151
  $ops[$prefix . 'margin_top'] !== ADINJ_RULE_DISABLED ||
152
  $ops[$prefix . 'margin_bottom'] !== ADINJ_RULE_DISABLED) {
 
153
  $top = "";
154
  $bottom = "";
 
155
  if ($ops[$prefix . 'margin_top'] !== ADINJ_RULE_DISABLED) $top="margin-top:" . $ops[$prefix . 'margin_top'] . "px;";
156
  if ($ops[$prefix . 'margin_bottom'] !== ADINJ_RULE_DISABLED) $bottom="margin-bottom:" . $ops[$prefix . 'margin_bottom'] . "px;";
 
157
 
158
  if ($ops[$prefix . 'align'] == 'left'){
159
- $div = "<div style='float:left;" . $top . $bottom . "'>ADCODE</div><br clear='all' />";
160
  } else if ($ops[$prefix . 'align'] == 'center'){
161
- $div = "<div style='" . $top . $bottom . "'><center>ADCODE</center></div>";
162
  } else if ($ops[$prefix . 'align'] == 'right'){
163
- $div = "<div style='float:right;" . $top . $bottom . "'>ADCODE</div><br clear='all' />";
164
  } else if ($ops[$prefix . 'align'] == 'float left'){
165
- $div = "<div style='float:left;" . $top . $bottom . "margin-right:5px;'>ADCODE</div>";
166
  } else if ($ops[$prefix . 'align'] == 'float right'){
167
- $div = "<div style='float:right;" . $top . $bottom . "margin-left:5px;'>ADCODE</div>";
168
  } else {
169
- $div = "<div style='" . $top . $bottom . "'>ADCODE</div>";
170
  }
171
  if (empty($func)){
172
  return str_replace("ADCODE", $ad, $div);
@@ -183,41 +186,41 @@ function adinj_add_tags($ad, $prefix, $func=NULL){
183
 
184
  function adinj_ad_code_random(){
185
  $ops = adinj_options();
186
- $ad = "";
 
187
  if ($ops['ad_insertion_mode'] == 'mfunc'){
188
  $ad = adinj_get_mfunc_code(ADINJ_AD_RANDOM_FILE);
189
  } else {
190
- $ad = $ops['ad_code_random_1'];
191
  $ad = adinj_add_tags($ad, 'rnd_');
192
  }
193
  return adinj_ad_code_eval($ad);
194
  }
195
 
196
  function adinj_ad_code_top(){
197
- global $adinj_total_all_ads_used;
198
- ++$adinj_total_all_ads_used;
199
  $ops = adinj_options();
200
- $ad = "";
 
201
  if ($ops['ad_insertion_mode'] == 'mfunc'){
202
  $ad = adinj_get_mfunc_code(ADINJ_AD_TOP_FILE);
203
  } else {
204
- $ad = $ops['ad_code_top_1'];
205
  $ad = adinj_add_tags($ad, 'top_');
206
  }
 
 
207
  return adinj_ad_code_eval($ad);
208
  }
209
 
210
  function adinj_ad_code_bottom(){
211
- global $adinj_total_all_ads_used;
212
- ++$adinj_total_all_ads_used;
213
  $ops = adinj_options();
214
- $ad = "";
 
215
  if ($ops['ad_insertion_mode'] == 'mfunc'){
216
  $ad = adinj_get_mfunc_code(ADINJ_AD_BOTTOM_FILE);
217
  } else {
218
- $ad = $ops['ad_code_bottom_1'];
219
  $ad = adinj_add_tags($ad, 'bottom_');
220
  }
 
 
221
  return adinj_ad_code_eval($ad);
222
  }
223
 
@@ -309,7 +312,6 @@ function adinj($content, $message){
309
  if (!adinj_ticked('debug_mode')) return $content;
310
  global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
311
  $path = ADINJ_AD_PATH;
312
- $path2 = ADINJ_AD_PATH2;
313
  $ops = adinj_options();
314
  $mode = $ops['ad_insertion_mode'];
315
  return $content."
@@ -321,7 +323,6 @@ content length=".strlen($content)."
321
  \$adinj_total_all_ads_used=$adinj_total_all_ads_used
322
  injection mode=$mode
323
  ADINJ_AD_PATH=$path
324
- ADINJ_AD_PATH2=$path2
325
  //-->\n";
326
  }
327
 
@@ -459,6 +460,8 @@ function adinj_inject_hook($content){
459
 
460
  $num_rand_ads_to_insert = adinj_num_rand_ads_to_insert($length);
461
  if ($num_rand_ads_to_insert <= 0) return adinj($content, "all ads used up");
 
 
462
 
463
  if ($ad_include !== false) $content = $ad_include.$content;
464
 
@@ -564,7 +567,6 @@ function adinj_inject_hook($content){
564
  sort($inj_positions);
565
 
566
  // Insert ads in reverse order
567
- $ad = adinj_ad_code_random();
568
  global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
569
  for ($adnum=sizeof($inj_positions)-1; $adnum>=0; $adnum--){
570
  $content = substr_replace($content, $ad, $inj_positions[$adnum], 0);
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.4.4
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
15
 
16
  // Files
17
  define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
18
+ define('ADINJ_CONFIG_FILE', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
19
+ define('ADINJ_AD_PATH', WP_PLUGIN_DIR.'/ad-injection-data'); // ad store from 0.9.2
 
20
  define('ADINJ_AD_RANDOM_FILE', 'ad_random_1.txt');
21
  define('ADINJ_AD_TOP_FILE', 'ad_top_1.txt');
22
  define('ADINJ_AD_BOTTOM_FILE', 'ad_bottom_1.txt');
147
  function adinj_add_tags($ad, $prefix, $func=NULL){
148
  $ops = adinj_options();
149
  if ($ops[$prefix . 'align'] !== ADINJ_RULE_DISABLED ||
150
+ $ops[$prefix . 'clear'] !== ADINJ_RULE_DISABLED ||
151
  $ops[$prefix . 'margin_top'] !== ADINJ_RULE_DISABLED ||
152
  $ops[$prefix . 'margin_bottom'] !== ADINJ_RULE_DISABLED) {
153
+ $clear = "";
154
  $top = "";
155
  $bottom = "";
156
+ if ($ops[$prefix . 'clear'] !== ADINJ_RULE_DISABLED) $clear="clear:" . $ops[$prefix . 'clear'] . ";";
157
  if ($ops[$prefix . 'margin_top'] !== ADINJ_RULE_DISABLED) $top="margin-top:" . $ops[$prefix . 'margin_top'] . "px;";
158
  if ($ops[$prefix . 'margin_bottom'] !== ADINJ_RULE_DISABLED) $bottom="margin-bottom:" . $ops[$prefix . 'margin_bottom'] . "px;";
159
+ $cssrules = $clear . $top . $bottom;
160
 
161
  if ($ops[$prefix . 'align'] == 'left'){
162
+ $div = "<div style='float:left;" . $cssrules . "'>ADCODE</div><br clear='all' />";
163
  } else if ($ops[$prefix . 'align'] == 'center'){
164
+ $div = "<div style='" . $cssrules . "'><center>ADCODE</center></div>";
165
  } else if ($ops[$prefix . 'align'] == 'right'){
166
+ $div = "<div style='float:right;" . $cssrules . "'>ADCODE</div><br clear='all' />";
167
  } else if ($ops[$prefix . 'align'] == 'float left'){
168
+ $div = "<div style='float:left;" . $cssrules . "margin-right:5px;'>ADCODE</div>";
169
  } else if ($ops[$prefix . 'align'] == 'float right'){
170
+ $div = "<div style='float:right;" . $cssrules . "margin-left:5px;'>ADCODE</div>";
171
  } else {
172
+ $div = "<div style='" . $cssrules . "'>ADCODE</div>";
173
  }
174
  if (empty($func)){
175
  return str_replace("ADCODE", $ad, $div);
186
 
187
  function adinj_ad_code_random(){
188
  $ops = adinj_options();
189
+ $ad = $ops['ad_code_random_1'];
190
+ if (empty($ad)) return false;
191
  if ($ops['ad_insertion_mode'] == 'mfunc'){
192
  $ad = adinj_get_mfunc_code(ADINJ_AD_RANDOM_FILE);
193
  } else {
 
194
  $ad = adinj_add_tags($ad, 'rnd_');
195
  }
196
  return adinj_ad_code_eval($ad);
197
  }
198
 
199
  function adinj_ad_code_top(){
 
 
200
  $ops = adinj_options();
201
+ $ad = $ops['ad_code_top_1'];
202
+ if (empty($ad)) return "<!--ADINJ DEBUG: no top ad defined. Either define it or turn the ad off-->";
203
  if ($ops['ad_insertion_mode'] == 'mfunc'){
204
  $ad = adinj_get_mfunc_code(ADINJ_AD_TOP_FILE);
205
  } else {
 
206
  $ad = adinj_add_tags($ad, 'top_');
207
  }
208
+ global $adinj_total_all_ads_used;
209
+ ++$adinj_total_all_ads_used;
210
  return adinj_ad_code_eval($ad);
211
  }
212
 
213
  function adinj_ad_code_bottom(){
 
 
214
  $ops = adinj_options();
215
+ $ad = $ops['ad_code_bottom_1'];
216
+ if (empty($ad)) return "<!--ADINJ DEBUG: no bottom ad defined. Either define it or turn the ad off-->";
217
  if ($ops['ad_insertion_mode'] == 'mfunc'){
218
  $ad = adinj_get_mfunc_code(ADINJ_AD_BOTTOM_FILE);
219
  } else {
 
220
  $ad = adinj_add_tags($ad, 'bottom_');
221
  }
222
+ global $adinj_total_all_ads_used;
223
+ ++$adinj_total_all_ads_used;
224
  return adinj_ad_code_eval($ad);
225
  }
226
 
312
  if (!adinj_ticked('debug_mode')) return $content;
313
  global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
314
  $path = ADINJ_AD_PATH;
 
315
  $ops = adinj_options();
316
  $mode = $ops['ad_insertion_mode'];
317
  return $content."
323
  \$adinj_total_all_ads_used=$adinj_total_all_ads_used
324
  injection mode=$mode
325
  ADINJ_AD_PATH=$path
 
326
  //-->\n";
327
  }
328
 
460
 
461
  $num_rand_ads_to_insert = adinj_num_rand_ads_to_insert($length);
462
  if ($num_rand_ads_to_insert <= 0) return adinj($content, "all ads used up");
463
+ $ad = adinj_ad_code_random();
464
+ if (empty($ad)) return adinj($content, "no random ad defined");
465
 
466
  if ($ad_include !== false) $content = $ad_include.$content;
467
 
567
  sort($inj_positions);
568
 
569
  // Insert ads in reverse order
 
570
  global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
571
  for ($adnum=sizeof($inj_positions)-1; $adnum>=0; $adnum--){
572
  $content = substr_replace($content, $ad, $inj_positions[$adnum], 0);
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: reviewmylife
3
  Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
4
  Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free
5
- Requires at least: 3.0.0
6
  Tested up to: 3.0.3
7
- Stable tag: 0.9.4.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
 
@@ -120,6 +120,10 @@ Yes you can do this, there are two ways.
120
  1. In the 'Single posts and pages' setting set the number of injected ads to 0. Then in the 'Home page' settings set the number of ads to whatever you want.
121
  2. Alternatively use the global exclude options at the top to exclude ads from all page types except the home page.
122
 
 
 
 
 
123
  = What if I am using an incompatible caching plugin? =
124
 
125
  Don't worry - everything will still work except for:
@@ -197,6 +201,11 @@ If you do get any errors please use the 'Report a bug or give feedback' link on
197
 
198
  == Changelog ==
199
 
 
 
 
 
 
200
  = 0.9.4.3 =
201
  Only write to config file in mfunc mode.
202
 
@@ -269,6 +278,9 @@ Fix 'Something badly wrong in num_rand_ads_to_insert' message that occurs on pag
269
 
270
  == Upgrade Notice ==
271
 
 
 
 
272
  = 0.9.4.3 =
273
  If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
274
 
2
  Contributors: reviewmylife
3
  Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
4
  Tags: ad injection, adsense, advert injection, advert, ad, injection, advertising, affiliate, inject, injection, insert, widget, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, Adsense Injection, free
5
+ Requires at least: 2.8.6
6
  Tested up to: 3.0.3
7
+ Stable tag: 0.9.4.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
 
120
  1. In the 'Single posts and pages' setting set the number of injected ads to 0. Then in the 'Home page' settings set the number of ads to whatever you want.
121
  2. Alternatively use the global exclude options at the top to exclude ads from all page types except the home page.
122
 
123
+ = My adverts are overlapping with other page elements (e.g. images) =
124
+
125
+ You can try defining the 'clear' display setting so that multiple floated parts of your page do not overlap.
126
+
127
  = What if I am using an incompatible caching plugin? =
128
 
129
  Don't worry - everything will still work except for:
201
 
202
  == Changelog ==
203
 
204
+ = 0.9.4.4 =
205
+ New display option for defining CSS clear as left, right or both.
206
+ Suppress file system warnings.
207
+ Tested on WordPress 2.8.6 - it works!
208
+
209
  = 0.9.4.3 =
210
  Only write to config file in mfunc mode.
211
 
278
 
279
  == Upgrade Notice ==
280
 
281
+ = 0.9.4.4 =
282
+ If you are using mfunc mode or switch to mfunc and have added ad widgets you may need to re-save them to regenerate the ad files.
283
+
284
  = 0.9.4.3 =
285
  If you are using mfunc mode and have added ad widgets with a version prior to 0.9.2 please re-save them to regenerate the ad files (fixed for upgrades from 0.9.2).
286