Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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 2011 Darko Miletic (dmiletic@moodlerooms.com)
  20   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21   */
  22  
  23  defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
  24  
  25  require_once($CFG->dirroot . '/backup/cc/entities.class.php');
  26  
  27  class entities11 extends entities {
  28  
  29      public function get_external_xml($identifier) {
  30          $xpath = cc2moodle::newx_path(cc112moodle::$manifest, cc112moodle::$namespaces);
  31          $files = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' .
  32                   $identifier . '"]/imscc:file/@href');
  33          $response = empty($files) || ($files->length == 0) ? '' : $files->item(0)->nodeValue;
  34          return $response;
  35      }
  36  
  37      protected function get_all_files () {
  38          global $CFG;
  39          $all_files = array();
  40          $xpath = cc2moodle::newx_path(cc112moodle::$manifest, cc112moodle::$namespaces);
  41          foreach (cc112moodle::$restypes as $type) {
  42              $files = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@type="' .
  43                                      $type . '"]/imscc:file/@href');
  44              if (empty($files) || ($files->length == 0)) {
  45                  continue;
  46              }
  47              foreach ($files as $file) {
  48                  //omit html files
  49                  //this is a bit too simplistic
  50                  $ext = strtolower(pathinfo($file->nodeValue, PATHINFO_EXTENSION));
  51                  if (in_array($ext, array('html', 'htm', 'xhtml'))) {
  52                      continue;
  53                  }
  54                  $all_files[] = $file->nodeValue;
  55              }
  56              unset($files);
  57          }
  58  
  59          //are there any labels?
  60          $xquery = "//imscc:item/imscc:item/imscc:item[imscc:title][not(@identifierref)]";
  61          $labels = $xpath->query($xquery);
  62          if (!empty($labels) && ($labels->length > 0)) {
  63              $tname = 'course_files';
  64              $dpath = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $tname;
  65              $rfpath = 'files.gif';
  66              $fpath = $dpath . DIRECTORY_SEPARATOR . 'files.gif';
  67              if (!file_exists($dpath)) {
  68                  mkdir($dpath, $CFG->directorypermissions, true);
  69              }
  70              //copy the folder.gif file
  71              $folder_gif = "{$CFG->dirroot}/pix/i/files.gif";
  72              copy($folder_gif, $fpath);
  73              $all_files[] = $rfpath;
  74          }
  75          $all_files = empty($all_files) ? '' : $all_files;
  76  
  77          return $all_files;
  78      }
  79  
  80  }
  81