| @@ -1,189 +1,0 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -use AcyMailing\Types\DelayType; | |
| 4 | - | |
| 5 | -class SendinblueCredentials extends SendinblueClass | |
| 6 | -{ | |
| 7 | - /** | |
| 8 | - * @param array $credentials | |
| 9 | - * @param string $sendingMethod | |
| 10 | - * @param array $sendingMethodListParams this parameter is only used for the plugin sending method list | |
| 11 | - * | |
| 12 | - * @return void | |
| 13 | - */ | |
| 14 | - public function onAcymGetCredentialsSendingMethod(array &$credentials, string $sendingMethod, array $sendingMethodListParams = []) | |
| 15 | - { | |
| 16 | - if ($sendingMethod != plgAcymSendinblue::SENDING_METHOD_ID) return; | |
| 17 | - | |
| 18 | - $key = plgAcymSendinblue::SENDING_METHOD_ID.'_api_key'; | |
| 19 | - | |
| 20 | - $credentials = [ | |
| 21 | - $key => $sendingMethodListParams[$key] ?? $this->config->get($key, ''), | |
| 22 | - ]; | |
| 23 | - } | |
| 24 | - | |
| 25 | - public function getHeadersSendingMethod($sendingMethod, $credentials = []): array | |
| 26 | - { | |
| 27 | - if (empty($credentials)) { | |
| 28 | - $this->onAcymGetCredentialsSendingMethod($credentials, $sendingMethod); | |
| 29 | - } | |
| 30 | - | |
| 31 | - return [ | |
| 32 | - 'api-key:'.$credentials[plgAcymSendinblue::SENDING_METHOD_ID.'_api_key'], | |
| 33 | - 'accept: application/json', | |
| 34 | - 'content-type: application/json', | |
| 35 | - ]; | |
| 36 | - } | |
| 37 | - | |
| 38 | - public function getSendingMethodsHtmlSetting(&$data) | |
| 39 | - { | |
| 40 | - $needValidation = $this->config->get('sendinblue_validation', 0); | |
| 41 | - $remindMe = json_decode($this->config->get('remindme', '[]'), true); | |
| 42 | - | |
| 43 | - if (intval($needValidation) === 1 && !in_array('sendinblue_validation', $remindMe)) { | |
| 44 | - $docUrl = ACYM_DOCUMENTATION.'external-sending-method/sendinblue#my-account-needs-validation'; | |
| 45 | - | |
| 46 | - $message = acym_translation('ACYM_SENDINBLUE_VALIDATION_NEEDED'); | |
| 47 | - $message .= '<br/><a href="'.$docUrl.'" target="_blank">'.$docUrl.'</a>'; | |
| 48 | - $message .= ' <a href="#" class="acym__do__not__remindme acym__do__not__remindme__info" title="sendinblue_validation">'; | |
| 49 | - $message .= acym_translation('ACYM_DO_NOT_REMIND_ME'); | |
| 50 | - $message .= '</a>'; | |
| 51 | - | |
| 52 | - $notification = [ | |
| 53 | - 'name' => 'sendinblue_validation', | |
| 54 | - 'removable' => 0, | |
| 55 | - ]; | |
| 56 | - acym_enqueueMessage($message, 'info', true, [$notification]); | |
| 57 | - } else { | |
| 58 | - acym_removeDashboardNotification('sendinblue_validation'); | |
| 59 | - } | |
| 60 | - | |
| 61 | - $delayType = new DelayType(); | |
| 62 | - ob_start(); | |
| 63 | - $delayType->display( | |
| 64 | - 'config['.plgAcymSendinblue::SENDING_METHOD_ID.'_clean_frequency]', | |
| 65 | - $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_clean_frequency', 604800), | |
| 66 | - DelayType::TYPE_WEEKS_MONTHS | |
| 67 | - ); | |
| 68 | - $delay = ob_get_clean(); | |
| 69 | - $config = empty($data['tab']) ? $this->config : $data['tab']->config; | |
| 70 | - $defaultApiKey = $config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_api_key'); | |
| 71 | - ?> | |
| 72 | - <div class="send_settings cell grid-x acym_vcenter" id="<?php echo esc_attr(plgAcymSendinblue::SENDING_METHOD_ID); ?>_settings"> | |
| 73 | - <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings"> | |
| 74 | - <label class="cell shrink margin-right-1" for="<?php echo esc_attr(plgAcymSendinblue::SENDING_METHOD_ID); ?>_settings_api-key"> | |
| 75 | - <?php echo esc_html(acym_translationSprintf('ACYM_SENDING_METHOD_API_KEY', plgAcymSendinblue::SENDING_METHOD_NAME)); ?> | |
| 76 | - </label> | |
| 77 | - <?php $this->getLinks('https://get.brevo.com/hbvmwg6onvve'); ?> | |
| 78 | - <input type="text" | |
| 79 | - id="<?php echo esc_attr(plgAcymSendinblue::SENDING_METHOD_ID); ?>_settings_api-key" | |
| 80 | - value="<?php echo esc_attr(empty($defaultApiKey) ? $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_api_key') : $defaultApiKey); ?>" | |
| 81 | - name="config[<?php echo esc_attr(plgAcymSendinblue::SENDING_METHOD_ID); ?>_api_key]" | |
| 82 | - class="cell margin-next-1 acym__configuration__mail__settings__text"> | |
| 83 | - <?php $this->getTestCredentialsSendingMethodButton(plgAcymSendinblue::SENDING_METHOD_ID); ?> | |
| 84 | - <?php $this->getCopySettingsButton($data, plgAcymSendinblue::SENDING_METHOD_ID, 'wp_mail_smtp'); ?> | |
| 85 | - <div class="cell grid-x margin-top-1 acym__sending__methods__synch"> | |
| 86 | - <button type="button" | |
| 87 | - sending-method-id="<?php echo esc_attr(plgAcymSendinblue::SENDING_METHOD_ID); ?>" | |
| 88 | - class="acym__configuration__sending__synch__users cell shrink button button-secondary"> | |
| 89 | - <?php echo esc_html(acym_translation('ACYM_SYNCHRO_EXISTING_USERS')); ?> | |
| 90 | - </button> | |
| 91 | - <span class="acym__configuration__sending__method-icon cell shrink margin-left-1 acym_vcenter"></span> | |
| 92 | - <span class="acym__configuration__sending__method-synch__message cell shrink margin-left-1 acym_vcenter"></span> | |
| 93 | - </div> | |
| 94 | - <?php if (!$this->plugin->isLogFileEmpty()) { ?> | |
| 95 | - <div class="cell grid-x margin-top-1 acym__sending__methods__log"> | |
| 96 | - <?php | |
| 97 | - acym_modal( | |
| 98 | - acym_translation('ACYM_REPORT_SEE'), | |
| 99 | - '', | |
| 100 | - null, | |
| 101 | - [], | |
| 102 | - [ | |
| 103 | - 'class' => 'button', | |
| 104 | - 'data-ajax' => 'true', | |
| 105 | - 'data-iframe' => '&ctrl=configuration&task=seeLogs&filename='.$this->plugin->logFilename, | |
| 106 | - ] | |
| 107 | - ); | |
| 108 | - ?> | |
| 109 | - </div> | |
| 110 | - <?php } ?> | |
| 111 | - <div class="cell grid-x margin-top-1 acym_vcenter acym__sending__methods__clean__data"> | |
| 112 | - <?php echo wp_kses( | |
| 113 | - acym_translationSprintf('ACYM_CLEAN_DATA_ON_X_X', plgAcymSendinblue::SENDING_METHOD_NAME, $delay), | |
| 114 | - [ | |
| 115 | - 'input' => [ | |
| 116 | - 'class' => true, | |
| 117 | - 'type' => true, | |
| 118 | - 'id' => true, | |
| 119 | - 'name' => true, | |
| 120 | - 'value' => true, | |
| 121 | - 'min' => true, | |
| 122 | - ], | |
| 123 | - 'select' => [ | |
| 124 | - 'name' => true, | |
| 125 | - 'id' => true, | |
| 126 | - 'class' => true, | |
| 127 | - ], | |
| 128 | - 'option' => [ | |
| 129 | - 'value' => true, | |
| 130 | - 'selected' => true, | |
| 131 | - ], | |
| 132 | - ] | |
| 133 | - ); ?> | |
| 134 | - </div> | |
| 135 | - </div> | |
| 136 | - </div> | |
| 137 | - <?php | |
| 138 | - } | |
| 139 | - | |
| 140 | - public function testCredentialSendingMethod($sendingMethod, $credentials) | |
| 141 | - { | |
| 142 | - if ($sendingMethod == plgAcymSendinblue::SENDING_METHOD_ID) { | |
| 143 | - $headers = $this->getHeadersSendingMethod(plgAcymSendinblue::SENDING_METHOD_ID, $credentials); | |
| 144 | - $response = $this->callApiSendingMethod('account', [], $headers); | |
| 145 | - if (!empty($response['error_curl'])) { | |
| 146 | - acym_sendAjaxResponse(acym_translationSprintf('ACYM_ERROR_OCCURRED_WHILE_CALLING_API', $response['error_curl']), [], false); | |
| 147 | - } elseif (!empty($response['code'])) { | |
| 148 | - $message = $response['code'] == 'unauthorized' | |
| 149 | - ? acym_translation('ACYM_AUTHENTICATION_FAILS_WITH_API_KEY') | |
| 150 | - : acym_translationSprintf( | |
| 151 | - 'ACYM_API_RETURN_THIS_ERROR', | |
| 152 | - $response['message'] | |
| 153 | - ); | |
| 154 | - acym_sendAjaxResponse($message, [], false); | |
| 155 | - } else { | |
| 156 | - acym_sendAjaxResponse(acym_translation('ACYM_API_KEY_CORRECT')); | |
| 157 | - } | |
| 158 | - } | |
| 159 | - } | |
| 160 | - | |
| 161 | - public function getCreditRemainingSendingMethod(&$html) | |
| 162 | - { | |
| 163 | - $sendingMethod = $this->config->get('mailer_method', ''); | |
| 164 | - if (empty($sendingMethod) || $sendingMethod != plgAcymSendinblue::SENDING_METHOD_ID) return; | |
| 165 | - $apiKey = $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_api_key', ''); | |
| 166 | - if (empty($apiKey)) return; | |
| 167 | - | |
| 168 | - $headers = $this->getHeadersSendingMethod(plgAcymSendinblue::SENDING_METHOD_ID); | |
| 169 | - $response = $this->callApiSendingMethod('account', [], $headers); | |
| 170 | - | |
| 171 | - if (!empty($response['code']) || empty($response['plan'])) { | |
| 172 | - $html = acym_translationSprintf( | |
| 173 | - 'ACYM_SENDING_METHOD_ERROR_WHILE_ACTION', | |
| 174 | - plgAcymSendinblue::SENDING_METHOD_NAME, | |
| 175 | - acym_translation('ACYM_GETTING_REMAINING_CREDITS'), | |
| 176 | - $response['message'] | |
| 177 | - ); | |
| 178 | - | |
| 179 | - return; | |
| 180 | - } | |
| 181 | - | |
| 182 | - $html = acym_translationSprintf( | |
| 183 | - 'ACYM_SENDING_METHOD_X_UNITY', | |
| 184 | - plgAcymSendinblue::SENDING_METHOD_NAME, | |
| 185 | - $response['plan'][0]['credits'], | |
| 186 | - '<span class="acym_not_bold">'.acym_translation('ACYM_CREDITS_REMAINING').'</span>' | |
| 187 | - ); | |
| 188 | - } | |
| 189 | -} | |