Révision 6eb8d15f
Ajouté par Assos Assos il y a presque 10 ans
drupal7/sites/all/modules/views/modules/system/views_handler_field_file_extension.inc | ||
---|---|---|
10 | 10 |
* @ingroup views_field_handlers |
11 | 11 |
*/ |
12 | 12 |
class views_handler_field_file_extension extends views_handler_field { |
13 |
public function option_definition() { |
|
14 |
$options = parent::option_definition(); |
|
15 |
$options['extension_detect_tar'] = array('default' => FALSE, 'bool' => TRUE); |
|
16 |
return $options; |
|
17 |
} |
|
18 |
|
|
19 |
public function options_form(&$form, &$form_state) { |
|
20 |
parent::options_form($form, $form_state); |
|
21 |
$form['extension_detect_tar'] = array( |
|
22 |
'#type' => 'checkbox', |
|
23 |
'#title' => t('Detect if tar is part of the extension'), |
|
24 |
'#description' => t("See if the previous extension is '.tar' and if so, add that, so we see 'tar.gz' or 'tar.bz2' instead of just 'gz'."), |
|
25 |
'#default_value' => $this->options['extension_detect_tar'], |
|
26 |
); |
|
27 |
} |
|
28 |
|
|
13 | 29 |
function render($values) { |
14 | 30 |
$value = $this->get_value($values); |
15 |
if (preg_match('/\.([^\.]+)$/', $value, $match)) { |
|
16 |
return $this->sanitize_value($match[1]); |
|
31 |
if (!$this->options['extension_detect_tar']) { |
|
32 |
if (preg_match('/\.([^\.]+)$/', $value, $match)) { |
|
33 |
return $this->sanitize_value($match[1]); |
|
34 |
} |
|
35 |
} |
|
36 |
else { |
|
37 |
$file_parts = explode('.', basename($value)); |
|
38 |
// If there is an extension. |
|
39 |
if (count($file_parts) > 1) { |
|
40 |
$extension = array_pop($file_parts); |
|
41 |
$last_part_in_name = array_pop($file_parts); |
|
42 |
if ($last_part_in_name === 'tar') { |
|
43 |
$extension = 'tar.' . $extension; |
|
44 |
} |
|
45 |
return $this->sanitize_value($extension); |
|
46 |
} |
|
17 | 47 |
} |
18 | 48 |
} |
19 | 49 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules