Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
Moodle\H5PCore Class Reference

Functions and storage shared by the other H5P classes. More...

Inheritance diagram for Moodle\H5PCore:
core_h5p\core

Public Member Functions

 __construct (H5PFrameworkInterface $H5PFramework, $path, $url, $language='en', $export=FALSE)
 Constructor for the H5PCore.
 
 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.
 
 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.
 
 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.
 
 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 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 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

 getDependencyPath (array $dependency)
 Get the path to the dependency.
 

Protected Attributes

string $fullPluginPath
 full path of plugin.
 

Detailed Description

Functions and storage shared by the other H5P classes.

Constructor & Destructor Documentation

◆ __construct()

Moodle\H5PCore::__construct ( H5PFrameworkInterface $H5PFramework,
$path,
$url,
$language = 'en',
$export = FALSE )

Constructor for the H5PCore.

Parameters
H5PFrameworkInterface$H5PFrameworkThe frameworks implementation of the H5PFrameworkInterface
string | H5PFileStorage$pathH5P file storage directory or class.
string$urlTo file storage directory.
string$languagecode. Defaults to english.
boolean$exportenabled?

Member Function Documentation

◆ ajaxError()

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

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 )
static

Makes it easier to print response when AJAX request succeeds.

Parameters
mixed$data
Since
1.6.0

◆ checkSetupErrorMessage()

Moodle\H5PCore::checkSetupErrorMessage ( )

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)

Easy way to combine similar data sets.

Parameters
array$inputsMultiple arrays with data
Return values
array

◆ createToken()

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

Get a new H5P security token for the given action.

Parameters
string$action
Return values
stringtoken

◆ deleteFileTree()

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

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)

Deletes a library.

Parameters
stdClass$libraryId

◆ determineEmbedType()

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

Determine the correct embed type to use.

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

◆ fetchLibrariesMetadata()

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

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)

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

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

◆ findLibraryDependencies()

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

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

◆ getAssetsUrls()

Moodle\H5PCore::getAssetsUrls ( $assets)

Combines path with cache buster / version.

Parameters
array$assets
Return values
array

◆ getDependenciesFiles()

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

Return file paths for all dependencies files.

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

◆ getDependencyPath()

Moodle\H5PCore::getDependencyPath ( array $dependency)
protected

Get the path to the dependency.

Parameters
array$dependency
Return values
string

Reimplemented in core_h5p\core.

◆ getDisplayOptionsForEdit()

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

Determine display options visibility and value on edit.

Parameters
int$disable
Return values
array

◆ getDisplayOptionsForView()

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

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 )

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 ( )

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

Return values
arrayA distinct array of installed libraries

◆ getLibraryId()

Moodle\H5PCore::getLibraryId ( $library,
$libString = NULL )

Small helper for getting the library's ID.

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

Reimplemented in core_h5p\core.

◆ getLocalization()

Moodle\H5PCore::getLocalization ( )

Provide localization for the Core JS.

Return values
array

◆ getStorableDisplayOptions()

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

Create representation of display options as int.

Parameters
array$sources
int$current
Return values
int

◆ getUpdatedContentHubMetadataCache()

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

Get updated content hub metadata cache.

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

◆ getUpgrades()

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

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

Parameters
object$library
array$versions
Return values
array

◆ hubAccountInfo()

Moodle\H5PCore::hubAccountInfo ( )

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 ( )

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 )

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 )

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)

Publish content on the H5P Hub.

Parameters
bigint$id
Return values
stdClass

◆ hubSyncContent()

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

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)

Unpublish content from content hub.

Parameters
integer$hubIdContent hub id
Return values
boolTrue if successful

◆ isSameVersion()

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

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)
static

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)
static

Get the name of a library's folder name.

Return values
string

◆ libraryToString()

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

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)
static

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

Parameters
object$library
Return values
string

◆ loadContent()

Moodle\H5PCore::loadContent ( $id)

Load content.

Parameters
int$idfor content.
Return values
object

◆ loadContentDependencies()

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

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 )

Load library.

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

◆ loadLibrarySemantics()

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

Load library semantics.

Parameters
$name
$majorVersion
$minorVersion
Return values
string

◆ mayUpdateLibraries()

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

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

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

◆ returnBytes()

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

Return bytes from php_ini string value.

Parameters
string$val
Return values
int|string

◆ saveContent()

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

Save content and clear cache.

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

◆ slugify()

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

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 )
static

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)

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 )
static

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
static
Initial value:
= array(
'js/jquery.js',
'js/h5p-utils.js',
)

◆ $coreApi

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

◆ $disable

Moodle\H5PCore::$disable
static
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
static
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
static
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: