[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/backup/cc/ -> restore_cc.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  /**
  17   * @package   moodlecore
  18   * @subpackage backup-imscc
  19   * @copyright 2009 Mauro Rondinelli (mauro.rondinelli [AT] uvcms.com)
  20   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21   */
  22  defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
  23  
  24  require_once($CFG->dirroot . '/backup/cc/includes/constants.php');
  25  require_once($CFG->dirroot . '/backup/cc/cc2moodle.php');
  26  
  27  function cc_convert ($dir) {
  28  
  29      $manifest_file = $dir . DIRECTORY_SEPARATOR . 'imsmanifest.xml';
  30      $moodle_file = $dir . DIRECTORY_SEPARATOR . 'moodle.xml';
  31      $schema_file = 'cc' . DIRECTORY_SEPARATOR . '' . DIRECTORY_SEPARATOR . 'schemas' . DIRECTORY_SEPARATOR . 'cclibxml2validator.xsd';
  32  
  33      if (is_readable($manifest_file) && !is_readable($moodle_file)) {
  34  
  35          $is_cc = detect_cc_format($manifest_file);
  36  
  37          if ($is_cc) {
  38  
  39              $detected_requirements = detect_requirements();
  40  
  41              if (!$detected_requirements["php5"]) {
  42                  notify(get_string('cc_import_req_php5', 'imscc'));
  43                  return false;
  44              }
  45  
  46              if (!$detected_requirements["dom"]) {
  47                  notify(get_string('cc_import_req_dom', 'imscc'));
  48                  return false;
  49              }
  50  
  51              if (!$detected_requirements["libxml"]) {
  52                  notify(get_string('cc_import_req_libxml', 'imscc'));
  53                  return false;
  54              }
  55  
  56              if (!$detected_requirements["libxmlminversion"]) {
  57                  notify(get_string('cc_import_req_libxmlminversion', 'imscc'));
  58                  return false;
  59              }
  60              if (!$detected_requirements["xsl"]) {
  61                  notify(get_string('cc_import_req_xsl', 'imscc'));
  62                  return false;
  63              }
  64  
  65              echo get_string('cc2moodle_checking_schema', 'imscc') . '<br />';
  66  
  67              $cc_manifest = new DOMDocument();
  68  
  69              if ($cc_manifest->load($manifest_file)) {
  70                  if ($cc_manifest->schemaValidate($schema_file)) {
  71  
  72                      echo get_string('cc2moodle_valid_schema', 'imscc') . '<br />';
  73  
  74                      $cc2moodle = new cc2moodle($manifest_file);
  75  
  76                      if (!$cc2moodle->is_auth()) {
  77                          return $cc2moodle->generate_moodle_xml();
  78                      } else {
  79                          notify(get_string('cc2moodle_req_auth', 'imscc'));
  80                          return false;
  81                      }
  82  
  83                  } else {
  84                      notify(get_string('cc2moodle_invalid_schema', 'imscc'));
  85                      return false;
  86                  }
  87  
  88              } else {
  89                  notify(get_string('cc2moodle_manifest_dont_load', 'imscc'));
  90                  return false;
  91              }
  92          }
  93      }
  94  
  95      return true;
  96  }
  97  
  98  function detect_requirements () {
  99  
 100      if (floor(phpversion()) >= 5) {
 101          $detected["php5"] = true;
 102      } else {
 103          $detected["php5"] = false;
 104      }
 105  
 106      $detected["xsl"] = extension_loaded('xsl');
 107      $detected['dom'] = extension_loaded('dom');
 108      $detected['libxml'] = extension_loaded('libxml');
 109      $detected['libxmlminversion'] = extension_loaded('libxml') && version_compare(LIBXML_DOTTED_VERSION, '2.6.30', '>=');
 110  
 111      return $detected;
 112  
 113  }
 114  
 115  function detect_cc_format ($xml_file) {
 116  
 117      $inpos = 0;
 118      $xml_snippet = file_get_contents($xml_file, 0, NULL, 0, 500);
 119  
 120      if (!empty($xml_snippet)) {
 121  
 122          $xml_snippet = strtolower($xml_snippet);
 123          $xml_snippet = preg_replace('/\s*/m', '', $xml_snippet);
 124          $xml_snippet = str_replace("'", '', $xml_snippet);
 125          $xml_snippet = str_replace('"', '', $xml_snippet);
 126  
 127          $search_string = "xmlns=" . NS_COMMON_CARTRIDGE;
 128  
 129          $inpos = strpos($xml_snippet, $search_string);
 130  
 131          if ($inpos) {
 132              return true;
 133          } else {
 134              return false;
 135          }
 136  
 137      } else {
 138          return false;
 139      }
 140  
 141  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1