Ad Injection - Version 0.9.2

Version Description

If you are using mfunc mode and have added ad widgets please re-save them to regenerate the ad files. Save ad files to a new directory so they don't need to be re-created after upgrade.

Download this release

Release Info

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

Code changes from version 0.9.1 to 0.9.2

Files changed (6) hide show
  1. ad-injection-admin.php +35 -11
  2. ad-injection-widget.php +11 -5
  3. ad-injection.php +10 -22
  4. adshow.php +20 -4
  5. readme.txt +11 -3
  6. uninstall.php +20 -0
ad-injection-admin.php CHANGED
@@ -4,6 +4,22 @@ Part of the Ad Injection plugin for WordPress
4
  http://www.reviewmylife.co.uk/
5
  */
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  if (!is_admin()) return;
8
 
9
  $adinj_warning_msg_chmod = "";
@@ -37,23 +53,30 @@ case 'Save all settings':
37
  }
38
  }
39
 
 
40
  if (!file_exists(ADINJ_AD_PATH)){
41
- global $adinj_warning_msg_filewrite;
42
- mkdir(ADINJ_AD_PATH, 0750) //TODO is this the right permission
43
  or $adinj_warning_msg_filewrite .= "<br />Error: could not create dir: ".ADINJ_AD_PATH.". Please create it manually and try again.";
44
  }
 
 
 
 
45
 
46
- // TODO we could stop writing to the ad files if direct insertion mode is used
47
  $raw_ad_code_random = stripslashes($_POST['ad_code_random_1']);
48
  write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE);
 
49
  $options['ad_code_random_1'] = $raw_ad_code_random;
50
 
51
  $raw_ad_code_top = stripslashes($_POST['ad_code_top_1']);
52
  write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE);
 
53
  $options['ad_code_top_1'] = $raw_ad_code_top;
54
 
55
  $raw_ad_code_bottom = stripslashes($_POST['ad_code_bottom_1']);
56
  write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE);
 
57
  $options['ad_code_bottom_1'] = $raw_ad_code_bottom;
58
 
59
  $ad_referrers = stripslashes($_POST['ad_referrers']); // TODO do i need strip slashes?
@@ -236,12 +259,13 @@ function adinj_options_page(){
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);
@@ -403,8 +427,7 @@ function adinj_options_page(){
403
  <?php adinj_add_alignment_options('top_'); ?>
404
  </td></tr>
405
  </table>
406
-
407
- <p><font color="red">Important: Make sure that the total number of ads does not exceed the amount allowed in your ad provider's TOS!</font> The top ad is in addition to the quantity of random ads selected.</p>
408
 
409
  <p><b>Docs:</b> The top ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a <a href="#468x15">468x15</a> or <a href="#336x280">336x280</a> advert.</p>
410
 
@@ -428,8 +451,7 @@ function adinj_options_page(){
428
  <?php adinj_add_alignment_options('bottom_'); ?>
429
  </td></tr>
430
  </table>
431
-
432
- <p><font color="red">Important: Make sure that the total number of ads does not exceed the amount allowed in your ad provider's TOS!</font> The top ad is in addition to the quantity of random ads selected.</p>
433
 
434
  <p><b>Docs:</b> The bottom ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a <a href="#336x280">336x280</a> advert.</p>
435
 
@@ -663,7 +685,8 @@ function adinj_debug_information(){
663
 
664
  echo 'ADINJ_PATH='.ADINJ_PATH.'<br />';
665
  echo 'ADINJ_CONFIG_FILE='.ADINJ_CONFIG_FILE.'<br />';
666
- echo 'ADINJ_AD_PATH='.ADINJ_AD_PATH.'<br />';
 
667
 
668
  echo 'Plugin version='.adinj_get_version();
669
  echo '</blockquote>';
@@ -739,6 +762,8 @@ function adinj_activate_hook() {
739
  }
740
 
741
  // Restore data after automatic upgrade
 
 
742
  $random_file = ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE;
743
  if (!file_exists($random_file) && !empty($pending_options['ad_code_random_1'])){
744
  write_ad_to_file($pending_options['ad_code_random_1'], $random_file);
@@ -845,7 +870,6 @@ function adinj_getdefault($option){
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
  }
4
  http://www.reviewmylife.co.uk/
5
  */
6
 
7
+ /* Copyright 2010 reviewmylife (contact : http://www.reviewmylife.co.uk/)
8
+
9
+ This program is free software; you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License, version 2, as
11
+ published by the Free Software Foundation.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software
20
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ */
22
+
23
  if (!is_admin()) return;
24
 
25
  $adinj_warning_msg_chmod = "";
53
  }
54
  }
55
 
56
+ global $adinj_warning_msg_filewrite;
57
  if (!file_exists(ADINJ_AD_PATH)){
58
+ mkdir(ADINJ_AD_PATH, 0750) //TODO is this the right permission?
 
59
  or $adinj_warning_msg_filewrite .= "<br />Error: could not create dir: ".ADINJ_AD_PATH.". Please create it manually and try again.";
60
  }
61
+ if (!file_exists(ADINJ_AD_PATH2)){
62
+ mkdir(ADINJ_AD_PATH2, 0750) //TODO is this the right permission?
63
+ or $adinj_warning_msg_filewrite .= "<br />Error: could not create dir: ".ADINJ_AD_PATH2.". Please create it manually and try again.";
64
+ }
65
 
66
+ // TODO later stop saving to old ADINJ_AD_PATH
67
  $raw_ad_code_random = stripslashes($_POST['ad_code_random_1']);
68
  write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE);
69
+ write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH2.'/'.ADINJ_AD_RANDOM_FILE);
70
  $options['ad_code_random_1'] = $raw_ad_code_random;
