mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-66609-master' of git://github.com/andrewnicols/moodle
This commit is contained in:
commit
08460f270f
@ -9,7 +9,6 @@ cache/stores/mongodb/MongoDB/
|
||||
enrol/lti/ims-blti/
|
||||
filter/algebra/AlgParser.pm
|
||||
filter/tex/mimetex.*
|
||||
lib/editor/atto/plugins/h5p/js/h5p-resizer.js
|
||||
lib/editor/atto/plugins/html/yui/src/codemirror/
|
||||
lib/editor/atto/plugins/html/yui/src/beautify/
|
||||
lib/editor/atto/yui/src/rangy/js/*.*
|
||||
@ -63,6 +62,7 @@ lib/geopattern-php/
|
||||
lib/php-jwt/
|
||||
lib/babel-polyfill/
|
||||
lib/emoji-data/
|
||||
lib/h5p/
|
||||
media/player/videojs/amd/src/video-lazy.js
|
||||
media/player/videojs/amd/src/Youtube-lazy.js
|
||||
media/player/videojs/videojs/
|
||||
@ -86,4 +86,4 @@ theme/boost/amd/src/toast.js
|
||||
theme/boost/amd/src/tooltip.js
|
||||
theme/boost/amd/src/util.js
|
||||
theme/boost/amd/src/tether.js
|
||||
theme/boost/scss/fontawesome/
|
||||
theme/boost/scss/fontawesome/
|
||||
|
@ -10,7 +10,6 @@ cache/stores/mongodb/MongoDB/
|
||||
enrol/lti/ims-blti/
|
||||
filter/algebra/AlgParser.pm
|
||||
filter/tex/mimetex.*
|
||||
lib/editor/atto/plugins/h5p/js/h5p-resizer.js
|
||||
lib/editor/atto/plugins/html/yui/src/codemirror/
|
||||
lib/editor/atto/plugins/html/yui/src/beautify/
|
||||
lib/editor/atto/yui/src/rangy/js/*.*
|
||||
@ -64,6 +63,7 @@ lib/geopattern-php/
|
||||
lib/php-jwt/
|
||||
lib/babel-polyfill/
|
||||
lib/emoji-data/
|
||||
lib/h5p/
|
||||
media/player/videojs/amd/src/video-lazy.js
|
||||
media/player/videojs/amd/src/Youtube-lazy.js
|
||||
media/player/videojs/videojs/
|
||||
@ -87,4 +87,4 @@ theme/boost/amd/src/toast.js
|
||||
theme/boost/amd/src/tooltip.js
|
||||
theme/boost/amd/src/util.js
|
||||
theme/boost/amd/src/tether.js
|
||||
theme/boost/scss/fontawesome/
|
||||
theme/boost/scss/fontawesome/
|
||||
|
@ -109,3 +109,27 @@ function block_html_global_db_replace($search, $replace) {
|
||||
}
|
||||
$instances->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
|
||||
*
|
||||
* @param string $filearea The filearea.
|
||||
* @param array $args The path (the part after the filearea and before the filename).
|
||||
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
|
||||
*/
|
||||
function block_html_get_path_from_pluginfile(string $filearea, array $args) : array {
|
||||
// This block never has an itemid (the number represents the revision but it's not stored in database).
|
||||
array_shift($args);
|
||||
|
||||
// Get the filepath.
|
||||
if (empty($args)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
}
|
||||
|
||||
return [
|
||||
'itemid' => 0,
|
||||
'filepath' => $filepath,
|
||||
];
|
||||
}
|
||||
|
@ -111,7 +111,8 @@ class filter_displayh5p extends moodle_text_filter {
|
||||
|
||||
// We want to request the resizing script only once.
|
||||
if (self::$loadresizerjs) {
|
||||
$tagend .= '<script src="https://h5p.org/sites/all/modules/h5p/library/js/h5p-resizer.js"></script>';
|
||||
$resizerurl = new moodle_url('/lib/h5p/js/h5p-resizer.js');
|
||||
$tagend .= '<script src="' . $resizerurl->out() . '"></script>';
|
||||
self::$loadresizerjs = false;
|
||||
}
|
||||
|
||||
|
59
h5p/classes/autoloader.php
Normal file
59
h5p/classes/autoloader.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* H5P Autoloader.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* H5P Autoloader.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class autoloader {
|
||||
public static function register(): void {
|
||||
spl_autoload_register([self::class, 'autoload']);
|
||||
}
|
||||
|
||||
public static function autoload($classname): void {
|
||||
global $CFG;
|
||||
|
||||
$classes = [
|
||||
'H5PCore' => '/lib/h5p/h5p.classes.php',
|
||||
'H5PFrameworkInterface' => '/lib/h5p/h5p.classes.php',
|
||||
'H5PContentValidator' => 'lib/h5p/h5p.classes.php',
|
||||
'H5PValidator' => '/lib/h5p/h5p.classes.php',
|
||||
'H5PStorage' => '/lib/h5p/h5p.classes.php',
|
||||
'H5PDevelopment' => '/lib/h5p/h5p-development.class.php',
|
||||
'H5PFileStorage' => '/lib/h5p/h5p-file-storage.interface.php',
|
||||
'H5PMetadata' => '/lib/h5p/h5p-metadata.class.php',
|
||||
];
|
||||
|
||||
if (isset($classes[$classname])) {
|
||||
require_once("{$CFG->dirroot}{$classes[$classname]}");
|
||||
}
|
||||
}
|
||||
}
|
113
h5p/classes/core.php
Normal file
113
h5p/classes/core.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* H5P player class.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p;
|
||||
|
||||
use H5PCore;
|
||||
use stdClass;
|
||||
use moodle_url;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* H5P player class, for displaying any local H5P content.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core extends \H5PCore {
|
||||
|
||||
protected $libraries;
|
||||
|
||||
protected function getDependencyPath(array $dependency): string {
|
||||
$library = $this->find_library($dependency);
|
||||
|
||||
return "libraries/{$library->id}/{$library->machinename}-{$library->majorversion}.{$library->minorversion}";
|
||||
}
|
||||
|
||||
public function get_dependency_roots(int $id): array {
|
||||
$roots = [];
|
||||
$dependencies = $this->h5pF->loadContentDependencies($id);
|
||||
$context = \context_system::instance();
|
||||
foreach ($dependencies as $dependency) {
|
||||
$library = $this->find_library($dependency);
|
||||
$roots[self::libraryToString($dependency, true)] = (moodle_url::make_pluginfile_url(
|
||||
$context->id,
|
||||
'core_h5p',
|
||||
'libraries',
|
||||
$library->id,
|
||||
"/" . self::libraryToString($dependency, true),
|
||||
''
|
||||
))->out(false);
|
||||
}
|
||||
|
||||
return $roots;
|
||||
}
|
||||
|
||||
protected function find_library($dependency): \stdClass {
|
||||
global $DB;
|
||||
if (null === $this->libraries) {
|
||||
$this->libraries = $DB->get_records('h5p_libraries');
|
||||
}
|
||||
|
||||
$major = $dependency['majorVersion'];
|
||||
$minor = $dependency['minorVersion'];
|
||||
$patch = $dependency['patchVersion'];
|
||||
|
||||
foreach ($this->libraries as $library) {
|
||||
if ($library->machinename !== $dependency['machineName']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($library->majorversion != $major) {
|
||||
continue;
|
||||
}
|
||||
if ($library->minorversion != $minor) {
|
||||
continue;
|
||||
}
|
||||
if ($library->patchversion != $patch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $library;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function get_scripts(): array {
|
||||
global $CFG;
|
||||
$cachebuster = '?ver='.$CFG->jsrev;
|
||||
$liburl = $CFG->wwwroot . '/lib/h5p/';
|
||||
$urls = [];
|
||||
|
||||
foreach (self::$scripts as $script) {
|
||||
$urls[] = new moodle_url($liburl . $script . $cachebuster);
|
||||
}
|
||||
$urls[] = new moodle_url("/h5p/js/h5p_overrides.js");
|
||||
|
||||
return $urls;
|
||||
}
|
||||
}
|
140
h5p/classes/factory.php
Normal file
140
h5p/classes/factory.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* H5P factory class.
|
||||
* This class is used to decouple the construction of H5P related objects.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \core_h5p\framework as framework;
|
||||
use \core_h5p\core as core;
|
||||
use \H5PStorage as storage;
|
||||
use \H5PValidator as validator;
|
||||
use \H5PContentValidator as content_validator;
|
||||
|
||||
/**
|
||||
* H5P factory class.
|
||||
* This class is used to decouple the construction of H5P related objects.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class factory {
|
||||
|
||||
/** @var \core_h5p\core The Moodle H5PCore implementation */
|
||||
protected $core;
|
||||
|
||||
/** @var \core_h5p\framework The Moodle H5PFramework implementation */
|
||||
protected $framework;
|
||||
|
||||
/** @var \core_h5p\file_storage The Moodle H5PStorage implementation */
|
||||
protected $storage;
|
||||
|
||||
/** @var validator The Moodle H5PValidator implementation */
|
||||
protected $validator;
|
||||
|
||||
/** @var content_validator The Moodle H5PContentValidator implementation */
|
||||
protected $content_validator;
|
||||
|
||||
/**
|
||||
* factory constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
// Loading classes we need from H5P third party library.
|
||||
autoloader::register();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the \core_h5p\framework class.
|
||||
*
|
||||
* @return \core_h5p\framework
|
||||
*/
|
||||
public function get_framework(): framework {
|
||||
if (null === $this->framework) {
|
||||
$this->framework = new framework();
|
||||
}
|
||||
|
||||
return $this->framework;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the \core_h5p\core class.
|
||||
*
|
||||
* @return \core_h5p\core
|
||||
*/
|
||||
public function get_core(): core {
|
||||
if (null === $this->core) {
|
||||
$fs = new \core_h5p\file_storage();
|
||||
$language = \core_h5p\framework::get_language();
|
||||
$context = \context_system::instance();
|
||||
|
||||
$url = \moodle_url::make_pluginfile_url($context->id, 'core_h5p', '', null,
|
||||
'', '')->out();
|
||||
|
||||
$this->core = new core($this->get_framework(), $fs, $url, $language, true);
|
||||
}
|
||||
|
||||
return $this->core;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the \H5PStorage class.
|
||||
*
|
||||
* @return \H5PStorage
|
||||
*/
|
||||
public function get_storage(): storage {
|
||||
if (null === $this->storage) {
|
||||
$this->storage = new storage($this->get_framework(), $this->get_core());
|
||||
}
|
||||
|
||||
return $this->storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the \H5PValidator class.
|
||||
*
|
||||
* @return \H5PValidator
|
||||
*/
|
||||
public function get_validator(): validator {
|
||||
if (null === $this->validator) {
|
||||
$this->validator = new validator($this->get_framework(), $this->get_core());
|
||||
}
|
||||
|
||||
return $this->validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the \H5PContentValidator class.
|
||||
*
|
||||
* @return \H5PContentValidator
|
||||
*/
|
||||
public function get_content_validator(): content_validator {
|
||||
if (null === $this->content_validator) {
|
||||
$this->content_validator = new content_validator($this->get_framework(), $this->get_core());
|
||||
}
|
||||
|
||||
return $this->content_validator;
|
||||
}
|
||||
}
|
624
h5p/classes/file_storage.php
Normal file
624
h5p/classes/file_storage.php
Normal file
@ -0,0 +1,624 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Class \core_h5p\file_storage.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Victor Deniz <victor@moodle.com>, base on code by Joubel AS
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class to handle storage and export of H5P Content.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Victor Deniz <victor@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class file_storage implements \H5PFileStorage {
|
||||
|
||||
/** The component for H5P. */
|
||||
public const COMPONENT = 'core_h5p';
|
||||
/** The library file area. */
|
||||
public const LIBRARY_FILEAREA = 'libraries';
|
||||
/** The content file area */
|
||||
public const CONTENT_FILEAREA = 'content';
|
||||
/** The cached assest file area. */
|
||||
public const CACHED_ASSETS_FILEAREA = 'cachedassets';
|
||||
/** The export file area */
|
||||
public const EXPORT_FILEAREA = 'export';
|
||||
|
||||
/**
|
||||
* @var \context $context Currently we use the system context everywhere.
|
||||
* Don't feel forced to keep it this way in the future.
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/** @var \file_storage $fs File storage. */
|
||||
protected $fs;
|
||||
|
||||
/**
|
||||
* Initial setup for file_storage.
|
||||
*/
|
||||
public function __construct() {
|
||||
// Currently everything uses the system context.
|
||||
$this->context = \context_system::instance();
|
||||
$this->fs = get_file_storage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a H5P library in the Moodle filesystem.
|
||||
*
|
||||
* @param array $library Library properties.
|
||||
*/
|
||||
public function saveLibrary($library) {
|
||||
$options = [
|
||||
'contextid' => $this->context->id,
|
||||
'component' => self::COMPONENT,
|
||||
'filearea' => self::LIBRARY_FILEAREA,
|
||||
'filepath' => '/' . \H5PCore::libraryToString($library, true) . '/',
|
||||
'itemid' => $library['libraryId']
|
||||
];
|
||||
|
||||
// Easiest approach: delete the existing library version and copy the new one.
|
||||
$this->delete_library($library);
|
||||
$this->copy_directory($library['uploadDirectory'], $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the content folder.
|
||||
*
|
||||
* @param string $source Path on file system to content directory.
|
||||
* @param array $content Content properties
|
||||
*/
|
||||
public function saveContent($source, $content) {
|
||||
$options = [
|
||||
'contextid' => $this->context->id,
|
||||
'component' => self::COMPONENT,
|
||||
'filearea' => self::CONTENT_FILEAREA,
|
||||
'itemid' => $content['id'],
|
||||
'filepath' => '/',
|
||||
];
|
||||
|
||||
$this->delete_directory($this->context->id, self::COMPONENT, self::CONTENT_FILEAREA, $content['id']);
|
||||
// Copy content directory into Moodle filesystem.
|
||||
$this->copy_directory($source, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove content folder.
|
||||
*
|
||||
* @param array $content Content properties
|
||||
*/
|
||||
public function deleteContent($content) {
|
||||
|
||||
$this->delete_directory($this->context->id, self::COMPONENT, self::CONTENT_FILEAREA, $content['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a stored copy of the content folder.
|
||||
*
|
||||
* @param string $id Identifier of content to clone.
|
||||
* @param int $newid The cloned content's identifier
|
||||
*/
|
||||
public function cloneContent($id, $newid) {
|
||||
// Not implemented in Moodle.
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path to a new unique tmp folder.
|
||||
* Please note this needs to not be a directory.
|
||||
*
|
||||
* @return string Path
|
||||
*/
|
||||
public function getTmpPath(): string {
|
||||
return make_request_directory() . '/' . uniqid('h5p-');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch content folder and save in target directory.
|
||||
*
|
||||
* @param int $id Content identifier
|
||||
* @param string $target Where the content folder will be saved
|
||||
*/
|
||||
public function exportContent($id, $target) {
|
||||
$this->export_file_tree($target, $this->context->id, self::CONTENT_FILEAREA, '/', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch library folder and save in target directory.
|
||||
*
|
||||
* @param array $library Library properties
|
||||
* @param string $target Where the library folder will be saved
|
||||
*/
|
||||
public function exportLibrary($library, $target) {
|
||||
$folder = \H5PCore::libraryToString($library, true);
|
||||
$this->export_file_tree($target . '/' . $folder, $this->context->id, self::LIBRARY_FILEAREA,
|
||||
'/' . $folder . '/', $library['libraryId']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save export in file system
|
||||
*
|
||||
* @param string $source Path on file system to temporary export file.
|
||||
* @param string $filename Name of export file.
|
||||
*/
|
||||
public function saveExport($source, $filename) {
|
||||
$filerecord = [
|
||||
'contextid' => $this->context->id,
|
||||
'component' => self::COMPONENT,
|
||||
'filearea' => self::EXPORT_FILEAREA,
|
||||
'itemid' => 0,
|
||||
'filepath' => '/',
|
||||
'filename' => $filename
|
||||
];
|
||||
$this->fs->create_file_from_pathname($filerecord, $source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes given export file
|
||||
*
|
||||
* @param string $filename filename of the export to delete.
|
||||
*/
|
||||
public function deleteExport($filename) {
|
||||
$file = $this->get_export_file($filename);
|
||||
if ($file) {
|
||||
$file->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given export file exists
|
||||
*
|
||||
* @param string $filename The export file to check.
|
||||
* @return boolean True if the export file exists.
|
||||
*/
|
||||
public function hasExport($filename) {
|
||||
return !!$this->get_export_file($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will concatenate all JavaScrips and Stylesheets into two files in order
|
||||
* to improve page performance.
|
||||
*
|
||||
* @param array $files A set of all the assets required for content to display
|
||||
* @param string $key Hashed key for cached asset
|
||||
*/
|
||||
public function cacheAssets(&$files, $key) {
|
||||
|
||||
foreach ($files as $type => $assets) {
|
||||
if (empty($assets)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create new file for cached assets.
|
||||
$ext = ($type === 'scripts' ? 'js' : 'css');
|
||||
$filename = $key . '.' . $ext;
|
||||
$fileinfo = [
|
||||
'contextid' => $this->context->id,
|
||||
'component' => self::COMPONENT,
|
||||
'filearea' => self::CACHED_ASSETS_FILEAREA,
|
||||
'itemid' => 0,
|
||||
'filepath' => '/',
|
||||
'filename' => $filename
|
||||
];
|
||||
|
||||
// Store concatenated content.
|
||||
$this->fs->create_file_from_string($fileinfo, $this->concatenate_files($assets, $type, $this->context));
|
||||
$files[$type] = [
|
||||
(object) [
|
||||
'path' => '/' . self::CACHED_ASSETS_FILEAREA . '/' . $filename,
|
||||
'version' => ''
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will check if there are cache assets available for content.
|
||||
*
|
||||
* @param string $key Hashed key for cached asset
|
||||
* @return array
|
||||
*/
|
||||
public function getCachedAssets($key) {
|
||||
$files = [];
|
||||
|
||||
$js = $this->fs->get_file($this->context->id, self::COMPONENT, self::CACHED_ASSETS_FILEAREA, 0, '/', "{$key}.js");
|
||||
if ($js && $js->get_filesize() > 0) {
|
||||
$files['scripts'] = [
|
||||
(object) [
|
||||
'path' => '/' . self::CACHED_ASSETS_FILEAREA . '/' . "{$key}.js",
|
||||
'version' => ''
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$css = $this->fs->get_file($this->context->id, self::COMPONENT, self::CACHED_ASSETS_FILEAREA, 0, '/', "{$key}.css");
|
||||
if ($css && $css->get_filesize() > 0) {
|
||||
$files['styles'] = [
|
||||
(object) [
|
||||
'path' => '/' . self::CACHED_ASSETS_FILEAREA . '/' . "{$key}.css",
|
||||
'version' => ''
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return empty($files) ? null : $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the aggregated cache files.
|
||||
*
|
||||
* @param array $keys The hash keys of removed files
|
||||
*/
|
||||
public function deleteCachedAssets($keys) {
|
||||
|
||||
if (empty($keys)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($keys as $hash) {
|
||||
foreach (['js', 'css'] as $type) {
|
||||
$cachedasset = $this->fs->get_file($this->context->id, self::COMPONENT, self::CACHED_ASSETS_FILEAREA, 0, '/',
|
||||
"{$hash}.{$type}");
|
||||
if ($cachedasset) {
|
||||
$cachedasset->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read file content of given file and then return it.
|
||||
*
|
||||
* @param string $filepath
|
||||
* @return string contents
|
||||
*/
|
||||
public function getContent($filepath) {
|
||||
list(
|
||||
'filearea' => $filearea,
|
||||
'filepath' => $filepath,
|
||||
'filename' => $filename,
|
||||
'itemid' => $itemid
|
||||
) = $this->get_file_elements_from_filepath($filepath);
|
||||
|
||||
if (!$itemid) {
|
||||
throw new \file_serving_exception('Could not retrieve the requested file, check your file permissions.');
|
||||
}
|
||||
|
||||
// Locate file.
|
||||
$file = $this->fs->get_file($this->context->id, self::COMPONENT, $filearea, $itemid, $filepath, $filename);
|
||||
|
||||
// Return content.
|
||||
return $file->get_content();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save files uploaded through the editor.
|
||||
* The files must be marked as temporary until the content form is saved.
|
||||
*
|
||||
* @param \H5peditorFile $file
|
||||
* @param int $contentid
|
||||
*/
|
||||
public function saveFile($file, $contentid) {
|
||||
// This is to be implemented when the h5p editor is introduced / created.
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a file from another content or editor tmp dir.
|
||||
* Used when copy pasting content in H5P.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param string|int $fromid Content ID or 'editor' string
|
||||
* @param int $toid Target Content ID
|
||||
*/
|
||||
public function cloneContentFile($file, $fromid, $toid) {
|
||||
// This is to be implemented when the h5p editor is introduced / created.
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy content from one directory to another. Defaults to cloning
|
||||
* content from the current temporary upload folder to the editor path.
|
||||
*
|
||||
* @param string $source path to source directory
|
||||
* @param string $contentid Id of content
|
||||
*
|
||||
* @return object Object containing h5p json and content json data
|
||||
*/
|
||||
public function moveContentDirectory($source, $contentid = null) {
|
||||
// This is to be implemented when the h5p editor is introduced / created.
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if content has the given file.
|
||||
* Used when saving content.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param int $contentid
|
||||
* @return string|int File ID or NULL if not found
|
||||
*/
|
||||
public function getContentFile($file, $contentid) {
|
||||
// This is to be implemented when the h5p editor is introduced / created.
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove content files that are no longer used.
|
||||
* Used when saving content.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param int $contentid
|
||||
*/
|
||||
public function removeContentFile($file, $contentid) {
|
||||
// This is to be implemented when the h5p editor is introduced / created.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if server setup has write permission to
|
||||
* the required folders
|
||||
*
|
||||
* @return bool True if server has the proper write access
|
||||
*/
|
||||
public function hasWriteAccess() {
|
||||
// Moodle has access to the files table which is where all of the folders are stored.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the library has a presave.js in the root folder
|
||||
*
|
||||
* @param string $libraryname
|
||||
* @param string $developmentpath
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPresave($libraryname, $developmentpath = null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if upgrades script exist for library.
|
||||
*
|
||||
* @param string $machinename
|
||||
* @param int $majorversion
|
||||
* @param int $minorversion
|
||||
* @return string Relative path
|
||||
*/
|
||||
public function getUpgradeScript($machinename, $majorversion, $minorversion) {
|
||||
$path = '/' . "{$machinename}-{$majorversion}.{$minorversion}" . '/';
|
||||
$file = 'upgrade.js';
|
||||
$itemid = $this->get_itemid_for_file(self::LIBRARY_FILEAREA, $path, $file);
|
||||
if ($this->fs->get_file($this->context->id, self::COMPONENT, self::LIBRARY_FILEAREA, $itemid, $path, $file)) {
|
||||
return '/' . self::LIBRARY_FILEAREA . $path. $file;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the given stream into the given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @param resource $stream
|
||||
* @return bool|int
|
||||
*/
|
||||
public function saveFileFromZip($path, $file, $stream) {
|
||||
$fullpath = $path . '/' . $file;
|
||||
check_dir_exists(pathinfo($fullpath, PATHINFO_DIRNAME));
|
||||
return file_put_contents($fullpath, $stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a library from the file system.
|
||||
*
|
||||
* @param array $library Library details
|
||||
*/
|
||||
public function delete_library(array $library): void {
|
||||
|
||||
// A library ID of false would result in all library files being deleted, which we don't want. Return instead.
|
||||
if ($library['libraryId'] === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->delete_directory($this->context->id, self::COMPONENT, self::LIBRARY_FILEAREA, $library['libraryId']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an H5P directory from the filesystem.
|
||||
*
|
||||
* @param int $contextid context ID
|
||||
* @param string $component component
|
||||
* @param string $filearea file area or all areas in context if not specified
|
||||
* @param int $itemid item ID or all files if not specified
|
||||
*/
|
||||
private function delete_directory(int $contextid, string $component, string $filearea, int $itemid): void {
|
||||
|
||||
$this->fs->delete_area_files($contextid, $component, $filearea, $itemid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy an H5P directory from the temporary directory into the file system.
|
||||
*
|
||||
* @param string $source Temporary location for files.
|
||||
* @param array $options File system information.
|
||||
*/
|
||||
private function copy_directory(string $source, array $options): void {
|
||||
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
\RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
$root = $options['filepath'];
|
||||
|
||||
$it->rewind();
|
||||
while ($it->valid()) {
|
||||
$item = $it->current();
|
||||
$subpath = $it->getSubPath();
|
||||
if (!$item->isDir()) {
|
||||
$options['filename'] = $it->getFilename();
|
||||
if (!$subpath == '') {
|
||||
$options['filepath'] = $root . $subpath . '/';
|
||||
} else {
|
||||
$options['filepath'] = $root;
|
||||
}
|
||||
|
||||
$this->fs->create_file_from_pathname($options, $item->getPathName());
|
||||
}
|
||||
$it->next();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies files from storage to temporary folder.
|
||||
*
|
||||
* @param string $target Path to temporary folder
|
||||
* @param int $contextid context where the files are found
|
||||
* @param string $filearea file area
|
||||
* @param string $filepath file path
|
||||
* @param int $itemid Optional item ID
|
||||
*/
|
||||
private function export_file_tree(string $target, int $contextid, string $filearea, string $filepath, int $itemid = 0): void {
|
||||
// Make sure target folder exists.
|
||||
check_dir_exists($target);
|
||||
|
||||
// Read source files.
|
||||
$files = $this->fs->get_directory_files($contextid, self::COMPONENT, $filearea, $itemid, $filepath, true);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$path = $target . str_replace($filepath, DIRECTORY_SEPARATOR, $file->get_filepath());
|
||||
if ($file->is_directory()) {
|
||||
check_dir_exists(rtrim($path));
|
||||
} else {
|
||||
$file->copy_content_to($path . $file->get_filename());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all files of a type into one file.
|
||||
*
|
||||
* @param array $assets A list of files.
|
||||
* @param string $type The type of files in assets. Either 'scripts' or 'styles'
|
||||
* @param \context $context Context
|
||||
* @return string All of the file content in one string.
|
||||
*/
|
||||
private function concatenate_files(array $assets, string $type, \context $context): string {
|
||||
$content = '';
|
||||
foreach ($assets as $asset) {
|
||||
// Find location of asset.
|
||||
list(
|
||||
'filearea' => $filearea,
|
||||
'filepath' => $filepath,
|
||||
'filename' => $filename,
|
||||
'itemid' => $itemid
|
||||
) = $this->get_file_elements_from_filepath($asset->path);
|
||||
|
||||
if ($itemid === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Locate file.
|
||||
$file = $this->fs->get_file($context->id, self::COMPONENT, $filearea, $itemid, $filepath, $filename);
|
||||
|
||||
// Get file content and concatenate.
|
||||
if ($type === 'scripts') {
|
||||
$content .= $file->get_content() . ";\n";
|
||||
} else {
|
||||
// Rewrite relative URLs used inside stylesheets.
|
||||
$content .= preg_replace_callback(
|
||||
'/url\([\'"]?([^"\')]+)[\'"]?\)/i',
|
||||
function ($matches) use ($filearea, $filepath, $itemid) {
|
||||
if (preg_match("/^(data:|([a-z0-9]+:)?\/)/i", $matches[1]) === 1) {
|
||||
return $matches[0]; // Not relative, skip.
|
||||
}
|
||||
// Find "../" in matches[1].
|
||||
// If it exists, we have to remove "../".
|
||||
// And switch the last folder in the filepath for the first folder in $matches[1].
|
||||
// For instance:
|
||||
// $filepath: /H5P.Question-1.4/styles/
|
||||
// $matches[1]: ../images/plus-one.svg
|
||||
// We want to avoid this: H5P.Question-1.4/styles/ITEMID/../images/minus-one.svg
|
||||
// We want this: H5P.Question-1.4/images/ITEMID/minus-one.svg.
|
||||
if (preg_match('/\.\.\//', $matches[1], $pathmatches)) {
|
||||
$path = preg_split('/\//', $filepath, -1, PREG_SPLIT_NO_EMPTY);
|
||||
$pathfilename = preg_split('/\//', $matches[1], -1, PREG_SPLIT_NO_EMPTY);
|
||||
// Remove the first element: ../.
|
||||
array_shift($pathfilename);
|
||||
// Replace pathfilename into the filepath.
|
||||
$path[count($path) - 1] = $pathfilename[0];
|
||||
$filepath = '/' . implode('/', $path) . '/';
|
||||
// Remove the element used to replace.
|
||||
array_shift($pathfilename);
|
||||
$matches[1] = implode('/', $pathfilename);
|
||||
}
|
||||
return 'url("../' . $filearea . $filepath . $itemid . '/' . $matches[1] . '")';
|
||||
},
|
||||
$file->get_content()) . "\n";
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get files ready for export.
|
||||
*
|
||||
* @param string $filename File name to retrieve.
|
||||
* @return bool|\stored_file Stored file instance if exists, false if not
|
||||
*/
|
||||
private function get_export_file(string $filename) {
|
||||
return $this->fs->get_file($this->context->id, self::COMPONENT, self::EXPORT_FILEAREA, 0, '/', $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a relative system file path into Moodle File API elements.
|
||||
*
|
||||
* @param string $filepath The system filepath to get information from.
|
||||
* @return array File information.
|
||||
*/
|
||||
private function get_file_elements_from_filepath(string $filepath): array {
|
||||
$sections = explode('/', $filepath);
|
||||
// Get the filename.
|
||||
$filename = array_pop($sections);
|
||||
// Discard first element.
|
||||
if (empty($sections[0])) {
|
||||
array_shift($sections);
|
||||
}
|
||||
// Get the filearea.
|
||||
$filearea = array_shift($sections);
|
||||
$itemid = array_shift($sections);
|
||||
// Get the filepath.
|
||||
$filepath = implode('/', $sections);
|
||||
$filepath = '/' . $filepath . '/';
|
||||
|
||||
return ['filearea' => $filearea, 'filepath' => $filepath, 'filename' => $filename, 'itemid' => $itemid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the item id given the other necessary variables.
|
||||
*
|
||||
* @param string $filearea The file area.
|
||||
* @param string $filepath The file path.
|
||||
* @param string $filename The file name.
|
||||
* @return mixed the specified value false if not found.
|
||||
*/
|
||||
private function get_itemid_for_file(string $filearea, string $filepath, string $filename) {
|
||||
global $DB;
|
||||
return $DB->get_field('files', 'itemid', ['component' => self::COMPONENT, 'filearea' => $filearea, 'filepath' => $filepath,
|
||||
'filename' => $filename]);
|
||||
}
|
||||
}
|
1626
h5p/classes/framework.php
Normal file
1626
h5p/classes/framework.php
Normal file
File diff suppressed because it is too large
Load Diff
663
h5p/classes/player.php
Normal file
663
h5p/classes/player.php
Normal file
@ -0,0 +1,663 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* H5P player class.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* H5P player class, for displaying any local H5P content.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class player {
|
||||
|
||||
/**
|
||||
* @var string The local H5P URL containing the .h5p file to display.
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var core The H5PCore object.
|
||||
*/
|
||||
private $core;
|
||||
|
||||
/**
|
||||
* @var int H5P DB id.
|
||||
*/
|
||||
private $h5pid;
|
||||
|
||||
/**
|
||||
* @var array JavaScript requirements for this H5P.
|
||||
*/
|
||||
private $jsrequires = [];
|
||||
|
||||
/**
|
||||
* @var array CSS requirements for this H5P.
|
||||
*/
|
||||
private $cssrequires = [];
|
||||
|
||||
/**
|
||||
* @var array H5P content to display.
|
||||
*/
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @var string Type of embed object, div or iframe.
|
||||
*/
|
||||
private $embedtype;
|
||||
|
||||
/**
|
||||
* @var context The context object where the .h5p belongs.
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* @var context The \core_h5p\factory object.
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
/**
|
||||
* Inits the H5P player for rendering the content.
|
||||
*
|
||||
* @param string $url Local URL of the H5P file to display.
|
||||
* @param stdClass $config Configuration for H5P buttons.
|
||||
*/
|
||||
public function __construct(string $url, \stdClass $config) {
|
||||
if (empty($url)) {
|
||||
throw new \moodle_exception('h5pinvalidurl', 'core_h5p');
|
||||
}
|
||||
$this->url = new \moodle_url($url);
|
||||
|
||||
$this->factory = new \core_h5p\factory();
|
||||
|
||||
// Create \core_h5p\core instance.
|
||||
$this->core = $this->factory->get_core();
|
||||
|
||||
// Get the H5P identifier linked to this URL.
|
||||
if ($this->h5pid = $this->get_h5p_id($url, $config)) {
|
||||
// Load the content of the H5P content associated to this $url.
|
||||
$this->content = $this->core->loadContent($this->h5pid);
|
||||
|
||||
// Get the embedtype to use for displaying the H5P content.
|
||||
$this->embedtype = core::determineEmbedType($this->content['embedType'], $this->content['library']['embedTypes']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error messages stored in our H5P framework.
|
||||
*
|
||||
* @return stdClass with framework error messages.
|
||||
*/
|
||||
public function get_messages() : \stdClass {
|
||||
$messages = new \stdClass();
|
||||
$messages->error = $this->core->h5pF->getMessages('error');
|
||||
|
||||
if (empty($messages->error)) {
|
||||
$messages->error = false;
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the H5PIntegration variable that will be included in the page. This variable is used as the
|
||||
* main H5P config variable.
|
||||
*/
|
||||
public function add_assets_to_page() {
|
||||
global $PAGE;
|
||||
|
||||
$cid = $this->get_cid();
|
||||
$systemcontext = \context_system::instance();
|
||||
|
||||
$disable = array_key_exists('disable', $this->content) ? $this->content['disable'] : core::DISABLE_NONE;
|
||||
$displayoptions = $this->core->getDisplayOptionsForView($disable, $this->h5pid);
|
||||
|
||||
$contenturl = \moodle_url::make_pluginfile_url($systemcontext->id, \core_h5p\file_storage::COMPONENT,
|
||||
\core_h5p\file_storage::CONTENT_FILEAREA, $this->h5pid, null, null);
|
||||
|
||||
$contentsettings = [
|
||||
'library' => core::libraryToString($this->content['library']),
|
||||
'fullScreen' => $this->content['library']['fullscreen'],
|
||||
'exportUrl' => $this->get_export_settings($displayoptions[ core::DISPLAY_OPTION_DOWNLOAD ]),
|
||||
'embedCode' => $this->get_embed_code($this->url->out(),
|
||||
$displayoptions[ core::DISPLAY_OPTION_EMBED ]),
|
||||
'resizeCode' => $this->get_resize_code(),
|
||||
'title' => $this->content['slug'],
|
||||
'displayOptions' => $displayoptions,
|
||||
'url' => self::get_embed_url($this->url->out())->out(),
|
||||
'contentUrl' => $contenturl->out(),
|
||||
'metadata' => $this->content['metadata'],
|
||||
'contentUserData' => [0 => ['state' => '{}']]
|
||||
];
|
||||
// Get the core H5P assets, needed by the H5P classes to render the H5P content.
|
||||
$settings = $this->get_assets();
|
||||
$settings['contents'][$cid] = array_merge($settings['contents'][$cid], $contentsettings);
|
||||
|
||||
foreach ($this->jsrequires as $script) {
|
||||
$PAGE->requires->js($script, true);
|
||||
}
|
||||
|
||||
foreach ($this->cssrequires as $css) {
|
||||
$PAGE->requires->css($css);
|
||||
}
|
||||
|
||||
// Print JavaScript settings to page.
|
||||
$PAGE->requires->data_for_js('H5PIntegration', $settings, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs H5P wrapper HTML.
|
||||
*
|
||||
* @return string The HTML code to display this H5P content.
|
||||
*/
|
||||
public function output() : string {
|
||||
global $OUTPUT;
|
||||
|
||||
$template = new \stdClass();
|
||||
$template->h5pid = $this->h5pid;
|
||||
if ($this->embedtype === 'div') {
|
||||
return $OUTPUT->render_from_template('core_h5p/h5pdiv', $template);
|
||||
} else {
|
||||
return $OUTPUT->render_from_template('core_h5p/h5piframe', $template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the title of the H5P content to display.
|
||||
*
|
||||
* @return string the title
|
||||
*/
|
||||
public function get_title() : string {
|
||||
return $this->content['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context where the .h5p file belongs.
|
||||
*
|
||||
* @return context The context.
|
||||
*/
|
||||
public function get_context() : \context {
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the H5P DB instance id for a H5P pluginfile URL. The H5P file will be saved if it doesn't exist previously or
|
||||
* if its content has changed. Besides, the displayoptions in the $config will be also updated when they have changed and
|
||||
* the user has the right permissions.
|
||||
*
|
||||
* @param string $url H5P pluginfile URL.
|
||||
* @param stdClass $config Configuration for H5P buttons.
|
||||
*
|
||||
* @return int|false H5P DB identifier.
|
||||
*/
|
||||
private function get_h5p_id(string $url, \stdClass $config) {
|
||||
global $DB;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
// Deconstruct the URL and get the pathname associated.
|
||||
$pathnamehash = $this->get_pluginfile_hash($url);
|
||||
if (!$pathnamehash) {
|
||||
$this->core->h5pF->setErrorMessage(get_string('h5pfilenotfound', 'core_h5p'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the file.
|
||||
$file = $fs->get_file_by_hash($pathnamehash);
|
||||
if (!$file) {
|
||||
$this->core->h5pF->setErrorMessage(get_string('h5pfilenotfound', 'core_h5p'));
|
||||
return false;
|
||||
}
|
||||
|
||||
$h5p = $DB->get_record('h5p', ['pathnamehash' => $pathnamehash]);
|
||||
$contenthash = $file->get_contenthash();
|
||||
if ($h5p && $h5p->contenthash != $contenthash) {
|
||||
// The content exists and it is different from the one deployed previously. The existing one should be removed before
|
||||
// deploying the new version.
|
||||
$this->delete_h5p($h5p);
|
||||
$h5p = false;
|
||||
}
|
||||
|
||||
if ($h5p) {
|
||||
// The H5P content has been deployed previously.
|
||||
$displayoptions = $this->get_display_options($config);
|
||||
// Check if the user can set the displayoptions.
|
||||
if ($displayoptions != $h5p->displayoptions && has_capability('moodle/h5p:setdisplayoptions', $this->context)) {
|
||||
// If the displayoptions has changed and the user has permission to modify it, update this information in the DB.
|
||||
$this->core->h5pF->updateContentFields($h5p->id, ['displayoptions' => $displayoptions]);
|
||||
}
|
||||
return $h5p->id;
|
||||
} else {
|
||||
// The H5P content hasn't been deployed previously.
|
||||
|
||||
// Check if the user uploading the H5P content is "trustable". If the file hasn't been uploaded by a user with this
|
||||
// capability, the content won't be deployed and an error message will be displayed.
|
||||
if (!has_capability('moodle/h5p:deploy', $this->context, $file->get_userid())) {
|
||||
$this->core->h5pF->setErrorMessage(get_string('nopermissiontodeploy', 'core_h5p'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate and store the H5P content before displaying it.
|
||||
return $this->save_h5p($file, $config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pathnamehash from an H5P internal URL.
|
||||
*
|
||||
* @param string $url H5P pluginfile URL poiting to an H5P file.
|
||||
*
|
||||
* @return string|false pathnamehash for the file in the internal URL.
|
||||
*/
|
||||
private function get_pluginfile_hash(string $url) {
|
||||
global $USER;
|
||||
|
||||
// Decode the URL before start processing it.
|
||||
$url = new \moodle_url(urldecode($url));
|
||||
|
||||
// Remove params from the URL (such as the 'forcedownload=1'), to avoid errors.
|
||||
$url->remove_params(array_keys($url->params()));
|
||||
$path = $url->out_as_local_url();
|
||||
|
||||
$parts = explode('/', $path);
|
||||
$filename = array_pop($parts);
|
||||
// First is an empty row and then the pluginfile.php part. Both can be ignored.
|
||||
array_shift($parts);
|
||||
array_shift($parts);
|
||||
|
||||
// Get the contextid, component and filearea.
|
||||
$contextid = array_shift($parts);
|
||||
$component = array_shift($parts);
|
||||
$filearea = array_shift($parts);
|
||||
|
||||
// Ignore draft files, because they are considered temporary files, so shouldn't be displayed.
|
||||
if ($filearea == 'draft') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the context.
|
||||
try {
|
||||
list($this->context, $course, $cm) = get_context_info_array($contextid);
|
||||
} catch (\moodle_exception $e) {
|
||||
throw new \moodle_exception('invalidcontextid', 'core_h5p');
|
||||
}
|
||||
|
||||
// For CONTEXT_USER, such as the private files, raise an exception if the owner of the file is not the current user.
|
||||
if ($this->context->contextlevel == CONTEXT_USER && $USER->id !== $this->context->instanceid) {
|
||||
throw new \moodle_exception('h5pprivatefile', 'core_h5p');
|
||||
}
|
||||
|
||||
// For CONTEXT_MODULE, check if the user is enrolled in the course and has permissions view this .h5p file.
|
||||
if ($this->context->contextlevel == CONTEXT_MODULE) {
|
||||
// Require login to the course first (without login to the module).
|
||||
require_course_login($course, true, null, false, true);
|
||||
|
||||
// Now check if module is available OR it is restricted but the intro is shown on the course page.
|
||||
$cminfo = \cm_info::create($cm);
|
||||
if (!$cminfo->uservisible) {
|
||||
if (!$cm->showdescription || !$cminfo->is_visible_on_course_page()) {
|
||||
// Module intro is not visible on the course page and module is not available, show access error.
|
||||
require_course_login($course, true, $cminfo, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Some components, such as mod_page or mod_resource, add the revision to the URL to prevent caching problems.
|
||||
// So the URL contains this revision number as itemid but a 0 is always stored in the files table.
|
||||
// In order to get the proper hash, a callback should be done (looking for those exceptions).
|
||||
$pathdata = component_callback($component, 'get_path_from_pluginfile', [$filearea, $parts], null);
|
||||
if (null === $pathdata) {
|
||||
// Look for the components and fileareas which have empty itemid defined in xxx_pluginfile.
|
||||
$hasnullitemid = false;
|
||||
$hasnullitemid = $hasnullitemid || ($component === 'user' && ($filearea === 'private' || $filearea === 'profile'));
|
||||
$hasnullitemid = $hasnullitemid || ($component === 'mod' && $filearea === 'intro');
|
||||
$hasnullitemid = $hasnullitemid || ($component === 'course' &&
|
||||
($filearea === 'summary' || $filearea === 'overviewfiles'));
|
||||
$hasnullitemid = $hasnullitemid || ($component === 'coursecat' && $filearea === 'description');
|
||||
$hasnullitemid = $hasnullitemid || ($component === 'backup' &&
|
||||
($filearea === 'course' || $filearea === 'activity' || $filearea === 'automated'));
|
||||
if ($hasnullitemid) {
|
||||
$itemid = 0;
|
||||
} else {
|
||||
$itemid = array_shift($parts);
|
||||
}
|
||||
|
||||
if (empty($parts)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $parts) . '/';
|
||||
}
|
||||
} else {
|
||||
// The itemid and filepath have been returned by the component callback.
|
||||
[
|
||||
'itemid' => $itemid,
|
||||
'filepath' => $filepath,
|
||||
] = $pathdata;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
return $fs->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store an H5P file
|
||||
*
|
||||
* @param stored_file $file Moodle file instance
|
||||
* @param stdClass $config Button options config.
|
||||
*
|
||||
* @return int|false The H5P identifier or false if it's not a valid H5P package.
|
||||
*/
|
||||
private function save_h5p($file, \stdClass $config) : int {
|
||||
// This may take a long time.
|
||||
\core_php_time_limit::raise();
|
||||
|
||||
$path = $this->core->fs->getTmpPath();
|
||||
$this->core->h5pF->getUploadedH5pFolderPath($path);
|
||||
// Add manually the extension to the file to avoid the validation fails.
|
||||
$path .= '.h5p';
|
||||
$this->core->h5pF->getUploadedH5pPath($path);
|
||||
|
||||
// Copy the .h5p file to the temporary folder.
|
||||
$file->copy_content_to($path);
|
||||
|
||||
// Check if the h5p file is valid before saving it.
|
||||
$h5pvalidator = $this->factory->get_validator();
|
||||
if ($h5pvalidator->isValidPackage(false, false)) {
|
||||
$h5pstorage = $this->factory->get_storage();
|
||||
|
||||
$options = ['disable' => $this->get_display_options($config)];
|
||||
$content = [
|
||||
'pathnamehash' => $file->get_pathnamehash(),
|
||||
'contenthash' => $file->get_contenthash(),
|
||||
];
|
||||
|
||||
$h5pstorage->savePackage($content, null, false, $options);
|
||||
return $h5pstorage->contentId;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the representation of display options as int.
|
||||
* @param stdClass $config Button options config.
|
||||
*
|
||||
* @return int The representation of display options as int.
|
||||
*/
|
||||
private function get_display_options(\stdClass $config) : int {
|
||||
$export = isset($config->export) ? $config->export : 0;
|
||||
$embed = isset($config->embed) ? $config->embed : 0;
|
||||
$copyright = isset($config->copyright) ? $config->copyright : 0;
|
||||
$frame = ($export || $embed || $copyright);
|
||||
if (!$frame) {
|
||||
$frame = isset($config->frame) ? $config->frame : 0;
|
||||
}
|
||||
|
||||
$disableoptions = [
|
||||
core::DISPLAY_OPTION_FRAME => $frame,
|
||||
core::DISPLAY_OPTION_DOWNLOAD => $export,
|
||||
core::DISPLAY_OPTION_EMBED => $embed,
|
||||
core::DISPLAY_OPTION_COPYRIGHT => $copyright,
|
||||
];
|
||||
|
||||
return $this->core->getStorableDisplayOptions($disableoptions, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an H5P package.
|
||||
*
|
||||
* @param stdClass $content The H5P package to delete.
|
||||
*/
|
||||
private function delete_h5p(\stdClass $content) {
|
||||
$h5pstorage = $this->factory->get_storage();
|
||||
// Add an empty slug to the content if it's not defined, because the H5P library requires this field exists.
|
||||
// It's not used when deleting a package, so the real slug value is not required at this point.
|
||||
$content->slug = $content->slug ?? '';
|
||||
$h5pstorage->deletePackage( (array) $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export path for settings
|
||||
*
|
||||
* @param bool $downloadenabled Whether the option to export the H5P content is enabled.
|
||||
*
|
||||
* @return string The URL of the exported file.
|
||||
*/
|
||||
private function get_export_settings(bool $downloadenabled) : string {
|
||||
|
||||
if ( ! $downloadenabled) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$systemcontext = \context_system::instance();
|
||||
$slug = $this->content['slug'] ? $this->content['slug'] . '-' : '';
|
||||
$url = \moodle_url::make_pluginfile_url(
|
||||
$systemcontext->id,
|
||||
\core_h5p\file_storage::COMPONENT,
|
||||
\core_h5p\file_storage::EXPORT_FILEAREA,
|
||||
'',
|
||||
'',
|
||||
"{$slug}{$this->content['id']}.h5p"
|
||||
);
|
||||
|
||||
return $url->out();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a query string with the theme revision number to include at the end
|
||||
* of URLs. This is used to force the browser to reload the asset when the
|
||||
* theme caches are cleared.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_cache_buster() : string {
|
||||
global $CFG;
|
||||
return '?ver=' . $CFG->themerev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier for the H5P content, to be used in the arrays as index.
|
||||
*
|
||||
* @return string The identifier.
|
||||
*/
|
||||
private function get_cid() : string {
|
||||
return 'cid-' . $this->h5pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the core H5P assets, including all core H5P JavaScript and CSS.
|
||||
*
|
||||
* @return Array core H5P assets.
|
||||
*/
|
||||
private function get_assets() : array {
|
||||
global $CFG;
|
||||
|
||||
// Get core settings.
|
||||
$settings = $this->get_core_settings();
|
||||
$settings['core'] = [
|
||||
'styles' => [],
|
||||
'scripts' => []
|
||||
];
|
||||
$settings['loadedJs'] = [];
|
||||
$settings['loadedCss'] = [];
|
||||
|
||||
// Make sure files are reloaded for each plugin update.
|
||||
$cachebuster = $this->get_cache_buster();
|
||||
|
||||
// Use relative URL to support both http and https.
|
||||
$liburl = $CFG->wwwroot . '/lib/h5p/';
|
||||
$relpath = '/' . preg_replace('/^[^:]+:\/\/[^\/]+\//', '', $liburl);
|
||||
|
||||
// Add core stylesheets.
|
||||
foreach (core::$styles as $style) {
|
||||
$settings['core']['styles'][] = $relpath . $style . $cachebuster;
|
||||
$this->cssrequires[] = new \moodle_url($liburl . $style . $cachebuster);
|
||||
}
|
||||
// Add core JavaScript.
|
||||
foreach (core::get_scripts() as $script) {
|
||||
$settings['core']['scripts'][] = $script->out(false);
|
||||
$this->jsrequires[] = $script;
|
||||
}
|
||||
|
||||
$cid = $this->get_cid();
|
||||
// The filterParameters function should be called before getting the dependencyfiles because it rebuild content
|
||||
// dependency cache and export file.
|
||||
$settings['contents'][$cid]['jsonContent'] = $this->core->filterParameters($this->content);
|
||||
|
||||
$files = $this->get_dependency_files();
|
||||
if ($this->embedtype === 'div') {
|
||||
$systemcontext = \context_system::instance();
|
||||
$h5ppath = "/pluginfile.php/{$systemcontext->id}/core_h5p";
|
||||
|
||||
// Schedule JavaScripts for loading through Moodle.
|
||||
foreach ($files['scripts'] as $script) {
|
||||
$url = $script->path . $script->version;
|
||||
|
||||
// Add URL prefix if not external.
|
||||
$isexternal = strpos($script->path, '://');
|
||||
if ($isexternal === false) {
|
||||
$url = $h5ppath . $url;
|
||||
}
|
||||
$settings['loadedJs'][] = $url;
|
||||
$this->jsrequires[] = new \moodle_url($isexternal ? $url : $CFG->wwwroot . $url);
|
||||
}
|
||||
|
||||
// Schedule stylesheets for loading through Moodle.
|
||||
foreach ($files['styles'] as $style) {
|
||||
$url = $style->path . $style->version;
|
||||
|
||||
// Add URL prefix if not external.
|
||||
$isexternal = strpos($style->path, '://');
|
||||
if ($isexternal === false) {
|
||||
$url = $h5ppath . $url;
|
||||
}
|
||||
$settings['loadedCss'][] = $url;
|
||||
$this->cssrequires[] = new \moodle_url($isexternal ? $url : $CFG->wwwroot . $url);
|
||||
}
|
||||
|
||||
} else {
|
||||
// JavaScripts and stylesheets will be loaded through h5p.js.
|
||||
$settings['contents'][$cid]['scripts'] = $this->core->getAssetsUrls($files['scripts']);
|
||||
$settings['contents'][$cid]['styles'] = $this->core->getAssetsUrls($files['styles']);
|
||||
}
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings needed by the H5P library.
|
||||
*
|
||||
* @return array The settings.
|
||||
*/
|
||||
private function get_core_settings() : array {
|
||||
global $CFG;
|
||||
|
||||
$basepath = $CFG->wwwroot . '/';
|
||||
$systemcontext = \context_system::instance();
|
||||
|
||||
// Generate AJAX paths.
|
||||
$ajaxpaths = [];
|
||||
$ajaxpaths['xAPIResult'] = '';
|
||||
$ajaxpaths['contentUserData'] = '';
|
||||
|
||||
$settings = array(
|
||||
'baseUrl' => $basepath,
|
||||
'url' => "{$basepath}pluginfile.php/{$systemcontext->instanceid}/core_h5p",
|
||||
'urlLibraries' => "{$basepath}pluginfile.php/{$systemcontext->id}/core_h5p/libraries",
|
||||
'postUserStatistics' => false,
|
||||
'ajax' => $ajaxpaths,
|
||||
'saveFreq' => false,
|
||||
'siteUrl' => $CFG->wwwroot,
|
||||
'l10n' => array('H5P' => $this->core->getLocalization()),
|
||||
'user' => [],
|
||||
'hubIsEnabled' => false,
|
||||
'reportingIsEnabled' => false,
|
||||
'crossorigin' => null,
|
||||
'libraryConfig' => $this->core->h5pF->getLibraryConfig(),
|
||||
'pluginCacheBuster' => $this->get_cache_buster(),
|
||||
'libraryUrl' => $basepath . 'lib/h5p/js',
|
||||
'moodleLibraryPaths' => $this->core->get_dependency_roots($this->h5pid),
|
||||
);
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds library dependencies of view
|
||||
*
|
||||
* @return array Files that the view has dependencies to
|
||||
*/
|
||||
private function get_dependency_files() : array {
|
||||
$preloadeddeps = $this->core->loadContentDependencies($this->h5pid, 'preloaded');
|
||||
$files = $this->core->getDependenciesFiles($preloadeddeps);
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizing script for settings
|
||||
*
|
||||
* @return string The HTML code with the resize script.
|
||||
*/
|
||||
private function get_resize_code() : string {
|
||||
global $OUTPUT;
|
||||
|
||||
$template = new \stdClass();
|
||||
$template->resizeurl = new \moodle_url('/lib/h5p/js/h5p-resizer.js');
|
||||
|
||||
return $OUTPUT->render_from_template('core_h5p/h5presize', $template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed code for settings
|
||||
*
|
||||
* @param string $url The URL of the .h5p file.
|
||||
* @param bool $embedenabled Whether the option to embed the H5P content is enabled.
|
||||
*
|
||||
* @return string The HTML code to reuse this H5P content in a different place.
|
||||
*/
|
||||
private function get_embed_code(string $url, bool $embedenabled) : string {
|
||||
global $OUTPUT;
|
||||
|
||||
if ( ! $embedenabled) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$template = new \stdClass();
|
||||
$template->embedurl = self::get_embed_url($url)->out();
|
||||
|
||||
return $OUTPUT->render_from_template('core_h5p/h5pembed', $template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the encoded URL for embeding this H5P content.
|
||||
* @param string $url The URL of the .h5p file.
|
||||
*
|
||||
* @return \moodle_url The embed URL.
|
||||
*/
|
||||
public static function get_embed_url(string $url) : \moodle_url {
|
||||
return new \moodle_url('/h5p/embed.php', ['url' => $url]);
|
||||
}
|
||||
}
|
45
h5p/classes/privacy/provider.php
Normal file
45
h5p/classes/privacy/provider.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Privacy provider implementation for h5p core subsytem.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p\privacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Privacy provider implementation for h5p core subsystem.
|
||||
*
|
||||
* @copyright 2019 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class provider implements \core_privacy\local\metadata\null_provider {
|
||||
/**
|
||||
* Get the language string identifier with the component's language
|
||||
* file to explain why this plugin stores no data.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_reason() : string {
|
||||
return 'privacy:metadata';
|
||||
}
|
||||
}
|
93
h5p/embed.php
Normal file
93
h5p/embed.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Render H5P content from an H5P file.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
|
||||
// The login check is done inside the player when getting the file from the url param.
|
||||
|
||||
$url = required_param('url', PARAM_LOCALURL);
|
||||
|
||||
$config = new stdClass();
|
||||
$config->frame = optional_param('frame', 0, PARAM_INT);
|
||||
$config->export = optional_param('export', 0, PARAM_INT);
|
||||
$config->embed = optional_param('embed', 0, PARAM_INT);
|
||||
$config->copyright = optional_param('copyright', 0, PARAM_INT);
|
||||
|
||||
$PAGE->set_url(new \moodle_url('/h5p/embed.php', array('url' => $url)));
|
||||
try {
|
||||
$h5pplayer = new \core_h5p\player($url, $config);
|
||||
$messages = $h5pplayer->get_messages();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$messages = (object) [
|
||||
'exception' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($messages->error) && empty($messages->exception)) {
|
||||
// Configure page.
|
||||
$PAGE->set_context($h5pplayer->get_context());
|
||||
$PAGE->set_title($h5pplayer->get_title());
|
||||
$PAGE->set_heading($h5pplayer->get_title());
|
||||
|
||||
// Embed specific page setup.
|
||||
$PAGE->add_body_class('h5p-embed');
|
||||
$PAGE->set_pagelayout('embedded');
|
||||
|
||||
// Load the embed.js to allow communication with the parent window.
|
||||
$PAGE->requires->js(new moodle_url('/h5p/js/embed.js'));
|
||||
|
||||
// Add H5P assets to the page.
|
||||
$h5pplayer->add_assets_to_page();
|
||||
|
||||
// Check if there is some error when adding assets to the page.
|
||||
$messages = $h5pplayer->get_messages();
|
||||
if (empty($messages->error) && empty($messages->exception)) {
|
||||
|
||||
// Print page HTML.
|
||||
echo $OUTPUT->header();
|
||||
|
||||
echo $h5pplayer->output();
|
||||
}
|
||||
} else {
|
||||
// If there is any error or exception when creating the player, it should be displayed.
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$title = get_string('h5p', 'core_h5p');
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($title);
|
||||
|
||||
$PAGE->add_body_class('h5p-embed');
|
||||
$PAGE->set_pagelayout('embedded');
|
||||
|
||||
// Errors can't be printed yet, because some more errors might been added while preparing the output
|
||||
}
|
||||
|
||||
if (!empty($messages->error) || !empty($messages->exception)) {
|
||||
// Print all the errors.
|
||||
echo $OUTPUT->header();
|
||||
$messages->h5picon = new \moodle_url('/h5p/pix/icon.svg');
|
||||
echo $OUTPUT->render_from_template('core_h5p/h5perror', $messages);
|
||||
}
|
||||
|
||||
echo $OUTPUT->footer();
|
155
h5p/js/embed.js
Normal file
155
h5p/js/embed.js
Normal file
@ -0,0 +1,155 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/* global H5PEmbedCommunicator:true */
|
||||
/**
|
||||
* When embedded the communicator helps talk to the parent page.
|
||||
* This is a copy of the H5P.communicator, which we need to communicate in this context
|
||||
*
|
||||
* @type {H5PEmbedCommunicator}
|
||||
* @module core_h5p
|
||||
* @copyright 2019 Joubel AS <contact@joubel.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
H5PEmbedCommunicator = (function() {
|
||||
/**
|
||||
* @class
|
||||
* @private
|
||||
*/
|
||||
function Communicator() {
|
||||
var self = this;
|
||||
|
||||
// Maps actions to functions.
|
||||
var actionHandlers = {};
|
||||
|
||||
// Register message listener.
|
||||
window.addEventListener('message', function receiveMessage(event) {
|
||||
if (window.parent !== event.source || event.data.context !== 'h5p') {
|
||||
return; // Only handle messages from parent and in the correct context.
|
||||
}
|
||||
|
||||
if (actionHandlers[event.data.action] !== undefined) {
|
||||
actionHandlers[event.data.action](event.data);
|
||||
}
|
||||
}, false);
|
||||
|
||||
/**
|
||||
* Register action listener.
|
||||
*
|
||||
* @param {string} action What you are waiting for
|
||||
* @param {function} handler What you want done
|
||||
*/
|
||||
self.on = function(action, handler) {
|
||||
actionHandlers[action] = handler;
|
||||
};
|
||||
|
||||
/**
|
||||
* Send a message to the all mighty father.
|
||||
*
|
||||
* @param {string} action
|
||||
* @param {Object} [data] payload
|
||||
*/
|
||||
self.send = function(action, data) {
|
||||
if (data === undefined) {
|
||||
data = {};
|
||||
}
|
||||
data.context = 'h5p';
|
||||
data.action = action;
|
||||
|
||||
// Parent origin can be anything.
|
||||
window.parent.postMessage(data, '*');
|
||||
};
|
||||
}
|
||||
|
||||
return (window.postMessage && window.addEventListener ? new Communicator() : undefined);
|
||||
})();
|
||||
|
||||
document.onreadystatechange = function() {
|
||||
// Wait for instances to be initialize.
|
||||
if (document.readyState !== 'complete') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for H5P iFrame.
|
||||
var iFrame = document.querySelector('.h5p-iframe');
|
||||
if (!iFrame || !iFrame.contentWindow) {
|
||||
return;
|
||||
}
|
||||
var H5P = iFrame.contentWindow.H5P;
|
||||
|
||||
// Check for H5P instances.
|
||||
if (!H5P || !H5P.instances || !H5P.instances[0]) {
|
||||
return;
|
||||
}
|
||||
|
||||
var resizeDelay;
|
||||
var instance = H5P.instances[0];
|
||||
var parentIsFriendly = false;
|
||||
|
||||
// Handle that the resizer is loaded after the iframe.
|
||||
H5PEmbedCommunicator.on('ready', function() {
|
||||
H5PEmbedCommunicator.send('hello');
|
||||
});
|
||||
|
||||
// Handle hello message from our parent window.
|
||||
H5PEmbedCommunicator.on('hello', function() {
|
||||
// Initial setup/handshake is done.
|
||||
parentIsFriendly = true;
|
||||
|
||||
// Hide scrollbars for correct size.
|
||||
iFrame.contentDocument.body.style.overflow = 'hidden';
|
||||
|
||||
document.body.classList.add('h5p-resizing');
|
||||
|
||||
// Content need to be resized to fit the new iframe size.
|
||||
H5P.trigger(instance, 'resize');
|
||||
});
|
||||
|
||||
// When resize has been prepared tell parent window to resize.
|
||||
H5PEmbedCommunicator.on('resizePrepared', function() {
|
||||
H5PEmbedCommunicator.send('resize', {
|
||||
scrollHeight: iFrame.contentDocument.body.scrollHeight
|
||||
});
|
||||
});
|
||||
|
||||
H5PEmbedCommunicator.on('resize', function() {
|
||||
H5P.trigger(instance, 'resize');
|
||||
});
|
||||
|
||||
H5P.on(instance, 'resize', function() {
|
||||
if (H5P.isFullscreen) {
|
||||
return; // Skip iframe resize.
|
||||
}
|
||||
|
||||
// Use a delay to make sure iframe is resized to the correct size.
|
||||
clearTimeout(resizeDelay);
|
||||
resizeDelay = setTimeout(function() {
|
||||
// Only resize if the iframe can be resized.
|
||||
if (parentIsFriendly) {
|
||||
H5PEmbedCommunicator.send('prepareResize',
|
||||
{
|
||||
scrollHeight: iFrame.contentDocument.body.scrollHeight,
|
||||
clientHeight: iFrame.contentDocument.body.clientHeight
|
||||
}
|
||||
);
|
||||
} else {
|
||||
H5PEmbedCommunicator.send('hello');
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
|
||||
// Trigger initial resize for instance.
|
||||
H5P.trigger(instance, 'resize');
|
||||
};
|
9
h5p/js/h5p_overrides.js
Normal file
9
h5p/js/h5p_overrides.js
Normal file
@ -0,0 +1,9 @@
|
||||
H5P._getLibraryPath = H5P.getLibraryPath;
|
||||
H5P.getLibraryPath = function (library) {
|
||||
if (H5PIntegration.moodleLibraryPaths) {
|
||||
if (H5PIntegration.moodleLibraryPaths[library]) {
|
||||
return H5PIntegration.moodleLibraryPaths[library];
|
||||
}
|
||||
}
|
||||
return H5P._getLibraryPath(library);
|
||||
};
|
115
h5p/lib.php
Normal file
115
h5p/lib.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Callbacks.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Bas Brands <bas@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Serve the files from the core_h5p file areas.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @category files
|
||||
*
|
||||
* @param stdClass $course the course object
|
||||
* @param stdClass $cm the course module object
|
||||
* @param stdClass $context the newmodule's context
|
||||
* @param string $filearea the name of the file area
|
||||
* @param array $args extra arguments (itemid, path)
|
||||
* @param bool $forcedownload whether or not force download
|
||||
* @param array $options additional options affecting the file serving
|
||||
*
|
||||
* @return bool Returns false if we don't find a file.
|
||||
*/
|
||||
function core_h5p_pluginfile($course, $cm, $context, string $filearea, array $args, bool $forcedownload,
|
||||
array $options = []) : bool {
|
||||
global $DB;
|
||||
|
||||
// Require classes from H5P third party library
|
||||
\core_h5p\autoloader::register();
|
||||
|
||||
$filesettingsset = false;
|
||||
|
||||
switch ($filearea) {
|
||||
default:
|
||||
return false; // Invalid file area.
|
||||
|
||||
case \core_h5p\file_storage::LIBRARY_FILEAREA:
|
||||
if ($context->contextlevel != CONTEXT_SYSTEM) {
|
||||
return false; // Invalid context because the libraries are loaded always in the context system.
|
||||
}
|
||||
|
||||
$itemid = null;
|
||||
|
||||
// The files that can be delivered to this function are unfortunately out of our control. Some of the
|
||||
// references are embedded into the JavaScript of the files and we have no ability to inject an item id.
|
||||
// We also don't know the location of the item id when we do include it, so we look for the first numeric
|
||||
// value and try to serve that file.
|
||||
foreach ($args as $key => $value) {
|
||||
if (is_numeric($value)) {
|
||||
$itemid = $value;
|
||||
unset($args[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($itemid)) {
|
||||
// We didn't find an item id to use, so we fall back to retrieving the record using all the other
|
||||
// fields. The combination of component, filearea, filepath, and filename is enough for a unique
|
||||
// record.
|
||||
$filename = array_pop($args);
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
$itemid = $DB->get_field('files', 'itemid', [
|
||||
'component' => \core_h5p\file_storage::COMPONENT,
|
||||
'filearea' => \core_h5p\file_storage::LIBRARY_FILEAREA,
|
||||
'filepath' => $filepath,
|
||||
'filename' => $filename
|
||||
]);
|
||||
$filesettingsset = true;
|
||||
}
|
||||
break;
|
||||
case \core_h5p\file_storage::CONTENT_FILEAREA:
|
||||
if ($context->contextlevel != CONTEXT_SYSTEM) {
|
||||
return false; // Invalid context because the content files are loaded always in the context system.
|
||||
}
|
||||
$itemid = array_shift($args);
|
||||
break;
|
||||
case \core_h5p\file_storage::CACHED_ASSETS_FILEAREA:
|
||||
case \core_h5p\file_storage::EXPORT_FILEAREA:
|
||||
$itemid = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$filesettingsset) {
|
||||
$filename = array_pop($args);
|
||||
$filepath = (!$args ? '/' : '/' . implode('/', $args) . '/');
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
$file = $fs->get_file($context->id, \core_h5p\file_storage::COMPONENT, $filearea, $itemid, $filepath, $filename);
|
||||
if (!$file) {
|
||||
return false; // No such file.
|
||||
}
|
||||
|
||||
send_stored_file($file, null, 0, $forcedownload, $options);
|
||||
|
||||
return true;
|
||||
}
|
14
h5p/pix/icon.svg
Normal file
14
h5p/pix/icon.svg
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 23.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 345 150" style="enable-background:new 0 0 345 150;" xml:space="preserve">
|
||||
<g>
|
||||
<path d="M325.7,14.7C317.6,6.9,305.3,3,289,3h-43.5H234v31h-66l-5.4,22.2c4.5-2.1,10.9-4.2,15.3-5.3c4.4-1.1,8.8-0.9,13.1-0.9
|
||||
c14.6,0,26.5,4.5,35.6,13.3c9.1,8.8,13.6,20,13.6,33.4c0,9.4-2.3,18.5-7,27.2s-11.3,15.4-19.9,20c-3.1,1.6-6.5,3.1-10.2,4.1h42.4
|
||||
H259V95h25c18.2,0,31.7-4.2,40.6-12.5s13.3-19.9,13.3-34.6C337.9,33.6,333.8,22.5,325.7,14.7z M288.7,60.6c-3.5,3-9.6,4.4-18.3,4.4
|
||||
H259V33h13.2c8.4,0,14.2,1.5,17.2,4.7c3.1,3.2,4.6,6.9,4.6,11.5C294,53.9,292.2,57.6,288.7,60.6z"/>
|
||||
<path d="M176.5,76.3c-7.9,0-14.7,4.6-18,11.2L119,81.9L136.8,3h-23.6H101v62H51V3H7v145h44V95h50v53h12.2h42
|
||||
c-6.7-2-12.5-4.6-17.2-8.1c-4.8-3.6-8.7-7.7-11.7-12.3c-3-4.6-5.3-9.7-7.3-16.5l39.6-5.7c3.3,6.6,10.1,11.1,17.9,11.1
|
||||
c11.1,0,20.1-9,20.1-20.1S187.5,76.3,176.5,76.3z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
34
h5p/templates/h5pdiv.mustache
Normal file
34
h5p/templates/h5pdiv.mustache
Normal file
@ -0,0 +1,34 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_message/h5pdiv
|
||||
|
||||
This template will render an div for h5p content.
|
||||
|
||||
Variables required for this template:
|
||||
* h5pid - The database id for the H5P content
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"h5pid": 123
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
<div class="h5p-content-wrapper">
|
||||
<div class="h5p-content" data-content-id="{{h5pid}}"></div>
|
||||
</div>
|
32
h5p/templates/h5pembed.mustache
Normal file
32
h5p/templates/h5pembed.mustache
Normal file
@ -0,0 +1,32 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_message/h5pembed
|
||||
|
||||
This template will render the embed code shown in the H5P content embed popup.
|
||||
|
||||
Variables required for this template:
|
||||
* embedurl - The URL with the H5P file to embed
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"embedurl": "http://example.com/h5p/embed.php?url=testurl"
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
<iframe src="{{embedurl}}" width=":w" height=":h" allowfullscreen="allowfullscreen"></iframe>
|
51
h5p/templates/h5perror.mustache
Normal file
51
h5p/templates/h5perror.mustache
Normal file
@ -0,0 +1,51 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_message/h5perror
|
||||
|
||||
This template will render the embed code shown in the H5P content embed popup.
|
||||
|
||||
Variables required for this template:
|
||||
* h5picon - The icon
|
||||
* message - The error message to display.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"embedurl": "http://example.com/h5p/embed.php?url=testurl"
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
<div class="d-flex h-100 position-relative align-items-center bg-light h5pmessages">
|
||||
<div class="position-absolute py-2 bg-secondary" style="top: 0px; left: 0px; right: 0px;">
|
||||
<div class="container">
|
||||
<img src="{{{h5picon}}}" class="h5picon" alt="{{#str}}h5p, core_h5p{{/str}}" style="width: 50px; height: auto; opacity: 0.5">
|
||||
</div>
|
||||
</div>
|
||||
<div class="container mt-5">
|
||||
{{#exception}}
|
||||
<div class="alert alert-block fade in alert-danger my-2" role="alert">
|
||||
{{{ exception }}}
|
||||
</div>
|
||||
{{/exception}}
|
||||
{{#error}}
|
||||
<div class="alert alert-block fade in alert-warning my-2" role="alert">
|
||||
{{{code}}} : {{{ message }}}
|
||||
</div>
|
||||
{{/error}}
|
||||
</div>
|
||||
</div>
|
35
h5p/templates/h5piframe.mustache
Normal file
35
h5p/templates/h5piframe.mustache
Normal file
@ -0,0 +1,35 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_h5p/h5piframe
|
||||
|
||||
This template will render an iframe for h5p content.
|
||||
|
||||
Variables required for this template:
|
||||
* h5pid - The database id for the H5P content
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"h5pid": 123
|
||||
}
|
||||
|
||||
}}
|
||||
<div class="h5p-iframe-wrapper">
|
||||
<iframe id="h5p-iframe-{{h5pid}}" class="h5p-iframe" data-content-id="{{h5pid}}"
|
||||
style="height:1px; min-width: 100%" src="about:blank">
|
||||
</iframe>
|
||||
</div>
|
32
h5p/templates/h5presize.mustache
Normal file
32
h5p/templates/h5presize.mustache
Normal file
@ -0,0 +1,32 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_message/h5presize
|
||||
|
||||
This template will render the resize JS code.
|
||||
|
||||
Variables required for this template:
|
||||
* resizeurl - The database id for the H5P content
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"resizeurl": "http://example.com/lib/h5p/js/h5p-resizer.js"
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
<script src="{{resizeurl}}"></script>
|
48
h5p/tests/coverage.php
Normal file
48
h5p/tests/coverage.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Coverage information for the core_h5p subsystem.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @category phpunit
|
||||
* @copyright 2019 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Coverage information for the core H5P subsystem.
|
||||
*
|
||||
* @copyright 2019 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
return new class extends phpunit_coverage_info {
|
||||
/** @var array The list of folders relative to the plugin root to whitelist in coverage generation. */
|
||||
protected $whitelistfolders = [
|
||||
'classes',
|
||||
];
|
||||
|
||||
/** @var array The list of files relative to the plugin root to whitelist in coverage generation. */
|
||||
protected $whitelistfiles = [];
|
||||
|
||||
/** @var array The list of folders relative to the plugin root to excludelist in coverage generation. */
|
||||
protected $excludelistfolders = [];
|
||||
|
||||
/** @var array The list of files relative to the plugin root to excludelist in coverage generation. */
|
||||
protected $excludelistfiles = [];
|
||||
};
|
BIN
h5p/tests/fixtures/h5ptest.zip
vendored
Normal file
BIN
h5p/tests/fixtures/h5ptest.zip
vendored
Normal file
Binary file not shown.
2017
h5p/tests/framework_test.php
Normal file
2017
h5p/tests/framework_test.php
Normal file
File diff suppressed because it is too large
Load Diff
342
h5p/tests/generator/lib.php
Normal file
342
h5p/tests/generator/lib.php
Normal file
@ -0,0 +1,342 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Generator for the core_h5p subsystem.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @category test
|
||||
* @copyright 2019 Victor Deniz <victor@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Generator for the core_h5p subsystem.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @category test
|
||||
* @copyright 2019 Victor Deniz <victor@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_h5p_generator extends \component_generator_base {
|
||||
|
||||
/**
|
||||
* Convenience function to create a file.
|
||||
*
|
||||
* @param string $file path to a file.
|
||||
* @param string $content file content.
|
||||
*/
|
||||
public function create_file(string $file, string $content=''): void {
|
||||
$handle = fopen($file, 'w+');
|
||||
// File content is not relevant.
|
||||
if (empty($content)) {
|
||||
$content = hash("md5", $file);
|
||||
}
|
||||
fwrite($handle, $content);
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the file record. Currently used for the cache tests.
|
||||
*
|
||||
* @param string $type Either 'scripts' or 'styles'.
|
||||
* @param string $path Path to the file in the file system.
|
||||
* @param string $version Not really needed at the moment.
|
||||
*/
|
||||
protected function add_libfile_to_array(string $type, string $path, string $version, &$files): void {
|
||||
$files[$type][] = (object)[
|
||||
'path' => $path,
|
||||
'version' => "?ver=$version"
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the necessary files and return an array structure for a library.
|
||||
*
|
||||
* @param string $uploaddirectory Base directory for the library.
|
||||
* @param int $libraryid Library id.
|
||||
* @param string $machinename Name for this library.
|
||||
* @param int $majorversion Major version (any number will do).
|
||||
* @param int $minorversion Minor version (any number will do).
|
||||
* @return array A list of library data and files that the core API will understand.
|
||||
*/
|
||||
public function create_library(string $uploaddirectory, int $libraryid, string $machinename, int $majorversion,
|
||||
int $minorversion): array {
|
||||
/** @var array $files an array used in the cache tests. */
|
||||
$files = ['scripts' => [], 'styles' => []];
|
||||
|
||||
check_dir_exists($uploaddirectory . '/' . 'scripts');
|
||||
check_dir_exists($uploaddirectory . '/' . 'styles');
|
||||
|
||||
$jsonfile = $uploaddirectory . '/' . 'library.json';
|
||||
$jsfile = $uploaddirectory . '/' . 'scripts/testlib.min.js';
|
||||
$cssfile = $uploaddirectory . '/' . 'styles/testlib.min.css';
|
||||
$this->create_file($jsonfile);
|
||||
$this->create_file($jsfile);
|
||||
$this->create_file($cssfile);
|
||||
|
||||
$lib = [
|
||||
'title' => 'Test lib',
|
||||
'description' => 'Test library description',
|
||||
'majorVersion' => $majorversion,
|
||||
'minorVersion' => $minorversion,
|
||||
'patchVersion' => 2,
|
||||
'machineName' => $machinename,
|
||||
'preloadedJs' => [
|
||||
[
|
||||
'path' => 'scripts' . '/' . 'testlib.min.js'
|
||||
]
|
||||
],
|
||||
'preloadedCss' => [
|
||||
[
|
||||
'path' => 'styles' . '/' . 'testlib.min.css'
|
||||
]
|
||||
],
|
||||
'uploadDirectory' => $uploaddirectory,
|
||||
'libraryId' => $libraryid
|
||||
];
|
||||
|
||||
$version = "{$majorversion}.{$minorversion}.2";
|
||||
$libname = "{$machinename}-{$majorversion}.{$minorversion}";
|
||||
$path = '/' . 'libraries' . '/' . $libraryid . '/' . $libname . '/' . 'scripts' . '/' . 'testlib.min.js';
|
||||
$this->add_libfile_to_array('scripts', $path, $version, $files);
|
||||
$path = '/' . 'libraries' . '/' . $libraryid .'/' . $libname . '/' . 'styles' . '/' . 'testlib.min.css';
|
||||
$this->add_libfile_to_array('styles', $path, $version, $files);
|
||||
|
||||
return [$lib, $files];
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the library files on the filesystem.
|
||||
*
|
||||
* @param stdClss $lib The library data
|
||||
*/
|
||||
private function save_library(stdClass $lib) {
|
||||
// Get a temp path.
|
||||
$filestorage = new \core_h5p\file_storage();
|
||||
$temppath = $filestorage->getTmpPath();
|
||||
|
||||
// Create and save the library files on the filesystem.
|
||||
$basedirectorymain = $temppath . '/' . $lib->machinename . '-' .
|
||||
$lib->majorversion . '.' . $lib->minorversion;
|
||||
|
||||
list($library, $libraryfiles) = $this->create_library($basedirectorymain, $lib->id, $lib->machinename,
|
||||
$lib->majorversion, $lib->minorversion);
|
||||
|
||||
$filestorage->saveLibrary($library);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate H5P database tables with relevant data to simulate the process of adding H5P content.
|
||||
*
|
||||
* @param bool $createlibraryfiles Whether to create and store library files on the filesystem
|
||||
* @return stdClass An object representing the added H5P records
|
||||
*/
|
||||
public function generate_h5p_data(bool $createlibraryfiles = false): stdClass {
|
||||
// Create libraries.
|
||||
$mainlib = $libraries[] = $this->create_library_record('MainLibrary', 'Main Lib', 1, 0);
|
||||
$lib1 = $libraries[] = $this->create_library_record('Library1', 'Lib1', 2, 0);
|
||||
$lib2 = $libraries[] = $this->create_library_record('Library2', 'Lib2', 2, 1);
|
||||
$lib3 = $libraries[] = $this->create_library_record('Library3', 'Lib3', 3, 2);
|
||||
$lib4 = $libraries[] = $this->create_library_record('Library4', 'Lib4', 1, 1);
|
||||
$lib5 = $libraries[] = $this->create_library_record('Library5', 'Lib5', 1, 3);
|
||||
|
||||
if ($createlibraryfiles) {
|
||||
foreach ($libraries as $lib) {
|
||||
// Create and save the library files on the filesystem.
|
||||
$this->save_library($lib);
|
||||
}
|
||||
}
|
||||
|
||||
// Create h5p content.
|
||||
$h5p = $this->create_h5p_record($mainlib->id);
|
||||
// Create h5p content library dependencies.
|
||||
$this->create_contents_libraries_record($h5p, $mainlib->id);
|
||||
$this->create_contents_libraries_record($h5p, $lib1->id);
|
||||
$this->create_contents_libraries_record($h5p, $lib2->id);
|
||||
$this->create_contents_libraries_record($h5p, $lib3->id);
|
||||
$this->create_contents_libraries_record($h5p, $lib4->id);
|
||||
// Create library dependencies for $mainlib.
|
||||
$this->create_library_dependency_record($mainlib->id, $lib1->id);
|
||||
$this->create_library_dependency_record($mainlib->id, $lib2->id);
|
||||
$this->create_library_dependency_record($mainlib->id, $lib3->id);
|
||||
// Create library dependencies for $lib1.
|
||||
$this->create_library_dependency_record($lib1->id, $lib2->id);
|
||||
$this->create_library_dependency_record($lib1->id, $lib3->id);
|
||||
$this->create_library_dependency_record($lib1->id, $lib4->id);
|
||||
// Create library dependencies for $lib3.
|
||||
$this->create_library_dependency_record($lib3->id, $lib5->id);
|
||||
|
||||
return (object) [
|
||||
'h5pcontent' => (object) array(
|
||||
'h5pid' => $h5p,
|
||||
'contentdependencies' => array($mainlib, $lib1, $lib2, $lib3, $lib4)
|
||||
),
|
||||
'mainlib' => (object) array(
|
||||
'data' => $mainlib,
|
||||
'dependencies' => array($lib1, $lib2, $lib3)
|
||||
),
|
||||
'lib1' => (object) array(
|
||||
'data' => $lib1,
|
||||
'dependencies' => array($lib2, $lib3, $lib4)
|
||||
),
|
||||
'lib2' => (object) array(
|
||||
'data' => $lib2,
|
||||
'dependencies' => array()
|
||||
),
|
||||
'lib3' => (object) array(
|
||||
'data' => $lib3,
|
||||
'dependencies' => array($lib5)
|
||||
),
|
||||
'lib4' => (object) array(
|
||||
'data' => $lib4,
|
||||
'dependencies' => array()
|
||||
),
|
||||
'lib5' => (object) array(
|
||||
'data' => $lib5,
|
||||
'dependencies' => array()
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a record in the h5p_libraries database table.
|
||||
*
|
||||
* @param string $machinename The library machine name
|
||||
* @param string $title The library's name
|
||||
* @param int $majorversion The library's major version
|
||||
* @param int $minorversion The library's minor version
|
||||
* @param int $patchversion The library's patch version
|
||||
* @param string $semantics Json describing the content structure for the library
|
||||
* @param string $addto The plugin configuration data
|
||||
* @return stdClass An object representing the added library record
|
||||
*/
|
||||
public function create_library_record(string $machinename, string $title, int $majorversion = 1,
|
||||
int $minorversion = 0, int $patchversion = 1, string $semantics = '', string $addto = null): stdClass {
|
||||
global $DB;
|
||||
|
||||
$content = array(
|
||||
'machinename' => $machinename,
|
||||
'title' => $title,
|
||||
'majorversion' => $majorversion,
|
||||
'minorversion' => $minorversion,
|
||||
'patchversion' => $patchversion,
|
||||
'runnable' => 1,
|
||||
'fullscreen' => 1,
|
||||
'preloadedjs' => 'js/example.js',
|
||||
'preloadedcss' => 'css/example.css',
|
||||
'droplibrarycss' => '',
|
||||
'semantics' => $semantics,
|
||||
'addto' => $addto
|
||||
);
|
||||
|
||||
$libraryid = $DB->insert_record('h5p_libraries', $content);
|
||||
|
||||
return $DB->get_record('h5p_libraries', ['id' => $libraryid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a record in the h5p database table.
|
||||
*
|
||||
* @param int $mainlibid The ID of the content's main library
|
||||
* @param string $jsoncontent The content in json format
|
||||
* @param string $filtered The filtered content parameters
|
||||
* @return int The ID of the added record
|
||||
*/
|
||||
public function create_h5p_record(int $mainlibid, string $jsoncontent = null, string $filtered = null): int {
|
||||
global $DB;
|
||||
|
||||
if (!$jsoncontent) {
|
||||
$jsoncontent = json_encode(
|
||||
array(
|
||||
'text' => '<p>Dummy text<\/p>\n',
|
||||
'questions' => '<p>Test question<\/p>\n'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!$filtered) {
|
||||
$filtered = json_encode(
|
||||
array(
|
||||
'text' => 'Dummy text',
|
||||
'questions' => 'Test question'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $DB->insert_record(
|
||||
'h5p',
|
||||
array(
|
||||
'jsoncontent' => $jsoncontent,
|
||||
'displayoptions' => 8,
|
||||
'mainlibraryid' => $mainlibid,
|
||||
'timecreated' => time(),
|
||||
'timemodified' => time(),
|
||||
'filtered' => $filtered,
|
||||
'pathnamehash' => sha1('pathname'),
|
||||
'contenthash' => sha1('content')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a record in the h5p_contents_libraries database table.
|
||||
*
|
||||
* @param string $h5pid The ID of the H5P content
|
||||
* @param int $libid The ID of the library
|
||||
* @param string $dependencytype The dependency type
|
||||
* @return int The ID of the added record
|
||||
*/
|
||||
public function create_contents_libraries_record(string $h5pid, int $libid,
|
||||
string $dependencytype = 'preloaded'): int {
|
||||
global $DB;
|
||||
|
||||
return $DB->insert_record(
|
||||
'h5p_contents_libraries',
|
||||
array(
|
||||
'h5pid' => $h5pid,
|
||||
'libraryid' => $libid,
|
||||
'dependencytype' => $dependencytype,
|
||||
'dropcss' => 0,
|
||||
'weight' => 1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a record in the h5p_library_dependencies database table.
|
||||
*
|
||||
* @param int $libid The ID of the library
|
||||
* @param int $requiredlibid The ID of the required library
|
||||
* @param string $dependencytype The dependency type
|
||||
* @return int The ID of the added record
|
||||
*/
|
||||
public function create_library_dependency_record(int $libid, int $requiredlibid,
|
||||
string $dependencytype = 'preloaded'): int {
|
||||
global $DB;
|
||||
|
||||
return $DB->insert_record(
|
||||
'h5p_library_dependencies',
|
||||
array(
|
||||
'libraryid' => $libid,
|
||||
'requiredlibraryid' => $requiredlibid,
|
||||
'dependencytype' => $dependencytype
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
478
h5p/tests/generator_test.php
Normal file
478
h5p/tests/generator_test.php
Normal file
@ -0,0 +1,478 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Test class covering the h5p data generator class.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @category test
|
||||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Generator testcase for the core_grading generator.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @category test
|
||||
* @copyright 2019 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class generator_testcase extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test the returned data of generate_h5p_data() when the method is called without requesting
|
||||
* creation of library files.
|
||||
*/
|
||||
public function test_generate_h5p_data_no_files_created_return_data() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_h5p');
|
||||
|
||||
$data = $generator->generate_h5p_data();
|
||||
|
||||
$mainlib = $DB->get_record('h5p_libraries', ['machinename' => 'MainLibrary']);
|
||||
$lib1 = $DB->get_record('h5p_libraries', ['machinename' => 'Library1']);
|
||||
$lib2 = $DB->get_record('h5p_libraries', ['machinename' => 'Library2']);
|
||||
$lib3 = $DB->get_record('h5p_libraries', ['machinename' => 'Library3']);
|
||||
$lib4 = $DB->get_record('h5p_libraries', ['machinename' => 'Library4']);
|
||||
$lib5 = $DB->get_record('h5p_libraries', ['machinename' => 'Library5']);
|
||||
|
||||
$h5p = $DB->get_record('h5p', ['mainlibraryid' => $mainlib->id]);
|
||||
|
||||
$expected = (object) [
|
||||
'h5pcontent' => (object) array(
|
||||
'h5pid' => $h5p->id,
|
||||
'contentdependencies' => array($mainlib, $lib1, $lib2, $lib3, $lib4)
|
||||
),
|
||||
'mainlib' => (object) array(
|
||||
'data' => $mainlib,
|
||||
'dependencies' => array($lib1, $lib2, $lib3)
|
||||
),
|
||||
'lib1' => (object) array(
|
||||
'data' => $lib1,
|
||||
'dependencies' => array($lib2, $lib3, $lib4)
|
||||
),
|
||||
'lib2' => (object) array(
|
||||
'data' => $lib2,
|
||||
'dependencies' => array()
|
||||
),
|
||||
'lib3' => (object) array(
|
||||
'data' => $lib3,
|
||||
'dependencies' => array($lib5)
|
||||
),
|
||||
'lib4' => (object) array(
|
||||
'data' => $lib4,
|
||||
'dependencies' => array()
|
||||
),
|
||||
'lib5' => (object) array(
|
||||
'data' => $lib5,
|
||||
'dependencies' => array()
|
||||
),
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the returned data of generate_h5p_data() when the method requests
|
||||
* creation of library files.
|
||||
*/
|
||||
public function test_generate_h5p_data_files_created_return_data() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_h5p');
|
||||
|
||||
$data = $generator->generate_h5p_data(true);
|
||||
|
||||
$mainlib = $DB->get_record('h5p_libraries', ['machinename' => 'MainLibrary']);
|
||||
$lib1 = $DB->get_record('h5p_libraries', ['machinename' => 'Library1']);
|
||||
$lib2 = $DB->get_record('h5p_libraries', ['machinename' => 'Library2']);
|
||||
$lib3 = $DB->get_record('h5p_libraries', ['machinename' => 'Library3']);
|
||||
$lib4 = $DB->get_record('h5p_libraries', ['machinename' => 'Library4']);
|
||||
$lib5 = $DB->get_record('h5p_libraries', ['machinename' => 'Library5']);
|
||||
|
||||
$h5p = $DB->get_record('h5p', ['mainlibraryid' => $mainlib->id]);
|
||||
|
||||
$expected = (object) [
|
||||
'h5pcontent' => (object) array(
|
||||
'h5pid' => $h5p->id,
|
||||
'contentdependencies' => array($mainlib, $lib1, $lib2, $lib3, $lib4)
|
||||
),
|
||||
'mainlib' => (object) array(
|
||||
'data' => $mainlib,
|
||||
'dependencies' => array($lib1, $lib2, $lib3)
|
||||
),
|
||||
'lib1' => (object) array(
|
||||
'data' => $lib1,
|
||||
'dependencies' => array($lib2, $lib3, $lib4)
|
||||
),
|
||||
'lib2' => (object) array(
|
||||
'data' => $lib2,
|
||||
'dependencies' => array()
|
||||
),
|
||||
'lib3' => (object) array(
|
||||
'data' => $lib3,
|
||||
'dependencies' => array($lib5)
|
||||
),
|
||||
'lib4' => (object) array(
|
||||
'data' => $lib4,
|
||||
'dependencies' => array()
|
||||
),
|
||||
'lib5' => (object) array(
|
||||
'data' => $lib5,
|
||||
'dependencies' => array()
|
||||
),
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of generate_h5p_data(). Test whether library files are created or not
|
||||
* on filesystem depending what the method defines.
|
||||
*
|
||||
* @dataProvider test_generate_h5p_data_files_creation_provider
|
||||
* @param bool $createlibraryfiles Whether to create library files on the filesystem
|
||||
* @param bool $expected The expectation whether the files have been created or not
|
||||
**/
|
||||
public function test_generate_h5p_data_files_creation(bool $createlibraryfiles, bool $expected) {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_h5p');
|
||||
$generator->generate_h5p_data($createlibraryfiles);
|
||||
|
||||
$libraries[] = $DB->get_record('h5p_libraries', ['machinename' => 'MainLibrary']);
|
||||
$libraries[] = $DB->get_record('h5p_libraries', ['machinename' => 'Library1']);
|
||||
$libraries[] = $DB->get_record('h5p_libraries', ['machinename' => 'Library2']);
|
||||
$libraries[] = $DB->get_record('h5p_libraries', ['machinename' => 'Library3']);
|
||||
$libraries[] = $DB->get_record('h5p_libraries', ['machinename' => 'Library4']);
|
||||
$libraries[] = $DB->get_record('h5p_libraries', ['machinename' => 'Library5']);
|
||||
|
||||
foreach($libraries as $lib) {
|
||||
// Return the created library files.
|
||||
$libraryfiles = $DB->get_records('files',
|
||||
array(
|
||||
'component' => \core_h5p\file_storage::COMPONENT,
|
||||
'filearea' => \core_h5p\file_storage::LIBRARY_FILEAREA,
|
||||
'itemid' => $lib->id
|
||||
)
|
||||
);
|
||||
|
||||
$haslibraryfiles = !empty($libraryfiles);
|
||||
|
||||
$this->assertEquals($expected, $haslibraryfiles);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_generate_h5p_data_files_creation().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function test_generate_h5p_data_files_creation_provider(): array {
|
||||
return [
|
||||
'Do not create library related files on the filesystem' => [
|
||||
false,
|
||||
false
|
||||
],
|
||||
'Create library related files on the filesystem' => [
|
||||
true,
|
||||
true
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of create_library_record(). Test whether the library data is properly
|
||||
* saved in the database.
|
||||
*/
|
||||
public function test_create_library_record() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_h5p');
|
||||
|
||||
$data = $generator->create_library_record('Library', 'Lib', 1, 2, 3, 'Semantics example', '/regex11/');
|
||||
unset($data->id);
|
||||
|
||||
$expected = (object) [
|
||||
'machinename' => 'Library',
|
||||
'title' => 'Lib',
|
||||
'majorversion' => '1',
|
||||
'minorversion' => '2',
|
||||
'patchversion' => '3',
|
||||
'runnable' => '1',
|
||||
'fullscreen' => '1',
|
||||
'embedtypes' => '',
|
||||
'preloadedjs' => 'js/example.js',
|
||||
'preloadedcss' => 'css/example.css',
|
||||
'droplibrarycss' => '',
|
||||
'semantics' => 'Semantics example',
|
||||
'addto' => '/regex11/'
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of create_h5p_record(). Test whather the h5p content data is
|
||||
* properly saved in the database.
|
||||
*
|
||||
* @dataProvider test_create_h5p_record_provider
|
||||
* @param array $h5pdata The h5p content data
|
||||
* @param \stdClass $expected The expected saved data
|
||||
**/
|
||||
public function test_create_h5p_record(array $h5pdata, \stdClass $expected) {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_h5p');
|
||||
|
||||
$h5pid = call_user_func_array([$generator, 'create_h5p_record'], $h5pdata);
|
||||
|
||||
$data = $DB->get_record('h5p', ['id' => $h5pid]);
|
||||
unset($data->id);
|
||||
unset($data->timecreated);
|
||||
unset($data->timemodified);
|
||||
|
||||
$this->assertEquals($data, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_create_h5p_record().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function test_create_h5p_record_provider(): array {
|
||||
$createdjsoncontent = json_encode(
|
||||
array(
|
||||
'text' => '<p>Created dummy text<\/p>\n',
|
||||
'questions' => '<p>Test created question<\/p>\n'
|
||||
)
|
||||
);
|
||||
|
||||
$defaultjsoncontent = json_encode(
|
||||
array(
|
||||
'text' => '<p>Dummy text<\/p>\n',
|
||||
'questions' => '<p>Test question<\/p>\n'
|
||||
)
|
||||
);
|
||||
|
||||
$createdfilteredcontent = json_encode(
|
||||
array(
|
||||
'text' => 'Created dummy text',
|
||||
'questions' => 'Test created question'
|
||||
)
|
||||
);
|
||||
|
||||
$defaultfilteredcontent = json_encode(
|
||||
array(
|
||||
'text' => 'Dummy text',
|
||||
'questions' => 'Test question'
|
||||
)
|
||||
);
|
||||
|
||||
return [
|
||||
'Create h5p content record with set json content and set filtered content' => [
|
||||
[
|
||||
1,
|
||||
$createdjsoncontent,
|
||||
$createdfilteredcontent
|
||||
],
|
||||
(object) array(
|
||||
'jsoncontent' => $createdjsoncontent,
|
||||
'mainlibraryid' => '1',
|
||||
'displayoptions' => '8',
|
||||
'pathnamehash' => sha1('pathname'),
|
||||
'contenthash' => sha1('content'),
|
||||
'filtered' => $createdfilteredcontent,
|
||||
)
|
||||
],
|
||||
'Create h5p content record with set json content and default filtered content' => [
|
||||
[
|
||||
1,
|
||||
$createdjsoncontent,
|
||||
null
|
||||
],
|
||||
(object) array(
|
||||
'jsoncontent' => $createdjsoncontent,
|
||||
'mainlibraryid' => '1',
|
||||
'displayoptions' => '8',
|
||||
'pathnamehash' => sha1('pathname'),
|
||||
'contenthash' => sha1('content'),
|
||||
'filtered' => $defaultfilteredcontent,
|
||||
)
|
||||
],
|
||||
'Create h5p content record with default json content and set filtered content' => [
|
||||
[
|
||||
1,
|
||||
null,
|
||||
$createdfilteredcontent
|
||||
],
|
||||
(object) array(
|
||||
'jsoncontent' => $defaultjsoncontent,
|
||||
'mainlibraryid' => '1',
|
||||
'displayoptions' => '8',
|
||||
'pathnamehash' => sha1('pathname'),
|
||||
'contenthash' => sha1('content'),
|
||||
'filtered' => $createdfilteredcontent,
|
||||
)
|
||||
],
|
||||
'Create h5p content record with default json content and default filtered content' => [
|
||||
[
|
||||
1,
|
||||
null,
|
||||
null
|
||||
],
|
||||
(object) array(
|
||||
'jsoncontent' => $defaultjsoncontent,
|
||||
'mainlibraryid' => '1',
|
||||
'displayoptions' => '8',
|
||||
'pathnamehash' => sha1('pathname'),
|
||||
'contenthash' => sha1('content'),
|
||||
'filtered' => $defaultfilteredcontent,
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of create_contents_libraries_record(). Test whether the contents libraries
|
||||
* are properly saved in the database.
|
||||
*
|
||||
* @dataProvider test_create_contents_libraries_record_provider
|
||||
* @param array $contentslibrariestdata The h5p contents libraries data.
|
||||
* @param \stdClass $expected The expected saved data.
|
||||
**/
|
||||
public function test_create_contents_libraries_record(array $contentslibrariestdata, \stdClass $expected) {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_h5p');
|
||||
|
||||
$contentlibid = call_user_func_array([$generator, 'create_contents_libraries_record'], $contentslibrariestdata);
|
||||
|
||||
$data = $DB->get_record('h5p_contents_libraries', ['id' => $contentlibid]);
|
||||
unset($data->id);
|
||||
|
||||
$this->assertEquals($data, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_create_contents_libraries_record().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function test_create_contents_libraries_record_provider(): array {
|
||||
return [
|
||||
'Create h5p content library with set dependency type' => [
|
||||
[
|
||||
1,
|
||||
1,
|
||||
'dynamic'
|
||||
],
|
||||
(object) array(
|
||||
'h5pid' => '1',
|
||||
'libraryid' => '1',
|
||||
'dependencytype' => 'dynamic',
|
||||
'dropcss' => '0',
|
||||
'weight' => '1'
|
||||
)
|
||||
],
|
||||
'Create h5p content library with a default dependency type' => [
|
||||
[
|
||||
1,
|
||||
1
|
||||
],
|
||||
(object) array(
|
||||
'h5pid' => '1',
|
||||
'libraryid' => '1',
|
||||
'dependencytype' => 'preloaded',
|
||||
'dropcss' => '0',
|
||||
'weight' => '1'
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of create_library_dependency_record(). Test whether the contents libraries
|
||||
* are properly saved in the database.
|
||||
*
|
||||
* @dataProvider test_create_library_dependency_record_provider
|
||||
* @param array $librarydependencydata The library dependency data.
|
||||
* @param \stdClass $expected The expected saved data.
|
||||
**/
|
||||
public function test_create_library_dependency_record(array $librarydependencydata, \stdClass $expected) {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('core_h5p');
|
||||
|
||||
$contentlibid = call_user_func_array([$generator, 'create_library_dependency_record'], $librarydependencydata);
|
||||
|
||||
$data = $DB->get_record('h5p_library_dependencies', ['id' => $contentlibid]);
|
||||
unset($data->id);
|
||||
|
||||
$this->assertEquals($data, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_create_library_dependency_record().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function test_create_library_dependency_record_provider(): array {
|
||||
return [
|
||||
'Create h5p library dependency with set dependency type' => [
|
||||
[
|
||||
1,
|
||||
1,
|
||||
'dynamic'
|
||||
],
|
||||
(object) array(
|
||||
'libraryid' => '1',
|
||||
'requiredlibraryid' => '1',
|
||||
'dependencytype' => 'dynamic'
|
||||
)
|
||||
],
|
||||
'Create h5p library dependency with default dependency type' => [
|
||||
[
|
||||
1,
|
||||
1
|
||||
],
|
||||
(object) array(
|
||||
'libraryid' => '1',
|
||||
'requiredlibraryid' => '1',
|
||||
'dependencytype' => 'preloaded'
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
552
h5p/tests/h5p_file_storage_test.php
Normal file
552
h5p/tests/h5p_file_storage_test.php
Normal file
@ -0,0 +1,552 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Testing the H5P H5PFileStorage interface implementation.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @category test
|
||||
* @copyright 2019 Victor Deniz <victor@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p\local\tests;
|
||||
|
||||
use core_h5p\file_storage;
|
||||
use file_archive;
|
||||
use zip_archive;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Test class covering the H5PFileStorage interface implementation.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Victor Deniz <victor@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class h5p_file_storage_testcase extends \advanced_testcase {
|
||||
|
||||
/** @var \core_h5p\file_storage H5P file storage instance */
|
||||
protected $h5p_file_storage;
|
||||
/** @var \file_storage Core Moodle file_storage associated to the H5P file_storage */
|
||||
protected $h5p_fs_fs;
|
||||
/** @var \context Moodle context of the H5P file_storage */
|
||||
protected $h5p_fs_context;
|
||||
/** @var string Path to temp directory */
|
||||
protected $h5p_tempath;
|
||||
/** @var \core_h5p_generator H5P generator instance */
|
||||
protected $h5p_generator;
|
||||
/** @var array $files an array used in the cache tests. */
|
||||
protected $files = ['scripts' => [], 'styles' => []];
|
||||
/** @var int $libraryid an id for the library. */
|
||||
protected $libraryid = 1;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Fetch generator.
|
||||
$generator = \testing_util::get_data_generator();
|
||||
$this->h5p_generator = $generator->get_plugin_generator('core_h5p');
|
||||
|
||||
// Create file_storage_instance and create H5P temp directory.
|
||||
$this->h5p_file_storage = new file_storage();
|
||||
$this->h5p_tempath = $this->h5p_file_storage->getTmpPath();
|
||||
check_dir_exists($this->h5p_tempath);
|
||||
|
||||
// Get value of protected properties.
|
||||
$h5p_fs_rc = new \ReflectionClass(file_storage::class);
|
||||
$h5p_file_storage_context = $h5p_fs_rc->getProperty('context');
|
||||
$h5p_file_storage_context->setAccessible(true);
|
||||
$this->h5p_fs_context = $h5p_file_storage_context->getValue($this->h5p_file_storage);
|
||||
|
||||
$h5p_file_storage_fs = $h5p_fs_rc->getProperty('fs');
|
||||
$h5p_file_storage_fs->setAccessible(true);
|
||||
$this->h5p_fs_fs = $h5p_file_storage_fs->getValue($this->h5p_file_storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that given the main directory of a library that all files are saved
|
||||
* into the file system.
|
||||
*/
|
||||
public function test_saveLibrary(): void {
|
||||
|
||||
$machinename = 'TestLib';
|
||||
$majorversion = 1;
|
||||
$minorversion = 0;
|
||||
[$lib, $files] = $this->h5p_generator->create_library($this->h5p_tempath, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
|
||||
// Now run the API call.
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
// Check that files are in the Moodle file system.
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::LIBRARY_FILEAREA, '1', "/{$machinename}-{$majorversion}.{$minorversion}/", 'library.json');
|
||||
$filepath = "/{$machinename}-{$majorversion}.{$minorversion}/";
|
||||
$this->assertEquals($filepath, $file->get_filepath());
|
||||
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::LIBRARY_FILEAREA, '1', "/{$machinename}-{$majorversion}.{$minorversion}/scripts/", 'testlib.min.js');
|
||||
$jsfilepath = "{$filepath}scripts/";
|
||||
$this->assertEquals($jsfilepath, $file->get_filepath());
|
||||
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::LIBRARY_FILEAREA, '1', "/{$machinename}-{$majorversion}.{$minorversion}/styles/", 'testlib.min.css');
|
||||
$cssfilepath = "{$filepath}styles/";
|
||||
$this->assertEquals($cssfilepath, $file->get_filepath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a content file can be saved.
|
||||
*/
|
||||
public function test_saveContent(): void {
|
||||
|
||||
$source = $this->h5p_tempath . '/' . 'content.json';
|
||||
$this->h5p_generator->create_file($source);
|
||||
|
||||
$this->h5p_file_storage->saveContent($this->h5p_tempath, ['id' => 5]);
|
||||
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::CONTENT_FILEAREA, '5', '/', 'content.json');
|
||||
$this->assertEquals(file_storage::CONTENT_FILEAREA, $file->get_filearea());
|
||||
$this->assertEquals('content.json', $file->get_filename());
|
||||
$this->assertEquals(5, $file->get_itemid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that content files located on the file system can be deleted.
|
||||
*/
|
||||
public function test_deleteContent(): void {
|
||||
|
||||
$source = $this->h5p_tempath . '/' . 'content.json';
|
||||
$this->h5p_generator->create_file($source);
|
||||
|
||||
$this->h5p_file_storage->saveContent($this->h5p_tempath, ['id' => 5]);
|
||||
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::CONTENT_FILEAREA, '5', '/', 'content.json');
|
||||
$this->assertEquals('content.json', $file->get_filename());
|
||||
|
||||
// Now to delete the record.
|
||||
$this->h5p_file_storage->deleteContent(['id' => 5]);
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::CONTENT_FILEAREA, '5', '/', 'content.json');
|
||||
$this->assertFalse($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that returning a temp path returns what is expected by the h5p library.
|
||||
*/
|
||||
public function test_getTmpPath(): void {
|
||||
|
||||
$temparray = explode('/', $this->h5p_tempath);
|
||||
$h5pdirectory = array_pop($temparray);
|
||||
$this->assertTrue(stripos($h5pdirectory, 'h5p-') === 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the content files can be exported to a specified location.
|
||||
*/
|
||||
public function test_exportContent(): void {
|
||||
|
||||
// Create a file to store.
|
||||
$source = $this->h5p_tempath . '/' . 'content.json';
|
||||
$this->h5p_generator->create_file($source);
|
||||
|
||||
$this->h5p_file_storage->saveContent($this->h5p_tempath, ['id' => 5]);
|
||||
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::CONTENT_FILEAREA, '5', '/', 'content.json');
|
||||
$this->assertEquals('content.json', $file->get_filename());
|
||||
|
||||
// Now export it.
|
||||
$destinationdirectory = $this->h5p_tempath . '/' . 'testdir';
|
||||
check_dir_exists($destinationdirectory);
|
||||
|
||||
$this->h5p_file_storage->exportContent(5, $destinationdirectory);
|
||||
// Check that there is a file now in that directory.
|
||||
$contents = scandir($destinationdirectory);
|
||||
$value = array_search('content.json', $contents);
|
||||
$this->assertEquals('content.json', $contents[$value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that libraries on the file system can be exported to a specified location.
|
||||
*/
|
||||
public function test_exportLibrary(): void {
|
||||
|
||||
$machinename = 'TestLib';
|
||||
$majorversion = 1;
|
||||
$minorversion = 0;
|
||||
[$lib, $files] = $this->h5p_generator->create_library($this->h5p_tempath, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
|
||||
// Now run the API call.
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
$destinationdirectory = $this->h5p_tempath . '/' . 'testdir';
|
||||
check_dir_exists($destinationdirectory);
|
||||
|
||||
$this->h5p_file_storage->exportLibrary($lib, $destinationdirectory);
|
||||
|
||||
$filepath = "/{$machinename}-{$majorversion}.{$minorversion}/";
|
||||
// There should be at least three items here (but could be more with . and ..).
|
||||
$this->assertFileExists($destinationdirectory . $filepath . 'library.json');
|
||||
$this->assertFileExists($destinationdirectory . $filepath . 'scripts/' . 'testlib.min.js');
|
||||
$this->assertFileExists($destinationdirectory . $filepath . 'styles/' . 'testlib.min.css');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an export file can be saved into the file system.
|
||||
*/
|
||||
public function test_saveExport(): void {
|
||||
|
||||
$filename = 'someexportedfile.h5p';
|
||||
$source = $this->h5p_tempath . '/' . $filename;
|
||||
$this->h5p_generator->create_file($source);
|
||||
|
||||
$this->h5p_file_storage->saveExport($source, $filename);
|
||||
|
||||
// Check out if the file is there.
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::EXPORT_FILEAREA, '0', '/', $filename);
|
||||
$this->assertEquals(file_storage::EXPORT_FILEAREA, $file->get_filearea());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an exort file can be deleted from the file system.
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function test_deleteExport(): void {
|
||||
|
||||
$filename = 'someexportedfile.h5p';
|
||||
$source = $this->h5p_tempath . '/' . $filename;
|
||||
$this->h5p_generator->create_file($source);
|
||||
|
||||
$this->h5p_file_storage->saveExport($source, $filename);
|
||||
|
||||
// Check out if the file is there.
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::EXPORT_FILEAREA, '0', '/', $filename);
|
||||
$this->assertEquals(file_storage::EXPORT_FILEAREA, $file->get_filearea());
|
||||
|
||||
// Time to delete.
|
||||
$this->h5p_file_storage->deleteExport($filename);
|
||||
|
||||
// Check out if the file is there.
|
||||
$file = $this->h5p_fs_fs->get_file ($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::EXPORT_FILEAREA, '0', '/', $filename);
|
||||
$this->assertFalse($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to check if an export file already exists on the file system.
|
||||
*/
|
||||
public function test_hasExport(): void {
|
||||
|
||||
$filename = 'someexportedfile.h5p';
|
||||
$source = $this->h5p_tempath . '/' . $filename;
|
||||
$this->h5p_generator->create_file($source);
|
||||
|
||||
// Check that it doesn't exist in the file system.
|
||||
$this->assertFalse($this->h5p_file_storage->hasExport($filename));
|
||||
|
||||
$this->h5p_file_storage->saveExport($source, $filename);
|
||||
// Now it should be present.
|
||||
$this->assertTrue($this->h5p_file_storage->hasExport($filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that all the library files for an H5P activity can be concatenated into "cache" files. One for js and another for css.
|
||||
*/
|
||||
public function test_cacheAssets(): void {
|
||||
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'test-1.0';
|
||||
|
||||
$machinename = 'TestLib';
|
||||
$majorversion = 1;
|
||||
$minorversion = 0;
|
||||
[$lib, $libfiles] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
array_push($this->files['scripts'], ...$libfiles['scripts']);
|
||||
array_push($this->files['styles'], ...$libfiles['styles']);
|
||||
|
||||
// Now run the API call.
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
// Second library.
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'supertest-2.4';
|
||||
|
||||
$this->libraryid++;
|
||||
$machinename = 'SuperTest';
|
||||
$majorversion = 2;
|
||||
$minorversion = 4;
|
||||
[$lib, $libfiles] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
array_push($this->files['scripts'], ...$libfiles['scripts']);
|
||||
array_push($this->files['styles'], ...$libfiles['styles']);
|
||||
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
$this->assertCount(2, $this->files['scripts']);
|
||||
$this->assertCount(2, $this->files['styles']);
|
||||
|
||||
$key = 'testhashkey';
|
||||
|
||||
$this->h5p_file_storage->cacheAssets($this->files, $key);
|
||||
$this->assertCount(1, $this->files['scripts']);
|
||||
$this->assertCount(1, $this->files['styles']);
|
||||
|
||||
|
||||
$expectedfile = '/' . file_storage::CACHED_ASSETS_FILEAREA . '/' . $key . '.js';
|
||||
$this->assertEquals($expectedfile, $this->files['scripts'][0]->path);
|
||||
$expectedfile = '/' . file_storage::CACHED_ASSETS_FILEAREA . '/' . $key . '.css';
|
||||
$this->assertEquals($expectedfile, $this->files['styles'][0]->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that cached files can be retrieved via a key.
|
||||
*/
|
||||
public function test_getCachedAssets() {
|
||||
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'test-1.0';
|
||||
|
||||
$machinename = 'TestLib';
|
||||
$majorversion = 1;
|
||||
$minorversion = 0;
|
||||
[$lib, $libfiles] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
array_push($this->files['scripts'], ...$libfiles['scripts']);
|
||||
array_push($this->files['styles'], ...$libfiles['styles']);
|
||||
|
||||
// Now run the API call.
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
// Second library.
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'supertest-2.4';
|
||||
|
||||
$this->libraryid++;
|
||||
$machinename = 'SuperTest';
|
||||
$majorversion = 2;
|
||||
$minorversion = 4;
|
||||
[$lib, $libfiles] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
array_push($this->files['scripts'], ...$libfiles['scripts']);
|
||||
array_push($this->files['styles'], ...$libfiles['styles']);
|
||||
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
$this->assertCount(2, $this->files['scripts']);
|
||||
$this->assertCount(2, $this->files['styles']);
|
||||
|
||||
$key = 'testhashkey';
|
||||
|
||||
$this->h5p_file_storage->cacheAssets($this->files, $key);
|
||||
|
||||
$testarray = $this->h5p_file_storage->getCachedAssets($key);
|
||||
$this->assertCount(1, $testarray['scripts']);
|
||||
$this->assertCount(1, $testarray['styles']);
|
||||
$expectedfile = '/' . file_storage::CACHED_ASSETS_FILEAREA . '/' . $key . '.js';
|
||||
$this->assertEquals($expectedfile, $testarray['scripts'][0]->path);
|
||||
$expectedfile = '/' . file_storage::CACHED_ASSETS_FILEAREA . '/' . $key . '.css';
|
||||
$this->assertEquals($expectedfile, $testarray['styles'][0]->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that cache files in the files system can be removed.
|
||||
*/
|
||||
public function test_deleteCachedAssets(): void {
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'test-1.0';
|
||||
|
||||
$machinename = 'TestLib';
|
||||
$majorversion = 1;
|
||||
$minorversion = 0;
|
||||
[$lib, $libfiles] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
array_push($this->files['scripts'], ...$libfiles['scripts']);
|
||||
array_push($this->files['styles'], ...$libfiles['styles']);
|
||||
|
||||
// Now run the API call.
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
// Second library.
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'supertest-2.4';
|
||||
|
||||
$this->libraryid++;
|
||||
$machinename = 'SuperTest';
|
||||
$majorversion = 2;
|
||||
$minorversion = 4;
|
||||
[$lib, $libfiles] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
array_push($this->files['scripts'], ...$libfiles['scripts']);
|
||||
array_push($this->files['styles'], ...$libfiles['styles']);
|
||||
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
$this->assertCount(2, $this->files['scripts']);
|
||||
$this->assertCount(2, $this->files['styles']);
|
||||
|
||||
$key = 'testhashkey';
|
||||
|
||||
$this->h5p_file_storage->cacheAssets($this->files, $key);
|
||||
|
||||
$testarray = $this->h5p_file_storage->getCachedAssets($key);
|
||||
$this->assertCount(1, $testarray['scripts']);
|
||||
$this->assertCount(1, $testarray['styles']);
|
||||
|
||||
// Time to delete.
|
||||
$this->h5p_file_storage->deleteCachedAssets([$key]);
|
||||
$testarray = $this->h5p_file_storage->getCachedAssets($key);
|
||||
$this->assertNull($testarray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve content from a file given a specific path.
|
||||
*/
|
||||
public function test_getContent() {
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'test-1.0';
|
||||
|
||||
$machinename = 'TestLib';
|
||||
$majorversion = 1;
|
||||
$minorversion = 0;
|
||||
[$lib, $libfiles] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
array_push($this->files['scripts'], ...$libfiles['scripts']);
|
||||
array_push($this->files['styles'], ...$libfiles['styles']);
|
||||
|
||||
// Now run the API call.
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
$content = $this->h5p_file_storage->getContent($this->files['scripts'][0]->path);
|
||||
// The file content is created based on the file system path (\core_h5p_generator::create_file).
|
||||
$expectedcontent = hash("md5", $basedirectory. '/' . 'scripts' . '/' . 'testlib.min.js');
|
||||
|
||||
$this->assertEquals($expectedcontent, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that an upgrade script can be found on the file system.
|
||||
*/
|
||||
public function test_getUpgradeScript() {
|
||||
// Upload an upgrade file.
|
||||
$machinename = 'TestLib';
|
||||
$majorversion = 3;
|
||||
$minorversion = 1;
|
||||
$filepath = '/' . "{$machinename}-{$majorversion}.{$minorversion}" . '/';
|
||||
$fs = get_file_storage();
|
||||
$filerecord = [
|
||||
'contextid' => \context_system::instance()->id,
|
||||
'component' => file_storage::COMPONENT,
|
||||
'filearea' => file_storage::LIBRARY_FILEAREA,
|
||||
'itemid' => 15,
|
||||
'filepath' => $filepath,
|
||||
'filename' => 'upgrade.js'
|
||||
];
|
||||
$filestorage = new file_storage();
|
||||
$fs->create_file_from_string($filerecord, 'test string info');
|
||||
$expectedfilepath = DIRECTORY_SEPARATOR . file_storage::LIBRARY_FILEAREA . $filepath . 'upgrade.js';
|
||||
$this->assertEquals($expectedfilepath, $filestorage->getUpgradeScript($machinename, $majorversion, $minorversion));
|
||||
$this->assertNull($filestorage->getUpgradeScript($machinename, $majorversion, 7));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that information from a source can be saved to the specified path.
|
||||
* The zip file has the following contents
|
||||
* - h5ptest
|
||||
* |- content
|
||||
* | |- content.json
|
||||
* |- testFont
|
||||
* | |- testfont.min.css
|
||||
* |- testJavaScript
|
||||
* | |- testscript.min.js
|
||||
* |- h5p.json
|
||||
*/
|
||||
public function test_saveFileFromZip() {
|
||||
|
||||
$ziparchive = new zip_archive();
|
||||
$path = __DIR__ . '/fixtures/h5ptest.zip';
|
||||
$result = $ziparchive->open($path, file_archive::OPEN);
|
||||
|
||||
$files = $ziparchive->list_files();
|
||||
foreach ($files as $file) {
|
||||
if (!$file->is_directory) {
|
||||
$stream = $ziparchive->get_stream($file->index);
|
||||
$items = explode(DIRECTORY_SEPARATOR, $file->pathname);
|
||||
array_shift($items);
|
||||
$path = implode(DIRECTORY_SEPARATOR, $items);
|
||||
$this->h5p_file_storage->saveFileFromZip($this->h5p_tempath, $path, $stream);
|
||||
$filestocheck[] = $path;
|
||||
}
|
||||
}
|
||||
$ziparchive->close();
|
||||
|
||||
foreach ($filestocheck as $filetocheck) {
|
||||
$pathtocheck = $this->h5p_tempath .'/'. $filetocheck;
|
||||
$this->assertFileExists($pathtocheck);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a library is fully deleted from the file system
|
||||
*/
|
||||
public function test_delete_library() {
|
||||
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'test-1.0';
|
||||
|
||||
$machinename = 'TestLib';
|
||||
$majorversion = 1;
|
||||
$minorversion = 0;
|
||||
[$lib, $files] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
|
||||
// Now run the API call.
|
||||
$this->h5p_file_storage->saveLibrary($lib);
|
||||
|
||||
// Save a second library to ensure we aren't deleting all libraries, but just the one specified.
|
||||
$basedirectory = $this->h5p_tempath . '/' . 'awesomelib-2.1';
|
||||
|
||||
$this->libraryid++;
|
||||
$machinename = 'AwesomeLib';
|
||||
$majorversion = 2;
|
||||
$minorversion = 1;
|
||||
[$lib2, $files2] = $this->h5p_generator->create_library($basedirectory, $this->libraryid, $machinename, $majorversion,
|
||||
$minorversion);
|
||||
|
||||
// Now run the API call.
|
||||
$this->h5p_file_storage->saveLibrary($lib2);
|
||||
|
||||
$files = $this->h5p_fs_fs->get_area_files($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::LIBRARY_FILEAREA);
|
||||
$this->assertCount(14, $files);
|
||||
|
||||
$this->h5p_file_storage->delete_library($lib);
|
||||
|
||||
// Let's look at the records.
|
||||
$files = $this->h5p_fs_fs->get_area_files($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::LIBRARY_FILEAREA);
|
||||
$this->assertCount(7, $files);
|
||||
|
||||
// Check that the db count is still the same after setting the libraryId to false.
|
||||
$lib['libraryId'] = false;
|
||||
$this->h5p_file_storage->delete_library($lib);
|
||||
|
||||
$files = $this->h5p_fs_fs->get_area_files($this->h5p_fs_context->id, file_storage::COMPONENT,
|
||||
file_storage::LIBRARY_FILEAREA);
|
||||
$this->assertCount(7, $files);
|
||||
}
|
||||
}
|
161
lang/en/h5p.php
Normal file
161
lang/en/h5p.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'h5p', language 'en', branch 'master'
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Moodle
|
||||
* @author Sara Arjona <sara@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['addedandupdatedpp'] = 'Added {$a->%new} new H5P libraries and updated {$a->%old} old ones.';
|
||||
$string['addedandupdatedps'] = 'Added {$a->%new} new H5P libraries and updated {$a->%old} old one.';
|
||||
$string['addedandupdatedsp'] = 'Added {$a->%new} new H5P library and updated {$a->%old} old ones.';
|
||||
$string['addedandupdatedss'] = 'Added {$a->%new} new H5P library and updated {$a->%old} old one.';
|
||||
$string['addednewlibraries'] = 'Added {$a->%new} new H5P libraries.';
|
||||
$string['addednewlibrary'] = 'Added {$a->%new} new H5P library.';
|
||||
$string['additionallicenseinfo'] = 'Any additional information about the license';
|
||||
$string['author'] = 'Author';
|
||||
$string['authorcomments'] = 'Author comments';
|
||||
$string['authorcommentsdescription'] = 'Comments for the editor of the content (This text will not be published as a part of copyright info)';
|
||||
$string['authorname'] = 'Author\'s name';
|
||||
$string['authorrole'] = 'Author\'s role';
|
||||
$string['by'] = 'by';
|
||||
$string['cancellabel'] = 'Cancel';
|
||||
$string['ccattribution'] = 'Attribution (CC BY)';
|
||||
$string['ccattributionnc'] = 'Attribution-NonCommercial (CC BY-NC)';
|
||||
$string['ccattributionncnd'] = 'Attribution-NonCommercial-NoDerivs (CC BY-NC-ND)';
|
||||
$string['ccattributionncsa'] = 'Attribution-NonCommercial-ShareAlike (CC BY-NC-SA)';
|
||||
$string['ccattributionnd'] = 'Attribution-NoDerivs (CC BY-ND)';
|
||||
$string['ccattributionsa'] = 'Attribution-ShareAlike (CC BY-SA)';
|
||||
$string['ccpdd'] = 'Public Domain Dedication (CC0)';
|
||||
$string['changedby'] = 'Changed by';
|
||||
$string['changedescription'] = 'Description of change';
|
||||
$string['changelog'] = 'Changelog';
|
||||
$string['changeplaceholder'] = 'Photo cropped, text changed, etc.';
|
||||
$string['close'] = 'Close';
|
||||
$string['confirmdialogbody'] = 'Please confirm that you wish to proceed. This action is not reversible.';
|
||||
$string['confirmdialogheader'] = 'Confirm action';
|
||||
$string['confirmlabel'] = 'Confirm';
|
||||
$string['connectionLost'] = 'Connection lost. Results will be stored and sent when you regain connection.';
|
||||
$string['connectionReestablished'] = 'Connection reestablished.';
|
||||
$string['contentCopied'] = 'Content is copied to the clipboard';
|
||||
$string['contentchanged'] = 'This content has changed since you last used it.';
|
||||
$string['contenttype'] = 'Content Type';
|
||||
$string['copyright'] = 'Rights of use';
|
||||
$string['copyrightinfo'] = 'Copyright information';
|
||||
$string['copyrightstring'] = 'Copyright';
|
||||
$string['copyrighttitle'] = 'View copyright information for this content.';
|
||||
$string['couldNotParseJSONFromZip'] = 'Unable to parse JSON from the package: {$a->%fileName}';
|
||||
$string['couldNotReadFileFromZip'] = 'Unable to read file from the package: {$a->%fileName}';
|
||||
$string['creativecommons'] = 'Creative Commons';
|
||||
$string['date'] = 'Date';
|
||||
$string['disablefullscreen'] = 'Disable fullscreen';
|
||||
$string['download'] = 'Download';
|
||||
$string['downloadtitle'] = 'Download this content as a H5P file.';
|
||||
$string['editor'] = 'Editor';
|
||||
$string['embed'] = 'Embed';
|
||||
$string['embedtitle'] = 'View the embed code for this content.';
|
||||
$string['fileExceedsMaxSize'] = 'One of the files inside the package exceeds the maximum file size allowed. ({$a->%file} {$a->%used} > {$a->%max})';
|
||||
$string['fullscreen'] = 'Fullscreen';
|
||||
$string['gpl'] = 'General Public License v3';
|
||||
$string['h5p'] = 'H5P';
|
||||
$string['h5ptitle'] = 'Visit H5P.org to check out more cool content.';
|
||||
$string['h5pfilenotfound'] = 'H5P file not found';
|
||||
$string['h5pinvalidurl'] = 'Invalid H5P content URL.';
|
||||
$string['h5pprivatefile'] = 'This H5P content can\'t be displayed because you don\'t have access to the .h5p file.';
|
||||
$string['hideadvanced'] = 'Hide advanced';
|
||||
$string['invalidcontextid'] = 'H5P file not found (invalid contextid)';
|
||||
$string['invalidfile'] = 'File "{$a->%filename}" not allowed. Only files with the following extensions are allowed: {$a->%files-allowed}.';
|
||||
$string['invalidlanguagefile'] = 'Invalid language file {$a->%file} in library {$a->%library}';
|
||||
$string['invalidlanguagefile2'] = 'Invalid language file {$a->%languageFile} has been included in the library {$a->%name}';
|
||||
$string['invalidlibrarydata'] = 'Invalid data provided for {$a->%property} in {$a->%library}';
|
||||
$string['invalidlibrarydataboolean'] = 'Invalid data provided for {$a->%property} in {$a->%library}. Boolean expected.';
|
||||
$string['invalidlibraryname'] = 'Invalid library name: {$a->%name}';
|
||||
$string['invalidlibrarynamed'] = 'The H5P library {$a->%library} used in the content is not valid';
|
||||
$string['invalidlibraryoption'] = 'Illegal option {$a->%option} in {$a->%library}';
|
||||
$string['invalidlibraryproperty'] = 'Can\'t read the property {$a->%property} in {$a->%library}';
|
||||
$string['invalidmainjson'] = 'A valid main h5p.json file is missing';
|
||||
$string['invalidmultiselectoption'] = 'Invalid selected option in multi-select.';
|
||||
$string['invalidselectoption'] = 'Invalid selected option in select.';
|
||||
$string['invalidsemanticsjson'] = 'Invalid semantics.json file has been included in the library {$a->%name}';
|
||||
$string['invalidsemanticstype'] = 'H5P internal error: unknown content type "{$a->@type}" in semantics. Removing content!';
|
||||
$string['invalidstring'] = 'Provided string is not valid according to regexp in semantics. (value: "{$a->%value}", regexp: "{$a->%regexp}")';
|
||||
$string['librarydirectoryerror'] = 'Library directory name must match machineName or machineName-majorVersion.minorVersion (from library.json). (Directory: {$a->%directoryName} , machineName: {$a->%machineName}, majorVersion: {$a->%majorVersion}, minorVersion: {$a->%minorVersion})';
|
||||
$string['license'] = 'License';
|
||||
$string['licenseCC010'] = 'CC0 1.0 Universal (CC0 1.0) Public Domain Dedication';
|
||||
$string['licenseCC010U'] = 'CC0 1.0 Universal';
|
||||
$string['licenseCC10'] = '1.0 Generic';
|
||||
$string['licenseCC20'] = '2.0 Generic';
|
||||
$string['licenseCC25'] = '2.5 Generic';
|
||||
$string['licenseCC30'] = '3.0 Unported';
|
||||
$string['licenseCC40'] = '4.0 International';
|
||||
$string['licenseGPL'] = 'General Public License';
|
||||
$string['licenseV1'] = 'Version 1';
|
||||
$string['licenseV2'] = 'Version 2';
|
||||
$string['licenseV3'] = 'Version 3';
|
||||
$string['licensee'] = 'Licensee';
|
||||
$string['licenseextras'] = 'License Extras';
|
||||
$string['licenseversion'] = 'License Version';
|
||||
$string['missingcontentfolder'] = 'A valid content folder is missing';
|
||||
$string['missingcoreversion'] = 'The system was unable to install the {$a->%component} component from the package, it requires a newer version of the H5P plugin. This site is currently running version {$a->%current}, whereas the required version is {$a->%required} or higher. You should consider upgrading and then try again.';
|
||||
$string['missingdependency'] = 'Missing dependency {$a->@dep} required by {$a->@lib}.';
|
||||
$string['missinglibrary'] = 'Missing required library {$a->@library}';
|
||||
$string['missinglibraryfile'] = 'The file "{$a->%file}" is missing from library: "{$a->%name}"';
|
||||
$string['missinglibraryjson'] = 'Could not find library.json file with valid json format for library {$a->%name}';
|
||||
$string['missinglibraryproperty'] = 'The required property {$a->%property} is missing from {$a->%library}';
|
||||
$string['missingmbstring'] = 'The mbstring PHP extension is not loaded. H5P need this to function properly';
|
||||
$string['missinguploadpermissions'] = 'Note that the libraries may exist in the file you uploaded, but you\'re not allowed to upload new libraries. Contact the site administrator about this.';
|
||||
$string['nocopyright'] = 'No copyright information available for this content.';
|
||||
$string['noextension'] = 'The file you uploaded is not a valid HTML5 Package (It does not have the .h5p file extension)';
|
||||
$string['nopermissiontodeploy'] = 'This file can\'t be displayed because it has been uploaded by a user without the required capability to deploy H5P content.';
|
||||
$string['nojson'] = 'The main h5p.json file is not valid';
|
||||
$string['nounzip'] = 'The file you uploaded is not a valid HTML5 Package (We are unable to unzip it)';
|
||||
$string['offlineDialogBody'] = 'We were unable to send information about your completion of this task. Please check your internet connection.';
|
||||
$string['offlineDialogHeader'] = 'Your connection to the server was lost';
|
||||
$string['offlineDialogRetryButtonLabel'] = 'Retry now';
|
||||
$string['offlineDialogRetryMessage'] = 'Retrying in :num....';
|
||||
$string['offlineSuccessfulSubmit'] = 'Successfully submitted results.';
|
||||
$string['originator'] = 'Originator';
|
||||
$string['pd'] = 'Public Domain';
|
||||
$string['pddl'] = 'Public Domain Dedication and Licence';
|
||||
$string['pdm'] = 'Public Domain Mark (PDM)';
|
||||
$string['privacy:metadata'] = 'H5P subsystem does not store any personal data.';
|
||||
$string['resizescript'] = 'Include this script on your website if you want dynamic sizing of the embedded content:';
|
||||
$string['resubmitScores'] = 'Attempting to submit stored results.';
|
||||
$string['reuse'] = 'Reuse';
|
||||
$string['reuseContent'] = 'Reuse Content';
|
||||
$string['reuseDescription'] = 'Reuse this content.';
|
||||
$string['showadvanced'] = 'Show advanced';
|
||||
$string['showless'] = 'Show less';
|
||||
$string['showmore'] = 'Show more';
|
||||
$string['size'] = 'Size';
|
||||
$string['source'] = 'Source';
|
||||
$string['startingover'] = 'You\'ll be starting over.';
|
||||
$string['sublevel'] = 'Sublevel';
|
||||
$string['thumbnail'] = 'Thumbnail';
|
||||
$string['title'] = 'Title';
|
||||
$string['undisclosed'] = 'Undisclosed';
|
||||
$string['unpackedFilesExceedsMaxSize'] = 'The total size of the unpacked files exceeds the maximum size allowed. ({$a->%used} > {$a->%max})';
|
||||
$string['updatedlibraries'] = 'Updated {$a->%old} H5P libraries.';
|
||||
$string['updatedlibrary'] = 'Updated {$a->%old} H5P library.';
|
||||
$string['wrongversion'] = 'The version of the H5P library {$a->%machineName} used in this content is not valid. Content contains {$a->%contentLibrary}, but it should be {$a->%semanticsLibrary}.';
|
||||
$string['year'] = 'Year';
|
||||
$string['years'] = 'Year(s)';
|
||||
$string['yearsfrom'] = 'Years (from)';
|
||||
$string['yearsto'] = 'Years (to)';
|
@ -260,6 +260,8 @@ $string['grade:unlock'] = 'Unlock grades or items';
|
||||
$string['grade:view'] = 'View own grades';
|
||||
$string['grade:viewall'] = 'View grades of other users';
|
||||
$string['grade:viewhidden'] = 'View hidden grades for owner';
|
||||
$string['h5p:deploy'] = 'Allow to deploy H5P content';
|
||||
$string['h5p:setdisplayoptions'] = 'Set the display options to an H5P content';
|
||||
$string['highlightedcellsshowdefault'] = 'The permissions highlighted in the table below are the defaults for the role archetype currently selected above.';
|
||||
$string['highlightedcellsshowinherit'] = 'The highlighted cells in the table below show the permission (if any) that will be inherited. Apart from the capabilities whose permission you actually want to alter, you should leave everything set to Inherit.';
|
||||
$string['checkglobalpermissions'] = 'Check system permissions';
|
||||
|
@ -77,6 +77,7 @@
|
||||
"group": "group",
|
||||
"help": null,
|
||||
"hub": null,
|
||||
"h5p": "h5p",
|
||||
"imscc": null,
|
||||
"install": null,
|
||||
"iso6392": null,
|
||||
|
@ -2430,4 +2430,24 @@ $capabilities = array(
|
||||
'user' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
|
||||
// Set display option buttons to an H5P content.
|
||||
'moodle/h5p:setdisplayoptions' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
)
|
||||
),
|
||||
|
||||
// Allow to deploy H5P content.
|
||||
'moodle/h5p:deploy' => array(
|
||||
'riskbitmask' => RISK_XSS,
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'manager' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
)
|
||||
),
|
||||
);
|
||||
|
82
lib/db/install.xml
Normal file → Executable file
82
lib/db/install.xml
Normal file → Executable file
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20190905" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20191015" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -4133,5 +4133,85 @@
|
||||
<INDEX NAME="fieldid-decvalue" UNIQUE="false" FIELDS="fieldid, decvalue"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="h5p_libraries" COMMENT="Stores information about libraries used by H5P content.">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary Key: The id of the library"/>
|
||||
<FIELD NAME="machinename" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The library machine name"/>
|
||||
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The human readable name of this library"/>
|
||||
<FIELD NAME="majorversion" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="minorversion" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="patchversion" TYPE="int" LENGTH="4" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="runnable" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="Can this library be started by the module? i.e. not a dependency."/>
|
||||
<FIELD NAME="fullscreen" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Display fullscreen button"/>
|
||||
<FIELD NAME="embedtypes" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="List of supported embed types"/>
|
||||
<FIELD NAME="preloadedjs" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Comma separated list of scripts to load."/>
|
||||
<FIELD NAME="preloadedcss" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Comma separated list of stylesheets to load."/>
|
||||
<FIELD NAME="droplibrarycss" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="List of libraries that should not have CSS included if this library is used. Comma separated list."/>
|
||||
<FIELD NAME="semantics" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The semantics definition in json format"/>
|
||||
<FIELD NAME="addto" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Plugin configuration data"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="machinemajorminorpatch" UNIQUE="false" FIELDS="machinename, majorversion, minorversion, patchversion, runnable"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="h5p_library_dependencies" COMMENT="Stores H5P library dependencies">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="libraryid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The id of a H5P library."/>
|
||||
<FIELD NAME="requiredlibraryid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The dependent library to load"/>
|
||||
<FIELD NAME="dependencytype" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="preloaded, dynamic, or editor"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="libraryid" TYPE="foreign" FIELDS="libraryid" REFTABLE="h5p_libraries" REFFIELDS="id"/>
|
||||
<KEY NAME="requiredlibraryid" TYPE="foreign" FIELDS="requiredlibraryid" REFTABLE="h5p_libraries" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="h5p" COMMENT="Stores H5P content information">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="jsoncontent" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The content in json format"/>
|
||||
<FIELD NAME="mainlibraryid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The library we first instanciate for this node"/>
|
||||
<FIELD NAME="displayoptions" TYPE="int" LENGTH="4" NOTNULL="false" SEQUENCE="false" COMMENT="H5P Button display options"/>
|
||||
<FIELD NAME="pathnamehash" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="Defines the complete unique hash for the file path where the H5P content was added."/>
|
||||
<FIELD NAME="contenthash" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="Defines the hash for the file content."/>
|
||||
<FIELD NAME="filtered" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Filtered version of json_content"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="mainlibraryid" TYPE="foreign" FIELDS="mainlibraryid" REFTABLE="h5p_libraries" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="h5p_contents_libraries" COMMENT="Store which library is used in which content.">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="h5pid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Identifier for the h5p content"/>
|
||||
<FIELD NAME="libraryid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The identifier of a H5P library this content uses"/>
|
||||
<FIELD NAME="dependencytype" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="dynamic, preloaded or editor"/>
|
||||
<FIELD NAME="dropcss" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="1 if the preloaded css from the dependency is to be excluded"/>
|
||||
<FIELD NAME="weight" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Determines the order in which the preloaded libraries will be loaded"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="h5pid" TYPE="foreign" FIELDS="h5pid" REFTABLE="h5p" REFFIELDS="id"/>
|
||||
<KEY NAME="libraryid" TYPE="foreign" FIELDS="libraryid" REFTABLE="h5p_libraries" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
<TABLE NAME="h5p_libraries_cachedassets" COMMENT="H5P cached library assets">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
|
||||
<FIELD NAME="libraryid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="hash" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Cache hash key that this library is part of."/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="libraryid" TYPE="foreign" FIELDS="libraryid" REFTABLE="h5p_libraries" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
@ -3638,5 +3638,121 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2019101800.02);
|
||||
}
|
||||
|
||||
if ($oldversion < 2019102500.01) {
|
||||
// Define table h5p_libraries to be created.
|
||||
$table = new xmldb_table('h5p_libraries');
|
||||
|
||||
// Adding fields to table h5p_libraries.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('machinename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('title', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('majorversion', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('minorversion', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('patchversion', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('runnable', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('fullscreen', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('embedtypes', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('preloadedjs', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('preloadedcss', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('droplibrarycss', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('semantics', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('addto', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
|
||||
// Adding keys to table h5p_libraries.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
|
||||
// Adding indexes to table h5p_libraries.
|
||||
$table->add_index('machinemajorminorpatch', XMLDB_INDEX_NOTUNIQUE,
|
||||
['machinename', 'majorversion', 'minorversion', 'patchversion', 'runnable']);
|
||||
|
||||
// Conditionally launch create table for h5p_libraries.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Define table h5p_library_dependencies to be created.
|
||||
$table = new xmldb_table('h5p_library_dependencies');
|
||||
|
||||
// Adding fields to table h5p_library_dependencies.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('libraryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('requiredlibraryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('dependencytype', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
|
||||
// Adding keys to table h5p_library_dependencies.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('libraryid', XMLDB_KEY_FOREIGN, ['libraryid'], 'h5p_libraries', ['id']);
|
||||
$table->add_key('requiredlibraryid', XMLDB_KEY_FOREIGN, ['requiredlibraryid'], 'h5p_libraries', ['id']);
|
||||
|
||||
// Conditionally launch create table for h5p_library_dependencies.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Define table h5p to be created.
|
||||
$table = new xmldb_table('h5p');
|
||||
|
||||
// Adding fields to table h5p.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('jsoncontent', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('mainlibraryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('displayoptions', XMLDB_TYPE_INTEGER, '4', null, null, null, null);
|
||||
$table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('filtered', XMLDB_TYPE_TEXT, null, null, null, null, null);
|
||||
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
|
||||
|
||||
// Adding keys to table h5p.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('mainlibraryid', XMLDB_KEY_FOREIGN, ['mainlibraryid'], 'h5p_libraries', ['id']);
|
||||
|
||||
// Conditionally launch create table for h5p.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Define table h5p_contents_libraries to be created.
|
||||
$table = new xmldb_table('h5p_contents_libraries');
|
||||
|
||||
// Adding fields to table h5p_contents_libraries.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('h5pid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('libraryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('dependencytype', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('dropcss', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('weight', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
|
||||
// Adding keys to table h5p_contents_libraries.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('h5pid', XMLDB_KEY_FOREIGN, ['h5pid'], 'h5p', ['id']);
|
||||
$table->add_key('libraryid', XMLDB_KEY_FOREIGN, ['libraryid'], 'h5p_libraries', ['id']);
|
||||
|
||||
// Conditionally launch create table for h5p_contents_libraries.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Define table h5p_libraries_cachedassets to be created.
|
||||
$table = new xmldb_table('h5p_libraries_cachedassets');
|
||||
|
||||
// Adding fields to table h5p_libraries_cachedassets.
|
||||
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
|
||||
$table->add_field('libraryid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
|
||||
$table->add_field('hash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
|
||||
|
||||
// Adding keys to table h5p_libraries_cachedassets.
|
||||
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
|
||||
$table->add_key('libraryid', XMLDB_KEY_FOREIGN, ['libraryid'], 'h5p_libraries_cachedassets', ['id']);
|
||||
|
||||
// Conditionally launch create table for h5p_libraries_cachedassets.
|
||||
if (!$dbman->table_exists($table)) {
|
||||
$dbman->create_table($table);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2019102500.01);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
The H5P resizer JS.
|
||||
|
||||
to update:
|
||||
|
||||
Downloaded last release from: https://github.com/h5p/h5p-php-library/releases
|
||||
|
||||
Import
|
||||
|
||||
- In the downloaded h5p-php-library copy js/h5p-resizer.js into lib/editor/atto/plugins/h5p/js
|
@ -61,7 +61,7 @@ function atto_h5p_strings_for_js() {
|
||||
);
|
||||
|
||||
$PAGE->requires->strings_for_js($strings, 'atto_h5p');
|
||||
$PAGE->requires->js(new moodle_url('/lib/editor/atto/plugins/h5p/js/h5p-resizer.js'));
|
||||
$PAGE->requires->js(new moodle_url('/lib/h5p/js/h5p-resizer.js'));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<libraries>
|
||||
<library>
|
||||
<location>js/h5p-resizer.js</location>
|
||||
<name>H5P Resizer</name>
|
||||
<license>GPL-3.0</license>
|
||||
<version>1.23.1</version>
|
||||
<licenseversion></licenseversion>
|
||||
</library>
|
||||
</libraries>
|
@ -68,7 +68,7 @@ var CSS = {
|
||||
'width="100%" height="637" frameborder="0"' +
|
||||
'allowfullscreen="{{allowfullscreen}}" allowmedia="{{allowmedia}}">' +
|
||||
'</iframe>' +
|
||||
'<script src="' + M.cfg.wwwroot + '/lib/editor/atto/plugins/h5p/js/h5p-resizer.js"' +
|
||||
'<script src="' + M.cfg.wwwroot + '/lib/h5p/js/h5p-resizer.js"' +
|
||||
'charset="UTF-8"></script>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
|
@ -1 +1 @@
|
||||
YUI.add("moodle-atto_h5p-button",function(e,t){var n={INPUTALT:"atto_h5p_altentry",INPUTSUBMIT:"atto_h5p_urlentrysubmit",INPUTH5PURL:"atto_h5p_url",URLWARNING:"atto_h5p_warning"},r={INPUTH5PURL:"."+n.INPUTH5PURL},i="atto_h5p",s='<form class="atto_form"><div class="mb-4"><label for="{{elementid}}_{{CSS.INPUTH5PURL}}">{{get_string "enterurl" component}}</label><div style="display:none" role="alert" class="alert alert-warning mb-1 {{CSS.URLWARNING}}">{{get_string "invalidh5purl" component}}</div><input class="form-control fullwidth {{CSS.INPUTH5PURL}}" type="url" id="{{elementid}}_{{CSS.INPUTH5PURL}}" size="32"/></div><div class="text-center"><button class="btn btn-secondary {{CSS.INPUTSUBMIT}}" type="submit">{{get_string "saveh5p" component}}</button></div></form>',o='<div class="position-relative h5p-embed-placeholder"><div class="attoh5poverlay"></div><iframe id="h5pcontent" class="h5pcontent" src="{{url}}/embed" width="100%" height="637" frameborder="0"allowfullscreen="{{allowfullscreen}}" allowmedia="{{allowmedia}}"></iframe><script src="'+M.cfg.wwwroot+'/lib/editor/atto/plugins/h5p/js/h5p-resizer.js"'+'charset="UTF-8"></script>'+"</div>"+"</div>"+"<p><br></p>";e.namespace("M.atto_h5p").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_form:null,_placeholderH5P:null,initializer:function(){var e=this.get("allowedmethods");if(e!=="embed")return;this.addButton({icon:"icon",iconComponent:"atto_h5p",callback:this._displayDialogue,tags:".attoh5poverlay",tagMatchRequiresAll:!1}),this.editor.delegate("dblclick",this._handleDblClick,".attoh5poverlay",this),this.editor.delegate("click",this._handleClick,".attoh5poverlay",this)},_handleDblClick:function(){this._displayDialogue()},_handleClick:function(e){var t=e.target,n=this.get("host").getSelectionFromNode(t);this.get("host").getSelection()!==n&&this.get("host").setSelection(n)},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection(),this._placeholderH5P=this._getH5PIframe();if(this._currentSelection===!1)return;var e=this.getDialogue({headerContent:M.util.get_string("h5pproperties",i),width:"auto",focusAfterHide:!0,focusOnShowSelector:r.INPUTH5PURL});e.set("bodyContent",this._getDialogueContent()).show()},_getH5PIframe:function(){var t=this.get("host").getSelectionParentNode();if(!t)return;return e.one(t).one("iframe.h5pcontent")},_getDialogueContent:function(){var t=e.Handlebars.compile(s),o=e.Node.create(t({elementid:this.get("host").get("elementid"),CSS:n,component:i}));this._form=o;if(this._placeholderH5P){var u=this._placeholderH5P.getAttribute("src");this._form.one(r.INPUTH5PURL).setAttribute("value",u)}return this._form.one("."+n.INPUTSUBMIT).on("click",this._setH5P,this),o},_setH5P:function(t){var n=this._form,i=n.one(r.INPUTH5PURL).get("value"),s,u=this.get("host");t.preventDefault();if(this._updateWarning())return;u.focus();if(this._placeholderH5P)this._placeholderH5P.setAttribute("src",i);else if(i!==""){u.setSelection(this._currentSelection);var a=e.Handlebars.compile(o);s=a({url:i,allowfullscreen:"allowfullscreen",allowmedia:"geolocation *; microphone *; camera *; midi *; encrypted-media *"}),this.get("host").insertContentAtFocusPoint(s),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()},_validURL:function(e){var t=new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*");return!!t.test(e)},_updateWarning:function(){var e=this._form,t=!0,r=e.one("."+n.INPUTH5PURL).get("value");return this._validURL(r)?(e.one("."+n.URLWARNING).setStyle("display","none"),t=!1):(e.one("."+n.URLWARNING).setStyle("display","block"),t=!0),t}},{ATTRS:{allowedmethods:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]});
|
||||
YUI.add("moodle-atto_h5p-button",function(e,t){var n={INPUTALT:"atto_h5p_altentry",INPUTSUBMIT:"atto_h5p_urlentrysubmit",INPUTH5PURL:"atto_h5p_url",URLWARNING:"atto_h5p_warning"},r={INPUTH5PURL:"."+n.INPUTH5PURL},i="atto_h5p",s='<form class="atto_form"><div class="mb-4"><label for="{{elementid}}_{{CSS.INPUTH5PURL}}">{{get_string "enterurl" component}}</label><div style="display:none" role="alert" class="alert alert-warning mb-1 {{CSS.URLWARNING}}">{{get_string "invalidh5purl" component}}</div><input class="form-control fullwidth {{CSS.INPUTH5PURL}}" type="url" id="{{elementid}}_{{CSS.INPUTH5PURL}}" size="32"/></div><div class="text-center"><button class="btn btn-secondary {{CSS.INPUTSUBMIT}}" type="submit">{{get_string "saveh5p" component}}</button></div></form>',o='<div class="position-relative h5p-embed-placeholder"><div class="attoh5poverlay"></div><iframe id="h5pcontent" class="h5pcontent" src="{{url}}/embed" width="100%" height="637" frameborder="0"allowfullscreen="{{allowfullscreen}}" allowmedia="{{allowmedia}}"></iframe><script src="'+M.cfg.wwwroot+'/lib/h5p/js/h5p-resizer.js"'+'charset="UTF-8"></script>'+"</div>"+"</div>"+"<p><br></p>";e.namespace("M.atto_h5p").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_form:null,_placeholderH5P:null,initializer:function(){var e=this.get("allowedmethods");if(e!=="embed")return;this.addButton({icon:"icon",iconComponent:"atto_h5p",callback:this._displayDialogue,tags:".attoh5poverlay",tagMatchRequiresAll:!1}),this.editor.delegate("dblclick",this._handleDblClick,".attoh5poverlay",this),this.editor.delegate("click",this._handleClick,".attoh5poverlay",this)},_handleDblClick:function(){this._displayDialogue()},_handleClick:function(e){var t=e.target,n=this.get("host").getSelectionFromNode(t);this.get("host").getSelection()!==n&&this.get("host").setSelection(n)},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection(),this._placeholderH5P=this._getH5PIframe();if(this._currentSelection===!1)return;var e=this.getDialogue({headerContent:M.util.get_string("h5pproperties",i),width:"auto",focusAfterHide:!0,focusOnShowSelector:r.INPUTH5PURL});e.set("bodyContent",this._getDialogueContent()).show()},_getH5PIframe:function(){var t=this.get("host").getSelectionParentNode();if(!t)return;return e.one(t).one("iframe.h5pcontent")},_getDialogueContent:function(){var t=e.Handlebars.compile(s),o=e.Node.create(t({elementid:this.get("host").get("elementid"),CSS:n,component:i}));this._form=o;if(this._placeholderH5P){var u=this._placeholderH5P.getAttribute("src");this._form.one(r.INPUTH5PURL).setAttribute("value",u)}return this._form.one("."+n.INPUTSUBMIT).on("click",this._setH5P,this),o},_setH5P:function(t){var n=this._form,i=n.one(r.INPUTH5PURL).get("value"),s,u=this.get("host");t.preventDefault();if(this._updateWarning())return;u.focus();if(this._placeholderH5P)this._placeholderH5P.setAttribute("src",i);else if(i!==""){u.setSelection(this._currentSelection);var a=e.Handlebars.compile(o);s=a({url:i,allowfullscreen:"allowfullscreen",allowmedia:"geolocation *; microphone *; camera *; midi *; encrypted-media *"}),this.get("host").insertContentAtFocusPoint(s),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()},_validURL:function(e){var t=new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*");return!!t.test(e)},_updateWarning:function(){var e=this._form,t=!0,r=e.one("."+n.INPUTH5PURL).get("value");return this._validURL(r)?(e.one("."+n.URLWARNING).setStyle("display","none"),t=!1):(e.one("."+n.URLWARNING).setStyle("display","block"),t=!0),t}},{ATTRS:{allowedmethods:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]});
|
||||
|
@ -68,7 +68,7 @@ var CSS = {
|
||||
'width="100%" height="637" frameborder="0"' +
|
||||
'allowfullscreen="{{allowfullscreen}}" allowmedia="{{allowmedia}}">' +
|
||||
'</iframe>' +
|
||||
'<script src="' + M.cfg.wwwroot + '/lib/editor/atto/plugins/h5p/js/h5p-resizer.js"' +
|
||||
'<script src="' + M.cfg.wwwroot + '/lib/h5p/js/h5p-resizer.js"' +
|
||||
'charset="UTF-8"></script>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
|
@ -66,7 +66,7 @@ var CSS = {
|
||||
'width="100%" height="637" frameborder="0"' +
|
||||
'allowfullscreen="{{allowfullscreen}}" allowmedia="{{allowmedia}}">' +
|
||||
'</iframe>' +
|
||||
'<script src="' + M.cfg.wwwroot + '/lib/editor/atto/plugins/h5p/js/h5p-resizer.js"' +
|
||||
'<script src="' + M.cfg.wwwroot + '/lib/h5p/js/h5p-resizer.js"' +
|
||||
'charset="UTF-8"></script>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
|
674
lib/h5p/LICENSE.txt
Normal file
674
lib/h5p/LICENSE.txt
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
14
lib/h5p/README.txt
Normal file
14
lib/h5p/README.txt
Normal file
@ -0,0 +1,14 @@
|
||||
This folder contains the general H5P library. The files within this folder are not specific to any framework.
|
||||
|
||||
Any interaction with an LMS, CMS or other frameworks is done through interfaces. Platforms need to implement
|
||||
the H5PFrameworkInterface(in h5p.classes.php) and also do the following:
|
||||
|
||||
- Provide a form for uploading H5P packages.
|
||||
- Place the uploaded H5P packages in a temporary directory
|
||||
+++
|
||||
|
||||
See existing implementations for details. For instance the Drupal H5P module located at drupal.org/project/h5p
|
||||
|
||||
We will make available documentation and tutorials for creating platform integrations in the future.
|
||||
|
||||
The H5P PHP library is GPL licensed due to GPL code being used for purifying HTML provided by authors.
|
168
lib/h5p/doc/spec_en.html
Normal file
168
lib/h5p/doc/spec_en.html
Normal file
@ -0,0 +1,168 @@
|
||||
<h2>Overview</h2>
|
||||
<p>H5P is a file format for content/applications made using modern, open web technologies (HTML5). The format enables easy installation and transfer of applications/content on different CMSes, LMSes and other platforms. An H5P can be uploaded and published on a platform in mostly the same way one would publish a Flash file today. H5P files may also be updated by simply uploading a new version of the file, the same way as one would using Flash.</p>
|
||||
<p>H5P opens for extensive reuse of code and wide flexibility regarding what may be developed as an H5P.</p>
|
||||
<p>The system uses package files containing all necessary files and libraries for the application to function. These files are based on open formats.</p>
|
||||
<h2>Overview of package files</h2>
|
||||
<p>Package files are normal <em>zip</em> files, with a naming convention of <i><filename>.h5p</i> to distinguish from any random zip file. This zip file then requires a specific file structure as described below.</p>
|
||||
<p>There will be a file in JSON format named h5p.json describing the contents of the package and how the system should interpret and use it. This file contains information about title, content type, usage, copyright, licensing, version, language etc. This is described in detail below.</p>
|
||||
<p>There shall be a folder for each included H5P library used by the package. These generic libraries may be reused by other H5P packages. As an example, a multi-choice question task may be used as a standalone block, or be included in a larger H5P package generating a game with quizzes.</p>
|
||||
<h2>Package file structure</h2>
|
||||
<p>A package contains the following elements:</p>
|
||||
<ol>
|
||||
<li>A mandatory file in the root folder named <i>h5p.json</i></li>
|
||||
<li>An optional image file named <i>h5p.jpg</i>. This is an icon or an image of the application, 512 × 512 pixels. This image may be used by the platform as a preview of the application, and could be included in OG meta tags for use with social media.</li>
|
||||
<li>One content folder, named <i>content</i>. This will contain the preset configuration for the application, as well as any required media files.</li>
|
||||
<li>One or more library directories named the same as the library's internal name.</li>
|
||||
</ol>
|
||||
<h2>h5p.json</h2>
|
||||
<p>The <i>h5p.json</i> file is a normal JSON text file containing a JSON object with the following predefined properties.</p>
|
||||
<p>Mandatory properties:</p>
|
||||
<ul>
|
||||
<li>title - Name of the package. Would typically be used as header for a page displaying the package.</li>
|
||||
<li>language - Standard language code. Use 'en' for english, 'nb' for norwegian "bokmål". Neutral content use "und".</li>
|
||||
<li>machineName - Machine readable name of the library. This is the name that will be used for the library folder in the package too.</li>
|
||||
<li>preloadedDependencies - Libraries that must be loaded on init. Specified as a list of objects with machineName, majorVersion and minorVersion. One would normally list all dependencies here to allow the platform displaying the package to merge JS and CSS files before returning the page.</li>
|
||||
<li>embedTypes - List of ways to embed the package in the web page. Currently "div" and "iframe" are supported.</li>
|
||||
</ul><p>Optional properties:</p>
|
||||
<ul><li>contentType - Textual description of the type of content.</li>
|
||||
<li>description - Textual description of the package.</li>
|
||||
<li>author - Name of author.</li>
|
||||
<li>license - Code for the content license. Use the following Creative Commons codes: cc-by, cc-by-sa, cc-by-nd, cc-by-nc, cc-by-nc-sa, cc-by-nc-nd. In addition for public domain: pd, and closed license: cr. More may be added later.</li>
|
||||
<li>dynamicDependencies - Libraries that may be loaded dynamically during execution.</li>
|
||||
<li>width - Width of the package content in cases where the package is not dynamically resizable.</li>
|
||||
<li>height - Height of the package content.</li>
|
||||
<li>metaKeywords - Suggestion for keywords for the application, as a string. May be used for OG meta tags for social media.</li>
|
||||
<li>metaDescription - Suggestion for application metaDescription. May be used for OG meta tags for social media.</li>
|
||||
</ul>
|
||||
<h3>Eksempel på h5p.json:</h3>
|
||||
<code>{ <br/>
|
||||
"title": "Biologi-spillet",<br/>
|
||||
"contentType": "Game",<br/>
|
||||
"utilization": "Lær om biologi",<br/>
|
||||
"language": "nb",<br/>
|
||||
"author": "Amendor AS", <br/>
|
||||
"license": "cc-by-sa", <br/>
|
||||
"preloadedDependencies": [ <br/>
|
||||
{<br/>
|
||||
"machineName": "H5P.Boardgame", <br/>
|
||||
"majorVersion": 1, <br/>
|
||||
"minorVersion": 0<br/>
|
||||
}, {<br/>
|
||||
"machineName": "H5P.QuestionSet", <br/>
|
||||
"majorVersion": 1, <br/>
|
||||
"minorVersion": 0<br/>
|
||||
}, {<br/>
|
||||
"machineName": "H5P.MultiChoice", <br/>
|
||||
"majorVersion": 1, "minorVersion": 0<br/>
|
||||
}, {<br/>
|
||||
"machineName": "EmbeddedJS", <br/>
|
||||
"majorVersion": 1, <br/>
|
||||
"minorVersion": 0<br/>
|
||||
} ], <br/>
|
||||
"embedTypes": ["div", "iframe"], <br/>
|
||||
"w": 635, <br/>
|
||||
"h": 500 <br/>
|
||||
}</code>
|
||||
<h2>The content folder</h2>
|
||||
<p>Contains all the content for the package and its libraries. There shall be no content inside the library folders. The content folder shall contain a file named <i>content.json</i>, containing the JSON object that will be passed to the initializer for the main package library.</p>
|
||||
|
||||
<p>Content required by libraries invoked from the main package library will get their contents passed from the main library. The JSON for this will be found within the main content.json for the package, and passed during initialization.</p>
|
||||
|
||||
<h2>Library folders</h2>
|
||||
|
||||
<p>A library folder contains all logic, stylesheets and graphics that will be common for all instances of a library. There shall be no content or interface text directly in these folders. All text displayed to the end user shall be passed as part of the library configuration. This make the libraries language independent.</p>
|
||||
|
||||
<p>The root of a library folder shall contain a file name <i>library.json</i> formatted similar to the package's <i>hp5.json</i>, but with a few differences. The library shall also have one or more images in the root folder, named <i>library.jpg</i>, <i>library1.jpg</i> etc. Image sizes 512px × 512px, and will be used in the H5P editor tool.</p>
|
||||
|
||||
<p>Libraries are not allowed to modify the document tree in ways that will have consequences for the web site or will be noticeable by the user without the library explicitly being initialized from the main package library or another invoked library.</p>
|
||||
|
||||
<p>The library shall always include a JavaScript object function named the same as the defined library <i>machineName</i> (defined in <i>library.json</i> and used as the library folder name). This object will be instantiated with the library options as parameter. The resulting object must contain a function <i>attach(target)</i> that will be called after instantiation to attach the library DOM to the main DOM inside <i>target</i></p>
|
||||
|
||||
<h3>Example</h3>
|
||||
<p>A library called H5P.multichoice would typically be instantiated and attached to the page like this:</p>
|
||||
<code>var multichoice = new H5P.multichoice(contentFromJson, contentId); <br/>
|
||||
multichoice.attach($multichoiceContainer);</code>
|
||||
|
||||
<h2>library.json</h2>
|
||||
<p>Mandatory properties:</p>
|
||||
<ul>
|
||||
<li>title - Human readable name of the library. May be used in the H5P editor and overviews of installed libraries.</li>
|
||||
<li>majorVersion - Version major number. (The x in x.y.z). Positive integer.</li>
|
||||
<li>minorVersion - Version minor number. (The y in x.y.z). Positive integer.</li>
|
||||
<li>patchVersion - Version patch number. (The z in x.y.z). Positive integer. The system will automatically update to the latest patchVersion installed for all packages that use the library with the same major and minor version number. A new patch version must therefore not change any behaviour of the library, only fix errors.</li>
|
||||
<li>machineName - Machine readable name for the library. Same as the folder name used.</li>
|
||||
<li>preloadedJs - List of path to the javascript files required for the library. At least one file need to be present (the one defining the library object). Paths are relative to the library root folder.</li>
|
||||
</ul>
|
||||
<p>Optional properties:</p>
|
||||
<ul>
|
||||
<li>author - Author name as text.</li>
|
||||
<li>license - Code describing the library license. Use the following creative commons codes: cc-by, cc-by-sa, cc-by-nd, cc-by-nc, cc-by-nc-sa, cc-by-nc-nd. In addition use <i>pd</i> for public domain, and <i>cr</i> for closed source</li>
|
||||
<li>description - Textual description of the library.</li>
|
||||
<li>preloadedDependencies - Libraries that need to be loaded for this library to work. Specified as a list of objects with <i>machineName</i>, <i>majorVersion</i> and <i>minorVersion</i> for the required libraries.</li>
|
||||
<li>dynamicDependencies - Libraries that may be loaded dynamically during library execution. Specified as a list of objects like preloadedDependencies above.</li>
|
||||
<li>preloadedCss - List of paths to CSS files to be loaded with the library. Paths are relative to the library root folder.</li>
|
||||
<li>w - Width in pixels for libraries that use a fixed width. Mandatory if the library shall be embedded in an iframe (see embedTypes below).</li>
|
||||
<li>h - Height in pixels for libraries that use a fixed height. Mandatory if the library shall be embedded in an iframe (see embedTypes below).</li>
|
||||
<li>embedTypes - List of possible ways to embed the package in the page. Available values are <i>div</i> and <i>iframe</i>.</li>
|
||||
</ul>
|
||||
<h3>Eksempel på library.json:</h3>
|
||||
<code>{<br/>
|
||||
"title": "Boardgame", <br/>
|
||||
"description": "The user is presented with a board with several hotspots. By clicking a hotspot he invokes a mini-game.", <br/>
|
||||
"majorVersion": 1, <br/>
|
||||
"minorVersion": 0, <br/>
|
||||
"patchVersion": 6, <br/>
|
||||
"runnable": 1, <br/>
|
||||
"machineName": "H5P.Boardgame", <br/>
|
||||
"author": "Amendor AS", <br/>
|
||||
"license": "cc-by-sa", <br/>
|
||||
"preloadedDependencies": [ <br/>
|
||||
{<br/>
|
||||
"machineName": "EmbeddedJS", <br/>
|
||||
"majorVersion": 1, <br/>
|
||||
"minorVersion": 0<br/>
|
||||
}, {<br/>
|
||||
"machineName": "H5P.MultiChoice",<br/>
|
||||
"majorVersion": 1,<br/>
|
||||
"minorVersion": 0<br/>
|
||||
}, {<br/>
|
||||
"machineName": "H5P.QuestionSet",<br/>
|
||||
"majorVersion": 1,<br/>
|
||||
"minorVersion": 0<br/>
|
||||
} ],<br/>
|
||||
"preloadedCss": [ {"path": "css/boardgame.css"} ], <br/>
|
||||
"preloadedJs": [ {"path": "js/boardgame.js"} ], <br/>
|
||||
"w": 635, <br/>
|
||||
"h": 500 }</code>
|
||||
|
||||
<h2>Allowed file types</h2>
|
||||
<p>Files that require server side execution or that cannot be regarded an open standard shall not be used. Allowed file types: js, json, png, jpg, gif, svg, css, mp3, wav (audio: PCM), m4a (audio: AAC), mp4 (video: H.264, audio: AAC/MP3), ogg (video: Theora, audio: Vorbis) and webm (video VP8, audio: Vorbis). Administrators of web sites implementing H5P may open for accepting further formats. HTML files shall not be used. HTML for each library shall be inserted from the library scripts to ease code reuse. (By avoiding content being defined in said HTML).</p>
|
||||
<h2>API functions</h2>
|
||||
<p>The following JavaScript functions are available through h5p:</p>
|
||||
<ul>
|
||||
<li>H5P.getUserData(namespace, variable)</li>
|
||||
<li>H5P.setUserData(namespace, variable, data)</li>
|
||||
<li>H5P.getUserStart(namespace)</li>
|
||||
<li>H5P.setUserStop(namespace)</li>
|
||||
<li>H5P.deleteUserData(namespace, variable)</li>
|
||||
<li>H5P.getGlobalData(namespace, variable)</li>
|
||||
<li>H5P.setGlobalData(namespace, variable, data)</li>
|
||||
<li>H5P.deleteGlobalData(namespace, variable)</li>
|
||||
</ul>
|
||||
<p>I tillegg er følgende api funksjoner tilgjengelig via ndla:</p>
|
||||
<ul>
|
||||
<li>H5P.setUserScore(contentId, score, maxScore)</li>
|
||||
</ul>
|
||||
<h2>Best practices</h2>
|
||||
<p>H5P is a very open standard. This is positive for flexibility. Most content may be produces as H5P. But this also allows for bad code, security weaknesses, code that may be difficult to reuse. Therefore the following best practices should be followed to get the most from H5P:</p>
|
||||
<ul>
|
||||
<li>Think reusability when creating a library. H5P support dependencies between libraries, so the same small quiz-library may be used in various larger packages or libraries.</li>
|
||||
<li>H5P supports library updates. This enables all content using a common library to be updated at once. This must be accounted for when writing new libraries. A library should be as general as possible. The content format should be thought out so there are no changes to the required content data when a library is updated. Note: Multiple versions of a library may exists at the same time, only patch level updates will be automatically installed.</li>
|
||||
<li>An H5P should not interact directly with the containing web site. It shall only affect elements within its own generated DOM tree. Elements shall also only be injected within the target defined on initialization. This is to avoid dependencies to a specific platform or web page.</li>
|
||||
<li>Prefix objects, global functions, etc with h5p to minimize the chance of namespace conflicts with the rest of the web page. Remember that there may also be multiple H5P objects inserted on a page, so plan ahead to avoid conflicts.</li>
|
||||
<li>Content should be responsive.</li>
|
||||
<li>Content should be WCAG 2 AA compliant</li>
|
||||
<li>All generated HTML should validate.</li>
|
||||
<li>All CSS should validate (some browser specific non-standard CSS may at times be required)</li>
|
||||
<li>Best practices for JavaScript, HTML, etc. should of course also be followed when writing an H5P.</li>
|
||||
</ul>
|
20
lib/h5p/embed.php
Normal file
20
lib/h5p/embed.php
Normal file
@ -0,0 +1,20 @@
|
||||
<!doctype html>
|
||||
<html lang="<?php print $lang; ?>" class="h5p-iframe">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><?php print $content['title']; ?></title>
|
||||
<?php for ($i = 0, $s = count($scripts); $i < $s; $i++): ?>
|
||||
<script src="<?php print $scripts[$i]; ?>"></script>
|
||||
<?php endfor; ?>
|
||||
<?php for ($i = 0, $s = count($styles); $i < $s; $i++): ?>
|
||||
<link rel="stylesheet" href="<?php print $styles[$i]; ?>">
|
||||
<?php endfor; ?>
|
||||
<?php if (!empty($additional_embed_head_tags)): print implode("\n", $additional_embed_head_tags); endif; ?>
|
||||
</head>
|
||||
<body>
|
||||
<div class="h5p-content" data-content-id="<?php print $content['id']; ?>"></div>
|
||||
<script>
|
||||
H5PIntegration = <?php print json_encode($integration); ?>;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
BIN
lib/h5p/fonts/h5p-core-23.eot
Normal file
BIN
lib/h5p/fonts/h5p-core-23.eot
Normal file
Binary file not shown.
62
lib/h5p/fonts/h5p-core-23.svg
Normal file
62
lib/h5p/fonts/h5p-core-23.svg
Normal file
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<metadata>
|
||||
<json>
|
||||
<![CDATA[
|
||||
{
|
||||
"fontFamily": "h5p-core-21",
|
||||
"description": "Font generated by IcoMoon.",
|
||||
"majorVersion": 1,
|
||||
"minorVersion": 1,
|
||||
"version": "Version 1.1",
|
||||
"fontId": "h5p-core-21",
|
||||
"psName": "h5p-core-21",
|
||||
"subFamily": "Regular",
|
||||
"fullName": "h5p-core-21"
|
||||
}
|
||||
]]>
|
||||
</json>
|
||||
</metadata>
|
||||
<defs>
|
||||
<font id="h5p-core-21" horiz-adv-x="1024">
|
||||
<font-face units-per-em="1024" ascent="960" descent="-64" />
|
||||
<missing-glyph horiz-adv-x="1024" />
|
||||
<glyph unicode=" " horiz-adv-x="512" d="" />
|
||||
<glyph unicode="" glyph-name="arrow-down" data-tags="arrow-down" d="M234 389.669h556l-278-278z" />
|
||||
<glyph unicode="" glyph-name="arrow-left" data-tags="arrow-left" d="M381-11.331v524l262-262z" />
|
||||
<glyph unicode="" glyph-name="colapse" data-tags="colapse" d="M512 447.336l256-256-60-60-196 196-196-196-60 60z" />
|
||||
<glyph unicode="" glyph-name="expand" data-tags="expand" d="M708 423.336l60-60-256-256-256 256 60 60 196-196z" />
|
||||
<glyph unicode="" glyph-name="move" data-tags="move" d="M386.662 725.063h71.27v-71.27h-71.27v71.27zM566.067 725.063h71.27v-71.27h-71.27v71.27zM386.662 568.8h71.27v-71.27h-71.27v71.27zM566.067 568.8h71.27v-71.27h-71.27v71.27zM386.662 412.435h71.27v-71.27h-71.27v71.27zM566.067 412.435h71.27v-71.27h-71.27v71.27zM386.662 256.173h71.27v-71.27h-71.27v71.27zM566.067 256.173h71.27v-71.27h-71.27v71.27zM386.662 99.808h71.27v-71.27h-71.27v71.27zM566.067 99.808h71.27v-71.27h-71.27v71.27zM386.662-56.454h71.27v-71.27h-71.27v71.27zM566.067-56.454h71.27v-71.27h-71.27v71.27z" />
|
||||
<glyph unicode="" glyph-name="check-mark" data-tags="check-mark" d="M454.299 245.924l-116.917 116.917-84.781-84.707 201.696-201.697 317.097 317.097-84.781 84.706z" />
|
||||
<glyph unicode="" glyph-name="arrow-up-circle" data-tags="arrow-up-circle" d="M512 606.057c-148.616 0-264.722-120.75-260.077-269.367 0-125.395 88.241-232.212 208.991-255.434v213.636h-92.885c-13.933 0-13.933 9.288-9.288 18.577l139.327 171.838c4.645 9.288 13.933 9.288 23.221 4.645 0 0 4.645-4.645 4.645-4.645l139.327-171.838c9.288-9.288 4.645-18.577-9.288-18.577h-92.885v-213.636c143.972 32.51 232.212 171.838 199.703 315.808-23.221 120.75-130.039 204.347-250.789 208.991z" />
|
||||
<glyph unicode="" glyph-name="info-circle" data-tags="info-circle" d="M512 601.601c-144.077 0-260.266-116.191-260.266-260.266s116.191-260.266 260.266-260.266 260.266 116.191 260.266 260.266v0c0 139.429-116.191 255.619-260.266 260.266zM470.171 550.478h88.305v-69.714h-88.305v69.714zM600.305 160.078h-181.257v51.123h51.123v162.666h-51.123v51.123h139.429v-218.438h46.477l-4.648-46.477z" />
|
||||
<glyph unicode="" glyph-name="search" data-tags="search" d="M772.098 125.51l-110.68 110.68c71.943 99.612 49.806 243.494-49.806 315.437s-243.494 44.27-315.437-55.339c-71.943-99.612-49.806-243.494 49.806-315.437 77.475-55.339 182.623-55.339 260.098 0l110.68-110.68c5.533-5.533 11.068-5.533 16.601 0 0 0 0 0 0 0l33.205 33.205c11.068 5.533 11.068 16.601 5.533 22.137 0 0 0 0 0 0zM478.795 202.985c-88.544 0-160.486 71.943-160.486 160.486s71.943 160.486 160.486 160.486 160.486-71.943 160.486-160.486-71.943-160.486-160.486-160.486v0z" />
|
||||
<glyph unicode="" glyph-name="fullscreen" data-tags="fullscreen" d="M368.55 490.521c5.737 5.737 0 5.737-5.737 5.737l-103.284 11.476c-5.737 5.737-11.476 0-11.476-5.737l11.476-109.021c0-5.737 5.737-5.737 5.737-5.737l103.284 103.284zM293.959 427.403l63.118-63.118c5.737-5.737 11.476-5.737 17.213 0l22.953 22.953c5.737 5.737 5.737 11.476 0 17.213l-63.118 57.379-40.166-34.429zM787.42 387.237c5.737-5.737 5.737 0 5.737 5.737l11.476 109.021c0 5.737-5.737 11.476-11.476 11.476l-109.021-11.476c-5.737 0-5.737-5.737-5.737-5.737l109.021-109.021zM724.305 461.832l-63.118-63.118c-5.737-5.737-5.737-11.476 0-17.213l22.953-22.953c5.737-5.737 11.476-5.737 17.213 0l63.118 63.118-40.166 40.166zM689.876 180.672c-5.737-5.737 0-5.737 5.737-5.737l109.021-11.476c5.737 0 11.476 5.737 11.476 11.476l-17.213 103.284c0 5.737-5.737 5.737-5.737 5.737l-103.284-103.284zM758.731 249.527l-63.118 63.118c-5.737 5.737-11.476 5.737-17.213 0l-22.953-22.953c-5.737-5.737-5.737-11.476 0-17.213l63.118-63.118 40.166 40.166zM265.269 283.956c-5.737 5.737-5.737 0-5.737-5.737l-11.476-109.021c0-5.737 5.737-11.476 11.476-11.476l109.021 11.476c5.737 0 5.737 5.737 5.737 5.737l-109.021 109.021zM334.124 209.362l63.118 63.118c5.737 5.737 5.737 11.476 0 17.213l-22.953 22.953c-5.737 5.737-11.476 5.737-17.213 0l-63.118-63.118 40.166-40.166zM161.985 593.805v-499.201h722.979v499.201h-722.979zM844.799 134.77h-636.911v413.13h636.911v-413.13z" />
|
||||
<glyph unicode="" glyph-name="h5p" data-tags="h5p" d="M934.072 489.192c-22.319 16.738-50.216 27.897-89.273 27.897h-139.487v-66.954h-156.225l-11.159-55.795c11.159 5.579 27.897 11.159 39.057 11.159s22.319 0 33.476 0c33.476 0 66.954-11.159 89.273-33.476s33.476-50.216 33.476-83.692c0-22.319-5.579-44.635-16.738-66.954s-27.897-39.057-50.216-50.216c-5.579-5.579-16.738 0-22.319-11.159h117.17v133.908h66.954c44.635 0 78.113 11.159 100.43 27.897 22.319 22.319 33.476 50.216 33.476 83.692 0 39.057-11.159 66.954-27.897 83.692v0zM839.221 377.603c-11.159-5.579-22.319-11.159-44.635-11.159h-33.476v83.692h39.057c22.319 0 33.476-5.579 44.635-11.159 5.579-5.579 11.159-16.738 11.159-27.897 0-16.738-5.579-27.897-16.738-33.476v0zM565.826 338.546c-16.738 0-33.476-11.159-44.635-27.897l-94.851 16.738 44.635 195.281h-94.851v-150.646h-117.17v150.646h-111.589v-362.667h111.589v133.908h117.17v-133.908h139.487c-16.738 11.159-33.476 11.159-44.635 22.319s-22.319 22.319-27.897 33.476c-5.579 11.159-11.159 22.319-16.738 39.057l94.851 16.738c5.579-16.738 22.319-27.897 44.635-27.897 27.897 0 50.216 22.319 50.216 50.216 0 22.319-22.319 44.635-50.216 44.635v0z" />
|
||||
<glyph unicode="" glyph-name="rights-of-use" data-tags="rights-of-use" d="M899.611 329.519c0-5.907 0-5.907 0-5.907-23.631-23.631-47.261-35.448-76.799-41.355-11.813 0-23.631-5.907-35.448-5.907s-17.724 0-29.537 0c0 0-5.907 0-5.907 5.907-64.985 59.079-135.877 118.153-200.863 183.139 0 0-5.907 0-5.907 0-23.631-5.907-47.261-11.813-70.892-17.724s-53.168 0-76.799 11.813c-17.724 11.813-23.631 17.724-29.537 35.448-5.907 5.907 0 23.631 11.813 23.631 41.355 11.813 88.616 29.537 129.971 47.261 11.813 5.907 29.537 5.907 41.355 5.907 5.907 0 11.813-5.907 11.813-5.907 41.355-17.724 82.709-29.537 124.060-47.261 0 0 5.907 0 5.907 0 29.537 5.907 64.985 17.724 94.523 23.631 5.907 0 5.907 0 5.907 0l106.34-212.676zM291.12 335.429c17.724 11.813 35.448 5.907 53.168-11.813 11.813-11.813 11.813-29.537 5.907-47.261 17.724 5.907 35.448-5.907 41.355-17.724 11.813-17.724 5.907-35.448-5.907-47.261 5.907 0 11.813 0 17.724 0 11.813-5.907 23.631-11.813 29.537-29.537s0-29.537-5.907-35.448c-5.907-5.907-11.813-11.813-17.724-17.724s-11.813-11.813-17.724-17.724-35.448-17.724-53.168 0c-29.537 29.537-53.168 64.985-82.709 94.523-17.724 23.631-35.448 41.355-47.261 64.985-5.907 11.813-11.813 17.724-11.813 29.537 0 5.907 0 17.724 5.907 23.631 11.813 11.813 17.724 17.724 29.537 29.537 17.724 17.724 47.261 11.813 64.985-5.907-5.907 0-5.907-5.907-5.907-11.813v0zM438.811 128.66l29.537-29.537c17.724-17.724 47.261-11.813 59.079 5.907l-5.907 5.907c-23.631 23.631-47.261 47.261-70.892 70.892-5.907 5.907-5.907 5.907-5.907 11.813s5.907 5.907 11.813 11.813c5.907 0 11.813 0 11.813-5.907 11.813-11.813 29.537-29.537 47.261-47.261 11.813-11.813 29.537-29.537 47.261-47.261 5.907-11.813 17.724-11.813 29.537-11.813 11.813 5.907 23.631 11.813 29.537 23.631 0 5.907 0 5.907 0 5.907-41.355 41.355-88.616 82.709-129.971 129.971-5.907 5.907-5.907 5.907-5.907 11.813 0 11.813 11.813 11.813 23.631 5.907 0 0 5.907 0 5.907-5.907 41.355-41.355 88.616-88.616 129.971-129.971 5.907-5.907 5.907-5.907 5.907-5.907 17.724 0 35.448 17.724 35.448 35.448 0 5.907 0 5.907 0 5.907-47.261 47.261-100.429 100.429-147.691 147.691-5.907 5.907-5.907 5.907-5.907 11.813s5.907 11.813 5.907 11.813c5.907 0 11.813 0 11.813-5.907 5.907-5.907 5.907-5.907 11.813-11.813 35.448-35.448 70.892-70.892 106.34-106.34 11.813-11.813 23.631-23.631 29.537-29.537 0 0 5.907-5.907 5.907 0 23.631 5.907 35.448 29.537 29.537 53.168h35.448c0 0 0 0 0 0 0-5.907 0-17.724 0-23.631-5.907-29.537-23.631-47.261-53.168-59.079 0 0-5.907 0-5.907-5.907-11.813-29.537-35.448-53.168-64.985-53.168-5.907 0-5.907 0-5.907-5.907-17.724-35.448-59.079-47.261-88.616-35.448-5.907 0-11.813 5.907-11.813 5.907-5.907-5.907-11.813-11.813-23.631-17.724-29.537-11.813-59.079-5.907-76.799 11.813-11.813 11.813-17.724 17.724-29.537 29.537 17.724 23.631 23.631 29.537 29.537 41.355v0 0zM273.396 642.628c29.537-11.813 64.985-23.631 94.523-29.537 35.448-11.813 64.985-23.631 100.429-29.537 0 0 0 0 5.907 0-17.724-5.907-35.448-11.813-47.261-17.724 0 0-5.907 0-5.907 0-47.261 11.813-94.523 23.631-135.877 41.355-5.907 0-5.907 0-5.907 0l-76.799-183.139c0-11.813 5.907-17.724 11.813-23.631s5.907-5.907 5.907-11.813c-5.907-5.907-11.813-17.724-23.631-23.631-17.724 17.724-29.537 35.448-29.537 64.985l88.616 212.676c-5.907-11.813 5.907 5.907 17.724 0v0z" />
|
||||
<glyph unicode="" glyph-name="delete-circle" data-tags="delete-circle" d="M512 601.601c-147.107 0-260.266-118.817-260.266-260.266s118.817-260.266 260.266-260.266 260.266 118.817 260.266 260.266-113.158 260.266-260.266 260.266zM653.449 262.123c5.659-5.659 5.659-16.973 0-28.29l-33.949-33.949c-5.659-5.659-16.973-5.659-28.29 0l-79.212 79.212-79.212-79.212c-5.659-5.659-16.973-5.659-28.29 0l-33.949 33.949c-5.659 5.659-5.659 16.973 0 28.29l84.871 79.212-79.212 79.212c-5.659 5.659-5.659 16.973 0 28.29l33.949 33.949c5.659 5.659 16.973 5.659 28.29 0l73.554-84.871 79.212 79.212c5.659 5.659 16.973 5.659 28.29 0l33.949-33.949c5.659-5.659 5.659-16.973 0-28.29l-79.212-73.554 79.212-79.212z" />
|
||||
<glyph unicode="" glyph-name="window" data-tags="window" d="M203.936 461.136c-5.704-5.704 0-5.704 5.704-5.704l108.394-11.41c5.704 0 11.41 5.704 11.41 11.41l-17.114 102.687c0 5.704-5.704 5.704-5.704 5.704l-102.687-102.687zM272.395 523.891l-62.752 62.752c-5.704 5.704-11.41 5.704-17.114 0l-17.114-22.821c-5.704-5.704-5.704-11.41 0-17.114l62.752-62.752 34.228 39.935zM751.605 558.119c-5.704 5.704-5.704 0-5.704-5.704l-11.41-108.394c0-5.704 5.704-11.41 11.41-11.41l108.394 11.41c5.704 0 5.704 5.704 5.704 5.704l-108.394 108.394zM814.357 483.957l62.752 62.752c5.704 5.704 5.704 11.41 0 17.114l-22.821 22.821c-5.704 5.704-11.41 5.704-17.114 0l-62.752-62.752 39.935-39.935zM848.588 221.534c5.704 5.704 0 5.704-5.704 5.704l-102.687 17.114c-5.704 0-11.41-5.704-11.41-11.41l11.41-108.394c0-5.704 5.704-5.704 5.704-5.704l102.687 102.687zM780.129 158.779l62.752-62.752c5.704-5.704 11.41-5.704 17.114 0l22.821 22.821c5.704 5.704 5.704 11.41 0 17.114l-62.752 62.752-39.935-39.935zM300.919 124.551c5.704-5.704 5.704 0 5.704 5.704l11.41 108.394c0 5.704-5.704 11.41-11.41 11.41l-108.394-11.41c-5.704 0-5.704-5.704-5.704-5.704l108.394-108.394zM238.167 193.010l-62.752-62.752c-5.704-5.704-5.704-11.41 0-17.114l22.821-22.821c5.704-5.704 11.41-5.704 17.114 0l62.752 62.752-39.935 39.935zM352.264 466.843v-239.605h347.998v239.605h-347.998zM654.622 267.172h-262.424v154.032h262.424v-154.032z" />
|
||||
<glyph unicode="" glyph-name="code" data-tags="code" d="M449.641 235.325c6.235-6.235 6.235-12.472 6.235-18.707v-62.359c0-6.235-6.235-6.235-6.235-6.235l-230.728 155.897c-6.235 6.235-6.235 12.472-6.235 18.707v49.886c0 6.235 6.235 12.472 6.235 18.707l230.728 155.897c6.235 6.235 6.235 0 6.235-6.235v-62.359c0-6.235-6.235-12.472-6.235-18.707l-162.134-112.245c-6.235-6.235-6.235-6.235 0-12.472l162.134-99.776zM736.493 341.335c6.235 6.235 6.235 6.235 0 12.472l-155.897 112.245c-6.235 6.235-6.235 12.472-6.235 18.707v62.359c0 6.235 6.235 6.235 6.235 6.235l230.728-155.897c6.235-6.235 6.235-12.472 6.235-18.707v-49.886c0-6.235-6.235-12.472-6.235-18.707l-230.728-155.897c-6.235-6.235-6.235 0-6.235 6.235v62.359c0 6.235 6.235 12.472 6.235 18.707l155.897 99.776z" />
|
||||
<glyph unicode="" glyph-name="download" data-tags="download" d="M358.941 435.525c-11.773 0-17.66-5.887-5.887-17.66l153.059-188.382c5.887-11.773 23.547-11.773 29.433 0l153.059 188.382c5.887 11.773 5.887 17.66-5.887 17.66h-323.782zM576.756 423.751v135.399c0 11.773-11.773 23.547-23.547 23.547h-70.643c-11.773 0-23.547-11.773-23.547-23.547v-141.286h117.739zM653.286 288.352c-5.887 0-17.66-5.887-23.547-11.773l-76.53-94.19c-5.887-5.887-17.66-17.66-23.547-23.547 0 0-5.887-5.887-11.773-5.887s-17.66 11.773-17.66 11.773c-5.887 5.887-17.66 17.66-23.547 23.547l-76.53 94.19c-5.887 5.887-17.66 11.773-23.547 11.773h-123.626c-5.887 0-17.66-5.887-17.66-17.66v-141.286c0-5.887 5.887-17.66 17.66-17.66h529.824c5.887 0 17.66 5.887 17.66 17.66v141.286c0 5.887-5.887 17.66-17.66 17.66l-129.513-5.887zM305.958 176.502c-17.66 0-29.433 11.773-29.433 29.433s11.773 29.433 29.433 29.433c17.66 0 29.433-11.773 29.433-29.433s-11.773-29.433-29.433-29.433v0z" />
|
||||
<glyph unicode="" glyph-name="delete" data-tags="delete" d="M620.266 341.335l134.045 134.045c10.311 10.311 10.311 30.934 0 41.245l-61.866 61.866c-10.311 10.311-30.934 10.311-41.245 0l-134.045-134.045-134.045 134.045c-10.311 10.311-30.934 10.311-41.245 0l-61.866-61.866c-10.311-10.311-10.311-30.934 0-41.245l134.045-134.045-134.045-134.045c-10.311-10.311-10.311-30.934 0-41.245l61.866-61.866c10.311-10.311 30.934-10.311 41.245 0l134.045 134.045 134.045-134.045c10.311-10.311 30.934-10.311 41.245 0l61.866 61.866c10.311 10.311 10.311 30.934 0 41.245l-134.045 134.045z" />
|
||||
<glyph unicode="" glyph-name="edit-image" data-tags="edit-image" d="M300.237 621.639c69.018 23.142 133.325 14.234 189.133-33.28 56.627-48.128 77.619-110.592 63.181-183.808-2.355-12.186 0.307-19.456 8.704-27.853 93.901-93.389 156.774-156.467 250.47-250.163 5.427-5.427 10.957-10.854 15.667-16.896 39.424-50.278 16.794-124.006-44.237-142.029-36.966-10.957-68.403 0-95.334 27.034-95.642 96.051-160.973 160.973-256.614 257.024-6.963 6.963-12.8 8.909-22.63 6.758-117.76-26.317-229.171 60.826-231.731 181.453-0.614 26.419 3.584 52.326 15.974 77.926 34.816-34.816 68.506-67.789 101.274-101.786 10.445-10.752 20.992-15.36 36.045-15.36 14.643 0 25.19 3.891 34.816 14.848 10.752 12.39 23.040 23.347 34.611 35.021 14.336 14.438 14.336 46.080-0.205 60.518-35.123 35.226-70.349 70.349-106.598 106.496 3.891 2.253 5.632 3.482 7.475 4.096zM703.386 63.559c-0.41-24.269 20.685-45.466 44.851-45.158 23.757 0.41 44.032 20.992 43.93 44.544-0.102 23.757-20.275 44.032-44.237 44.134-23.859 0.307-44.237-19.661-44.544-43.52z" />
|
||||
<glyph unicode="" glyph-name="hourglass" data-tags="hourglass" d="M733.286-10.579c-147.763 0-295.526 0-443.29 0 0 2.048 0.102 4.096 0 6.144-0.307 13.824-1.024 32.666-0.922 46.49 0.41 39.731 6.861 78.131 19.046 115.2 17.203 52.224 43.725 96.256 81.306 130.355 4.506 4.096 9.216 7.885 13.722 11.776-0.205 0.717-0.307 1.126-0.41 1.229-1.331 1.229-2.765 2.355-4.198 3.584-28.058 22.63-50.688 51.405-68.403 85.606-30.618 59.085-43.52 123.597-41.165 192.614 0.205 7.168 0.614 18.33 0.922 25.498 147.763 0 295.526 0 443.29 0 0.205-1.331 0.512-2.662 0.614-3.994 2.662-36.966 1.229-77.722-5.939-113.869-14.336-72.909-44.544-133.837-95.027-179.405-4.096-3.686-8.294-7.066-12.39-10.547 0.205-0.717 0.307-1.126 0.512-1.331 0.819-0.717 1.638-1.434 2.458-2.15 42.189-33.894 71.68-79.872 90.931-135.782 11.776-34.202 18.637-69.837 20.070-106.701 0.819-19.763-0.614-44.851-1.126-64.717zM687.309 32.634c0 6.554 0.205 12.493 0 18.432-1.331 37.581-7.27 74.138-19.866 108.749-17.92 49.562-45.568 88.269-88.678 108.646-2.458 1.126-2.97 3.072-2.97 5.837 0.102 16.691 0.102 33.485 0 50.176 0 3.994 1.331 5.427 4.096 6.963 9.114 5.325 18.432 10.24 26.829 16.896 29.696 23.552 49.152 56.934 62.362 95.744 10.342 30.413 15.77 62.259 17.818 94.822 0.614 9.114 0.102 18.227 0.102 27.546-116.634 0-233.574 0-351.027 0 0.307-8.704 0.614-16.998 1.024-25.395 1.946-37.274 8.499-73.216 21.504-107.213 18.125-47.104 45.261-83.558 86.528-103.117 2.253-1.024 2.867-2.662 2.867-5.427-0.102-17.203-0.102-34.509 0-51.712 0-3.072-1.024-4.506-3.277-5.632-5.632-2.867-11.366-5.734-16.691-9.216-34.304-22.733-56.832-57.754-71.987-100.147-12.493-35.123-18.125-71.987-19.661-109.875-0.205-5.325 0-10.752 0-16.282 117.35 0.205 234.189 0.205 351.027 0.205zM410.214 451.962c68.096 0 135.373 0 203.674 0-3.789-6.554-7.168-12.595-10.752-18.227-10.957-16.998-24.269-30.618-39.731-41.472s-27.75-25.293-32.768-46.592c-1.638-6.963-2.765-14.336-2.867-21.606-0.307-17.203-0.205-34.406 0.307-51.712 0.717-28.058 12.493-48.947 32.154-62.566 43.008-30.003 65.843-75.878 75.776-132.506 0.307-1.638 0.307-3.379 0.614-5.53-83.149 0-166.093 0-249.242 0 2.662 20.685 7.885 40.346 15.462 59.085 13.312 32.973 32.768 59.187 59.494 77.722 16.589 11.469 28.365 27.955 32.358 50.995 0.819 4.813 1.331 9.83 1.434 14.746 0.102 18.637 0.614 37.274-0.205 55.808-1.126 24.678-11.981 43.213-28.57 57.139-9.216 7.782-18.944 14.746-27.648 23.142-11.981 11.162-21.197 25.395-29.491 41.574z" />
|
||||
<glyph unicode="" glyph-name="plus-icon" data-tags="plus-icon" d="M768 285.015c0-19.323-15.664-34.987-34.987-34.987h-151.040v-151.467c0-19.323-15.664-34.987-34.987-34.987h-69.547c-19.323 0-34.987 15.664-34.987 34.987v151.467h-151.467c-19.323 0-34.987 15.664-34.987 34.987v69.547c0 19.323 15.664 34.987 34.987 34.987h151.467v151.467c0 19.323 15.664 34.987 34.987 34.987h69.547c19.323 0 34.987-15.664 34.987-34.987v-151.467h151.467c19.323 0 34.987-15.664 34.987-34.987z" />
|
||||
<glyph unicode="" glyph-name="video-upload-icon" data-tags="video-upload-icon" d="M384 328.535v-128c0-21.333 21.333-42.667 42.667-42.667h128c21.333 0 42.667 17.067 42.667 42.667v128c0 21.333-17.067 42.667-42.667 42.667h-128c-21.333 0-42.667-17.067-42.667-42.667zM785.067 499.201l-102.4 106.667c-12.8 12.8-38.4 21.333-55.467 21.333h-140.8l21.333-42.667h89.6v-136.533c0-17.067 12.8-29.867 29.867-29.867h140.8v-341.333h-426.667v328.533h-42.667v-341.333c0-17.067 12.8-29.867 29.867-29.867h448c17.067 0 29.867 12.8 29.867 29.867v384c4.267 17.067-8.533 38.4-21.333 51.2zM640 456.535v123.733c4.267 0 12.8-4.267 12.8-8.533l102.4-102.4c4.267-4.267 4.267-8.533 8.533-12.8h-123.733zM725.333 166.401v196.267c0 4.267-4.267 8.533-8.533 8.533s-8.533 0-12.8-4.267l-89.6-89.6v-29.867l89.6-89.6c8.533-4.267 8.533 0 12.8 0 4.267 4.267 8.533 4.267 8.533 8.533zM349.867 473.601v136.533l59.733-59.733c8.533-8.533 17.067-4.267 25.6 0l12.8 12.8c8.533 8.533 8.533 17.067 0 25.6l-115.2 106.667c-8.533 8.533-17.067 8.533-21.333 0l-115.2-110.933c-4.267-8.533-4.267-17.067 0-25.6l12.8-12.8c8.533-8.533 17.067-8.533 21.333 0l59.733 59.733v-136.533c0-8.533 8.533-17.067 17.067-17.067h25.6c0 0 17.067 8.533 17.067 21.333z" />
|
||||
<glyph unicode="" glyph-name="play-icon" data-tags="play-icon" d="M392.533 597.335c81.067 46.933 187.733 46.933 273.067 0 42.667-25.6 72.533-55.467 98.133-98.133 72.533-128 29.867-294.4-98.133-371.2-128-72.533-294.4-29.867-371.2 98.133-46.933 81.067-46.933 187.733 0 273.067 21.333 42.667 55.467 72.533 98.133 98.133zM661.333 345.601c12.8 8.533 12.8 29.867 0 38.4l-192 110.933c-8.533 4.267-12.8 4.267-21.333 0s-12.8-12.8-12.8-21.333v-226.133c0-8.533 4.267-17.067 12.8-21.333s17.067-4.267 21.333 0l192 119.467z" />
|
||||
<glyph unicode="" glyph-name="copy" data-tags="copy" d="M722.133 561.201h-247.733c-65.867 0-119.2-53.333-119.2-119.2v-288.533c0-65.867 53.333-119.2 119.2-119.2h247.867c65.867 0 119.2 53.333 119.2 119.2v288.533c-0.267 65.867-53.467 119.2-119.333 119.2zM778.533 156.534c0-31.333-25.067-56.4-56.4-56.4h-247.867c-31.333 0-56.4 25.067-56.4 56.4v285.467c0 31.333 25.067 56.4 56.4 56.4h247.733c31.333 0 56.4-25.067 56.4-56.4v-285.467zM245.2 326.001v288.533c0 31.333 25.067 56.4 56.4 56.4h247.733c31.333 0 56.4-25.067 56.4-56.4v-18.8h62.667v18.8c0 65.867-53.333 119.2-119.2 119.2h-247.467c-65.867 0-119.2-53.333-119.2-119.2v-288.533c0-65.867 53.333-119.2 119.2-119.2h18.8v62.667h-18.8c-31.467-3.067-56.533 22-56.533 56.533zM681.2 360.534h-163.067c-18.8 0-31.333 12.533-31.333 31.333s12.533 31.333 31.333 31.333h163.067c18.8 0 31.333-12.533 31.333-31.333s-15.6-31.333-31.333-31.333zM681.2 266.401h-163.067c-18.8 0-31.333 12.533-31.333 31.333s12.533 31.333 31.333 31.333h163.067c18.8 0 31.333-12.533 31.333-31.333s-15.6-31.333-31.333-31.333zM681.2 172.268h-163.067c-18.8 0-31.333 12.533-31.333 31.333s12.533 31.333 31.333 31.333h163.067c18.8 0 31.333-12.533 31.333-31.333s-15.6-31.333-31.333-31.333z" />
|
||||
<glyph unicode="" glyph-name="examples-icon" data-tags="examples-icon" d="M213.333 166.402c89.6 38.4 183.467 68.267 273.067 17.067v281.6c-68.267 46.933-157.867 55.467-234.667 12.8l-38.4-311.467zM810.667 166.402l-42.667 315.733c-72.533 38.4-166.4 34.133-234.667-17.067v-285.867c93.867 51.2 187.733 21.333 277.333-12.8zM832 520.535c-51.2 29.867-110.933 46.933-170.667 55.467-51.2 0-102.4-8.533-149.333-29.867-46.933 21.333-98.133 29.867-149.333 29.867-59.733-4.267-119.467-25.6-170.667-55.467l-64-452.267c0 0 29.867-17.067 110.933 21.333 46.933 25.6 102.4 34.133 157.867 25.6 42.667-4.267 85.333-21.333 115.2-55.467v0c29.867 34.133 72.533 51.2 115.2 55.467 55.467 4.267 106.667-4.267 157.867-29.867 81.067-38.4 110.933-21.333 110.933-21.333l-64 456.533zM793.6 115.202c-42.667 21.333-89.6 34.133-140.8 34.133-8.533 0-21.333 0-29.867 0-42.667-4.267-81.067-17.067-115.2-42.667-34.133 25.6-72.533 38.4-115.2 42.667-12.8 0-21.333 0-34.133 0-46.933 0-93.867-8.533-136.533-29.867-21.333-12.8-46.933-21.333-72.533-25.6l64 413.867c46.933 25.6 98.133 38.4 149.333 42.667 46.933 0 93.867-8.533 136.533-25.6l12.8-8.533 12.8 4.267c42.667 17.067 89.6 25.6 136.533 25.6 51.2-4.267 102.4-17.067 149.333-42.667l59.733-418.133c-29.867 8.533-51.2 17.067-76.8 29.867z" />
|
||||
<glyph unicode="" glyph-name="tutorials-icon" data-tags="tutorials-icon" d="M887.467 430.935l-375.467-110.933h-4.267l-217.6 68.267c-21.333-25.6-34.133-59.733-34.133-98.133 21.333-12.8 25.6-38.4 12.8-59.733-4.267-4.267-8.533-8.533-12.8-12.8l17.067-145.067c0-4.267 0-4.267-4.267-8.533 0 0 0 0-4.267 0h-64c-4.267 0-4.267 0-8.533 4.267 0 4.267-4.267 4.267-4.267 8.533l17.067 145.067c-12.8 8.533-17.067 21.333-17.067 34.133 0 17.067 8.533 29.867 21.333 38.4 0 38.4 12.8 76.8 34.133 110.933l-106.667 29.867c-8.533 4.267-8.533 8.533-8.533 17.067 0 4.267 4.267 4.267 4.267 4.267l375.467 119.467h4.267l375.467-123.733c4.267 0 8.533-4.267 8.533-8.533s-4.267-8.533-8.533-12.8zM725.333 234.669c4.267-46.933-93.867-85.333-213.333-85.333s-213.333 38.4-213.333 85.333l4.267 106.667 192-64c4.267 0 12.8 0 17.067 0s12.8 0 17.067 4.267l192 59.733 4.267-106.667z" />
|
||||
<glyph unicode="" glyph-name="info-important-description" data-tags="info-important-description" d="M512 697.368c-188.5 0-341.3-152.8-341.3-341.3s152.8-341.4 341.3-341.4 341.3 152.8 341.3 341.3-152.8 341.4-341.3 341.4v0zM512 43.268c-172.7 0-312.7 140-312.7 312.7s140 312.7 312.7 312.7c172.7 0 312.7-140 312.7-312.7-0.2-172.6-140.1-312.5-312.7-312.7v0zM512 605.568c-137.9 0-249.6-111.8-249.6-249.6s111.7-249.6 249.6-249.6 249.6 111.8 249.6 249.6-111.8 249.6-249.6 249.6v0z" />
|
||||
<glyph unicode="" glyph-name="icon-info" data-tags="icon-info" d="M467.2 459.522h87.467c0.028 0 0.062 0 0.095 0 6.056 0 11.499 2.629 15.248 6.808 3.979 4.15 6.419 9.769 6.419 15.957 0 0.097-0.001 0.194-0.002 0.29v70.385c0.001 0.082 0.002 0.179 0.002 0.276 0 6.188-2.44 11.806-6.409 15.946-3.759 4.19-9.201 6.819-15.257 6.819-0.033 0-0.067 0-0.1 0h-87.462c-0.028 0-0.062 0-0.095 0-6.056 0-11.499-2.629-15.248-6.808-3.979-4.15-6.419-9.769-6.419-15.957 0-0.097 0.001-0.194 0.002-0.29v-69.959c-0.001-0.082-0.002-0.179-0.002-0.276 0-6.188 2.44-11.806 6.409-15.946 3.715-4.373 9.2-7.159 15.338-7.245zM597.333 156.589h-22.187v209.92c0.001 0.082 0.002 0.179 0.002 0.276 0 6.188-2.44 11.806-6.409 15.946-3.759 4.19-9.201 6.819-15.257 6.819-0.033 0-0.067 0-0.1 0h-130.128c-0.028 0-0.062 0-0.095 0-6.056 0-11.499-2.629-15.248-6.808-3.979-4.15-6.419-9.769-6.419-15.957 0-0.097 0.001-0.194 0.002-0.29v-46.492c-0.001-0.082-0.002-0.179-0.002-0.276 0-6.188 2.44-11.806 6.409-15.946 3.759-4.19 9.201-6.819 15.257-6.819 0.033 0 0.067 0 0.1 0h22.182v-139.947h-22.187c-0.028 0-0.062 0-0.095 0-6.056 0-11.499-2.629-15.248-6.808-3.979-4.15-6.419-9.769-6.419-15.957 0-0.097 0.001-0.194 0.002-0.29v-46.492c-0.001-0.082-0.002-0.179-0.002-0.276 0-6.188 2.44-11.806 6.409-15.946 3.759-4.19 9.201-6.819 15.257-6.819 0.033 0 0.067 0 0.1 0h174.075c0.028 0 0.062 0 0.095 0 6.056 0 11.499 2.629 15.248 6.808 3.979 4.15 6.419 9.769 6.419 15.957 0 0.097-0.001 0.194-0.002 0.29v46.065c0.043 0.527 0.067 1.141 0.067 1.761 0 5.302-1.791 10.185-4.8 14.079-3.742 4.424-9.36 7.247-15.636 7.247-0.489 0-0.975-0.017-1.456-0.051z" />
|
||||
<glyph unicode="" glyph-name="paste" data-tags="paste" d="M394.402 702.4h-75.333c-65.867 0-119.2-53.333-119.2-119.2v-288.533c0-56.4 37.6-100.4 87.867-116v69.067c-15.733 9.467-25.067 25.067-25.067 47.067v288.4c0 31.333 25.067 56.4 56.4 56.4h131.733c0 0 0 0 3.2 3.2v0c0 31.333-28.267 59.6-59.6 59.6zM704.802 592.533c0 0-28.267 0-40.8 0-12.533 34.533-43.867 59.6-84.667 59.6s-69.067-25.067-81.6-59.6c-12.533 0-40.8 0-40.8 0-65.867 0-119.2-53.333-119.2-119.2v-288.533c0-65.867 53.333-119.2 119.2-119.2h247.867c65.867 0 119.2 53.333 119.2 119.2v285.467c3.2 65.867-53.2 122.267-119.2 122.267zM582.535 605.2c22 0 40.8-18.8 40.8-40.8s-18.8-40.8-40.8-40.8c-22 0-40.8 18.8-40.8 40.8s15.733 40.8 40.8 40.8zM764.402 181.733c0-31.333-25.067-56.4-56.4-56.4h-250.933c-31.333 0-56.4 25.067-56.4 56.4v288.533c0 18.8 9.467 37.6 25.067 47.067v0c0-43.867 34.533-78.4 78.4-78.4h160c43.867 0 78.4 34.533 78.4 78.4v0c12.533-9.467 22-28.267 22-47.067v-288.533z" />
|
||||
<glyph unicode="" glyph-name="reuse" data-tags="reuse" d="M734.974 624.751c-54.605 61.619-134.123 100.573-222.977 100.573-164.936 0-298.661-133.724-298.661-298.661h74.667c0 123.721 100.272 223.993 223.993 223.993 68.214 0 128.747-30.96 169.766-79.119l-70.213-70.213h199.109v199.109l-75.689-75.689zM511.999 202.671c-68.214 0-128.747 30.96-169.766 79.119l70.213 70.213h-199.109v-199.109l75.689 75.689c54.605-61.619 134.123-100.573 222.977-100.573 164.936 0 298.661 133.724 298.661 298.661h-74.667c0-123.721-100.272-223.993-223.993-223.993z" />
|
||||
<glyph unicode="" glyph-name="info-outlined" data-tags="info-outlined" d="M467.199 181.336h89.599v268.8h-89.599v-268.8zM512 853.335c-247.296 0-448.001-200.705-448.001-448.001s200.705-448.001 448.001-448.001 448.001 200.705 448.001 448.001-200.705 448.001-448.001 448.001zM512 46.936c-197.568 0-358.398 160.83-358.398 358.398s160.83 358.398 358.398 358.398 358.398-160.83 358.398-358.398-160.83-358.398-358.398-358.398zM467.199 539.734h89.599v89.599h-89.599v-89.599z" />
|
||||
<glyph unicode="" glyph-name="spinner" data-tags="spinner" d="M600 808.001c0-48.602-39.398-88-88-88s-88 39.398-88 88 39.398 88 88 88 88-39.398 88-88zM512 133.333c-48.602 0-88-39.398-88-88s39.398-88 88-88 88 39.398 88 88-39.398 88-88 88zM893.334 514.667c-48.602 0-88-39.398-88-88s39.398-88 88-88 88 39.398 88 88-39.398 88-88 88zM218.666 426.667c0 48.602-39.398 88-88 88s-88-39.398-88-88 39.398-88 88-88 88 39.398 88 88zM242.357 245.024c-48.602 0-88-39.398-88-88s39.398-88 88-88 88 39.398 88 88c0 48.6-39.4 88-88 88zM781.643 245.024c-48.602 0-88-39.398-88-88s39.398-88 88-88 88 39.398 88 88c0 48.6-39.398 88-88 88zM242.357 784.31c-48.602 0-88-39.398-88-88s39.398-88 88-88 88 39.398 88 88-39.4 88-88 88z" />
|
||||
<glyph unicode="" glyph-name="copy-enabled" data-tags="copy-enabled" d="M614.525 809.292h-317.672c-74.968 0-135.9-60.931-135.9-135.9v-370.388c0-43.817 20.88-82.842 53.231-107.83v70.346c-4.45 11.297-7.016 23.962-7.016 37.484v370.388c0 49.292 40.224 89.516 89.516 89.516h318.014c15.232 0 29.611-3.766 42.107-10.613h68.294c-24.646 34.402-65.039 56.997-110.57 56.997zM674.431 267.403h-209.327c-14.721 0-23.105-8.388-23.105-23.105s8.388-23.105 23.105-23.105h209.327c11.124 0 23.105 8.899 23.105 23.105 0 14.721-8.388 23.105-23.105 23.105zM674.431 388.244h-209.327c-14.721 0-23.105-8.388-23.105-23.105s8.388-23.105 23.105-23.105h209.327c11.124 0 23.105 8.899 23.105 23.105 0 14.721-8.388 23.105-23.105 23.105zM726.978 686.23h-318.014c-74.968 0-135.9-60.931-135.9-135.9v-370.388c0-74.968 60.931-135.9 135.9-135.9v0h318.183c74.968 0 135.9 60.931 135.9 135.9v370.388c-0.342 74.968-61.273 135.9-136.073 135.9zM816.494 183.878c0-49.292-40.224-89.516-89.516-89.516h-318.183c-49.292 0-89.516 40.224-89.516 89.516v366.449c0 49.292 40.224 89.516 89.516 89.516h318.014c49.292 0 89.516-40.224 89.516-89.516v-349.334h0.173v-17.115zM674.431 509.081h-209.327c-14.721 0-23.105-8.388-23.105-23.105s8.388-23.105 23.105-23.105h209.327c11.124 0 23.105 8.899 23.105 23.105 0 14.721-8.388 23.105-23.105 23.105z" />
|
||||
<glyph unicode="" glyph-name="copy-disabled" data-tags="copy-disabled" d="M614.525 809.292h-317.672c-74.968 0-135.9-60.931-135.9-135.9v-370.388c0-43.817 20.88-82.842 53.231-107.83v70.346c-4.45 11.297-7.016 23.962-7.016 37.484v370.388c0 49.292 40.224 89.516 89.516 89.516h318.014c15.232 0 29.611-3.766 42.107-10.613h68.294c-24.646 34.402-65.039 56.997-110.57 56.997zM726.978 686.23h-318.014c-74.968 0-135.9-60.931-135.9-135.9v-370.388c0-74.968 60.931-135.9 135.9-135.9v0h318.183c74.968 0 135.9 60.931 135.9 135.9v370.388c-0.342 74.968-61.273 135.9-136.073 135.9zM816.494 183.878c0-49.292-40.224-89.516-89.516-89.516h-318.183c-49.292 0-89.516 40.224-89.516 89.516v366.449c0 49.292 40.224 89.516 89.516 89.516h318.014c49.292 0 89.516-40.224 89.516-89.516v-349.334h0.173v-17.115zM709.521 468.857l-27.728 27.555-109.544-109.544-109.544 109.544-27.555-27.555 109.544-109.544-109.544-109.544 27.555-27.555 109.544 109.544 109.544-109.544 27.555 27.555-109.544 109.544 109.713 109.544z" />
|
||||
<glyph unicode="" glyph-name="paste-enabled" data-tags="paste-enabled" d="M410.237 57.275c-75.402 0-136.793 61.394-136.793 136.793v373.025c0 75.402 61.394 136.793 136.793 136.793h64.85l4.152 11.413c15.219 41.678 47.732 65.715 89.237 65.715 42.716 0 78.512-25.075 93.212-65.715l4.152-11.413h64.85c37.007 0 73.499-15.911 99.786-43.581 25.594-26.805 38.737-61.048 37.007-96.326v-369.738c0-75.402-61.394-136.793-136.793-136.793l-320.453-0.173zM360.947 638.689c-24.729-15.046-40.64-44.619-40.64-75.575v-373.025c0-49.804 40.467-90.271 90.271-90.271h324.432c43.754 0 80.415 31.476 88.545 72.981h1.73l0.173 17.295v373.025c0 28.708-14.181 58.627-35.277 74.71l-27.67 20.923v-17.468c0-47.213-36.834-84.048-84.048-84.048h-207.351c-47.213 0-84.048 36.834-84.048 84.048v13.489l-26.113-16.084zM572.451 733.631c-27.843 0-48.766-20.923-48.766-48.766 0-26.459 22.307-48.766 48.766-48.766s48.766 22.307 48.766 48.766c0.173 26.286-22.134 48.766-48.766 48.766zM422.169 764.069c7.78 8.818 16.603 16.776 24.383 25.594 1.903 2.076 3.806 4.325 5.709 6.401h-158.585c-75.748 0-137.312-61.567-137.312-137.312v-374.236c0-44.965 21.788-84.913 55.167-109.988v68.829c-5.536 12.278-8.472 26.113-8.472 41.159v374.236c0 49.804 40.64 90.444 90.444 90.444h116.561c3.633 5.19 7.78 10.202 12.105 14.873z" />
|
||||
<glyph unicode="" glyph-name="paste-disabled" data-tags="paste-disabled" d="M410.237 57.275c-75.402 0-136.793 61.394-136.793 136.793v373.025c0 75.402 61.394 136.793 136.793 136.793h64.85l4.152 11.413c15.219 41.678 47.732 65.715 89.237 65.715 42.716 0 78.512-25.075 93.212-65.715l4.152-11.413h64.85c37.007 0 73.499-15.911 99.786-43.581 25.594-26.805 38.737-61.048 37.007-96.326v-369.738c0-75.402-61.394-136.793-136.793-136.793l-320.453-0.173zM360.947 638.689c-24.729-15.046-40.64-44.619-40.64-75.575v-373.025c0-49.804 40.467-90.271 90.271-90.271h324.432c43.754 0 80.415 31.476 88.545 72.981h1.73l0.173 17.295v373.025c0 28.708-14.181 58.627-35.277 74.71l-27.67 20.923v-17.468c0-47.213-36.834-84.048-84.048-84.048h-207.351c-47.213 0-84.048 36.834-84.048 84.048v13.489l-26.113-16.084zM572.451 733.631c-27.843 0-48.766-20.923-48.766-48.766 0-26.459 22.307-48.766 48.766-48.766s48.766 22.307 48.766 48.766c0.173 26.286-22.134 48.766-48.766 48.766zM422.169 764.069c7.78 8.818 16.603 16.776 24.383 25.594 1.903 2.076 3.806 4.325 5.709 6.401h-158.585c-75.748 0-137.312-61.567-137.312-137.312v-374.236c0-44.965 21.788-84.913 55.167-109.988v68.829c-5.536 12.278-8.472 26.113-8.472 41.159v374.236c0 49.804 40.64 90.444 90.444 90.444h116.561c3.633 5.19 7.78 10.202 12.105 14.873zM718.585 463.848l-28.016 27.843-110.68-110.68-110.68 110.68-27.843-27.843 110.68-110.68-110.68-110.68 27.843-27.843 110.68 110.68 110.68-110.68 27.843 27.843-110.68 110.68 110.853 110.68z" />
|
||||
<glyph unicode="" glyph-name="button-disabled" data-tags="button-disabled" d="M853.333 699.246l-68.754 68.754-272.579-272.579-272.579 272.579-68.754-68.754 272.579-272.579-272.579-272.579 68.754-68.754 272.579 272.579 272.579-272.579 68.754 68.754-272.579 272.579z" />
|
||||
</font></defs></svg>
|
After Width: | Height: | Size: 32 KiB |
BIN
lib/h5p/fonts/h5p-core-23.ttf
Normal file
BIN
lib/h5p/fonts/h5p-core-23.ttf
Normal file
Binary file not shown.
BIN
lib/h5p/fonts/h5p-core-23.woff
Normal file
BIN
lib/h5p/fonts/h5p-core-23.woff
Normal file
Binary file not shown.
586
lib/h5p/h5p-default-storage.class.php
Normal file
586
lib/h5p/h5p-default-storage.class.php
Normal file
@ -0,0 +1,586 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* File info?
|
||||
*/
|
||||
|
||||
/**
|
||||
* The default file storage class for H5P. Will carry out the requested file
|
||||
* operations using PHP's standard file operation functions.
|
||||
*
|
||||
* Some implementations of H5P that doesn't use the standard file system will
|
||||
* want to create their own implementation of the \H5P\FileStorage interface.
|
||||
*
|
||||
* @package H5P
|
||||
* @copyright 2016 Joubel AS
|
||||
* @license MIT
|
||||
*/
|
||||
class H5PDefaultStorage implements \H5PFileStorage {
|
||||
private $path, $alteditorpath;
|
||||
|
||||
/**
|
||||
* The great Constructor!
|
||||
*
|
||||
* @param string $path
|
||||
* The base location of H5P files
|
||||
* @param string $alteditorpath
|
||||
* Optional. Use a different editor path
|
||||
*/
|
||||
function __construct($path, $alteditorpath = NULL) {
|
||||
// Set H5P storage path
|
||||
$this->path = $path;
|
||||
$this->alteditorpath = $alteditorpath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the library folder.
|
||||
*
|
||||
* @param array $library
|
||||
* Library properties
|
||||
*/
|
||||
public function saveLibrary($library) {
|
||||
$dest = $this->path . '/libraries/' . \H5PCore::libraryToString($library, TRUE);
|
||||
|
||||
// Make sure destination dir doesn't exist
|
||||
\H5PCore::deleteFileTree($dest);
|
||||
|
||||
// Move library folder
|
||||
self::copyFileTree($library['uploadDirectory'], $dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the content folder.
|
||||
*
|
||||
* @param string $source
|
||||
* Path on file system to content directory.
|
||||
* @param array $content
|
||||
* Content properties
|
||||
*/
|
||||
public function saveContent($source, $content) {
|
||||
$dest = "{$this->path}/content/{$content['id']}";
|
||||
|
||||
// Remove any old content
|
||||
\H5PCore::deleteFileTree($dest);
|
||||
|
||||
self::copyFileTree($source, $dest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove content folder.
|
||||
*
|
||||
* @param array $content
|
||||
* Content properties
|
||||
*/
|
||||
public function deleteContent($content) {
|
||||
\H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a stored copy of the content folder.
|
||||
*
|
||||
* @param string $id
|
||||
* Identifier of content to clone.
|
||||
* @param int $newId
|
||||
* The cloned content's identifier
|
||||
*/
|
||||
public function cloneContent($id, $newId) {
|
||||
$path = $this->path . '/content/';
|
||||
if (file_exists($path . $id)) {
|
||||
self::copyFileTree($path . $id, $path . $newId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path to a new unique tmp folder.
|
||||
*
|
||||
* @return string
|
||||
* Path
|
||||
*/
|
||||
public function getTmpPath() {
|
||||
$temp = "{$this->path}/temp";
|
||||
self::dirReady($temp);
|
||||
return "{$temp}/" . uniqid('h5p-');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch content folder and save in target directory.
|
||||
*
|
||||
* @param int $id
|
||||
* Content identifier
|
||||
* @param string $target
|
||||
* Where the content folder will be saved
|
||||
*/
|
||||
public function exportContent($id, $target) {
|
||||
$source = "{$this->path}/content/{$id}";
|
||||
if (file_exists($source)) {
|
||||
// Copy content folder if it exists
|
||||
self::copyFileTree($source, $target);
|
||||
}
|
||||
else {
|
||||
// No contnet folder, create emty dir for content.json
|
||||
self::dirReady($target);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch library folder and save in target directory.
|
||||
*
|
||||
* @param array $library
|
||||
* Library properties
|
||||
* @param string $target
|
||||
* Where the library folder will be saved
|
||||
* @param string $developmentPath
|
||||
* Folder that library resides in
|
||||
*/
|
||||
public function exportLibrary($library, $target, $developmentPath=NULL) {
|
||||
$folder = \H5PCore::libraryToString($library, TRUE);
|
||||
$srcPath = ($developmentPath === NULL ? "/libraries/{$folder}" : $developmentPath);
|
||||
self::copyFileTree("{$this->path}{$srcPath}", "{$target}/{$folder}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Save export in file system
|
||||
*
|
||||
* @param string $source
|
||||
* Path on file system to temporary export file.
|
||||
* @param string $filename
|
||||
* Name of export file.
|
||||
* @throws Exception Unable to save the file
|
||||
*/
|
||||
public function saveExport($source, $filename) {
|
||||
$this->deleteExport($filename);
|
||||
|
||||
if (!self::dirReady("{$this->path}/exports")) {
|
||||
throw new Exception("Unable to create directory for H5P export file.");
|
||||
}
|
||||
|
||||
if (!copy($source, "{$this->path}/exports/{$filename}")) {
|
||||
throw new Exception("Unable to save H5P export file.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes given export file
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public function deleteExport($filename) {
|
||||
$target = "{$this->path}/exports/{$filename}";
|
||||
if (file_exists($target)) {
|
||||
unlink($target);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given export file exists
|
||||
*
|
||||
* @param string $filename
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasExport($filename) {
|
||||
$target = "{$this->path}/exports/{$filename}";
|
||||
return file_exists($target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will concatenate all JavaScrips and Stylesheets into two files in order
|
||||
* to improve page performance.
|
||||
*
|
||||
* @param array $files
|
||||
* A set of all the assets required for content to display
|
||||
* @param string $key
|
||||
* Hashed key for cached asset
|
||||
*/
|
||||
public function cacheAssets(&$files, $key) {
|
||||
foreach ($files as $type => $assets) {
|
||||
if (empty($assets)) {
|
||||
continue; // Skip no assets
|
||||
}
|
||||
|
||||
$content = '';
|
||||
foreach ($assets as $asset) {
|
||||
// Get content from asset file
|
||||
$assetContent = file_get_contents($this->path . $asset->path);
|
||||
$cssRelPath = preg_replace('/[^\/]+$/', '', $asset->path);
|
||||
|
||||
// Get file content and concatenate
|
||||
if ($type === 'scripts') {
|
||||
$content .= $assetContent . ";\n";
|
||||
}
|
||||
else {
|
||||
// Rewrite relative URLs used inside stylesheets
|
||||
$content .= preg_replace_callback(
|
||||
'/url\([\'"]?([^"\')]+)[\'"]?\)/i',
|
||||
function ($matches) use ($cssRelPath) {
|
||||
if (preg_match("/^(data:|([a-z0-9]+:)?\/)/i", $matches[1]) === 1) {
|
||||
return $matches[0]; // Not relative, skip
|
||||
}
|
||||
return 'url("../' . $cssRelPath . $matches[1] . '")';
|
||||
},
|
||||
$assetContent) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
self::dirReady("{$this->path}/cachedassets");
|
||||
$ext = ($type === 'scripts' ? 'js' : 'css');
|
||||
$outputfile = "/cachedassets/{$key}.{$ext}";
|
||||
file_put_contents($this->path . $outputfile, $content);
|
||||
$files[$type] = array((object) array(
|
||||
'path' => $outputfile,
|
||||
'version' => ''
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Will check if there are cache assets available for content.
|
||||
*
|
||||
* @param string $key
|
||||
* Hashed key for cached asset
|
||||
* @return array
|
||||
*/
|
||||
public function getCachedAssets($key) {
|
||||
$files = array();
|
||||
|
||||
$js = "/cachedassets/{$key}.js";
|
||||
if (file_exists($this->path . $js)) {
|
||||
$files['scripts'] = array((object) array(
|
||||
'path' => $js,
|
||||
'version' => ''
|
||||
));
|
||||
}
|
||||
|
||||
$css = "/cachedassets/{$key}.css";
|
||||
if (file_exists($this->path . $css)) {
|
||||
$files['styles'] = array((object) array(
|
||||
'path' => $css,
|
||||
'version' => ''
|
||||
));
|
||||
}
|
||||
|
||||
return empty($files) ? NULL : $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the aggregated cache files.
|
||||
*
|
||||
* @param array $keys
|
||||
* The hash keys of removed files
|
||||
*/
|
||||
public function deleteCachedAssets($keys) {
|
||||
foreach ($keys as $hash) {
|
||||
foreach (array('js', 'css') as $ext) {
|
||||
$path = "{$this->path}/cachedassets/{$hash}.{$ext}";
|
||||
if (file_exists($path)) {
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read file content of given file and then return it.
|
||||
*
|
||||
* @param string $file_path
|
||||
* @return string
|
||||
*/
|
||||
public function getContent($file_path) {
|
||||
return file_get_contents($file_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save files uploaded through the editor.
|
||||
* The files must be marked as temporary until the content form is saved.
|
||||
*
|
||||
* @param \H5peditorFile $file
|
||||
* @param int $contentid
|
||||
*/
|
||||
public function saveFile($file, $contentId) {
|
||||
// Prepare directory
|
||||
if (empty($contentId)) {
|
||||
// Should be in editor tmp folder
|
||||
$path = $this->getEditorPath();
|
||||
}
|
||||
else {
|
||||
// Should be in content folder
|
||||
$path = $this->path . '/content/' . $contentId;
|
||||
}
|
||||
$path .= '/' . $file->getType() . 's';
|
||||
self::dirReady($path);
|
||||
|
||||
// Add filename to path
|
||||
$path .= '/' . $file->getName();
|
||||
|
||||
copy($_FILES['file']['tmp_name'], $path);
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a file from another content or editor tmp dir.
|
||||
* Used when copy pasting content in H5P Editor.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param string|int $fromid Content ID or 'editor' string
|
||||
* @param int $toid Target Content ID
|
||||
*/
|
||||
public function cloneContentFile($file, $fromId, $toId) {
|
||||
// Determine source path
|
||||
if ($fromId === 'editor') {
|
||||
$sourcepath = $this->getEditorPath();
|
||||
}
|
||||
else {
|
||||
$sourcepath = "{$this->path}/content/{$fromId}";
|
||||
}
|
||||
$sourcepath .= '/' . $file;
|
||||
|
||||
// Determine target path
|
||||
$filename = basename($file);
|
||||
$filedir = str_replace($filename, '', $file);
|
||||
$targetpath = "{$this->path}/content/{$toId}/{$filedir}";
|
||||
|
||||
// Make sure it's ready
|
||||
self::dirReady($targetpath);
|
||||
|
||||
$targetpath .= $filename;
|
||||
|
||||
// Check to see if source exist and if target doesn't
|
||||
if (!file_exists($sourcepath) || file_exists($targetpath)) {
|
||||
return; // Nothing to copy from or target already exists
|
||||
}
|
||||
|
||||
copy($sourcepath, $targetpath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a content from one directory to another. Defaults to cloning
|
||||
* content from the current temporary upload folder to the editor path.
|
||||
*
|
||||
* @param string $source path to source directory
|
||||
* @param string $contentId Id of contentarray
|
||||
*/
|
||||
public function moveContentDirectory($source, $contentId = NULL) {
|
||||
if ($source === NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO: Remove $contentId and never copy temporary files into content folder. JI-366
|
||||
if ($contentId === NULL || $contentId == 0) {
|
||||
$target = $this->getEditorPath();
|
||||
}
|
||||
else {
|
||||
// Use content folder
|
||||
$target = "{$this->path}/content/{$contentId}";
|
||||
}
|
||||
|
||||
$contentSource = $source . '/' . 'content';
|
||||
$contentFiles = array_diff(scandir($contentSource), array('.','..', 'content.json'));
|
||||
foreach ($contentFiles as $file) {
|
||||
if (is_dir("{$contentSource}/{$file}")) {
|
||||
self::copyFileTree("{$contentSource}/{$file}", "{$target}/{$file}");
|
||||
}
|
||||
else {
|
||||
copy("{$contentSource}/{$file}", "{$target}/{$file}");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Return list of all files so that they can be marked as temporary. JI-366
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if content has the given file.
|
||||
* Used when saving content.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param int $contentId
|
||||
* @return string File ID or NULL if not found
|
||||
*/
|
||||
public function getContentFile($file, $contentId) {
|
||||
$path = "{$this->path}/content/{$contentId}/{$file}";
|
||||
return file_exists($path) ? $path : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if content has the given file.
|
||||
* Used when saving content.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param int $contentid
|
||||
* @return string|int File ID or NULL if not found
|
||||
*/
|
||||
public function removeContentFile($file, $contentId) {
|
||||
$path = "{$this->path}/content/{$contentId}/{$file}";
|
||||
if (file_exists($path)) {
|
||||
unlink($path);
|
||||
|
||||
// Clean up any empty parent directories to avoid cluttering the file system
|
||||
$parts = explode('/', $path);
|
||||
while (array_pop($parts) !== NULL) {
|
||||
$dir = implode('/', $parts);
|
||||
if (is_dir($dir) && count(scandir($dir)) === 2) { // empty contains '.' and '..'
|
||||
rmdir($dir); // Remove empty parent
|
||||
}
|
||||
else {
|
||||
return; // Not empty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if server setup has write permission to
|
||||
* the required folders
|
||||
*
|
||||
* @return bool True if site can write to the H5P files folder
|
||||
*/
|
||||
public function hasWriteAccess() {
|
||||
return self::dirReady($this->path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the file presave.js exists in the root of the library
|
||||
*
|
||||
* @param string $libraryFolder
|
||||
* @param string $developmentPath
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPresave($libraryFolder, $developmentPath = null) {
|
||||
$path = is_null($developmentPath) ? 'libraries' . '/' . $libraryFolder : $developmentPath;
|
||||
$filePath = realpath($this->path . '/' . $path . '/' . 'presave.js');
|
||||
return file_exists($filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if upgrades script exist for library.
|
||||
*
|
||||
* @param string $machineName
|
||||
* @param int $majorVersion
|
||||
* @param int $minorVersion
|
||||
* @return string Relative path
|
||||
*/
|
||||
public function getUpgradeScript($machineName, $majorVersion, $minorVersion) {
|
||||
$upgrades = "/libraries/{$machineName}-{$majorVersion}.{$minorVersion}/upgrades.js";
|
||||
if (file_exists($this->path . $upgrades)) {
|
||||
return $upgrades;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the given stream into the given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @param resource $stream
|
||||
* @return bool
|
||||
*/
|
||||
public function saveFileFromZip($path, $file, $stream) {
|
||||
$filePath = $path . '/' . $file;
|
||||
|
||||
// Make sure the directory exists first
|
||||
$matches = array();
|
||||
preg_match('/(.+)\/[^\/]*$/', $filePath, $matches);
|
||||
self::dirReady($matches[1]);
|
||||
|
||||
// Store in local storage folder
|
||||
return file_put_contents($filePath, $stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive function for copying directories.
|
||||
*
|
||||
* @param string $source
|
||||
* From path
|
||||
* @param string $destination
|
||||
* To path
|
||||
* @return boolean
|
||||
* Indicates if the directory existed.
|
||||
*
|
||||
* @throws Exception Unable to copy the file
|
||||
*/
|
||||
private static function copyFileTree($source, $destination) {
|
||||
if (!self::dirReady($destination)) {
|
||||
throw new \Exception('unabletocopy');
|
||||
}
|
||||
|
||||
$ignoredFiles = self::getIgnoredFiles("{$source}/.h5pignore");
|
||||
|
||||
$dir = opendir($source);
|
||||
if ($dir === FALSE) {
|
||||
trigger_error('Unable to open directory ' . $source, E_USER_WARNING);
|
||||
throw new \Exception('unabletocopy');
|
||||
}
|
||||
|
||||
while (false !== ($file = readdir($dir))) {
|
||||
if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore' && !in_array($file, $ignoredFiles)) {
|
||||
if (is_dir("{$source}/{$file}")) {
|
||||
self::copyFileTree("{$source}/{$file}", "{$destination}/{$file}");
|
||||
}
|
||||
else {
|
||||
copy("{$source}/{$file}", "{$destination}/{$file}");
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve array of file names from file.
|
||||
*
|
||||
* @param string $file
|
||||
* @return array Array with files that should be ignored
|
||||
*/
|
||||
private static function getIgnoredFiles($file) {
|
||||
if (file_exists($file) === FALSE) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$contents = file_get_contents($file);
|
||||
if ($contents === FALSE) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return preg_split('/\s+/', $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive function that makes sure the specified directory exists and
|
||||
* is writable.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
private static function dirReady($path) {
|
||||
if (!file_exists($path)) {
|
||||
$parent = preg_replace("/\/[^\/]+\/?$/", '', $path);
|
||||
if (!self::dirReady($parent)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
mkdir($path, 0777, true);
|
||||
}
|
||||
|
||||
if (!is_dir($path)) {
|
||||
trigger_error('Path is not a directory ' . $path, E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!is_writable($path)) {
|
||||
trigger_error('Unable to write to ' . $path . ' – check directory permissions –', E_USER_WARNING);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Easy helper function for retrieving the editor path
|
||||
*
|
||||
* @return string Path to editor files
|
||||
*/
|
||||
private function getEditorPath() {
|
||||
return ($this->alteditorpath !== NULL ? $this->alteditorpath : "{$this->path}/editor");
|
||||
}
|
||||
}
|
189
lib/h5p/h5p-development.class.php
Normal file
189
lib/h5p/h5p-development.class.php
Normal file
@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This is a data layer which uses the file system so it isn't specific to any framework.
|
||||
*/
|
||||
class H5PDevelopment {
|
||||
|
||||
const MODE_NONE = 0;
|
||||
const MODE_CONTENT = 1;
|
||||
const MODE_LIBRARY = 2;
|
||||
|
||||
private $h5pF, $libraries, $language, $filesPath;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param H5PFrameworkInterface|object $H5PFramework
|
||||
* The frameworks implementation of the H5PFrameworkInterface
|
||||
* @param string $filesPath
|
||||
* Path to where H5P should store its files
|
||||
* @param $language
|
||||
* @param array $libraries Optional cache input.
|
||||
*/
|
||||
public function __construct(H5PFrameworkInterface $H5PFramework, $filesPath, $language, $libraries = NULL) {
|
||||
$this->h5pF = $H5PFramework;
|
||||
$this->language = $language;
|
||||
$this->filesPath = $filesPath;
|
||||
if ($libraries !== NULL) {
|
||||
$this->libraries = $libraries;
|
||||
}
|
||||
else {
|
||||
$this->findLibraries($filesPath . '/development');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contents of file.
|
||||
*
|
||||
* @param string $file File path.
|
||||
* @return mixed String on success or NULL on failure.
|
||||
*/
|
||||
private function getFileContents($file) {
|
||||
if (file_exists($file) === FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$contents = file_get_contents($file);
|
||||
if ($contents === FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans development directory and find all libraries.
|
||||
*
|
||||
* @param string $path Libraries development folder
|
||||
*/
|
||||
private function findLibraries($path) {
|
||||
$this->libraries = array();
|
||||
|
||||
if (is_dir($path) === FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$contents = scandir($path);
|
||||
|
||||
for ($i = 0, $s = count($contents); $i < $s; $i++) {
|
||||
if ($contents[$i]{0} === '.') {
|
||||
continue; // Skip hidden stuff.
|
||||
}
|
||||
|
||||
$libraryPath = $path . '/' . $contents[$i];
|
||||
$libraryJSON = $this->getFileContents($libraryPath . '/library.json');
|
||||
if ($libraryJSON === NULL) {
|
||||
continue; // No JSON file, skip.
|
||||
}
|
||||
|
||||
$library = json_decode($libraryJSON, TRUE);
|
||||
if ($library === NULL) {
|
||||
continue; // Invalid JSON.
|
||||
}
|
||||
|
||||
// TODO: Validate props? Not really needed, is it? this is a dev site.
|
||||
|
||||
$library['libraryId'] = $this->h5pF->getLibraryId($library['machineName'], $library['majorVersion'], $library['minorVersion']);
|
||||
|
||||
// Convert metadataSettings values to boolean & json_encode it before saving
|
||||
$library['metadataSettings'] = isset($library['metadataSettings']) ?
|
||||
H5PMetadata::boolifyAndEncodeSettings($library['metadataSettings']) :
|
||||
NULL;
|
||||
|
||||
// Save/update library.
|
||||
$this->h5pF->saveLibraryData($library, $library['libraryId'] === FALSE);
|
||||
|
||||
// Need to decode it again, since it is served from here.
|
||||
$library['metadataSettings'] = json_decode($library['metadataSettings']);
|
||||
|
||||
$library['path'] = 'development/' . $contents[$i];
|
||||
$this->libraries[H5PDevelopment::libraryToString($library['machineName'], $library['majorVersion'], $library['minorVersion'])] = $library;
|
||||
}
|
||||
|
||||
// TODO: Should we remove libraries without files? Not really needed, but must be cleaned up some time, right?
|
||||
|
||||
// Go trough libraries and insert dependencies. Missing deps. will just be ignored and not available. (I guess?!)
|
||||
$this->h5pF->lockDependencyStorage();
|
||||
foreach ($this->libraries as $library) {
|
||||
$this->h5pF->deleteLibraryDependencies($library['libraryId']);
|
||||
// This isn't optimal, but without it we would get duplicate warnings.
|
||||
// TODO: You might get PDOExceptions if two or more requests does this at the same time!!
|
||||
$types = array('preloaded', 'dynamic', 'editor');
|
||||
foreach ($types as $type) {
|
||||
if (isset($library[$type . 'Dependencies'])) {
|
||||
$this->h5pF->saveLibraryDependencies($library['libraryId'], $library[$type . 'Dependencies'], $type);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->h5pF->unlockDependencyStorage();
|
||||
// TODO: Deps must be inserted into h5p_nodes_libraries as well... ? But only if they are used?!
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array Libraries in development folder.
|
||||
*/
|
||||
public function getLibraries() {
|
||||
return $this->libraries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get library
|
||||
*
|
||||
* @param string $name of the library.
|
||||
* @param int $majorVersion of the library.
|
||||
* @param int $minorVersion of the library.
|
||||
* @return array library.
|
||||
*/
|
||||
public function getLibrary($name, $majorVersion, $minorVersion) {
|
||||
$library = H5PDevelopment::libraryToString($name, $majorVersion, $minorVersion);
|
||||
return isset($this->libraries[$library]) === TRUE ? $this->libraries[$library] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get semantics for the given library.
|
||||
*
|
||||
* @param string $name of the library.
|
||||
* @param int $majorVersion of the library.
|
||||
* @param int $minorVersion of the library.
|
||||
* @return string Semantics
|
||||
*/
|
||||
public function getSemantics($name, $majorVersion, $minorVersion) {
|
||||
$library = H5PDevelopment::libraryToString($name, $majorVersion, $minorVersion);
|
||||
if (isset($this->libraries[$library]) === FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
return $this->getFileContents($this->filesPath . $this->libraries[$library]['path'] . '/semantics.json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translations for the given library.
|
||||
*
|
||||
* @param string $name of the library.
|
||||
* @param int $majorVersion of the library.
|
||||
* @param int $minorVersion of the library.
|
||||
* @param $language
|
||||
* @return string Translation
|
||||
*/
|
||||
public function getLanguage($name, $majorVersion, $minorVersion, $language) {
|
||||
$library = H5PDevelopment::libraryToString($name, $majorVersion, $minorVersion);
|
||||
|
||||
if (isset($this->libraries[$library]) === FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $this->getFileContents($this->filesPath . $this->libraries[$library]['path'] . '/language/' . $language . '.json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes library as string on the form "name majorVersion.minorVersion"
|
||||
*
|
||||
* @param string $name Machine readable library name
|
||||
* @param integer $majorVersion
|
||||
* @param $minorVersion
|
||||
* @return string Library identifier.
|
||||
*/
|
||||
public static function libraryToString($name, $majorVersion, $minorVersion) {
|
||||
return $name . ' ' . $majorVersion . '.' . $minorVersion;
|
||||
}
|
||||
}
|
191
lib/h5p/h5p-event-base.class.php
Normal file
191
lib/h5p/h5p-event-base.class.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The base class for H5P events. Extend to track H5P events in your system.
|
||||
*
|
||||
* @package H5P
|
||||
* @copyright 2016 Joubel AS
|
||||
* @license MIT
|
||||
*/
|
||||
abstract class H5PEventBase {
|
||||
// Constants
|
||||
const LOG_NONE = 0;
|
||||
const LOG_ALL = 1;
|
||||
const LOG_ACTIONS = 2;
|
||||
|
||||
// Static options
|
||||
public static $log_level = self::LOG_ACTIONS;
|
||||
public static $log_time = 2592000; // 30 Days
|
||||
|
||||
// Protected variables
|
||||
protected $id, $type, $sub_type, $content_id, $content_title, $library_name, $library_version, $time;
|
||||
|
||||
/**
|
||||
* Adds event type, h5p library and timestamp to event before saving it.
|
||||
*
|
||||
* Common event types with sub type:
|
||||
* content, <none> – content view
|
||||
* embed – viewed through embed code
|
||||
* shortcode – viewed through internal shortcode
|
||||
* edit – opened in editor
|
||||
* delete – deleted
|
||||
* create – created through editor
|
||||
* create upload – created through upload
|
||||
* update – updated through editor
|
||||
* update upload – updated through upload
|
||||
* upgrade – upgraded
|
||||
*
|
||||
* results, <none> – view own results
|
||||
* content – view results for content
|
||||
* set – new results inserted or updated
|
||||
*
|
||||
* settings, <none> – settings page loaded
|
||||
*
|
||||
* library, <none> – loaded in editor
|
||||
* create – new library installed
|
||||
* update – old library updated
|
||||
*
|
||||
* @param string $type
|
||||
* Name of event type
|
||||
* @param string $sub_type
|
||||
* Name of event sub type
|
||||
* @param string $content_id
|
||||
* Identifier for content affected by the event
|
||||
* @param string $content_title
|
||||
* Content title (makes it easier to know which content was deleted etc.)
|
||||
* @param string $library_name
|
||||
* Name of the library affected by the event
|
||||
* @param string $library_version
|
||||
* Library version
|
||||
*/
|
||||
function __construct($type, $sub_type = NULL, $content_id = NULL, $content_title = NULL, $library_name = NULL, $library_version = NULL) {
|
||||
$this->type = $type;
|
||||
$this->sub_type = $sub_type;
|
||||
$this->content_id = $content_id;
|
||||
$this->content_title = $content_title;
|
||||
$this->library_name = $library_name;
|
||||
$this->library_version = $library_version;
|
||||
$this->time = time();
|
||||
|
||||
if (self::validLogLevel($type, $sub_type)) {
|
||||
$this->save();
|
||||
}
|
||||
if (self::validStats($type, $sub_type)) {
|
||||
$this->saveStats();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the event type should be saved/logged.
|
||||
*
|
||||
* @param string $type
|
||||
* Name of event type
|
||||
* @param string $sub_type
|
||||
* Name of event sub type
|
||||
* @return boolean
|
||||
*/
|
||||
private static function validLogLevel($type, $sub_type) {
|
||||
switch (self::$log_level) {
|
||||
default:
|
||||
case self::LOG_NONE:
|
||||
return FALSE;
|
||||
case self::LOG_ALL:
|
||||
return TRUE; // Log everything
|
||||
case self::LOG_ACTIONS:
|
||||
if (self::isAction($type, $sub_type)) {
|
||||
return TRUE; // Log actions
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the event should be included in the statistics counter.
|
||||
*
|
||||
* @param string $type
|
||||
* Name of event type
|
||||
* @param string $sub_type
|
||||
* Name of event sub type
|
||||
* @return boolean
|
||||
*/
|
||||
private static function validStats($type, $sub_type) {
|
||||
if ( ($type === 'content' && $sub_type === 'shortcode insert') || // Count number of shortcode inserts
|
||||
($type === 'library' && $sub_type === NULL) || // Count number of times library is loaded in editor
|
||||
($type === 'results' && $sub_type === 'content') ) { // Count number of times results page has been opened
|
||||
return TRUE;
|
||||
}
|
||||
elseif (self::isAction($type, $sub_type)) { // Count all actions
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if event type is an action.
|
||||
*
|
||||
* @param string $type
|
||||
* Name of event type
|
||||
* @param string $sub_type
|
||||
* Name of event sub type
|
||||
* @return boolean
|
||||
*/
|
||||
private static function isAction($type, $sub_type) {
|
||||
if ( ($type === 'content' && in_array($sub_type, array('create', 'create upload', 'update', 'update upload', 'upgrade', 'delete'))) ||
|
||||
($type === 'library' && in_array($sub_type, array('create', 'update'))) ) {
|
||||
return TRUE; // Log actions
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper which makes it easier for systems to save the data.
|
||||
* Add all relevant properties to a assoc. array.
|
||||
* There are no NULL values. Empty string or 0 is used instead.
|
||||
* Used by both Drupal and WordPress.
|
||||
*
|
||||
* @return array with keyed values
|
||||
*/
|
||||
protected function getDataArray() {
|
||||
return array(
|
||||
'created_at' => $this->time,
|
||||
'type' => $this->type,
|
||||
'sub_type' => empty($this->sub_type) ? '' : $this->sub_type,
|
||||
'content_id' => empty($this->content_id) ? 0 : $this->content_id,
|
||||
'content_title' => empty($this->content_title) ? '' : $this->content_title,
|
||||
'library_name' => empty($this->library_name) ? '' : $this->library_name,
|
||||
'library_version' => empty($this->library_version) ? '' : $this->library_version
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A helper which makes it easier for systems to save the data.
|
||||
* Used in WordPress.
|
||||
*
|
||||
* @return array with strings
|
||||
*/
|
||||
protected function getFormatArray() {
|
||||
return array(
|
||||
'%d',
|
||||
'%s',
|
||||
'%s',
|
||||
'%d',
|
||||
'%s',
|
||||
'%s',
|
||||
'%s'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the event data in the database.
|
||||
*
|
||||
* Must be overridden by plugin.
|
||||
*/
|
||||
abstract protected function save();
|
||||
|
||||
/**
|
||||
* Add current event data to statistics counter.
|
||||
*
|
||||
* Must be overridden by plugin.
|
||||
*/
|
||||
abstract protected function saveStats();
|
||||
}
|
222
lib/h5p/h5p-file-storage.interface.php
Normal file
222
lib/h5p/h5p-file-storage.interface.php
Normal file
@ -0,0 +1,222 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* File info?
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface needed to handle storage and export of H5P Content.
|
||||
*/
|
||||
interface H5PFileStorage {
|
||||
|
||||
/**
|
||||
* Store the library folder.
|
||||
*
|
||||
* @param array $library
|
||||
* Library properties
|
||||
*/
|
||||
public function saveLibrary($library);
|
||||
|
||||
/**
|
||||
* Store the content folder.
|
||||
*
|
||||
* @param string $source
|
||||
* Path on file system to content directory.
|
||||
* @param array $content
|
||||
* Content properties
|
||||
*/
|
||||
public function saveContent($source, $content);
|
||||
|
||||
/**
|
||||
* Remove content folder.
|
||||
*
|
||||
* @param array $content
|
||||
* Content properties
|
||||
*/
|
||||
public function deleteContent($content);
|
||||
|
||||
/**
|
||||
* Creates a stored copy of the content folder.
|
||||
*
|
||||
* @param string $id
|
||||
* Identifier of content to clone.
|
||||
* @param int $newId
|
||||
* The cloned content's identifier
|
||||
*/
|
||||
public function cloneContent($id, $newId);
|
||||
|
||||
/**
|
||||
* Get path to a new unique tmp folder.
|
||||
*
|
||||
* @return string
|
||||
* Path
|
||||
*/
|
||||
public function getTmpPath();
|
||||
|
||||
/**
|
||||
* Fetch content folder and save in target directory.
|
||||
*
|
||||
* @param int $id
|
||||
* Content identifier
|
||||
* @param string $target
|
||||
* Where the content folder will be saved
|
||||
*/
|
||||
public function exportContent($id, $target);
|
||||
|
||||
/**
|
||||
* Fetch library folder and save in target directory.
|
||||
*
|
||||
* @param array $library
|
||||
* Library properties
|
||||
* @param string $target
|
||||
* Where the library folder will be saved
|
||||
*/
|
||||
public function exportLibrary($library, $target);
|
||||
|
||||
/**
|
||||
* Save export in file system
|
||||
*
|
||||
* @param string $source
|
||||
* Path on file system to temporary export file.
|
||||
* @param string $filename
|
||||
* Name of export file.
|
||||
*/
|
||||
public function saveExport($source, $filename);
|
||||
|
||||
/**
|
||||
* Removes given export file
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public function deleteExport($filename);
|
||||
|
||||
/**
|
||||
* Check if the given export file exists
|
||||
*
|
||||
* @param string $filename
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasExport($filename);
|
||||
|
||||
/**
|
||||
* Will concatenate all JavaScrips and Stylesheets into two files in order
|
||||
* to improve page performance.
|
||||
*
|
||||
* @param array $files
|
||||
* A set of all the assets required for content to display
|
||||
* @param string $key
|
||||
* Hashed key for cached asset
|
||||
*/
|
||||
public function cacheAssets(&$files, $key);
|
||||
|
||||
/**
|
||||
* Will check if there are cache assets available for content.
|
||||
*
|
||||
* @param string $key
|
||||
* Hashed key for cached asset
|
||||
* @return array
|
||||
*/
|
||||
public function getCachedAssets($key);
|
||||
|
||||
/**
|
||||
* Remove the aggregated cache files.
|
||||
*
|
||||
* @param array $keys
|
||||
* The hash keys of removed files
|
||||
*/
|
||||
public function deleteCachedAssets($keys);
|
||||
|
||||
/**
|
||||
* Read file content of given file and then return it.
|
||||
*
|
||||
* @param string $file_path
|
||||
* @return string contents
|
||||
*/
|
||||
public function getContent($file_path);
|
||||
|
||||
/**
|
||||
* Save files uploaded through the editor.
|
||||
* The files must be marked as temporary until the content form is saved.
|
||||
*
|
||||
* @param \H5peditorFile $file
|
||||
* @param int $contentId
|
||||
*/
|
||||
public function saveFile($file, $contentId);
|
||||
|
||||
/**
|
||||
* Copy a file from another content or editor tmp dir.
|
||||
* Used when copy pasting content in H5P.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param string|int $fromId Content ID or 'editor' string
|
||||
* @param int $toId Target Content ID
|
||||
*/
|
||||
public function cloneContentFile($file, $fromId, $toId);
|
||||
|
||||
/**
|
||||
* Copy a content from one directory to another. Defaults to cloning
|
||||
* content from the current temporary upload folder to the editor path.
|
||||
*
|
||||
* @param string $source path to source directory
|
||||
* @param string $contentId Id of content
|
||||
*
|
||||
* @return object Object containing h5p json and content json data
|
||||
*/
|
||||
public function moveContentDirectory($source, $contentId = NULL);
|
||||
|
||||
/**
|
||||
* Checks to see if content has the given file.
|
||||
* Used when saving content.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param int $contentId
|
||||
* @return string|int File ID or NULL if not found
|
||||
*/
|
||||
public function getContentFile($file, $contentId);
|
||||
|
||||
/**
|
||||
* Remove content files that are no longer used.
|
||||
* Used when saving content.
|
||||
*
|
||||
* @param string $file path + name
|
||||
* @param int $contentId
|
||||
*/
|
||||
public function removeContentFile($file, $contentId);
|
||||
|
||||
/**
|
||||
* Check if server setup has write permission to
|
||||
* the required folders
|
||||
*
|
||||
* @return bool True if server has the proper write access
|
||||
*/
|
||||
public function hasWriteAccess();
|
||||
|
||||
/**
|
||||
* Check if the library has a presave.js in the root folder
|
||||
*
|
||||
* @param string $libraryName
|
||||
* @param string $developmentPath
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPresave($libraryName, $developmentPath = null);
|
||||
|
||||
/**
|
||||
* Check if upgrades script exist for library.
|
||||
*
|
||||
* @param string $machineName
|
||||
* @param int $majorVersion
|
||||
* @param int $minorVersion
|
||||
* @return string Relative path
|
||||
*/
|
||||
public function getUpgradeScript($machineName, $majorVersion, $minorVersion);
|
||||
|
||||
/**
|
||||
* Store the given stream into the given file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $file
|
||||
* @param resource $stream
|
||||
* @return bool
|
||||
*/
|
||||
public function saveFileFromZip($path, $file, $stream);
|
||||
}
|
151
lib/h5p/h5p-metadata.class.php
Normal file
151
lib/h5p/h5p-metadata.class.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* Utility class for handling metadata
|
||||
*/
|
||||
abstract class H5PMetadata {
|
||||
|
||||
private static $fields = array(
|
||||
'title' => array(
|
||||
'type' => 'text',
|
||||
'maxLength' => 255
|
||||
),
|
||||
'authors' => array(
|
||||
'type' => 'json'
|
||||
),
|
||||
'changes' => array(
|
||||
'type' => 'json'
|
||||
),
|
||||
'source' => array(
|
||||
'type' => 'text',
|
||||
'maxLength' => 255
|
||||
),
|
||||
'license' => array(
|
||||
'type' => 'text',
|
||||
'maxLength' => 32
|
||||
),
|
||||
'licenseVersion' => array(
|
||||
'type' => 'text',
|
||||
'maxLength' => 10
|
||||
),
|
||||
'licenseExtras' => array(
|
||||
'type' => 'text',
|
||||
'maxLength' => 5000
|
||||
),
|
||||
'authorComments' => array(
|
||||
'type' => 'text',
|
||||
'maxLength' => 5000
|
||||
),
|
||||
'yearFrom' => array(
|
||||
'type' => 'int'
|
||||
),
|
||||
'yearTo' => array(
|
||||
'type' => 'int'
|
||||
),
|
||||
'defaultLanguage' => array(
|
||||
'type' => 'text',
|
||||
'maxLength' => 32,
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* JSON encode metadata
|
||||
*
|
||||
* @param object $content
|
||||
* @return string
|
||||
*/
|
||||
public static function toJSON($content) {
|
||||
// Note: deliberatly creating JSON string "manually" to improve performance
|
||||
return
|
||||
'{"title":' . (isset($content->title) ? json_encode($content->title) : 'null') .
|
||||
',"authors":' . (isset($content->authors) ? $content->authors : 'null') .
|
||||
',"source":' . (isset($content->source) ? '"' . $content->source . '"' : 'null') .
|
||||
',"license":' . (isset($content->license) ? '"' . $content->license . '"' : 'null') .
|
||||
',"licenseVersion":' . (isset($content->license_version) ? '"' . $content->license_version . '"' : 'null') .
|
||||
',"licenseExtras":' . (isset($content->license_extras) ? json_encode($content->license_extras) : 'null') .
|
||||
',"yearFrom":' . (isset($content->year_from) ? $content->year_from : 'null') .
|
||||
',"yearTo":' . (isset($content->year_to) ? $content->year_to : 'null') .
|
||||
',"changes":' . (isset($content->changes) ? $content->changes : 'null') .
|
||||
',"defaultLanguage":' . (isset($content->default_language) ? '"' . $content->default_language . '"' : 'null') .
|
||||
',"authorComments":' . (isset($content->author_comments) ? json_encode($content->author_comments) : 'null') . '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the metadata into an associative array keyed by the property names
|
||||
* @param mixed $metadata Array or object containing metadata
|
||||
* @param bool $include_title
|
||||
* @param bool $include_missing For metadata fields not being set, skip 'em.
|
||||
* Relevant for content upgrade
|
||||
* @param array $types
|
||||
* @return array
|
||||
*/
|
||||
public static function toDBArray($metadata, $include_title = true, $include_missing = true, &$types = array()) {
|
||||
$fields = array();
|
||||
|
||||
if (!is_array($metadata)) {
|
||||
$metadata = (array) $metadata;
|
||||
}
|
||||
|
||||
foreach (self::$fields as $key => $config) {
|
||||
|
||||
// Ignore title?
|
||||
if ($key === 'title' && !$include_title) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$exists = array_key_exists($key, $metadata);
|
||||
|
||||
// Don't include missing fields
|
||||
if (!$include_missing && !$exists) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $exists ? $metadata[$key] : null;
|
||||
|
||||
// lowerCamelCase to snake_case
|
||||
$db_field_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $key));
|
||||
|
||||
switch ($config['type']) {
|
||||
case 'text':
|
||||
if ($value !== null && strlen($value) > $config['maxLength']) {
|
||||
$value = \core_text::substr($value, 0, $config['maxLength']);
|
||||
}
|
||||
$types[] = '%s';
|
||||
break;
|
||||
|
||||
case 'int':
|
||||
$value = ($value !== null) ? intval($value) : null;
|
||||
$types[] = '%d';
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
$value = ($value !== null) ? json_encode($value) : null;
|
||||
$types[] = '%s';
|
||||
break;
|
||||
}
|
||||
|
||||
$fields[$db_field_name] = $value;
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* The metadataSettings field in libraryJson uses 1 for true and 0 for false.
|
||||
* Here we are converting these to booleans, and also doing JSON encoding.
|
||||
* This is invoked before the library data is beeing inserted/updated to DB.
|
||||
*
|
||||
* @param array $metadataSettings
|
||||
* @return string
|
||||
*/
|
||||
public static function boolifyAndEncodeSettings($metadataSettings) {
|
||||
// Convert metadataSettings values to boolean
|
||||
if (isset($metadataSettings['disable'])) {
|
||||
$metadataSettings['disable'] = $metadataSettings['disable'] === 1;
|
||||
}
|
||||
if (isset($metadataSettings['disableExtraTitleField'])) {
|
||||
$metadataSettings['disableExtraTitleField'] = $metadataSettings['disableExtraTitleField'] === 1;
|
||||
}
|
||||
|
||||
return json_encode($metadataSettings);
|
||||
}
|
||||
}
|
4910
lib/h5p/h5p.classes.php
Normal file
4910
lib/h5p/h5p.classes.php
Normal file
File diff suppressed because it is too large
Load Diff
16
lib/h5p/images/h5p.svg
Normal file
16
lib/h5p/images/h5p.svg
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 345 150" enable-background="new 0 0 345 150" xml:space="preserve">
|
||||
<g>
|
||||
<path fill="#FFFFFF" d="M325.7,14.7C317.6,6.9,305.3,3,289,3h-43.5H234v31h-66l-5.4,22.2c4.5-2.1,10.9-4.2,15.3-5.3
|
||||
c4.4-1.1,8.8-0.9,13.1-0.9c14.6,0,26.5,4.5,35.6,13.3c9.1,8.8,13.6,20,13.6,33.4c0,9.4-2.3,18.5-7,27.2c-4.7,8.7-11.3,15.4-19.9,20
|
||||
c-3.1,1.6-6.5,3.1-10.2,4.1h42.4H259V95h25c18.2,0,31.7-4.2,40.6-12.5c8.9-8.3,13.3-19.9,13.3-34.6
|
||||
C337.9,33.6,333.8,22.5,325.7,14.7z M288.7,60.6c-3.5,3-9.6,4.4-18.3,4.4H259V33h13.2c8.4,0,14.2,1.5,17.2,4.7
|
||||
c3.1,3.2,4.6,6.9,4.6,11.5C294,53.9,292.2,57.6,288.7,60.6z"/>
|
||||
<path fill="#FFFFFF" d="M176.5,76.3c-7.9,0-14.7,4.6-18,11.2L119,81.9L136.8,3h-23.6H101v62H51V3H7v145h44V95h50v53h12.2h42
|
||||
c-6.7-2-12.5-4.6-17.2-8.1c-4.8-3.6-8.7-7.7-11.7-12.3c-3-4.6-5.3-9.7-7.3-16.5l39.6-5.7c3.3,6.6,10.1,11.1,17.9,11.1
|
||||
c11.1,0,20.1-9,20.1-20.1S187.5,76.3,176.5,76.3z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.2 KiB |
BIN
lib/h5p/images/throbber.gif
Normal file
BIN
lib/h5p/images/throbber.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
100
lib/h5p/js/h5p-action-bar.js
Normal file
100
lib/h5p/js/h5p-action-bar.js
Normal file
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* @class
|
||||
* @augments H5P.EventDispatcher
|
||||
* @param {Object} displayOptions
|
||||
* @param {boolean} displayOptions.export Triggers the display of the 'Download' button
|
||||
* @param {boolean} displayOptions.copyright Triggers the display of the 'Copyright' button
|
||||
* @param {boolean} displayOptions.embed Triggers the display of the 'Embed' button
|
||||
* @param {boolean} displayOptions.icon Triggers the display of the 'H5P icon' link
|
||||
*/
|
||||
H5P.ActionBar = (function ($, EventDispatcher) {
|
||||
"use strict";
|
||||
|
||||
function ActionBar(displayOptions) {
|
||||
EventDispatcher.call(this);
|
||||
|
||||
/** @alias H5P.ActionBar# */
|
||||
var self = this;
|
||||
|
||||
var hasActions = false;
|
||||
|
||||
// Create action bar
|
||||
var $actions = H5P.jQuery('<ul class="h5p-actions"></ul>');
|
||||
|
||||
/**
|
||||
* Helper for creating action bar buttons.
|
||||
*
|
||||
* @private
|
||||
* @param {string} type
|
||||
* @param {string} customClass Instead of type class
|
||||
*/
|
||||
var addActionButton = function (type, customClass) {
|
||||
/**
|
||||
* Handles selection of action
|
||||
*/
|
||||
var handler = function () {
|
||||
self.trigger(type);
|
||||
};
|
||||
H5P.jQuery('<li/>', {
|
||||
'class': 'h5p-button h5p-noselect h5p-' + (customClass ? customClass : type),
|
||||
role: 'button',
|
||||
tabindex: 0,
|
||||
title: H5P.t(type + 'Description'),
|
||||
html: H5P.t(type),
|
||||
on: {
|
||||
click: handler,
|
||||
keypress: function (e) {
|
||||
if (e.which === 32) {
|
||||
handler();
|
||||
e.preventDefault(); // (since return false will block other inputs)
|
||||
}
|
||||
}
|
||||
},
|
||||
appendTo: $actions
|
||||
});
|
||||
|
||||
hasActions = true;
|
||||
};
|
||||
|
||||
// Register action bar buttons
|
||||
if (displayOptions.export || displayOptions.copy) {
|
||||
// Add export button
|
||||
addActionButton('reuse', 'export');
|
||||
}
|
||||
if (displayOptions.copyright) {
|
||||
addActionButton('copyrights');
|
||||
}
|
||||
if (displayOptions.embed) {
|
||||
addActionButton('embed');
|
||||
}
|
||||
if (displayOptions.icon) {
|
||||
// Add about H5P button icon
|
||||
H5P.jQuery('<li><a class="h5p-link" href="http://h5p.org" target="_blank" title="' + H5P.t('h5pDescription') + '"></a></li>').appendTo($actions);
|
||||
hasActions = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the dom element
|
||||
*
|
||||
* @return {H5P.jQuery}
|
||||
*/
|
||||
self.getDOMElement = function () {
|
||||
return $actions;
|
||||
};
|
||||
|
||||
/**
|
||||
* Does the actionbar contain actions?
|
||||
*
|
||||
* @return {Boolean}
|
||||
*/
|
||||
self.hasActions = function () {
|
||||
return hasActions;
|
||||
};
|
||||
}
|
||||
|
||||
ActionBar.prototype = Object.create(EventDispatcher.prototype);
|
||||
ActionBar.prototype.constructor = ActionBar;
|
||||
|
||||
return ActionBar;
|
||||
|
||||
})(H5P.jQuery, H5P.EventDispatcher);
|
410
lib/h5p/js/h5p-confirmation-dialog.js
Normal file
410
lib/h5p/js/h5p-confirmation-dialog.js
Normal file
@ -0,0 +1,410 @@
|
||||
/*global H5P*/
|
||||
H5P.ConfirmationDialog = (function (EventDispatcher) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Create a confirmation dialog
|
||||
*
|
||||
* @param [options] Options for confirmation dialog
|
||||
* @param [options.instance] Instance that uses confirmation dialog
|
||||
* @param [options.headerText] Header text
|
||||
* @param [options.dialogText] Dialog text
|
||||
* @param [options.cancelText] Cancel dialog button text
|
||||
* @param [options.confirmText] Confirm dialog button text
|
||||
* @param [options.hideCancel] Hide cancel button
|
||||
* @param [options.hideExit] Hide exit button
|
||||
* @param [options.skipRestoreFocus] Skip restoring focus when hiding the dialog
|
||||
* @param [options.classes] Extra classes for popup
|
||||
* @constructor
|
||||
*/
|
||||
function ConfirmationDialog(options) {
|
||||
EventDispatcher.call(this);
|
||||
var self = this;
|
||||
|
||||
// Make sure confirmation dialogs have unique id
|
||||
H5P.ConfirmationDialog.uniqueId += 1;
|
||||
var uniqueId = H5P.ConfirmationDialog.uniqueId;
|
||||
|
||||
// Default options
|
||||
options = options || {};
|
||||
options.headerText = options.headerText || H5P.t('confirmDialogHeader');
|
||||
options.dialogText = options.dialogText || H5P.t('confirmDialogBody');
|
||||
options.cancelText = options.cancelText || H5P.t('cancelLabel');
|
||||
options.confirmText = options.confirmText || H5P.t('confirmLabel');
|
||||
|
||||
/**
|
||||
* Handle confirming event
|
||||
* @param {Event} e
|
||||
*/
|
||||
function dialogConfirmed(e) {
|
||||
self.hide();
|
||||
self.trigger('confirmed');
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dialog canceled
|
||||
* @param {Event} e
|
||||
*/
|
||||
function dialogCanceled(e) {
|
||||
self.hide();
|
||||
self.trigger('canceled');
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flow focus to element
|
||||
* @param {HTMLElement} element Next element to be focused
|
||||
* @param {Event} e Original tab event
|
||||
*/
|
||||
function flowTo(element, e) {
|
||||
element.focus();
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
// Offset of exit button
|
||||
var exitButtonOffset = 2 * 16;
|
||||
var shadowOffset = 8;
|
||||
|
||||
// Determine if we are too large for our container and must resize
|
||||
var resizeIFrame = false;
|
||||
|
||||
// Create background
|
||||
var popupBackground = document.createElement('div');
|
||||
popupBackground.classList
|
||||
.add('h5p-confirmation-dialog-background', 'hidden', 'hiding');
|
||||
|
||||
// Create outer popup
|
||||
var popup = document.createElement('div');
|
||||
popup.classList.add('h5p-confirmation-dialog-popup', 'hidden');
|
||||
if (options.classes) {
|
||||
options.classes.forEach(function (popupClass) {
|
||||
popup.classList.add(popupClass);
|
||||
});
|
||||
}
|
||||
|
||||
popup.setAttribute('role', 'dialog');
|
||||
popup.setAttribute('aria-labelledby', 'h5p-confirmation-dialog-dialog-text-' + uniqueId);
|
||||
popupBackground.appendChild(popup);
|
||||
popup.addEventListener('keydown', function (e) {
|
||||
if (e.which === 27) {// Esc key
|
||||
// Exit dialog
|
||||
dialogCanceled(e);
|
||||
}
|
||||
});
|
||||
|
||||
// Popup header
|
||||
var header = document.createElement('div');
|
||||
header.classList.add('h5p-confirmation-dialog-header');
|
||||
popup.appendChild(header);
|
||||
|
||||
// Header text
|
||||
var headerText = document.createElement('div');
|
||||
headerText.classList.add('h5p-confirmation-dialog-header-text');
|
||||
headerText.innerHTML = options.headerText;
|
||||
header.appendChild(headerText);
|
||||
|
||||
// Popup body
|
||||
var body = document.createElement('div');
|
||||
body.classList.add('h5p-confirmation-dialog-body');
|
||||
popup.appendChild(body);
|
||||
|
||||
// Popup text
|
||||
var text = document.createElement('div');
|
||||
text.classList.add('h5p-confirmation-dialog-text');
|
||||
text.innerHTML = options.dialogText;
|
||||
text.id = 'h5p-confirmation-dialog-dialog-text-' + uniqueId;
|
||||
body.appendChild(text);
|
||||
|
||||
// Popup buttons
|
||||
var buttons = document.createElement('div');
|
||||
buttons.classList.add('h5p-confirmation-dialog-buttons');
|
||||
body.appendChild(buttons);
|
||||
|
||||
// Cancel button
|
||||
var cancelButton = document.createElement('button');
|
||||
cancelButton.classList.add('h5p-core-cancel-button');
|
||||
cancelButton.textContent = options.cancelText;
|
||||
|
||||
// Confirm button
|
||||
var confirmButton = document.createElement('button');
|
||||
confirmButton.classList.add('h5p-core-button');
|
||||
confirmButton.classList.add('h5p-confirmation-dialog-confirm-button');
|
||||
confirmButton.textContent = options.confirmText;
|
||||
|
||||
// Exit button
|
||||
var exitButton = document.createElement('button');
|
||||
exitButton.classList.add('h5p-confirmation-dialog-exit');
|
||||
exitButton.setAttribute('aria-hidden', 'true');
|
||||
exitButton.tabIndex = -1;
|
||||
exitButton.title = options.cancelText;
|
||||
|
||||
// Cancel handler
|
||||
cancelButton.addEventListener('click', dialogCanceled);
|
||||
cancelButton.addEventListener('keydown', function (e) {
|
||||
if (e.which === 32) { // Space
|
||||
dialogCanceled(e);
|
||||
}
|
||||
else if (e.which === 9 && e.shiftKey) { // Shift-tab
|
||||
flowTo(confirmButton, e);
|
||||
}
|
||||
});
|
||||
|
||||
if (!options.hideCancel) {
|
||||
buttons.appendChild(cancelButton);
|
||||
}
|
||||
else {
|
||||
// Center buttons
|
||||
buttons.classList.add('center');
|
||||
}
|
||||
|
||||
// Confirm handler
|
||||
confirmButton.addEventListener('click', dialogConfirmed);
|
||||
confirmButton.addEventListener('keydown', function (e) {
|
||||
if (e.which === 32) { // Space
|
||||
dialogConfirmed(e);
|
||||
}
|
||||
else if (e.which === 9 && !e.shiftKey) { // Tab
|
||||
const nextButton = !options.hideCancel ? cancelButton : confirmButton;
|
||||
flowTo(nextButton, e);
|
||||
}
|
||||
});
|
||||
buttons.appendChild(confirmButton);
|
||||
|
||||
// Exit handler
|
||||
exitButton.addEventListener('click', dialogCanceled);
|
||||
exitButton.addEventListener('keydown', function (e) {
|
||||
if (e.which === 32) { // Space
|
||||
dialogCanceled(e);
|
||||
}
|
||||
});
|
||||
if (!options.hideExit) {
|
||||
popup.appendChild(exitButton);
|
||||
}
|
||||
|
||||
// Wrapper element
|
||||
var wrapperElement;
|
||||
|
||||
// Focus capturing
|
||||
var focusPredator;
|
||||
|
||||
// Maintains hidden state of elements
|
||||
var wrapperSiblingsHidden = [];
|
||||
var popupSiblingsHidden = [];
|
||||
|
||||
// Element with focus before dialog
|
||||
var previouslyFocused;
|
||||
|
||||
/**
|
||||
* Set parent of confirmation dialog
|
||||
* @param {HTMLElement} wrapper
|
||||
* @returns {H5P.ConfirmationDialog}
|
||||
*/
|
||||
this.appendTo = function (wrapper) {
|
||||
wrapperElement = wrapper;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Capture the focus element, send it to confirmation button
|
||||
* @param {Event} e Original focus event
|
||||
*/
|
||||
var captureFocus = function (e) {
|
||||
if (!popupBackground.contains(e.target)) {
|
||||
e.preventDefault();
|
||||
confirmButton.focus();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide siblings of element from assistive technology
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* @returns {Array} The previous hidden state of all siblings
|
||||
*/
|
||||
var hideSiblings = function (element) {
|
||||
var hiddenSiblings = [];
|
||||
var siblings = element.parentNode.children;
|
||||
var i;
|
||||
for (i = 0; i < siblings.length; i += 1) {
|
||||
// Preserve hidden state
|
||||
hiddenSiblings[i] = siblings[i].getAttribute('aria-hidden') ?
|
||||
true : false;
|
||||
|
||||
if (siblings[i] !== element) {
|
||||
siblings[i].setAttribute('aria-hidden', true);
|
||||
}
|
||||
}
|
||||
return hiddenSiblings;
|
||||
};
|
||||
|
||||
/**
|
||||
* Restores assistive technology state of element's siblings
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* @param {Array} hiddenSiblings Hidden state of all siblings
|
||||
*/
|
||||
var restoreSiblings = function (element, hiddenSiblings) {
|
||||
var siblings = element.parentNode.children;
|
||||
var i;
|
||||
for (i = 0; i < siblings.length; i += 1) {
|
||||
if (siblings[i] !== element && !hiddenSiblings[i]) {
|
||||
siblings[i].removeAttribute('aria-hidden');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Start capturing focus of parent and send it to dialog
|
||||
*/
|
||||
var startCapturingFocus = function () {
|
||||
focusPredator = wrapperElement.parentNode || wrapperElement;
|
||||
focusPredator.addEventListener('focus', captureFocus, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up event listener for capturing focus
|
||||
*/
|
||||
var stopCapturingFocus = function () {
|
||||
focusPredator.removeAttribute('aria-hidden');
|
||||
focusPredator.removeEventListener('focus', captureFocus, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide siblings in underlay from assistive technologies
|
||||
*/
|
||||
var disableUnderlay = function () {
|
||||
wrapperSiblingsHidden = hideSiblings(wrapperElement);
|
||||
popupSiblingsHidden = hideSiblings(popupBackground);
|
||||
};
|
||||
|
||||
/**
|
||||
* Restore state of underlay for assistive technologies
|
||||
*/
|
||||
var restoreUnderlay = function () {
|
||||
restoreSiblings(wrapperElement, wrapperSiblingsHidden);
|
||||
restoreSiblings(popupBackground, popupSiblingsHidden);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fit popup to container. Makes sure it doesn't overflow.
|
||||
* @params {number} [offsetTop] Offset of popup
|
||||
*/
|
||||
var fitToContainer = function (offsetTop) {
|
||||
var popupOffsetTop = parseInt(popup.style.top, 10);
|
||||
if (offsetTop !== undefined) {
|
||||
popupOffsetTop = offsetTop;
|
||||
}
|
||||
|
||||
if (!popupOffsetTop) {
|
||||
popupOffsetTop = 0;
|
||||
}
|
||||
|
||||
// Overflows height
|
||||
if (popupOffsetTop + popup.offsetHeight > wrapperElement.offsetHeight) {
|
||||
popupOffsetTop = wrapperElement.offsetHeight - popup.offsetHeight - shadowOffset;
|
||||
}
|
||||
|
||||
if (popupOffsetTop - exitButtonOffset <= 0) {
|
||||
popupOffsetTop = exitButtonOffset + shadowOffset;
|
||||
|
||||
// We are too big and must resize
|
||||
resizeIFrame = true;
|
||||
}
|
||||
popup.style.top = popupOffsetTop + 'px';
|
||||
};
|
||||
|
||||
/**
|
||||
* Show confirmation dialog
|
||||
* @params {number} offsetTop Offset top
|
||||
* @returns {H5P.ConfirmationDialog}
|
||||
*/
|
||||
this.show = function (offsetTop) {
|
||||
// Capture focused item
|
||||
previouslyFocused = document.activeElement;
|
||||
wrapperElement.appendChild(popupBackground);
|
||||
startCapturingFocus();
|
||||
disableUnderlay();
|
||||
popupBackground.classList.remove('hidden');
|
||||
fitToContainer(offsetTop);
|
||||
setTimeout(function () {
|
||||
popup.classList.remove('hidden');
|
||||
popupBackground.classList.remove('hiding');
|
||||
|
||||
setTimeout(function () {
|
||||
// Focus confirm button
|
||||
confirmButton.focus();
|
||||
|
||||
// Resize iFrame if necessary
|
||||
if (resizeIFrame && options.instance) {
|
||||
var minHeight = parseInt(popup.offsetHeight, 10) +
|
||||
exitButtonOffset + (2 * shadowOffset);
|
||||
self.setViewPortMinimumHeight(minHeight);
|
||||
options.instance.trigger('resize');
|
||||
resizeIFrame = false;
|
||||
}
|
||||
}, 100);
|
||||
}, 0);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide confirmation dialog
|
||||
* @returns {H5P.ConfirmationDialog}
|
||||
*/
|
||||
this.hide = function () {
|
||||
popupBackground.classList.add('hiding');
|
||||
popup.classList.add('hidden');
|
||||
|
||||
// Restore focus
|
||||
stopCapturingFocus();
|
||||
if (!options.skipRestoreFocus) {
|
||||
previouslyFocused.focus();
|
||||
}
|
||||
restoreUnderlay();
|
||||
setTimeout(function () {
|
||||
popupBackground.classList.add('hidden');
|
||||
wrapperElement.removeChild(popupBackground);
|
||||
self.setViewPortMinimumHeight(null);
|
||||
}, 100);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve element
|
||||
*
|
||||
* @return {HTMLElement}
|
||||
*/
|
||||
this.getElement = function () {
|
||||
return popup;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get previously focused element
|
||||
* @return {HTMLElement}
|
||||
*/
|
||||
this.getPreviouslyFocused = function () {
|
||||
return previouslyFocused;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the minimum height of the view port
|
||||
*
|
||||
* @param {number|null} minHeight
|
||||
*/
|
||||
this.setViewPortMinimumHeight = function (minHeight) {
|
||||
var container = document.querySelector('.h5p-container') || document.body;
|
||||
container.style.minHeight = (typeof minHeight === 'number') ? (minHeight + 'px') : minHeight;
|
||||
};
|
||||
}
|
||||
|
||||
ConfirmationDialog.prototype = Object.create(EventDispatcher.prototype);
|
||||
ConfirmationDialog.prototype.constructor = ConfirmationDialog;
|
||||
|
||||
return ConfirmationDialog;
|
||||
|
||||
}(H5P.EventDispatcher));
|
||||
|
||||
H5P.ConfirmationDialog.uniqueId = -1;
|
41
lib/h5p/js/h5p-content-type.js
Normal file
41
lib/h5p/js/h5p-content-type.js
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* H5P.ContentType is a base class for all content types. Used by newRunnable()
|
||||
*
|
||||
* Functions here may be overridable by the libraries. In special cases,
|
||||
* it is also possible to override H5P.ContentType on a global level.
|
||||
*
|
||||
* NOTE that this doesn't actually 'extend' the event dispatcher but instead
|
||||
* it creates a single instance which all content types shares as their base
|
||||
* prototype. (in some cases this may be the root of strange event behavior)
|
||||
*
|
||||
* @class
|
||||
* @augments H5P.EventDispatcher
|
||||
*/
|
||||
H5P.ContentType = function (isRootLibrary) {
|
||||
|
||||
function ContentType() {}
|
||||
|
||||
// Inherit from EventDispatcher.
|
||||
ContentType.prototype = new H5P.EventDispatcher();
|
||||
|
||||
/**
|
||||
* Is library standalone or not? Not beeing standalone, means it is
|
||||
* included in another library
|
||||
*
|
||||
* @return {Boolean}
|
||||
*/
|
||||
ContentType.prototype.isRoot = function () {
|
||||
return isRootLibrary;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the file path of a file in the current library
|
||||
* @param {string} filePath The path to the file relative to the library folder
|
||||
* @return {string} The full path to the file
|
||||
*/
|
||||
ContentType.prototype.getLibraryFilePath = function (filePath) {
|
||||
return H5P.getLibraryPath(this.libraryInfo.versionedNameNoSpaces) + '/' + filePath;
|
||||
};
|
||||
|
||||
return ContentType;
|
||||
};
|
313
lib/h5p/js/h5p-content-upgrade-process.js
Normal file
313
lib/h5p/js/h5p-content-upgrade-process.js
Normal file
@ -0,0 +1,313 @@
|
||||
/*jshint -W083 */
|
||||
var H5PUpgrades = H5PUpgrades || {};
|
||||
|
||||
H5P.ContentUpgradeProcess = (function (Version) {
|
||||
|
||||
/**
|
||||
* @class
|
||||
* @namespace H5P
|
||||
*/
|
||||
function ContentUpgradeProcess(name, oldVersion, newVersion, params, id, loadLibrary, done) {
|
||||
var self = this;
|
||||
|
||||
// Make params possible to work with
|
||||
try {
|
||||
params = JSON.parse(params);
|
||||
if (!(params instanceof Object)) {
|
||||
throw true;
|
||||
}
|
||||
}
|
||||
catch (event) {
|
||||
return done({
|
||||
type: 'errorParamsBroken',
|
||||
id: id
|
||||
});
|
||||
}
|
||||
|
||||
self.loadLibrary = loadLibrary;
|
||||
self.upgrade(name, oldVersion, newVersion, params.params, params.metadata, function (err, upgradedParams, upgradedMetadata) {
|
||||
if (err) {
|
||||
err.id = id;
|
||||
return done(err);
|
||||
}
|
||||
|
||||
done(null, JSON.stringify({params: upgradedParams, metadata: upgradedMetadata}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Run content upgrade.
|
||||
*
|
||||
* @public
|
||||
* @param {string} name
|
||||
* @param {Version} oldVersion
|
||||
* @param {Version} newVersion
|
||||
* @param {Object} params
|
||||
* @param {Object} metadata
|
||||
* @param {Function} done
|
||||
*/
|
||||
ContentUpgradeProcess.prototype.upgrade = function (name, oldVersion, newVersion, params, metadata, done) {
|
||||
var self = this;
|
||||
|
||||
// Load library details and upgrade routines
|
||||
self.loadLibrary(name, newVersion, function (err, library) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
if (library.semantics === null) {
|
||||
return done({
|
||||
type: 'libraryMissing',
|
||||
library: library.name + ' ' + library.version.major + '.' + library.version.minor
|
||||
});
|
||||
}
|
||||
|
||||
// Run upgrade routines on params
|
||||
self.processParams(library, oldVersion, newVersion, params, metadata, function (err, params, metadata) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
// Check if any of the sub-libraries need upgrading
|
||||
asyncSerial(library.semantics, function (index, field, next) {
|
||||
self.processField(field, params[field.name], function (err, upgradedParams) {
|
||||
if (upgradedParams) {
|
||||
params[field.name] = upgradedParams;
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
}, function (err) {
|
||||
done(err, params, metadata);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Run upgrade hooks on params.
|
||||
*
|
||||
* @public
|
||||
* @param {Object} library
|
||||
* @param {Version} oldVersion
|
||||
* @param {Version} newVersion
|
||||
* @param {Object} params
|
||||
* @param {Function} next
|
||||
*/
|
||||
ContentUpgradeProcess.prototype.processParams = function (library, oldVersion, newVersion, params, metadata, next) {
|
||||
if (H5PUpgrades[library.name] === undefined) {
|
||||
if (library.upgradesScript) {
|
||||
// Upgrades script should be loaded so the upgrades should be here.
|
||||
return next({
|
||||
type: 'scriptMissing',
|
||||
library: library.name + ' ' + newVersion
|
||||
});
|
||||
}
|
||||
|
||||
// No upgrades script. Move on
|
||||
return next(null, params, metadata);
|
||||
}
|
||||
|
||||
// Run upgrade hooks. Start by going through major versions
|
||||
asyncSerial(H5PUpgrades[library.name], function (major, minors, nextMajor) {
|
||||
if (major < oldVersion.major || major > newVersion.major) {
|
||||
// Older than the current version or newer than the selected
|
||||
nextMajor();
|
||||
}
|
||||
else {
|
||||
// Go through the minor versions for this major version
|
||||
asyncSerial(minors, function (minor, upgrade, nextMinor) {
|
||||
minor =+ minor;
|
||||
if (minor <= oldVersion.minor || minor > newVersion.minor) {
|
||||
// Older than or equal to the current version or newer than the selected
|
||||
nextMinor();
|
||||
}
|
||||
else {
|
||||
// We found an upgrade hook, run it
|
||||
var unnecessaryWrapper = (upgrade.contentUpgrade !== undefined ? upgrade.contentUpgrade : upgrade);
|
||||
|
||||
try {
|
||||
unnecessaryWrapper(params, function (err, upgradedParams, upgradedExtras) {
|
||||
params = upgradedParams;
|
||||
if (upgradedExtras && upgradedExtras.metadata) { // Optional
|
||||
metadata = upgradedExtras.metadata;
|
||||
}
|
||||
nextMinor(err);
|
||||
}, {metadata: metadata});
|
||||
}
|
||||
catch (err) {
|
||||
if (console && console.error) {
|
||||
console.error("Error", err.stack);
|
||||
console.error("Error", err.name);
|
||||
console.error("Error", err.message);
|
||||
}
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
}, nextMajor);
|
||||
}
|
||||
}, function (err) {
|
||||
next(err, params, metadata);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Process parameter fields to find and upgrade sub-libraries.
|
||||
*
|
||||
* @public
|
||||
* @param {Object} field
|
||||
* @param {Object} params
|
||||
* @param {Function} done
|
||||
*/
|
||||
ContentUpgradeProcess.prototype.processField = function (field, params, done) {
|
||||
var self = this;
|
||||
|
||||
if (params === undefined) {
|
||||
return done();
|
||||
}
|
||||
|
||||
switch (field.type) {
|
||||
case 'library':
|
||||
if (params.library === undefined || params.params === undefined) {
|
||||
return done();
|
||||
}
|
||||
|
||||
// Look for available upgrades
|
||||
var usedLib = params.library.split(' ', 2);
|
||||
for (var i = 0; i < field.options.length; i++) {
|
||||
var availableLib = (typeof field.options[i] === 'string') ? field.options[i].split(' ', 2) : field.options[i].name.split(' ', 2);
|
||||
if (availableLib[0] === usedLib[0]) {
|
||||
if (availableLib[1] === usedLib[1]) {
|
||||
return done(); // Same version
|
||||
}
|
||||
|
||||
// We have different versions
|
||||
var usedVer = new Version(usedLib[1]);
|
||||
var availableVer = new Version(availableLib[1]);
|
||||
if (usedVer.major > availableVer.major || (usedVer.major === availableVer.major && usedVer.minor >= availableVer.minor)) {
|
||||
return done({
|
||||
type: 'errorTooHighVersion',
|
||||
used: usedLib[0] + ' ' + usedVer,
|
||||
supported: availableLib[0] + ' ' + availableVer
|
||||
}); // Larger or same version that's available
|
||||
}
|
||||
|
||||
// A newer version is available, upgrade params
|
||||
return self.upgrade(availableLib[0], usedVer, availableVer, params.params, params.metadata, function (err, upgradedParams, upgradedMetadata) {
|
||||
if (!err) {
|
||||
params.library = availableLib[0] + ' ' + availableVer.major + '.' + availableVer.minor;
|
||||
params.params = upgradedParams;
|
||||
if (upgradedMetadata) {
|
||||
params.metadata = upgradedMetadata;
|
||||
}
|
||||
}
|
||||
done(err, params);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Content type was not supporte by the higher version
|
||||
done({
|
||||
type: 'errorNotSupported',
|
||||
used: usedLib[0] + ' ' + usedVer
|
||||
});
|
||||
break;
|
||||
|
||||
case 'group':
|
||||
if (field.fields.length === 1 && field.isSubContent !== true) {
|
||||
// Single field to process, wrapper will be skipped
|
||||
self.processField(field.fields[0], params, function (err, upgradedParams) {
|
||||
if (upgradedParams) {
|
||||
params = upgradedParams;
|
||||
}
|
||||
done(err, params);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Go through all fields in the group
|
||||
asyncSerial(field.fields, function (index, subField, next) {
|
||||
var paramsToProcess = params ? params[subField.name] : null;
|
||||
self.processField(subField, paramsToProcess, function (err, upgradedParams) {
|
||||
if (upgradedParams) {
|
||||
params[subField.name] = upgradedParams;
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
|
||||
}, function (err) {
|
||||
done(err, params);
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case 'list':
|
||||
// Go trough all params in the list
|
||||
asyncSerial(params, function (index, subParams, next) {
|
||||
self.processField(field.field, subParams, function (err, upgradedParams) {
|
||||
if (upgradedParams) {
|
||||
params[index] = upgradedParams;
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
}, function (err) {
|
||||
done(err, params);
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Helps process each property on the given object asynchronously in serial order.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} obj
|
||||
* @param {Function} process
|
||||
* @param {Function} finished
|
||||
*/
|
||||
var asyncSerial = function (obj, process, finished) {
|
||||
var id, isArray = obj instanceof Array;
|
||||
|
||||
// Keep track of each property that belongs to this object.
|
||||
if (!isArray) {
|
||||
var ids = [];
|
||||
for (id in obj) {
|
||||
if (obj.hasOwnProperty(id)) {
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var i = -1; // Keeps track of the current property
|
||||
|
||||
/**
|
||||
* Private. Process the next property
|
||||
*/
|
||||
var next = function () {
|
||||
id = isArray ? i : ids[i];
|
||||
process(id, obj[id], check);
|
||||
};
|
||||
|
||||
/**
|
||||
* Private. Check if we're done or have an error.
|
||||
*
|
||||
* @param {String} err
|
||||
*/
|
||||
var check = function (err) {
|
||||
// We need to use a real async function in order for the stack to clear.
|
||||
setTimeout(function () {
|
||||
i++;
|
||||
if (i === (isArray ? obj.length : ids.length) || (err !== undefined && err !== null)) {
|
||||
finished(err);
|
||||
}
|
||||
else {
|
||||
next();
|
||||
}
|
||||
}, 0);
|
||||
};
|
||||
|
||||
check(); // Start
|
||||
};
|
||||
|
||||
return ContentUpgradeProcess;
|
||||
})(H5P.Version);
|
63
lib/h5p/js/h5p-content-upgrade-worker.js
Normal file
63
lib/h5p/js/h5p-content-upgrade-worker.js
Normal file
@ -0,0 +1,63 @@
|
||||
/* global importScripts */
|
||||
var H5P = H5P || {};
|
||||
importScripts('h5p-version.js', 'h5p-content-upgrade-process.js');
|
||||
|
||||
var libraryLoadedCallback;
|
||||
|
||||
/**
|
||||
* Register message handlers
|
||||
*/
|
||||
var messageHandlers = {
|
||||
newJob: function (job) {
|
||||
// Start new job
|
||||
new H5P.ContentUpgradeProcess(job.name, new H5P.Version(job.oldVersion), new H5P.Version(job.newVersion), job.params, job.id, function loadLibrary(name, version, next) {
|
||||
// TODO: Cache?
|
||||
postMessage({
|
||||
action: 'loadLibrary',
|
||||
name: name,
|
||||
version: version.toString()
|
||||
});
|
||||
libraryLoadedCallback = next;
|
||||
}, function done(err, result) {
|
||||
if (err) {
|
||||
// Return error
|
||||
postMessage({
|
||||
action: 'error',
|
||||
id: job.id,
|
||||
err: err.message ? err.message : err
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Return upgraded content
|
||||
postMessage({
|
||||
action: 'done',
|
||||
id: job.id,
|
||||
params: result
|
||||
});
|
||||
});
|
||||
},
|
||||
libraryLoaded: function (data) {
|
||||
var library = data.library;
|
||||
if (library.upgradesScript) {
|
||||
try {
|
||||
importScripts(library.upgradesScript);
|
||||
}
|
||||
catch (err) {
|
||||
libraryLoadedCallback(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
libraryLoadedCallback(null, data.library);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle messages from our master
|
||||
*/
|
||||
onmessage = function (event) {
|
||||
if (event.data.action !== undefined && messageHandlers[event.data.action]) {
|
||||
messageHandlers[event.data.action].call(this, event.data);
|
||||
}
|
||||
};
|
445
lib/h5p/js/h5p-content-upgrade.js
Normal file
445
lib/h5p/js/h5p-content-upgrade.js
Normal file
@ -0,0 +1,445 @@
|
||||
/* global H5PAdminIntegration H5PUtils */
|
||||
|
||||
(function ($, Version) {
|
||||
var info, $log, $container, librariesCache = {}, scriptsCache = {};
|
||||
|
||||
// Initialize
|
||||
$(document).ready(function () {
|
||||
// Get library info
|
||||
info = H5PAdminIntegration.libraryInfo;
|
||||
|
||||
// Get and reset container
|
||||
const $wrapper = $('#h5p-admin-container').html('');
|
||||
$log = $('<ul class="content-upgrade-log"></ul>').appendTo($wrapper);
|
||||
$container = $('<div><p>' + info.message + '</p></div>').appendTo($wrapper);
|
||||
|
||||
// Make it possible to select version
|
||||
var $version = $(getVersionSelect(info.versions)).appendTo($container);
|
||||
|
||||
// Add "go" button
|
||||
$('<button/>', {
|
||||
class: 'h5p-admin-upgrade-button',
|
||||
text: info.buttonLabel,
|
||||
click: function () {
|
||||
// Start new content upgrade
|
||||
new ContentUpgrade($version.val());
|
||||
}
|
||||
}).appendTo($container);
|
||||
});
|
||||
|
||||
/**
|
||||
* Generate html for version select.
|
||||
*
|
||||
* @param {Object} versions
|
||||
* @returns {String}
|
||||
*/
|
||||
var getVersionSelect = function (versions) {
|
||||
var html = '';
|
||||
for (var id in versions) {
|
||||
html += '<option value="' + id + '">' + versions[id] + '</option>';
|
||||
}
|
||||
if (html !== '') {
|
||||
html = '<select>' + html + '</select>';
|
||||
return html;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Displays a throbber in the status field.
|
||||
*
|
||||
* @param {String} msg
|
||||
* @returns {_L1.Throbber}
|
||||
*/
|
||||
function Throbber(msg) {
|
||||
var $throbber = H5PUtils.throbber(msg);
|
||||
$container.html('').append($throbber);
|
||||
|
||||
/**
|
||||
* Makes it possible to set the progress.
|
||||
*
|
||||
* @param {String} progress
|
||||
*/
|
||||
this.setProgress = function (progress) {
|
||||
$throbber.text(msg + ' ' + progress);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a new content upgrade.
|
||||
*
|
||||
* @param {Number} libraryId
|
||||
* @returns {_L1.ContentUpgrade}
|
||||
*/
|
||||
function ContentUpgrade(libraryId) {
|
||||
var self = this;
|
||||
|
||||
// Get selected version
|
||||
self.version = new Version(info.versions[libraryId]);
|
||||
self.version.libraryId = libraryId;
|
||||
|
||||
// Create throbber with loading text and progress
|
||||
self.throbber = new Throbber(info.inProgress.replace('%ver', self.version));
|
||||
|
||||
self.started = new Date().getTime();
|
||||
self.io = 0;
|
||||
|
||||
// Track number of working
|
||||
self.working = 0;
|
||||
|
||||
var start = function () {
|
||||
// Get the next batch
|
||||
self.nextBatch({
|
||||
libraryId: libraryId,
|
||||
token: info.token
|
||||
});
|
||||
};
|
||||
|
||||
if (window.Worker !== undefined) {
|
||||
// Prepare our workers
|
||||
self.initWorkers();
|
||||
start();
|
||||
}
|
||||
else {
|
||||
// No workers, do the job ourselves
|
||||
self.loadScript(info.scriptBaseUrl + '/h5p-content-upgrade-process.js' + info.buster, start);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize workers
|
||||
*/
|
||||
ContentUpgrade.prototype.initWorkers = function () {
|
||||
var self = this;
|
||||
|
||||
// Determine number of workers (defaults to 4)
|
||||
var numWorkers = (window.navigator !== undefined && window.navigator.hardwareConcurrency ? window.navigator.hardwareConcurrency : 4);
|
||||
self.workers = new Array(numWorkers);
|
||||
|
||||
// Register message handlers
|
||||
var messageHandlers = {
|
||||
done: function (result) {
|
||||
self.workDone(result.id, result.params, this);
|
||||
},
|
||||
error: function (error) {
|
||||
self.printError(error.err);
|
||||
self.workDone(error.id, null, this);
|
||||
},
|
||||
loadLibrary: function (details) {
|
||||
var worker = this;
|
||||
self.loadLibrary(details.name, new Version(details.version), function (err, library) {
|
||||
if (err) {
|
||||
// Reset worker?
|
||||
return;
|
||||
}
|
||||
|
||||
worker.postMessage({
|
||||
action: 'libraryLoaded',
|
||||
library: library
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
for (var i = 0; i < numWorkers; i++) {
|
||||
self.workers[i] = new Worker(info.scriptBaseUrl + '/h5p-content-upgrade-worker.js' + info.buster);
|
||||
self.workers[i].onmessage = function (event) {
|
||||
if (event.data.action !== undefined && messageHandlers[event.data.action]) {
|
||||
messageHandlers[event.data.action].call(this, event.data);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the next batch and start processing it.
|
||||
*
|
||||
* @param {Object} outData
|
||||
*/
|
||||
ContentUpgrade.prototype.nextBatch = function (outData) {
|
||||
var self = this;
|
||||
|
||||
// Track time spent on IO
|
||||
var start = new Date().getTime();
|
||||
$.post(info.infoUrl, outData, function (inData) {
|
||||
self.io += new Date().getTime() - start;
|
||||
if (!(inData instanceof Object)) {
|
||||
// Print errors from backend
|
||||
return self.setStatus(inData);
|
||||
}
|
||||
if (inData.left === 0) {
|
||||
var total = new Date().getTime() - self.started;
|
||||
|
||||
if (window.console && console.log) {
|
||||
console.log('The upgrade process took ' + (total / 1000) + ' seconds. (' + (Math.round((self.io / (total / 100)) * 100) / 100) + ' % IO)' );
|
||||
}
|
||||
|
||||
// Terminate workers
|
||||
self.terminate();
|
||||
|
||||
// Nothing left to process
|
||||
return self.setStatus(info.done);
|
||||
}
|
||||
|
||||
self.left = inData.left;
|
||||
self.token = inData.token;
|
||||
|
||||
// Start processing
|
||||
self.processBatch(inData.params, inData.skipped);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Set current status message.
|
||||
*
|
||||
* @param {String} msg
|
||||
*/
|
||||
ContentUpgrade.prototype.setStatus = function (msg) {
|
||||
$container.html(msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Process the given parameters.
|
||||
*
|
||||
* @param {Object} parameters
|
||||
*/
|
||||
ContentUpgrade.prototype.processBatch = function (parameters, skipped) {
|
||||
var self = this;
|
||||
|
||||
// Track upgraded params
|
||||
self.upgraded = {};
|
||||
self.skipped = skipped;
|
||||
|
||||
// Track current batch
|
||||
self.parameters = parameters;
|
||||
|
||||
// Create id mapping
|
||||
self.ids = [];
|
||||
for (var id in parameters) {
|
||||
if (parameters.hasOwnProperty(id)) {
|
||||
self.ids.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Keep track of current content
|
||||
self.current = -1;
|
||||
|
||||
if (self.workers !== undefined) {
|
||||
// Assign each worker content to upgrade
|
||||
for (var i = 0; i < self.workers.length; i++) {
|
||||
self.assignWork(self.workers[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
self.assignWork();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ContentUpgrade.prototype.assignWork = function (worker) {
|
||||
var self = this;
|
||||
|
||||
var id = self.ids[self.current + 1];
|
||||
if (id === undefined) {
|
||||
return false; // Out of work
|
||||
}
|
||||
self.current++;
|
||||
self.working++;
|
||||
|
||||
if (worker) {
|
||||
worker.postMessage({
|
||||
action: 'newJob',
|
||||
id: id,
|
||||
name: info.library.name,
|
||||
oldVersion: info.library.version,
|
||||
newVersion: self.version.toString(),
|
||||
params: self.parameters[id]
|
||||
});
|
||||
}
|
||||
else {
|
||||
new H5P.ContentUpgradeProcess(info.library.name, new Version(info.library.version), self.version, self.parameters[id], id, function loadLibrary(name, version, next) {
|
||||
self.loadLibrary(name, version, function (err, library) {
|
||||
if (library.upgradesScript) {
|
||||
self.loadScript(library.upgradesScript, function (err) {
|
||||
if (err) {
|
||||
err = info.errorScript.replace('%lib', name + ' ' + version);
|
||||
}
|
||||
next(err, library);
|
||||
});
|
||||
}
|
||||
else {
|
||||
next(null, library);
|
||||
}
|
||||
});
|
||||
|
||||
}, function done(err, result) {
|
||||
if (err) {
|
||||
self.printError(err);
|
||||
result = null;
|
||||
}
|
||||
|
||||
self.workDone(id, result);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ContentUpgrade.prototype.workDone = function (id, result, worker) {
|
||||
var self = this;
|
||||
|
||||
self.working--;
|
||||
if (result === null) {
|
||||
self.skipped.push(id);
|
||||
}
|
||||
else {
|
||||
self.upgraded[id] = result;
|
||||
}
|
||||
|
||||
// Update progress message
|
||||
self.throbber.setProgress(Math.round((info.total - self.left + self.current) / (info.total / 100)) + ' %');
|
||||
|
||||
// Assign next job
|
||||
if (self.assignWork(worker) === false && self.working === 0) {
|
||||
// All workers have finsihed.
|
||||
self.nextBatch({
|
||||
libraryId: self.version.libraryId,
|
||||
token: self.token,
|
||||
skipped: JSON.stringify(self.skipped),
|
||||
params: JSON.stringify(self.upgraded)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ContentUpgrade.prototype.terminate = function () {
|
||||
var self = this;
|
||||
|
||||
if (self.workers) {
|
||||
// Stop all workers
|
||||
for (var i = 0; i < self.workers.length; i++) {
|
||||
self.workers[i].terminate();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var librariesLoadedCallbacks = {};
|
||||
|
||||
/**
|
||||
* Load library data needed for content upgrade.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Version} version
|
||||
* @param {Function} next
|
||||
*/
|
||||
ContentUpgrade.prototype.loadLibrary = function (name, version, next) {
|
||||
var self = this;
|
||||
|
||||
var key = name + '/' + version.major + '/' + version.minor;
|
||||
|
||||
if (librariesCache[key] === true) {
|
||||
// Library is being loaded, que callback
|
||||
if (librariesLoadedCallbacks[key] === undefined) {
|
||||
librariesLoadedCallbacks[key] = [next];
|
||||
return;
|
||||
}
|
||||
librariesLoadedCallbacks[key].push(next);
|
||||
return;
|
||||
}
|
||||
else if (librariesCache[key] !== undefined) {
|
||||
// Library has been loaded before. Return cache.
|
||||
next(null, librariesCache[key]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Track time spent loading
|
||||
var start = new Date().getTime();
|
||||
librariesCache[key] = true;
|
||||
$.ajax({
|
||||
dataType: 'json',
|
||||
cache: true,
|
||||
url: info.libraryBaseUrl + '/' + key
|
||||
}).fail(function () {
|
||||
self.io += new Date().getTime() - start;
|
||||
next(info.errorData.replace('%lib', name + ' ' + version));
|
||||
}).done(function (library) {
|
||||
self.io += new Date().getTime() - start;
|
||||
librariesCache[key] = library;
|
||||
next(null, library);
|
||||
|
||||
if (librariesLoadedCallbacks[key] !== undefined) {
|
||||
for (var i = 0; i < librariesLoadedCallbacks[key].length; i++) {
|
||||
librariesLoadedCallbacks[key][i](null, library);
|
||||
}
|
||||
}
|
||||
delete librariesLoadedCallbacks[key];
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Load script with upgrade hooks.
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {Function} next
|
||||
*/
|
||||
ContentUpgrade.prototype.loadScript = function (url, next) {
|
||||
var self = this;
|
||||
|
||||
if (scriptsCache[url] !== undefined) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
// Track time spent loading
|
||||
var start = new Date().getTime();
|
||||
$.ajax({
|
||||
dataType: 'script',
|
||||
cache: true,
|
||||
url: url
|
||||
}).fail(function () {
|
||||
self.io += new Date().getTime() - start;
|
||||
next(true);
|
||||
}).done(function () {
|
||||
scriptsCache[url] = true;
|
||||
self.io += new Date().getTime() - start;
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ContentUpgrade.prototype.printError = function (error) {
|
||||
var self = this;
|
||||
|
||||
switch (error.type) {
|
||||
case 'errorParamsBroken':
|
||||
error = info.errorContent.replace('%id', error.id) + ' ' + info.errorParamsBroken;
|
||||
break;
|
||||
|
||||
case 'libraryMissing':
|
||||
error = info.errorLibrary.replace('%lib', error.library);
|
||||
break;
|
||||
|
||||
case 'scriptMissing':
|
||||
error = info.errorScript.replace('%lib', error.library);
|
||||
break;
|
||||
|
||||
case 'errorTooHighVersion':
|
||||
error = info.errorContent.replace('%id', error.id) + ' ' + info.errorTooHighVersion.replace('%used', error.used).replace('%supported', error.supported);
|
||||
break;
|
||||
|
||||
case 'errorNotSupported':
|
||||
error = info.errorContent.replace('%id', error.id) + ' ' + info.errorNotSupported.replace('%used', error.used);
|
||||
break;
|
||||
}
|
||||
|
||||
$('<li>' + info.error + '<br/>' + error + '</li>').appendTo($log);
|
||||
};
|
||||
|
||||
})(H5P.jQuery, H5P.Version);
|
442
lib/h5p/js/h5p-data-view.js
Normal file
442
lib/h5p/js/h5p-data-view.js
Normal file
@ -0,0 +1,442 @@
|
||||
/* global H5PUtils */
|
||||
var H5PDataView = (function ($) {
|
||||
|
||||
/**
|
||||
* Initialize a new H5P data view.
|
||||
*
|
||||
* @class
|
||||
* @param {Object} container
|
||||
* Element to clear out and append to.
|
||||
* @param {String} source
|
||||
* URL to get data from. Data format: {num: 123, rows:[[1,2,3],[2,4,6]]}
|
||||
* @param {Array} headers
|
||||
* List with column headers. Can be strings or objects with options like
|
||||
* "text" and "sortable". E.g.
|
||||
* [{text: 'Col 1', sortable: true}, 'Col 2', 'Col 3']
|
||||
* @param {Object} l10n
|
||||
* Localization / translations. e.g.
|
||||
* {
|
||||
* loading: 'Loading data.',
|
||||
* ajaxFailed: 'Failed to load data.',
|
||||
* noData: "There's no data available that matches your criteria.",
|
||||
* currentPage: 'Page $current of $total',
|
||||
* nextPage: 'Next page',
|
||||
* previousPage: 'Previous page',
|
||||
* search: 'Search'
|
||||
* }
|
||||
* @param {Object} classes
|
||||
* Custom html classes to use on elements.
|
||||
* e.g. {tableClass: 'fixed'}.
|
||||
* @param {Array} filters
|
||||
* Make it possible to filter/search in the given column.
|
||||
* e.g. [null, true, null, null] will make it possible to do a text
|
||||
* search in column 2.
|
||||
* @param {Function} loaded
|
||||
* Callback for when data has been loaded.
|
||||
* @param {Object} order
|
||||
*/
|
||||
function H5PDataView(container, source, headers, l10n, classes, filters, loaded, order) {
|
||||
var self = this;
|
||||
|
||||
self.$container = $(container).addClass('h5p-data-view').html('');
|
||||
|
||||
self.source = source;
|
||||
self.headers = headers;
|
||||
self.l10n = l10n;
|
||||
self.classes = (classes === undefined ? {} : classes);
|
||||
self.filters = (filters === undefined ? [] : filters);
|
||||
self.loaded = loaded;
|
||||
self.order = order;
|
||||
|
||||
self.limit = 20;
|
||||
self.offset = 0;
|
||||
self.filterOn = [];
|
||||
self.facets = {};
|
||||
|
||||
// Index of column with author name; could be made more general by passing database column names and checking for position
|
||||
self.columnIdAuthor = 2;
|
||||
|
||||
// Future option: Create more general solution for filter presets
|
||||
if (H5PIntegration.user && parseInt(H5PIntegration.user.canToggleViewOthersH5PContents) === 1) {
|
||||
self.updateTable([]);
|
||||
self.filterByFacet(self.columnIdAuthor, H5PIntegration.user.id, H5PIntegration.user.name || '');
|
||||
}
|
||||
else {
|
||||
self.loadData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load data from source URL.
|
||||
*/
|
||||
H5PDataView.prototype.loadData = function () {
|
||||
var self = this;
|
||||
|
||||
// Throbb
|
||||
self.setMessage(H5PUtils.throbber(self.l10n.loading));
|
||||
|
||||
// Create URL
|
||||
var url = self.source;
|
||||
url += (url.indexOf('?') === -1 ? '?' : '&') + 'offset=' + self.offset + '&limit=' + self.limit;
|
||||
|
||||
// Add sorting
|
||||
if (self.order !== undefined) {
|
||||
url += '&sortBy=' + self.order.by + '&sortDir=' + self.order.dir;
|
||||
}
|
||||
|
||||
// Add filters
|
||||
var filtering;
|
||||
for (var i = 0; i < self.filterOn.length; i++) {
|
||||
if (self.filterOn[i] === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
filtering = true;
|
||||
url += '&filters[' + i + ']=' + encodeURIComponent(self.filterOn[i]);
|
||||
}
|
||||
|
||||
// Add facets
|
||||
for (var col in self.facets) {
|
||||
if (!self.facets.hasOwnProperty(col)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
url += '&facets[' + col + ']=' + self.facets[col].id;
|
||||
}
|
||||
|
||||
// Fire ajax request
|
||||
$.ajax({
|
||||
dataType: 'json',
|
||||
cache: true,
|
||||
url: url
|
||||
}).fail(function () {
|
||||
// Error handling
|
||||
self.setMessage($('<p/>', {text: self.l10n.ajaxFailed}));
|
||||
}).done(function (data) {
|
||||
if (!data.rows.length) {
|
||||
self.setMessage($('<p/>', {text: filtering ? self.l10n.noData : self.l10n.empty}));
|
||||
}
|
||||
else {
|
||||
// Update table data
|
||||
self.updateTable(data.rows);
|
||||
}
|
||||
|
||||
// Update pagination widget
|
||||
self.updatePagination(data.num);
|
||||
|
||||
if (self.loaded !== undefined) {
|
||||
self.loaded();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Display the given message to the user.
|
||||
*
|
||||
* @param {jQuery} $message wrapper with message
|
||||
*/
|
||||
H5PDataView.prototype.setMessage = function ($message) {
|
||||
var self = this;
|
||||
|
||||
if (self.table === undefined) {
|
||||
self.$container.html('').append($message);
|
||||
}
|
||||
else {
|
||||
self.table.setBody($message);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update table data.
|
||||
*
|
||||
* @param {Array} rows
|
||||
*/
|
||||
H5PDataView.prototype.updateTable = function (rows) {
|
||||
var self = this;
|
||||
|
||||
if (self.table === undefined) {
|
||||
// Clear out container
|
||||
self.$container.html('');
|
||||
|
||||
// Add filters
|
||||
self.addFilters();
|
||||
|
||||
// Add toggler for others' content
|
||||
if (H5PIntegration.user && parseInt(H5PIntegration.user.canToggleViewOthersH5PContents) > 0) {
|
||||
// canToggleViewOthersH5PContents = 1 is setting for only showing current user's contents
|
||||
self.addOthersContentToggler(parseInt(H5PIntegration.user.canToggleViewOthersH5PContents) === 1);
|
||||
}
|
||||
|
||||
// Add facets
|
||||
self.$facets = $('<div/>', {
|
||||
'class': 'h5p-facet-wrapper',
|
||||
appendTo: self.$container
|
||||
});
|
||||
|
||||
// Create new table
|
||||
self.table = new H5PUtils.Table(self.classes, self.headers);
|
||||
self.table.setHeaders(self.headers, function (order) {
|
||||
// Sorting column or direction has changed.
|
||||
self.order = order;
|
||||
self.loadData();
|
||||
}, self.order);
|
||||
self.table.appendTo(self.$container);
|
||||
}
|
||||
|
||||
// Process cell data before updating table
|
||||
for (var i = 0; i < self.headers.length; i++) {
|
||||
if (self.headers[i].facet === true) {
|
||||
// Process rows for col, expect object or array
|
||||
for (var j = 0; j < rows.length; j++) {
|
||||
rows[j][i] = self.createFacets(rows[j][i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add/update rows
|
||||
var $tbody = self.table.setRows(rows);
|
||||
|
||||
// Add event handlers for facets
|
||||
$('.h5p-facet', $tbody).click(function () {
|
||||
var $facet = $(this);
|
||||
self.filterByFacet($facet.data('col'), $facet.data('id'), $facet.text());
|
||||
}).keypress(function (event) {
|
||||
if (event.which === 32) {
|
||||
var $facet = $(this);
|
||||
self.filterByFacet($facet.data('col'), $facet.data('id'), $facet.text());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Create button for adding facet to filter.
|
||||
*
|
||||
* @param (object|Array) input
|
||||
* @param number col ID of column
|
||||
*/
|
||||
H5PDataView.prototype.createFacets = function (input, col) {
|
||||
var facets = '';
|
||||
|
||||
if (input instanceof Array) {
|
||||
// Facet can be filtered on multiple values at the same time
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
if (facets !== '') {
|
||||
facets += ', ';
|
||||
}
|
||||
facets += '<span class="h5p-facet" role="button" tabindex="0" data-id="' + input[i].id + '" data-col="' + col + '">' + input[i].title + '</span>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Single value facet filtering
|
||||
facets += '<span class="h5p-facet" role="button" tabindex="0" data-id="' + input.id + '" data-col="' + col + '">' + input.title + '</span>';
|
||||
}
|
||||
|
||||
return facets === '' ? '—' : facets;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a filter based on the given facet.
|
||||
*
|
||||
* @param number col ID of column we're filtering
|
||||
* @param number id ID to filter on
|
||||
* @param string text Human readable label for the filter
|
||||
*/
|
||||
H5PDataView.prototype.filterByFacet = function (col, id, text) {
|
||||
var self = this;
|
||||
|
||||
if (self.facets[col] !== undefined) {
|
||||
if (self.facets[col].id === id) {
|
||||
return; // Don't use the same filter again
|
||||
}
|
||||
|
||||
// Remove current filter for this col
|
||||
self.facets[col].$tag.remove();
|
||||
}
|
||||
|
||||
// Add to UI
|
||||
self.facets[col] = {
|
||||
id: id,
|
||||
'$tag': $('<span/>', {
|
||||
'class': 'h5p-facet-tag',
|
||||
text: text,
|
||||
appendTo: self.$facets,
|
||||
})
|
||||
};
|
||||
/**
|
||||
* Callback for removing filter.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
var remove = function () {
|
||||
// Uncheck toggler for others' H5P contents
|
||||
if ( self.$othersContentToggler && self.facets.hasOwnProperty( self.columnIdAuthor ) ) {
|
||||
self.$othersContentToggler.prop('checked', false );
|
||||
}
|
||||
|
||||
self.facets[col].$tag.remove();
|
||||
delete self.facets[col];
|
||||
self.loadData();
|
||||
};
|
||||
|
||||
// Remove button
|
||||
$('<span/>', {
|
||||
role: 'button',
|
||||
tabindex: 0,
|
||||
appendTo: self.facets[col].$tag,
|
||||
text: self.l10n.remove,
|
||||
title: self.l10n.remove,
|
||||
on: {
|
||||
click: remove,
|
||||
keypress: function (event) {
|
||||
if (event.which === 32) {
|
||||
remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Load data with new filter
|
||||
self.loadData();
|
||||
};
|
||||
|
||||
/**
|
||||
* Update pagination widget.
|
||||
*
|
||||
* @param {Number} num size of data collection
|
||||
*/
|
||||
H5PDataView.prototype.updatePagination = function (num) {
|
||||
var self = this;
|
||||
|
||||
if (self.pagination === undefined) {
|
||||
if (self.table === undefined) {
|
||||
// No table, no pagination
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new widget
|
||||
var $pagerContainer = $('<div/>', {'class': 'h5p-pagination'});
|
||||
self.pagination = new H5PUtils.Pagination(num, self.limit, function (offset) {
|
||||
// Handle page changes in pagination widget
|
||||
self.offset = offset;
|
||||
self.loadData();
|
||||
}, self.l10n);
|
||||
|
||||
self.pagination.appendTo($pagerContainer);
|
||||
self.table.setFoot($pagerContainer);
|
||||
}
|
||||
else {
|
||||
// Update existing widget
|
||||
self.pagination.update(num, self.limit);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add filters.
|
||||
*/
|
||||
H5PDataView.prototype.addFilters = function () {
|
||||
var self = this;
|
||||
|
||||
for (var i = 0; i < self.filters.length; i++) {
|
||||
if (self.filters[i] === true) {
|
||||
// Add text input filter for col i
|
||||
self.addTextFilter(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add text filter for given col num.
|
||||
*
|
||||
* @param {Number} col
|
||||
*/
|
||||
H5PDataView.prototype.addTextFilter = function (col) {
|
||||
var self = this;
|
||||
|
||||
/**
|
||||
* Find input value and filter on it.
|
||||
* @private
|
||||
*/
|
||||
var search = function () {
|
||||
var filterOn = $input.val().replace(/^\s+|\s+$/g, '');
|
||||
if (filterOn === '') {
|
||||
filterOn = undefined;
|
||||
}
|
||||
if (filterOn !== self.filterOn[col]) {
|
||||
self.filterOn[col] = filterOn;
|
||||
self.loadData();
|
||||
}
|
||||
};
|
||||
|
||||
// Add text field for filtering
|
||||
var typing;
|
||||
var $input = $('<input/>', {
|
||||
type: 'text',
|
||||
placeholder: self.l10n.search,
|
||||
on: {
|
||||
'blur': function () {
|
||||
clearTimeout(typing);
|
||||
search();
|
||||
},
|
||||
'keyup': function (event) {
|
||||
if (event.keyCode === 13) {
|
||||
clearTimeout(typing);
|
||||
search();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
clearTimeout(typing);
|
||||
typing = setTimeout(function () {
|
||||
search();
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).appendTo(self.$container);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add toggle for others' H5P content.
|
||||
* @param {boolean} [checked=false] Initial check setting.
|
||||
*/
|
||||
H5PDataView.prototype.addOthersContentToggler = function (checked) {
|
||||
var self = this;
|
||||
|
||||
checked = (typeof checked === 'undefined') ? false : checked;
|
||||
|
||||
// Checkbox
|
||||
this.$othersContentToggler = $('<input/>', {
|
||||
type: 'checkbox',
|
||||
'class': 'h5p-others-contents-toggler',
|
||||
'id': 'h5p-others-contents-toggler',
|
||||
'checked': checked,
|
||||
'click': function () {
|
||||
if ( this.checked ) {
|
||||
// Add filter on current user
|
||||
self.filterByFacet( self.columnIdAuthor, H5PIntegration.user.id, H5PIntegration.user.name );
|
||||
}
|
||||
else {
|
||||
// Remove facet indicator and reload full data view
|
||||
if ( self.facets.hasOwnProperty( self.columnIdAuthor ) && self.facets[self.columnIdAuthor].$tag ) {
|
||||
self.facets[self.columnIdAuthor].$tag.remove();
|
||||
}
|
||||
delete self.facets[self.columnIdAuthor];
|
||||
self.loadData();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Label
|
||||
var $label = $('<label>', {
|
||||
'class': 'h5p-others-contents-toggler-label',
|
||||
'text': this.l10n.showOwnContentOnly,
|
||||
'for': 'h5p-others-contents-toggler'
|
||||
}).prepend(this.$othersContentToggler);
|
||||
|
||||
$('<div>', {
|
||||
'class': 'h5p-others-contents-toggler-wrapper'
|
||||
}).append($label)
|
||||
.appendTo(this.$container);
|
||||
};
|
||||
|
||||
return H5PDataView;
|
||||
})(H5P.jQuery);
|
54
lib/h5p/js/h5p-display-options.js
Normal file
54
lib/h5p/js/h5p-display-options.js
Normal file
@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Utility that makes it possible to hide fields when a checkbox is unchecked
|
||||
*/
|
||||
(function ($) {
|
||||
function setupHiding() {
|
||||
var $toggler = $(this);
|
||||
|
||||
// Getting the field which should be hidden:
|
||||
var $subject = $($toggler.data('h5p-visibility-subject-selector'));
|
||||
|
||||
var toggle = function () {
|
||||
$subject.toggle($toggler.is(':checked'));
|
||||
};
|
||||
|
||||
$toggler.change(toggle);
|
||||
toggle();
|
||||
}
|
||||
|
||||
function setupRevealing() {
|
||||
var $button = $(this);
|
||||
|
||||
// Getting the field which should have the value:
|
||||
var $input = $('#' + $button.data('control'));
|
||||
|
||||
if (!$input.data('value')) {
|
||||
$button.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup button action
|
||||
var revealed = false;
|
||||
var text = $button.html();
|
||||
$button.click(function () {
|
||||
if (revealed) {
|
||||
$input.val('');
|
||||
$button.html(text);
|
||||
revealed = false;
|
||||
}
|
||||
else {
|
||||
$input.val($input.data('value'));
|
||||
$button.html($button.data('hide'));
|
||||
revealed = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
// Get the checkboxes making other fields being hidden:
|
||||
$('.h5p-visibility-toggler').each(setupHiding);
|
||||
|
||||
// Get the buttons making other fields have hidden values:
|
||||
$('.h5p-reveal-value').each(setupRevealing);
|
||||
});
|
||||
})(H5P.jQuery);
|
75
lib/h5p/js/h5p-embed.js
Normal file
75
lib/h5p/js/h5p-embed.js
Normal file
@ -0,0 +1,75 @@
|
||||
/*jshint multistr: true */
|
||||
|
||||
/**
|
||||
* Converts old script tag embed to iframe
|
||||
*/
|
||||
var H5POldEmbed = H5POldEmbed || (function () {
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
var resizer = false;
|
||||
|
||||
/**
|
||||
* Loads the resizing script
|
||||
*/
|
||||
var loadResizer = function (url) {
|
||||
var data, callback = 'H5POldEmbed';
|
||||
resizer = true;
|
||||
|
||||
// Callback for when content data is loaded.
|
||||
window[callback] = function (content) {
|
||||
// Add resizing script to head
|
||||
var resizer = document.createElement('script');
|
||||
resizer.src = content;
|
||||
head.appendChild(resizer);
|
||||
|
||||
// Clean up
|
||||
head.removeChild(data);
|
||||
delete window[callback];
|
||||
};
|
||||
|
||||
// Create data script
|
||||
data = document.createElement('script');
|
||||
data.src = url + (url.indexOf('?') === -1 ? '?' : '&') + 'callback=' + callback;
|
||||
head.appendChild(data);
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaced script tag with iframe
|
||||
*/
|
||||
var addIframe = function (script) {
|
||||
// Add iframe
|
||||
var iframe = document.createElement('iframe');
|
||||
iframe.src = script.getAttribute('data-h5p');
|
||||
iframe.frameBorder = false;
|
||||
iframe.allowFullscreen = true;
|
||||
var parent = script.parentNode;
|
||||
parent.insertBefore(iframe, script);
|
||||
parent.removeChild(script);
|
||||
};
|
||||
|
||||
/**
|
||||
* Go throught all script tags with the data-h5p attribute and load content.
|
||||
*/
|
||||
function H5POldEmbed() {
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
var h5ps = []; // Use seperate array since scripts grow in size.
|
||||
for (var i = 0; i < scripts.length; i++) {
|
||||
var script = scripts[i];
|
||||
if (script.src.indexOf('/h5p-resizer.js') !== -1) {
|
||||
resizer = true;
|
||||
}
|
||||
else if (script.hasAttribute('data-h5p')) {
|
||||
h5ps.push(script);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < h5ps.length; i++) {
|
||||
if (!resizer) {
|
||||
loadResizer(h5ps[i].getAttribute('data-h5p'));
|
||||
}
|
||||
addIframe(h5ps[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return H5POldEmbed;
|
||||
})();
|
||||
|
||||
new H5POldEmbed();
|
258
lib/h5p/js/h5p-event-dispatcher.js
Normal file
258
lib/h5p/js/h5p-event-dispatcher.js
Normal file
@ -0,0 +1,258 @@
|
||||
var H5P = window.H5P = window.H5P || {};
|
||||
|
||||
/**
|
||||
* The Event class for the EventDispatcher.
|
||||
*
|
||||
* @class
|
||||
* @param {string} type
|
||||
* @param {*} data
|
||||
* @param {Object} [extras]
|
||||
* @param {boolean} [extras.bubbles]
|
||||
* @param {boolean} [extras.external]
|
||||
*/
|
||||
H5P.Event = function (type, data, extras) {
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
var bubbles = false;
|
||||
|
||||
// Is this an external event?
|
||||
var external = false;
|
||||
|
||||
// Is this event scheduled to be sent externally?
|
||||
var scheduledForExternal = false;
|
||||
|
||||
if (extras === undefined) {
|
||||
extras = {};
|
||||
}
|
||||
if (extras.bubbles === true) {
|
||||
bubbles = true;
|
||||
}
|
||||
if (extras.external === true) {
|
||||
external = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent this event from bubbling up to parent
|
||||
*/
|
||||
this.preventBubbling = function () {
|
||||
bubbles = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get bubbling status
|
||||
*
|
||||
* @returns {boolean}
|
||||
* true if bubbling false otherwise
|
||||
*/
|
||||
this.getBubbles = function () {
|
||||
return bubbles;
|
||||
};
|
||||
|
||||
/**
|
||||
* Try to schedule an event for externalDispatcher
|
||||
*
|
||||
* @returns {boolean}
|
||||
* true if external and not already scheduled, otherwise false
|
||||
*/
|
||||
this.scheduleForExternal = function () {
|
||||
if (external && !scheduledForExternal) {
|
||||
scheduledForExternal = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback type for event listeners.
|
||||
*
|
||||
* @callback H5P.EventCallback
|
||||
* @param {H5P.Event} event
|
||||
*/
|
||||
|
||||
H5P.EventDispatcher = (function () {
|
||||
|
||||
/**
|
||||
* The base of the event system.
|
||||
* Inherit this class if you want your H5P to dispatch events.
|
||||
*
|
||||
* @class
|
||||
* @memberof H5P
|
||||
*/
|
||||
function EventDispatcher() {
|
||||
var self = this;
|
||||
|
||||
/**
|
||||
* Keep track of listeners for each event.
|
||||
*
|
||||
* @private
|
||||
* @type {Object}
|
||||
*/
|
||||
var triggers = {};
|
||||
|
||||
/**
|
||||
* Add new event listener.
|
||||
*
|
||||
* @throws {TypeError}
|
||||
* listener must be a function
|
||||
* @param {string} type
|
||||
* Event type
|
||||
* @param {H5P.EventCallback} listener
|
||||
* Event listener
|
||||
* @param {Object} [thisArg]
|
||||
* Optionally specify the this value when calling listener.
|
||||
*/
|
||||
this.on = function (type, listener, thisArg) {
|
||||
if (typeof listener !== 'function') {
|
||||
throw TypeError('listener must be a function');
|
||||
}
|
||||
|
||||
// Trigger event before adding to avoid recursion
|
||||
self.trigger('newListener', {'type': type, 'listener': listener});
|
||||
|
||||
var trigger = {'listener': listener, 'thisArg': thisArg};
|
||||
if (!triggers[type]) {
|
||||
// First
|
||||
triggers[type] = [trigger];
|
||||
}
|
||||
else {
|
||||
// Append
|
||||
triggers[type].push(trigger);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add new event listener that will be fired only once.
|
||||
*
|
||||
* @throws {TypeError}
|
||||
* listener must be a function
|
||||
* @param {string} type
|
||||
* Event type
|
||||
* @param {H5P.EventCallback} listener
|
||||
* Event listener
|
||||
* @param {Object} thisArg
|
||||
* Optionally specify the this value when calling listener.
|
||||
*/
|
||||
this.once = function (type, listener, thisArg) {
|
||||
if (!(listener instanceof Function)) {
|
||||
throw TypeError('listener must be a function');
|
||||
}
|
||||
|
||||
var once = function (event) {
|
||||
self.off(event.type, once);
|
||||
listener.call(this, event);
|
||||
};
|
||||
|
||||
self.on(type, once, thisArg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove event listener.
|
||||
* If no listener is specified, all listeners will be removed.
|
||||
*
|
||||
* @throws {TypeError}
|
||||
* listener must be a function
|
||||
* @param {string} type
|
||||
* Event type
|
||||
* @param {H5P.EventCallback} listener
|
||||
* Event listener
|
||||
*/
|
||||
this.off = function (type, listener) {
|
||||
if (listener !== undefined && !(listener instanceof Function)) {
|
||||
throw TypeError('listener must be a function');
|
||||
}
|
||||
|
||||
if (triggers[type] === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (listener === undefined) {
|
||||
// Remove all listeners
|
||||
delete triggers[type];
|
||||
self.trigger('removeListener', type);
|
||||
return;
|
||||
}
|
||||
|
||||
// Find specific listener
|
||||
for (var i = 0; i < triggers[type].length; i++) {
|
||||
if (triggers[type][i].listener === listener) {
|
||||
triggers[type].splice(i, 1);
|
||||
self.trigger('removeListener', type, {'listener': listener});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up empty arrays
|
||||
if (!triggers[type].length) {
|
||||
delete triggers[type];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Try to call all event listeners for the given event type.
|
||||
*
|
||||
* @private
|
||||
* @param {string} Event type
|
||||
*/
|
||||
var call = function (type, event) {
|
||||
if (triggers[type] === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clone array (prevents triggers from being modified during the event)
|
||||
var handlers = triggers[type].slice();
|
||||
|
||||
// Call all listeners
|
||||
for (var i = 0; i < handlers.length; i++) {
|
||||
var trigger = handlers[i];
|
||||
var thisArg = (trigger.thisArg ? trigger.thisArg : this);
|
||||
trigger.listener.call(thisArg, event);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispatch event.
|
||||
*
|
||||
* @param {string|H5P.Event} event
|
||||
* Event object or event type as string
|
||||
* @param {*} [eventData]
|
||||
* Custom event data(used when event type as string is used as first
|
||||
* argument).
|
||||
* @param {Object} [extras]
|
||||
* @param {boolean} [extras.bubbles]
|
||||
* @param {boolean} [extras.external]
|
||||
*/
|
||||
this.trigger = function (event, eventData, extras) {
|
||||
if (event === undefined) {
|
||||
return;
|
||||
}
|
||||
if (event instanceof String || typeof event === 'string') {
|
||||
event = new H5P.Event(event, eventData, extras);
|
||||
}
|
||||
else if (eventData !== undefined) {
|
||||
event.data = eventData;
|
||||
}
|
||||
|
||||
// Check to see if this event should go externally after all triggering and bubbling is done
|
||||
var scheduledForExternal = event.scheduleForExternal();
|
||||
|
||||
// Call all listeners
|
||||
call.call(this, event.type, event);
|
||||
|
||||
// Call all * listeners
|
||||
call.call(this, '*', event);
|
||||
|
||||
// Bubble
|
||||
if (event.getBubbles() && self.parent instanceof H5P.EventDispatcher &&
|
||||
(self.parent.trigger instanceof Function || typeof self.parent.trigger === 'function')) {
|
||||
self.parent.trigger(event);
|
||||
}
|
||||
|
||||
if (scheduledForExternal) {
|
||||
H5P.externalDispatcher.trigger.call(this, event);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return EventDispatcher;
|
||||
})();
|
297
lib/h5p/js/h5p-library-details.js
Normal file
297
lib/h5p/js/h5p-library-details.js
Normal file
@ -0,0 +1,297 @@
|
||||
/* global H5PAdminIntegration H5PUtils */
|
||||
var H5PLibraryDetails = H5PLibraryDetails || {};
|
||||
|
||||
(function ($) {
|
||||
|
||||
H5PLibraryDetails.PAGER_SIZE = 20;
|
||||
/**
|
||||
* Initializing
|
||||
*/
|
||||
H5PLibraryDetails.init = function () {
|
||||
H5PLibraryDetails.$adminContainer = H5P.jQuery(H5PAdminIntegration.containerSelector);
|
||||
H5PLibraryDetails.library = H5PAdminIntegration.libraryInfo;
|
||||
|
||||
// currentContent holds the current list if data (relevant for filtering)
|
||||
H5PLibraryDetails.currentContent = H5PLibraryDetails.library.content;
|
||||
|
||||
// The current page index (for pager)
|
||||
H5PLibraryDetails.currentPage = 0;
|
||||
|
||||
// The current filter
|
||||
H5PLibraryDetails.currentFilter = '';
|
||||
|
||||
// We cache the filtered results, so we don't have to do unneccessary searches
|
||||
H5PLibraryDetails.filterCache = [];
|
||||
|
||||
// Append library info
|
||||
H5PLibraryDetails.$adminContainer.append(H5PLibraryDetails.createLibraryInfo());
|
||||
|
||||
// Append node list
|
||||
H5PLibraryDetails.$adminContainer.append(H5PLibraryDetails.createContentElement());
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the library details view
|
||||
*/
|
||||
H5PLibraryDetails.createLibraryInfo = function () {
|
||||
var $libraryInfo = $('<div class="h5p-library-info"></div>');
|
||||
|
||||
$.each(H5PLibraryDetails.library.info, function (title, value) {
|
||||
$libraryInfo.append(H5PUtils.createLabeledField(title, value));
|
||||
});
|
||||
|
||||
return $libraryInfo;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the content list with searching and paging
|
||||
*/
|
||||
H5PLibraryDetails.createContentElement = function () {
|
||||
if (H5PLibraryDetails.library.notCached !== undefined) {
|
||||
return H5PUtils.getRebuildCache(H5PLibraryDetails.library.notCached);
|
||||
}
|
||||
|
||||
if (H5PLibraryDetails.currentContent === undefined) {
|
||||
H5PLibraryDetails.$content = $('<div class="h5p-content empty">' + H5PLibraryDetails.library.translations.noContent + '</div>');
|
||||
}
|
||||
else {
|
||||
H5PLibraryDetails.$content = $('<div class="h5p-content"><h3>' + H5PLibraryDetails.library.translations.contentHeader + '</h3></div>');
|
||||
H5PLibraryDetails.createSearchElement();
|
||||
H5PLibraryDetails.createPageSizeSelector();
|
||||
H5PLibraryDetails.createContentTable();
|
||||
H5PLibraryDetails.createPagerElement();
|
||||
return H5PLibraryDetails.$content;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the content list
|
||||
*/
|
||||
H5PLibraryDetails.createContentTable = function () {
|
||||
// Remove it if it exists:
|
||||
if (H5PLibraryDetails.$contentTable) {
|
||||
H5PLibraryDetails.$contentTable.remove();
|
||||
}
|
||||
|
||||
H5PLibraryDetails.$contentTable = H5PUtils.createTable();
|
||||
|
||||
var i = (H5PLibraryDetails.currentPage*H5PLibraryDetails.PAGER_SIZE);
|
||||
var lastIndex = (i+H5PLibraryDetails.PAGER_SIZE);
|
||||
|
||||
if (lastIndex > H5PLibraryDetails.currentContent.length) {
|
||||
lastIndex = H5PLibraryDetails.currentContent.length;
|
||||
}
|
||||
for (; i<lastIndex; i++) {
|
||||
var content = H5PLibraryDetails.currentContent[i];
|
||||
H5PLibraryDetails.$contentTable.append(H5PUtils.createTableRow(['<a href="' + content.url + '">' + content.title + '</a>']));
|
||||
}
|
||||
|
||||
// Appends it to the browser DOM
|
||||
H5PLibraryDetails.$contentTable.insertAfter(H5PLibraryDetails.$search);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the pager element on the bottom of the list
|
||||
*/
|
||||
H5PLibraryDetails.createPagerElement = function () {
|
||||
H5PLibraryDetails.$previous = $('<button type="button" class="previous h5p-admin"><</button>');
|
||||
H5PLibraryDetails.$next = $('<button type="button" class="next h5p-admin">></button>');
|
||||
|
||||
H5PLibraryDetails.$previous.on('click', function () {
|
||||
if (H5PLibraryDetails.$previous.hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
H5PLibraryDetails.currentPage--;
|
||||
H5PLibraryDetails.updatePager();
|
||||
H5PLibraryDetails.createContentTable();
|
||||
});
|
||||
|
||||
H5PLibraryDetails.$next.on('click', function () {
|
||||
if (H5PLibraryDetails.$next.hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
H5PLibraryDetails.currentPage++;
|
||||
H5PLibraryDetails.updatePager();
|
||||
H5PLibraryDetails.createContentTable();
|
||||
});
|
||||
|
||||
// This is the Page x of y widget:
|
||||
H5PLibraryDetails.$pagerInfo = $('<span class="pager-info"></span>');
|
||||
|
||||
H5PLibraryDetails.$pager = $('<div class="h5p-content-pager"></div>').append(H5PLibraryDetails.$previous, H5PLibraryDetails.$pagerInfo, H5PLibraryDetails.$next);
|
||||
H5PLibraryDetails.$content.append(H5PLibraryDetails.$pager);
|
||||
|
||||
H5PLibraryDetails.$pagerInfo.on('click', function () {
|
||||
var width = H5PLibraryDetails.$pagerInfo.innerWidth();
|
||||
H5PLibraryDetails.$pagerInfo.hide();
|
||||
|
||||
// User has updated the pageNumber
|
||||
var pageNumerUpdated = function () {
|
||||
var newPageNum = $gotoInput.val()-1;
|
||||
var intRegex = /^\d+$/;
|
||||
|
||||
$goto.remove();
|
||||
H5PLibraryDetails.$pagerInfo.css({display: 'inline-block'});
|
||||
|
||||
// Check if input value is valid, and that it has actually changed
|
||||
if (!(intRegex.test(newPageNum) && newPageNum >= 0 && newPageNum < H5PLibraryDetails.getNumPages() && newPageNum != H5PLibraryDetails.currentPage)) {
|
||||
return;
|
||||
}
|
||||
|
||||
H5PLibraryDetails.currentPage = newPageNum;
|
||||
H5PLibraryDetails.updatePager();
|
||||
H5PLibraryDetails.createContentTable();
|
||||
};
|
||||
|
||||
// We create an input box where the user may type in the page number
|
||||
// he wants to be displayed.
|
||||
// Reson for doing this is when user has ten-thousands of elements in list,
|
||||
// this is the easiest way of getting to a specified page
|
||||
var $gotoInput = $('<input/>', {
|
||||
type: 'number',
|
||||
min : 1,
|
||||
max: H5PLibraryDetails.getNumPages(),
|
||||
on: {
|
||||
// Listen to blur, and the enter-key:
|
||||
'blur': pageNumerUpdated,
|
||||
'keyup': function (event) {
|
||||
if (event.keyCode === 13) {
|
||||
pageNumerUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
}).css({width: width});
|
||||
var $goto = $('<span/>', {
|
||||
'class': 'h5p-pager-goto'
|
||||
}).css({width: width}).append($gotoInput).insertAfter(H5PLibraryDetails.$pagerInfo);
|
||||
|
||||
$gotoInput.focus();
|
||||
});
|
||||
|
||||
H5PLibraryDetails.updatePager();
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates number of pages
|
||||
*/
|
||||
H5PLibraryDetails.getNumPages = function () {
|
||||
return Math.ceil(H5PLibraryDetails.currentContent.length / H5PLibraryDetails.PAGER_SIZE);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the pager text, and enables/disables the next and previous buttons as needed
|
||||
*/
|
||||
H5PLibraryDetails.updatePager = function () {
|
||||
H5PLibraryDetails.$pagerInfo.css({display: 'inline-block'});
|
||||
|
||||
if (H5PLibraryDetails.getNumPages() > 0) {
|
||||
var message = H5PUtils.translateReplace(H5PLibraryDetails.library.translations.pageXOfY, {
|
||||
'$x': (H5PLibraryDetails.currentPage+1),
|
||||
'$y': H5PLibraryDetails.getNumPages()
|
||||
});
|
||||
H5PLibraryDetails.$pagerInfo.html(message);
|
||||
}
|
||||
else {
|
||||
H5PLibraryDetails.$pagerInfo.html('');
|
||||
}
|
||||
|
||||
H5PLibraryDetails.$previous.toggleClass('disabled', H5PLibraryDetails.currentPage <= 0);
|
||||
H5PLibraryDetails.$next.toggleClass('disabled', H5PLibraryDetails.currentContent.length < (H5PLibraryDetails.currentPage+1)*H5PLibraryDetails.PAGER_SIZE);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the search element
|
||||
*/
|
||||
H5PLibraryDetails.createSearchElement = function () {
|
||||
|
||||
H5PLibraryDetails.$search = $('<div class="h5p-content-search"><input placeholder="' + H5PLibraryDetails.library.translations.filterPlaceholder + '" type="search"></div>');
|
||||
|
||||
var performSeach = function () {
|
||||
var searchString = $('.h5p-content-search > input').val();
|
||||
|
||||
// If search string same as previous, just do nothing
|
||||
if (H5PLibraryDetails.currentFilter === searchString) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (searchString.trim().length === 0) {
|
||||
// If empty search, use the complete list
|
||||
H5PLibraryDetails.currentContent = H5PLibraryDetails.library.content;
|
||||
}
|
||||
else if (H5PLibraryDetails.filterCache[searchString]) {
|
||||
// If search is cached, no need to filter
|
||||
H5PLibraryDetails.currentContent = H5PLibraryDetails.filterCache[searchString];
|
||||
}
|
||||
else {
|
||||
var listToFilter = H5PLibraryDetails.library.content;
|
||||
|
||||
// Check if we can filter the already filtered results (for performance)
|
||||
if (searchString.length > 1 && H5PLibraryDetails.currentFilter === searchString.substr(0, H5PLibraryDetails.currentFilter.length)) {
|
||||
listToFilter = H5PLibraryDetails.currentContent;
|
||||
}
|
||||
H5PLibraryDetails.currentContent = $.grep(listToFilter, function (content) {
|
||||
return content.title && content.title.match(new RegExp(searchString, 'i'));
|
||||
});
|
||||
}
|
||||
|
||||
H5PLibraryDetails.currentFilter = searchString;
|
||||
// Cache the current result
|
||||
H5PLibraryDetails.filterCache[searchString] = H5PLibraryDetails.currentContent;
|
||||
H5PLibraryDetails.currentPage = 0;
|
||||
H5PLibraryDetails.createContentTable();
|
||||
|
||||
// Display search results:
|
||||
if (H5PLibraryDetails.$searchResults) {
|
||||
H5PLibraryDetails.$searchResults.remove();
|
||||
}
|
||||
if (searchString.trim().length > 0) {
|
||||
H5PLibraryDetails.$searchResults = $('<span class="h5p-admin-search-results">' + H5PLibraryDetails.currentContent.length + ' hits on ' + H5PLibraryDetails.currentFilter + '</span>');
|
||||
H5PLibraryDetails.$search.append(H5PLibraryDetails.$searchResults);
|
||||
}
|
||||
H5PLibraryDetails.updatePager();
|
||||
};
|
||||
|
||||
var inputTimer;
|
||||
$('input', H5PLibraryDetails.$search).on('change keypress paste input', function () {
|
||||
// Here we start the filtering
|
||||
// We wait at least 500 ms after last input to perform search
|
||||
if (inputTimer) {
|
||||
clearTimeout(inputTimer);
|
||||
}
|
||||
|
||||
inputTimer = setTimeout( function () {
|
||||
performSeach();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
H5PLibraryDetails.$content.append(H5PLibraryDetails.$search);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates the page size selector
|
||||
*/
|
||||
H5PLibraryDetails.createPageSizeSelector = function () {
|
||||
H5PLibraryDetails.$search.append('<div class="h5p-admin-pager-size-selector">' + H5PLibraryDetails.library.translations.pageSizeSelectorLabel + ':<span data-page-size="10">10</span><span class="selected" data-page-size="20">20</span><span data-page-size="50">50</span><span data-page-size="100">100</span><span data-page-size="200">200</span></div>');
|
||||
|
||||
// Listen to clicks on the page size selector:
|
||||
$('.h5p-admin-pager-size-selector > span', H5PLibraryDetails.$search).on('click', function () {
|
||||
H5PLibraryDetails.PAGER_SIZE = $(this).data('page-size');
|
||||
$('.h5p-admin-pager-size-selector > span', H5PLibraryDetails.$search).removeClass('selected');
|
||||
$(this).addClass('selected');
|
||||
H5PLibraryDetails.currentPage = 0;
|
||||
H5PLibraryDetails.createContentTable();
|
||||
H5PLibraryDetails.updatePager();
|
||||
});
|
||||
};
|
||||
|
||||
// Initialize me:
|
||||
$(document).ready(function () {
|
||||
if (!H5PLibraryDetails.initialized) {
|
||||
H5PLibraryDetails.initialized = true;
|
||||
H5PLibraryDetails.init();
|
||||
}
|
||||
});
|
||||
|
||||
})(H5P.jQuery);
|
140
lib/h5p/js/h5p-library-list.js
Normal file
140
lib/h5p/js/h5p-library-list.js
Normal file
@ -0,0 +1,140 @@
|
||||
/* global H5PAdminIntegration H5PUtils */
|
||||
var H5PLibraryList = H5PLibraryList || {};
|
||||
|
||||
(function ($) {
|
||||
|
||||
/**
|
||||
* Initializing
|
||||
*/
|
||||
H5PLibraryList.init = function () {
|
||||
var $adminContainer = H5P.jQuery(H5PAdminIntegration.containerSelector).html('');
|
||||
|
||||
var libraryList = H5PAdminIntegration.libraryList;
|
||||
if (libraryList.notCached) {
|
||||
$adminContainer.append(H5PUtils.getRebuildCache(libraryList.notCached));
|
||||
}
|
||||
|
||||
// Create library list
|
||||
$adminContainer.append(H5PLibraryList.createLibraryList(H5PAdminIntegration.libraryList));
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the library list
|
||||
*
|
||||
* @param {object} libraries List of libraries and headers
|
||||
*/
|
||||
H5PLibraryList.createLibraryList = function (libraries) {
|
||||
var t = H5PAdminIntegration.l10n;
|
||||
if (libraries.listData === undefined || libraries.listData.length === 0) {
|
||||
return $('<div>' + t.NA + '</div>');
|
||||
}
|
||||
|
||||
// Create table
|
||||
var $table = H5PUtils.createTable(libraries.listHeaders);
|
||||
$table.addClass('libraries');
|
||||
|
||||
// Add libraries
|
||||
$.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'
|
||||
},
|
||||
{
|
||||
text: library.numContentDependencies,
|
||||
class: 'h5p-admin-center'
|
||||
},
|
||||
{
|
||||
text: library.numLibraryDependencies,
|
||||
class: 'h5p-admin-center'
|
||||
},
|
||||
'<div class="h5p-admin-buttons-wrapper">' +
|
||||
'<button class="h5p-admin-upgrade-library"></button>' +
|
||||
(library.detailsUrl ? '<button class="h5p-admin-view-library" title="' + t.viewLibrary + '"></button>' : '') +
|
||||
(library.deleteUrl ? '<button class="h5p-admin-delete-library"></button>' : '') +
|
||||
'</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();
|
||||
}
|
||||
else if (library.upgradeUrl === false || !hasContent) {
|
||||
$('.h5p-admin-upgrade-library', $libraryRow).attr('disabled', true);
|
||||
}
|
||||
else {
|
||||
$('.h5p-admin-upgrade-library', $libraryRow).attr('title', t.upgradeLibrary).click(function () {
|
||||
window.location.href = library.upgradeUrl;
|
||||
});
|
||||
}
|
||||
|
||||
// Open details view when clicked
|
||||
$('.h5p-admin-view-library', $libraryRow).on('click', function () {
|
||||
window.location.href = library.detailsUrl;
|
||||
});
|
||||
|
||||
var $deleteButton = $('.h5p-admin-delete-library', $libraryRow);
|
||||
if (libraries.notCached !== undefined ||
|
||||
hasContent ||
|
||||
(library.numContentDependencies !== '' &&
|
||||
library.numContentDependencies !== 0) ||
|
||||
(library.numLibraryDependencies !== '' &&
|
||||
library.numLibraryDependencies !== 0)) {
|
||||
// Disabled delete if content.
|
||||
$deleteButton.attr('disabled', true);
|
||||
}
|
||||
else {
|
||||
// Go to delete page om click.
|
||||
$deleteButton.attr('title', t.deleteLibrary).on('click', function () {
|
||||
window.location.href = library.deleteUrl;
|
||||
});
|
||||
}
|
||||
|
||||
$table.append($libraryRow);
|
||||
});
|
||||
|
||||
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 () {
|
||||
if (!H5PLibraryList.initialized) {
|
||||
H5PLibraryList.initialized = true;
|
||||
H5PLibraryList.init();
|
||||
}
|
||||
});
|
||||
|
||||
})(H5P.jQuery);
|
506
lib/h5p/js/h5p-utils.js
Normal file
506
lib/h5p/js/h5p-utils.js
Normal file
@ -0,0 +1,506 @@
|
||||
/* global H5PAdminIntegration*/
|
||||
var H5PUtils = H5PUtils || {};
|
||||
|
||||
(function ($) {
|
||||
/**
|
||||
* Generic function for creating a table including the headers
|
||||
*
|
||||
* @param {array} headers List of headers
|
||||
*/
|
||||
H5PUtils.createTable = function (headers) {
|
||||
var $table = $('<table class="h5p-admin-table' + (H5PAdminIntegration.extraTableClasses !== undefined ? ' ' + H5PAdminIntegration.extraTableClasses : '') + '"></table>');
|
||||
|
||||
if (headers) {
|
||||
var $thead = $('<thead></thead>');
|
||||
var $tr = $('<tr></tr>');
|
||||
|
||||
$.each(headers, function (index, value) {
|
||||
if (!(value instanceof Object)) {
|
||||
value = {
|
||||
html: value
|
||||
};
|
||||
}
|
||||
|
||||
$('<th/>', value).appendTo($tr);
|
||||
});
|
||||
|
||||
$table.append($thead.append($tr));
|
||||
}
|
||||
|
||||
return $table;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic function for creating a table row
|
||||
*
|
||||
* @param {array} rows Value list. Object name is used as class name in <TD>
|
||||
*/
|
||||
H5PUtils.createTableRow = function (rows) {
|
||||
var $tr = $('<tr></tr>');
|
||||
|
||||
$.each(rows, function (index, value) {
|
||||
if (!(value instanceof Object)) {
|
||||
value = {
|
||||
html: value
|
||||
};
|
||||
}
|
||||
|
||||
$('<td/>', value).appendTo($tr);
|
||||
});
|
||||
|
||||
return $tr;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic function for creating a field containing label and value
|
||||
*
|
||||
* @param {string} label The label displayed in front of the value
|
||||
* @param {string} value The value
|
||||
*/
|
||||
H5PUtils.createLabeledField = function (label, value) {
|
||||
var $field = $('<div class="h5p-labeled-field"></div>');
|
||||
|
||||
$field.append('<div class="h5p-label">' + label + '</div>');
|
||||
$field.append('<div class="h5p-value">' + value + '</div>');
|
||||
|
||||
return $field;
|
||||
};
|
||||
|
||||
/**
|
||||
* Replaces placeholder fields in translation strings
|
||||
*
|
||||
* @param {string} template The translation template string in the following format: "$name is a $sex"
|
||||
* @param {array} replacors An js object with key and values. Eg: {'$name': 'Frode', '$sex': 'male'}
|
||||
*/
|
||||
H5PUtils.translateReplace = function (template, replacors) {
|
||||
$.each(replacors, function (key, value) {
|
||||
template = template.replace(new RegExp('\\'+key, 'g'), value);
|
||||
});
|
||||
return template;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get throbber with given text.
|
||||
*
|
||||
* @param {String} text
|
||||
* @returns {$}
|
||||
*/
|
||||
H5PUtils.throbber = function (text) {
|
||||
return $('<div/>', {
|
||||
class: 'h5p-throbber',
|
||||
text: text
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes it possbile to rebuild all content caches from admin UI.
|
||||
* @param {Object} notCached
|
||||
* @returns {$}
|
||||
*/
|
||||
H5PUtils.getRebuildCache = function (notCached) {
|
||||
var $container = $('<div class="h5p-admin-rebuild-cache"><p class="message">' + notCached.message + '</p><p class="progress">' + notCached.progress + '</p></div>');
|
||||
var $button = $('<button>' + notCached.button + '</button>').appendTo($container).click(function () {
|
||||
var $spinner = $('<div/>', {class: 'h5p-spinner'}).replaceAll($button);
|
||||
var parts = ['|', '/', '-', '\\'];
|
||||
var current = 0;
|
||||
var spinning = setInterval(function () {
|
||||
$spinner.text(parts[current]);
|
||||
current++;
|
||||
if (current === parts.length) current = 0;
|
||||
}, 100);
|
||||
|
||||
var $counter = $container.find('.progress');
|
||||
var build = function () {
|
||||
$.post(notCached.url, function (left) {
|
||||
if (left === '0') {
|
||||
clearInterval(spinning);
|
||||
$container.remove();
|
||||
location.reload();
|
||||
}
|
||||
else {
|
||||
var counter = $counter.text().split(' ');
|
||||
counter[0] = left;
|
||||
$counter.text(counter.join(' '));
|
||||
build();
|
||||
}
|
||||
});
|
||||
};
|
||||
build();
|
||||
});
|
||||
|
||||
return $container;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic table class with useful helpers.
|
||||
*
|
||||
* @class
|
||||
* @param {Object} classes
|
||||
* Custom html classes to use on elements.
|
||||
* e.g. {tableClass: 'fixed'}.
|
||||
*/
|
||||
H5PUtils.Table = function (classes) {
|
||||
var numCols;
|
||||
var sortByCol;
|
||||
var $sortCol;
|
||||
var sortCol;
|
||||
var sortDir;
|
||||
|
||||
// Create basic table
|
||||
var tableOptions = {};
|
||||
if (classes.table !== undefined) {
|
||||
tableOptions['class'] = classes.table;
|
||||
}
|
||||
var $table = $('<table/>', tableOptions);
|
||||
var $thead = $('<thead/>').appendTo($table);
|
||||
var $tfoot = $('<tfoot/>').appendTo($table);
|
||||
var $tbody = $('<tbody/>').appendTo($table);
|
||||
|
||||
/**
|
||||
* Add columns to given table row.
|
||||
*
|
||||
* @private
|
||||
* @param {jQuery} $tr Table row
|
||||
* @param {(String|Object)} col Column properties
|
||||
* @param {Number} id Used to seperate the columns
|
||||
*/
|
||||
var addCol = function ($tr, col, id) {
|
||||
var options = {
|
||||
on: {}
|
||||
};
|
||||
|
||||
if (!(col instanceof Object)) {
|
||||
options.text = col;
|
||||
}
|
||||
else {
|
||||
if (col.text !== undefined) {
|
||||
options.text = col.text;
|
||||
}
|
||||
if (col.class !== undefined) {
|
||||
options.class = col.class;
|
||||
}
|
||||
|
||||
if (sortByCol !== undefined && col.sortable === true) {
|
||||
// Make sortable
|
||||
options.role = 'button';
|
||||
options.tabIndex = 0;
|
||||
|
||||
// This is the first sortable column, use as default sort
|
||||
if (sortCol === undefined) {
|
||||
sortCol = id;
|
||||
sortDir = 0;
|
||||
}
|
||||
|
||||
// This is the sort column
|
||||
if (sortCol === id) {
|
||||
options['class'] = 'h5p-sort';
|
||||
if (sortDir === 1) {
|
||||
options['class'] += ' h5p-reverse';
|
||||
}
|
||||
}
|
||||
|
||||
options.on.click = function () {
|
||||
sort($th, id);
|
||||
};
|
||||
options.on.keypress = function (event) {
|
||||
if ((event.charCode || event.keyCode) === 32) { // Space
|
||||
sort($th, id);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Append
|
||||
var $th = $('<th>', options).appendTo($tr);
|
||||
if (sortCol === id) {
|
||||
$sortCol = $th; // Default sort column
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the UI when a column header has been clicked.
|
||||
* Triggers sorting callback.
|
||||
*
|
||||
* @private
|
||||
* @param {jQuery} $th Table header
|
||||
* @param {Number} id Used to seperate the columns
|
||||
*/
|
||||
var sort = function ($th, id) {
|
||||
if (id === sortCol) {
|
||||
// Change sorting direction
|
||||
if (sortDir === 0) {
|
||||
sortDir = 1;
|
||||
$th.addClass('h5p-reverse');
|
||||
}
|
||||
else {
|
||||
sortDir = 0;
|
||||
$th.removeClass('h5p-reverse');
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Change sorting column
|
||||
$sortCol.removeClass('h5p-sort').removeClass('h5p-reverse');
|
||||
$sortCol = $th.addClass('h5p-sort');
|
||||
sortCol = id;
|
||||
sortDir = 0;
|
||||
}
|
||||
|
||||
sortByCol({
|
||||
by: sortCol,
|
||||
dir: sortDir
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Set table headers.
|
||||
*
|
||||
* @public
|
||||
* @param {Array} cols
|
||||
* Table header data. Can be strings or objects with options like
|
||||
* "text" and "sortable". E.g.
|
||||
* [{text: 'Col 1', sortable: true}, 'Col 2', 'Col 3']
|
||||
* @param {Function} sort Callback which is runned when sorting changes
|
||||
* @param {Object} [order]
|
||||
*/
|
||||
this.setHeaders = function (cols, sort, order) {
|
||||
numCols = cols.length;
|
||||
sortByCol = sort;
|
||||
|
||||
if (order) {
|
||||
sortCol = order.by;
|
||||
sortDir = order.dir;
|
||||
}
|
||||
|
||||
// Create new head
|
||||
var $newThead = $('<thead/>');
|
||||
var $tr = $('<tr/>').appendTo($newThead);
|
||||
for (var i = 0; i < cols.length; i++) {
|
||||
addCol($tr, cols[i], i);
|
||||
}
|
||||
|
||||
// Update DOM
|
||||
$thead.replaceWith($newThead);
|
||||
$thead = $newThead;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set table rows.
|
||||
*
|
||||
* @public
|
||||
* @param {Array} rows Table rows with cols: [[1,'hello',3],[2,'asd',6]]
|
||||
*/
|
||||
this.setRows = function (rows) {
|
||||
var $newTbody = $('<tbody/>');
|
||||
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
var $tr = $('<tr/>').appendTo($newTbody);
|
||||
|
||||
for (var j = 0; j < rows[i].length; j++) {
|
||||
$('<td>', {
|
||||
html: rows[i][j]
|
||||
}).appendTo($tr);
|
||||
}
|
||||
}
|
||||
|
||||
$tbody.replaceWith($newTbody);
|
||||
$tbody = $newTbody;
|
||||
|
||||
return $tbody;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set custom table body content. This can be a message or a throbber.
|
||||
* Will cover all table columns.
|
||||
*
|
||||
* @public
|
||||
* @param {jQuery} $content Custom content
|
||||
*/
|
||||
this.setBody = function ($content) {
|
||||
var $newTbody = $('<tbody/>');
|
||||
var $tr = $('<tr/>').appendTo($newTbody);
|
||||
$('<td>', {
|
||||
colspan: numCols
|
||||
}).append($content).appendTo($tr);
|
||||
$tbody.replaceWith($newTbody);
|
||||
$tbody = $newTbody;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set custom table foot content. This can be a pagination widget.
|
||||
* Will cover all table columns.
|
||||
*
|
||||
* @public
|
||||
* @param {jQuery} $content Custom content
|
||||
*/
|
||||
this.setFoot = function ($content) {
|
||||
var $newTfoot = $('<tfoot/>');
|
||||
var $tr = $('<tr/>').appendTo($newTfoot);
|
||||
$('<td>', {
|
||||
colspan: numCols
|
||||
}).append($content).appendTo($tr);
|
||||
$tfoot.replaceWith($newTfoot);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Appends the table to the given container.
|
||||
*
|
||||
* @public
|
||||
* @param {jQuery} $container
|
||||
*/
|
||||
this.appendTo = function ($container) {
|
||||
$table.appendTo($container);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Generic pagination class. Creates a useful pagination widget.
|
||||
*
|
||||
* @class
|
||||
* @param {Number} num Total number of items to pagiate.
|
||||
* @param {Number} limit Number of items to dispaly per page.
|
||||
* @param {Function} goneTo
|
||||
* Callback which is fired when the user wants to go to another page.
|
||||
* @param {Object} l10n
|
||||
* Localization / translations. e.g.
|
||||
* {
|
||||
* currentPage: 'Page $current of $total',
|
||||
* nextPage: 'Next page',
|
||||
* previousPage: 'Previous page'
|
||||
* }
|
||||
*/
|
||||
H5PUtils.Pagination = function (num, limit, goneTo, l10n) {
|
||||
var current = 0;
|
||||
var pages = Math.ceil(num / limit);
|
||||
|
||||
// Create components
|
||||
|
||||
// Previous button
|
||||
var $left = $('<button/>', {
|
||||
html: '<',
|
||||
'class': 'button',
|
||||
title: l10n.previousPage
|
||||
}).click(function () {
|
||||
goTo(current - 1);
|
||||
});
|
||||
|
||||
// Current page text
|
||||
var $text = $('<span/>').click(function () {
|
||||
$input.width($text.width()).show().val(current + 1).focus();
|
||||
$text.hide();
|
||||
});
|
||||
|
||||
// Jump to page input
|
||||
var $input = $('<input/>', {
|
||||
type: 'number',
|
||||
min : 1,
|
||||
max: pages,
|
||||
on: {
|
||||
'blur': function () {
|
||||
gotInput();
|
||||
},
|
||||
'keyup': function (event) {
|
||||
if (event.keyCode === 13) {
|
||||
gotInput();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).hide();
|
||||
|
||||
// Next button
|
||||
var $right = $('<button/>', {
|
||||
html: '>',
|
||||
'class': 'button',
|
||||
title: l10n.nextPage
|
||||
}).click(function () {
|
||||
goTo(current + 1);
|
||||
});
|
||||
|
||||
/**
|
||||
* Check what page the user has typed in and jump to it.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
var gotInput = function () {
|
||||
var page = parseInt($input.hide().val());
|
||||
if (!isNaN(page)) {
|
||||
goTo(page - 1);
|
||||
}
|
||||
$text.show();
|
||||
};
|
||||
|
||||
/**
|
||||
* Update UI elements.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
var updateUI = function () {
|
||||
var next = current + 1;
|
||||
|
||||
// Disable or enable buttons
|
||||
$left.attr('disabled', current === 0);
|
||||
$right.attr('disabled', next === pages);
|
||||
|
||||
// Update counter
|
||||
$text.html(l10n.currentPage.replace('$current', next).replace('$total', pages));
|
||||
};
|
||||
|
||||
/**
|
||||
* Try to go to the requested page.
|
||||
*
|
||||
* @private
|
||||
* @param {Number} page
|
||||
*/
|
||||
var goTo = function (page) {
|
||||
if (page === current || page < 0 || page >= pages) {
|
||||
return; // Invalid page number
|
||||
}
|
||||
current = page;
|
||||
|
||||
updateUI();
|
||||
|
||||
// Fire callback
|
||||
goneTo(page * limit);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update number of items and limit.
|
||||
*
|
||||
* @public
|
||||
* @param {Number} newNum Total number of items to pagiate.
|
||||
* @param {Number} newLimit Number of items to dispaly per page.
|
||||
*/
|
||||
this.update = function (newNum, newLimit) {
|
||||
if (newNum !== num || newLimit !== limit) {
|
||||
// Update num and limit
|
||||
num = newNum;
|
||||
limit = newLimit;
|
||||
pages = Math.ceil(num / limit);
|
||||
$input.attr('max', pages);
|
||||
|
||||
if (current >= pages) {
|
||||
// Content is gone, move to last page.
|
||||
goTo(pages - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
updateUI();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Append the pagination widget to the given container.
|
||||
*
|
||||
* @public
|
||||
* @param {jQuery} $container
|
||||
*/
|
||||
this.appendTo = function ($container) {
|
||||
$left.add($text).add($input).add($right).appendTo($container);
|
||||
};
|
||||
|
||||
// Update UI
|
||||
updateUI();
|
||||
};
|
||||
|
||||
})(H5P.jQuery);
|
40
lib/h5p/js/h5p-version.js
Normal file
40
lib/h5p/js/h5p-version.js
Normal file
@ -0,0 +1,40 @@
|
||||
H5P.Version = (function () {
|
||||
/**
|
||||
* Make it easy to keep track of version details.
|
||||
*
|
||||
* @class
|
||||
* @namespace H5P
|
||||
* @param {String} version
|
||||
*/
|
||||
function Version(version) {
|
||||
|
||||
if (typeof version === 'string') {
|
||||
// Name version string (used by content upgrade)
|
||||
var versionSplit = version.split('.', 3);
|
||||
this.major =+ versionSplit[0];
|
||||
this.minor =+ versionSplit[1];
|
||||
}
|
||||
else {
|
||||
// Library objects (used by editor)
|
||||
if (version.localMajorVersion !== undefined) {
|
||||
this.major =+ version.localMajorVersion;
|
||||
this.minor =+ version.localMinorVersion;
|
||||
}
|
||||
else {
|
||||
this.major =+ version.majorVersion;
|
||||
this.minor =+ version.minorVersion;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Public. Custom string for this object.
|
||||
*
|
||||
* @returns {String}
|
||||
*/
|
||||
this.toString = function () {
|
||||
return version;
|
||||
};
|
||||
}
|
||||
|
||||
return Version;
|
||||
})();
|
331
lib/h5p/js/h5p-x-api-event.js
Normal file
331
lib/h5p/js/h5p-x-api-event.js
Normal file
@ -0,0 +1,331 @@
|
||||
var H5P = window.H5P = window.H5P || {};
|
||||
|
||||
/**
|
||||
* Used for xAPI events.
|
||||
*
|
||||
* @class
|
||||
* @extends H5P.Event
|
||||
*/
|
||||
H5P.XAPIEvent = function () {
|
||||
H5P.Event.call(this, 'xAPI', {'statement': {}}, {bubbles: true, external: true});
|
||||
};
|
||||
|
||||
H5P.XAPIEvent.prototype = Object.create(H5P.Event.prototype);
|
||||
H5P.XAPIEvent.prototype.constructor = H5P.XAPIEvent;
|
||||
|
||||
/**
|
||||
* Set scored result statements.
|
||||
*
|
||||
* @param {number} score
|
||||
* @param {number} maxScore
|
||||
* @param {object} instance
|
||||
* @param {boolean} completion
|
||||
* @param {boolean} success
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance, completion, success) {
|
||||
this.data.statement.result = {};
|
||||
|
||||
if (typeof score !== 'undefined') {
|
||||
if (typeof maxScore === 'undefined') {
|
||||
this.data.statement.result.score = {'raw': score};
|
||||
}
|
||||
else {
|
||||
this.data.statement.result.score = {
|
||||
'min': 0,
|
||||
'max': maxScore,
|
||||
'raw': score
|
||||
};
|
||||
if (maxScore > 0) {
|
||||
this.data.statement.result.score.scaled = Math.round(score / maxScore * 10000) / 10000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof completion === 'undefined') {
|
||||
this.data.statement.result.completion = (this.getVerb() === 'completed' || this.getVerb() === 'answered');
|
||||
}
|
||||
else {
|
||||
this.data.statement.result.completion = completion;
|
||||
}
|
||||
|
||||
if (typeof success !== 'undefined') {
|
||||
this.data.statement.result.success = success;
|
||||
}
|
||||
|
||||
if (instance && instance.activityStartTime) {
|
||||
var duration = Math.round((Date.now() - instance.activityStartTime ) / 10) / 100;
|
||||
// xAPI spec allows a precision of 0.01 seconds
|
||||
|
||||
this.data.statement.result.duration = 'PT' + duration + 'S';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set a verb.
|
||||
*
|
||||
* @param {string} verb
|
||||
* Verb in short form, one of the verbs defined at
|
||||
* {@link http://adlnet.gov/expapi/verbs/|ADL xAPI Vocabulary}
|
||||
*
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.setVerb = function (verb) {
|
||||
if (H5P.jQuery.inArray(verb, H5P.XAPIEvent.allowedXAPIVerbs) !== -1) {
|
||||
this.data.statement.verb = {
|
||||
'id': 'http://adlnet.gov/expapi/verbs/' + verb,
|
||||
'display': {
|
||||
'en-US': verb
|
||||
}
|
||||
};
|
||||
}
|
||||
else if (verb.id !== undefined) {
|
||||
this.data.statement.verb = verb;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the statements verb id.
|
||||
*
|
||||
* @param {boolean} full
|
||||
* if true the full verb id prefixed by http://adlnet.gov/expapi/verbs/
|
||||
* will be returned
|
||||
* @returns {string}
|
||||
* Verb or null if no verb with an id has been defined
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.getVerb = function (full) {
|
||||
var statement = this.data.statement;
|
||||
if ('verb' in statement) {
|
||||
if (full === true) {
|
||||
return statement.verb;
|
||||
}
|
||||
return statement.verb.id.slice(31);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the object part of the statement.
|
||||
*
|
||||
* The id is found automatically (the url to the content)
|
||||
*
|
||||
* @param {Object} instance
|
||||
* The H5P instance
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.setObject = function (instance) {
|
||||
if (instance.contentId) {
|
||||
this.data.statement.object = {
|
||||
'id': this.getContentXAPIId(instance),
|
||||
'objectType': 'Activity',
|
||||
'definition': {
|
||||
'extensions': {
|
||||
'http://h5p.org/x-api/h5p-local-content-id': instance.contentId
|
||||
}
|
||||
}
|
||||
};
|
||||
if (instance.subContentId) {
|
||||
this.data.statement.object.definition.extensions['http://h5p.org/x-api/h5p-subContentId'] = instance.subContentId;
|
||||
// Don't set titles on main content, title should come from publishing platform
|
||||
if (typeof instance.getTitle === 'function') {
|
||||
this.data.statement.object.definition.name = {
|
||||
"en-US": instance.getTitle()
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
var content = H5P.getContentForInstance(instance.contentId);
|
||||
if (content && content.metadata && content.metadata.title) {
|
||||
this.data.statement.object.definition.name = {
|
||||
"en-US": H5P.createTitle(content.metadata.title)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Content types view always expect to have a contentId when they are displayed.
|
||||
// This is not the case if they are displayed in the editor as part of a preview.
|
||||
// The fix is to set an empty object with definition for the xAPI event, so all
|
||||
// the content types that rely on this does not have to handle it. This means
|
||||
// that content types that are being previewed will send xAPI completed events,
|
||||
// but since there are no scripts that catch these events in the editor,
|
||||
// this is not a problem.
|
||||
this.data.statement.object = {
|
||||
definition: {}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the context part of the statement.
|
||||
*
|
||||
* @param {Object} instance
|
||||
* The H5P instance
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.setContext = function (instance) {
|
||||
if (instance.parent && (instance.parent.contentId || instance.parent.subContentId)) {
|
||||
this.data.statement.context = {
|
||||
"contextActivities": {
|
||||
"parent": [
|
||||
{
|
||||
"id": this.getContentXAPIId(instance.parent),
|
||||
"objectType": "Activity"
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
if (instance.libraryInfo) {
|
||||
if (this.data.statement.context === undefined) {
|
||||
this.data.statement.context = {"contextActivities":{}};
|
||||
}
|
||||
this.data.statement.context.contextActivities.category = [
|
||||
{
|
||||
"id": "http://h5p.org/libraries/" + instance.libraryInfo.versionedNameNoSpaces,
|
||||
"objectType": "Activity"
|
||||
}
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the actor. Email and name will be added automatically.
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.setActor = function () {
|
||||
if (H5PIntegration.user !== undefined) {
|
||||
this.data.statement.actor = {
|
||||
'name': H5PIntegration.user.name,
|
||||
'mbox': 'mailto:' + H5PIntegration.user.mail,
|
||||
'objectType': 'Agent'
|
||||
};
|
||||
}
|
||||
else {
|
||||
var uuid;
|
||||
try {
|
||||
if (localStorage.H5PUserUUID) {
|
||||
uuid = localStorage.H5PUserUUID;
|
||||
}
|
||||
else {
|
||||
uuid = H5P.createUUID();
|
||||
localStorage.H5PUserUUID = uuid;
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
// LocalStorage and Cookies are probably disabled. Do not track the user.
|
||||
uuid = 'not-trackable-' + H5P.createUUID();
|
||||
}
|
||||
this.data.statement.actor = {
|
||||
'account': {
|
||||
'name': uuid,
|
||||
'homePage': H5PIntegration.siteUrl
|
||||
},
|
||||
'objectType': 'Agent'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the max value of the result - score part of the statement
|
||||
*
|
||||
* @returns {number}
|
||||
* The max score, or null if not defined
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.getMaxScore = function () {
|
||||
return this.getVerifiedStatementValue(['result', 'score', 'max']);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the raw value of the result - score part of the statement
|
||||
*
|
||||
* @returns {number}
|
||||
* The score, or null if not defined
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.getScore = function () {
|
||||
return this.getVerifiedStatementValue(['result', 'score', 'raw']);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get content xAPI ID.
|
||||
*
|
||||
* @param {Object} instance
|
||||
* The H5P instance
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.getContentXAPIId = function (instance) {
|
||||
var xAPIId;
|
||||
if (instance.contentId && H5PIntegration && H5PIntegration.contents && H5PIntegration.contents['cid-' + instance.contentId]) {
|
||||
xAPIId = H5PIntegration.contents['cid-' + instance.contentId].url;
|
||||
if (instance.subContentId) {
|
||||
xAPIId += '?subContentId=' + instance.subContentId;
|
||||
}
|
||||
}
|
||||
return xAPIId;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if this event is sent from a child (i.e not from grandchild)
|
||||
*
|
||||
* @return {Boolean}
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.isFromChild = function () {
|
||||
var parentId = this.getVerifiedStatementValue(['context', 'contextActivities', 'parent', 0, 'id']);
|
||||
return !parentId || parentId.indexOf('subContentId') === -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Figure out if a property exists in the statement and return it
|
||||
*
|
||||
* @param {string[]} keys
|
||||
* List describing the property we're looking for. For instance
|
||||
* ['result', 'score', 'raw'] for result.score.raw
|
||||
* @returns {*}
|
||||
* The value of the property if it is set, null otherwise.
|
||||
*/
|
||||
H5P.XAPIEvent.prototype.getVerifiedStatementValue = function (keys) {
|
||||
var val = this.data.statement;
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if (val[keys[i]] === undefined) {
|
||||
return null;
|
||||
}
|
||||
val = val[keys[i]];
|
||||
}
|
||||
return val;
|
||||
};
|
||||
|
||||
/**
|
||||
* List of verbs defined at {@link http://adlnet.gov/expapi/verbs/|ADL xAPI Vocabulary}
|
||||
*
|
||||
* @type Array
|
||||
*/
|
||||
H5P.XAPIEvent.allowedXAPIVerbs = [
|
||||
'answered',
|
||||
'asked',
|
||||
'attempted',
|
||||
'attended',
|
||||
'commented',
|
||||
'completed',
|
||||
'exited',
|
||||
'experienced',
|
||||
'failed',
|
||||
'imported',
|
||||
'initialized',
|
||||
'interacted',
|
||||
'launched',
|
||||
'mastered',
|
||||
'passed',
|
||||
'preferred',
|
||||
'progressed',
|
||||
'registered',
|
||||
'responded',
|
||||
'resumed',
|
||||
'scored',
|
||||
'shared',
|
||||
'suspended',
|
||||
'terminated',
|
||||
'voided',
|
||||
|
||||
// Custom verbs used for action toolbar below content
|
||||
'downloaded',
|
||||
'copied',
|
||||
'accessed-reuse',
|
||||
'accessed-embed',
|
||||
'accessed-copyright'
|
||||
];
|
119
lib/h5p/js/h5p-x-api.js
Normal file
119
lib/h5p/js/h5p-x-api.js
Normal file
@ -0,0 +1,119 @@
|
||||
var H5P = window.H5P = window.H5P || {};
|
||||
|
||||
/**
|
||||
* The external event dispatcher. Others, outside of H5P may register and
|
||||
* listen for H5P Events here.
|
||||
*
|
||||
* @type {H5P.EventDispatcher}
|
||||
*/
|
||||
H5P.externalDispatcher = new H5P.EventDispatcher();
|
||||
|
||||
// EventDispatcher extensions
|
||||
|
||||
/**
|
||||
* Helper function for triggering xAPI added to the EventDispatcher.
|
||||
*
|
||||
* @param {string} verb
|
||||
* The short id of the verb we want to trigger
|
||||
* @param {Oject} [extra]
|
||||
* Extra properties for the xAPI statement
|
||||
*/
|
||||
H5P.EventDispatcher.prototype.triggerXAPI = function (verb, extra) {
|
||||
this.trigger(this.createXAPIEventTemplate(verb, extra));
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to create event templates added to the EventDispatcher.
|
||||
*
|
||||
* Will in the future be used to add representations of the questions to the
|
||||
* statements.
|
||||
*
|
||||
* @param {string} verb
|
||||
* Verb id in short form
|
||||
* @param {Object} [extra]
|
||||
* Extra values to be added to the statement
|
||||
* @returns {H5P.XAPIEvent}
|
||||
* Instance
|
||||
*/
|
||||
H5P.EventDispatcher.prototype.createXAPIEventTemplate = function (verb, extra) {
|
||||
var event = new H5P.XAPIEvent();
|
||||
|
||||
event.setActor();
|
||||
event.setVerb(verb);
|
||||
if (extra !== undefined) {
|
||||
for (var i in extra) {
|
||||
event.data.statement[i] = extra[i];
|
||||
}
|
||||
}
|
||||
if (!('object' in event.data.statement)) {
|
||||
event.setObject(this);
|
||||
}
|
||||
if (!('context' in event.data.statement)) {
|
||||
event.setContext(this);
|
||||
}
|
||||
return event;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to create xAPI completed events
|
||||
*
|
||||
* DEPRECATED - USE triggerXAPIScored instead
|
||||
*
|
||||
* @deprecated
|
||||
* since 1.5, use triggerXAPIScored instead.
|
||||
* @param {number} score
|
||||
* Will be set as the 'raw' value of the score object
|
||||
* @param {number} maxScore
|
||||
* will be set as the "max" value of the score object
|
||||
* @param {boolean} success
|
||||
* will be set as the "success" value of the result object
|
||||
*/
|
||||
H5P.EventDispatcher.prototype.triggerXAPICompleted = function (score, maxScore, success) {
|
||||
this.triggerXAPIScored(score, maxScore, 'completed', true, success);
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to create scored xAPI events
|
||||
*
|
||||
* @param {number} score
|
||||
* Will be set as the 'raw' value of the score object
|
||||
* @param {number} maxScore
|
||||
* Will be set as the "max" value of the score object
|
||||
* @param {string} verb
|
||||
* Short form of adl verb
|
||||
* @param {boolean} completion
|
||||
* Is this a statement from a completed activity?
|
||||
* @param {boolean} success
|
||||
* Is this a statement from an activity that was done successfully?
|
||||
*/
|
||||
H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, verb, completion, success) {
|
||||
var event = this.createXAPIEventTemplate(verb);
|
||||
event.setScoredResult(score, maxScore, this, completion, success);
|
||||
this.trigger(event);
|
||||
};
|
||||
|
||||
H5P.EventDispatcher.prototype.setActivityStarted = function () {
|
||||
if (this.activityStartTime === undefined) {
|
||||
// Don't trigger xAPI events in the editor
|
||||
if (this.contentId !== undefined &&
|
||||
H5PIntegration.contents !== undefined &&
|
||||
H5PIntegration.contents['cid-' + this.contentId] !== undefined) {
|
||||
this.triggerXAPI('attempted');
|
||||
}
|
||||
this.activityStartTime = Date.now();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Internal H5P function listening for xAPI completed events and stores scores
|
||||
*
|
||||
* @param {H5P.XAPIEvent} event
|
||||
*/
|
||||
H5P.xAPICompletedListener = function (event) {
|
||||
if ((event.getVerb() === 'completed' || event.getVerb() === 'answered') && !event.getVerifiedStatementValue(['context', 'contextActivities', 'parent'])) {
|
||||
var score = event.getScore();
|
||||
var maxScore = event.getMaxScore();
|
||||
var contentId = event.getVerifiedStatementValue(['object', 'definition', 'extensions', 'http://h5p.org/x-api/h5p-local-content-id']);
|
||||
H5P.setFinished(contentId, score, maxScore);
|
||||
}
|
||||
};
|
2847
lib/h5p/js/h5p.js
Normal file
2847
lib/h5p/js/h5p.js
Normal file
File diff suppressed because it is too large
Load Diff
20
lib/h5p/js/jquery.js
vendored
Normal file
20
lib/h5p/js/jquery.js
vendored
Normal file
File diff suppressed because one or more lines are too long
436
lib/h5p/js/request-queue.js
Normal file
436
lib/h5p/js/request-queue.js
Normal file
@ -0,0 +1,436 @@
|
||||
/**
|
||||
* Queue requests and handle them at your convenience
|
||||
*
|
||||
* @type {RequestQueue}
|
||||
*/
|
||||
H5P.RequestQueue = (function ($, EventDispatcher) {
|
||||
/**
|
||||
* A queue for requests, will be automatically processed when regaining connection
|
||||
*
|
||||
* @param {boolean} [options.showToast] Show toast when losing or regaining connection
|
||||
* @constructor
|
||||
*/
|
||||
const RequestQueue = function (options) {
|
||||
EventDispatcher.call(this);
|
||||
this.processingQueue = false;
|
||||
options = options || {};
|
||||
|
||||
this.showToast = options.showToast;
|
||||
this.itemName = 'requestQueue';
|
||||
};
|
||||
|
||||
/**
|
||||
* Add request to queue. Only supports posts currently.
|
||||
*
|
||||
* @param {string} url
|
||||
* @param {Object} data
|
||||
* @returns {boolean}
|
||||
*/
|
||||
RequestQueue.prototype.add = function (url, data) {
|
||||
if (!window.localStorage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let storedStatements = this.getStoredRequests();
|
||||
if (!storedStatements) {
|
||||
storedStatements = [];
|
||||
}
|
||||
|
||||
storedStatements.push({
|
||||
url: url,
|
||||
data: data,
|
||||
});
|
||||
|
||||
window.localStorage.setItem(this.itemName, JSON.stringify(storedStatements));
|
||||
|
||||
this.trigger('requestQueued', {
|
||||
storedStatements: storedStatements,
|
||||
processingQueue: this.processingQueue,
|
||||
});
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get stored requests
|
||||
*
|
||||
* @returns {boolean|Array} Stored requests
|
||||
*/
|
||||
RequestQueue.prototype.getStoredRequests = function () {
|
||||
if (!window.localStorage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const item = window.localStorage.getItem(this.itemName);
|
||||
if (!item) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return JSON.parse(item);
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear stored requests
|
||||
*
|
||||
* @returns {boolean} True if the storage was successfully cleared
|
||||
*/
|
||||
RequestQueue.prototype.clearQueue = function () {
|
||||
if (!window.localStorage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
window.localStorage.removeItem(this.itemName);
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Start processing of requests queue
|
||||
*
|
||||
* @return {boolean} Returns false if it was not possible to resume processing queue
|
||||
*/
|
||||
RequestQueue.prototype.resumeQueue = function () {
|
||||
// Not supported
|
||||
if (!H5PIntegration || !window.navigator || !window.localStorage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Already processing
|
||||
if (this.processingQueue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Attempt to send queued requests
|
||||
const queue = this.getStoredRequests();
|
||||
const queueLength = queue.length;
|
||||
|
||||
// Clear storage, failed requests will be re-added
|
||||
this.clearQueue();
|
||||
|
||||
// No items left in queue
|
||||
if (!queueLength) {
|
||||
this.trigger('emptiedQueue', queue);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Make sure requests are not changed while they're being handled
|
||||
this.processingQueue = true;
|
||||
|
||||
// Process queue in original order
|
||||
this.processQueue(queue);
|
||||
return true
|
||||
};
|
||||
|
||||
/**
|
||||
* Process first item in the request queue
|
||||
*
|
||||
* @param {Array} queue Request queue
|
||||
*/
|
||||
RequestQueue.prototype.processQueue = function (queue) {
|
||||
if (!queue.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.trigger('processingQueue');
|
||||
|
||||
// Make sure the requests are processed in a FIFO order
|
||||
const request = queue.shift();
|
||||
|
||||
const self = this;
|
||||
$.post(request.url, request.data)
|
||||
.fail(self.onQueuedRequestFail.bind(self, request))
|
||||
.always(self.onQueuedRequestProcessed.bind(self, queue))
|
||||
};
|
||||
|
||||
/**
|
||||
* Request fail handler
|
||||
*
|
||||
* @param {Object} request
|
||||
*/
|
||||
RequestQueue.prototype.onQueuedRequestFail = function (request) {
|
||||
// Queue the failed request again if we're offline
|
||||
if (!window.navigator.onLine) {
|
||||
this.add(request.url, request.data);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* An item in the queue was processed
|
||||
*
|
||||
* @param {Array} queue Queue that was processed
|
||||
*/
|
||||
RequestQueue.prototype.onQueuedRequestProcessed = function (queue) {
|
||||
if (queue.length) {
|
||||
this.processQueue(queue);
|
||||
return;
|
||||
}
|
||||
|
||||
// Finished processing this queue
|
||||
this.processingQueue = false;
|
||||
|
||||
// Run empty queue callback with next request queue
|
||||
const requestQueue = this.getStoredRequests();
|
||||
this.trigger('queueEmptied', requestQueue);
|
||||
};
|
||||
|
||||
/**
|
||||
* Display toast message on the first content of current page
|
||||
*
|
||||
* @param {string} msg Message to display
|
||||
* @param {boolean} [forceShow] Force override showing the toast
|
||||
* @param {Object} [configOverride] Override toast message config
|
||||
*/
|
||||
RequestQueue.prototype.displayToastMessage = function (msg, forceShow, configOverride) {
|
||||
if (!this.showToast && !forceShow) {
|
||||
return;
|
||||
}
|
||||
|
||||
const config = H5P.jQuery.extend(true, {}, {
|
||||
position: {
|
||||
horizontal : 'centered',
|
||||
vertical: 'centered',
|
||||
noOverflowX: true,
|
||||
}
|
||||
}, configOverride);
|
||||
|
||||
H5P.attachToastTo(H5P.jQuery('.h5p-content:first')[0], msg, config);
|
||||
};
|
||||
|
||||
return RequestQueue;
|
||||
})(H5P.jQuery, H5P.EventDispatcher);
|
||||
|
||||
/**
|
||||
* Request queue for retrying failing requests, will automatically retry them when you come online
|
||||
*
|
||||
* @type {offlineRequestQueue}
|
||||
*/
|
||||
H5P.OfflineRequestQueue = (function (RequestQueue, Dialog) {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param {Object} [options] Options for offline request queue
|
||||
* @param {Object} [options.instance] The H5P instance which UI components are placed within
|
||||
*/
|
||||
const offlineRequestQueue = function (options) {
|
||||
const requestQueue = new RequestQueue();
|
||||
|
||||
// We could handle requests from previous pages here, but instead we throw them away
|
||||
requestQueue.clearQueue();
|
||||
|
||||
let startTime = null;
|
||||
const retryIntervals = [10, 20, 40, 60, 120, 300, 600];
|
||||
let intervalIndex = -1;
|
||||
let currentInterval = null;
|
||||
let isAttached = false;
|
||||
let isShowing = false;
|
||||
let isLoading = false;
|
||||
const instance = options.instance;
|
||||
|
||||
const offlineDialog = new Dialog({
|
||||
headerText: H5P.t('offlineDialogHeader'),
|
||||
dialogText: H5P.t('offlineDialogBody'),
|
||||
confirmText: H5P.t('offlineDialogRetryButtonLabel'),
|
||||
hideCancel: true,
|
||||
hideExit: true,
|
||||
classes: ['offline'],
|
||||
instance: instance,
|
||||
skipRestoreFocus: true,
|
||||
});
|
||||
|
||||
const dialog = offlineDialog.getElement();
|
||||
|
||||
// Add retry text to body
|
||||
const countDownText = document.createElement('div');
|
||||
countDownText.classList.add('count-down');
|
||||
countDownText.innerHTML = H5P.t('offlineDialogRetryMessage')
|
||||
.replace(':num', '<span class="count-down-num">0</span>');
|
||||
|
||||
dialog.querySelector('.h5p-confirmation-dialog-text').appendChild(countDownText);
|
||||
const countDownNum = countDownText.querySelector('.count-down-num');
|
||||
|
||||
// Create throbber
|
||||
const throbberWrapper = document.createElement('div');
|
||||
throbberWrapper.classList.add('throbber-wrapper');
|
||||
const throbber = document.createElement('div');
|
||||
throbber.classList.add('sending-requests-throbber');
|
||||
throbberWrapper.appendChild(throbber);
|
||||
|
||||
requestQueue.on('requestQueued', function (e) {
|
||||
// Already processing queue, wait until queue has finished processing before showing dialog
|
||||
if (e.data && e.data.processingQueue) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAttached) {
|
||||
const rootContent = document.body.querySelector('.h5p-content');
|
||||
if (!rootContent) {
|
||||
return;
|
||||
}
|
||||
offlineDialog.appendTo(rootContent);
|
||||
rootContent.appendChild(throbberWrapper);
|
||||
isAttached = true;
|
||||
}
|
||||
|
||||
startCountDown();
|
||||
}.bind(this));
|
||||
|
||||
requestQueue.on('queueEmptied', function (e) {
|
||||
if (e.data && e.data.length) {
|
||||
// New requests were added while processing queue or requests failed again. Re-queue requests.
|
||||
startCountDown(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Successfully emptied queue
|
||||
clearInterval(currentInterval);
|
||||
toggleThrobber(false);
|
||||
intervalIndex = -1;
|
||||
if (isShowing) {
|
||||
offlineDialog.hide();
|
||||
isShowing = false;
|
||||
}
|
||||
|
||||
requestQueue.displayToastMessage(
|
||||
H5P.t('offlineSuccessfulSubmit'),
|
||||
true,
|
||||
{
|
||||
position: {
|
||||
vertical: 'top',
|
||||
offsetVertical: '100',
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}.bind(this));
|
||||
|
||||
offlineDialog.on('confirmed', function () {
|
||||
// Show dialog on next render in case it is being hidden by the 'confirm' button
|
||||
isShowing = false;
|
||||
setTimeout(function () {
|
||||
retryRequests();
|
||||
}, 100);
|
||||
}.bind(this));
|
||||
|
||||
// Initialize listener for when requests are added to queue
|
||||
window.addEventListener('online', function () {
|
||||
retryRequests();
|
||||
}.bind(this));
|
||||
|
||||
// Listen for queued requests outside the iframe
|
||||
window.addEventListener('message', function (event) {
|
||||
const isValidQueueEvent = window.parent === event.source
|
||||
&& event.data.context === 'h5p'
|
||||
&& event.data.action === 'queueRequest';
|
||||
|
||||
if (!isValidQueueEvent) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.add(event.data.url, event.data.data);
|
||||
}.bind(this));
|
||||
|
||||
/**
|
||||
* Toggle throbber visibility
|
||||
*
|
||||
* @param {boolean} [forceShow] Will force throbber visibility if set
|
||||
*/
|
||||
const toggleThrobber = function (forceShow) {
|
||||
isLoading = !isLoading;
|
||||
if (forceShow !== undefined) {
|
||||
isLoading = forceShow;
|
||||
}
|
||||
|
||||
if (isLoading && isShowing) {
|
||||
offlineDialog.hide();
|
||||
isShowing = false;
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
throbberWrapper.classList.add('show');
|
||||
}
|
||||
else {
|
||||
throbberWrapper.classList.remove('show');
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Retries the failed requests
|
||||
*/
|
||||
const retryRequests = function () {
|
||||
clearInterval(currentInterval);
|
||||
toggleThrobber(true);
|
||||
requestQueue.resumeQueue();
|
||||
};
|
||||
|
||||
/**
|
||||
* Increments retry interval
|
||||
*/
|
||||
const incrementRetryInterval = function () {
|
||||
intervalIndex += 1;
|
||||
if (intervalIndex >= retryIntervals.length) {
|
||||
intervalIndex = retryIntervals.length - 1;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts counting down to retrying queued requests.
|
||||
*
|
||||
* @param forceDelayedShow
|
||||
*/
|
||||
const startCountDown = function (forceDelayedShow) {
|
||||
// Already showing, wait for retry
|
||||
if (isShowing) {
|
||||
return;
|
||||
}
|
||||
|
||||
toggleThrobber(false);
|
||||
if (!isShowing) {
|
||||
if (forceDelayedShow) {
|
||||
// Must force delayed show since dialog may be hiding, and confirmation dialog does not
|
||||
// support this.
|
||||
setTimeout(function () {
|
||||
offlineDialog.show(0);
|
||||
}, 100);
|
||||
}
|
||||
else {
|
||||
offlineDialog.show(0);
|
||||
}
|
||||
}
|
||||
isShowing = true;
|
||||
startTime = new Date().getTime();
|
||||
incrementRetryInterval();
|
||||
clearInterval(currentInterval);
|
||||
currentInterval = setInterval(updateCountDown, 100);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the count down timer. Retries requests when time expires.
|
||||
*/
|
||||
const updateCountDown = function () {
|
||||
const time = new Date().getTime();
|
||||
const timeElapsed = Math.floor((time - startTime) / 1000);
|
||||
const timeLeft = retryIntervals[intervalIndex] - timeElapsed;
|
||||
countDownNum.textContent = timeLeft.toString();
|
||||
|
||||
// Retry interval reached, retry requests
|
||||
if (timeLeft <= 0) {
|
||||
retryRequests();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add request to offline request queue. Only supports posts for now.
|
||||
*
|
||||
* @param {string} url The request url
|
||||
* @param {Object} data The request data
|
||||
*/
|
||||
this.add = function (url, data) {
|
||||
// Only queue request if it failed because we are offline
|
||||
if (window.navigator.onLine) {
|
||||
return false;
|
||||
}
|
||||
|
||||
requestQueue.add(url, data);
|
||||
};
|
||||
};
|
||||
|
||||
return offlineRequestQueue;
|
||||
})(H5P.RequestQueue, H5P.ConfirmationDialog);
|
68
lib/h5p/js/settings/h5p-disable-hub.js
Normal file
68
lib/h5p/js/settings/h5p-disable-hub.js
Normal file
@ -0,0 +1,68 @@
|
||||
/* global H5PDisableHubData */
|
||||
|
||||
/**
|
||||
* Global data for disable hub functionality
|
||||
*
|
||||
* @typedef {object} H5PDisableHubData Data passed in from the backend
|
||||
*
|
||||
* @property {string} selector Selector for the disable hub check-button
|
||||
* @property {string} overlaySelector Selector for the element that the confirmation dialog will mask
|
||||
* @property {Array} errors Errors found with the current server setup
|
||||
*
|
||||
* @property {string} header Header of the confirmation dialog
|
||||
* @property {string} confirmationDialogMsg Body of the confirmation dialog
|
||||
* @property {string} cancelLabel Cancel label of the confirmation dialog
|
||||
* @property {string} confirmLabel Confirm button label of the confirmation dialog
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Utility that makes it possible to force the user to confirm that he really
|
||||
* wants to use the H5P hub without proper server settings.
|
||||
*/
|
||||
(function ($) {
|
||||
|
||||
$(document).on('ready', function () {
|
||||
|
||||
// No data found
|
||||
if (!H5PDisableHubData) {
|
||||
return;
|
||||
}
|
||||
|
||||
// No errors found, no need for confirmation dialog
|
||||
if (!H5PDisableHubData.errors || !H5PDisableHubData.errors.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
H5PDisableHubData.selector = H5PDisableHubData.selector ||
|
||||
'.h5p-settings-disable-hub-checkbox';
|
||||
H5PDisableHubData.overlaySelector = H5PDisableHubData.overlaySelector ||
|
||||
'.h5p-settings-container';
|
||||
|
||||
var dialogHtml = '<div>' +
|
||||
'<p>' + H5PDisableHubData.errors.join('</p><p>') + '</p>' +
|
||||
'<p>' + H5PDisableHubData.confirmationDialogMsg + '</p>';
|
||||
|
||||
// Create confirmation dialog, make sure to include translations
|
||||
var confirmationDialog = new H5P.ConfirmationDialog({
|
||||
headerText: H5PDisableHubData.header,
|
||||
dialogText: dialogHtml,
|
||||
cancelText: H5PDisableHubData.cancelLabel,
|
||||
confirmText: H5PDisableHubData.confirmLabel
|
||||
}).appendTo($(H5PDisableHubData.overlaySelector).get(0));
|
||||
|
||||
confirmationDialog.on('confirmed', function () {
|
||||
enableButton.get(0).checked = true;
|
||||
});
|
||||
|
||||
confirmationDialog.on('canceled', function () {
|
||||
enableButton.get(0).checked = false;
|
||||
});
|
||||
|
||||
var enableButton = $(H5PDisableHubData.selector);
|
||||
enableButton.change(function () {
|
||||
if ($(this).is(':checked')) {
|
||||
confirmationDialog.show(enableButton.offset().top);
|
||||
}
|
||||
});
|
||||
});
|
||||
})(H5P.jQuery);
|
47
lib/h5p/readme_moodle.txt
Normal file
47
lib/h5p/readme_moodle.txt
Normal file
@ -0,0 +1,47 @@
|
||||
H5P PHP library
|
||||
---------------
|
||||
|
||||
Downloaded last release from: https://github.com/h5p/h5p-php-library/releases
|
||||
|
||||
Import procedure:
|
||||
|
||||
- Copy all the files from the folder repository in this directory.
|
||||
|
||||
Removed:
|
||||
* composer.json
|
||||
* .gitignore
|
||||
|
||||
Added:
|
||||
* readme_moodle.txt
|
||||
|
||||
Downloaded version: 1.24 release
|
||||
|
||||
|
||||
=== 3.8 ===
|
||||
1. In order to allow the dependency path to be overridden by child H5PCore classes, a couple of minor changes have been added to the
|
||||
h5p.classes.php file:
|
||||
- Into the getDependenciesFiles method, the line 2435:
|
||||
$dependency['path'] = 'libraries/' . H5PCore::libraryToString($dependency, TRUE);
|
||||
|
||||
has been changed to:
|
||||
$dependency['path'] = $this->getDependencyPath($dependency);
|
||||
|
||||
- The method getDependencyPath has been added (line 2455). It might be rewritten by child classes.
|
||||
A PR has been sent to the H5P library with these changes:
|
||||
https://github.com/h5p/h5p-php-library/compare/master...andrewnicols:libraryPathSubclass
|
||||
Hopefully, when upgrading, these patch won't be needed because it will be included in the H5P library by default.
|
||||
|
||||
|
||||
2. As the mbstring extension is optional in Moodle, the following changes have been hardcoded to the library:
|
||||
2.1. Comment the following methods in h5p.classes.php file where the extension_loaded('mbstring') is called:
|
||||
* isValidPackage
|
||||
* checkSetupErrorMessage
|
||||
* validateText
|
||||
* validateContentFiles
|
||||
|
||||
2.2. Change all the mb_uses straight to the core_text() alternatives. Version 1.24 has 3 ocurrences in h5p.classes.php
|
||||
and 1 ocurrence in h5p-metadata.class.php.
|
||||
|
||||
|
||||
The point 2 from above won't be needed once the mbstring extension becomes mandatory in Moodle. A request has been
|
||||
sent to MDL-65809.
|
358
lib/h5p/styles/h5p-admin.css
Normal file
358
lib/h5p/styles/h5p-admin.css
Normal file
@ -0,0 +1,358 @@
|
||||
/* Administration interface styling */
|
||||
|
||||
.h5p-content {
|
||||
border: 1px solid #DDD;
|
||||
border-radius: 3px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.h5p-admin-table,
|
||||
.h5p-admin-table > tbody {
|
||||
border: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.h5p-admin-table tr:nth-child(odd),
|
||||
.h5p-data-view tr:nth-child(odd) {
|
||||
background-color: #F9F9F9;
|
||||
}
|
||||
.h5p-admin-table tbody tr:hover {
|
||||
background-color: #EEE;
|
||||
}
|
||||
.h5p-admin-table.empty {
|
||||
padding: 1em;
|
||||
background-color: #EEE;
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.h5p-admin-table.libraries th:last-child,
|
||||
.h5p-admin-table.libraries td:last-child {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.h5p-admin-buttons-wrapper {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.h5p-admin-table.libraries button {
|
||||
font-size: 2em;
|
||||
cursor: pointer;
|
||||
border: 1px solid #AAA;
|
||||
border-radius: .2em;
|
||||
background-color: #e0e0e0;
|
||||
text-shadow: 0 0 0.5em #fff;
|
||||
padding: 0;
|
||||
line-height: 1em;
|
||||
width: 1.125em;
|
||||
height: 1.05em;
|
||||
text-indent: -0.125em;
|
||||
margin: 0.125em 0.125em 0 0.125em;
|
||||
}
|
||||
.h5p-admin-upgrade-library:before {
|
||||
font-family: 'H5P';
|
||||
content: "\e888";
|
||||
}
|
||||
.h5p-admin-view-library:before {
|
||||
font-family: 'H5P';
|
||||
content: "\e889";
|
||||
}
|
||||
.h5p-admin-delete-library:before {
|
||||
font-family: 'H5P';
|
||||
content: "\e890";
|
||||
}
|
||||
|
||||
.h5p-admin-table.libraries button:hover {
|
||||
background-color: #d0d0d0;
|
||||
}
|
||||
.h5p-admin-table.libraries button:disabled:hover {
|
||||
background-color: #e0e0e0;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.h5p-admin-upgrade-library {
|
||||
color: #339900;
|
||||
}
|
||||
.h5p-admin-view-library {
|
||||
color: #0066cc;
|
||||
}
|
||||
.h5p-admin-delete-library {
|
||||
color: #990000;
|
||||
}
|
||||
.h5p-admin-delete-library:disabled,
|
||||
.h5p-admin-upgrade-library:disabled {
|
||||
cursor: default;
|
||||
color: #c0c0c0;
|
||||
}
|
||||
|
||||
.h5p-library-info {
|
||||
padding: 1em 1em;
|
||||
margin: 1em 0;
|
||||
|
||||
width: 350px;
|
||||
|
||||
border: 1px solid #DDD;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* Labeled field (label + value) */
|
||||
.h5p-labeled-field {
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
.h5p-labeled-field:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.h5p-labeled-field .h5p-label {
|
||||
display: inline-block;
|
||||
min-width: 150px;
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
padding: 0.2em;
|
||||
}
|
||||
|
||||
.h5p-labeled-field .h5p-value {
|
||||
display: inline-block;
|
||||
padding: 0.2em;
|
||||
}
|
||||
|
||||
/* Search element */
|
||||
.h5p-content-search {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
|
||||
width: 100%;
|
||||
padding: 5px 0;
|
||||
margin-top: 10px;
|
||||
|
||||
border: 1px solid #CCC;
|
||||
border-radius: 3px;
|
||||
box-shadow: 2px 2px 5px #888888;
|
||||
}
|
||||
.h5p-content-search:before {
|
||||
font-family: 'H5P';
|
||||
vertical-align: bottom;
|
||||
content: "\e88a";
|
||||
font-size: 2em;
|
||||
line-height: 1.25em;
|
||||
}
|
||||
.h5p-content-search input {
|
||||
font-size: 120%;
|
||||
line-height: 120%;
|
||||
}
|
||||
.h5p-admin-search-results {
|
||||
margin-left: 10px;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.h5p-admin-pager-size-selector {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: .75em;
|
||||
display: inline-block;
|
||||
}
|
||||
.h5p-admin-pager-size-selector > span {
|
||||
padding: 5px;
|
||||
margin-left: 10px;
|
||||
cursor: pointer;
|
||||
border: 1px solid #CCC;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.h5p-admin-pager-size-selector > span.selected {
|
||||
background-color: #edf5fa;
|
||||
}
|
||||
.h5p-admin-pager-size-selector > span:hover {
|
||||
background-color: #555;
|
||||
color: #FFF;
|
||||
}
|
||||
|
||||
/* Generic "javascript"-action button */
|
||||
button.h5p-admin {
|
||||
border: 1px solid #AAA;
|
||||
border-radius: 5px;
|
||||
padding: 3px 10px;
|
||||
background-color: #EEE;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
color: #222;
|
||||
}
|
||||
button.h5p-admin:hover {
|
||||
background-color: #555;
|
||||
color: #FFF;
|
||||
}
|
||||
button.h5p-admin.disabled,
|
||||
button.h5p-admin.disabled:hover {
|
||||
cursor: auto;
|
||||
color: #CCC;
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
/* Pager element */
|
||||
.h5p-content-pager {
|
||||
display: inline-block;
|
||||
border: 1px solid #CCC;
|
||||
border-radius: 3px;
|
||||
box-shadow: 2px 2px 5px #888888;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
padding: 3px 0;
|
||||
}
|
||||
.h5p-content-pager > button {
|
||||
min-width: 80px;
|
||||
font-size: 130%;
|
||||
line-height: 130%;
|
||||
border: none;
|
||||
background: none;
|
||||
font-family: 'H5P';
|
||||
font-size: 1.4em;
|
||||
}
|
||||
.h5p-content-pager > button:focus {
|
||||
outline: 0;
|
||||
}
|
||||
.h5p-content-pager > button:last-child {
|
||||
margin-left: 10px;
|
||||
}
|
||||
.h5p-content-pager > .pager-info {
|
||||
cursor: pointer;
|
||||
padding: 5px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.h5p-content-pager > .pager-info:hover {
|
||||
background-color: #555;
|
||||
color: #FFF;
|
||||
}
|
||||
.h5p-content-pager > .pager-info,
|
||||
.h5p-content-pager > .h5p-pager-goto {
|
||||
margin: 0 10px;
|
||||
line-height: 130%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.h5p-admin-header {
|
||||
margin-top: 1.5em;
|
||||
}
|
||||
#h5p-library-upload-form.h5p-admin-upload-libraries-form,
|
||||
#h5p-content-type-cache-update-form.h5p-admin-upload-libraries-form {
|
||||
position: relative;
|
||||
margin: 0;
|
||||
|
||||
}
|
||||
.h5p-admin-upload-libraries-form .form-submit {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
}
|
||||
.h5p-spinner {
|
||||
padding: 0 0.5em;
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
}
|
||||
#h5p-admin-container .h5p-admin-center {
|
||||
text-align: center;
|
||||
}
|
||||
.h5p-pagination {
|
||||
text-align: center;
|
||||
}
|
||||
.h5p-pagination > span, .h5p-pagination > input {
|
||||
margin: 0 1em;
|
||||
}
|
||||
.h5p-data-view input[type="text"] {
|
||||
margin-bottom: 0.5em;
|
||||
margin-right: 0.5em;
|
||||
float: left;
|
||||
}
|
||||
.h5p-data-view input[type="text"]::-ms-clear {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.h5p-data-view .h5p-others-contents-toggler-wrapper {
|
||||
float: right;
|
||||
line-height: 2;
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
.h5p-data-view .h5p-others-contents-toggler-label {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.h5p-data-view .h5p-others-contents-toggler {
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
.h5p-data-view th[role="button"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
.h5p-data-view th[role="button"].h5p-sort:after,
|
||||
.h5p-data-view th[role="button"]:hover:after,
|
||||
.h5p-data-view th[role="button"].h5p-sort.h5p-reverse:hover:after {
|
||||
content: "\25BE";
|
||||
position: relative;
|
||||
left: 0.5em;
|
||||
top: -1px;
|
||||
}
|
||||
.h5p-data-view th[role="button"].h5p-sort.h5p-reverse:after,
|
||||
.h5p-data-view th[role="button"].h5p-sort:hover:after {
|
||||
content: "\25B4";
|
||||
top: -2px;
|
||||
}
|
||||
.h5p-data-view th[role="button"]:hover:after,
|
||||
.h5p-data-view th[role="button"].h5p-sort.h5p-reverse:hover:after,
|
||||
.h5p-data-view th[role="button"].h5p-sort:hover:after {
|
||||
color: #999;
|
||||
}
|
||||
.h5p-data-view .h5p-facet {
|
||||
cursor: pointer;
|
||||
color: #0073aa;
|
||||
outline: none;
|
||||
}
|
||||
.h5p-data-view .h5p-facet:hover,
|
||||
.h5p-data-view .h5p-facet:active {
|
||||
color: #00a0d2;
|
||||
}
|
||||
.h5p-data-view .h5p-facet:focus {
|
||||
color: #124964;
|
||||
box-shadow: 0 0 0 1px #5b9dd9,0 0 2px 1px rgba(30,140,190,.8);
|
||||
}
|
||||
.h5p-data-view .h5p-facet-wrapper {
|
||||
line-height: 23px;
|
||||
}
|
||||
.h5p-data-view .h5p-facet-tag {
|
||||
margin: 2px 0 0 0.5em;
|
||||
font-size: 12px;
|
||||
background: #e8e8e8;
|
||||
border: 1px solid #cbcbcc;
|
||||
border-radius: 5px;
|
||||
color: #5d5d5d;
|
||||
padding: 0 24px 0 10px;
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
}
|
||||
.h5p-data-view .h5p-facet-tag > span {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: auto;
|
||||
bottom: auto;
|
||||
font-size: 18px;
|
||||
color: #a2a2a2;
|
||||
outline: none;
|
||||
width: 21px;
|
||||
text-indent: 4px;
|
||||
letter-spacing: 10px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
}
|
||||
.h5p-data-view .h5p-facet-tag > span:before {
|
||||
content: "×";
|
||||
font-weight: bold;
|
||||
}
|
||||
.h5p-data-view .h5p-facet-tag > span:hover,
|
||||
.h5p-data-view .h5p-facet-tag > span:focus {
|
||||
color: #a20000;
|
||||
}
|
||||
.h5p-data-view .h5p-facet-tag > span:active {
|
||||
color: #d20000;
|
||||
}
|
||||
.content-upgrade-log {
|
||||
color: red;
|
||||
}
|
183
lib/h5p/styles/h5p-confirmation-dialog.css
Normal file
183
lib/h5p/styles/h5p-confirmation-dialog.css
Normal file
@ -0,0 +1,183 @@
|
||||
.h5p-confirmation-dialog-background {
|
||||
position: fixed;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
left: 0;
|
||||
top: 0;
|
||||
|
||||
background: rgba(44, 44, 44, 0.9);
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
-webkit-transition: opacity 0.1s, linear 0s, visibility 0s linear 0s;
|
||||
transition: opacity 0.1s linear 0s, visibility 0s linear 0s;
|
||||
|
||||
z-index: 201;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-background.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-background.hiding {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
-webkit-transition: opacity 0.1s, linear 0s, visibility 0s linear 0.1s;
|
||||
transition: opacity 0.1s linear 0s, visibility 0s linear 0.1s;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-popup:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-popup {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
box-sizing: border-box;
|
||||
max-width: 35em;
|
||||
min-width: 25em;
|
||||
|
||||
top: 2em;
|
||||
left: 50%;
|
||||
-webkit-transform: translate(-50%, 0%);
|
||||
-ms-transform: translate(-50%, 0%);
|
||||
transform: translate(-50%, 0%);
|
||||
|
||||
color: #555;
|
||||
box-shadow: 0 0 6px 6px rgba(10,10,10,0.3);
|
||||
|
||||
-webkit-transition: transform 0.1s ease-in;
|
||||
transition: transform 0.1s ease-in;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-popup.hidden {
|
||||
-webkit-transform: translate(-50%, 50%);
|
||||
-ms-transform: translate(-50%, 50%);
|
||||
transform: translate(-50%, 50%);
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-header {
|
||||
padding: 1.5em;
|
||||
background: #fff;
|
||||
color: #356593;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-header-text {
|
||||
font-size: 1.25em;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-body {
|
||||
background: #fafbfc;
|
||||
border-top: solid 1px #dde0e9;
|
||||
padding: 1.25em 1.5em;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-text {
|
||||
margin-bottom: 1.5em;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-buttons {
|
||||
float: right;
|
||||
}
|
||||
|
||||
button.h5p-confirmation-dialog-exit:visited,
|
||||
button.h5p-confirmation-dialog-exit:link,
|
||||
button.h5p-confirmation-dialog-exit {
|
||||
position: absolute;
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 2.5em;
|
||||
top: -0.9em;
|
||||
right: -1.15em;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
button.h5p-confirmation-dialog-exit:focus,
|
||||
button.h5p-confirmation-dialog-exit:hover {
|
||||
color: #E4ECF5;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-exit:before {
|
||||
font-family: "H5P";
|
||||
content: "\e890";
|
||||
}
|
||||
|
||||
.h5p-core-button.h5p-confirmation-dialog-confirm-button {
|
||||
padding-left: 0.75em;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.h5p-core-button.h5p-confirmation-dialog-confirm-button:before {
|
||||
content: "\e601";
|
||||
margin-top: -6px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-popup.offline .h5p-confirmation-dialog-buttons {
|
||||
float: none;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-popup.offline .count-down {
|
||||
font-family: Arial;
|
||||
margin-top: 0.15em;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.h5p-confirmation-dialog-popup.offline .h5p-confirmation-dialog-confirm-button:before {
|
||||
content: "\e90b";
|
||||
font-weight: normal;
|
||||
vertical-align: text-bottom;
|
||||
}
|
||||
|
||||
.throbber-wrapper {
|
||||
display: none;
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
background: rgba(44, 44, 44, 0.9);
|
||||
}
|
||||
|
||||
.throbber-wrapper.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.throbber-wrapper .throbber-container {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
}
|
||||
|
||||
.throbber-wrapper .sending-requests-throbber{
|
||||
position: absolute;
|
||||
top: 7em;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
.throbber-wrapper .sending-requests-throbber:before {
|
||||
display: block;
|
||||
font-family: 'H5P';
|
||||
content: "\e90b";
|
||||
color: white;
|
||||
font-size: 10em;
|
||||
animation: request-throbber 1.5s infinite linear;
|
||||
}
|
||||
|
||||
@keyframes request-throbber {
|
||||
from {
|
||||
transform: rotate(0);
|
||||
}
|
||||
|
||||
to {
|
||||
transform: rotate(359deg);
|
||||
}
|
||||
}
|
60
lib/h5p/styles/h5p-core-button.css
Normal file
60
lib/h5p/styles/h5p-core-button.css
Normal file
@ -0,0 +1,60 @@
|
||||
button.h5p-core-button:visited,
|
||||
button.h5p-core-button:link,
|
||||
button.h5p-core-button {
|
||||
font-family: "Open Sans", sans-serif;
|
||||
font-weight: 600;
|
||||
font-size: 1em;
|
||||
line-height: 1.2;
|
||||
padding: 0.5em 1.25em;
|
||||
border-radius: 2em;
|
||||
|
||||
background: #2579c6;
|
||||
color: #fff;
|
||||
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
outline: none;
|
||||
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
text-shadow: none;
|
||||
vertical-align: baseline;
|
||||
text-decoration: none;
|
||||
|
||||
-webkit-transition: initial;
|
||||
transition: initial;
|
||||
}
|
||||
button.h5p-core-button:focus {
|
||||
background: #1f67a8;
|
||||
}
|
||||
button.h5p-core-button:hover {
|
||||
background: rgba(31, 103, 168, 0.83);
|
||||
}
|
||||
button.h5p-core-button:active {
|
||||
background: #104888;
|
||||
}
|
||||
button.h5p-core-button:before {
|
||||
font-family: 'H5P';
|
||||
padding-right: 0.15em;
|
||||
font-size: 1.5em;
|
||||
vertical-align: middle;
|
||||
line-height: 0.7;
|
||||
}
|
||||
button.h5p-core-cancel-button:visited,
|
||||
button.h5p-core-cancel-button:link,
|
||||
button.h5p-core-cancel-button {
|
||||
border: none;
|
||||
background: none;
|
||||
color: #a00;
|
||||
margin-right: 1em;
|
||||
font-size: 1em;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
button.h5p-core-cancel-button:hover,
|
||||
button.h5p-core-cancel-button:focus {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #e40000;
|
||||
}
|
566
lib/h5p/styles/h5p.css
Normal file
566
lib/h5p/styles/h5p.css
Normal file
@ -0,0 +1,566 @@
|
||||
/* General CSS for H5P. Licensed under the MIT License.*/
|
||||
|
||||
/* Custom H5P font to use for icons. */
|
||||
@font-face {
|
||||
font-family: 'h5p';
|
||||
src: url('../fonts/h5p-core-23.eot?mz1lkp');
|
||||
src: url('../fonts/h5p-core-23.eot?mz1lkp#iefix') format('embedded-opentype'),
|
||||
url('../fonts/h5p-core-23.ttf?mz1lkp') format('truetype'),
|
||||
url('../fonts/h5p-core-23.woff?mz1lkp') format('woff'),
|
||||
url('../fonts/h5p-core-23.svg?mz1lkp#h5p') format('svg');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
html.h5p-iframe, html.h5p-iframe > body {
|
||||
font-family: Sans-Serif; /* Use the browser's default sans-serif font. (Since Heletica doesn't look nice on Windows, and Arial on OS X.) */
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.h5p-semi-fullscreen, .h5p-fullscreen, html.h5p-iframe .h5p-container {
|
||||
overflow: hidden;
|
||||
}
|
||||
.h5p-content {
|
||||
position: relative;
|
||||
background: #fefefe;
|
||||
border: 1px solid #EEE;
|
||||
border-bottom: none;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
}
|
||||
.h5p-noselect
|
||||
{
|
||||
-khtml-user-select: none;
|
||||
-ms-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
html.h5p-iframe .h5p-content {
|
||||
font-size: 16px;
|
||||
line-height: 1.5em;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
html.h5p-iframe .h5p-fullscreen .h5p-content,
|
||||
html.h5p-iframe .h5p-semi-fullscreen .h5p-content {
|
||||
height: 100%;
|
||||
}
|
||||
.h5p-content.h5p-no-frame,
|
||||
.h5p-fullscreen .h5p-content,
|
||||
.h5p-semi-fullscreen .h5p-content {
|
||||
border: 0;
|
||||
}
|
||||
.h5p-container {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
.h5p-iframe-wrapper.h5p-fullscreen {
|
||||
background-color: #000;
|
||||
}
|
||||
body.h5p-semi-fullscreen {
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.h5p-container.h5p-semi-fullscreen {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 101;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #FFF;
|
||||
}
|
||||
|
||||
.h5p-content-controls {
|
||||
margin: 0;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
z-index: 3;
|
||||
}
|
||||
.h5p-fullscreen .h5p-content-controls {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.h5p-content-controls > a:link, .h5p-content-controls > a:visited, a.h5p-disable-fullscreen:link, a.h5p-disable-fullscreen:visited {
|
||||
color: #e5eef6;
|
||||
}
|
||||
|
||||
.h5p-enable-fullscreen:before {
|
||||
font-family: 'H5P';
|
||||
content: "\e88c";
|
||||
}
|
||||
.h5p-disable-fullscreen:before {
|
||||
font-family: 'H5P';
|
||||
content: "\e891";
|
||||
}
|
||||
.h5p-enable-fullscreen, .h5p-disable-fullscreen {
|
||||
cursor: pointer;
|
||||
color: #EEE;
|
||||
background: rgb(0,0,0);
|
||||
background: rgba(0,0,0,0.3);
|
||||
line-height: 0.975em;
|
||||
font-size: 2em;
|
||||
width: 1.125em;
|
||||
height: 1em;
|
||||
text-indent: 0.04em;
|
||||
}
|
||||
.h5p-disable-fullscreen {
|
||||
line-height: 0.925em;
|
||||
width: 1.1em;
|
||||
height: 0.9em;
|
||||
}
|
||||
|
||||
.h5p-enable-fullscreen:focus,
|
||||
.h5p-disable-fullscreen:focus {
|
||||
outline-style: solid;
|
||||
outline-width: 1px;
|
||||
outline-offset: 0.25em;
|
||||
}
|
||||
|
||||
.h5p-enable-fullscreen:hover, .h5p-disable-fullscreen:hover {
|
||||
background: rgba(0,0,0,0.5);
|
||||
}
|
||||
.h5p-semi-fullscreen .h5p-enable-fullscreen {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.h5p-fullscreen {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.h5p-iframe-wrapper {
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.h5p-fullscreen .h5p-iframe-wrapper,
|
||||
.h5p-semi-fullscreen .h5p-iframe-wrapper {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.h5p-iframe-wrapper.h5p-semi-fullscreen {
|
||||
width: auto;
|
||||
height: auto;
|
||||
background: black;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 100001;
|
||||
}
|
||||
.h5p-iframe-wrapper.h5p-semi-fullscreen .buttons {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 20;
|
||||
}
|
||||
.h5p-iframe-wrapper iframe.h5p-iframe {
|
||||
/* Hack for IOS landscape / portrait */
|
||||
width: 10px;
|
||||
min-width: 100%;
|
||||
*width: 100%;
|
||||
/* End of hack */
|
||||
height: 100%;
|
||||
z-index: 10;
|
||||
overflow: hidden;
|
||||
border: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.h5p-content ul.h5p-actions {
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
list-style: none;
|
||||
padding: 0px 10px;
|
||||
margin: 0;
|
||||
height: 25px;
|
||||
font-size: 12px;
|
||||
background: #FAFAFA;
|
||||
border-top: 1px solid #EEE;
|
||||
border-bottom: 1px solid #EEE;
|
||||
clear: both;
|
||||
font-family: Sans-Serif;
|
||||
}
|
||||
.h5p-fullscreen .h5p-actions, .h5p-semi-fullscreen .h5p-actions {
|
||||
display: none;
|
||||
}
|
||||
.h5p-actions > .h5p-button {
|
||||
float: left;
|
||||
cursor: pointer;
|
||||
margin: 0 0.5em 0 0;
|
||||
background: none;
|
||||
padding: 0 0.75em 0 0.25em;
|
||||
vertical-align: top;
|
||||
color: #999;
|
||||
text-decoration: none;
|
||||
outline: none;
|
||||
line-height: 23px;
|
||||
}
|
||||
.h5p-actions > .h5p-button:hover {
|
||||
color: #666;
|
||||
}
|
||||
.h5p-actions > .h5p-button:active,
|
||||
.h5p-actions > .h5p-button:focus,
|
||||
.h5p-actions .h5p-link:active,
|
||||
.h5p-actions .h5p-link:focus {
|
||||
color: #666;
|
||||
}
|
||||
.h5p-actions > .h5p-button:focus,
|
||||
.h5p-actions .h5p-link:focus {
|
||||
outline-style: solid;
|
||||
outline-width: thin;
|
||||
outline-offset: -2px;
|
||||
outline-color: #9ecaed;
|
||||
}
|
||||
.h5p-actions > .h5p-button:before {
|
||||
font-family: 'H5P';
|
||||
font-size: 20px;
|
||||
line-height: 20px;
|
||||
vertical-align: top;
|
||||
padding-right: 0;
|
||||
}
|
||||
.h5p-actions > .h5p-button.h5p-export:before {
|
||||
content: "\e90b";
|
||||
}
|
||||
.h5p-actions > .h5p-button.h5p-copyrights:before {
|
||||
content: "\e88f";
|
||||
}
|
||||
.h5p-actions > .h5p-button.h5p-embed:before {
|
||||
content: "\e892";
|
||||
}
|
||||
.h5p-actions .h5p-link {
|
||||
float: right;
|
||||
margin-right: 0;
|
||||
font-size: 2.0em;
|
||||
line-height: 23px;
|
||||
overflow: hidden;
|
||||
color: #999;
|
||||
text-decoration: none;
|
||||
outline: none;
|
||||
}
|
||||
.h5p-actions .h5p-link:before {
|
||||
font-family: 'H5P';
|
||||
content: "\e88e";
|
||||
vertical-align: bottom;
|
||||
}
|
||||
.h5p-actions > li {
|
||||
margin: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.h5p-popup-dialog {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
z-index: 100;
|
||||
padding: 2em;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.2s;
|
||||
-moz-transition: opacity 0.2s;
|
||||
-o-transition: opacity 0.2s;
|
||||
transition: opacity 0.2s;
|
||||
background:#000;
|
||||
background:rgba(0,0,0,0.75);
|
||||
}
|
||||
.h5p-popup-dialog.h5p-open {
|
||||
opacity: 1;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-inner {
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
background: #fff;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-inner > h2 {
|
||||
position: absolute;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
background: #eee;
|
||||
display: block;
|
||||
color: #656565;
|
||||
font-size: 1.25em;
|
||||
padding: 0.325em 0.5em 0.25em;
|
||||
line-height: 1.25em;
|
||||
border-bottom: 1px solid #ccc;
|
||||
z-index: 2;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-inner > h2 > a {
|
||||
font-size: 12px;
|
||||
margin-left: 1em;
|
||||
}
|
||||
.h5p-embed-dialog .h5p-inner,
|
||||
.h5p-reuse-dialog .h5p-inner,
|
||||
.h5p-content-user-data-reset-dialog .h5p-inner {
|
||||
min-width: 316px;
|
||||
max-width: 400px;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.h5p-embed-dialog .h5p-embed-code-container,
|
||||
.h5p-embed-size {
|
||||
resize: none;
|
||||
outline: none;
|
||||
width: 100%;
|
||||
padding: 0.375em 0.5em 0.25em;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: 0 1px 2px 0 #d0d0d0 inset;
|
||||
font-size: 0.875em;
|
||||
letter-spacing: 0.065em;
|
||||
font-family: sans-serif;
|
||||
white-space: pre;
|
||||
line-height: 1.5em;
|
||||
height: 2.0714em;
|
||||
background: #f5f5f5;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
}
|
||||
.h5p-embed-dialog .h5p-embed-code-container:focus {
|
||||
height: 5em;
|
||||
}
|
||||
.h5p-embed-size {
|
||||
width: 3.5em;
|
||||
text-align: right;
|
||||
margin: 0.5em 0;
|
||||
line-height: 2em;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-scroll-content {
|
||||
border-top: 2.25em solid transparent;
|
||||
padding: 1em;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
color: #555555;
|
||||
z-index: 1;
|
||||
}
|
||||
.h5p-popup-dialog.h5p-open .h5p-scroll-content {
|
||||
overflow: auto;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-scroll-content::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-scroll-content::-webkit-scrollbar-track {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-scroll-content::-webkit-scrollbar-thumb {
|
||||
box-shadow: 0 0 10px #000 inset;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-close {
|
||||
cursor: pointer;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-close:after {
|
||||
font-family: 'H5P';
|
||||
content: "\e894";
|
||||
font-size: 2em;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
width: 1.125em;
|
||||
height: 1.125em;
|
||||
line-height: 1.125em;
|
||||
color: #656565;
|
||||
cursor: pointer;
|
||||
text-indent: -0.065em;
|
||||
z-index: 3
|
||||
}
|
||||
.h5p-popup-dialog .h5p-close:hover:after,
|
||||
.h5p-popup-dialog .h5p-close:focus:after {
|
||||
color: #454545;
|
||||
}
|
||||
.h5p-popup-dialog .h5p-close:active:after {
|
||||
color: #252525;
|
||||
}
|
||||
.h5p-poopup-dialog h2 {
|
||||
margin: 0.25em 0 0.5em;
|
||||
}
|
||||
.h5p-popup-dialog h3 {
|
||||
margin: 0.75em 0 0.25em;
|
||||
}
|
||||
.h5p-popup-dialog dl {
|
||||
margin: 0.25em 0 0.75em;
|
||||
}
|
||||
.h5p-popup-dialog dt {
|
||||
float: left;
|
||||
margin: 0 0.75em 0 0;
|
||||
}
|
||||
.h5p-popup-dialog dt:after {
|
||||
content: ':';
|
||||
}
|
||||
.h5p-popup-dialog dd {
|
||||
margin: 0;
|
||||
}
|
||||
.h5p-expander {
|
||||
cursor: pointer;
|
||||
font-size: 1.125em;
|
||||
outline: none;
|
||||
margin: 0.5em 0 0;
|
||||
display: inline-block;
|
||||
}
|
||||
.h5p-expander:before {
|
||||
content: "+";
|
||||
width: 1em;
|
||||
display: inline-block;
|
||||
font-weight: bold;
|
||||
}
|
||||
.h5p-expander.h5p-open:before {
|
||||
content: "-";
|
||||
text-indent: 0.125em;
|
||||
}
|
||||
.h5p-expander:hover,
|
||||
.h5p-expander:focus {
|
||||
color: #303030;
|
||||
}
|
||||
.h5p-expander:active {
|
||||
color: #202020;
|
||||
}
|
||||
.h5p-expander-content {
|
||||
display: none;
|
||||
}
|
||||
.h5p-expander-content p {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
.h5p-content-copyrights {
|
||||
border-left: 0.25em solid #d0d0d0;
|
||||
margin-left: 0.25em;
|
||||
padding-left: 0.25em;
|
||||
}
|
||||
.h5p-throbber {
|
||||
background: url('../images/throbber.gif?ver=1.2.1') 10px center no-repeat;
|
||||
padding-left: 38px;
|
||||
min-height: 30px;
|
||||
line-height: 30px;
|
||||
}
|
||||
.h5p-dialog-ok-button {
|
||||
cursor: default;
|
||||
float: right;
|
||||
outline: none;
|
||||
border: 2px solid #ccc;
|
||||
padding: 0.25em 0.75em 0.125em;
|
||||
background: #eee;
|
||||
}
|
||||
.h5p-dialog-ok-button:hover,
|
||||
.h5p-dialog-ok-button:focus {
|
||||
background: #fafafa;
|
||||
}
|
||||
.h5p-dialog-ok-button:active {
|
||||
background: #eeffee;
|
||||
}
|
||||
.h5p-big-button {
|
||||
line-height: 1.25;
|
||||
display: block;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
padding: 1em 1em 1em 3.75em;
|
||||
text-align: left;
|
||||
border: 1px solid #dedede;
|
||||
background: linear-gradient(#ffffff, #f1f1f2);
|
||||
border-radius: 0.25em;
|
||||
}
|
||||
.h5p-big-button:before {
|
||||
font-family: 'h5p';
|
||||
content: "\e893";
|
||||
line-height: 1;
|
||||
font-size: 3em;
|
||||
color: #2747f7;
|
||||
position: absolute;
|
||||
left: 0.125em;
|
||||
top: 0.125em;
|
||||
}
|
||||
.h5p-copy-button:before {
|
||||
content: "\e905";
|
||||
}
|
||||
.h5p-big-button:hover {
|
||||
border: 1px solid #2747f7;
|
||||
background: #eff1fe;
|
||||
}
|
||||
.h5p-big-button:active {
|
||||
border: 1px solid #dedede;
|
||||
background: #dfe4fe;
|
||||
}
|
||||
.h5p-button-title {
|
||||
color: #2747f7;
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.h5p-button-description {
|
||||
color: #757575;
|
||||
}
|
||||
.h5p-horizontal-line-text {
|
||||
border-top: 1px solid #dadada;
|
||||
line-height: 1;
|
||||
color: #474747;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
margin: 1.25em 0;
|
||||
}
|
||||
.h5p-horizontal-line-text > span {
|
||||
background: white;
|
||||
padding: 0.5em;
|
||||
position: absolute;
|
||||
top: -1em;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
.h5p-toast {
|
||||
font-size: 0.75em;
|
||||
background-color: rgba(0, 0, 0, 0.9);
|
||||
color: #fff;
|
||||
z-index: 110;
|
||||
position: absolute;
|
||||
padding: 0 0.5em;
|
||||
line-height: 2;
|
||||
border-radius: 4px;
|
||||
white-space: nowrap;
|
||||
pointer-events: none;
|
||||
top: 0;
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
transition: opacity 1s;
|
||||
}
|
||||
.h5p-toast-disabled {
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
|
||||
/* This is loaded as part of Core and not Editor since this needs to be outside the editor iframe */
|
||||
.h5peditor-semi-fullscreen {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 101;
|
||||
}
|
||||
iframe.h5peditor-semi-fullscreen {
|
||||
background: #fff;
|
||||
z-index: 100001;
|
||||
}
|
||||
|
||||
.h5p-content.using-mouse *:not(textarea):focus {
|
||||
outline: none !important;
|
||||
}
|
@ -36,7 +36,7 @@ class core_component_testcase extends advanced_testcase {
|
||||
* this is defined here to annoy devs that try to add more without any thinking,
|
||||
* always verify that it does not collide with any existing add-on modules and subplugins!!!
|
||||
*/
|
||||
const SUBSYSTEMCOUNT = 68;
|
||||
const SUBSYSTEMCOUNT = 69;
|
||||
|
||||
public function setUp() {
|
||||
$psr0namespaces = new ReflectionProperty('core_component', 'psr0namespaces');
|
||||
|
@ -314,4 +314,10 @@
|
||||
<license>MIT</license>
|
||||
<version>4.1.0</version>
|
||||
</library>
|
||||
<library>
|
||||
<location>h5p</location>
|
||||
<name>h5p-php-library</name>
|
||||
<license>GPL-3.0</license>
|
||||
<version>1.24</version>
|
||||
</library>
|
||||
</libraries>
|
||||
|
@ -70,6 +70,12 @@ validation against and defaults to null (so, no user needed) if not provided.
|
||||
* \single_button constructor has a new attributes param to add attributes to the button HTML tag.
|
||||
* Improved url matching behaviour for profiled urls and excluded urls
|
||||
* Attempting to use xsendfile via the 3rd param of readstring_accel() is now ignored.
|
||||
* New H5P libraries have been added to Moodle core in /lib/h5p.
|
||||
* New H5P core subsystem have been added.
|
||||
* Introduced new callback for plugin developers '<component>_get_path_from_pluginfile($filearea, $args)': This will return
|
||||
the itemid and filepath for the filearea and path defined in $args. It has been added in order to get the correct itemid and
|
||||
filepath because some components, such as mod_page or mod_resource, add the revision to the URL where the itemid should be placed
|
||||
(to prevent caching problems), but then they don't store it in database.
|
||||
|
||||
=== 3.7 ===
|
||||
|
||||
|
@ -1753,3 +1753,27 @@ function mod_assign_user_preferences() {
|
||||
|
||||
return $preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
|
||||
*
|
||||
* @param string $filearea The filearea.
|
||||
* @param array $args The path (the part after the filearea and before the filename).
|
||||
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
|
||||
*/
|
||||
function mod_assign_get_path_from_pluginfile(string $filearea, array $args) : array {
|
||||
// Assign never has an itemid (the number represents the revision but it's not stored in database).
|
||||
array_shift($args);
|
||||
|
||||
// Get the filepath.
|
||||
if (empty($args)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
}
|
||||
|
||||
return [
|
||||
'itemid' => 0,
|
||||
'filepath' => $filepath,
|
||||
];
|
||||
}
|
||||
|
@ -818,3 +818,27 @@ function mod_folder_core_calendar_provide_event_action(calendar_event $event,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
|
||||
*
|
||||
* @param string $filearea The filearea.
|
||||
* @param array $args The path (the part after the filearea and before the filename).
|
||||
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
|
||||
*/
|
||||
function mod_folder_get_path_from_pluginfile(string $filearea, array $args) : array {
|
||||
// Folder never has an itemid (the number represents the revision but it's not stored in database).
|
||||
array_shift($args);
|
||||
|
||||
// Get the filepath.
|
||||
if (empty($args)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
}
|
||||
|
||||
return [
|
||||
'itemid' => 0,
|
||||
'filepath' => $filepath,
|
||||
];
|
||||
}
|
||||
|
@ -571,3 +571,27 @@ function mod_page_core_calendar_provide_event_action(calendar_event $event,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
|
||||
*
|
||||
* @param string $filearea The filearea.
|
||||
* @param array $args The path (the part after the filearea and before the filename).
|
||||
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
|
||||
*/
|
||||
function mod_page_get_path_from_pluginfile(string $filearea, array $args) : array {
|
||||
// Page never has an itemid (the number represents the revision but it's not stored in database).
|
||||
array_shift($args);
|
||||
|
||||
// Get the filepath.
|
||||
if (empty($args)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
}
|
||||
|
||||
return [
|
||||
'itemid' => 0,
|
||||
'filepath' => $filepath,
|
||||
];
|
||||
}
|
||||
|
@ -584,3 +584,28 @@ function mod_resource_core_calendar_provide_event_action(calendar_event $event,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
|
||||
*
|
||||
* @param string $filearea The filearea.
|
||||
* @param array $args The path (the part after the filearea and before the filename).
|
||||
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
|
||||
*/
|
||||
function mod_resource_get_path_from_pluginfile(string $filearea, array $args) : array {
|
||||
// Resource never has an itemid (the number represents the revision but it's not stored in database).
|
||||
array_shift($args);
|
||||
|
||||
// Get the filepath.
|
||||
if (empty($args)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
}
|
||||
|
||||
return [
|
||||
'itemid' => 0,
|
||||
'filepath' => $filepath,
|
||||
];
|
||||
}
|
||||
|
@ -1887,3 +1887,27 @@ function mod_scorm_core_calendar_get_valid_event_timestart_range(\calendar_event
|
||||
|
||||
return [$mindate, $maxdate];
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
|
||||
*
|
||||
* @param string $filearea The filearea.
|
||||
* @param array $args The path (the part after the filearea and before the filename).
|
||||
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
|
||||
*/
|
||||
function mod_scorm_get_path_from_pluginfile(string $filearea, array $args) : array {
|
||||
// SCORM never has an itemid (the number represents the revision but it's not stored in database).
|
||||
array_shift($args);
|
||||
|
||||
// Get the filepath.
|
||||
if (empty($args)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
}
|
||||
|
||||
return [
|
||||
'itemid' => 0,
|
||||
'filepath' => $filepath,
|
||||
];
|
||||
}
|
||||
|
@ -2177,3 +2177,31 @@ function workshop_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
}
|
||||
return $updates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
|
||||
*
|
||||
* @param string $filearea The filearea.
|
||||
* @param array $args The path (the part after the filearea and before the filename).
|
||||
* @return array|null The itemid and the filepath inside the $args path, for the defined filearea.
|
||||
*/
|
||||
function mod_workshop_get_path_from_pluginfile(string $filearea, array $args) : ?array {
|
||||
if ($filearea !== 'instructauthors' && $filearea !== 'instructreviewers' && $filearea !== 'conclusion') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Workshop only has empty itemid for some of the fileareas.
|
||||
array_shift($args);
|
||||
|
||||
// Get the filepath.
|
||||
if (empty($args)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
}
|
||||
|
||||
return [
|
||||
'itemid' => 0,
|
||||
'filepath' => $filepath,
|
||||
];
|
||||
}
|
||||
|
@ -188,6 +188,9 @@
|
||||
<testsuite name="core_rss_testsuite">
|
||||
<directory suffix="_test.php">rss/tests</directory>
|
||||
</testsuite>
|
||||
<testsuite name="core_h5p_testsuite">
|
||||
<directory suffix="_test.php">h5p/tests</directory>
|
||||
</testsuite>
|
||||
|
||||
<!--Plugin suites: use admin/tool/phpunit/cli/util.php to build phpunit.xml from phpunit.xml.dist with up-to-date list of plugins in current install-->
|
||||
<!--@plugin_suites_start@-->
|
||||
|
@ -2254,6 +2254,15 @@ $switch-transition: .2s all !default;
|
||||
min-height: 3.125rem;
|
||||
}
|
||||
|
||||
body.h5p-embed {
|
||||
#maincontent {
|
||||
display: none;
|
||||
}
|
||||
.h5pmessages {
|
||||
min-height: 230px; // This should be the same height as default core_h5p iframes.
|
||||
}
|
||||
}
|
||||
|
||||
.text-decoration-none {
|
||||
text-decoration: none !important; /* stylelint-disable-line declaration-no-important */
|
||||
}
|
||||
|
@ -11452,6 +11452,12 @@ div.editor_atto_toolbar button .icon {
|
||||
.paged-content-page-container {
|
||||
min-height: 3.125rem; }
|
||||
|
||||
body.h5p-embed #maincontent {
|
||||
display: none; }
|
||||
|
||||
body.h5p-embed .h5pmessages {
|
||||
min-height: 230px; }
|
||||
|
||||
.text-decoration-none {
|
||||
text-decoration: none !important;
|
||||
/* stylelint-disable-line declaration-no-important */ }
|
||||
|
@ -11707,6 +11707,12 @@ div.editor_atto_toolbar button .icon {
|
||||
.paged-content-page-container {
|
||||
min-height: 3.125rem; }
|
||||
|
||||
body.h5p-embed #maincontent {
|
||||
display: none; }
|
||||
|
||||
body.h5p-embed .h5pmessages {
|
||||
min-height: 230px; }
|
||||
|
||||
.text-decoration-none {
|
||||
text-decoration: none !important;
|
||||
/* stylelint-disable-line declaration-no-important */ }
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2019102500.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2019102500.03; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user