| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | use AcyMailing\Core\AcymPlugin; |
| 4 | +use AcyMailing\Helpers\MailerHelper; | |
| 4 | 5 | |
| 5 | 6 | class plgAcymGoogle extends AcymPlugin |
| 6 | 7 | { |
| 7 | 8 | const SENDING_METHOD_ID = 'google'; |
| @@ -33,61 +34,65 @@ | ||
| 33 | 34 | |
| 34 | 35 | $refreshToken = $this->config->get('google_refresh_token'); |
| 35 | 36 | $refreshTokenExpiration = $this->config->get('google_refresh_token_expiration'); |
| 36 | 37 | $mustAuthenticate = empty($refreshToken) || (!empty($refreshTokenExpiration) && $refreshTokenExpiration < time()); |
| 37 | - | |
| 38 | - ob_start(); | |
| 39 | 38 | ?> |
| 40 | - <div class="send_settings grid-x cell large-6 xlarge-5 xxlarge-4 margin-auto" id="<?php echo self::SENDING_METHOD_ID; ?>_settings"> | |
| 39 | + <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"> | |
| 40 | + <div class="acym_port_465_closed is-hidden"> | |
| 41 | + <?php acym_display(acym_translation('ACYM_PORT_NEEDED'), 'error', false); ?> | |
| 42 | + </div> | |
| 41 | 43 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 42 | - <label for="google_username" class="cell"><?php echo acym_translation('ACYM_SMTP_USERNAME').acym_info('ACYM_SMTP_USERNAME_DESC'); ?></label> | |
| 44 | + <label for="google_username" class="cell"> | |
| 45 | + <?php echo esc_html(acym_translation('ACYM_SMTP_USERNAME')); | |
| 46 | + acym_info(['textShownInTooltip' => 'ACYM_SMTP_USERNAME_DESC']); ?> | |
| 47 | + </label> | |
| 43 | 48 | <input id="google_username" |
| 44 | - class="cell" | |
| 45 | - type="text" | |
| 46 | - name="config[google_username]" | |
| 47 | - value="<?php echo acym_escape($username); ?>"> | |
| 49 | + class="cell" | |
| 50 | + type="text" | |
| 51 | + name="config[google_username]" | |
| 52 | + value="<?php echo esc_attr($username); ?>"> | |
| 48 | 53 | </div> |
| 49 | 54 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 50 | - <label for="google_client_id" class="cell"><?php echo acym_externalLink('ACYM_SMTP_CLIENT_ID', $setupDocumentation, false); ?></label> | |
| 55 | + <label for="google_client_id" class="cell"><?php acym_externalLink('ACYM_SMTP_CLIENT_ID', $setupDocumentation, false); ?></label> | |
| 51 | 56 | <input id="google_client_id" |
| 52 | - class="cell" | |
| 53 | - type="text" | |
| 54 | - name="config[google_client_id]" | |
| 55 | - value="<?php echo acym_escape($this->config->get('google_client_id')); ?>"> | |
| 57 | + class="cell" | |
| 58 | + type="text" | |
| 59 | + name="config[google_client_id]" | |
| 60 | + value="<?php echo esc_attr($this->config->get('google_client_id')); ?>"> | |
| 56 | 61 | </div> |
| 57 | 62 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 58 | - <label for="google_client_secret" class="cell"><?php echo acym_externalLink('ACYM_SMTP_CLIENT_SECRET', $setupDocumentation, false); ?></label> | |
| 63 | + <label for="google_client_secret" class="cell"><?php acym_externalLink('ACYM_SMTP_CLIENT_SECRET', $setupDocumentation, false); ?></label> | |
| 59 | 64 | <input id="google_client_secret" |
| 60 | - class="cell" | |
| 61 | - type="text" | |
| 62 | - name="config[google_client_secret]" | |
| 63 | - value="<?php echo acym_escape($this->config->get('google_client_secret')); ?>"> | |
| 65 | + class="cell" | |
| 66 | + type="text" | |
| 67 | + name="config[google_client_secret]" | |
| 68 | + value="<?php echo esc_attr($this->config->get('google_client_secret')); ?>"> | |
| 64 | 69 | </div> |
| 65 | 70 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 66 | - <label for="google_redirect_url" class="cell"><?php echo acym_translation('ACYM_SMTP_REDIRECT_URL'); ?></label> | |
| 71 | + <label for="google_redirect_url" class="cell"><?php echo esc_html(acym_translation('ACYM_SMTP_REDIRECT_URL')); ?></label> | |
| 67 | 72 | <input id="google_redirect_url" |
| 68 | - class="cell" | |
| 69 | - type="text" | |
| 70 | - name="config[google_redirect_url]" | |
| 71 | - value="<?php echo acym_escape($redirectUrl); ?>"> | |
| 73 | + class="cell" | |
| 74 | + type="text" | |
| 75 | + name="config[google_redirect_url]" | |
| 76 | + value="<?php echo esc_attr($redirectUrl); ?>"> | |
| 72 | 77 | </div> |
| 73 | 78 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 74 | 79 | <?php if ($mustAuthenticate) { ?> |
| 75 | - <button acym-data-before="jQuery.acymConfigSave();" | |
| 76 | - data-task="loginForOAuth2Smtp" | |
| 77 | - class="button acy_button_submit margin-right-1"> | |
| 78 | - <?php echo acym_translation('ACYM_AUTHENTICATE'); ?> | |
| 80 | + <button data-before-action="configSave" | |
| 81 | + data-task="loginForOAuth2Smtp" | |
| 82 | + class="button acy_button_submit margin-next-1"> | |
| 83 | + <?php echo esc_html(acym_translation('ACYM_AUTHENTICATE')); ?> | |
| 79 | 84 | </button> |
| 80 | - <?php echo $this->getCopySettingsButton($data, self::SENDING_METHOD_ID, 'wp_mail_smtp', false); ?> | |
| 85 | + <?php $this->getCopySettingsButton($data, self::SENDING_METHOD_ID, 'wp_mail_smtp', false); ?> | |
| 81 | 86 | <?php } else { ?> |
| 82 | - <button acym-data-before="jQuery.acymConfigSave();" | |
| 83 | - data-task="logoutForOAuth2Smtp" | |
| 84 | - class="button acy_button_submit button-secondary margin-bottom-1"> | |
| 85 | - <?php echo acym_translation('ACYM_REVOKE_PERMISSIONS'); ?> | |
| 87 | + <button data-before-action="configSave" | |
| 88 | + data-task="logoutForOAuth2Smtp" | |
| 89 | + class="button acy_button_submit button-secondary margin-bottom-1"> | |
| 90 | + <?php echo esc_html(acym_translation('ACYM_REVOKE_PERMISSIONS')); ?> | |
| 86 | 91 | </button> |
| 87 | 92 | <?php |
| 88 | 93 | if (!empty($refreshTokenExpiration)) { |
| 89 | - echo acym_translationSprintf('ACYM_AUTHENTICATION_WILL_EXPIRE', acym_date($refreshTokenExpiration, 'ACYM_DATE_FORMAT_LC2')); | |
| 94 | + echo esc_html(acym_translationSprintf('ACYM_AUTHENTICATION_WILL_EXPIRE', acym_date($refreshTokenExpiration, 'ACYM_DATE_FORMAT_LC2'))); | |
| 90 | 95 | } |
| 91 | 96 | ?> |
| 92 | 97 | <?php } ?> |
| 93 | 98 | </div> |
| @@ -92,9 +97,8 @@ | ||
| 92 | 97 | <?php } ?> |
| 93 | 98 | </div> |
| 94 | 99 | </div> |
| 95 | 100 | <?php |
| 96 | - $data['sendingMethodsHtmlSettings'][self::SENDING_METHOD_ID] = ob_get_clean(); | |
| 97 | 101 | } |
| 98 | 102 | |
| 99 | 103 | public function onAcymGetSettingsSendingMethodFromPlugin(&$data, $plugin, $method) |
| 100 | 104 | { |
| @@ -114,8 +118,11 @@ | ||
| 114 | 118 | $data['google_client_secret'] = $wpMailSmtpSetting['gmail']['client_secret'] ?? ''; |
| 115 | 119 | } |
| 116 | 120 | } |
| 117 | 121 | |
| 122 | + /** | |
| 123 | + * Doc: https://developers.google.com/identity/protocols/oauth2/web-server#httprest_2 | |
| 124 | + */ | |
| 118 | 125 | public function onAcymOauthAuthenticate(string &$consentUrl, bool $isSmtp): void |
| 119 | 126 | { |
| 120 | 127 | if ($isSmtp) { |
| 121 | 128 | if ($this->config->get('mailer_method') !== self::SENDING_METHOD_ID) { |
| @@ -148,8 +155,11 @@ | ||
| 148 | 155 | $consentUrl .= '&scope='.urlencode('https://mail.google.com/'); |
| 149 | 156 | $consentUrl .= '&state=acymailing'.($isSmtp ? 'smtp' : 'bounce'); |
| 150 | 157 | } |
| 151 | 158 | |
| 159 | + /** | |
| 160 | + * Doc: https://developers.google.com/identity/protocols/oauth2/web-server#httprest_3 | |
| 161 | + */ | |
| 152 | 162 | public function onAcymOauthCredentialsCreation(bool $isSmtp, string $code): void |
| 153 | 163 | { |
| 154 | 164 | if ($isSmtp) { |
| 155 | 165 | if ($this->config->get('mailer_method') !== self::SENDING_METHOD_ID) { |
| @@ -230,9 +240,9 @@ | ||
| 230 | 240 | 'bounce_refresh_token_expiration' => $refreshExpiringTime, |
| 231 | 241 | ]; |
| 232 | 242 | } |
| 233 | 243 | |
| 234 | - $this->config->save($newConfig); | |
| 244 | + $this->config->saveConfig($newConfig); | |
| 235 | 245 | acym_config(true); |
| 236 | 246 | } |
| 237 | 247 | |
| 238 | 248 | public function onAcymOauthRevoke(): void |
| @@ -240,9 +250,9 @@ | ||
| 240 | 250 | if ($this->config->get('mailer_method') !== self::SENDING_METHOD_ID) { |
| 241 | 251 | return; |
| 242 | 252 | } |
| 243 | 253 | |
| 244 | - $this->config->save( | |
| 254 | + $this->config->saveConfig( | |
| 245 | 255 | [ |
| 246 | 256 | 'google_refresh_token' => '', |
| 247 | 257 | 'google_refresh_token_expiration' => '', |
| 248 | 258 | ] |