function dfp_format_targeting in Doubleclick for Publishers (DFP) 7.2
Same name and namespace in other branches
- 7 dfp.module \dfp_format_targeting()
Format the given array of values to be displayed as part of a javascript.
Parameters
array $variables: 'values' => A simple array of targeting values. Ex. val1, val2, val3
Return value
string If $values had one item, then a string in the format ["val1"]. If $values has more than one item, then a string in the format ["val1","val2","val3"].
2 calls to dfp_format_targeting()
- _dfp_js_global_settings in ./
dfp.module - Helper function to include javascript variables, etc in the header above all slot definitions.
- _dfp_js_slot_definition in ./
dfp.module - Helper function to build the javascript needed to define an ad slot and add it to the head tag.
File
- ./
dfp.module, line 587
Code
function dfp_format_targeting($targeting, $tag = '') {
foreach ($targeting as $key => &$target) {
$target['target'] = check_plain($target['target']);
$target['value'] = dfp_token_replace(check_plain($target['value']), $tag, array(
'sanitize' => TRUE,
'clear' => TRUE,
));
// The target value could be blank if tokens are used. If so, removed it.
if (empty($target['value'])) {
unset($targeting[$key]);
continue;
}
// Allow other modules to alter the target.
drupal_alter('dfp_target', $target);
// Convert the values into an array and trim the whitespace from each value.
$values = explode(',', $target['value']);
$values = array_map('trim', $values);
if (count($values) == 1) {
$target['value'] = $values[0];
}
elseif (count($values) > 1) {
$target['value'] = $values;
}
}
return $targeting;
}