$cloneid = optional_param('clone', 0, PARAM_INT); if ($cloneid) { $pageparams['clone'] = $cloneid; } // Construct discussion variable (will check id is valid) // Retrieve new copy of discussion from database, but store it in cache // for further use. $discussion = mod_forumng_discussion::get_from_id($discussionid, $cloneid, 0, false, true); $forum = $discussion->get_forum(); $course = $forum->get_course(); $cm = $forum->get_course_module(); $context = $forum->get_context(); $draftid = optional_param('draft', 0, PARAM_INT); if ($draftid) { $pageparams['draft'] = $draftid; $draft = mod_forumng_draft::get_from_id($draftid); if (!$draft->is_reply() || $draft->get_discussion_id() != $discussionid) { print_error('draft_mismatch', 'forumng', $forum->get_url(mod_forumng::PARAM_HTML)); } $root = $discussion->get_root_post(); $inreplyto = $root->find_child($draft->get_parent_post_id(), false); if (!$inreplyto || !$inreplyto->can_reply($whynot) || !$discussion->can_view()) { if (!$whynot) { $whynot = 'reply_missing'; } print_error('draft_cannotreply', 'forumng', $forum->get_url(mod_forumng::PARAM_HTML), get_string($whynot, 'forumng')); } $inreplyto->force_expand(); } // Check that discussion can be viewed [Handles all other permissions] $discussion->require_view();
function mod_forumng_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { global $CFG, $USER; require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php'; // Check remaining slash arguments if (count($args) != 2) { send_file_not_found(); } list($itemid, $filename) = $args; if ($filearea == 'attachment' || $filearea == 'message') { // Get post object and check permissions $cloneid = optional_param('clone', 0, PARAM_INT); $post = mod_forumng_post::get_from_id($itemid, $cloneid); $post->require_view(); if ($cloneid) { // File is actually in other context $context = $post->get_forum()->get_context(true); } } else { if ($filearea == 'draft' || $filearea == 'draftmessage') { // Get draft object and check it's yours (note: I'm not sure whether it is possible to // ever access draft attachments in this manner, as while editing, this access is not // used; maybe from the X view, but I don't think it works there, however perhaps in // future). $draft = mod_forumng_draft::get_from_id($itemid); if ($draft->get_user_id() !== $USER->id) { send_file_not_found(); } } else { send_file_not_found(); } } // Get file object and send it $fs = get_file_storage(); $file = $fs->get_file($context->id, 'mod_forumng', $filearea, $itemid, '/', $filename); if (!$file || $file->is_directory()) { send_file_not_found(); } $lifetime = isset($CFG->filelifetime) ? $CFG->filelifetime : 86400; send_stored_file($file, $lifetime, 0); }