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  // 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 produce XSL documentation for the loaded 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 generate_documentation extends XMLDBAction {
  31  
  32      /**
  33       * Init method, every subclass will have its own
  34       */
  35      function init() {
  36          parent::init();
  37  
  38          // Set own custom attributes
  39          $this->sesskey_protected = false; // This action doesn't need sesskey protection
  40  
  41          // Get needed strings
  42          $this->loadStrings(array(
  43              'backtomainview' => 'tool_xmldb',
  44              'documentationintro' => 'tool_xmldb'
  45          ));
  46      }
  47  
  48      /**
  49       * Invoke method, every class will have its own
  50       * returns true/false on completion, setting both
  51       * errormsg and output as necessary
  52       */
  53      function invoke() {
  54          parent::invoke();
  55  
  56          $result = true;
  57  
  58          // Set own core attributes
  59          $this->does_generate = ACTION_GENERATE_HTML;
  60  
  61          // These are always here
  62          global $CFG, $XMLDB;
  63  
  64          // Do the job, setting $result as needed
  65  
  66          // Get the dir containing the file
  67          $dirpath = required_param('dir', PARAM_PATH);
  68          $dirpath = $CFG->dirroot . $dirpath;
  69          $path = $dirpath.'/install.xml';
  70          if(!file_exists($path) || !is_readable($path)) {
  71              return false;
  72          }
  73  
  74          // Add link back to home
  75          $b = ' <p class="centerpara buttons">';
  76          $b .= '&nbsp;<a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>';
  77          $b .= '</p>';
  78          $this->output=$b;
  79  
  80          $c = ' <p class="centerpara">';
  81          $c .= $this->str['documentationintro'];
  82          $c .= '</p>';
  83          $this->output.=$c;
  84  
  85          if(class_exists('XSLTProcessor')) {
  86              // Transform XML file and display it
  87              $doc = new DOMDocument();
  88              $xsl = new XSLTProcessor();
  89  
  90              $doc->load(__DIR__.'/xmldb.xsl');
  91              $xsl->importStyleSheet($doc);
  92  
  93              $doc->load($path);
  94              $this->output.=$xsl->transformToXML($doc);
  95              $this->output.=$b;
  96          } else {
  97              $this->output.=get_string('extensionrequired','tool_xmldb','xsl');
  98          }
  99  
 100          // Launch postaction if exists (leave this unmodified)
 101          if ($this->getPostAction() && $result) {
 102              return $this->launch($this->getPostAction());
 103          }
 104  
 105          return $result;
 106      }
 107  }
 108