function ad_cache_file_id in Advertisement 5.2
Same name and namespace in other branches
- 6.3 cache/file/ad_cache_file.inc \ad_cache_file_id()
- 6.2 cache/file/ad_cache_file.inc \ad_cache_file_id()
- 7 cache/file/ad_cache_file.inc \ad_cache_file_id()
Return an array of aids to choose an advertisement from.
File
- cache/
file/ ad_cache_file.inc, line 74 - A plug in for the ad.module, providing a file cache mechanism for improved performance when displaying ads.
Code
function ad_cache_file_id($type, $id, $hostid) {
$cache = ad_cache_file_cache();
_debug_echo("File cache: ad_cache_file_id type({$type}) id({$id}) hostid({$hostid})");
switch ($type) {
case 'host':
if (isset($cache['hostid'][$hostid]['aids'])) {
return $cache['hostid'][$hostid]['aids'];
}
break;
case 'nids':
return explode(',', $id);
case 'tids':
if (!isset($cache['tids'][$id])) {
$cache['tids'][$id] = array();
$tids = explode(',', $id);
foreach ($tids as $tid) {
if (is_array($cache['tid'][$tid]['aid'])) {
$cache['tids'][$id] += $cache['tid'][$tid]['aid'];
}
}
// rebuild keys from 0, cache for re-use on next ad display
$cache['tids'][$id] = array_values($cache['tids'][$id]);
// update cache
ad_cache_file_cache($cache);
}
return $cache['tids'][$id];
case 'default':
return $cache['tid'][0]['aid'];
default:
_debug_echo("File cache: unkown id type '{$type}'.");
break;
}
}