PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.5
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.5
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 / Classes / FormClass.php

FormClass.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.5, at back/Classes/FormClass.php

747 lines 31.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Classes;
4
5 use AcyMailing\Helpers\PaginationHelper;
6 use AcyMailing\Core\AcymClass;
7
8 class FormClass extends AcymClass
9 {
10 const SUB_FORM_TYPE_SHORTCODE = 'shortcode';
11 const SUB_FORM_TYPE_POPUP = 'popup';
12 const SUB_FORM_TYPE_HEADER = 'header';
13 const SUB_FORM_TYPE_FOOTER = 'footer';
14
15 private array $settings = [];
16
17 public function __construct()
18 {
19 parent::__construct();
20
21 $this->table = 'form';
22 $this->pkey = 'id';
23 }
24
25 private function initSettings()
26 {
27 if (!empty($this->settings)) {
28 return;
29 }
30
31 $listClass = new ListClass();
32 $lists = $listClass->getAllForSelect(false);
33
34 $fieldClass = new FieldClass();
35 $allFields = $fieldClass->getAll();
36 $fields = [];
37 foreach ($allFields as $field) {
38 if ($field->id == 2 || intval($field->active) === 0) {
39 continue;
40 }
41 $fields[$field->id] = acym_translation($field->name);
42 }
43
44 $this->settings = [
45 'options' => [
46 'display' => [
47 'display_action' => [
48 'label' => 'ACYM_DISPLAY_ON_CLICK',
49 'description' => 'ACYM_DISPLAY_ON_CLICK_DESC',
50 'type' => 'select',
51 'options' => [
52 'yes' => acym_translation('ACYM_YES'),
53 'no' => acym_translation('ACYM_NO'),
54 ],
55 'default' => 'no',
56 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
57 ],
58 'button' => [
59 'label' => 'ACYM_BUTTON_ID',
60 'description' => 'ACYM_BUTTON_ID_DESC',
61 'type' => 'text',
62 'default' => '',
63 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
64 ],
65 'delay' => [
66 'label' => 'ACYM_DELAY',
67 'description' => 'ACYM_DELAY_DESC',
68 'type' => 'number',
69 'unit' => acym_translation('ACYM_SECONDS'),
70 'default' => 0,
71 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
72 ],
73 'scroll' => [
74 'label' => 'ACYM_SCROLL',
75 'description' => 'ACYM_SCROLL_DESC',
76 'type' => 'number',
77 'unit' => '%',
78 'max' => 100,
79 'default' => 0,
80 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
81 ],
82 'popup_position' => [
83 'label' => 'ACYM_POPUP_POSITION',
84 'type' => 'select',
85 'options' => [
86 'center' => acym_translation('ACYM_CENTER'),
87 'top_left' => acym_translation('ACYM_POSITION_LEFT_TOP'),
88 'top_center' => acym_translation('ACYM_POSITION_TOP_CENTER'),
89 'top_right' => acym_translation('ACYM_POSITION_RIGHT_TOP'),
90 'middle_left' => acym_translation('ACYM_POSITION_LEFT_MIDDLE'),
91 'middle_right' => acym_translation('ACYM_POSITION_RIGHT_MIDDLE'),
92 'bottom_left' => acym_translation('ACYM_POSITION_LEFT_BOTTOM'),
93 'bottom_center' => acym_translation('ACYM_POSITION_BOTTOM_CENTER'),
94 'bottom_right' => acym_translation('ACYM_POSITION_RIGHT_BOTTOM'),
95 ],
96 'default' => 'center',
97 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
98 ],
99 ],
100 'lists' => [
101 'automatic_subscribe' => [
102 'label' => 'ACYM_AUTO_SUBSCRIBE_TO',
103 'description' => 'ACYM_AUTO_SUBSCRIBE_TO_DESC',
104 'type' => 'multiselect',
105 'options' => $lists,
106 'default' => [],
107 ],
108 'displayed' => [
109 'label' => 'ACYM_DISPLAYED_LISTS',
110 'description' => 'ACYM_DISPLAYED_LISTS_DESC',
111 'type' => 'multiselect',
112 'options' => $lists,
113 'default' => [],
114 ],
115 'checked' => [
116 'label' => 'ACYM_LISTS_CHECKED_DEFAULT',
117 'description' => 'ACYM_LISTS_CHECKED_DEFAULT_DESC',
118 'type' => 'multiselect',
119 'options' => $lists,
120 'default' => [],
121 ],
122 'display_position' => [
123 'label' => 'ACYM_DISPLAY_LISTS',
124 'type' => 'select',
125 'options' => [
126 'after' => acym_translation('ACYM_AFTER_FIELDS'),
127 'before' => acym_translation('ACYM_BEFORE_FIELDS'),
128 ],
129 'default' => 'after',
130 ],
131 ],
132 'fields' => [
133 'displayed' => [
134 'label' => 'ACYM_FIELDS_TO_DISPLAY',
135 'type' => 'multiselect',
136 'options' => $fields,
137 'default' => [],
138 ],
139 'display_mode' => [
140 'label' => 'ACYM_DISPLAY_FIELDS_LABEL',
141 'type' => 'select',
142 'options' => [
143 'inside' => acym_translation('ACYM_TEXT_INSIDE'),
144 'outside' => acym_translation('ACYM_TEXT_OUTSIDE'),
145 ],
146 'default' => 'inside',
147 ],
148 'fields_width' => [
149 'label' => 'ACYM_FIELDS_WIDTH',
150 'description' => 'ACYM_FIELDS_WIDTH_DESC',
151 'type' => 'number',
152 'unit' => '%',
153 // Set to 65% by default to fit with the default size of the email field
154 'default' => 65,
155 ],
156 ],
157 'termspolicy' => [
158 'terms_type' => [
159 'label' => 'ACYM_TERMS_TYPE',
160 'type' => 'select',
161 'options' => [
162 'article' => acym_translation('ACYM_ARTICLE'),
163 'url' => acym_translation('ACYM_LINK'),
164 ],
165 'default' => 'article',
166 ],
167 'termscond' => [
168 'label' => 'ACYM_TERMS_CONDITIONS',
169 'type' => 'article',
170 'default' => 0,
171 'conditional' => ['terms_type' => 'article'],
172 ],
173 'terms_url' => [
174 'label' => 'ACYM_TERMS_CONDITIONS_URL',
175 'description' => 'ACYM_TERMS_CONDITIONS_URL_DESC',
176 'type' => 'text',
177 'default' => '',
178 'conditional' => ['terms_type' => 'url'],
179 ],
180 'privacy_type' => [
181 'label' => 'ACYM_PRIVACY_TYPE',
182 'type' => 'select',
183 'options' => [
184 'article' => acym_translation('ACYM_ARTICLE'),
185 'url' => acym_translation('ACYM_LINK'),
186 ],
187 'default' => 'article',
188 ],
189 'privacy' => [
190 'label' => 'ACYM_PRIVACY_POLICY',
191 'type' => 'article',
192 'default' => 0,
193 'conditional' => ['privacy_type' => 'article'],
194 ],
195 'privacy_url' => [
196 'label' => 'ACYM_PRIVACY_POLICY_URL',
197 'description' => 'ACYM_PRIVACY_POLICY_URL_DESC',
198 'type' => 'text',
199 'default' => '',
200 'conditional' => ['privacy_type' => 'url'],
201 ],
202 'tracking_consent' => [
203 'label' => 'ACYM_DISPLAY_TRACKING_CONSENT',
204 'description' => 'ACYM_DISPLAY_TRACKING_CONSENT_DESC',
205 'type' => 'select',
206 'options' => [
207 'no' => acym_translation('ACYM_NO'),
208 'yes' => acym_translation('ACYM_YES'),
209 ],
210 'default' => 'no',
211 ],
212 ],
213 'message' => [
214 'text' => [
215 'label' => 'ACYM_CUSTOM_MESSAGE_DISPLAY',
216 'type' => 'textarea',
217 'default' => '',
218 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
219 ],
220 'position' => [
221 'label' => 'ACYM_MESSAGE_POSITION',
222 'type' => 'select',
223 'options' => [
224 'before-image' => acym_translation('ACYM_BEFORE_IMAGE'),
225 'before-fields' => acym_translation('ACYM_BEFORE_FIELDS'),
226 'before-lists' => acym_translation('ACYM_BEFORE_LISTS'),
227 'before-button' => acym_translation('ACYM_BEFORE_BUTTON'),
228 ],
229 'default' => 'before-fields',
230 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
231 ],
232 'color' => [
233 'label' => 'ACYM_COLOR',
234 'type' => 'color',
235 'default' => '#000000',
236 ],
237 ],
238 'cookie' => [
239 'cookie_expiration' => [
240 'label' => 'ACYM_COOKIE_EXPIRATION',
241 'type' => 'number',
242 'min' => 1,
243 'unit' => acym_translation('ACYM_DAYS'),
244 'default' => 1,
245 'allowed_types' => [self::SUB_FORM_TYPE_POPUP, self::SUB_FORM_TYPE_HEADER, self::SUB_FORM_TYPE_FOOTER],
246 ],
247 ],
248 'redirection' => [
249 'after_subscription' => [
250 'label' => 'ACYM_AFTER_SUBSCRIPTION',
251 'description' => 'ACYM_REDIRECT_LINK_DESC',
252 'type' => 'text',
253 'default' => '',
254 ],
255 'confirmation_message' => [
256 'label' => 'ACYM_CONFIRMATION_MESSAGE',
257 'description' => 'ACYM_CONFIRMATION_MESSAGE_DESC',
258 'type' => 'text',
259 'default' => '',
260 ],
261 ],
262 'miscellaneous' => [
263 'js_loading' => [
264 'label' => 'ACYM_JS_LOADING',
265 'description' => 'ACYM_MODULE_JS_DESC',
266 'type' => 'select',
267 'options' => [
268 'form' => acym_translation('ACYM_IN_FORM'),
269 'head' => acym_translation('ACYM_WP_ENQUEUE_SCRIPT'),
270 ],
271 'default' => 'form',
272 'allowed_types' => [self::SUB_FORM_TYPE_SHORTCODE],
273 ],
274 ],
275 ],
276 'styles' => [
277 'image' => [
278 'url' => [
279 'label' => 'ACYM_CHOOSE_IMAGE',
280 'type' => 'media',
281 'default' => '',
282 ],
283 'size' => [
284 'label' => 'ACYM_SIZE',
285 'type' => 'dimensions',
286 'default' => ['width' => 100, 'height' => 100],
287 ],
288 ],
289 'button' => [
290 'background_color' => [
291 'label' => 'ACYM_BACKGROUND_COLOR',
292 'type' => 'color',
293 'default' => '#000000',
294 ],
295 'text_color' => [
296 'label' => 'ACYM_TEXT_COLOR',
297 'type' => 'color',
298 'default' => '#ffffff',
299 ],
300 'border_color' => [
301 'label' => 'ACYM_BORDER_COLOR',
302 'type' => 'color',
303 'default' => '#000000',
304 ],
305 'border_type' => [
306 'label' => 'ACYM_BORDER_TYPE',
307 'type' => 'select',
308 'options' => [
309 'solid' => acym_translation('ACYM_SOLID'),
310 'dotted' => acym_translation('ACYM_DOTTED'),
311 'dashed' => acym_translation('ACYM_DASHED'),
312 'double' => acym_translation('ACYM_DOUBLE'),
313 'groove' => acym_translation('ACYM_GROOVE'),
314 'ridge' => acym_translation('ACYM_RIDGE'),
315 'inset' => acym_translation('ACYM_INSET'),
316 'outset' => acym_translation('ACYM_OUTSET'),
317 ],
318 'default' => 'solid',
319 ],
320 'border_size' => [
321 'label' => 'ACYM_BORDER_SIZE',
322 'type' => 'number',
323 'default' => 0,
324 ],
325 'border_radius' => [
326 'label' => 'ACYM_RADIUS',
327 'type' => 'number',
328 'default' => 0,
329 ],
330 'size' => [
331 'label' => 'ACYM_SIZE',
332 'type' => 'dimensions',
333 'default' => ['width' => 20, 'height' => 10],
334 ],
335 'text' => [
336 'label' => 'ACYM_SUBSCRIBE_TEXT',
337 'type' => 'text',
338 'placeholder' => acym_translation('ACYM_SUBSCRIBE'),
339 'default' => '',
340 ],
341 ],
342 'style' => [
343 'position' => [
344 'label' => 'ACYM_DISPLAY_FIELDS_LABEL',
345 'type' => 'position',
346 'default' => 'image-top',
347 'allowed_types' => [self::SUB_FORM_TYPE_HEADER, self::SUB_FORM_TYPE_POPUP, self::SUB_FORM_TYPE_FOOTER],
348 ],
349 'background_color' => [
350 'label' => 'ACYM_BACKGROUND_COLOR',
351 'type' => 'color',
352 'default' => '#ffffff',
353 ],
354 'background_image' => [
355 'label' => 'ACYM_BACKGROUND_IMAGE',
356 'type' => 'media',
357 'default' => '',
358 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
359 ],
360 'background_position' => [
361 'label' => 'ACYM_POSITION',
362 'type' => 'select',
363 'options' => [
364 'center' => acym_translation('ACYM_CENTER'),
365 'top' => acym_translation('ACYM_POSITION_TOP'),
366 'right' => acym_translation('ACYM_RIGHT'),
367 'right_bottom' => acym_translation('ACYM_POSITION_RIGHT_BOTTOM'),
368 'right_top' => acym_translation('ACYM_POSITION_RIGHT_TOP'),
369 'bottom' => acym_translation('ACYM_POSITION_BOTTOM'),
370 'left' => acym_translation('ACYM_LEFT'),
371 'left_top' => acym_translation('ACYM_POSITION_LEFT_TOP'),
372 'left_bottom' => acym_translation('ACYM_POSITION_LEFT_BOTTOM'),
373 ],
374 'default' => 'center',
375 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
376 ],
377 'background_size' => [
378 'label' => 'ACYM_BACKGROUND_SIZE',
379 'type' => 'select',
380 'options' => [
381 'contain' => acym_translation('ACYM_BG_CONTAIN'),
382 'cover' => acym_translation('ACYM_BG_COVER'),
383 ],
384 'default' => 'contain',
385 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
386 ],
387 'background_repeat' => [
388 'label' => 'ACYM_BACKGROUND_REPEAT',
389 'type' => 'select',
390 'options' => [
391 'repeat' => acym_translation('ACYM_YES'),
392 'no-repeat' => acym_translation('ACYM_NO'),
393 ],
394 'default' => 'no-repeat',
395 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
396 ],
397 'border_radius' => [
398 'label' => 'ACYM_RADIUS',
399 'type' => 'number',
400 'unit' => 'px',
401 'default' => 0,
402 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
403 ],
404 'shadow_color' => [
405 'label' => 'ACYM_SHADOW_COLOR',
406 'type' => 'color',
407 'default' => '#000000',
408 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
409 ],
410 'shadow_blur' => [
411 'label' => 'ACYM_SHADOW_BLUR',
412 'type' => 'number',
413 'unit' => 'px',
414 'default' => 0,
415 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
416 ],
417 'shadow_x' => [
418 'label' => 'ACYM_SHADOW_OFFSET_X',
419 'type' => 'number',
420 'unit' => 'px',
421 'default' => 0,
422 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
423 ],
424 'shadow_y' => [
425 'label' => 'ACYM_SHADOW_OFFSET_Y',
426 'type' => 'number',
427 'unit' => 'px',
428 'default' => 0,
429 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
430 ],
431 'text_color' => [
432 'label' => 'ACYM_TEXT_COLOR',
433 'type' => 'color',
434 'default' => '#000000',
435 ],
436 'padding' => [
437 'label' => 'ACYM_PADDING',
438 'type' => 'dimensions',
439 'default' => ['width' => 20, 'height' => 20],
440 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
441 ],
442 'size' => [
443 'label' => 'ACYM_SIZE',
444 'type' => 'dimensions',
445 'units' => [
446 self::SUB_FORM_TYPE_HEADER => ['width' => '%', 'height' => 'px'],
447 self::SUB_FORM_TYPE_FOOTER => ['width' => '%', 'height' => 'px'],
448 ],
449 'default' => ['width' => 400, 'height' => 300],
450 'allowed_types' => [self::SUB_FORM_TYPE_HEADER, self::SUB_FORM_TYPE_SHORTCODE, self::SUB_FORM_TYPE_FOOTER],
451 ],
452 ],
453 ],
454 ];
455
456 if (!acym_isMultilingual()) {
457 return;
458 }
459
460 $languageTexts = [];
461 foreach (acym_getMultilingualLanguages() as $key => $languages) {
462 $languageTexts[$key] = '';
463 }
464 unset($this->settings['options']['redirection']['confirmation_message']);
465 $this->settings['options']['redirection']['langConfirm'] = [
466 'label' => 'ACYM_CONFIRMATION_MESSAGE',
467 'description' => 'ACYM_CONFIRMATION_MESSAGE_DESC',
468 'type' => 'language',
469 'default' => $languageTexts,
470 ];
471
472 unset($this->settings['styles']['button']['text']);
473 $this->settings['styles']['button']['lang'] = [
474 'label' => 'ACYM_SUBSCRIBE_TEXT',
475 'type' => 'language',
476 'default' => $languageTexts,
477 ];
478 }
479
480 private function getSectionTranslations(): array
481 {
482 return [
483 'display' => 'ACYM_DISPLAY',
484 'lists' => 'ACYM_LISTS',
485 'fields' => 'ACYM_FIELDS',
486 'termspolicy' => 'ACYM_ARTICLE',
487 'cookie' => 'ACYM_COOKIE_SETTINGS',
488 'redirection' => 'ACYM_REDIRECTIONS',
489 'miscellaneous' => 'ACYM_MISCELLANEOUS',
490 'message' => 'ACYM_MESSAGE',
491 'image' => 'ACYM_IMAGE',
492 'button' => 'ACYM_BUTTON',
493 'style' => 'ACYM_STYLE',
494 'links' => 'ACYM_LINKS',
495 ];
496 }
497
498 public function getMatchingElements(array $settings = []): array
499 {
500 $query = 'SELECT form.* FROM #__acym_form AS form';
501 $queryCount = 'SELECT COUNT(form.id) AS total, SUM(active) AS totalActive FROM #__acym_form AS form';
502
503 if (!empty($settings['search'])) {
504 $filters[] = 'name LIKE '.acym_escapeDB('%'.$settings['search'].'%');
505 }
506
507 if (!empty($filters)) {
508 $query .= ' WHERE ('.implode(') AND (', $filters).')';
509 $queryCount .= ' WHERE ('.implode(') AND (', $filters).')';
510 }
511
512 if (!empty($settings['status'])) {
513 $query .= empty($filters) ? ' WHERE ' : ' AND ';
514 $query .= 'active = '.($settings['status'] == 'active' ? '1' : '0');
515 }
516
517 if (!empty($settings['ordering']) && !empty($settings['ordering_sort_order'])) {
518 $query .= ' ORDER BY '.acym_secureDBColumn($settings['ordering']).' '.acym_secureDBColumn(strtoupper($settings['ordering_sort_order']));
519 } else {
520 $query .= ' ORDER BY id asc';
521 }
522
523 if (empty($settings['offset']) || $settings['offset'] < 0) {
524 $settings['offset'] = 0;
525 }
526
527 if (empty($settings['elementsPerPage']) || $settings['elementsPerPage'] < 1) {
528 $pagination = new PaginationHelper();
529 $settings['elementsPerPage'] = $pagination->getListLimit();
530 }
531
532 return [
533 'elements' => acym_loadObjectList($query, '', $settings['offset'], $settings['elementsPerPage']),
534 'total' => acym_loadObject($queryCount),
535 ];
536 }
537
538 public function getTranslatedTypes(): array
539 {
540 return [
541 self::SUB_FORM_TYPE_FOOTER => acym_translation('ACYM_FOOTER'),
542 self::SUB_FORM_TYPE_HEADER => acym_translation('ACYM_HEADER'),
543 self::SUB_FORM_TYPE_POPUP => acym_translation('ACYM_POPUP'),
544 self::SUB_FORM_TYPE_SHORTCODE => acym_translation('ACYM_SHORTCODE'),
545 ];
546 }
547
548 public function getOneById(int $id): ?object
549 {
550 $form = parent::getOneById($id);
551
552 if (empty($form)) {
553 return null;
554 }
555
556 $form->pages = json_decode($form->pages, true);
557 $form->settings = json_decode($form->settings, true);
558 $form->display_languages = json_decode($form->display_languages, true);
559
560 return $form;
561 }
562
563 public function getAllFormsToDisplay(): array
564 {
565 $forms = acym_loadObjectList('SELECT * FROM #__acym_form WHERE active = 1 AND type != '.acym_escapeDB(self::SUB_FORM_TYPE_SHORTCODE));
566 foreach ($forms as $form) {
567 $form->pages = json_decode($form->pages, true);
568 $form->settings = json_decode($form->settings, true);
569 $form->display_languages = json_decode($form->display_languages, true);
570 }
571
572 return $forms;
573 }
574
575 public function initEmptyForm(string $type): object
576 {
577 $this->initSettings();
578
579 $newForm = new \stdClass();
580 $newForm->id = 0;
581 $newForm->name = '';
582 $newForm->creation_date = acym_date('now', 'Y-m-d H:i:s');
583 $newForm->active = 1;
584 $newForm->type = $type;
585 $newForm->pages = ['all'];
586 $newForm->display_languages = ['all'];
587
588 $newForm->settings = [];
589 foreach ($this->settings['options'] as $category => $options) {
590 foreach ($options as $name => $oneOption) {
591 $newForm->settings[$category][$name] = $oneOption['default'];
592 }
593 }
594 foreach ($this->settings['styles'] as $category => $options) {
595 foreach ($options as $name => $oneOption) {
596 $newForm->settings[$category][$name] = $oneOption['default'];
597 }
598 }
599
600 if ($type === self::SUB_FORM_TYPE_HEADER) {
601 $newForm->settings['style']['position'] = 'button-left';
602 $newForm->settings['style']['size'] = ['height' => '', 'width' => ''];
603 } elseif ($type === self::SUB_FORM_TYPE_FOOTER) {
604 $newForm->settings['style']['position'] = 'button-left';
605 $newForm->settings['style']['size'] = ['width' => '100%', 'height' => '50'];
606 }
607
608 return $newForm;
609 }
610
611 public function getFormWithMissingParams(array $formArray): object
612 {
613 $form = new \stdClass();
614 $formEmpty = $this->initEmptyForm($formArray['type']);
615
616 if (!empty($formArray['id'])) {
617 $form->id = $formArray['id'];
618 }
619
620 foreach ($formEmpty as $key => $value) {
621 if ($key === 'settings') {
622 continue;
623 }
624
625 if (isset($formArray[$key])) {
626 $form->$key = $formArray[$key];
627 } else {
628 $form->$key = $value;
629 }
630 }
631
632 $form->settings = $formEmpty->settings;
633 foreach ($formArray['settings'] as $category => $options) {
634 foreach ($options as $optionName => $value) {
635 $form->settings[$category][$optionName] = $value;
636 }
637 }
638
639 return $form;
640 }
641
642 public function prepareMenuHtml(object $form, string $type): array
643 {
644 $this->initSettings();
645
646 $sections = $this->getSectionTranslations();
647 $htmlMenu = [];
648 foreach ($this->settings[$type] as $category => $options) {
649 $categoryOptions = [];
650 foreach ($options as $key => $option) {
651 if (!empty($option['allowed_types']) && !in_array($form->type, $option['allowed_types'])) {
652 continue;
653 }
654
655 $id = 'form_'.$category.'_'.$key;
656 $name = 'form[settings]['.$category.']['.$key.']';
657 $vModel = 'form.settings.'.$category.'.'.$key;
658 $value = $form->settings[$category][$key] ?? $option['default'];
659
660 $label = '<label class="cell" for="'.$id.'">'.acym_translation($option['label']);
661 if (!empty($option['description'])) {
662 ob_start();
663 acym_info(['textShownInTooltip' => $option['description']]);
664 $label .= ob_get_clean();
665 }
666 $label .= '</label>';
667
668 ob_start();
669 include acym_getPartial('fields', $option['type']);
670 $categoryOptions[$key] = $label.ob_get_clean();
671 }
672
673 if (!empty($categoryOptions)) {
674 $htmlMenu[] = [
675 'title' => acym_translation($sections[$category]),
676 'render' => $categoryOptions,
677 ];
678 }
679 }
680
681 return $htmlMenu;
682 }
683
684 public function renderForm(object $form, bool $edition = false, bool $isShortcode = false): string
685 {
686 if (!empty($form->display_languages) && !in_array('all', $form->display_languages) && !$edition) {
687 if (!in_array(acym_getLanguageTag(), $form->display_languages)) {
688 return '';
689 }
690 }
691 $loadJsInModule = $isShortcode;
692 if ($isShortcode && isset($form->settings['miscellaneous']['js_loading']) && $form->settings['miscellaneous']['js_loading'] === 'head') {
693 $loadJsInModule = false;
694 }
695 acym_initModule(null, ['loadJsInModule' => $loadJsInModule]);
696 $fieldClass = new FieldClass();
697 $listClass = new ListClass();
698
699 $form = $this->getFormWithMissingParams(get_object_vars($form));
700
701 $form->settings['fields']['displayed'][] = 2;
702 $form->settings['fields']['displayed'] = $fieldClass->getFieldsByID($form->settings['fields']['displayed']);
703 foreach ($form->settings['fields']['displayed'] as $key => $field) {
704 $field->option = json_decode($field->option ?? '');
705 $fieldDB = empty($field->option->fieldDB) ? '' : json_decode($field->option->fieldDB);
706 $field->value = empty($field->value) ? '' : json_decode($field->value);
707 $valuesArray = [];
708
709 if (!empty($field->value)) {
710 foreach ($field->value as $value) {
711 $valueTmp = new \stdClass();
712 $valueTmp->text = $value->title;
713 $valueTmp->value = $value->value;
714 if ($value->disabled == 'y') {
715 $valueTmp->disable = true;
716 }
717 $valuesArray[$value->value] = $valueTmp;
718 }
719 }
720
721 if (!empty($fieldDB) && !empty($fieldDB->value)) {
722 $fromDB = $fieldClass->getValueFromDB($fieldDB);
723 foreach ($fromDB as $value) {
724 $valuesArray[$value->value] = $value->title;
725 }
726 }
727
728 $form->settings['fields']['displayed'][$key]->valuesArray = $valuesArray;
729 }
730 $form->fieldClass = $fieldClass;
731 $form->lists = $listClass->getAllForSelect(false, 0, true, true);
732 $form->form_tag_name = 'formAcym'.$form->id;
733 $form->form_tag_action = htmlspecialchars_decode(ACYM_CMS == 'wordpress' ? acym_frontendLink('frontusers') : acym_completeLink('frontusers', true, true));
734 $form->formClass = $this;
735
736 $formFieldRender = acym_getPartial('forms', $form->type);
737 if (!file_exists($formFieldRender)) return '';
738
739 acym_initModule(null, ['loadJsInModule' => $loadJsInModule]);
740
741 ob_start();
742 include $formFieldRender;
743
744 return ob_get_clean();
745 }
746 }
747