Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

   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  (C) 2001-3001 Eloy Lafuente (stronk7) {@link http://contiento.com}
  20   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21   */
  22  
  23  /**
  24   * This class will produce the documentation for all the XMLDB files in the server,
  25   * via XSL, performing the output in HTML format.
  26   *
  27   * @package    tool_xmldb
  28   * @copyright  (C) 2001-3001 Eloy Lafuente (stronk7) {@link http://contiento.com}
  29   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class generate_all_documentation extends XMLDBAction {
  32  
  33      /**
  34       * Init method, every subclass will have its own
  35       */
  36      function init() {
  37          parent::init();
  38  
  39          // Set own custom attributes
  40          $this->sesskey_protected = false; // This action doesn't need sesskey protection
  41  
  42          // Get needed strings
  43          $this->loadStrings(array(
  44              'backtomainview' => 'tool_xmldb',
  45              'documentationintro' => 'tool_xmldb',
  46              'docindex' => 'tool_xmldb'
  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       */
  55      function invoke() {
  56          parent::invoke();
  57  
  58          $result = true;
  59  
  60          // Set own core attributes
  61          $this->does_generate = ACTION_GENERATE_HTML;
  62  
  63          // These are always here
  64          global $CFG, $XMLDB;
  65  
  66          // Do the job, setting $result as needed
  67  
  68          // Add link back to home
  69          $b = ' <p class="centerpara buttons">';
  70          $b .= '&nbsp;<a href="index.php?action=main_view#lastused">[' . $this->str['backtomainview'] . ']</a>';
  71          $b .= '</p>';
  72          $this->output=$b;
  73  
  74          $c = ' <p class="centerpara">';
  75          $c .= $this->str['documentationintro'];
  76          $c .= '</p>';
  77          $this->output.=$c;
  78  
  79          $docs = '';
  80  
  81          if(class_exists('XSLTProcessor')) {
  82  
  83              $doc = new DOMDocument();
  84              $xsl = new XSLTProcessor();
  85  
  86              $doc->load(__DIR__.'/../generate_documentation/xmldb.xsl');
  87              $xsl->importStyleSheet($doc);
  88  
  89              $dbdirs = get_db_directories();
  90              sort($dbdirs);
  91              $index = $this->str['docindex'] . ' ';
  92              foreach ($dbdirs as $path) {
  93  
  94                  if (!file_exists($path . '/install.xml')) {
  95                      continue;
  96                  }
  97  
  98                  $dir = trim(dirname(str_replace($CFG->dirroot, '', $path)), '/');
  99                  $index .= '<a href="#file_' . str_replace('/', '_', $dir) . '">' . $dir . '</a>, ';
 100                  $docs .= '<div class="file" id="file_' . str_replace('/', '_', $dir) . '">';
 101                  $docs .= '<h2>' . $dir . '</h2>';
 102  
 103                  $doc->load($path . '/install.xml');
 104                  $docs .= $xsl->transformToXML($doc);
 105  
 106                  $docs .= '</div>';
 107              }
 108  
 109              $this->output .= '<div id="file_idex">' . trim($index, ' ,') . '</div>' . $docs;
 110  
 111              $this->output.=$b;
 112          } else {
 113              $this->output.=get_string('extensionrequired','tool_xmldb','xsl');
 114          }
 115  
 116          // Launch postaction if exists (leave this unmodified)
 117          if ($this->getPostAction() && $result) {
 118              return $this->launch($this->getPostAction());
 119          }
 120  
 121          return $result;
 122      }
 123  }
 124