/** * 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 morsle_get_coursemodule_info($coursemodule) { global $CFG, $DB; require_once "{$CFG->dirroot}/mod/morsle/locallib.php"; if (!($url = $DB->get_record('morsle', array('id' => $coursemodule->instance), 'id, name, display, displayoptions, externalurl, parameters, intro, introformat'))) { return NULL; } $info = new cached_cm_info(); $info->name = $url->name; //note: there should be a way to differentiate links from normal resources $info->icon = morsle_guess_icon($url->externalurl); $display = morsle_get_final_display_type($url); if ($display == RESOURCELIB_DISPLAY_POPUP) { $fullurl = "{$CFG->wwwroot}/mod/morsle/view.php?id={$coursemodule->id}&redirect=1"; $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"; $info->onclick = "window.open('{$fullurl}', '', '{$wh}'); return false;"; } else { if ($display == RESOURCELIB_DISPLAY_NEW) { $fullurl = "{$CFG->wwwroot}/mod/morsle/view.php?id={$coursemodule->id}&redirect=1"; $info->onclick = "window.open('{$fullurl}'); return false;"; } } if ($coursemodule->showdescription) { // Convert intro to html. Do not filter cached version, filters run at display time. $info->content = format_module_intro('morsle', $url, $coursemodule->id, false); } return $info; }
// 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) { // coming from course page or morsle index page, // the redirection is needed for completion tracking and logging $fullurl = morsle_get_full_url($morsle, $cm, $course); redirect(str_replace('&', '&', $fullurl)); } switch ($displaytype) { case RESOURCELIB_DISPLAY_EMBED:
/** * Print url info and link. * @param object $url * @param object $cm * @param object $course * @return does not return */ function morsle_print_workaround($url, $cm, $course) { global $OUTPUT; morsle_print_header($url, $cm, $course); morsle_print_heading($url, $cm, $course, true); morsle_print_intro($url, $cm, $course, true); $fullurl = morsle_get_full_url($url, $cm, $course); $display = morsle_get_final_display_type($url); if ($display == RESOURCELIB_DISPLAY_POPUP) { $jsfullurl = addslashes_js($fullurl); $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('{$jsfullurl}', '', '{$wh}'); return false;\""; } else { if ($display == RESOURCELIB_DISPLAY_NEW) { $extra = "onclick=\"this.target='_blank';\""; } else { $extra = ''; } } echo '<div class="urlworkaround">'; print_string('clicktoopen', 'url', "<a href=\"{$fullurl}\" {$extra}>{$fullurl}</a>"); echo '</div>'; echo $OUTPUT->footer(); die; }