/** * Given a course_module object, this function returns any * "extra" information that may be needed when printing * this activity in a course listing. * * See {@link get_array_of_activities()} in course/lib.php * * @param object $coursemodule * @return object info */ function mediaelementjs_get_coursemodule_info($coursemodule) { global $CFG, $DB; require_once "{$CFG->dirroot}/mod/mediaelementjs/locallib.php"; if (!($mediaelementjs = $DB->get_record('mediaelementjs', array('id' => $coursemodule->instance), 'id, name, display, displayoptions, externalurl, parameters'))) { return NULL; } $info = new stdClass(); $info->name = $mediaelementjs->name; //note: there should be a way to differentiate links from normal resources $info->icon = mediaelementjs_guess_icon($mediaelementjs->externalurl); $display = mediaelementjs_get_final_display_type($mediaelementjs); if ($display == RESOURCELIB_DISPLAY_POPUP) { $fullurl = "{$CFG->wwwroot}/mod/mediaelementjs/view.php?id={$coursemodule->id}&redirect=1"; $options = empty($mediaelementjs->displayoptions) ? array() : unserialize($mediaelementjs->displayoptions); $width = empty($options['popupwidth']) ? 620 : $options['popupwidth']; $height = empty($options['popupheight']) ? 450 : $options['popupheight']; $wh = "width={$width},height={$height},toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes"; $info->extra = "onclick=\"window.open('{$fullurl}', '', '{$wh}'); return false;\""; } else { if ($display == RESOURCELIB_DISPLAY_NEW) { $fullurl = "{$CFG->wwwroot}/mod/mediaelementjs/view.php?id={$coursemodule->id}&redirect=1"; $info->extra = "onclick=\"window.open('{$fullurl}'); return false;\""; } else { if ($display == RESOURCELIB_DISPLAY_OPEN) { $fullurl = "{$CFG->wwwroot}/mod/mediaelementjs/view.php?id={$coursemodule->id}&redirect=1"; $info->extra = "onclick=\"window.location.href ='{$fullurl}';return false;\""; } } } return $info; }
/** * Print url info and link. * @param object $url * @param object $cm * @param object $course * @return does not return */ function mediaelementjs_print_workaround($url, $cm, $course) { global $OUTPUT; mediaelementjs_print_header($url, $cm, $course); mediaelementjs_print_heading($url, $cm, $course, true); mediaelementjs_print_intro($url, $cm, $course, true); $fullurl = mediaelementjs_get_full_url($url, $cm, $course); $display = mediaelementjs_get_final_display_type($url); if ($display == RESOURCELIB_DISPLAY_POPUP) { $options = empty($url->displayoptions) ? array() : unserialize($url->displayoptions); $width = empty($options['popupwidth']) ? 620 : $options['popupwidth']; $height = empty($options['popupheight']) ? 450 : $options['popupheight']; $wh = "width={$width},height={$height},toolbar=no,location=no,menubar=no,copyhistory=no,status=no,directories=no,scrollbars=yes,resizable=yes"; $extra = "onclick=\"window.open('{$fullurl}', '', '{$wh}'); return false;\""; } else { if ($display == RESOURCELIB_DISPLAY_NEW) { $extra = "onclick=\"this.target='_blank';\""; } else { $extra = ''; } } echo '<div class="urlworkaround">'; print_string('clicktoopen', 'mediaelementjs', "<a href=\"{$fullurl}\" {$extra}>{$fullurl}</a>"); echo '</div>'; echo $OUTPUT->footer(); die; }
$cm = get_coursemodule_from_instance('mediaelementjs', $url->id, $url->course, false, MUST_EXIST); } else { $cm = get_coursemodule_from_id('mediaelementjs', $id, 0, false, MUST_EXIST); $url = $DB->get_record('mediaelementjs', array('id' => $cm->instance), '*', MUST_EXIST); } $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); require_course_login($course, true, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('mod/mediaelementjs:view', $context); add_to_log($course->id, 'mediaelementjs', 'view', 'view.php?id=' . $cm->id, $url->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/mediaelementjs/view.php', array('id' => $cm->id)); if ($redirect) { // coming from course page or url index page, // the redirection is needed for completion tracking and logging $fullurl = mediaelementjs_get_full_url($url, $cm, $course); redirect(str_replace('&', '&', $fullurl)); } switch (mediaelementjs_get_final_display_type($url)) { case RESOURCELIB_DISPLAY_EMBED: mediaelementjs_display_embed($url, $cm, $course); break; case RESOURCELIB_DISPLAY_FRAME: mediaelementjs_display_frame($url, $cm, $course); break; default: mediaelementjs_print_workaround($url, $cm, $course); break; }