Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-22504 Course drag and drop upload - removed browser specific cont…

…ent hacks, made 'text and link' dragging an experimental feature
  • Loading branch information...
commit f684250bda8bfc36969d35c3e0a63b361fca47af 1 parent 5a4decb
@davosmith davosmith authored
View
4 admin/settings/development.php
@@ -13,6 +13,10 @@
$temp->add(new admin_setting_configcheckbox('enablesafebrowserintegration', new lang_string('enablesafebrowserintegration', 'admin'), new lang_string('configenablesafebrowserintegration', 'admin'), 0));
$temp->add(new admin_setting_configcheckbox('enablegroupmembersonly', new lang_string('enablegroupmembersonly', 'admin'), new lang_string('configenablegroupmembersonly', 'admin'), 0));
+ $dndopts = array(0 => new lang_string('dnduploadfiles', 'admin'),
+ 1 => new lang_string('dnduploadfilestextlink', 'admin'));
+ $temp->add(new admin_setting_configselect('dndallowtextandlinks', new lang_string('dndallowtextandlinks', 'admin'), new lang_string('configdndallowtextandlinks', 'admin'), 0, $dndopts));
+
$ADMIN->add('experimental', $temp);
// "debugging" settingpage
View
41 course/dndupload.js
@@ -903,34 +903,6 @@ M.course_dndupload = {
}
};
- if (type == 'text/html') {
- // If this was html content dragged from Chrome => Firefox, we will
- // need to fix the byte order of the content.
- if (this.Y.UA.gecko > 0) {
- if (contents.indexOf('<') == -1) {
- // There are no html tags in this content => it probably needs fixing.
- var codes = new Array();
- for (i=0; i<contents.length; i++) {
- var val = contents.charCodeAt(i);
- var val1 = Math.floor(val / 256);
- var val2 = val % 256;
- codes[i*2] = val2;
- codes[i*2+1] = val1;
- }
- var fixedcontents = '';
- for (i=0; i<codes.length; i++) {
- var val = codes[i];
- // Ideally we should deal with multi-byte characters here; I'm not sure how.
- fixedcontents += String.fromCharCode(val);
- }
- if (fixedcontents.indexOf('<') != -1) {
- // The fixed content contains html tags => it is probably correct.
- contents = fixedcontents;
- }
- }
- }
- }
-
// Prepare the data to send
var formData = new FormData();
formData.append('contents', contents);
@@ -941,19 +913,6 @@ M.course_dndupload = {
formData.append('type', type);
formData.append('module', module);
- if (type == 'text/html') {
- // This html content might have been dragged from Firefox to Chrome (in Linux).
- // Need to provide an extra fixed version of the contents, in case the original does not upload.
- if (this.Y.UA.webkit > 0 && this.Y.UA.os == 'linux') {
- var fixedcontents = '';
- for (i=0; i<contents.length; i+=2) {
- var val = contents.charCodeAt(i+1) * 256 + contents.charCodeAt(i);
- fixedcontents += String.fromCharCode(val);
- }
- formData.append('fixedcontents', fixedcontents);
- }
- }
-
// Send the data
xhr.open("POST", this.url, true);
xhr.send(formData);
View
4 course/dndupload.php
@@ -34,10 +34,6 @@
$modulename = required_param('module', PARAM_PLUGIN);
$displayname = optional_param('displayname', null, PARAM_TEXT);
$contents = optional_param('contents', null, PARAM_RAW); // It will be up to each plugin to clean this data, before saving it.
-if (!$contents) {
- // Check if there was a fixed version of contents provided (to cope with dragging from Firefox).
- $contents = optional_param('fixedcontents', null, PARAM_RAW);
-}
$dndproc = new dndupload_ajax_processor($courseid, $section, $type, $modulename);
$dndproc->process($displayname, $contents);
View
16 course/dnduploadlib.php
@@ -304,17 +304,21 @@ public function get_handled_file_types($module) {
* @return object Data to pass on to Javascript code
*/
public function get_js_data() {
+ global $CFG;
+
$ret = new stdClass;
// Sort the types by priority.
uasort($this->types, array($this, 'type_compare'));
$ret->types = array();
- foreach ($this->types as $type) {
- if (empty($type->handlers)) {
- continue; // Skip any types without registered handlers.
+ if ($CFG->dndallowtextandlinks) {
+ foreach ($this->types as $type) {
+ if (empty($type->handlers)) {
+ continue; // Skip any types without registered handlers.
+ }
+ $ret->types[] = $type;
}
- $ret->types[] = $type;
}
$ret->filehandlers = $this->filehandlers;
@@ -436,6 +440,10 @@ public function process($displayname = null, $content = null) {
if ($content != null) {
throw new moodle_exception('fileuploadwithcontent', 'moodle');
}
+ } else {
+ if (empty($content)) {
+ throw new moodle_exception('dnduploadwithoutcontent', 'moodle');
+ }
}
require_sesskey();
View
4 lang/en/admin.php
@@ -183,6 +183,7 @@
$string['configenabledevicedetection'] = 'Enables detection of mobiles, smartphones, tablets or default devices (desktop PCs, laptops, etc) for the application of themes and other features.';
$string['configdisableuserimages'] = 'Disable the ability for users to change user profile images.';
$string['configdisplayloginfailures'] = 'This will display information to selected users about previous failed logins.';
+$string['configdndallowtextandlinks'] = 'Enable or disable the dragging and dropping of text and links onto a course page, alongside the dragging and dropping of files. Note that the dragging of text into Firefox or between different browsers is unreliable and may result in no data being uploaded, or corrupted text being uploaded.';
$string['configdocroot'] = 'Defines the path to the Moodle Docs. You can change this if you wish to have your own custom online documentation. However, if you do that make sure that the paths in your documentation follow the same format as http://docs.moodle.org.';
$string['configdoctonewwindow'] = 'If you enable this, then links to Moodle Docs will be shown in a new window.';
$string['configeditordictionary'] = 'This value will be used if aspell doesn\'t have dictionary for users own language.';
@@ -431,6 +432,9 @@
$string['disableuserimages'] = 'Disable user profile images';
$string['displayerrorswarning'] = 'Enabling the PHP setting <em>display_errors</em> is not recommended on production sites because some error messages may reveal sensitive information about your server.';
$string['displayloginfailures'] = 'Display login failures to';
+$string['dndallowtextandlinks'] = 'Drag and drop upload allows';
+$string['dnduploadfiles'] = 'files only';
+$string['dnduploadfilestextlink'] = 'files, text and links';
$string['docroot'] = 'Moodle Docs document root';
$string['doctonewwindow'] = 'Open in new window';
$string['download'] = 'Download';
View
1  lang/en/moodle.php
@@ -466,6 +466,7 @@
$string['dndenabled_help'] = 'You can drag one or more files from your desktop and drop them onto the box below to upload them.<br />Note: this may not work with other web browsers';
$string['dndenabled_insentence'] = 'drag and drop available';
$string['dndenabled_inbox'] = 'drag and drop files here to upload them';
+$string['dnduploadwithoutcontent'] = 'This upload does not have any content';
$string['dndworkingfiletextlink'] = 'Drag and drop files, text or links onto course sections to upload them';
$string['dndworkingfilelink'] = 'Drag and drop files or links onto course sections to upload them';
$string['dndworkingfiletext'] = 'Drag and drop files or text onto course sections to upload them';
Please sign in to comment.
Something went wrong with that request. Please try again.