← All changes
|
includes/Core/Integration/Rapidmail/RapidmailHandler.php
+42
-15
2.0
→
3.3.1
View file →
| @@ -6,19 +6,30 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace BitCode\BitForm\Core\Integration\Rapidmail; |
| 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; |
| 16 | +use BitCode\BitForm\GlobalHelper; | |
| 12 | 17 | use WP_Error; |
| 13 | 18 | |
| 14 | -class RapidmailHandler { | |
| 19 | +class RapidmailHandler | |
| 20 | +{ | |
| 15 | 21 | private $_integrationID; |
| 16 | 22 | public static $apiBaseUri = 'https://apiv3.emailsys.net/v1'; |
| 17 | 23 | protected $_defaultHeader; |
| 18 | 24 | |
| 19 | - public function __construct($integrationID) { | |
| 25 | + private $formID; | |
| 26 | + | |
| 27 | + public function __construct($integrationID, $formID) | |
| 28 | + { | |
| 20 | 29 | $this->_integrationID = $integrationID; |
| 30 | + | |
| 31 | + $this->formID = $formID; | |
| 21 | 32 | } |
| 22 | 33 | |
| 23 | 34 | /** |
| 24 | 35 | * Helps to register ajax function's with wp |
| @@ -24,19 +35,26 @@ | ||
| 24 | 35 | * Helps to register ajax function's with wp |
| 25 | 36 | * |
| 26 | 37 | * @return null |
| 27 | 38 | */ |
| 28 | - public static function registerAjax() { | |
| 39 | + public static function registerAjax() | |
| 40 | + { | |
| 29 | 41 | add_action('wp_ajax_bitforms_rapidmail_authorization', [__CLASS__, 'checkAuthorization']); |
| 30 | 42 | add_action('wp_ajax_bitforms_rapidmail_get_all_recipients', [__CLASS__, 'getAllRecipients']); |
| 31 | 43 | add_action('wp_ajax_bitforms_rapidmail_get_all_fields', [__CLASS__, 'getAllFields']); |
| 32 | 44 | } |
| 33 | 45 | |
| 34 | - public static function checkAuthorization() { | |
| 35 | - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 36 | - $inputJSON = file_get_contents('php://input'); | |
| 37 | - $tokenRequestParams = json_decode($inputJSON); | |
| 46 | + public static function checkAuthorization() | |
| 47 | + { | |
| 48 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 49 | + GlobalHelper::requirePostMethod(); | |
| 38 | 50 | |
| 51 | + try { | |
| 52 | + $tokenRequestParams = GlobalHelper::formatRequestData(); | |
| 53 | + } catch (\InvalidArgumentException $e) { | |
| 54 | + wp_send_json_error($e->getMessage(), 400); | |
| 55 | + } | |
| 56 | + | |
| 39 | 57 | if ( |
| 40 | 58 | empty($tokenRequestParams->username) |
| 41 | 59 | || empty($tokenRequestParams->password) |
| 42 | 60 | ) { |
| @@ -75,14 +93,20 @@ | ||
| 75 | 93 | * @param $queryParams Mandatory params to get recipients |
| 76 | 94 | * |
| 77 | 95 | * @return JSON rapidmailmail recipientlists data |
| 78 | 96 | */ |
| 79 | - public static function getAllRecipients() { | |
| 97 | + public static function getAllRecipients() | |
| 98 | + { | |
| 80 | 99 | $response = null; |
| 81 | - if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { | |
| 82 | - $inputJSON = file_get_contents('php://input'); | |
| 83 | - $queryParams = json_decode($inputJSON); | |
| 100 | + if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['_ajax_nonce'])), 'bitforms_save')) { | |
| 101 | + GlobalHelper::requirePostMethod(); | |
| 84 | 102 | |
| 103 | + try { | |
| 104 | + $queryParams = GlobalHelper::formatRequestData(); | |
| 105 | + } catch (\InvalidArgumentException $e) { | |
| 106 | + wp_send_json_error($e->getMessage(), 400); | |
| 107 | + } | |
| 108 | + | |
| 85 | 109 | if ( |
| 86 | 110 | empty($queryParams->username) |
| 87 | 111 | || empty($queryParams->password) |
| 88 | 112 | ) { |
| @@ -114,9 +138,10 @@ | ||
| 114 | 138 | wp_send_json_success($response, 200); |
| 115 | 139 | } |
| 116 | 140 | } |
| 117 | 141 | |
| 118 | - public static function getAllFields($queryParams) { | |
| 142 | + public static function getAllFields($queryParams) | |
| 143 | + { | |
| 119 | 144 | if ( |
| 120 | 145 | empty($queryParams->username) |
| 121 | 146 | || empty($queryParams->password) |
| 122 | 147 | ) { |
| @@ -147,9 +172,10 @@ | ||
| 147 | 172 | $response['recipientlists'] = $data; |
| 148 | 173 | wp_send_json_success($response, 200); |
| 149 | 174 | } |
| 150 | 175 | |
| 151 | - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) { | |
| 176 | + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) | |
| 177 | + { | |
| 152 | 178 | $integrationDetails = $integrationData->integration_details; |
| 153 | 179 | if (is_string($integrationDetails)) { |
| 154 | 180 | $integrationDetails = json_decode($integrationDetails); |
| 155 | 181 | } |
| @@ -172,9 +198,9 @@ | ||
| 172 | 198 | return $error; |
| 173 | 199 | } |
| 174 | 200 | $actions = $integrationDetails->actions; |
| 175 | 201 | |
| 176 | - $recordApiHelper = new RecordApiHelper($integrationDetails, $username, $password, $logID); | |
| 202 | + $recordApiHelper = new RecordApiHelper($integrationDetails, $username, $password, $logID, $entryID); | |
| 177 | 203 | $rapidmailResponse = $recordApiHelper->executeRecordApi( |
| 178 | 204 | $this->_integrationID, |
| 179 | 205 | $defaultDataConf, |
| 180 | 206 | $recipientLists, |
| @@ -179,9 +205,10 @@ | ||
| 179 | 205 | $defaultDataConf, |
| 180 | 206 | $recipientLists, |
| 181 | 207 | $fieldValues, |
| 182 | 208 | $fieldMap, |
| 183 | - $actions | |
| 209 | + $actions, | |
| 210 | + $this->formID, | |
| 184 | 211 | ); |
| 185 | 212 | if (is_wp_error($rapidmailResponse)) { |
| 186 | 213 | return $rapidmailResponse; |
| 187 | 214 | } |