Skip to content

Commit b5eb0d1

Browse files
author
Gravity Forms
committedMay 29, 2024
Updates to 3.2.0
1 parent ea6bcc2 commit b5eb0d1

37 files changed

+353
-154
lines changed
 

‎change_log.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### 3.2.0 | 2024-05-28
2+
- Updated the [gform_dropbox_folder_path](https://docs.gravityforms.com/gform_dropbox_folder_path/) filter to include `$file_url` as the sixth parameter.
3+
- Updated the status indicator component to be compatible with Gravity Forms version 2.8.8.
4+
- Fixed an issue where files uploaded to Dropbox are not attached when the attachments setting is enabled on the form submission notification.
5+
- Fixed layout issues with the Dropbox field when compact view is enabled in the form editor.
6+
- Fixed an issue where site admins are unable to reconnect after a custom app is deleted in Dropbox.
7+
8+
19
### 3.1 | 2022-02-17
210
- Added the [gform_dropbox_should_upload_file](https://docs.gravityforms.com/gform_dropbox_should_upload_file/) filter.
311
- Fixed an issue where the upload is attempted again for existing files if the feed is reprocessed by other add-ons.

‎class-gf-dropbox.php

Lines changed: 202 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ public function init_ajax() {
275275
// Add AJAX callback for de-authorizing with Dropbox.
276276
add_action( 'wp_ajax_gfdropbox_deauthorize', array( $this, 'ajax_deauthorize' ) );
277277

278+
// Add AJAX callback for removing the access token so that the user can re-authorize.
279+
add_action( 'wp_ajax_gfdropbox_remove_access_token', array( $this, 'ajax_remove_access_token' ) );
280+
278281
// Add AJAX callback for checking app key/secret validity.
279282
add_action( 'wp_ajax_gfdropbox_valid_app_key_secret', array( $this, 'ajax_is_valid_app_key_secret' ) );
280283

@@ -725,29 +728,28 @@ public function settings_auth_token_button( $field, $echo = true ) {
725728
// Get account information.
726729
$account = $this->api->get_current_account();
727730

728-
$html .= '<p>';
729-
$html .= sprintf(
730-
// Translators: 1. Link to forms list page, 2. Closing </a> tag
731-
esc_html__( 'To configure Dropbox with your form(s), choose a form you wish to use Dropbox with from the %sforms list page%s, and select Dropbox from the form settings menu.', 'gravityformsdropbox' ),
732-
'<a href="?page=gf_edit_forms">',
733-
'</a>'
734-
);
735-
$html .= '</p>';
736-
$html .= '<p><strong>' . esc_html__( 'Dropbox Account Status' ) . '</strong></p>';
737-
$html .= '<p><span class="gform-status-indicator gform-status--active">';
738-
if ( $this->is_gravityforms_supported( '2.5' ) ) {
739-
$html .= '<svg viewBox="0 0 6 6" xmlns="http://www.w3.org/2000/svg"><circle cx="3" cy="2" r="1" stroke-width="2"/></svg>';
740-
}
741-
if ( isset( $account->name ) ) {
742-
$html .= esc_html__( 'Connected to Dropbox as: ', 'gravityformsdropbox' );
743-
$html .= esc_html( $account->name->display_name ) . '</span></p>';
731+
$is_account_disabled = method_exists( $account, 'getCode' ) && $account->getCode() === 400;
732+
733+
if ( $is_account_disabled ) {
734+
$html .= $this->get_error_indicator();
744735
} else {
745-
$html .= esc_html__( 'Connected to Dropbox.', 'gravityformsdropbox' ) . '</span></p>';
736+
737+
$html .= '<p>';
738+
$html .= sprintf(
739+
// Translators: 1. Link to forms list page, 2. Closing </a> tag.
740+
esc_html__( 'To configure Dropbox with your form(s), choose a form you wish to use Dropbox with from the %sforms list page%s, and select Dropbox from the form settings menu.', 'gravityformsdropbox' ),
741+
'<a href="?page=gf_edit_forms">',
742+
'</a>'
743+
);
744+
$html .= '</p>';
745+
$html .= '<p><strong>' . esc_html__( 'Dropbox Account Status' ) . '</strong></p>';
746+
$html .= $this->get_status_indicator( $account );
747+
748+
$html .= sprintf(
749+
' <a href="#" class="button primary" id="gform_dropbox_deauth_button">%1$s</a>',
750+
esc_html__( 'Disconnect from Dropbox', 'gravityformsdropbox' )
751+
);
746752
}
747-
$html .= sprintf(
748-
' <a href="#" class="button primary" id="gform_dropbox_deauth_button">%1$s</a>',
749-
esc_html__( 'Disconnect from Dropbox', 'gravityformsdropbox' )
750-
);
751753

752754
} catch ( Exception $e ) {
753755

@@ -829,6 +831,81 @@ public function settings_auth_token_button( $field, $echo = true ) {
829831

830832
}
831833

834+
/**
835+
* Get the correct status indicator markup for the version of Core.
836+
*
837+
* @since 3.1.2
838+
*
839+
* @param $account The account being evaluated.
840+
*
841+
* @return string
842+
*/
843+
private function get_status_indicator( $account ) {
844+
845+
// Indicator styles were updated in 2.8.8
846+
if ( $this->is_gravityforms_supported( '2.8.8' ) ) {
847+
$html = '<p><span class="gform-status-indicator gform-status-indicator--size-sm gform-status-indicator--theme-cosmos gform-status--active gform-status--no-icon gform-status--no-hover">';
848+
$html .= '<span class="gform-status-indicator-status gform-typography--weight-medium gform-typography--size-text-xs">';
849+
850+
if ( isset( $account->name ) ) {
851+
$html .= esc_html__( 'Connected to Dropbox as: ', 'gravityformsdropbox' );
852+
$html .= esc_html( $account->name->display_name );
853+
} else {
854+
$html .= esc_html__( 'Connected to Dropbox.', 'gravityformsdropbox' );
855+
}
856+
857+
$html .= '</span></span></p>';
858+
859+
return $html;
860+
}
861+
862+
$html = '<p><span class="gform-status-indicator gform-status--static gform-status--active">';
863+
if ( $this->is_gravityforms_supported( '2.5' ) ) {
864+
$html .= '<svg viewBox="0 0 6 6" xmlns="http://www.w3.org/2000/svg"><circle cx="3" cy="2" r="1" stroke-width="2"/></svg>';
865+
}
866+
if ( isset( $account->name ) ) {
867+
$html .= esc_html__( 'Connected to Dropbox as: ', 'gravityformsdropbox' );
868+
$html .= esc_html( $account->name->display_name ) . '</span></p>';
869+
} else {
870+
$html .= esc_html__( 'Connected to Dropbox.', 'gravityformsdropbox' ) . '</span></p>';
871+
}
872+
873+
return $html;
874+
}
875+
876+
/**
877+
* Get the correct error indicator markup for the version of Core.
878+
*
879+
* @since 3.1.2
880+
*
881+
* @return string
882+
*/
883+
private function get_error_indicator() {
884+
885+
// Indicator styles were updated in 2.8.8
886+
if ( $this->is_gravityforms_supported( '2.8.8' ) ) {
887+
$html = '<p><span class="gform-status-indicator gform-status-indicator--size-sm gform-status-indicator--theme-cosmos gform-status--error gform-status--no-icon gform-status--no-hover">';
888+
$html .= '<span class="gform-status-indicator-status gform-typography--weight-medium gform-typography--size-text-xs">';
889+
$html .= esc_html__( 'The connected Dropbox app is disabled or has been deleted. Please reconnect.', 'gravityformsdropbox' );
890+
$html .= '</span></span></p>';
891+
892+
$html .= sprintf(
893+
' <a href="#" class="button primary" id="gform_dropbox_reconnect_button">%1$s</a>',
894+
esc_html__( 'Reconnect to Dropbox', 'gravityformsdropbox' )
895+
);
896+
897+
return $html;
898+
}
899+
900+
$html = '<p> <span class="gform-status-indicator gform-status--static gform-status--error">' . esc_html__( 'The connected Dropbox app is disabled or has been deleted. Please reconnect.', 'gravityformsdropbox' ) . ' </span></p>';
901+
$html = sprintf(
902+
' <a href="#" class="button primary" id="gform_dropbox_reconnect_button">%1$s</a>',
903+
esc_html__( 'Reconnect to Dropbox', 'gravityformsdropbox' )
904+
);
905+
906+
return $html;
907+
}
908+
832909
/**
833910
* Renders settings section for custom Dropbox app.
834911
*
@@ -911,6 +988,34 @@ public function custom_app_settings() {
911988

912989
}
913990

991+
/**
992+
* Removes access token and custom app settings to deauthorize.
993+
*
994+
* @since 3.2
995+
*
996+
* @param array $settings Existing settings.
997+
*
998+
* @return void
999+
*/
1000+
public function remove_access_token( $settings = null ) {
1001+
1002+
if ( ! $settings ) {
1003+
$settings = $this->get_plugin_settings();
1004+
}
1005+
1006+
// Remove access token from settings to deauthorize.
1007+
unset( $settings['accessToken'] );
1008+
unset( $settings['access_token_expires'] );
1009+
unset( $settings['refresh_token'] );
1010+
1011+
// Removing custom app settings if they exist.
1012+
unset( $settings['customAppKey'] );
1013+
unset( $settings['customAppSecret'] );
1014+
1015+
// Save settings.
1016+
$this->update_plugin_settings( $settings );
1017+
}
1018+
9141019
/**
9151020
* Deauthorize with Dropbox.
9161021
*
@@ -944,13 +1049,7 @@ public function ajax_deauthorize() {
9441049
// Log that we revoked the access token.
9451050
$this->log_debug( __METHOD__ . '(): Access token revoked.' );
9461051

947-
// Remove access token from settings.
948-
unset( $settings['accessToken'] );
949-
unset( $settings['access_token_expires'] );
950-
unset( $settings['refresh_token'] );
951-
952-
// Save settings.
953-
$this->update_plugin_settings( $settings );
1052+
$this->remove_access_token( $settings );
9541053

9551054
// Return success response.
9561055
wp_send_json_success();
@@ -961,25 +1060,48 @@ public function ajax_deauthorize() {
9611060
$this->log_debug( __METHOD__ . '(): Unable to revoke access token; ' . $e->getMessage() );
9621061

9631062
if ( $e->getCode() === 401 ) {
964-
// Remove access token from settings because it was already revoked.
965-
unset( $settings['accessToken'] );
966-
unset( $settings['access_token_expires'] );
967-
unset( $settings['refresh_token'] );
9681063

969-
// Save settings.
970-
$this->update_plugin_settings( $settings );
1064+
$this->remove_access_token( $settings );
1065+
1066+
// Return success response.
1067+
wp_send_json_success();
1068+
1069+
} else {
1070+
1071+
// Return error response.
1072+
wp_send_json_error(
1073+
array(
1074+
'message' => $e->getMessage(),
1075+
'code' => $e->getCode(),
1076+
)
1077+
);
1078+
9711079
}
1080+
}
1081+
}
9721082

973-
// Return error response.
974-
wp_send_json_error(
975-
array(
976-
'message' => $e->getMessage(),
977-
'code' => $e->getCode(),
978-
)
979-
);
1083+
/**
1084+
* Handles the AJAX request to remove the access token .
1085+
*
1086+
* @since 3.2
1087+
*/
1088+
public function ajax_remove_access_token() {
1089+
1090+
// Verify nonce.
1091+
if ( false === wp_verify_nonce( rgget( 'nonce' ), 'gfdropbox_deauthorize' ) ) {
1092+
wp_send_json_error( array( 'message' => esc_html__( 'Access denied.', 'gravityformsdropbox' ) ) );
1093+
}
9801094

1095+
// If user is not authorized, exit.
1096+
if ( ! GFCommon::current_user_can_any( $this->_capabilities_settings_page ) ) {
1097+
wp_send_json_error( array( 'message' => esc_html__( 'Access denied.', 'gravityformsdropbox' ) ) );
9811098
}
9821099

1100+
// Remove access token.
1101+
$this->remove_access_token();
1102+
1103+
// Return success response.
1104+
wp_send_json_success();
9831105
}
9841106

9851107

@@ -1812,6 +1934,40 @@ public function process_feed_files( $feed, $entry, $form ) {
18121934

18131935
}
18141936

1937+
/**
1938+
* Passes the folder path through the gform_dropbox_folder_path filter.
1939+
*
1940+
* @since 3.2
1941+
*
1942+
* @param string $folder_path The folder in the Dropbox account where the files will be stored.
1943+
* @param array $form Form object.
1944+
* @param int|string $field_id The ID of the field currently being processed.
1945+
* @param array $entry Entry object.
1946+
* @param array $feed Feed object.
1947+
* @param string $file_url The URL of the file being processed.
1948+
*
1949+
* @return string
1950+
*/
1951+
public function filter_folder_path( $folder_path, $form, $field_id, $entry, $feed, $file_url ) {
1952+
/**
1953+
* Modify the destination folder configured on the Dropbox feed.
1954+
*
1955+
* @since 1.0
1956+
* @since 3.2 Added the $file_url param.
1957+
*
1958+
* @param string $folder_path The folder in the Dropbox account where the files will be stored.
1959+
* @param array $form Form object.
1960+
* @param int|string $field_id The ID of the field currently being processed.
1961+
* @param array $entry Entry object.
1962+
* @param array $feed Feed object.
1963+
* @param string $file_url The URL of the file being processed.
1964+
*/
1965+
return gf_apply_filters( array(
1966+
'gform_dropbox_folder_path',
1967+
rgar( $form, 'id' ),
1968+
), $folder_path, $form, $field_id, $entry, $feed, $file_url );
1969+
}
1970+
18151971
/**
18161972
* Process Dropbox upload fields.
18171973
*
@@ -1850,19 +2006,7 @@ public function process_dropbox_fields( $field, $feed, $entry, $form ) {
18502006
}
18512007

18522008
// Get destination path.
1853-
$folder_path = rgars( $feed, 'meta/destinationFolder' );
1854-
1855-
/**
1856-
* Modify the destination folder configured on the Dropbox feed.
1857-
*
1858-
* @since 1.0
1859-
* @param string $folder_path The folder in the Dropbox account where the files will be stored.
1860-
* @param array $form Form object.
1861-
* @param string $field_id The ID of the field currently being processed.
1862-
* @param array $entry Entry object.
1863-
* @param array $feed Feed object.
1864-
*/
1865-
$folder_path = gf_apply_filters( array( 'gform_dropbox_folder_path', $form['id'] ), $folder_path, $form, $field->id, $entry, $feed );
2009+
$folder_path = $this->filter_folder_path( rgars( $feed, 'meta/destinationFolder' ), $form, $field->id, $entry, $feed, $file );
18662010

18672011
// Add starting slash to folder path.
18682012
$folder_path = strpos( $folder_path, '/' ) !== 0 ? '/' . $folder_path : $folder_path;
@@ -2076,17 +2220,7 @@ public function upload_file( $file, $form, $field_id, $entry, $feed ) {
20762220

20772221
}
20782222

2079-
/**
2080-
* Modify the destination folder configured on the Dropbox feed.
2081-
*
2082-
* @since 1.0
2083-
* @param string $folder_path The folder in the Dropbox account where the files will be stored.
2084-
* @param array $form Form object.
2085-
* @param string $field_id The ID of the field currently being processed.
2086-
* @param array $entry Entry object.
2087-
* @param array $feed Feed object.
2088-
*/
2089-
$folder_path = gf_apply_filters( array( 'gform_dropbox_folder_path', $form['id'] ), $file['destination'], $form, $field_id, $entry, $feed );
2223+
$folder_path = $this->filter_folder_path( rgar( $file, 'destination' ), $form, $field_id, $entry, $feed, rgar( $file, 'url' ) );
20902224

20912225
// If destination folder is not the root folder, ensure the folder exists.
20922226
if ( '/' !== $folder_path ) {
@@ -2302,9 +2436,8 @@ public function filter_gform_pre_send_email( $email, $message_format, $notificat
23022436
continue;
23032437
}
23042438

2305-
// Get file name.
2306-
$file_name = basename( $attachment_path );
2307-
$file_name = str_replace( '?dl=0', '', $file_name );
2439+
// Get file name without the Dropbox query arguments.
2440+
$file_name = basename( strtok( $attachment_path, '?' ) );
23082441

23092442
// Get path to local file.
23102443
$local_path = GFFormsModel::get_upload_path( $entry['form_id'] ) . GFCommon::format_date( rgar( $entry, 'date_created' ), false, '/Y/m/', false ) . $file_name;
@@ -2313,6 +2446,7 @@ public function filter_gform_pre_send_email( $email, $message_format, $notificat
23132446
if ( file_exists( $local_path ) ) {
23142447
$email['attachments'][ $a ] = $local_path;
23152448
} else {
2449+
gf_dropbox()->log_debug( __METHOD__ . '(): Removing attachment from notification as file "' . $local_path . '" does not exist.' );
23162450
unset( $email['attachments'][ $a ] );
23172451
}
23182452

0 commit comments

Comments
 (0)