MDL-67059 core_h5p: UI to manually upload H5P content type libraries
Co-authored by: Mihail Geshoski <[email protected]>
This commit is contained in:
committed by
Adrian Greeve
parent
cf29a4857a
commit
b57e1c9590
@@ -0,0 +1,29 @@
|
||||
<?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 settings link.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Amaia Anabitarte <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
// Settings page.
|
||||
$ADMIN->add('h5p', new admin_externalpage('h5psettings', get_string('h5pmanage', 'core_h5p'),
|
||||
new moodle_url('/h5p/libraries.php'), ['moodle/site:config', 'moodle/h5p:updatelibraries']));
|
||||
@@ -31,6 +31,7 @@ $ADMIN->add('root', new admin_category('grades', new lang_string('grades')));
|
||||
$ADMIN->add('root', new admin_category('analytics', new lang_string('analytics', 'analytics')));
|
||||
$ADMIN->add('root', new admin_category('competencies', new lang_string('competencies', 'core_competency')));
|
||||
$ADMIN->add('root', new admin_category('badges', new lang_string('badges'), empty($CFG->enablebadges)));
|
||||
$ADMIN->add('root', new admin_category('h5p', new lang_string('h5p', 'core_h5p')));
|
||||
$ADMIN->add('root', new admin_category('location', new lang_string('location','admin')));
|
||||
$ADMIN->add('root', new admin_category('language', new lang_string('language')));
|
||||
$ADMIN->add('root', new admin_category('messaging', new lang_string('messagingcategory', 'admin')));
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Upload an h5p content to update the content libraries.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Amaia Anabitarte <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_h5p\form;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Upload a zip or h5p content to update the content libraries.
|
||||
*
|
||||
* @copyright 2019 Amaia Anabitarte <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class uploadlibraries_form extends \moodleform {
|
||||
/**
|
||||
* Form definition.
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$mform->addElement('header', 'settingsheader', get_string('uploadlibraries', 'core_h5p'));
|
||||
|
||||
$filemanageroptions = array(
|
||||
'accepted_types' => array('.h5p', '.zip'),
|
||||
'maxbytes' => 0,
|
||||
'maxfiles' => 1,
|
||||
'subdirs' => 0
|
||||
);
|
||||
|
||||
$mform->addElement('filepicker', 'h5ppackage', get_string('h5ppackage', 'core_h5p'),
|
||||
null, $filemanageroptions);
|
||||
$mform->addHelpButton('h5ppackage', 'h5ppackage', 'core_h5p');
|
||||
$mform->addRule('h5ppackage', null, 'required');
|
||||
|
||||
$this->add_action_buttons(false, get_string('uploadlibraries', 'core_h5p'));
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,6 @@ class helper {
|
||||
|
||||
return $h5pstorage->contentId;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Manage H5P libraries settings page.
|
||||
*
|
||||
* @package core_h5p
|
||||
* @copyright 2019 Amaia Anabitarte <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../config.php');
|
||||
|
||||
require_login(null, false);
|
||||
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/h5p:updatelibraries', $context);
|
||||
|
||||
$pagetitle = get_string('h5pmanage', 'core_h5p');
|
||||
$url = new \moodle_url("/h5p/libraries.php");
|
||||
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_title($pagetitle);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_heading($pagetitle);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($pagetitle);
|
||||
echo $OUTPUT->box(get_string('librariesmanagerdescription', 'core_h5p'));
|
||||
|
||||
$form = new \core_h5p\form\uploadlibraries_form();
|
||||
if ($data = $form->get_data()) {
|
||||
require_sesskey();
|
||||
|
||||
// Get the file from the users draft area.
|
||||
$usercontext = context_user::instance($USER->id);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data->h5ppackage, 'id',
|
||||
false);
|
||||
$file = reset($files);
|
||||
|
||||
// Validate and save the H5P package.
|
||||
$h5pfactory = new \core_h5p\factory();
|
||||
// Because we are passing skipcontent = true to save_h5p function, the returning value is false in an error
|
||||
// is encountered, null when successfully saving the package without creating the content.
|
||||
if (\core_h5p\helper::save_h5p($h5pfactory, $file, new stdClass(), false, true) === false) {
|
||||
echo $OUTPUT->notification(get_string('invalidpackage', 'core_h5p'), 'error');
|
||||
} else {
|
||||
echo $OUTPUT->notification(get_string('uploadsuccess', 'core_h5p'), 'success');
|
||||
}
|
||||
}
|
||||
$form->display();
|
||||
echo $OUTPUT->footer();
|
||||
@@ -79,6 +79,9 @@ $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['h5pmanage'] = 'Manage H5P content types';
|
||||
$string['h5ppackage'] = 'H5P content type';
|
||||
$string['h5ppackage_help'] = 'An H5P content type is a file with an H5P or ZIP extension containing all libraries required to display the content.';
|
||||
$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}.';
|
||||
@@ -92,11 +95,16 @@ $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['invalidpackage'] = 'Invalid H5P content type';
|
||||
$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['librariesmanagerdescription'] = '<p>H5P enables users to create interactive content by providing a range of content types.</p>'.
|
||||
'<p>To ensure that only trusted H5P content types are used on your site, you need to <i>either</i></p>'.
|
||||
'<ul><li>Upload H5P content types from h5p.org <i>or</i></li><li>Enable the scheduled task \'Download available H5P content types from h5p.org</li></ul>'.
|
||||
'<p>Note that users will only be able to use the H5P content types which are installed on your site.</p>';
|
||||
$string['license'] = 'License';
|
||||
$string['licenseCC010'] = 'CC0 1.0 Universal (CC0 1.0) Public Domain Dedication';
|
||||
$string['licenseCC010U'] = 'CC0 1.0 Universal';
|
||||
@@ -155,6 +163,8 @@ $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['uploadlibraries'] = 'Upload H5P content types';
|
||||
$string['uploadsuccess'] = 'H5P content types uploaded successfully';
|
||||
$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)';
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2019110500.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2019110500.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user