Drag and Drop Multiple File Upload – Contact Form 7 - Version 1.3.3.3.1

Version Description

= 1.2.3 = This version fixed minor issues/bugs and add multiple drag and drop fields in a form.

= 1.2.1 = This version fixed minor issues and bugs.

= 1.2.2 = Added some usefull features.

= 1.2.4 = Added new features and fixes.

Download this release

Release Info

Developer glenwpcoder
Plugin Icon 128x128 Drag and Drop Multiple File Upload – Contact Form 7
Version 1.3.3.3.1
Comparing to
See all releases

Code changes from version 1.3.3.2 to 1.3.3.3.1

assets/css/dnd-upload-cf7.css CHANGED
@@ -161,6 +161,19 @@
161
  font-style:italic;
162
  }
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  @media screen and (max-width: 767px) {
165
  .dnd-upload-status .dnd-upload-details .name em { font-weight:normal; }
166
  .dnd-upload-status .dnd-upload-details .name { padding-right:60px; }
161
  font-style:italic;
162
  }
163
 
164
+ /* Jquery Validation For Contact Form 7 */
165
+ .wpcf7-form label.error-new {
166
+ color: #900;
167
+ font-size: 11px;
168
+ float: none;
169
+ padding-left: 5px;
170
+ }
171
+ .wpcf7-form .codedropz-upload-wrapper.invalid .codedropz-upload-handler{
172
+ border-bottom-color: #900;
173
+ border-bottom-style: solid;
174
+ }
175
+ /* END : Jquery Validation CF7 */
176
+
177
  @media screen and (max-width: 767px) {
178
  .dnd-upload-status .dnd-upload-details .name em { font-weight:normal; }
179
  .dnd-upload-status .dnd-upload-details .name { padding-right:60px; }
assets/js/codedropz-uploader-min.js CHANGED
@@ -1,5 +1,5 @@
1
  /**
2
- * CodeDropz Uploader v1.3.3
3
  * Copyright 2018 Glen Mongaya
4
  * CodeDrop Drag&Drop Uploader
5
  * @version 1.0
@@ -8,4 +8,4 @@
8
  */
9
 
10
  // CodeDropz Drag and Drop Plugin
11
- !function(e){e.fn.CodeDropz_Uploader=function(a){this.each(function(){var d=e(this),r=e.extend({handler:d,color:"#000",background:"",server_max_error:"Uploaded file exceeds the maximum upload size of your server.",max_file:d.data("max")?d.data("max"):10,max_upload_size:d.data("limit")?d.data("limit"):"5242880",supported_type:d.data("type")?d.data("type"):"jpg|jpeg|JPG|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv|xls",text:"Drag & Drop Files Here",separator:"or",button_text:"Browse Files",on_success:""},a),o=d.data("name")+"_count_files";localStorage.setItem(o,1);var s='<div class="codedropz-upload-handler"><div class="codedropz-upload-container"><div class="codedropz-upload-inner"><h3>'+r.text+"</h3><span>"+r.separator+'</span><div class="codedropz-btn-wrap"><a class="cd-upload-btn" href="javascript:void(0)">'+r.button_text+"</a></div></div></div></div>";r.handler.wrapAll('<div class="codedropz-upload-wrapper"></div>');var t=r.handler.parents("form"),n=r.handler.parents(".codedropz-upload-wrapper"),p=e('input[type="submit"]',t);r.handler.after(s),e(".codedropz-upload-handler",n).on("drag dragstart dragend dragover dragenter dragleave drop",function(e){e.preventDefault(),e.stopPropagation()}),e(".codedropz-upload-handler",n).on("dragover dragenter",function(a){e(this).addClass("codedropz-dragover")}),e(".codedropz-upload-handler",n).on("dragleave dragend drop",function(a){e(this).removeClass("codedropz-dragover")}),e("a.cd-upload-btn",n).on("click",function(e){e.preventDefault(),r.handler.val(null),r.handler.click()}),e(".codedropz-upload-handler",n).on("drop",function(e){l(e.originalEvent.dataTransfer.files,"drop")}),r.handler.on("change",function(e){l(this.files,"click")});var l=function(a,s){if(!(!a.length>1)){var p=new FormData;p.append("supported_type",r.supported_type),p.append("size_limit",r.max_upload_size),p.append("action","dnd_codedropz_upload"),p.append("type",s),p.append("security",dnd_cf7_uploader.ajax_nonce),e("span.has-error",r.handler).remove(),e.each(a,function(a,s){if(void 0!==p.delete&&p.delete("upload-file"),localStorage.getItem(o)>r.max_file)return!e("span.has-error-msg",n).length>0&&(err_msg=dnd_cf7_uploader.drag_n_drop_upload.max_file_limit,n.append('<span class="has-error-msg">'+err_msg.replace("%count%",r.max_file)+"</span>")),!1;var l=i.createProgressBar(s),c=!1;if(s.size>r.max_upload_size&&(e(".dnd-upload-details",e("#"+l)).append('<span class="has-error">'+dnd_cf7_uploader.drag_n_drop_upload.large_file+"</span>"),c=!0),regex_type=new RegExp("(.*?).("+r.supported_type+")$"),!1!==c||regex_type.test(s.name.toLowerCase())||(e(".dnd-upload-details",e("#"+l)).append('<span class="has-error">'+dnd_cf7_uploader.drag_n_drop_upload.inavalid_type+"</span>"),c=!0),localStorage.setItem(o,Number(localStorage.getItem(o))+1),!1===c){p.append("upload-file",s);e.ajax({url:r.ajax_url,type:t.attr("method"),data:p,dataType:"json",cache:!1,contentType:!1,processData:!1,xhr:function(){var e=new window.XMLHttpRequest;return e.upload.addEventListener("progress",function(e){if(e.lengthComputable){var a=e.loaded/e.total,d=parseInt(100*a);i.setProgressBar(l,d)}},!1),e},complete:function(){i.setProgressBar(l,100)},success:function(a){a.success?e.isFunction(r.on_success)&&r.on_success.call(this,d,l,a):(e(".dnd-progress-bar",e("#"+l)).remove(),e(".dnd-upload-details",e("#"+l)).append('<span class="has-error">'+a.data+"</span>"),e('input[type="submit"]',t).removeClass("disabled").prop("disabled",!1))},error:function(a,d,o){e(".dnd-progress-bar",e("#"+l)).remove(),e(".dnd-upload-details",e("#"+l)).append('<span class="has-error">'+r.server_max_error+"</span>"),e('input[type="submit"]',t).removeClass("disabled").prop("disabled",!1)}})}})}},i={createProgressBar:function(a){var d=e(".codedropz-upload-handler",n),r="dnd-file-"+Math.random().toString(36).substr(2,9),s='<div class="dnd-upload-image"><span class="dnd-icon-blank-file"></span></div><div class="dnd-upload-details"><span class="name"><span>'+a.name+"</span><em>("+i.bytesToSize(a.size)+')</em></span><a href="javascript:void(0)" title="Remove" class="remove-file" data-storage="'+o+'"><span class="dnd-icon-remove"></span></a><span class="dnd-progress-bar"><span></span></span></div>';return d.after('<div id="'+r+'" class="dnd-upload-status">'+s+"</div>"),r},setProgressBar:function(a,d){var r=e(".dnd-progress-bar",e("#"+a));return r.length>0&&(i.disableBtn(p),progress_width=d*r.width()/100,e("span",r).addClass("in-progress").animate({width:progress_width},10).text(d+"% "),100==d&&e("span",r).addClass("complete").removeClass("in-progress")),!1},bytesToSize:function(e){return 0===e?"0":(kBytes=e/1024,fileSize=kBytes>=1024?(kBytes/1024).toFixed(2)+"MB":kBytes.toFixed(2)+"KB",fileSize)},disableBtn:function(e){e.length>0&&e.addClass("disable").prop("disabled",!0)}}}),e(document).on("click",".dnd-icon-remove",function(d){var r=e(this),o=r.parents(".dnd-upload-status"),s=r.parents(".codedropz-upload-wrapper"),t=r.parent("a").attr("data-storage");return!(e("span.in-progress",o).length>0)&&(e(".has-error",o).length>0?(o.remove(),localStorage.setItem(t,Number(localStorage.getItem(t))-1),!1):(r.addClass("deleting").text("deleting..."),void e.post(a.ajax_url,{path:o.find('input[type="hidden"]').val(),action:"dnd_codedropz_upload_delete",security:dnd_cf7_uploader.ajax_nonce},function(a){a.success&&(o.remove(),localStorage.setItem(t,Number(localStorage.getItem(t))-1),e(".dnd-upload-status",s).length<=1&&e("span.has-error-msg",s).remove())})))})}}(jQuery);
1
  /**
2
+ * CodeDropz Uploader v1.3.3.3
3
  * Copyright 2018 Glen Mongaya
4
  * CodeDrop Drag&Drop Uploader
5
  * @version 1.0
8
  */
9
 
10
  // CodeDropz Drag and Drop Plugin
11
+ !function(e){e.fn.CodeDropz_Uploader=function(a){this.each(function(){var d=e(this),r=e.extend({handler:d,color:"#000",background:"",server_max_error:"Uploaded file exceeds the maximum upload size of your server.",max_file:d.data("max")?d.data("max"):10,max_upload_size:d.data("limit")?d.data("limit"):"5242880",supported_type:d.data("type")?d.data("type"):"jpg|jpeg|JPG|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv|xls",text:"Drag & Drop Files Here",separator:"or",button_text:"Browse Files",on_success:""},a),o=d.data("name")+"_count_files";localStorage.setItem(o,1);var t='<div class="codedropz-upload-handler"><div class="codedropz-upload-container"><div class="codedropz-upload-inner"><h3>'+r.text+"</h3><span>"+r.separator+'</span><div class="codedropz-btn-wrap"><a class="cd-upload-btn" href="javascript:void(0)">'+r.button_text+"</a></div></div></div></div>";r.handler.wrapAll('<div class="codedropz-upload-wrapper"></div>'),r.supported_type=r.supported_type.replace(/[^a-zA-Z0-9| ]/g,"");var s=r.handler.parents("form"),n=r.handler.parents(".codedropz-upload-wrapper"),p=e('input[type="submit"]',s);r.handler.after(t),e(".codedropz-upload-handler",n).on("drag dragstart dragend dragover dragenter dragleave drop",function(e){e.preventDefault(),e.stopPropagation()}),e(".codedropz-upload-handler",n).on("dragover dragenter",function(a){e(this).addClass("codedropz-dragover")}),e(".codedropz-upload-handler",n).on("dragleave dragend drop",function(a){e(this).removeClass("codedropz-dragover")}),e("a.cd-upload-btn",n).on("click",function(e){e.preventDefault(),r.handler.val(null),r.handler.click()}),e(".codedropz-upload-handler",n).on("drop",function(e){l(e.originalEvent.dataTransfer.files,"drop")}),r.handler.on("change",function(e){l(this.files,"click")});var l=function(a,t){if(!(!a.length>1)){var p=new FormData;p.append("supported_type",r.supported_type),p.append("size_limit",r.max_upload_size),p.append("action","dnd_codedropz_upload"),p.append("type",t),p.append("security",dnd_cf7_uploader.ajax_nonce),e("span.has-error",r.handler).remove(),e.each(a,function(a,t){if(void 0!==p.delete&&p.delete("upload-file"),localStorage.getItem(o)>r.max_file)return!e("span.has-error-msg",n).length>0&&(err_msg=dnd_cf7_uploader.drag_n_drop_upload.max_file_limit,n.append('<span class="has-error-msg">'+err_msg.replace("%count%",r.max_file)+"</span>")),!1;var l=i.createProgressBar(t),c=!1;if(t.size>r.max_upload_size&&(e(".dnd-upload-details",e("#"+l)).append('<span class="has-error">'+dnd_cf7_uploader.drag_n_drop_upload.large_file+"</span>"),c=!0),regex_type=new RegExp("(.*?).("+r.supported_type+")$"),!1!==c||regex_type.test(t.name.toLowerCase())||(e(".dnd-upload-details",e("#"+l)).append('<span class="has-error">'+dnd_cf7_uploader.drag_n_drop_upload.inavalid_type+"</span>"),c=!0),localStorage.setItem(o,Number(localStorage.getItem(o))+1),!1===c){p.append("upload-file",t);e.ajax({url:r.ajax_url,type:s.attr("method"),data:p,dataType:"json",cache:!1,contentType:!1,processData:!1,xhr:function(){var e=new window.XMLHttpRequest;return e.upload.addEventListener("progress",function(e){if(e.lengthComputable){var a=e.loaded/e.total,d=parseInt(100*a);i.setProgressBar(l,d)}},!1),e},complete:function(){i.setProgressBar(l,100)},success:function(a){a.success?e.isFunction(r.on_success)&&r.on_success.call(this,d,l,a):(e(".dnd-progress-bar",e("#"+l)).remove(),e(".dnd-upload-details",e("#"+l)).append('<span class="has-error">'+a.data+"</span>"),e('input[type="submit"]',s).removeClass("disabled").prop("disabled",!1))},error:function(a,d,o){e(".dnd-progress-bar",e("#"+l)).remove(),e(".dnd-upload-details",e("#"+l)).append('<span class="has-error">'+r.server_max_error+"</span>"),e('input[type="submit"]',s).removeClass("disabled").prop("disabled",!1)}})}})}},i={createProgressBar:function(a){var d=e(".codedropz-upload-handler",n),r="dnd-file-"+Math.random().toString(36).substr(2,9),t='<div class="dnd-upload-image"><span class="dnd-icon-blank-file"></span></div><div class="dnd-upload-details"><span class="name"><span>'+a.name+"</span><em>("+i.bytesToSize(a.size)+')</em></span><a href="javascript:void(0)" title="'+dnd_cf7_uploader.drag_n_drop_upload.delete.title+'" class="remove-file" data-storage="'+o+'"><span class="dnd-icon-remove"></span></a><span class="dnd-progress-bar"><span></span></span></div>';return d.after('<div id="'+r+'" class="dnd-upload-status">'+t+"</div>"),r},setProgressBar:function(a,d){var r=e(".dnd-progress-bar",e("#"+a));return r.length>0&&(i.disableBtn(p),progress_width=d*r.width()/100,e("span",r).addClass("in-progress").animate({width:progress_width},10).text(d+"% "),100==d&&e("span",r).addClass("complete").removeClass("in-progress")),!1},bytesToSize:function(e){return 0===e?"0":(kBytes=e/1024,fileSize=kBytes>=1024?(kBytes/1024).toFixed(2)+"MB":kBytes.toFixed(2)+"KB",fileSize)},disableBtn:function(e){e.length>0&&e.addClass("disable").prop("disabled",!0)}}}),e(document).on("click",".dnd-icon-remove",function(d){var r=e(this),o=r.parents(".dnd-upload-status"),t=r.parents(".codedropz-upload-wrapper"),s=r.parent("a").attr("data-storage");return!(e("span.in-progress",o).length>0)&&(e(".has-error",o).length>0?(o.remove(),localStorage.setItem(s,Number(localStorage.getItem(s))-1),!1):(r.addClass("deleting").text(dnd_cf7_uploader.drag_n_drop_upload.delete.text+"..."),void e.post(a.ajax_url,{path:o.find('input[type="hidden"]').val(),action:"dnd_codedropz_upload_delete",security:dnd_cf7_uploader.ajax_nonce},function(a){a.success&&(o.remove(),localStorage.setItem(s,Number(localStorage.getItem(s))-1),e(".dnd-upload-status",t).length<=1&&e("span.has-error-msg",t).remove())})))})}}(jQuery);
assets/js/codedropz-uploader.js DELETED
@@ -1,322 +0,0 @@
1
- /**
2
- * CodeDropz Uploader v1.3.3
3
- * Copyright 2018 Glen Mongaya
4
- * CodeDrop Drag&Drop Uploader
5
- * @version 1.0
6
- * @author CodeDropz, Glen Don L. Mongaya
7
- * @license The MIT License (MIT)
8
- */
9
-
10
- // CodeDropz Drag and Drop Plugin
11
- (function($){
12
- $.fn.CodeDropz_Uploader = function( settings ){
13
-
14
- // Support multiple elements
15
- this.each( function() {
16
-
17
- // Parent input file type
18
- var input = $(this);
19
-
20
- // Extends options
21
- var options = $.extend({
22
- handler : input,
23
- color : "#000",
24
- background : '',
25
- server_max_error : 'Uploaded file exceeds the maximum upload size of your server.',
26
- max_file : input.data('max') ? input.data('max') : 10, // default 10
27
- max_upload_size : input.data('limit') ? input.data('limit') : '5242880', // should be a bytes it's (5MB)
28
- supported_type : input.data('type') ? input.data('type') : 'jpg|jpeg|JPG|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv|xls',
29
- text : 'Drag & Drop Files Here',
30
- separator : 'or',
31
- button_text : 'Browse Files',
32
- on_success : ''
33
- }, settings);
34
-
35
- // Get storage name
36
- var dataStorageName = input.data('name') + '_count_files';
37
-
38
- // File Counter
39
- localStorage.setItem( dataStorageName, 1);
40
-
41
- // Template Container
42
- var cdropz_template = '<div class="codedropz-upload-handler">'
43
- + '<div class="codedropz-upload-container">'
44
- + '<div class="codedropz-upload-inner">'
45
- + '<h3>'+ options.text +'</h3>'
46
- + '<span>'+ options.separator +'</span>'
47
- +'<div class="codedropz-btn-wrap"><a class="cd-upload-btn" href="javascript:void(0)">'+ options.button_text +'</a></div>'
48
- +'</div>'
49
- + '</div>'
50
- + '</div>';
51
-
52
- // Wrap input fields
53
- options.handler.wrapAll('<div class="codedropz-upload-wrapper"></div>');
54
-
55
- // Element Handler
56
- var form_handler = options.handler.parents('form'),
57
- options_handler = options.handler.parents('.codedropz-upload-wrapper'),
58
- btnOBJ = $('input[type="submit"]', form_handler );
59
-
60
- // Append Format
61
- options.handler.after( cdropz_template);
62
-
63
- // preventing the unwanted behaviours
64
- $('.codedropz-upload-handler', options_handler ).on( 'drag dragstart dragend dragover dragenter dragleave drop', function( e ){
65
- e.preventDefault();
66
- e.stopPropagation();
67
- })
68
-
69
- // dragover and dragenter - add class
70
- $('.codedropz-upload-handler', options_handler ).on( 'dragover dragenter', function( e ){
71
- $(this).addClass('codedropz-dragover');
72
- });
73
-
74
- // dragleave dragend drop - remove class
75
- $('.codedropz-upload-handler', options_handler ).on( 'dragleave dragend drop', function( e ){
76
- $(this).removeClass('codedropz-dragover');
77
- });
78
-
79
- // Browse button clicked
80
- $( 'a.cd-upload-btn', options_handler ).on("click", function(e){
81
- // stops the default action of an element from happening
82
- e.preventDefault();
83
-
84
- // Reset value
85
- options.handler.val(null);
86
-
87
- // Click input type[file] element
88
- options.handler.click();
89
- });
90
-
91
- // when dropping files
92
- $('.codedropz-upload-handler', options_handler ).on('drop', function(event){
93
- // Run the uploader
94
- DND_Setup_Uploader( event.originalEvent.dataTransfer.files, 'drop' );
95
- });
96
-
97
- // Trigger when input type[file] is click/changed
98
- options.handler.on("change", function(e){
99
- // Run the uploader
100
- DND_Setup_Uploader( this.files, 'click' );
101
- });
102
-
103
- // Setup Uploader
104
- var DND_Setup_Uploader = function( files, action ) {
105
-
106
- // make sure we have files
107
- if( ! files.length > 1 ) {
108
- return;
109
- }
110
-
111
- // gathering the form data
112
- var formData = new FormData();
113
-
114
- // Append file
115
- formData.append('supported_type', options.supported_type );
116
- formData.append('size_limit', options.max_upload_size );
117
- formData.append('action', 'dnd_codedropz_upload' );
118
- formData.append('type', action );
119
- formData.append('security', dnd_cf7_uploader.ajax_nonce );
120
-
121
- // remove has error
122
- $('span.has-error', options.handler ).remove();
123
-
124
- // Loop files
125
- $.each( files,function( i, file ) {
126
-
127
- // Reset upload file type
128
- if( typeof formData.delete !== 'undefined' ) {
129
- formData.delete('upload-file');
130
- }
131
-
132
- // Limit file upload
133
- if( localStorage.getItem( dataStorageName ) > options.max_file ) {
134
- if( ! $('span.has-error-msg', options_handler ).length > 0 ) {
135
- err_msg = dnd_cf7_uploader.drag_n_drop_upload.max_file_limit;
136
- options_handler.append('<span class="has-error-msg">'+ err_msg.replace('%count%', options.max_file ) +'</span>');
137
- }
138
- return false;
139
- }
140
-
141
- // Create progress bar
142
- var progressBarID = CodeDropz_Object.createProgressBar( file ),
143
- has_error = false;
144
-
145
- // File size limit - validation
146
- if( file.size > options.max_upload_size ) {
147
- $('.dnd-upload-details', $('#' + progressBarID)).append('<span class="has-error">'+ dnd_cf7_uploader.drag_n_drop_upload.large_file +'</span>');
148
- has_error = true;
149
- }
150
-
151
- // Validate file type
152
- regex_type = new RegExp("(.*?)\.("+ options.supported_type +")$");
153
- if ( has_error === false && !( regex_type.test( file.name.toLowerCase() ) ) ) {
154
- $('.dnd-upload-details', $('#' + progressBarID)).append('<span class="has-error">'+ dnd_cf7_uploader.drag_n_drop_upload.inavalid_type +'</span>');
155
- has_error = true;
156
- }
157
-
158
- // Increment count
159
- localStorage.setItem( dataStorageName, ( Number( localStorage.getItem( dataStorageName ) ) + 1 ) );
160
-
161
- // Make sure there's no error
162
- if( has_error === false ) {
163
-
164
- // Append file
165
- formData.append('upload-file', file );
166
-
167
- // Process ajax upload
168
- var dnd_ajax_upload = $.ajax({
169
- url : options.ajax_url,
170
- type : form_handler.attr('method'),
171
- data : formData,
172
- dataType : 'json',
173
- cache : false,
174
- contentType : false,
175
- processData : false,
176
- xhr : function(){
177
- //objects to interact with servers.
178
- var _xhr = new window.XMLHttpRequest();
179
-
180
- // reference : https://stackoverflow.com/questions/15410265/file-upload-progress-bar-with-jquery
181
- _xhr.upload.addEventListener("progress", function(event){
182
- if ( event.lengthComputable ) {
183
- var percentComplete = ( event.loaded / event.total );
184
- var percentage = parseInt( percentComplete * 100 );
185
-
186
- // Progress Loading
187
- CodeDropz_Object.setProgressBar( progressBarID, percentage );
188
-
189
- }
190
- }, false);
191
-
192
- return _xhr;
193
- },
194
- complete : function() {
195
- // Set progress bar to 100%
196
- CodeDropz_Object.setProgressBar( progressBarID, 100 );
197
- },
198
- success: function(response) {
199
- if( response.success ) {
200
-
201
- // Callback on success
202
- if ( $.isFunction( options.on_success ) ) {
203
- options.on_success.call( this, input, progressBarID, response );
204
- }
205
-
206
- }else {
207
- $('.dnd-progress-bar', $('#' + progressBarID)).remove();
208
- $('.dnd-upload-details', $('#' + progressBarID)).append('<span class="has-error">'+ response.data +'</span>');
209
- $('input[type="submit"]', form_handler ).removeClass('disabled').prop( "disabled", false );
210
- }
211
- },
212
- error: function(xhr,ajax,thrownError ) {
213
- $('.dnd-progress-bar', $('#' + progressBarID)).remove();
214
- $('.dnd-upload-details', $('#' + progressBarID)).append('<span class="has-error">'+ options.server_max_error +'</span>');
215
- $('input[type="submit"]', form_handler ).removeClass('disabled').prop( "disabled", false );
216
- }
217
- });
218
- }
219
- });
220
-
221
- }
222
-
223
- // CodeDropz object and functions
224
- var CodeDropz_Object = {
225
-
226
- // Create progress bar
227
- createProgressBar : function( file ) {
228
-
229
- // Setup progress bar variable
230
- var upload_handler = $('.codedropz-upload-handler', options_handler ),
231
- generated_ID = 'dnd-file-' + Math.random().toString(36).substr(2, 9);
232
-
233
- // Setup progressbar elements
234
- var fileDetails = '<div class="dnd-upload-image"><span class="dnd-icon-blank-file"></span></div>'
235
- + '<div class="dnd-upload-details">'
236
- + '<span class="name"><span>'+ file.name +'</span><em>('+ CodeDropz_Object.bytesToSize( file.size ) +')</em></span>'
237
- + '<a href="javascript:void(0)" title="Remove" class="remove-file" data-storage="'+ dataStorageName +'"><span class="dnd-icon-remove"></span></a>'
238
- + '<span class="dnd-progress-bar"><span></span></span>'
239
- + '</div>';
240
-
241
- // Append Status Bar
242
- upload_handler.after('<div id="'+ generated_ID +'" class="dnd-upload-status">'+ fileDetails +'</div>');
243
-
244
- return generated_ID;
245
- },
246
-
247
- // Process progressbar ( Animate progress )
248
- setProgressBar : function( statusbar, percent ) {
249
- var statusBar = $( '.dnd-progress-bar', $('#' + statusbar) );
250
- if( statusBar.length > 0 ) {
251
- // Disable submit button
252
- CodeDropz_Object.disableBtn( btnOBJ );
253
-
254
- // Compute Progress bar
255
- progress_width = ( percent * statusBar.width() / 100);
256
-
257
- $('span', statusBar ).addClass('in-progress').animate({ width: progress_width }, 10).text( percent + '% ');
258
- if( percent == 100 ) {
259
- $('span', statusBar ).addClass('complete').removeClass('in-progress');
260
- }
261
- }
262
- return false;
263
- },
264
-
265
- // Size Conversion
266
- bytesToSize : function( bytes ) {
267
-
268
- if( bytes === 0 )
269
- return '0';
270
-
271
- kBytes = (bytes / 1024);
272
- fileSize = ( kBytes >= 1024 ? ( kBytes / 1024 ).toFixed(2) + 'MB' : kBytes.toFixed(2) + 'KB' );
273
-
274
- return fileSize;
275
- },
276
-
277
- // Disable button
278
- disableBtn : function( BtnOJB ) {
279
- if( BtnOJB.length > 0 ) {
280
- BtnOJB.addClass('disable').prop( "disabled", true );
281
- }
282
- }
283
- };
284
- });// end each
285
-
286
- // Remove File
287
- $(document).on("click",'.dnd-icon-remove',function(e){
288
- var _self = $(this), _dnd_status = _self.parents('.dnd-upload-status'), _parent_wrap = _self.parents('.codedropz-upload-wrapper');
289
- var removeStorageData = _self.parent('a').attr('data-storage');
290
-
291
- // If file upload is in progress don't delete
292
- if( $('span.in-progress', _dnd_status ).length > 0 ) {
293
- return false;
294
- }
295
-
296
- // Direct remove the file if there's any error.
297
- if( $( '.has-error', _dnd_status ).length > 0 ) {
298
- _dnd_status.remove(); localStorage.setItem( removeStorageData, ( Number( localStorage.getItem( removeStorageData ) ) - 1 ) );
299
- return false;
300
- }
301
-
302
- // Change text Status
303
- _self.addClass('deleting').text('deleting...');
304
-
305
- // Request ajax image delete
306
- $.post( settings.ajax_url, { path : _dnd_status.find('input[type="hidden"]').val(), 'action' : 'dnd_codedropz_upload_delete', security : dnd_cf7_uploader.ajax_nonce }, function(response) {
307
- if( response.success ) {
308
-
309
- // Reduce file count and status bar element.
310
- _dnd_status.remove(); localStorage.setItem( removeStorageData, ( Number( localStorage.getItem( removeStorageData ) ) - 1 ) );
311
-
312
- // Remove error msg
313
- if( $('.dnd-upload-status', _parent_wrap ).length <= 1 ) {
314
- $('span.has-error-msg', _parent_wrap ).remove();
315
- }
316
- }
317
- });
318
- });
319
-
320
- }; // end fn.function
321
-
322
- }( jQuery ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
drag-n-drop-upload-cf7.php CHANGED
@@ -6,7 +6,7 @@
6
  * Description: This simple plugin create Drag & Drop or choose Multiple File upload in your Confact Form 7 Forms.
7
  * Text Domain: dnd-upload-cf7
8
  * Domain Path: /languages
9
- * Version: 1.3.3.2
10
  * Author: Glen Don L. Mongaya
11
  * Author URI: http://codedropz.com
12
  * License: GPL2
@@ -21,7 +21,7 @@
21
  define( 'dnd_upload_cf7', true );
22
 
23
  /** Define plugin Version */
24
- define( 'dnd_upload_cf7_version', '1.3.3.2' );
25
 
26
  /** Define constant Plugin Directories */
27
  define( 'dnd_upload_cf7_directory', untrailingslashit( dirname( __FILE__ ) ) );
6
  * Description: This simple plugin create Drag & Drop or choose Multiple File upload in your Confact Form 7 Forms.
7
  * Text Domain: dnd-upload-cf7
8
  * Domain Path: /languages
9
+ * Version: 1.3.3.3.1
10
  * Author: Glen Don L. Mongaya
11
  * Author URI: http://codedropz.com
12
  * License: GPL2
21
  define( 'dnd_upload_cf7', true );
22
 
23
  /** Define plugin Version */
24
+ define( 'dnd_upload_cf7_version', '1.3.3.3.1' );
25
 
26
  /** Define constant Plugin Directories */
27
  define( 'dnd_upload_cf7_directory', untrailingslashit( dirname( __FILE__ ) ) );
inc/dnd-upload-cf7.php CHANGED
@@ -45,6 +45,9 @@
45
  // Add Submenu - Settings
46
  add_action('admin_menu', 'dnd_admin_settings');
47
 
 
 
 
48
  // Load plugin text-domain
49
  function dnd_load_plugin_textdomain() {
50
  load_plugin_textdomain( 'dnd-upload-cf7', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages' );
@@ -102,6 +105,7 @@
102
  'large_file' => __('Uploaded file is too large','dnd-upload-cf7'),
103
  'invalid_type' => __('Uploaded file is not allowed for file type','dnd-upload-cf7'),
104
  'max_file_limit' => __('Note : Some of the files are not uploaded ( Only %count% files allowed )','dnd-upload-cf7'),
 
105
  );
106
 
107
  // return error message based on $error_key request
@@ -321,6 +325,11 @@
321
  'large_file' => ( get_option('drag_n_drop_error_files_too_large') ? get_option('drag_n_drop_error_files_too_large') : dnd_cf7_error_msg('large_file') ),
322
  'inavalid_type' => ( get_option('drag_n_drop_error_invalid_file') ? get_option('drag_n_drop_error_invalid_file') : dnd_cf7_error_msg('invalid_type') ),
323
  'max_file_limit' => ( get_option('drag_n_drop_error_max_file') ? get_option('drag_n_drop_error_max_file') : dnd_cf7_error_msg('max_file_limit') ),
 
 
 
 
 
324
  )
325
  )
326
  );
@@ -404,9 +413,18 @@
404
  function dnd_upload_cf7_validation_filter( $result, $tag ) {
405
  $name = $tag->name;
406
  $id = $tag->get_id_option();
407
-
408
  $multiple_files = ( ( isset( $_POST[ $name ] ) && count( $_POST[ $name ] ) > 0 ) ? sanitize_text_field( $_POST[ $name ] ) : null );
409
 
 
 
 
 
 
 
 
 
 
 
410
  // Check if we have files or if it's empty
411
  if( is_null( $multiple_files ) && $tag->is_required() ) {
412
  $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
@@ -507,6 +525,7 @@
507
  // input type file 'name'
508
  $name = 'upload-file';
509
 
 
510
  $file = isset( $_FILES[$name] ) ? $_FILES[$name] : null;
511
 
512
  // Tells whether the file was uploaded via HTTP POST
@@ -515,10 +534,14 @@
515
  }
516
 
517
  /* File type validation */
518
- $file_type_pattern = dnd_upload_cf7_filetypes( $_POST['supported_type'] );
 
 
 
 
519
 
520
  // validate file type
521
- if ( ! preg_match( $file_type_pattern, $file['name'] ) ) {
522
  wp_send_json_error( get_option('drag_n_drop_error_invalid_file') ? get_option('drag_n_drop_error_invalid_file') : dnd_cf7_error_msg('invalid_type') );
523
  }
524
 
@@ -630,6 +653,33 @@
630
  return $file_type_pattern;
631
  }
632
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633
  // Admin Settings
634
  function dnd_upload_admin_settings( ) {
635
  echo '<div class="wrap">';
@@ -703,6 +753,41 @@
703
  echo '</div>';
704
  }
705
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706
  // Add custom links
707
  function dnd_custom_plugin_row_meta( $links, $file ) {
708
  if ( strpos( $file, 'drag-n-drop-upload-cf7.php' ) !== false ) {
45
  // Add Submenu - Settings
46
  add_action('admin_menu', 'dnd_admin_settings');
47
 
48
+ // Add custom script in footer
49
+ add_action('wp_footer','dnd_custom_scripts');
50
+
51
  // Load plugin text-domain
52
  function dnd_load_plugin_textdomain() {
53
  load_plugin_textdomain( 'dnd-upload-cf7', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages' );
105
  'large_file' => __('Uploaded file is too large','dnd-upload-cf7'),
106
  'invalid_type' => __('Uploaded file is not allowed for file type','dnd-upload-cf7'),
107
  'max_file_limit' => __('Note : Some of the files are not uploaded ( Only %count% files allowed )','dnd-upload-cf7'),
108
+ 'required' => __('This field is required.', 'dnd-upload-cf7' )
109
  );
110
 
111
  // return error message based on $error_key request
325
  'large_file' => ( get_option('drag_n_drop_error_files_too_large') ? get_option('drag_n_drop_error_files_too_large') : dnd_cf7_error_msg('large_file') ),
326
  'inavalid_type' => ( get_option('drag_n_drop_error_invalid_file') ? get_option('drag_n_drop_error_invalid_file') : dnd_cf7_error_msg('invalid_type') ),
327
  'max_file_limit' => ( get_option('drag_n_drop_error_max_file') ? get_option('drag_n_drop_error_max_file') : dnd_cf7_error_msg('max_file_limit') ),
328
+ 'required' => dnd_cf7_error_msg('required'),
329
+ 'delete' => array(
330
+ 'text' => __('deleting','dnd-upload-cf7'),
331
+ 'title' => __('Remove','dnd-upload-cf7')
332
+ )
333
  )
334
  )
335
  );
413
  function dnd_upload_cf7_validation_filter( $result, $tag ) {
414
  $name = $tag->name;
415
  $id = $tag->get_id_option();
 
416
  $multiple_files = ( ( isset( $_POST[ $name ] ) && count( $_POST[ $name ] ) > 0 ) ? sanitize_text_field( $_POST[ $name ] ) : null );
417
 
418
+ // Cf7 Conditional Field
419
+ if ( is_plugin_active( 'cf7-conditional-fields/contact-form-7-conditional-fields.php' ) ) {
420
+ $hidden_groups = json_decode( stripslashes( $_POST['_wpcf7cf_hidden_groups'] ) );
421
+ if( $tag->is_required() && ! in_array( $name, $hidden_groups ) && is_null( $multiple_files ) ) {
422
+ $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
423
+ return $result;
424
+ }
425
+ return $result;
426
+ }
427
+
428
  // Check if we have files or if it's empty
429
  if( is_null( $multiple_files ) && $tag->is_required() ) {
430
  $result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
525
  // input type file 'name'
526
  $name = 'upload-file';
527
 
528
+ // Get File ( name, type, tmp_name, size, error )
529
  $file = isset( $_FILES[$name] ) ? $_FILES[$name] : null;
530
 
531
  // Tells whether the file was uploaded via HTTP POST
534
  }
535
 
536
  /* File type validation */
537
+ $supported_type = preg_replace( '/[^a-zA-Z0-9|\']/', '', sanitize_text_field($_POST['supported_type']) );
538
+ $file_type_pattern = dnd_upload_cf7_filetypes( $supported_type );
539
+
540
+ // Get file extension
541
+ $extension = strtolower( pathinfo( $file['name'], PATHINFO_EXTENSION ) );
542
 
543
  // validate file type
544
+ if ( ! preg_match( $file_type_pattern, $file['name'] ) || ! dnd_cf7_validate_type( $extension, $supported_type ) ) {
545
  wp_send_json_error( get_option('drag_n_drop_error_invalid_file') ? get_option('drag_n_drop_error_invalid_file') : dnd_cf7_error_msg('invalid_type') );
546
  }
547
 
653
  return $file_type_pattern;
654
  }
655
 
656
+ // Add more validation for file extension
657
+ function dnd_cf7_validate_type( $extension, $supported_types ) {
658
+ $valid = true;
659
+ $extension = preg_replace( '/[^A-Za-z0-9,|]/', '', $extension );
660
+
661
+ // not allowed file types
662
+ $not_allowed = array( 'php', 'php3','php4','phtml','exe','script', 'app', 'asp', 'bas', 'bat', 'cer', 'cgi', 'chm', 'cmd', 'com', 'cpl', 'crt', 'csh', 'csr', 'dll', 'drv', 'fxp', 'flv', 'hlp', 'hta', 'htaccess', 'htm', 'htpasswd', 'inf', 'ins', 'isp', 'jar', 'js', 'jse', 'jsp', 'ksh', 'lnk', 'mdb', 'mde', 'mdt', 'mdw', 'msc', 'msi', 'msp', 'mst', 'ops', 'pcd', 'php', 'pif', 'pl', 'prg', 'ps1', 'ps2', 'py', 'rb', 'reg', 'scr', 'sct', 'sh', 'shb', 'shs', 'sys', 'swf', 'tmp', 'torrent', 'url', 'vb', 'vbe', 'vbs', 'vbscript', 'wsc', 'wsf', 'wsf', 'wsh' );
663
+
664
+ // Search in $not_allowed extension and match
665
+ foreach( $not_allowed as $single_ext ) {
666
+ if ( strpos( $single_ext, $extension ) !== false ) {
667
+ $valid = false;
668
+ break;
669
+ }
670
+ }
671
+
672
+ // If pass on first validation - check extension if exists in allowed types
673
+ if( $valid === true ) {
674
+ $extensions = explode('|', strtolower( $supported_types ) );
675
+ if( ! in_array( $extension, $extensions ) ) {
676
+ $valid = false;
677
+ }
678
+ }
679
+
680
+ return $valid;
681
+ }
682
+
683
  // Admin Settings
684
  function dnd_upload_admin_settings( ) {
685
  echo '<div class="wrap">';
753
  echo '</div>';
754
  }
755
 
756
+ // Add script in footer
757
+ function dnd_custom_scripts() {
758
+ if( ! in_array('jquery-validation-for-contact-form-7/jquery-validation-for-contact-form-7.php', get_option('active_plugins') ) ){
759
+ return;
760
+ }
761
+ ?>
762
+ <script type="text/javascript">
763
+ // Contact form 7 - Jquery validation
764
+ jQuery(document).ready(function($){
765
+ jQuery('.wpcf7-form-control.wpcf7-submit').click(function(e){
766
+ var uploadFields = $(this).parents('form').find('.wpcf7-drag-n-drop-file');
767
+ var valid = true;
768
+ if( uploadFields.length > 0 ) {
769
+ jQuery.each(uploadFields, function(i,field){
770
+ if( $(field).attr('aria-required') == 'true' ) {
771
+ parentsWrap = $(field).parents('.codedropz-upload-wrapper');
772
+ parentsWrap.removeClass('invalid');
773
+ parentsWrap.find('label').remove();
774
+ if( $('[type="hidden"][name="'+$(field).attr('data-name')+'[]"]').length == 0 ) {
775
+ parentsWrap.append('<label class="error-new">'+ dnd_cf7_uploader.drag_n_drop_upload.required +'</label>').addClass('invalid');
776
+ valid = false;
777
+ }
778
+ }
779
+ });
780
+ if( ! valid ) {
781
+ return false;
782
+ }
783
+ }
784
+ return true;
785
+ });
786
+ });
787
+ </script>
788
+ <?php
789
+ }
790
+
791
  // Add custom links
792
  function dnd_custom_plugin_row_meta( $links, $file ) {
793
  if ( strpos( $file, 'drag-n-drop-upload-cf7.php' ) !== false ) {
readme.txt CHANGED
@@ -3,7 +3,7 @@ Donate link : http://codedropz.com/donation
3
  Tags: drag and drop, contact form 7, ajax uploader, multiple file, upload, contact form 7 uploader
4
  Requires at least: 3.0.1
5
  Tested up to: 5.4.1
6
- Stable tag: 1.3.3.2
7
  Requires PHP: 5.2.4
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -47,15 +47,15 @@ Checkout available features on **PRO version**.
47
  - By User
48
  - Custom Folder
49
  * Send to email as individual attachment, ZIP archive or as a links
50
- * Improved Security
51
- * Optimized Code and Performance
52
- * 1 Month Premium Support
53
  * Chunks Upload *( Break large files into smaller Chunks )*
54
- * Max Total Size *( All Uploaded Files )*
55
  * Parallel/Sequential Upload *( Number of files to simultaneously upload )*
56
  * Change Filename Pattern ({filename}, {ip_address}, {random}, {post_id}, {post_slug}, etc.)
57
- * Optimize Image
58
- * Able to Resize/Crop image
 
 
 
59
 
60
  You can get [PRO Version here](https://www.codedropz.com/purchase-plugin/)!
61
 
@@ -80,7 +80,7 @@ Please take note it should be `Bytes` you may use any converter just Google (MB
80
 
81
  You can limit the number of files in your file upload by adding this parameter `max-file:3` to your shortcode :
82
 
83
- Example: *[mfile upload-file-344 max-file:3] * - this option will limit the user to upload only 3 files.
84
 
85
  = How can I Add or Limit file types =
86
 
@@ -124,6 +124,12 @@ To install this plugin see below:
124
 
125
  == Changelog ==
126
 
 
 
 
 
 
 
127
  = 1.3.3.2 =
128
  * Fixed - PHP warning reported [here](https://wordpress.org/support/topic/php-warning-count-parameter-must-be-an-array-2/)
129
 
3
  Tags: drag and drop, contact form 7, ajax uploader, multiple file, upload, contact form 7 uploader
4
  Requires at least: 3.0.1
5
  Tested up to: 5.4.1
6
+ Stable tag: 1.3.3.3.1
7
  Requires PHP: 5.2.4
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
47
  - By User
48
  - Custom Folder
49
  * Send to email as individual attachment, ZIP archive or as a links
 
 
 
50
  * Chunks Upload *( Break large files into smaller Chunks )*
51
+ * Max Total Size *( of all Uploaded Files )*
52
  * Parallel/Sequential Upload *( Number of files to simultaneously upload )*
53
  * Change Filename Pattern ({filename}, {ip_address}, {random}, {post_id}, {post_slug}, etc.)
54
+ * Automatically Optimize Images
55
+ * Able to Resize/Crop image (ie: 800x800)
56
+ * Improved Security
57
+ * Optimized Code and Performance
58
+ * 1 Month Premium Support
59
 
60
  You can get [PRO Version here](https://www.codedropz.com/purchase-plugin/)!
61
 
80
 
81
  You can limit the number of files in your file upload by adding this parameter `max-file:3` to your shortcode :
82
 
83
+ Example: *[mfile upload-file-344 max-file:3]* - this option will limit the user to upload only 3 files.
84
 
85
  = How can I Add or Limit file types =
86
 
124
 
125
  == Changelog ==
126
 
127
+ = 1.3.3.3 =
128
+ * Fixed - Security Issues ( Unrestricted File Upload to Remote Code Execution - Thanks to @Austin )
129
+ - Able bypass and upload file (remotely) by renaming to ie: shell.php% and modified supported_type to `jpg|png|php%`
130
+ - Solution : Added more security, check/validate file type and created new function 'dnd_cf7_validate_type' to determine if file name extension is valid or not.
131
+ * New - Make 'deleting...' and 'remove' text translatable ( compatible using WPML String Translation ).
132
+
133
  = 1.3.3.2 =
134
  * Fixed - PHP warning reported [here](https://wordpress.org/support/topic/php-warning-count-parameter-must-be-an-array-2/)
135