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.

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

   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   * Web services API documentation
  20   *
  21   * @package   webservice
  22   * @copyright 2011 Moodle Pty Ltd (http://moodle.com)
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   * @author Jerome Mouneyrac
  25   */
  26  require_once('../../config.php');
  27  require_once($CFG->libdir . '/adminlib.php');
  28  require_once($CFG->dirroot . '/webservice/lib.php');
  29  
  30  admin_externalpage_setup('webservicedocumentation');
  31  
  32  // TODO: MDL-76078 - Incorrect inter-communication, core cannot have plugin dependencies like this.
  33  
  34  //display the documentation for all documented protocols,
  35  //regardless if they are activated or not
  36  $protocols = array();
  37  $protocols['rest'] = true;
  38  $protocols['xmlrpc'] = true;
  39  
  40  /// Check if we are in printable mode
  41  $printableformat = optional_param('print', false, PARAM_BOOL);
  42  
  43  /// OUTPUT
  44  echo $OUTPUT->header();
  45  
  46  // Get all the function descriptions.
  47  $functions = $DB->get_records('external_functions', [], 'name');
  48  $functiondescs = [];
  49  foreach ($functions as $function) {
  50  
  51      // Skip invalid or otherwise incorrectly defined functions, otherwise the entire page is rendered inaccessible.
  52      try {
  53          $functiondescs[$function->name] = external_api::external_function_info($function);
  54      } catch (Throwable $exception) {
  55          echo $OUTPUT->notification($exception->getMessage(), \core\output\notification::NOTIFY_ERROR);
  56      }
  57  }
  58  
  59  $renderer = $PAGE->get_renderer('core', 'webservice');
  60  echo $renderer->documentation_html($functiondescs,
  61          $printableformat, $protocols, array(), $PAGE->url);
  62  
  63  /// trigger browser print operation
  64  if (!empty($printableformat)) {
  65      $PAGE->requires->js_function_call('window.print', array());
  66  }
  67  
  68  echo $OUTPUT->footer();
  69