function widget($args, $instance)
 {
     if (adinj_ads_completely_disabled_from_page()) {
         return;
     }
     $options = adinj_options();
     if (is_home() && adinj_ticked('widget_exclude_home') || is_page() && adinj_ticked('widget_exclude_page') || is_single() && adinj_ticked('widget_exclude_single') || is_archive() && adinj_ticked('widget_exclude_archive')) {
         return;
     }
     if ($options['ad_insertion_mode'] == 'direct_dynamic') {
         if (adinj_show_adverts() !== true) {
             return;
         }
     }
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     $advert = $instance['advert'];
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     $adcode = "";
     $include = "";
     if ($options['ad_insertion_mode'] == 'mfunc') {
         $include = adinj_ad_code_include();
         $adcode = adinj_get_mfunc_code($this->get_ad_file_name());
     } else {
         $adcode = $advert;
     }
     $adcode = adinj_ad_code_eval($adcode);
     if ($advert) {
         echo $include;
         echo $adcode;
     }
     echo $after_widget;
 }
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';
        }
    }
    if ($stored_dbversion < 19) {
        if ($new_options['random_ads_start_at'] == 'd' || $new_options['random_ads_start_at'] == 'Rule Disabled' || $new_options['random_ads_start_at'] == 'Disabled') {
            $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();
    }
}
Example #3
0
 function adinj_config_debug_mode()
 {
     return adinj_ticked('debug_mode');
 }
