$value){ if (isset($_POST[$key])){ $options[$key] = $_POST[$key]; } else { $options[$key] = ""; } } if (!file_exists(ADINJ_AD_PATH)){ mkdir(ADINJ_AD_PATH, 0750) //TODO is this the right permission or print("Error: could not create dir: ADINJ_AD_PATH. Please create it manually and try again."); } $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); 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'); 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(){ $handle = fopen(ADINJ_CONFIG_FILE, "w") or die("could not open config file: $ad_path"); $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; fwrite($handle, $config) or die("could not write to config file: $config_file"); fclose($handle); chmod(ADINJ_CONFIG_FILE, 0640) or die("chmod on config file failed: $config_file"); } 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() . '

'; ?>

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!

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 '
'; } function adinj_get_version(){ $plugin_data=get_plugin_data(ADINJ_PATH . '/ad-injection.php'); return $plugin_data['Version']; } function adinj_problem_with_wpminify_check(){ $wpm_options = get_option('wp_minify'); if ($wpm_options['enable_html'] == true && is_plugin_active('wp-super-cache/wp-cache.php')){ return true; } return false; } function adinj_get_problem_with_wpminify_message(){ return 'Problem: 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]; } } } update_option('adinj_options', $pending_options); // 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(); } } // 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] . ")"; } // TODO is the chmod'ing here a bit extreme? function write_ad_to_file($ad, $ad_path){ chmod(ADINJ_AD_PATH, 0750) or die("chmod failed: " . ADINJ_AD_PATH); if (file_exists($ad_path)){ chmod($ad_path, 0640) or die("chmod failed: $ad_path"); } $handle = fopen($ad_path, "w") or die("could not open ad file: $ad_path"); if (strlen($ad) >0){ fwrite($handle, $ad) or die("could not write to ad file: $ad_path"); } fclose($handle); chmod($ad_path, 0640) or die("chmod failed: $ad_path"); } 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