Utility class for handling with file types in the forms.
More...
Utility class for handling with file types in the forms.
This class is supposed to serve as a helper class for MoodleQuickForm_filetypes and admin_setting_filetypes classes.
The file types can be specified in a syntax compatible with what filepicker and filemanager support via the "accepted_types" option: a list of extensions (e.g. ".doc"), mimetypes ("image/png") or groups ("audio").
- Copyright
- 2017 David Mudrak david.nosp@m.@moo.nosp@m.dle.c.nosp@m.om
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ data_for_browser()
core_form\filetypes_util::data_for_browser |
( |
| $onlytypes = null, |
|
|
| $allowall = true, |
|
|
| $current = null ) |
Prepares data for the filetypes-browser.mustache.
- Parameters
-
string | array | $onlytypes | Allow selection from these file types only; for example 'web_image'. |
bool | $allowall | Allow to select 'All file types'. Does not apply with onlytypes are set. |
string | array | $current | Current values that should be selected. |
- Return values
-
◆ describe_file_types()
core_form\filetypes_util::describe_file_types |
( |
| $types | ) |
|
Describe the list of file types for human user.
Given the list of file types, return a list of human readable descriptive names of relevant groups, types or file formats.
- Parameters
-
- Return values
-
◆ expand()
core_form\filetypes_util::expand |
( |
| $types, |
|
|
| $keepgroups = false, |
|
|
| $keepmimetypes = false ) |
Expands the file types into the list of file extensions.
The groups and mimetypes are expanded into the list of their associated file extensions. Depending on the $keepgroups and $keepmimetypes, the groups and mimetypes themselves are either kept in the list or removed.
- Parameters
-
string | array | $types | |
bool | $keepgroups | Keep the group item in the list after expansion |
bool | $keepmimetypes | Keep the mimetype item in the list after expansion |
- Return values
-
array | list of extensions and eventually groups and types |
◆ get_group_description()
core_form\filetypes_util::get_group_description |
( |
| $group | ) |
|
Return a human readable name of the filetype group.
- Parameters
-
- Return values
-
◆ get_groups_info()
core_form\filetypes_util::get_groups_info |
( |
| ) |
|
Provides a list of all known file type groups and their properties.
- Return values
-
◆ get_not_listed()
core_form\filetypes_util::get_not_listed |
( |
| $types, |
|
|
| $list ) |
Returns all types that are not part of the given list.
This is similar check to the {
- See also
- self\is_listed()} but this one actually returns the extra types.
- Parameters
-
string | array | $types | File type or list of types to be checked. |
string | array | $list | An array or string listing the types to check against. |
- Return values
-
array | Types not present in the list. |
◆ get_not_whitelisted()
core_form\filetypes_util::get_not_whitelisted |
( |
| ) |
|
◆ get_unknown_file_types()
core_form\filetypes_util::get_unknown_file_types |
( |
| $types | ) |
|
Returns file types from the list that are not recognized.
- Parameters
-
string | array | $types | list of user-defined file types |
- Return values
-
array | A list of unknown file types. |
◆ is_allowed_file_type()
core_form\filetypes_util::is_allowed_file_type |
( |
| $filename, |
|
|
| $allowlist ) |
Is the given filename of an allowed file type?
Empty allowlist is interpreted as "any file type is allowed" rather than "no file can be uploaded".
- Parameters
-
string | $filename | the file name |
string | array | $allowlist | list of allowed file extensions |
- Return values
-
boolean | True if the file type is allowed, false if not |
◆ is_filetype_group()
core_form\filetypes_util::is_filetype_group |
( |
| $type | ) |
|
Is the given string a known filetype group?
- Parameters
-
- Return values
-
bool|object | false or the group info |
◆ is_listed()
core_form\filetypes_util::is_listed |
( |
| $types, |
|
|
| $list ) |
Should the file type be considered as a part of the given list.
If multiple types are provided, all of them must be part of the list. Empty type is part of any list. Any type is part of an empty list.
- Parameters
-
string | array | $types | File type or list of types to be checked. |
string | array | $list | An array or string listing the types to check against. |
- Return values
-
◆ is_whitelisted()
core_form\filetypes_util::is_whitelisted |
( |
| ) |
|
◆ looks_like_mimetype()
core_form\filetypes_util::looks_like_mimetype |
( |
| $type | ) |
|
Does the given file type looks like a valid MIME type?
This does not check of the MIME type is actually registered here/known.
- Parameters
-
- Return values
-
◆ normalize_file_types()
core_form\filetypes_util::normalize_file_types |
( |
| $types | ) |
|
Converts the argument into an array (list) of file types.
The list can be separated by whitespace, end of lines, commas, colons and semicolons. Empty values are not returned. Values are converted to lowercase. Duplicates are removed. Glob evaluation is not supported.
The return value can be used as the accepted_types option for the filepicker.
- Parameters
-
string | array | $types | List of file extensions, groups or mimetypes |
- Return values
-
The documentation for this class was generated from the following file:
- lib/form/classes/filetypes_util.php