Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core_form\filetypes_util Class Reference

Utility class for handling with file types in the forms. More...

Public Member Functions

 data_for_browser ($onlytypes=null, $allowall=true, $current=null)
 Prepares data for the filetypes-browser.mustache.
 
 describe_file_types ($types)
 Describe the list of file types for human user.
 
 expand ($types, $keepgroups=false, $keepmimetypes=false)
 Expands the file types into the list of file extensions.
 
 get_group_description ($group)
 Return a human readable name of the filetype group.
 
 get_groups_info ()
 Provides a list of all known file type groups and their properties.
 
 get_not_listed ($types, $list)
 Returns all types that are not part of the given list.
 
 get_not_whitelisted ()
 
 get_unknown_file_types ($types)
 Returns file types from the list that are not recognized.
 
 is_allowed_file_type ($filename, $allowlist)
 Is the given filename of an allowed file type?
 
 is_filetype_group ($type)
 Is the given string a known filetype group?
 
 is_listed ($types, $list)
 Should the file type be considered as a part of the given list.
 
 is_whitelisted ()
 
 looks_like_mimetype ($type)
 Does the given file type looks like a valid MIME type?
 
 normalize_file_types ($types)
 Converts the argument into an array (list) of file types.
 

Protected Attributes

array $cachegroups = null
 Cache of all file type groups for the self::get_groups_info().
 

Detailed Description

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").

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ 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$onlytypesAllow selection from these file types only; for example 'web_image'.
bool$allowallAllow to select 'All file types'. Does not apply with onlytypes are set.
string | array$currentCurrent values that should be selected.
Return values
array

◆ 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
string | array$types
Return values
object

◆ 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$keepgroupsKeep the group item in the list after expansion
bool$keepmimetypesKeep the mimetype item in the list after expansion
Return values
arraylist 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
string$group
Return values
string

◆ get_groups_info()

core_form\filetypes_util::get_groups_info ( )

Provides a list of all known file type groups and their properties.

Return values
array

◆ 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$typesFile type or list of types to be checked.
string | array$listAn array or string listing the types to check against.
Return values
arrayTypes not present in the list.

◆ get_not_whitelisted()

core_form\filetypes_util::get_not_whitelisted ( )
Deprecated
since Moodle 3.10 MDL-69050 - please use {
See also
get_not_listed} instead.

◆ 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$typeslist of user-defined file types
Return values
arrayA 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$filenamethe file name
string | array$allowlistlist of allowed file extensions
Return values
booleanTrue 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
string$type
Return values
bool|objectfalse 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$typesFile type or list of types to be checked.
string | array$listAn array or string listing the types to check against.
Return values
boolean

◆ is_whitelisted()

core_form\filetypes_util::is_whitelisted ( )
Deprecated
since Moodle 3.10 MDL-69050 - please use {
See also
is_listed} instead.

◆ 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
string$type
Return values
bool

◆ 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$typesList of file extensions, groups or mimetypes
Return values
arrayof strings

The documentation for this class was generated from the following file: