Пример #1
1
/**
 * Serves assignment feedback and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignfeedback_editpdf_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB, $CFG;
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_login($course, false, $cm);
        $itemid = (int) array_shift($args);
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        $record = $DB->get_record('assign_grades', array('id' => $itemid), 'userid,assignment', MUST_EXIST);
        $userid = $record->userid;
        if ($assign->id != $record->assignment) {
            return false;
        }
        // Check is users feedback or has grading permission.
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/assignfeedback_editpdf/{$filearea}/{$itemid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Download MUST be forced - security!
        send_stored_file($file, 0, 0, true);
        // Check if we want to retrieve the stamps.
    }
}
Пример #2
0
 public function streamFileContent()
 {
     if (!$this->fileref) {
         $this->fileref = $this->getFile();
     }
     \send_stored_file($this->fileref);
 }
Пример #3
0
/**
 * Serves the message attachments. Implements needed access control ;-)
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function block_jmail_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        //send_file_not_found();
    }
    require_course_login($course);
    $coursecontext = block_jmail_get_context(CONTEXT_COURSE, $course->id, MUST_EXIST);
    // The mailbox constructor does the permission validation
    if (!($mailbox = new block_jmail_mailbox($course, $coursecontext, $context))) {
        return;
    }
    $messageid = (int) array_shift($args);
    $message = block_jmail_message::get_from_id($messageid);
    // We check if we are the senders or the receivers
    if (!$message) {
        send_file_not_found();
    }
    $pendingaprobal = !$message->approved and has_capability('block/jmail:approvemessages', $context);
    if (!$message->is_mine() and !$pendingaprobal) {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/block_jmail/{$filearea}/{$messageid}/{$relativepath}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        send_file_not_found();
    }
    $forcedownload = true;
    send_stored_file($file, 60 * 60, 0, $forcedownload);
}
Пример #4
0
function workshopform_numerrors_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload) {
    global $DB;

    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }

    require_login($course, true, $cm);

    if ($filearea !== 'description') {
        return false;
    }

    $itemid = (int)array_shift($args); // the id of the assessment form dimension
    if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
        send_file_not_found();
    }

    if (!$dimension = $DB->get_record('workshopform_numerrors', array('id' => $itemid ,'workshopid' => $workshop->id))) {
        send_file_not_found();
    }

    // TODO now make sure the user is allowed to see the file
    // (media embedded into the dimension description)

    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/$context->id/workshopform_numerrors/$filearea/$itemid/$relativepath";
    if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
        return false;
    }

    // finally send the file
    send_stored_file($file);
}
Пример #5
0
/**
 * Serves assignment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignsubmission_onenote_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid, assignment, groupid', MUST_EXIST);
    $userid = $record->userid;
    $groupid = $record->groupid;
    require_once $CFG->dirroot . '/mod/assign/locallib.php';
    $assign = new assign($context, $cm, $course);
    if ($assign->get_instance()->id != $record->assignment) {
        return false;
    }
    if ($assign->get_instance()->teamsubmission && !$assign->can_view_group_submission($groupid)) {
        return false;
    }
    if (!$assign->get_instance()->teamsubmission && !$assign->can_view_submission($userid)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/assignsubmission_onenote/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
Пример #6
0
function local_filemanager_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB;
    if ($context->contextlevel != CONTEXT_SYSTEM) {
        return false;
    }
    require_login();
    if ($filearea != 'attachment') {
        return false;
    }
    $itemid = (int) array_shift($args);
    if ($itemid != 0) {
        return false;
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    if (empty($args)) {
        $filepath = '/';
    } else {
        $filepath = '/' . implode('/', $args) . '/';
    }
    $file = $fs->get_file($context->id, 'local_filemanager', $filearea, $itemid, $filepath, $filename);
    if (!$file) {
        return false;
    }
    // finally send the file
    send_stored_file($file, 0, 0, true, $options);
    // download MUST be forced - security!
}
Пример #7
0
/**
 * Serves the dataformview_tabular template files.
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - justsend the file
 */
