Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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.

Differences Between: [Versions 310 and 403]

   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   * Search and replace http -> https throughout all texts in the whole database
  19   *
  20   * @package    tool_httpsreplace
  21   * @copyright Copyright (c) 2016 Blackboard Inc. (http://www.blackboard.com)
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  define('NO_OUTPUT_BUFFERING', true);
  26  
  27  require_once(__DIR__ . '/../../../config.php');
  28  require_once($CFG->dirroot . '/course/lib.php');
  29  require_once($CFG->libdir . '/adminlib.php');
  30  
  31  admin_externalpage_setup('toolhttpsreplace');
  32  
  33  $context = context_system::instance();
  34  
  35  $PAGE->set_context($context);
  36  $PAGE->set_url(new moodle_url('/admin/tool/httpsreplace/index.php'));
  37  $PAGE->set_title(get_string('pageheader', 'tool_httpsreplace'));
  38  $PAGE->set_pagelayout('admin');
  39  
  40  echo $OUTPUT->header();
  41  
  42  echo $OUTPUT->heading(get_string('pageheader', 'tool_httpsreplace'));
  43  
  44  if (!$DB->replace_all_text_supported()) {
  45      echo $OUTPUT->notification(get_string('notimplemented', 'tool_httpsreplace'));
  46      echo $OUTPUT->footer();
  47      die;
  48  }
  49  
  50  if (!is_https()) {
  51      echo $OUTPUT->notification(get_string('httpwarning', 'tool_httpsreplace'), 'warning');
  52  }
  53  
  54  $form = new \tool_httpsreplace\form();
  55  
  56  $finder = new \tool_httpsreplace\url_finder();
  57  
  58  $PAGE->set_cacheable(false);
  59  $progressbar = new progress_bar();
  60  
  61  if (!$data = $form->get_data()) {
  62  
  63      echo $progressbar->create();
  64  
  65      $results = $finder->http_link_stats($progressbar);
  66  
  67      $progressbar->update_full(100, get_string('complete', 'tool_httpsreplace'));
  68  
  69      if (empty($results)) {
  70          echo '<p>'.get_string('oktoprocede', 'tool_httpsreplace').'</p>';
  71      } else {
  72          arsort($results);
  73          $table = new html_table();
  74          $table->id = 'plugins-check';
  75          $table->head = array(
  76              get_string('domain', 'tool_httpsreplace'),
  77              get_string('count', 'tool_httpsreplace'),
  78          );
  79          $data = array();
  80          foreach ($results as $domain => $count) {
  81              $cleandomain = format_text($domain, FORMAT_PLAIN);
  82              $data[] = [$cleandomain, $count];
  83          }
  84          $table->data = $data;
  85          echo html_writer::table($table);
  86          echo get_string('domainexplainhelp', 'tool_httpsreplace');
  87      }
  88      echo $OUTPUT->notification(get_string('takeabackupwarning', 'tool_httpsreplace'), 'warning');
  89      $form->display();
  90  } else {
  91      // Scroll to the end when finished.
  92      $PAGE->requires->js_init_code("window.scrollTo(0, document.body.scrollHeight);");
  93  
  94      echo html_writer::tag('p', get_string('replacing', 'tool_httpsreplace'));
  95  
  96      echo $progressbar->create();
  97  
  98      echo $OUTPUT->box_start();
  99      $finder->upgrade_http_links($progressbar);
 100      echo $OUTPUT->box_end();
 101  
 102      $progressbar->update_full(100, get_string('complete', 'tool_httpsreplace'));
 103  
 104      echo $OUTPUT->continue_button(new moodle_url('/admin/settings.php', ['section' => 'httpsecurity']));
 105  }
 106  echo $OUTPUT->footer();