⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deploy.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php // $Id: deploy.php,v 1.24.2.3 2009/03/23 09:46:59 mudrd8mz Exp $/////////////////////////////////////////////////////////////////////////////                                                                       //// NOTICE OF COPYRIGHT                                                   ////                                                                       //// Moodle - Modular Object-Oriented Dynamic Learning Environment         ////          http://moodle.com                                            ////                                                                       //// Copyright (C) 1999 onwards Martin Dougiamas        http://dougiamas.com  ////           (C) 2001-3001 Eloy Lafuente (stronk7) http://contiento.com  ////                                                                       //// This program is free software; you can redistribute it and/or modify  //// it under the terms of the GNU General Public License as published by  //// the Free Software Foundation; either version 2 of the License, or     //// (at your option) any later version.                                   ////                                                                       //// This program is distributed in the hope that it will be useful,       //// but WITHOUT ANY WARRANTY; without even the implied warranty of        //// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //// GNU General Public License for more details:                          ////                                                                       ////          http://www.gnu.org/copyleft/gpl.html                         ////                                                                       /////////////////////////////////////////////////////////////////////////////    /***     * This page will deploy an IMS Content Package zip file,      * building all the structures and auxiliary files to     * work inside a Moodle resource.     *//// Required stuff    require_once('../../../../config.php');    require_once('../../lib.php');    require_once('resource.class.php');    require_once('../../../../backup/lib.php');    require_once('../../../../lib/filelib.php');    require_once('../../../../lib/xmlize.php');/// Load request parameters    $courseid   = required_param ('courseid', PARAM_INT);    $cmid       = required_param ('cmid', PARAM_INT);    $file       = required_param ('file', PARAM_PATH);    $inpopup    = optional_param ('inpopup', 0, PARAM_BOOL);/// Fetch some records from DB    $course   = get_record ('course', 'id', $courseid);    $cm       = get_coursemodule_from_id('resource', $cmid);    $resource = get_record ('resource', 'id', $cm->instance);/// Get some needed strings    $strdeploy = get_string('deploy','resource');/// Instantiate a resource_ims object and modify its navigation    $resource_obj = new resource_ims ($cmid);    /// Print the header of the page    $pagetitle = strip_tags($course->shortname.': '.                     format_string($resource->name)).': '.                     $strdeploy;    if ($inpopup) {        print_header($pagetitle, $course->fullname);    } else {        $resource_obj->navlinks[] = array('name' => $strdeploy, 'link' => '', 'type' => 'action');        $navigation = build_navigation($resource_obj->navlinks, $cm);        print_header($pagetitle, $course->fullname, $navigation,                     '', '', true,                      update_module_button($cm->id, $course->id, $resource_obj->strresource));    }/// Security Constraints (sesskey and isteacheredit)    if (!confirm_sesskey()) {        print_error('confirmsesskeybad', 'error');    } else if (!has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {        print_error('onlyeditingteachers', 'error');    }////// Main process, where everything is deployed////// Set some variables/// Create directories    if (!$resourcedir = make_upload_directory($courseid.'/'.$CFG->moddata.'/resource/'.$resource->id)) {        error (get_string('errorcreatingdirectory', 'error', $CFG->moddata.'/resource/'.$resource->id));    }/// Ensure it's empty    if (!delete_dir_contents($resourcedir)) {        error (get_string('errorcleaningdirectory', 'error', $resourcedir));    }    /// Copy files    $origin = $CFG->dataroot.'/'.$courseid.'/'.$file;    if (!is_file($origin)) {        error (get_string('filenotfound' , 'error', $file));    }    $mimetype = mimeinfo("type", $file);    if ($mimetype != "application/zip") {        error (get_string('invalidfiletype', 'error', $file));    }    $resourcefile = $resourcedir.'/'.basename($origin);    if (!backup_copy_file($origin, $resourcefile)) {        error (get_string('errorcopyingfiles', 'error'));    }/// Unzip files    if (!unzip_file($resourcefile, '', false)) {        error (get_string('errorunzippingfiles', 'error'));    }/// Check for imsmanifest    if (!file_exists($resourcedir.'/imsmanifest.xml')) {        error (get_string('filenotfound', 'error', 'imsmanifest.xml'));    }/// 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 {        error (get_string ('invalidxmlfile', 'error', 'imsmanifest.xml'));    }/// xmlize the variable    $data = xmlize($imsmanifest, 0);/// 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'])) {        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    if (!ims_save_serialized_file($resourcedir.'/moodle_inx.ser', $items)) {        error (get_string('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)) {        error (get_string('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    print_footer();////// Common and useful functions used by the body of the script///

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -