get_ad($ad); } } /* INITIALISATION All functions in here called at startup (after other plugins have loaded, in case we need to wait for the widget-plugin). */ class adsensem { var $benice=true; function get_ad_inline($ad=false) { $options = get_option('plugin_adsensem'); if($ad===false){$ad=$options['ads'][$options['defaults']['ad']];} $ad=$this->merge_defaults($ad); //Apply defaults $code=''; /* This test block determines whether to display the Ad in the current location. The home,single,archive,search tests only apply to Ads displayed inline, so we test for that here */ if( ($ad['show-home'] && is_home()) || ($ad['show-post'] && (is_single() || is_page())) || ($ad['show-archive'] && is_archive()) || ($ad['show-search'] && is_search()) ) { /* We passed the test, display the Ad */ $code.=$this->get_ad($ad); } return $code; } function get_ad($ad=false) { $options = get_option('plugin_adsensem'); if($ad===false){$ad=$options['ads'][$options['defaults']['ad']];} $ad=$this->merge_defaults($ad); //Apply defaults $code=''; /* Valid entry */ if(is_array($ad)){ //Default to Ad if($ad['product']=='link'){ $format = $ad['linkformat'] . $ad['linktype']; list($width,$height,$null)=split('[x]',$ad['linkformat']); } else { $format = $ad['adformat'] . '_as'; list($width,$height,$null)=split('[x]',$ad['adformat']); } $code .= $ad['html-before']; if($_GET['preview']){ /* We are in the editor, output fake */ $code .= '
'; $code .= 'AdSense
#' . $ad['name'] . '
Block'; $code .= '
'; } else { $code .= '' . "\n"; $code.= '' . "\n"; } $code.=$ad['html-after']; } return $code; } /* ADMIN ELEMENTS - REUSABLE PAGE ELEMENTS FOR CONFIGURATION */ function set_defaults() { $options['ads'] = array(); $options['google-account']=""; $options['be-nice']=ADSENSEM_BE_NICE; $options['defaults'] = array ( 'colors' => array( 'border'=> 'FFFFFF', 'link' => '0000FF', 'bg' => 'FFFFFF', 'text' => '000000', 'url' => '008000' ), 'channel' => '', 'adformat' => '250x250', 'adtype' => 'text_image', 'linkformat' => '120x90', 'linktype' => '_0ads_al_s', 'show-home' => true, 'show-post' => true, 'show-archive' => true, 'show-search' => true ); update_option('plugin_adsensem', $options); } /* MERGE DEFAULTS - Merge in default settings to fill gaps in Ad setup */ function merge_defaults($settings) { $options = get_option('plugin_adsensem'); if(is_array($options['defaults'])){ foreach($options['defaults'] as $key=>$value) { if($settings[$key]==''){$settings[$key]=$value;} } } if(is_array($options['defaults']['colors'])){ foreach($options['defaults']['colors'] as $key=>$value){ if($settings['colors'][$key]==''){$settings['colors'][$key]=$value;} } } return $settings; } function output_select($list,$selected) { foreach($list as $key=>$value) { ?>array()),$name=false) { $colors = $settings['colors']; // $options = get_option('plugin_adsensem'); // $defaults = $options['defaults']; if($settings['product']==''){$settings['product']='ad';} ?>
'Use Default'); $formats['ads']['horizontal']=array('728x90' => '728 x 90 Leaderboard', '468x60' => '468 x 60 Banner', '234x60' => '234 x 60 Half Banner'); $formats['ads']['vertical']=array('120x600' => '120 x 600 Skyscraper', '160x600' => '160 x 600 Wide Skyscraper', '120x240' => '120 x 240 Vertical Banner'); $formats['ads']['square']=array('336x280' => '336 x 280 Large Rectangle', '300x250' => '300 x 250 Medium Rectangle', '250x250' => '250 x 250 Square', '200x200' => '200 x 200 Small Square', '180x150' => '180 x 150 Small Rectangle', '125x125' => '125 x 125 Button'); $formats['links']['horizontal']=array('728x15' => '728 x 15', '468x15' => '468 x 15'); $formats['links']['square']=array('200x90' => '200 x 90', '180x90' => '180 x 90', '160x90' => '160 x 90', '120x90' => '120 x 90'); $adtypes=array('text_image' => 'Text & Image', 'image' => 'Image Only', 'text' => 'Text Only'); $linktypes=array('_0ads_al' => '4 Ads Per Unit', '_0ads_al_s' => '5 Ads Per Unit'); $yesno=array(true => 'Yes', false => 'No'); $default=array('' => 'Use Default'); $products=array('ad' => 'Ad Unit','link' => 'Link Unit'); ?>

Basic

Layout

Ad Colours

#
#
#
#
#
merge_defaults($settings); $colors = $temp['colors']; } else { $colors = $settings['colors']; } ?>
Advertiser's ad text here
www.advertiser-url.com
 Ads by Google

Inline Ads

