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 402] [Versions 401 and 403]

(no description)

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

Defines 11 classes

H5PFrameworkInterface:: (58 methods):
  getPlatformInfo()
  fetchExternalData()
  setLibraryTutorialUrl()
  setErrorMessage()
  setInfoMessage()
  getMessages()
  t()
  getLibraryFileUrl()
  getUploadedH5pFolderPath()
  getUploadedH5pPath()
  loadAddons()
  getLibraryConfig()
  loadLibraries()
  getAdminUrl()
  getLibraryId()
  getWhitelist()
  isPatchedLibrary()
  isInDevMode()
  mayUpdateLibraries()
  saveLibraryData()
  insertContent()
  updateContent()
  resetContentUserData()
  saveLibraryDependencies()
  copyLibraryUsage()
  deleteContentData()
  deleteLibraryUsage()
  saveLibraryUsage()
  getLibraryUsage()
  loadLibrary()
  loadLibrarySemantics()
  alterLibrarySemantics()
  deleteLibraryDependencies()
  lockDependencyStorage()
  unlockDependencyStorage()
  deleteLibrary()
  loadContent()
  loadContentDependencies()
  getOption()
  setOption()
  updateContentFields()
  clearFilteredParameters()
  getNumNotFiltered()
  getNumContent()
  isContentSlugAvailable()
  getLibraryStats()
  getNumAuthors()
  saveCachedAssets()
  deleteCachedAssets()
  getLibraryContentCount()
  afterExportCreated()
  hasPermission()
  replaceContentTypeCache()
  libraryHasUpgrade()
  replaceContentHubMetadataCache()
  getContentHubMetadataCache()
  getContentHubMetadataChecked()
  setContentHubMetadataChecked()

H5PValidator:: (15 methods):
  __construct()
  isValidPackage()
  getJson()
  getWhitelistRegExp()
  getLibraryData()
  getMissingLibraries()
  getMissingDependencies()
  isExistingFiles()
  isValidH5pData()
  isValidOptionalH5pData()
  isValidRequirement()
  isValidRequiredH5pData()
  isValidH5pDataOptions()
  getJsonData()
  arrayCopy()

H5PStorage:: (5 methods):
  __construct()
  savePackage()
  saveLibraries()
  deletePackage()
  copyPackage()

H5PExport:: (6 methods):
  __construct()
  revertH5PEditorTextEscape()
  createExportFile()
  populateFileList()
  deleteExport()
  addEditorLibraries()

H5PPermission:: (0 methods):

H5PDisplayOptionBehaviour:: (0 methods):

H5PContentHubSyncStatus:: (0 methods):

H5PContentStatus:: (0 methods):

H5PHubEndpoints:: (1 method):
  createURL()

H5PCore:: (59 methods):
  __construct()
  saveContent()
  loadContent()
  filterParameters()
  retrieveValue()
  textAddonMatches()
  generateContentSlug()
  loadContentDependencies()
  getDependencyAssets()
  getAssetsUrls()
  getDependenciesFiles()
  getDependencyPath()
  getDependenciesHash()
  loadLibrarySemantics()
  loadLibrary()
  deleteLibrary()
  findLibraryDependencies()
  isSameVersion()
  deleteFileTree()
  libraryToString()
  libraryFromString()
  determineEmbedType()
  libraryVersion()
  getUpgrades()
  snakeToCamel()
  detectSiteType()
  getLibrariesInstalled()
  combineArrayValues()
  fetchLibrariesMetadata()
  getStorableDisplayOptions()
  getDisplayOptionsForEdit()
  setDisplayOptionOverrides()
  getDisplayOptionsForView()
  getDisplayOptionsAsArray()
  getLibraryId()
  slugify()
  ajaxSuccess()
  ajaxError()
  printJson()
  createToken()
  getTimeFactor()
  hashToken()
  validToken()
  updateContentTypeCache()
  updateContentHubMetadataCache()
  getUpdatedContentHubMetadataCache()
  checkSetupErrorMessage()
  checkSetupForRequirements()
  returnBytes()
  mayUpdateLibraries()
  getLocalization()
  hubRetrieveContent()
  hubPublishContent()
  hubGetAuthorizationHeader()
  hubUnpublishContent()
  hubSyncContent()
  hubAccountInfo()
  hubRegisterAccount()
  getHubContentStatus()

