PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
← All changes | includes/Core/Integration/Dropbox/DropboxHandler.php +49 -19 2.03.3.1 View file →
@@ -1,22 +1,29 @@
1 1 <?php
2 2
3 3 namespace BitCode\BitForm\Core\Integration\Dropbox;
4 4
5 +if (!defined('ABSPATH')) {
6 + exit;
7 +}
8 +
5 9 use BitCode\BitForm\Core\Integration\Dropbox\RecordApiHelper as DropboxRecordApiHelper;
6 10 use BitCode\BitForm\Core\Integration\IntegrationHandler;
7 11 use BitCode\BitForm\Core\Util\ApiResponse;
8 12 use BitCode\BitForm\Core\Util\HttpHelper;
9 13 use BitCode\BitForm\Core\Util\IpTool;
14 +use BitCode\BitForm\GlobalHelper;
10 15 use WP_Error;
11 16
12 -class DropboxHandler {
17 +class DropboxHandler
18 +{
13 19 private $formID;
14 20 private $integrationID;
15 21 protected static $apiBaseUri = 'https://api.dropboxapi.com';
16 22 protected static $contentBaseUri = 'https://content.dropboxapi.com';
17 23
18 - public function __construct($integrationID, $fromID) {
24 + public function __construct($integrationID, $fromID)
25 + {
19 26 $this->formID = $fromID;
20 27 $this->integrationID = $integrationID;
21 28 }
22 29
@@ -24,9 +31,10 @@
24 31 * Helps to register ajax function's with wp
25 32 *
26 33 * @return null
27 34 */
28 - public static function registerAjax() {
35 + public static function registerAjax()
36 + {
29 37 add_action('wp_ajax_bitforms_dropbox_authorization', [__CLASS__, 'checkAuthorization']);
30 38 add_action('wp_ajax_bitforms_dropbox_get_all_folders', [__CLASS__, 'getAllFolders']);
31 39 }
32 40
@@ -34,16 +42,22 @@
34 42 * authorize dropbox
35 43 *
36 44 * @return JSON
37 45 */
38 - public static function checkAuthorization() {
39 - if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
46 + public static function checkAuthorization()
47 + {
48 + if (!isset($_REQUEST['_ajax_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
40 49 wp_send_json_error(__('Token expired', 'bit-form'), 401);
41 50 }
42 51
43 - $inputJSON = file_get_contents('php://input');
44 - $queryParams = json_decode($inputJSON);
52 + GlobalHelper::requirePostMethod();
45 53
54 + try {
55 + $queryParams = GlobalHelper::formatRequestData();
56 + } catch (\InvalidArgumentException $e) {
57 + wp_send_json_error($e->getMessage(), 400);
58 + }
59 +
46 60 if (empty($queryParams->accessCode) || empty($queryParams->apiKey) || empty($queryParams->apiSecret)) {
47 61 wp_send_json_error(__('Requested parameter is empty', 'bit-form'), 400);
48 62 }
49 63
@@ -68,16 +82,22 @@
68 82 * get dropbox folders List
69 83 *
70 84 * @return JSON
71 85 */
72 - public static function getAllFolders() {
73 - if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
86 + public static function getAllFolders()
87 + {
88 + if (!isset($_REQUEST['_ajax_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
74 89 wp_send_json_error(__('Token expired', 'bit-form'), 401);
75 90 }
76 91
77 - $inputJSON = file_get_contents('php://input');
78 - $queryParams = json_decode($inputJSON);
92 + GlobalHelper::requirePostMethod();
79 93
94 + try {
95 + $queryParams = GlobalHelper::formatRequestData();
96 + } catch (\InvalidArgumentException $e) {
97 + wp_send_json_error($e->getMessage(), 400);
98 + }
99 +
80 100 if (empty($queryParams->tokenDetails) || empty($queryParams->apiKey) || empty($queryParams->apiSecret)) {
81 101 wp_send_json_error(__('Requested parameter is empty', 'bit-form'), 400);
82 102 }
83 103
@@ -104,9 +124,10 @@
104 124 $response['tokenDetails'] = $token;
105 125 wp_send_json_success($response, 200);
106 126 }
107 127
108 - public static function getDropboxFoldersList($token) {
128 + public static function getDropboxFoldersList($token)
129 + {
109 130 $headers = [
110 131 'Content-Type' => 'application/json; charset=utf-8',
111 132 'Authorization' => 'Bearer ' . $token,
112 133 ];
@@ -116,9 +137,9 @@
116 137 'include_deleted' => false,
117 138 'include_mounted_folders' => true,
118 139 'include_non_downloadable_files' => true
119 140 ];
120 - $options = json_encode($options);
141 + $options = wp_json_encode($options);
121 142
122 143 $recipientApiEndpoint = self::$apiBaseUri . '/2/files/list_folder';
123 144 $apiResponse = HttpHelper::post($recipientApiEndpoint, $options, $headers);
124 145 if (is_wp_error($apiResponse) || !empty($apiResponse->error)) {
@@ -126,9 +147,10 @@
126 147 }
127 148 return $apiResponse;
128 149 }
129 150
130 - private static function tokenExpiryCheck($token, $apiKey, $apiSecret) {
151 + private static function tokenExpiryCheck($token, $apiKey, $apiSecret)
152 + {
131 153 if (!$token) {
132 154 return false;
133 155 }
134 156
@@ -144,9 +166,10 @@
144 166 }
145 167 return $token;
146 168 }
147 169
148 - private static function refreshToken($refresh_token, $apiKey, $apiSecret) {
170 + private static function refreshToken($refresh_token, $apiKey, $apiSecret)
171 + {
149 172 $body = [
150 173 'grant_type' => 'refresh_token',
151 174 'client_id' => $apiKey,
152 175 'client_secret' => $apiSecret,
@@ -162,9 +185,10 @@
162 185 $token->generates_on = \time();
163 186 return $token;
164 187 }
165 188
166 - private static function saveRefreshedToken($formID, $integrationID, $tokenDetails) {
189 + private static function saveRefreshedToken($formID, $integrationID, $tokenDetails)
190 + {
167 191 if (empty($formID) || empty($integrationID)) {
168 192 return;
169 193 }
170 194
@@ -175,16 +199,22 @@
175 199 }
176 200
177 201 $newDetails = json_decode($dropboxDetails[0]->integration_details);
178 202 $newDetails->tokenDetails = $tokenDetails;
179 - $integrationHandler->updateIntegration($integrationID, $dropboxDetails[0]->integration_name, 'Dropbox', \json_encode($newDetails), 'form');
203 + $integrationHandler->updateIntegration($integrationID, $dropboxDetails[0]->integration_name, 'Dropbox', wp_json_encode($newDetails), 'form');
180 204 }
181 205
182 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
206 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
207 + {
183 208 $integrationDetails = json_decode($integrationData->integration_details);
209 + $entryDetails = [
210 + 'formId' => $this->formID,
211 + 'entryId' => $entryID,
212 + 'fieldValues' => $fieldValues
213 + ];
184 214
185 215 if (empty($integrationDetails->tokenDetails->access_token)) {
186 - (new ApiResponse())->apiResponse($logID, $this->integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', 'Not Authorization By Dropbox.');
216 + (new ApiResponse())->apiResponse($logID, $this->integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', 'Not Authorization By Dropbox.', $entryDetails);
187 217 return;
188 218 }
189 219
190 220 $actions = $integrationDetails->actions;