$value){ if (isset($_POST[$key])){ $ops[$key] = $_POST[$key]; } } extract_text_args('ad_code_random_', $ops, 1, 10, ADINJ_AD_PATH.'/ad_random_'); extract_text_args('ad_code_top_', $ops, 1, 10, ADINJ_AD_PATH.'/ad_top_'); extract_text_args('ad_code_bottom_', $ops, 1, 10, ADINJ_AD_PATH.'/ad_bottom_'); extract_text_args('ad_code_footer_', $ops, 1, 10, ADINJ_AD_PATH.'/ad_footer_'); extract_text_args('ad_code_random_alt_', $ops, 1, 2, ADINJ_AD_PATH.'/ad_random_alt_'); extract_text_args('ad_code_top_alt_', $ops, 1, 2, ADINJ_AD_PATH.'/ad_top_alt_'); extract_text_args('ad_code_bottom_alt_', $ops, 1, 2, ADINJ_AD_PATH.'/ad_bottom_alt_'); extract_text_args('ad_code_footer_alt_', $ops, 1, 2, ADINJ_AD_PATH.'/ad_footer_alt_'); extract_text_args('ad_referrers', $ops); extract_text_args('blocked_ips', $ops); adinj_update_options($ops); if (adinj_mfunc_mode()) { adinj_write_config_file(); } break; case 'Reset to Default': adinj_checkNonce(); adinj_update_options(adinj_default_options()); break; case 'Delete settings from DB': adinj_checkNonce(); delete_option('adinj_options'); adinj_install_db(); adinj_options(1); break; case 'Delete widget settings from DB': adinj_checkNonce(); delete_option('widget_adinj'); // TODO add option to delete ads files as well break; } } function extract_text_args($name, &$ops, $start=NULL, $end=NULL, $save_path_stem=NULL){ if ($start === NULL){ if (isset($_POST[$name])){ $ops[$name] = stripslashes($_POST[$name]); if ($save_path_stem != NULL){ write_ad_to_file($ops[$name], $save_path_stem.'1.txt'); } } } else { for ($i = $start; $i<=$end; ++$i){ if (isset($_POST[$name.$i])){ $ops[$name.$i] = stripslashes($_POST[$name.$i]); if ($save_path_stem != NULL){ write_ad_to_file($ops[$name.$i], $save_path_stem.$i.'.txt'); } } } } } // 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(){ if (!adinj_mfunc_mode()) return; $sevisitors_only = adinj_ticked('sevisitors_only')?'true':'false'; $referrer_list = adinj_quote_list('ad_referrers'); $block_ips = adinj_ticked('block_ips')?'true':'false'; $ip_list = adinj_quote_list('blocked_ips'); $block_keywords = adinj_ticked('block_keywords')?'true':'false'; $keyword_list = adinj_quote_list('blocked_keywords'); $debug_mode = adinj_ticked('debug_mode')?'true':'false'; $config = << CONFIG; adinj_write_file(ADINJ_CONFIG_FILE, $config, 0640); } function adinj_write_file($path, $content, $permission){ $ops = adinj_options(); global $adinj_warning_msg_filewrite; $dir = dirname($path); if (!@file_exists($dir)){ if (!@mkdir($dir, 0750)){ @mkdir($dir, 0755) or $adinj_warning_msg_filewrite .= "
Warning: could not create dir: ".$dir.". Please create it manually and try again."; } } $handle = @fopen($path, "w"); if (strlen($content) > 0){ @fwrite($handle, $content) or $adinj_warning_msg_filewrite .= "
Warning: could not write to file: $path"; } @fclose($handle); if (@file_exists($path)){ adinj_chmod($path, $permission); } } function adinj_chmod($path, $permission){ global $adinj_warning_msg_chmod; $oldperm = substr(decoct(@fileperms($path)), -3); $newperm = decoct($permission); if ($newperm == $oldperm) return; @chmod($path, $permission) or $adinj_warning_msg_chmod .= "
Warning: chmod $newperm " . "on $path failed. Current permissions: $oldperm
Try manually updating the permission if problems occur."; } function adinj_get_logo(){ return 'reviewmylife'; } // only for Ad Injection admin pages function adinj_admin_print_scripts_main(){ adinj_admin_print_scripts_widgets(); } // only for widgets.php function adinj_admin_print_scripts_widgets(){ echo ""; adinj_javascript_addtext(); echo << function adinj_toggle_click(show_setting_id, toggle_button_id, toggle_box_id){ jQuery('#'+show_setting_id).val(jQuery('#'+toggle_box_id).is(":hidden")); adinj_button_update(show_setting_id, toggle_button_id); jQuery('#'+toggle_box_id).slideToggle(300); } function adinj_button_update(show_setting_id, toggle_button_id){ if (jQuery('#'+show_setting_id).val() == 'true'){ jQuery('#'+toggle_button_id).text('-'); } else { jQuery('#'+toggle_button_id).text('+'); } } HTML; } function adinj_options_page(){ if (isset($_POST['adinj_action'])){ adinj_save_options(); } adinj_upgrade_db_if_necessary(); $ops = adinj_options(); 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() . '

