📄 repository_deploy.php
字号:
<?php // $Id: repository_deploy.php,v 1.7.2.3 2009/03/23 09:47:00 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 from repository. * Just adds hash file. * Arguments: * - file directory containing CP to deploy * - all if not set, will deploy 1 package * if = true, will recursively deploy all packages * found in directory file. * if = force, same as above but will redeploy too. *//// 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'); require_once('repository_config.php'); /// Security - Admin Only require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); $file = required_param ('file', PARAM_PATH); $all = optional_param ('all', '', PARAM_ALPHA); if ($all == '') { print_header(); ims_deploy_file($file); print_footer(); } else { print_header(); ims_deploy_folder($file, $all); print_footer(); }/// Deploys all packages found in the folder recursively. function ims_deploy_folder($file, $all='') { global $CFG; $dirpath = "$CFG->repository/$file"; $dir = opendir($dirpath); while (false !== ($filename = readdir($dir))) { if ($filename != '.' && $filename != '..') { $path = $dirpath.'/'.$filename; if (is_dir($path) && file_exists("$path/imsmanifest.xml")) { if ($all == 'force' || !file_exists("$path/moodle_inx.ser")) { echo "DEPLOYING $path<br/>"; ims_deploy_file($file.'/'.$filename, $all); } } else if (is_dir($path)) { echo "DEPLOYING $path<br/>"; ims_deploy_folder($file.'/'.$filename, $all); } else { echo "WONT DEPLOY $path<br/>"; } } } closedir($dir); } 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 /// }////// Common and useful functions used by the body of the script/// /*** This function will return a tree of manifests (xmlized) as they are * found and extracted from one manifest file. The first manifest in the * will be the main one, while the rest will be submanifests. In the * future (when IMS CP suppors it, external submanifest will be detected * and retrieved here too). See IMS specs for more info. */ function ims_extract_manifests($data) { $manifest = new stdClass; //To store found manifests in a tree structure /// If there are some manifests if (!empty($data['manifest'])) { /// Add manifest to results array $manifest->data = $data['manifest'];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -