Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
Functions and storage shared by the other H5P classes. More...
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. | |
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. | |
Functions and storage shared by the other H5P classes.
Moodle\H5PCore::__construct | ( | H5PFrameworkInterface | $H5PFramework, |
$path, | |||
$url, | |||
$language = 'en', | |||
$export = FALSE ) |
Constructor for the H5PCore.
H5PFrameworkInterface | $H5PFramework | The frameworks implementation of the H5PFrameworkInterface |
string | H5PFileStorage | $path | H5P file storage directory or class. |
string | $url | To file storage directory. |
string | $language | code. Defaults to english. |
boolean | $export | enabled? |
|
static |
Makes it easier to print response when AJAX request fails.
Will exit after printing error.
string | $message | A human readable error message |
string | $error_code | An machine readable error code that a client should be able to interpret |
null | int | $status_code | Http response code |
array | [$details=null] Better description of the error and possible which action to take |
|
static |
Makes it easier to print response when AJAX request succeeds.
mixed | $data |
Moodle\H5PCore::checkSetupErrorMessage | ( | ) |
Check if the current server setup is valid and set error messages.
object | Setup object with errors and disable hub properties |
Moodle\H5PCore::combineArrayValues | ( | $inputs | ) |
Easy way to combine similar data sets.
array | $inputs | Multiple arrays with data |
array |
|
static |
Get a new H5P security token for the given action.
string | $action |
string | token |
|
static |
Recursive function for removing directories.
string | $dir | Path to the directory we'll be deleting |
boolean | Indicates if the directory existed. |
Moodle\H5PCore::deleteLibrary | ( | $libraryId | ) |
Deletes a library.
stdClass | $libraryId |
|
static |
Determine the correct embed type to use.
$contentEmbedType | |
$libraryEmbedTypes |
string | 'div' or 'iframe'. |
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
bool | $fetchingDisabled | |
bool | $onlyRegister | Only register site with H5P.org |
bool|object | Returns endpoint data if found, otherwise FALSE |
Moodle\H5PCore::filterParameters | ( | & | $content | ) |
Filter content run parameters, rebuild content dependency cache and export file.
Object | array | $content |
Object | NULL on failure. |
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.
$dependencies | ||
array | $library | To find all dependencies for. |
int | $nextWeight | An integer determining the order of the libraries when they are loaded |
bool | $editor | Used internally to force all preloaded sub dependencies of an editor dependency to be editor dependencies. |
int |
Moodle\H5PCore::getAssetsUrls | ( | $assets | ) |
Combines path with cache buster / version.
array | $assets |
array |
Moodle\H5PCore::getDependenciesFiles | ( | $dependencies, | |
$prefix = '' ) |
Return file paths for all dependencies files.
array | $dependencies | |
string | $prefix | Optional. Make paths relative to another dir. |
array | files. |
|
protected |
Get the path to the dependency.
array | $dependency |
string |
Reimplemented in core_h5p\core.
Moodle\H5PCore::getDisplayOptionsForEdit | ( | $disable = NULL | ) |
Determine display options visibility and value on edit.
int | $disable |
array |
Moodle\H5PCore::getDisplayOptionsForView | ( | $disable, | |
$id ) |
Determine display option visibility when viewing H5P.
int | $display_options | |
int | $id | Might be content id or user id. Depends on what the platform needs to be able to determine permissions. |
array |
Moodle\H5PCore::getHubContentStatus | ( | $hubContentId, | |
$syncStatus ) |
Get status of content from content hub.
string | $hubContentId | |
int | $syncStatus |
false|int | Returns a new H5PContentStatus if successful, else false |
Moodle\H5PCore::getLibrariesInstalled | ( | ) |
Get a list of installed libraries, different minor versions will return separate entries.
array | A distinct array of installed libraries |
Moodle\H5PCore::getLibraryId | ( | $library, | |
$libString = NULL ) |
Small helper for getting the library's ID.
array | $library | |
string | [$libString] |
int | Identifier, or FALSE if non-existent |
Reimplemented in core_h5p\core.
Moodle\H5PCore::getLocalization | ( | ) |
Provide localization for the Core JS.
array |
Moodle\H5PCore::getStorableDisplayOptions | ( | & | $sources, |
$current ) |
Create representation of display options as int.
array | $sources | |
int | $current |
int |
Moodle\H5PCore::getUpdatedContentHubMetadataCache | ( | $lang = 'en' | ) |
Get updated content hub metadata cache.
string | $lang | Language as ISO 639-1 code |
JsonSerializable|string |
Moodle\H5PCore::getUpgrades | ( | $library, | |
$versions ) |
Determine which versions content with the given library can be upgraded to.
object | $library | |
array | $versions |
array |
Moodle\H5PCore::hubAccountInfo | ( | ) |
Fetch account info for our site from the content hub.
array|bool|string | False if account is not setup, otherwise data |
Moodle\H5PCore::hubGetAuthorizationHeader | ( | ) |
Creates the authorization header needed to access the private parts of the H5P Hub.
string |
Moodle\H5PCore::hubPublishContent | ( | $data, | |
$files, | |||
$content_hub_id = NULL ) |
Publish content on the H5P Hub.
array | $data | Data from content publishing process |
array | $files | Files to upload with the content publish |
bigint | $content_hub_id | For updating existing content |
stdClass |
Moodle\H5PCore::hubRegisterAccount | ( | $formData, | |
$logo ) |
Register account.
array | $formData | Form data. Should include: name, email, description, contact_person, phone, address, city, zip, country, remove_logo |
object | $logo | Input image |
array |
Moodle\H5PCore::hubRetrieveContent | ( | $id | ) |
Publish content on the H5P Hub.
bigint | $id |
stdClass |
Moodle\H5PCore::hubSyncContent | ( | $hubId, | |
$exportPath ) |
Sync content with content hub.
integer | $hubId | Content hub id |
string | $exportPath | Export path where .h5p for content can be found |
bool |
Moodle\H5PCore::hubUnpublishContent | ( | $hubId | ) |
Unpublish content from content hub.
integer | $hubId | Content hub id |
bool | True if successful |
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
array | $library | Data from library.json |
array | $dependency | Definition of what library we're looking for |
boolean | TRUE if the library is the same version as the dependency FALSE otherwise |
|
static |
Parses library data from a string on the form {machineName} {majorVersion}.
{minorVersion}
string | $libraryString | On the form {machineName} {majorVersion}.{minorVersion} |
array|FALSE | With 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" |
|
static |
Get the name of a library's folder name.
string |
|
static |
Writes library data as string on the form {machineName} {majorVersion}.
{minorVersion}
array | $library | With keys (machineName and/or name), majorVersion and minorVersion |
string | On the form {machineName} {majorVersion}.{minorVersion} |
|
static |
Get the absolute version for the library as a human readable string.
object | $library |
string |
Moodle\H5PCore::loadContent | ( | $id | ) |
Load content.
int | $id | for content. |
object |
Moodle\H5PCore::loadContentDependencies | ( | $id, | |
$type = NULL ) |
Find the files required for this content to work.
int | $id | for content. |
null | $type |
array |
Moodle\H5PCore::loadLibrary | ( | $name, | |
$majorVersion, | |||
$minorVersion ) |
Load library.
$name | |
$majorVersion | |
$minorVersion |
array | or null. |
Moodle\H5PCore::loadLibrarySemantics | ( | $name, | |
$majorVersion, | |||
$minorVersion ) |
Load library semantics.
$name | |
$majorVersion | |
$minorVersion |
string |
Moodle\H5PCore::mayUpdateLibraries | ( | $set = null | ) |
Check if the current user has permission to update and install new libraries.
bool | [$set] Optional, sets the permission |
bool |
|
static |
Return bytes from php_ini string value.
string | $val |
int|string |
Moodle\H5PCore::saveContent | ( | $content, | |
$contentMainId = NULL ) |
Save content and clear cache.
array | $content | |
null | int | $contentMainId |
int | Content ID |
|
static |
Convert strings of text into simple kebab case slugs.
Very useful for readable urls etc.
string | $input |
string |
|
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.
mixed | $arr | input |
boolean | $obj | return object |
mixed | object or array |
Moodle\H5PCore::updateContentTypeCache | ( | $postData = NULL | ) |
Update content type cache.
object | $postData | Data sent to the hub |
bool|object | Returns endpoint data if found, otherwise FALSE |
|
static |
Verify if the given token is valid for the given action.
string | $action | |
string | $token |
boolean | valid token |
|
static |
|
static |
|
static |
|
static |
|
static |