Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core_h5p\core Class Reference
Inheritance diagram for core_h5p\core:
Moodle\H5PCore

Public Member Functions

 __construct (H5PFrameworkInterface $framework, $path, string $url, string $language='en', bool $export=false)
 Constructor for core_h5p/core.
 
 checkSetupErrorMessage ()
 Check if the current server setup is valid and set error messages.
 
 checkSetupForRequirements ()
 Check that all H5P requirements for the server setup is met.
 
 combineArrayValues ($inputs)
 Easy way to combine similar data sets.
 
 deleteLibrary ($libraryId)
 Deletes a library.
 
 detectSiteType ()
 Detects if the site was accessed from localhost, through a local network or from the internet.
 
 fetch_content_type (array $library)
 Given an H5P content type machine name, fetch and install the required library from the official H5P repository.
 
 fetch_latest_content_types ()
 Fetch and install the latest H5P content types libraries from the official H5P repository.
 
 fetchLibrariesMetadata ($fetchingDisabled=FALSE, $onlyRegister=false)
 Communicate with H5P.org and get content type cache.
 
 filterParameters (&$content)
 Filter content run parameters, rebuild content dependency cache and export file.
 
 findLibraryDependencies (&$dependencies, $library, $nextWeight=1, $editor=FALSE)
 Recursive.
 
 get_api_endpoint (?string $library=null, string $endpoint='content')
 Get H5P endpoints.
 
 get_dependency_roots (int $id)
 Get the paths to the content dependencies.
 
 get_latest_content_types ()
 Get the latest version of the H5P content types available in the official repository.
 
 get_site_uuid ()
 Get the site UUID.
 
 getAssetsUrls ($assets)
 Combines path with cache buster / version.
 
 getDependenciesFiles ($dependencies, $prefix='')
 Return file paths for all dependencies files.
 
 getDisplayOptionsForEdit ($disable=NULL)
 Determine display options visibility and value on edit.
 
 getDisplayOptionsForView ($disable, $id)
 Determine display option visibility when viewing H5P.
 
 getHubContentStatus ($hubContentId, $syncStatus)
 Get status of content from content hub.
 
 getLibrariesInstalled ()
 Get a list of installed libraries, different minor versions will return separate entries.
 
 getLibraryId ($library, $libString=null)
 Small helper for getting the library's ID.
 
 getLocalization ()
 Provide localization for the Core JS.
 
 getStorableDisplayOptions (&$sources, $current)
 Create representation of display options as int.
 
 getUpdatedContentHubMetadataCache ($lang='en')
 Get updated content hub metadata cache.
 
 getUpgrades ($library, $versions)
 Determine which versions content with the given library can be upgraded to.
 
 hubAccountInfo ()
 Fetch account info for our site from the content hub.
 
 hubGetAuthorizationHeader ()
 Creates the authorization header needed to access the private parts of the H5P Hub.
 
 hubPublishContent ($data, $files, $content_hub_id=NULL)
 Publish content on the H5P Hub.
 
 hubRegisterAccount ($formData, $logo)
 Register account.
 
 hubRetrieveContent ($id)
 Publish content on the H5P Hub.
 
 hubSyncContent ($hubId, $exportPath)
 Sync content with content hub.
 
 hubUnpublishContent ($hubId)
 Unpublish content from content hub.
 
 is_required_core_api ($coreapi)
 Checks that the required H5P core API version or higher is installed.
 
 isSameVersion ($library, $dependency)
 Check if a library is of the version we're looking for.
 
 loadContent ($id)
 Load content.
 
 loadContentDependencies ($id, $type=NULL)
 Find the files required for this content to work.
 
 loadLibrary ($name, $majorVersion, $minorVersion)
 Load library.
 
 loadLibrarySemantics ($name, $majorVersion, $minorVersion)
 Load library semantics.
 
 mayUpdateLibraries ($set=null)
 Check if the current user has permission to update and install new libraries.
 
 saveContent ($content, $contentMainId=NULL)
 Save content and clear cache.
 
 updateContentHubMetadataCache ($lang='en')
 Update content hub metadata cache.
 
 updateContentTypeCache ($postData=NULL)
 Update content type cache.
 

