| @@ -5,9 +5,8 @@ | ||
| 5 | 5 | class plgAcymSmtp extends AcymPlugin |
| 6 | 6 | { |
| 7 | 7 | const SENDING_METHOD_ID = 'smtp'; |
| 8 | 8 | const SENDING_METHOD_NAME = 'SMTP'; |
| 9 | - const HOST_AUTH_2 = ['smtp.gmail.com', 'smtp-mail.outlook.com', 'smtp.office365.com']; | |
| 10 | 9 | |
| 11 | 10 | public function __construct() |
| 12 | 11 | { |
| 13 | 12 | parent::__construct(); |
| @@ -24,41 +23,34 @@ | ||
| 24 | 23 | } |
| 25 | 24 | |
| 26 | 25 | public function onAcymGetSendingMethodsHtmlSetting(&$data) |
| 27 | 26 | { |
| 28 | - $smtpRedirectUrl = trim($this->config->get('smtp_redirectUrl')); | |
| 29 | - $redirectUrl = empty($smtpRedirectUrl) ? acym_baseURI() : $smtpRedirectUrl; | |
| 30 | - | |
| 31 | - $isWalkTrough = $this->config->get('walk_through', 0); | |
| 32 | - $loginAttribute = !$isWalkTrough ? 'acym-data-before="jQuery.acymConfigSave();"' : ''; | |
| 33 | - | |
| 34 | - $link = ACYM_DOCUMENTATION.'setup/configuration/mail-configuration/set-up-oauth-2.0'; | |
| 35 | - | |
| 36 | - ob_start(); | |
| 37 | 27 | ?> |
| 38 | - <div class="send_settings grid-x cell large-6 xlarge-5 xxlarge-4 margin-auto" id="<?php echo self::SENDING_METHOD_ID; ?>_settings"> | |
| 28 | + <div class="send_settings grid-x cell large-6 xlarge-5 xxlarge-4 margin-auto" id="<?php echo esc_attr(self::SENDING_METHOD_ID); ?>_settings"> | |
| 39 | 29 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 40 | - <label for="smtp_host" class="cell"><?php echo acym_translation('ACYM_SMTP_SERVER'); ?></label> | |
| 41 | - <input id="smtp_host" class="cell" type="text" name="config[smtp_host]" value="<?php echo acym_escape($this->config->get('smtp_host')); ?>"> | |
| 30 | + <label for="smtp_host" class="cell"><?php echo esc_html(acym_translation('ACYM_SMTP_SERVER')); ?></label> | |
| 31 | + <input id="smtp_host" class="cell" type="text" name="config[smtp_host]" value="<?php echo esc_attr($this->config->get('smtp_host')); ?>"> | |
| 42 | 32 | </div> |
| 43 | 33 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 44 | - <label for="smtp_port" class="cell"><?php echo acym_translation('ACYM_SMTP_PORT').acym_info('ACYM_SMTP_PORT_DESC'); ?></label> | |
| 34 | + <label for="smtp_port" class="cell"><?php echo esc_html(acym_translation('ACYM_SMTP_PORT')); | |
| 35 | + acym_info(['textShownInTooltip' => 'ACYM_SMTP_PORT_DESC']); ?></label> | |
| 45 | 36 | <input |
| 46 | 37 | id="smtp_port" |
| 47 | 38 | class="cell medium-6" |
| 48 | 39 | type="number" |
| 49 | - name="config[smtp_port]" value="<?php echo acym_escape($this->config->get('smtp_port')); ?>" | |
| 40 | + name="config[smtp_port]" value="<?php echo esc_attr($this->config->get('smtp_port')); ?>" | |
| 50 | 41 | placeholder="465, 587, 2525, 25"> |
| 51 | 42 | </div> |
| 52 | 43 | <div id="available_ports" class="cell acym__sending__methods__one__settings"> |
| 53 | - <a href="#" id="available_ports_check"><?php echo acym_translation('ACYM_SMTP_AVAILABLE_PORTS'); ?></a> | |
| 54 | - <?php echo $this->getCopySettingsButton($data, self::SENDING_METHOD_ID, 'wp_mail_smtp'); ?> | |
| 44 | + <?php echo esc_html(acym_translation('ACYM_SMTP_AVAILABLE_PORTS')); ?> | |
| 45 | + <?php $this->getCopySettingsButton($data, self::SENDING_METHOD_ID, 'wp_mail_smtp'); ?> | |
| 55 | 46 | </div> |
| 56 | 47 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 57 | - <label for="smtp_secured" class="cell"><?php echo acym_translation('ACYM_SMTP_SECURE').acym_info('ACYM_SMTP_SECURE_DESC'); ?></label> | |
| 48 | + <label for="smtp_secured" class="cell"><?php echo esc_html(acym_translation('ACYM_SMTP_SECURE')); | |
| 49 | + acym_info(['textShownInTooltip' => 'ACYM_SMTP_SECURE_DESC']); ?></label> | |
| 58 | 50 | <div class="cell medium-6"> |
| 59 | 51 | <?php |
| 60 | - echo acym_select( | |
| 52 | + acym_select( | |
| 61 | 53 | [ |
| 62 | 54 | '' => '- - -', |
| 63 | 55 | 'ssl' => 'SSL', |
| 64 | 56 | 'tls' => 'TLS', |
| @@ -70,9 +62,11 @@ | ||
| 70 | 62 | 'acym-data-infinite' => '', |
| 71 | 63 | ], |
| 72 | 64 | '', |
| 73 | 65 | '', |
| 74 | - 'smtp_secured' | |
| 66 | + 'smtp_secured', | |
| 67 | + false, | |
| 68 | + true | |
| 75 | 69 | ); |
| 76 | 70 | ?> |
| 77 | 71 | </div> |
| 78 | 72 | </div> |
| @@ -77,39 +71,41 @@ | ||
| 77 | 71 | </div> |
| 78 | 72 | </div> |
| 79 | 73 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 80 | 74 | <?php |
| 81 | - echo acym_switch( | |
| 82 | - 'config[smtp_keepalive]', | |
| 83 | - $this->config->get('smtp_keepalive'), | |
| 84 | - acym_translation('ACYM_SMTP_ALIVE').acym_info('ACYM_SMTP_ALIVE_DESC'), | |
| 85 | - [], | |
| 86 | - 'medium-5 small-9' | |
| 87 | - ); | |
| 75 | + acym_switch([ | |
| 76 | + 'name' => 'config[smtp_keepalive]', | |
| 77 | + 'value' => $this->config->get('smtp_keepalive'), | |
| 78 | + 'label' => acym_translation('ACYM_SMTP_ALIVE'), | |
| 79 | + 'tip' => ['textShownInTooltip' => 'ACYM_SMTP_ALIVE_DESC'], | |
| 80 | + 'labelClass' => 'medium-5 small-9', | |
| 81 | + ]); | |
| 88 | 82 | ?> |
| 89 | 83 | </div> |
| 90 | 84 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 91 | 85 | <?php |
| 92 | - echo acym_switch( | |
| 93 | - 'config[smtp_auth]', | |
| 94 | - $this->config->get('smtp_auth', 1), | |
| 95 | - acym_translation('ACYM_SMTP_AUTHENTICATION').acym_info('ACYM_SMTP_AUTHENTICATION_DESC'), | |
| 96 | - [], | |
| 97 | - 'medium-5 small-9' | |
| 98 | - ); | |
| 86 | + acym_switch([ | |
| 87 | + 'name' => 'config[smtp_auth]', | |
| 88 | + 'value' => $this->config->get('smtp_auth', 1), | |
| 89 | + 'label' => acym_translation('ACYM_SMTP_AUTHENTICATION'), | |
| 90 | + 'tip' => ['textShownInTooltip' => 'ACYM_SMTP_AUTHENTICATION_DESC'], | |
| 91 | + 'labelClass' => 'medium-5 small-9', | |
| 92 | + ]); | |
| 99 | 93 | ?> |
| 100 | 94 | </div> |
| 101 | 95 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 102 | - <label for="smtp_method" class="cell"><?php echo acym_translation('ACYM_AUTHENTICATION_METHOD').acym_info('ACYM_AUTHENTICATION_METHOD_DESC'); ?></label> | |
| 96 | + <label for="smtp_method" class="cell"> | |
| 97 | + <?php echo esc_html(acym_translation('ACYM_AUTHENTICATION_METHOD')); | |
| 98 | + acym_info(['textShownInTooltip' => 'ACYM_AUTHENTICATION_METHOD_DESC']); ?> | |
| 99 | + </label> | |
| 103 | 100 | <div class="cell medium-6"> |
| 104 | 101 | <?php |
| 105 | - echo acym_select( | |
| 102 | + acym_select( | |
| 106 | 103 | [ |
| 107 | 104 | '' => acym_translation('ACYM_AUTOMATIC'), |
| 108 | 105 | 'CRAM-MD5' => 'CRAM-MD5', |
| 109 | 106 | 'LOGIN' => 'LOGIN', |
| 110 | 107 | 'PLAIN' => 'PLAIN', |
| 111 | - 'XOAUTH2' => 'XOAUTH2', | |
| 112 | 108 | ], |
| 113 | 109 | 'config[smtp_method]', |
| 114 | 110 | $this->config->get('smtp_method', ''), |
| 115 | 111 | [ |
| @@ -117,31 +113,10 @@ | ||
| 117 | 113 | 'acym-data-infinite' => '', |
| 118 | 114 | ], |
| 119 | 115 | '', |
| 120 | 116 | '', |
| 121 | - 'smtp_method' | |
| 122 | - ); | |
| 123 | - ?> | |
| 124 | - </div> | |
| 125 | - </div> | |
| 126 | - <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings" id="acym__sending__methods__one__settings__type"> | |
| 127 | - <label for="smtp_type" class="cell"><?php echo acym_translation('ACYM_CONNECTION_TYPE').acym_info('ACYM_CONNECTION_TYPE_DESC'); ?></label> | |
| 128 | - <div class="cell medium-6"> | |
| 129 | - <?php | |
| 130 | - echo acym_select( | |
| 131 | - [ | |
| 132 | - 'oauth' => 'ACYM_WITH_OAUTH', | |
| 133 | - 'password' => 'ACYM_WITH_PASSWORD', | |
| 134 | - ], | |
| 135 | - 'config[smtp_type]', | |
| 136 | - $this->config->get('smtp_type', 'oauth'), | |
| 137 | - [ | |
| 138 | - 'class' => 'acym__select', | |
| 139 | - 'acym-data-infinite' => '', | |
| 140 | - ], | |
| 141 | - '', | |
| 142 | - '', | |
| 143 | - 'smtp_type', | |
| 117 | + 'smtp_method', | |
| 118 | + false, | |
| 144 | 119 | true |
| 145 | 120 | ); |
| 146 | 121 | ?> |
| 147 | 122 | </div> |
| @@ -146,81 +121,38 @@ | ||
| 146 | 121 | ?> |
| 147 | 122 | </div> |
| 148 | 123 | </div> |
| 149 | 124 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 150 | - <label for="smtp_username" class="cell"><?php echo acym_translation('ACYM_SMTP_USERNAME').acym_info('ACYM_SMTP_USERNAME_DESC'); ?></label> | |
| 125 | + <label for="smtp_username" class="cell"><?php echo esc_html(acym_translation('ACYM_SMTP_USERNAME')); | |
| 126 | + acym_info(['textShownInTooltip' => 'ACYM_SMTP_USERNAME_DESC']); ?></label> | |
| 151 | 127 | <input id="smtp_username" |
| 152 | - class="cell" | |
| 153 | - type="text" | |
| 154 | - name="config[smtp_username]" | |
| 155 | - value="<?php echo acym_escape($this->config->get('smtp_username')); ?>"> | |
| 128 | + class="cell" | |
| 129 | + type="text" | |
| 130 | + name="config[smtp_username]" | |
| 131 | + value="<?php echo esc_attr($this->config->get('smtp_username')); ?>"> | |
| 156 | 132 | </div> |
| 157 | 133 | <div class="acym__default_auth_sending_params cell"> |
| 158 | 134 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings" id="oauthParams"> |
| 159 | - <label for="smtp_password" class="cell"><?php echo acym_translation('ACYM_SMTP_PASSWORD').acym_info('ACYM_SMTP_PASSWORD_DESC'); ?></label> | |
| 135 | + <label for="smtp_password" class="cell"> | |
| 136 | + <?php echo esc_html(acym_translation('ACYM_SMTP_PASSWORD')); | |
| 137 | + acym_info(['textShownInTooltip' => 'ACYM_SMTP_PASSWORD_DESC']); ?> | |
| 138 | + </label> | |
| 160 | 139 | <input id="smtp_password" |
| 161 | - class="cell" | |
| 162 | - type="text" | |
| 163 | - name="config[smtp_password]" | |
| 164 | - value="<?php echo str_repeat('*', strlen($this->config->get('smtp_password'))); ?>"> | |
| 140 | + class="cell" | |
| 141 | + type="text" | |
| 142 | + name="config[smtp_password]" | |
| 143 | + value="<?php echo esc_attr(str_repeat('*', strlen($this->config->get('smtp_password')))); ?>"> | |
| 165 | 144 | </div> |
| 166 | 145 | </div> |
| 167 | - <div class="acym__oauth2_sending_params cell"> | |
| 168 | - <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 169 | - <label for="smtp_clientId" class="cell"><?php echo acym_externalLink('ACYM_SMTP_CLIENT_ID', $link, false); ?></label> | |
| 170 | - <input id="smtp_clientId" class="cell" type="text" name="config[smtp_clientId]" value="<?php echo acym_escape($this->config->get('smtp_clientId')); ?>"> | |
| 171 | - </div> | |
| 172 | - <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 173 | - <label for="smtp_secret" class="cell"><?php echo acym_externalLink('ACYM_SMTP_CLIENT_SECRET', $link, false); ?></label> | |
| 174 | - <input id="smtp_secret" class="cell" type="text" name="config[smtp_secret]" value="<?php echo acym_escape($this->config->get('smtp_secret')); ?>"> | |
| 175 | - </div> | |
| 176 | - <div id="smtp_tenant_container" class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 177 | - <label for="smtp_tenant" class="cell"><?php echo acym_externalLink('ACYM_TENANT', $link, false); ?></label> | |
| 178 | - <?php | |
| 179 | - $valuesArray = [ | |
| 180 | - 'consumers' => 'ACYM_MICROSOFT_ACCOUNTS', | |
| 181 | - 'common' => 'ACYM_ANY_ACCOUNT_TYPE', | |
| 182 | - 'organizations' => 'ACYM_ORGANIZATIONS', | |
| 183 | - ]; | |
| 184 | - $value = $this->config->get('smtp_tenant'); | |
| 185 | - echo acym_select( | |
| 186 | - $valuesArray, | |
| 187 | - 'config[smtp_tenant]', | |
| 188 | - empty($value) ? 'consumers' : $value, | |
| 189 | - [ | |
| 190 | - 'class' => 'acym__select', | |
| 191 | - ], | |
| 192 | - '', | |
| 193 | - '', | |
| 194 | - '', | |
| 195 | - true | |
| 196 | - ); | |
| 197 | - ?> | |
| 198 | - </div> | |
| 199 | - <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 200 | - <label for="smtp_redirectUrl" class="cell"><?php echo acym_translation('ACYM_SMTP_REDIRECT_URL'); ?></label> | |
| 201 | - <input id="smtp_redirectUrl" class="cell" type="text" name="config[smtp_redirectUrl]" value="<?php echo acym_escape($redirectUrl); ?>"> | |
| 202 | - </div> | |
| 203 | - <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 204 | - <button <?php echo $loginAttribute; ?> | |
| 205 | - data-task="loginForOAuth2Smtp" | |
| 206 | - class="button acy_button_submit button-secondary margin-bottom-1" | |
| 207 | - id="smtp_account_login"> | |
| 208 | - <?php echo acym_translation('ACYM_LOGIN'); ?> | |
| 209 | - </button> | |
| 210 | - </div> | |
| 211 | - </div> | |
| 212 | 146 | </div> |
| 213 | 147 | <?php |
| 214 | - $data['sendingMethodsHtmlSettings'][self::SENDING_METHOD_ID] = ob_get_clean(); | |
| 215 | 148 | } |
| 216 | 149 | |
| 217 | - | |
| 218 | 150 | public function onAcymGetSettingsSendingMethodFromPlugin(&$data, $plugin, $method) |
| 219 | 151 | { |
| 220 | 152 | if ($method != self::SENDING_METHOD_ID) return; |
| 221 | 153 | |
| 222 | - if (ACYM_CMS == 'wordpress' && $plugin == 'wp_mail_smtp') { | |
| 154 | + if (ACYM_CMS === 'wordpress' && $plugin === 'wp_mail_smtp') { | |
| 223 | 155 | $wpMailSmtpSetting = get_option('wp_mail_smtp', ''); |
| 224 | 156 | if (empty($wpMailSmtpSetting) || empty($wpMailSmtpSetting['smtp'])) { |
| 225 | 157 | return; |
| 226 | 158 | } |
| @@ -231,28 +163,7 @@ | ||
| 231 | 163 | $data['smtp_keepalive'] = 1; |
| 232 | 164 | $data['smtp_auth'] = $wpMailSmtpSetting['smtp']['auth'] ? 1 : 0; |
| 233 | 165 | $data['smtp_username'] = $wpMailSmtpSetting['smtp']['user']; |
| 234 | 166 | $data['smtp_password'] = WPMailSMTP\Helpers\Crypto::decrypt($wpMailSmtpSetting['smtp']['pass']); |
| 235 | - } | |
| 236 | - } | |
| 237 | - | |
| 238 | - public function onAcymDisplayPage() | |
| 239 | - { | |
| 240 | - $mailerMethod = trim($this->config->get('mailer_method')); | |
| 241 | - if ($mailerMethod != self::SENDING_METHOD_ID) return; | |
| 242 | - | |
| 243 | - $clientId = trim($this->config->get('smtp_clientId')); | |
| 244 | - $secret = trim($this->config->get('smtp_secret')); | |
| 245 | - $host = trim($this->config->get('smtp_host')); | |
| 246 | - $connectionType = $this->config->get('smtp_type'); | |
| 247 | - | |
| 248 | - $requireAuth = false; | |
| 249 | - if (in_array($host, self::HOST_AUTH_2) && $connectionType !== 'password') { | |
| 250 | - $requireAuth = true; | |
| 251 | - } | |
| 252 | - | |
| 253 | - if ((empty($clientId) || empty($secret)) && $requireAuth) { | |
| 254 | - $link = '<a class="acym_message_link" href="'.acym_completeLink('configuration#oauthParams').'">'.strtolower(acym_translation('ACYM_HERE')).'</a>'; | |
| 255 | - acym_enqueueMessage(acym_translationSprintf('ACYM_SMTP_OAUTH_WARNING', $link), 'warning'); | |
| 256 | 167 | } |
| 257 | 168 | } |
| 258 | 169 | } |