function _ad_build_cache in Advertisement 6
Same name and namespace in other branches
- 5.2 cache/file/ad_cache_file.module \_ad_build_cache()
- 5 cache/file/ad_cache_file.module \_ad_build_cache()
- 6.3 cache/file/ad_cache_file.module \_ad_build_cache()
- 6.2 cache/file/ad_cache_file.module \_ad_build_cache()
- 7 cache/file/ad_cache_file.module \_ad_build_cache()
Returns the cache structure:
// The ad html. $cache['ad'][$aid]['display'] = $ad // Impressions counter. $cache['ad'][$aid][$hostid]['view'] // Ad type. $cache['ad'][$aid]['adtype'] = $adtype // Synchronization timestamp. $cache['last_sync'] = $timestamp
// Owner ID index. $cache['uid'][$uid]['aid'][] = $aid $cache['ad'][$aid]['uid'][] = $uid; // Host ID index. $cache['uid'][$uid]['hostid'] = $hostid
1 call to _ad_build_cache()
- ad_cache_file_build in cache/
file/ ad_cache_file.module - Build all required cache files when using the file cache.
File
- cache/
file/ ad_cache_file.module, line 183 - A plug in for the ad.module, providing a file cache mechanism for improved performance when displaying ads.
Code
function _ad_build_cache() {
$cache = array();
$result = db_query("SELECT aid FROM {ads} WHERE adstatus = 'active' OR adstatus = 'approved' OR adstatus = 'offline'");
while ($ad = db_fetch_object($result)) {
$node = node_load($ad->aid);
// Ad information.
$cache['ad'][$ad->aid]['display'] = module_invoke("ad_{$node->adtype}", 'display_ad', $node);
$cache['ad'][$ad->aid]['adtype'] = $node->adtype;
$cache['ad']['aid'][] = $node->aid;
// Owner indexes.
// TODO: Disable this query if ad_remote isn't enabled?
$owners = db_query('SELECT o.uid, h.hostid FROM {ad_owners} o LEFT JOIN {ad_hosts} h ON o.uid = h.uid WHERE aid = %d', $ad->aid);
$counter = 0;
while ($owner = db_fetch_object($owners)) {
$cache['uid'][$owner->uid]['aid'][] = $ad->aid;
$cache['ad'][$ad->aid]['uid'][] = $owner->uid;
$cache['ad'][$ad->aid][$owner->hostid]['view'] = array();
}
// Taxonomy index.
$terms = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $ad->aid);
$match = FALSE;
while ($term = db_fetch_object($terms)) {
$cache['tid'][$term->tid]['aid'][$ad->aid] = $ad->aid;
$match = TRUE;
}
if (!$match) {
$cache['tid'][0]['aid'][] = $ad->aid;
}
}
// HostID index
$owners = db_query('SELECT uid, hostid FROM {ad_hosts}');
while ($owner = db_fetch_object($owners)) {
$cache['uid'][$owner->uid]['hostid'] = $owner->hostid;
$cache['ad'][0][$owner->hostid]['count'] = array();
if (($user = user_load(array(
'uid' => $owner->uid,
))) && user_access('host remote advertisements', $user)) {
$cache['hostid'][$owner->hostid] = TRUE;
}
}
$cache = array_merge($cache, module_invoke_all('ad_build_cache'));
$cache['last_sync'] = time();
$cache['lifetime'] = variable_get('ad_cache_file_lifetime', 60);
return $cache;
}