Ad Injection - Version 0.8.4

Version Description

  • Fix deletion of ad code and config file that happens during automatic update.
Download this release

Release Info

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

Code changes from version 0.8.3 to 0.8.4

Files changed (4) hide show
  1. ad-injection-admin.php +35 -9
  2. ad-injection.php +5 -3
  3. readme.txt +16 -6
  4. uninstall.php +1 -1
ad-injection-admin.php CHANGED
@@ -42,12 +42,15 @@ case 'Save all settings':
42
 
43
  $raw_ad_code_random = stripslashes($_POST['ad_code_random_1']);
44
  write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE);
 
45
 
46
  $raw_ad_code_top = stripslashes($_POST['ad_code_top_1']);
47
  write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE);
 
48
 
49
  $raw_ad_code_bottom = stripslashes($_POST['ad_code_bottom_1']);
50
  write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE);
 
51
 
52
  $ad_referrers = stripslashes($_POST['ad_referrers']); // TODO do i need strip slashes?
53
  $options['ad_referrers'] = $ad_referrers;
@@ -124,6 +127,9 @@ function adinj_options_page(){
124
  adinj_activate_hook();
125
  $options = adinj_options(1);
126
  }
 
 
 
127
 
128
  echo '<div class="wrap">';
129
 
@@ -547,6 +553,7 @@ function adinj_debug_information(){
547
  }
548
  echo "$key";
549
  echo "</td><td>";
 
550
  echo "$value";
551
  echo "</td><td>";
552
  echo $default_options[$key];
@@ -613,22 +620,39 @@ function adinj_compatibility_checks() {
613
 
614
  function adinj_activate_hook() {
615
  $stored_options = adinj_options();
616
- $default_options = adinj_default_options();
617
- if($stored_options === false){
618
  // Save defaults to DB below.
619
  if (!is_plugin_active('wp-super-cache/wp-cache.php')){
620
- $stored_options['ad_insertion_mode'] = 'direct_dynamic';
621
  }
622
  } else {
623
  // Upgrade options if necessary. Use default as a baseline,
624
  // and then overwrite default with the saved ones.
625
- foreach ($default_options as $key => $value){
626
  if (array_key_exists($key, $stored_options)){
627
- $default_options[$key] = $stored_options[$key];
628
  }
629
  }
630
  }
631
- update_option('adinj_options', $default_options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
632
  }
633
 
634
  // If the options in the database are out of sync with our default options
@@ -677,6 +701,9 @@ function adinj_default_options(){
677
  'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search., /search/',
678
  'blocked_ips' => '',
679
  'ad_insertion_mode' => 'mfunc',
 
 
 
680
  'ui_random_hide' => 'false',
681
  'ui_topad_hide' => 'false',
682
  'ui_bottomad_hide' => 'false',
@@ -816,7 +843,7 @@ function adinj_docs(){
816
  <h4><a name="336x280"></a>336x280 large rectangle</h4>
817
 
818
  <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ccccff; width:336px; height:280px;&quot;&gt;
819
- &lt;h5&gt;TEST ADVERT 336x280 - &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;www.reviewmylife.co.uk&lt;/a&gt;&lt;&lt;/h5&gt;
820
  &lt;/div&gt;</textarea></p>
821
 
822
  <div style="background-color:#ccccff; width:336px; height:280px;">
@@ -849,9 +876,8 @@ function adinj_init_hook() {
849
  }
850
  }
851
 
 
852
  add_action('init', 'adinj_init_hook');
853
- // Install / activate
854
- register_activation_hook( __FILE__, 'adinj_activate_hook' );
855
  // Config links
856
  add_action('admin_menu', 'adinj_admin_menu_hook');
857
  add_filter('plugin_action_links', 'adinj_options_link_hook', 10, 2); // digits = priority, num args
42
 
43
  $raw_ad_code_random = stripslashes($_POST['ad_code_random_1']);
44
  write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE);
45
+ $options['ad_code_random_1'] = $raw_ad_code_random;
46
 
47
  $raw_ad_code_top = stripslashes($_POST['ad_code_top_1']);
48
  write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE);
49
+ $options['ad_code_top_1'] = $raw_ad_code_top;
50
 
51
  $raw_ad_code_bottom = stripslashes($_POST['ad_code_bottom_1']);
52
  write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE);
