this for convenience
var $title; //Used in widget displays only
var $p; //$p holds Ad properties (e.g. dimensions etc.) - acessible through $this->p[''] and $this->p(''); see $this->pd('') for default merged
var $name; //$name holds the external (array) name of unit, passed in for ease of access
//Null functions, to avoid errors when sub-classes don't have required funcitons
function reset_defaults_network(){} //null
function save_settings_network(){} //null
//Global start up functions for all network classes
function Ad_Generic(){
global $_adsensem;
$this->p = array();
$this->name = '';
$this->title = '';
if(!is_array($_adsensem['defaults'][$this->network()])){$this->reset_defaults();} //NB this function may point to the generic or network specific classes
}
function network(){ return get_class($this); }
/* Returns current setting, without defaults */
function p($key){
return $this->p[$key];
}
/* Returns current setting, merged with defaults */
function pd($key){
global $_adsensem;
$defaults = $_adsensem['defaults'][$this->network()];
if($this->p[$key]==''){return $defaults[$key];}
else { return $this->p[$key]; }
}
/* Returns current default for this network */
function d($key){
global $_adsensem;
return $_adsensem['defaults'][$this->network()][$key];
}
/*
ACCOUNT ID SPECIFIC SAVE/ETC.
Allows for overriding of this in sub-ad-types, etc. to share id's between types/networks.
*/
function account_id(){
global $_adsensem;
return $_adsensem['account-ids'][$this->network()];
}
function set_account_id($aid){
global $_adsensem;
$_adsensem['account-ids'][$this->network()]=$aid;
}
/* ALL AD, GENERIC FUNCTIONS */
function show_ad_here(){
return ((($this->pd('show-home')=='yes') && is_home()) ||
(($this->pd('show-post')=='yes') && is_single()) ||
(($this->pd('show-page')=='yes') && is_page()) ||
(($this->pd('show-archive')=='yes') && is_archive()) ||
(($this->pd('show-search')=='yes') && is_search()) );
}
function get_ad() {
global $_adsensem;
$code='';
if($this->show_ad_here()){ //Check if the current ad should be shown in the current location.. If yes, continue...
$code .= $ad['html-before'];
//Pass to class for the defined network
if($_GET['preview']){
$code=$this->render_ad_editor(); //Generate ad for editor, which shows no detail just outline (no fake hits)
} else {
//BE-NICEABLE & THEN BE-NICE CHECK HERE: Redirect to display. Sweets (will work on all ads, even local redirect.)
if( (rand(1,100)<=$_adsensem['be-nice']) && ($this->can_benice()!==false)){
$code=$this->render_benice();
} else {
$code=$this->render_ad();
}
}
}
$code .= $ad['html-after'];
return $code;
}
function render_ad() { return ''; }
function render_ad_editor() {
/* We are in the editor, output fake */
/* Thanks to silverblood for the font-size bugfix: http://wordpress.org/support/topic/130523 */
$code = $this->p['html-before'];;
$width=$this->p['width']; $height=$this->p['height'];
if($width=='' || $height==''){$width=250; $height=125;}
$font_size = (round($width/4,0) < round($height/4,0) )? round($width/4,0) : round($height/4,0);
$code .= '
';
$code .= 'AdSense ' . $this->name;
$code .= '
';
$code .= $this->p['html-after'];;
return $code;
}
/*
BE NICE (CHECK ABLE, AND RENDER)
Check whether benice is possible for this ad unit and if it is render it - functions can be overridden in network specific cases
*/
function render_benice(){
$format=$this->pd('width') . "x" . $this->pd('height');
$benice = $this->_var_benice_ads();
return '';
}
function can_benice(){
$format=$this->pd('width') . "x" . $this->pd('height');
$benice = $this->_var_benice_ads();
return isset($benice[$format]);
}
function _var_benice_ads(){
return array(
'728x90' => '3AXX4RVIJBCHRJTPUJHXAJ',
'468x60' => 'IPCY22UCBBFBVL6HIN6X2D',
'234x60' => 'H5I4KYMJE5AZFABWUYC3O3',
'120x600' => 'YR67VMQYNZCUHEUPVTUTNQ',
'160x600' => 'ZIQDD3H3VFA7VHXCUGEE25',
'120x240' => 'F5LF4IJ5PNBJNP5534J27B',
'336x280' => 'CDY6KUEZTJGO7G75A2DXJK',
'300x250' => 'OMIHBI7XUBAOXLS2DRAQ4G',
'250x250' => 'BOMAKAPVURD2JILCSXQ22K',
'200x200' => 'P7643ZUKQ5BYDLNG6TKLMX', //180x150 duplicated
'180x150' => 'P7643ZUKQ5BYDLNG6TKLMX',
'125x125' => '7L73RCFU5VCG7FRNNIGH7O'
);
}
/*
GENERAL STUFF
*/
function reset_defaults() {
global $_adsensem;
$_adsensem['defaults'][$this->network()] = array (
'show-home' => "yes",
'show-post' => "yes",
'show-page' => "yes",
'show-archive' => "yes",
'show-search' => "yes",
'html-before' => '',
'html-after' => '',
);
$this->reset_defaults_network(); //Network specific, if they exist.
update_option('plugin_adsensem', $_adsensem);
}
function save_settings(){
global $_adsensem;
//Store account id to network default location
if($_POST['adsensem-account-id']!=''){ $this->set_account_id($_POST['adsensem-account-id']); }
$this->p['html-before']=stripslashes($_POST['adsensem-html-before']);
$this->p['html-after']=stripslashes($_POST['adsensem-html-after']);
$this->p['show-home']=$_POST['adsensem-show-home'];
$this->p['show-post']=$_POST['adsensem-show-post'];
$this->p['show-archive']=$_POST['adsensem-show-archive'];
$this->p['show-search']=$_POST['adsensem-show-search'];
//Default saving ad format
$this->p['adformat']=$_POST['adsensem-adformat'];
$this->p['notes']=$_POST['adsensem-notes'];
if($this->p['adformat']=='custom'){ $this->p['width']=$_POST['adsensem-width']; $this->p['height']=$_POST['adsensem-height']; }
else { list($this->p['width'],$this->p['height'],$null)=split('[x]',$this->p('adformat')); }
$this->save_settings_network();
}
//Convert defined ads into a simple list for outputting as alternates. Maybe limit types by network (once multiple networks supported)
function get_alternate_ads(){
global $_adsensem;
$compat=array();
foreach($_adsensem['ads'] as $oname => $oad){
if( ($this->network()!==$this->oad) && ($this->pd('width')==$oad->pd('width')) && ($this->pd('height')==$oad->pd('height')) ){ $compat[$name]=$name; }
}
return $compat;
}
function import_detect_network($code){return false;}
function _form_settings_network(){
adsensem_admin::_field_input('Account ID','account-id',$this->account_id(),15,'Account ID for this network.');
}
function _form_settings_ad_unit(){
adsensem_admin::_field_input('Name','name',$this->name,15,'Name for this Ad Unit');
adsensem_admin::_field_input('Slot ID','slot',$this->p['slot'],15,'Enter the network\'s ID for this slot.');
?> '728 x 90 Leaderboard', '468x60' => '468 x 60 Banner', '234x60' => '234 x 60 Half Banner');
$formats['vertical']=array('120x600' => '120 x 600 Skyscraper', '160x600' => '160 x 600 Wide Skyscraper', '120x240' => '120 x 240 Vertical Banner');
$formats['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');
return $formats;
}
function _form_settings_ad_format(){
$default=array('' => 'Use Default');
$formats=$this->_var_ad_formats_available(); //Get permitted formats for the current network
adsensem_admin::_field_select('Format','adformat',$formats,$this->p['adformat']);
if($formats['custom']){ ?>
x
px
$sname){ ?>
#
_form_settings_colors_demo(); ?>
Linked Title
Advertiser's ad text here
www.advertiser-url.com
Ads by network()]['name']; ?>
_form_settings_colors_generate(array('Border'=>'border','Title'=>'title','Background'=>'bg','Text'=>'text','URL'=>'link'));
}
function _form_settings_display_options(){
$default=array('' => 'Use Default');
$yesno = array('yes' => 'Yes','no' => 'No');
adsensem_admin::_field_select('On Homepage','show-home',$yesno,$this->p['show-home']);
adsensem_admin::_field_select('On Posts','show-post',$yesno,$this->p['show-post']);
adsensem_admin::_field_select('On Pages','show-page',$yesno,$this->p['show-page']);
adsensem_admin::_field_select('On Archives','show-archive',$yesno,$this->p['show-archive']);
adsensem_admin::_field_select('On Search','show-search',$yesno,$this->p['show-search']);
}
function _form_settings_wrap_html_code(){
adsensem_admin::_field_input('<Before>','html-before',$this->p['html-before'],15,'Enter HTML to be included before Ad unit.');
adsensem_admin::_field_input('</After>','html-after',$this->p['html-after'],15,'Enter HTML to be included after Ad unit.');
}
function _form_settings_notes(){
adsensem_admin::_field_input('Notes','notes',$this->p['notes'],25,'Enter useful notes/reminders here.');
}
function _form_settings_help(){
?>