Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/auth/cas/ -> lib.php (source)
   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   * Authentication Plugin: CAS Authentication.
  19   *
  20   * Authentication using CAS (Central Authentication Server).
  21   *
  22   * @package     auth_cas
  23   * @copyright   2018 Fabrice Ménard <menard.fabrice@gmail.com>
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die;
  28  
  29  /**
  30   * Serves the logo file settings.
  31   *
  32   * @param   stdClass $course course object
  33   * @param   stdClass $cm course module object
  34   * @param   stdClass $context context object
  35   * @param   string $filearea file area
  36   * @param   array $args extra arguments
  37   * @param   bool $forcedownload whether or not force download
  38   * @param   array $options additional options affecting the file serving
  39   * @return  bool false|void
  40   */
  41  function auth_cas_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = []) {
  42      if ($context->contextlevel != CONTEXT_SYSTEM) {
  43          return false;
  44      }
  45  
  46      if ($filearea !== 'logo' ) {
  47          return false;
  48      }
  49  
  50      // Extract the filename / filepath from the $args array.
  51      $filename = array_pop($args);
  52      if (!$args) {
  53          $filepath = '/';
  54      } else {
  55          $filepath = '/' . implode('/', $args) . '/';
  56      }
  57  
  58      // Retrieve the file from the Files API.
  59      $itemid = 0;
  60      $fs = get_file_storage();
  61      $file = $fs->get_file($context->id, 'auth_cas', $filearea, $itemid, $filepath, $filename);
  62      if (!$file) {
  63          return false; // The file does not exist.
  64      }
  65  
  66      send_stored_file($file, null, 0, $forcedownload, $options);
  67  }