/**
 * Add required assets for displaying the editor.
 *
 * @param int $id Content being edited. null for creating new content
 */
function hvp_add_editor_assets($id = null)
{
    global $PAGE, $CFG, $COURSE;
    $settings = \hvp_get_core_assets();
    // Use jQuery and styles from core.
    $assets = array('css' => $settings['core']['styles'], 'js' => $settings['core']['scripts']);
    // Use relative URL to support both http and https.
    $url = $CFG->httpswwwroot . '/mod/hvp/';
    $url = '/' . preg_replace('/^[^:]+:\\/\\/[^\\/]+\\//', '', $url);
    // Make sure files are reloaded for each plugin update.
    $cachebuster = \hvp_get_cache_buster();
    // Add editor styles
    foreach (H5peditor::$styles as $style) {
        $assets['css'][] = $url . 'editor/' . $style . $cachebuster;
    }
    // Add editor JavaScript
    foreach (H5peditor::$scripts as $script) {
        // We do not want the creator of the iframe inside the iframe
        if ($script !== 'scripts/h5peditor-editor.js') {
            $assets['js'][] = $url . 'editor/' . $script . $cachebuster;
        }
    }
    // Add JavaScript with library framework integration (editor part)
    $PAGE->requires->js(new moodle_url('/mod/hvp/editor/scripts/h5peditor-editor.js' . $cachebuster), true);
    $PAGE->requires->js(new moodle_url('/mod/hvp/editor/scripts/h5peditor-init.js' . $cachebuster), true);
    $PAGE->requires->js(new moodle_url('/mod/hvp/editor.js' . $cachebuster), true);
    // Add translations
    $language = \mod_hvp\framework::get_language();
    $languagescript = "editor/language/{$language}.js";
    if (!file_exists("{$CFG->dirroot}/mod/hvp/{$languagescript}")) {
        $languagescript = 'editor/language/en.js';
    }
    $PAGE->requires->js(new moodle_url('/mod/hvp/' . $languagescript . $cachebuster), true);
    // Add JavaScript settings
    $context = \context_course::instance($COURSE->id);
    $filespathbase = "{$CFG->httpswwwroot}/pluginfile.php/{$context->id}/mod_hvp/";
    $contentvalidator = $core = \mod_hvp\framework::instance('contentvalidator');
    $editorajaxtoken = \H5PCore::createToken('editorajax');
    $settings['editor'] = array('filesPath' => $filespathbase . ($id ? "content/{$id}" : 'editor'), 'fileIcon' => array('path' => $url . 'editor/images/binary-file.png', 'width' => 50, 'height' => 50), 'ajaxPath' => "{$url}ajax.php?contextId={$context->id}&token={$editorajaxtoken}&action=", 'libraryUrl' => $url . 'editor/', 'copyrightSemantics' => $contentvalidator->getCopyrightSemantics(), 'assets' => $assets);
    if ($id !== null) {
        $settings['editor']['nodeVersionId'] = $id;
        // Find cm context
        $cm = \get_coursemodule_from_instance('hvp', $id);
        $context = \context_module::instance($cm->id);
        // Override content URL
        $settings['contents']['cid-' . $id]['contentUrl'] = "{$CFG->httpswwwroot}/pluginfile.php/{$context->id}/mod_hvp/content/{$id}";
    }
    $PAGE->requires->data_for_js('H5PIntegration', $settings, true);
}
Beispiel #2
0
// Load H5P Core.
$core = \mod_hvp\framework::instance();
// Load H5P Content.
$content = $core->loadContent($cm->instance);
if ($content === null) {
    print_error('invalidhvp');
}
// Log view
new \mod_hvp\event('content', NULL, $content['id'], $content['title'], $content['library']['name'], $content['library']['majorVersion'] . '.' . $content['library']['minorVersion']);
$PAGE->set_title(format_string($content['title']));
$PAGE->set_heading($course->fullname);
// Mark viewed by user (if required).
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Attach scripts, styles, etc. from core.
$settings = hvp_get_core_assets();
// Add global disable settings.
if (!isset($content['disable'])) {
    $content['disable'] = $core->getGlobalDisable();
} else {
    $content['disable'] |= $core->getGlobalDisable();
}
// Embed is not supported in Moodle.
$content['disable'] |= \H5PCore::DISABLE_EMBED;
// Filter content parameters.
$safeparameters = $core->filterParameters($content);
$export = '';
if (!isset($CFG->mod_hvp_export) || $CFG->mod_hvp_export === true) {
    // Find course context.
    $context = \context_course::instance($course->id);
    if (has_capability('mod/hvp:getexport', $context)) {