diff --git a/h5p/classes/player.php b/h5p/classes/player.php new file mode 100644 index 0000000000000..f07e7ac21085e --- /dev/null +++ b/h5p/classes/player.php @@ -0,0 +1,82 @@ +. + +/** + * H5P player class. + * + * @package core + * @subpackage h5p + * @copyright 2019 Moodle + * @author Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core_h5p; + +defined('MOODLE_INTERNAL') || die(); + +class player { + protected $embedtype; + protected $settings; + + /** + * Inits the H5P player for rendering the content. + * + * @param string $pluginfile Local URL of the H5P file to display. + */ + public function __construct(string $pluginfile) { + global $CFG; + + } + + /** + * Adds js assets to the current page. + */ + public function addassetstopage() { + global $PAGE, $CFG; + + 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', $this->settings, true); + } + + /** + * Outputs an H5P content. + */ + public function outputview() { + if ($this->embedtype === 'div') { + echo "
idnumber}\">
"; + } else { + echo "
" . + "" . + "
"; + } + } +} diff --git a/h5p/embed.php b/h5p/embed.php new file mode 100644 index 0000000000000..b2faeda66046b --- /dev/null +++ b/h5p/embed.php @@ -0,0 +1,56 @@ +. + +/** + * Render H5P content from an H5P file. + * + * @package core_h5p + * @copyright 2019 Sara Arjona + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once(__DIR__ . '/../config.php'); + +$pluginfile = required_param('pluginfile', PARAM_LOCALURL); + +// TODO: Check if the user has access to the file. +require_login(null, false); + +// Set up the H5P player class. +$h5pplayer = new \core_h5p\player($pluginfile); + +// Configure page. +$context = context_system::instance(); +// TODO: update the correct context. +$PAGE->set_context($context); +$PAGE->set_url(new moodle_url ('/h5p/embed.php', array('pluginfile' => $pluginfile))); +// TODO: set the title and the heading. They should be added to the h5p lang or taken from the metadata. +$PAGE->set_title('render h5p'); +$PAGE->set_heading('h5p rendering'); + +// Embed specific page setup. +$PAGE->add_body_class('h5p-embed'); +$PAGE->set_pagelayout('embedded'); + +// Add H5P assets to the page. +$h5pplayer->addassetstopage(); + +// Print page HTML. +echo $OUTPUT->header(); + +echo $h5pplayer->outputview(); + +echo $OUTPUT->footer();