← All changes
|
includes/Core/Integration/Dropbox/DropboxHandler.php
+27
-7
2.10.0
→
3.3.1
View file →
| @@ -1,13 +1,18 @@ | ||
| 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 | 17 | class DropboxHandler |
| 13 | 18 | { |
| @@ -39,15 +44,20 @@ | ||
| 39 | 44 | * @return JSON |
| 40 | 45 | */ |
| 41 | 46 | public static function checkAuthorization() |
| 42 | 47 | { |
| 43 | - if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 48 | + if (!isset($_REQUEST['_ajax_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 44 | 49 | wp_send_json_error(__('Token expired', 'bit-form'), 401); |
| 45 | 50 | } |
| 46 | 51 | |
| 47 | - $inputJSON = file_get_contents('php://input'); | |
| 48 | - $queryParams = json_decode($inputJSON); | |
| 52 | + GlobalHelper::requirePostMethod(); | |
| 49 | 53 | |
| 54 | + try { | |
| 55 | + $queryParams = GlobalHelper::formatRequestData(); | |
| 56 | + } catch (\InvalidArgumentException $e) { | |
| 57 | + wp_send_json_error($e->getMessage(), 400); | |
| 58 | + } | |
| 59 | + | |
| 50 | 60 | if (empty($queryParams->accessCode) || empty($queryParams->apiKey) || empty($queryParams->apiSecret)) { |
| 51 | 61 | wp_send_json_error(__('Requested parameter is empty', 'bit-form'), 400); |
| 52 | 62 | } |
| 53 | 63 | |
| @@ -74,15 +84,20 @@ | ||
| 74 | 84 | * @return JSON |
| 75 | 85 | */ |
| 76 | 86 | public static function getAllFolders() |
| 77 | 87 | { |
| 78 | - if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 88 | + if (!isset($_REQUEST['_ajax_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 79 | 89 | wp_send_json_error(__('Token expired', 'bit-form'), 401); |
| 80 | 90 | } |
| 81 | 91 | |
| 82 | - $inputJSON = file_get_contents('php://input'); | |
| 83 | - $queryParams = json_decode($inputJSON); | |
| 92 | + GlobalHelper::requirePostMethod(); | |
| 84 | 93 | |
| 94 | + try { | |
| 95 | + $queryParams = GlobalHelper::formatRequestData(); | |
| 96 | + } catch (\InvalidArgumentException $e) { | |
| 97 | + wp_send_json_error($e->getMessage(), 400); | |
| 98 | + } | |
| 99 | + | |
| 85 | 100 | if (empty($queryParams->tokenDetails) || empty($queryParams->apiKey) || empty($queryParams->apiSecret)) { |
| 86 | 101 | wp_send_json_error(__('Requested parameter is empty', 'bit-form'), 400); |
| 87 | 102 | } |
| 88 | 103 | |
| @@ -190,11 +205,16 @@ | ||
| 190 | 205 | |
| 191 | 206 | public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) |
| 192 | 207 | { |
| 193 | 208 | $integrationDetails = json_decode($integrationData->integration_details); |
| 209 | + $entryDetails = [ | |
| 210 | + 'formId' => $this->formID, | |
| 211 | + 'entryId' => $entryID, | |
| 212 | + 'fieldValues' => $fieldValues | |
| 213 | + ]; | |
| 194 | 214 | |
| 195 | 215 | if (empty($integrationDetails->tokenDetails->access_token)) { |
| 196 | - (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); | |
| 197 | 217 | return; |
| 198 | 218 | } |
| 199 | 219 | |
| 200 | 220 | $actions = $integrationDetails->actions; |