| @@ -1,0 +1,91 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +use AcyMailing\Core\AcymPlugin; | |
| 4 | + | |
| 5 | +class plgAcymAmazon extends AcymPlugin | |
| 6 | +{ | |
| 7 | + const SENDING_METHOD_ID = 'amazon'; | |
| 8 | + const SENDING_METHOD_NAME = 'Amazon SES'; | |
| 9 | + // phpcs:ignore PluginCheck.CodeAnalysis.Offloading.OffloadedContent -- False alarm. | |
| 10 | + const SENDING_METHOD_HOST = 'email-smtp.us-east-2.amazonaws.com'; | |
| 11 | + | |
| 12 | + public function __construct() | |
| 13 | + { | |
| 14 | + parent::__construct(); | |
| 15 | + $this->pluginDescription->name = self::SENDING_METHOD_NAME; | |
| 16 | + } | |
| 17 | + | |
| 18 | + public function onAcymGetSendingMethods(&$data, $isMailer = false) | |
| 19 | + { | |
| 20 | + $data['sendingMethods'][self::SENDING_METHOD_ID] = [ | |
| 21 | + 'name' => $this->pluginDescription->name, | |
| 22 | + 'image' => ACYM_IMAGES.'mailers/amazon.png', | |
| 23 | + 'image_class' => '', | |
| 24 | + ]; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public function onAcymGetSendingMethodsHtmlSetting(&$data) | |
| 28 | + { | |
| 29 | + ?> | |
| 30 | + <div class="send_settings cell grid-x acym_vcenter" id="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_settings"> | |
| 31 | + <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 32 | + <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 33 | + <label for="amazon_host" class="cell shrink"> | |
| 34 | + <?php | |
| 35 | + echo esc_html(acym_translation('ACYM_AMAZON_SES_SERVER')); | |
| 36 | + acym_info( | |
| 37 | + [ | |
| 38 | + 'textShownInTooltip' => acym_translation('ACYM_AMAZON_SES_SERVER_DESC'), | |
| 39 | + ] | |
| 40 | + ); | |
| 41 | + ?> | |
| 42 | + </label> | |
| 43 | + <?php $this->getLinks( | |
| 44 | + 'https://signin.aws.amazon.com/signin?redirect_uri=https%3A%2F%2Fportal.aws.amazon.com%2Fbilling%2Fsignup%2Fresume&client_id=signup', | |
| 45 | + 'https://aws.amazon.com/en/ses/pricing/' | |
| 46 | + ); ?> | |
| 47 | + <input id="amazon_host" | |
| 48 | + class="cell" | |
| 49 | + type="text" | |
| 50 | + name="config[amazon_host]" | |
| 51 | + value="<?php echo esc_attr($this->config->get('amazon_host', self::SENDING_METHOD_HOST)); ?>"> | |
| 52 | + </div> | |
| 53 | + <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 54 | + <label for="amazon_username" class="cell"><?php echo esc_html(acym_translation('ACYM_AMAZON_SES_USERNAME')); ?></label> | |
| 55 | + <input id="amazon_username" | |
| 56 | + class="cell" | |
| 57 | + type="text" | |
| 58 | + name="config[amazon_username]" | |
| 59 | + value="<?php echo esc_attr($this->config->get('amazon_username')); ?>"> | |
| 60 | + </div> | |
| 61 | + <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 62 | + <label for="amazon_password" class="cell"><?php echo esc_html(acym_translation('ACYM_AMAZON_SES_PASSWORD')); ?></label> | |
| 63 | + <input id="amazon_password" | |
| 64 | + class="cell" | |
| 65 | + type="text" | |
| 66 | + name="config[amazon_password]" | |
| 67 | + value="<?php echo esc_attr(str_repeat('*', strlen($this->config->get('amazon_password')))); ?>"> | |
| 68 | + </div> | |
| 69 | + </div> | |
| 70 | + </div> | |
| 71 | + <?php | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * @param array $credentials | |
| 76 | + * @param string $sendingMethod | |
| 77 | + * @param array $sendingMethodListParams this parameter is only used for the plugin sending method list | |
| 78 | + * | |
| 79 | + * @return void | |
| 80 | + */ | |
| 81 | + public function onAcymGetCredentialsSendingMethod(array &$credentials, string $sendingMethod, array $sendingMethodListParams = []) | |
| 82 | + { | |
| 83 | + if ($sendingMethod != self::SENDING_METHOD_ID) return; | |
| 84 | + | |
| 85 | + $credentials = [ | |
| 86 | + self::SENDING_METHOD_ID.'_host' => $sendingMethodListParams[self::SENDING_METHOD_ID.'_host'] ?? $this->config->get(self::SENDING_METHOD_ID.'_host', ''), | |
| 87 | + self::SENDING_METHOD_ID.'_username' => $sendingMethodListParams[self::SENDING_METHOD_ID.'_username'] ?? $this->config->get(self::SENDING_METHOD_ID.'_username', ''), | |
| 88 | + self::SENDING_METHOD_ID.'_password' => $sendingMethodListParams[self::SENDING_METHOD_ID.'_password'] ?? $this->config->get(self::SENDING_METHOD_ID.'_password', ''), | |
| 89 | + ]; | |
| 90 | + } | |
| 91 | +} | |