/** * Include settings and assets for the given content. * * @since 1.0.0 * @param array $content * @param boolean $no_cache * @return string Embed code */ public function add_assets($content, $no_cache = FALSE) { // Add core assets $this->add_core_assets(); // Detemine embed type $embed = H5PCore::determineEmbedType($content['embedType'], $content['library']['embedTypes']); // Make sure content isn't added twice $cid = 'cid-' . $content['id']; if (!isset(self::$settings['contents'][$cid])) { self::$settings['contents'][$cid] = $this->get_content_settings($content); $core = $this->get_h5p_instance('core'); // Get assets for this content $preloaded_dependencies = $core->loadContentDependencies($content['id'], 'preloaded'); $files = $core->getDependenciesFiles($preloaded_dependencies); $this->alter_assets($files, $preloaded_dependencies, $embed); if ($embed === 'div') { $this->enqueue_assets($files); } elseif ($embed === 'iframe') { self::$settings['contents'][$cid]['scripts'] = $core->getAssetsUrls($files['scripts']); self::$settings['contents'][$cid]['styles'] = $core->getAssetsUrls($files['styles']); } } if ($embed === 'div') { return '<div class="h5p-content" data-content-id="' . $content['id'] . '"></div>'; } else { return '<div class="h5p-iframe-wrapper"><iframe id="h5p-iframe-' . $content['id'] . '" class="h5p-iframe" data-content-id="' . $content['id'] . '" style="height:1px" src="about:blank" frameBorder="0" scrolling="no"></iframe></div>'; } }
} } if (empty($export)) { // Remove Download button when there's no export URL $content['disable'] |= \H5PCore::DISABLE_DOWNLOAD; } // Find cm context $context = \context_module::instance($cm->id); // Add JavaScript settings for this content. $cid = 'cid-' . $content['id']; $settings['contents'][$cid] = array('library' => \H5PCore::libraryToString($content['library']), 'jsonContent' => $safeparameters, 'fullScreen' => $content['library']['fullscreen'], 'exportUrl' => $export, 'title' => $content['title'], 'disable' => $content['disable'], 'url' => "{$CFG->httpswwwroot}/mod/hvp/view.php?id={$id}", 'contentUrl' => "{$CFG->httpswwwroot}/pluginfile.php/{$context->id}/mod_hvp/content/" . $content['id'], 'contentUserData' => array(0 => \mod_hvp\content_user_data::load_pre_loaded_user_data($content['id']))); // Get assets for this content. $preloadeddependencies = $core->loadContentDependencies($content['id'], 'preloaded'); $files = $core->getDependenciesFiles($preloadeddependencies); // Determine embed type. $embedtype = \H5PCore::determineEmbedType($content['embedType'], $content['library']['embedTypes']); if ($embedtype === 'div') { $context = \context_system::instance(); $hvppath = "/pluginfile.php/{$context->id}/mod_hvp"; // Schedule JavaScripts for loading through Moodle. foreach ($files['scripts'] as $script) { $url = $hvppath . $script->path . $script->version; $settings['loadedJs'][] = $url; $PAGE->requires->js(new moodle_url($CFG->httpswwwroot . $url), true); } // Schedule stylesheets for loading through Moodle. foreach ($files['styles'] as $style) { $url = $hvppath . $style->path . $style->version; $settings['loadedCss'][] = $url; $PAGE->requires->css(new moodle_url($CFG->httpswwwroot . $url)); }