Static Public Member Functions

static ajaxError ($message=NULL, $error_code=NULL, $status_code=NULL, $details=NULL)
 Makes it easier to print response when AJAX request fails.
 
static ajaxSuccess ($data=NULL, $only_data=FALSE)
 Makes it easier to print response when AJAX request succeeds.
 
static createToken ($action)
 Get a new H5P security token for the given action.
 
static deleteFileTree ($dir)
 Recursive function for removing directories.
 
static determineEmbedType ($contentEmbedType, $libraryEmbedTypes)
 Determine the correct embed type to use.
 
static get_scripts ()
 Get the list of JS scripts to include on the page.
 
static libraryFromString ($libraryString)
 Parses library data from a string on the form {machineName} {majorVersion}.
 
static libraryToFolderName ($library)
 Get the name of a library's folder name.
 
static libraryToString ($library)
 Writes library data as string on the form {machineName} {majorVersion}.
 
static libraryVersion ($library)
 Get the absolute version for the library as a human readable string.
 
static record_to_string (stdClass $record, bool $foldername=false)
 Get the library string from a DB library record.
 
static returnBytes ($val)
 Return bytes from php_ini string value.
 
static slugify ($input)
 Convert strings of text into simple kebab case slugs.
 
static snakeToCamel ($arr, $obj=false)
 Converts all the properties of the given object or array from snake_case to camelCase.
 
static validToken ($action, $token)
 Verify if the given token is valid for the given action.
 

Public Attributes

bool $aggregateAssets
 aggregated files for assets.
 
 $contentJsonData
 
int $development_mode
 evelopment mode.
 
 $disableFileCheck
 
 $fs
 
 $h5pD
 
 $h5pF
 
 $librariesJsonData
 
 $mainJsonData
 
string $relativePathRegExp
 regex for converting copied files paths.
 
string $url
 
const DISABLE_ABOUT = 16
 
const DISABLE_COPYRIGHT = 8
 
const DISABLE_DOWNLOAD = 2
 
const DISABLE_EMBED = 4
 
const DISABLE_FRAME = 1
 
const DISABLE_NONE = 0
 
const DISPLAY_OPTION_ABOUT = 'icon'
 
const DISPLAY_OPTION_COPY = 'copy'
 
const DISPLAY_OPTION_COPYRIGHT = 'copyright'
 
const DISPLAY_OPTION_DOWNLOAD = 'export'
 
const DISPLAY_OPTION_EMBED = 'embed'
 
const DISPLAY_OPTION_FRAME = 'frame'
 
const SECONDS_IN_WEEK = 604800
 

Static Public Attributes

static $adminScripts
 
static $coreApi
 
static $defaultContentWhitelist = 'json png jpg jpeg gif bmp tif tiff svg eot ttf woff woff2 otf webm mp4 ogg mp3 m4a wav txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile vtt webvtt gltf glb'
 
static $defaultLibraryWhitelistExtras = 'js css'
 
static $disable
 
static $scripts
 
static $styles
 

Protected Member Functions

 find_library (array $dependency)
 Get a particular dependency library.
 
 getDependencyPath (array $dependency)
 Get the path to the dependency.
 

Protected Attributes

string $fullPluginPath
 full path of plugin.
 
array $libraries
 The array containing all the present libraries.
 

Constructor & Destructor Documentation

◆ __construct()

core_h5p\core::__construct ( H5PFrameworkInterface $framework,
$path,
string $url,
string $language = 'en',
bool $export = false )

Constructor for core_h5p/core.

Parameters
H5PFrameworkInterface$frameworkThe frameworks implementation of the H5PFrameworkInterface
string | H5PFileStorage$pathThe H5P file storage directory or class
string$urlThe URL to the file storage directory
string$languageThe language code. Defaults to english
boolean$exportWhether export is enabled

Member Function Documentation

◆ ajaxError()

static Moodle\H5PCore::ajaxError ( $message = NULL,
$error_code = NULL,
$status_code = NULL,
$details = NULL )
staticinherited

