PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.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 / Core / wordpress / form.php

form.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.4, at back/Core/wordpress/form.php

466 lines 16.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') || die('Restricted Access');
4
5 use AcyMailing\Classes\FieldClass;
6 use AcyMailing\Classes\ListClass;
7 use AcyMailing\Classes\UserClass;
8 use AcyMailing\Core\AcymParameter;
9 use AcyMailing\FrontControllers\FrontusersController;
10 use AcyMailing\FrontControllers\ArchiveController;
11
12 function acym_formToken(): void
13 {
14 echo '<input type="hidden" name="_wpnonce" value="'.esc_attr(wp_create_nonce('acymnonce')).'">';
15 }
16
17 /**
18 * Check token with all the possibilities
19 */
20 function acym_checkToken(): void
21 {
22 $token = acym_getVar('cmd', '_wpnonce');
23 if (!wp_verify_nonce($token, 'acymnonce')) {
24 die('Invalid Token');
25 }
26 }
27
28 function acym_getFormToken(): string
29 {
30 $token = acym_getVar('cmd', '_wpnonce', '');
31 if (empty($token)) {
32 $token = wp_create_nonce('acymnonce');
33 acym_setVar('_wpnonce', $token);
34 }
35
36 return '_wpnonce='.$token;
37 }
38
39 function acym_noTemplate(): string
40 {
41 return 'noheader=1';
42 }
43
44 function acym_isNoTemplate(): bool
45 {
46 return acym_getVar('cmd', 'noheader') == '1';
47 }
48
49 function acym_setNoTemplate(bool $status = true): void
50 {
51 if ($status) {
52 acym_setVar('noheader', '1');
53 } else {
54 unset($_REQUEST['noheader']);
55 }
56 }
57
58 function acym_formOptions(bool $token = true, string $task = '', string $currentStep = '', string $currentCtrl = '', bool $addPage = true): void
59 {
60 if (!empty($currentStep)) {
61 echo '<input type="hidden" name="step" value="'.esc_attr($currentStep).'"/>';
62 }
63 echo '<input type="hidden" name="nextstep" value=""/>';
64 echo '<input type="hidden" name="task" value="'.esc_attr($task).'"/>';
65 if ($addPage) {
66 echo '<input type="hidden" name="page" value="'.esc_attr(acym_getVar('cmd', 'page', '')).'"/>';
67 }
68 echo '<input type="hidden" name="ctrl" value="'.esc_attr(empty($currentCtrl) ? acym_getVar('cmd', 'ctrl', '') : $currentCtrl).'"/>';
69 if ($token) {
70 acym_formToken();
71 }
72 echo '<button type="submit" class="is-hidden" id="formSubmit"></button>';
73 }
74
75 global $acymMetaData;
76 function acym_addMetadata($meta, $data, string $name = 'name'): void
77 {
78 global $acymMetaData;
79
80 $tag = new stdClass();
81 $tag->meta = $meta;
82 $tag->data = $data;
83 $tag->name = $name;
84
85 $acymMetaData[] = $tag;
86 }
87
88 add_action('wp_head', 'acym_head_wp');
89 add_action('admin_head', 'acym_head_wp');
90 add_action('acym_head', 'acym_head_wp');
91 function acym_head_wp(): void
92 {
93 global $acymMetaData;
94
95 if (!empty($acymMetaData)) {
96 foreach ($acymMetaData as $metadata) {
97 if (empty($metadata->data)) {
98 echo '<meta '.esc_attr($metadata->name).'="'.esc_attr($metadata->meta).'"/>';
99 } else {
100 echo '<meta '.esc_attr($metadata->name).'="'.esc_attr($metadata->meta).'" content="'.esc_attr($metadata->data).'"/>';
101 }
102 }
103 }
104
105 $acymMetaData = [];
106 }
107
108 function acym_includeHeaders(): void
109 {
110 do_action('acym_head');
111 }
112
113 function acym_getOptionRegacyPosition(): void
114 {
115 }
116
117 function acym_renderForm(AcymParameter $params, array $args = []): void
118 {
119 acym_initModule($params);
120
121 if (!empty($args['before_widget'])) {
122 echo wp_kses_post($args['before_widget']);
123 }
124
125 $title = apply_filters('widget_title', $params->get('title'));
126 if (!empty($title)) {
127 if (!empty($args['before_title'])) {
128 echo wp_kses_post($args['before_title']);
129 }
130 echo esc_html($title);
131 if (!empty($args['after_title'])) {
132 echo wp_kses_post($args['after_title']);
133 }
134 }
135
136 $identifiedUser = null;
137 $currentUserEmail = acym_currentUserEmail();
138 $userClass = new UserClass();
139 if ($params->get('userinfo', '1') == '1' && !empty($currentUserEmail)) {
140 $identifiedUser = $userClass->getOneByEmail($currentUserEmail);
141 }
142
143 $visibleLists = $params->get('displists', []);
144 $hiddenLists = $params->get('hiddenlists', []);
145 $allFields = $params->get('fields', []);
146 acym_arrayToInteger($visibleLists);
147 acym_arrayToInteger($hiddenLists);
148 acym_arrayToInteger($allFields);
149
150 // We need the email address
151 if (!in_array(2, $allFields)) {
152 $allFields[] = 2;
153 }
154
155 $listClass = new ListClass();
156 $fieldClass = new FieldClass();
157
158 $allLists = $listClass->getAllWithoutManagement(true);
159 $visibleLists = array_intersect($visibleLists, array_keys($allLists));
160 $hiddenLists = array_intersect($hiddenLists, array_keys($allLists));
161
162 $allFields = $fieldClass->getFieldsByID($allFields);
163 $fields = [];
164 foreach ($allFields as $field) {
165 if (intval($field->active) === 0) continue;
166 $fields[$field->id] = $field;
167 }
168
169 if (empty($visibleLists) && empty($hiddenLists)) {
170 $hiddenLists = array_keys($allLists);
171 }
172
173 // Make sure we don't display a list that's in "automatically subscribe to"
174 if (!empty($visibleLists) && !empty($hiddenLists)) {
175 $visibleLists = array_diff($visibleLists, $hiddenLists);
176 }
177
178 if (empty($identifiedUser->id)) {
179 //Check lists based on the option
180 $checkedLists = $params->get('listschecked', []);
181 if (!is_array($checkedLists)) {
182 if (strtolower($checkedLists) == 'all') {
183 $checkedLists = $visibleLists;
184 } elseif (strpos($checkedLists, ',') || is_numeric($checkedLists)) {
185 $checkedLists = explode(',', $checkedLists);
186 } else {
187 $checkedLists = [];
188 }
189 }
190 } else {
191 $checkedLists = [];
192 $userLists = $userClass->getUserSubscriptionById($identifiedUser->id);
193
194 $countSub = 0;
195 $countUnsub = 0;
196 $formLists = array_merge($visibleLists, $hiddenLists);
197 foreach ($formLists as $idOneList) {
198 if (empty($userLists[$idOneList]) || $userLists[$idOneList]->status == 0) {
199 $countSub++;
200 } else {
201 $countUnsub++;
202 $checkedLists[] = $idOneList;
203 }
204 }
205 }
206 acym_arrayToInteger($checkedLists);
207
208 $config = acym_config();
209
210 // Texts
211 $subscribeText = $params->get('subtext', 'ACYM_SUBSCRIBE');
212 if (!empty($identifiedUser->id)) $subscribeText = $params->get('subtextlogged', 'ACYM_SUBSCRIBE');
213 $unsubscribeText = $params->get('unsubtext', 'ACYM_UNSUBSCRIBE');
214 $unsubButton = $params->get('unsub', '0');
215
216 $disableButtons = !empty($args['disableButtons']) || acym_isAdmin();
217
218 // Formatting
219 $listPosition = $params->get('listposition', 'before');
220 $displayOutside = $params->get('textmode') == '0';
221
222 $showTrackingConsent = $params->get('trackingconsent', '0') == '1';
223
224 // Display success message
225 $successMode = $params->get('successmode', 'replace');
226
227 // Redirections
228 $redirectURL = $params->get('redirect', '');
229 $unsubRedirectURL = $params->get('unsubredirect', '');
230 $ajax = empty($redirectURL) && empty($unsubRedirectURL) && $successMode != 'standard' ? '1' : '0';
231
232 // Customization
233 $formClass = $params->get('formclass', '');
234 $alignment = $params->get('alignment', 'none');
235
236 // Articles
237 $termsURL = acym_getArticleURL($params->get('termscontent', 0), false, 'ACYM_TERMS_CONDITIONS');
238 $privacyURL = acym_getArticleURL($params->get('privacypolicy', 0), false, 'ACYM_PRIVACY_POLICY');
239
240 if (empty($termsURL)) {
241 $termsURL = $params->get('termscontentURL') ?? '';
242 if (!empty($termsURL)) {
243 $termsURL = '<a href="'.esc_url($termsURL).'" target="_blank">'.esc_html(acym_translation('ACYM_TERMS_CONDITIONS')).'</a>';
244 }
245 }
246
247 if (empty($privacyURL)) {
248 $privacyURL = $params->get('privacypolicyURL') ?? '';
249 if (!empty($privacyURL)) {
250 $privacyURL = '<a href="'.esc_url($privacyURL).'" target="_blank">'.esc_html(acym_translation('ACYM_PRIVACY_POLICY')).'</a>';
251 }
252 }
253
254 if (empty($termsURL) && empty($privacyURL)) {
255 $termslink = '';
256 } elseif (empty($privacyURL)) {
257 $termslink = acym_translationSprintf('ACYM_I_AGREE_TERMS', $termsURL);
258 } elseif (empty($termsURL)) {
259 $termslink = acym_translationSprintf('ACYM_I_AGREE_PRIVACY', $privacyURL);
260 } else {
261 $termslink = acym_translationSprintf('ACYM_I_AGREE_BOTH', $termsURL, $privacyURL);
262 }
263
264 $formName = acym_getModuleFormName();
265 $formAction = htmlspecialchars_decode(acym_frontendLink('frontusers'));
266
267 $buttonStyle = '';
268 if (!empty($params->get('button_background_color', ''))) $buttonStyle .= 'background-color: '.esc_attr($params->get('button_background_color', '')).';';
269 if (!empty($params->get('button_text_color', ''))) $buttonStyle .= 'color: '.esc_attr($params->get('button_text_color', '')).';';
270 if (strlen($params->get('button_border_size', '')) > 0) $buttonStyle .= 'border-width: '.esc_attr($params->get('button_border_size', '')).'px;';
271 if (!empty($params->get('button_border_type', ''))) $buttonStyle .= 'border-style: '.esc_attr($params->get('button_border_type', '')).';';
272 if (!empty($params->get('button_border_color', ''))) $buttonStyle .= 'border-color: '.esc_attr($params->get('button_border_color', '')).';';
273 if (strlen($params->get('button_border_radius', '')) > 0) $buttonStyle .= 'border-radius: '.esc_attr($params->get('button_border_radius', '')).'px;';
274
275 if (!empty($buttonStyle)) {
276 acym_addStyle(true, '#acym_module_'.$formName.' .acysubbuttons .subbutton {'.$buttonStyle.'}');
277 }
278
279 $globalStyle = '';
280 if (!empty($params->get('background_color', ''))) $globalStyle .= 'background-color: '.$params->get('background_color', '').';';
281 if (!empty($params->get('text_color', ''))) $globalStyle .= 'color: '.$params->get('text_color', '').';';
282
283 if (!empty($globalStyle)) {
284 acym_addStyle(true, '#acym_module_'.$formName.', #acym_module_'.$formName.' td {'.$globalStyle.'}');
285 }
286
287 // Exclude default values from fields, if the user didn't fill them in
288 ?>
289 <script type="text/javascript">
290 window.addEventListener('DOMContentLoaded', (event) => {
291 window.acymModule[<?php echo json_encode('excludeValues'.$formName); ?>] = [];
292 <?php
293 foreach ($fields as $field) {
294 echo 'window.acymModule["excludeValues'.esc_attr($formName).'"]["'.esc_attr($field->id).'"] = '.json_encode(acym_translation($field->name)).';';
295 }
296 ?>
297 });
298 </script>
299 <div class="acym_module <?php echo esc_attr($formClass); ?>" id="acym_module_<?php echo esc_attr($formName); ?>">
300 <div class="acym_fulldiv" id="acym_fulldiv_<?php echo esc_attr($formName); ?>" <?php echo $alignment === 'none' ? '' : 'style="text-align: '.esc_attr($alignment).'"'; ?>>
301 <form enctype="multipart/form-data"
302 id="<?php echo esc_attr($formName); ?>"
303 name="<?php echo esc_attr($formName); ?>"
304 method="POST"
305 action="<?php echo esc_attr($formAction); ?>"
306 onsubmit="return submitAcymForm('subscribe','<?php echo esc_attr($formName); ?>')">
307 <div class="acym_module_form">
308 <?php
309 $introText = $params->get('introtext', '');
310 if (!empty($introText)) {
311 echo '<div class="acym_introtext">'.esc_html($introText).'</div>';
312 }
313 if ($params->get('mode', 'tableless') === 'tableless') {
314 include ACYM_FOLDER.'widgets'.DS.'subscriptionform'.DS.'tmpl'.DS.'tableless.php';
315 } else {
316 $displayInline = $params->get('mode', 'tableless') !== 'vertical';
317 include ACYM_FOLDER.'widgets'.DS.'subscriptionform'.DS.'tmpl'.DS.'default.php';
318 }
319 ?>
320 </div>
321
322 <input type="hidden" name="ctrl" value="frontusers" />
323 <input type="hidden" name="task" value="notask" />
324 <input type="hidden" name="option" value="<?php echo esc_attr(ACYM_COMPONENT); ?>" />
325
326 <?php
327 if (!empty($redirectURL)) echo '<input type="hidden" name="redirect" value="'.esc_url($redirectURL).'"/>';
328 if (!empty($unsubRedirectURL)) echo '<input type="hidden" name="redirectunsub" value="'.esc_url($unsubRedirectURL).'"/>';
329 ?>
330 <input type="hidden" name="ajax" value="<?php echo esc_attr($ajax); ?>" />
331 <input type="hidden" name="successmode" value="<?php echo esc_attr($successMode); ?>" />
332 <input type="hidden" name="acy_source" value="<?php echo esc_attr($params->get('source', '')); ?>" />
333 <input type="hidden" name="hiddenlists" value="<?php echo esc_attr(implode(',', $hiddenLists)); ?>" />
334 <input type="hidden" name="acyformname" value="<?php echo esc_attr($formName); ?>" />
335 <input type="hidden" name="acysubmode" value="widget_acym" />
336 <input type="hidden" name="confirmation_message" value="<?php echo esc_attr($params->get('confirmation_message', '')); ?>" />
337
338 <?php
339 $postText = $params->get('posttext', '');
340 if (!empty($postText)) {
341 echo '<div class="acym_posttext">'.esc_html($postText).'</div>';
342 }
343 ?>
344 </form>
345 </div>
346 </div>
347 <?php
348 if (!empty($args['after_widget'])) {
349 echo wp_kses_post($args['after_widget']);
350 }
351 }
352
353 function acym_renderFormProfile(AcymParameter $params, array $args = []): string
354 {
355 acym_initModule($params);
356
357 if (!is_array($params->get('listsdropdown', '0'))) {
358 $listDropdown = $params->get('listsdropdown', '0');
359 } else {
360 $listDropdown = $params->get('listsdropdown')[0];
361 }
362
363 $instance = [
364 'title' => $params->get('title', ''),
365 'lists' => $params->get('lists'),
366 'listschecked' => $params->get('listschecked'),
367 'dropdown' => $listDropdown,
368 'hiddenlists' => $params->get('hiddenlists'),
369 'fields' => $params->get('fields'),
370 'introtext' => $params->get('introtext', ''),
371 'posttext' => $params->get('posttext', ''),
372 'source' => $params->get('source', ''),
373 ];
374
375 $title = apply_filters('widget_title', $instance['title']);
376 if (!empty($title)) {
377 $title = '<span class="gamma widget-title">'.esc_html($title).'</span>';
378 }
379 $return = $title;
380
381 ob_start();
382 acym_setVar('page', ACYM_COMPONENT.'_front');
383
384 $userController = new FrontusersController();
385 $data = $userController->prepareParams((object)$instance);
386 $data['disableButtons'] = !empty($args['disableButtons']) || acym_isAdmin();
387
388 if (empty($data['user']->language)) {
389 $cmsUserLanguage = acym_getCmsUserLanguage();
390 $data['user']->language = empty($cmsUserLanguage) ? acym_getLanguageTag() : $cmsUserLanguage;
391 }
392
393 acym_setVar('layout', 'profile');
394 $userController->display($data);
395 $return .= ob_get_clean();
396
397 return $return;
398 }
399
400 function acym_renderFormArchive(AcymParameter $params, array $args = []): string
401 {
402 acym_initModule($params);
403
404 if (!is_array($params->get('popup', '1'))) {
405 $popup = $params->get('popup', '1');
406 } else {
407 $popup = $params->get('popup')[0];
408 }
409 if (!is_array($params->get('displayUserListOnly', '1'))) {
410 $displayUserListOnly = $params->get('displayUserListOnly', '1');
411 } else {
412 $displayUserListOnly = $params->get('displayUserListOnly')[0];
413 }
414
415 $instance = [
416 'title' => $params->get('title', ''),
417 'archiveNbNewslettersPerPage' => $params->get('archiveNbNewslettersPerPage', 20),
418 'lists' => $params->get('lists'),
419 'popup' => $popup,
420 'displayUserListOnly' => $displayUserListOnly,
421 ];
422
423 $title = apply_filters('widget_title', $instance['title']);
424 if (!empty($title)) {
425 $title = '<span class="gamma widget-title">'.esc_html($title).'</span>';
426 }
427 $return = $title;
428 ob_start();
429 acym_setVar('page', 'front');
430 $searchs = acym_getVar('array', 'acym_search', []);
431 $search = '';
432 if (!empty($searchs[0])) $search = $searchs[0];
433 $disableButtons = !empty($args['disableButtons']) || acym_isAdmin();
434 $viewParams = [
435 'listsSent' => isset($instance['lists']) ? $instance['lists'] : [],
436 'popup' => isset($instance['popup']) ? $instance['popup'] : '1',
437 'displayUserListOnly' => isset($instance['displayUserListOnly']) ? $instance['displayUserListOnly'] : '1',
438 'paramsCMS' => ['widget_id' => 0, 'suffix' => ''],
439 'search' => $search,
440 'disableButtons' => $disableButtons,
441 'nbNewslettersPerPage' => $instance['archiveNbNewslettersPerPage'],
442 ];
443
444 $archiveController = new ArchiveController();
445 $archiveController->showArchive($viewParams);
446
447 $return .= ob_get_clean();
448
449 return $return;
450 }
451
452 function acym_checked(bool $checked, bool $current = true, bool $display = true): string
453 {
454 return checked($checked, $current, $display);
455 }
456
457 function acym_selected(bool $selected, bool $current = true, bool $display = true): string
458 {
459 return selected($selected, $current, $display);
460 }
461
462 function acym_disabled(bool $disabled, bool $current = true, bool $display = true): string
463 {
464 return disabled($disabled, $current, $display);
465 }
466