Ejemplo n.º 1
0
/**
 * Export URL resource contents
 *
 * @return array of file content
 */
function morsle_export_contents($cm, $baseurl)
{
    global $CFG, $DB;
    require_once "{$CFG->dirroot}/mod/morsle/locallib.php";
    $contents = array();
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $url = $DB->get_record('url', array('id' => $cm->instance), '*', MUST_EXIST);
    $fullurl = str_replace('&', '&', morsle_get_full_url($url, $cm, $course));
    $isurl = clean_param($fullurl, PARAM_URL);
    if (empty($isurl)) {
        return null;
    }
    $url = array();
    $url['type'] = 'url';
    $url['filename'] = $url->name;
    $url['filepath'] = null;
    $url['filesize'] = 0;
    $url['fileurl'] = $fullurl;
    $url['timecreated'] = null;
    $url['timemodified'] = $url->timemodified;
    $url['sortorder'] = null;
    $url['userid'] = null;
    $url['author'] = null;
    $url['license'] = null;
    $contents[] = $url;
    return $contents;
}
Ejemplo n.º 2
0
    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:
        morsle_display_embed($morsle, $cm, $course);
        break;
    case RESOURCELIB_DISPLAY_FRAME:
        morsle_display_frame($morsle, $cm, $course);
        break;
    default:
        morsle_print_workaround($morsle, $cm, $course);
        break;
}
Ejemplo n.º 3
0
/**
 * 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;
}