53
+ $options['ad_code_bottom_1'] = $raw_ad_code_bottom;
54
 
55
  $ad_referrers = stripslashes($_POST['ad_referrers']); // TODO do i need strip slashes?
56
  $options['ad_referrers'] = $ad_referrers;
127
  adinj_activate_hook();
128
  $options = adinj_options(1);
129
  }
130
+ if (!file_exists(ADINJ_CONFIG_FILE)){
131
+ adinj_write_config_file();
132
+ }
133
 
134
  echo '<div class="wrap">';
135
 
553
  }
554
  echo "$key";
555
  echo "</td><td>";
556
+ $value = htmlentities($value);
557
  echo "$value";
558
  echo "</td><td>";
559
  echo $default_options[$key];
620
 
621
  function adinj_activate_hook() {
622
  $stored_options = adinj_options();
623
+ $pending_options = adinj_default_options();
624
+ if(empty($stored_options)){
625
  // Save defaults to DB below.
626
  if (!is_plugin_active('wp-super-cache/wp-cache.php')){
627
+ $pending_options['ad_insertion_mode'] = 'direct_dynamic';
628
  }
629
  } else {
630
  // Upgrade options if necessary. Use default as a baseline,
631
  // and then overwrite default with the saved ones.
632
+ foreach ($pending_options as $key => $value){
633
  if (array_key_exists($key, $stored_options)){
634
+ $pending_options[$key] = $stored_options[$key];
635
  }
636
  }
637
  }
638
+ update_option('adinj_options', $pending_options);
639
+
640
+ // Restore data after automatic upgrade
641
+ $random_file = ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE;
642
+ if (!file_exists($random_file) && !empty($pending_options['ad_code_random_1'])){
643
+ write_ad_to_file($pending_options['ad_code_random_1'], $random_file);
644
+ }
645
+ $top_file = ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE;
646
+ if (!file_exists($top_file) && !empty($pending_options['ad_code_top_1'])){
647
+ write_ad_to_file($pending_options['ad_code_top_1'], $top_file);
648
+ }
649
+ $bottom_file = ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE;
650
+ if (!file_exists($bottom_file) && !empty($pending_options['ad_code_bottom_1'])){
651
+ write_ad_to_file($pending_options['ad_code_bottom_1'], $bottom_file);
652
+ }
653
+ if (!file_exists(ADINJ_CONFIG_FILE)){
654
+ adinj_write_config_file();
655
+ }
656
  }
657
 
658
  // If the options in the database are out of sync with our default options
701
  'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search., /search/',
702
  'blocked_ips' => '',
703
  'ad_insertion_mode' => 'mfunc',
704
+ 'ad_code_random_1' => '',
705
+ 'ad_code_top_1' => '',
706
+ 'ad_code_bottom_1' => '',
707
  'ui_random_hide' => 'false',
708
  'ui_topad_hide' => 'false',
709
  'ui_bottomad_hide' => 'false',
843
  <h4><a name="336x280"></a>336x280 large rectangle</h4>
844
 
845
  <p><textarea onclick="javascript:this.focus();this.select();" style="min-height:50px;" cols="80" rows="4">&lt;div style=&quot;background-color:#ccccff; width:336px; height:280px;&quot;&gt;
846
+ &lt;h5&gt;TEST ADVERT 336x280 - &lt;a href=&quot;http://www.reviewmylife.co.uk/&quot;&gt;www.reviewmylife.co.uk&lt;/a&gt;&lt;/h5&gt;
847
  &lt;/div&gt;</textarea></p>
848
 
849
  <div style="background-color:#ccccff; width:336px; height:280px;">
876
  }
877
  }
878
 
879
+ // init
880
  add_action('init', 'adinj_init_hook');
 
 
881
  // Config links
882
  add_action('admin_menu', 'adinj_admin_menu_hook');
