Edit File by line
/home/barbar84/www/wp-conte.../plugins/pjtpjma/inc
File: dnd-upload-cf7.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* @Description : Plugin main core
[3] Fix | Delete
* @Package : Drag & Drop Multiple File Upload - Contact Form 7
[4] Fix | Delete
* @Author : Glen Don L. Mongaya
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
if ( ! defined( 'ABSPATH' ) || ! defined('dnd_upload_cf7') ) {
[8] Fix | Delete
exit;
[9] Fix | Delete
}
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Begin : begin plugin hooks
[13] Fix | Delete
*/
[14] Fix | Delete
[15] Fix | Delete
add_action( 'wpcf7_init', 'dnd_cf7_upload_add_form_tag_file' );
[16] Fix | Delete
add_action( 'wpcf7_enqueue_scripts', 'dnd_cf7_scripts' );
[17] Fix | Delete
[18] Fix | Delete
// Hook on plugins loaded
[19] Fix | Delete
add_action('plugins_loaded','dnd_cf7_upload_plugins_loaded');
[20] Fix | Delete
[21] Fix | Delete
// Ajax Upload
[22] Fix | Delete
add_action( 'wp_ajax_dnd_codedropz_upload', 'dnd_upload_cf7_upload' );
[23] Fix | Delete
add_action( 'wp_ajax_nopriv_dnd_codedropz_upload', 'dnd_upload_cf7_upload' );
[24] Fix | Delete
[25] Fix | Delete
// Hook - Ajax Delete
[26] Fix | Delete
add_action('wp_ajax_nopriv_dnd_codedropz_upload_delete', 'dnd_codedropz_upload_delete');
[27] Fix | Delete
add_action('wp_ajax_dnd_codedropz_upload_delete','dnd_codedropz_upload_delete');
[28] Fix | Delete
[29] Fix | Delete
// Ajax Nonce check
[30] Fix | Delete
add_action('wp_ajax__wpcf7_check_nonce', 'dnd_wpcf7_nonce_check');
[31] Fix | Delete
add_action('wp_ajax_nopriv__wpcf7_check_nonce', 'dnd_wpcf7_nonce_check');
[32] Fix | Delete
[33] Fix | Delete
// Hook mail cf7
[34] Fix | Delete
add_filter('wpcf7_posted_data', 'dnd_wpcf7_posted_data', 10, 1);
[35] Fix | Delete
add_action('wpcf7_before_send_mail','dnd_cf7_before_send_mail', 30, 1);
[36] Fix | Delete
add_action('wpcf7_mail_components','dnd_cf7_mail_components', 50, 2);
[37] Fix | Delete
[38] Fix | Delete
// Auto clean up dir/files
[39] Fix | Delete
add_action('template_redirect', 'dnd_cf7_auto_clean_dir', 20, 0 );
[40] Fix | Delete
[41] Fix | Delete
// Add row meta links
[42] Fix | Delete
add_filter( 'plugin_row_meta', 'dnd_custom_plugin_row_meta', 10, 2 );
[43] Fix | Delete
[44] Fix | Delete
// Add custom mime-type
[45] Fix | Delete
add_filter('upload_mimes', 'dnd_extra_mime_types', 1, 1);
[46] Fix | Delete
[47] Fix | Delete
// Plugin settings
[48] Fix | Delete
add_filter( 'plugin_action_links_' . plugin_basename( dnd_upload_cf7_directory ) .'/drag-n-drop-upload-cf7.php', 'dnd_cf7_upload_links' );
[49] Fix | Delete
[50] Fix | Delete
// Add Submenu - Settings
[51] Fix | Delete
add_action('admin_menu', 'dnd_admin_settings');
[52] Fix | Delete
[53] Fix | Delete
// Add custom script in footer
[54] Fix | Delete
add_action('wp_footer','dnd_custom_scripts');
[55] Fix | Delete
[56] Fix | Delete
// Flamingo Hooks
[57] Fix | Delete
add_action('before_delete_post', 'dnd_remove_uploaded_files');
[58] Fix | Delete
[59] Fix | Delete
// Nonce
[60] Fix | Delete
function dnd_wpcf7_nonce_check(){
[61] Fix | Delete
if( ! check_ajax_referer( 'dnd-cf7-security-nonce', false, false ) ){
[62] Fix | Delete
wp_send_json_success( wp_create_nonce( "dnd-cf7-security-nonce" ) );
[63] Fix | Delete
}
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
// Add links to settings
[67] Fix | Delete
function dnd_cf7_upload_links( $actions ) {
[68] Fix | Delete
$upload_links = array('<a href="' . admin_url( 'admin.php?page=drag-n-drop-upload' ) . '">Settings</a>',);
[69] Fix | Delete
$actions = array_merge( $upload_links, $actions );
[70] Fix | Delete
return $actions;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
// Load plugin text-domain
[74] Fix | Delete
function dnd_cf7_upload_plugins_loaded() {
[75] Fix | Delete
[76] Fix | Delete
// Load language domain
[77] Fix | Delete
load_plugin_textdomain( 'drag-and-drop-multiple-file-upload-contact-form-7', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages' );
[78] Fix | Delete
[79] Fix | Delete
// Create dir
[80] Fix | Delete
$dir = dnd_get_upload_dir();
[81] Fix | Delete
if( isset( $dir['upload_dir'] ) && is_dir( $dir['upload_dir'] ) ) {
[82] Fix | Delete
// Generate .htaccess file`
[83] Fix | Delete
$htaccess_file = path_join( dirname( $dir['upload_dir'] ), '.htaccess' );
[84] Fix | Delete
if ( ! file_exists( $htaccess_file ) ) {
[85] Fix | Delete
if ( $handle = fopen( $htaccess_file, 'w' ) ) {
[86] Fix | Delete
fwrite( $handle, "Options -Indexes \n <Files *.php> \n deny from all \n </Files>" );
[87] Fix | Delete
fclose( $handle );
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
// fix spam
[93] Fix | Delete
if( get_option('drag_n_drop_fix_spam') == 'yes' ) {
[94] Fix | Delete
add_filter('wpcf7_spam', function(){
[95] Fix | Delete
return false;
[96] Fix | Delete
});
[97] Fix | Delete
}
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
// Remove uploaded files when item is deleted permanently.
[101] Fix | Delete
function dnd_remove_uploaded_files( $post_id ) {
[102] Fix | Delete
$post_type = get_post_type( $post_id );
[103] Fix | Delete
$page = get_post( $post_id );
[104] Fix | Delete
if( $post_type == 'flamingo_inbound' ) {
[105] Fix | Delete
preg_match_all( '/(.*?)(\/'.wpcf7_dnd_dir.'\/wpcf7-files\/.*$)/m', $page->post_content, $matches );
[106] Fix | Delete
if( $matches[0] && count( $matches[0] ) > 0 ) {
[107] Fix | Delete
foreach( $matches[0] as $files ) {
[108] Fix | Delete
$new_file = str_replace( site_url().'/', wp_normalize_path( ABSPATH ), $files );
[109] Fix | Delete
if( file_exists( $new_file ) ) {
[110] Fix | Delete
wp_delete_file( $new_file );
[111] Fix | Delete
}
[112] Fix | Delete
}
[113] Fix | Delete
}
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
// Modify contact form posted_data
[118] Fix | Delete
function dnd_wpcf7_posted_data( $posted_data ){
[119] Fix | Delete
[120] Fix | Delete
// Subbmisson instance from CF7
[121] Fix | Delete
$submission = WPCF7_Submission::get_instance();
[122] Fix | Delete
[123] Fix | Delete
// Make sure we have the data
[124] Fix | Delete
if ( ! $posted_data ) {
[125] Fix | Delete
$posted_data = $submission->get_posted_data();
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
// Scan and get all form tags from cf7 generator
[129] Fix | Delete
$forms_tags = $submission->get_contact_form();
[130] Fix | Delete
$uploads_dir = dnd_get_upload_dir();
[131] Fix | Delete
[132] Fix | Delete
if( $forms = $forms_tags->scan_form_tags() ) {
[133] Fix | Delete
foreach( $forms as $field ) {
[134] Fix | Delete
$field_name = $field->name;
[135] Fix | Delete
if( $field->basetype == 'mfile' && isset( $posted_data[$field_name] ) && ! empty( $posted_data[$field_name] ) ) {
[136] Fix | Delete
foreach( $posted_data[$field_name] as $key => $file ) {
[137] Fix | Delete
$posted_data[$field_name][$key] = trailingslashit( $uploads_dir['upload_url'] ) . wp_basename( $file );
[138] Fix | Delete
}
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
return $posted_data;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
// Hooks for admin settings
[147] Fix | Delete
function dnd_admin_settings() {
[148] Fix | Delete
add_submenu_page( 'wpcf7', 'Drag & Drop Uploader - Settings', 'Drag & Drop Upload', 'manage_options', 'drag-n-drop-upload','dnd_upload_admin_settings');
[149] Fix | Delete
add_action('admin_init','dnd_upload_register_settings');
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
// Add custom mime-types
[153] Fix | Delete
function dnd_extra_mime_types( $mime_types ){
[154] Fix | Delete
$mime_types['xls'] = 'application/excel, application/vnd.ms-excel, application/x-excel, application/x-msexcel';
[155] Fix | Delete
$mime_types['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
[156] Fix | Delete
return $mime_types;
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
// Default Error Message
[160] Fix | Delete
function dnd_cf7_error_msg( $error_key ) {
[161] Fix | Delete
[162] Fix | Delete
// Array of default error message
[163] Fix | Delete
$errors = array(
[164] Fix | Delete
'server_limit' => __('The uploaded file exceeds the maximum upload size of your server.','drag-and-drop-multiple-file-upload-contact-form-7'),
[165] Fix | Delete
'failed_upload' => __('Uploading a file fails for any reason','drag-and-drop-multiple-file-upload-contact-form-7'),
[166] Fix | Delete
'large_file' => __('Uploaded file is too large','drag-and-drop-multiple-file-upload-contact-form-7'),
[167] Fix | Delete
'invalid_type' => __('Uploaded file is not allowed for file type','drag-and-drop-multiple-file-upload-contact-form-7'),
[168] Fix | Delete
'max_file_limit' => __('Note : Some of the files are not uploaded ( Only %count% files allowed )','drag-and-drop-multiple-file-upload-contact-form-7'),
[169] Fix | Delete
'required' => __('This field is required.', 'drag-and-drop-multiple-file-upload-contact-form-7' ),
[170] Fix | Delete
'min_file' => __('The minimum file upload is','drag-and-drop-multiple-file-upload-contact-form-7'),
[171] Fix | Delete
);
[172] Fix | Delete
[173] Fix | Delete
// return error message based on $error_key request
[174] Fix | Delete
if( isset( $errors[ $error_key ] ) ) {
[175] Fix | Delete
return $errors[ $error_key ];
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
return false;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
// Get folder path
[182] Fix | Delete
function dnd_get_upload_dir() {
[183] Fix | Delete
$upload = wp_upload_dir();
[184] Fix | Delete
$uploads_dir = wpcf7_dnd_dir . '/wpcf7-files';
[185] Fix | Delete
[186] Fix | Delete
// If save as attachment ( also : Check if upload use year and month folders )
[187] Fix | Delete
if( get_option('drag_n_drop_mail_attachment') == 'yes' ) {
[188] Fix | Delete
$uploads_dir = ( get_option('uploads_use_yearmonth_folders') ? wpcf7_dnd_dir . $upload['subdir'] : wpcf7_dnd_dir );
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
// Create directory
[192] Fix | Delete
if ( ! is_dir( trailingslashit( $upload['basedir'] ) . $uploads_dir ) ) {
[193] Fix | Delete
wp_mkdir_p( trailingslashit( $upload['basedir'] ) . $uploads_dir );
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
// Make sure directory exist before returning
[197] Fix | Delete
if( file_exists( trailingslashit( $upload['basedir'] ) . $uploads_dir ) ) {
[198] Fix | Delete
return array(
[199] Fix | Delete
'upload_dir' => trailingslashit( $upload['basedir'] ) . $uploads_dir,
[200] Fix | Delete
'upload_url' => trailingslashit( $upload['baseurl'] ) . $uploads_dir
[201] Fix | Delete
);
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
return trailingslashit( $upload['basedir'] ) . $uploads_dir;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
// Clean up directory - From Contact Form 7
[208] Fix | Delete
function dnd_cf7_auto_clean_dir( $seconds = 3600, $max = 60 ) {
[209] Fix | Delete
if ( is_admin() || 'GET' != $_SERVER['REQUEST_METHOD'] || is_robots() || is_feed() || is_trackback() ) {
[210] Fix | Delete
return;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
// Disable auto delete
[214] Fix | Delete
if( get_option('drag_n_drop_disable_auto_delete') == 'yes' ) {
[215] Fix | Delete
return;
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
// Setup dirctory path
[219] Fix | Delete
$upload = wp_upload_dir();
[220] Fix | Delete
$dir = trailingslashit( $upload['basedir'] ) . wpcf7_dnd_dir . '/wpcf7-files/';
[221] Fix | Delete
[222] Fix | Delete
// Make sure dir is readable or writable
[223] Fix | Delete
if ( ! is_dir( $dir ) || ! is_readable( $dir ) || ! wp_is_writable( $dir ) ) {
[224] Fix | Delete
return;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
$seconds = apply_filters( 'dnd_cf7_auto_delete_files', $seconds );
[228] Fix | Delete
$max = absint( $max );
[229] Fix | Delete
$count = 0;
[230] Fix | Delete
[231] Fix | Delete
if ( $handle = @opendir( $dir ) ) {
[232] Fix | Delete
while ( false !== ( $file = readdir( $handle ) ) ) {
[233] Fix | Delete
if ( $file == "." || $file == ".." ) {
[234] Fix | Delete
continue;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
// Get file time of files OLD files.
[238] Fix | Delete
$mtime = @filemtime( $dir . $file );
[239] Fix | Delete
[240] Fix | Delete
if ( $mtime && time() < $mtime + absint( $seconds ) ) { // less than $seconds old
[241] Fix | Delete
continue;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
// Delete files from dir
[245] Fix | Delete
if( $file != '.htaccess' ) {
[246] Fix | Delete
wp_delete_file( $dir . $file );
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
$count += 1;
[250] Fix | Delete
[251] Fix | Delete
if ( $max <= $count ) {
[252] Fix | Delete
break;
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
@closedir( $handle );
[256] Fix | Delete
}
[257] Fix | Delete
@rmdir( $dir );
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
// Hooks before sending the email - ( append links to body email )
[261] Fix | Delete
function dnd_cf7_before_send_mail( $wpcf7 ){
[262] Fix | Delete
global $_mail;
[263] Fix | Delete
[264] Fix | Delete
// Get upload path / dir
[265] Fix | Delete
$upload_path = dnd_get_upload_dir();
[266] Fix | Delete
[267] Fix | Delete
// Mail Counter
[268] Fix | Delete
$_mail = 0;
[269] Fix | Delete
[270] Fix | Delete
// Check If send attachment as link
[271] Fix | Delete
if( ! get_option('drag_n_drop_mail_attachment') ) {
[272] Fix | Delete
return $wpcf7;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
// cf7 instance
[276] Fix | Delete
$submission = WPCF7_Submission::get_instance();
[277] Fix | Delete
[278] Fix | Delete
// Check for submission
[279] Fix | Delete
if( $submission ) {
[280] Fix | Delete
[281] Fix | Delete
// Get posted data
[282] Fix | Delete
$submitted['posted_data'] = $submission->get_posted_data();
[283] Fix | Delete
[284] Fix | Delete
// Parse fields
[285] Fix | Delete
$fields = $wpcf7->scan_form_tags();
[286] Fix | Delete
[287] Fix | Delete
// Links
[288] Fix | Delete
$links = array();
[289] Fix | Delete
[290] Fix | Delete
// Prop email
[291] Fix | Delete
$mail = $wpcf7->prop('mail');
[292] Fix | Delete
$mail_2 = $wpcf7->prop('mail_2');
[293] Fix | Delete
[294] Fix | Delete
// Default upload path
[295] Fix | Delete
$simple_path = dirname( $upload_path['upload_url'] ); // dirname - remove duplicate form dir (/wpcf-dnd-uploads/wpcf7-dnd-uploads/example.jpg)
[296] Fix | Delete
[297] Fix | Delete
// Loop fields and replace mfile code
[298] Fix | Delete
foreach( $fields as $field ) {
[299] Fix | Delete
if( $field->basetype == 'mfile') {
[300] Fix | Delete
if( isset( $submitted['posted_data'][$field->name] ) && ! empty( $submitted['posted_data'][$field->name] ) ) {
[301] Fix | Delete
[302] Fix | Delete
// Get posted_data files
[303] Fix | Delete
$files = $submitted['posted_data'][$field->name];
[304] Fix | Delete
[305] Fix | Delete
// Links - 1
[306] Fix | Delete
$mail_links = dnd_cf7_links( $files, $mail['use_html'] );
[307] Fix | Delete
$mail['body'] = str_replace( "[$field->name]", "\n" . implode( "\n", $mail_links ), $mail['body'] );
[308] Fix | Delete
[309] Fix | Delete
// Links - 2
[310] Fix | Delete
if( $mail_2['active'] ) {
[311] Fix | Delete
$mail_links_2 = dnd_cf7_links( $files, $mail_2['use_html'] );
[312] Fix | Delete
$mail_2['body'] = str_replace( "[$field->name]", "\n" . implode( "\n", $mail_links_2 ), $mail_2['body'] );
[313] Fix | Delete
}
[314] Fix | Delete
}
[315] Fix | Delete
}
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
// Save the email body
[319] Fix | Delete
$wpcf7->set_properties( array("mail" => $mail) );
[320] Fix | Delete
[321] Fix | Delete
// if mail 2
[322] Fix | Delete
if( $mail_2['active'] ) {
[323] Fix | Delete
$wpcf7->set_properties( array("mail_2" => $mail_2) );
[324] Fix | Delete
}
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
return $wpcf7;
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
// Get file links.
[331] Fix | Delete
function dnd_cf7_links( $files, $use_html = false) {
[332] Fix | Delete
[333] Fix | Delete
// check and make sure we have files
[334] Fix | Delete
if( ! $files ) {
[335] Fix | Delete
return;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
// Setup html links
[339] Fix | Delete
$links = array();
[340] Fix | Delete
foreach( $files as $file ) {
[341] Fix | Delete
$links[] = ( $use_html ? '<a href="'. esc_url( $file ) .'">'. wp_basename( $file ) .'</a>' : $file );
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
// Allow other themes/plugin to modify data.
[345] Fix | Delete
return apply_filters('dndcf7_before_send_files', $links, $files );
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
// Log message...
[349] Fix | Delete
function dnd_logs( $message, $email = false ) {
[350] Fix | Delete
$uploads_dir = dnd_get_upload_dir();
[351] Fix | Delete
$file = fopen( $uploads_dir['upload_dir']."/logs.txt", "a") or die("Unable to open file!");
[352] Fix | Delete
fwrite( $file, "\n". ( is_array( $message ) ? print_r( $message, true ) : $message ) );
[353] Fix | Delete
fclose( $file );
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
// hooks - Custom cf7 Mail components ( Attached File on Email )
[357] Fix | Delete
function dnd_cf7_mail_components( $components, $form ) {
[358] Fix | Delete
global $_mail;
[359] Fix | Delete
[360] Fix | Delete
if( ! $form ) {
[361] Fix | Delete
return;
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
// Get upload directory
[365] Fix | Delete
$uploads_dir = dnd_get_upload_dir();
[366] Fix | Delete
[367] Fix | Delete
// cf7 - Submission Object
[368] Fix | Delete
$submission = WPCF7_Submission::get_instance();
[369] Fix | Delete
[370] Fix | Delete
// get all form fields
[371] Fix | Delete
$fields = $form->scan_form_tags();
[372] Fix | Delete
[373] Fix | Delete
// Send email link as an attachment.
[374] Fix | Delete
if( get_option('drag_n_drop_mail_attachment') == 'yes' ) {
[375] Fix | Delete
return $components;
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
// Get mail,mail_2 attachment [tags]
[379] Fix | Delete
$mail = array('mail','mail_2');
[380] Fix | Delete
$props_mail = array();
[381] Fix | Delete
[382] Fix | Delete
foreach( $mail as $single_mail ) {
[383] Fix | Delete
$props_mail[] = $form->prop( $single_mail );
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
// Get email attachments (mail, mail_2)
[387] Fix | Delete
$mail = $props_mail[ $_mail ];
[388] Fix | Delete
if( $mail['active'] && $mail['attachments'] ) {
[389] Fix | Delete
[390] Fix | Delete
// Loop fields get mfile only.
[391] Fix | Delete
foreach( $fields as $field ) {
[392] Fix | Delete
[393] Fix | Delete
// If field type equal to mfile which our default field.
[394] Fix | Delete
if( $field->basetype == 'mfile') {
[395] Fix | Delete
[396] Fix | Delete
// Make sure we have files to attach
[397] Fix | Delete
if( isset( $_POST[ $field->name ] ) && count( $_POST[ $field->name ] ) > 0 ) {
[398] Fix | Delete
[399] Fix | Delete
// Check and make sure [upload-file-xxx] exists in attachments - fields
[400] Fix | Delete
if ( false !== strpos( $mail['attachments'], "[{$field->name}]" ) ) {
[401] Fix | Delete
[402] Fix | Delete
// Loop all the files and attach to cf7 components
[403] Fix | Delete
foreach( $_POST[ $field->name ] as $_file ) {
[404] Fix | Delete
[405] Fix | Delete
// Join dir and a new file name ( get from <input type="hidden" name="upload-file-333"> )
[406] Fix | Delete
$new_file_name = trailingslashit( $uploads_dir['upload_dir'] ) . wp_basename( $_file );
[407] Fix | Delete
[408] Fix | Delete
// Check if submitted and file exists then file is ready.
[409] Fix | Delete
if ( $submission && file_exists( $new_file_name ) ) {
[410] Fix | Delete
$components['attachments'][] = $new_file_name;
[411] Fix | Delete
}
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
}
[415] Fix | Delete
}
[416] Fix | Delete
}
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
// Increment mail counter
[422] Fix | Delete
$_mail = $_mail + 1;
[423] Fix | Delete
[424] Fix | Delete
// Return setup components
[425] Fix | Delete
return $components;
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
// Load js and css
[429] Fix | Delete
function dnd_cf7_scripts() {
[430] Fix | Delete
[431] Fix | Delete
// Get plugin version
[432] Fix | Delete
$version = dnd_upload_cf7_version;
[433] Fix | Delete
[434] Fix | Delete
// enque script
[435] Fix | Delete
wp_enqueue_script( 'codedropz-uploader', plugins_url ('/assets/js/codedropz-uploader-min.js', dirname(__FILE__) ), array('jquery'), $version, true );
[436] Fix | Delete
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 );
[437] Fix | Delete
[438] Fix | Delete
// All data options
[439] Fix | Delete
$data_options = apply_filters('dnd_cf7_data_options',
[440] Fix | Delete
array(
[441] Fix | Delete
'tag' => ( get_option('drag_n_drop_heading_tag') ? get_option('drag_n_drop_heading_tag') : 'h3' ),
[442] Fix | Delete
'text' => ( get_option('drag_n_drop_text') ? get_option('drag_n_drop_text') : __('Drag & Drop Files Here','drag-and-drop-multiple-file-upload-contact-form-7') ),
[443] Fix | Delete
'or_separator' => ( get_option('drag_n_drop_separator') ? get_option('drag_n_drop_separator') : __('or','drag-and-drop-multiple-file-upload-contact-form-7') ),
[444] Fix | Delete
'browse' => ( get_option('drag_n_drop_browse_text') ? get_option('drag_n_drop_browse_text') : __('Browse Files','drag-and-drop-multiple-file-upload-contact-form-7') ),
[445] Fix | Delete
'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') ),
[446] Fix | Delete
'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') ),
[447] Fix | Delete
'inavalid_type' => ( get_option('drag_n_drop_error_invalid_file') ? get_option('drag_n_drop_error_invalid_file') : dnd_cf7_error_msg('invalid_type') ),
[448] Fix | Delete
'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') ),
[449] Fix | Delete
'required' => dnd_cf7_error_msg('required'),
[450] Fix | Delete
'delete' => array(
[451] Fix | Delete
'text' => __('deleting','drag-and-drop-multiple-file-upload-contact-form-7'),
[452] Fix | Delete
'title' => __('Remove','drag-and-drop-multiple-file-upload-contact-form-7')
[453] Fix | Delete
)
[454] Fix | Delete
)
[455] Fix | Delete
);
[456] Fix | Delete
[457] Fix | Delete
// registered script with data for a JavaScript variable.
[458] Fix | Delete
wp_localize_script( 'dnd-upload-cf7', 'dnd_cf7_uploader',
[459] Fix | Delete
array(
[460] Fix | Delete
'ajax_url' => admin_url( 'admin-ajax.php' ),
[461] Fix | Delete
'ajax_nonce' => wp_create_nonce( "dnd-cf7-security-nonce" ),
[462] Fix | Delete
'drag_n_drop_upload' => $data_options,
[463] Fix | Delete
'dnd_text_counter' => __('of','drag-and-drop-multiple-file-upload-contact-form-7'),
[464] Fix | Delete
'disable_btn' => ( get_option('drag_n_drop_disable_btn') == 'yes' ? true : false )
[465] Fix | Delete
)
[466] Fix | Delete
);
[467] Fix | Delete
[468] Fix | Delete
// enque style
[469] Fix | Delete
wp_enqueue_style( 'dnd-upload-cf7', plugins_url ('/assets/css/dnd-upload-cf7.css', dirname(__FILE__) ), '', $version );
[470] Fix | Delete
}
[471] Fix | Delete
[472] Fix | Delete
// Generate tag
[473] Fix | Delete
function dnd_cf7_upload_add_form_tag_file() {
[474] Fix | Delete
wpcf7_add_form_tag( array( 'mfile ', 'mfile*'), 'dnd_cf7_upload_form_tag_handler', array( 'name-attr' => true ) );
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
// Form tag handler from the tag - callback
[478] Fix | Delete
function dnd_cf7_upload_form_tag_handler( $tag ) {
[479] Fix | Delete
[480] Fix | Delete
// check and make sure tag name is not empty
[481] Fix | Delete
if ( empty( $tag->name ) ) {
[482] Fix | Delete
return '';
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
// Validate our fields
[486] Fix | Delete
$validation_error = wpcf7_get_validation_error( $tag->name );
[487] Fix | Delete
[488] Fix | Delete
// Generate class
[489] Fix | Delete
$class = wpcf7_form_controls_class( 'drag-n-drop-file d-none' );
[490] Fix | Delete
[491] Fix | Delete
// Add not-valid class if there's an error.
[492] Fix | Delete
if ( $validation_error ) {
[493] Fix | Delete
$class .= ' wpcf7-not-valid';
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
// Get current form Object
[497] Fix | Delete
$form = WPCF7_ContactForm::get_current();
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function