$rule){ $func = "VerifyRule_" . $rule['type']; if(!function_exists($func) || !call_user_func($func, $rule)){ return false; } } return true; } return true; } return false; } } if(!function_exists('VerifyAllocation')){ function VerifyAllocation($allocation){ if(isset($allocation)){ if(isset($allocation['rulesets'])){ foreach($allocation['rulesets'] as $id => $set){ if(VerifyRuleset($set)){ return true; } } return false; } return true; } return false; } } if(!function_exists('AllocateAd')){ function AllocateAd($campaign, $index, $allocation){ global $pluginname; if ($wp_version=="2.6"){ // 2.6 fix, this version unserializes data for some odd reason. $options = get_option($name . "_options"); }else{ $options = unserialize(get_option($pluginname . "_options")); } if(isset($allocation)){ // Get the weighted ad // Get Counts for Served Ads //echo "

Allocations for $campaign


"; if($options['stats']['sponsor']['weight'] >= 20){ // Serve Sponsor Add //echo "

Serving a sponsor ad


"; ServeAd(); $options['stats']['sponsor']['weight'] = 0; $options['stats']['sponsor']['total'] = 0; /** @todo rotate stats (today, yesterday, this week, last week, this month, last month, all time */ }else{ // Serve one of the ad source ads $served = false; if(isset($options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'])){ foreach($options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'] as $j => $weight){ $w = isset($allocation['ads'][$j]['percent-weight'])?$allocation['ads'][$j]['percent-weight']:$allocation['ads'][$j]['weight']; if($weight < $w){ //Serve the add //echo "

Serving a " . $allocation['ads'][$j]['advertisement'] . " ad


"; ServeAd($allocation['ads'][$j]['advertisement']); $options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'][$j]++; $served = true; break; } } if(!$served){ // Reset weights and serve first foreach($options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'] as $j => $weight){ $options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'][$j] = 0; } //echo "

Serving a " . $allocation['ads'][0]['advertisement'] . " ad


"; ServeAd($allocation['ads'][0]['advertisement']); $options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'][0]++; } $options['stats']['sponsor']['weight']++; } } foreach($options['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'] as $j => $weight){ $w = isset($allocation['ads'][$j]['percent-weight'])?$allocation['ads'][$j]['percent-weight']:$allocation['ads'][$j]['weight']; //echo "

" . $campaign. "[$index] - " . $allocation['ads'][$j]['advertisement'] . " allocated $weight of $w


"; } //echo "

Sponsor ads at " . $options['stats']['sponsor']['weight'] . " of 20


"; }else if(isset($options['settings']['fillEmptyAllocations']) && $options['settings']['fillEmptyAllocations']){ ServeAd($options['settings']['defaultsource']); } // else no add allocated update_option($pluginname . "_options", serialize($options)); } } if(!function_exists('ServeAd')){ require_once('AdsenseStats.php'); function ServeAd($ad = null){ global $pluginname; global $pluginversion; if(is_null($ad)){ $adserv = "http://www.mobilesentience.com/ads/WordpressPlugins&plugin=" . $pluginname . "&pluginversion=" . $pluginversion; echo ''; }else if(strpos($ad, 'adsense-') === 0){ $adsense = new AdsenseStats(); $unit = $adsense->GetAdUnit(substr($ad, 8)); echo html_entity_decode($unit['code']); }else{ if ($wp_version=="2.6"){ // 2.6 fix, this version unserializes data for some odd reason. $options = get_option($pluginname . "_options"); }else{ $options = unserialize(get_option($pluginname . "_options")); } $source = $options['adsources'][$ad]; switch($source['adtype']){ case 'url': if($source['wrap_url']){ echo ''; }else{ echo $source['url']; } break; case 'inline': echo html_entity_decode($source['code']); break; } } } }