Example #4
0
function adinj_add_exclude_row_td($prefix, $setting, $class, $all)
{
    if (adinj_ticked($setting) || adinj_ticked($prefix . $setting)) {
        ?>
		<td style="background-color:#ff9999"><?php 
        adinj_add_checkbox($prefix . $setting, $class, $all);
        ?>
</td>
		<?php 
    } else {
        ?>
		<td style="background-color:#ccff99"><?php 
        adinj_add_checkbox($prefix . $setting, $class, $all);
        ?>
</td>
		<?php 
    }
}
Example #5
0
function adinj_inject_hook($content)
{
    if (is_feed()) {
        return $content;
    }
    $reason = adinj_ads_completely_disabled_from_page($content);
    if ($reason !== false) {
        return adinj($content, $reason);
    }
    $ops = adinj_options();
    if ($ops['ad_insertion_mode'] == 'direct_dynamic') {
        $showads = adinj_show_adverts();
        if ($showads !== true) {
            return adinj($content, "NOADS: ad blocked at run time reason={$showads}");
        }
    }
    $ad_include = adinj_ad_code_include();
    # Ad sandwich mode
    if (is_page() || is_single()) {
        if (stripos($content, "<!--adsandwich-->") !== false) {
            return adinj($ad_include . adinj_ad_code_top() . $content . adinj_ad_code_bottom(), "Ads=adsandwich");
        }
        if (stripos($content, "<!--adfooter-->") !== false) {
            return adinj($content . $ad_include . adinj_ad_code_bottom(), "Ads=adfooter");
        }
    }
    # Insert top and bottom ads if necesary
    $length = strlen($content);
    if (is_page() || is_single()) {
        if (adinj_do_rule_if($ops['top_ad_if_longer_than'], '<', $length)) {
            $content = $ad_include . adinj_ad_code_top() . $content;
            $ad_include = false;
        }
        if (adinj_do_rule_if($ops['bottom_ad_if_longer_than'], '<', $length)) {
            $content = $content . adinj_ad_code_bottom();
        }
    }
    $num_rand_ads_to_insert = adinj_num_rand_ads_to_insert($length);
    if ($num_rand_ads_to_insert <= 0) {
        return adinj($content, "all ads used up");
    }
    $ad = adinj_ad_code_random();
    if (empty($ad)) {
        return adinj($content, "no random ad defined");
    }
    if ($ad_include !== false) {
        $content = $ad_include . $content;
    }
    $debug_on = $ops['debug_mode'];
    if (!$debug_on) {
        $debugtags = false;
    }
    $content_adfree_header = "";
    $content_adfree_footer = "";
    // TODO add docs explaining the significance of leaving blank lines
    // before or after these tags
    # 'Adsense Injection' tag compatibility
    $split = adinj_split_by_tag($content, "<!--adsensestart-->", $debugtags);
    if (count($split) == 2) {
        $content_adfree_header = $split[0];
        $content = $split[1];
    }
    # Use the same naming convention for the end tag
    $split = adinj_split_by_tag($content, "<!--adsenseend-->", $debugtags);
    if (count($split) == 2) {
        $content = $split[0];
        $content_adfree_footer = $split[1];
    }
    $split = adinj_split_by_tag($content, "<!--adstart-->", $debugtags);
    if (count($split) == 2) {
        $content_adfree_header = $split[0];
        $content = $split[1];
    }
    $split = adinj_split_by_tag($content, "<!--adend-->", $debugtags);
    if (count($split) == 2) {
        $content = $split[0];
        $content_adfree_footer = $split[1];
    }
    // TODO add note explaining that start tags are processed before the 'first
    // paragraph ad
    // Move onto random ad insertions
    $paragraphmarker = "</p>";
    if (stripos($content, $paragraphmarker) === false) {
        return adinj($content, "no &lt;/p&gt; tags");
    }
    if ($debug_on) {
        $debug = "\nTags=" . htmlentities($debugtags);
    }
    // Generate a list of all potential injection points
    if ($debug_on) {
        $debug .= "\nPotential positions: ";
    }
    $potential_inj_positions = array();
    $prevpos = -1;
    while (($prevpos = stripos($content, $paragraphmarker, $prevpos + 1)) !== false) {
        $potential_inj_positions[] = $prevpos + strlen($paragraphmarker);
        if ($debug_on) {
            $debug .= $prevpos . ", ";
        }
    }
    if ($debug_on) {
        $debug .= "\npotential_inj_positions:" . sizeof($potential_inj_positions);
    }
    if (sizeof($potential_inj_positions) == 0) {
        return adinj($content, "Error: no potential inj positions");
    }
    $inj_positions = array();
    if (adinj_ticked('first_paragraph_ad')) {
        $inj_positions[] = array_shift($potential_inj_positions);
        --$num_rand_ads_to_insert;
    }
    // Pick the correct number of random injection points
    if (sizeof($potential_inj_positions) > 0 && $num_rand_ads_to_insert > 0) {
        if (!adinj_ticked('multiple_ads_at_same_position')) {
            // Each ad is inserted into a unique position
            if (sizeof($potential_inj_positions) < $num_rand_ads_to_insert) {
                $debug .= "\nnum_rand_ads_to_insert requested={$num_rand_ads_to_insert}. But restricted to " . sizeof($potential_inj_positions) . " due to limited injection points.";
                $num_rand_ads_to_insert = sizeof($potential_inj_positions);
            }
            $rand_positions = array_rand(array_flip($potential_inj_positions), $num_rand_ads_to_insert);
            if ($num_rand_ads_to_insert == 1) {
                // Convert it back into an array
                $inj_positions[] = $rand_positions;
            } else {
                $inj_positions = array_merge($inj_positions, $rand_positions);
            }
            foreach ($inj_positions as $pos) {
                if ($debug_on) {
                    $debug = $pos . ", " . $debug;
                }
            }
        } else {
            // Multiple ads may be inserted at the same position
            $injections = 0;
            while ($injections++ < $num_rand_ads_to_insert) {
                $rnd = array_rand($potential_inj_positions);
                if ($debug_on) {
                    $debug = $potential_inj_positions[$rnd] . ", " . $debug;
                }
                $inj_positions[] = $potential_inj_positions[$rnd];
            }
        }
    }
    if (sizeof($inj_positions) == 0) {
        return adinj($content_adfree_header . $content . $content_adfree_footer, "Error: No ad injection positions: " . $debug);
    }
    // Sort positions
    sort($inj_positions);
    // Insert ads in reverse order
    global $adinj_total_rand_ads_used, $adinj_total_all_ads_used;
    for ($adnum = sizeof($inj_positions) - 1; $adnum >= 0; $adnum--) {
        $content = substr_replace($content, $ad, $inj_positions[$adnum], 0);
        ++$adinj_total_rand_ads_used;
        ++$adinj_total_all_ads_used;
    }
    return adinj($content_adfree_header . $content . $content_adfree_footer, "Ads injected: " . $debug);
}
    function add_checkbox($name, $instance)
    {
        ?>
		<input type="hidden" <?php 
        $this->add_name($name);
        ?>
 value="off" />
		<input type="checkbox" <?php 
        $this->add_name($name);
        ?>
 <?php 
        echo adinj_ticked($name, $instance);
        ?>
 />
	<?php 
    }
