Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 403]

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

Copyright: 2014 The Open University
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 742 lines (42 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: core_filetypes  - X-Ref

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

get_default_types()   X-Ref
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: array Default (pre-installed) MIME type information

get_file_extension($mimetype)   X-Ref
Given a mimetype - return a valid file extension for it.

param: $mimetype string
return: string|bool False if the mimetype was not known, a string indicating a valid file extension otherwise. It may not

get_types()   X-Ref
Gets all the current types.

return: array Associative array from extension to array of data about type

get_custom_types()   X-Ref
Gets custom types from config variable, after decoding the JSON if required.

return: array Array of custom types (empty array if none)

set_custom_types(array $types)   X-Ref
Sets the custom types into config variable, encoding into JSON.

param: array $types Array of custom types

reset_caches()   X-Ref
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.


get_deleted_types()   X-Ref
Gets the default types that have been deleted. Returns an array containing
the defaults of all those types.

return: array Array (same format as get_mimetypes_array)

add_type($extension, $mimetype, $coreicon,array $groups = array()   X-Ref
Adds a new entry to the list of custom filetypes.

param: string $extension File extension without dot, e.g. 'doc'
param: string $mimetype MIME type e.g. 'application/msword'
param: string $coreicon Core icon to use e.g. 'document'
param: array $groups Array of group strings that this type belongs to
param: string $corestring Custom lang string name in mimetypes.php
param: string $customdescription Custom description (plain text/multilang)
param: bool $defaulticon True if this should be the default icon for the type

update_type($extension, $newextension, $mimetype, $coreicon,array $groups = array()   X-Ref
Updates an entry in the list of filetypes in config.

param: string $extension File extension without dot, e.g. 'doc'
param: string $newextension New file extension (same if not changing)
param: string $mimetype MIME type e.g. 'application/msword'
param: string $coreicon Core icon to use e.g. 'document'
param: array $groups Array of group strings that this type belongs to
param: string $corestring Custom lang string name in mimetypes.php
param: string $customdescription Custom description (plain text/multilang)
param: bool $defaulticon True if this should be the default icon for the type

delete_type($extension)   X-Ref
Deletes a file type from the config list (or, for a standard one, marks it
as deleted).

param: string $extension File extension without dot, e.g. 'doc'

revert_type_to_default($extension)   X-Ref
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.

param: string $extension File extension without dot, e.g. 'doc'
return: bool True if anything was changed, false if it was already default

create_config_record($extension, $mimetype,$coreicon, array $groups, $corestring, $customdescription, $defaulticon)   X-Ref
Converts function parameters into a record for storing in the JSON value.

param: string $extension File extension without dot, e.g. 'doc'
param: string $mimetype MIME type e.g. 'application/msword'
param: string $coreicon Core icon to use e.g. 'document'
param: array $groups Array of group strings that this type belongs to
param: string $corestring Custom lang string name in mimetypes.php
param: string $customdescription Custom description (plain text/multilang)
param: bool $defaulticon True if this should be the default icon for the type
return: stdClass Record matching the parameters