Array ( [ad-1] => Ad_AdSense Object ( [title] => [p] => Array ( [html-before] => [html-after] => [show-home] => [show-post] => [show-page] => [show-archive] => [show-search] => [adformat] => => [notes] => 160x90, created 4/16/08 5 Link for side bar [height] => [width] => [slot] => 6983861882 [adtype] => link ) [name] => ad-1 ) [ad-2] => Ad_AdSense Object ( [title] => [p] => Array ( [html-before] => [html-after] => [show-home] => [show-post] => [show-page] => [show-archive] => [show-search] => [adformat] => => [notes] => 160x90, created 4/16/08 5 Link for side bar [height] => [width] => [slot] => 6983861882 [adtype] => link ) [name] => ad-2 ) [co-1] => Ad_Code Object ( [title] => [p] => Array ( [html-before] => [html-after] => [show-home] => [show-post] => [show-page] => [show-archive] => [show-search] => [adformat] => => [notes] => [height] => [width] => ) [name] => co-1 ) ) [defaults] => Array ( [ad_adsense] => Array ( [html-before] => [html-after] => [show-home] => yes [show-post] => yes [show-page] => yes [show-archive] => yes [show-search] => yes [adformat] => 120x240 => [notes] => 120x240, created 4/15/08 [height] => 240 [width] => 120 [slot] => [adtype] => ad ) [ad_adsense_classic] => Array ( [show-home] => yes [show-post] => yes [show-page] => yes [show-archive] => yes [show-search] => yes [html-before] => [html-after] => [color-border] => FFFFFF [color-title] => 0000FF [color-bg] => FFFFFF [color-text] => 000000 [color-link] => 008000 [channel] => [uistyle] => [slot] => [adformat] => 250x250 [adtype] => text_image [linkformat] => 120x90 [linktype] => _0ads_al_s ) [ad_code] => Array ( [show-home] => yes [show-post] => yes [show-page] => yes [show-archive] => yes [show-search] => yes [html-before] => [html-after] => ) ) [account-ids] => Array ( [ad_adsense] => 3904618150325763 ) [be-nice] => 3 [version] => 3.2.11 [default-ad] => ad-1 )
/*
STANDARD OUTPUT FUNCTIONS
These are out of the main function block below so they can be called
from outside "widget-space". This means we can re-use code for widget
and non-widget versions
*/
//Kept external for backward compatibility
if(!function_exists('adsensem_ad')) {
function adsensem_ad($name=false) {
global $_adsensem;
if($name===false)
{$ad=$_adsensem['ads'][$_adsensem['default-ad']];}
else
{$ad=$_adsensem['ads'][$name];}
if(is_object($ad)){
if($ad->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'));
}
}
function init_admin(){
//Pull in the admin functions before triggering
require_once('class-admin.php');
adsensem_admin::init_admin();
}
function setup_is_valid(){ //Check we have ads, (removed default-ad checks as causes problems where is not set, not essential.
global $_adsensem;
if(is_array($_adsensem)){
if(is_array($_adsensem['ads'])){
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') )
{
/* Default Ad widget */
if(is_object($_adsensem['ads'][$_adsensem['default-ad']])){ 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);
adsensem::register_widget($name,$args);
}
}
}
}
function register_widget($name,$args){
if(function_exists('wp_register_sidebar_widget')){
//$id, $name, $output_callback, $options = array()
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;
//If name not passed in (Sidebar Modules), extract from the widget-id (WordPress Widgets)
if($n==''){ $n=substr($args['widget_id'],9); } //Chop off beginning adsensem- bit
if($n!=='default-ad'){$ad = $_adsensem['ads'][$n];} else {$ad = $_adsensem['ads'][$_adsensem['default-ad']];}
if($ad->show_ad_here()){
echo $before_widget;
if($ad->title!=''){ echo $before_title . $ad->title . $after_title; }
echo $ad->get_ad(); //Output the selected ad
echo $after_widget;
$ad->counter_click();
}
}
/* 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);
}
?>
<label for="adsensem--title" >Title:<input style="width: 200px;" id="adsensem--title" name="adsensem--title" type="text" value="title, ENT_QUOTES);?>" />
<input type="hidden" name="adsensem--submit" value="1">
<!-- AdSense Manager v ( seconds.) -->show_ad_here()){
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("//","//","/\[ad\]/"),array('adsensem','filter_ad_callback'),$content);
}
$content=preg_replace_callback(array("//","//","/\[ad#(.*)\]/"),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('admin_menu', array('adsensem','init_admin'));
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');
?>
Watch videos at Vodpod and other videos from this collection.