Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Provides support for the conversion of moodle1 backup to the moodle2 format
  20   *
  21   * @package    mod_url
  22   * @copyright  2011 Andrew Davis <andrew@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * URL conversion handler. This resource handler is called by moodle1_mod_resource_handler
  30   */
  31  class moodle1_mod_url_handler extends moodle1_resource_successor_handler {
  32  
  33      /** @var moodle1_file_manager instance */
  34      protected $fileman = null;
  35  
  36      /**
  37       * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
  38       * Called by moodle1_mod_resource_handler::process_resource()
  39       */
  40      public function process_legacy_resource(array $data, array $raw = null) {
  41  
  42          // get the course module id and context id
  43          $instanceid = $data['id'];
  44          $cminfo     = $this->get_cminfo($instanceid, 'resource');
  45          $moduleid   = $cminfo['id'];
  46          $contextid  = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
  47  
  48          // prepare the new url instance record
  49          $url                 = array();
  50          $url['id']           = $data['id'];
  51          $url['name']         = $data['name'];
  52          $url['intro']        = $data['intro'];
  53          $url['introformat']  = $data['introformat'];
  54          $url['externalurl']  = $data['reference'];
  55          $url['timemodified'] = $data['timemodified'];
  56  
  57          // populate display and displayoptions fields
  58          $options = array('printintro' => 1);
  59          if ($data['options'] == 'frame') {
  60              $url['display'] = RESOURCELIB_DISPLAY_FRAME;
  61  
  62          } else if ($data['options'] == 'objectframe') {
  63              $url['display'] = RESOURCELIB_DISPLAY_EMBED;
  64  
  65          } else if ($data['popup']) {
  66              $url['display'] = RESOURCELIB_DISPLAY_POPUP;
  67              $rawoptions = explode(',', $data['popup']);
  68              foreach ($rawoptions as $rawoption) {
  69                  list($name, $value) = explode('=', trim($rawoption), 2);
  70                  if ($value > 0 and ($name == 'width' or $name == 'height')) {
  71                      $options['popup'.$name] = $value;
  72                      continue;
  73                  }
  74              }
  75  
  76          } else {
  77              $url['display'] = RESOURCELIB_DISPLAY_AUTO;
  78          }
  79          $url['displayoptions'] = serialize($options);
  80  
  81          // populate the parameters field
  82          $parameters = array();
  83          if ($data['alltext']) {
  84              $rawoptions = explode(',', $data['alltext']);
  85              foreach ($rawoptions as $rawoption) {
  86                  list($variable, $parameter) = explode('=', trim($rawoption), 2);
  87                  $parameters[$parameter] = $variable;
  88              }
  89          }
  90          $url['parameters'] = serialize($parameters);
  91  
  92          // convert course files embedded into the intro
  93          $this->fileman = $this->converter->get_file_manager($contextid, 'mod_url', 'intro');
  94          $url['intro'] = moodle1_converter::migrate_referenced_files($url['intro'], $this->fileman);
  95  
  96          // write url.xml
  97          $this->open_xml_writer("activities/url_{$moduleid}/url.xml");
  98          $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
  99              'modulename' => 'url', 'contextid' => $contextid));
 100          $this->write_xml('url', $url, array('/url/id'));
 101          $this->xmlwriter->end_tag('activity');
 102          $this->close_xml_writer();
 103  
 104          // write inforef.xml
 105          $this->open_xml_writer("activities/url_{$moduleid}/inforef.xml");
 106          $this->xmlwriter->begin_tag('inforef');
 107          $this->xmlwriter->begin_tag('fileref');
 108          foreach ($this->fileman->get_fileids() as $fileid) {
 109              $this->write_xml('file', array('id' => $fileid));
 110          }
 111          $this->xmlwriter->end_tag('fileref');
 112          $this->xmlwriter->end_tag('inforef');
 113          $this->close_xml_writer();
 114      }
 115  }