mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-33948 mod_forum correctly passes files options to file_save_draft_area_files()
This commit is contained in:
parent
3b6629c088
commit
61a339e598
3 changed files with 52 additions and 22 deletions
|
@ -27,6 +27,7 @@ defined('MOODLE_INTERNAL') || die();
|
|||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->libdir.'/eventslib.php');
|
||||
require_once($CFG->dirroot.'/user/selector/lib.php');
|
||||
require_once($CFG->dirroot.'/mod/forum/post_form.php');
|
||||
|
||||
/// CONSTANTS ///////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -99,7 +100,8 @@ function forum_add_instance($forum, $mform = null) {
|
|||
$discussion = $DB->get_record('forum_discussions', array('id'=>$discussion->id), '*', MUST_EXIST);
|
||||
$post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST);
|
||||
|
||||
$post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
|
||||
$post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id,
|
||||
mod_forum_post_form::attachment_options($forum), $post->message);
|
||||
$DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id));
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +198,8 @@ function forum_update_instance($forum, $mform) {
|
|||
$discussion = $DB->get_record('forum_discussions', array('id'=>$discussion->id), '*', MUST_EXIST);
|
||||
$post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST);
|
||||
|
||||
$post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
|
||||
$post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id,
|
||||
mod_forum_post_form::editor_options(), $post->message);
|
||||
}
|
||||
|
||||
$post->subject = $forum->name;
|
||||
|
@ -4230,7 +4233,8 @@ function forum_add_attachment($post, $forum, $cm, $mform=null, &$message=null) {
|
|||
|
||||
$info = file_get_draft_area_info($post->attachments);
|
||||
$present = ($info['filecount']>0) ? '1' : '';
|
||||
file_save_draft_area_files($post->attachments, $context->id, 'mod_forum', 'attachment', $post->id);
|
||||
file_save_draft_area_files($post->attachments, $context->id, 'mod_forum', 'attachment', $post->id,
|
||||
mod_forum_post_form::attachment_options($forum));
|
||||
|
||||
$DB->set_field('forum_posts', 'attachment', $present, array('id'=>$post->id));
|
||||
|
||||
|
@ -4262,7 +4266,8 @@ function forum_add_new_post($post, $mform, &$message) {
|
|||
$post->attachment = "";
|
||||
|
||||
$post->id = $DB->insert_record("forum_posts", $post);
|
||||
$post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
|
||||
$post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id,
|
||||
mod_forum_post_form::editor_options(), $post->message);
|
||||
$DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id));
|
||||
forum_add_attachment($post, $forum, $cm, $mform, $message);
|
||||
|
||||
|
@ -4308,7 +4313,8 @@ function forum_update_post($post, $mform, &$message) {
|
|||
$discussion->timestart = $post->timestart;
|
||||
$discussion->timeend = $post->timeend;
|
||||
}
|
||||
$post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
|
||||
$post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id,
|
||||
mod_forum_post_form::editor_options(), $post->message);
|
||||
$DB->set_field('forum_posts', 'message', $post->message, array('id'=>$post->id));
|
||||
|
||||
$DB->update_record('forum_discussions', $discussion);
|
||||
|
@ -4371,7 +4377,8 @@ function forum_add_discussion($discussion, $mform=null, &$message=null, $userid=
|
|||
// TODO: Fix the calling code so that there always is a $cm when this function is called
|
||||
if (!empty($cm->id) && !empty($discussion->itemid)) { // In "single simple discussions" this may not exist yet
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$text = file_save_draft_area_files($discussion->itemid, $context->id, 'mod_forum', 'post', $post->id, array('subdirs'=>true), $post->message);
|
||||
$text = file_save_draft_area_files($discussion->itemid, $context->id, 'mod_forum', 'post', $post->id,
|
||||
mod_forum_post_form::editor_options(), $post->message);
|
||||
$DB->set_field('forum_posts', 'message', $text, array('id'=>$post->id));
|
||||
}
|
||||
|
||||
|
|
|
@ -510,7 +510,7 @@ require_once('post_form.php');
|
|||
$mform_post = new mod_forum_post_form('post.php', array('course'=>$course, 'cm'=>$cm, 'coursecontext'=>$coursecontext, 'modcontext'=>$modcontext, 'forum'=>$forum, 'post'=>$post));
|
||||
|
||||
$draftitemid = file_get_submitted_draft_itemid('attachments');
|
||||
file_prepare_draft_area($draftitemid, $modcontext->id, 'mod_forum', 'attachment', empty($post->id)?null:$post->id);
|
||||
file_prepare_draft_area($draftitemid, $modcontext->id, 'mod_forum', 'attachment', empty($post->id)?null:$post->id, mod_forum_post_form::attachment_options($forum));
|
||||
|
||||
//load data into form NOW!
|
||||
|
||||
|
@ -550,7 +550,7 @@ if (forum_is_subscribed($USER->id, $forum->id)) {
|
|||
}
|
||||
|
||||
$draftid_editor = file_get_submitted_draft_itemid('message');
|
||||
$currenttext = file_prepare_draft_area($draftid_editor, $modcontext->id, 'mod_forum', 'post', empty($post->id) ? null : $post->id, array('subdirs'=>true), $post->message);
|
||||
$currenttext = file_prepare_draft_area($draftid_editor, $modcontext->id, 'mod_forum', 'post', empty($post->id) ? null : $post->id, mod_forum_post_form::editor_options(), $post->message);
|
||||
$mform_post->set_data(array( 'attachments'=>$draftitemid,
|
||||
'general'=>$heading,
|
||||
'subject'=>$post->subject,
|
||||
|
|
|
@ -29,6 +29,41 @@ require_once($CFG->libdir.'/formslib.php');
|
|||
|
||||
class mod_forum_post_form extends moodleform {
|
||||
|
||||
/**
|
||||
* Returns the options array to use in filemanager for forum attachments
|
||||
*
|
||||
* @param stdClass $forum
|
||||
* @return array
|
||||
*/
|
||||
public static function attachment_options($forum) {
|
||||
global $COURSE, $PAGE, $CFG;
|
||||
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes, $forum->maxbytes);
|
||||
return array(
|
||||
'subdirs' => 0,
|
||||
'maxbytes' => $maxbytes,
|
||||
'maxfiles' => $forum->maxattachments,
|
||||
'accepted_types' => '*',
|
||||
'return_types' => FILE_INTERNAL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options array to use in forum text editor
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function editor_options() {
|
||||
global $COURSE, $PAGE, $CFG;
|
||||
// TODO: add max files and max size support
|
||||
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
|
||||
return array(
|
||||
'maxfiles' => EDITOR_UNLIMITED_FILES,
|
||||
'maxbytes' => $maxbytes,
|
||||
'trusttext'=> true,
|
||||
'return_types'=> FILE_INTERNAL | FILE_EXTERNAL
|
||||
);
|
||||
}
|
||||
|
||||
function definition() {
|
||||
|
||||
global $CFG;
|
||||
|
@ -40,13 +75,6 @@ class mod_forum_post_form extends moodleform {
|
|||
$modcontext = $this->_customdata['modcontext'];
|
||||
$forum = $this->_customdata['forum'];
|
||||
$post = $this->_customdata['post'];
|
||||
// if $forum->maxbytes == '0' means we should use $course->maxbytes
|
||||
if ($forum->maxbytes == '0') {
|
||||
$forum->maxbytes = $course->maxbytes;
|
||||
}
|
||||
// TODO: add max files and max size support
|
||||
$editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext'=>true,
|
||||
'context'=>$modcontext, 'return_types'=>FILE_INTERNAL | FILE_EXTERNAL);
|
||||
|
||||
$mform->addElement('header', 'general', '');//fill in the data depending on page params later using set_data
|
||||
$mform->addElement('text', 'subject', get_string('subject', 'forum'), 'size="48"');
|
||||
|
@ -54,7 +82,7 @@ class mod_forum_post_form extends moodleform {
|
|||
$mform->addRule('subject', get_string('required'), 'required', null, 'client');
|
||||
$mform->addRule('subject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
|
||||
|
||||
$mform->addElement('editor', 'message', get_string('message', 'forum'), null, $editoroptions);
|
||||
$mform->addElement('editor', 'message', get_string('message', 'forum'), null, self::editor_options());
|
||||
$mform->setType('message', PARAM_RAW);
|
||||
$mform->addRule('message', get_string('required'), 'required', null, 'client');
|
||||
|
||||
|
@ -82,12 +110,7 @@ class mod_forum_post_form extends moodleform {
|
|||
}
|
||||
|
||||
if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext)) { // 1 = No attachments at all
|
||||
$mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null,
|
||||
array('subdirs'=>0,
|
||||
'maxbytes'=>$forum->maxbytes,
|
||||
'maxfiles'=>$forum->maxattachments,
|
||||
'accepted_types'=>'*',
|
||||
'return_types'=>FILE_INTERNAL));
|
||||
$mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null, self::attachment_options($forum));
|
||||
$mform->addHelpButton('attachments', 'attachment', 'forum');
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue