Mercurial > defr > drupal > ad
comparison channel/ad_channel.inc @ 1:948362c2a207 ad
update advertisement
author | pierre |
---|---|
date | Thu, 02 Apr 2009 15:28:21 +0000 |
parents | |
children | e5584a19768b |
comparison
equal
deleted
inserted
replaced
0:d8a3998dac8e | 1:948362c2a207 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Ad Channel include file. | |
6 * | |
7 * Copyright (c) 2008-2009. | |
8 * Jeremy Andrews <jeremy@tag1consulting.com>. | |
9 */ | |
10 | |
11 /** | |
12 * Filter advertisements not in an appropriate channel, from cache. | |
13 */ | |
14 function ad_channel_cache_filter($ads) { | |
15 _debug_echo("ad_channel_cache: adserve_cache_filter"); | |
16 | |
17 $channels = adserve_cache('get_cache', 'channel'); | |
18 $valid = array(); | |
19 $nochannel = array(); | |
20 foreach ($ads as $aid) { | |
21 _debug_echo("ad_channel_cache: checking aid($aid)"); | |
22 if (is_array($channels['ads']) && isset($channels['ads'][$aid]) && | |
23 is_array($channels['ads'][$aid])) { | |
24 foreach ($channels['ads'][$aid] as $chid) { | |
25 $channel = $channels['channels'][$chid]; | |
26 $display = $channel->display; | |
27 $urls = unserialize($channel->urls); | |
28 $frontpage = adserve_variable('site_frontpage') ? adserve_variable('site_frontpage') : 'node'; | |
29 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote($frontpage, '/') .'\2'), preg_quote($urls, '/')) .')$/'; | |
30 $match = preg_match($regexp, adserve_variable('url')); | |
31 _debug_echo("ad_channel_cache: checking aid($aid) against channel($chid) path(". adserve_variable('url') .") regexp($regexp) match($match)"); | |
32 if ($display == 0) { // display on all except listed urls | |
33 if (empty($urls) || !$match) { | |
34 _debug_echo("ad_channel_cache: aid($aid) is valid"); | |
35 $valid[] = $aid; | |
36 break; | |
37 } | |
38 } | |
39 else { // display only on listed urls | |
40 if (!empty($urls) && $match) { | |
41 _debug_echo("ad_channel_cache: aid($aid) is valid"); | |
42 $valid[] = $aid; | |
43 break; | |
44 } | |
45 } | |
46 _debug_echo("ad_channel_cache: aid($aid) is not valid"); | |
47 } | |
48 } | |
49 else { | |
50 // no channel information for ad, it's valid | |
51 $display = $channels['display']; | |
52 _debug_echo("ad_channel_cache: aid($aid) has no channel info [$display]"); | |
53 switch ($display) { | |
54 case 0: | |
55 $nochannel[] = $aid; | |
56 _debug_echo("ad_channel_cache: aid($aid) is valid if no valid ads found in current channel"); | |
57 break; | |
58 case 1: | |
59 $valid[] = $aid; | |
60 _debug_echo("ad_channel_cache: aid($aid) is valid"); | |
61 break; | |
62 case 2: | |
63 _debug_echo("ad_channel_cache: aid($aid) is not valid"); | |
64 break; | |
65 } | |
66 } | |
67 } | |
68 | |
69 if (empty($valid) && !empty($nochannel)) { | |
70 _debug_echo("ad_channel_cache: using ads with no channel info"); | |
71 $valid = $nochannel; | |
72 } | |
73 | |
74 $premiere = adserve_cache('get_cache', 'premiere'); | |
75 $premieres = array(); | |
76 if (is_array($premiere)) { | |
77 foreach ($valid as $aid) { | |
78 if (in_array($aid, $premiere)) { | |
79 _debug_echo("ad_channel_cache: aid($aid) is premiere advertisement"); | |
80 $premieres[$aid] = $aid; | |
81 } | |
82 else { | |
83 _debug_echo("ad_channel_cache: aid($aid) is not a premiere advertisement"); | |
84 } | |
85 } | |
86 if (!empty($premieres)) { | |
87 _debug_echo("ad_channel_cache: returning premiere advertisements"); | |
88 return $premieres; | |
89 } | |
90 } | |
91 _debug_echo("ad_channel_cache: returning non-premiere advertisements"); | |
92 return $valid; | |
93 } |