'; adinj_top_message_box(); adinj_admin_tabs(); echo '
'; switch( $_GET[ 'tab' ] ) { case "adrotation": require_once(ADINJ_PATH . '/ui-tab-adrotation.php'); adinj_side_donate_box(); adinj_side_info_box(); echo '
'; echo '
'; wp_nonce_field('_adinj_form'); adinj_tab_adrotation(); break; case "debug": require_once(ADINJ_PATH . '/ui-tab-debug.php'); adinj_side_donate_box(); adinj_side_info_box(); echo '
'; echo ''; wp_nonce_field('_adinj_form'); adinj_tab_debug(); break; case "main": default: require_once(ADINJ_PATH . '/ui-tab-main.php'); adinj_side_status_box(); adinj_side_donate_box(); adinj_side_info_box(); echo ''; echo ''; wp_nonce_field('_adinj_form'); adinj_tab_main(); break; } echo ''; echo ' '; } function adinj_top_message_box(){ $ops = adinj_options(); 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 if (is_plugin_active('w3-total-cache/w3-total-cache.php')){ echo "You might need to clear your W3 Total Cache cache for the settings to take effect."; } else if (is_plugin_active('wp-cache/wp-cache.php')){ echo "You might need to clear your WP 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 ($ops['debug_mode']=='on' && $ops['ads_enabled'] == 'on'){ echo "
Recommendation: Turn debug mode off once you have got your ads working."; } if (adinj_mfunc_mode()){ if (!is_supported_caching_plugin_active()){ echo "
Recommendation: It looks like you don't have a supported caching plugin (WP Super Cache, W3 Total Cache or WP Cache) active. Therefore direct insertion modes might be better for you."; } 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 warnings below for more info.'; } foreach (array('top', 'random', 'bottom', 'footer') as $type){ $adcount = adinj_count_live_ads($type, $ops); if ($adcount > 0 && !adinj_ad_type_enabled($type)){ $adads = 'ad'; $isare = 'is'; $theyit = 'it is'; if ($adcount > 1) { $adads = 'ads'; $isare = 'are'; $theyit = 'they are'; } echo "
Warning: $adcount $type $adads $isare defined, but $theyit not enabled."; } } if ($ops['ads_enabled'] != 'on'){ echo '
Warning: Ads are not enabled. You need to turn the ads on for everyone to see them.'; } echo '

'; } else if (!isset($_GET['tab'])){ echo '

'; echo "14th September 2011: This is a big update with many new positioning options for top/random/bottom ads and completely re-written ad insertion code. More details of some of the new features are on Advanced HTML. I've tested this as much as I can, but some bugs may have slipped through. I'm waiting to fix them as soon as I hear about them! Please contact me ASAP if you spot any bugs, or odd behaviour via the ".'quick feedback form.'; echo '

'; } } function adinj_side_donate_box(){ ?>

Donate $10, $20 or $50!

I have spent many hundreds of hours creating this plugin. If it helps you to make money please consider making a donation. Thank you!

Amount:

Info

More Ad Injection information

Important!

You are responsible for making sure the ad settings and positioning you define are in compliance with your ad provider's terms of service! Failure to do so could get you banned by them!

Still in development

I'm actively listening to your feedback and fixing problems, and will be adding new features later in 2011. Please let me know if you like the plugin too!

More by this author

'; echo '"; if ($all != NULL && adinj_ticked($name)){ ?> __( 'Main', 'ad-injection' ), 'adrotation' => __( 'Ad codes / Ad rotation', 'ad-injection' ), 'debug' => __( 'Debug' ) ); $links = array(); foreach( $tabs as $tab => $name ) { if ( $current == $tab ) { $links[] = "$name"; } else { $links[] = "$name"; } } echo ''; } // TODO replace with new Javascript function adinj_postbox_start($title, $anchor, $width='650px'){ $ops = adinj_options(); ?>
HTML; ?>

'; } function adinj_get_status($name){ $ops = adinj_options(); $status[] = 'black'; $status[] = 'Error...'; if ($name == 'global'){ if ($ops['exclude_front'] == 'on' && $ops['exclude_home'] == 'on' && $ops['exclude_page'] == 'on' && $ops['exclude_single'] == 'on' && $ops['exclude_archive'] == 'on' && $ops['exclude_search'] == 'on' && $ops['exclude_404'] == 'on'){ $status[0] = 'red'; $status[1] = 'excluded from all'; return $status; } $val = $ops['ads_enabled']; if ($val == 'on'){ $status[0] = 'green'; $status[1] = $val; } else if ($val == 'off' || $val == ''){ $status[0] = 'red'; $status[1] = $val; } else if ($val == 'test'){ $status[0] = 'orange'; $status[1] = 'test mode'; } } else if ($name == 'mode'){ $status[0] = 'green'; if ($ops['ad_insertion_mode'] == 'direct_static') $status[0] = 'orange'; $status[1] = $ops['ad_insertion_mode']; } else if ($name == 'restrictions'){ $status[0] = 'green'; $status[1] = ""; if ($ops['sevisitors_only'] == 'on'){ $status[1] .= 'referrer'; } if ($ops['sevisitors_only'] == 'on'){ $status[1] .= ' keywords'; } if ($ops['block_ips'] == 'on' && !empty($ops['blocked_ips'])){ $status[1] .= ' ip'; } } else if ($name == 'older_than_normal'){ $status[0] = 'green'; $days = $ops['ads_on_page_older_than']; $status[1] = "> $days days"; } else if ($name == 'older_than_widgets'){ $status[0] = 'green'; $days = $ops['widgets_on_page_older_than']; $status[1] = "> $days days"; } else if ($name == 'adsettings'){ $status[0] = 'green'; } else if ($name == 'adverts'){ if (adinj_count_live_ads('top', $ops) > 0 || adinj_count_live_ads('random', $ops) > 0 || adinj_count_live_ads('bottom', $ops) > 0 || adinj_count_live_ads('footer', $ops) > 0){ $status[0] = 'green'; } else { $status[0] = 'red'; } } else if ($name == 'filters'){ $status[0] = 'green'; } else if ($name == 'debugging'){ $val = $ops['debug_mode']; if ($val == 'on'){ $status[0] = 'green'; $status[1] = 'on'; } else { $status[0] = 'red'; $status[1] = 'off'; } } return $status; } // This is for 'exclude' options so 'on' is red. function adinj_green_or_red_dot($option){ $ops = adinj_options(); if ($ops[$option] == 'on'){ return adinj_dot('red'); } else { return adinj_dot('green'); } } function adinj_print_ad_dot($adtype, $pagetype){ if (adinj_max_num_ads($adtype, $pagetype) > 0){ echo adinj_dot('green'); } else { echo adinj_dot('red'); } } function adinj_dot($colour){ return ''; } function adinj_max_num_ads($adtype, $pagetype){ $ops = adinj_options(); if (adinj_ticked('exclude_'.$pagetype)) return 0; if ($adtype == 'top' || $adtype == 'random' || $adtype == 'bottom' || $adtype == 'footer' || $adtype == 'widget'){ if (adinj_ticked($adtype.'_exclude_'.$pagetype)) return 0; } if ($adtype == 'top' || $adtype == 'random' || $adtype == 'bottom' || $adtype == 'footer'){ if (adinj_count_live_ads($adtype, $ops) == 0) return 0; } if ($adtype == 'top' || $adtype == 'bottom'){ if ($pagetype == "single" || $pagetype == "page"){ return 1; } else if ($pagetype == 'home' || $pagetype == 'archive'){ return $ops[$pagetype.'_max_num_'.$adtype.'_ads_per_page']; } else if ($pagetype == "excerpt"){ //TODO } } else if ($adtype == "random"){ if ($pagetype == "single" || $pagetype == "page"){ return $ops['max_num_of_ads']; } else if ($pagetype == 'home' || $pagetype == 'archive'){ if ($ops[$pagetype.'_max_num_random_ads_per_post'] > 0) return $ops[$pagetype.'_max_num_random_ads_per_page']; } else if ($pagetype == "excerpt"){ //TODO } } if ($adtype == 'widget' || $adtype == 'footer'){ return 1; } return 0; } function adinj_ad_type_enabled($adtype){ return (adinj_max_num_ads($adtype, 'single') > 0 || adinj_max_num_ads($adtype, 'page') > 0 || adinj_max_num_ads($adtype, 'home') > 0 || adinj_max_num_ads($adtype, 'archive') > 0 || adinj_max_num_ads($adtype, 'front') > 0 || adinj_max_num_ads($adtype, '404') > 0 || adinj_max_num_ads($adtype, 'search') > 0); } function adinj_selection_box($name, $values, $type="", $selected_value=NULL){ $associative = false; if (!array_key_exists(0, $values)){ // Very naive test but works for me. $associative = true; } if ($selected_value == NULL){ $ops = adinj_options(); $selected_value = $ops[$name]; } echo ""; } function adinj_javascript_addtext(){ ?>
HTML; if ($show_value == 'false'){ echo "
"; } else { echo "
"; } } function adinj_condition_tables($prefix, $show_setting){ $ops = adinj_options(); if (strlen($ops[$prefix.'category_condition_entries'])>0 || strlen($ops[$prefix.'tag_condition_entries'])>0 || strlen($ops[$prefix.'author_condition_entries'])>0 || strlen($ops[$prefix.'id_condition_entries'])>0){ $msg = "configured"; } else { $msg = "empty"; } echo "Category tag, author, and post id conditions [".$msg."]"; adinj_add_show_hide_section('ad_conditions_'.uniqid(''), $show_setting, $show_setting, $ops); adinj_condition_table($prefix.'category', 'category slugs. e.g: cat1, cat2, cat3', 'category', $ops); adinj_condition_table($prefix.'tag', 'tag slugs. e.g: tag1, tag2, tag3', 'tag', $ops); adinj_condition_table($prefix.'author', 'author nicknames. e.g: john, paul', 'author', $ops); adinj_condition_table($prefix.'id', 'post or page ids. e.g: 7, 38, 243', 'id', $ops); echo '
'; } function adinj_condition_table($name, $description, $type, $ops, $dropdown_fieldname=NULL, $textarea_fieldname=NULL){ $style = ""; if ($dropdown_fieldname == NULL){ $dropdown_fieldname = $name."_condition_mode"; // Only for the main screen - not for widgets screen. $style = "style='width:280px'"; } if ($textarea_fieldname == NULL){ $textarea_fieldname = $name."_condition_entries"; } ?>

Comma separated list of
$quantity, 'offset' => $offset)); if (count($tags) == 0) return false; $tag = NULL; foreach ($tags as $tag) { $slug = rawurldecode($tag->slug); echo ''; } unset ($tag); if (count($tags) < $quantity) { return false; } return true; } // TODO Currently gets all users function adinj_get_authors(){ global $wpdb; $authors = $wpdb->get_results( "SELECT user_login, display_name from $wpdb->users" ); return $authors; } function adinj_table_width($table){ global $wp_db_version; if ($table == 'ad'){ if ($wp_db_version < 18226){ echo '60'; } else { //WP3.2+ echo '70'; } } else if ($table == 'rotation'){ if ($wp_db_version < 18226){ echo '65'; } else { //WP3.2+ echo '75'; } } else if ($table == 'dynamic'){ if ($wp_db_version < 18226){ echo '70'; } else { //WP3.2+ echo '80'; } } else { echo '61'; } } function adinj_add_alignment_options($prefix){ adinj_add_alignment_clear_options($prefix); echo "
"; adinj_add_padding_top_bottom_options($prefix); echo "
"; adinj_add_margin_top_bottom_options($prefix); } function adinj_add_alignment_clear_options($prefix, $options=NULL, $alignname=NULL, $clearname=NULL){ $aname = $prefix.'align'; $cname = $prefix.'clear'; $adefault = NULL; $cdefault = NULL; if ($alignname != NULL){ $aname = $alignname; $adefault = "align"; } if ($clearname != NULL){ $cname = $clearname; $cdefault = "clear"; } _e("Alignment", 'adinj'); echo "
"; adinj_selection_box($aname,array('d','left','center','right','float left','float right','rand lcr','rand float lr','rand all'),"",$options[$adefault]); echo "
"; _e("Clear (CSS)", 'adinj'); echo "
"; adinj_selection_box($cname,array('d','left','right','both'),"",$options[$cdefault]); } function adinj_add_margin_top_bottom_options($prefix, $options=NULL, $topname=NULL, $bottomname=NULL){ $tname = $prefix.'margin_top'; $bname = $prefix.'margin_bottom'; $tdefault = NULL; $bdefault = NULL; if ($topname != NULL){ $tname = $topname; $tdefault = "margin_top"; } if ($bottomname != NULL){ $bname = $bottomname; $bdefault = "margin_bottom"; } _e("Margin top", 'adinj'); echo "
"; $margin_settings = array('d',0,1,2,3,4,5,7,10,15,20,30); adinj_selection_box($tname, $margin_settings, "(px)", $options[$tdefault]); echo "
"; _e("Margin bottom", 'adinj'); echo "
"; adinj_selection_box($bname, $margin_settings, "(px)", $options[$bdefault]); } function adinj_add_padding_top_bottom_options($prefix, $options=NULL, $topname=NULL, $bottomname=NULL){ $tname = $prefix.'padding_top'; $bname = $prefix.'padding_bottom'; $tdefault = NULL; $bdefault = NULL; if ($topname != NULL){ $tname = $topname; $tdefault = "padding_top"; } if ($bottomname != NULL){ $bname = $bottomname; $bdefault = "padding_bottom"; } _e("Padding top", 'adinj'); echo "
"; $padding_settings = array('d',0,1,2,3,4,5,7,10,15,20,30); adinj_selection_box($tname, $padding_settings, "(px)", $options[$tdefault]); echo "
"; _e("Padding bottom", 'adinj'); echo "
"; adinj_selection_box($bname, $padding_settings, "(px)", $options[$bdefault]); } function adinj_get_version(){ $plugin_data=get_plugin_data(ADINJ_PATH . '/ad-injection.php'); return $plugin_data['Version']; } function adinj_problem_with_wpminify_check(){ if (!is_plugin_active('wp-minify/wp-minify.php')) return false; $wpm_options = get_option('wp_minify'); $ops = adinj_options(); if ($wpm_options['enable_html'] == true && adinj_mfunc_mode()){ 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 mfunc mode 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 is_supported_caching_plugin_active(){ if (!is_plugin_active('wp-super-cache/wp-cache.php') && !is_plugin_active('w3-total-cache/w3-total-cache.php') && !is_plugin_active('wp-cache/wp-cache.php')){ return false; } return true; } ////////////////////////////////////////////////////////////////////////////// function adinj_testads(){ adinj_postbox_start(__("Test Adverts and template ad examples", 'adinj'), "testads", '95%'); ?>

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 468x15 reviewmylife.co.uk

