[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/page/ -> view.php (source)

   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/locallib.php');
  28  require_once($CFG->libdir.'/completionlib.php');
  29  
  30  $id      = optional_param('id', 0, PARAM_INT); // Course Module ID
  31  $p       = optional_param('p', 0, PARAM_INT);  // Page instance ID
  32  $inpopup = optional_param('inpopup', 0, PARAM_BOOL);
  33  
  34  if ($p) {
  35      if (!$page = $DB->get_record('page', array('id'=>$p))) {
  36          print_error('invalidaccessparameter');
  37      }
  38      $cm = get_coursemodule_from_instance('page', $page->id, $page->course, false, MUST_EXIST);
  39  
  40  } else {
  41      if (!$cm = get_coursemodule_from_id('page', $id)) {
  42          print_error('invalidcoursemodule');
  43      }
  44      $page = $DB->get_record('page', array('id'=>$cm->instance), '*', MUST_EXIST);
  45  }
  46  
  47  $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
  48  
  49  require_course_login($course, true, $cm);
  50  $context = context_module::instance($cm->id);
  51  require_capability('mod/page:view', $context);
  52  
  53  // Trigger module viewed event.
  54  $event = \mod_page\event\course_module_viewed::create(array(
  55     'objectid' => $page->id,
  56     'context' => $context
  57  ));
  58  $event->add_record_snapshot('course_modules', $cm);
  59  $event->add_record_snapshot('course', $course);
  60  $event->add_record_snapshot('page', $page);
  61  $event->trigger();
  62  
  63  // Update 'viewed' state if required by completion system
  64  require_once($CFG->libdir . '/completionlib.php');
  65  $completion = new completion_info($course);
  66  $completion->set_module_viewed($cm);
  67  
  68  $PAGE->set_url('/mod/page/view.php', array('id' => $cm->id));
  69  
  70  $options = empty($page->displayoptions) ? array() : unserialize($page->displayoptions);
  71  
  72  if ($inpopup and $page->display == RESOURCELIB_DISPLAY_POPUP) {
  73      $PAGE->set_pagelayout('popup');
  74      $PAGE->set_title($course->shortname.': '.$page->name);
  75      $PAGE->set_heading($course->fullname);
  76  } else {
  77      $PAGE->set_title($course->shortname.': '.$page->name);
  78      $PAGE->set_heading($course->fullname);
  79      $PAGE->set_activity_record($page);
  80  }
  81  echo $OUTPUT->header();
  82  if (!isset($options['printheading']) || !empty($options['printheading'])) {
  83      echo $OUTPUT->heading(format_string($page->name), 2);
  84  }
  85  
  86  if (!empty($options['printintro'])) {
  87      if (trim(strip_tags($page->intro))) {
  88          echo $OUTPUT->box_start('mod_introbox', 'pageintro');
  89          echo format_module_intro('page', $page, $cm->id);
  90          echo $OUTPUT->box_end();
  91      }
  92  }
  93  
  94  $content = file_rewrite_pluginfile_urls($page->content, 'pluginfile.php', $context->id, 'mod_page', 'content', $page->revision);
  95  $formatoptions = new stdClass;
  96  $formatoptions->noclean = true;
  97  $formatoptions->overflowdiv = true;
  98  $formatoptions->context = $context;
  99  $content = format_text($content, $page->contentformat, $formatoptions);
 100  echo $OUTPUT->box($content, "generalbox center clearfix");
 101  
 102  $strlastmodified = get_string("lastmodified");
 103  echo "<div class=\"modified\">$strlastmodified: ".userdate($page->timemodified)."</div>";
 104  
 105  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1