Makes it easier to print response when AJAX request fails.

Will exit after printing error.

Parameters
string$messageA human readable error message
string$error_codeAn machine readable error code that a client should be able to interpret
null | int$status_codeHttp response code
array[$details=null] Better description of the error and possible which action to take
Since
1.6.0

◆ ajaxSuccess()

static Moodle\H5PCore::ajaxSuccess ( $data = NULL,
$only_data = FALSE )
staticinherited

Makes it easier to print response when AJAX request succeeds.

Parameters
mixed$data
Since
1.6.0

◆ checkSetupErrorMessage()

Moodle\H5PCore::checkSetupErrorMessage ( )
inherited

Check if the current server setup is valid and set error messages.

Return values
objectSetup object with errors and disable hub properties

◆ combineArrayValues()

Moodle\H5PCore::combineArrayValues ( $inputs)
inherited

Easy way to combine similar data sets.

Parameters
array$inputsMultiple arrays with data
Return values
array

◆ createToken()

static Moodle\H5PCore::createToken ( $action)
staticinherited

Get a new H5P security token for the given action.

Parameters
string$action
Return values
stringtoken

◆ deleteFileTree()

static Moodle\H5PCore::deleteFileTree ( $dir)
staticinherited

Recursive function for removing directories.

Parameters
string$dirPath to the directory we'll be deleting
Return values
booleanIndicates if the directory existed.

◆ deleteLibrary()

Moodle\H5PCore::deleteLibrary ( $libraryId)
inherited

Deletes a library.

Parameters
stdClass$libraryId

◆ determineEmbedType()

static Moodle\H5PCore::determineEmbedType ( $contentEmbedType,
$libraryEmbedTypes )
staticinherited

Determine the correct embed type to use.

Parameters
$contentEmbedType
$libraryEmbedTypes
Return values
string'div' or 'iframe'.

◆ fetch_content_type()

core_h5p\core::fetch_content_type ( array $library)

Given an H5P content type machine name, fetch and install the required library from the official H5P repository.

Parameters
array$libraryLibrary machineName, majorversion and minorversion.
Return values
int|nullReturns the id of the content type library installed, null otherwise.

◆ fetch_latest_content_types()

core_h5p\core::fetch_latest_content_types ( )

Fetch and install the latest H5P content types libraries from the official H5P repository.

If the latest version of a content type library is present in the system, nothing is done for that content type.

Return values
stdClass

◆ fetchLibrariesMetadata()

Moodle\H5PCore::fetchLibrariesMetadata ( $fetchingDisabled = FALSE,
$onlyRegister = false )
inherited

Communicate with H5P.org and get content type cache.

Each platform implementation is responsible for invoking this, eg using cron

Parameters
bool$fetchingDisabled
bool$onlyRegisterOnly register site with H5P.org
Return values
bool|objectReturns endpoint data if found, otherwise FALSE

◆ filterParameters()

Moodle\H5PCore::filterParameters ( & $content)
inherited

Filter content run parameters, rebuild content dependency cache and export file.

Parameters
Object | array$content
Return values
ObjectNULL on failure.

◆ find_library()

core_h5p\core::find_library ( array $dependency)
protected

Get a particular dependency library.

Parameters
array$dependencyAn array containing information of the dependency library
Return values
stdClass|nullThe library object if the library dependency exists, null otherwise

◆ findLibraryDependencies()

Moodle\H5PCore::findLibraryDependencies ( & $dependencies,
$library,
$nextWeight = 1,
$editor = FALSE )
inherited

Recursive.

Goes through the dependency tree for the given library and adds all the dependencies to the given array in a flat format.

Parameters
$dependencies
array$libraryTo find all dependencies for.
int$nextWeightAn integer determining the order of the libraries when they are loaded
bool$editorUsed internally to force all preloaded sub dependencies of an editor dependency to be editor dependencies.
Return values
int

◆ get_api_endpoint()

core_h5p\core::get_api_endpoint ( ?string $library = null,
string $endpoint = 'content' )

