Ad Injection - Version 0.9.0

Version Description

Widget support. Only write to the ad files if necessary. Chrome display fixes. More informative save messages. Other fixes.

Download this release

Release Info

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

Code changes from version 0.8.9 to 0.9.0

Files changed (4) hide show
  1. ad-injection-admin.php +78 -29
  2. ad-injection-widget.php +111 -0
  3. ad-injection.php +20 -6
  4. readme.txt +27 -4
ad-injection-admin.php CHANGED
@@ -6,7 +6,6 @@ http://www.reviewmylife.co.uk/
6
 
7
  if (!is_admin()) return;
8
 
9
- $adinj_error_msg = "";
10
  $adinj_warning_msg_chmod = "";
11
  $adinj_warning_msg_filewrite = "";
12
 
@@ -87,6 +86,8 @@ case 'Save all settings':
87
  // so be careful if adding any new ones - they might not exist yet, but could
88
  // still be referenced by adshow.
89
  function adinj_write_config_file(){
 
 
90
  $referrer_list = adinj_quote_list('ad_referrers');
91
  $ip_list = adinj_quote_list('blocked_ips');
92
  $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false';
@@ -125,6 +126,8 @@ CONFIG;
125
  }
126
 
127
  function adinj_write_file($path, $content, $permission){
 
 
128
  global $adinj_warning_msg_filewrite;
129
  $handle = fopen($path, "w");
130
  fwrite($handle, $content) or $adinj_warning_msg_filewrite .= "<br />Error: could not write to file: $path";
@@ -137,7 +140,7 @@ function adinj_chmod($path, $permission){
137
  $oldperm = fileperms($path);
138
  if ($permission == $oldperm) return;
139
  chmod($path, $permission) or $adinj_warning_msg_chmod .= "<br />Warning: chmod ".decoct($permission).
140
- " on $path failed. Current permissions: ".substr(decoct($oldperm) ,-4).'.<br /> Try manually updating the permission if problems occur.';
141
  }
142
 
143
  function adinj_get_logo(){
@@ -149,8 +152,8 @@ function adinj_options_page(){
149
  if ($options === false || adinj_options_need_upgrading($options)){
150
  // Upgraded via FTP without being deactivated/reactivated
151
  adinj_activate_hook();
152
- $options = adinj_options(1);
153
  }
 
154
  if (!file_exists(ADINJ_CONFIG_FILE)){
155
  adinj_write_config_file();
156
  }
@@ -185,6 +188,10 @@ function adinj_options_page(){
185
  if (!empty($adinj_warning_msg_chmod)){
186
  echo '<br />Info: Some warnings were generated by chmod. See the <a href="#debugging">debugging</a> section for more info.';
187
  }
 
 
 
 
188
  echo '</p></div>';
189
 
190
  }
@@ -220,14 +227,21 @@ function adinj_options_page(){
220
  </div>
221
  </div>
222
 
223
- <p><a href="#random">Random ads</a> | <a href="#topad">Top ad</a> | <a href="#bottomad">Bottom ad</a> | <a href="#restrictions">Ad insertion mode/dynamic restrictions</a> | <a href="#debugging">Debugging</a> | <a href="#docs">Quick Start</a> | <a href="#testads">Test ads</a></p>
224
 
225
  <form name="adinjform" method="post" action="">
226
  <?php wp_nonce_field('_adinj_form', '_adinj_nonce'); ?>
227
 
 
 
 
 
228
  <p><input type="checkbox" name="ads_enabled" <?php echo adinj_ticked('ads_enabled'); ?> /><b><?php _e('Ads enabled', 'adinj') ?></b> - Tick this to turn your ads on!<br />
 
 
 
229
  <?php _e("Only show ads on pages older than ", 'adinj') ?>
230
-
231
  <select name='ads_on_page_older_than'>
232
  <?php
233
  $older_than_days = array(0, 1, 2, 3, 5, 7, 10, 14, 21, 28, 40, 50);
@@ -237,8 +251,22 @@ function adinj_options_page(){
237
  echo ">$older_than_days[$value]</option>";
238
  }
239
  ?>
240
- </select><?php _e(" (days)", 'adinj') ?></p>
241
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
 
243
  <?php adinj_postbox_start(__("Randomly Injected ad code", 'adinj'), 'random'); ?>
244
 
@@ -248,6 +276,10 @@ function adinj_options_page(){
248
  </td><td style="vertical-align: top">
249
  <?php adinj_add_alignment_options('rnd_'); ?>
250
  </td></tr>
 
 
 
 
251
  </table>
252
 
253
 
@@ -258,27 +290,16 @@ function adinj_options_page(){
258
  <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
259
  <h3><?php _e("Single posts and pages: Randomly Injected ad settings", 'adinj') ?></h3>
260
  <div class="inside" style="margin:10px">
 
261
 
262
  <table border="0">
263
 
264
- <tr><td>
265
- <?php _e("Always put the first ad after the first paragraph.", 'adinj') ?>
266
- </td><td>
267
- <input type="checkbox" name="first_paragraph_ad" <?php echo adinj_ticked('first_paragraph_ad'); ?> />
268
- </td></tr>
269
-
270
  <tr><td>
271
  <?php _e("Allow multiple ads to be injected at the same positions.", 'adinj') ?>
272
  </td><td>
273
- <input type="checkbox" name="multiple_ads_at_same_position" <?php echo adinj_ticked('multiple_ads_at_same_position'); ?> /> (The default behaviour is to inject ads at unique positions)
274
- </td></tr>
275
-
276
- <tr><td>
277
- <p>Don't show ads on these page types: </p>
278
- </td><td>
279
- <input type="checkbox" name="exclude_page" <?php echo adinj_ticked('exclude_page'); ?> />page (<?php echo wp_count_posts('page', 'readable')->publish; ?> page(s))<br />
280
- <input type="checkbox" name="exclude_single" <?php echo adinj_ticked('exclude_single'); ?> />single (<?php echo wp_count_posts('post', 'readable')->publish; ?> individual blog post(s))<br />
281
  </td></tr>
 
282
 
283
  <tr><td>
284
  <?php _e("Maximum number of randomly injected ads: ", 'adinj') ?></td><td>
@@ -345,7 +366,7 @@ function adinj_options_page(){
345
  <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
346
  <h3><?php _e("Home page: Randomly Injected ad settings", 'adinj') ?> (<?php echo get_bloginfo('url'); ?>)</h3>
347
  <div class="inside" style="margin:10px">
348
-
349
 
350
  <?php _e("Maximum number of injected ads: ", 'adinj') ?>
351
  <select name='max_num_of_ads_home_page'>
@@ -416,6 +437,27 @@ function adinj_options_page(){
416
  <?php adinj_postbox_end(); ?>
417
 
418
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
  <?php adinj_postbox_start(__("Ad insertion mode and dynamic ad display restrictions", 'adinj'), 'restrictions'); ?>
420
 
421
  <h4>Ad insertion mode</h4>
@@ -433,14 +475,14 @@ function adinj_options_page(){
433
 
434
  <blockquote>
435
  <input type="checkbox" name="sevisitors_only" <?php echo adinj_ticked('sevisitors_only'); ?> /><?php _e("Only show ads to search engine visitors (customise search engine referrers below if necessary).", 'adinj') ?><br />
436
- <textarea name="ad_referrers" rows="2" cols="80"><?php echo $options['ad_referrers']; ?></textarea>
437
  <p>Comma separated list e.g.: <br /><code>.google., .bing., .yahoo., .ask., search?, search., /search/</code></p>
438
  </blockquote>
439
 
440
  <h4>Blocked IP addresses (dynamic feature)</h4>
441
 
442
  <blockquote>
443
- <textarea name="blocked_ips" rows="4" cols="80"><?php echo $options['blocked_ips']; ?></textarea>
444
  <p>Comma separated list e.g.: <br /><code>0.0.0.1, 0.0.0.2</code></p>
445
  <p>Or you can list one IP per line with optional comments e.g.</p>
446
  <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>
@@ -591,8 +633,8 @@ function adinj_debug_information(){
591
  $stored_options = adinj_options();
592
  $default_options = adinj_default_options();
593
  ?>
594
- <h4>Settings dump from database (all in 'adinj_options' option)</h4><blockquote>
595
- <table border="1">
596
  <tr><td><b>Name</b></td><td><b>Stored</b></td><td><b>Default</b></td></tr>
597
  <?php
598
  if ($stored_options !== false){
@@ -616,7 +658,6 @@ function adinj_debug_information(){
616
  echo "<br />No options in database!";
617
  }
618
  echo '</table>';
619
- echo '</blockquote>';
620
 
621
  echo '<h4>Other settings</h4><blockquote>';
622
 
@@ -766,9 +807,15 @@ function adinj_default_options(){
766
  'bottom_align' => ADINJ_RULE_DISABLED,
767
  'bottom_margin_top' => '3',
768
  'bottom_margin_bottom' => '3',
 
 
 
 
769
  'ads_on_page_older_than' => '10',
 
770
  'exclude_page' => '',
771
  'exclude_single' => '',
 
772
  'first_paragraph_ad' => '',
773
  'multiple_ads_at_same_position' => '',
774
  'sevisitors_only' => '',
@@ -778,9 +825,11 @@ function adinj_default_options(){
778
  'ad_code_random_1' => '',
779
  'ad_code_top_1' => '',
780
  'ad_code_bottom_1' => '',
 
781
  'ui_random_hide' => 'false',
782
  'ui_topad_hide' => 'false',
783
  'ui_bottomad_hide' => 'false',
 
784
  'ui_restrictions_hide' => 'false',
785
  'ui_debugging_hide' => 'true',
786
  'ui_docs_hide' => 'false',
@@ -795,8 +844,8 @@ function adinj_getdefault($option){
795
  }
796
 
797
  function write_ad_to_file($ad, $ad_path){
798
- adinj_chmod(ADINJ_AD_PATH, 0750);
799
- if (strlen($ad) >0){
800
  adinj_write_file($ad_path, $ad, 0640);
801
  }
802
  }
6
 
7
  if (!is_admin()) return;
8
 
 
9
  $adinj_warning_msg_chmod = "";
10
  $adinj_warning_msg_filewrite = "";
11
 
86
  // so be careful if adding any new ones - they might not exist yet, but could
87
  // still be referenced by adshow.
88
  function adinj_write_config_file(){
89
+ $options = adinj_options();
90
+ if ($options['ad_insertion_mode'] != 'mfunc') return;
91
  $referrer_list = adinj_quote_list('ad_referrers');
92
  $ip_list = adinj_quote_list('blocked_ips');
93
  $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false';
126
  }
127
 
128
  function adinj_write_file($path, $content, $permission){
129
+ $options = adinj_options();
130
+ if ($options['ad_insertion_mode'] != 'mfunc') return;
131
  global $adinj_warning_msg_filewrite;
132
  $handle = fopen($path, "w");
133
  fwrite($handle, $content) or $adinj_warning_msg_filewrite .= "<br />Error: could not write to file: $path";
140
  $oldperm = fileperms($path);
141
  if ($permission == $oldperm) return;
142
  chmod($path, $permission) or $adinj_warning_msg_chmod .= "<br />Warning: chmod ".decoct($permission).
143
+ " on $path failed. Current permissions: ".substr(decoct($oldperm), -4).'.<br /> Try manually updating the permission if problems occur.';
144
  }
145
 
146
  function adinj_get_logo(){
152
  if ($options === false || adinj_options_need_upgrading($options)){
153
  // Upgraded via FTP without being deactivated/reactivated
154
  adinj_activate_hook();
 
155
  }
156
+ $options = adinj_options(1);
157
  if (!file_exists(ADINJ_CONFIG_FILE)){
158
  adinj_write_config_file();
159
  }
188
  if (!empty($adinj_warning_msg_chmod)){
189
  echo '<br />Info: Some warnings were generated by chmod. See the <a href="#debugging">debugging</a> section for more info.';
190
  }
191
+ echo '<br />Info: <a href="#restrictions">injection mode</a>='.$options['ad_insertion_mode'];
192
+ if (empty($options['ads_enabled'])){
193
+ echo '<br /><font color="red">Warning: Ads are currently disabled. You need to tick the "Ads enabled" box to see them.</font>';
194
+ }
195
  echo '</p></div>';
196
 
197
  }
227
  </div>
228
  </div>
229
 
230
+ <p><a href="#random">Random ads</a> | <a href="#topad">Top</a> | <a href="#bottomad">Bottom</a> | <a href="#widgets">Widgets</a> | <a href="#restrictions">Ad insert mode/dynamic restrictions</a> | <a href="#debugging">Debug</a> | <a href="#docs">Quick Start</a> | <a href="#testads">Test ads</a></p>
231
 
232
  <form name="adinjform" method="post" action="">
233
  <?php wp_nonce_field('_adinj_form', '_adinj_nonce'); ?>
234
 
235
+ <?php adinj_postbox_start(__("Global settings", 'adinj'), 'global'); ?>
236
+
237
+ <p>These settings apply to all ads (random, top, bottom, and widget). They will override all other settings.</p>
238
+
239
  <p><input type="checkbox" name="ads_enabled" <?php echo adinj_ticked('ads_enabled'); ?> /><b><?php _e('Ads enabled', 'adinj') ?></b> - Tick this to turn your ads on!<br />
240
+
241
+ <table border="0">
242
+ <tr><td>
243
  <?php _e("Only show ads on pages older than ", 'adinj') ?>
244
+ </td><td>
245
  <select name='ads_on_page_older_than'>
246
  <?php
247
  $older_than_days = array(0, 1, 2, 3, 5, 7, 10, 14, 21, 28, 40, 50);
251
  echo ">$older_than_days[$value]</option>";
252
  }
253
  ?>
254
+ </select><?php _e(" (days)", 'adinj') ?> (only for single posts and pages)</p>
255
+ </td></tr>
256
+ <tr><td>
257
+ Don't show ads on these page types:
258
+ </td><td>
259
+ <input type="checkbox" name="exclude_home" <?php echo adinj_ticked('exclude_home'); ?> />home<br />
260
+ <input type="checkbox" name="exclude_page" <?php echo adinj_ticked('exclude_page'); ?> />page (<?php echo wp_count_posts('page', 'readable')->publish; ?> page(s))<br />
261
+ <input type="checkbox" name="exclude_single" <?php echo adinj_ticked('exclude_single'); ?> />single (<?php echo wp_count_posts('post', 'readable')->publish; ?> individual blog post(s))<br />
262
+ <input type="checkbox" name="exclude_archive" <?php echo adinj_ticked('exclude_archive'); ?> />archive (only <a href="#widgets">widgets</a> currently appear on archives)<br />
263
+ </td></tr>
264
+ </table>
265
+
266
+ <?php adinj_postbox_end(); ?>
267
+
268
+
269
+
270
 
271
  <?php adinj_postbox_start(__("Randomly Injected ad code", 'adinj'), 'random'); ?>
272
 
276
  </td><td style="vertical-align: top">
277
  <?php adinj_add_alignment_options('rnd_'); ?>
278
  </td></tr>
279
+ <tr><td>
280
+ <?php _e("Always put the first ad after the first paragraph.", 'adinj') ?> <input type="checkbox" name="first_paragraph_ad" <?php echo adinj_ticked('first_paragraph_ad'); ?> />
281
+ </td><td>
282
+ </td></tr>
283
  </table>
284
 
285
 
290
  <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
291
  <h3><?php _e("Single posts and pages: Randomly Injected ad settings", 'adinj') ?></h3>
292
  <div class="inside" style="margin:10px">
293
+ <p>These random ad injection settings are specific to individual posts and pages.</p>
294
 
295
  <table border="0">
296
 
 
 
 
 
 
 
297
  <tr><td>
298
  <?php _e("Allow multiple ads to be injected at the same positions.", 'adinj') ?>
299
  </td><td>
300
+ <input type="checkbox" name="multiple_ads_at_same_position" <?php echo adinj_ticked('multiple_ads_at_same_position'); ?> /> (default is to inject ads at unique positions)
 
 
 
 
 
 
 
301
  </td></tr>
302
+
303
 
304
  <tr><td>
305
  <?php _e("Maximum number of randomly injected ads: ", 'adinj') ?></td><td>
366
  <input type="submit" style="float:right" name="adinj_action" value="<?php _e('Save all settings', 'adinj') ?>" />
367
  <h3><?php _e("Home page: Randomly Injected ad settings", 'adinj') ?> (<?php echo get_bloginfo('url'); ?>)</h3>
368
  <div class="inside" style="margin:10px">
369
+ <p>These random ad injection settings are specific to your home page.</p>
370
 
371
  <?php _e("Maximum number of injected ads: ", 'adinj') ?>
372
  <select name='max_num_of_ads_home_page'>
437
  <?php adinj_postbox_end(); ?>
438
 
439
 
440
+ <?php adinj_postbox_start(__("Widget settings", 'adinj'), 'widgets'); ?>
441
+
442
+ <p>You must configure your individual widgets from the <a href="widgets.php">widgets control panel</a>. However these settings are global to all widgets. Also note that the main set of <a href="#global">global settings</a> will override these ones.</p>
443
+
444
+ <table border="0">
445
+
446
+ <tr><td>
447
+ <p>Don't show widget ads on these page types:</p>
448
+ </td><td>
449
+ <input type="checkbox" name="widget_exclude_home" <?php echo adinj_ticked('widget_exclude_home'); ?> />home<br />
450
+ <input type="checkbox" name="widget_exclude_page" <?php echo adinj_ticked('widget_exclude_page'); ?> />page (<?php echo wp_count_posts('page', 'readable')->publish; ?> page(s))<br />
451
+ <input type="checkbox" name="widget_exclude_single" <?php echo adinj_ticked('widget_exclude_single'); ?> />single (<?php echo wp_count_posts('post', 'readable')->publish; ?> individual blog post(s))<br />
452
+ <input type="checkbox" name="widget_exclude_archive" <?php echo adinj_ticked('widget_exclude_archive'); ?> />archive (includes category, tag, author, and date pages types)<br />
453
+ </td></tr>
454
+
455
+ </table>
456
+
457
+
458
+ <?php adinj_postbox_end(); ?>
459
+
460
+
461
  <?php adinj_postbox_start(__("Ad insertion mode and dynamic ad display restrictions", 'adinj'), 'restrictions'); ?>
462
 
463
  <h4>Ad insertion mode</h4>
475
 
476
  <blockquote>
477
  <input type="checkbox" name="sevisitors_only" <?php echo adinj_ticked('sevisitors_only'); ?> /><?php _e("Only show ads to search engine visitors (customise search engine referrers below if necessary).", 'adinj') ?><br />
478
+ <textarea name="ad_referrers" rows="2" cols="70"><?php echo $options['ad_referrers']; ?></textarea>
479
  <p>Comma separated list e.g.: <br /><code>.google., .bing., .yahoo., .ask., search?, search., /search/</code></p>
480
  </blockquote>
481
 
482
  <h4>Blocked IP addresses (dynamic feature)</h4>
483
 
484
  <blockquote>
485
+ <textarea name="blocked_ips" rows="4" cols="70"><?php echo $options['blocked_ips']; ?></textarea>
486
  <p>Comma separated list e.g.: <br /><code>0.0.0.1, 0.0.0.2</code></p>
487
  <p>Or you can list one IP per line with optional comments e.g.</p>
488
  <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>
633
  $stored_options = adinj_options();
634
  $default_options = adinj_default_options();
635
  ?>
636
+ <h4>Settings dump from database (all in 'adinj_options' option)</h4>
637
+ <table border="1" style="width:610px; table-layout:fixed; word-wrap:break-word;">
638
  <tr><td><b>Name</b></td><td><b>Stored</b></td><td><b>Default</b></td></tr>
639
  <?php
640
  if ($stored_options !== false){
658
  echo "<br />No options in database!";
659
  }
660
  echo '</table>';
 
661
 
662
  echo '<h4>Other settings</h4><blockquote>';
663
 
807
  'bottom_align' => ADINJ_RULE_DISABLED,
808
  'bottom_margin_top' => '3',
809
  'bottom_margin_bottom' => '3',
810
+ 'widget_exclude_home' => '',
811
+ 'widget_exclude_page' => '',
812
+ 'widget_exclude_single' => '',
813
+ 'widget_exclude_archive' => '',
814
  'ads_on_page_older_than' => '10',
815
+ 'exclude_home' => '',
816
  'exclude_page' => '',
817
  'exclude_single' => '',
818
+ 'exclude_archive' => '',
819
  'first_paragraph_ad' => '',
820
  'multiple_ads_at_same_position' => '',
821
  'sevisitors_only' => '',
825
  'ad_code_random_1' => '',
826
  'ad_code_top_1' => '',
827
  'ad_code_bottom_1' => '',
828
+ 'ui_global_hide' => 'false',
829
  'ui_random_hide' => 'false',
830
  'ui_topad_hide' => 'false',
831
  'ui_bottomad_hide' => 'false',
832
+ 'ui_widgets_hide' => 'false',
833
  'ui_restrictions_hide' => 'false',
834
  'ui_debugging_hide' => 'true',
835
  'ui_docs_hide' => 'false',
844
  }
845
 
846
  function write_ad_to_file($ad, $ad_path){
847
+ if (strlen($ad) > 0){
848
+ adinj_chmod(ADINJ_AD_PATH, 0750);
849
  adinj_write_file($ad_path, $ad, 0640);
850
  }
851
  }
ad-injection-widget.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Part of the Ad Injection plugin for WordPress
4
+ http://www.reviewmylife.co.uk/
5
+ */
6
+
7
+ class Ad_Injection_Widget extends WP_Widget {
8
+ function Ad_Injection_Widget() {
9
+ $widget_ops = array( 'classname' => 'adinjwidget', 'description' => 'Insert Ad Injection adverts into your sidebars/widget areas.' );
10
+ $control_ops = array( 'width' => 400, 'height' => 300, 'id_base' => 'adinj' );
11
+ $this->WP_Widget( 'adinj', 'Ad Injection', $widget_ops, $control_ops );
12
+ }
13
+
14
+ function widget( $args, $instance ) {
15
+ if (adinj_ads_completely_disabled_from_page()) return;
16
+ $options = adinj_options();
17
+
18
+ if ((is_home() && adinj_ticked('widget_exclude_home')) ||
19
+ (is_page() && adinj_ticked('widget_exclude_page')) ||
20
+ (is_single() && adinj_ticked('widget_exclude_single')) ||
21
+ (is_archive() && adinj_ticked('widget_exclude_archive'))){
22
+ return;
23
+ }
24
+
25
+ extract( $args );
26
+
27
+ $title = apply_filters('widget_title', $instance['title'] );
28
+ $advert = $instance['advert'];
29
+
30
+ echo $before_widget;
31
+ if ( $title ) {
32
+ echo $before_title . $title . $after_title;
33
+ }
34
+
35
+ $adcode = "";
36
+ if ($options['ad_insertion_mode'] == 'mfunc'){
37
+ $adcode = adinj_get_mfunc_code($this->get_ad_file_name());
38
+ } else {
39
+ $adcode = $advert;
40
+ }
41
+ $adcode = adinj_ad_code_eval($adcode);
42
+
43
+ if ( $advert ){
44
+ echo $adcode;
45
+ }
46
+
47
+ echo $after_widget;
48
+ }
49
+
50
+ function update( $new_instance, $old_instance ) {
51
+ $instance = $old_instance;
52
+
53
+ /* Strip tags (if needed) and update the widget settings. */
54
+ $instance['title'] = strip_tags( $new_instance['title'] );
55
+ $instance['advert'] = $new_instance['advert'];
56
+
57
+ write_ad_to_file($instance['advert'], $this->get_ad_file_path());
58
+
59
+ return $instance;
60
+ }
61
+
62
+ function form( $instance ) {
63
+
64
+ /* Set up some default widget settings. */
65
+ $defaults = array( 'title' => '', 'advert' => '' );
66
+ $instance = wp_parse_args( (array) $instance, $defaults );
67
+ ?>
68
+
69
+ <p>
70
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
71
+ <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
72
+ <br />
73
+ <span style="font-size:10px;">Make sure any label complies with your ad provider's TOS. More info for <a href="http://adsense.blogspot.com/2007/04/encouraging-clicks.html" target="_new">AdSense</a> users.</span>
74
+ </p>
75
+
76
+ <p>
77
+ <label for="<?php echo $this->get_field_id( 'advert' ); ?>">Ad code:</label>
78
+ <textarea class="widefat" rows="12" cols="20" id="<?php echo $this->get_field_id( 'advert' ); ?>" name="<?php echo $this->get_field_name( 'advert' ); ?>"><?php echo $instance['advert']; ?></textarea>
79
+ </p>
80
+
81
+ <p>The following dynamic options to define who sees these adverts are on the main <a href='options-general.php?page=ad-injection.php'>Ad Injection settings page</a>. The title will however always be displayed. If you want the title to be dynamic as well you should embed it in the ad code text box.</p>
82
+
83
+ <blockquote>
84
+ <ul>
85
+ <li>Ads on pages older than...</li>
86
+ <li>Ads for search engine visitors only.</li>
87
+ <li>Block ads by IP.</li>
88
+ </ul>
89
+ </blockquote>
90
+
91
+ <p>You can also set which <a href='options-general.php?page=ad-injection.php#widgets'>page types</a> the widgets appear on.</p>
92
+
93
+ <?php
94
+ }
95
+
96
+ function get_ad_file_path(){
97
+ return ADINJ_AD_PATH.'/'.get_ad_file_name();
98
+ }
99
+
100
+ function get_ad_file_name(){
101
+ return 'ad_widget_'.$this->get_id().'.txt';
102
+ }
103
+
104
+ function get_id(){
105
+ $field = $this->get_field_id('advert');
106
+ preg_match('/-(\d+)-/', $field, $matches);
107
+ return $matches[1];
108
+ }
109
+ }
110
+
111
+ ?>
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: Inserts any advert into your blog. Options to exclude by post age, visitor IP, and visitor referrer. Works with WP Super Cache.
6
- Version: 0.8.9
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
@@ -81,17 +81,18 @@ function adinj_option($option){
81
  //$cookie_domain = COOKIE_DOMAIN; // TODO test
82
  //var adinj_cookie_domain = "$cookie_domain"; //JS line. TODO test
83
  function adinj_print_referrers_hook(){
84
- if (adinj_ads_completely_disabled_from_page()) return;
 
85
  if (adinj_ticked('sevisitors_only')){
86
  $referrer_list = adinj_quote_list('ad_referrers');
87
  echo <<<SCRIPT
88
  <script type="text/javascript">
 
89
  var adinj_referrers = new Array($referrer_list);
90
  adinj_searchenginevisitor();
91
  </script>
92
 
93
  SCRIPT;
94
- // TODO add comment to script // Ad Injection plugin
95
  }
96
  }
97
 
@@ -116,7 +117,9 @@ function adinj_quote_list($option){
116
  }
117
 
118
  function adinj_addsevjs_hook(){
119
- if (adinj_ads_completely_disabled_from_page()) return;
 
 
120
  // Put the search engine detection / cookie setting script in the footer
121
  wp_enqueue_script('adinj_sev', WP_PLUGIN_URL.'/ad-injection/adinj-sev.js', NULL, NULL, true);
122
  }
@@ -340,7 +343,8 @@ function adinj_ads_completely_disabled_from_page($content=NULL){
340
  if ((is_home() && adinj_ticked('exclude_home')) ||
341
  (is_page() && adinj_ticked('exclude_page')) ||
342
  (is_single() && adinj_ticked('exclude_single')) ||
343
- (is_archive() || is_search() || is_404())){
 
344
  return "NOADS: excluded from this post type-".get_post_type();
345
  }
346
 
@@ -439,7 +443,10 @@ function adinj_inject_hook($content){
439
  $content_adfree_footer = $split[1];
440
  }
441
 
442
- # Move onto random ad insertions
 
 
 
443
  $paragraphmarker = "</p>";
444
  if(stripos($content, $paragraphmarker) === false) return adinj($content, "no &lt;/p&gt; tags");
445
 
@@ -580,6 +587,13 @@ function adinj_ticked($option){
580
  return false;
581
  }
582
 
 
 
 
 
 
 
 
583
  // activate
584
  register_activation_hook( __FILE__, 'adinj_activate_hook' );
585
  // Content injection
3
  Plugin Name: Ad Injection
4
  Plugin URI: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
5
  Description: Inserts any advert into your blog. Options to exclude by post age, visitor IP, and visitor referrer. Works with WP Super Cache.
6
+ Version: 0.9.0
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
81
  //$cookie_domain = COOKIE_DOMAIN; // TODO test
82
  //var adinj_cookie_domain = "$cookie_domain"; //JS line. TODO test
83
  function adinj_print_referrers_hook(){
84
+ // TODO can re-enable this check once the widget ads are factored in.
85
+ //if (adinj_ads_completely_disabled_from_page()) return;
86
  if (adinj_ticked('sevisitors_only')){
87
  $referrer_list = adinj_quote_list('ad_referrers');
88
  echo <<<SCRIPT
89
  <script type="text/javascript">
90
+ // Ad Injection plugin
91
  var adinj_referrers = new Array($referrer_list);
92
  adinj_searchenginevisitor();
93
  </script>
94
 
95
  SCRIPT;
 
96
  }
97
  }
98
 
117
  }
118
 
119
  function adinj_addsevjs_hook(){
120
+ // TODO can re-enable this check once the widget ads are factored in.
121
+ //if (adinj_ads_completely_disabled_from_page()) return;
122
+ if (!adinj_ticked('sevisitors_only')) return;
123
  // Put the search engine detection / cookie setting script in the footer
124
  wp_enqueue_script('adinj_sev', WP_PLUGIN_URL.'/ad-injection/adinj-sev.js', NULL, NULL, true);
125
  }
343
  if ((is_home() && adinj_ticked('exclude_home')) ||
344
  (is_page() && adinj_ticked('exclude_page')) ||
345
  (is_single() && adinj_ticked('exclude_single')) ||
346
+ (is_archive() && adinj_ticked('exclude_archive')) ||
347
+ is_search() || is_404()){
348
  return "NOADS: excluded from this post type-".get_post_type();
349
  }
350
 
443
  $content_adfree_footer = $split[1];
444
  }
445
 
446
+ // TODO add note explaining that start tags are processed before the 'first
447
+ // paragraph ad
448
+
449
+ // Move onto random ad insertions
450
  $paragraphmarker = "</p>";
451
  if(stripos($content, $paragraphmarker) === false) return adinj($content, "no &lt;/p&gt; tags");
452
 
587
  return false;
588
  }
589
 
590
+ // Widget support
591
+ require_once('ad-injection-widget.php');
592
+ add_action('widgets_init', 'adinj_widgets_init');
593
+ function adinj_widgets_init() {
594
+ register_widget('Ad_Injection_Widget');
595
+ }
596
+
597
  // activate
598
  register_activation_hook( __FILE__, 'adinj_activate_hook' );
599
  // Content injection
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Ad Injection ===
2
  Contributors: reviewmylife
3
  Donate link: http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/
4
- Tags: ad injection, advert injection, advert, ad, injection, adsense, advertising, affiliate, inject, injection, insert, monetize, monetise, banner, Amazon, ClickBank, TradeDoubler, Google, adBrite, post, WordPress, automatically, plugin, free
5
  Requires at least: 3.0.0
6
  Tested up to: 3.0.3
7
- Stable tag: 0.8.9
8
 
9
  Injects any kind of advert into existing WordPress posts. Can restrict who sees the ads by post age, visitor referrer, IP address. Cache compatible.
10
 
@@ -16,11 +16,15 @@ It injects any kind of advert (e.g. Google AdSense, Amazon Associates, ClickBank
16
 
17
  The ads can be injected into existing posts without requiring any modification of the post. The injection can be done randomly between paragraphs, and there is an option to always inject the first advert after the first paragraph. Two separate adverts can be defined for the top and bottom of the content. Randomly positioning the adverts helps to reduce 'ad blindness'.
18
 
 
 
 
 
19
  = Ad quantity by post length =
20
 
21
  The number of adverts can be set based on the length of the post. It is a good idea for longer posts to have more adverts than shorter posts for example. Adverts can also be turned off for very short posts.
22
 
23
- = Search engines only =
24
 
25
  You can specify that ads should only be shown to search engine visitors (or from any other referring websites) so that your regular visitors (who are unlikely to click your ads) get a better experience of your site. You can define which search engines or any other referring sites see your adverts. A visitor who enters the site by a search engine will see ads for the next hour.
26
 
@@ -94,6 +98,15 @@ No! All the features of this plugin will work with no caching plugin installed.
94
 
95
  Potentially - if they are compatible with WP Super Cache's mfunc tags. I'm guessing they will work with the original WP Cache as I think the mfunc tags in WP Super Cache were inherited from here. However I haven't yet tested this. W3 Total Cache does have support for some kind of mfunc tags, but I haven't tested to see if they are compatible with the WP Super Cache ones. Do let me know!
96
 
 
 
 
 
 
 
 
 
 
97
  = What if I am using an incompatible caching plugin? =
98
 
99
  Don't worry - everything will still work except for:
@@ -145,7 +158,7 @@ If you are getting errors when using the plugin check the following.
145
  2. Are there text files in the ads directory? The ad code that you enter into the ad boxes should get saved in text files in the ads directory.
146
  3. Has the config file been created? It should be at '/wp-content/plugins/ad-injection/ad-injection-config.php'. If not make sure the '/wp-content/plugins/ad-injection/' directory is writeable (chmod 0750 is best, chmod 0755 will do).
147
 
148
- If you do get any errors please use the 'Report a bug or give feedback' link on the plugin to send me the error details. If things go so badly wrong that you can't even get to the settings page please send me an email via [this contact form](http://www.reviewmylife.co.uk/blog/contact-us/ "contact form").
149
 
150
  For more information visit [reviewmylife](http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/ "reviewmylife blog").
151
 
@@ -157,6 +170,13 @@ For more information visit [reviewmylife](http://www.reviewmylife.co.uk/blog/201
157
 
158
  == Changelog ==
159
 
 
 
 
 
 
 
 
160
  = 0.8.9 =
161
  Prevent config file being lost by bulk automatic update.
162
  Error messages from adshow.php are hidden in HTML now rather than being visible to everyone.
@@ -184,6 +204,9 @@ Fix 'Something badly wrong in num_rand_ads_to_insert' message that occurs on pag
184
 
185
  == Upgrade Notice ==
186
 
 
 
 
187
  = 0.8.9 =
188
  Upgrade to this version by going to the plugins tab and upgrading the individual plugin. If you upgrade from the bulk updator the mfunc config file will be lost and you would have to go to 'Save all settings' to re-generate it. This version attempts to solve the bulk update problem.
189
 
1
  === Ad Injection ===
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, 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.0
8
 
9
  Injects any kind of advert into existing WordPress posts. Can restrict who sees the ads by post age, visitor referrer, IP address. Cache compatible.
10
 
16
 
17
  The ads can be injected into existing posts without requiring any modification of the post. The injection can be done randomly between paragraphs, and there is an option to always inject the first advert after the first paragraph. Two separate adverts can be defined for the top and bottom of the content. Randomly positioning the adverts helps to reduce 'ad blindness'.
18
 
19
+ = Widget support [new] =
20
+
21
+ Widgets can be added to your sidebars, or other widget areas on any pages. The same ad display restrictions that you setup for your other ads will also apply to the widgets.
22
+
23
  = Ad quantity by post length =
24
 
25
  The number of adverts can be set based on the length of the post. It is a good idea for longer posts to have more adverts than shorter posts for example. Adverts can also be turned off for very short posts.
26
 
27
+ = Search engines only mode =
28
 
29
  You can specify that ads should only be shown to search engine visitors (or from any other referring websites) so that your regular visitors (who are unlikely to click your ads) get a better experience of your site. You can define which search engines or any other referring sites see your adverts. A visitor who enters the site by a search engine will see ads for the next hour.
30
 
98
 
99
  Potentially - if they are compatible with WP Super Cache's mfunc tags. I'm guessing they will work with the original WP Cache as I think the mfunc tags in WP Super Cache were inherited from here. However I haven't yet tested this. W3 Total Cache does have support for some kind of mfunc tags, but I haven't tested to see if they are compatible with the WP Super Cache ones. Do let me know!
100
 
101
+ = Can I just have adverts on the home page? =
102
+
103
+ i.e. adverts on the home page, but not on single posts or pages.
104
+
105
+ Yes you can do this, there are two ways.
106
+
107
+ 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.
108
+ 2. Alternatively use the global exclude options at the top to exclude ads from all page types except the home page.
109
+
110
  = What if I am using an incompatible caching plugin? =
111
 
112
  Don't worry - everything will still work except for:
158
  2. Are there text files in the ads directory? The ad code that you enter into the ad boxes should get saved in text files in the ads directory.
159
  3. Has the config file been created? It should be at '/wp-content/plugins/ad-injection/ad-injection-config.php'. If not make sure the '/wp-content/plugins/ad-injection/' directory is writeable (chmod 0750 is best, chmod 0755 will do).
160
 
161
+ If you do get any errors please use the 'Report a bug or give feedback' link on the plugin to send me the error details. If things go so badly wrong that you can't even get to the settings page please send me an email via [this contact form](http://www.reviewmylife.co.uk/contact-us/ "contact form").
162
 
163
  For more information visit [reviewmylife](http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/ "reviewmylife blog").
164
 
170
 
171
  == Changelog ==
172
 
173
+ = 0.9.0 =
174
+ Widget support.
175
+ Only write to the ad files if necessary.
176
+ Chrome display fixes.
177
+ More informative save messages.
178
+ Other fixes.
179
+
180
  = 0.8.9 =
181
  Prevent config file being lost by bulk automatic update.
182
  Error messages from adshow.php are hidden in HTML now rather than being visible to everyone.
204
 
205
  == Upgrade Notice ==
206
 
207
+ = 0.9.0 =
208
+ Widget support and other fixes.
209
+
210
  = 0.8.9 =
211
  Upgrade to this version by going to the plugins tab and upgrading the individual plugin. If you upgrade from the bulk updator the mfunc config file will be lost and you would have to go to 'Save all settings' to re-generate it. This version attempts to solve the bulk update problem.
212