PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / dynamics / sendinblue / credentials.php

credentials.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.1.4, at back/dynamics/sendinblue/credentials.php

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