show_ad_here()){ echo $ad->get_ad(); $ad->counter_click(); } } } /* 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 { //STARTUP INITIALISATION function init(){ global $_adsensem; //Only run main site code if setup & functional if(adsensem::setup_is_valid()){ add_filter('the_content', array('adsensem','filter_ads')); add_action('wp_footer', array('adsensem','footer')); } add_action('admin_menu', array('adsensem_admin','init_admin')); add_action('admin_head', array('adsensem_admin','add_header_script')); add_action('admin_footer', array('adsensem_admin','admin_callback_editor')); } function setup_is_valid(){ global $_adsensem; if(is_array($_adsensem)){ if(is_array($_adsensem['ads'])){ if(is_object($_adsensem['ads'][$_adsensem['default-ad']])){ return true; } } } return false; } function init_widgets() { global $_adsensem; /* SITE SECTION: WIDGET DISPLAY CODE /* Add the blocks to the Widget panel for positioning WP2.2+*/ if (function_exists('wp_register_sidebar_widget') || function_exists('register_sidebar_module') ) { /* Create Ad Unit for the 'Default Ad' */ //$args = array('name' => 'default-ad', 'height' => 80, 'width' => 300); //adsensem::register_widget('default-ad',$args); /* Loop through available ads and generate widget one at a time */ if(is_array($_adsensem['ads'])){ foreach($_adsensem['ads'] as $name => $ad){ $args = array('name' => $name, 'height' => 80, 'width' => 300); //$id, $name, $output_callback, $_adsensem = array() adsensem::register_widget($name,$args); } } } } function register_widget($name,$args){ if(function_exists('wp_register_sidebar_widget')){ wp_register_sidebar_widget('adsensem-' . $name,'Ad #' . $name, array('adsensem','widget'), $args, $name); wp_register_widget_control('adsensem-' . $name,'Ad #' . $name, array('adsensem','widget_control'), $args, $name); } else if (function_exists('register_sidebar_module') ){ register_sidebar_module('Ad #' . $name, 'adsensem_sbm_widget', 'adsensem-' . $name, $args ); register_sidebar_module_control('Ad #' . $name, array('adsensem','widget_control'), 'adsensem-' . $name); } } // This is the function that outputs adsensem widget. function widget($args,$n) { // $args is an array of strings that help widgets to conform to // the active theme: before_widget, before_title, after_widget, // and after_title are the array keys. Default tags: li and h2. extract($args); //nb. $name comes out of this, hence the use of $n global $_adsensem; // Each widget can store its own options. We keep strings here. if($n){$ad = $_adsensem['ads'][$n];} else {$ad = $_adsensem['ads'][$_adsensem['default-ad']];} if($ad->show_ad_here()){ $ad->counter_click(); echo $before_widget; if($ad->title!=''){ echo $before_title . $ad->title . $after_title; } echo $ad->get_ad(); //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) { global $_adsensem; if ( $_POST['adsensem-' . $name . '-submit'] ) { global $_adsensem; // Remember to sanitize and format use input appropriately. $_adsensem['ads'][$name]->title = strip_tags(stripslashes($_POST['adsensem-' . $name . '-title'])); update_option('plugin_adsensem', $_adsensem); } ?> show_ad_here()){ $ad->counter_click(); return $ad->get_ad(); } } return ''; } /* This filter parses post content and replaces markup with the correct ad, for named ad or for default */ function filter_ads($content) { global $_adsensem; if(is_object($_adsensem['ads'][$_adsensem['default-ad']])){ $content=preg_replace_callback(array("//","//"),array('adsensem','filter_ad_callback'),$content); $content=preg_replace_callback(array("//","//"),array('adsensem','filter_ad_callback'),$content); } return $content; } } /* SHOW ALTERNATE AD UNITS */ if ($_REQUEST['adsensem-show-ad']){ ?>options['name']); } /* SIDEBAR MODULES COMPATIBILITY FUNCTION */ add_action('plugins_loaded', array('adsensem','init'), 1); add_action('widgets_init', array('adsensem','init_widgets'), 1); function kda_mce_callback(){ // echo " handle_event_callback : \"scheduleScan\",\n"; } add_action('mce_options', 'kda_mce_callback'); ?>