/**
 * Export practice resource contents
 *
 * @return array of file content
 */
function practice_export_contents($cm, $basepractice)
{
    global $CFG, $DB;
    require_once "{$CFG->dirroot}/mod/practice/locallib.php";
    $contents = array();
    $context = context_module::instance($cm->id);
    $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    $practicerecord = $DB->get_record('practice', array('id' => $cm->instance), '*', MUST_EXIST);
    $fullpractice = str_replace('&', '&', practice_get_full_practice($practicerecord, $cm, $course));
    $ispractice = clean_param($fullpractice, PARAM_practice);
    if (empty($ispractice)) {
        return null;
    }
    $practice = array();
    $practice['type'] = 'practice';
    $practice['filename'] = clean_param(format_string($practicerecord->name), PARAM_FILE);
    $practice['filepath'] = null;
    $practice['filesize'] = 0;
    $practice['filepractice'] = $fullpractice;
    $practice['timecreated'] = null;
    $practice['timemodified'] = $practicerecord->timemodified;
    $practice['sortorder'] = null;
    $practice['userid'] = null;
    $practice['author'] = null;
    $practice['license'] = null;
    $contents[] = $practice;
    return $contents;
}
    notice(get_string('invalidstoredpractice', 'practice'), new moodle_practice('/course/practice.php', array('pid' => $practice->externalurl)));
    die;
}
unset($extpractice);
$displaytype = practice_get_final_display_type($practice);
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 practice index page,
    // the redirection is needed for completion tracking and logging
    $fullpractice = str_replace('&', '&', practice_get_full_practice($practice, $cm, $course));
    if (!course_get_format($course)->has_view_page()) {
        // If course format does not have a view page, add redirection delay with a link to the edit page.
        // Otherwise teacher is redirected to the external practice without any possibility to edit activity or course settings.
        $editpractice = null;
        if (has_capability('moodle/course:manageactivities', $context)) {
            $editpractice = new moodle_practice('/course/modedit.php', array('update' => $cm->id));
            $edittext = get_string('editthisactivity');
        } else {
            if (has_capability('moodle/course:update', $context->get_course_context())) {
                $editpractice = new moodle_practice('/course/edit.php', array('id' => $course->id));
                $edittext = get_string('editcoursesettings');
            }
        }
        if ($editpractice) {
            redirect($fullpractice, html_writer::link($editpractice, $edittext) . "<br/>" . get_string('pageshouldredirect'), 10);
/**
 * Display embedded practice file.
 * @param object $practice
 * @param object $cm
 * @param object $course
 * @return does not return
 */
function practice_display_embed($practice, $cm, $course)
{
    global $CFG, $PAGE, $OUTPUT;
    $mimetype = resourcelib_guess_practice_mimetype($practice->externalpractice);
    $fullpractice = practice_get_full_practice($practice, $cm, $course);
    $title = $practice->name;
    $link = html_writer::tag('a', $fullpractice, array('href' => str_replace('&amp;', '&', $fullpractice)));
    $clicktoopen = get_string('clicktoopen', 'practice', $link);
    $moodlepractice = new moodle_practice($fullpractice);
    $extension = resourcelib_get_extension($practice->externalpractice);
    $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($fullpractice, $title);
    } else {
        if ($mediarenderer->can_embed_practice($moodlepractice, $embedoptions)) {
            // Media (audio/video) file.
            $code = $mediarenderer->embed_practice($moodlepractice, $title, 0, 0, $embedoptions);
        } else {
            // anything else - just try object tag enlarged as much as possible
            $code = resourcelib_embed_general($fullpractice, $title, $clicktoopen, $mimetype);
        }
    }
    practice_print_header($practice, $cm, $course);
    practice_print_heading($practice, $cm, $course);
    echo $code;
    practice_print_intro($practice, $cm, $course);
    echo $OUTPUT->footer();
    die;
}