Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
core_filetypes Class Reference

Class to manage the custom filetypes list that is stored in a config variable. More...

Static Public Member Functions

static add_type ($extension, $mimetype, $coreicon, array $groups=array(), $corestring='', $customdescription='', $defaulticon=false)
 Adds a new entry to the list of custom filetypes.
 
static delete_type ($extension)
 Deletes a file type from the config list (or, for a standard one, marks it as deleted).
 
static get_deleted_types ()
 Gets the default types that have been deleted.
 
static get_file_extension ($mimetype)
 Given a mimetype - return a valid file extension for it.
 
static & get_types ()
 Gets all the current types.
 
static reset_caches ()
 Clears the type cache.
 
static revert_type_to_default ($extension)
 Reverts a file type to the default.
 
static update_type ($extension, $newextension, $mimetype, $coreicon, array $groups=array(), $corestring='', $customdescription='', $defaulticon=false)
 Updates an entry in the list of filetypes in config.
 

Static Protected Member Functions

static create_config_record ($extension, $mimetype, $coreicon, array $groups, $corestring, $customdescription, $defaulticon)
 Converts function parameters into a record for storing in the JSON value.
 
static get_custom_types ()
 Gets custom types from config variable, after decoding the JSON if required.
 
static get_default_types ()
 Gets default MIME types that are included as standard.
 
static set_custom_types (array $types)
 Sets the custom types into config variable, encoding into JSON.
 

Static Protected Attributes

static array $cachedtypes
 Cached MIME types for current request.
 

Detailed Description

Class to manage the custom filetypes list that is stored in a config variable.

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

Member Function Documentation

◆ add_type()

static core_filetypes::add_type ( $extension,
$mimetype,
$coreicon,
array $groups = array(),
$corestring = '',
$customdescription = '',
$defaulticon = false )
static

Adds a new entry to the list of custom filetypes.

Parameters
string$extensionFile extension without dot, e.g. 'doc'
string$mimetypeMIME type e.g. 'application/msword'
string$coreiconCore icon to use e.g. 'document'
array$groupsArray of group strings that this type belongs to
string$corestringCustom lang string name in mimetypes.php
string$customdescriptionCustom description (plain text/multilang)
bool$defaulticonTrue if this should be the default icon for the type
Exceptions
coding_exceptionIf the extension already exists, or otherwise invalid

◆ create_config_record()

static core_filetypes::create_config_record ( $extension,
$mimetype,
$coreicon,
array $groups,
$corestring,
$customdescription,
$defaulticon )
staticprotected

Converts function parameters into a record for storing in the JSON value.

Parameters
string$extensionFile extension without dot, e.g. 'doc'
string$mimetypeMIME type e.g. 'application/msword'
string$coreiconCore icon to use e.g. 'document'
array$groupsArray of group strings that this type belongs to
string$corestringCustom lang string name in mimetypes.php
string$customdescriptionCustom description (plain text/multilang)
bool$defaulticonTrue if this should be the default icon for the type
Return values
stdClassRecord matching the parameters

◆ delete_type()

static core_filetypes::delete_type ( $extension)
static

Deletes a file type from the config list (or, for a standard one, marks it as deleted).

Parameters
string$extensionFile extension without dot, e.g. 'doc'
Exceptions
coding_exceptionIf the extension does not exist, or otherwise invalid

◆ get_custom_types()

static core_filetypes::get_custom_types ( )
staticprotected

Gets custom types from config variable, after decoding the JSON if required.

Return values
arrayArray of custom types (empty array if none)

◆ get_default_types()

static core_filetypes::get_default_types ( )
staticprotected

Gets default MIME types that are included as standard.

Note: Use the function get_mimetypes_array to access this data including any customisations the user might have made.

Return values
arrayDefault (pre-installed) MIME type information

◆ get_deleted_types()

static core_filetypes::get_deleted_types ( )
static

Gets the default types that have been deleted.

Returns an array containing the defaults of all those types.

Return values
arrayArray (same format as get_mimetypes_array)

◆ get_file_extension()

static core_filetypes::get_file_extension ( $mimetype)
static

Given a mimetype - return a valid file extension for it.

Parameters
$mimetypestring
Return values
string|boolFalse if the mimetype was not known, a string indicating a valid file extension otherwise. It may not be the only valid file extension - just the first one found.

◆ get_types()

static & core_filetypes::get_types ( )
static

Gets all the current types.

Return values
arrayAssociative array from extension to array of data about type

◆ reset_caches()

static core_filetypes::reset_caches ( )
static

Clears the type cache.

This is not needed in normal use as the set_custom_types function automatically clears the cache. Intended for use in unit tests.

◆ revert_type_to_default()

static core_filetypes::revert_type_to_default ( $extension)
static

Reverts a file type to the default.

May only be called on types that have default values. This will undelete the type if necessary or set its values. If the type is already at default values, does nothing.

Parameters
string$extensionFile extension without dot, e.g. 'doc'
Return values
boolTrue if anything was changed, false if it was already default
Exceptions
coding_exceptionIf the extension is not a default type.

◆ set_custom_types()

static core_filetypes::set_custom_types ( array $types)
staticprotected

Sets the custom types into config variable, encoding into JSON.

Parameters
array$typesArray of custom types
Exceptions
coding_exceptionIf the custom types are fixed in config.php.

◆ update_type()

static core_filetypes::update_type ( $extension,
$newextension,
$mimetype,
$coreicon,
array $groups = array(),
$corestring = '',
$customdescription = '',
$defaulticon = false )
static

Updates an entry in the list of filetypes in config.

Parameters
string$extensionFile extension without dot, e.g. 'doc'
string$newextensionNew file extension (same if not changing)
string$mimetypeMIME type e.g. 'application/msword'
string$coreiconCore icon to use e.g. 'document'
array$groupsArray of group strings that this type belongs to
string$corestringCustom lang string name in mimetypes.php
string$customdescriptionCustom description (plain text/multilang)
bool$defaulticonTrue if this should be the default icon for the type
Exceptions
coding_exceptionIf the new extension already exists, or otherwise invalid

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