function dataformview_tabular_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    if (!in_array($filearea, dataformview_tabular_tabular::get_file_areas())) {
        return false;
    }
    if ($context->contextlevel == CONTEXT_MODULE) {
        require_course_login($course, true, $cm);
        $viewid = (int) array_shift($args);
        $dataformid = $cm->instance;
        // Confirm user access.
        $params = array('dataformid' => $dataformid, 'viewid' => $viewid);
        if (!mod_dataform\access\view_access::validate($params)) {
            return false;
        }
        $relativepath = implode('/', $args);
        $fullpath = "/{$context->id}/dataformview_tabular/{$filearea}/{$viewid}/{$relativepath}";
        $fs = get_file_storage();
        if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
            return false;
        }
        // Finally send the file.
        send_stored_file($file, 0, 0, true);
        // Download MUST be forced - security!
    }
    return false;
}
Пример #8
0
function atto_ejsapp_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    // Make sure the user is logged in and has access to the module (plugins that are not course modules should leave out the 'cm' part).
    require_login($course, true, $cm);
    // Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).
    $itemid = array_shift($args);
    // The first item in the $args array.
    // Use the itemid to retrieve any relevant data records and perform any security checks to see if the
    // user really does have access to the file in question.
    // Extract the filename / filepath from the $args array.
    $filename = array_pop($args);
    // The last item in the $args array.
    if (!$args) {
        $filepath = '/';
        // $args is empty => the path is '/'
    } else {
        $filepath = '/' . implode('/', $args) . '/';
        // $args contains elements of the filepath
    }
    // Retrieve the file from the Files API.
    $fs = get_file_storage();
    $file = $fs->get_file($context->id, 'atto_ejsapp', $filearea, $itemid, $filepath, $filename);
    if (!$file) {
        return false;
        // The file does not exist.
    }
    // We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
    // From Moodle 2.3, use send_stored_file instead.
    send_stored_file($file, 86400, 0, $forcedownload, $options);
}
Пример #9
0
/**
 * Form for editing HTML block instances.
 *
 * @copyright 2010 Petr Skoda (http://skodak.org)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @package   block_html
 * @category  files
 * @param stdClass $course course object
 * @param stdClass $birecord_or_cm block instance record
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    require_course_login($course);
    if ($filearea !== 'content') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = get_context_instance_by_id($birecord_or_cm->parentcontextid)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    session_get_instance()->write_close();
    send_stored_file($file, 60 * 60, 0, $forcedownload, $options);
}
Пример #10
0
/**
 * Serves seplment feedback and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function seplfeedback_file_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('sepl_grades', array('id' => $itemid), 'userid,seplment', MUST_EXIST);
    $userid = $record->userid;
    if (!($sepl = $DB->get_record('sepl', array('id' => $cm->instance)))) {
        return false;
    }
    if ($sepl->id != $record->seplment) {
        return false;
    }
    // Check is users feedback or has grading permission.
    if ($USER->id != $userid and !has_capability('mod/sepl:grade', $context)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/seplfeedback_file/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
Пример #11
0
/**
 * Server teamwork files
 *
 * @category files
 * @param stdClass $course course object
 * @param stdClass $cm course module object
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function teamworkform_rubric_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options = array())
{
    global $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, true, $cm);
    if ($filearea !== 'description') {
        return false;
    }
    $itemid = (int) array_shift($args);
    // the id of the assessment form dimension
    if (!($teamwork = $DB->get_record('teamwork', array('id' => $cm->instance)))) {
        send_file_not_found();
    }
    if (!($dimension = $DB->get_record('teamworkform_rubric', array('id' => $itemid, 'teamworkid' => $teamwork->id)))) {
        send_file_not_found();
    }
    // TODO now make sure the user is allowed to see the file
    // (media embedded into the dimension description)
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/teamworkform_rubric/{$filearea}/{$itemid}/{$relativepath}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    // finally send the file
    send_stored_file($file, 0, 0, $forcedownload, $options);
}
Пример #12
0
/**
 * Testimonials block for Moodle
 *
 * @package   block_testimonials
 * @copyright 2015 Thomas Threadgold <*****@*****.**>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
function block_testimonials_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        return false;
    }
    if ($filearea !== 'photo') {
        return false;
    }
    $itemid = array_shift($args);
    // Extract the filename / filepath from the $args array.
    $filename = array_pop($args);
    // The last item in the $args array.
    if (!$args) {
        $filepath = '/';
        // $args is empty => the path is '/'
    } else {
        $filepath = '/' . implode('/', $args) . '/';
        // $args contains elements of the filepath
    }
    // Retrieve the file from the Files API.
    $fs = get_file_storage();
    $file = $fs->get_file($context->id, 'block_testimonials', $filearea, $itemid, $filepath, $filename);
    if (!$file) {
        return false;
        // The file does not exist.
    }
    send_stored_file($file, 86400, 0, $forcedownload, $options);
}
Пример #13
0
/**
 * Serves assignment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function assignsubmission_onlinepoodll_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $USER, $DB;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    //back image is a special case
    if (!($itemid == 0 && ($filearea = "onlinepoodll_backimage"))) {
        $record = $DB->get_record('assign_submission', array('id' => $itemid), 'userid, assignment', MUST_EXIST);
        $userid = $record->userid;
        if (!($assign = $DB->get_record('assign', array('id' => $cm->instance)))) {
            return false;
        }
        if ($assign->id != $record->assignment) {
            return false;
        }
        // check is users submission or has grading permission
        if ($USER->id != $userid and !has_capability('mod/assign:grade', $context)) {
            return false;
        }
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/assignsubmission_onlinepoodll/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    send_stored_file($file, 0, 0, true);
    // download MUST be forced - security!
}
Пример #14
0
/**
 * File serving.
 *
 * @param stdClass $course The course object.
 * @param stdClass $bi Block instance record.
 * @param context $context The context object.
 * @param string $filearea The file area.
 * @param array $args List of arguments.
 * @param bool $forcedownload Whether or not to force the download of the file.
 * @param array $options Array of options.
 * @return void|false
 */
