Skip to content

Commit

Permalink
MDL-22504 Course drag and drop upload - removed browser specific cont…
Browse files Browse the repository at this point in the history
…ent hacks, made 'text and link' dragging an experimental feature
  • Loading branch information
davosmith committed May 21, 2012
1 parent 5a4decb commit f684250
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 49 deletions.
4 changes: 4 additions & 0 deletions admin/settings/development.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 0 additions & 41 deletions course/dndupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions course/dndupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
16 changes: 12 additions & 4 deletions course/dnduploadlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit f684250

Please sign in to comment.