1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Form Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Form; |
10
|
|
|
|
11
|
|
|
use Joomla\Form\Html\Select as HtmlSelect; |
12
|
|
|
use Joomla\Language\Text; |
13
|
|
|
use Joomla\Filesystem\File; |
14
|
|
|
use Joomla\Filesystem\Folder; |
15
|
|
|
|
16
|
|
|
FormHelper::loadFieldClass('list'); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Supports an HTML select list of files |
20
|
|
|
* |
21
|
|
|
* @since 1.0 |
22
|
|
|
* @deprecated The joomla/form package is deprecated |
23
|
|
|
*/ |
24
|
|
|
class Field_FileList extends Field_List |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* The form field type. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
* @since 1.0 |
31
|
|
|
*/ |
32
|
|
|
public $type = 'FileList'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Method to get the list of files for the field options. |
36
|
|
|
* Specify the target directory with a directory attribute |
37
|
|
|
* Attributes allow an exclude mask and stripping of extensions from file name. |
38
|
|
|
* Default attribute may optionally be set to null (no file) or -1 (use a default). |
39
|
|
|
* |
40
|
|
|
* @return array The field option objects. |
41
|
|
|
* |
42
|
|
|
* @since 1.0 |
43
|
|
|
*/ |
44
|
|
|
protected function getOptions() |
45
|
|
|
{ |
46
|
|
|
$options = array(); |
47
|
|
|
|
48
|
|
|
// Initialize some field attributes. |
49
|
|
|
$filter = (string) $this->element['filter']; |
50
|
|
|
$exclude = (string) $this->element['exclude']; |
51
|
|
|
$stripExt = (string) $this->element['stripext']; |
52
|
|
|
$hideNone = (string) $this->element['hide_none']; |
53
|
|
|
$hideDefault = (string) $this->element['hide_default']; |
54
|
|
|
|
55
|
|
|
// Get the path in which to search for file options. |
56
|
|
|
$path = (string) $this->element['directory']; |
57
|
|
|
|
58
|
|
|
if (!is_dir($path)) |
59
|
|
|
{ |
60
|
|
|
$path = JPATH_ROOT . '/' . $path; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// Prepend some default options based on field attributes. |
64
|
|
View Code Duplication |
if (!$hideNone) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$options[] = HtmlSelect::option('-1', Text::alt('JOPTION_DO_NOT_USE', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname))); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
if (!$hideDefault) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$options[] = HtmlSelect::option('', Text::alt('JOPTION_USE_DEFAULT', preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname))); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// Get a list of files in the search path with the given filter. |
75
|
|
|
$files = Folder::files($path, $filter); |
76
|
|
|
|
77
|
|
|
// Build the options list from the list of files. |
78
|
|
|
if (is_array($files)) |
79
|
|
|
{ |
80
|
|
|
foreach ($files as $file) |
81
|
|
|
{ |
82
|
|
|
// Check to see if the file is in the exclude mask. |
83
|
|
View Code Duplication |
if ($exclude) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
if (preg_match(chr(1) . $exclude . chr(1), $file)) |
86
|
|
|
{ |
87
|
|
|
continue; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// If the extension is to be stripped, do it. |
92
|
|
|
if ($stripExt) |
93
|
|
|
{ |
94
|
|
|
$file = File::stripExt($file); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$options[] = HtmlSelect::option($file, $file); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
// Merge any additional options in the XML definition. |
102
|
|
|
$options = array_merge(parent::getOptions(), $options); |
103
|
|
|
|
104
|
|
|
return $options; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.