71
 
72
  $raw_ad_code_top = stripslashes($_POST['ad_code_top_1']);
73
  write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE);
74
+ write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH2.'/'.ADINJ_AD_TOP_FILE);
75
  $options['ad_code_top_1'] = $raw_ad_code_top;
76
 
77
  $raw_ad_code_bottom = stripslashes($_POST['ad_code_bottom_1']);
78
  write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE);
79
+ write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH2.'/'.ADINJ_AD_BOTTOM_FILE);
80
  $options['ad_code_bottom_1'] = $raw_ad_code_bottom;
81
 
82
  $ad_referrers = stripslashes($_POST['ad_referrers']); // TODO do i need strip slashes?
259
 
260
  <p>These settings apply to all ads (random, top, bottom, and widget). They will override all other settings.</p>
261
 
262
+ <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!</p><br />
263
 
264
  <table border="0">
265
  <tr><td>
266
+ <p><?php _e("Only show ads on pages older than ", 'adinj') ?></p>
267
  </td><td>
268
+ <p>
269
  <select name='ads_on_page_older_than'>
270
  <?php
271
  $older_than_days = array(0, 1, 2, 3, 5, 7, 10, 14, 21, 28, 40, 50);
427
  <?php adinj_add_alignment_options('top_'); ?>
428
  </td></tr>
429
  </table>
430
+ <span style="font-size:10px;">The top ad is in addition to the quantity of other ads selected.</span>
 
431
 
432
  <p><b>Docs:</b> The top ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a <a href="#468x15">468x15</a> or <a href="#336x280">336x280</a> advert.</p>
433
 
451
  <?php adinj_add_alignment_options('bottom_'); ?>
452
  </td></tr>
453
  </table>
454
+ <span style="font-size:10px;">The top ad is in addition to the quantity of other ads selected.</span>
 
455
 
456
  <p><b>Docs:</b> The bottom ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a <a href="#336x280">336x280</a> advert.</p>
457
 
685
 
686
  echo 'ADINJ_PATH='.ADINJ_PATH.'<br />';
687
  echo 'ADINJ_CONFIG_FILE='.ADINJ_CONFIG_FILE.'<br />';
688
+ echo 'ADINJ_AD_PATH='.ADINJ_AD_PATH.' (up to v0.9.1)<br />';
689
+ echo 'ADINJ_AD_PATH2='.ADINJ_AD_PATH2.' (v0.9.2+)<br />';
690
 
691
  echo 'Plugin version='.adinj_get_version();
692
  echo '</blockquote>';
762
  }
763
 
764
  // Restore data after automatic upgrade
765
+ // TODO could remove this code further down the line when everyone
766
+ // has moved to the new ad store location
767
  $random_file = ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE;
