Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

File info?

File Size: 588 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: H5PDefaultStorage  - X-Ref

The default file storage class for H5P. Will carry out the requested file
operations using PHP's standard file operation functions.

Some implementations of H5P that doesn't use the standard file system will
want to create their own implementation of the H5PFileStorage interface.

__construct($path, $alteditorpath = NULL)   X-Ref
The great Constructor!

param: string $path
param: string $alteditorpath

saveLibrary($library)   X-Ref
Store the library folder.

param: array $library

saveContent($source, $content)   X-Ref
Store the content folder.

param: string $source
param: array $content

deleteContent($content)   X-Ref
Remove content folder.

param: array $content

cloneContent($id, $newId)   X-Ref
Creates a stored copy of the content folder.

param: string $id
param: int $newId

getTmpPath()   X-Ref
Get path to a new unique tmp folder.

return: string

exportContent($id, $target)   X-Ref
Fetch content folder and save in target directory.

param: int $id
param: string $target

exportLibrary($library, $target, $developmentPath=NULL)   X-Ref
Fetch library folder and save in target directory.

param: array $library
param: string $target
param: string $developmentPath

saveExport($source, $filename)   X-Ref
Save export in file system

param: string $source
param: string $filename

deleteExport($filename)   X-Ref
Removes given export file

param: string $filename

hasExport($filename)   X-Ref
Check if the given export file exists

return: boolean
param: string $filename

cacheAssets(&$files, $key)   X-Ref
Will concatenate all JavaScrips and Stylesheets into two files in order
to improve page performance.

param: array $files
param: string $key

getCachedAssets($key)   X-Ref
No description

deleteCachedAssets($keys)   X-Ref
Remove the aggregated cache files.

param: array $keys

getContent($file_path)   X-Ref
Read file content of given file and then return it.

return: string
param: string $file_path

saveFile($file, $contentId)   X-Ref
Save files uploaded through the editor.
The files must be marked as temporary until the content form is saved.

param: \H5peditorFile $file
param: int $contentid

cloneContentFile($file, $fromId, $toId)   X-Ref
Copy a file from another content or editor tmp dir.
Used when copy pasting content in H5P Editor.

param: string $file path + name
param: string|int $fromid Content ID or 'editor' string
param: int $toid Target Content ID

moveContentDirectory($source, $contentId = NULL)   X-Ref
Copy a content from one directory to another. Defaults to cloning
content from the current temporary upload folder to the editor path.

param: string $source path to source directory
param: string $contentId Id of contentarray

getContentFile($file, $contentId)   X-Ref
Checks to see if content has the given file.
Used when saving content.

return: string File ID or NULL if not found
param: string $file path + name
param: int $contentId

removeContentFile($file, $contentId)   X-Ref
Checks to see if content has the given file.
Used when saving content.

return: string|int File ID or NULL if not found
param: string $file path + name
param: int $contentid

hasWriteAccess()   X-Ref
Check if server setup has write permission to
the required folders

return: bool True if site can write to the H5P files folder

hasPresave($libraryFolder, $developmentPath = null)   X-Ref
Check if the file presave.js exists in the root of the library

return: bool
param: string $libraryFolder
param: string $developmentPath

getUpgradeScript($machineName, $majorVersion, $minorVersion)   X-Ref
Check if upgrades script exist for library.

return: string Relative path
param: string $machineName
param: int $majorVersion
param: int $minorVersion

saveFileFromZip($path, $file, $stream)   X-Ref
Store the given stream into the given file.

return: bool
param: string $path
param: string $file
param: resource $stream

copyFileTree($source, $destination)   X-Ref
Recursive function for copying directories.

return: boolean
param: string $source
param: string $destination

getIgnoredFiles($file)   X-Ref
Retrieve array of file names from file.

return: array Array with files that should be ignored
param: string $file

dirReady($path)   X-Ref
Recursive function that makes sure the specified directory exists and
is writable.

return: bool
param: string $path

getEditorPath()   X-Ref
Easy helper function for retrieving the editor path

return: string Path to editor files