Пример #1
0
    flexpaper_print_tobemigrated($flexpaper, $cm, $course);
    die;
}

$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_flexpaper', 'content', 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!!
if (count($files) < 1) {
    flexpaper_print_filenotfound($flexpaper, $cm, $course);
    die;
} else {
    $file = reset($files);
    unset($files);
}

$flexpaper->mainfile = $file->get_filename();
$displaytype = flexpaper_get_final_display_type($flexpaper);
if ($displaytype == RESOURCELIB_DISPLAY_OPEN || $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD) {
    // For 'open' and 'download' 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 url index page
    // this redirect trick solves caching problems when tracking views ;-)
    $path = '/'.$context->id.'/mod_flexpaper/content/'.$flexpaper->revision.$file->get_filepath().$file->get_filename();
    $fullurl = moodle_url::make_file_url('/pluginfile.php', $path, $displaytype == RESOURCELIB_DISPLAY_DOWNLOAD);
    redirect($fullurl);
Пример #2
0
/**
 * 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 stdClass $coursemodule
 * @return cached_cm_info info
 */
function flexpaper_get_coursemodule_info($coursemodule) {
    global $CFG, $DB;
    require_once("$CFG->libdir/filelib.php");
    require_once("$CFG->dirroot/mod/flexpaper/locallib.php");
    require_once($CFG->libdir.'/completionlib.php');

    $context = context_module::instance($coursemodule->id);

    if (!$flexpaper = $DB->get_record('flexpaper', array('id'=>$coursemodule->instance),
            'id, name, display, displayoptions, tobemigrated, revision, intro, introformat')) {
        return NULL;
    }

    $info = new cached_cm_info();
    $info->name = $flexpaper->name;
    if ($coursemodule->showdescription) {
        // Convert intro to html. Do not filter cached version, filters run at display time.
        $info->content = format_module_intro('flexpaper', $flexpaper, $coursemodule->id, false);
    }

    if ($flexpaper->tobemigrated) {
        $info->icon ='i/invalid';
        return $info;
    }
    $fs = get_file_storage();
    $files = $fs->get_area_files($context->id, 'mod_flexpaper', 'content', 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!!
    if (count($files) >= 1) {
        $mainfile = reset($files);
        $info->icon = file_file_icon($mainfile, 24);
        $flexpaper->mainfile = $mainfile->get_filename();
    }

    $display = flexpaper_get_final_display_type($flexpaper);

    if ($display == RESOURCELIB_DISPLAY_POPUP) {
        $fullurl = "$CFG->wwwroot/mod/flexpaper/view.php?id=$coursemodule->id&amp;redirect=1";
        $options = empty($flexpaper->displayoptions) ? array() : unserialize($flexpaper->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/flexpaper/view.php?id=$coursemodule->id&amp;redirect=1";
        $info->onclick = "window.open('$fullurl'); return false;";

    }

    // If any optional extra details are turned on, store in custom data
    $info->customdata = flexpaper_get_optional_details($flexpaper, $coursemodule);

    return $info;
}
Пример #3
0
/**
 * Print flexpaper info and workaround link when JS not available.
 * @param object $flexpaper
 * @param object $cm
 * @param object $course
 * @param stored_file $file main file
 * @return does not return
 */
function flexpaper_print_workaround($flexpaper, $cm, $course, $file) {
    global $CFG, $OUTPUT;

    flexpaper_print_header($flexpaper, $cm, $course);
    flexpaper_print_heading($flexpaper, $cm, $course, true);
    flexpaper_print_intro($flexpaper, $cm, $course, true);

    $flexpaper->mainfile = $file->get_filename();
    echo '<div class="flexpaperworkaround">';
    switch (flexpaper_get_final_display_type($flexpaper)) {
        case RESOURCELIB_DISPLAY_POPUP:
            $path = '/'.$file->get_contextid().'/mod_flexpaper/content/'.$flexpaper->revision.$file->get_filepath().$file->get_filename();
            $fullurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
            $options = empty($flexpaper->displayoptions) ? array() : unserialize($flexpaper->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;\"";
            echo flexpaper_get_clicktoopen($file, $flexpaper->revision, $extra);
            break;

        case RESOURCELIB_DISPLAY_NEW:
            $extra = 'onclick="this.target=\'_blank\'"';
            echo flexpaper_get_clicktoopen($file, $flexpaper->revision, $extra);
            break;

        case RESOURCELIB_DISPLAY_DOWNLOAD:
            echo flexpaper_get_clicktodownload($file, $flexpaper->revision);
            break;

        case RESOURCELIB_DISPLAY_OPEN:
        default:
            echo flexpaper_get_clicktoopen($file, $flexpaper->revision);
            break;
    }
    echo '</div>';

    echo $OUTPUT->footer();
    die;
}