← All changes
|
includes/Core/Integration/OneDrive/OneDriveHandler.php
+41
-12
2.10.0
→
3.3.1
View file →
| @@ -1,13 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Integration\OneDrive; |
| 4 | 4 | |
| 5 | +if (!defined('ABSPATH')) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 6 | 10 | use BitCode\BitForm\Core\Integration\OneDrive\RecordApiHelper as OneDriveRecordApiHelper; |
| 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 | |
| 11 | 16 | class OneDriveHandler |
| 12 | 17 | { |
| 13 | 18 | private $formID; |
| @@ -27,15 +32,20 @@ | ||
| 27 | 32 | } |
| 28 | 33 | |
| 29 | 34 | public static function authorization() |
| 30 | 35 | { |
| 31 | - if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 36 | + if (!isset($_REQUEST['_ajax_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 32 | 37 | wp_send_json_error(__('Token expired', 'bit-form'), 401); |
| 33 | 38 | } |
| 34 | 39 | |
| 35 | - $inputJSON = file_get_contents('php://input'); | |
| 36 | - $queryParams = json_decode($inputJSON); | |
| 40 | + GlobalHelper::requirePostMethod(); | |
| 37 | 41 | |
| 42 | + try { | |
| 43 | + $queryParams = GlobalHelper::formatRequestData(); | |
| 44 | + } catch (\InvalidArgumentException $e) { | |
| 45 | + wp_send_json_error($e->getMessage(), 400); | |
| 46 | + } | |
| 47 | + | |
| 38 | 48 | if (empty($queryParams->clientId) || empty($queryParams->clientSecret) || empty($queryParams->code) || empty($queryParams->redirectURI)) { |
| 39 | 49 | wp_send_json_error(__('Requested parameter is empty', 'bit-form'), 400); |
| 40 | 50 | } |
| 41 | 51 | |
| @@ -58,14 +68,19 @@ | ||
| 58 | 68 | } |
| 59 | 69 | |
| 60 | 70 | public static function getAllFolders() |
| 61 | 71 | { |
| 62 | - if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 72 | + if (!isset($_REQUEST['_ajax_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 63 | 73 | wp_send_json_error(__('Token expired', 'bit-form'), 401); |
| 64 | 74 | } |
| 65 | 75 | |
| 66 | - $inputJSON = file_get_contents('php://input'); | |
| 67 | - $queryParams = json_decode($inputJSON); | |
| 76 | + GlobalHelper::requirePostMethod(); | |
| 77 | + | |
| 78 | + try { | |
| 79 | + $queryParams = GlobalHelper::formatRequestData(); | |
| 80 | + } catch (\InvalidArgumentException $e) { | |
| 81 | + wp_send_json_error($e->getMessage(), 400); | |
| 82 | + } | |
| 68 | 83 | if (empty($queryParams->tokenDetails) || empty($queryParams->clientId) || empty($queryParams->clientSecret)) { |
| 69 | 84 | wp_send_json_error(__('Requested parameter is empty', 'bit-form'), 400); |
| 70 | 85 | } |
| 71 | 86 | |
| @@ -106,15 +121,20 @@ | ||
| 106 | 121 | } |
| 107 | 122 | |
| 108 | 123 | public static function singleOneDriveFolderList() |
| 109 | 124 | { |
| 110 | - if (!isset($_REQUEST['_ajax_nonce']) && !wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 125 | + if (!isset($_REQUEST['_ajax_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 111 | 126 | wp_send_json_error(__('Token expired', 'bit-form'), 401); |
| 112 | 127 | } |
| 113 | 128 | |
| 114 | - $inputJSON = file_get_contents('php://input'); | |
| 115 | - $queryParams = json_decode($inputJSON); | |
| 129 | + GlobalHelper::requirePostMethod(); | |
| 116 | 130 | |
| 131 | + try { | |
| 132 | + $queryParams = GlobalHelper::formatRequestData(); | |
| 133 | + } catch (\InvalidArgumentException $e) { | |
| 134 | + wp_send_json_error($e->getMessage(), 400); | |
| 135 | + } | |
| 136 | + | |
| 117 | 137 | if (empty($queryParams->tokenDetails) || empty($queryParams->clientId) || empty($queryParams->clientSecret)) { |
| 118 | 138 | wp_send_json_error(__('Requested parameter is empty', 'bit-form'), 400); |
| 119 | 139 | } |
| 120 | 140 | |
| @@ -201,10 +221,17 @@ | ||
| 201 | 221 | |
| 202 | 222 | public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) |
| 203 | 223 | { |
| 204 | 224 | $integrationDetails = json_decode($integrationData->integration_details); |
| 225 | + | |
| 226 | + $entryDetails = [ | |
| 227 | + 'formID' => $this->formID, | |
| 228 | + 'entryID' => $entryID, | |
| 229 | + 'fieldValues' => $fieldValues | |
| 230 | + ]; | |
| 231 | + | |
| 205 | 232 | if (empty($integrationDetails->tokenDetails->access_token)) { |
| 206 | - (new ApiResponse())->apiResponse($logID, $this->integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', 'Not Authorization By OneDrive.'); | |
| 233 | + (new ApiResponse())->apiResponse($logID, $this->integrationID, ['type' => 'record', 'type_name' => 'insert'], 'error', 'Not Authorization By OneDrive.', $entryDetails); | |
| 207 | 234 | return; |
| 208 | 235 | } |
| 209 | 236 | |
| 210 | 237 | $actions = $integrationDetails->actions; |
| @@ -210,13 +237,15 @@ | ||
| 210 | 237 | $actions = $integrationDetails->actions; |
| 211 | 238 | $folderId = $integrationDetails->folder; |
| 212 | 239 | $fieldMap = $integrationDetails->field_map; |
| 213 | 240 | $tokenDetails = self::tokenExpiryCheck($integrationDetails->tokenDetails, $integrationDetails->clientId, $integrationDetails->clientSecret); |
| 214 | - $parentId = $integrationData->flow_details->folderMap[1]; | |
| 241 | + $parentId = $integrationDetails->folderMap[0]; | |
| 215 | 242 | if ($tokenDetails->access_token !== $integrationDetails->tokenDetails->access_token) { |
| 216 | 243 | self::saveRefreshedToken($this->formID, $this->integrationID, $tokenDetails); |
| 217 | 244 | } |
| 218 | 245 | |
| 219 | - (new OneDriveRecordApiHelper($tokenDetails->access_token, $this->formID, $entryID))->executeRecordApi($this->integrationID, $logID, $fieldValues, $fieldMap, $actions, $folderId, $parentId); | |
| 246 | + $oneDriveRecordApiHelper = new OneDriveRecordApiHelper($tokenDetails->access_token, $this->formID, $entryID); | |
| 247 | + | |
| 248 | + $oneDriveRecordApiHelper->executeRecordApi($this->integrationID, $logID, $fieldValues, $fieldMap, $actions, $folderId, $parentId, $this->formID); | |
| 220 | 249 | return true; |
| 221 | 250 | } |
| 222 | 251 | } |