768
  if (!file_exists($random_file) && !empty($pending_options['ad_code_random_1'])){
769
  write_ad_to_file($pending_options['ad_code_random_1'], $random_file);
870
 
871
  function write_ad_to_file($ad, $ad_path){
872
  if (strlen($ad) > 0){
 
873
  adinj_write_file($ad_path, $ad, 0640);
874
  }
875
  }
ad-injection-widget.php CHANGED
@@ -60,7 +60,9 @@ class Ad_Injection_Widget extends WP_Widget {
60
  $instance['title'] = strip_tags( $new_instance['title'] );
61
  $instance['advert'] = $new_instance['advert'];
62
 
 
63
  write_ad_to_file($instance['advert'], $this->get_ad_file_path());
 
64
 
65
  return $instance;
66
  }
@@ -68,20 +70,20 @@ class Ad_Injection_Widget extends WP_Widget {
68
  function form( $instance ) {
69
 
70
  /* Set up some default widget settings. */
71
- $defaults = array( 'title' => '', 'advert' => '' );
72
  $instance = wp_parse_args( (array) $instance, $defaults );
73
  ?>
74
 
75
  <p>
76
- <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
77
- <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%;" />
78
  <br />
79
  <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>
80
  </p>
81
 
82
  <p>
83
- <label for="<?php echo $this->get_field_id( 'advert' ); ?>">Ad code:</label>
84
- <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>
85
  </p>
86
 
87
  <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>
@@ -103,6 +105,10 @@ class Ad_Injection_Widget extends WP_Widget {
103
  return ADINJ_AD_PATH.'/'.$this->get_ad_file_name();
104
  }
105
 
 
 
 
 
106
  function get_ad_file_name(){
107
  return 'ad_widget_'.$this->get_id().'.txt';
108
  }
60
  $instance['title'] = strip_tags( $new_instance['title'] );
61
  $instance['advert'] = $new_instance['advert'];
62
 
63
+ // TODO later on stop saving to the old ad path
64
  write_ad_to_file($instance['advert'], $this->get_ad_file_path());
65
+ write_ad_to_file($instance['advert'], $this->get_ad_file_path2());
66
 
67
  return $instance;
68
  }
70
  function form( $instance ) {
71
 
72
  /* Set up some default widget settings. */
73
+ $defaults = array('title' => '', 'advert' => '');
74
  $instance = wp_parse_args( (array) $instance, $defaults );
75
  ?>
76
 
77
  <p>
78
+ <label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
79
+ <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%;" />
80
  <br />
81
  <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>
82
  </p>
83
 
84
  <p>
85
+ <label for="<?php echo $this->get_field_id('advert'); ?>">Ad code:</label>
86
+ <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>
87
  </p>
88
 
89
  <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>
105
  return ADINJ_AD_PATH.'/'.$this->get_ad_file_name();
106
  }
107
 
108
+ function get_ad_file_path2(){
109
+ return ADINJ_AD_PATH2.'/'.$this->get_ad_file_name();
110
+ }
111
+
112
  function get_ad_file_name(){
113
  return 'ad_widget_'.$this->get_id().'.txt';
114
  }
ad-injection.php CHANGED
@@ -2,29 +2,14 @@
2
  /*
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.1
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
10
  */
11
 
12
- /* Copyright 2010 reviewmylife (contact : http://www.reviewmylife.co.uk/)
13
-
14
- This program is free software; you can redistribute it and/or modify
15
- it under the terms of the GNU General Public License, version 2, as
16
- published by the Free Software Foundation.
17
-
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
-
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
- */
27
-
28
 
29
  //error_reporting(E_ALL ^ E_STRICT);
30
 
@@ -32,7 +17,8 @@ License: GPLv2
32
  define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
33
  define('ADINJ_CONFIG_FILE', ADINJ_PATH . '/ad-injection-config.php');
34
  define('ADINJ_CONFIG_FILE2', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
35
- define('ADINJ_AD_PATH', ADINJ_PATH . '/ads');
 
36
  define('ADINJ_AD_RANDOM_FILE', 'ad_random_1.txt');
37
  define('ADINJ_AD_TOP_FILE', 'ad_top_1.txt');
38
  define('ADINJ_AD_BOTTOM_FILE', 'ad_bottom_1.txt');
@@ -320,6 +306,7 @@ function adinj($content, $message){
320
  if (!adinj_ticked('debug_mode')) return $content;
321
  global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
322
  $path = ADINJ_AD_PATH;
 
323
  $options = adinj_options();
324
  $mode = $options['ad_insertion_mode'];
325
  return $content."
@@ -331,6 +318,7 @@ content length=".strlen($content)."
331
  \$adinj_total_all_ads_used=$adinj_total_all_ads_used
332
  injection mode=$mode
333
  ADINJ_AD_PATH=$path
 
334
  //-->\n";
335
  }
336
 
@@ -522,7 +510,7 @@ function adinj_inject_hook($content){
522
  return adinj($content_adfree_header.$content.$content_adfree_footer, "Ads injected: " . $debug);
523
  }
524
 
525
- function adinj_split_by_tag($content, $tag, &$debugtags=false){
526
  $ret = array();
527
  if (strpos($content, $tag) !== false){
528
  if ($debugtags !== false) $debugtags .= "$tag, ";
@@ -595,10 +583,10 @@ function adinj_widgets_init() {
595
  }
596
 
597
  // activate
598
- register_activation_hook( __FILE__, 'adinj_activate_hook' );
599
  // Content injection
600
  add_action('wp_enqueue_scripts', 'adinj_addsevjs_hook');
601
- add_action('wp_footer', 'adinj_print_referrers_hook');
602
  add_filter('the_content', 'adinj_inject_hook');
 
603
 
604
  ?>
2
  /*
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.2
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/
9
  License: GPLv2
10
  */
11
 
12
+ /* License header moved to ad-injection-admin.php */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  //error_reporting(E_ALL ^ E_STRICT);
15
 
17
  define('ADINJ_PATH', WP_PLUGIN_DIR.'/ad-injection');
18
  define('ADINJ_CONFIG_FILE', ADINJ_PATH . '/ad-injection-config.php');
19
  define('ADINJ_CONFIG_FILE2', WP_CONTENT_DIR . '/ad-injection-config.php'); // same directory as WP Super Cache config file
20
+ define('ADINJ_AD_PATH', ADINJ_PATH . '/ads'); // old ad store
21
+ define('ADINJ_AD_PATH2', WP_PLUGIN_DIR.'/ad-injection-data'); // ad store from 0.9.2
22
  define('ADINJ_AD_RANDOM_FILE', 'ad_random_1.txt');
23
  define('ADINJ_AD_TOP_FILE', 'ad_top_1.txt');
24
  define('ADINJ_AD_BOTTOM_FILE', 'ad_bottom_1.txt');
306
  if (!adinj_ticked('debug_mode')) return $content;
307
  global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
308
  $path = ADINJ_AD_PATH;
309
+ $path2 = ADINJ_AD_PATH2;
310
  $options = adinj_options();
311
  $mode = $options['ad_insertion_mode'];
312
  return $content."
318
  \$adinj_total_all_ads_used=$adinj_total_all_ads_used
319
  injection mode=$mode
320
  ADINJ_AD_PATH=$path
321
+ ADINJ_AD_PATH2=$path2
322
  //-->\n";
323
  }
324
 
510
  return adinj($content_adfree_header.$content.$content_adfree_footer, "Ads injected: " . $debug);
511
  }
512
 
513
+ function adinj_split_by_tag($content, $tag, &$debugtags){
514
  $ret = array();
515
  if (strpos($content, $tag) !== false){
516
  if ($debugtags !== false) $debugtags .= "$tag, ";
583
  }
584
 
585
  // activate
586
+ register_activation_hook(__FILE__, 'adinj_activate_hook');
587
  // Content injection
588
  add_action('wp_enqueue_scripts', 'adinj_addsevjs_hook');
 
589
  add_filter('the_content', 'adinj_inject_hook');
590
+ add_action('wp_footer', 'adinj_print_referrers_hook');
591
 
592
  ?>
adshow.php CHANGED
@@ -44,8 +44,24 @@ function adshow_display_ad_file($adfile){
44
  if (adinj_config_debug_mode()){
45
  echo "<!--ADINJ DEBUG: adshow_display_ad_file($adfile)-->";
46
  }
47
- $ad_path = dirname(__FILE__).'/ads/'.$adfile;
48
- adshow_display_ad_full_path($ad_path);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
  }
51
 
@@ -62,7 +78,7 @@ function adshow_display_ad_full_path($ad_path){
62
  }
63
  if (file_exists($ad_path)){
64
  $ad = file_get_contents($ad_path);
65
- if ($ad === false) die("could not read from file: $ad_path");
66
  if (stripos($ad_path, 'random_1.txt') > 0){ // TODO something better than this
67
  echo adinj_config_add_tags_rnd(adshow_eval_php($ad));
68
  } else if (stripos($ad_path, 'top_1.txt') > 0){
@@ -73,7 +89,7 @@ function adshow_display_ad_full_path($ad_path){
73
  echo adshow_eval_php($ad);
74
  }
75
  } else {
76
- echo "<!--ADINJ DEBUG: file does not exist: $ad_path-->";
77
  }
78
  }
79
  }
44
  if (adinj_config_debug_mode()){
45
  echo "<!--ADINJ DEBUG: adshow_display_ad_file($adfile)-->";
46
  }
47
+ $plugin_dir = dirname(__FILE__);
48
+ $ad_path1 = $plugin_dir.'/ads/'.$adfile;
49
+ if (file_exists($ad_path1)){
50
+ adshow_display_ad_full_path($ad_path1);
51
+ return;
52
+ }
53
+
54
+ $ad_path2 = dirname($plugin_dir).'/ad-injection-data/'.$adfile;
55
+ if (file_exists($ad_path2)){
56
+ adshow_display_ad_full_path($ad_path2);
57
+ return;
58
+ }
59
+ echo "
60
+ <!--ADINJ DEBUG: could not read ad from either:
61
+ $ad_path1
62
+ $ad_path2
63
+ If you have just upgraded you may need to re-save your ads to regenerate the ad files.
64
+ -->";
65
  }
66
  }
67
 
78
  }
