Example #1
0
}
///Now we assign to each item, its resource (by identifier)
foreach ($items as $key => $item) {
    if (!empty($resources[$item->identifierref])) {
        $items[$key]->href = $resources[$item->identifierref];
    } else {
        $items[$key]->href = '';
    }
}
/// Create the INDEX (moodle_inx.ser - where the order of the pages are stored serialized) file
if (!ims_save_serialized_file($resourcedir . '/moodle_inx.ser', $items)) {
    print_error('errorcreatingfile', 'error', '', 'moodle_inx.ser');
}
/// Create the HASH file (moodle_hash.ser - where the hash of the ims is stored serialized) file
$hash = $resource_obj->calculatefilehash($resourcefile);
if (!ims_save_serialized_file($resourcedir . '/moodle_hash.ser', $hash)) {
    print_error('errorcreatingfile', 'error', '', 'moodle_hash.ser');
}
/// End button (go to view mode)
echo '<center>';
print_simple_box(get_string('imspackageloaded', 'resource'), 'center');
$link = $CFG->wwwroot . '/mod/resource/view.php';
$options['r'] = $resource->id;
$label = get_string('viewims', 'resource');
$method = 'post';
print_single_button($link, $options, $label, $method);
echo '</center>';
///
/// End of main process, where everything is deployed
///
/// Print the footer of the page
function ims_deploy_file($file, $all = '')
{
    global $CFG;
    /// Load request parameters
    $resourcedir = "{$CFG->repository}/{$file}";
    /// Get some needed strings
    $strdeploy = get_string('deploy', 'resource');
    ///
    /// Main process, where everything is deployed
    ///
    /// Load imsmanifest to memory (instead of using a full parser,
    /// we are going to use xmlize intensively (because files aren't too big)
    if (!($imsmanifest = ims_file2var($resourcedir . '/imsmanifest.xml'))) {
        error(get_string('errorreadingfile', 'error', 'imsmanifest.xml'));
    }
    /// Check if the first line is a proper one, because I've seen some
    /// packages with some control characters at the beginning.
    $inixml = strpos($imsmanifest, '<?xml ');
    if ($inixml !== false) {
        if ($inixml !== 0) {
            //Strip strange chars before "<?xml "
            $imsmanifest = substr($imsmanifest, $inixml);
        }
    } else {
        if (ord($imsmanifest[0]) == 0xff && ord($imsmanifest[1]) == 0xfe || ord($imsmanifest[0]) == 0xfe && ord($imsmanifest[1]) == 0xff) {
            echo " UTF-16 - CAN'T DEPLOY.";
            return;
        } else {
            error(get_string('invalidxmlfile', 'error', 'imsmanifest.xml'));
        }
    }
    /// xmlize the variable
    $data = xmlize($imsmanifest, 0);
    ///    traverse_xmlize($data);
    $title = ims_get_cp_title($data);
    ///    foreach ($GLOBALS['traverse_array'] as $line) echo $line;
    /// Extract every manifest present in the imsmanifest file.
    /// Returns a tree structure.
    if (!($manifests = ims_extract_manifests($data))) {
        error(get_string('nonmeaningfulcontent', 'error'));
    }
    /// Process every manifest found in inverse order so every one
    /// will be able to use its own submanifests. Not perfect because
    /// teorically this will allow some manifests to use other non-childs
    /// but this is supposed to be
    /// Detect if all the manifest share a common xml:base tag
    $manifest_base = $data['manifest']['@']['xml:base'];
    /// Parse XML-metadata
    /// Skip this for now (until a proper METADATA container was created in Moodle).
    /// Parse XML-content package data
    /// First we select an organization an load all the items
    if (!($items = ims_process_organizations($data['manifest']['#']['organizations']['0']))) {
        if ($all == 'force') {
            return;
        } else {
            error(get_string('nonmeaningfulcontent', 'error'));
        }
    }
    /// Detect if all the resources share a common xml:base tag
    $resources_base = $data['manifest']['#']['resources']['0']['@']['xml:base'];
    /// Now, we load all the resources available (keys are identifiers)
    if (!($resources = ims_load_resources($data['manifest']['#']['resources']['0']['#']['resource'], $manifest_base, $resources_base))) {
        error(get_string('nonmeaningfulcontent', 'error'));
    }
    ///Now we assign to each item, its resource (by identifier)
    foreach ($items as $key => $item) {
        if (!empty($resources[$item->identifierref])) {
            $items[$key]->href = $resources[$item->identifierref];
        } else {
            $items[$key]->href = '';
        }
    }
    /// Create the INDEX (moodle_inx.ser - where the order of the pages are stored serialized) file
    $items['title'] = $title;
    if (!ims_save_serialized_file($resourcedir . '/moodle_inx.ser', $items)) {
        error(get_string('errorcreatingfile', 'error', 'moodle_inx.ser'));
    }
    /// No zip so no HASH
    /// End button (go to view mode)
    echo '<center>';
    print_simple_box(get_string('imspackageloaded', 'resource'), 'center');
    $link = $CFG->wwwroot . '/mod/resource/type/ims/preview.php';
    $options['directory'] = $file;
    $label = get_string('viewims', 'resource');
    $method = 'get';
    print_single_button($link, $options, $label, $method);
    echo '</center>';
    ///
    /// End of main process, where everything is deployed
    ///
}