883
  add_filter('plugin_action_links', 'adinj_options_link_hook', 10, 2); // digits = priority, num args
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.3
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/blog/
9
  License: GPLv2
@@ -43,7 +43,7 @@ define('ADINJ_ALWAYS_SHOW', 'Always show');
43
  // Global variables
44
  $adinj_total_rand_ads_used = 0;
45
  $adinj_total_all_ads_used = 0;
46
- $adinj_data = false;
47
 
48
  if (is_admin()){
49
  require_once(ADINJ_PATH . '/ad-injection-admin.php');
@@ -65,7 +65,7 @@ function adinj_options_link_hook($links, $file) {
65
 
66
  function adinj_options($reset=false){
67
  global $adinj_data;
68
- if ($adinj_data === false || $reset !== false){
69
  $adinj_data = get_option('adinj_options');
70
  }
71
  return $adinj_data;
@@ -559,6 +559,8 @@ function adinj_ticked($option){
559
  return false;
560
  }
561
 
 
 
562
  // Content injection
563
  add_action('wp_enqueue_scripts', 'adinj_addsevjs_hook');
564
  add_action('wp_footer', 'adinj_print_referrers_hook');
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.4
7
  Author: reviewmylife
8
  Author URI: http://www.reviewmylife.co.uk/blog/
9
  License: GPLv2
43
  // Global variables
44
  $adinj_total_rand_ads_used = 0;
45
  $adinj_total_all_ads_used = 0;
46
+ $adinj_data = array();
47
 
48
  if (is_admin()){
49
  require_once(ADINJ_PATH . '/ad-injection-admin.php');
65
 
66
  function adinj_options($reset=false){
67
  global $adinj_data;
68
+ if (empty($adinj_data) || $reset !== false){
69
  $adinj_data = get_option('adinj_options');
70
  }
71
  return $adinj_data;
559
  return false;
560
  }
561
 
562
+ // activate
563
+ register_activation_hook( __FILE__, 'adinj_activate_hook' );
564
  // Content injection
565
  add_action('wp_enqueue_scripts', 'adinj_addsevjs_hook');
566
  add_action('wp_footer', 'adinj_print_referrers_hook');
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, 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.2
7
- Stable tag: 0.8.3
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
 
@@ -12,8 +12,6 @@ Injects any kind of advert into existing WordPress posts. Can restrict who sees
12
 
13
  It injects any kind of advert (e.g. Google AdSense, Amazon Associates, ClickBank, TradeDoubler, etc) into the existing content of your WordPress posts and pages. You can control the number of adverts based on the post length, and it can restrict who sees adverts by post age, visitor referrer and IP address. And the dynamic restrictions (by IP and referrer) work with WP Super Cache!
14
 
15
- Note: This version (0.8.3) has a bug whereby when you upgrade to the next version your ad code will be lost. Please back up your ad code before you upgrade. I am working on a fix, but unfortunately the data loss will occur if you have already installed 0.8.3. I hope to have submitted a fix later today (7th December 2010).
16
-
17
  = Automatic advert injection =
18
 
19
  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'.
@@ -60,9 +58,10 @@ This section describes how to install the plugin and get it working.
60
 
61
  1. Upload the ad-injection folder to the '/wp-content/plugins/' directory. The plugin must be in a folder called 'ad-injection'. So the main plugin file will be at /wp-content/plugins/ad-injection/ad-injection.php
62
  2. Activate the plugin through the 'Plugins' menu in WordPress.
63
- 3. Configure your ads. Make sure you select the option to say which ad injection mode to use. You need to say whether you are using WP Super Cache (or compatible) or not. Dynamic features (referrer and IP ad filtering) will only work with either 1) WP Super Cache (or compatible) or 2) no caching plugin.
64
- 4. Tick the box right at the top to enable your ads.
65
- 5. If you are using a caching plugin you may need to clear the cache to see your ads immediately.
 
66
 
67
  == Frequently Asked Questions ==
68
 
@@ -135,6 +134,11 @@ If you are using WP Super Cache.
135
  2. Are your WP Super Cache settings correct? It must be in 'Legacy' mode.
136
  3. If you are using WP Minify as well then turn off the HTML minification as this strips out the mfunc tags that Ad Injection uses to check if the adverts should be inserted.
137
 
 
 
 
 
 
138
  If you are getting errors when using the plugin check the following.
139
 
140
  1. Is there an 'ads' directory in the plugin directory? The path will probably be: '/wp-content/plugins/ad-injection/ads/'. If not create the ads directory and make sure it is writeable by the plugin (chmod 0755 will do, chmod 0750 is better).
@@ -153,11 +157,17 @@ For more information visit [reviewmylife](http://www.reviewmylife.co.uk/blog/201
153
 
154
  == Changelog ==
155
 
 
 
 
156
  = 0.8.3 =
157
  * First public release
158
 
159
  == Upgrade Notice ==
160
 
 
 
 
161
  = 0.8.3 =
162
  First public release.
163
 
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.2
7
+ Stable tag: 0.8.4
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
 
12
 
13
  It injects any kind of advert (e.g. Google AdSense, Amazon Associates, ClickBank, TradeDoubler, etc) into the existing content of your WordPress posts and pages. You can control the number of adverts based on the post length, and it can restrict who sees adverts by post age, visitor referrer and IP address. And the dynamic restrictions (by IP and referrer) work with WP Super Cache!
14
 
 
 
15
  = Automatic advert injection =
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'.
58
 
59
  1. Upload the ad-injection folder to the '/wp-content/plugins/' directory. The plugin must be in a folder called 'ad-injection'. So the main plugin file will be at /wp-content/plugins/ad-injection/ad-injection.php
60
  2. Activate the plugin through the 'Plugins' menu in WordPress.
61
+ 3. Configure your ads. Carefully go through all the sections to setup your ad placements.
62
+ 4. Make sure you select the option to say which ad injection mode to use. You need to say whether you are using WP Super Cache (or compatible) or not. Dynamic features (referrer and IP ad filtering) will only work with either 1) WP Super Cache (or compatible) or 2) no caching plugin.
63
+ 5. Tick the box right at the top to enable your ads.
64
+ 6. If you are using a caching plugin you may need to clear the cache to see your ads immediately.
65
 
66
  == Frequently Asked Questions ==
67
 
134
  2. Are your WP Super Cache settings correct? It must be in 'Legacy' mode.
135
  3. If you are using WP Minify as well then turn off the HTML minification as this strips out the mfunc tags that Ad Injection uses to check if the adverts should be inserted.
136
 
137
+ If you are using WP Minify
138
+
139
+ 1. Turn off the HTML minification mode if you are also using WP Super Cache. HTML minification strips out the mfunc tags that Ad Injection needs to inject its ads.
140
+ 2. If you use the 'Place Minified JavaScript in footer' then try turning it off.
141
+
142
  If you are getting errors when using the plugin check the following.
143
 
144
  1. Is there an 'ads' directory in the plugin directory? The path will probably be: '/wp-content/plugins/ad-injection/ads/'. If not create the ads directory and make sure it is writeable by the plugin (chmod 0755 will do, chmod 0750 is better).
157
 
158
  == Changelog ==
159
 
160
+ = 0.8.4 =
161
+ * Fix deletion of ad code and config file that happens during automatic update.
162
+
163
  = 0.8.3 =
164
  * First public release
165
 
166
  == Upgrade Notice ==
167
 
168
+ = 0.8.4 =
169
+ If you have already configured your ad code then this update will delete the ads. Sorry - this update fixes that bug. Before upgrading please save your ads. All other settings will be carried over.
170
+
171
  = 0.8.3 =
172
  First public release.
173
 
uninstall.php CHANGED
@@ -6,7 +6,7 @@ http://www.reviewmylife.co.uk/blog/
6
 
7
  if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
8
  exit();
9
-
10
  delete_option('adinj_options');
11
 
12
  ?>
6
 
7
  if( !defined( 'ABSPATH') && !defined('WP_UNINSTALL_PLUGIN') )
8
  exit();
9
+
10
  delete_option('adinj_options');
11
 
12
  ?>