/** * Display embedded url file. * @param object $url * @param object $cm * @param object $course * @param stored_file $file main file * @return does not return */ function url_display_embed($url, $cm, $course) { global $CFG, $PAGE, $OUTPUT; $mimetype = resourcelib_guess_url_mimetype($url->externalurl); $fullurl = url_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); $extension = resourcelib_get_extension($url->externalurl); if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // It's an image $code = resourcelib_embed_image($fullurl, $title); } else { if ($mimetype == 'audio/mp3') { // MP3 audio file $code = resourcelib_embed_mp3($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'video/x-flv' or $extension === 'f4v') { // Flash video file $code = resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'application/x-shockwave-flash') { // Flash file $code = resourcelib_embed_flash($fullurl, $title, $clicktoopen); } else { if (substr($mimetype, 0, 10) == 'video/x-ms') { // Windows Media Player file $code = resourcelib_embed_mediaplayer($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'video/quicktime') { // Quicktime file $code = resourcelib_embed_quicktime($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'video/mpeg') { // Mpeg file $code = resourcelib_embed_mpeg($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'audio/x-pn-realaudio-plugin') { // RealMedia file $code = resourcelib_embed_real($fullurl, $title, $clicktoopen); } else { // anything else - just try object tag enlarged as much as possible $code = resourcelib_embed_general($fullurl, $title, $clicktoopen, $mimetype); } } } } } } } } url_print_header($url, $cm, $course); url_print_heading($url, $cm, $course); echo $code; url_print_intro($url, $cm, $course); echo $OUTPUT->footer(); die; }
/** * Display embedded resource file. * @param object $resource * @param object $cm * @param object $course * @param stored_file $file main file * @return does not return */ function resource_display_embed($resource, $cm, $course, $file) { global $CFG, $PAGE, $OUTPUT; $clicktoopen = resource_get_clicktoopen($file, $resource->revision); $context = get_context_instance(CONTEXT_MODULE, $cm->id); $path = '/' . $context->id . '/mod_resource/content/' . $resource->revision . $file->get_filepath() . $file->get_filename(); $fullurl = file_encode_url($CFG->wwwroot . '/pluginfile.php', $path, false); $mimetype = $file->get_mimetype(); $title = $resource->name; $extension = resourcelib_get_extension($file->get_filename()); if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // It's an image $code = resourcelib_embed_image($fullurl, $title); } else { if ($mimetype === 'application/pdf') { // PDF document $code = resourcelib_embed_pdf($fullurl, $title, $clicktoopen); } else { if ($mimetype === 'audio/mp3') { // MP3 audio file $code = resourcelib_embed_mp3($fullurl, $title, $clicktoopen); } else { if ($mimetype === 'video/x-flv' or $extension === 'f4v') { // Flash video file $code = resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen); } else { if ($mimetype === 'application/x-shockwave-flash') { // Flash file $code = resourcelib_embed_flash($fullurl, $title, $clicktoopen); } else { if (substr($mimetype, 0, 10) === 'video/x-ms') { // Windows Media Player file $code = resourcelib_embed_mediaplayer($fullurl, $title, $clicktoopen); } else { if ($mimetype === 'video/quicktime') { // Quicktime file $code = resourcelib_embed_quicktime($fullurl, $title, $clicktoopen); } else { if ($mimetype === 'video/mpeg') { // Mpeg file $code = resourcelib_embed_mpeg($fullurl, $title, $clicktoopen); } else { if ($mimetype === 'audio/x-pn-realaudio') { // RealMedia file $code = resourcelib_embed_real($fullurl, $title, $clicktoopen); } else { // anything else - just try object tag enlarged as much as possible $code = resourcelib_embed_general($fullurl, $title, $clicktoopen, $mimetype); } } } } } } } } } resource_print_header($resource, $cm, $course); resource_print_heading($resource, $cm, $course); echo $code; resource_print_intro($resource, $cm, $course); echo $OUTPUT->footer(); die; }
/** * This is a function used to detect media types and generate html code. * * @global object $CFG * @global object $PAGE * @param object $lesson * @param object $context * @return string $code the html code of media */ function lesson_get_media_html($lesson, $context) { global $CFG, $PAGE, $OUTPUT; require_once "{$CFG->libdir}/resourcelib.php"; // get the media file link if (strpos($lesson->mediafile, '://') !== false) { $url = new moodle_url($lesson->mediafile); } else { // the timemodified is used to prevent caching problems, instead of '/' we should better read from files table and use sortorder $url = moodle_url::make_pluginfile_url($context->id, 'mod_lesson', 'mediafile', $lesson->timemodified, '/', ltrim($lesson->mediafile, '/')); } $title = $lesson->mediafile; $clicktoopen = html_writer::link($url, get_string('download')); $mimetype = resourcelib_guess_url_mimetype($url); $extension = resourcelib_get_extension($url->out(false)); // find the correct type and print it out if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // It's an image $code = resourcelib_embed_image($url, $title); } else { if ($mimetype == 'audio/mp3') { // MP3 audio file $code = resourcelib_embed_mp3($url, $title, $clicktoopen); } else { if ($mimetype == 'video/x-flv' or $extension === 'f4v') { // Flash video file $code = resourcelib_embed_flashvideo($url, $title, $clicktoopen); } else { if ($mimetype == 'application/x-shockwave-flash') { // Flash file $code = resourcelib_embed_flash($url, $title, $clicktoopen); } else { if (substr($mimetype, 0, 10) == 'video/x-ms') { // Windows Media Player file $code = resourcelib_embed_mediaplayer($url, $title, $clicktoopen); } else { if ($mimetype == 'video/quicktime') { // Quicktime file $code = resourcelib_embed_quicktime($url, $title, $clicktoopen); } else { if ($mimetype == 'video/mpeg') { // Mpeg file $code = resourcelib_embed_mpeg($url, $title, $clicktoopen); } else { if ($mimetype == 'audio/x-pn-realaudio-plugin') { // RealMedia file $code = resourcelib_embed_real($url, $title, $clicktoopen); } else { // anything else - just try object tag enlarged as much as possible $code = resourcelib_embed_general($url, $title, $clicktoopen, $mimetype); } } } } } } } } return $code; }
/** * Display embedded url file. * @param object $url * @param object $cm * @param object $course * @param stored_file $file main file * @return does not return */ function url_display_embed($url, $cm, $course) { global $CFG, $PAGE; $clicktoopen = get_string('clicktoopen', 'url', $url->externalurl); $mimetype = resourcelib_guess_url_mimetype($url->externalurl); $fullurl = url_get_full_url($url, $cm, $course); $title = $url->name; if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // It's an image $code = resourcelib_embed_image($fullurl, $title); } else { if ($mimetype == 'audio/mp3') { // MP3 audio file $code = resourcelib_embed_mp3($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'video/x-flv') { // Flash video file $code = resourcelib_embed_flashvideo($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'application/x-shockwave-flash') { // Flash file $code = resourcelib_embed_flash($fullurl, $title, $clicktoopen); } else { if (substr($mimetype, 0, 10) == 'video/x-ms') { // Windows Media Player file $code = resourcelib_embed_mediaplayer($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'video/quicktime') { // Quicktime file $code = resourcelib_embed_quicktime($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'video/mpeg') { // Mpeg file $code = resourcelib_embed_mpeg($fullurl, $title, $clicktoopen); } else { if ($mimetype == 'audio/x-pn-realaudio') { // RealMedia file $code = resourcelib_embed_real($fullurl, $title, $clicktoopen); } else { // anything else - just try object tag enlarged as much as possible $code = resourcelib_embed_general($fullurl, $title, $clicktoopen, $mimetype); $PAGE->requires->yui_lib('dom')->in_head(); $PAGE->requires->js('mod/url/functions.js')->in_head(); $PAGE->requires->js_function_call('url_init_object'); } } } } } } } } url_print_header($url, $cm, $course); url_print_heading($url, $cm, $course); echo $code; url_print_intro($url, $cm, $course); print_footer(); die; }