From 97f72bf6f6ea5e8bcce063e676521dd57403c6bf Mon Sep 17 00:00:00 2001 From: Deependra Chaudhary Date: Fri, 30 Aug 2024 15:45:49 +0545 Subject: [PATCH 1/2] Enhancement- send File directly to cloud --- .../class-evf-form-fields-upload.php | 80 ++++++++++++++++++- includes/class-evf-emails.php | 16 ++++ 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/includes/abstracts/class-evf-form-fields-upload.php b/includes/abstracts/class-evf-form-fields-upload.php index dc4754685..7db15a22f 100644 --- a/includes/abstracts/class-evf-form-fields-upload.php +++ b/includes/abstracts/class-evf-form-fields-upload.php @@ -1287,10 +1287,15 @@ public function max_file_size() { public function send_file_as_email_attachment( $attachment, $entry, $form_data, $context, $connection_id, $entry_id ) { $file_email_attachments = isset( $form_data['settings']['email'][ $connection_id ]['file-email-attachments'] ) ? $form_data['settings']['email'][ $connection_id ]['file-email-attachments'] : 0; - if ( '1' !== $file_email_attachments ) { + if ( isset( $form_data['settings']['disabled_entries'] ) && '1' === $form_data['settings']['disabled_entries'] ) { + $attachment = $this->attach_entry_files_upload( $entry ); + } + + if ( '1' === $file_email_attachments ) { + $attachment = array_unique( array_merge( (array) $attachment, $this->attach_entry_files( $entry_id ) ) ); return $attachment; } - $attachment = array_unique( array_merge( (array) $attachment, $this->attach_entry_files( $entry_id ) ) ); + return $attachment; } @@ -1325,22 +1330,52 @@ public function send_csv_file_as_email_attachment( $attachment, $entry, $form_da * @param integer $entry_id Entry id for the form. */ public function remove_csv_file_after_email_send( $attachment, $entry, $form_data, $context, $connection_id, $entry_id ) { + + if ( isset( $form_data['settings']['disabled_entries'] ) && '1' === $form_data['settings']['disabled_entries'] ) { + if ( ! empty( $entry ) && is_array( $entry ) ) { + foreach ( $entry as $meta_key => $meta_value ) { + if ( empty( $meta_value ) ) { + continue; + } + + if ( preg_match( '/signature_/', $meta_key ) && file_exists( $meta_value ) ) { + unlink( $meta_value ); + } + + if ( isset( $meta_value['type'] ) && 'file-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) ) { + foreach ( $meta_value['value_raw'] as $file_data ) { + if ( isset( $file_data['value'] ) ) { + $file_url = $file_data['value']; + + $uploaded_file = ABSPATH . preg_replace( '/.*wp-content/', 'wp-content', wp_parse_url( $file_url, PHP_URL_PATH ) ); + if ( file_exists( $uploaded_file ) ) { + unlink( $uploaded_file ); + } + } + } + } + } + } + } + if ( ! $entry_id ) { return; } + $file_email_attachments = isset( $form_data['settings']['email'][ $connection_id ]['file-email-attachments'] ) ? $form_data['settings']['email'][ $connection_id ]['file-email-attachments'] : 0; $csv_file_email_attachments = isset( $form_data['settings']['email'][ $connection_id ]['csv-file-email-attachments'] ) ? $form_data['settings']['email'][ $connection_id ]['csv-file-email-attachments'] : 0; $csv_file_email_attachments = apply_filters( 'everest_forms_change_csv_attachments', $csv_file_email_attachments ); if ( '1' === $csv_file_email_attachments ) { - $get_entry = evf_get_entry( $entry_id, 'meta' ); $upload_dir = WP_CONTENT_DIR . '/uploads/Everes-Froms-Entries-CSV-file/'; - $csv_path = $upload_dir . 'Entry data-' . $get_entry->entry_id . '.csv'; + $csv_path = $upload_dir . 'Entry data-' . $entry_id . '.csv'; if ( file_exists( $csv_path ) ) { unlink( $csv_path ); } } + } + /** * Attach the entry file. * @@ -1377,6 +1412,43 @@ public function attach_entry_files( $entry_id ) { return $entry_files; } + /** + * Attach the entry file. + * + * @param int $entry Entry for which file should be attached. + */ + public function attach_entry_files_upload( $entry ) { + $entry_files = array(); + + if ( ! empty( $entry ) && is_array( $entry ) ) { + foreach ( $entry as $meta_key => $meta_value ) { + if ( empty( $meta_value ) ) { + continue; + } + + if ( preg_match( '/signature_/', $meta_key ) ) { + if ( file_exists( $meta_value ) ) { + $entry_files[] = $meta_value; + } + } elseif ( isset( $meta_value['type'] ) && 'file-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) ) { + foreach ( $meta_value['value_raw'] as $file_data ) { + if ( isset( $file_data['value'] ) ) { + $file_url = $file_data['value']; + $uploaded_file = ABSPATH . preg_replace( '/.*wp-content/', 'wp-content', wp_parse_url( $file_url, PHP_URL_PATH ) ); + + if ( ! in_array( $uploaded_file, $entry_files ) && file_exists( $uploaded_file ) ) { + $entry_files[] = $uploaded_file; + } + } + } + } + } + } + + return $entry_files; + } + + /** * Attach the csv file. * diff --git a/includes/class-evf-emails.php b/includes/class-evf-emails.php index b5c5d8779..96d12cff1 100644 --- a/includes/class-evf-emails.php +++ b/includes/class-evf-emails.php @@ -449,6 +449,7 @@ public function everest_forms_html_field_value( $html = true ) { $message = ''; if ( $html ) { + /* * HTML emails. */ @@ -464,6 +465,13 @@ public function everest_forms_html_field_value( $html = true ) { $field_iterator = 1; foreach ( $this->fields as $meta_id => $field ) { + + if ( isset( $this->form_data['settings']['disabled_entries'] ) && '1' === $this->form_data['settings']['disabled_entries'] ) { + $types_to_remove = array( 'image-upload', 'file-upload', 'signature' ); + if ( isset( $field['type'] ) && in_array( $field['type'], $types_to_remove, true ) ) { + continue; + } + } if ( ! apply_filters( 'everest_forms_email_display_empty_fields', false ) && ( empty( $field['value'] ) && '0' !== $field['value'] ) @@ -572,6 +580,14 @@ public function everest_forms_html_field_value( $html = true ) { * Plain Text emails. */ foreach ( $this->fields as $field ) { + + if ( isset( $this->form_data['settings']['disabled_entries'] ) && '1' === $this->form_data['settings']['disabled_entries'] ) { + $types_to_remove = array( 'image-upload', 'file-upload', 'signature' ); + if ( isset( $field['type'] ) && in_array( $field['type'], $types_to_remove, true ) ) { + continue; + } + } + if ( ! apply_filters( 'everest_forms_email_display_empty_fields', false ) && ( empty( $field['value'] ) && '0' !== $field['value'] ) ) { continue; } From 643402f078a2f75a0f0dbcda5f5e262d7dfde2d1 Mon Sep 17 00:00:00 2001 From: Deependra Chaudhary Date: Wed, 4 Sep 2024 13:52:19 +0545 Subject: [PATCH 2/2] Added - Support for image upload --- includes/abstracts/class-evf-form-fields-upload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/abstracts/class-evf-form-fields-upload.php b/includes/abstracts/class-evf-form-fields-upload.php index 7db15a22f..70ecf04ef 100644 --- a/includes/abstracts/class-evf-form-fields-upload.php +++ b/includes/abstracts/class-evf-form-fields-upload.php @@ -1342,7 +1342,7 @@ public function remove_csv_file_after_email_send( $attachment, $entry, $form_dat unlink( $meta_value ); } - if ( isset( $meta_value['type'] ) && 'file-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) ) { + if ( isset( $meta_value['type'] ) && ( 'file-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) || 'image-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) ) ) { foreach ( $meta_value['value_raw'] as $file_data ) { if ( isset( $file_data['value'] ) ) { $file_url = $file_data['value']; @@ -1430,7 +1430,7 @@ public function attach_entry_files_upload( $entry ) { if ( file_exists( $meta_value ) ) { $entry_files[] = $meta_value; } - } elseif ( isset( $meta_value['type'] ) && 'file-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) ) { + } elseif ( isset( $meta_value['type'] ) && ( 'file-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) || 'image-upload' === $meta_value['type'] && isset( $meta_value['value_raw'] ) ) ) { foreach ( $meta_value['value_raw'] as $file_data ) { if ( isset( $file_data['value'] ) ) { $file_url = $file_data['value'];