function block_xp_pluginfile($course, $bi, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG;
    if ($CFG->block_xp_context == CONTEXT_SYSTEM && $context->contextlevel !== CONTEXT_SYSTEM) {
        return false;
    } else {
        if ($CFG->block_xp_context != CONTEXT_SYSTEM && $context->contextlevel !== CONTEXT_COURSE) {
            return false;
        }
    }
    $fs = get_file_storage();
    $file = null;
    if ($filearea == 'badges') {
        // For performance reason, and very low risk, we do not restrict the access to the level badges
        // to the participant of the course, nor do we check if they have the required level, etc...
        $itemid = array_shift($args);
        $filename = array_shift($args);
        $filepath = '/';
        $file = $fs->get_file($context->id, 'block_xp', $filearea, $itemid, $filepath, $filename . '.png');
        if (!$file) {
            $file = $fs->get_file($context->id, 'block_xp', $filearea, $itemid, $filepath, $filename . '.jpg');
        }
    }
    if (!$file) {
        return false;
    }
    send_stored_file($file);
}
Пример #15
0
/**
 * Serves the eexcess files.
 *
 * @param stdClass $course course object
 * @param stdClass $cm course module object
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @return bool false if file not found, does not return if found - just send the file
 */
function block_eexcess_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    $fullpath = "/{$context->id}/block_eexcess/{$filearea}/{$args[0]}/{$args[1]}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    send_stored_file($file);
}
/**
 * Form for editing Information Spot  block instances.
 *
 * @copyright 2014 Roberto Pinna
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @package   block_informationspot
 * @category  files
 * @param stdClass $course course object
 * @param stdClass $birecord_or_cm block instance record
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 */
function block_informationspot_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB, $CFG, $USER;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    // If block is in course context, then check if user has capability to access course.
    if ($context->get_course_context(false)) {
        require_course_login($course);
    } else {
        if ($CFG->forcelogin) {
            require_login();
        } else {
            // Get parent context and see if user have proper permission.
            $parentcontext = $context->get_parent_context();
            if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
                // Check if category is visible and user can view this category.
                $category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
                if (!$category->visible) {
                    require_capability('moodle/category:viewhiddencategories', $parentcontext);
                }
            } else {
                if ($parentcontext->contextlevel === CONTEXT_USER && $parentcontext->instanceid != $USER->id) {
                    // The block is in the context of a user, it is only visible to the user who it belongs to.
                    send_file_not_found();
                }
            }
            // At this point there is no way to check SYSTEM context, so ignoring it.
        }
    }
    if ($filearea != 'image') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $imageid = array_shift($args);
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_informationspot', $filearea, $imageid, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    // NOTE: it woudl be nice to have file revisions here, for now rely on standard file lifetime,
    //       do not lower it because the files are dispalyed very often.
    \core\session\manager::write_close();
    send_stored_file($file, null, 0, $forcedownload, $options);
}
Пример #17
0
function local_email_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $filename = $args[1];
    $itemid = $args[0];
    if (!($file = $fs->get_file($context->id, 'local_email', $filearea, $itemid, '/', $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    send_stored_file($file, 0, 0);
}
Пример #18
0
function question_preview_question_pluginfile_joomdle($course, $context, $component, $filearea, $qubaid, $slot, $filename, $forcedownload)
{
    global $USER, $DB, $CFG;
    $query = "SELECT *\n                FROM {$CFG->prefix}files\n                WHERE component = 'question'\n                AND filearea = ?\n                AND itemid = ?\n                AND filename = ?\n                ORDER by id\n                LIMIT 1";
    $params = array($filearea, $qubaid, $filename);
    $record = $DB->get_record_sql($query, $params);
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash($record->pathnamehash))) {
        send_file_not_found();
    }
    send_stored_file($file, 0, 0, $forcedownload);
}
Пример #19
0
/**
 * This is method serves up files to the user.  The files used in this course are just images,
 * but they are sent largely the same way.
 *
 */