336x280 large rectangle

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

468x60 banner with dynamic PHP

The PHP will execute if you use a mfunc compatible caching plugin which is correctly configured, or if you don't use any caching plugin at all.

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

www.advancedhtml.co.uk

Template ad examples

Template ads allow any of the ads to be inserted anywhere in your theme. *Don't* try putting any of this code into one of the ad boxes - it is not an advert - it is code to load an advert directly your theme.

Simple examples for loading top, random, bottom or footer ads

If you are using mfunc mode (for caching plugins) you may need to include the ad framework loading code snippet below. You would have to include this snippet above the ad display code.

You can load the 'top', 'random', 'bottom', and 'footer' ads.

Or you can load ads stored as text files in the ad-injection-data directory (/)

Ad framework loading code for mfunc mode with caching plugins + 1 random ad

0){ $total += $ops[$split]; } } return $total; } function adinj_count_live_ads($adtype, $ops){ $name_stem = adinj_ad_name_stem($adtype); $total = 0; for ($i=1; $i<=10; ++$i){ $split = $name_stem.$i.'_split'; if (!empty($ops[$name_stem.$i]) && is_numeric($ops[$split]) && $ops[$split] > 0){ $total += 1; } } return $total; } function adinj_ad_name_stem($adtype){ if ($adtype == 'top') return 'ad_code_top_'; if ($adtype == 'random') return 'ad_code_random_'; if ($adtype == 'bottom') return 'ad_code_bottom_'; if ($adtype == 'footer') return 'ad_code_footer_'; if ($adtype == 'top_alt') return 'ad_code_top_alt_'; if ($adtype == 'random_alt') return 'ad_code_random_alt_'; if ($adtype == 'bottom_alt') return 'ad_code_bottom_alt_'; if ($adtype == 'footer_alt') return 'ad_code_footer_alt_'; // TODO widget? return 'Error: adinj_ad_name_stem:'.$adtype; } ////////////////////////////////////////////////////////////////////////////// // Hopefully run on install and upgrade function adinj_activate_hook(){ $ops = adinj_options(); if(empty($ops)){ // 1st Install. adinj_install_db(); } else { // Upgrade check. adinj_upgrade_db_if_necessary(); } } function adinj_install_db(){ $new_options = adinj_default_options(); // Dynamic defaults. if (!is_supported_caching_plugin_active()){ $new_options['ad_insertion_mode'] = 'direct'; } adinj_update_options($new_options); if (adinj_mfunc_mode()){ // Create config file. adinj_write_config_file(); } } function adinj_upgrade_db(){ $stored_options = adinj_options(); $new_options = adinj_default_options(); $stored_dbversion = adinj_db_version($stored_options); $new_dbversion = adinj_db_version($new_options); // 1. Copy existing options to new array. Use default as a baseline, // and then overwrite default with the saved ones. foreach ($new_options as $key => $value){ if (array_key_exists($key, $stored_options)){ $new_options[$key] = $stored_options[$key]; } } // 2. Upgrade options if necessary. if ($stored_dbversion == 1){ // Copy this to new setting if (adinj_ticked('first_paragraph_ad')){ $new_options['start_from_paragraph'] = 1; } // This previously wan't configured correctly $new_options['block_ips'] = 'on'; } if ($stored_dbversion < 4){ // Maintain previous behaviour for users who upgrade $new_options['content_length_unit'] = 'all'; } if ($stored_dbversion < 5){ // Maintain previous behaviour for users who upgrade $new_options['exclude_search'] = 'on'; $new_options['exclude_404'] = 'on'; $new_options['widget_exclude_search'] = 'on'; $new_options['widget_exclude_404'] = 'on'; } if ($stored_dbversion < 6){ $new_options['home_max_num_random_ads_per_page'] = $stored_options['max_num_of_ads_home_page']; } if ($stored_dbversion < 9){ if ($stored_options['ad_insertion_mode'] == 'direct_static'){ $new_options['ad_insertion_mode'] = 'direct'; $new_options['block_ips'] = 'off'; $new_options['sevisitors_only'] = 'off'; } if ($stored_options['ad_insertion_mode'] == 'direct_dynamic'){ $new_options['ad_insertion_mode'] = 'direct'; } } if ($stored_dbversion < 11){ $new_options['rnd_allow_ads_on_last_paragraph'] = 'on'; } if ($stored_dbversion < 15){ // values deliberately hard coded here to fix them on constants used for this version of db // if set to disabled if ($stored_options['top_ad_if_longer_than'] == 'd' || $stored_options['top_ad_if_longer_than'] == 'Disabled' || $stored_options['top_ad_if_longer_than'] == 'Rule Disabled'){ $new_options['top_exclude_single'] = 'on'; $new_options['top_exclude_page'] = 'on'; } if ($stored_options['home_top_ad_if_longer_than'] == 'd' || $stored_options['home_top_ad_if_longer_than'] == 'Disabled' || $stored_option['home_top_ad_if_longer_than'] == 'Rule Disabled'){ $new_options['top_exclude_home'] = 'on'; } if ($stored_options['archive_top_ad_if_longer_than'] == 'd' || $stored_options['archive_top_ad_if_longer_than'] == 'Disabled' || $stored_options['archive_top_ad_if_longer_than'] == 'Rule Disabled'){ $new_options['top_exclude_archive'] = 'on'; } if ($stored_options['bottom_ad_if_longer_than'] == 'd' || $stored_options['bottom_ad_if_longer_than'] == 'Disabled' || $stored_options['bottom_ad_if_longer_than'] == 'Rule Disabled'){ $new_options['bottom_exclude_single'] = 'on'; $new_options['bottom_exclude_page'] = 'on'; } if ($stored_options['home_bottom_ad_if_longer_than'] == 'd' || $stored_options['home_bottom_ad_if_longer_than'] == 'Disabled' || $stored_options['home_bottom_ad_if_longer_than'] == 'Rule Disabled'){ $new_options['bottom_exclude_home'] = 'on'; } if ($stored_options['archive_bottom_ad_if_longer_than'] == 'd' || $stored_options['archive_bottom_ad_if_longer_than'] == 'Disabled' || $stored_options['archive_bottom_ad_if_longer_than'] == 'Rule Disabled'){ $new_options['bottom_exclude_archive'] = 'on'; } // if set to always show if ($stored_options['top_ad_if_longer_than'] == 'a' || $stored_options['top_ad_if_longer_than'] == 'Always show'){ $new_options['top_ad_if_longer_than'] = 'd'; } if ($stored_options['home_top_ad_if_longer_than'] == 'a' || $stored_options['home_top_ad_if_longer_than'] == 'Always show'){ $new_options['home_top_ad_if_longer_than'] = 'd'; } if ($stored_options['archive_top_ad_if_longer_than'] == 'a' || $stored_options['archive_top_ad_if_longer_than'] == 'Always show'){ $new_options['archive_top_ad_if_longer_than'] = 'd'; } if ($stored_options['bottom_ad_if_longer_than'] == 'a' || $stored_options['bottom_ad_if_longer_than'] == 'Always show'){ $new_options['bottom_ad_if_longer_than'] = 'd'; } if ($stored_options['home_bottom_ad_if_longer_than'] == 'a' || $stored_options['home_bottom_ad_if_longer_than'] == 'Always show'){ $new_options['home_bottom_ad_if_longer_than'] = 'd'; } if ($stored_options['archive_bottom_ad_if_longer_than'] == 'a' || $stored_options['archive_bottom_ad_if_longer_than'] == 'Always show'){ $new_options['archive_bottom_ad_if_longer_than'] = 'd'; } } if ($stored_dbversion < 16){ $new_options['widgets_on_page_older_than'] = $stored_options['ads_on_page_older_than']; } if ($stored_dbversion < 18){ // todo test $new_options['random_ads_start_mode'] = $stored_options['random_ads_after_mode']; $new_options['random_ads_start_unit'] = $stored_options['random_ads_after_unit']; $new_options['random_ads_start_at'] = $stored_options['start_from_paragraph']; if ($new_options['random_ads_start_at'] == 'd'){ $new_options['random_ads_start_mode'] = 'anywhere'; $new_options['random_ads_start_at'] = '1'; } } // 3. Bump up db version number. $new_options['db_version'] = $new_dbversion; // 4. Save upgraded options. adinj_update_options($new_options); // 5. Update config file. if ($new_options['ad_insertion_mode'] == 'mfunc'){ // Update config file adinj_write_config_file(); } } // All these stored in a single DB option row function adinj_default_options(){ return array( // Global settings 'ads_enabled' => 'off', 'ads_on_page_older_than' => '0', 'widgets_on_page_older_than' => '0', 'content_length_unit' => 'words', // random ad start/end position 'random_ads_start_mode' => 'anywhere', 'random_ads_start_unit' => 'paragraph', 'random_ads_start_at' => '1', 'random_ads_end_mode' => 'anywhere', 'random_ads_end_unit' => 'paragraph', 'random_ads_end_at' => '20', 'random_ads_end_direction' => 'fromstart', 'rnd_allow_ads_on_last_paragraph' => '', 'rnd_reselect_ad_per_position_in_post' => '', 'multiple_ads_at_same_position' => '', // top/bottom ad position 'top_ad_position' => '0', 'top_ad_position_unit' => 'paragraph', 'bottom_ad_position' => '0', 'bottom_ad_position_unit' => 'paragraph', // single posts and pages 'top_ad_if_longer_than' => 'd', 'max_num_of_ads' => '2', // random ads 'no_random_ads_if_shorter_than' => '100', 'one_ad_if_shorter_than' => '500', 'two_ads_if_shorter_than' => '1000', 'three_ads_if_shorter_than' => 'd', 'bottom_ad_if_longer_than' => 'd', // Home page ads 'home_top_ad_if_longer_than' => 'd', 'home_max_num_top_ads_per_page' => '1', 'home_max_num_random_ads_per_post' => '1', 'home_max_num_random_ads_per_page' => '3', 'home_no_random_ads_if_shorter_than' => '100', 'home_one_ad_if_shorter_than' => '500', 'home_two_ads_if_shorter_than' => '1000', 'home_three_ads_if_shorter_than' => 'd', 'home_bottom_ad_if_longer_than' => 'd', 'home_max_num_bottom_ads_per_page' => '1', // Archive ads 'archive_top_ad_if_longer_than' => 'd', 'archive_max_num_top_ads_per_page' => '1', 'archive_max_num_random_ads_per_post' => '1', 'archive_max_num_random_ads_per_page' => '3', 'archive_no_random_ads_if_shorter_than' => '100', 'archive_one_ad_if_shorter_than' => '500', 'archive_two_ads_if_shorter_than' => '1000', 'archive_three_ads_if_shorter_than' => 'd', 'archive_bottom_ad_if_longer_than' => 'd', 'archive_max_num_bottom_ads_per_page' => '1', // Top ads 'ad_code_top_1' => '', 'ad_code_top_2' => '', 'ad_code_top_3' => '', 'ad_code_top_4' => '', 'ad_code_top_5' => '', 'ad_code_top_6' => '', 'ad_code_top_7' => '', 'ad_code_top_8' => '', 'ad_code_top_9' => '', 'ad_code_top_10' => '', 'ad_code_top_1_split' => '100', 'ad_code_top_2_split' => '100', 'ad_code_top_3_split' => '100', 'ad_code_top_4_split' => '100', 'ad_code_top_5_split' => '100', 'ad_code_top_6_split' => '100', 'ad_code_top_7_split' => '100', 'ad_code_top_8_split' => '100', 'ad_code_top_9_split' => '100', 'ad_code_top_10_split' => '100', 'ad_code_top_alt_1' => '', 'ad_code_top_alt_2' => '', 'ad_code_top_alt_1_split' => '100', 'ad_code_top_alt_2_split' => '100', // Random ads 'ad_code_random_1' => '', 'ad_code_random_2' => '', 'ad_code_random_3' => '', 'ad_code_random_4' => '', 'ad_code_random_5' => '', 'ad_code_random_6' => '', 'ad_code_random_7' => '', 'ad_code_random_8' => '', 'ad_code_random_9' => '', 'ad_code_random_10' => '', 'ad_code_random_1_split' => '100', 'ad_code_random_2_split' => '100', 'ad_code_random_3_split' => '100', 'ad_code_random_4_split' => '100', 'ad_code_random_5_split' => '100', 'ad_code_random_6_split' => '100', 'ad_code_random_7_split' => '100', 'ad_code_random_8_split' => '100', 'ad_code_random_9_split' => '100', 'ad_code_random_10_split' => '100', 'ad_code_random_alt_1' => '', 'ad_code_random_alt_2' => '', 'ad_code_random_alt_1_split' => '100', 'ad_code_random_alt_2_split' => '100', // Bottom ads 'ad_code_bottom_1' => '', 'ad_code_bottom_2' => '', 'ad_code_bottom_3' => '', 'ad_code_bottom_4' => '', 'ad_code_bottom_5' => '', 'ad_code_bottom_6' => '', 'ad_code_bottom_7' => '', 'ad_code_bottom_8' => '', 'ad_code_bottom_9' => '', 'ad_code_bottom_10' => '', 'ad_code_bottom_1_split' => '100', 'ad_code_bottom_2_split' => '100', 'ad_code_bottom_3_split' => '100', 'ad_code_bottom_4_split' => '100', 'ad_code_bottom_5_split' => '100', 'ad_code_bottom_6_split' => '100', 'ad_code_bottom_7_split' => '100', 'ad_code_bottom_8_split' => '100', 'ad_code_bottom_9_split' => '100', 'ad_code_bottom_10_split' => '100', 'ad_code_bottom_alt_1' => '', 'ad_code_bottom_alt_2' => '', 'ad_code_bottom_alt_1_split' => '100', 'ad_code_bottom_alt_2_split' => '100', // Footer ads 'ad_code_footer_1' => '', 'ad_code_footer_2' => '', 'ad_code_footer_3' => '', 'ad_code_footer_4' => '', 'ad_code_footer_5' => '', 'ad_code_footer_6' => '', 'ad_code_footer_7' => '', 'ad_code_footer_8' => '', 'ad_code_footer_9' => '', 'ad_code_footer_10' => '', 'ad_code_footer_1_split' => '100', 'ad_code_footer_2_split' => '100', 'ad_code_footer_3_split' => '100', 'ad_code_footer_4_split' => '100', 'ad_code_footer_5_split' => '100', 'ad_code_footer_6_split' => '100', 'ad_code_footer_7_split' => '100', 'ad_code_footer_8_split' => '100', 'ad_code_footer_9_split' => '100', 'ad_code_footer_10_split' => '100', 'ad_code_footer_alt_1' => '', 'ad_code_footer_alt_2' => '', 'ad_code_footer_alt_1_split' => '100', 'ad_code_footer_alt_2_split' => '100', // dynamic features 'ad_insertion_mode' => 'mfunc', 'sevisitors_only' => 'off', 'ad_referrers' => '.google., .bing., .yahoo., .ask., search?, search.', 'block_keywords' => 'off', 'blocked_keywords' => '', 'block_ads_for_hours' => '24', 'block_ips' => 'off', 'blocked_ips' => '', // ad display (layout) settings 'top_align' => 'd', 'top_clear' => 'd', 'top_margin_top' => 'd', 'top_margin_bottom' => 'd', 'top_padding_top' => 'd', 'top_padding_bottom' => 'd', 'rnd_align' => 'd', 'rnd_clear' => 'd', 'rnd_margin_top' => 'd', 'rnd_margin_bottom' => 'd', 'rnd_padding_top' => 'd', 'rnd_padding_bottom' => 'd', 'bottom_align' => 'd', 'bottom_clear' => 'd', 'bottom_margin_top' => 'd', 'bottom_margin_bottom' => 'd', 'bottom_padding_top' => 'd', 'bottom_padding_bottom' => 'd', 'footer_align' => 'center', 'footer_clear' => 'd', 'footer_margin_top' => 'd', 'footer_margin_bottom' => 'd', 'footer_padding_top' => 'd', 'footer_padding_bottom' => '3', // category, tag, author, id filters 'global_category_condition_mode' => 'o', 'global_category_condition_entries' => '', 'global_tag_condition_mode' => 'o', 'global_tag_condition_entries' => '', 'global_author_condition_mode' => 'o', 'global_author_condition_entries' => '', 'global_id_condition_mode' => 'o', 'global_id_condition_entries' => '', 'top_category_condition_mode' => 'o', 'top_category_condition_entries' => '', 'top_tag_condition_mode' => 'o', 'top_tag_condition_entries' => '', 'top_author_condition_mode' => 'o', 'top_author_condition_entries' => '', 'top_id_condition_mode' => 'o', 'top_id_condition_entries' => '', 'random_category_condition_mode' => 'o', 'random_category_condition_entries' => '', 'random_tag_condition_mode' => 'o', 'random_tag_condition_entries' => '', 'random_author_condition_mode' => 'o', 'random_author_condition_entries' => '', 'random_id_condition_mode' => 'o', 'random_id_condition_entries' => '', 'bottom_category_condition_mode' => 'o', 'bottom_category_condition_entries' => '', 'bottom_tag_condition_mode' => 'o', 'bottom_tag_condition_entries' => '', 'bottom_author_condition_mode' => 'o', 'bottom_author_condition_entries' => '', 'bottom_id_condition_mode' => 'o', 'bottom_id_condition_entries' => '', 'footer_category_condition_mode' => 'o', 'footer_category_condition_entries' => '', 'footer_tag_condition_mode' => 'o', 'footer_tag_condition_entries' => '', 'footer_author_condition_mode' => 'o', 'footer_author_condition_entries' => '', 'footer_id_condition_mode' => 'o', 'footer_id_condition_entries' => '', // exclusion tick boxes 'exclude_front' => '', 'exclude_home' => '', 'exclude_page' => '', 'exclude_single' => '', 'exclude_archive' => '', 'exclude_search' => 'on', 'exclude_404' => 'on', 'top_exclude_front' => '', 'top_exclude_home' => '', 'top_exclude_page' => '', 'top_exclude_single' => '', 'top_exclude_archive' => '', 'top_exclude_search' => '', 'top_exclude_404' => '', 'random_exclude_front' => '', 'random_exclude_home' => '', 'random_exclude_page' => '', 'random_exclude_single' => '', 'random_exclude_archive' => '', 'random_exclude_search' => '', 'random_exclude_404' => '', 'bottom_exclude_front' => '', 'bottom_exclude_home' => '', 'bottom_exclude_page' => '', 'bottom_exclude_single' => '', 'bottom_exclude_archive' => '', 'bottom_exclude_search' => '', 'bottom_exclude_404' => '', 'footer_exclude_front' => '', 'footer_exclude_home' => '', 'footer_exclude_page' => '', 'footer_exclude_single' => '', 'footer_exclude_archive' => '', 'footer_exclude_search' => '', 'footer_exclude_404' => '', 'widget_exclude_front' => '', 'widget_exclude_home' => '', 'widget_exclude_page' => '', 'widget_exclude_single' => '', 'widget_exclude_archive' => '', 'widget_exclude_search' => '', 'widget_exclude_404' => '', 'template_exclude_front' => '', 'template_exclude_home' => '', 'template_exclude_page' => '', 'template_exclude_single' => '', 'template_exclude_archive' => '', 'template_exclude_search' => '', 'template_exclude_404' => '', // ui main tab 'ui_global_hide' => 'false', 'ui_adsettings_hide' => 'false', 'ui_adverts_hide' => 'false', 'ui_filters_hide' => 'false', 'ui_restrictions_hide' => 'false', 'ui_docsquickstart_hide' => 'false', 'ui_testads_hide' => 'false', 'ui_conditions_show' => 'false', 'ui_top_conditions_show' => 'false', 'ui_random_conditions_show' => 'false', 'ui_bottom_conditions_show' => 'false', 'ui_footer_conditions_show' => 'false', 'ui_footer_docs_show' => 'false', // ui ad rotation tab 'ui_docs_adrotation_hide' => 'false', 'ui_multiple_top_hide' => 'false', 'ui_multiple_random_hide' => 'false', 'ui_multiple_bottom_hide' => 'false', 'ui_multiple_footer_hide' => 'false', 'ui_misc_hide' => 'true', 'ui_docs_tags_hide' => 'true', // ui debug tab 'ui_debugging_hide' => 'false', // debug 'debug_mode' => '', // version 'db_version' => ADINJ_DB_VERSION ); } function adinj_getdefault($option){ $default_options = adinj_default_options(); return "(default: " . $default_options[$option] . ")"; } function write_ad_to_file($ad, $ad_path){ adinj_write_file($ad_path, $ad, 0640); } function adinj_init_hook() { $ops = adinj_options(); if ($ops['ads_enabled'] != 'on') { add_action('admin_notices', 'adinj_init_warning'); } } // init add_action('init', 'adinj_init_hook'); // Config links add_action('admin_menu', 'adinj_admin_menu_hook'); add_filter('plugin_action_links', 'adinj_options_link_hook', 10, 2); // digits = priority, num args ?>