79
  if (file_exists($ad_path)){
80
  $ad = file_get_contents($ad_path);
81
+ if ($ad === false) echo "\n<!--ADINJ DEBUG: could not read ad from file: $ad_path-->";
82
  if (stripos($ad_path, 'random_1.txt') > 0){ // TODO something better than this
83
  echo adinj_config_add_tags_rnd(adshow_eval_php($ad));
84
  } else if (stripos($ad_path, 'top_1.txt') > 0){
89
  echo adshow_eval_php($ad);
90
  }
91
  } else {
92
+ echo "\n<!--ADINJ DEBUG: ad file does not exist: $ad_path.\nIf you have just upgraded you may need to re-save your ads to regenerate the ad files.\n-->";
93
  }
94
  }
95
  }
readme.txt CHANGED
@@ -4,9 +4,9 @@ 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, 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.1
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
 
11
  == Description ==
12
 
@@ -81,6 +81,7 @@ One a basic level it can do the same job as Dax's excellent Adsense Injection. I
81
  * Restrict ad display by referrer (e.g. can restrict display to search engine visitors).
82
  * Can prevent specific IP addresses from seeing adverts.
83
  * Can define randomly positioned adverts, and adverts at the top and bottom of the posts.
 
84
  * Vary number of adverts based on post length.
