function views_handler_field_file_extension::render

Overrides views_handler_field::render

File

modules/system/views_handler_field_file_extension.inc, line 40

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