H5PContentValidator:: (25 methods):
  __construct()
  addon()
  getDependencies()
  validateMetadata()
  validateText()
  validateContentFiles()
  validateNumber()
  validateBoolean()
  validateSelect()
  validateList()
  _validateFilelike()
  validateFile()
  validateImage()
  validateVideo()
  validateAudio()
  validateGroup()
  validateLibrary()
  filterParams()
  filter_xss()
  _filter_xss_split()
  _filter_xss_attributes()
  filter_xss_bad_protocol()
  _strip_dangerous_protocols()
  getMetadataSemantics()
  getCopyrightSemantics()


Interface: H5PFrameworkInterface  - X-Ref

Interface defining functions the h5p library needs the framework to implement

getPlatformInfo()   X-Ref
Returns info for the current platform

return: array

fetchExternalData($url, $data = NULL, $blocking = TRUE, $stream = NULL, $fullData = FALSE, $headers = array()   X-Ref
Fetches a file from a remote server using HTTP GET

param: string  $url  Where you want to get or send data.
param: array  $data  Data to post to the URL.
param: bool  $blocking  Set to 'FALSE' to instantly time out (fire and forget).
param: string  $stream  Path to where the file should be saved.
param: bool  $fullData  Return additional response data such as headers and potentially other data
param: array  $headers  Headers to send
param: array  $files Files to send
param: string  $method
return: string|array The content (response body), or an array with data. NULL if something went wrong

setLibraryTutorialUrl($machineName, $tutorialUrl)   X-Ref
Set the tutorial URL for a library. All versions of the library is set

param: string $machineName
param: string $tutorialUrl

setErrorMessage($message, $code = NULL)   X-Ref
Show the user an error message

param: string $message The error message
param: string $code An optional code

setInfoMessage($message)   X-Ref
Show the user an information message

param: string $message

getMessages($type)   X-Ref
Return messages

param: string $type 'info' or 'error'
return: string[]

t($message, $replacements = array()   X-Ref
Translation function

param: string $message
param: array $replacements
return: string Translated string

getLibraryFileUrl($libraryFolderName, $fileName)   X-Ref
Get URL to file in the specific library

param: string $libraryFolderName
param: string $fileName
return: string URL to file

getUploadedH5pFolderPath()   X-Ref
Get the Path to the last uploaded h5p

return: string

getUploadedH5pPath()   X-Ref
Get the path to the last uploaded h5p file

return: string

loadAddons()   X-Ref
Load addon libraries

return: array

getLibraryConfig($libraries = NULL)   X-Ref
Load config for libraries

param: array $libraries
return: array

loadLibraries()   X-Ref
Get a list of the current installed libraries

return: array

getAdminUrl()   X-Ref
Returns the URL to the library admin page

return: string

getLibraryId($machineName, $majorVersion = NULL, $minorVersion = NULL)   X-Ref
Get id to an existing library.
If version number is not specified, the newest version will be returned.

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

getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibraryWhitelist)   X-Ref
Get file extension whitelist

The default extension list is part of h5p, but admins should be allowed to modify it

param: boolean $isLibrary
param: string $defaultContentWhitelist
param: string $defaultLibraryWhitelist

isPatchedLibrary($library)   X-Ref
Is the library a patched version of an existing library?

param: object $library
return: boolean

isInDevMode()   X-Ref
Is H5P in development mode?

return: boolean

mayUpdateLibraries()   X-Ref
Is the current user allowed to update libraries?

return: boolean

saveLibraryData(&$libraryData, $new = TRUE)   X-Ref
Store data about a library

Also fills in the libraryId in the libraryData object if the object is new

param: object $libraryData
param: bool $new
return:

insertContent($content, $contentMainId = NULL)   X-Ref
Insert new content.

param: array $content
param: int $contentMainId

updateContent($content, $contentMainId = NULL)   X-Ref
Update old content.

param: array $content
param: int $contentMainId

resetContentUserData($contentId)   X-Ref
Resets marked user data for the given content.

param: int $contentId

saveLibraryDependencies($libraryId, $dependencies, $dependency_type)   X-Ref
Save what libraries a library is depending on

param: int $libraryId
param: array $dependencies
param: string $dependency_type

copyLibraryUsage($contentId, $copyFromId, $contentMainId = NULL)   X-Ref
Give an H5P the same library dependencies as a given H5P

param: int $contentId
param: int $copyFromId
param: int $contentMainId

deleteContentData($contentId)   X-Ref
Deletes content data

param: int $contentId

deleteLibraryUsage($contentId)   X-Ref
Delete what libraries a content item is using

param: int $contentId

saveLibraryUsage($contentId, $librariesInUse)   X-Ref
Saves what libraries the content uses

param: int $contentId
param: array $librariesInUse

getLibraryUsage($libraryId, $skipContent = FALSE)   X-Ref
Get number of content/nodes using a library, and the number of
dependencies to other libraries

param: int $libraryId
param: boolean $skipContent
return: array

loadLibrary($machineName, $majorVersion, $minorVersion)   X-Ref
Loads a library

param: string $machineName
param: int $majorVersion
param: int $minorVersion
return: array|FALSE

loadLibrarySemantics($machineName, $majorVersion, $minorVersion)   X-Ref
Loads library semantics.

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

alterLibrarySemantics(&$semantics, $machineName, $majorVersion, $minorVersion)   X-Ref
Makes it possible to alter the semantics, adding custom fields, etc.

param: array $semantics
param: string $machineName
param: int $majorVersion
param: int $minorVersion

deleteLibraryDependencies($libraryId)   X-Ref
Delete all dependencies belonging to given library

param: int $libraryId

lockDependencyStorage()   X-Ref
Start an atomic operation against the dependency storage


unlockDependencyStorage()   X-Ref
Stops an atomic operation against the dependency storage


deleteLibrary($library)   X-Ref
Delete a library from database and file system

param: stdClass $library

loadContent($id)   X-Ref
Load content.

param: int $id
return: array

loadContentDependencies($id, $type = NULL)   X-Ref
Load dependencies for the given content of the given type.

param: int $id
param: int $type
return: array

getOption($name, $default = NULL)   X-Ref
Get stored setting.

param: string $name
param: string $default
return: mixed

setOption($name, $value)   X-Ref
Stores the given setting.
For example when did we last check h5p.org for updates to our libraries.

param: string $name
param: mixed $value Data

updateContentFields($id, $fields)   X-Ref
This will update selected fields on the given content.

param: int $id Content identifier
param: array $fields Content fields, e.g. filtered or slug.

clearFilteredParameters($library_ids)   X-Ref
Will clear filtered params for all the content that uses the specified
libraries. This means that the content dependencies will have to be rebuilt,
and the parameters re-filtered.

param: array $library_ids

getNumNotFiltered()   X-Ref
Get number of contents that has to get their content dependencies rebuilt
and parameters re-filtered.

return: int

getNumContent($libraryId, $skip = NULL)   X-Ref
Get number of contents using library as main library.

param: int $libraryId
param: array $skip
return: int

isContentSlugAvailable($slug)   X-Ref
Determines if content slug is used.

param: string $slug
return: boolean

getLibraryStats($type)   X-Ref
Generates statistics from the event log per library

param: string $type Type of event to generate stats for
return: array Number values indexed by library name and version

getNumAuthors()   X-Ref
Aggregate the current number of H5P authors

return: int

saveCachedAssets($key, $libraries)   X-Ref
Stores hash keys for cached assets, aggregated JavaScripts and
stylesheets, and connects it to libraries so that we know which cache file
to delete when a library is updated.

param: string $key
param: array $libraries

deleteCachedAssets($library_id)   X-Ref
Locate hash keys for given library and delete them.
Used when cache file are deleted.

param: int $library_id
return: array

getLibraryContentCount()   X-Ref
Get the amount of content items associated to a library
return int


afterExportCreated($content, $filename)   X-Ref
Will trigger after the export file is created.


hasPermission($permission, $id = NULL)   X-Ref
Check if user has permissions to an action

param: [H5PPermission] $permission Permission type, ref H5PPermission
param: [int]           $id         Id need by platform to determine permission
return: boolean

replaceContentTypeCache($contentTypeCache)   X-Ref
Replaces existing content type cache with the one passed in

param: object $contentTypeCache Json with an array called 'libraries'

libraryHasUpgrade($library)   X-Ref
Checks if the given library has a higher version.

param: array $library
return: boolean

replaceContentHubMetadataCache($metadata, $lang)   X-Ref
Replace content hub metadata cache

param: JsonSerializable $metadata Metadata as received from content hub
param: string $lang Language in ISO 639-1
return: mixed

getContentHubMetadataCache($lang = 'en')   X-Ref
Get content hub metadata cache from db

param: string  $lang Language code in ISO 639-1
return: JsonSerializable Json string

getContentHubMetadataChecked($lang = 'en')   X-Ref
Get time of last content hub metadata check

param: string  $lang Language code iin ISO 639-1 format
return: string|null Time in RFC7231 format

setContentHubMetadataChecked($time, $lang = 'en')   X-Ref
Set time of last content hub metadata check

param: int|null  $time Time in RFC7231 format
param: string  $lang Language code iin ISO 639-1 format
return: bool True if successful

Class: H5PValidator  - X-Ref

This class is used for validating H5P files

__construct($H5PFramework, $H5PCore)   X-Ref
Constructor for the H5PValidator

param: H5PFrameworkInterface $H5PFramework
param: H5PCore $H5PCore

isValidPackage($skipContent = FALSE, $upgradeOnly = FALSE)   X-Ref
Validates a .h5p file

param: bool $skipContent
param: bool $upgradeOnly
return: bool TRUE if the .h5p file is valid

getJson($path, $zip, $file, $assoc = FALSE)   X-Ref
Help read JSON from the archive

param: string $path
param: ZipArchive $zip
param: string $file
return: mixed JSON content if valid, FALSE for invalid, NULL for breaking error.

getWhitelistRegExp($isLibrary)   X-Ref
Help retrieve file type regexp whitelist from plugin.

param: bool $isLibrary Separate list with more allowed file types
return: string RegExp

getLibraryData($file, $filePath, $tmpDir)   X-Ref
Validates a H5P library

param: string $file
param: string $filePath
param: string $tmpDir
return: boolean|array

getMissingLibraries($libraries)   X-Ref
Use the dependency declarations to find any missing libraries

param: array $libraries
return: array

getMissingDependencies($dependencies, $libraries)   X-Ref
Helper function for getMissingLibraries, searches for dependency required libraries in
the provided list of libraries

param: array $dependencies
param: array $libraries
return:

isExistingFiles($files, $tmpDir, $library)   X-Ref
Figure out if the provided file paths exists

Triggers error messages if files doesn't exist

param: array $files
param: string $tmpDir
param: string $library
return: boolean

isValidH5pData($h5pData, $library_name, $required, $optional)   X-Ref
Validates h5p.json and library.json data

Error messages are triggered if the data isn't valid

param: array $h5pData
param: string $library_name
param: array $required
param: array $optional
return: boolean

isValidOptionalH5pData($h5pData, $requirements, $library_name)   X-Ref
Helper function for isValidH5pData

Validates the optional part of the h5pData

Triggers error messages

param: array $h5pData
param: array $requirements
param: string $library_name
return: boolean

isValidRequirement($h5pData, $requirement, $library_name, $property_name)   X-Ref
Validate a requirement given as regexp or an array of requirements

param: mixed $h5pData
param: mixed $requirement
param: string $library_name
param: string $property_name
return: boolean

isValidRequiredH5pData($h5pData, $requirements, $library_name)   X-Ref
Validates the required h5p data in libraray.json and h5p.json

param: mixed $h5pData
param: array $requirements
param: string $library_name
return: boolean

isValidH5pDataOptions($selected, $allowed, $library_name)   X-Ref
Validates h5p data against a set of allowed values(options)

param: array $selected
param: array $allowed
param: string $library_name
return: boolean

getJsonData($filePath, $return_as_string = FALSE)   X-Ref
Fetch json data from file

param: string $filePath
param: boolean $return_as_string
return: mixed

arrayCopy(array $array)   X-Ref
Helper function that copies an array

param: array $array
return: array

Class: H5PStorage  - X-Ref

This class is used for saving H5P files

__construct(H5PFrameworkInterface $H5PFramework, H5PCore $H5PCore)   X-Ref
Constructor for the H5PStorage

param: H5PFrameworkInterface|object $H5PFramework
param: H5PCore $H5PCore

savePackage($content = NULL, $contentMainId = NULL, $skipContent = FALSE, $options = array()   X-Ref
Saves a H5P file

param: null $content
param: int $contentMainId
param: bool $skipContent
param: array $options
return: bool TRUE if one or more libraries were updated

saveLibraries()   X-Ref
Helps savePackage.

return: int Number of libraries saved

deletePackage($content)   X-Ref
Delete an H5P package

param: $content

copyPackage($contentId, $copyFromId, $contentMainId = NULL)   X-Ref
Copy/clone an H5P package

May for instance be used if the content is being revisioned without
uploading a new H5P package

param: int $contentId
param: int $copyFromId
param: int $contentMainId

Class: H5PExport  - X-Ref

This class is used for exporting zips

__construct(H5PFrameworkInterface $H5PFramework, H5PCore $H5PCore)   X-Ref
Constructor for the H5PExport

param: H5PFrameworkInterface|object $H5PFramework
param: H5PCore $H5PCore

revertH5PEditorTextEscape($value)   X-Ref
Reverts the replace pattern used by the text editor

param: string $value
return: string

createExportFile($content)   X-Ref
Return path to h5p package.

Creates package if not already created

param: array $content
return: string

populateFileList($dir, &$files, $relative = '')   X-Ref
Recursive function the will add the files of the given directory to the
given files list. All files are objects with an absolute path and
a relative path. The relative path is forward slashes only! Great for
use in zip files and URLs.

param: string $dir path
param: array $files list
param: string $relative prefix. Optional

deleteExport($content)   X-Ref
Delete .h5p file

param: array $content object

addEditorLibraries($libraries, $editorLibraries)   X-Ref
Add editor libraries to the list of libraries

These are not supposed to go into h5p.json, but must be included with the rest
of the libraries

TODO This is a private function that is not currently being used

param: array $libraries
param: array $editorLibraries
return: array List of libraries keyed by machineName

Class: H5PPermission  - X-Ref

Class: H5PContentStatus  - X-Ref

Class: H5PHubEndpoints  - X-Ref

createURL($endpoint)   X-Ref
No description

Class: H5PCore  - X-Ref

Functions and storage shared by the other H5P classes

__construct(H5PFrameworkInterface $H5PFramework, $path, $url, $language = 'en', $export = FALSE)   X-Ref
Constructor for the H5PCore

param: H5PFrameworkInterface $H5PFramework
param: string|H5PFileStorage $path H5P file storage directory or class.
param: string $url To file storage directory.
param: string $language code. Defaults to english.
param: boolean $export enabled?

saveContent($content, $contentMainId = NULL)   X-Ref
Save content and clear cache.

param: array $content
param: null|int $contentMainId
return: int Content ID

loadContent($id)   X-Ref
Load content.

param: int $id for content.
return: object

filterParameters(&$content)   X-Ref
Filter content run parameters, rebuild content dependency cache and export file.

param: Object|array $content
return: Object NULL on failure.

retrieveValue($params, $path, $delimiter='.')   X-Ref
Retrieve a value from a nested mixed array structure.

param: Array $params Array to be looked in.
param: String $path Supposed path to the value.
param: String [$delimiter='.'] Property delimiter within the path.
return: Object|NULL The object found or NULL.

textAddonMatches($params, $pattern, $found = false)   X-Ref
Determine if params contain any match.

param: {object} params - Parameters.
param: {string} [pattern] - Regular expression to identify pattern.
param: {boolean} [found] - Used for recursion.
return: {boolean} True, if params matches pattern.

generateContentSlug($content)   X-Ref
Generate content slug

param: array $content object
return: string unique content slug

loadContentDependencies($id, $type = NULL)   X-Ref
Find the files required for this content to work.

param: int $id for content.
param: null $type
return: array

getDependencyAssets($dependency, $type, &$assets, $prefix = '')   X-Ref
Get all dependency assets of the given type

param: array $dependency
param: string $type
param: array $assets
param: string $prefix Optional. Make paths relative to another dir.

getAssetsUrls($assets)   X-Ref
Combines path with cache buster / version.

param: array $assets
return: array

getDependenciesFiles($dependencies, $prefix = '')   X-Ref
Return file paths for all dependencies files.

param: array $dependencies
param: string $prefix Optional. Make paths relative to another dir.
return: array files.

getDependencyPath(array $dependency)   X-Ref
Get the path to the dependency.

param: array $dependency
return: string

getDependenciesHash(&$dependencies)   X-Ref
No description

loadLibrarySemantics($name, $majorVersion, $minorVersion)   X-Ref
Load library semantics.

param: $name
param: $majorVersion
param: $minorVersion
return: string

loadLibrary($name, $majorVersion, $minorVersion)   X-Ref
Load library.

param: $name
param: $majorVersion
param: $minorVersion
return: array or null.

deleteLibrary($libraryId)   X-Ref
Deletes a library

param: stdClass $libraryId

findLibraryDependencies(&$dependencies, $library, $nextWeight = 1, $editor = FALSE)   X-Ref
Recursive. Goes through the dependency tree for the given library and
adds all the dependencies to the given array in a flat format.

param: $dependencies
param: array $library To find all dependencies for.
param: int $nextWeight An integer determining the order of the libraries
param: bool $editor Used internally to force all preloaded sub dependencies
return: int

isSameVersion($library, $dependency)   X-Ref
Check if a library is of the version we're looking for

Same version means that the majorVersion and minorVersion is the same

param: array $library
param: array $dependency
return: boolean

deleteFileTree($dir)   X-Ref
Recursive function for removing directories.

param: string $dir
return: boolean

libraryToString($library, $folderName = FALSE)   X-Ref
Writes library data as string on the form {machineName} {majorVersion}.{minorVersion}

param: array $library
param: boolean $folderName
return: string

libraryFromString($libraryString)   X-Ref
Parses library data from a string on the form {machineName} {majorVersion}.{minorVersion}

param: string $libraryString
return: array|FALSE

determineEmbedType($contentEmbedType, $libraryEmbedTypes)   X-Ref
Determine the correct embed type to use.

param: $contentEmbedType
param: $libraryEmbedTypes
return: string 'div' or 'iframe'.

libraryVersion($library)   X-Ref
Get the absolute version for the library as a human readable string.

param: object $library
return: string

getUpgrades($library, $versions)   X-Ref
Determine which versions content with the given library can be upgraded to.

param: object $library
param: array $versions
return: array

snakeToCamel($arr, $obj = false)   X-Ref
Converts all the properties of the given object or array from
snake_case to camelCase. Useful after fetching data from the database.

Note that some databases does not support camelCase.

param: mixed $arr input
param: boolean $obj return object
return: mixed object or array

detectSiteType()   X-Ref
Detects if the site was accessed from localhost,
through a local network or from the internet.


getLibrariesInstalled()   X-Ref
Get a list of installed libraries, different minor versions will
return separate entries.

return: array

combineArrayValues($inputs)   X-Ref
Easy way to combine similar data sets.

param: array $inputs Multiple arrays with data
return: array

fetchLibrariesMetadata($fetchingDisabled = FALSE, $onlyRegister = false)   X-Ref
Communicate with H5P.org and get content type cache. Each platform
implementation is responsible for invoking this, eg using cron

param: bool $fetchingDisabled
param: bool $onlyRegister Only register site with H5P.org
return: bool|object Returns endpoint data if found, otherwise FALSE

getStorableDisplayOptions(&$sources, $current)   X-Ref
Create representation of display options as int

param: array $sources
param: int $current
return: int

getDisplayOptionsForEdit($disable = NULL)   X-Ref
Determine display options visibility and value on edit

param: int $disable
return: array

setDisplayOptionOverrides($option_name, $permission, $id, &$value)   X-Ref
Helper function used to figure out embed & download behaviour

param: string $option_name
param: H5PPermission $permission
param: int $id
param: bool &$value

getDisplayOptionsForView($disable, $id)   X-Ref
Determine display option visibility when viewing H5P

param: int $display_options
param: int  $id Might be content id or user id.
return: array

getDisplayOptionsAsArray($disable)   X-Ref
Convert display options as single byte to array

param: int $disable
return: array

getLibraryId($library, $libString = NULL)   X-Ref
Small helper for getting the library's ID.

param: array $library
param: string [$libString]
return: int Identifier, or FALSE if non-existent

slugify($input)   X-Ref
Convert strings of text into simple kebab case slugs.
Very useful for readable urls etc.

param: string $input
return: string

ajaxSuccess($data = NULL, $only_data = FALSE)   X-Ref
Makes it easier to print response when AJAX request succeeds.

param: mixed $data

ajaxError($message = NULL, $error_code = NULL, $status_code = NULL, $details = NULL)   X-Ref
Makes it easier to print response when AJAX request fails.
Will exit after printing error.

param: string $message A human readable error message
param: string $error_code An machine readable error code that a client
param: null|int $status_code Http response code
param: array [$details=null] Better description of the error and possible which action to take

printJson($data, $status_code = NULL)   X-Ref
Print JSON headers with UTF-8 charset and json encode response data.
Makes it easier to respond using JSON.

param: mixed $data
param: null|int $status_code Http response code

createToken($action)   X-Ref
Get a new H5P security token for the given action.

param: string $action
return: string token

getTimeFactor()   X-Ref
Create a time based number which is unique for each 12 hour.

return: int

hashToken($action, $time_factor)   X-Ref
Generate a unique hash string based on action, time and token

param: string $action
param: int $time_factor
return: string

validToken($action, $token)   X-Ref
Verify if the given token is valid for the given action.

param: string $action
param: string $token
return: boolean valid token

updateContentTypeCache($postData = NULL)   X-Ref
Update content type cache

param: object $postData Data sent to the hub
return: bool|object Returns endpoint data if found, otherwise FALSE

updateContentHubMetadataCache($lang = 'en')   X-Ref
Update content hub metadata cache


getUpdatedContentHubMetadataCache($lang = 'en')   X-Ref
Get updated content hub metadata cache

param: string  $lang Language as ISO 639-1 code
return: JsonSerializable|string

checkSetupErrorMessage()   X-Ref
Check if the current server setup is valid and set error messages

return: object Setup object with errors and disable hub properties

checkSetupForRequirements()   X-Ref
Check that all H5P requirements for the server setup is met.


returnBytes($val)   X-Ref
Return bytes from php_ini string value

param: string $val
return: int|string

mayUpdateLibraries($set = null)   X-Ref
Check if the current user has permission to update and install new
libraries.

param: bool [$set] Optional, sets the permission
return: bool

getLocalization()   X-Ref
Provide localization for the Core JS

return: array

hubRetrieveContent($id)   X-Ref
Publish content on the H5P Hub.

param: bigint $id
return: stdClass

hubPublishContent($data, $files, $content_hub_id = NULL)   X-Ref
Publish content on the H5P Hub.

param: array $data Data from content publishing process
param: array $files Files to upload with the content publish
param: bigint $content_hub_id For updating existing content
return: stdClass

hubGetAuthorizationHeader()   X-Ref
Creates the authorization header needed to access the private parts of
the H5P Hub.

return: string

hubUnpublishContent($hubId)   X-Ref
Unpublish content from content hub

param: integer  $hubId  Content hub id
return: bool True if successful

hubSyncContent($hubId, $exportPath)   X-Ref
Sync content with content hub

param: integer $hubId Content hub id
param: string $exportPath Export path where .h5p for content can be found
return: bool

hubAccountInfo()   X-Ref
Fetch account info for our site from the content hub

return: array|bool|string False if account is not setup, otherwise data

hubRegisterAccount($formData, $logo)   X-Ref
Register account

param: array $formData Form data. Should include: name, email, description,
param: object $logo Input image
return: array

getHubContentStatus($hubContentId, $syncStatus)   X-Ref
Get status of content from content hub

param: string $hubContentId
param: int $syncStatus
return: false|int Returns a new H5PContentStatus if successful, else false

Class: H5PContentValidator  - X-Ref

Functions for validating basic types from H5P library semantics.

__construct($H5PFramework, $H5PCore)   X-Ref
Constructor for the H5PContentValidator

param: object $H5PFramework
param: object $H5PCore

addon($library)   X-Ref
Add Addon library.


getDependencies()   X-Ref
Get the flat dependency tree.

return: array

validateMetadata($metadata)   X-Ref
Validate metadata

param: array $metadata
return: array Validated & filtered

validateText(&$text, $semantics)   X-Ref
Validate given text value against text semantics.

param: $text
param: $semantics

validateContentFiles($contentPath, $isLibrary = FALSE)   X-Ref
Validates content files

param: string $contentPath
param: bool $isLibrary
return: bool TRUE if all files are valid

validateNumber(&$number, $semantics)   X-Ref
Validate given value against number semantics

param: $number
param: $semantics

validateBoolean(&$bool)   X-Ref
Validate given value against boolean semantics

param: $bool
return: bool

validateSelect(&$select, $semantics)   X-Ref
Validate select values

param: $select
param: $semantics

validateList(&$list, $semantics)   X-Ref
Validate given list value against list semantics.
Will recurse into validating each item in the list according to the type.

param: $list
param: $semantics

_validateFilelike(&$file, $semantics, $typeValidKeys = array()   X-Ref
Validate a file like object, such as video, image, audio and file.

param: $file
param: $semantics
param: array $typeValidKeys

validateFile(&$file, $semantics)   X-Ref
Validate given file data

param: $file
param: $semantics

validateImage(&$image, $semantics)   X-Ref
Validate given image data

param: $image
param: $semantics

validateVideo(&$video, $semantics)   X-Ref
Validate given video data

param: $video
param: $semantics

validateAudio(&$audio, $semantics)   X-Ref
Validate given audio data

param: $audio
param: $semantics

validateGroup(&$group, $semantics, $flatten = TRUE)   X-Ref
Validate given group value against group semantics.
Will recurse into validating each group member.

param: $group
param: $semantics
param: bool $flatten

validateLibrary(&$value, $semantics)   X-Ref
Validate given library value against library semantics.
Check if provided library is within allowed options.

Will recurse into validating the library's semantics too.
param: $value
param: $semantics

filterParams(&$params, $whitelist)   X-Ref
Check params for a whitelist of allowed properties

param: array/object $params
param: array $whitelist

filter_xss($string, $allowed_tags = array('a', 'em', 'strong', 'cite', 'blockquote', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd')   X-Ref
Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities.

Based on kses by Ulf Harnhammar, see http://sourceforge.net/projects/kses.
For examples of various XSS attacks, see: http://ha.ckers.org/xss.html.

This code does four things:
- Removes characters and constructs that can trick browsers.
- Makes sure all HTML entities are well-formed.
- Makes sure all HTML tags and attributes are well-formed.
- Makes sure no HTML tags contain URLs with a disallowed protocol (e.g.
javascript:).

param: $string
param: array $allowed_tags
param: bool $allowedStyles
return: mixed|string An XSS safe version of $string, or an empty string if $string is not

_filter_xss_split($m, $store = FALSE)   X-Ref
Processes an HTML tag.

param: $m
param: bool $store
return: string If the element isn't allowed, an empty string. Otherwise, the cleaned up

_filter_xss_attributes($attr, $allowedStyles = FALSE)   X-Ref
Processes a string of HTML attributes.

param: $attr
param: array|bool|object $allowedStyles
return: array Cleaned up version of the HTML attributes.

filter_xss_bad_protocol($string, $decode = TRUE)   X-Ref
Processes an HTML attribute value and strips dangerous protocols from URLs.

param: $string
param: bool $decode
return: string Cleaned up and HTML-escaped version of $string.

_strip_dangerous_protocols($uri)   X-Ref
Strips dangerous protocols (e.g. 'javascript:') from a URI.

This function must be called for all URIs within user-entered input prior
to being output to an HTML attribute value. It is often called as part of
check_url() or filter_xss(), but those functions return an HTML-encoded
string, so this function can be called independently when the output needs to
be a plain-text string for passing to t(), l(), drupal_attributes(), or
another function that will call check_plain() separately.

param: $uri
return: string A plain-text URI stripped of dangerous protocols. As with all plain-text

getMetadataSemantics()   X-Ref
No description

getCopyrightSemantics()   X-Ref
No description