Search moodle.org's
Developer Documentation


Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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   * This file is serving the javascript source map.
      19   *
      20   * @package    core
      21   * @copyright  2019 Ryan Wyllie
      22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
      23   */
      24  
      25  // Disable moodle specific debug messages and any errors in output,
      26  // comment out when debugging or better look into error log!
      27  define('NO_DEBUG_DISPLAY', true);
      28  
      29  require('../config.php');
      30  require_once("$CFG->dirroot/lib/configonlylib.php");
      31  require_once("$CFG->dirroot/lib/classes/requirejs.php");
      32  
      33  $slashargument = min_get_slash_argument();
      34  if (!$slashargument) {
      35      // The above call to min_get_slash_argument should always work.
      36      die('Invalid request');
      37  }
      38  
      39  $slashargument = ltrim($slashargument, '/');
      40  // Split into revision and module name.
      41  [$file] = explode('/', $slashargument, 1);
      42  $file = '/' . min_clean_param($file, 'SAFEPATH');
      43  
      44  // Only load js files from the js modules folder from the components.
      45  [$unused, $component, $module] = explode('/', $file, 3);
      46  
      47  // When running a lazy load, we only deal with one file so we can just return the working sourcemap.
      48  $jsfiles = core_requirejs::find_one_amd_module($component, $module, false);
      49  $jsfile = reset($jsfiles);
      50  
      51  $mapfile = $jsfile . '.map';
      52  
      53  if (file_exists($mapfile)) {
      54      $mapdata = file_get_contents($mapfile);
      55      $mapdata = json_decode($mapdata, true);
      56  
      57      $shortfilename = str_replace($CFG->dirroot, '', $jsfile);
      58      $srcfilename = str_replace('/amd/build/', '/amd/src/', $shortfilename);
      59      $srcfilename = str_replace('.min.js', '.js', $srcfilename);
      60      $fullsrcfilename = $CFG->wwwroot . $srcfilename;
      61      $mapdata['sources'][0] = $fullsrcfilename;
      62  
      63      echo json_encode($mapdata);
      64  } else {
      65      // If there is no source map file, then we will not generate one for you, sorry.
      66      header('HTTP/1.0 404 not found');
      67  }
    

    Search This Site: