���ѧۧݧ�ӧ�� �ާ֧ߧ֧էا֧� - ���֧էѧܧ�ڧ��ӧѧ�� - /home3/cpr76684/public_html/h5p.tar
���ѧ٧ѧ�
db/access.php 0000644 00000003504 15152206471 0007110 0 ustar 00 <?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 content bank contenttype capabilities. * * @package contenttype_h5p * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); $capabilities = [ 'contenttype/h5p:access' => array( 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, 'archetypes' => array( 'manager' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, ) ), 'contenttype/h5p:upload' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, 'archetypes' => [ 'manager' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, ] ], 'contenttype/h5p:useeditor' => [ 'riskbitmask' => RISK_SPAM, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, 'archetypes' => [ 'manager' => CAP_ALLOW, 'coursecreator' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, ] ], ]; tests/content_h5p_test.php 0000644 00000017570 15152206471 0011721 0 ustar 00 <?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/>. namespace contenttype_h5p; /** * Test for H5P content bank plugin. * * @package contenttype_h5p * @category test * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @coversDefaultClass \contenttype_h5p\content */ class content_h5p_test extends \advanced_testcase { /** * Tests for uploaded file. * * @covers ::get_file */ public function test_upload_file() { $this->resetAfterTest(); // Create content. $record = new \stdClass(); $record->name = 'Test content'; $record->configdata = ''; $contenttype = new \contenttype_h5p\contenttype(\context_system::instance()); $content = $contenttype->create_content($record); // Create a dummy file. $filename = 'content.h5p'; $dummy = [ 'contextid' => \context_system::instance()->id, 'component' => 'contentbank', 'filearea' => 'public', 'itemid' => $content->get_id(), 'filepath' => '/', 'filename' => $filename ]; $fs = get_file_storage(); $fs->create_file_from_string($dummy, 'dummy content'); $file = $content->get_file(); $this->assertInstanceOf(\stored_file::class, $file); $this->assertEquals($filename, $file->get_filename()); } /** * Tests for is view allowed content. * * @covers ::is_view_allowed * @dataProvider is_view_allowed_provider * * @param string $role User role to use for create and view contents. * @param array $disabledlibraries Library names to disable. * @param array $expected Array with the expected values for the contents in the following order: * ['H5P.Blanks deployed', 'H5P.Accordion deployed', 'H5P.Accordion undeployed', 'Invalid content']. */ public function test_is_view_allowed(string $role, array $disabledlibraries, array $expected): void { global $CFG, $USER, $DB; $this->resetAfterTest(); // Create a course. $course = $this->getDataGenerator()->create_course(); $coursecontext = \context_course::instance($course->id); // Set user. if ($role == 'admin') { $this->setAdminUser(); } else { // Enrol user to the course. $user = $this->getDataGenerator()->create_and_enrol($course, $role); $this->setUser($user); } // Add contents to the content bank. $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank'); $filepath = $CFG->dirroot . '/h5p/tests/fixtures/filltheblanks.h5p'; $contents = $generator->generate_contentbank_data('contenttype_h5p', 1, $USER->id, $coursecontext, true, $filepath); $filltheblanks = array_shift($contents); $filepath = $CFG->dirroot . '/h5p/tests/fixtures/ipsums.h5p'; $contents = $generator->generate_contentbank_data('contenttype_h5p', 2, $USER->id, $coursecontext, true, $filepath); $accordion1 = array_shift($contents); $accordion2 = array_shift($contents); $filepath = $CFG->dirroot . '/h5p/tests/fixtures/invalid.zip'; $contents = $generator->generate_contentbank_data('contenttype_h5p', 1, $USER->id, $coursecontext, true, $filepath); $invalid = array_shift($contents); // Load some of these H5P files though the player to create the H5P DB entries. $h5pplayer = new \core_h5p\player($filltheblanks->get_file_url(), new \stdClass(), true); $h5pplayer = new \core_h5p\player($accordion1->get_file_url(), new \stdClass(), true); // Check the expected H5P content has been created. $this->assertEquals(2, $DB->count_records('h5p')); $this->assertEquals(4, $DB->count_records('contentbank_content')); // Disable libraries. foreach ($disabledlibraries as $libraryname) { $libraryid = $DB->get_field('h5p_libraries', 'id', ['machinename' => $libraryname]); \core_h5p\api::set_library_enabled((int) $libraryid, false); } $this->assertEquals($expected[0], $filltheblanks->is_view_allowed()); $this->assertEquals($expected[1], $accordion1->is_view_allowed()); $this->assertEquals($expected[2], $accordion2->is_view_allowed()); $this->assertEquals($expected[3], $invalid->is_view_allowed()); // Check that after enabling libraries again, all the content return true (but the invalid package). foreach ($disabledlibraries as $libraryname) { $libraryid = $DB->get_field('h5p_libraries', 'id', ['machinename' => $libraryname]); \core_h5p\api::set_library_enabled((int) $libraryid, true); } $this->assertEquals(true, $filltheblanks->is_view_allowed()); $this->assertEquals(true, $accordion1->is_view_allowed()); $this->assertEquals(true, $accordion2->is_view_allowed()); // It will be deployed, so now it will always return true. $this->assertEquals($expected[3], $invalid->is_view_allowed()); } /** * Data provider for test_is_view_allowed. * * @return array */ public function is_view_allowed_provider(): array { return [ 'Editing teacher with all libraries enabled' => [ 'role' => 'editingteacher', 'disabledlibraries' => [], 'expected' => [true, true, true, false], ], 'Manager with all libraries enabled' => [ 'role' => 'manager', 'disabledlibraries' => [], 'expected' => [true, true, true, true], ], 'Admin with all libraries enabled' => [ 'role' => 'admin', 'disabledlibraries' => [], 'expected' => [true, true, true, true], ], 'Editing teacher with H5P.Accordion disabled' => [ 'role' => 'editingteacher', 'disabledlibraries' => ['H5P.Accordion'], 'expected' => [true, false, false, false], ], 'Manager with H5P.Accordion disabled' => [ 'role' => 'manager', 'disabledlibraries' => ['H5P.Accordion'], 'expected' => [true, false, true, true], ], 'Admin with H5P.Accordion disabled' => [ 'role' => 'admin', 'disabledlibraries' => ['H5P.Accordion'], 'expected' => [true, false, true, true], ], 'Editing teacher with all libraries disabled' => [ 'role' => 'editingteacher', 'disabledlibraries' => ['H5P.Accordion', 'H5P.Blanks'], 'expected' => [false, false, false, false], ], 'Manager with all libraries disabled' => [ 'role' => 'manager', 'disabledlibraries' => ['H5P.Accordion', 'H5P.Blanks'], 'expected' => [false, false, true, true], ], 'Admin with all libraries disabled' => [ 'role' => 'admin', 'disabledlibraries' => ['H5P.Accordion', 'H5P.Blanks'], 'expected' => [false, false, true, true], ], ]; } } tests/contenttype_h5p_test.php 0000644 00000016723 15152206471 0012622 0 ustar 00 <?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/>. namespace contenttype_h5p; /** * Test for H5P content bank plugin. * * @package contenttype_h5p * @category test * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @coversDefaultClass \contenttype_h5p\contenttype */ class contenttype_h5p_test extends \advanced_testcase { /** * Test the behaviour of delete_content(). */ public function test_delete_content() { global $CFG, $USER, $DB; $this->resetAfterTest(); $systemcontext = \context_system::instance(); // Create users. $roleid = $DB->get_field('role', 'id', array('shortname' => 'manager')); $manager = $this->getDataGenerator()->create_user(); $this->getDataGenerator()->role_assign($roleid, $manager->id); $this->setUser($manager); // Add an H5P file to the content bank. $filepath = $CFG->dirroot . '/h5p/tests/fixtures/filltheblanks.h5p'; $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank'); $contents = $generator->generate_contentbank_data('contenttype_h5p', 2, $USER->id, $systemcontext, true, $filepath); $content1 = array_shift($contents); $content2 = array_shift($contents); // Load this H5P file though the player to create the H5P DB entries. $h5pplayer = new \core_h5p\player($content1->get_file_url(), new \stdClass(), true); $h5pplayer->add_assets_to_page(); $h5pplayer->output(); $h5pplayer = new \core_h5p\player($content2->get_file_url(), new \stdClass(), true); $h5pplayer->add_assets_to_page(); $h5pplayer->output(); // Check the H5P content has been created. $this->assertEquals(2, $DB->count_records('h5p')); $this->assertEquals(2, $DB->count_records('contentbank_content')); // Check the H5P content is removed after calling this method. $contenttype = new \contenttype_h5p\contenttype($systemcontext); $contenttype->delete_content($content1); $this->assertEquals(1, $DB->count_records('h5p')); $this->assertEquals(1, $DB->count_records('contentbank_content')); } /** * Tests can_upload behavior. * * @covers ::can_upload */ public function test_can_upload() { $this->resetAfterTest(); $systemcontext = \context_system::instance(); $systemtype = new \contenttype_h5p\contenttype($systemcontext); // Admins can upload. $this->setAdminUser(); $this->assertTrue($systemtype->can_upload()); // Teacher can upload in the course but not at system level. $course = $this->getDataGenerator()->create_course(); $teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher'); $coursecontext = \context_course::instance($course->id); $coursetype = new \contenttype_h5p\contenttype($coursecontext); $this->setUser($teacher); $this->assertTrue($coursetype->can_upload()); $this->assertFalse($systemtype->can_upload()); // Users can't upload. $user = $this->getDataGenerator()->create_user(); $this->setUser($user); $this->assertFalse($coursetype->can_upload()); $this->assertFalse($systemtype->can_upload()); } /** * Tests get_icon result. * * @covers ::get_icon */ public function test_get_icon() { global $CFG; $this->resetAfterTest(); $systemcontext = \context_system::instance(); $this->setAdminUser(); $contenttype = new contenttype($systemcontext); // Add an H5P fill the blanks file to the content bank. $filepath = $CFG->dirroot . '/h5p/tests/fixtures/filltheblanks.h5p'; $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank'); $contents = $generator->generate_contentbank_data('contenttype_h5p', 1, 0, $systemcontext, true, $filepath); $filltheblanks = array_shift($contents); // Add an H5P find the words file to the content bank. $filepath = $CFG->dirroot . '/h5p/tests/fixtures/find-the-words.h5p'; $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank'); $contents = $generator->generate_contentbank_data('contenttype_h5p', 1, 0, $systemcontext, true, $filepath); $findethewords = array_shift($contents); // Check before deploying the icon for both contents is the same: default one. // Because we don't know specific H5P content type yet. $defaulticon = $contenttype->get_icon($filltheblanks); $this->assertEquals($defaulticon, $contenttype->get_icon($findethewords)); $this->assertStringContainsString('h5p', $defaulticon); // Deploy one of the contents though the player to create the H5P DB entries and know specific content type. $h5pplayer = new \core_h5p\player($findethewords->get_file_url(), new \stdClass(), true); $h5pplayer->add_assets_to_page(); $h5pplayer->output(); // Once the H5P has been deployed, we know the specific H5P content type, so the icon returned is not default one. $findicon = $contenttype->get_icon($findethewords); $this->assertNotEquals($defaulticon, $findicon); $this->assertStringContainsStringIgnoringCase('find', $findicon); } /** * Tests get_download_url result. * * @covers ::get_download_url */ public function test_get_download_url() { global $CFG; $this->resetAfterTest(); $systemcontext = \context_system::instance(); $this->setAdminUser(); $contenttype = new contenttype($systemcontext); // Add an H5P fill the blanks file to the content bank. $filename = 'filltheblanks.h5p'; $filepath = $CFG->dirroot . '/h5p/tests/fixtures/' . $filename; $generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank'); $contents = $generator->generate_contentbank_data('contenttype_h5p', 1, 0, $systemcontext, true, $filepath); $filltheblanks = array_shift($contents); // Check before deploying the URL is returned OK. $url1 = $contenttype->get_download_url($filltheblanks); $this->assertNotEmpty($url1); $this->assertStringContainsString($filename, $url1); // Deploy the contents though the player to create the H5P DB entries and know specific content type. $h5pplayer = new \core_h5p\player($filltheblanks->get_file_url(), new \stdClass(), true); $h5pplayer->add_assets_to_page(); $h5pplayer->output(); // Once the H5P has been deployed, the URL is still the same. $url2 = $contenttype->get_download_url($filltheblanks); $this->assertNotEmpty($url2); $this->assertEquals($url1, $url2); } } tests/behat/teacher_upload_content.feature 0000644 00000020136 15152206471 0015064 0 ustar 00 @core @core_contentbank @core_h5p @contenttype_h5p @_file_upload @_switch_iframe @javascript Feature: H5P file upload to content bank for non admins In order import new H5P content to content bank As an admin I need to be able to upload a new .h5p file to content bank Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | | teacher2 | Teacher | 2 | teacher2@example.com | And the following "categories" exist: | name | category | idnumber | | Cat 1 | 0 | CAT1 | And the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | CAT1 | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | | teacher2 | C1 | editingteacher | And the following "blocks" exist: | blockname | contextlevel | reference | pagetypepattern | defaultregion | | private_files | System | 1 | my-index | side-post | And I log in as "teacher1" And I follow "Manage private files..." And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager And I click on "Save changes" "button" Scenario: Teachers can not access system level content bank Given I turn editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present When I expand "Site pages" node Then I should not see "Content bank" Scenario: Teachers can access course level content bank Given I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present When I expand "Site pages" node Then I should see "Content bank" Scenario: Teachers can upload .h5p extension files to course content bank Given I log out And I log in as "admin" And I navigate to "H5P > Manage H5P content types" in site administration And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "H5P content type" filemanager And I click on "Upload H5P content types" "button" in the "#fitem_id_uploadlibraries" "css_element" And I log out And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present When I expand "Site pages" node And I click on "Content bank" "link" Then I should not see "filltheblanks.h5p" And I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" And I wait until the page is ready And I should see "filltheblanks.h5p" Scenario: Other teachers can see uploaded H5P contents Given I log out And I log in as "admin" And I navigate to "H5P > Manage H5P content types" in site administration And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "H5P content type" filemanager And I click on "Upload H5P content types" "button" in the "#fitem_id_uploadlibraries" "css_element" And I log out And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present When I expand "Site pages" node And I click on "Content bank" "link" And I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" And I wait until the page is ready And I should see "filltheblanks.h5p" And I log out When I log in as "teacher2" And I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Content bank" "link" Then I should see "filltheblanks.h5p" Scenario: Teachers can not upload and deploy content types when libraries are not installed Given I log out And I log in as "admin" And I navigate to "H5P > Manage H5P content types" in site administration And I should not see "Fill in the Blanks" And I log out And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Content bank" "link" When I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" Then I should see "Sorry, this file is not valid." And I should not see "filltheblanks.h5p" And I log out And I log in as "admin" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I should not see "filltheblanks.h5p" Scenario: Teachers can not see existing contents when libraries are not installed Given I log out And I log in as "admin" And I follow "Manage private files..." And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager And I click on "Save changes" "button" And I navigate to "H5P > Manage H5P content types" in site administration And I should not see "Fill in the Blanks" When I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "H5P content type" filemanager And I click on "Upload H5P content types" "button" in the "#fitem_id_uploadlibraries" "css_element" And I wait until the page is ready And I should see "Fill in the Blanks" And I log out And I log in as "teacher1" Given I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present When I expand "Site pages" node And I click on "Content bank" "link" And I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" And I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe Then I should see "Of which countries" Then I should not see "missing-required-library" And I switch to the main frame Given I log out And I log in as "admin" And I navigate to "H5P > Manage H5P content types" in site administration When I click on "Delete version" "link" in the "Fill in the Blanks" "table_row" And I press "Continue" Then I should not see "Fill in the Blanks" And I log out And I log in as "teacher1" Given I am on "Course 1" course homepage When I expand "Site pages" node And I click on "Content bank" "link" Then I should not see "filltheblanks.h5p" And I log out And I log in as "admin" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I should see "filltheblanks.h5p" And I click on "filltheblanks.h5p" "link" And I switch to "h5p-player" class iframe And I should see "missing-required-library" tests/behat/manage_content.feature 0000644 00000005307 15152206471 0013340 0 ustar 00 @core @core_contentbank @core_h5p @contenttype_h5p @_file_upload @javascript Feature: Manage H5P content from the content bank In order to manage H5P content in the content bank As an admin I need to be able to edit any H5P content in the content bank Background: Given I log in as "admin" And I navigate to "H5P > Manage H5P content types" in site administration And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "H5P content type" filemanager And I click on "Upload H5P content types" "button" in the "#fitem_id_uploadlibraries" "css_element" And I upload "h5p/tests/fixtures/ipsums.h5p" file to "H5P content type" filemanager And I click on "Upload H5P content types" "button" in the "#fitem_id_uploadlibraries" "css_element" And the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | And the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | And the following "contentbank content" exist: | contextlevel | reference | contenttype | user | contentname | filepath | | Course | C1 | contenttype_h5p | admin | filltheblanks.h5p | /h5p/tests/fixtures/filltheblanks.h5p | | Course | C1 | contenttype_h5p | teacher1 | ipsums.h5p | /h5p/tests/fixtures/ipsums.h5p | And I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present And I log out Scenario: Teachers can rename their own content in the content bank Given I log in as "teacher1" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I follow "ipsums.h5p" When I click on "More" "button" And I should see "Rename" And I click on "Rename" "link" And I set the field "Content name" to "New name" And I click on "Rename" "button" And I wait until the page is ready Then I should not see "ipsums.h5p" And I should see "New name" Scenario: Teachers can't rename content created by other users in the content bank Given I log in as "teacher1" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" When I follow "filltheblanks.h5p" And I click on "More" "button" Then I should not see "Rename" tests/behat/admin_replace_content.feature 0000644 00000002776 15152206471 0014702 0 ustar 00 @core @core_contentbank @core_h5p @contenttype_h5p @_file_upload @_switch_iframe @javascript Feature: Replace H5P file from an existing content In order to replace an H5P content from the content bank As an admin I need to be able to replace the content with a new .h5p file Background: Given the following "contentbank content" exist: | contextlevel | reference | contenttype | user | contentname | filepath | | System | | contenttype_h5p | admin | filltheblanks.h5p | /h5p/tests/fixtures/filltheblanks.h5p | And I log in as "admin" And I turn editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Content bank" "link" Scenario: Admins can replace the original .h5p file with a new one Given I click on "filltheblanks.h5p" "link" And I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe And I should see "Of which countries" And I switch to the main frame When I click on "More" "button" And I click on "Replace with file" "link" And I upload "h5p/tests/fixtures/ipsums.h5p" file to "Upload content" filemanager And I click on "Save changes" "button" Then I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe And I should see "Lorum ipsum" And I switch to the main frame tests/behat/admin_upload_content.feature 0000644 00000011000 15152206471 0014527 0 ustar 00 @core @core_contentbank @core_h5p @contenttype_h5p @_file_upload @_switch_iframe @javascript Feature: H5P file upload to content bank for admins In order import new H5P content to content bank As an admin I need to be able to upload a new .h5p file to content bank Background: Given the following "blocks" exist: | blockname | contextlevel | reference | pagetypepattern | defaultregion | | private_files | System | 1 | my-index | side-post | And I log in as "admin" And I follow "Manage private files..." And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "Files" filemanager And I click on "Save changes" "button" And I turn editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Content bank" "link" Scenario: Admins can upload .h5p extension files to content bank Given I should not see "filltheblanks.h5p" When I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" And I wait until the page is ready Then I should see "filltheblanks.h5p" Scenario: Admins can see uploaded H5P contents Given I should not see "filltheblanks.h5p" When I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" And I wait until the page is ready And I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe Then I should see "Of which countries" Scenario: Users can't see content managed by disabled plugins Given I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" And I wait until the page is ready And I should see "filltheblanks.h5p" And I navigate to "Plugins > Content bank > Manage content types" in site administration And I click on "Disable" "icon" in the "H5P" "table_row" And I wait until the page is ready When I navigate to "Plugins > Content bank" in site administration Then I should not see "filltheblanks.h5p" Scenario: Contents in a context are not available from other contexts Given the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | When I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" And I wait until the page is ready Then I should see "filltheblanks.h5p" And I am on "Course 1" course homepage And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Content bank" "link" And I should not see "filltheblanks.h5p" Scenario: Admins can upload and deployed content types when libraries are not installed Given I navigate to "H5P > Manage H5P content types" in site administration And I should not see "Fill in the Blanks" And I follow "Dashboard" And I expand "Site pages" node And I click on "Content bank" "link" And I should not see "filltheblanks.h5p" When I click on "Upload" "link" And I click on "Choose a file..." "button" And I click on "Private files" "link" in the ".fp-repo-area" "css_element" And I click on "filltheblanks.h5p" "link" And I click on "Select this file" "button" And I click on "Save changes" "button" And I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe Then I should see "Of which countries" And I switch to the main frame And I navigate to "H5P > Manage H5P content types" in site administration And I should see "Fill in the Blanks" tests/behat/teacher_replace_content.feature 0000644 00000010414 15152206471 0015211 0 ustar 00 @core @core_contentbank @core_h5p @contenttype_h5p @_file_upload @_switch_iframe @javascript Feature: Replace H5P file from an existing content requires special capabilities In order replace an H5P content from the content bank As a teacher I need to be able to replace the content only if certain capabilities are allowed Background: Given I log in as "admin" And I navigate to "H5P > Manage H5P content types" in site administration And I upload "h5p/tests/fixtures/ipsums.h5p" file to "H5P content type" filemanager And I click on "Upload H5P content types" "button" in the "#fitem_id_uploadlibraries" "css_element" And I upload "h5p/tests/fixtures/filltheblanks.h5p" file to "H5P content type" filemanager And I click on "Upload H5P content types" "button" in the "#fitem_id_uploadlibraries" "css_element" And the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | And the following "categories" exist: | name | category | idnumber | | Cat 1 | 0 | CAT1 | And the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | CAT1 | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | And the following "contentbank content" exist: | contextlevel | reference | contenttype | user | contentname | filepath | | Course | C1 | contenttype_h5p | admin | admincontent | /h5p/tests/fixtures/ipsums.h5p | | Course | C1 | contenttype_h5p | teacher1 | teachercontent | /h5p/tests/fixtures/filltheblanks.h5p | And I log out And I log in as "teacher1" And I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present And I expand "Site pages" node And I click on "Content bank" "link" # Force the content deploy And I click on "admincontent" "link" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" Scenario: Teacher can replace its own H5P files Given I click on "teachercontent" "link" When I click on "More" "button" And I click on "Replace with file" "link" And I upload "h5p/tests/fixtures/ipsums.h5p" file to "Upload content" filemanager And I click on "Save changes" "button" Then I switch to "h5p-player" class iframe And I switch to "h5p-iframe" class iframe And I should see "Lorum ipsum" And I switch to the main frame Scenario: Teacher cannot replace another user's H5P files When I click on "admincontent" "link" And I click on "More" "button" Then I should not see "Replace with file" Scenario: Teacher cannot replace a content without having upload capability Given the following "permission overrides" exist: | capability | permission | role | contextlevel | reference | | moodle/contentbank:upload | Prevent | editingteacher | Course | C1 | When I click on "teachercontent" "link" And I click on "More" "button" Then I should not see "Replace with file" Scenario: Teacher cannot replace a content without having the H5P upload capability Given the following "permission overrides" exist: | capability | permission | role | contextlevel | reference | | contenttype/h5p:upload | Prevent | editingteacher | Course | C1 | When I click on "teachercontent" "link" And I click on "More" "button" Then I should not see "Replace with file" Scenario: Teacher cannot replace a content without having the manage own content capability Given the following "permission overrides" exist: | capability | permission | role | contextlevel | reference | | moodle/contentbank:manageowncontent | Prevent | editingteacher | Course | C1 | When I click on "teachercontent" "link" And I click on "More" "button" Then I should not see "Replace with file" tests/behat/disable_contenttypes.feature 0000644 00000010756 15152206471 0014604 0 ustar 00 @core @core_contentbank @core_h5p @contenttype_h5p @_file_upload @javascript Feature: Disable H5P content-types from the content bank In order to disable H5P content-types As an admin I need to be able to check they are not displayed in the content bank Background: Given the following "users" exist: | username | firstname | lastname | email | | teacher1 | Teacher | 1 | teacher1@example.com | And the following "courses" exist: | fullname | shortname | category | | Course 1 | C1 | 0 | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | And the following "contentbank contents" exist: | contextlevel | reference | contenttype | user | contentname | filepath | | Course | C1 | contenttype_h5p | admin | filltheblanks | /h5p/tests/fixtures/filltheblanks.h5p | | Course | C1 | contenttype_h5p | admin | accordion | /h5p/tests/fixtures/ipsums.h5p | | Course | C1 | contenttype_h5p | admin | invalidh5p | /h5p/tests/fixtures/h5ptest.zip | And I log in as "admin" And I am on "Course 1" course homepage with editing mode on And the following config values are set as admin: | unaddableblocks | | theme_boost| And I add the "Navigation" block if not present And I log out Scenario: Teachers cannot view disabled or invalid content-types Given I log in as "teacher1" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I should see "accordion" And I should see "filltheblanks" And I should not see "invalidh5p" And I log out And I log in as "admin" And I navigate to "H5P > Manage H5P content types" in site administration And I click on "Disable" "link" in the "Accordion" "table_row" And I log out When I log in as "teacher1" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" Then I should not see "accordion" And I should see "filltheblanks" And I should not see "invalidh5p" Scenario: Admins cannot view disabled content-types Given I log in as "admin" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I should see "accordion" And I should see "filltheblanks" And I should see "invalidh5p" And I navigate to "H5P > Manage H5P content types" in site administration And I click on "Disable" "link" in the "Accordion" "table_row" When I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" Then I should not see "accordion" And I should see "filltheblanks" And I should see "invalidh5p" Scenario: Teachers cannot create disabled content-types Given I log in as "teacher1" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I click on "[data-action=Add-content]" "css_element" And I should see "Accordion" And I should see "Fill in the Blanks" And I log out And I log in as "admin" And I navigate to "H5P > Manage H5P content types" in site administration And I click on "Disable" "link" in the "Accordion" "table_row" And I log out When I log in as "teacher1" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I click on "[data-action=Add-content]" "css_element" Then I should not see "Accordion" And I should see "Fill in the Blanks" Scenario: Admins cannot create disabled content-types Given I log in as "admin" And I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I click on "[data-action=Add-content]" "css_element" And I should see "Accordion" And I should see "Fill in the Blanks" And I navigate to "H5P > Manage H5P content types" in site administration And I click on "Disable" "link" in the "Accordion" "table_row" When I am on "Course 1" course homepage And I expand "Site pages" node And I click on "Content bank" "link" And I click on "[data-action=Add-content]" "css_element" Then I should not see "Accordion" And I should see "Fill in the Blanks" version.php 0000644 00000002224 15152206471 0006745 0 ustar 00 <?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/>. /** * Version details * * @package contenttype_h5p * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); $plugin->version = 2022112800; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2022111800; // Requires this Moodle version. $plugin->component = 'contenttype_h5p'; // Full name of the plugin (used for diagnostics). classes/privacy/provider.php 0000644 00000002720 15152206471 0012225 0 ustar 00 <?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 core_contentbank. * * @package contenttype_h5p * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace contenttype_h5p\privacy; /** * Privacy provider implementation for contenttype_h5p. * * @copyright 2020 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'; } } classes/form/editor.php 0000644 00000015736 15152206471 0011162 0 ustar 00 <?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/>. /** * Provides the class that defines the form for the H5P authoring tool. * * @package contenttype_h5p * @copyright 2020 Victor Deniz <victor@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace contenttype_h5p\form; use contenttype_h5p\content; use contenttype_h5p\contenttype; use core_contentbank\form\edit_content; use core_h5p\api; use core_h5p\editor as h5peditor; use core_h5p\factory; use core_h5p\helper; use stdClass; /** * Defines the form for editing an H5P content. * * @copyright 2020 Victor Deniz <victor@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class editor extends edit_content { /** @var $h5peditor H5P editor object */ private $h5peditor; /** @var $content The content being edited */ private $content; /** * Defines the form fields. */ protected function definition() { global $DB, $OUTPUT; $mform = $this->_form; $errors = []; $notifications = []; // Id of the content to edit. $id = $this->_customdata['id']; // H5P content type to create. $library = optional_param('library', null, PARAM_TEXT); if (empty($id) && empty($library)) { $returnurl = new \moodle_url('/contentbank/index.php', ['contextid' => $this->_customdata['contextid']]); throw new \moodle_exception('invalidcontentid', 'error', $returnurl); } $this->h5peditor = new h5peditor(); $this->set_display_vertical(); $mform->addElement('html', $OUTPUT->heading($this->_customdata['heading'], 2)); if ($id) { // The H5P editor needs the H5P content id (h5p table). $record = $DB->get_record('contentbank_content', ['id' => $id]); $this->content = new content($record); $file = $this->content->get_file(); $h5p = api::get_content_from_pathnamehash($file->get_pathnamehash()); if (!$h5p) { // H5P content has not been deployed yet. Let's check why. $factory = new \core_h5p\factory(); $factory->get_framework()->set_file($file); $h5pid = helper::save_h5p($factory, $file, new stdClass()); $errors = $factory->get_framework()->getMessages('error'); $notifications = $factory->get_framework()->getMessages('info'); } else { $h5pid = $h5p->id; } if ($h5pid) { $mform->addElement('hidden', 'h5pid', $h5pid); $mform->setType('h5pid', PARAM_INT); $this->h5peditor->set_content($h5pid); } } else { // The H5P editor needs the H5P content type library name for a new content. $mform->addElement('hidden', 'library', $library); $mform->setType('library', PARAM_TEXT); $this->h5peditor->set_library($library, $this->_customdata['contextid'], 'contentbank', 'public'); } $mformid = 'coolh5peditor'; $mform->setAttributes(array('id' => $mformid) + $mform->getAttributes()); if ($errors || $notifications) { // Show the error messages and a Cancel button. foreach ($errors as $error) { $mform->addElement('warning', $error->code, 'notify', $error->message); } foreach ($notifications as $key => $notification) { $mform->addElement('warning', 'notification_'.$key, 'notify', $notification); } $mform->addElement('cancel', 'cancel', get_string('back')); } else { $this->h5peditor->add_editor_to_form($mform); $this->add_action_buttons(); } } /** * Modify or create an H5P content from the form data. * * @param stdClass $data Form data to create or modify an H5P content. * * @return int The id of the edited or created content. */ public function save_content(stdClass $data): int { global $DB; // The H5P libraries expect data->id as the H5P content id. // The method H5PCore::saveContent throws an error if id is set but empty. if (empty($data->id)) { unset($data->id); } else { // The H5P libraries save in $data->id the H5P content id (h5p table), so the content id is saved in another var. $contentid = $data->id; } $h5pcontentid = $this->h5peditor->save_content($data); $factory = new factory(); $h5pfs = $factory->get_framework(); // Needs the H5P file id to create or update the content bank record. $h5pcontent = $h5pfs->loadContent($h5pcontentid); $fs = get_file_storage(); $file = $fs->get_file_by_hash($h5pcontent['pathnamehash']); // Creating new content. if (!isset($data->h5pid)) { // The initial name of the content is the title of the H5P content. $cbrecord = new stdClass(); $cbrecord->name = json_decode($data->h5pparams)->metadata->title; $context = \context::instance_by_id($data->contextid, MUST_EXIST); // Create entry in content bank. $contenttype = new contenttype($context); $newcontent = $contenttype->create_content($cbrecord); if ($file && $newcontent) { $updatedfilerecord = new stdClass(); $updatedfilerecord->id = $file->get_id(); $updatedfilerecord->itemid = $newcontent->get_id(); // As itemid changed, the pathnamehash has to be updated in the file table. $pathnamehash = \file_storage::get_pathname_hash($file->get_contextid(), $file->get_component(), $file->get_filearea(), $updatedfilerecord->itemid, $file->get_filepath(), $file->get_filename()); $updatedfilerecord->pathnamehash = $pathnamehash; $DB->update_record('files', $updatedfilerecord); // The pathnamehash in the h5p table must match the file pathnamehash. $h5pfs->updateContentFields($h5pcontentid, ['pathnamehash' => $pathnamehash]); } } else { // Update content. $this->content->update_content(); } return $contentid ?? $newcontent->get_id(); } } classes/content.php 0000644 00000010323 15152206471 0010366 0 ustar 00 <?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 Content manager class * * @package contenttype_h5p * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace contenttype_h5p; /** * H5P Content manager class * * @package contenttype_h5p * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class content extends \core_contentbank\content { /** * Returns user has access permission for the content itself. * If the H5P content-type library is disabled, the user won't have access to it. * * @return bool True if content could be accessed. False otherwise. */ public function is_view_allowed(): bool { // Force H5P content to be deployed. $fileurl = $this->get_file_url(); if (empty($fileurl)) { // This should never happen because H5P contents should have always a file. However, this extra-checked has been added // to avoid the contentbank stop working if, for any unkonwn/weird reason, the file doesn't exist. return false; } // Skip capability check when creating the H5P content (because it has been created by trusted users). $h5pplayer = new \core_h5p\player($fileurl, new \stdClass(), true, '', true); // Flush error messages. $h5pplayer->get_messages(); // Check if the H5P entry has been created and if the main library is enabled. $file = $this->get_file(); if (!empty($file)) { $h5p = \core_h5p\api::get_content_from_pathnamehash($file->get_pathnamehash()); if (empty($h5p)) { // If there is no H5P entry for this content, it won't be displayed unless the user has the manageanycontent // capability. Reasons for contents without a proper H5P entry in DB: // - Invalid H5P package (it won't be never deployed). // - Disabled content-type library (it can't be deployed so there is no way to know the mainlibraryid). $context = \context::instance_by_id($this->content->contextid); if (!has_capability('moodle/contentbank:manageanycontent', $context)) { return false; } } else if (!\core_h5p\api::is_library_enabled((object) ['id' => $h5p->mainlibraryid])) { // If the main library is disabled, it won't be displayed. return false; } } return parent::is_view_allowed(); } /** * Import a file as a valid content. * Before importing the file, this method will check if the file is a valid H5P package. If it's not valid, it will thrown * an exception. * * @throws \file_exception If file operations fail * @param \stored_file $file File to store in the content file area. * @return \stored_file|null the stored content file or null if the file is discarted. */ public function import_file(\stored_file $file): ?\stored_file { // The H5P content can be only deployed if the author of the .h5p file can update libraries or if all the // content-type libraries exist, to avoid users without the h5p:updatelibraries capability upload malicious content. $onlyupdatelibs = !\core_h5p\helper::can_update_library($file); if (!\core_h5p\api::is_valid_package($file, $onlyupdatelibs)) { throw new \file_exception('invalidpackage'); } return parent::import_file($file); } } classes/contenttype.php 0000644 00000014203 15152206471 0011271 0 ustar 00 <?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 content type manager class * * @package contenttype_h5p * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace contenttype_h5p; use core\event\contentbank_content_viewed; use stdClass; use core_h5p\editor_ajax; use core_h5p\file_storage; use core_h5p\local\library\autoloader; use Moodle\H5PCore; /** * H5P content bank manager class * * @package contenttype_h5p * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class contenttype extends \core_contentbank\contenttype { /** * Delete this content from the content_bank and remove all the H5P related information. * * @param content $content The content to delete. * @return boolean true if the content has been deleted; false otherwise. */ public function delete_content(\core_contentbank\content $content): bool { // Delete the H5P content. $factory = new \core_h5p\factory(); if (!empty($content->get_file_url())) { \core_h5p\api::delete_content_from_pluginfile_url($content->get_file_url(), $factory); } // Delete the content from the content_bank. return parent::delete_content($content); } /** * Returns the HTML content to add to view.php visualizer. * * @param content $content The content to be displayed. * @return string HTML code to include in view.php. */ public function get_view_content(\core_contentbank\content $content): string { // Trigger an event for viewing this content. $event = contentbank_content_viewed::create_from_record($content->get_content()); $event->trigger(); $fileurl = $content->get_file_url(); $html = \core_h5p\player::display($fileurl, new \stdClass(), true); return $html; } /** * Returns the HTML code to render the icon for H5P content types. * * @param content $content The content to be displayed. * @return string HTML code to render the icon */ public function get_icon(\core_contentbank\content $content): string { global $OUTPUT, $DB; $iconurl = $OUTPUT->image_url('f/h5p-64', 'moodle')->out(false); $file = $content->get_file(); if (!empty($file)) { $h5p = \core_h5p\api::get_content_from_pathnamehash($file->get_pathnamehash()); if (!empty($h5p)) { \core_h5p\local\library\autoloader::register(); if ($h5plib = $DB->get_record('h5p_libraries', ['id' => $h5p->mainlibraryid])) { $h5pfilestorage = new \core_h5p\file_storage(); $h5picon = $h5pfilestorage->get_icon_url( $h5plib->id, $h5plib->machinename, $h5plib->majorversion, $h5plib->minorversion); if (!empty($h5picon)) { $iconurl = $h5picon; } } } } return $iconurl; } /** * Return an array of implemented features by this plugin. * * @return array */ protected function get_implemented_features(): array { return [self::CAN_UPLOAD, self::CAN_EDIT, self::CAN_DOWNLOAD]; } /** * Return an array of extensions this contenttype could manage. * * @return array */ public function get_manageable_extensions(): array { return ['.h5p']; } /** * Returns user has access capability for the content itself. * * @return bool True if content could be accessed. False otherwise. */ protected function is_access_allowed(): bool { return true; } /** * Returns the list of different H5P content types the user can create. * * @return array An object for each H5P content type: * - string typename: descriptive name of the H5P content type. * - string typeeditorparams: params required by the H5P editor. * - url typeicon: H5P content type icon. */ public function get_contenttype_types(): array { // Get the H5P content types available. autoloader::register(); $editorajax = new editor_ajax(); $h5pcontenttypes = $editorajax->getLatestLibraryVersions(); $types = []; $h5pfilestorage = new file_storage(); foreach ($h5pcontenttypes as $h5pcontenttype) { if ($h5pcontenttype->enabled) { // Only enabled content-types will be displayed. $library = [ 'name' => $h5pcontenttype->machine_name, 'majorVersion' => $h5pcontenttype->major_version, 'minorVersion' => $h5pcontenttype->minor_version, ]; $key = H5PCore::libraryToString($library); $type = new stdClass(); $type->key = $key; $type->typename = $h5pcontenttype->title; $type->typeeditorparams = 'library=' . $key; $type->typeicon = $h5pfilestorage->get_icon_url( $h5pcontenttype->id, $h5pcontenttype->machine_name, $h5pcontenttype->major_version, $h5pcontenttype->minor_version); $types[] = $type; } } return $types; } } lang/en/contenttype_h5p.php 0000644 00000002501 15152206471 0011731 0 ustar 00 <?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 plugin 'contenttype_h5p' * * @package contenttype_h5p * @copyright 2020 Amaia Anabitarte <amaia@moodle.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $string['description'] = 'H5P interactive content'; $string['pluginname'] = 'H5P'; $string['pluginname_help'] = 'Content bank to upload and share H5P content'; $string['privacy:metadata'] = 'The H5P content bank plugin does not store any personal data.'; $string['h5p:access'] = 'Access H5P content in the content bank'; $string['h5p:upload'] = 'Upload new H5P content'; $string['h5p:useeditor'] = 'Create or edit content using the H5P editor';
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | ���֧ߧ֧�ѧ�ڧ� ����ѧߧڧ��: 0 |
proxy
|
phpinfo
|
���ѧ����ۧܧ