HTML Markup (Optional)

AdSense Manager Options

Configure your basic settings here, such as default colours & Google account settings. Once you have set up the basics, click Save » to save changes, then go to Manage » Ads to create your Ad blocks.

Basic Setup

Enter your : ">
You can find this number at the bottom of your Account Settings page.

Please Be Nice and donate more than Thankyou for Being Nice and continuing to donate % of your Ad space to support development of this plugin. It didn't write itself.

admin_save_settings($options['defaults']); } else { $name=sanitize_title($_POST['adsensem-name']); /* Changing the name of an Ad, copy and delete old */ if($_POST['adsensem-name']!=$_POST['adsensem-name-old']){ $options['ads'][$name]=$options['ads'][$_POST['adsensem-name-old']]; unset($options['ads'][$_POST['adsensem-name-old']]); /* We can now use the new $name from this point forward, lovely */ /* Update default if neccessary */ if($options['defaults']['ad']==$_POST['adsensem-name-old']){$options['defaults']['ad']=$name;} } $options['ads'][$name]=$this->admin_save_settings($options['ads'][$name]); } update_option('plugin_adsensem', $options); } if ( $_POST['adsensem-delete'] ) { //Delete selected advert if($_POST['adsensem-delete-name']!=$options['defaults']['ad']){ unset($options['ads'][$_POST['adsensem-delete-name']]); update_option('plugin_adsensem', $options); } } if ( $_POST['adsensem-default'] ) { //Set selected advert as default $options['defaults']['ad']=$_POST['adsensem-default-name']; update_option('plugin_adsensem', $options); } if($options['defaults']['ad']==''){$options['defaults']['ad']=key($options['ads']);} ?>

Manage Ads

Below are your currently created Ads. Remember to set your Google Adsense ID at Options » AdSense Manager

$ad) { ?>style="background-color:#eee;">
NameChannelProductColoursFormatAdmin
Default Settings          
          Default Ad
None.

By changing the Default settings (shown on the top line) you can update all Ads at once.
Default Ad indicates which Ad will be displayed when no specific ID is used.



Edit ''

Edit the settings for your Ad below. If you want to use the default settings for any element, simply leave that section unchanged.

admin_settingsform($options['ads'][$_POST['adsensem-edit-name']],$_POST['adsensem-edit-name']); } else { $this->admin_settingsform($options['defaults'],false); } ?>

Create New

Enter the settings for your new Ad below. If you want to use the default settings for any element, simply leave that section unchanged.

admin_settingsform(null,''); ?>

get_ad($options['ads'][$n]); //Output the selected ad echo $after_widget; } /* Widget admin block for each Ad element on the page, allows movement of them around the sidebar */ function widget_control($name) { $options = get_option('plugin_adsensem'); if ( $_POST['adsensem-' . $name . '-submit'] ) { // Remember to sanitize and format use input appropriately. $options['ads'][$name]['title'] = strip_tags(stripslashes($_POST['adsensem-' . $name . '-title'])); update_option('plugin_adsensem', $options); } ?> $ad){ $widget=array('Ad #%s', '', $name); register_sidebar_widget($widget, array(&$this,'widget'),$name); register_widget_control($widget, array(&$this,'widget_control'), 300, 80, $name); } } } } /* This filter parses post content and replaces markup with the correct ad, for named ad or for default */ function filter_ads($content) { $options = get_option('plugin_adsensem'); if(is_array($options['ads'])){ //Insert default ad first $content=str_replace("",$this->get_ad_inline(),$content); foreach($options['ads'] as $name=>$ad) { $content = str_replace("", $this->get_ad_inline($ad), $content); } } return $content; } /* Editor functions */ /* Add button to simple editor to include AdSense code */ function admin_callback_editor() { $options = get_option('plugin_adsensem'); //Editor page, so we need to output this editor button code if(strpos($_SERVER['REQUEST_URI'], 'post.php') || strpos($_SERVER['REQUEST_URI'], 'page-new.php') || strpos($_SERVER['REQUEST_URI'], 'bookmarklet.php')) { ?> set_defaults();} $this->benice = (rand(1,100)<=$options['be-nice']); add_action('admin_menu', array(&$this,'admin_add_pages')); add_filter('the_content', array(&$this,'filter_ads')); add_action('admin_footer', array(&$this,'admin_callback_editor')); /* Add the blocks to the Widget panel for positioning */ if (function_exists('register_sidebar_widget') ) { /* Loop through available ads and generate widget one at a time */ if(is_array($options['ads'])){ foreach($options['ads'] as $name => $ad){ $widget=array('Ad #%s', '', $name); register_sidebar_widget($widget, array(&$this,'widget'), $name); register_widget_control($widget, array(&$this,'widget_control'), 300, 80, $name); } } } } } $adsensem = new adsensem(); // Run our code later in case this loads prior to any required plugins. add_action('plugins_loaded', array(&$adsensem,'init')); ?>