Get H5P endpoints.

If $endpoint = 'content' and $library is null, moodle_url is the endpoint of the latest version of the H5P content types; however, if $library is the machine name of a content type, moodle_url is the endpoint to download the content type. The SITES endpoint ($endpoint = 'site') may be use to get a site UUID or send site data.

Parameters
string | null$libraryThe machineName of the library whose endpoint is requested.
string$endpointThe endpoint required. Valid values: "site", "content".
Return values
moodle_urlThe endpoint moodle_url object.

◆ get_dependency_roots()

core_h5p\core::get_dependency_roots ( int $id)

Get the paths to the content dependencies.

Parameters
int$idThe H5P content ID
Return values
arrayAn array containing the path of each content dependency

◆ get_latest_content_types()

core_h5p\core::get_latest_content_types ( )

Get the latest version of the H5P content types available in the official repository.

Return values
stdClassAn object with 2 properties:
  • string error: error message when there is any problem, empty otherwise
  • array contentTypes: an object for each H5P content type with its information

◆ get_scripts()

static core_h5p\core::get_scripts ( )
static

Get the list of JS scripts to include on the page.

Return values
arrayThe array containg urls of the core JavaScript files

◆ get_site_uuid()

core_h5p\core::get_site_uuid ( )

Get the site UUID.

If site UUID is not defined, try to register the site.

return $string The site UUID, null if it is not set.

◆ getAssetsUrls()

Moodle\H5PCore::getAssetsUrls ( $assets)
inherited

Combines path with cache buster / version.

Parameters
array$assets
Return values
array

◆ getDependenciesFiles()

Moodle\H5PCore::getDependenciesFiles ( $dependencies,
$prefix = '' )
inherited

Return file paths for all dependencies files.

Parameters
array$dependencies
string$prefixOptional. Make paths relative to another dir.
Return values
arrayfiles.

◆ getDependencyPath()

core_h5p\core::getDependencyPath ( array $dependency)
protected

Get the path to the dependency.

Parameters
array$dependencyAn array containing the information of the requested dependency library
Return values
stringThe path to the dependency library

Reimplemented from Moodle\H5PCore.

◆ getDisplayOptionsForEdit()

Moodle\H5PCore::getDisplayOptionsForEdit ( $disable = NULL)
inherited

Determine display options visibility and value on edit.

Parameters
int$disable
Return values
array

◆ getDisplayOptionsForView()

Moodle\H5PCore::getDisplayOptionsForView ( $disable,
$id )
inherited

Determine display option visibility when viewing H5P.

Parameters
int$display_options
int$idMight be content id or user id. Depends on what the platform needs to be able to determine permissions.
Return values
array

◆ getHubContentStatus()

Moodle\H5PCore::getHubContentStatus ( $hubContentId,
$syncStatus )
inherited

Get status of content from content hub.

Parameters
string$hubContentId
int$syncStatus
Return values
false|intReturns a new H5PContentStatus if successful, else false

◆ getLibrariesInstalled()

Moodle\H5PCore::getLibrariesInstalled ( )
inherited

Get a list of installed libraries, different minor versions will return separate entries.

Return values
arrayA distinct array of installed libraries

◆ getLibraryId()

core_h5p\core::getLibraryId ( $library,
$libString = null )

Small helper for getting the library's ID.

This method is rewritten to use MUC (instead of an static variable which causes some problems with PHPUnit).

Parameters
array$library
string$libString
Return values
intIdentifier, or FALSE if non-existent

Reimplemented from Moodle\H5PCore.

◆ getLocalization()

Moodle\H5PCore::getLocalization ( )
inherited

Provide localization for the Core JS.

Return values
array

◆ getStorableDisplayOptions()

Moodle\H5PCore::getStorableDisplayOptions ( & $sources,
$current )
inherited

Create representation of display options as int.

Parameters
array$sources
int$current
Return values
int

◆ getUpdatedContentHubMetadataCache()

Moodle\H5PCore::getUpdatedContentHubMetadataCache ( $lang = 'en')
inherited

Get updated content hub metadata cache.

