Mercurial > defr > drupal > ad
diff channel/ad_channel.inc @ 1:948362c2a207 ad
update advertisement
author | pierre |
---|---|
date | Thu, 02 Apr 2009 15:28:21 +0000 |
parents | |
children | e5584a19768b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/channel/ad_channel.inc Thu Apr 02 15:28:21 2009 +0000 @@ -0,0 +1,93 @@ +<?php + +/** + * @file + * Ad Channel include file. + * + * Copyright (c) 2008-2009. + * Jeremy Andrews <jeremy@tag1consulting.com>. + */ + +/** + * Filter advertisements not in an appropriate channel, from cache. + */ +function ad_channel_cache_filter($ads) { + _debug_echo("ad_channel_cache: adserve_cache_filter"); + + $channels = adserve_cache('get_cache', 'channel'); + $valid = array(); + $nochannel = array(); + foreach ($ads as $aid) { + _debug_echo("ad_channel_cache: checking aid($aid)"); + if (is_array($channels['ads']) && isset($channels['ads'][$aid]) && + is_array($channels['ads'][$aid])) { + foreach ($channels['ads'][$aid] as $chid) { + $channel = $channels['channels'][$chid]; + $display = $channel->display; + $urls = unserialize($channel->urls); + $frontpage = adserve_variable('site_frontpage') ? adserve_variable('site_frontpage') : 'node'; + $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote($frontpage, '/') .'\2'), preg_quote($urls, '/')) .')$/'; + $match = preg_match($regexp, adserve_variable('url')); + _debug_echo("ad_channel_cache: checking aid($aid) against channel($chid) path(". adserve_variable('url') .") regexp($regexp) match($match)"); + if ($display == 0) { // display on all except listed urls + if (empty($urls) || !$match) { + _debug_echo("ad_channel_cache: aid($aid) is valid"); + $valid[] = $aid; + break; + } + } + else { // display only on listed urls + if (!empty($urls) && $match) { + _debug_echo("ad_channel_cache: aid($aid) is valid"); + $valid[] = $aid; + break; + } + } + _debug_echo("ad_channel_cache: aid($aid) is not valid"); + } + } + else { + // no channel information for ad, it's valid + $display = $channels['display']; + _debug_echo("ad_channel_cache: aid($aid) has no channel info [$display]"); + switch ($display) { + case 0: + $nochannel[] = $aid; + _debug_echo("ad_channel_cache: aid($aid) is valid if no valid ads found in current channel"); + break; + case 1: + $valid[] = $aid; + _debug_echo("ad_channel_cache: aid($aid) is valid"); + break; + case 2: + _debug_echo("ad_channel_cache: aid($aid) is not valid"); + break; + } + } + } + + if (empty($valid) && !empty($nochannel)) { + _debug_echo("ad_channel_cache: using ads with no channel info"); + $valid = $nochannel; + } + + $premiere = adserve_cache('get_cache', 'premiere'); + $premieres = array(); + if (is_array($premiere)) { + foreach ($valid as $aid) { + if (in_array($aid, $premiere)) { + _debug_echo("ad_channel_cache: aid($aid) is premiere advertisement"); + $premieres[$aid] = $aid; + } + else { + _debug_echo("ad_channel_cache: aid($aid) is not a premiere advertisement"); + } + } + if (!empty($premieres)) { + _debug_echo("ad_channel_cache: returning premiere advertisements"); + return $premieres; + } + } + _debug_echo("ad_channel_cache: returning non-premiere advertisements"); + return $valid; +}