function adinj_get_random_paragraphs($content, $length, $original_paragraph_positions, &$debug)
{
    $ops = adinj_options();
    $debug_on = adinj_debug_on();
    $random_ad_paragraphs = array();
    $random_start_paragraph = 0;
    $random_end_paragraph = 0;
    adinj_get_random_ad_start_end_paragraph($content, $original_paragraph_positions, $random_start_paragraph, $random_end_paragraph, $debug);
    if ($debug_on) {
        $debug .= "\n1st Injected random ads range starts at: {$random_start_paragraph}, and ends at: {$random_end_paragraph}";
    }
    $paracount = count($original_paragraph_positions);
    $random_end_paragraph = min($random_end_paragraph, $paracount);
    if (!adinj_ticked('rnd_allow_ads_on_last_paragraph')) {
        if ($random_end_paragraph == $paracount) {
            --$random_end_paragraph;
        }
        if ($random_end_paragraph == 0) {
            if ($debug_on) {
                $debug .= "\nNo random ads: no potential inj positions after removing last paragraph position";
            }
            return;
        }
    }
    if ($random_start_paragraph <= 0 || $random_end_paragraph <= 0 || $random_end_paragraph - $random_start_paragraph < 0) {
        if ($debug_on) {
            $debug .= "\nWarning: No paragraphs: random_start_paragraph:{$random_start_paragraph} random_end_paragraph:{$random_end_paragraph}";
        }
        return array();
    }
    if ($debug_on) {
        $debug .= "\n2nd Injected random ads range starts at: {$random_start_paragraph}, and ends at: {$random_end_paragraph}";
    }
    $potential_random_ad_paragraphs = range($random_start_paragraph, $random_end_paragraph);
    if ($debug_on) {
        $debug .= "\npotential_random_ad_paragraphs:" . sizeof($potential_random_ad_paragraphs);
    }
    if (sizeof($potential_random_ad_paragraphs) == 0) {
        if ($debug_on) {
            $debug .= "\nNo random ads: no potential inj positions found in content";
        }
        return array();
    }
    # Checks to see if we can inject random ads
    $requested_num_rand_ads_to_insert = adinj_num_rand_ads_to_insert($length, $debug);
    if ($debug_on) {
        $debug .= "\nrequested_num_rand_ads_to_insert:{$requested_num_rand_ads_to_insert}";
    }
    if ($requested_num_rand_ads_to_insert <= 0) {
        if ($debug_on) {
            $debug .= "\nNo random ads enabled on this post";
        }
        return array();
    }
    $num_rand_ads_to_insert = $requested_num_rand_ads_to_insert;
    # We have to put the first ad at the first position we already selected unless the first ad can start 'anywhere'
    if ($ops['random_ads_start_mode'] != 'anywhere' && $ops['random_ads_start_mode'] != 'after') {
        $random_ad_paragraphs[] = array_shift($potential_random_ad_paragraphs);
        --$num_rand_ads_to_insert;
    }
    # Pick the correct number of random injection points
    if (sizeof($potential_random_ad_paragraphs) > 0 && $num_rand_ads_to_insert > 0) {
        if (!adinj_ticked('multiple_ads_at_same_position')) {
            // Each ad is inserted into a unique position
            if (sizeof($potential_random_ad_paragraphs) < $num_rand_ads_to_insert) {
                $debug .= "\nNum random ads requested={$requested_num_rand_ads_to_insert}. But restricted to " . (sizeof($potential_random_ad_paragraphs) + sizeof($random_ad_paragraphs)) . " due to limited injection points.";
                $num_rand_ads_to_insert = sizeof($potential_random_ad_paragraphs);
            }
            $rand_positions = array_rand(array_flip($potential_random_ad_paragraphs), $num_rand_ads_to_insert);
            if ($num_rand_ads_to_insert == 1) {
                // Add the single value to the array
                $random_ad_paragraphs[] = $rand_positions;
            } else {
                // Merge the values with the array
                $random_ad_paragraphs = array_merge($random_ad_paragraphs, $rand_positions);
            }
        } else {
            // Multiple ads may be inserted at the same position
            $injections = 0;
            while ($injections++ < $num_rand_ads_to_insert) {
                $rnd = array_rand($potential_random_ad_paragraphs);
                $random_ad_paragraphs[] = $potential_random_ad_paragraphs[$rnd];
            }
        }
    }
    # Sort positions
    sort($random_ad_paragraphs);
    if ($debug_on) {
        $injected_list = '';
        foreach ($random_ad_paragraphs as $pos) {
            $injected_list .= "{$pos} ";
        }
        $debug .= "\nInjected ads at: {$injected_list}";
    }
    return $random_ad_paragraphs;
}
function adinj_options_page()
{
    adinj_save_options();
    $ops = adinj_options();
    if ($ops === false || adinj_options_need_upgrading($ops)) {
        // Upgraded via FTP without being deactivated/reactivated
        adinj_activate_hook();
    }
    $ops = adinj_options(1);
    if ($ops['ad_insertion_mode'] == 'mfunc') {
        if (!@file_exists(ADINJ_CONFIG_FILE)) {
            adinj_write_config_file();
        }
    }
    echo '<div class="wrap">';
    if (adinj_problem_with_wpminify_check()) {
        echo '<div id="ad-injection-warning" class="error"><p><strong>';
        echo adinj_get_problem_with_wpminify_message();
        echo '</strong></p></div>';
    }
    echo '<div id="icon-options-general" class="icon32"></div><h2>Ad Injection ' . adinj_get_version() . adinj_get_logo() . '</h2>';
    if (isset($_POST['adinj_action'])) {
        echo '<div id="message" class="updated below-h2"><p><strong>';
        echo 'All settings saved: ';
        if (is_plugin_active('wp-super-cache/wp-cache.php')) {
            echo "You might need to <a href='options-general.php?page=wpsupercache&amp;tab=tester'>clear your WP Super Cache cache</a> 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 '</strong>';
        if ($ops['ad_insertion_mode'] == 'mfunc') {
            global $adinj_warning_msg_filewrite;
            if (!empty($adinj_warning_msg_filewrite)) {
                echo $adinj_warning_msg_filewrite;
                echo "<br />Workaround: If you are unable to fix these errors you will have to switch to a <a href='#restrictions'>direct insertion mode</a> (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 '<br />Info: Some warnings were generated by chmod. See the <a href="#debugging">debugging</a> section for more info.';
        }
        if ($ops['ads_enabled'] != 'on') {
            echo '<br /><font color="red">Warning: Ads are not enabled. You need to turn the ads on for everyone to see them.</font>';
        }
        echo '</p></div>';
    } else {
        echo '<div id="message" class="updated below-h2"><p style="line-height:140%"><strong>';
        echo "24th December 2010: I'll be taking a break from updating Ad Injection over Christmas and the New Year. The next release will probably be on the 5th January. But please keep sending me any <a href='https://spreadsheets.google.com/viewform?formkey=dFUwZzBYcG1HNzNKMmJZdWFDdFhkY0E6MQ' target='_new'>feedback or bug reports</a>. I read and act on all feedback! Merry Christmas :)";
        echo '</strong></p></div>';
    }
    ?>
	
	
	
	<div style="width:258px; float:right;">
	<div class="postbox-container" style="width:258px;">
		<div class="metabox-holder">	
		<div class="meta-box-sortables" style="min-height:50px;">
		<div id="toc" class="postbox">
		<h3 class="hndle"><span><?php 
    echo adinj_get_logo();
    ?>
 Status</span></h3>
		<div class="inside" style="margin:5px;">
			<table border="0" cellpadding="2">
			<tr><td style="text-align:right; vertical-align:top">
			<b><a href="#global">Ads enabled</a></b>
			</td><td>
			<?php 
    $info = adinj_get_status('global');
    echo adinj_dot($info[0]) . ' ' . $info[1];
    if ($info[0] != 'red') {
        ?>
			<br />&nbsp;&nbsp;<?php 
        echo adinj_green_or_red_dot('exclude_home');
        ?>
 home
			<br />&nbsp;&nbsp;<?php 
        echo adinj_green_or_red_dot('exclude_page');
        ?>
 page
			<br />&nbsp;&nbsp;<?php 
        echo adinj_green_or_red_dot('exclude_single');
        ?>
 single
			<br />&nbsp;&nbsp;<?php 
        echo adinj_green_or_red_dot('exclude_archive');
        ?>
 archive
			</td></tr>
			<tr><td style="text-align:right; vertical-align:top">
			<b><a href="#random">Random ads</a></b>
			</td><td>
			<?php 
        $info = adinj_get_status('random');
        echo adinj_dot($info[0]) . ' ' . $info[1] . '<br />';
        $info = adinj_get_status('random_home');
        echo adinj_dot($info[0]) . ' ' . $info[1];
        ?>
			</td></tr>
			<tr><td style="text-align:right">
			<b><a href="#topad">Top ad</a></b>
			</td><td>
			<?php 
        $info = adinj_get_status('topad');
        echo adinj_dot($info[0]) . ' ' . $info[1];
        ?>
			</td></tr>
			<tr><td style="text-align:right">
			<b><a href="#bottomad">Bottom ad</a></b>
			</td><td>
			<?php 
        $info = adinj_get_status('bottomad');
        echo adinj_dot($info[0]) . ' ' . $info[1];
        ?>
			</td></tr>
			<tr><td style="text-align:right; vertical-align:top">
			<b><a href="#widgets">Widgets</a></b>
			</td><td>
			<?php 
        $info = adinj_get_status('widgets');
        echo adinj_dot($info[0]) . ' ' . $info[1];
        if ($info[0] != 'red') {
            ?>
			<br />&nbsp;&nbsp;<?php 
            echo adinj_green_or_red_dot('widget_exclude_home');
            ?>
 home
			<br />&nbsp;&nbsp;<?php 
            echo adinj_green_or_red_dot('widget_exclude_page');
            ?>
 page
			<br />&nbsp;&nbsp;<?php 
            echo adinj_green_or_red_dot('widget_exclude_single');
            ?>
 single
			<br />&nbsp;&nbsp;<?php 
            echo adinj_green_or_red_dot('widget_exclude_archive');
            ?>
 archive
			<?php 
        }
        ?>
			</td></tr>
			<tr><td style="text-align:right">
			<b><a href="#restrictions">Mode</a></b>
			</td><td>
			<?php 
        $info = adinj_get_status('mode');
        echo adinj_dot($info[0]) . ' ' . $info[1];
        ?>
			</td></tr>
			<tr><td style="text-align:right">
			<b><a href="#dynamic">Restrictions</a></b>
			</td><td>
			<?php 
        $info = adinj_get_status('restrictions');
        echo adinj_dot($info[0]) . ' ' . $info[1];
        ?>
			</td></tr>
			<tr><td style="text-align:right">
			<b><a href="#debugging">Debug mode</a></b>
			</td><td>
			<?php 
        $info = adinj_get_status('debugging');
        echo adinj_dot($info[0]) . ' ' . $info[1];
        ?>
			</td></tr>
			<tr><td>
			</td><td>
			</td></tr>
			<tr><td>
			</td><td>
			<?php 
    }
    ?>
			</td></tr>
			</table>
		</div>
		</div>	
		</div>
		</div>
	</div> 	
	
	<br />
	
	<div class="postbox-container" style="width:258px;">
		<div class="metabox-holder">	
		<div class="meta-box-sortables">
		<div id="toc" class="postbox">
		<h3 class="hndle"><span><?php 
    echo adinj_get_logo();
    ?>
 More info...</span></h3>
		<div class="inside" style="margin:5px;">
			<h4>More Ad Injection information</h4>
			<ul>
			<li><a href="http://www.reviewmylife.co.uk/blog/2010/12/06/ad-injection-plugin-wordpress/" target="_new">Ad Injection at reviewmylife</a></li>
			<li><a href="http://wordpress.org/extend/plugins/ad-injection/" target="_new">Ad Injection at WordPress</a></li>
			<li><b><a href="https://spreadsheets.google.com/viewform?formkey=dFUwZzBYcG1HNzNKMmJZdWFDdFhkY0E6MQ" target="_new">Report a bug / give feedback</a></b></li>
			</ul>
			<h4>Coming in 2011</h4>
			<ul>
			<li>More precise control over which categories and tags the ads are shown in.</li>
			<li>Extra places where adverts can be inserted.</li>
			</ul>
			
			<h4><font color="red">Important!</font></h4>
			<p>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!</p>
		
			<h4><font color="red">Beta version</font></h4>
			<p>This plugin has only only recently been released. I'm actively listening to your feedback and fixing any problems, and adding new features that you request. Please let me know if you like the plugin too!</p>
			
			<h4>More by this author</h4>
			<ul>
			<li><a href="http://www.reviewmylife.co.uk/" target="_new">www.reviewmylife.co.uk</a></li>
			<li><a href="http://www.advancedhtml.co.uk/" target="_new">www.advancedhtml.co.uk</a></li>
			</ul>
		</div>
		</div>	
		</div>
		</div>
	</div> 
	</div>
		
	<script type="text/javascript">
	function adinj_addtext(element, value) {
		if (value.length == 0) return;
		separator = ', ';
		if (element.value.length == 0){
			separator = '';
		}
		element.value += (separator + value);
	}
	</script>
	
	<p><a href="#random">Random ads</a> | <a href="#topad">Top</a> | <a href="#bottomad">Bottom</a> | <a href="#widgets">Widgets</a> | <a href="#restrictions">Ad insert mode/dynamic restrictions</a> | <a href="#debugging">Debug</a> | <a href="#docs">Quick Start</a> | <a href="#testads">Test ads</a></p>
	
	<form name="adinjform" method="post" action="">
	<?php 
    wp_nonce_field('_adinj_form', '_adinj_nonce');
    ?>
	
	
	<?php 
    adinj_postbox_start(__("Global settings", 'adinj'), 'global');
    ?>
	
	<p>These settings apply to all ads (random, top, bottom, and widget). They will override all other settings.</p>
	
	<input type="radio" name="ads_enabled" value="on" <?php 
    if ($ops['ads_enabled'] == 'on') {
        echo 'checked="checked"';
    }
    ?>
 /> <b>On: <?php 
    _e('Ads enabled', 'adinj');
    ?>
</b><br />
	<input type="radio" name="ads_enabled" value="off" <?php 
    if ($ops['ads_enabled'] == 'off' || $ops['ads_enabled'] == '') {
        echo 'checked="checked"';
    }
    ?>
 /> <b>Off</b><br />
	<input type="radio" name="ads_enabled" value="test" <?php 
    if ($ops['ads_enabled'] == 'test') {
        echo 'checked="checked"';
    }
    ?>
 /> <b>Test mode</b> - Only show ads to admin.<br />
	<span style="font-size:10px;color:red;">Warning: Turn any caching plugin *off* before using test mode. If you leave them on the test adverts will be cached and shown to your real visitors.</span><br />

	<table border="0">
	<tr><td>
	<p><?php 
    _e("Only show ads on pages older than ", 'adinj');
    ?>
</p>
	</td><td>
	<p>
	<select name='ads_on_page_older_than'>
	<?php 
    $older_than_days = array(0, 1, 2, 3, 5, 7, 10, 14, 21, 28, 40, 50);
    for ($value = 0; $value < sizeof($older_than_days); ++$value) {
        echo "<option value=\"{$older_than_days[$value]}\" ";
        if ($ops['ads_on_page_older_than'] == $older_than_days[$value]) {
            echo 'selected="selected"';
        }
        echo ">{$older_than_days[$value]}</option>";
    }
    ?>
	</select><?php 
    _e(" (days)", 'adinj');
    ?>
 - only for single posts and pages</p>
	</td></tr>
	<tr><td style="vertical-align:top">
	Don't show ads on these page types:
	</td><td>
	<input type="checkbox" name="exclude_home" <?php 
    echo adinj_ticked('exclude_home');
    ?>
 />home - <?php 
    echo get_bloginfo('url');
    ?>
<br />
	<?php 
    $count_pages = wp_count_posts('page', 'readable');
    $count_posts = wp_count_posts('post', 'readable');
    ?>
	<input type="checkbox" name="exclude_page" <?php 
    echo adinj_ticked('exclude_page');
    ?>
 />page - <?php 
    echo $count_pages->publish;
    ?>
 page(s)<br />
	<input type="checkbox" name="exclude_single" <?php 
    echo adinj_ticked('exclude_single');
    ?>
 />single -<?php 
    echo $count_posts->publish;
    ?>
 individual blog post(s)<br />
	<input type="checkbox" name="exclude_archive" <?php 
    echo adinj_ticked('exclude_archive');
    ?>
 />archive - only <a href="#widgets">widgets</a> currently appear on archives<br />
	</td></tr>
	</table>
	
	<b>Category and tag conditions</b>
	
	<?php 
    adinj_condition_table('global_category', 'category slugs. e.g: cat1, cat2, cat3', 'category');
    ?>
	
	<?php 
    adinj_condition_table('global_tag', 'tag slugs. e.g: tag1, tag2, tag3', 'tag');
    ?>
	
	<?php 
    adinj_postbox_end();
    ?>
	
	
	
	
	<?php 
    adinj_postbox_start(__("Randomly Injected ad code", 'adinj'), 'random');
    ?>
	
	<table border="0" cellspacing="5">
	<tr><td style="vertical-align: top">
	<textarea name="ad_code_random_1" rows="10" cols="60"><?php 
    echo $ops['ad_code_random_1'];
    ?>
</textarea>
	</td><td style="vertical-align: top">
	<?php 
    adinj_add_alignment_options('rnd_');
    ?>
	</td></tr>
	<tr><td>
	<?php 
    _e("Always put the first ad after the first paragraph.", 'adinj');
    ?>
 <input type="checkbox" name="first_paragraph_ad" <?php 
    echo adinj_ticked('first_paragraph_ad');
    ?>
 />
	</td><td>
	</td></tr>
	</table>

	
	<p><span style="font-size:10px;"><b>Docs:</b> 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 <a href="#468x60">468x60</a> or <a href="#728x90">728x90</a> banner.</span></p>
	<p><span style="font-size:10px;">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.</span></p>
	</div>
	
	<input type="submit" style="float:right" name="adinj_action" value="<?php 
    _e('Save all settings', 'adinj');
    ?>
" />
	<h3><?php 
    _e("Single posts and pages: Randomly Injected ad settings", 'adinj');
    ?>
</h3>
	<div class="inside" style="margin:10px">
	<p>These random ad injection settings are specific to individual posts and pages.</p>
	
	<table border="0">
	
	<tr><td>
	<?php 
    _e("Allow multiple ads to be injected at the same positions.", 'adinj');
    ?>
	</td><td>
	<input type="checkbox" name="multiple_ads_at_same_position" <?php 
    echo adinj_ticked('multiple_ads_at_same_position');
    ?>
 /> (default is to inject ads at unique positions)
	</td></tr>

	
	<tr><td>
	<?php 
    _e("Maximum number of randomly injected ads: ", 'adinj');
    ?>
</td><td>
	<select name='max_num_of_ads'>
	<?php 
    for ($value = 0; $value <= 10; ++$value) {
        echo "<option value=\"{$value}\" ";
        if ($ops['max_num_of_ads'] == $value) {
            echo 'selected="selected"';
        }
        echo ">{$value}</option>";
    }
    ?>
	</select> <?php 
    echo adinj_getdefault('max_num_of_ads');
    ?>
<br />
	</td></tr>
	
	<tr><td>
	<?php 
    _e("No random ads if page shorter than: ", 'adinj');
    echo '</td><td>';
    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');
    ?>
	</td></tr>
	
	<tr><td>
	<?php 
    _e("Limit of 1 ad if page shorter than: ", 'adinj');
    echo '</td><td>';
    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');
    ?>
	</td></tr>
	
	<tr><td>
	<?php 
    _e("Limit of 2 ads if page shorter than: ", 'adinj');
    echo '</td><td>';
    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');
    ?>
	</td></tr>

	<tr><td>
	<?php 
    _e("Limit of 3 ads if page shorter than: ", 'adinj');
    echo '</td><td>';
    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');
    ?>
	</td></tr>
	</table>
	
	<br clear="all" />
	<p><span style="font-size:10px;"><b>Docs:</b> The above directives are processed in order from top to bottom.</span></p>
	

	<p></p>
	
	</div>
	
	<input type="submit" style="float:right" name="adinj_action" value="<?php 
    _e('Save all settings', 'adinj');
    ?>
" />
	<h3><a name="random_home"></a><?php 
    _e("Home page: Randomly Injected ad settings", 'adinj');
    ?>
 (<?php 
    echo get_bloginfo('url');
    ?>
)</h3>
	<div class="inside" style="margin:10px">
	<p>These random ad injection settings are specific to your home page.</p>
	
	<?php 
    _e("Maximum number of injected ads: ", 'adinj');
    ?>
	<select name='max_num_of_ads_home_page'>
	<?php 
    for ($value = 0; $value <= 10; ++$value) {
        echo "<option value=\"{$value}\" ";
        if ($ops['max_num_of_ads_home_page'] == $value) {
            echo 'selected="selected"';
        }
        echo ">{$value}</option>";
    }
    ?>
	</select> <?php 
    echo adinj_getdefault('max_num_of_ads_home_page');
    ?>
<br />
	
	<p><span style="font-size:10px;"><b>Docs:</b> On a multi-post home page, one randomly positioned advert will be inserted into each post, up to the maximum number specified here.</span></p>
	
	<?php 
    adinj_postbox_end();
    ?>
	
	
	
	<?php 
    adinj_postbox_start(__("Optional top advert (single posts and pages only)", 'adinj'), 'topad');
    ?>
	
	<?php 
    _e("Only show top ad on pages longer than: ", 'adinj');
    adinj_selection_box("top_ad_if_longer_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000, ADINJ_ALWAYS_SHOW));
    ?>

	<br clear="all" />
	
	<table border="0">
	<tr><td>
	<textarea name="ad_code_top_1" rows="10" cols="60"><?php 
    echo $ops['ad_code_top_1'];
    ?>
</textarea>
	</td><td style="vertical-align: top">
	<?php 
    adinj_add_alignment_options('top_');
    ?>
	</td></tr>
	</table>
	<span style="font-size:10px;">The top ad is in addition to the quantity of other ads selected.</span>
	
	<p><span style="font-size:10px;"><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.</span></p>
	
	<?php 
    adinj_postbox_end();
    ?>
	
	
	<?php 
    adinj_postbox_start(__("Optional bottom advert (single posts and pages only)", 'adinj'), 'bottomad');
    ?>
	
	<?php 
    _e("Only show bottom ad on pages longer than: ", 'adinj');
    adinj_selection_box("bottom_ad_if_longer_than", array(ADINJ_RULE_DISABLED, 100, 200, 300, 500, 1000, 1500, 2000, 2500, 3000, 5000, 10000, 20000, ADINJ_ALWAYS_SHOW));
    ?>
	
	<br clear="all"/>
	
	<table border="0">
	<tr><td>
	<textarea name="ad_code_bottom_1" rows="10" cols="60"><?php 
    echo $ops['ad_code_bottom_1'];
    ?>
</textarea>
	</td><td style="vertical-align: top">
	<?php 
    adinj_add_alignment_options('bottom_');
    ?>
	</td></tr>
	</table>
	<span style="font-size:10px;">The top ad is in addition to the quantity of other ads selected.</span>
	
	<p><span style="font-size:10px;"><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.</span></p>
	
	
	<?php 
    adinj_postbox_end();
    ?>
	
	
	<?php 
    adinj_postbox_start(__("Widget settings (sidebar ads)", 'adinj'), 'widgets');
    ?>
	
	<p>You must configure your individual widgets from the <a href="widgets.php">widgets control panel</a>. However these settings are global to all widgets. Also note that the main set of <a href="#global">global settings</a> will override these ones.</p>

	<table border="0">
	
	<tr><td>
	<p>Don't show widget ads on these page types:</p>
	</td><td>
	<input type="checkbox" name="widget_exclude_home" <?php 
    echo adinj_ticked('widget_exclude_home');
    ?>
 />home - <?php 
    echo get_bloginfo('url');
    ?>
<br />
	<input type="checkbox" name="widget_exclude_page" <?php 
    echo adinj_ticked('widget_exclude_page');
    ?>
 />page - <?php 
    echo $count_pages->publish;
    ?>
 page(s)<br />
	<input type="checkbox" name="widget_exclude_single" <?php 
    echo adinj_ticked('widget_exclude_single');
    ?>
 />single - <?php 
    echo $count_posts->publish;
    ?>
 individual blog post(s)<br />
	<input type="checkbox" name="widget_exclude_archive" <?php 
    echo adinj_ticked('widget_exclude_archive');
    ?>
 />archive - includes category, tag, author, and date pages types<br />
	</td></tr>
	
	</table>
	
	
	<?php 
    adinj_postbox_end();
    ?>
	
	
	<?php 
    adinj_postbox_start(__("Ad insertion mode and dynamic ad display restrictions", 'adinj'), 'restrictions');
    ?>
	
	<h4>Ad insertion mode</h4>
	
	<blockquote>
	<p><input type="radio" name="ad_insertion_mode" value="mfunc" <?php 
    if ($ops['ad_insertion_mode'] == 'mfunc') {
        echo 'checked="checked"';
    }
    ?>
 /> <b>Use mfunc tags for dynamic features</b> - 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.</p>
	<p><input type="radio" name="ad_insertion_mode" value="direct_dynamic" <?php 
    if ($ops['ad_insertion_mode'] == 'direct_dynamic') {
        echo 'checked="checked"';
    }
    ?>
 /> <b>Direct ad insertion with dynamic features</b> - Dynamic features will work if no caching is used. Only select this if you are not using any caching plugin.</p>
	<p><input type="radio" name="ad_insertion_mode" value="direct_static" <?php 
    if ($ops['ad_insertion_mode'] == 'direct_static') {
        echo 'checked="checked"';
    }
    ?>
 /> <b>Direct static ad insertion</b> - No dynamic feature support. Select this if you are using a caching plugin which is not compatible with WP Super Cache's mfunc tags.</p>
	</blockquote>
	</div>
	<p></p>
	
	<script type="text/javascript">
	jQuery(document).ready(function(){
	jQuery('input[name=ad_insertion_mode]:radio').change(function() {
		if (jQuery('input[name=ad_insertion_mode]:checked').val() == "direct_static"){
			jQuery('.dynamic_features').slideUp(1000);
			jQuery('.dynamic_features_msg').slideDown(1000);
		} else {
			jQuery('.dynamic_features_msg').slideUp(1000);
			jQuery('.dynamic_features').slideDown(1000);
		}
		return true;
		});
	});
	</script>
	
	<?php 
    if ($ops['ad_insertion_mode'] == 'direct_static') {
        ?>
	<div class="dynamic_features_msg">
	<?php 
    } else {
        ?>
	<div class="dynamic_features_msg" style="display:none">
	<?php 
    }
    ?>
	<div class="inside" style="margin:10px">
	<b><span style="font-size:10px;color:red;">Note: Dynamic features (restricting ad views by referrer and IP address) are only available in the mfunc, or direct dynamic modes.</span></b>
	</div>
	</div>
	
	<?php 
    if ($ops['ad_insertion_mode'] == 'direct_static') {
        ?>
	<script type="text/javascript">
	document.write('<style type="text/css" media="screen">#dynamic_features { display: none; }</style>');
	</script>
	<?php 
    }
    ?>
	<div id="dynamic_features" class="dynamic_features">
	
	<div class="inside" style="margin:10px">

	<h4><a name="dynamic"></a>Show ads only to search engine visitors (dynamic feature)</h4>
	
	<blockquote>
	<input type="checkbox" name="sevisitors_only" <?php 
    echo adinj_ticked('sevisitors_only');
    ?>
 /><?php 
    _e("Only show ads to search engine visitors (customise search engine referrers below if necessary).", 'adinj');
    ?>
<br />
	<textarea name="ad_referrers" rows="2" cols="70"><?php 
    echo $ops['ad_referrers'];
    ?>
</textarea>
	<p>Comma separated list e.g.: <br /><code>.google., .bing., .yahoo., .ask., search?, search., /search/</code></p>
	</blockquote>
	
	<h4>Blocked IP addresses (dynamic feature)</h4>
	
	<blockquote>
	<textarea name="blocked_ips" rows="4" cols="70"><?php 
    echo $ops['blocked_ips'];
    ?>
</textarea>
	<p>Comma separated list e.g.: <br /><code>0.0.0.1, 0.0.0.2</code></p>
	<p>Or you can list one IP per line with optional comments e.g.</p>
	<code style="padding:0px 0px">192.168.0.1<br />0.0.0.2<br /><?php 
    echo $_SERVER['REMOTE_ADDR'];
    ?>
 //my ip<br />0.0.0.3</code>
	
	<p>For reference your current IP address is <code><?php 
    echo $_SERVER['REMOTE_ADDR'];
    ?>
</code></p>
	</blockquote>
	</div>
	
	
	<h3>Recommended WP Super Cache settings:</h3>
	<div class="inside" style="margin:10px">

	<blockquote>
		<ul>
		<li>Cache hits to this website for quick access.</li>
		<li>Legacy page caching.</li>
		<li>Compress pages so they&#x2019;re served more quickly to visitors.</li>
		<li>Expire time: 36000 (10 hours). Or 3600 (1 hour) for very busy site.</li>
		</ul>
	</blockquote>
	
	<p>
	<?php 
    if (is_plugin_active('wp-super-cache/wp-cache.php')) {
        echo "Go to the WP Super Cache <a href='options-general.php?page=wpsupercache&amp;tab=settings'>advanced settings page</a> (where you can set the caching mode to Legacy).";
    } else {
        echo "Note: WP Super Cache does not appear to be active.";
    }
    ?>
	</p>
	</div>
	
	</div>
	
	<?php 
    adinj_postbox_end();
    ?>
	
	
	<?php 
    adinj_postbox_start(__("Debugging", 'adinj'), 'debugging');
    ?>
	
	<input type="checkbox" name="debug_mode" <?php 
    echo adinj_ticked('debug_mode');
    ?>
 />Enable debug mode
	
	<p>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.</p>
	
	<?php 
    if (adinj_problem_with_wpminify_check()) {
        echo adinj_get_problem_with_wpminify_message();
    }
    adinj_debug_information();
    ?>
	
	<p></p>
	
	<p>If you want to restore all settings (excluding the ad contents) to their default values use this button.</p>
	
	<input type="submit" name="adinj_action" value="<?php 
    _e('Reset to Default', 'adinj');
    ?>
" />
	
	<p>You can delete the database settings if you are going to uninstall Ad Injection.</p>
	
	<input type="submit" name="adinj_action" value="<?php 
    _e('Delete settings from DB', 'adinj');
    ?>
" />
	
	<?php 
    adinj_postbox_end();
    ?>


	<br clear="all" />
	
	<?php 
    adinj_docs();
    echo '</form>';
    echo '</div> <!--wrap-->';
}