Search moodle.org's
Developer Documentation

See Release Notes
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.
/mod/page/ -> view.php (source)

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

   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   * Page module version information
  20   *
  21   * @package mod_page
  22   * @copyright  2009 Petr Skoda (http://skodak.org)
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require('../../config.php');
  27  require_once($CFG->dirroot.'/mod/page/lib.php');
  28  require_once($CFG->dirroot.'/mod/page/locallib.php');
  29  require_once($CFG->libdir.'/completionlib.php');
  30  
  31  $id      = optional_param('id', 0, PARAM_INT); // Course Module ID
  32  $p       = optional_param('p', 0, PARAM_INT);  // Page instance ID
  33  $inpopup = optional_param('inpopup', 0, PARAM_BOOL);
  34  
  35  if ($p) {
  36      if (!$page = $DB->get_record('page', array('id'=>$p))) {
  37          print_error('invalidaccessparameter');
  38      }
  39      $cm = get_coursemodule_from_instance('page', $page->id, $page->course, false, MUST_EXIST);
  40  
  41  } else {
  42      if (!$cm = get_coursemodule_from_id('page', $id)) {
  43          print_error('invalidcoursemodule');
  44      }
  45      $page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST);
  46  }
  47  
  48  $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
  49  
  50  require_course_login($course, true, $cm);
  51  $context = context_module::instance($cm->id);
  52  require_capability('mod/page:view', $context);
  53  
  54  // Completion and trigger events.
  55  page_view($page, $course, $cm, $context);
  56  
  57  $PAGE->set_url('/mod/page/view.php', array('id' => $cm->id));
  58  
  59  $options = empty($page->displayoptions) ? [] : (array) unserialize_array($page->displayoptions);
  60  
  61  if ($inpopup and $page->display == RESOURCELIB_DISPLAY_POPUP) {
  62      $PAGE->set_pagelayout('popup');
  63      $PAGE->set_title($course->shortname.': '.$page->name);
  64      $PAGE->set_heading($course->fullname);
  65  } else {
  66      $PAGE->set_title($course->shortname.': '.$page->name);
  67      $PAGE->set_heading($course->fullname);
  68      $PAGE->set_activity_record($page);
  69  }
  70  echo $OUTPUT->header();
  71  if (!isset($options['printheading']) || !empty($options['printheading'])) {
  72      echo $OUTPUT->heading(format_string($page->name), 2);
  73  }
  74  
  75  if (!empty($options['printintro'])) {
  76      if (trim(strip_tags($page->intro))) {
  77          echo $OUTPUT->box_start('mod_introbox', 'pageintro');
  78          echo format_module_intro('page', $page, $cm->id);
  79          echo $OUTPUT->box_end();
  80      }
  81  }
  82  
  83  $content = file_rewrite_pluginfile_urls($page->content, 'pluginfile.php', $context->id, 'mod_page', 'content', $page->revision);
  84  $formatoptions = new stdClass;
  85  $formatoptions->noclean = true;
  86  $formatoptions->overflowdiv = true;
  87  $formatoptions->context = $context;
  88  $content = format_text($content, $page->contentformat, $formatoptions);
  89  echo $OUTPUT->box($content, "generalbox center clearfix");
  90  
  91  if (!isset($options['printlastmodified']) || !empty($options['printlastmodified'])) {
  92      $strlastmodified = get_string("lastmodified");
  93      echo html_writer::div("$strlastmodified: " . userdate($page->timemodified), 'modified');
  94  }
  95  
  96  echo $OUTPUT->footer();