PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / V3.3.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder vV3.3.2
V3.3.3 V3.3.2 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 All 140 releases
← All changes | includes/Core/Integration/GoogleSheet/GoogleSheetHandler.php +71 -31 2.0 → V3.3.2 View file →
@@ -6,21 +6,28 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\GoogleSheet;
9 9
10 +if (!defined('ABSPATH')) {
11 + exit;
12 +}
13 +
10 14 use BitCode\BitForm\Core\Integration\IntegrationHandler;
11 15 use BitCode\BitForm\Core\Util\HttpHelper;
12 16 use BitCode\BitForm\Core\Util\IpTool;
17 +use BitCode\BitForm\GlobalHelper;
13 18 use WP_Error;
14 19
15 20 /**
16 21 * Provide functionality for ZohoCrm integration
17 22 */
18 -class GoogleSheetHandler {
23 +class GoogleSheetHandler
24 +{
19 25 private $_formID;
20 26 private $_integrationID;
21 27
22 - public function __construct($integrationID, $fromID) {
28 + public function __construct($integrationID, $fromID)
29 + {
23 30 $this->_formID = $fromID;
24 31 $this->_integrationID = $integrationID;
25 32 }
26 33
@@ -28,9 +35,10 @@
28 35 * Helps to register ajax function's with wp
29 36 *
30 37 * @return null
31 38 */
32 - public static function registerAjax() {
39 + public static function registerAjax()
40 + {
33 41 add_action('wp_ajax_bitforms_gsheet_generate_token', [__CLASS__, 'generateTokens']);
34 42 add_action('wp_ajax_bitforms_gsheet_refresh_spreadsheets', [__CLASS__, 'refreshSpreadsheetsAjaxHelper']);
35 43 add_action('wp_ajax_bitforms_gsheet_refresh_worksheets', [__CLASS__, 'refreshWorksheetsAjaxHelper']);
36 44 add_action('wp_ajax_bitforms_gsheet_refresh_worksheet_headers', [__CLASS__, 'refreshWorksheetHeadersAjaxHelper']);
@@ -38,15 +46,23 @@
38 46
39 47 /**
40 48 * Process ajax request for generate_token
41 49 *
42 - * @return JSON api response and status
50 + * @return string json api response and status
43 51 */
44 - public static function generateTokens() {
45 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
52 + public static function generateTokens()
53 + {
54 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
46 55 $authorizationHeader = null;
47 - $inputJSON = file_get_contents('php://input');
48 - $requestsParams = json_decode($inputJSON);
56 +
57 + GlobalHelper::requirePostMethod();
58 +
59 + try {
60 + $requestsParams = GlobalHelper::formatRequestData();
61 + } catch (\InvalidArgumentException $e) {
62 + wp_send_json_error($e->getMessage(), 400);
63 + }
64 +
49 65 if (
50 66 empty($requestsParams->clientId)
51 67 || empty($requestsParams->clientSecret)
52 68 || empty($requestsParams->redirectURI)
@@ -93,15 +109,22 @@
93 109
94 110 /**
95 111 * Process ajax request for refresh crm modules
96 112 *
97 - * @return JSON crm module data
113 + * @return string json crm module data
98 114 */
99 - public static function refreshSpreadsheetsAjaxHelper() {
100 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
115 + public static function refreshSpreadsheetsAjaxHelper()
116 + {
117 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
101 118 $authorizationHeader = null;
102 - $inputJSON = file_get_contents('php://input');
103 - $queryParams = json_decode($inputJSON);
119 +
120 + GlobalHelper::requirePostMethod();
121 + try {
122 + $queryParams = GlobalHelper::formatRequestData();
123 + } catch (\InvalidArgumentException $e) {
124 + wp_send_json_error($e->getMessage(), 400);
125 + }
126 +
104 127 if (
105 128 empty($queryParams->tokenDetails)
106 129 || empty($queryParams->clientId)
107 130 || empty($queryParams->clientSecret)
@@ -161,14 +184,21 @@
161 184 * Process ajax request for refesh crm layouts
162 185 *
163 186 * @return JSON data
164 187 */
165 - public static function refreshWorksheetsAjaxHelper() {
166 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
188 + public static function refreshWorksheetsAjaxHelper()
189 + {
190 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
167 191 $authorizationHeader = null;
168 - $inputJSON = file_get_contents('php://input');
169 - $queryParams = json_decode($inputJSON);
170 192
193 + GlobalHelper::requirePostMethod();
194 +
195 + try {
196 + $queryParams = GlobalHelper::formatRequestData();
197 + } catch (\InvalidArgumentException $e) {
198 + wp_send_json_error($e->getMessage(), 400);
199 + }
200 +
171 201 if (
172 202 empty($queryParams->clientId)
173 203 || empty($queryParams->clientSecret)
174 204 || empty($queryParams->spreadsheetId)
@@ -220,14 +250,20 @@
220 250 * Process ajax request for refesh crm layouts
221 251 *
222 252 * @return JSON data
223 253 */
224 - public static function refreshWorksheetHeadersAjaxHelper() {
225 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
254 + public static function refreshWorksheetHeadersAjaxHelper()
255 + {
256 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
226 257 $authorizationHeader = null;
227 - $inputJSON = file_get_contents('php://input');
228 - $queryParams = json_decode($inputJSON);
229 258
259 + GlobalHelper::requirePostMethod();
260 + try {
261 + $queryParams = GlobalHelper::formatRequestData();
262 + } catch (\InvalidArgumentException $e) {
263 + wp_send_json_error($e->getMessage(), 400);
264 + }
265 +
230 266 if (
231 267 empty($queryParams->worksheetName)
232 268 || empty($queryParams->tokenDetails)
233 269 || empty($queryParams->clientId)
@@ -293,12 +329,13 @@
293 329
294 330 /**
295 331 * Helps to refresh zoho crm access_token
296 332 *
297 - * @param Array $apiData Contains required data for refresh access token
298 - * @return JSON $tokenDetails API token details
333 + * @param object $apiData Contains required data for refresh access token
334 + * @return string|boolean $tokenDetails API token details
299 335 */
300 - protected static function _refreshAccessToken($apiData) {
336 + protected static function _refreshAccessToken($apiData)
337 + {
301 338 if (
302 339 empty($apiData->clientId)
303 340 || empty($apiData->clientSecret)
304 341 || empty($apiData->tokenDetails)
@@ -326,15 +363,16 @@
326 363
327 364 /**
328 365 * Save updated access_token to avoid unnecessary token generation
329 366 *
330 - * @param Integer $fromID ID of Integration related form
331 - * @param Integer $integrationID ID of Google Sheet Integration
332 - * @param Obeject $tokenDetails refreshed token info
367 + * @param integer $fromID ID of Integration related form
368 + * @param integer $integrationID ID of Google Sheet Integration
369 + * @param object $tokenDetails refreshed token info
333 370 *
334 371 * @return null
335 372 */
336 - protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null) {
373 + protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null)
374 + {
337 375 if (empty($formID) || empty($integrationID)) {
338 376 return;
339 377 }
340 378
@@ -356,12 +394,13 @@
356 394 if (!empty($others['worksheet_headers'])) {
357 395 $newDetails->default->worksheets->headers->{$others['worksheet']} = $others['worksheet_headers'];
358 396 }
359 397
360 - $integrationHandler->updateIntegration($integrationID, $gsheetDetails[0]->integration_name, 'Google Sheet', \json_encode($newDetails), 'form');
398 + $integrationHandler->updateIntegration($integrationID, $gsheetDetails[0]->integration_name, 'Google Sheet', wp_json_encode($newDetails), 'form');
361 399 }
362 400
363 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
401 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
402 + {
364 403 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
365 404
366 405 $tokenDetails = $integrationDetails->tokenDetails;
367 406 $spreadsheetId = $integrationDetails->spreadsheetId;
@@ -401,9 +440,10 @@
401 440 $header,
402 441 $actions,
403 442 $defaultDataConf,
404 443 $fieldValues,
405 - $fieldMap
444 + $fieldMap,
445 + $this->_formID
406 446 );
407 447
408 448 if (is_wp_error($gsheetApiResponse)) {
409 449 return $gsheetApiResponse;