$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; global $wp_version; //if ($wp_version=="2.6"){ // // 2.6 fix, this version unserializes data for some odd reason. // $options = get_option($pluginname . "_options"); // $stats = get_option($pluginname . "_stats"); //}else{ $options = maybe_unserialize(get_option($pluginname . "_options")); $stats = get_option($pluginname . "_stats"); if(!is_array($stats)) $stats = array(); //} if(isset($allocation)){ // Get the weighted ad // Get Counts for Served Ads //echo "

Allocations for $campaign


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

Serving a sponsor ad


"; ServeAd(); $stats['stats']['sponsor']['weight'] = 0; $stats['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($stats['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'])){ foreach($stats['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){ ServeAd($allocation['ads'][$j]['advertisement']); $stats['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'][$j]++; $served = true; break; } } if(!$served){ // Reset weights and serve first foreach($stats['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'] as $j => $weight){ $stats['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'][$j] = 0; } ServeAd($allocation['ads'][0]['advertisement']); $stats['stats']['adcampaigns'][$campaign]['allocations'][$index]['sourceweights'][0]++; } $stats['stats']['sponsor']['weight']++; } } }else if(isset($options['settings']['fillEmptyAllocations']) && $options['settings']['fillEmptyAllocations']){ ServeAd($options['settings']['defaultsource']); } update_option($pluginname . "_stats", $stats); } } 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 = maybe_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; } } } }