/** * Extracts scrom package, sets up all variables. * Called whenever scorm changes * @param object $scorm instance - fields are updated and changes saved into database * @param bool $full force full update if true * @return void */ function scorm_parse($scorm, $full) { global $CFG, $DB; $cfg_scorm = get_config('scorm'); if (!isset($scorm->cmid)) { $cm = get_coursemodule_from_instance('scorm', $scorm->id); $scorm->cmid = $cm->id; } $context = context_module::instance($scorm->cmid); $newhash = $scorm->sha1hash; if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) { $fs = get_file_storage(); $packagefile = false; $packagefileimsmanifest = false; if ($scorm->scormtype === SCORM_TYPE_LOCAL) { if ($packagefile = $fs->get_file($context->id, 'mod_scorm', 'package', 0, '/', $scorm->reference)) { if ($packagefile->is_external_file()) { // Get zip file so we can check it is correct. $packagefile->import_external_file_contents(); } $newhash = $packagefile->get_contenthash(); if (strtolower($packagefile->get_filename()) == 'imsmanifest.xml') { $packagefileimsmanifest = true; } } else { $newhash = null; } } else { if (!$cfg_scorm->allowtypelocalsync) { // sorry - localsync disabled return; } if ($scorm->reference !== '' and (!$full or $scorm->sha1hash !== sha1($scorm->reference))) { $fs->delete_area_files($context->id, 'mod_scorm', 'package'); $file_record = array('contextid' => $context->id, 'component' => 'mod_scorm', 'filearea' => 'package', 'itemid' => 0, 'filepath' => '/'); if ($packagefile = $fs->create_file_from_url($file_record, $scorm->reference, array('calctimeout' => true))) { $newhash = sha1($scorm->reference); } else { $newhash = null; } } } if ($packagefile) { if (!$full and $packagefile and $scorm->sha1hash === $newhash) { if (strpos($scorm->version, 'SCORM') !== false) { if ($packagefileimsmanifest || $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) { // No need to update. return; } } else { if (strpos($scorm->version, 'AICC') !== false) { // TODO: add more sanity checks - something really exists in scorm_content area return; } } } if (!$packagefileimsmanifest) { // Now extract files. $fs->delete_area_files($context->id, 'mod_scorm', 'content'); $packer = get_file_packer('application/zip'); $packagefile->extract_to_storage($packer, $context->id, 'mod_scorm', 'content', 0, '/'); } } else { if (!$full) { return; } } if ($packagefileimsmanifest) { require_once "{$CFG->dirroot}/mod/scorm/datamodels/scormlib.php"; // Direct link to imsmanifest.xml file. if (!scorm_parse_scorm($scorm, $packagefile)) { $scorm->version = 'ERROR'; } } else { if ($manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) { require_once "{$CFG->dirroot}/mod/scorm/datamodels/scormlib.php"; // SCORM if (!scorm_parse_scorm($scorm, $manifest)) { $scorm->version = 'ERROR'; } } else { require_once "{$CFG->dirroot}/mod/scorm/datamodels/aicclib.php"; // AICC if (!scorm_parse_aicc($scorm)) { $scorm->version = 'ERROR'; } $scorm->version = 'AICC'; } } } else { if ($scorm->scormtype === SCORM_TYPE_EXTERNAL and $cfg_scorm->allowtypeexternal) { require_once "{$CFG->dirroot}/mod/scorm/datamodels/scormlib.php"; // SCORM only, AICC can not be external if (!scorm_parse_scorm($scorm, $scorm->reference)) { $scorm->version = 'ERROR'; } $newhash = sha1($scorm->reference); } else { if ($scorm->scormtype === SCORM_TYPE_AICCURL and $cfg_scorm->allowtypeexternalaicc) { require_once "{$CFG->dirroot}/mod/scorm/datamodels/aicclib.php"; // AICC if (!scorm_parse_aicc($scorm)) { $scorm->version = 'ERROR'; } $scorm->version = 'AICC'; } else { // sorry, disabled type return; } } } $scorm->revision++; $scorm->sha1hash = $newhash; $DB->update_record('scorm', $scorm); }
/** * Extracts scrom package, sets up all variables. * Called whenever scorm changes * @param object $scorm instance - fields are updated and changes saved into database * @param bool $full force full update if true * @return void */ function scorm_parse($scorm, $full) { global $CFG, $DB; $cfg_scorm = get_config('scorm'); if (!isset($scorm->cmid)) { $cm = get_coursemodule_from_instance('scorm', $scorm->id); $scorm->cmid = $cm->id; } $context = get_context_instance(CONTEXT_MODULE, $scorm->cmid); $newhash = $scorm->sha1hash; if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) { $fs = get_file_storage(); $packagefile = false; if ($scorm->scormtype === SCORM_TYPE_LOCAL) { if ($packagefile = $fs->get_file($context->id, 'mod_scorm', 'package', 0, '/', $scorm->reference)) { $newhash = $packagefile->get_contenthash(); } else { $newhash = null; } } else { if (!$cfg_scorm->allowtypelocalsync) { // sorry - localsync disabled return; } if ($scorm->reference !== '' and (!$full or $scorm->sha1hash !== sha1($scorm->reference))) { $fs->delete_area_files($context->id, 'mod_scorm', 'package'); $file_record = array('contextid'=>$context->id, 'component'=>'mod_scorm', 'filearea'=>'package', 'itemid'=>0, 'filepath'=>'/'); if ($packagefile = $fs->create_file_from_url($file_record, $scorm->reference, array('calctimeout' => true))) { $newhash = sha1($scorm->reference); } else { $newhash = null; } } } if ($packagefile) { if (!$full and $packagefile and $scorm->sha1hash === $newhash) { if (strpos($scorm->version, 'SCORM') !== false) { if ($fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) { // no need to update return; } } else if (strpos($scorm->version, 'AICC') !== false) { // TODO: add more sanity checks - something really exists in scorm_content area return; } } // now extract files $fs->delete_area_files($context->id, 'mod_scorm', 'content'); $packer = get_file_packer('application/zip'); $packagefile->extract_to_storage($packer, $context->id, 'mod_scorm', 'content', 0, '/'); } else if (!$full) { return; } if ($manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) { require_once("$CFG->dirroot/mod/scorm/datamodels/scormlib.php"); // SCORM if (!scorm_parse_scorm($scorm, $manifest)) { $scorm->version = 'ERROR'; } } else { require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php"); // AICC if (!scorm_parse_aicc($scorm)) { $scorm->version = 'ERROR'; } $scorm->version = 'AICC'; } } else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL and $cfg_scorm->allowtypeexternal) { if (!$full and $scorm->sha1hash === sha1($scorm->reference)) { return; } require_once("$CFG->dirroot/mod/scorm/datamodels/scormlib.php"); // SCORM only, AICC can not be external if (!scorm_parse_scorm($scorm, $scorm->reference)) { $scorm->version = 'ERROR'; } $newhash = sha1($scorm->reference); } else if ($scorm->scormtype === SCORM_TYPE_IMSREPOSITORY and !empty($CFG->repositoryactivate) and $cfg_scorm->allowtypeimsrepository) { if (!$full and $scorm->sha1hash === sha1($scorm->reference)) { return; } require_once("$CFG->dirroot/mod/scorm/datamodels/scormlib.php"); if (!scorm_parse_scorm($scorm, $CFG->repository.substr($scorm->reference, 1).'/imsmanifest.xml')) { $scorm->version = 'ERROR'; } $newhash = sha1($scorm->reference); } else if ($scorm->scormtype === SCORM_TYPE_AICCURL and $cfg_scorm->allowtypeexternalaicc) { require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php"); // AICC if (!scorm_parse_aicc($scorm)) { $scorm->version = 'ERROR'; } $scorm->version = 'AICC'; } else { // sorry, disabled type return; } $scorm->revision++; $scorm->sha1hash = $newhash; $DB->update_record('scorm', $scorm); }
function scorm_parse($scorm) { global $CFG, $repositoryconfigfile; if ($scorm->reference[0] == '#') { $reference = $CFG->repository . substr($scorm->reference, 1); require_once $repositoryconfigfile; } else { if (!scorm_external_link($scorm->reference) && basename($scorm->reference) == 'imsmanifest.xml') { $referencedir = dirname($scorm->reference) == '.' ? '' : dirname($scorm->reference); $reference = $CFG->dataroot . '/' . $scorm->course . '/' . $referencedir; } else { $reference = $scorm->dir . '/' . $scorm->id; } } // Parse scorm manifest if ($scorm->pkgtype == 'AICC') { require_once 'datamodels/aicclib.php'; $scorm->launch = scorm_parse_aicc($reference, $scorm->id); } else { require_once 'datamodels/scormlib.php'; $scorm->launch = scorm_parse_scorm($reference, $scorm->id); } return $scorm->launch; }
function scorm_parse($scorm) { global $CFG; if ($scorm->reference[0] == '#') { if (isset($CFG->repositoryactivate) && $CFG->repositoryactivate) { $referencedir = $CFG->repository . substr($scorm->reference, 1); } } else { if (!scorm_external_link($scorm->reference) && basename($scorm->reference) == 'imsmanifest.xml') { $referencedir = $CFG->dataroot . '/' . $scorm->course . '/' . $scorm->datadir; } else { $referencedir = $CFG->dataroot . '/' . $scorm->course . '/moddata/scorm/' . $scorm->id; } } // Parse scorm manifest if ($scorm->pkgtype == 'AICC') { require_once 'datamodels/aicclib.php'; $scorm->launch = scorm_parse_aicc($referencedir, $scorm->id); } else { require_once 'datamodels/scormlib.php'; $scorm->launch = scorm_parse_scorm($referencedir, $scorm->id); } return $scorm->launch; }
/** * Extracts scrom package, sets up all variables. * Called whenever scorm changes * @param object $scorm instance - fields are updated and changes saved into database * @param bool $full force full update if true * @return void */ function scorm_parse($scorm, $full) { global $CFG, $DB; $cfg_scorm = get_config('scorm'); if (!isset($scorm->cmid)) { $cm = get_coursemodule_from_instance('scorm', $scorm->id); $scorm->cmid = $cm->id; } $context = context_module::instance($scorm->cmid); $newhash = $scorm->sha1hash; if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) { $fs = get_file_storage(); $packagefile = false; if ($scorm->scormtype === SCORM_TYPE_LOCAL) { if ($packagefile = $fs->get_file($context->id, 'mod_scorm', 'package', 0, '/', $scorm->reference)) { $newhash = $packagefile->get_contenthash(); } else { $newhash = null; } } else { if (!$cfg_scorm->allowtypelocalsync) { // sorry - localsync disabled return; } if ($scorm->reference !== '' and (!$full or $scorm->sha1hash !== sha1($scorm->reference))) { $fs->delete_area_files($context->id, 'mod_scorm', 'package'); $file_record = array('contextid' => $context->id, 'component' => 'mod_scorm', 'filearea' => 'package', 'itemid' => 0, 'filepath' => '/'); if ($packagefile = $fs->create_file_from_url($file_record, $scorm->reference, array('calctimeout' => true))) { $newhash = sha1($scorm->reference); } else { $newhash = null; } } } if ($packagefile) { if (!$full and $packagefile and $scorm->sha1hash === $newhash) { if (strpos($scorm->version, 'SCORM') !== false) { if ($fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) { // no need to update return; } /* * TCAPI Modification * Allow for TinCan package file, tincan.xml. */ } else { if (strpos($scorm->version, 'TCAPI') !== false) { if ($fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'tincan.xml')) { // no need to update return; } /* * End TCAPI Modification */ } else { if (strpos($scorm->version, 'AICC') !== false) { // TODO: add more sanity checks - something really exists in scorm_content area return; } } } } // now extract files $fs->delete_area_files($context->id, 'mod_scorm', 'content'); $packer = get_file_packer('application/zip'); $packagefile->extract_to_storage($packer, $context->id, 'mod_scorm', 'content', 0, '/'); } else { if (!$full) { return; } } if ($manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'imsmanifest.xml')) { require_once "{$CFG->dirroot}/mod/scorm/datamodels/scormlib.php"; // SCORM if (!scorm_parse_scorm($scorm, $manifest)) { $scorm->version = 'ERROR'; } /* * TCAPI Modification * Detect if tincan.xml exists and handle as TCAPI package. */ } else { if ($manifest = $fs->get_file($context->id, 'mod_scorm', 'content', 0, '/', 'tincan.xml')) { require_once "{$CFG->dirroot}/mod/scorm/datamodels/tincanlib.php"; // TCAPI if (!scorm_parse_tincan($scorm, $manifest)) { $scorm->version = 'ERROR'; } /* * End TCAPI Modification */ } else { require_once "{$CFG->dirroot}/mod/scorm/datamodels/aicclib.php"; // AICC if (!scorm_parse_aicc($scorm)) { $scorm->version = 'ERROR'; } $scorm->version = 'AICC'; } } } else { if ($scorm->scormtype === SCORM_TYPE_EXTERNAL and $cfg_scorm->allowtypeexternal) { /* * TCAPI Modification * Determine if is SCORM or TCAPI based on referenced package manifest filename. */ // SCORM or TCAPI only, AICC can not be external if (preg_match('/(http:\\/\\/|https:\\/\\/|www).*\\/imsmanifest.xml$/i', $scorm->reference)) { // SCORM require_once "{$CFG->dirroot}/mod/scorm/datamodels/scormlib.php"; if (!scorm_parse_scorm($scorm, $scorm->reference)) { $scorm->version = 'ERROR'; } } else { if (preg_match('/(http:\\/\\/|https:\\/\\/|www).*\\/tincan.xml$/i', $scorm->reference)) { require_once "{$CFG->dirroot}/mod/scorm/datamodels/tincanlib.php"; // TCAPI if (!scorm_parse_tincan($scorm, $scorm->reference)) { $scorm->version = 'ERROR'; } } else { $scorm->version = 'ERROR'; } } /* * Replaces: * require_once("$CFG->dirroot/mod/scorm/datamodels/scormlib.php"); // SCORM only, AICC can not be external if (!scorm_parse_scorm($scorm, $scorm->reference)) { $scorm->version = 'ERROR'; } */ /* * End TCAPI Modification */ $newhash = sha1($scorm->reference); } else { if ($scorm->scormtype === SCORM_TYPE_IMSREPOSITORY and !empty($CFG->repositoryactivate) and $cfg_scorm->allowtypeimsrepository) { if (!$full and $scorm->sha1hash === sha1($scorm->reference)) { return; } require_once "{$CFG->dirroot}/mod/scorm/datamodels/scormlib.php"; if (!scorm_parse_scorm($scorm, $CFG->repository . substr($scorm->reference, 1) . '/imsmanifest.xml')) { $scorm->version = 'ERROR'; } $newhash = sha1($scorm->reference); } else { if ($scorm->scormtype === SCORM_TYPE_AICCURL and $cfg_scorm->allowtypeexternalaicc) { require_once "{$CFG->dirroot}/mod/scorm/datamodels/aicclib.php"; // AICC if (!scorm_parse_aicc($scorm)) { $scorm->version = 'ERROR'; } $scorm->version = 'AICC'; } else { // sorry, disabled type return; } } } } $scorm->revision++; $scorm->sha1hash = $newhash; $DB->update_record('scorm', $scorm); }