| @@ -36,32 +36,29 @@ | ||
| 36 | 36 | |
| 37 | 37 | $refreshToken = $this->config->get('outlook_refresh_token'); |
| 38 | 38 | $refreshTokenExpiration = $this->config->get('outlook_refresh_token_expiration'); |
| 39 | 39 | $mustAuthenticate = empty($refreshToken) || (!empty($refreshTokenExpiration) && $refreshTokenExpiration < time()); |
| 40 | - | |
| 41 | - $mailerHelper = new MailerHelper(); | |
| 42 | - | |
| 43 | - ob_start(); | |
| 44 | 40 | ?> |
| 45 | - <div class="send_settings grid-x cell large-6 xlarge-5 xxlarge-4 margin-auto" id="<?php echo self::SENDING_METHOD_ID; ?>_settings"> | |
| 41 | + <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"> | |
| 46 | 42 | <div class="acym_port_465_closed is-hidden"> |
| 47 | 43 | <?php acym_display(acym_translation('ACYM_PORT_NEEDED'), 'error', false); ?> |
| 48 | 44 | </div> |
| 49 | 45 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 50 | 46 | <label for="outlook_username" class="cell"> |
| 51 | - <?php echo acym_translation('ACYM_SMTP_USERNAME').acym_info(['textShownInTooltip' => 'ACYM_SMTP_USERNAME_DESC']); ?> | |
| 47 | + <?php echo esc_html(acym_translation('ACYM_SMTP_USERNAME')); | |
| 48 | + acym_info(['textShownInTooltip' => 'ACYM_SMTP_USERNAME_DESC']); ?> | |
| 52 | 49 | </label> |
| 53 | 50 | <input id="outlook_username" |
| 54 | - class="cell" | |
| 55 | - type="text" | |
| 56 | - name="config[outlook_username]" | |
| 57 | - value="<?php echo acym_escape($username); ?>"> | |
| 51 | + class="cell" | |
| 52 | + type="text" | |
| 53 | + name="config[outlook_username]" | |
| 54 | + value="<?php echo esc_attr($username); ?>"> | |
| 58 | 55 | </div> |
| 59 | 56 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 60 | - <label for="outlook_tenant" class="cell"><?php echo acym_externalLink('ACYM_TENANT', $setupDocumentation, false); ?></label> | |
| 57 | + <label for="outlook_tenant" class="cell"><?php acym_externalLink('ACYM_TENANT', $setupDocumentation, false); ?></label> | |
| 61 | 58 | <?php |
| 62 | 59 | $value = $this->config->get('outlook_tenant'); |
| 63 | - echo acym_select( | |
| 60 | + acym_select( | |
| 64 | 61 | [ |
| 65 | 62 | 'common' => 'ACYM_ANY_ACCOUNT_TYPE', |
| 66 | 63 | 'consumers' => 'ACYM_MICROSOFT_ACCOUNTS', |
| 67 | 64 | 'organizations' => 'ACYM_ORGANIZATIONS', |
| @@ -73,53 +70,54 @@ | ||
| 73 | 70 | ], |
| 74 | 71 | '', |
| 75 | 72 | '', |
| 76 | 73 | '', |
| 74 | + true, | |
| 77 | 75 | true |
| 78 | 76 | ); |
| 79 | 77 | ?> |
| 80 | 78 | </div> |
| 81 | 79 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 82 | - <label for="outlook_client_id" class="cell"><?php echo acym_externalLink('ACYM_SMTP_CLIENT_ID', $setupDocumentation, false); ?></label> | |
| 80 | + <label for="outlook_client_id" class="cell"><?php acym_externalLink('ACYM_SMTP_CLIENT_ID', $setupDocumentation, false); ?></label> | |
| 83 | 81 | <input id="outlook_client_id" |
| 84 | - class="cell" | |
| 85 | - type="text" | |
| 86 | - name="config[outlook_client_id]" | |
| 87 | - value="<?php echo acym_escape($this->config->get('outlook_client_id')); ?>"> | |
| 82 | + class="cell" | |
| 83 | + type="text" | |
| 84 | + name="config[outlook_client_id]" | |
| 85 | + value="<?php echo esc_attr($this->config->get('outlook_client_id')); ?>"> | |
| 88 | 86 | </div> |
| 89 | 87 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 90 | - <label for="outlook_client_secret" class="cell"><?php echo acym_externalLink('ACYM_SMTP_CLIENT_SECRET', $setupDocumentation, false); ?></label> | |
| 88 | + <label for="outlook_client_secret" class="cell"><?php acym_externalLink('ACYM_SMTP_CLIENT_SECRET', $setupDocumentation, false); ?></label> | |
| 91 | 89 | <input id="outlook_client_secret" |
| 92 | - class="cell" | |
| 93 | - type="text" | |
| 94 | - name="config[outlook_client_secret]" | |
| 95 | - value="<?php echo acym_escape($this->config->get('outlook_client_secret')); ?>"> | |
| 90 | + class="cell" | |
| 91 | + type="text" | |
| 92 | + name="config[outlook_client_secret]" | |
| 93 | + value="<?php echo esc_attr($this->config->get('outlook_client_secret')); ?>"> | |
| 96 | 94 | </div> |
| 97 | 95 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 98 | - <label for="outlook_redirect_url" class="cell"><?php echo acym_translation('ACYM_SMTP_REDIRECT_URL'); ?></label> | |
| 96 | + <label for="outlook_redirect_url" class="cell"><?php echo esc_html(acym_translation('ACYM_SMTP_REDIRECT_URL')); ?></label> | |
| 99 | 97 | <input id="outlook_redirect_url" |
| 100 | - class="cell" | |
| 101 | - type="text" | |
| 102 | - name="config[outlook_redirect_url]" | |
| 103 | - value="<?php echo acym_escape($redirectUrl); ?>"> | |
| 98 | + class="cell" | |
| 99 | + type="text" | |
| 100 | + name="config[outlook_redirect_url]" | |
| 101 | + value="<?php echo esc_attr($redirectUrl); ?>"> | |
| 104 | 102 | </div> |
| 105 | 103 | <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> |
| 106 | 104 | <?php if ($mustAuthenticate) { ?> |
| 107 | 105 | <button data-before-action="configSave" |
| 108 | - data-task="loginForOAuth2Smtp" | |
| 109 | - class="button acy_button_submit margin-next-1"> | |
| 110 | - <?php echo acym_translation('ACYM_AUTHENTICATE'); ?> | |
| 106 | + data-task="loginForOAuth2Smtp" | |
| 107 | + class="button acy_button_submit margin-next-1"> | |
| 108 | + <?php echo esc_html(acym_translation('ACYM_AUTHENTICATE')); ?> | |
| 111 | 109 | </button> |
| 112 | - <?php echo $this->getCopySettingsButton($data, self::SENDING_METHOD_ID, 'wp_mail_smtp', false); ?> | |
| 110 | + <?php $this->getCopySettingsButton($data, self::SENDING_METHOD_ID, 'wp_mail_smtp', false); ?> | |
| 113 | 111 | <?php } else { ?> |
| 114 | 112 | <button data-before-action="configSave" |
| 115 | - data-task="logoutForOAuth2Smtp" | |
| 116 | - class="button acy_button_submit button-secondary margin-bottom-1"> | |
| 117 | - <?php echo acym_translation('ACYM_REVOKE_PERMISSIONS'); ?> | |
| 113 | + data-task="logoutForOAuth2Smtp" | |
| 114 | + class="button acy_button_submit button-secondary margin-bottom-1"> | |
| 115 | + <?php echo esc_html(acym_translation('ACYM_REVOKE_PERMISSIONS')); ?> | |
| 118 | 116 | </button> |
| 119 | 117 | <?php |
| 120 | 118 | if (!empty($refreshTokenExpiration)) { |
| 121 | - echo acym_translationSprintf('ACYM_AUTHENTICATION_WILL_EXPIRE', acym_date($refreshTokenExpiration, 'ACYM_DATE_FORMAT_LC2')); | |
| 119 | + echo esc_html(acym_translationSprintf('ACYM_AUTHENTICATION_WILL_EXPIRE', acym_date($refreshTokenExpiration, 'ACYM_DATE_FORMAT_LC2'))); | |
| 122 | 120 | } |
| 123 | 121 | ?> |
| 124 | 122 | <?php } ?> |
| 125 | 123 | </div> |
| @@ -124,9 +122,8 @@ | ||
| 124 | 122 | <?php } ?> |
| 125 | 123 | </div> |
| 126 | 124 | </div> |
| 127 | 125 | <?php |
| 128 | - $data['sendingMethodsHtmlSettings'][self::SENDING_METHOD_ID] = ob_get_clean(); | |
| 129 | 126 | } |
| 130 | 127 | |
| 131 | 128 | public function onAcymGetSettingsSendingMethodFromPlugin(&$data, $plugin, $method) |
| 132 | 129 | { |
| @@ -145,8 +142,11 @@ | ||
| 145 | 142 | $data['outlook_client_secret'] = $wpMailSmtpSetting['outlook']['client_secret'] ?? ''; |
| 146 | 143 | } |
| 147 | 144 | } |
| 148 | 145 | |
| 146 | + /** | |
| 147 | + * Doc: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#request-an-authorization-code | |
| 148 | + */ | |
| 149 | 149 | public function onAcymOauthAuthenticate(string &$consentUrl, bool $isSmtp): void |
| 150 | 150 | { |
| 151 | 151 | if ($isSmtp) { |
| 152 | 152 | if ($this->config->get('mailer_method') !== self::SENDING_METHOD_ID) { |
| @@ -185,8 +185,11 @@ | ||
| 185 | 185 | $consentUrl .= '&scope='.urlencode($scope); |
| 186 | 186 | $consentUrl .= '&state=acymailing'.($isSmtp ? 'smtp' : 'bounce'); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | + /** | |
| 190 | + * Doc: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#redeem-a-code-for-an-access-token | |
| 191 | + */ | |
| 189 | 192 | public function onAcymOauthCredentialsCreation(bool $isSmtp, string $code): void |
| 190 | 193 | { |
| 191 | 194 | if ($isSmtp) { |
| 192 | 195 | if ($this->config->get('mailer_method') !== self::SENDING_METHOD_ID) { |