Beispiel #1
0
function xmldb_hvp_install()
{
    // Try to install all the default content types
    require_once __DIR__ . '/../autoloader.php';
    // Override permission check for the install process, since caps hasn't
    // been set yet.
    $interface = \mod_hvp\framework::instance('interface');
    $interface->mayUpdateLibraries(true);
    // Fetch info about library updates
    $core = \mod_hvp\framework::instance('core');
    $core->fetchLibrariesMetadata();
    // Download default libraries and try to install
    $error = \mod_hvp\framework::downloadH5pLibraries();
    if ($error !== null) {
        \mod_hvp\framework::messages('error', $error);
    }
    // Print any messages
    echo '<h3>' . get_string('welcomeheader', 'hvp') . '</h3>' . '<p>' . get_string('welcomegettingstarted', 'hvp', array('moodle_tutorial' => 'href="https://h5p.org/moodle" target="_blank"', 'example_content' => 'href="https://h5p.org/content-types-and-applications" target="_blank"')) . '</p>' . '<p>' . get_string('welcomecommunity', 'hvp', array('forums' => 'href="https://h5p.org/forum" target="_blank"', 'gitter' => 'href="https://gitter.im/h5p/CommunityChat" target="_blank"')) . '</p>' . '<p>' . get_string('welcomecontactus', 'hvp', 'href="https://h5p.org/contact" target="_blank"') . '</p>';
    \mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info'));
    \mod_hvp\framework::printMessages('error', \mod_hvp\framework::messages('error'));
}
Beispiel #2
0
 /**
  * Make it easy to download and install H5P libraries.
  *
  * @param boolean $onlyupdate Prevent install of new libraries
  * @return string|null Error or null if everything's OK.
  */
 public static function downloadH5pLibraries($onlyupdate = false)
 {
     global $CFG;
     $update_available = \get_config('mod_hvp', 'update_available');
     $current_update = \get_config('mod_hvp', 'current_update');
     if ($update_available === $current_update) {
         // Prevent re-submission of forms/action
         return null;
     }
     // URL for file to download
     $download_url = \get_config('mod_hvp', 'update_available_path');
     if (!$download_url) {
         return get_string('missingh5purl', 'hvp');
     }
     // Generate local tmp file path
     $local_folder = $CFG->tempdir . uniqid('/hvp-');
     $local_file = $local_folder . '.h5p';
     if (!\download_file_content($download_url, null, null, false, 300, 20, false, $local_file)) {
         return get_string('unabletodownloadh5p', 'hvp');
     }
     // Add folder and file paths to H5P Core
     $interface = \mod_hvp\framework::instance('interface');
     $interface->getUploadedH5pFolderPath($local_folder);
     $interface->getUploadedH5pPath($local_file);
     // Validate package
     $h5pValidator = \mod_hvp\framework::instance('validator');
     if (!$h5pValidator->isValidPackage(true, $onlyupdate)) {
         @unlink($local_file);
         $messages = \mod_hvp\framework::messages('error');
         return implode('<br/>', $messages);
     }
     // Install H5P file into Moodle
     $storage = \mod_hvp\framework::instance('storage');
     $storage->savePackage(null, null, true);
     \set_config('current_update', $update_available, 'mod_hvp');
     return null;
 }
