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/ZohoAnalytics/ZohoAnalyticsHandler.php +84 -31 2.03.3.1 View file →
@@ -6,24 +6,31 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\ZohoAnalytics;
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\ApiResponse as UtilApiResponse;
12 16 use BitCode\BitForm\Core\Util\HttpHelper;
13 17 use BitCode\BitForm\Core\Util\IpTool;
18 +use BitCode\BitForm\GlobalHelper;
14 19 use WP_Error;
15 20
16 21 /**
17 22 * Provide functionality for ZohoCrm integration
18 23 */
19 -class ZohoAnalyticsHandler {
24 +class ZohoAnalyticsHandler
25 +{
20 26 private $_formID;
21 27 private $_integrationID;
22 28
23 29 private $_logResponse;
24 30
25 - public function __construct($integrationID, $fromID) {
31 + public function __construct($integrationID, $fromID)
32 + {
26 33 $this->_formID = $fromID;
27 34 $this->_integrationID = $integrationID;
28 35 $this->_logResponse = new UtilApiResponse();
29 36 }
@@ -32,9 +39,10 @@
32 39 * Helps to register ajax function's with wp
33 40 *
34 41 * @return null
35 42 */
36 - public static function registerAjax() {
43 + public static function registerAjax()
44 + {
37 45 add_action('wp_ajax_bitforms_zanalytics_generate_token', [__CLASS__, 'generateTokens']);
38 46 add_action('wp_ajax_bitforms_zanalytics_refresh_workspaces', [__CLASS__, 'refreshWorkspacesAjaxHelper']);
39 47 add_action('wp_ajax_bitforms_zanalytics_refresh_users', [__CLASS__, 'refreshUsersAjaxHelper']);
40 48 add_action('wp_ajax_bitforms_zanalytics_refresh_tables', [__CLASS__, 'refreshTablesAjaxHelper']);
@@ -45,12 +53,19 @@
45 53 * Process ajax request for generate_token
46 54 *
47 55 * @return JSON zoho crm api response and status
48 56 */
49 - public static function generateTokens() {
50 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
51 - $inputJSON = file_get_contents('php://input');
52 - $requestsParams = json_decode($inputJSON);
57 + public static function generateTokens()
58 + {
59 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
60 + GlobalHelper::requirePostMethod();
61 +
62 + try {
63 + $requestsParams = GlobalHelper::formatRequestData();
64 + } catch (\InvalidArgumentException $e) {
65 + wp_send_json_error($e->getMessage(), 400);
66 + }
67 +
53 68 if (
54 69 empty($requestsParams->{'accounts-server'})
55 70 || empty($requestsParams->dataCenter)
56 71 || empty($requestsParams->clientId)
@@ -100,13 +115,20 @@
100 115 * Process ajax request for refresh crm modules
101 116 *
102 117 * @return JSON crm module data
103 118 */
104 - public static function refreshWorkspacesAjaxHelper() {
105 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
119 + public static function refreshWorkspacesAjaxHelper()
120 + {
121 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
106 122 $authorizationHeader = null;
107 - $inputJSON = file_get_contents('php://input');
108 - $queryParams = json_decode($inputJSON);
123 +
124 + GlobalHelper::requirePostMethod();
125 +
126 + try {
127 + $queryParams = GlobalHelper::formatRequestData();
128 + } catch (\InvalidArgumentException $e) {
129 + wp_send_json_error($e->getMessage(), 400);
130 + }
109 131 if (
110 132 empty($queryParams->tokenDetails)
111 133 || empty($queryParams->dataCenter)
112 134 || empty($queryParams->clientId)
@@ -159,13 +181,21 @@
159 181 );
160 182 }
161 183 }
162 184
163 - public static function refreshUsersAjaxHelper() {
164 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
185 + public static function refreshUsersAjaxHelper()
186 + {
187 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
165 188 $authorizationHeader = null;
166 - $inputJSON = file_get_contents('php://input');
167 - $queryParams = json_decode($inputJSON);
189 +
190 + GlobalHelper::requirePostMethod();
191 +
192 + try {
193 + $queryParams = GlobalHelper::formatRequestData();
194 + } catch (\InvalidArgumentException $e) {
195 + wp_send_json_error($e->getMessage(), 400);
196 + }
197 +
168 198 if (
169 199 empty($queryParams->tokenDetails)
170 200 || empty($queryParams->dataCenter)
171 201 || empty($queryParams->clientId)
@@ -223,13 +253,20 @@
223 253 * Process ajax request for refesh crm layouts
224 254 *
225 255 * @return JSON crm layout data
226 256 */
227 - public static function refreshTablesAjaxHelper() {
228 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
257 + public static function refreshTablesAjaxHelper()
258 + {
259 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
229 260 $authorizationHeader = null;
230 - $inputJSON = file_get_contents('php://input');
231 - $queryParams = json_decode($inputJSON);
261 +
262 + GlobalHelper::requirePostMethod();
263 +
264 + try {
265 + $queryParams = GlobalHelper::formatRequestData();
266 + } catch (\InvalidArgumentException $e) {
267 + wp_send_json_error($e->getMessage(), 400);
268 + }
232 269 if (
233 270 empty($queryParams->workspace)
234 271 || empty($queryParams->tokenDetails)
235 272 || empty($queryParams->dataCenter)
@@ -290,13 +327,19 @@
290 327 * Process ajax request for refesh crm layouts
291 328 *
292 329 * @return JSON crm layout data
293 330 */
294 - public static function refreshTableHeadersAjaxHelper() {
295 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
331 + public static function refreshTableHeadersAjaxHelper()
332 + {
333 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
296 334 $authorizationHeader = null;
297 - $inputJSON = file_get_contents('php://input');
298 - $queryParams = json_decode($inputJSON);
335 +
336 + GlobalHelper::requirePostMethod();
337 + try {
338 + $queryParams = GlobalHelper::formatRequestData();
339 + } catch (\InvalidArgumentException $e) {
340 + wp_send_json_error($e->getMessage(), 400);
341 + }
299 342 if (
300 343 empty($queryParams->workspace)
301 344 || empty($queryParams->table)
302 345 || empty($queryParams->tokenDetails)
@@ -354,12 +397,13 @@
354 397
355 398 /**
356 399 * Helps to refresh zoho crm access_token
357 400 *
358 - * @param Array $apiData Contains required data for refresh access token
359 - * @return JSON $tokenDetails API token details
401 + * @param object $apiData Contains required data for refresh access token
402 + * @return string|boolean $tokenDetails API token details
360 403 */
361 - protected static function _refreshAccessToken($apiData) {
404 + protected static function _refreshAccessToken($apiData)
405 + {
362 406 if (
363 407 empty($apiData->dataCenter)
364 408 || empty($apiData->clientId)
365 409 || empty($apiData->clientSecret)
@@ -395,9 +439,10 @@
395 439 * @param Obeject $tokenDetails refreshed token info
396 440 *
397 441 * @return null
398 442 */
399 - protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null) {
443 + protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null)
444 + {
400 445 if (empty($formID) || empty($integrationID)) {
401 446 return;
402 447 }
403 448
@@ -419,12 +464,13 @@
419 464 if (!empty($others['table_headers'])) {
420 465 $newDetails->default->tables->headers->{$others['table']} = $others['table_headers'];
421 466 }
422 467
423 - $integrationHandler->updateIntegration($integrationID, $zanalyticsDetails[0]->integration_name, 'Zoho Analytics', \json_encode($newDetails), 'form');
468 + $integrationHandler->updateIntegration($integrationID, $zanalyticsDetails[0]->integration_name, 'Zoho Analytics', wp_json_encode($newDetails), 'form');
424 469 }
425 470
426 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
471 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
472 + {
427 473 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
428 474
429 475 $tokenDetails = $integrationDetails->tokenDetails;
430 476 $workspace = $integrationDetails->workspace;
@@ -433,8 +479,15 @@
433 479 $dataCenter = $integrationDetails->dataCenter;
434 480 $fieldMap = $integrationDetails->field_map;
435 481 $actions = $integrationDetails->actions;
436 482 $defaultDataConf = $integrationDetails->default;
483 +
484 + $entryDetails = [
485 + 'formId' => $this->_formID,
486 + 'entryId' => $entryID,
487 + 'fieldValues' => $fieldValues
488 + ];
489 +
437 490 if (
438 491 empty($tokenDetails)
439 492 || empty($workspace)
440 493 || empty($table)
@@ -440,9 +493,9 @@
440 493 || empty($table)
441 494 || empty($fieldMap)
442 495 ) {
443 496 $error = new WP_Error('REQ_FIELD_EMPTY', __('workspace, table, fields are required for zoho analytics api', 'bit-form'));
444 - $this->_logResponse->apiResponse($logID, $this->_integrationID, 'record', 'validation', $error);
497 + $this->_logResponse->apiResponse($logID, $this->_integrationID, 'record', 'validation', $error, $entryDetails);
445 498 return $error;
446 499 }
447 500
448 501 $requiredParams = null;
@@ -458,9 +511,9 @@
458 511 }
459 512 }
460 513
461 514 // $actions = $integrationDetails->actions;
462 - $recordApiHelper = new RecordApiHelper($tokenDetails, $this->_integrationID, $logID);
515 + $recordApiHelper = new RecordApiHelper($tokenDetails, $this->_integrationID, $logID, $this->_formID, $entryID);
463 516
464 517 $zanalyticsApiResponse = $recordApiHelper->executeRecordApi(
465 518 $workspace,
466 519 $table,