$morsle = $DB->get_record('morsle', array('id' => $cm->instance), '*', MUST_EXIST); } $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_course_login($course, true, $cm); $context = context_module::instance($cm->id); require_capability('mod/morsle:view', $context); add_to_log($course->id, 'morsle', 'view', 'view.php?id=' . $cm->id, $morsle->id, $cm->id); // Update 'viewed' state if required by completion system $completion = new completion_info($course); $completion->set_module_viewed($cm); $PAGE->set_url('/mod/morsle/view.php', array('id' => $cm->id)); // Make sure morsle exists before generating output - some older sites may contain empty urls // Do not use PARAM_URL here, it is too strict and does not support general URIs! $exturl = trim($morsle->externalurl); if (empty($exturl) or $exturl === 'http://') { morsle_print_header($morsle, $cm, $course); morsle_print_heading($morsle, $cm, $course); morsle_print_intro($morsle, $cm, $course); notice(get_string('invalidstoredurl', 'morsle'), new moodle_url('/course/view.php', array('id' => $cm->course))); die; } unset($exturl); $displaytype = morsle_get_final_display_type($morsle); if ($displaytype == RESOURCELIB_DISPLAY_OPEN) { // For 'open' links, we always redirect to the content - except if the user // just chose 'save and display' from the form then that would be confusing if (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], 'modedit.php') === false) { $redirect = true; } } if ($redirect) {
/** * Display embedded url file. * @param object $url * @param object $cm * @param object $course * @return does not return */ function morsle_display_embed($url, $cm, $course) { global $CFG, $PAGE, $OUTPUT; $mimetype = resourcelib_guess_url_mimetype($url->externalurl); $fullurl = morsle_get_full_url($url, $cm, $course); $title = $url->name; $link = html_writer::tag('a', $fullurl, array('href' => str_replace('&', '&', $fullurl))); $clicktoopen = get_string('clicktoopen', 'url', $link); $moodleurl = new moodle_url($fullurl); $extension = resourcelib_get_extension($url->externalurl); $mediarenderer = $PAGE->get_renderer('core', 'media'); $embedoptions = array(core_media::OPTION_TRUSTED => true, core_media::OPTION_BLOCK => true); if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // It's an image $code = resourcelib_embed_image($fullurl, $title); } else { if ($mediarenderer->can_embed_url($moodleurl, $embedoptions)) { // Media (audio/video) file. $code = $mediarenderer->embed_url($moodleurl, $title, 0, 0, $embedoptions); } else { // anything else - just try object tag enlarged as much as possible $code = resourcelib_embed_general($fullurl, $title, $clicktoopen, $mimetype); } } morsle_print_header($url, $cm, $course); morsle_print_heading($url, $cm, $course); echo $code; morsle_print_intro($url, $cm, $course); echo $OUTPUT->footer(); die; }