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/ZohoProjects/ZohoProjectsHandler.php +153 -60 2.03.3.1 View file →
@@ -6,20 +6,28 @@
6 6 */
7 7
8 8 namespace BitCode\BitForm\Core\Integration\ZohoProjects;
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;
18 +use WP_Error;
13 19
14 20 /**
15 21 * Provide functionality for ZohoCrm integration
16 22 */
17 -class ZohoProjectsHandler {
23 +class ZohoProjectsHandler
24 +{
18 25 private $_formID;
19 26 private $_integrationID;
20 27
21 - public function __construct($integrationID, $formID) {
28 + public function __construct($integrationID, $formID)
29 + {
22 30 $this->_formID = $formID;
23 31 $this->_integrationID = $integrationID;
24 32 }
25 33
@@ -27,9 +35,10 @@
27 35 * Helps to register ajax function's with wp
28 36 *
29 37 * @return null
30 38 */
31 - public static function registerAjax() {
39 + public static function registerAjax()
40 + {
32 41 add_action('wp_ajax_bitforms_zprojects_generate_token', [__CLASS__, 'generateTokens']);
33 42 add_action('wp_ajax_bitforms_zprojects_refresh_portals', [__CLASS__, 'refreshPortalsAjaxHelper']);
34 43 add_action('wp_ajax_bitforms_zprojects_refresh_projects', [__CLASS__, 'refreshProjectsAjaxHelper']);
35 44 add_action('wp_ajax_bitforms_zprojects_refresh_milestones', [__CLASS__, 'refreshMilestonesAjaxHelper']);
@@ -44,14 +53,21 @@
44 53
45 54 /**
46 55 * Process ajax request for generate_token
47 56 *
48 - * @return JSON zoho crm api response and status
57 + * @return string zoho crm api response and status
49 58 */
50 - public static function generateTokens() {
51 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
52 - $inputJSON = file_get_contents('php://input');
53 - $requestsParams = json_decode($inputJSON);
59 + public static function generateTokens()
60 + {
61 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
62 + GlobalHelper::requirePostMethod();
63 +
64 + try {
65 + $requestsParams = GlobalHelper::formatRequestData();
66 + } catch (\InvalidArgumentException $e) {
67 + wp_send_json_error($e->getMessage(), 400);
68 + }
69 +
54 70 if (
55 71 empty($requestsParams->{'accounts-server'})
56 72 || empty($requestsParams->dataCenter)
57 73 || empty($requestsParams->clientId)
@@ -96,13 +112,20 @@
96 112 );
97 113 }
98 114 }
99 115
100 - public static function refreshPortalsAjaxHelper() {
116 + public static function refreshPortalsAjaxHelper()
117 + {
101 118 $authorizationHeader = null;
102 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
103 - $inputJSON = file_get_contents('php://input');
104 - $queryParams = json_decode($inputJSON);
119 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
120 + GlobalHelper::requirePostMethod();
121 +
122 + try {
123 + $queryParams = GlobalHelper::formatRequestData();
124 + } catch (\InvalidArgumentException $e) {
125 + wp_send_json_error($e->getMessage(), 400);
126 + }
127 +
105 128 if (
106 129 empty($queryParams->tokenDetails)
107 130 || empty($queryParams->dataCenter)
108 131 || empty($queryParams->clientId)
@@ -160,13 +183,20 @@
160 183 );
161 184 }
162 185 }
163 186
164 - public static function refreshProjectsAjaxHelper() {
187 + public static function refreshProjectsAjaxHelper()
188 + {
165 189 $authorizationHeader = null;
166 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
167 - $inputJSON = file_get_contents('php://input');
168 - $queryParams = json_decode($inputJSON);
190 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
191 + GlobalHelper::requirePostMethod();
192 +
193 + try {
194 + $queryParams = GlobalHelper::formatRequestData();
195 + } catch (\InvalidArgumentException $e) {
196 + wp_send_json_error($e->getMessage(), 400);
197 + }
198 +
169 199 if (
170 200 empty($queryParams->tokenDetails)
171 201 || empty($queryParams->dataCenter)
172 202 || empty($queryParams->clientId)
@@ -227,13 +257,20 @@
227 257 );
228 258 }
229 259 }
230 260
231 - public static function refreshMilestonesAjaxHelper() {
261 + public static function refreshMilestonesAjaxHelper()
262 + {
232 263 $authorizationHeader = null;
233 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
234 - $inputJSON = file_get_contents('php://input');
235 - $queryParams = json_decode($inputJSON);
264 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
265 + GlobalHelper::requirePostMethod();
266 +
267 + try {
268 + $queryParams = GlobalHelper::formatRequestData();
269 + } catch (\InvalidArgumentException $e) {
270 + wp_send_json_error($e->getMessage(), 400);
271 + }
272 +
236 273 if (
237 274 empty($queryParams->tokenDetails)
238 275 || empty($queryParams->dataCenter)
239 276 || empty($queryParams->clientId)
@@ -293,13 +330,20 @@
293 330 );
294 331 }
295 332 }
296 333
297 - public static function refreshTasklistsAjaxHelper() {
334 + public static function refreshTasklistsAjaxHelper()
335 + {
298 336 $authorizationHeader = null;
299 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
300 - $inputJSON = file_get_contents('php://input');
301 - $queryParams = json_decode($inputJSON);
337 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
338 + GlobalHelper::requirePostMethod();
339 +
340 + try {
341 + $queryParams = GlobalHelper::formatRequestData();
342 + } catch (\InvalidArgumentException $e) {
343 + wp_send_json_error($e->getMessage(), 400);
344 + }
345 +
302 346 if (
303 347 empty($queryParams->tokenDetails)
304 348 || empty($queryParams->dataCenter)
305 349 || empty($queryParams->clientId)
@@ -364,13 +408,20 @@
364 408 );
365 409 }
366 410 }
367 411
368 - public static function refreshTasksAjaxHelper() {
412 + public static function refreshTasksAjaxHelper()
413 + {
369 414 $authorizationHeader = null;
370 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
371 - $inputJSON = file_get_contents('php://input');
372 - $queryParams = json_decode($inputJSON);
415 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
416 + GlobalHelper::requirePostMethod();
417 +
418 + try {
419 + $queryParams = GlobalHelper::formatRequestData();
420 + } catch (\InvalidArgumentException $e) {
421 + wp_send_json_error($e->getMessage(), 400);
422 + }
423 +
373 424 if (
374 425 empty($queryParams->tokenDetails)
375 426 || empty($queryParams->dataCenter)
376 427 || empty($queryParams->clientId)
@@ -437,12 +488,19 @@
437 488 );
438 489 }
439 490 }
440 491
441 - public static function refreshFieldsAjaxHelper() {
442 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
443 - $inputJSON = file_get_contents('php://input');
444 - $queryParams = json_decode($inputJSON);
492 + public static function refreshFieldsAjaxHelper()
493 + {
494 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
495 + GlobalHelper::requirePostMethod();
496 +
497 + try {
498 + $queryParams = GlobalHelper::formatRequestData();
499 + } catch (\InvalidArgumentException $e) {
500 + wp_send_json_error($e->getMessage(), 400);
501 + }
502 +
445 503 if (
446 504 empty($queryParams->tokenDetails)
447 505 || empty($queryParams->dataCenter)
448 506 || empty($queryParams->clientId)
@@ -490,9 +548,10 @@
490 548 );
491 549 }
492 550 }
493 551
494 - protected static function getProjectFields($dataCenter, $portalId, $access_token) {
552 + protected static function getProjectFields($dataCenter, $portalId, $access_token)
553 + {
495 554 $allFields = [
496 555 'Project Title' => [
497 556 'apiName' => 'name',
498 557 'displayLabel' => 'Project Title',
@@ -577,9 +636,10 @@
577 636
578 637 return $response;
579 638 }
580 639
581 - protected static function getMilestoneFields() {
640 + protected static function getMilestoneFields()
641 + {
582 642 $allFields = [
583 643 'Milestone Title' => [
584 644 'apiName' => 'name',
585 645 'displayLabel' => 'Milestone Title',
@@ -605,9 +665,10 @@
605 665
606 666 return $response;
607 667 }
608 668
609 - protected static function getTasklistFields() {
669 + protected static function getTasklistFields()
670 + {
610 671 $allFields = [
611 672 'Tasklist Title' => [
612 673 'apiName' => 'name',
613 674 'displayLabel' => 'Tasklist Title',
@@ -623,9 +684,10 @@
623 684
624 685 return $response;
625 686 }
626 687
627 - protected static function getTaskFields($dataCenter, $portalId, $access_token, $projectId) {
688 + protected static function getTaskFields($dataCenter, $portalId, $access_token, $projectId)
689 + {
628 690 $allFields = [
629 691 'Task Title' => [
630 692 'apiName' => 'name',
631 693 'displayLabel' => 'Task Title',
@@ -706,9 +768,10 @@
706 768
707 769 return $response;
708 770 }
709 771
710 - protected static function getIssueFields($dataCenter, $portalId, $access_token, $projectId) {
772 + protected static function getIssueFields($dataCenter, $portalId, $access_token, $projectId)
773 + {
711 774 $allFields = [
712 775 'Issue Title' => [
713 776 'apiName' => 'title',
714 777 'displayLabel' => 'Issue Title',
@@ -771,13 +834,20 @@
771 834
772 835 return $response;
773 836 }
774 837
775 - public static function refreshUsersAjaxHelper() {
838 + public static function refreshUsersAjaxHelper()
839 + {
776 840 $authorizationHeader = null;
777 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
778 - $inputJSON = file_get_contents('php://input');
779 - $queryParams = json_decode($inputJSON);
841 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
842 + GlobalHelper::requirePostMethod();
843 +
844 + try {
845 + $queryParams = GlobalHelper::formatRequestData();
846 + } catch (\InvalidArgumentException $e) {
847 + wp_send_json_error($e->getMessage(), 400);
848 + }
849 +
780 850 if (
781 851 empty($queryParams->tokenDetails)
782 852 || empty($queryParams->dataCenter)
783 853 || empty($queryParams->clientId)
@@ -842,13 +912,20 @@
842 912 );
843 913 }
844 914 }
845 915
846 - public static function refreshTaskLaysAjaxHelper() {
916 + public static function refreshTaskLaysAjaxHelper()
917 + {
847 918 $authorizationHeader = null;
848 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
849 - $inputJSON = file_get_contents('php://input');
850 - $queryParams = json_decode($inputJSON);
919 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
920 + GlobalHelper::requirePostMethod();
921 +
922 + try {
923 + $queryParams = GlobalHelper::formatRequestData();
924 + } catch (\InvalidArgumentException $e) {
925 + wp_send_json_error($e->getMessage(), 400);
926 + }
927 +
851 928 if (
852 929 empty($queryParams->tokenDetails)
853 930 || empty($queryParams->dataCenter)
854 931 || empty($queryParams->clientId)
@@ -906,13 +983,19 @@
906 983 );
907 984 }
908 985 }
909 986
910 - public static function refreshGroupsAjaxHelper() {
987 + public static function refreshGroupsAjaxHelper()
988 + {
911 989 $authorizationHeader = null;
912 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
913 - $inputJSON = file_get_contents('php://input');
914 - $queryParams = json_decode($inputJSON);
990 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
991 + GlobalHelper::requirePostMethod();
992 +
993 + try {
994 + $queryParams = GlobalHelper::formatRequestData();
995 + } catch (\InvalidArgumentException $e) {
996 + wp_send_json_error($e->getMessage(), 400);
997 + }
915 998 if (
916 999 empty($queryParams->tokenDetails)
917 1000 || empty($queryParams->dataCenter)
918 1001 || empty($queryParams->clientId)
@@ -970,13 +1053,20 @@
970 1053 );
971 1054 }
972 1055 }
973 1056
974 - public static function refreshTagsAjaxHelper() {
1057 + public static function refreshTagsAjaxHelper()
1058 + {
975 1059 $authorizationHeader = null;
976 - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) {
977 - $inputJSON = file_get_contents('php://input');
978 - $queryParams = json_decode($inputJSON);
1060 + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) {
1061 + GlobalHelper::requirePostMethod();
1062 +
1063 + try {
1064 + $queryParams = GlobalHelper::formatRequestData();
1065 + } catch (\InvalidArgumentException $e) {
1066 + wp_send_json_error($e->getMessage(), 400);
1067 + }
1068 +
979 1069 if (
980 1070 empty($queryParams->tokenDetails)
981 1071 || empty($queryParams->dataCenter)
982 1072 || empty($queryParams->clientId)
@@ -1038,9 +1128,10 @@
1038 1128 );
1039 1129 }
1040 1130 }
1041 1131
1042 - protected static function _refreshAccessToken($apiData) {
1132 + protected static function _refreshAccessToken($apiData)
1133 + {
1043 1134 if (
1044 1135 empty($apiData->dataCenter)
1045 1136 || empty($apiData->clientId)
1046 1137 || empty($apiData->clientSecret)
@@ -1070,15 +1161,16 @@
1070 1161
1071 1162 /**
1072 1163 * Save updated access_token to avoid unnecessary token generation
1073 1164 *
1074 - * @param Integer $formID ID of Integration related form
1075 - * @param Integer $integrationID ID of Zoho crm Integration
1076 - * @param Obeject $tokenDetails refreshed token info
1165 + * @param integer $formID ID of Integration related form
1166 + * @param integer $integrationID ID of Zoho crm Integration
1167 + * @param object $tokenDetails refreshed token info
1077 1168 *
1078 1169 * @return null
1079 1170 */
1080 - protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null) {
1171 + protected static function _saveRefreshedToken($formID, $integrationID, $tokenDetails, $others = null)
1172 + {
1081 1173 if (empty($formID) || empty($integrationID)) {
1082 1174 return;
1083 1175 }
1084 1176
@@ -1094,12 +1186,13 @@
1094 1186 if (!empty($others['portals'])) {
1095 1187 $newDetails->default->portals = $others['portals'];
1096 1188 }
1097 1189
1098 - $integrationHandler->updateIntegration($integrationID, $zprojectsDetails[0]->integration_name, 'Zoho Projects', \json_encode($newDetails), 'form');
1190 + $integrationHandler->updateIntegration($integrationID, $zprojectsDetails[0]->integration_name, 'Zoho Projects', wp_json_encode($newDetails), 'form');
1099 1191 }
1100 1192
1101 - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) {
1193 + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
1194 + {
1102 1195 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
1103 1196
1104 1197 $tokenDetails = $integrationDetails->tokenDetails;
1105 1198 $portalId = $integrationDetails->portalId;