PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.2
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.10.2, at back/dynamics/sendinblue/credentials.php

165 lines 7.7 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 $notification = [
46 'name' => 'sendinblue_validation',
47 'removable' => 0,
48 ];
49 acym_enqueueMessage($message, 'info', true, [$notification]);
50 } else {
51 acym_removeDashboardNotification('sendinblue_validation');
52 }
53
54 $delayType = new DelayType();
55 $config = empty($data['tab']) ? $this->config : $data['tab']->config;
56 $defaultApiKey = $config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_api_key');
57 ob_start();
58 ?>
59 <div class="send_settings cell grid-x acym_vcenter" id="<?php echo plgAcymSendinblue::SENDING_METHOD_ID; ?>_settings">
60 <div class="cell grid-x acym_vcenter acym__sending__methods__one__settings">
61 <label class="cell shrink margin-right-1" for="<?php echo plgAcymSendinblue::SENDING_METHOD_ID; ?>_settings_api-key">
62 <?php echo acym_translationSprintf('ACYM_SENDING_METHOD_API_KEY', plgAcymSendinblue::SENDING_METHOD_NAME); ?>
63 </label>
64 <?php echo $this->getLinks('https://get.brevo.com/hbvmwg6onvve'); ?>
65 <input type="text"
66 id="<?php echo plgAcymSendinblue::SENDING_METHOD_ID; ?>_settings_api-key"
67 value="<?php echo empty($defaultApiKey) ? $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_api_key') : $defaultApiKey; ?>"
68 name="config[<?php echo plgAcymSendinblue::SENDING_METHOD_ID; ?>_api_key]"
69 class="cell margin-next-1 acym__configuration__mail__settings__text">
70 <?php echo $this->getTestCredentialsSendingMethodButton(plgAcymSendinblue::SENDING_METHOD_ID); ?>
71 <?php echo $this->getCopySettingsButton($data, plgAcymSendinblue::SENDING_METHOD_ID, 'wp_mail_smtp'); ?>
72 <div class="cell grid-x margin-top-1 acym__sending__methods__synch">
73 <button type="button"
74 sending-method-id="<?php echo plgAcymSendinblue::SENDING_METHOD_ID; ?>"
75 class="acym__configuration__sending__synch__users cell shrink button button-secondary">
76 <?php echo acym_translation('ACYM_SYNCHRO_EXISTING_USERS'); ?>
77 </button>
78 <span class="acym__configuration__sending__method-icon cell shrink margin-left-1 acym_vcenter"></span>
79 <span class="acym__configuration__sending__method-synch__message cell shrink margin-left-1 acym_vcenter"></span>
80 </div>
81 <?php if (!$this->plugin->isLogFileEmpty()) { ?>
82 <div class="cell grid-x margin-top-1 acym__sending__methods__log">
83 <?php
84 echo acym_modal(
85 acym_translation('ACYM_REPORT_SEE'),
86 '',
87 null,
88 [],
89 [
90 'class' => 'button',
91 'data-ajax' => 'true',
92 'data-iframe' => '&ctrl=configuration&task=seeLogs&filename='.$this->plugin->logFilename,
93 ]
94 );
95 ?>
96 </div>
97 <?php } ?>
98 <div class="cell grid-x margin-top-1 acym_vcenter acym__sending__methods__clean__data">
99 <?php echo acym_translationSprintf(
100 'ACYM_CLEAN_DATA_ON_X_X',
101 plgAcymSendinblue::SENDING_METHOD_NAME,
102 $delayType->display(
103 'config['.plgAcymSendinblue::SENDING_METHOD_ID.'_clean_frequency]',
104 $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_clean_frequency', 604800),
105 DelayType::TYPE_WEEKS_MONTHS
106 )
107 ); ?>
108 </div>
109 </div>
110 </div>
111 <?php
112 $data['sendingMethodsHtmlSettings'][plgAcymSendinblue::SENDING_METHOD_ID] = ob_get_clean();
113 }
114
115 public function testCredentialSendingMethod($sendingMethod, $credentials)
116 {
117 if ($sendingMethod == plgAcymSendinblue::SENDING_METHOD_ID) {
118 $headers = $this->getHeadersSendingMethod(plgAcymSendinblue::SENDING_METHOD_ID, $credentials);
119 $response = $this->callApiSendingMethod('account', [], $headers);
120 if (!empty($response['error_curl'])) {
121 acym_sendAjaxResponse(acym_translationSprintf('ACYM_ERROR_OCCURRED_WHILE_CALLING_API', $response['error_curl']), [], false);
122 } elseif (!empty($response['code'])) {
123 $message = $response['code'] == 'unauthorized'
124 ? acym_translation('ACYM_AUTHENTICATION_FAILS_WITH_API_KEY')
125 : acym_translationSprintf(
126 'ACYM_API_RETURN_THIS_ERROR',
127 $response['message']
128 );
129 acym_sendAjaxResponse($message, [], false);
130 } else {
131 acym_sendAjaxResponse(acym_translation('ACYM_API_KEY_CORRECT'));
132 }
133 }
134 }
135
136 public function getCreditRemainingSendingMethod(&$html)
137 {
138 $sendingMethod = $this->config->get('mailer_method', '');
139 if (empty($sendingMethod) || $sendingMethod != plgAcymSendinblue::SENDING_METHOD_ID) return;
140 $apiKey = $this->config->get(plgAcymSendinblue::SENDING_METHOD_ID.'_api_key', '');
141 if (empty($apiKey)) return;
142
143 $headers = $this->getHeadersSendingMethod(plgAcymSendinblue::SENDING_METHOD_ID);
144 $response = $this->callApiSendingMethod('account', [], $headers);
145
146 if (!empty($response['code']) || empty($response['plan'])) {
147 $html = acym_translationSprintf(
148 'ACYM_SENDING_METHOD_ERROR_WHILE_ACTION',
149 plgAcymSendinblue::SENDING_METHOD_NAME,
150 acym_translation('ACYM_GETTING_REMAINING_CREDITS'),
151 $response['message']
152 );
153
154 return;
155 }
156
157 $html = acym_translationSprintf(
158 'ACYM_SENDING_METHOD_X_UNITY',
159 plgAcymSendinblue::SENDING_METHOD_NAME,
160 $response['plan'][0]['credits'],
161 '<span class="acym_not_bold">'.acym_translation('ACYM_CREDITS_REMAINING').'</span>'
162 );
163 }
164 }
165