diff --git a/lib/questionlib.php b/lib/questionlib.php index c61beac67ed..45dde0c5f3c 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1753,7 +1753,7 @@ function question_rewrite_questiontext_preview_urls($questiontext, $contextid, FROM {question} q JOIN {question_categories} qc ON qc.id = q.category WHERE q.id = :id', array('id' => $questionid), MUST_EXIST); - + return question_rewrite_question_preview_urls($questiontext, $questioncontextid, 'question', 'questiontext', $contextid, $component, $questionid, $options); } @@ -1971,13 +1971,17 @@ function question_pluginfile($course, $context, $component, $filearea, $args, $f * * @package core_files * @category files - * @param stdClass $context the context - * @param int $questionid the question id - * @param array $args remaining file args - * @param bool $forcedownload - * @param array $options additional options affecting the file serving + * @param context $previewcontext the context in which the preview is happening. + * @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 core_question_questiontext_preview_pluginfile($context, $questionid, $args, $forcedownload, array $options=array()) { +function core_question_question_preview_pluginfile($previewcontext, $questionid, + $filecontext, $filecomponent, $filearea, $args, $forcedownload, $options = array()) { global $DB; // Verify that contextid matches the question. @@ -1986,15 +1990,22 @@ function core_question_questiontext_preview_pluginfile($context, $questionid, $a FROM {question} q JOIN {question_categories} qc ON qc.id = q.category WHERE q.id = :id AND qc.contextid = :contextid', - array('id' => $questionid, 'contextid' => $context->id), MUST_EXIST); + array('id' => $questionid, 'contextid' => $filecontext->id), MUST_EXIST); // Check the capability. - list($context, $course, $cm) = get_context_info_array($context->id); + list($context, $course, $cm) = get_context_info_array($previewcontext->id); require_login($course, false, $cm); question_require_capability_on($question, 'use'); - question_send_questiontext_file($questionid, $args, $forcedownload, $options); + $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); } /** diff --git a/mod/quiz/report/statistics/lib.php b/mod/quiz/report/statistics/lib.php index 038d12a2bf0..081d2a8f267 100644 --- a/mod/quiz/report/statistics/lib.php +++ b/mod/quiz/report/statistics/lib.php @@ -29,26 +29,37 @@ defined('MOODLE_INTERNAL') || die(); /** * Serve questiontext files in the question text when they are displayed in this report. * - * @package mod_quiz + * @package quiz_statistics * @category files - * @param stdClass $context the context - * @param int $questionid the question id - * @param array $args remaining file args - * @param bool $forcedownload - * @param array $options additional options affecting the file serving + * @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_questiontext_preview_pluginfile($context, $questionid, $args, $forcedownload, array $options=array()) { +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($context->id); + 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); - question_send_questiontext_file($questionid, $args, $forcedownload, $options); + $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); } /** diff --git a/mod/quiz/report/statistics/report.php b/mod/quiz/report/statistics/report.php index 244d82d4e84..d781d85b0e5 100644 --- a/mod/quiz/report/statistics/report.php +++ b/mod/quiz/report/statistics/report.php @@ -326,8 +326,9 @@ class quiz_statistics_report extends quiz_default_report { protected function render_question_text($question) { global $OUTPUT; - $text = question_rewrite_questiontext_preview_urls($question->questiontext, - $this->context->id, 'quiz_statistics', $question->id); + $text = question_rewrite_question_preview_urls($question->questiontext, $question->id, + $question->contextid, 'question', 'questiontext', $question->id, + $this->context->id, 'quiz_statistics'); return $OUTPUT->box(format_text($text, $question->questiontextformat, array('noclean' => true, 'para' => false, 'overflowdiv' => true)), diff --git a/question/editlib.php b/question/editlib.php index 556dcc76763..b8d7b3e3a12 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -852,8 +852,9 @@ class question_bank_question_text_row extends question_bank_row_base { } protected function display_content($question, $rowclasses) { - $text = question_rewrite_questiontext_preview_urls($question->questiontext, - $question->contextid, 'question', $question->id); + $text = question_rewrite_question_preview_urls($question->questiontext, $question->id, + $question->contextid, 'question', 'questiontext', $question->id, + $question->contextid, 'core_question'); $text = format_text($text, $question->questiontextformat, $this->formatoptions); if ($text == '') {