Ejemplo n.º 1
0
  *
  * Parameters:
  *  string machineName
  *  int majorVersion
  *  int minorVersion
  */
 case 'libraries':
     /// Get parameters
     $name = optional_param('machineName', '', PARAM_TEXT);
     $major = optional_param('majorVersion', 0, PARAM_INT);
     $minor = optional_param('minorVersion', 0, PARAM_INT);
     $editor = \mod_hvp\framework::instance('editor');
     header('Cache-Control: no-cache');
     header('Content-type: application/json');
     if (!empty($name)) {
         print $editor->getLibraryData($name, $major, $minor, \mod_hvp\framework::get_language());
         new \mod_hvp\event('library', NULL, NULL, NULL, $name, $major . '.' . $minor);
     } else {
         print $editor->getLibraries();
     }
     break;
     /*
      * Handle file upload through the editor.
      *
      * Parameters:
      *  int contentId
      *  int contextId
      */
 /*
  * Handle file upload through the editor.
  *
Ejemplo n.º 2
0
/**
 * 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);
}