You are here

function ad_cache_file_increment in Advertisement 5.2

Same name and namespace in other branches
  1. 5 cache/file/ad_cache_file.inc \ad_cache_file_increment()
  2. 6.3 cache/file/ad_cache_file.inc \ad_cache_file_increment()
  3. 6 cache/file/ad_cache_file.inc \ad_cache_file_increment()
  4. 6.2 cache/file/ad_cache_file.inc \ad_cache_file_increment()
  5. 7 cache/file/ad_cache_file.inc \ad_cache_file_increment()

Increment an advertisement counter.

File

cache/file/ad_cache_file.inc, line 155
A plug in for the ad.module, providing a file cache mechanism for improved performance when displaying ads.

Code

function ad_cache_file_increment($action, $aid) {
  $group = adserve_variable('group');
  $hostid = adserve_variable('hostid') ? adserve_variable('hostid') : 'none';
  $cache = ad_cache_file_cache();
  $timestamp = date('YmdH');
  $extra = adserve_invoke_hook('increment_extra', 'merge', $action, $aid);
  if (is_array($extra) && !empty($extra)) {
    $extra = implode('|,|', $extra);
  }
  adserve_variable('extra', $extra);

  // increment counter
  if (is_array($cache['ad'][$aid]) && isset($cache['ad'][$aid]['counts']) && is_array($cache['ad'][$aid]['counts'][$group]) && is_array($cache['ad'][$aid]['counts'][$group][$extra]) && is_array($cache['ad'][$aid]['counts'][$group][$extra][$hostid]) && is_array($cache['ad'][$aid]['counts'][$group][$extra][$hostid][$action]) && is_array($cache['ad'][$aid]['counts'][$group][$extra][$hostid][$action]) && isset($cache['ad'][$aid]['counts'][$group][$extra][$hostid][$action][$timestamp])) {
    $cache['ad'][$aid]['counts'][$group][$extra][$hostid][$action][$timestamp]++;
  }
  else {
    $cache['ad'][$aid]['counts'][$group][$extra][$hostid][$action][$timestamp] = 1;
  }
  _debug_echo("File cache: aid({$aid}) group({$group}) extra({$extra}) hostid({$hostid}) action({$action}) timestamp({$timestamp}) count: " . $cache['ad'][$aid]['counts'][$group][$extra][$hostid][$action][$timestamp]);

  // update the cache in memory
  ad_cache_file_cache($cache);
}