85
  * You can inject raw JavaScript and PHP.
86
  * The dynamic features (restricting ads by referrer and IP) work with WP Super Cache.
@@ -126,7 +127,7 @@ If you use WP Minify and WP Super Cache in combination with this plugin, you'll
126
  * Uninstall support is provided to delete this option if you uninstall the plugin.
127
  * Admin code is separated into a separate file so it is not loaded when your visitors view your pages.
128
  * When used with WP Super Cache the plugin loads its dynamic settings from a static PHP file so no MySQL database queries are required.
129
- * The ads are saved as text files into the plugin folder. The plugin will therefore need write access to its own folder.
130
  * The JavaScript for setting the referrer cookie is inserted using wp_enqueue_scripts.
131
  * If there is anything I can do better please let me know - this is my first plugin so I still have a lot to learn!
132
 
@@ -170,6 +171,10 @@ For more information visit [reviewmylife](http://www.reviewmylife.co.uk/blog/201
170
 
171
  == Changelog ==
172
 
 
 
 
 
173
  = 0.9.1 =
174
  Fix dynamic checking for widgets.
175
  Fix potential PHP error message with widgets.
@@ -208,6 +213,9 @@ Fix 'Something badly wrong in num_rand_ads_to_insert' message that occurs on pag
208
 
209
  == Upgrade Notice ==
210
 
 
 
 
211
  = 0.9.1 =
212
  Fix dynamic checking for widgets. Fix potential PHP error message with widgets.
213
 
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.2
8
 
9
+ 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.
10
 
11
  == Description ==
12
 
81
  * Restrict ad display by referrer (e.g. can restrict display to search engine visitors).
82
  * Can prevent specific IP addresses from seeing adverts.
83
  * Can define randomly positioned adverts, and adverts at the top and bottom of the posts.
84
+ * Add adverts to the widget area.
85
  * Vary number of adverts based on post length.
86
  * You can inject raw JavaScript and PHP.
87
  * The dynamic features (restricting ads by referrer and IP) work with WP Super Cache.
127
  * Uninstall support is provided to delete this option if you uninstall the plugin.
128
  * Admin code is separated into a separate file so it is not loaded when your visitors view your pages.
129
  * When used with WP Super Cache the plugin loads its dynamic settings from a static PHP file so no MySQL database queries are required.
130
+ * When mfunc mode is used the ads are saved as text files into the plugin folder. The plugin will therefore need write access to the plugins folder.
131
  * The JavaScript for setting the referrer cookie is inserted using wp_enqueue_scripts.
132
  * If there is anything I can do better please let me know - this is my first plugin so I still have a lot to learn!
133
 
171
 
172
  == Changelog ==
173
 
174
+ = 0.9.2 =
175
+ If you are using mfunc mode and have added ad widgets please re-save them to regenerate the ad files.
176
+ Save ad files to a new directory so they don't need to be re-created after upgrade.
177
+
178
  = 0.9.1 =
179
  Fix dynamic checking for widgets.
180
  Fix potential PHP error message with widgets.
213
 
214
  == Upgrade Notice ==
215
 
216
+ = 0.9.2 =
217
+ If you are using mfunc mode and have added ad widgets please re-save them to regenerate the ad files.
218
+
219
  = 0.9.1 =
220
  Fix dynamic checking for widgets. Fix potential PHP error message with widgets.
221
 
uninstall.php CHANGED
@@ -7,11 +7,31 @@ http://www.reviewmylife.co.uk/
7
  if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
8
  exit();
9
 
 
10
  delete_option('adinj_options');
11
 
 
12
  $adinj_dir = dirname(__FILE__);
13
  if (file_exists($adinj_dir.'/../../ad-injection-config.php')) {
14
  unlink($adinj_dir.'/../../ad-injection-config.php');
15
  }
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ?>
7
  if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
8
  exit();
9
 
10
+ // Database cleanup
11
  delete_option('adinj_options');
12
 
13
+ // Delete the configuration file
14
  $adinj_dir = dirname(__FILE__);
15
  if (file_exists($adinj_dir.'/../../ad-injection-config.php')) {
16
  unlink($adinj_dir.'/../../ad-injection-config.php');
17
  }
18
 
19
+ // Delete the ads which are stored outside the plugin directory
20
+ $adinj_dir2 = dirname($adinj_dir).'/ad-injection-data/';
21
+ adinj_delete_directory($adinj_dir2);
22
+
23
+ // From http://stackoverflow.com/questions/1447791/delete-directory-in-php
24
+ function adinj_delete_directory($dir) {
25
+ if (!file_exists($dir)) return true;
26
+ if (!is_dir($dir) || is_link($dir)) return unlink($dir);
27
+ foreach (scandir($dir) as $item) {
28
+ if ($item == '.' || $item == '..') continue;
29
+ if (!adinj_delete_directory($dir . "/" . $item)) {
30
+ chmod($dir . "/" . $item, 0777);
31
+ if (!adinj_delete_directory($dir . "/" . $item)) return false;
32
+ };
33
+ }
34
+ return rmdir($dir);
35
+ }
36
+
37
  ?>