You are here

function dfp_tokens in Doubleclick for Publishers (DFP) 7

Same name and namespace in other branches
  1. 8 dfp.tokens.inc \dfp_tokens()
  2. 7.2 dfp.module \dfp_tokens()

Implements hook_tokens().

File

./dfp.module, line 329

Code

function dfp_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'dfp_tag') {
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'slot':
          if (!empty($data['tag'])) {
            $replacements[$original] = check_plain($data['tag']->slot);
          }
          break;
        case 'network_id':
          $replacements[$original] = check_plain(variable_get('dfp_network_id', ''));
          break;
        case 'ad_categories':
          $term_names =& drupal_static('dfp_entity_targeting_terms', array());
          $replacements[$original] = implode(',', $term_names);
          break;
      }
    }
    if ($created_tokens = token_find_with_prefix($tokens, 'url_parts')) {
      foreach ($created_tokens as $name => $original) {
        $url_parts = explode('/', $_GET['q']);
        $replacements[$original] = implode('/', array_slice($url_parts, 0, $name));
      }
    }
  }
  return $replacements;
}