PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.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
← All changes | back/Classes/FormClass.php +0 -733 10.10.2 → 11.1.1 View file →
@@ -1,733 +1,0 @@
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 - 'default' => 65,
154 - ],
155 - ],
156 - 'termspolicy' => [
157 - 'terms_type' => [
158 - 'label' => 'ACYM_TERMS_TYPE',
159 - 'type' => 'select',
160 - 'options' => [
161 - 'article' => acym_translation('ACYM_ARTICLE'),
162 - 'url' => acym_translation('ACYM_LINK'),
163 - ],
164 - 'default' => 'article',
165 - ],
166 - 'termscond' => [
167 - 'label' => 'ACYM_TERMS_CONDITIONS',
168 - 'type' => 'article',
169 - 'default' => 0,
170 - 'conditional' => ['terms_type' => 'article'],
171 - ],
172 - 'terms_url' => [
173 - 'label' => 'ACYM_TERMS_CONDITIONS_URL',
174 - 'description' => 'ACYM_TERMS_CONDITIONS_URL_DESC',
175 - 'type' => 'text',
176 - 'default' => '',
177 - 'conditional' => ['terms_type' => 'url'],
178 - ],
179 - 'privacy_type' => [
180 - 'label' => 'ACYM_PRIVACY_TYPE',
181 - 'type' => 'select',
182 - 'options' => [
183 - 'article' => acym_translation('ACYM_ARTICLE'),
184 - 'url' => acym_translation('ACYM_LINK'),
185 - ],
186 - 'default' => 'article',
187 - ],
188 - 'privacy' => [
189 - 'label' => 'ACYM_PRIVACY_POLICY',
190 - 'type' => 'article',
191 - 'default' => 0,
192 - 'conditional' => ['privacy_type' => 'article'],
193 - ],
194 - 'privacy_url' => [
195 - 'label' => 'ACYM_PRIVACY_POLICY_URL',
196 - 'description' => 'ACYM_PRIVACY_POLICY_URL_DESC',
197 - 'type' => 'text',
198 - 'default' => '',
199 - 'conditional' => ['privacy_type' => 'url'],
200 - ],
201 - ],
202 - 'message' => [
203 - 'text' => [
204 - 'label' => 'ACYM_CUSTOM_MESSAGE_DISPLAY',
205 - 'type' => 'textarea',
206 - 'default' => '',
207 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
208 - ],
209 - 'position' => [
210 - 'label' => 'ACYM_MESSAGE_POSITION',
211 - 'type' => 'select',
212 - 'options' => [
213 - 'before-image' => acym_translation('ACYM_BEFORE_IMAGE'),
214 - 'before-fields' => acym_translation('ACYM_BEFORE_FIELDS'),
215 - 'before-lists' => acym_translation('ACYM_BEFORE_LISTS'),
216 - 'before-button' => acym_translation('ACYM_BEFORE_BUTTON'),
217 - ],
218 - 'default' => 'before-fields',
219 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
220 - ],
221 - 'color' => [
222 - 'label' => 'ACYM_COLOR',
223 - 'type' => 'color',
224 - 'default' => '#000000',
225 - ],
226 - ],
227 - 'cookie' => [
228 - 'cookie_expiration' => [
229 - 'label' => 'ACYM_COOKIE_EXPIRATION',
230 - 'type' => 'number',
231 - 'min' => 1,
232 - 'unit' => acym_translation('ACYM_DAYS'),
233 - 'default' => 1,
234 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP, self::SUB_FORM_TYPE_HEADER, self::SUB_FORM_TYPE_FOOTER],
235 - ],
236 - ],
237 - 'redirection' => [
238 - 'after_subscription' => [
239 - 'label' => 'ACYM_AFTER_SUBSCRIPTION',
240 - 'description' => 'ACYM_REDIRECT_LINK_DESC',
241 - 'type' => 'text',
242 - 'default' => '',
243 - ],
244 - 'confirmation_message' => [
245 - 'label' => 'ACYM_CONFIRMATION_MESSAGE',
246 - 'description' => 'ACYM_CONFIRMATION_MESSAGE_DESC',
247 - 'type' => 'text',
248 - 'default' => '',
249 - ],
250 - ],
251 - 'miscellaneous' => [
252 - 'js_loading' => [
253 - 'label' => 'ACYM_JS_LOADING',
254 - 'description' => 'ACYM_MODULE_JS_DESC',
255 - 'type' => 'select',
256 - 'options' => [
257 - 'form' => acym_translation('ACYM_IN_FORM'),
258 - 'head' => acym_translation('ACYM_WP_ENQUEUE_SCRIPT'),
259 - ],
260 - 'default' => 'form',
261 - 'allowed_types' => [self::SUB_FORM_TYPE_SHORTCODE],
262 - ],
263 - ],
264 - ],
265 - 'styles' => [
266 - 'image' => [
267 - 'url' => [
268 - 'label' => 'ACYM_CHOOSE_IMAGE',
269 - 'type' => 'media',
270 - 'default' => '',
271 - ],
272 - 'size' => [
273 - 'label' => 'ACYM_SIZE',
274 - 'type' => 'dimensions',
275 - 'default' => ['width' => 100, 'height' => 100],
276 - ],
277 - ],
278 - 'button' => [
279 - 'background_color' => [
280 - 'label' => 'ACYM_BACKGROUND_COLOR',
281 - 'type' => 'color',
282 - 'default' => '#000000',
283 - ],
284 - 'text_color' => [
285 - 'label' => 'ACYM_TEXT_COLOR',
286 - 'type' => 'color',
287 - 'default' => '#ffffff',
288 - ],
289 - 'border_color' => [
290 - 'label' => 'ACYM_BORDER_COLOR',
291 - 'type' => 'color',
292 - 'default' => '#000000',
293 - ],
294 - 'border_type' => [
295 - 'label' => 'ACYM_BORDER_TYPE',
296 - 'type' => 'select',
297 - 'options' => [
298 - 'solid' => acym_translation('ACYM_SOLID'),
299 - 'dotted' => acym_translation('ACYM_DOTTED'),
300 - 'dashed' => acym_translation('ACYM_DASHED'),
301 - 'double' => acym_translation('ACYM_DOUBLE'),
302 - 'groove' => acym_translation('ACYM_GROOVE'),
303 - 'ridge' => acym_translation('ACYM_RIDGE'),
304 - 'inset' => acym_translation('ACYM_INSET'),
305 - 'outset' => acym_translation('ACYM_OUTSET'),
306 - ],
307 - 'default' => 'solid',
308 - ],
309 - 'border_size' => [
310 - 'label' => 'ACYM_BORDER_SIZE',
311 - 'type' => 'number',
312 - 'default' => 0,
313 - ],
314 - 'border_radius' => [
315 - 'label' => 'ACYM_RADIUS',
316 - 'type' => 'number',
317 - 'default' => 0,
318 - ],
319 - 'size' => [
320 - 'label' => 'ACYM_SIZE',
321 - 'type' => 'dimensions',
322 - 'default' => ['width' => 20, 'height' => 10],
323 - ],
324 - 'text' => [
325 - 'label' => 'ACYM_SUBSCRIBE_TEXT',
326 - 'type' => 'text',
327 - 'placeholder' => acym_translation('ACYM_SUBSCRIBE'),
328 - 'default' => '',
329 - ],
330 - ],
331 - 'style' => [
332 - 'position' => [
333 - 'label' => 'ACYM_DISPLAY_FIELDS_LABEL',
334 - 'type' => 'position',
335 - 'default' => 'image-top',
336 - 'allowed_types' => [self::SUB_FORM_TYPE_HEADER, self::SUB_FORM_TYPE_POPUP, self::SUB_FORM_TYPE_FOOTER],
337 - ],
338 - 'background_color' => [
339 - 'label' => 'ACYM_BACKGROUND_COLOR',
340 - 'type' => 'color',
341 - 'default' => '#ffffff',
342 - ],
343 - 'background_image' => [
344 - 'label' => 'ACYM_BACKGROUND_IMAGE',
345 - 'type' => 'media',
346 - 'default' => '',
347 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
348 - ],
349 - 'background_position' => [
350 - 'label' => 'ACYM_POSITION',
351 - 'type' => 'select',
352 - 'options' => [
353 - 'center' => acym_translation('ACYM_CENTER'),
354 - 'top' => acym_translation('ACYM_POSITION_TOP'),
355 - 'right' => acym_translation('ACYM_RIGHT'),
356 - 'right_bottom' => acym_translation('ACYM_POSITION_RIGHT_BOTTOM'),
357 - 'right_top' => acym_translation('ACYM_POSITION_RIGHT_TOP'),
358 - 'bottom' => acym_translation('ACYM_POSITION_BOTTOM'),
359 - 'left' => acym_translation('ACYM_LEFT'),
360 - 'left_top' => acym_translation('ACYM_POSITION_LEFT_TOP'),
361 - 'left_bottom' => acym_translation('ACYM_POSITION_LEFT_BOTTOM'),
362 - ],
363 - 'default' => 'center',
364 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
365 - ],
366 - 'background_size' => [
367 - 'label' => 'ACYM_BACKGROUND_SIZE',
368 - 'type' => 'select',
369 - 'options' => [
370 - 'contain' => acym_translation('ACYM_BG_CONTAIN'),
371 - 'cover' => acym_translation('ACYM_BG_COVER'),
372 - ],
373 - 'default' => 'contain',
374 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
375 - ],
376 - 'background_repeat' => [
377 - 'label' => 'ACYM_BACKGROUND_REPEAT',
378 - 'type' => 'select',
379 - 'options' => [
380 - 'repeat' => acym_translation('ACYM_YES'),
381 - 'no-repeat' => acym_translation('ACYM_NO'),
382 - ],
383 - 'default' => 'no-repeat',
384 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
385 - ],
386 - 'border_radius' => [
387 - 'label' => 'ACYM_RADIUS',
388 - 'type' => 'number',
389 - 'unit' => 'px',
390 - 'default' => 0,
391 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
392 - ],
393 - 'shadow_color' => [
394 - 'label' => 'ACYM_SHADOW_COLOR',
395 - 'type' => 'color',
396 - 'default' => '#000000',
397 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
398 - ],
399 - 'shadow_blur' => [
400 - 'label' => 'ACYM_SHADOW_BLUR',
401 - 'type' => 'number',
402 - 'unit' => 'px',
403 - 'default' => 0,
404 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
405 - ],
406 - 'shadow_x' => [
407 - 'label' => 'ACYM_SHADOW_OFFSET_X',
408 - 'type' => 'number',
409 - 'unit' => 'px',
410 - 'default' => 0,
411 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
412 - ],
413 - 'shadow_y' => [
414 - 'label' => 'ACYM_SHADOW_OFFSET_Y',
415 - 'type' => 'number',
416 - 'unit' => 'px',
417 - 'default' => 0,
418 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
419 - ],
420 - 'text_color' => [
421 - 'label' => 'ACYM_TEXT_COLOR',
422 - 'type' => 'color',
423 - 'default' => '#000000',
424 - ],
425 - 'padding' => [
426 - 'label' => 'ACYM_PADDING',
427 - 'type' => 'dimensions',
428 - 'default' => ['width' => 20, 'height' => 20],
429 - 'allowed_types' => [self::SUB_FORM_TYPE_POPUP],
430 - ],
431 - 'size' => [
432 - 'label' => 'ACYM_SIZE',
433 - 'type' => 'dimensions',
434 - 'units' => [
435 - self::SUB_FORM_TYPE_HEADER => ['width' => '%', 'height' => 'px'],
436 - self::SUB_FORM_TYPE_FOOTER => ['width' => '%', 'height' => 'px'],
437 - ],
438 - 'default' => ['width' => 400, 'height' => 300],
439 - 'allowed_types' => [self::SUB_FORM_TYPE_HEADER, self::SUB_FORM_TYPE_SHORTCODE, self::SUB_FORM_TYPE_FOOTER],
440 - ],
441 - ],
442 - ],
443 - ];
444 -
445 - if (!acym_isMultilingual()) {
446 - return;
447 - }
448 -
449 - $languageTexts = [];
450 - foreach (acym_getMultilingualLanguages() as $key => $languages) {
451 - $languageTexts[$key] = '';
452 - }
453 - unset($this->settings['options']['redirection']['confirmation_message']);
454 - $this->settings['options']['redirection']['langConfirm'] = [
455 - 'label' => 'ACYM_CONFIRMATION_MESSAGE',
456 - 'description' => 'ACYM_CONFIRMATION_MESSAGE_DESC',
457 - 'type' => 'language',
458 - 'default' => $languageTexts,
459 - ];
460 -
461 - unset($this->settings['styles']['button']['text']);
462 - $this->settings['styles']['button']['lang'] = [
463 - 'label' => 'ACYM_SUBSCRIBE_TEXT',
464 - 'type' => 'language',
465 - 'default' => $languageTexts,
466 - ];
467 - }
468 -
469 - private function getSectionTranslations(): array
470 - {
471 - return [
472 - 'display' => 'ACYM_DISPLAY',
473 - 'lists' => 'ACYM_LISTS',
474 - 'fields' => 'ACYM_FIELDS',
475 - 'termspolicy' => 'ACYM_ARTICLE',
476 - 'cookie' => 'ACYM_COOKIE_SETTINGS',
477 - 'redirection' => 'ACYM_REDIRECTIONS',
478 - 'miscellaneous' => 'ACYM_MISCELLANEOUS',
479 - 'message' => 'ACYM_MESSAGE',
480 - 'image' => 'ACYM_IMAGE',
481 - 'button' => 'ACYM_BUTTON',
482 - 'style' => 'ACYM_STYLE',
483 - 'links' => 'ACYM_LINKS',
484 - ];
485 - }
486 -
487 - public function getMatchingElements(array $settings = []): array
488 - {
489 - $query = 'SELECT form.* FROM #__acym_form AS form';
490 - $queryCount = 'SELECT COUNT(form.id) AS total, SUM(active) AS totalActive FROM #__acym_form AS form';
491 -
492 - if (!empty($settings['search'])) {
493 - $filters[] = 'name LIKE '.acym_escapeDB('%'.$settings['search'].'%');
494 - }
495 -
496 - if (!empty($filters)) {
497 - $query .= ' WHERE ('.implode(') AND (', $filters).')';
498 - $queryCount .= ' WHERE ('.implode(') AND (', $filters).')';
499 - }
500 -
501 - if (!empty($settings['status'])) {
502 - $query .= empty($filters) ? ' WHERE ' : ' AND ';
503 - $query .= 'active = '.($settings['status'] == 'active' ? '1' : '0');
504 - }
505 -
506 - if (!empty($settings['ordering']) && !empty($settings['ordering_sort_order'])) {
507 - $query .= ' ORDER BY '.acym_secureDBColumn($settings['ordering']).' '.acym_secureDBColumn(strtoupper($settings['ordering_sort_order']));
508 - } else {
509 - $query .= ' ORDER BY id asc';
510 - }
511 -
512 - if (empty($settings['offset']) || $settings['offset'] < 0) {
513 - $settings['offset'] = 0;
514 - }
515 -
516 - if (empty($settings['elementsPerPage']) || $settings['elementsPerPage'] < 1) {
517 - $pagination = new PaginationHelper();
518 - $settings['elementsPerPage'] = $pagination->getListLimit();
519 - }
520 -
521 - return [
522 - 'elements' => acym_loadObjectList($query, '', $settings['offset'], $settings['elementsPerPage']),
523 - 'total' => acym_loadObject($queryCount),
524 - ];
525 - }
526 -
527 - public function getTranslatedTypes(): array
528 - {
529 - return [
530 - self::SUB_FORM_TYPE_FOOTER => acym_translation('ACYM_FOOTER'),
531 - self::SUB_FORM_TYPE_HEADER => acym_translation('ACYM_HEADER'),
532 - self::SUB_FORM_TYPE_POPUP => acym_translation('ACYM_POPUP'),
533 - self::SUB_FORM_TYPE_SHORTCODE => acym_translation('ACYM_SHORTCODE'),
534 - ];
535 - }
536 -
537 - public function getOneById(int $id): ?object
538 - {
539 - $form = parent::getOneById($id);
540 -
541 - if (empty($form)) {
542 - return null;
543 - }
544 -
545 - $form->pages = json_decode($form->pages, true);
546 - $form->settings = json_decode($form->settings, true);
547 - $form->display_languages = json_decode($form->display_languages, true);
548 -
549 - return $form;
550 - }
551 -
552 - public function getAllFormsToDisplay(): array
553 - {
554 - $forms = acym_loadObjectList('SELECT * FROM #__acym_form WHERE active = 1 AND type != '.acym_escapeDB(self::SUB_FORM_TYPE_SHORTCODE));
555 - foreach ($forms as $form) {
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 -
561 - return $forms;
562 - }
563 -
564 - public function initEmptyForm(string $type): object
565 - {
566 - $this->initSettings();
567 -
568 - $newForm = new \stdClass();
569 - $newForm->id = 0;
570 - $newForm->name = '';
571 - $newForm->creation_date = acym_date('now', 'Y-m-d H:i:s');
572 - $newForm->active = 1;
573 - $newForm->type = $type;
574 - $newForm->pages = ['all'];
575 - $newForm->display_languages = ['all'];
576 -
577 - $newForm->settings = [];
578 - foreach ($this->settings['options'] as $category => $options) {
579 - foreach ($options as $name => $oneOption) {
580 - $newForm->settings[$category][$name] = $oneOption['default'];
581 - }
582 - }
583 - foreach ($this->settings['styles'] as $category => $options) {
584 - foreach ($options as $name => $oneOption) {
585 - $newForm->settings[$category][$name] = $oneOption['default'];
586 - }
587 - }
588 -
589 - if ($type === self::SUB_FORM_TYPE_HEADER) {
590 - $newForm->settings['style']['position'] = 'button-left';
591 - $newForm->settings['style']['size'] = ['height' => '', 'width' => ''];
592 - } elseif ($type === self::SUB_FORM_TYPE_FOOTER) {
593 - $newForm->settings['style']['position'] = 'button-left';
594 - $newForm->settings['style']['size'] = ['width' => '100%', 'height' => '50'];
595 - }
596 -
597 - return $newForm;
598 - }
599 -
600 - public function getFormWithMissingParams(array $formArray): object
601 - {
602 - $form = new \stdClass();
603 - $formEmpty = $this->initEmptyForm($formArray['type']);
604 -
605 - if (!empty($formArray['id'])) {
606 - $form->id = $formArray['id'];
607 - }
608 -
609 - foreach ($formEmpty as $key => $value) {
610 - if ($key === 'settings') {
611 - continue;
612 - }
613 -
614 - if (isset($formArray[$key])) {
615 - $form->$key = $formArray[$key];
616 - } else {
617 - $form->$key = $value;
618 - }
619 - }
620 -
621 - $form->settings = $formEmpty->settings;
622 - foreach ($formArray['settings'] as $category => $options) {
623 - foreach ($options as $optionName => $value) {
624 - $form->settings[$category][$optionName] = $value;
625 - }
626 - }
627 -
628 - return $form;
629 - }
630 -
631 - public function prepareMenuHtml(object $form, string $type): array
632 - {
633 - $this->initSettings();
634 -
635 - $sections = $this->getSectionTranslations();
636 - $htmlMenu = [];
637 - foreach ($this->settings[$type] as $category => $options) {
638 - $categoryOptions = [];
639 - foreach ($options as $key => $option) {
640 - if (!empty($option['allowed_types']) && !in_array($form->type, $option['allowed_types'])) {
641 - continue;
642 - }
643 -
644 - $id = 'form_'.$category.'_'.$key;
645 - $name = 'form[settings]['.$category.']['.$key.']';
646 - $vModel = 'form.settings.'.$category.'.'.$key;
647 - $value = $form->settings[$category][$key] ?? $option['default'];
648 -
649 - $label = '<label class="cell" for="'.$id.'">'.acym_translation($option['label']);
650 - if (!empty($option['description'])) {
651 - $label .= acym_info(['textShownInTooltip' => $option['description']]);
652 - }
653 - $label .= '</label>';
654 -
655 - ob_start();
656 - include acym_getPartial('fields', $option['type']);
657 - $categoryOptions[$key] = $label.ob_get_clean();
658 - }
659 -
660 - if (!empty($categoryOptions)) {
661 - $htmlMenu[] = [
662 - 'title' => acym_translation($sections[$category]),
663 - 'render' => $categoryOptions,
664 - ];
665 - }
666 - }
667 -
668 - return $htmlMenu;
669 - }
670 -
671 - public function renderForm(object $form, bool $edition = false, bool $isShortcode = false): string
672 - {
673 - if (!empty($form->display_languages) && !in_array('all', $form->display_languages) && !$edition) {
674 - if (!in_array(acym_getLanguageTag(), $form->display_languages)) {
675 - return '';
676 - }
677 - }
678 - $loadJsInModule = $isShortcode;
679 - if ($isShortcode && isset($form->settings['miscellaneous']['js_loading']) && $form->settings['miscellaneous']['js_loading'] === 'head') {
680 - $loadJsInModule = false;
681 - }
682 - acym_initModule(null, ['loadJsInModule' => $loadJsInModule]);
683 - $fieldClass = new FieldClass();
684 - $listClass = new ListClass();
685 -
686 - $form = $this->getFormWithMissingParams(get_object_vars($form));
687 -
688 - $form->settings['fields']['displayed'][] = 2;
689 - $form->settings['fields']['displayed'] = $fieldClass->getFieldsByID($form->settings['fields']['displayed']);
690 - foreach ($form->settings['fields']['displayed'] as $key => $field) {
691 - $field->option = json_decode($field->option ?? '');
692 - $fieldDB = empty($field->option->fieldDB) ? '' : json_decode($field->option->fieldDB);
693 - $field->value = empty($field->value) ? '' : json_decode($field->value);
694 - $valuesArray = [];
695 -
696 - if (!empty($field->value)) {
697 - foreach ($field->value as $value) {
698 - $valueTmp = new \stdClass();
699 - $valueTmp->text = $value->title;
700 - $valueTmp->value = $value->value;
701 - if ($value->disabled == 'y') {
702 - $valueTmp->disable = true;
703 - }
704 - $valuesArray[$value->value] = $valueTmp;
705 - }
706 - }
707 -
708 - if (!empty($fieldDB) && !empty($fieldDB->value)) {
709 - $fromDB = $fieldClass->getValueFromDB($fieldDB);
710 - foreach ($fromDB as $value) {
711 - $valuesArray[$value->value] = $value->title;
712 - }
713 - }
714 -
715 - $form->settings['fields']['displayed'][$key]->valuesArray = $valuesArray;
716 - }
717 - $form->fieldClass = $fieldClass;
718 - $form->lists = $listClass->getAllForSelect(false, 0, true, true);
719 - $form->form_tag_name = 'formAcym'.$form->id;
720 - $form->form_tag_action = htmlspecialchars_decode(ACYM_CMS == 'wordpress' ? acym_frontendLink('frontusers') : acym_completeLink('frontusers', true, true));
721 - $form->formClass = $this;
722 -
723 - $formFieldRender = acym_getPartial('forms', $form->type);
724 - if (!file_exists($formFieldRender)) return '';
725 -
726 - acym_initModule(null, ['loadJsInModule' => $loadJsInModule]);
727 -
728 - ob_start();
729 - include $formFieldRender;
730 -
731 - return ob_get_clean();
732 - }
733 -}