Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/cc/restore_cc.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00022 defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
00023 
00024 require_once($CFG->dirroot . '/backup/cc/includes/constants.php');
00025 require_once($CFG->dirroot . '/backup/cc/cc2moodle.php');
00026 
00027 function cc_convert ($dir) {
00028 
00029     $manifest_file = $dir . DIRECTORY_SEPARATOR . 'imsmanifest.xml';
00030     $moodle_file = $dir . DIRECTORY_SEPARATOR . 'moodle.xml';
00031     $schema_file = 'cc' . DIRECTORY_SEPARATOR . '' . DIRECTORY_SEPARATOR . 'schemas' . DIRECTORY_SEPARATOR . 'cclibxml2validator.xsd';
00032 
00033     if (is_readable($manifest_file) && !is_readable($moodle_file)) {
00034 
00035         $is_cc = detect_cc_format($manifest_file);
00036 
00037         if ($is_cc) {
00038 
00039             $detected_requirements = detect_requirements();
00040 
00041             if (!$detected_requirements["php5"]) {
00042                 notify(get_string('cc_import_req_php5', 'imscc'));
00043                 return false;
00044             }
00045 
00046             if (!$detected_requirements["dom"]) {
00047                 notify(get_string('cc_import_req_dom', 'imscc'));
00048                 return false;
00049             }
00050 
00051             if (!$detected_requirements["libxml"]) {
00052                 notify(get_string('cc_import_req_libxml', 'imscc'));
00053                 return false;
00054             }
00055 
00056             if (!$detected_requirements["libxmlminversion"]) {
00057                 notify(get_string('cc_import_req_libxmlminversion', 'imscc'));
00058                 return false;
00059             }
00060             if (!$detected_requirements["xsl"]) {
00061                 notify(get_string('cc_import_req_xsl', 'imscc'));
00062                 return false;
00063             }
00064 
00065             echo get_string('cc2moodle_checking_schema', 'imscc') . '<br />';
00066 
00067             $cc_manifest = new DOMDocument();
00068 
00069             if ($cc_manifest->load($manifest_file)) {
00070                 if ($cc_manifest->schemaValidate($schema_file)) {
00071 
00072                     echo get_string('cc2moodle_valid_schema', 'imscc') . '<br />';
00073 
00074                     $cc2moodle = new cc2moodle($manifest_file);
00075 
00076                     if (!$cc2moodle->is_auth()) {
00077                         return $cc2moodle->generate_moodle_xml();
00078                     } else {
00079                         notify(get_string('cc2moodle_req_auth', 'imscc'));
00080                         return false;
00081                     }
00082 
00083                 } else {
00084                     notify(get_string('cc2moodle_invalid_schema', 'imscc'));
00085                     return false;
00086                 }
00087 
00088             } else {
00089                 notify(get_string('cc2moodle_manifest_dont_load', 'imscc'));
00090                 return false;
00091             }
00092         }
00093     }
00094 
00095     return true;
00096 }
00097 
00098 function detect_requirements () {
00099 
00100     if (floor(phpversion()) >= 5) {
00101         $detected["php5"] = true;
00102     } else {
00103         $detected["php5"] = false;
00104     }
00105 
00106     $detected["xsl"] = extension_loaded('xsl');
00107     $detected['dom'] = extension_loaded('dom');
00108     $detected['libxml'] = extension_loaded('libxml');
00109     $detected['libxmlminversion'] = extension_loaded('libxml') && version_compare(LIBXML_DOTTED_VERSION, '2.6.30', '>=');
00110 
00111     return $detected;
00112 
00113 }
00114 
00115 function detect_cc_format ($xml_file) {
00116 
00117     $inpos = 0;
00118     $xml_snippet = file_get_contents($xml_file, 0, NULL, 0, 500);
00119 
00120     if (!empty($xml_snippet)) {
00121 
00122         $xml_snippet = strtolower($xml_snippet);
00123         $xml_snippet = preg_replace('/\s*/m', '', $xml_snippet);
00124         $xml_snippet = str_replace("'", '', $xml_snippet);
00125         $xml_snippet = str_replace('"', '', $xml_snippet);
00126 
00127         $search_string = "xmlns=" . NS_COMMON_CARTRIDGE;
00128 
00129         $inpos = strpos($xml_snippet, $search_string);
00130 
00131         if ($inpos) {
00132             return true;
00133         } else {
00134             return false;
00135         }
00136 
00137     } else {
00138         return false;
00139     }
00140 
00141 }
 All Data Structures Namespaces Files Functions Variables Enumerations