PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
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
← All changes | back/Classes/FormClass.php +161 -49 10.1.4 → 11.1.0 View file →
@@ -11,9 +11,9 @@
11 11 const SUB_FORM_TYPE_POPUP = 'popup';
12 12 const SUB_FORM_TYPE_HEADER = 'header';
13 13 const SUB_FORM_TYPE_FOOTER = 'footer';
14 14
15 - private $settings;
15 + private array $settings = [];
16 16
17 17 public function __construct()
18 18 {
19 19 parent::__construct();
@@ -19,9 +19,16 @@
19 19 parent::__construct();
20 20
21 21 $this->table = 'form';
22 22 $this->pkey = 'id';
23 + }
23 24
25 + private function initSettings()
26 + {
27 + if (!empty($this->settings)) {
28 + return;
29 + }
30 +
24 31 $listClass = new ListClass();
25 32 $lists = $listClass->getAllForSelect(false);
26 33
27 34 $fieldClass = new FieldClass();
@@ -27,9 +34,11 @@
27 34 $fieldClass = new FieldClass();
28 35 $allFields = $fieldClass->getAll();
29 36 $fields = [];
30 37 foreach ($allFields as $field) {
31 - if ($field->id == 2 || intval($field->active) === 0) continue;
38 + if ($field->id == 2 || intval($field->active) === 0) {
39 + continue;
40 + }
32 41 $fields[$field->id] = acym_translation($field->name);
33 42 }
34 43
35 44 $this->settings = [
@@ -69,8 +78,25 @@
69 78 'max' => 100,
70 79 'default' => 0,
71 80 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
72 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 + ],
73 99 ],
74 100 'lists' => [
75 101 'automatic_subscribe' => [
76 102 'label' => 'ACYM_AUTO_SUBSCRIBE_TO',
@@ -118,20 +144,72 @@
118 144 'outside' => acym_translation('ACYM_TEXT_OUTSIDE'),
119 145 ],
120 146 'default' => 'inside',
121 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 + ],
122 156 ],
123 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 + ],
124 167 'termscond' => [
125 168 'label' => 'ACYM_TERMS_CONDITIONS',
126 169 'type' => 'article',
127 170 'default' => 0,
171 + 'conditional' => ['terms_type' => 'article'],
128 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 + ],
129 189 'privacy' => [
130 190 'label' => 'ACYM_PRIVACY_POLICY',
131 191 'type' => 'article',
132 192 'default' => 0,
193 + 'conditional' => ['privacy_type' => 'article'],
133 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 + ],
134 212 ],
135 213 'message' => [
136 214 'text' => [
137 215 'label' => 'ACYM_CUSTOM_MESSAGE_DISPLAY',
@@ -315,8 +393,42 @@
315 393 ],
316 394 'default' => 'no-repeat',
317 395 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
318 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 + ],
319 431 'text_color' => [
320 432 'label' => 'ACYM_TEXT_COLOR',
321 433 'type' => 'color',
322 434 'default' => '#000000',
@@ -340,28 +452,30 @@
340 452 ],
341 453 ],
342 454 ];
343 455
344 - if (acym_isMultilingual()) {
345 - $languageTexts = [];
346 - foreach (acym_getMultilingualLanguages() as $key => $languages) {
347 - $languageTexts[$key] = '';
348 - }
349 - unset($this->settings['options']['redirection']['confirmation_message']);
350 - $this->settings['options']['redirection']['langConfirm'] = [
351 - 'label' => 'ACYM_CONFIRMATION_MESSAGE',
352 - 'description' => 'ACYM_CONFIRMATION_MESSAGE_DESC',
353 - 'type' => 'language',
354 - 'default' => $languageTexts,
355 - ];
456 + if (!acym_isMultilingual()) {
457 + return;
458 + }
356 459
357 - unset($this->settings['styles']['button']['text']);
358 - $this->settings['styles']['button']['lang'] = [
359 - 'label' => 'ACYM_SUBSCRIBE_TEXT',
360 - 'type' => 'language',
361 - 'default' => $languageTexts,
362 - ];
460 + $languageTexts = [];
461 + foreach (acym_getMultilingualLanguages() as $key => $languages) {
462 + $languageTexts[$key] = '';
363 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 + ];
364 478 }
365 479
366 480 private function getSectionTranslations(): array
367 481 {
@@ -376,8 +490,9 @@
376 490 'message' => 'ACYM_MESSAGE',
377 491 'image' => 'ACYM_IMAGE',
378 492 'button' => 'ACYM_BUTTON',
379 493 'style' => 'ACYM_STYLE',
494 + 'links' => 'ACYM_LINKS',
380 495 ];
381 496 }
382 497
383 498 public function getMatchingElements(array $settings = []): array
@@ -429,14 +544,14 @@
429 544 self::SUB_FORM_TYPE_SHORTCODE => acym_translation('ACYM_SHORTCODE'),
430 545 ];
431 546 }
432 547
433 - public function getOneById($id)
548 + public function getOneById(int $id): ?object
434 549 {
435 - $form = acym_loadObject('SELECT * FROM #__acym_form WHERE id = '.intval($id));
550 + $form = parent::getOneById($id);
436 551
437 552 if (empty($form)) {
438 - return $form;
553 + return null;
439 554 }
440 555
441 556 $form->pages = json_decode($form->pages, true);
442 557 $form->settings = json_decode($form->settings, true);
@@ -444,9 +559,9 @@
444 559
445 560 return $form;
446 561 }
447 562
448 - public function getAllFormsToDisplay()
563 + public function getAllFormsToDisplay(): array
449 564 {
450 565 $forms = acym_loadObjectList('SELECT * FROM #__acym_form WHERE active = 1 AND type != '.acym_escapeDB(self::SUB_FORM_TYPE_SHORTCODE));
451 566 foreach ($forms as $form) {
452 567 $form->pages = json_decode($form->pages, true);
@@ -456,10 +571,12 @@
456 571
457 572 return $forms;
458 573 }
459 574
460 - public function initEmptyForm($type)
575 + public function initEmptyForm(string $type): object
461 576 {
577 + $this->initSettings();
578 +
462 579 $newForm = new \stdClass();
463 580 $newForm->id = 0;
464 581 $newForm->name = '';
465 582 $newForm->creation_date = acym_date('now', 'Y-m-d H:i:s');
@@ -490,14 +607,10 @@
490 607
491 608 return $newForm;
492 609 }
493 610
494 - public function getFormWithMissingParams($formArray): \stdClass
611 + public function getFormWithMissingParams(array $formArray): object
495 612 {
496 - if (!is_array($formArray)) {
497 - $formArray = get_object_vars($formArray);
498 - }
499 -
500 613 $form = new \stdClass();
501 614 $formEmpty = $this->initEmptyForm($formArray['type']);
502 615
503 616 if (!empty($formArray['id'])) {
@@ -525,47 +638,46 @@
525 638
526 639 return $form;
527 640 }
528 641
529 - public function prepareMenuHtml($form, $type): array
642 + public function prepareMenuHtml(object $form, string $type): void
530 643 {
644 + $this->initSettings();
645 +
531 646 $sections = $this->getSectionTranslations();
532 - $htmlMenu = [];
533 647 foreach ($this->settings[$type] as $category => $options) {
534 - $categoryOptions = [];
648 + $hasOptions = false;
649 +
535 650 foreach ($options as $key => $option) {
536 651 if (!empty($option['allowed_types']) && !in_array($form->type, $option['allowed_types'])) {
537 652 continue;
538 653 }
539 654
655 + if (!$hasOptions) {
656 + $hasOptions = true;
657 + echo '<h3 class="cell acym__forms__menu__title acym__title acym__title__tertiary">'.esc_html(acym_translation($sections[$category])).'</h3>';
658 + }
659 +
540 660 $id = 'form_'.$category.'_'.$key;
541 661 $name = 'form[settings]['.$category.']['.$key.']';
542 662 $vModel = 'form.settings.'.$category.'.'.$key;
543 663 $value = $form->settings[$category][$key] ?? $option['default'];
544 664
545 - $label = '<label class="cell" for="'.$id.'">'.acym_translation($option['label']);
665 + echo '<div class="cell grid-x acym__forms__menu__options grid-margin-x acym_vcenter">';
666 +
667 + echo '<label class="cell" for="'.esc_attr($id).'">'.esc_html(acym_translation($option['label']));
546 668 if (!empty($option['description'])) {
547 - $label .= acym_info($option['description']);
669 + acym_info(['textShownInTooltip' => $option['description']]);
548 670 }
549 - $label .= '</label>';
671 + echo '</label>';
550 672
551 - ob_start();
552 673 include acym_getPartial('fields', $option['type']);
553 - $categoryOptions[$key] = $label.ob_get_clean();
674 + echo '</div>';
554 675 }
555 -
556 - if (!empty($categoryOptions)) {
557 - $htmlMenu[] = [
558 - 'title' => acym_translation($sections[$category]),
559 - 'render' => $categoryOptions,
560 - ];
561 - }
562 676 }
563 -
564 - return $htmlMenu;
565 677 }
566 678
567 - public function renderForm($form, $edition = false, $isShortcode = false)
679 + public function renderForm(object $form, bool $edition = false, bool $isShortcode = false): string
568 680 {
569 681 if (!empty($form->display_languages) && !in_array('all', $form->display_languages) && !$edition) {
570 682 if (!in_array(acym_getLanguageTag(), $form->display_languages)) {
571 683 return '';
@@ -578,9 +690,9 @@
578 690 acym_initModule(null, ['loadJsInModule' => $loadJsInModule]);
579 691 $fieldClass = new FieldClass();
580 692 $listClass = new ListClass();
581 693
582 - $form = $this->getFormWithMissingParams($form);
694 + $form = $this->getFormWithMissingParams(get_object_vars($form));
583 695
584 696 $form->settings['fields']['displayed'][] = 2;
585 697 $form->settings['fields']['displayed'] = $fieldClass->getFieldsByID($form->settings['fields']['displayed']);
586 698 foreach ($form->settings['fields']['displayed'] as $key => $field) {