Resolve conflict
commit
73c9f2768d
287
h5p.classes.php
287
h5p.classes.php
|
@ -4,6 +4,16 @@
|
|||
*/
|
||||
interface H5PFrameworkInterface {
|
||||
|
||||
/**
|
||||
* Returns info for the current platform
|
||||
*
|
||||
* @return array
|
||||
* An associative array containing:
|
||||
* - name: The name of the plattform, for instance "Wordpress"
|
||||
* - version: The version of the pattform, for instance "4.0"
|
||||
*/
|
||||
public function getPlatformInfo();
|
||||
|
||||
/**
|
||||
* Show the user an error message
|
||||
*
|
||||
|
@ -33,59 +43,82 @@ interface H5PFrameworkInterface {
|
|||
* - @variable: escape plain text to HTML
|
||||
* - %variable: escape text and theme as a placeholder for user-submitted
|
||||
* content
|
||||
* @return string Translated string
|
||||
* @return string
|
||||
* Translated string
|
||||
*/
|
||||
public function t($message, $replacements = array());
|
||||
|
||||
/**
|
||||
* Get the Path to the last uploaded h5p
|
||||
*
|
||||
* @return string Path to the folder where the last uploaded h5p for this session is located.
|
||||
* @return string
|
||||
* Path to the folder where the last uploaded h5p for this session is located.
|
||||
*/
|
||||
public function getUploadedH5pFolderPath();
|
||||
|
||||
/**
|
||||
* @return string Path to the folder where all h5p files are stored
|
||||
* @return string
|
||||
* Path to the folder where all h5p files are stored
|
||||
*/
|
||||
public function getH5pPath();
|
||||
|
||||
/**
|
||||
* Get the path to the last uploaded h5p file
|
||||
*
|
||||
* @return string Path to the last uploaded h5p
|
||||
* @return string
|
||||
* Path to the last uploaded h5p
|
||||
*/
|
||||
public function getUploadedH5pPath();
|
||||
|
||||
/**
|
||||
* Get the list of the current installed libraries
|
||||
* Get a list of the current installed libraries
|
||||
*
|
||||
* @return array Associative array containg one item per machine name. This item contains an array of libraries.
|
||||
* @return array
|
||||
* Associative array containg one entry per machine name.
|
||||
* For each machineName there is a list of libraries(with different versions)
|
||||
*/
|
||||
public function loadLibraries();
|
||||
|
||||
/**
|
||||
* Saving the unsupported library list
|
||||
*
|
||||
* @param array A list of unsupported libraries
|
||||
* @param array
|
||||
* A list of unsupported libraries. Each list entry contains:
|
||||
* - name: MachineName for the library
|
||||
* - downloadUrl: URL to a location a new version of the library may be downloaded from
|
||||
* - currentVersion: The unsupported version of the library installed on the system.
|
||||
* This is an associative array containing:
|
||||
* - major: The major version of the library
|
||||
* - minor: The minor version of the library
|
||||
* - patch: The patch version of the library
|
||||
*/
|
||||
public function setUnsupportedLibraries($libraries);
|
||||
|
||||
/**
|
||||
* Returns unsupported libraries
|
||||
*
|
||||
* @return array A list of the unsupported libraries
|
||||
* @return array
|
||||
* A list of unsupported libraries. Each entry contains an associative array with:
|
||||
* - name: MachineName for the library
|
||||
* - downloadUrl: URL to a location a new version of the library may be downloaded from
|
||||
* - currentVersion: The unsupported version of the library installed on the system.
|
||||
* This is an associative array containing:
|
||||
* - major: The major version of the library
|
||||
* - minor: The minor version of the library
|
||||
* - patch: The patch version of the library
|
||||
*/
|
||||
public function getUnsupportedLibraries();
|
||||
|
||||
/**
|
||||
* Returns the URL to the library admin page
|
||||
*
|
||||
* @return string URL to admin page
|
||||
* @return string
|
||||
* URL to admin page
|
||||
*/
|
||||
public function getAdminUrl();
|
||||
|
||||
/**
|
||||
* Get id to an excisting library
|
||||
* Get id to an existing library
|
||||
*
|
||||
* @param string $machineName
|
||||
* The librarys machine name
|
||||
|
@ -104,8 +137,12 @@ interface H5PFrameworkInterface {
|
|||
* The default extension list is part of h5p, but admins should be allowed to modify it
|
||||
*
|
||||
* @param boolean $isLibrary
|
||||
* TRUE if this is the whitelist for a library. FALSE if it is the whitelist
|
||||
* for the content folder we are getting
|
||||
* @param string $defaultContentWhitelist
|
||||
* A string of file extensions separated by whitespace
|
||||
* @param string $defaultLibraryWhitelist
|
||||
* A string of file extensions separated by whitespace
|
||||
*/
|
||||
public function getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibraryWhitelist);
|
||||
|
||||
|
@ -113,9 +150,13 @@ interface H5PFrameworkInterface {
|
|||
* Is the library a patched version of an existing library?
|
||||
*
|
||||
* @param object $library
|
||||
* The library data for a library we are checking
|
||||
* An associateve array containing:
|
||||
* - machineName: The library machineName
|
||||
* - majorVersion: The librarys majorVersion
|
||||
* - minorVersion: The librarys minorVersion
|
||||
* - patchVersion: The librarys patchVersion
|
||||
* @return boolean
|
||||
* TRUE if the library is a patched version of an excisting library
|
||||
* TRUE if the library is a patched version of an existing library
|
||||
* FALSE otherwise
|
||||
*/
|
||||
public function isPatchedLibrary($library);
|
||||
|
@ -144,23 +185,53 @@ interface H5PFrameworkInterface {
|
|||
* Also fills in the libraryId in the libraryData object if the object is new
|
||||
*
|
||||
* @param object $libraryData
|
||||
* Object holding the information that is to be stored
|
||||
* Associative array containing:
|
||||
* - libraryId: The id of the library if it is an existing library.
|
||||
* - title: The library's name
|
||||
* - machineName: The library machineName
|
||||
* - majorVersion: The library's majorVersion
|
||||
* - minorVersion: The library's minorVersion
|
||||
* - patchVersion: The library's patchVersion
|
||||
* - runnable: 1 if the library is a content type, 0 otherwise
|
||||
* - fullscreen(optional): 1 if the library supports fullscreen, 0 otherwise
|
||||
* - embedTypes(optional): list of supported embed types
|
||||
* - preloadedJs(optional): list of associative arrays containing:
|
||||
* - path: path to a js file relative to the library root folder
|
||||
* - preloadedCss(optional): list of associative arrays containing:
|
||||
* - path: path to css file relative to the library root folder
|
||||
* - dropLibraryCss(optional): list of associative arrays containing:
|
||||
* - machineName: machine name for the librarys that are to drop their css
|
||||
* - semantics(optional): Json describing the content structure for the library
|
||||
* - language(optional): associative array containing:
|
||||
* - languageCode: Translation in json format
|
||||
*/
|
||||
public function saveLibraryData(&$libraryData, $new = TRUE);
|
||||
|
||||
/**
|
||||
* Insert new content.
|
||||
*
|
||||
* @param object $content
|
||||
* @param array $content
|
||||
* An associative array containing:
|
||||
* - id: The content id
|
||||
* - params: The content in json format
|
||||
* - library: An associative array containing:
|
||||
* - libraryId: The id of the main library for this content
|
||||
* @param int $contentMainId
|
||||
* Main id for the content if this is a system that supports versioning
|
||||
*/
|
||||
public function insertContent($content, $contentMainId = NULL);
|
||||
|
||||
/**
|
||||
* Update old content.
|
||||
*
|
||||
* @param object $content
|
||||
* @param array $content
|
||||
* An associative array containing:
|
||||
* - id: The content id
|
||||
* - params: The content in json format
|
||||
* - library: An associative array containing:
|
||||
* - libraryId: The id of the main library for this content
|
||||
* @param int $contentMainId
|
||||
* Main id for the content if this is a system that supports versioning
|
||||
*/
|
||||
public function updateContent($content, $contentMainId = NULL);
|
||||
|
||||
|
@ -170,21 +241,27 @@ interface H5PFrameworkInterface {
|
|||
* @param int $libraryId
|
||||
* Library Id for the library we're saving dependencies for
|
||||
* @param array $dependencies
|
||||
* List of dependencies in the format used in library.json
|
||||
* List of dependencies as associative arrays containing:
|
||||
* - machineName: The library machineName
|
||||
* - majorVersion: The library's majorVersion
|
||||
* - minorVersion: The library's minorVersion
|
||||
* @param string $dependency_type
|
||||
* What type of dependency this is, for instance it might be an editor dependency
|
||||
* What type of dependency this is, the following values are allowed:
|
||||
* - editor
|
||||
* - preloaded
|
||||
* - dynamic
|
||||
*/
|
||||
public function saveLibraryDependencies($libraryId, $dependencies, $dependency_type);
|
||||
|
||||
/**
|
||||
* Copies library usage
|
||||
* Give an H5P the same library dependencies as a given H5P
|
||||
*
|
||||
* @param int $contentId
|
||||
* Framework specific id identifying the content
|
||||
* Id identifying the content
|
||||
* @param int $copyFromId
|
||||
* Framework specific id identifying the content to be copied
|
||||
* Id identifying the content to be copied
|
||||
* @param int $contentMainId
|
||||
* Framework specific main id for the content, typically used in frameworks
|
||||
* Main id for the content, typically used in frameworks
|
||||
* That supports versioning. (In this case the content id will typically be
|
||||
* the version id, and the contentMainId will be the frameworks content id
|
||||
*/
|
||||
|
@ -194,7 +271,7 @@ interface H5PFrameworkInterface {
|
|||
* Deletes content data
|
||||
*
|
||||
* @param int $contentId
|
||||
* Framework specific id identifying the content
|
||||
* Id identifying the content
|
||||
*/
|
||||
public function deleteContentData($contentId);
|
||||
|
||||
|
@ -210,11 +287,17 @@ interface H5PFrameworkInterface {
|
|||
* Saves what libraries the content uses
|
||||
*
|
||||
* @param int $contentId
|
||||
* Framework specific id identifying the content
|
||||
* Id identifying the content
|
||||
* @param array $librariesInUse
|
||||
* List of libraries the content uses. Libraries consist of arrays with:
|
||||
* - libraryId stored in $librariesInUse[<place>]['library']['libraryId']
|
||||
* - libraryId stored in $librariesInUse[<place>]['preloaded']
|
||||
* List of libraries the content uses. Libraries consist of associative arrays with:
|
||||
* - library: Associative array containing:
|
||||
* - dropLibraryCss(optional): commasepareted list of machineNames
|
||||
* - machineName: Machine name for the library
|
||||
* - libraryId: Id of the library
|
||||
* - type: The dependency type. Allowed values:
|
||||
* - editor
|
||||
* - dynamic
|
||||
* - preloaded
|
||||
*/
|
||||
public function saveLibraryUsage($contentId, $librariesInUse);
|
||||
|
||||
|
@ -222,9 +305,12 @@ interface H5PFrameworkInterface {
|
|||
* Get number of content/nodes using a library, and the number of
|
||||
* dependencies to other libraries
|
||||
*
|
||||
* @param int $library_id
|
||||
* @return array The array contains two elements, keyed by 'content' and 'libraries'.
|
||||
* Each element contains a number
|
||||
* @param int $libraryId
|
||||
* Library identifier
|
||||
* @return array
|
||||
* Associative array containing:
|
||||
* - content: Number of content using the library
|
||||
* - libraries: Number of libraries depending on the library
|
||||
*/
|
||||
public function getLibraryUsage($libraryId);
|
||||
|
||||
|
@ -232,71 +318,140 @@ interface H5PFrameworkInterface {
|
|||
* Loads a library
|
||||
*
|
||||
* @param string $machineName
|
||||
* The library's machine name
|
||||
* @param int $majorVersion
|
||||
* The library's major version
|
||||
* @param int $minorVersion
|
||||
* The library's minor version
|
||||
* @return array|FALSE
|
||||
* Array representing the library with dependency descriptions
|
||||
* FALSE if the library doesn't exist
|
||||
* FALSE if the library doesn't exist.
|
||||
* Otherwise an associative array containing:
|
||||
* - libraryId: The id of the library if it is an existing library.
|
||||
* - title: The library's name
|
||||
* - machineName: The library machineName
|
||||
* - majorVersion: The library's majorVersion
|
||||
* - minorVersion: The library's minorVersion
|
||||
* - patchVersion: The library's patchVersion
|
||||
* - runnable: 1 if the library is a content type, 0 otherwise
|
||||
* - fullscreen(optional): 1 if the library supports fullscreen, 0 otherwise
|
||||
* - embedTypes(optional): list of supported embed types
|
||||
* - preloadedJs(optional): comma separated string with js file paths
|
||||
* - preloadedCss(optional): comma separated sting with css file paths
|
||||
* - dropLibraryCss(optional): list of associative arrays containing:
|
||||
* - machineName: machine name for the librarys that are to drop their css
|
||||
* - semantics(optional): Json describing the content structure for the library
|
||||
* - preloadedDependencies(optional): list of associative arrays containing:
|
||||
* - machineName: Machine name for a library this library is depending on
|
||||
* - majorVersion: Major version for a library this library is depending on
|
||||
* - minorVersion: Minor for a library this library is depending on
|
||||
* - dynamicDependencies(optional): list of associative arrays containing:
|
||||
* - machineName: Machine name for a library this library is depending on
|
||||
* - majorVersion: Major version for a library this library is depending on
|
||||
* - minorVersion: Minor for a library this library is depending on
|
||||
* - editorDependencies(optional): list of associative arrays containing:
|
||||
* - machineName: Machine name for a library this library is depending on
|
||||
* - majorVersion: Major version for a library this library is depending on
|
||||
* - minorVersion: Minor for a library this library is depending on
|
||||
*/
|
||||
public function loadLibrary($machineName, $majorVersion, $minorVersion);
|
||||
|
||||
/**
|
||||
* Loads library semantics.
|
||||
*
|
||||
* @param string $name library identifier.
|
||||
* @param int $majorVersion library identifier.
|
||||
* @param int $minorVersion library identifier.
|
||||
* @return string semantics.
|
||||
* @param string $machineName
|
||||
* Machine name for the library
|
||||
* @param int $majorVersion
|
||||
* The library's major version
|
||||
* @param int $minorVersion
|
||||
* The library's minor version
|
||||
* @return string
|
||||
* The library's semantics as json
|
||||
*/
|
||||
public function loadLibrarySemantics($name, $majorVersion, $minorVersion);
|
||||
public function loadLibrarySemantics($machineName, $majorVersion, $minorVersion);
|
||||
|
||||
/**
|
||||
* Makes it possible to alter the semantics, adding custom fields, etc.
|
||||
*
|
||||
* @param array $semantics
|
||||
* @param string $name library identifier.
|
||||
* @param int $majorVersion library identifier.
|
||||
* @param int $minorVersion library identifier.
|
||||
* Associative array representing the semantics
|
||||
* @param string $machineName
|
||||
* The library's machine name
|
||||
* @param int $majorVersion
|
||||
* The library's major version
|
||||
* @param int $minorVersion
|
||||
* The library's minor version
|
||||
*/
|
||||
public function alterLibrarySemantics(&$semantics, $name, $majorVersion, $minorVersion);
|
||||
public function alterLibrarySemantics(&$semantics, $machineName, $majorVersion, $minorVersion);
|
||||
|
||||
/**
|
||||
* Delete all dependencies belonging to given library
|
||||
*
|
||||
* @param int $libraryId
|
||||
* Library Id
|
||||
* Library identifier
|
||||
*/
|
||||
public function deleteLibraryDependencies($libraryId);
|
||||
|
||||
/**
|
||||
* Delete a library from database and file system
|
||||
*
|
||||
* @param mixed $library Library
|
||||
* @param stdClass $library
|
||||
* Library object with id, name, major version and minor version.
|
||||
*/
|
||||
public function deleteLibrary($library);
|
||||
|
||||
/**
|
||||
* Load content.
|
||||
*
|
||||
* @return object Content, null if not found.
|
||||
* @param int $id
|
||||
* Content identifier
|
||||
* @return array
|
||||
* Associative array containing:
|
||||
* - contentId: Identifier for the content
|
||||
* - params: json content as string
|
||||
* - embedType: csv of embed types
|
||||
* - title: The contents title
|
||||
* - language: Language code for the content
|
||||
* - libraryId: Id for the main library
|
||||
* - libraryName: The library machine name
|
||||
* - libraryMajorVersion: The library's majorVersion
|
||||
* - libraryMinorVersion: The library's minorVersion
|
||||
* - libraryEmbedTypes: CSV of the main library's embed types
|
||||
* - libraryFullscreen: 1 if fullscreen is supported. 0 otherwise.
|
||||
*/
|
||||
public function loadContent($id);
|
||||
|
||||
/**
|
||||
* Load dependencies for the given content of the given type.
|
||||
*
|
||||
* @param int $id content.
|
||||
* @param int $type dependency.
|
||||
* @param int $id
|
||||
* Content identifier
|
||||
* @param int $type
|
||||
* Dependency types. Allowed values:
|
||||
* - editor
|
||||
* - preloaded
|
||||
* - dynamic
|
||||
* @return array
|
||||
* List of associative arrays containing:
|
||||
* - libraryId: The id of the library if it is an existing library.
|
||||
* - machineName: The library machineName
|
||||
* - majorVersion: The library's majorVersion
|
||||
* - minorVersion: The library's minorVersion
|
||||
* - patchVersion: The library's patchVersion
|
||||
* - preloadedJs(optional): comma separated string with js file paths
|
||||
* - preloadedCss(optional): comma separated sting with css file paths
|
||||
* - dropCss(optional): csv of machine names
|
||||
*/
|
||||
public function loadContentDependencies($id, $type = NULL);
|
||||
|
||||
/**
|
||||
* Get stored setting.
|
||||
*
|
||||
* @param string $name Identifier
|
||||
* @param string $default Optional
|
||||
* @return mixed data
|
||||
* @param string $name
|
||||
* Identifier for the setting
|
||||
* @param string $default
|
||||
* Optional default value if settings is not set
|
||||
* @return mixed
|
||||
* Whatever has been stored as the setting
|
||||
*/
|
||||
public function getOption($name, $default = NULL);
|
||||
|
||||
|
@ -304,8 +459,10 @@ interface H5PFrameworkInterface {
|
|||
* Stores the given setting.
|
||||
* For example when did we last check h5p.org for updates to our libraries.
|
||||
*
|
||||
* @param string $name Identifier
|
||||
* @param mixed $value Data limited to 2^32 bytes of data
|
||||
* @param string $name
|
||||
* Identifier for the setting
|
||||
* @param mixed $value Data
|
||||
* Whatever we want to store as the setting
|
||||
*/
|
||||
public function setOption($name, $value);
|
||||
|
||||
|
@ -337,10 +494,10 @@ interface H5PFrameworkInterface {
|
|||
/**
|
||||
* Get number of contents using library as main library.
|
||||
*
|
||||
* @param int $library_id
|
||||
* @param int $libraryId
|
||||
* @return int
|
||||
*/
|
||||
public function getNumContent($library_id);
|
||||
public function getNumContent($libraryId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1370,6 +1527,8 @@ class H5PCore {
|
|||
public static $defaultLibraryWhitelistExtras = 'js css';
|
||||
|
||||
public $librariesJsonData, $contentJsonData, $mainJsonData, $h5pF, $path, $development_mode, $h5pD, $disableFileCheck;
|
||||
const SECONDS_IN_WEEK = 604800;
|
||||
|
||||
private $exportEnabled;
|
||||
|
||||
/**
|
||||
|
@ -1996,6 +2155,30 @@ class H5PCore {
|
|||
$html .= '</ul><span><br>These libraries may cause problems on this site. See <a href="http://h5p.org/releases/h5p-core-1.3">here</a> for more info</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of libraries' metadata from h5p.org. Cache it, and refetch once a week.
|
||||
*
|
||||
* @return mixed An object of objects keyed by machineName
|
||||
*/
|
||||
public function getLibrariesMetadata() {
|
||||
// Fetch from cache:
|
||||
$metadata = $this->h5pF->cacheGet('libraries','metadata');
|
||||
|
||||
// If not available in cache, or older than a week => refetch!
|
||||
if ($metadata === NULL || $metadata->lastTimeFetched < (time() - self::SECONDS_IN_WEEK)) {
|
||||
$platformInfo = $this->h5pF->getPlatformInfo();
|
||||
$json = file_get_contents('http://h5p.org/libraries-metadata.json?platform=' . json_encode($platformInfo));
|
||||
|
||||
$metadata = new stdClass();
|
||||
$metadata->json = ($json === FALSE ? NULL : json_decode($json));
|
||||
$metadata->lastTimeFetched = time();
|
||||
|
||||
$this->h5pF->cacheSet('libraries','metadata', $metadata);
|
||||
}
|
||||
|
||||
return $metadata->json;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,6 +37,7 @@ var H5PLibraryList= H5PLibraryList || {};
|
|||
$.each (libraries.listData, function (index, library) {
|
||||
var $libraryRow = H5PUtils.createTableRow([
|
||||
library.title,
|
||||
'<input class="h5p-admin-restricted" type="checkbox"/>',
|
||||
{
|
||||
text: library.numContent,
|
||||
class: 'h5p-admin-center'
|
||||
|
@ -56,6 +57,8 @@ var H5PLibraryList= H5PLibraryList || {};
|
|||
</div>'
|
||||
]);
|
||||
|
||||
H5PLibraryList.addRestricted($('.h5p-admin-restricted', $libraryRow), library.restrictedUrl, library.restricted);
|
||||
|
||||
var hasContent = !(library.numContent === '' || library.numContent === 0);
|
||||
if (library.upgradeUrl === null) {
|
||||
$('.h5p-admin-upgrade-library', $libraryRow).remove();
|
||||
|
@ -92,6 +95,34 @@ var H5PLibraryList= H5PLibraryList || {};
|
|||
return $table;
|
||||
};
|
||||
|
||||
H5PLibraryList.addRestricted = function ($checkbox, url, selected) {
|
||||
if (selected === null) {
|
||||
$checkbox.remove();
|
||||
}
|
||||
else {
|
||||
$checkbox.change(function () {
|
||||
$checkbox.attr('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
dataType: 'json',
|
||||
url: url,
|
||||
cache: false
|
||||
}).fail(function () {
|
||||
$checkbox.attr('disabled', false);
|
||||
|
||||
// Reset
|
||||
$checkbox.attr('checked', !$checkbox.is(':checked'));
|
||||
}).done(function (result) {
|
||||
url = result.url;
|
||||
$checkbox.attr('disabled', false);
|
||||
});
|
||||
});
|
||||
|
||||
if (selected) {
|
||||
$checkbox.attr('checked', true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize me:
|
||||
$(document).ready(function () {
|
||||
|
|
Loading…
Reference in New Issue