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

Version Description

  • Added - Multiple Drag and Drop fields in a form
  • Added - Options in admin for error message
  • Added - Option that allow user to send attachment as links
  • Added - Added new folder name wp_dndcf7_uploads to separate files from wpcf7_uploads ( When option 'Send Attachment as links?' is check ).
Download this release

Release Info

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

Code changes from version 1.2.2 to 1.2.3

assets/js/codedropz-uploader-min.js CHANGED
@@ -7,4 +7,5 @@
7
  * @license The MIT License (MIT)
8
  */
9
 
10
- !function(e){e.fn.CodeDropz_Uploader=function(a){var d=e.extend({handler:this,color:"#000",background:"",max_file:10,text:"Drag & Drop Files Here",separator:"or",button_text:"Browse Files",max_upload_size:"5242880",supported_type:"jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv",on_success:""},a),o=0,n='<div class="codedropz-upload-handler"><div class="codedropz-upload-container"><div class="codedropz-upload-inner"><h3>'+d.text+"</h3><span>"+d.separator+'</span><div class="codedropz-btn-wrap"><a class="cd-upload-btn" href="javascript:void(0)">'+d.button_text+"</a></div></div></div></div>",r=d.handler.parents("form");d.handler.wrapAll('<div class="codedropz-upload-wrapper"></div>'),d.handler.after(n),e(".codedropz-upload-handler",r).on("drag dragstart dragend dragover dragenter dragleave drop",function(e){e.preventDefault(),e.stopPropagation()}),e(".codedropz-upload-handler",r).on("dragover dragenter",function(a){e(this).addClass("codedropz-dragover")}),e(".codedropz-upload-handler",r).on("dragleave dragend drop",function(a){e(this).removeClass("codedropz-dragover")}),e("a.cd-upload-btn",r).on("click",function(e){e.preventDefault(),d.handler.click()}),e(".codedropz-upload-handler",r).on("drop",function(e){t(e.originalEvent.dataTransfer.files,"drop"),d.handler.trigger("change")}),d.handler.on("change",function(e){t(this.files,"click")});var t=function(a,n){if(!(!a.length>1)){var t=new FormData;e.each(a,function(a,p){if(o++>=d.max_file)return!1;var i,l,c,u,v,f=(i=p,l=e(".codedropz-upload-handler",r),c="dnd-file-"+Math.random().toString(36).substr(2,9),u='<div class="dnd-upload-image"><span class="dnd-icon-blank-file"></span></div><div class="dnd-upload-details"><span class="name">'+i.name+" <em>("+(0===(v=i.size)?"0":(kBytes=v/1024,fileSize=kBytes>=1024?(kBytes/1024).toFixed(2)+"MB":kBytes.toFixed(2)+"KB",fileSize))+')</em></span><a href="javascript:void(0)" title="Remove" class="remove-file"><span class="dnd-icon-remove"></span></a><span class="dnd-progress-bar"><span></span></span></div>',l.after('<div id="'+c+'" class="dnd-upload-status">'+u+"</div>"),c);t.append("upload-file",p),t.append("supported_type",d.supported_type),t.append("size_limit",d.max_upload_size),t.append("action","dnd_codedropz_upload"),t.append("type",n);e.ajax({url:d.ajax_url,type:r.attr("method"),data:t,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);s(f,d)}},!1),e},complete:function(){s(f,100)},success:function(a){a.success?e.isFunction(d.on_success)&&d.on_success.call(this,f,a):(e(".dnd-progress-bar",e("#"+f)).remove(),e(".dnd-upload-details",e("#"+f)).append('<span class="has-error">'+a.data+"</span>"))},error:function(e,a,d){alert("The uploaded file exceeds the Upload Max File size")}})})}};function s(a,d){var o=e(".dnd-progress-bar",e("#"+a));return o.length>0&&(progress_width=d*o.width()/100,e("span",o).animate({width:progress_width},10).text(d+"% "),100==d&&e("span",o).addClass("complete")),!1}e(document).on("click",".dnd-icon-remove",function(){e(this).parents(".dnd-upload-status").remove(),o-=1,alert(o)})}}(jQuery);
 
7
  * @license The MIT License (MIT)
8
  */
9
 