Parameters
string$langLanguage as ISO 639-1 code
Return values
JsonSerializable|string

◆ getUpgrades()

Moodle\H5PCore::getUpgrades ( $library,
$versions )
inherited

Determine which versions content with the given library can be upgraded to.

Parameters
object$library
array$versions
Return values
array

◆ hubAccountInfo()

Moodle\H5PCore::hubAccountInfo ( )
inherited

Fetch account info for our site from the content hub.

Return values
array|bool|stringFalse if account is not setup, otherwise data

◆ hubGetAuthorizationHeader()

Moodle\H5PCore::hubGetAuthorizationHeader ( )
inherited

Creates the authorization header needed to access the private parts of the H5P Hub.

Return values
string

◆ hubPublishContent()

Moodle\H5PCore::hubPublishContent ( $data,
$files,
$content_hub_id = NULL )
inherited

Publish content on the H5P Hub.

Parameters
array$dataData from content publishing process
array$filesFiles to upload with the content publish
bigint$content_hub_idFor updating existing content
Return values
stdClass

◆ hubRegisterAccount()

Moodle\H5PCore::hubRegisterAccount ( $formData,
$logo )
inherited

Register account.

Parameters
array$formDataForm data. Should include: name, email, description, contact_person, phone, address, city, zip, country, remove_logo
object$logoInput image
Return values
array

◆ hubRetrieveContent()

Moodle\H5PCore::hubRetrieveContent ( $id)
inherited

Publish content on the H5P Hub.

Parameters
bigint$id
Return values
stdClass

◆ hubSyncContent()

Moodle\H5PCore::hubSyncContent ( $hubId,
$exportPath )
inherited

Sync content with content hub.

Parameters
integer$hubIdContent hub id
string$exportPathExport path where .h5p for content can be found
Return values
bool

◆ hubUnpublishContent()

Moodle\H5PCore::hubUnpublishContent ( $hubId)
inherited

Unpublish content from content hub.

Parameters
integer$hubIdContent hub id
Return values
boolTrue if successful

◆ is_required_core_api()

core_h5p\core::is_required_core_api ( $coreapi)

Checks that the required H5P core API version or higher is installed.

Parameters
stdClass$coreapiObject with properties major and minor for the core API version required.
Return values
boolTrue if the required H5P core API version is installed. False if not.

◆ isSameVersion()

Moodle\H5PCore::isSameVersion ( $library,
$dependency )
inherited

Check if a library is of the version we're looking for.

Same version means that the majorVersion and minorVersion is the same

Parameters
array$libraryData from library.json
array$dependencyDefinition of what library we're looking for
Return values
booleanTRUE if the library is the same version as the dependency FALSE otherwise

◆ libraryFromString()

static Moodle\H5PCore::libraryFromString ( $libraryString)
staticinherited

Parses library data from a string on the form {machineName} {majorVersion}.

{minorVersion}

Parameters
string$libraryStringOn the form {machineName} {majorVersion}.{minorVersion}
Return values
array|FALSEWith keys machineName, majorVersion and minorVersion. Returns FALSE only if string is not parsable in the normal library string formats "Lib.Name-x.y" or "Lib.Name x.y"

◆ libraryToFolderName()

static Moodle\H5PCore::libraryToFolderName ( $library)
staticinherited

Get the name of a library's folder name.

Return values
string

◆ libraryToString()

static Moodle\H5PCore::libraryToString ( $library)
staticinherited

Writes library data as string on the form {machineName} {majorVersion}.

{minorVersion}

Parameters
array$libraryWith keys (machineName and/or name), majorVersion and minorVersion
Return values
stringOn the form {machineName} {majorVersion}.{minorVersion}

◆ libraryVersion()

static Moodle\H5PCore::libraryVersion ( $library)
staticinherited

Get the absolute version for the library as a human readable string.

Parameters
object$library
Return values
string

◆ loadContent()

Moodle\H5PCore::loadContent ( $id)
inherited

Load content.

Parameters
int$idfor content.
Return values
object

◆ loadContentDependencies()

