You are here

function feeds_excel_tokens in Feeds Excel 7

Implements hook_tokens().

File

./feeds_excel.module, line 248

Code

function feeds_excel_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $values = array();
  switch ($type) {
    case 'excel-file':
      $func = '_feeds_excel_token_values__excel_file';
      break;
    case 'excel-sheet':
      $func = '_feeds_excel_token_values__excel_sheet';
      break;
    case 'excel-row':
      $func = '_feeds_excel_token_values__excel_row';
      break;
    case 'excel-column':
      $func = '_feeds_excel_token_values__excel_column';
      break;
  }
  $replacements = array();

  // After we got our callback, we process each token.
  if (!empty($func) && function_exists($func) && isset($data[$type])) {
    $sanitize = !empty($options['sanitize']);
    foreach ($tokens as $name => $original) {
      $value = $func($data[$type], $name, $original, $sanitize);

      // Callback has to return a explicit value, else we do not add it to the
      // replacement array. Non defined tokens are handled via $options['clear]
      // in token_replace().
      if (isset($value)) {
        $replacements[$original] = $value;
      }
    }
  }
  return $replacements;
}