You are here

public function views_handler_field_file_extension::render in Views (for Drupal 7) 7.3

Same name and namespace in other branches
  1. 6.3 modules/system/views_handler_field_file_extension.inc \views_handler_field_file_extension::render()

Render the field.

Parameters

array $values: The values retrieved from the database.

Overrides views_handler_field::render

File

modules/system/views_handler_field_file_extension.inc, line 40
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

public 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);
    }
  }
}