function block_nurs_navigation_pluginfile($course, $birecord, $context, $filearea, $args, $forcedownload)
{
    require_once 'lib/filelib.php';
    $fs = get_file_storage();
    $entryid = clean_param(array_shift($args), PARAM_INT);
    $file = array_shift($args);
    if (!($file = $fs->get_file($context->id, 'block_nurs_navigation', $filearea, $entryid, '/', $file))) {
        send_file_not_found();
        return;
    }
    send_stored_file($file, 10 * 60, 0, true);
}
Пример #20
0
function block_nsreas_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    // Check the contextlevel is as expected - if your plugin is a block, this becomes CONTEXT_BLOCK, etc.
    $fs = get_file_storage();
    $fullpath = "/{$context->id}/block_nscoursefields/{$filearea}/{$args['0']}/{$args['1']}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        return false;
    }
    // finally send the file
    send_stored_file($file, 86400, 0, true, $options);
    // download MUST be forced - security!
}
Пример #21
0
/**
 * Serve question files when they are displayed in this export format.
 *
 * @param context $previewcontext the quiz context
 * @param int $questionid the question id.
 * @param context $filecontext the file (question) context
 * @param string $filecomponent the component the file belongs to.
 * @param string $filearea the file area.
 * @param array $args remaining file args.
 * @param bool $forcedownload.
 * @param array $options additional options affecting the file serving.
 */
function qformat_xhtml_question_preview_pluginfile($previewcontext, $questionid, $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = array())
{
    global $CFG;
    list($context, $course, $cm) = get_context_info_array($previewcontext->id);
    require_login($course, false, $cm);
    question_require_capability_on($questionid, 'view');
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/{$filecontext->id}/{$filecomponent}/{$filearea}/{$relativepath}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        send_file_not_found();
    }
    send_stored_file($file, 0, 0, $forcedownload, $options);
}
Пример #22
0
/**
 * Serves any files associated with the theme settings.
 *
 * @param stdClass $course
 * @param stdClass $cm
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @param array $options
 * @return bool
 */
