function views_handler_field_file_extension::render

3.x views_handler_field_file_extension.inc views_handler_field_file_extension::render($values)

Render the field.

Parameters

$values: The values retrieved from the database.

Overrides views_handler_field::render

File

modules/system/views_handler_field_file_extension.inc, line 29
Definition of views_handler_field_file_extension.

Class

views_handler_field_file_extension
Returns a pure file extension of the file, for example 'module'.

Code

function render($values) {
  $value = $this->get_value($values);
  if (!$this->options['extension_detect_tar']) {
    if (preg_match('/\.([^\.]+)$/', $value, $match)) {
      return $this->sanitize_value($match[1]);
    }
  }
  else {
    $file_parts = explode('.', basename($value));
    // If there is an extension.
    if (count($file_parts) > 1) {
      $extension = array_pop($file_parts);
      $last_part_in_name = array_pop($file_parts);
      if ($last_part_in_name === 'tar') {
        $extension = 'tar.' . $extension;
      }
      return $this->sanitize_value($extension);
    }
  }
}