$value){ if (isset($_POST[$key])){ $options[$key] = $_POST[$key]; } else { $options[$key] = ""; } } if (!file_exists(ADINJ_AD_PATH)){ global $adinj_warning_msg_filewrite; mkdir(ADINJ_AD_PATH, 0750) //TODO is this the right permission or $adinj_warning_msg_filewrite .= "
Error: could not create dir: ".ADINJ_AD_PATH.". Please create it manually and try again."; } // TODO we could stop writing to the ad files if direct insertion mode is used $raw_ad_code_random = stripslashes($_POST['ad_code_random_1']); write_ad_to_file($raw_ad_code_random, ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE); $options['ad_code_random_1'] = $raw_ad_code_random; $raw_ad_code_top = stripslashes($_POST['ad_code_top_1']); write_ad_to_file($raw_ad_code_top, ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE); $options['ad_code_top_1'] = $raw_ad_code_top; $raw_ad_code_bottom = stripslashes($_POST['ad_code_bottom_1']); write_ad_to_file($raw_ad_code_bottom, ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE); $options['ad_code_bottom_1'] = $raw_ad_code_bottom; $ad_referrers = stripslashes($_POST['ad_referrers']); // TODO do i need strip slashes? $options['ad_referrers'] = $ad_referrers; $blocked_ips = stripslashes($_POST['blocked_ips']); $options['blocked_ips'] = $blocked_ips; update_option('adinj_options', $options); // TODO could stop this if not mfunc mode adinj_write_config_file(); break; case 'Reset to Default': adinj_checkNonce(); update_option('adinj_options', adinj_default_options()); break; case 'Delete settings from DB': adinj_checkNonce(); delete_option('adinj_options'); // TODO add option to delete ads files as well break; } } // Test reminder: These generated functions won't exist until the first save // so be careful if adding any new ones - they might not exist yet, but could // still be referenced by adshow. function adinj_write_config_file(){ $referrer_list = adinj_quote_list('ad_referrers'); $ip_list = adinj_quote_list('blocked_ips'); $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false'; $debug_mode = adinj_ticked('debug_mode')?'true':'false'; $rnd_func = adinj_add_tags(NULL, 'rnd_', 'adinj_config_add_tags_rnd'); $top_func = adinj_add_tags(NULL, 'top_', 'adinj_config_add_tags_top'); $bottom_func = adinj_add_tags(NULL, 'bottom_', 'adinj_config_add_tags_bottom'); $config = << CONFIG; adinj_write_file(ADINJ_CONFIG_FILE, $config, 0640); } function adinj_write_file($path, $content, $permission){ global $adinj_warning_msg_filewrite; $handle = fopen($path, "w"); fwrite($handle, $content) or $adinj_warning_msg_filewrite .= "
Error: could not write to file: $path"; fclose($handle); adinj_chmod($path, $permission); } function adinj_chmod($path, $permission){ global $adinj_warning_msg_chmod; $oldperm = fileperms($path); if ($permission == $oldperm) return; chmod($path, $permission) or $adinj_warning_msg_chmod .= "
Warning: chmod ".decoct($permission). " on $path failed. Current permissions: ".substr(decoct($oldperm) ,-4).'.
Try manually updating the permission if problems occur.'; } function adinj_get_logo(){ return 'reviewmylife'; } function adinj_options_page(){ $options = adinj_options(); if ($options === false || adinj_options_need_upgrading($options)){ // Upgraded via FTP without being deactivated/reactivated adinj_activate_hook(); $options = adinj_options(1); } if (!file_exists(ADINJ_CONFIG_FILE)){ adinj_write_config_file(); } echo '
'; if (adinj_problem_with_wpminify_check()){ echo '

'; echo adinj_get_problem_with_wpminify_message(); echo '

'; } echo '

Ad Injection ' . adinj_get_version() . adinj_get_logo() . '

'; if (isset($_POST['adinj_action'])) { echo '

'; echo 'All settings saved: '; if (is_plugin_active('wp-super-cache/wp-cache.php')) { echo "You might need to clear your WP Super Cache cache for the settings to take effect."; } else { echo "If you are using a caching plugin you might need to delete its cache for any changes to take effect."; } echo ''; if ($options['ad_insertion_mode']=='mfunc'){ global $adinj_warning_msg_filewrite; if (!empty($adinj_warning_msg_filewrite)){ echo $adinj_warning_msg_filewrite; echo "
Workaround: If you are unable to fix these errors you will have to switch to a direct insertion mode (however dynamic features won't work if you are using a caching plugin)."; } } global $adinj_warning_msg_chmod; if (!empty($adinj_warning_msg_chmod)){ echo '
Info: Some warnings were generated by chmod. See the debugging section for more info.'; } echo '

'; } ?>

More info...

More Ad Injection information

More by this author

Be careful!

Make sure that the ad settings and positioning you define are in compliance with your ad provider's terms of service!

Beta version!

This plugin has only just been released - please bare with me if there are any bugs. I'm actively listening to your feedback and fixing any problems. Please let me know if you like the plugin too!

Random ads | Top ad | Bottom ad | Ad insertion mode/dynamic restrictions | Debugging | Quick Start | Test ads

/> - Tick this to turn your ads on!

Docs: On individual posts or pages this advert is inserted between randomly selected paragraphs. On a multi-post page (e.g. home page), one ad is inserted into each post. Try a 468x60 or 728x90 banner.

Be especially careful if you decide to use the 'float' layout options. Make sure that you don't have adverts floated over the top of other page elements, or vice-versa.

/>
/> (The default behaviour is to inject ads at unique positions)

Don't show ads on these page types:

/>page (publish; ?> page(s))
/>single (publish; ?> individual blog post(s))

'; adinj_selection_box("no_random_ads_if_shorter_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000)); echo adinj_getdefault('no_random_ads_if_shorter_than'); ?>
'; adinj_selection_box("one_ad_if_shorter_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000)); echo adinj_getdefault('one_ad_if_shorter_than'); ?>
'; adinj_selection_box("two_ads_if_shorter_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000)); echo adinj_getdefault('two_ads_if_shorter_than'); ?>
'; adinj_selection_box("three_ads_if_shorter_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000)); echo adinj_getdefault('three_ads_if_shorter_than'); ?>

Docs: The above directives are processed in order from top to bottom.

()


Docs: On multi-post pages such as the home page, one randomly positioned advert will be inserted into each page, up to the maximum number specified here.


Important: Make sure that the total number of ads does not exceed the amount allowed in your ad provider's TOS! The top ad is in addition to the quantity of random ads selected.

Docs: The top ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a 468x15 or 336x280 advert.


Important: Make sure that the total number of ads does not exceed the amount allowed in your ad provider's TOS! The top ad is in addition to the quantity of random ads selected.

Docs: The bottom ad will only appear on single posts and pages. It will not appear on multi-post pages. Try a 336x280 advert.

Ad insertion mode

/> Use mfunc tags for dynamic features - Dynamic features will work with WP Super Cache in legacy mode (or with a caching program that is compatible with WP Super Cache's mfunc tags). Dynamic features will also work if you don't use a caching program, although if you don't use a caching program 'direct' insertion will be more efficient.

/> Direct ad insertion with dynamic features - Dynamic features will work if no caching is used. Only select this if you are not using any caching plugin.

/> Direct static ad insertion - No dynamic feature support. Select this if you are using a caching plugin which is not compatible with WP Super Cache's mfunc tags.

Show ads only to search engine visitors (dynamic feature)

/>

Comma separated list e.g.:
.google., .bing., .yahoo., .ask., search?, search., /search/

Blocked IP addresses (dynamic feature)

Comma separated list e.g.:
0.0.0.1, 0.0.0.2

Or you can list one IP per line with optional comments e.g.

192.168.0.1
0.0.0.2
//my ip
0.0.0.3

For reference your current IP address is

Recommended WP Super Cache settings:

  • Cache hits to this website for quick access.
  • Legacy page caching.
  • Compress pages so they’re served more quickly to visitors.
  • Expire time: 36000 (10 hours). Or 3600 (1 hour) for very busy site.

advanced settings page (where you can set the caching mode to Legacy)."; } else { echo "Note: WP Super Cache does not appear to be active."; } ?>

/>Enable debug mode

If you are not sure why ads aren't appearing, or why they are appearing, enable debug mode and look at the debug information (search for 'ADINJ DEBUG') in the HTML of your content pages.

If you want to restore all settings (excluding the ad contents) to their default values use this button.

You can delete the database settings if you are going to uninstall Ad Injection.


'; echo '
'; } function adinj_postbox_start($title, $anchor, $width='650px'){ $options = adinj_options(); ?>
' />

'; } function adinj_selection_box($name, $values, $type=NULL){ echo ""; } function adinj_add_alignment_options($prefix){ _e("Alignment", 'adinj'); echo "
"; adinj_selection_box($prefix.'align', array(ADINJ_RULE_DISABLED, 'left', 'center', 'right', 'float left', 'float right')); echo "
"; _e("Margin top", 'adinj'); echo "
"; adinj_selection_box($prefix.'margin_top', array(ADINJ_RULE_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)"); echo "
"; _e("Margin bottom", 'adinj'); echo "
"; adinj_selection_box($prefix.'margin_bottom', array(ADINJ_RULE_DISABLED, 0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30), "(px)"); } function adinj_debug_information(){ $stored_options = adinj_options(); $default_options = adinj_default_options(); ?>

Settings dump from database (all in 'adinj_options' option)

$value){ if ($count % 2 == 0){ echo '"; $count++; } } else { echo "
No options in database!"; } echo '
NameStoredDefault
'; } else { echo '
'; } echo "$key"; echo ""; $value = htmlentities($value); echo "$value"; echo ""; echo $default_options[$key]; echo "
'; echo '
'; echo '

Other settings

'; echo 'ADINJ_PATH='.ADINJ_PATH.'
'; echo 'ADINJ_CONFIG_FILE='.ADINJ_CONFIG_FILE.'
'; echo 'ADINJ_AD_PATH='.ADINJ_AD_PATH.'
'; echo 'Plugin version='.adinj_get_version(); echo '
'; global $adinj_warning_msg_filewrite; if (!empty($adinj_warning_msg_filewrite)){ echo "

Errors on 'Save all settings'

$adinj_warning_msg_filewriteWarnings on 'Save all settings'
$adinj_warning_msg_chmodProblem: Ad Injection will not work if WP Minify is set to minify HTML whilst WP Super Cache is enabled.
Solution: Go to the WP Minify settings page and untick "Enable HTML Minification".'; } function adinj_init_warning() { if (stripos($_SERVER["PHP_SELF"], 'plugins.php') !== false){ echo '

Ad Injection needs configuring: Go to the settings page to configure and enable your ads.

'; } // TODO add option to disable message without having to go to settings. } function adinj_compatibility_checks() { if (stripos($_SERVER["PHP_SELF"], 'ad-injection') !== false){ $wpm_options = get_option('wp_minify'); if ($wpm_options['enable_html'] == true){ echo '

'; echo adinj_get_problem_with_wpminify_message(); echo '

'; } } } function adinj_activate_hook() { $stored_options = adinj_options(); $pending_options = adinj_default_options(); if(empty($stored_options)){ // Save defaults to DB below. if (!is_plugin_active('wp-super-cache/wp-cache.php')){ $pending_options['ad_insertion_mode'] = 'direct_dynamic'; } } else { // Upgrade options if necessary. Use default as a baseline, // and then overwrite default with the saved ones. foreach ($pending_options as $key => $value){ if (array_key_exists($key, $stored_options)){ $pending_options[$key] = $stored_options[$key]; } } } // Restore data after automatic upgrade $random_file = ADINJ_AD_PATH.'/'.ADINJ_AD_RANDOM_FILE; if (!file_exists($random_file) && !empty($pending_options['ad_code_random_1'])){ write_ad_to_file($pending_options['ad_code_random_1'], $random_file); } $top_file = ADINJ_AD_PATH.'/'.ADINJ_AD_TOP_FILE; if (!file_exists($top_file) && !empty($pending_options['ad_code_top_1'])){ write_ad_to_file($pending_options['ad_code_top_1'], $top_file); } $bottom_file = ADINJ_AD_PATH.'/'.ADINJ_AD_BOTTOM_FILE; if (!file_exists($bottom_file) && !empty($pending_options['ad_code_bottom_1'])){ write_ad_to_file($pending_options['ad_code_bottom_1'], $bottom_file); } if (!file_exists(ADINJ_CONFIG_FILE)){ adinj_write_config_file(); } // In case ads are saved on file and upgrading from first version on plugin // TODO maybe delete this in a few versions time? if (empty($pending_options['ad_code_random_1']) && file_exists($random_file)){ $pending_options['ad_code_random_1'] = read_ad_from_file($random_file); } if (empty($pending_options['ad_code_top_1']) && file_exists($top_file)){ $pending_options['ad_code_top_1'] = read_ad_from_file($top_file); } if (empty($pending_options['ad_code_bottom_1']) && file_exists($bottom_file)){ $pending_options['ad_code_bottom_1'] = read_ad_from_file($bottom_file); } update_option('adinj_options', $pending_options); } // If the options in the database are out of sync with our default options // then the database options will need upgrading function adinj_options_need_upgrading($stored_options){ $default_options = adinj_default_options(); foreach ($default_options as $key => $value){ if (!array_key_exists($key, $stored_options)){ return true; } } foreach ($stored_options as $key => $value){ if (!array_key_exists($key, $default_options)){ return true; } } return false; } function adinj_default_options(){ return array( 'ads_enabled' => '', 'max_num_of_ads' => '2', // single posts and pages 'max_num_of_ads_home_page' => '3', 'no_random_ads_if_shorter_than' => '100', 'one_ad_if_shorter_than' => '500', 'two_ads_if_shorter_than' => '1000', 'three_ads_if_shorter_than' => ADINJ_RULE_DISABLED, 'top_ad_if_longer_than' => ADINJ_RULE_DISABLED, 'bottom_ad_if_longer_than' => ADINJ_RULE_DISABLED, 'rnd_align' => ADINJ_RULE_DISABLED, 'rnd_margin_top' => '3', 'rnd_margin_bottom' => '3', 'top_align' => ADINJ_RULE_DISABLED, 'top_margin_top' => '3', 'top_margin_bottom' => '3', 'bottom_align' => ADINJ_RULE_DISABLED, 'bottom_margin_top' => '3', 'bottom_margin_bottom' => '3', 'ads_on_page_older_than' => '10', 'exclude_page' => '', 'exclude_single' => '', 'first_paragraph_ad' => '', 'multiple_ads_at_same_position' => '', 'sevisitors_only' => '', 'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search., /search/', 'blocked_ips' => '', 'ad_insertion_mode' => 'mfunc', 'ad_code_random_1' => '', 'ad_code_top_1' => '', 'ad_code_bottom_1' => '', 'ui_random_hide' => 'false', 'ui_topad_hide' => 'false', 'ui_bottomad_hide' => 'false', 'ui_restrictions_hide' => 'false', 'ui_debugging_hide' => 'true', 'ui_docs_hide' => 'false', 'ui_testads_hide' => 'false', 'debug_mode' => '' ); } function adinj_getdefault($option){ $default_options = adinj_default_options(); return "(default: " . $default_options[$option] . ")"; } function write_ad_to_file($ad, $ad_path){ adinj_chmod(ADINJ_AD_PATH, 0750); if (strlen($ad) >0){ adinj_write_file($ad_path, $ad, 0640); } } function adinj_docs(){ ?>

1. Copy and paste your ad code into the ad code boxes.

2. Choose how many ads of each type you want displayed.

3. Configure any ad positioning (optional).

4. Check the ad insertion mode (in the Insertion mode and ad display restriction section).

5. If you are using a compatible ad insertion mode you may configure dynamic ad display restrictions. i.e. showing ads only to certain people (e.g. search engine visitors), or blocking ads from specific IPs.

6. Enable your ads (tick box at the very top).

Supported in-page tags

These tags can be inserted into the page source to override the configured behaviour on individual pages. Because sometimes specific pages need to be treated differently.

  1. <!--adsensestart--> - Random ads will start from this point*. For compatibility with Adsense Injection.
  2. <!--adsenseend--> - Random ads will not be inserted after this point*. New tag but I've kept the Adsense Injection naming convention to make it fit with the above tag.
  3. <!--adstart--> - Random ads will start from this point*.
  4. <!--adend--> - Random ads will not be inserted after this point*.

These four tags will not affect the top and bottom ad.

Custom field for disabling adverts

To disable all adverts on the page you can also set the custom disable_adverts field to '1' from the WordPress post editor.

You can copy and paste these adverts into the boxes above to test your ad setup before switching to your real ads.

468x60 banner

TEST ADVERT 468x60 - www.reviewmylife.co.uk

728x90 banner

TEST ADVERT 728x90
www.reviewmylife.co.uk
www.advancedhtml.co.uk

160x90 link unit

TEST ADVERT 160x90
reviewmylife.co.uk advancedhtml.co.uk

468x15 link unit

TEST ADVERT 160x90 reviewmylife.co.uk

336x280 large rectangle

TEST ADVERT 336x280 - www.reviewmylife.co.uk

468x60 banner with dynamic PHP

The PHP will execute if 1) WP Super Cache is turned on in legacy mode, and 2) if WP Super Cache is not installed/disabled.

TEST ADVERT 468x60 with date() and rand()

www.advancedhtml.co.uk