10
+ // CodeDropz Drag and Drop Plugin
11
+ !function(e){e.fn.CodeDropz_Uploader=function(a){var d=e.extend({handler:this,color:"#000",background:"",server_max_error:"Uploaded file exceeds the maximum upload size of your server.",max_file:10,text:"Drag & Drop Files Here",separator:"or",button_text:"Browse Files",max_upload_size:"5242880",supported_type:"jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv",on_success:""},a),r=1,o='<div class="codedropz-upload-handler"><div class="codedropz-upload-container"><div class="codedropz-upload-inner"><h3>'+d.text+"</h3><span>"+d.separator+'</span><div class="codedropz-btn-wrap"><a class="cd-upload-btn" href="javascript:void(0)">'+d.button_text+"</a></div></div></div></div>";d.handler.wrapAll('<div class="codedropz-upload-wrapper"></div>');var n=d.handler.parents("form"),s=d.handler.parents(".codedropz-upload-wrapper");d.handler.after(o),e(".codedropz-upload-handler",s).on("drag dragstart dragend dragover dragenter dragleave drop",function(e){e.preventDefault(),e.stopPropagation()}),e(".codedropz-upload-handler",s).on("dragover dragenter",function(a){e(this).addClass("codedropz-dragover")}),e(".codedropz-upload-handler",s).on("dragleave dragend drop",function(a){e(this).removeClass("codedropz-dragover")}),e("a.cd-upload-btn",s).on("click",function(e){e.preventDefault(),d.handler.click()}),e(".codedropz-upload-handler",s).on("drop",function(e){p(e.originalEvent.dataTransfer.files,"drop"),d.handler.trigger("change")}),d.handler.on("change",function(e){p(this.files,"click")});var p=function(a,o){if(!(!a.length>1)){var p=new FormData;e.each(a,function(a,i){if(r>d.max_file)return!1;r++;var l,c,u,v,f,h=(l=i,c=e(".codedropz-upload-handler",s),u="dnd-file-"+Math.random().toString(36).substr(2,9),v='<div class="dnd-upload-image"><span class="dnd-icon-blank-file"></span></div><div class="dnd-upload-details"><span class="name">'+l.name+" <em>("+(0===(f=l.size)?"0":(kBytes=f/1024,fileSize=kBytes>=1024?(kBytes/1024).toFixed(2)+"MB":kBytes.toFixed(2)+"KB",fileSize))+')</em></span><a href="javascript:void(0)" title="Remove" class="remove-file"><span class="dnd-icon-remove"></span></a><span class="dnd-progress-bar"><span></span></span></div>',c.after('<div id="'+u+'" class="dnd-upload-status">'+v+"</div>"),u);p.append("upload-file",i),p.append("supported_type",d.supported_type),p.append("size_limit",d.max_upload_size),p.append("action","dnd_codedropz_upload"),p.append("type",o);e.ajax({url:d.ajax_url,type:n.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);t(h,d)}},!1),e},complete:function(){t(h,100)},success:function(a){a.success?e.isFunction(d.on_success)&&d.on_success.call(this,h,a):(e(".dnd-progress-bar",e("#"+h)).remove(),e(".dnd-upload-details",e("#"+h)).append('<span class="has-error">'+a.data+"</span>"))},error:function(a,r,o){e(".dnd-progress-bar",e("#"+h)).remove(),e(".dnd-upload-details",e("#"+h)).append('<span class="has-error">'+d.server_max_error+"</span>")}})})}};function t(a,d){var r=e(".dnd-progress-bar",e("#"+a));return r.length>0&&(progress_width=d*r.width()/100,e("span",r).animate({width:progress_width},10).text(d+"% "),100==d&&e("span",r).addClass("complete")),!1}e(document).on("click",".dnd-icon-remove",function(){e(this).parents(".dnd-upload-status").remove(),r-=1})}}(jQuery);
assets/js/dnd-upload-cf7.js CHANGED
@@ -3,32 +3,41 @@ jQuery(document).ready(function($){
3
  var Cf7myUploadFile = $('.wpcf7-drag-n-drop-file'),
4
  TextOJB = dnd_cf7_uploader.drag_n_drop_upload
5
 
6
- Cf7myUploadFile.CodeDropz_Uploader({
7
- 'color' : '#fff',
8
- 'ajax_url' : dnd_cf7_uploader.ajax_url,
9
- 'max_upload_size' : Cf7myUploadFile.data('limit'),
10
- 'supported_type' : Cf7myUploadFile.data('type'),
11
- 'max_file' : Cf7myUploadFile.data('max'),
12
- 'text' : TextOJB.text,
13
- 'separator' : TextOJB.or_separator,
14
- 'button_text' : TextOJB.browse,
15
- 'on_success' : function( progressBar, response ){
 
 
 
16
 
17
- // Progressbar Object
18
- var progressDetails = $('#' + progressBar );
19
 
20
- // Append hidden input field
21
- progressDetails
22
- .find('.dnd-upload-details')
23
- .append('<span><input type="hidden" name="'+ Cf7myUploadFile.attr('name') +'[]" value="'+ response.data.path +'/'+ response.data.file +'"></span>');
24
- }
 
25
  });
26
 
27
  // Fires when an Ajax form submission has completed successfully, and mail has been sent.
28
- document.addEventListener( 'wpcf7mailsent ', function( event ) {
29
  // Reset upload list
30
- $('.dnd-upload-status', $('span.' + Cf7myUploadFile.attr('name'))).remove();
31
-
 
 
 
 
 
32
  // Reset count files
33
  count_files=0;
34
  }, false );
3
  var Cf7myUploadFile = $('.wpcf7-drag-n-drop-file'),
4
  TextOJB = dnd_cf7_uploader.drag_n_drop_upload
5
 
6
+ $.each( Cf7myUploadFile, function(){
7
+ var dnd_input_file = $(this);
8
+ $(this).CodeDropz_Uploader({
9
+ 'color' : '#fff',
10
+ 'ajax_url' : dnd_cf7_uploader.ajax_url,
11
+ 'max_upload_size' : dnd_input_file.data('limit'),
12
+ 'supported_type' : dnd_input_file.data('type'),
13
+ 'max_file' : dnd_input_file.data('max'),
14
+ 'text' : TextOJB.text,
15
+ 'separator' : TextOJB.or_separator,
16
+ 'button_text' : TextOJB.browse,
17
+ 'server_max_error' : TextOJB.server_max_error,
18
+ 'on_success' : function( progressBar, response ){
19
 
20
+ // Progressbar Object
21
+ var progressDetails = $('#' + progressBar, dnd_input_file.parents('.codedropz-upload-wrapper') );
22
 
23
+ // Append hidden input field
24
+ progressDetails
25
+ .find('.dnd-upload-details')
26
+ .append('<span><input type="hidden" name="'+ dnd_input_file.attr('name') +'[]" value="'+ response.data.path +'/'+ response.data.file +'"></span>');
27
+ }
28
+ });
29
  });
30
 
31
  // Fires when an Ajax form submission has completed successfully, and mail has been sent.
32
+ document.addEventListener( 'wpcf7mailsent', function( event ) {
33
  // Reset upload list
34
+ if( Cf7myUploadFile.length > 0 ) {
35
+ $.each( Cf7myUploadFile, function(){
36
+ $('.dnd-upload-status', $('span.' + $(this).attr('name'))).remove();
37
+ });
38
+ }else {
39
+ $('.dnd-upload-status', $('span.' + Cf7myUploadFile.attr('name'))).remove();
40
+ }
41
  // Reset count files
42
  count_files=0;
43
  }, false );
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.2.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.2.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.2.3
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.2.3' );
25
 
26
  /** Define constant Plugin Directories */
27
  define( 'dnd_upload_cf7_directory', untrailingslashit( dirname( __FILE__ ) ) );
inc/dnd-upload-cf7.php CHANGED
@@ -15,14 +15,15 @@
15
  */
16
 
17
  add_action( 'wpcf7_init', 'dnd_cf7_upload_add_form_tag_file' );
18
- add_action( 'wp_enqueue_scripts', 'dnd_cf7_scripts' );
19
 
20
  // Ajax Upload
21
  add_action( 'wp_ajax_dnd_codedropz_upload', 'dnd_upload_cf7_upload' );
22
  add_action( 'wp_ajax_nopriv_dnd_codedropz_upload', 'dnd_upload_cf7_upload' );
23
 
24
- // Hook mail
25
- add_action('wpcf7_mail_components','mycustom_wpcf7_mail_components', 50, 2);
 
26
 
27
  // Add Submenu - Settings
28
  add_action('admin_menu', 'dnd_admin_settings');
@@ -33,40 +34,118 @@
33
  add_action('admin_init','dnd_upload_register_settings');
34
  }
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  // hooks - Custom cf7 Mail components
37
- function mycustom_wpcf7_mail_components( $components, $form ) {
 
 
 
38
 
39
  // get all form fields
40
  $fields = $form->scan_form_tags();
41
- $user_fields = wp_list_pluck( $fields, 'name','basetype' );
42
 
43
- // Make sure mfile field is set.
44
- if( ! isset( $_POST[ $user_fields['mfile'] ] ) ) {
45
  return $components;
46
  }
47
 
48
- // Get uploaded files
49
- $uploaded_files = ( isset( $_POST[ $user_fields['mfile'] ] ) ? $_POST[ $user_fields['mfile'] ] : null );
50
 
51
- // Mail Files
52
- if( ! is_null( $uploaded_files ) && count( $uploaded_files ) > 0 ) {
53
- $counter = 0;
54
 
55
- // Confirm upload dir
56
- wpcf7_init_uploads();
57
 
58
- // Get cf7 upload directory
59
- $uploads_dir = wpcf7_upload_tmp_dir();
 
 
 
 
 
 
60
 
61
- // cf7 - Submission Object
62
- $submission = WPCF7_Submission::get_instance();
63
 
64
- // Loop and add our files
65
- foreach( $uploaded_files as $_file ) {
66
- $new_file_name = path_join( $uploads_dir, $_file );
67
- if ( $submission && file_exists( $new_file_name ) ) {
68
- $components['attachments'][] = $new_file_name;
69
  }
 
70
  }
71
  }
72
 
@@ -76,24 +155,28 @@
76
  // Load js and css
77
  function dnd_cf7_scripts() {
78
 
 
 
 
79
  // enque script
80
- wp_enqueue_script( 'codedropz-uploader', plugins_url ('/assets/js/codedropz-uploader-min.js', dirname(__FILE__) ), array('jquery'), '1.1.2', true );
81
- wp_enqueue_script( 'dnd-upload-cf7', plugins_url ('/assets/js/dnd-upload-cf7.js', dirname(__FILE__) ), array('jquery','codedropz-uploader'), '1.1.2', true );
82
 
83
  // registered script with data for a JavaScript variable.
84
  wp_localize_script( 'dnd-upload-cf7', 'dnd_cf7_uploader',
85
  array(
86
  'ajax_url' => admin_url( 'admin-ajax.php' ),
87
  'drag_n_drop_upload' => array(
88
- 'text' => ( get_option('drag_n_drop_text') ? get_option('drag_n_drop_text') : 'Drag & Drop Files Here' ),
89
- 'or_separator' => ( get_option('drag_n_drop_separator') ? get_option('drag_n_drop_separator') : 'or' ),
90
- 'browse' => ( get_option('drag_n_drop_browse_text') ? get_option('drag_n_drop_browse_text') : 'Browse Files' ),
 
91
  )
92
  )
93
  );
94
 
95
  // enque style
96
- wp_enqueue_style( 'dnd-upload-cf7', plugins_url ('/assets/css/dnd-upload-cf7.css', dirname(__FILE__) ), '', '1.0' );
97
  }
98
 
99
  // Generate tag
@@ -285,7 +368,7 @@
285
 
286
  // Tells whether the file was uploaded via HTTP POST
287
  if ( ! is_uploaded_file( $file['tmp_name'] ) ) {
288
- wp_send_json_error( __('Uploading a file fails for any reason','dnd-upload-cf7') );
289
  }
290
 
291
  /* File type validation */
@@ -293,22 +376,42 @@
293
 
294
  // validate file type
295
  if ( ! preg_match( $file_type_pattern, $file['name'] ) ) {
296
- wp_send_json_error( __('Uploaded file is not allowed for file type','dnd-upload-cf7') );
297
  }
298
 
299
  // validate file size limit
300
  if( $file['size'] > (int)$_POST['size_limit'] ) {
301
- wp_send_json_error( __('Uploaded file is too large','dnd-upload-cf7') );
302
  }
303
 
304
- wpcf7_init_uploads(); // Confirm upload dir
305
- $uploads_dir = wpcf7_upload_tmp_dir();
306
- $uploads_dir = wpcf7_maybe_add_random_dir( $uploads_dir );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
 
 
308
  $filename = $file['name'];
309
  $filename = wpcf7_canonicalize( $filename, 'as-is' );
310
  $filename = wpcf7_antiscript_file_name( $filename );
311
 
 
312
  $filename = apply_filters( 'wpcf7_upload_file_name', $filename, $file['name'] );
313
 
314
  // Generate new filename
@@ -317,7 +420,7 @@
317
 
318
  // Upload File
319
  if ( false === move_uploaded_file( $file['tmp_name'], $new_file ) ) {
320
- wp_send_json_error( __('Uploading a file fails for any reason','dnd-upload-cf7') );
321
  }else{
322
 
323
  $files = array(
@@ -326,7 +429,7 @@
326
  );
327
 
328
  // Change file permission to 0400
329
- chmod( $new_file, 0400 );
330
 
331
  wp_send_json_success( $files );
332
  }
@@ -371,6 +474,16 @@
371
  settings_fields( 'drag-n-drop-upload-file-cf7' );
372
  do_settings_sections( 'drag-n-drop-upload-file-cf7' );
373
  ?>
 
 
 
 
 
 
 
 
 
 
374
  <table class="form-table">
375
  <tr valign="top">
376
  <th scope="row"><?php _e('Drag & Drop Text','dnd-upload-cf7'); ?></th>
@@ -386,6 +499,27 @@
386
  </tr>
387
  </table>
388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  <?php submit_button(); ?>
390
 
391
  <?php
@@ -395,7 +529,12 @@
395
 
396
  // Save admin settings
397
  function dnd_upload_register_settings() {
 
398
  register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_text' );
399
  register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_separator' );
400
  register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_browse_text' );
 
 
 
 
401
  }
15
  */
16
 
17
  add_action( 'wpcf7_init', 'dnd_cf7_upload_add_form_tag_file' );
18
+ add_action( 'wpcf7_enqueue_scripts', 'dnd_cf7_scripts' );
19
 
20
  // Ajax Upload
21
  add_action( 'wp_ajax_dnd_codedropz_upload', 'dnd_upload_cf7_upload' );
22
  add_action( 'wp_ajax_nopriv_dnd_codedropz_upload', 'dnd_upload_cf7_upload' );
23
 
24
+ // Hook mail cf7
25
+ add_action('wpcf7_before_send_mail','dnd_cf7_before_send_mail', 30, 1);
26
+ add_action('wpcf7_mail_components','dnd_cf7_mail_components', 50, 2);
27
 
28
  // Add Submenu - Settings
29
  add_action('admin_menu', 'dnd_admin_settings');
34
  add_action('admin_init','dnd_upload_register_settings');
35
  }
36
 
37
+ // Default Error Message
38
+ function dnd_cf7_error_msg( $error_key ) {
39
+
40
+ // Array of default error message
41
+ $errors = array(
42
+ 'server_limit' => __('The uploaded file exceeds the maximum upload size of your server.','dnd-upload-cf7'),
43
+ 'failed_upload' => __('Uploading a file fails for any reason','dnd-upload-cf7'),
44
+ 'large_file' => __('Uploaded file is too large','dnd-upload-cf7'),
45
+ 'invalid_type' => __('Uploaded file is not allowed for file type','dnd-upload-cf7'),
46
+ );
47
+
48
+ // return error message based on $error_key request
49
+ if( isset( $errors[ $error_key ] ) ) {
50
+ return $errors[ $error_key ];
51
+ }
52
+
53
+ return false;
54
+ }
55
+
56
+ // Hooks before sending the email
57
+ function dnd_cf7_before_send_mail( $wpcf7 ){
58
+
59
+ // Check If send attachment as link
60
+ if( ! get_option('drag_n_drop_mail_attachment') ) {
61
+ return $wpcf7;
62
+ }
63
+
64
+ // cf7 instance
65
+ $submission = WPCF7_Submission::get_instance();
66
+
67
+ // Check for submission
68
+ if( $submission ) {
69
+
70
+ // Get posted data
71
+ $submitted['posted_data'] = $submission->get_posted_data();
72
+
73
+ //Get an array containing the current upload directory’s path and url.
74
+ $upload_dir = wp_upload_dir();
75
+
76
+ // Parse fields
77
+ $fields = $wpcf7->scan_form_tags();
78
+
79
+ // Prop email
80
+ $mail = $wpcf7->prop('mail');
81
+
82
+ // Default upload path
83
+ $simple_path = $upload_dir['baseurl'];
84
+
85
+ // Check if media upload oraganized by year and month folders
86
+ if( get_option('uploads_use_yearmonth_folders') ) {
87
+ $simple_path = $upload_dir['baseurl'] . '/wp_dndcf7_uploads' . dirname( $upload_dir['subdir'] );
88
+ }
89
+
90
+ // Loop fields and replace mfile code
91
+ foreach( $fields as $field ) {
92
+ if( $field->basetype == 'mfile') {
93
+ if( isset( $submitted['posted_data'][$field->name] ) && ! empty( $submitted['posted_data'][$field->name] ) ) {
94
+ $files = implode( "\n" . $simple_path . '/' , $submitted['posted_data'][$field->name] );
95
+ $mail['body'] = str_replace( "[$field->name]", "\n" . $simple_path .'/'. $files, $mail['body'] );
96
+ }
97
+ }
98
+ }
99
+
100
+ // Save the email body
101
+ $wpcf7->set_properties( array("mail" => $mail) );
102
+ }
103
+
104
+ return $wpcf7;
105
+ }
106
+
107
  // hooks - Custom cf7 Mail components
108
+ function dnd_cf7_mail_components( $components, $form ) {
109
+
110
+ // cf7 - Submission Object
111
+ $submission = WPCF7_Submission::get_instance();
112
 
113
  // get all form fields
114
  $fields = $form->scan_form_tags();
 
115
 
116
+ // Send email link as an attachment.
117
+ if( get_option('drag_n_drop_mail_attachment') == 'yes' ) {
118
  return $components;
119
  }
120
 
121
+ // Confirm upload dir
122
+ wpcf7_init_uploads();
123
 
124
+ // Get cf7 upload directory
125
+ $uploads_dir = wpcf7_upload_tmp_dir();
 
126
 
127
+ // Loop fields get mfile only.
128
+ foreach( $fields as $field ) {
129
 
130
+ // If field type equal to mfile which our default field.
131
+ if( $field->basetype == 'mfile') {
132
+
133
+ // Make sure we have files to attach
134
+ if( isset( $_POST[ $field->name ] ) && count( $_POST[ $field->name ] ) > 0 ) {
135
+
136
+ // Loop all the files and attach to cf7 components
137
+ foreach( $_POST[ $field->name ] as $_file ) {
138
 
139
+ // Join dir and a new file name ( get from <input type="hidden" name="upload-file-333"> )
140
+ $new_file_name = path_join( $uploads_dir, $_file );
141
 
142
+ // Check if submitted and file exists then file is ready.
143
+ if ( $submission && file_exists( $new_file_name ) ) {
144
+ $components['attachments'][] = $new_file_name;
145
+ }
146
+ }
147
  }
148
+
149
  }
150
  }
151
 
155
  // Load js and css
156
  function dnd_cf7_scripts() {
157
 
158
+ // Get plugin version
159
+ $version = dnd_upload_cf7_version;
160
+
161
  // enque script
162
+ wp_enqueue_script( 'codedropz-uploader', plugins_url ('/assets/js/codedropz-uploader-min.js', dirname(__FILE__) ), array('jquery'), $version, true );
163
+ wp_enqueue_script( 'dnd-upload-cf7', plugins_url ('/assets/js/dnd-upload-cf7.js', dirname(__FILE__) ), array('jquery','codedropz-uploader','contact-form-7'), $version, true );
164
 
165
  // registered script with data for a JavaScript variable.
166
  wp_localize_script( 'dnd-upload-cf7', 'dnd_cf7_uploader',
167
  array(
168
  'ajax_url' => admin_url( 'admin-ajax.php' ),
169
  'drag_n_drop_upload' => array(
170
+ 'text' => ( get_option('drag_n_drop_text') ? get_option('drag_n_drop_text') : 'Drag & Drop Files Here' ),
171
+ 'or_separator' => ( get_option('drag_n_drop_separator') ? get_option('drag_n_drop_separator') : 'or' ),
172
+ 'browse' => ( get_option('drag_n_drop_browse_text') ? get_option('drag_n_drop_browse_text') : 'Browse Files' ),
173
+ 'server_max_error' => ( get_option('drag_n_drop_error_server_limit') ? get_option('drag_n_drop_error_server_limit') : dnd_cf7_error_msg('server_limit') ),
174
  )
175
  )
176
  );
177
 
178
  // enque style
179
+ wp_enqueue_style( 'dnd-upload-cf7', plugins_url ('/assets/css/dnd-upload-cf7.css', dirname(__FILE__) ), '', $version );
180
  }
181
 
182
  // Generate tag
368
 
369
  // Tells whether the file was uploaded via HTTP POST
370
  if ( ! is_uploaded_file( $file['tmp_name'] ) ) {
371
+ wp_send_json_error( get_option('drag_n_drop_error_failed_to_upload') ? get_option('drag_n_drop_error_failed_to_upload') : dnd_cf7_error_msg('failed_upload') );
372
  }
373
 
374
  /* File type validation */
376
 
377
  // validate file type
378
  if ( ! preg_match( $file_type_pattern, $file['name'] ) ) {
379
+ 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') );
380
  }
381
 
382
  // validate file size limit
383
  if( $file['size'] > (int)$_POST['size_limit'] ) {
384
+ wp_send_json_error( get_option('drag_n_drop_error_files_too_large') ? get_option('drag_n_drop_error_files_too_large') : dnd_cf7_error_msg('large_file') );
385
  }
386
 
387
+ wpcf7_init_uploads(); // Confirm upload dir from Contact Form 7
388
+
389
+ // Manage create directory ( Attach image through email or send as links )
390
+ if( get_option('drag_n_drop_mail_attachment') == 'yes' ) {
391
+
392
+ $upload = wp_upload_dir();
393
+ $uploads_dir = apply_filters('dnd_cf7_upload_path', $upload['basedir'] . '/wp_dndcf7_uploads', $upload );
394
+
395
+ // Check if upload use year and month folders
396
+ if( get_option('uploads_use_yearmonth_folders') ) {
397
+ $uploads_dir = apply_filters('dnd_cf7_upload_path', $upload['basedir'] . '/wp_dndcf7_uploads'. $upload['subdir'], $upload );
398
+ }
399
+
400
+ if ( ! is_dir( $uploads_dir ) ) {
401
+ wp_mkdir_p( $uploads_dir );
402
+ }
403
+
404
+ }else {
405
+ $uploads_dir = wpcf7_upload_tmp_dir();
406
+ $uploads_dir = wpcf7_maybe_add_random_dir( $uploads_dir );
407
+ }
408
 
409
+ // Create file name
410
  $filename = $file['name'];
411
  $filename = wpcf7_canonicalize( $filename, 'as-is' );
412
  $filename = wpcf7_antiscript_file_name( $filename );
413
 
414
+ // Add filter on upload file name
415
  $filename = apply_filters( 'wpcf7_upload_file_name', $filename, $file['name'] );
416
 
417
  // Generate new filename
420
 
421
  // Upload File
422
  if ( false === move_uploaded_file( $file['tmp_name'], $new_file ) ) {
423
+ wp_send_json_error( get_option('drag_n_drop_error_failed_to_upload') ? get_option('drag_n_drop_error_failed_to_upload') : dnd_cf7_error_msg('failed_upload') );
424
  }else{
425
 
426
  $files = array(
429
  );
430
 
431
  // Change file permission to 0400
432
+ chmod( $new_file, 0644 );
433
 
434
  wp_send_json_success( $files );
435
  }
474
  settings_fields( 'drag-n-drop-upload-file-cf7' );
475
  do_settings_sections( 'drag-n-drop-upload-file-cf7' );
476
  ?>
477
+
478
+ <table class="form-table">
479
+ <tr valign="top">
480
+ <th scope="row"><?php _e('Send Attachment as links?','dnd-upload-cf7'); ?></th>
481
+ <td><input name="drag_n_drop_mail_attachment" type="checkbox" value="yes" <?php checked('yes', get_option('drag_n_drop_mail_attachment')); ?>></td>
482
+ </tr>
483
+ </table>
484
+
485
+ <h2><?php _e('Uploader Info','dnd-upload-cf7'); ?></h2>
486
+
487
  <table class="form-table">
488
  <tr valign="top">
489
  <th scope="row"><?php _e('Drag & Drop Text','dnd-upload-cf7'); ?></th>
499
  </tr>
500
  </table>
501
 
502
+ <h2><?php _e('Error Message','dnd-upload-cf7'); ?></h2>
503
+
504
+ <table class="form-table">
505
+ <tr valign="top">
506
+ <th scope="row"><?php _e('File exceeds server limit','dnd-upload-cf7'); ?></th>
507
+ <td><input type="text" name="drag_n_drop_error_server_limit" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_server_limit') ); ?>" placeholder="<?php echo dnd_cf7_error_msg('server_limit'); ?>" /></td>
508
+ </tr>
509
+ <tr valign="top">
510
+ <th scope="row"><?php _e('Failed to Upload','dnd-upload-cf7'); ?></th>
511
+ <td><input type="text" name="drag_n_drop_error_failed_to_upload" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_failed_to_upload') ); ?>" placeholder="<?php echo dnd_cf7_error_msg('failed_upload'); ?>" /></td>
512
+ </tr>
513
+ <tr valign="top">
514
+ <th scope="row"><?php _e('Files too large','dnd-upload-cf7'); ?></th>
515
+ <td><input type="text" name="drag_n_drop_error_files_too_large" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_files_too_large') ); ?>" placeholder="<?php echo dnd_cf7_error_msg('large_file'); ?>" /></td>
516
+ </tr>
517
+ <tr valign="top">
518
+ <th scope="row"><?php _e('Invalid file Type','dnd-upload-cf7'); ?></th>
519
+ <td><input type="text" name="drag_n_drop_error_invalid_file" class="regular-text" value="<?php echo esc_attr( get_option('drag_n_drop_error_invalid_file') ); ?>" placeholder="<?php echo dnd_cf7_error_msg('invalid_type'); ?>" /></td>
520
+ </tr>
521
+ </table>
522
+
523
  <?php submit_button(); ?>
524
 
525
  <?php
529
 
530
  // Save admin settings
531
  function dnd_upload_register_settings() {
532
+ register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_mail_attachment' );
533
  register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_text' );
534
  register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_separator' );
535
  register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_browse_text' );
536
+ register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_server_limit' );
537
+ register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_failed_to_upload' );
538
+ register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_files_too_large' );
539
+ register_setting( 'drag-n-drop-upload-file-cf7', 'drag_n_drop_error_invalid_file' );
540
  }
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.0
6
- Stable tag: 1.2.2
7
  Requires PHP: 5.2.4
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -19,10 +19,12 @@ Here's a little demo [here](http://codedropz.com/contact).
19
  * File Type Validation
20
  * File Size Validation
21
  * Ajax Upload
 
22
  * Drag & Drop or Browse File - Multiple Upload
 
 
23
  * Mobile Responsive
24
  * Cool Progress Bar
25
- * Limit number of files Upload.
26
  * Browser Compatability
27
 
28
  == Frequently Asked Questions ==
@@ -47,39 +49,84 @@ You can add or change file types in cf7 Form-tag Generator Options by adding `jp
47
 
48
  Example : [mfile upload-file-433 filetypes:jpeg|png|jpg|gif]
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  == Installation ==
51
 
52
  To install this plugin see below:
53
 
54
- 1. Upload the plugin files to the `/wp-content/plugins/drag-n-drop-upload-cf7.zip` directory, or install the plugin through the WordPress plugins screen directly.
55
  2. Activate the plugin through the 'Plugins' screen in WordPress
56
 
57
  == Screenshots ==
58
 
59
  1. Generate Upload Field - Admin
60
  2. Form Field Settings - Admin
 
 
 
 
61
 
62
  == Changelog ==
63
 
64
- = 1.0 =
65
- * Initial Release
 
 
 
66
 
67
- = 1.1 =
68
- - This version fixes on user drop validation.
69
- - Optimized Javascript File
 
 
 
70
 
71
- = 1.2 =
72
- - Add admin option to limit the number of files. (Maximum File Upload Limit)
 
73
 
74
  = 1.2.1 =
75
  * Issue - fixed bug when file is not required(*).
76
  * Issue - fixed error on 'wpcf7_mail_components' components hooks when there's no file.
77
 
 
 
 
 
 
 
 
 
 
 
78
  == Upgrade Notice ==
79
 
 
 
 
80
  = 1.2.1 =
81
  This version fixed minor issues and bugs.
82
 
 
 
 
83
  == Donations ==
84
 
85
- Would you like to support the advancement of this plugin? [Donate](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.0
6
+ Stable tag: 1.2.3
7
  Requires PHP: 5.2.4
8
  License: GPLv2 or later
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
19
  * File Type Validation
20
  * File Size Validation
21
  * Ajax Upload
22
+ * Limit number of files Upload.
23
  * Drag & Drop or Browse File - Multiple Upload
24
+ * Support Multiple Drag and Drop in One Form.
25
+ * Attach to email or send as links.
26
  * Mobile Responsive
27
  * Cool Progress Bar
 
28
  * Browser Compatability
29
 
30
  == Frequently Asked Questions ==
49
 
50
  Example : [mfile upload-file-433 filetypes:jpeg|png|jpg|gif]
51
 
52
+ = How can I change text in Drag and Drop Uploading area? =
53
+
54
+ You can change text `Drag & Drop Files Here or Browse Files` text in Wordpress Admin menu under `Contact` > `Drag & Drop Upload`.
55
+
56
+ = How can I change email attachment as links? =
57
+
58
+ Go to WP Admin `Contact->Drag & Drop Upload` settings then check "Send Attachment as links?" option.
59
+
60
+ To manage mail template, go to Contact Forms edit specific form and Select `Mail` tab. In Message Body add generated code from mfile. ( Example Below )
61
+
62
+ Message Body : [your-message]
63
+
64
+ File Links 1 : [upload-file-754]
65
+
66
+ File Links2 : [upload-file-755]
67
+
68
+ Note : No need to add in `File Attachments` field.
69
+
70
  == Installation ==
71
 
72
  To install this plugin see below:
73
 
74
+ 1. Upload the plugin files to the `/wp-content/plugins/drag-and-drop-multiple-file-upload-contact-form-7.zip` directory, or install the plugin through the WordPress plugins screen directly.
75
  2. Activate the plugin through the 'Plugins' screen in WordPress
76
 
77
  == Screenshots ==
78
 
79
  1. Generate Upload Field - Admin
80
  2. Form Field Settings - Admin
81
+ 3. Uploader Settings - Admin
82
+ 4. Email Attachment- Gmail
83
+ 5. Email Attachment As links - Gmail
84
+ 6. Multiple Drag and Drop Fields - Front
85
 
86
  == Changelog ==
87
 
88
+ = 1.2.3 =
89
+ * Added - Multiple Drag and Drop fields in a form
90
+ * Added - Options in admin for error message
91
+ * Added - Option that allow user to send attachment as links
92
+ * Added - Added new folder name `wp_dndcf7_uploads` to separate files from wpcf7_uploads ( When option 'Send Attachment as links?' is check ).
93
 
94
+ = 1.2.2 =
95
+ * Add - Create admin settings where you can manage or change text in your uploading area. It's under 'contacts' > 'Drag and Drop'.
96
+ * New - Empty or Clear attachment file when Contact Form successfully send.
97
+ * Fixes - Fixed remove item bugs when file is greater than file limit.
98
+ * Fixes - Changed 'icon-moon' fonts to avoid conflict with the other themes.
99
+ * New - Added text domain for language translations.
100
 
101
+ = 1.2.2 =
102
+ * Issue - fixed bug when file is not required(*).
103
+ * Issue - fixed error on 'wpcf7_mail_components' components hooks when there's no file.
104
 
105
  = 1.2.1 =
106
  * Issue - fixed bug when file is not required(*).
107
  * Issue - fixed error on 'wpcf7_mail_components' components hooks when there's no file.
108
 
109
+ = 1.2 =
110
+ - Add admin option to limit the number of files. (Maximum File Upload Limit)
111
+
112
+ = 1.1 =
113
+ - This version fixes on user drop validation.
114
+ - Optimized Javascript File
115
+
116
+ = 1.0 =
117
+ * Initial Release
118
+
119
  == Upgrade Notice ==
120
 
121
+ = 1.2.3 =
122
+ This version fixed minor issues/bugs and add multiple drag and drop fields in a form.
123
+
124
  = 1.2.1 =
125
  This version fixed minor issues and bugs.
126
 
127
+ = 1.2.2 =
128
+ Added some usefull features.
129
+
130
  == Donations ==
131
 
132
+ Would you like to support the advancement of this plugin? [Donate](http://codedropz.com/donation)