Beispiel #3
0
        $PAGE->requires->css(new moodle_url($CFG->httpswwwroot . $url));
    }
} else {
    // JavaScripts and stylesheets will be loaded through h5p.js.
    $settings['contents'][$cid]['scripts'] = $core->getAssetsUrls($files['scripts']);
    $settings['contents'][$cid]['styles'] = $core->getAssetsUrls($files['styles']);
}
// Print JavaScript settings to page.
$PAGE->requires->data_for_js('H5PIntegration', $settings, true);
// Print page HTML.
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($content['title']));
echo '<div class="clearer"></div>';
// Print any messages.
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info'));
\mod_hvp\framework::printMessages('error', \mod_hvp\framework::messages('error'));
// Print intro.
if (trim(strip_tags($content['intro']))) {
    echo $OUTPUT->box_start('mod_introbox', 'hvpintro');
    echo format_module_intro('hvp', (object) array('intro' => $content['intro'], 'introformat' => $content['introformat']), $cm->id);
    echo $OUTPUT->box_end();
}
// Print H5P Content
if ($embedtype === 'div') {
    echo '<div class="h5p-content" data-content-id="' . $content['id'] . '"></div>';
} else {
    echo '<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>';
}
// Find cm context
$context = \context_module::instance($cm->id);
// Trigger module viewed event.
 public function validation($data, $files)
 {
     global $CFG;
     $errors = parent::validation($data, $files);
     if ($data['h5paction'] === 'upload') {
         // Validate uploaded H5P file
         if (empty($data['h5pfile'])) {
             // Field missing
             $errors['h5pfile'] = get_string('required');
         } else {
             $files = $this->get_draft_files('h5pfile');
             if (count($files) < 1) {
                 // No file uploaded
                 $errors['h5pfile'] = get_string('required');
             } else {
                 // Prepare to validate package
                 $file = reset($files);
                 $interface = \mod_hvp\framework::instance('interface');
                 $path = $CFG->tempdir . uniqid('/hvp-');
                 $interface->getUploadedH5pFolderPath($path);
                 $path .= '.h5p';
                 $interface->getUploadedH5pPath($path);
                 $file->copy_content_to($path);
                 $h5pvalidator = \mod_hvp\framework::instance('validator');
                 if (!$h5pvalidator->isValidPackage()) {
                     // Errors while validating the package
                     $infomessages = implode('<br/>', \mod_hvp\framework::messages('info'));
                     $errormessages = implode('<br/>', \mod_hvp\framework::messages('error'));
                     $errors['h5pfile'] = ($errormessages ? $errormessages . '<br/>' : '') . $infomessages;
                 }
             }
         }
     } else {
         // Validate library and params used in editor
         $core = \mod_hvp\framework::instance();
         // Get library array from string
         $library = H5PCore::libraryFromString($data['h5plibrary']);
         if (!$library) {
             $errors['h5peditor'] = get_string('invalidlibrary', 'hvp');
         } else {
             // Check that library exists
             $library['libraryId'] = $core->h5pF->getLibraryId($library['machineName'], $library['majorVersion'], $library['minorVersion']);
             if (!$library['libraryId']) {
                 $errors['h5peditor'] = get_string('nosuchlibrary', 'hvp');
             } else {
                 $data['h5plibrary'] = $library;
                 // Verify that parameters are valid
                 if (empty($data['h5pparams'])) {
                     $errors['h5peditor'] = get_string('noparameters', 'hvp');
                 } else {
                     $params = json_decode($data['h5pparams']);
                     if ($params === NULL) {
                         $errors['h5peditor'] = get_string('invalidparameters', 'hvp');
                     } else {
                         $data['h5pparams'] = $params;
                     }
                 }
             }
         }
     }
     return $errors;
 }
 /**
  * Validate incoming data
  *
  * @param array $data array of ("fieldname"=>value) of submitted data
  * @param array $files array of uploaded files "element_name"=>tmp_file_path
  * @return array of "element_name"=>"error_description" if there are errors,
  *         or an empty array if everything is OK (true allowed for backwards compatibility too).
  */
 function validation($data, $files)
 {
     global $CFG;
     $errors = array();
     // Check for file
     if (empty($data['h5pfile'])) {
         $errors['h5pfile'] = get_string('required');
         return $errors;
     }
     $files = $this->get_draft_files('h5pfile');
     if (count($files) < 1) {
         $errors['h5pfile'] = get_string('required');
         return $errors;
     }
     // Add file so that core framework can find it
     $file = reset($files);
     $interface = \mod_hvp\framework::instance('interface');
     $path = $CFG->tempdir . uniqid('/hvp-');
     $interface->getUploadedH5pFolderPath($path);
     $path .= '.h5p';
     $interface->getUploadedH5pPath($path);
     $file->copy_content_to($path);
     // Validate package
     $h5pValidator = \mod_hvp\framework::instance('validator');
     if (!$h5pValidator->isValidPackage(true, isset($data['onlyupdate']))) {
         $infomessages = implode('<br/>', \mod_hvp\framework::messages('info'));
         $errormessages = implode('<br/>', \mod_hvp\framework::messages('error'));
         $errors['h5pfile'] = ($errormessages ? $errormessages . '<br/>' : '') . $infomessages;
     }
     return $errors;
 }