Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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  /**
  18   * @package    tool_xmldb
  19   * @copyright  2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  20   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21   */
  22  
  23  /**
  24   * This class will display one XML file
  25   *
  26   * @package    tool_xmldb
  27   * @copyright  2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  class view_xml extends XMLDBAction {
  31  
  32      /**
  33       * Init method, every subclass will have its own
  34       */
  35      function init() {
  36          parent::init();
  37          // Set own core attributes
  38          $this->can_subaction = ACTION_NONE;
  39          //$this->can_subaction = ACTION_HAVE_SUBACTIONS;
  40  
  41          // Set own custom attributes
  42          $this->sesskey_protected = false; // This action doesn't need sesskey protection
  43  
  44          // Get needed strings
  45          $this->loadStrings(array(
  46              // 'key' => 'module',
  47          ));
  48      }
  49  
  50      /**
  51       * Invoke method, every class will have its own
  52       * returns true/false on completion, setting both
  53       * errormsg and output as necessary
  54       * @return mixed
  55       */
  56      function invoke() {
  57          parent::invoke();
  58  
  59          $result = true;
  60  
  61          // Set own core attributes
  62          $this->does_generate = ACTION_GENERATE_XML;
  63  
  64          // These are always here
  65          global $CFG, $XMLDB;
  66  
  67          // Do the job, setting result as needed
  68  
  69          // Get the file parameter
  70          $file = required_param('file', PARAM_PATH);
  71  
  72          $fullpath = $CFG->dirroot . $file;
  73          // File param must start with / and end with /db/install.xml to be safe.
  74          if (substr($file, 0, 1) == '/' &&
  75              substr($file, -15, 15) == '/db/install.xml') {
  76              // Everything is ok. Load the file to memory
  77              $this->output = file_get_contents($fullpath);
  78          } else {
  79              // Switch to HTML and error
  80              $this->does_generate = ACTION_GENERATE_HTML;
  81              $this->errormsg = 'File not viewable (' . $file .')';
  82              $result = false;
  83          }
  84  
  85          // Return ok if arrived here
  86          return $result;
  87      }
  88  }
  89