Skip to content

Commit

Permalink
Merge branch 'MDL-66609-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Oct 29, 2019
2 parents 501c568 + 8fda136 commit 08460f2
Show file tree
Hide file tree
Showing 96 changed files with 23,302 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*.*
Expand Down Expand Up @@ -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/
Expand All @@ -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/
4 changes: 2 additions & 2 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*.*
Expand Down Expand Up @@ -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/
Expand All @@ -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/
24 changes: 24 additions & 0 deletions blocks/html/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
3 changes: 2 additions & 1 deletion filter/displayh5p/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public function filterobject_prepare_replacement_callback($tagbegin, $tagend, $u

// 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;
}

Expand Down
59 changes: 59 additions & 0 deletions h5p/classes/autoloader.php
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @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 <[email protected]>
* @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 changes: 113 additions & 0 deletions h5p/classes/core.php
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @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 <[email protected]>
* @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 changes: 140 additions & 0 deletions h5p/classes/factory.php
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @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 <[email protected]>
* @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;
}
}
Loading

0 comments on commit 08460f2

Please sign in to comment.