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.
   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   * MFA guidance page.
  18   *
  19   * @package     tool_mfa
  20   * @author      Peter Burnett <peterburnett@catalyst-au.net>
  21   * @copyright   Catalyst IT
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  // Require_login is not needed here.
  25  // phpcs:disable moodle.Files.RequireLogin.Missing
  26  require_once(__DIR__ . '/../../../config.php');
  27  
  28  // No require_login, unauthenticated page.
  29  $PAGE->set_context(\context_system::instance());
  30  $PAGE->set_url(new moodle_url('/admin/tool/mfa/guide.php'));
  31  $PAGE->set_title(get_string('guidance', 'tool_mfa'));
  32  $PAGE->set_pagelayout('standard');
  33  
  34  // If guidance page isn't enabled, just redir back to home.
  35  if (!get_config('tool_mfa', 'guidance')) {
  36      redirect(new moodle_url('/'));
  37  }
  38  
  39  // Navigation. Target user preferences as previous node if authed.
  40  if (isloggedin() && (isset($SESSION->tool_mfa_authenticated) && $SESSION->tool_mfa_authenticated)) {
  41      if ($node = $PAGE->settingsnav->find('usercurrentsettings', null)) {
  42          $PAGE->navbar->add($node->get_content(), $node->action());
  43      }
  44      $PAGE->navbar->add(get_string('preferences:header', 'tool_mfa'), new \moodle_url('/admin/tool/mfa/user_preferences.php'));
  45  } else {
  46      // Otherwise just point to site home.
  47      if ($node = $PAGE->settingsnav->find('home', null)) {
  48          $PAGE->navbar->add($node->get_content(), $node->action());
  49      }
  50  }
  51  $PAGE->navbar->add(get_string('guidance', 'tool_mfa'), new \moodle_url('/admin/tool/mfa/guide.php'));
  52  
  53  echo $OUTPUT->header();
  54  $html = get_config('tool_mfa', 'guidancecontent');
  55  
  56  // We need to go through and replace file markups with a matching filename.
  57  $fs = get_file_storage();
  58  $context = context_system::instance();
  59  $files = $fs->get_area_files($context->id, 'tool_mfa', 'guidance', 0, 'filepath, filename', false);
  60  foreach ($files as $file) {
  61      $filename = $file->get_filename();
  62      $url = moodle_url::make_pluginfile_url(
  63          $file->get_contextid(),
  64          $file->get_component(),
  65          $file->get_filearea(),
  66          $file->get_itemid(),
  67          $file->get_filepath(),
  68          $file->get_filename()
  69      );
  70      // For cases where the format is {{{filename}}}, preserve the default
  71      // behaviour of converting this to a html link.
  72      $html = str_replace('{{{' . $filename . '}}}', html_writer::link($url, $url), $html);
  73      // When used with {{filename}}, the template string will be replaced with
  74      // the resolved value (similar to Mustache templates). Usage will most
  75      // likely be used for direct embeds within links, imgs, etc.
  76      $html = str_replace('{{' . $filename . '}}', $url, $html);
  77  }
  78  
  79  // Parses and returns the text after default moodle filters with cleaning disabled, to allow for any inline styles.
  80  echo format_text($html, FORMAT_MOODLE, ['noclean' => true]);
  81  echo $OUTPUT->footer();