| @@ -25,30 +25,30 @@ | ||
| 25 | 25 | public function onAcymGetSendingMethodsHtmlSetting(&$data) |
| 26 | 26 | { |
| 27 | 27 | $config = empty($data['tab']) ? $this->config : $data['tab']->config; |
| 28 | 28 | $defaultApiKey = $config->get(self::SENDING_METHOD_ID.'_api_key'); |
| 29 | - ob_start(); | |
| 30 | 29 | ?> |
| 31 | - <div class="send_settings cell grid-x acym_vcenter" id="<?php echo self::SENDING_METHOD_ID; ?>_settings"> | |
| 30 | + <div class="send_settings cell grid-x acym_vcenter" id="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_settings"> | |
| 32 | 31 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 33 | - <label class="cell shrink margin-right-1" for="<?php echo self::SENDING_METHOD_ID; ?>_settings_api-key"> | |
| 34 | - <?php echo acym_translationSprintf( | |
| 35 | - 'ACYM_SENDING_METHOD_API_KEY', | |
| 36 | - self::SENDING_METHOD_NAME | |
| 32 | + <label class="cell shrink margin-right-1" for="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_settings_api-key"> | |
| 33 | + <?php echo esc_html( | |
| 34 | + acym_translationSprintf( | |
| 35 | + 'ACYM_SENDING_METHOD_API_KEY', | |
| 36 | + self::SENDING_METHOD_NAME | |
| 37 | + ) | |
| 37 | 38 | ); ?> |
| 38 | 39 | </label> |
| 39 | - <?php echo $this->getLinks('https://signup.sendgrid.com/', 'https://sendgrid.com/pricing/'); ?> | |
| 40 | + <?php $this->getLinks('https://signup.sendgrid.com/', 'https://sendgrid.com/pricing/'); ?> | |
| 40 | 41 | <input type="text" |
| 41 | - id="<?php echo self::SENDING_METHOD_ID; ?>_settings_api-key" | |
| 42 | - value="<?php echo empty($defaultApiKey) ? $this->config->get(self::SENDING_METHOD_ID.'_api_key') : $defaultApiKey; ?>" | |
| 43 | - name="config[<?php echo self::SENDING_METHOD_ID; ?>_api_key]" | |
| 44 | - class="cell margin-right-1 acym__configuration__mail__settings__text"> | |
| 45 | - <?php echo $this->getTestCredentialsSendingMethodButton(self::SENDING_METHOD_ID); ?> | |
| 46 | - <?php echo $this->getCopySettingsButton($data, self::SENDING_METHOD_ID, 'wp_mail_smtp'); ?> | |
| 42 | + id="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_settings_api-key" | |
| 43 | + value="<?php echo esc_attr(empty($defaultApiKey) ? $this->config->get(self::SENDING_METHOD_ID.'_api_key') : $defaultApiKey); ?>" | |
| 44 | + name="config[<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_api_key]" | |
| 45 | + class="cell margin-next-1 acym__configuration__mail__settings__text"> | |
| 46 | + <?php $this->getTestCredentialsSendingMethodButton(self::SENDING_METHOD_ID); ?> | |
| 47 | + <?php $this->getCopySettingsButton($data, self::SENDING_METHOD_ID, 'wp_mail_smtp'); ?> | |
| 47 | 48 | </div> |
| 48 | 49 | </div> |
| 49 | 50 | <?php |
| 50 | - $data['sendingMethodsHtmlSettings'][self::SENDING_METHOD_ID] = ob_get_clean(); | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | public function onAcymTestCredentialSendingMethod($sendingMethod, $credentials) |
| 54 | 54 | { |
| @@ -57,9 +57,9 @@ | ||
| 57 | 57 | $response = $this->callApiSendingMethod(self::SENDING_METHOD_API_URL.'scopes', [], $headers); |
| 58 | 58 | if (!empty($response['error_curl'])) { |
| 59 | 59 | acym_sendAjaxResponse(acym_translationSprintf('ACYM_ERROR_OCCURRED_WHILE_CALLING_API', $response['error_curl']), [], false); |
| 60 | 60 | } elseif (!empty($response['errors'])) { |
| 61 | - $message = $response['errors'][0]['message'] == 'authorization required' | |
| 61 | + $message = $response['errors'][0]['message'] === 'authorization required' | |
| 62 | 62 | ? acym_translation('ACYM_AUTHENTICATION_FAILS_WITH_API_KEY') |
| 63 | 63 | : acym_translationSprintf( |
| 64 | 64 | 'ACYM_API_RETURN_THIS_ERROR', |
| 65 | 65 | $response['errors'][0]['message'] |
| @@ -72,8 +72,9 @@ | ||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | public function onAcymSendEmail(&$response, $mailerHelper, $to, $from, $reply_to, $bcc = [], $attachments = [], $sendingMethodListParams = []) |
| 75 | 75 | { |
| 76 | + //https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html | |
| 76 | 77 | if ($mailerHelper->externalMailer !== self::SENDING_METHOD_ID) return; |
| 77 | 78 | $headers = $this->getHeadersSendingMethod(self::SENDING_METHOD_ID, [], $sendingMethodListParams); |
| 78 | 79 | $headers[] = 'Content-Type: application/json'; |
| 79 | 80 | |
| @@ -133,11 +134,18 @@ | ||
| 133 | 134 | $response['message'] = $responseMailer['errors'][0]['message']; |
| 134 | 135 | } |
| 135 | 136 | } |
| 136 | 137 | |
| 138 | + /** | |
| 139 | + * @param array $credentials | |
| 140 | + * @param string $sendingMethod | |
| 141 | + * @param array $sendingMethodListParams this parameter is only used for the plugin sending method list | |
| 142 | + * | |
| 143 | + * @return void | |
| 144 | + */ | |
| 137 | 145 | public function onAcymGetCredentialsSendingMethod(array &$credentials, string $sendingMethod, array $sendingMethodListParams = []) |
| 138 | 146 | { |
| 139 | - if ($sendingMethod != self::SENDING_METHOD_ID) return; | |
| 147 | + if ($sendingMethod !== self::SENDING_METHOD_ID) return; | |
| 140 | 148 | |
| 141 | 149 | $key = self::SENDING_METHOD_ID.'_api_key'; |
| 142 | 150 | |
| 143 | 151 | $credentials = [ |
| @@ -147,9 +155,9 @@ | ||
| 147 | 155 | |
| 148 | 156 | public function onAcymGetCreditRemainingSendingMethod(&$html, $reloading = false) |
| 149 | 157 | { |
| 150 | 158 | $sendingMethod = $this->config->get('mailer_method', ''); |
| 151 | - if (empty($sendingMethod) || $sendingMethod != self::SENDING_METHOD_ID) return; | |
| 159 | + if (empty($sendingMethod) || $sendingMethod !== self::SENDING_METHOD_ID) return; | |
| 152 | 160 | |
| 153 | 161 | $headers = $this->getHeadersSendingMethod(self::SENDING_METHOD_ID); |
| 154 | 162 | |
| 155 | 163 | $response = $this->callApiSendingMethod(self::SENDING_METHOD_API_URL.'user/credits', [], $headers); |
| @@ -165,9 +173,8 @@ | ||
| 165 | 173 | return; |
| 166 | 174 | } |
| 167 | 175 | |
| 168 | 176 | if (!isset($response['remain']) || !isset($response['total'])) { |
| 169 | - | |
| 170 | 177 | $html = acym_translationSprintf( |
| 171 | 178 | 'ACYM_SENDING_METHOD_ERROR_WHILE_ACTION', |
| 172 | 179 | self::SENDING_METHOD_NAME, |
| 173 | 180 | acym_translation('ACYM_GETTING_REMAINING_CREDITS'), |
| @@ -201,9 +208,9 @@ | ||
| 201 | 208 | } |
| 202 | 209 | |
| 203 | 210 | public function onAcymGetSettingsSendingMethodFromPlugin(&$data, $plugin, $method) |
| 204 | 211 | { |
| 205 | - if ($method != self::SENDING_METHOD_ID) return; | |
| 212 | + if ($method !== self::SENDING_METHOD_ID) return; | |
| 206 | 213 | |
| 207 | 214 | if (ACYM_CMS === 'wordpress' && $plugin === 'wp_mail_smtp') { |
| 208 | 215 | $wpMailSmtpSetting = get_option('wp_mail_smtp', ''); |
| 209 | 216 | if (empty($wpMailSmtpSetting) || empty($wpMailSmtpSetting['sendgrid']) || (!empty($wpMailSmtpSetting['sendgrid'] && empty($wpMailSmtpSetting['sendgrid']['api_key'])))) { |