function theme_bootstrap_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $filename = $args[1];
    $itemid = $args[0];
    if ($filearea == 'logo') {
        $itemid = 0;
    }
    if (!($file = $fs->get_file($context->id, 'theme_bootstrap', $filearea, $itemid, '/', $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    send_stored_file($file, 0, 0, $forcedownload);
}
Пример #23
0
function block_course_message_pluginfile($course, $birecord, $context, $filearea, $args, $forcedownload)
{
    require_once 'lib/filelib.php';
    $fs = get_file_storage();
    $context = context_course::instance($course->id);
    $entryid = clean_param(array_shift($args), PARAM_INT);
    $file = array_shift($args);
    if (!($file = $fs->get_file($context->id, 'block_course_message', $filearea, $entryid, '/', $file))) {
        send_file_not_found();
        return;
    }
    // Fourth parameter forces the user to download the file.
    send_stored_file($file, BLOCK_CM_LIFETIME, 0, $forcedownload);
}
Пример #24
0
/**
 * Files support.
 *
 * Exits if the required permissions are not satisfied.
 *
 * @param stdClass $course course object
 * @param stdClass $cm
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return void The file is sent along with it's headers
 */
function tool_generator_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    // Only for admins or CLI.
    if (!defined('CLI_SCRIPT') && !is_siteadmin()) {
        die;
    }
    if ($context->contextlevel != CONTEXT_SYSTEM) {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $file = $fs->get_file($context->id, 'tool_generator', $filearea, $args[0], '/', $args[1]);
    // Send the file, always forcing download, we don't want options.
    session_get_instance()->write_close();
    send_stored_file($file, 0, 0, true);
}
Пример #25
0
/**
 * Form for editing HTML block instances.
 *
 * @copyright 2010 Petr Skoda (http://skodak.org)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @package   block_html
 * @category  files
 * @param stdClass $course course object
 * @param stdClass $birecord_or_cm block instance record
 * @param stdClass $context context object
 * @param string $filearea file area
 * @param array $args extra arguments
 * @param bool $forcedownload whether or not force download
 * @param array $options additional options affecting the file serving
 * @return bool
 * @todo MDL-36050 improve capability check on stick blocks, so we can check user capability before sending images.
 */
function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_BLOCK) {
        send_file_not_found();
    }
    // If block is in course context, then check if user has capability to access course.
    if ($context->get_course_context(false)) {
        require_course_login($course);
    } else {
        if ($CFG->forcelogin) {
            require_login();
        } else {
            // Get parent context and see if user have proper permission.
            $parentcontext = $context->get_parent_context();
            if ($parentcontext->contextlevel === CONTEXT_COURSECAT) {
                // Check if category is visible and user can view this category.
                $category = $DB->get_record('course_categories', array('id' => $parentcontext->instanceid), '*', MUST_EXIST);
                if (!$category->visible) {
                    require_capability('moodle/category:viewhiddencategories', $parentcontext);
                }
            }
            // At this point there is no way to check SYSTEM or USER context, so ignoring it.
        }
    }
    if ($filearea !== 'content') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $filename = array_pop($args);
    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
    if (!($file = $fs->get_file($context->id, 'block_html', 'content', 0, $filepath, $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($parentcontext = get_context_instance_by_id($birecord_or_cm->parentcontextid)) {
        if ($parentcontext->contextlevel == CONTEXT_USER) {
            // force download on all personal pages including /my/
            //because we do not have reliable way to find out from where this is used
            $forcedownload = true;
        }
    } else {
        // weird, there should be parent context, better force dowload then
        $forcedownload = true;
    }
    session_get_instance()->write_close();
    send_stored_file($file, 60 * 60, 0, $forcedownload, $options);
}
Пример #26
0
/**
 * Serve questiontext files in the question text when they are displayed in this report.
 *
 * @package  quiz_statistics
 * @category files
 * @param context $previewcontext the quiz context
 * @param int $questionid the question id.
 * @param context $filecontext the file (question) context
 * @param string $filecomponent the component the file belongs to.
 * @param string $filearea the file area.
 * @param array $args remaining file args.
 * @param bool $forcedownload.
 * @param array $options additional options affecting the file serving.
 */
function quiz_statistics_question_preview_pluginfile($previewcontext, $questionid, $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = array())
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/quiz/locallib.php';
    list($context, $course, $cm) = get_context_info_array($previewcontext->id);
    require_login($course, false, $cm);
    // Assume only trusted people can see this report. There is no real way to
    // validate questionid, becuase of the complexity of random quetsions.
    require_capability('quiz/statistics:view', $context);
    $fs = get_file_storage();
    $relativepath = implode('/', $args);
    $fullpath = "/{$filecontext->id}/{$filecomponent}/{$filearea}/{$relativepath}";
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        send_file_not_found();
    }
    send_stored_file($file, 0, 0, $forcedownload, $options);
}
Пример #27
0
function block_course_profile_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $SCRIPT;
    if ($context->contextlevel != CONTEXT_COURSE) {
        send_file_not_found();
    }
    if ($filearea !== 'courseicon') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $file = $fs->get_file($context->id, 'block_course_profile', 'courseicon', 0, '/', $course->id);
    if (!$file or $file->is_directory()) {
        send_file_not_found();
    }
    session_get_instance()->write_close();
    send_stored_file($file, 60 * 60, 0, false, $options);
}
Пример #28
0
function block_navbuttons_pluginfile($course, $birecord_or_cm, $context, $filearea, $args, $forcedownload)
{
    if ($context->contextlevel != CONTEXT_COURSE) {
        send_file_not_found();
    }
    require_course_login($course);
    if ($filearea !== 'icons') {
        send_file_not_found();
    }
    $fs = get_file_storage();
    $filename = $args[1];
    $iconid = $args[0];
    if (!($file = $fs->get_file($context->id, 'block_navbuttons', 'icons', $iconid, '/', $filename)) or $file->is_directory()) {
        send_file_not_found();
    }
    send_stored_file($file, 60 * 60, 0, $forcedownload);
}
Пример #29
0
/**
 * Serves rolesexport xml files.
 *
 * @param object $course
 * @param object $cm
 * @param object $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function report_rolesmigration_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload)
{
    global $USER;
    //require_capability('mod/assignment:view', $this->context);
    $fullpath = "/{$context->id}/report_rolesmigration/{$filearea}/" . implode('/', $args);
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) or $file->is_directory()) {
        send_file_not_found();
    }
    if ($USER->id != $file->get_userid() && !has_capability('moodle/role:manage', $context)) {
        send_file_not_found();
    }
    session_get_instance()->write_close();
    // unlock session during fileserving
    if (!send_stored_file($file, 60 * 60, 0, true)) {
        send_file_not_found();
    }
}
Пример #30
0
function booking_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG, $DB;
    // Check the contextlevel is as expected - if your plugin is a block, this becomes CONTEXT_BLOCK, etc.
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    // Make sure the filearea is one of those used by the plugin.
    if ($filearea !== 'myfilemanager') {
        return false;
    }
    // Make sure the user is logged in and has access to the module (plugins that are not course modules should leave out the 'cm' part).
    require_login($course, true, $cm);
    // Leave this line out if you set the itemid to null in make_pluginfile_url (set $itemid to 0 instead).
    $itemid = array_shift($args);
    // The first item in the $args array.
    // Use the itemid to retrieve any relevant data records and perform any security checks to see if the
    // user really does have access to the file in question.
    // Extract the filename / filepath from the $args array.
    $filename = array_pop($args);
    // The last item in the $args array.
    if (!$args) {
        $filepath = '/';
        // $args is empty => the path is '/'
    } else {
        $filepath = '/' . implode('/', $args) . '/';
        // $args contains elements of the filepath
    }
    // Retrieve the file from the Files API.
    $fs = get_file_storage();
    $file = $fs->get_file($context->id, 'mod_booking', $filearea, $itemid, $filepath, $filename);
    if (!$file) {
        return false;
        // The file does not exist.
    }
    // We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
    // From Moodle 2.3, use send_stored_file instead.
    //send_file($file, 86400, 0, $forcedownload, $options);
    send_stored_file($file, 0, 0, true, $options);
}