PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.11.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.11.1
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 10.11.1, at back/Core/wordpress/form.php

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