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

📄 deploy.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    /*** 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'];        /// Look for submanifests            $submanifests = ims_extract_submanifests($data['manifest']['#']);        /// Add them as child            if (!empty($submanifests)) {                $manifest->childs = $submanifests;            }        }    /// Return tree of manifests found        return $manifest;    }    /* This function will search recursively for submanifests returning an array     * containing them (xmlized) following a tree structure.     */    function ims_extract_submanifests($data) {        $submanifests = array();  //To store found submanifests    /// If there are some manifests        if (!empty($data['manifest'])) {        /// Get them            foreach ($data['manifest'] as $submanifest) {            /// Create a new submanifest object                $submanifest_object = new stdClass;                $submanifest_object->data = $submanifest;            /// Look for more submanifests recursively                $moresubmanifests = ims_extract_submanifests($submanifest['#']);            /// Add them to results array                if (!empty($moresubmanifests)) {                    $submanifest_object->childs = $moresubmanifests;                }            /// Add submanifest object to results array                $submanifests[] = $submanifest_object;            }        }    /// Return array of manifests found        return $submanifests;    }    /*** This function will return an ordered and nested array of items     *   that is a perfect representation of the prefered organization     */    function ims_process_organizations($data) {        global $CFG;    /// Get the default organization        $default_organization = $data['@']['default'];        debugging('default_organization: '.$default_organization);    /// Iterate (reverse) over organizations until we find the default one        if (empty($data['#']['organization'])) {  /// Verify <organization> exists            return false;        }        $count_organizations = count($data['#']['organization']);        debugging('count_organizations: '.$count_organizations);        $current_organization = $count_organizations - 1;        while ($current_organization >= 0) {        /// Load organization and check it            $organization = $data['#']['organization'][$current_organization];            if ($organization['@']['identifier'] == $default_organization) {                    $current_organization = -1;   //Match, so exit.            }            $current_organization--;        }    /// At this point we MUST have the final organization        debugging('final organization: '.$organization['#']['title'][0]['#']);        if (empty($organization)) {            return false;    //Error, no organization found        }    /// Extract items map from organization        $items = $organization['#']['item'];        if (empty($organization['#']['item'])) {  /// Verify <item> exists            return false;        }        if (!$itemmap = ims_process_items($items)) {            return false;    //Error, no items found        }        return $itemmap;    }    /*** This function gets the xmlized representation of the items     *   and returns an array of items, ordered, with level and info     */    function ims_process_items($items, $level = 1, $id = 1, $parent = 0) {        global $CFG;        $itemmap = array();    /// Iterate over items from start to end        $count_items = count($items);        debugging('level '.$level.'-count_items: '.$count_items);        $current_item = 0;        while ($current_item < $count_items) {        /// Load item             $item = $items[$current_item];            $obj_item = new stdClass;            $obj_item->title         = $item['#']['title'][0]['#'];            $obj_item->identifier    = $item['@']['identifier'];            $obj_item->identifierref = $item['@']['identifierref'];            $obj_item->id            = $id;            $obj_item->level         = $level;            $obj_item->parent        = $parent;        /// Only if the item has everything            if (!empty($obj_item->title) &&                 !empty($obj_item->identifier)) {            /// Add to itemmap                $itemmap[$id] = $obj_item;                debugging('level '.$level.'-id '.$id.'-parent '.$parent.'-'.$obj_item->title);            /// Counters go up                $id++;            /// Check for subitems recursively                $subitems = $item['#']['item'];                if (count($subitems)) {                /// Recursive call                    $subitemmap = ims_process_items($subitems, $level+1, $id, $obj_item->id);                /// Add at the end and counters if necessary                    if ($count_subitems = count($subitemmap)) {                        foreach ($subitemmap as $subitem) {                        /// Add the subitem to the main items array                            $itemmap[$subitem->id] = $subitem;                        /// Counters go up                            $id++;                        }                    }                }            }            $current_item++;        }        return $itemmap;    }    /*** This function will load an array of resources to be used later.      *   Keys are identifiers     */    function ims_load_resources($data, $manifest_base, $resources_base) {        global $CFG;        $resources = array();        if (empty($data)) {  /// Verify <resource> exists            return false;        }        $count_resources = count($data);        debugging('count_resources: '.$count_resources);        $current_resource = 0;        while ($current_resource < $count_resources) {        /// Load resource             $resource = $data[$current_resource];        /// Create a new object resource            $obj_resource = new stdClass;            $obj_resource->identifier = $resource['@']['identifier'];            $obj_resource->resource_base = $resource['@']['xml:base'];            $obj_resource->href = $resource['@']['href'];            if (empty($obj_resource->href)) {                $obj_resource->href = $resource['#']['file']['0']['@']['href'];            }                    /// Some packages are poorly done and use \ in roots. This makes them         /// not display since the URLs are not valid.            if (!empty($obj_resource->href)) {                $obj_resource->href = strtr($obj_resource->href, "\\", '/');                }                    /// Only if the resource has everything            if (!empty($obj_resource->identifier) &&                !empty($obj_resource->href)) {            /// Add to resources (identifier as key)            /// Depending of $manifest_base, $resources_base and the particular            /// $resource_base variable, concatenate them to build the correct href                $href_base = '';                if (!empty($manifest_base)) {                    $href_base = $manifest_base;                }                if (!empty($resources_base)) {                    $href_base .= $resources_base;                }                if (!empty($obj_resource->resource_base)) {                    $href_base .= $obj_resource->resource_base;                }                $resources[$obj_resource->identifier] = $href_base.$obj_resource->href;            }        /// Counters go up            $current_resource++;        }        return $resources;    }?>

⌨️ 快捷键说明

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