Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * Checks the write permission for the given plugin type
  20   *
  21   * @package     tool_installaddon
  22   * @subpackage  ajax
  23   * @copyright   2013 David Mudrak <david@moodle.com>
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  define('AJAX_SCRIPT', true);
  28  
  29  require(__DIR__ . '/../../../config.php');
  30  require_once($CFG->libdir.'/adminlib.php');
  31  
  32  require_login(null, false);
  33  
  34  if (!has_capability('moodle/site:config', context_system::instance())) {
  35      header('HTTP/1.1 403 Forbidden');
  36      die();
  37  }
  38  
  39  if (!empty($CFG->disableupdateautodeploy)) {
  40      header('HTTP/1.1 403 Forbidden');
  41      die();
  42  }
  43  
  44  if (!confirm_sesskey()) {
  45      header('HTTP/1.1 403 Forbidden');
  46      die();
  47  }
  48  
  49  $plugintype = optional_param('plugintype', null, PARAM_ALPHANUMEXT);
  50  if (is_null($plugintype)) {
  51      header('HTTP/1.1 400 Bad Request');
  52      die();
  53  }
  54  
  55  $pluginman = core_plugin_manager::instance();
  56  
  57  $plugintypepath = $pluginman->get_plugintype_root($plugintype);
  58  
  59  if (empty($plugintypepath)) {
  60      header('HTTP/1.1 400 Bad Request');
  61      die();
  62  }
  63  
  64  $response = array('path' => $plugintypepath);
  65  
  66  if ($pluginman->is_plugintype_writable($plugintype)) {
  67      $response['writable'] = 1;
  68  } else {
  69      $response['writable'] = 0;
  70  }
  71  
  72  header('Content-Type: application/json; charset: utf-8');
  73  echo json_encode($response);