You are here

function _feeds_excel_token_values__excel_row in Feeds Excel 7

Helper function for rendering token values for excel row tokens.

Parameters

object $object: the exce row object to build the token value for.

string $token_name: the specific token name, like passed to hook_tokens() as $tokens key.

string $original_token: the original complete token, containing type and name, like passed to hook_tokens() as $tokens value.

Return value

string rendered token value for the given token

1 string reference to '_feeds_excel_token_values__excel_row'
feeds_excel_tokens in ./feeds_excel.module
Implements hook_tokens().

File

./feeds_excel.module, line 361

Code

function _feeds_excel_token_values__excel_row($object, $token_name, $original_token, $sanitize) {

  // Subpattern for preg_match
  $subpattern = array();
  if ($token_name == 'row') {
    return $sanitize ? check_plain($object->row) : $object->row;
  }
  elseif ($token_name == 'range-id') {
    return $sanitize ? check_plain($object->meta['range_id']) : $object->meta['range_id'];
  }
  elseif ($token_name == 'column-offset') {
    return $sanitize ? check_plain($object->meta['range_col_offset']) : $object->meta['range_col_offset'];
  }
  elseif (is_array($object->cells) && preg_match('&^x-([0-9]+)(-formatted)?$&is', $token_name, $subpattern)) {
    $x = $subpattern[1];
    $formatted = !empty($subpattern[2]);
    foreach ($object->cells as $id => $cell) {

      // We found the correct cell.
      if ($cell['x'] == $x) {
        $key = $formatted ? 'value' : 'raw';
        return $sanitize ? check_plain($cell[$key]) : $cell[$key];
      }
    }
    return '';
  }
  elseif (is_array($object->cells) && preg_match('&^column-([0-9]+)(-formatted)?$&is', $token_name, $subpattern)) {
    $column = $subpattern[1];
    $formatted = !empty($subpattern[2]);
    foreach ($object->cells as $id => $cell) {

      // We found the correct cell.
      if ($cell['column'] == $column) {
        $key = $formatted ? 'value' : 'raw';
        return $sanitize ? check_plain($cell[$key]) : $cell[$key];
      }
    }
    return '';
  }
}