You are here

function adserve_invoke_hook in Advertisement 5

Same name and namespace in other branches
  1. 5.2 adcache.inc \adserve_invoke_hook()
  2. 6.3 adcache.inc \adserve_invoke_hook()
  3. 6 adserve.inc \adserve_invoke_hook()
  4. 6.2 adcache.inc \adserve_invoke_hook()
  5. 7 adcache.inc \adserve_invoke_hook()

Invoke adserve hooks, defined in adapi with adserve_HOOK.

2 calls to adserve_invoke_hook()
adserve_ad in ./adserve.inc
The main adserve logic.
adserve_select_ad in ./adserve.inc
Simple default function to randomly select an ad. Provides a hook to allow the definition of external display methods.

File

./adserve.inc, line 422

Code

function adserve_invoke_hook($hook, $a1 = NULL, $a2 = NULL) {
  if (adserve_variable('adcache') != 'none') {
    $cache = adserve_variable('adcache');
    _debug_echo("Invoking adserve hook '{$hook}' in {$cache} cache.");

    // Get information from cache.
    return adserve_invoke_file("ad_cache_{$cache}_{$hook}", $a1, $a2);
  }
  else {
    _debug_echo("Invoking adserve hook '{$hook}'.");

    // Get information from Drupal variable table.
    $actions = variable_get($hook, '');
    $return = array();
    if (!empty($actions)) {
      $actions = unserialize($actions);
      foreach ($actions as $name => $action) {
        if ($action['function']) {
          $function = $action['function'];
          if (!function_exists($function)) {
            if ($action['path']) {
              _debug_echo("Including file '" . $action['path'] . "'.");
              include_once $action['path'];
            }
          }
          if (function_exists($function)) {
            _debug_echo("Invoking function '{$function}'.");
            $return[] = $function($a1, $a2);
          }
          else {
            if (adserve_variable('debug')) {
              echo "Function '{$function}' does not exist.<br />\n";
            }
          }
        }
        else {
          $return[] = $action;
        }
      }
    }
    return $return;
  }

  // Retreive hook definition from cache if using, or from variable_get
  // return hook action.
}