Moodle\H5PCore::loadContentDependencies ( $id,
$type = NULL )
inherited

Find the files required for this content to work.

Parameters
int$idfor content.
null$type
Return values
array

◆ loadLibrary()

Moodle\H5PCore::loadLibrary ( $name,
$majorVersion,
$minorVersion )
inherited

Load library.

Parameters
$name
$majorVersion
$minorVersion
Return values
arrayor null.

◆ loadLibrarySemantics()

Moodle\H5PCore::loadLibrarySemantics ( $name,
$majorVersion,
$minorVersion )
inherited

Load library semantics.

Parameters
$name
$majorVersion
$minorVersion
Return values
string

◆ mayUpdateLibraries()

Moodle\H5PCore::mayUpdateLibraries ( $set = null)
inherited

Check if the current user has permission to update and install new libraries.

Parameters
bool[$set] Optional, sets the permission
Return values
bool

◆ record_to_string()

static core_h5p\core::record_to_string ( stdClass $record,
bool $foldername = false )
static

Get the library string from a DB library record.

Parameters
stdClass$recordThe DB library record.
bool$foldernameIf true, use hyphen instead of space in returned string.
Return values
stringThe string name on the form {machineName} {majorVersion}.{minorVersion}.

◆ returnBytes()

static Moodle\H5PCore::returnBytes ( $val)
staticinherited

Return bytes from php_ini string value.

Parameters
string$val
Return values
int|string

◆ saveContent()

Moodle\H5PCore::saveContent ( $content,
$contentMainId = NULL )
inherited

Save content and clear cache.

Parameters
array$content
null | int$contentMainId
Return values
intContent ID

◆ slugify()

static Moodle\H5PCore::slugify ( $input)
staticinherited

Convert strings of text into simple kebab case slugs.

Very useful for readable urls etc.

Parameters
string$input
Return values
string

◆ snakeToCamel()

static Moodle\H5PCore::snakeToCamel ( $arr,
$obj = false )
staticinherited

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.

Parameters
mixed$arrinput
boolean$objreturn object
Return values
mixedobject or array

◆ updateContentTypeCache()

Moodle\H5PCore::updateContentTypeCache ( $postData = NULL)
inherited

Update content type cache.

Parameters
object$postDataData sent to the hub
Return values
bool|objectReturns endpoint data if found, otherwise FALSE

◆ validToken()

static Moodle\H5PCore::validToken ( $action,
$token )
staticinherited

Verify if the given token is valid for the given action.

Parameters
string$action
string$token
Return values
booleanvalid token

Member Data Documentation

◆ $adminScripts

Moodle\H5PCore::$adminScripts
staticinherited
Initial value:
= array(
'js/jquery.js',
'js/h5p-utils.js',
)

◆ $coreApi

Moodle\H5PCore::$coreApi
staticinherited
Initial value:
= array(
'majorVersion' => 1,
'minorVersion' => 26
)

◆ $disable

Moodle\H5PCore::$disable
staticinherited
Initial value:
= array(
self::DISABLE_FRAME => self::DISPLAY_OPTION_FRAME,
self::DISABLE_DOWNLOAD => self::DISPLAY_OPTION_DOWNLOAD,
self::DISABLE_EMBED => self::DISPLAY_OPTION_EMBED,
self::DISABLE_COPYRIGHT => self::DISPLAY_OPTION_COPYRIGHT
)

◆ $scripts

Moodle\H5PCore::$scripts
staticinherited
Initial value:
= array(
'js/jquery.js',
'js/h5p.js',
'js/h5p-event-dispatcher.js',
'js/h5p-x-api-event.js',
'js/h5p-x-api.js',
'js/h5p-content-type.js',
'js/h5p-confirmation-dialog.js',
'js/h5p-action-bar.js',
'js/request-queue.js',
'js/h5p-tooltip.js',
)

◆ $styles

Moodle\H5PCore::$styles
staticinherited
Initial value:
= array(
'styles/h5p.css',
'styles/h5p-confirmation-dialog.css',
'styles/h5p-core-button.css',
'styles/h5p-tooltip.css',
)

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