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
acymailing / back / Helpers / global / field.php

field.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.1.0, at back/Helpers/global/field.php

983 lines 30.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die('Restricted Access');
3
4 use AcyMailing\Helpers\SecurityHelper;
5
6 /**
7 * @param ?mixed $selected
8 */
9 function acym_radio(
10 array $options,
11 string $name,
12 $selected = null,
13 array $attributes = [],
14 array $params = [],
15 bool $frontDisplay = false,
16 array $disabledOptions = []
17 ): void {
18 $id = preg_replace(
19 '#[^a-zA-Z0-9_]+#mi',
20 '_',
21 str_replace(
22 ['[', ']'],
23 ['_', ''],
24 empty($params['id']) ? $name : $params['id']
25 )
26 );
27
28 $objValue = empty($params['objectValue']) ? 'value' : $params['objectValue'];
29 $objText = empty($params['objectText']) ? 'text' : $params['objectText'];
30
31 $attributes['type'] = 'radio';
32 $attributes['name'] = $name;
33 if (empty($params['containerClass'])) {
34 $params['containerClass'] = '';
35 }
36
37 echo '<div class="acym_radio_group '.esc_attr($params['containerClass']).'">';
38 $k = 0;
39 foreach ($options as $value => $label) {
40 $currentAttributes = $attributes;
41 $currentAttributes['class'] = '';
42 unset($currentAttributes['related']);
43
44 if (is_object($label)) {
45 if (!empty($label->class)) {
46 $currentAttributes['class'] = $label->class;
47 }
48
49 $value = $label->$objValue;
50 $label = $label->$objText;
51 }
52
53 $currentId = empty($params['useIncrement']) ? $id.$value : $id.$k;
54
55 $currentAttributes['value'] = $value;
56 $currentAttributes['id'] = $currentId;
57
58 if (isset($attributes['related'][$value])) {
59 $currentAttributes['acym-data-related'] = $attributes['related'][$value];
60 }
61
62 $extraClass = '';
63 if (!empty($disabledOptions[$value])) {
64 $currentAttributes['disabled'] = 'disabled';
65 $extraClass = ' '.$disabledOptions[$value]['disabledClass'];
66 $currentAttributes['class'] .= $extraClass;
67 }
68
69 if (!empty($params['required'])) {
70 $currentAttributes['required'] = 'required';
71 unset($params['required']);
72 }
73
74 if (!empty($disabledOptions[$value]['tooltipTxt'])) {
75 ob_start();
76 }
77
78 if (!$frontDisplay) {
79 echo '<i data-radio="'.esc_attr($currentId).'" class="acymicon-radio-button-checked acym_radio_checked'.esc_attr($extraClass).'"></i>';
80 echo '<i data-radio="'.esc_attr($currentId).'" class="acymicon-radio-button-unchecked acym_radio_unchecked'.esc_attr($extraClass).'"></i>';
81 }
82
83 echo '<input ';
84 checked((string)$value === (string)$selected);
85 foreach ($currentAttributes as $oneAttribute => $oneValue) {
86 if (is_array($oneValue) || is_object($oneValue)) {
87 $oneValue = json_encode($oneValue);
88 } elseif ($oneValue === true) {
89 $oneValue = $oneAttribute;
90 }
91
92 echo ' '.esc_attr($oneAttribute).'="'.esc_attr($oneValue).'"';
93 }
94 echo ' />';
95
96 echo '<label for="'.esc_attr($currentId).'" id="'.esc_attr($currentId).'-lbl" class="'.esc_attr($extraClass).'">';
97 echo wp_kses(
98 acym_translation($label),
99 [
100 'input' => [
101 'type' => true,
102 'value' => true,
103 'name' => true,
104 'placeholder' => true,
105 ],
106 ]
107 );
108 echo '</label>';
109
110 if (!empty($disabledOptions[$value]['tooltipTxt'])) {
111 $currentOption = ob_get_clean();
112 acym_tooltip(
113 [
114 'hoveredText' => $currentOption,
115 'textShownInTooltip' => $disabledOptions[$value]['tooltipTxt'],
116 ]
117 );
118 }
119
120 if (!empty($params['pluginMode'])) {
121 echo '<br />';
122 }
123 $k++;
124 }
125 echo '</div>';
126 }
127
128 function acym_boolean(
129 string $name,
130 bool $selected = false,
131 ?string $id = null,
132 array $attributes = [],
133 string $yes = 'ACYM_YES',
134 string $no = 'ACYM_NO'
135 ): void {
136 $options = [
137 '1' => acym_translation($yes),
138 '0' => acym_translation($no),
139 ];
140
141 $params = ['id' => $id];
142 if (!empty($attributes['containerClass'])) {
143 $params['containerClass'] = $attributes['containerClass'];
144 unset($attributes['containerClass']);
145 }
146
147 acym_radio(
148 $options,
149 $name,
150 $selected ? 1 : 0,
151 $attributes,
152 $params,
153 !acym_isAdmin()
154 );
155 }
156
157 /**
158 * @param ?mixed $selected
159 */
160 function acym_select(
161 array $data,
162 string $name,
163 $selected = null,
164 ?array $attribs = null,
165 string $optKey = 'value',
166 string $optText = 'text',
167 ?string $idtag = null,
168 bool $translate = false,
169 bool $display = false
170 ): string {
171 if (empty($attribs)) {
172 $attribs = [];
173 }
174
175 $attribs['name'] = $name;
176 $attribs['id'] = str_replace(['[', ']', ' '], '', empty($idtag) ? $name : $idtag);
177
178 if (!$display) {
179 ob_start();
180 }
181
182 echo '<select ';
183 foreach ($attribs as $oneAttribute => $oneValue) {
184 if (is_array($oneValue) || is_object($oneValue)) {
185 $oneValue = json_encode($oneValue);
186 } elseif ($oneValue === true) {
187 $oneValue = $oneAttribute;
188 }
189
190 echo ' '.esc_attr($oneAttribute).'="'.esc_attr($oneValue).'"';
191 }
192 echo '>';
193
194 foreach ($data as $key => $oneOption) {
195 $disabled = false;
196 if (is_object($oneOption)) {
197 $value = $oneOption->$optKey;
198 $text = $oneOption->$optText;
199 if (isset($oneOption->disable)) {
200 $disabled = $oneOption->disable;
201 }
202 } else {
203 $value = $key;
204 $text = $oneOption;
205 }
206
207 if ($translate) {
208 $text = acym_translation($text);
209 }
210
211 if (strtolower($value) === '<optgroup>') {
212 echo '<optgroup label="'.esc_attr($text).'">';
213 } elseif (strtolower($value) === '</optgroup>') {
214 echo '</optgroup>';
215 } else {
216 echo '<option value="'.esc_attr($value).'"';
217 selected(strval($value) === strval($selected));
218 disabled($disabled);
219 echo '>'.esc_html($text).'</option>';
220 }
221 }
222
223 echo '</select>';
224
225 if (!$display) {
226 return ob_get_clean();
227 }
228
229 return '';
230 }
231
232 function acym_selectMultiple(
233 array $data,
234 string $name,
235 array $selected = [],
236 array $attribs = [],
237 string $optValue = 'value',
238 string $optText = 'text',
239 bool $display = false
240 ): string {
241 if (substr($name, -2) !== '[]') {
242 $name .= '[]';
243 }
244 $baseName = substr($name, 0, -2);
245
246 $attribs['name'] = $name;
247 $attribs['multiple'] = 'multiple';
248
249 if (!$display) {
250 ob_start();
251 }
252
253 echo '<input type="hidden" name="'.esc_attr($baseName).'" value="">';
254 echo '<select ';
255 foreach ($attribs as $oneAttribute => $oneValue) {
256 if (is_array($oneValue) || is_object($oneValue)) {
257 $oneValue = json_encode($oneValue);
258 } elseif ($oneValue === true) {
259 $oneValue = $oneAttribute;
260 }
261
262 echo ' '.esc_attr($oneAttribute).'="'.esc_attr($oneValue).'"';
263 }
264 echo '>';
265
266 foreach ($data as $oneDataKey => $oneDataValue) {
267 if (is_object($oneDataValue)) {
268 $value = $oneDataValue->$optValue;
269 $text = $oneDataValue->$optText;
270 } else {
271 $value = $oneDataKey;
272 $text = $oneDataValue;
273 }
274
275 if (strtolower($value) === '<optgroup>') {
276 echo '<optgroup label="'.esc_attr($text).'">';
277 } elseif (strtolower($value) === '</optgroup>') {
278 echo '</optgroup>';
279 } else {
280 echo '<option value="'.esc_attr($value).'"';
281 selected(in_array($value, $selected));
282 disabled(is_object($oneDataValue) && !empty($oneDataValue->disable));
283 echo '>'.esc_html($text).'</option>';
284 }
285 }
286
287 echo '</select>';
288
289 if (!$display) {
290 return ob_get_clean();
291 }
292
293 return '';
294 }
295
296 /**
297 * @param mixed $value
298 */
299 function acym_selectOption(
300 $value,
301 string $text = '',
302 string $optKey = 'value',
303 string $optText = 'text',
304 bool $disable = false
305 ): object {
306 $option = new stdClass();
307 $option->$optKey = $value;
308 $option->$optText = acym_translation($text);
309 $option->disable = $disable;
310
311 return $option;
312 }
313
314 /**
315 * @param string|array $options The string name or the new options in an array
316 * @param mixed $value
317 */
318 function acym_switch(
319 $options,
320 $value = '',
321 ?string $label = null,
322 array $attrInput = [],
323 string $labelClass = 'medium-6 small-9',
324 string $switchContainerClass = 'auto',
325 string $switchClass = '',
326 ?string $toggle = null
327 ): void {
328 static $occurrence = 100;
329 $occurrence++;
330
331 // A switch displayed in a filter or a condition is cloned for every row
332 $id = (is_array($options) && !empty($options['idPrefix']) ? $options['idPrefix'] : '').'switch_'.$occurrence;
333
334 //TODO remove old parameters in January 2027 (only used in WC, Hika, VM and ultimate member plugins, which were updated in July 2026
335 if (!is_array($options)) {
336 $options = [
337 'name' => $options,
338 'value' => $value,
339 'label' => $label,
340 'attributes' => $attrInput,
341 'labelClass' => $labelClass,
342 'switchContainerClass' => $switchContainerClass,
343 'switchClass' => $switchClass,
344 'toggle' => $toggle,
345 'toggleOpen' => true,
346 'disabled' => false,
347 ];
348 } else {
349 $options['attributes'] = $options['attributes'] ?? [];
350 $options['labelClass'] = $options['labelClass'] ?? 'medium-6 small-9';
351 $options['switchContainerClass'] = $options['switchContainerClass'] ?? 'auto';
352 $options['switchClass'] = $options['switchClass'] ?? '';
353 $options['toggleOpen'] = $options['toggleOpen'] ?? true;
354 $options['disabled'] = $options['disabled'] ?? false;
355 }
356
357 $checkboxAriaLabel = '';
358 if (!empty($options['attributes']['aria-label'])) {
359 $checkboxAriaLabel = $options['attributes']['aria-label'];
360 unset($options['attributes']['aria-label']);
361 }
362
363 $options['attributes']['name'] = $options['name'];
364 $options['attributes']['data-switch'] = $id;
365 $options['attributes']['value'] = $options['value'];
366
367 if (!empty($options['toggle'])) {
368 $options['attributes']['data-toggle-switch'] = $options['toggle'];
369 $options['attributes']['data-toggle-switch-open'] = $options['toggleOpen'] ? 'show' : 'hide';
370 }
371
372 if (!empty($options['label']) || !empty($options['tooltip'])) {
373 echo '<label for="'.esc_attr($id).'" class="cell '.esc_attr($options['labelClass']).' switch-label">';
374 if (!empty($options['label'])) {
375 echo esc_html($options['label']);
376 }
377
378 if (!empty($options['tooltip'])) {
379 acym_tooltip($options['tooltip']);
380 }
381
382 if (!empty($options['tip'])) {
383 acym_info($options['tip']);
384 }
385 echo '</label>';
386 echo '<div class="cell '.esc_attr($options['switchContainerClass']).'">';
387 }
388
389 $labelSwitchDisabled = !$options['disabled'] ? '' : ' disabled';
390 ?>
391
392 <div class="switch <?php echo esc_attr($options['switchClass']); ?>">
393 <input type="hidden"
394 <?php
395 foreach ($options['attributes'] as $oneAttribute => $oneValue) {
396 if (is_array($oneValue) || is_object($oneValue)) {
397 $oneValue = json_encode($oneValue);
398 } elseif ($oneValue === true) {
399 $oneValue = $oneAttribute;
400 }
401
402 echo ' '.esc_attr($oneAttribute).'="'.esc_attr($oneValue).'"';
403 }
404 ?>
405 >
406
407 <input class="switch-input"
408 type="checkbox"
409 id="<?php echo esc_attr($id); ?>"
410 value="1"
411 tabindex="0"
412 role="switch"
413 <?php
414 checked($options['value'] == 1);
415 disabled($options['disabled']);
416 if (!empty($checkboxAriaLabel)) {
417 echo ' aria-label="'.esc_attr($checkboxAriaLabel).'"';
418 }
419 ?>
420 >
421 <label class="switch-paddle switch-label <?php echo esc_attr($labelSwitchDisabled); ?>" for="<?php echo esc_attr($id); ?>">
422 <span class="switch-active" aria-hidden="true">1</span>
423 <span class="switch-inactive" aria-hidden="true">0</span>
424 </label>
425 </div>
426
427 <?php
428 if (!empty($options['label']) || !empty($options['tooltip'])) {
429 echo '</div>';
430 }
431 }
432
433 function acym_showMore(string $toggle, string $text = 'ACYM_SHOW_MORE', string $class = ''): void
434 {
435 ?>
436 <div class="showmore <?php echo esc_attr($class); ?>" data-toggle-showmore="<?php echo esc_attr($toggle); ?>">
437 <label>
438 <?php echo esc_html(acym_translation($text)); ?><i class="acymicon-keyboard-arrow-down"></i>
439 </label>
440 </div>
441 <?php
442 }
443
444 function acym_generateCountryNumber(string $name, string $defaultvalue = ''): void
445 {
446 $country = [
447 '' => acym_translation('ACYM_PHONE_NOCOUNTRY'),
448 '93' => 'Afghanistan',
449 '355' => 'Albania',
450 '213' => 'Algeria',
451 '1684' => 'American Samoa',
452 '376' => 'Andorra',
453 '244' => 'Angola',
454 '1264' => 'Anguilla',
455 '672' => 'Antarctica',
456 '1268' => 'Antigua & Barbuda',
457 '54' => 'Argentina',
458 '374' => 'Armenia',
459 '297' => 'Aruba',
460 '247' => 'Ascension Island',
461 '61' => 'Australia',
462 '43' => 'Austria',
463 '994' => 'Azerbaijan',
464 '1242' => 'Bahamas',
465 '973' => 'Bahrain',
466 '880' => 'Bangladesh',
467 '1246' => 'Barbados',
468 '375' => 'Belarus',
469 '32' => 'Belgium',
470 '501' => 'Belize',
471 '229' => 'Benin',
472 '1441' => 'Bermuda',
473 '975' => 'Bhutan',
474 '591' => 'Bolivia',
475 '387' => 'Bosnia/Herzegovina',
476 '267' => 'Botswana',
477 '55' => 'Brazil',
478 '1284' => 'British Virgin Islands',
479 '673' => 'Brunei',
480 '359' => 'Bulgaria',
481 '226' => 'Burkina Faso',
482 '257' => 'Burundi',
483 '855' => 'Cambodia',
484 '237' => 'Cameroon',
485 '1' => 'Canada/USA',
486 '238' => 'Cape Verde Islands',
487 '1345' => 'Cayman Islands',
488 '236' => 'Central African Republic',
489 '235' => 'Chad Republic',
490 '56' => 'Chile',
491 '86' => 'China',
492 '6724' => 'Christmas Island',
493 '6722' => 'Cocos Keeling Island',
494 '57' => 'Colombia',
495 '269' => 'Comoros',
496 '243' => 'Congo Democratic Republic',
497 '242' => 'Congo, Republic of',
498 '682' => 'Cook Islands',
499 '506' => 'Costa Rica',
500 '225' => 'Cote D\'Ivoire',
501 '385' => 'Croatia',
502 '53' => 'Cuba',
503 '357' => 'Cyprus',
504 '420' => 'Czech Republic',
505 '45' => 'Denmark',
506 '253' => 'Djibouti',
507 '1767' => 'Dominica',
508 '1809' => 'Dominican Republic',
509 '593' => 'Ecuador',
510 '20' => 'Egypt',
511 '503' => 'El Salvador',
512 '240' => 'Equatorial Guinea',
513 '291' => 'Eritrea',
514 '372' => 'Estonia',
515 '251' => 'Ethiopia',
516 '500' => 'Falkland Islands',
517 '298' => 'Faroe Island',
518 '679' => 'Fiji Islands',
519 '358' => 'Finland',
520 '33' => 'France',
521 '596' => 'French Antilles/Martinique',
522 '594' => 'French Guiana',
523 '689' => 'French Polynesia',
524 '241' => 'Gabon Republic',
525 '220' => 'Gambia',
526 '995' => 'Georgia',
527 '49' => 'Germany',
528 '233' => 'Ghana',
529 '350' => 'Gibraltar',
530 '30' => 'Greece',
531 '299' => 'Greenland',
532 '1473' => 'Grenada',
533 '590' => 'Guadeloupe',
534 '1671' => 'Guam',
535 '502' => 'Guatemala',
536 '224' => 'Guinea Republic',
537 '245' => 'Guinea-Bissau',
538 '592' => 'Guyana',
539 '509' => 'Haiti',
540 '504' => 'Honduras',
541 '852' => 'Hong Kong',
542 '36' => 'Hungary',
543 '354' => 'Iceland',
544 '91' => 'India',
545 '62' => 'Indonesia',
546 '964' => 'Iraq',
547 '98' => 'Iran',
548 '353' => 'Ireland',
549 '972' => 'Israel',
550 '39' => 'Italy',
551 '1876' => 'Jamaica',
552 '81' => 'Japan',
553 '962' => 'Jordan',
554 '254' => 'Kenya',
555 '686' => 'Kiribati',
556 '3774' => 'Kosovo',
557 '965' => 'Kuwait',
558 '996' => 'Kyrgyzstan',
559 '856' => 'Laos',
560 '371' => 'Latvia',
561 '961' => 'Lebanon',
562 '266' => 'Lesotho',
563 '231' => 'Liberia',
564 '218' => 'Libya',
565 '423' => 'Liechtenstein',
566 '370' => 'Lithuania',
567 '352' => 'Luxembourg',
568 '853' => 'Macau',
569 '389' => 'Macedonia',
570 '261' => 'Madagascar',
571 '265' => 'Malawi',
572 '60' => 'Malaysia',
573 '960' => 'Maldives',
574 '223' => 'Mali Republic',
575 '356' => 'Malta',
576 '692' => 'Marshall Islands',
577 '222' => 'Mauritania',
578 '230' => 'Mauritius',
579 '52' => 'Mexico',
580 '691' => 'Micronesia',
581 '373' => 'Moldova',
582 '377' => 'Monaco',
583 '976' => 'Mongolia',
584 '382' => 'Montenegro',
585 '1664' => 'Montserrat',
586 '212' => 'Morocco',
587 '258' => 'Mozambique',
588 '95' => 'Myanmar (Burma)',
589 '264' => 'Namibia',
590 '674' => 'Nauru',
591 '977' => 'Nepal',
592 '31' => 'Netherlands',
593 '599' => 'Netherlands Antilles',
594 '687' => 'New Caledonia',
595 '64' => 'New Zealand',
596 '505' => 'Nicaragua',
597 '227' => 'Niger Republic',
598 '234' => 'Nigeria',
599 '683' => 'Niue Island',
600 '6723' => 'Norfolk',
601 '850' => 'North Korea',
602 '47' => 'Norway',
603 '968' => 'Oman Dem Republic',
604 '92' => 'Pakistan',
605 '680' => 'Palau Republic',
606 '970' => 'Palestine',
607 '507' => 'Panama',
608 '675' => 'Papua New Guinea',
609 '595' => 'Paraguay',
610 '51' => 'Peru',
611 '63' => 'Philippines',
612 '48' => 'Poland',
613 '351' => 'Portugal',
614 '1787' => 'Puerto Rico',
615 '974' => 'Qatar',
616 '262' => 'Reunion Island',
617 '40' => 'Romania',
618 '7' => 'Russia',
619 '250' => 'Rwanda Republic',
620 '1670' => 'Saipan/Mariannas',
621 '378' => 'San Marino',
622 '239' => 'Sao Tome/Principe',
623 '966' => 'Saudi Arabia',
624 '221' => 'Senegal',
625 '381' => 'Serbia',
626 '248' => 'Seychelles Island',
627 '232' => 'Sierra Leone',
628 '65' => 'Singapore',
629 '421' => 'Slovakia',
630 '386' => 'Slovenia',
631 '677' => 'Solomon Islands',
632 '252' => 'Somalia Republic',
633 '685' => 'Somoa',
634 '27' => 'South Africa',
635 '82' => 'South Korea',
636 '34' => 'Spain',
637 '94' => 'Sri Lanka',
638 '290' => 'St. Helena',
639 '1869' => 'St. Kitts',
640 '1758' => 'St. Lucia',
641 '508' => 'St. Pierre',
642 '1784' => 'St. Vincent',
643 '249' => 'Sudan',
644 '597' => 'Suriname',
645 '268' => 'Swaziland',
646 '46' => 'Sweden',
647 '41' => 'Switzerland',
648 '963' => 'Syria',
649 '886' => 'Taiwan',
650 '992' => 'Tajikistan',
651 '255' => 'Tanzania',
652 '66' => 'Thailand',
653 '228' => 'Togo Republic',
654 '690' => 'Tokelau',
655 '676' => 'Tonga Islands',
656 '1868' => 'Trinidad & Tobago',
657 '216' => 'Tunisia',
658 '90' => 'Turkey',
659 '993' => 'Turkmenistan',
660 '1649' => 'Turks & Caicos Island',
661 '688' => 'Tuvalu',
662 '256' => 'Uganda',
663 '380' => 'Ukraine',
664 '971' => 'United Arab Emirates',
665 '44' => 'United Kingdom',
666 '598' => 'Uruguay',
667 '1 ' => 'USA/Canada',
668 '998' => 'Uzbekistan',
669 '678' => 'Vanuatu',
670 '3966' => 'Vatican City',
671 '58' => 'Venezuela',
672 '84' => 'Vietnam',
673 '1340' => 'Virgin Islands (US)',
674 '681' => 'Wallis/Futuna Islands',
675 '967' => 'Yemen Arab Republic',
676 '260' => 'Zambia',
677 '263' => 'Zimbabwe',
678 ];
679
680 $countryCodeForSelect = [];
681
682 foreach ($country as $key => $one) {
683 $countryCodeForSelect[$key] = '+'.$key.' ('.$one.')';
684 }
685
686 acym_select(
687 $countryCodeForSelect,
688 $name,
689 empty($defaultvalue) ? '' : $defaultvalue,
690 [
691 'class' => 'acym__select__country acym__select',
692 'autocomplete' => 'tel-country-code',
693 'aria-label' => acym_translation('ACYM_PHONE_COUNTRY_CODE'),
694 ],
695 'value',
696 'text',
697 null,
698 false,
699 true
700 );
701 }
702
703 function acym_cancelButton(string $text = 'ACYM_CANCEL', string $url = '', string $class = 'button medium-6 large-shrink'): void
704 {
705 if (empty($url)) {
706 $url = acym_completeLink(acym_getVar('cmd', 'ctrl').'&task=listing');
707 }
708
709 echo '<a href="'.esc_url($url).'" class="cell '.esc_attr($class).' acym__button__cancel">'.esc_html(acym_translation($text)).'</a>';
710 }
711
712 /**
713 * Options:
714 * classContainer => Classes applied on the main container
715 * hoveredText => Text shown on the page
716 * classText => Classes applied to the hovered text container
717 * titleShownInTooltip => Title added above the tooltip text
718 * textShownInTooltip => Text shown inside the tooltip box
719 * link => URL to redirect on click to the hovered text
720 * classLink => Classes applied on the link element if any
721 */
722 function acym_tooltip(array $options): void
723 {
724 if (!isset($options['classContainer'])) $options['classContainer'] = '';
725 if (!isset($options['classText'])) $options['classText'] = '';
726 if (!isset($options['titleShownInTooltip'])) $options['titleShownInTooltip'] = '';
727 if (!isset($options['textShownInTooltip'])) $options['textShownInTooltip'] = '';
728 if (!isset($options['hoveredText'])) $options['hoveredText'] = '';
729 if (!isset($options['classLink'])) $options['classLink'] = '';
730
731 echo '<span class="acym__tooltip '.esc_attr($options['classContainer']).'">';
732 echo '<span class="acym__tooltip__text '.esc_attr($options['classText']).'">';
733
734 if (!empty($options['titleShownInTooltip'])) {
735 echo '<span class="acym__tooltip__title">';
736 }
737 echo esc_html($options['titleShownInTooltip']);
738 if (!empty($options['titleShownInTooltip'])) {
739 echo '</span>';
740 }
741
742 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Text escaped by caller, too many possible inputs.
743 echo $options['textShownInTooltip'];
744 echo '</span>';
745
746 if (!empty($options['link'])) {
747 echo '<a
748 href="'.esc_url($options['link']).'"
749 title="'.esc_attr($options['titleShownInTooltip']).'"
750 target="_blank"
751 class="'.esc_attr($options['classLink']).'">';
752 }
753 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Text escaped by caller, too many possible inputs.
754 echo $options['hoveredText'];
755 if (!empty($options['link'])) {
756 echo '</a>';
757 }
758 echo '</span>';
759 }
760
761 /**
762 * Options:
763 * textShownInTooltip => Text shown inside the tooltip box
764 * classContainer => Classes applied on the main container
765 * classText => Classes applied to the hovered icon container
766 * classIcon => Classes applied to the hovered icon
767 * isWarning => Is the tooltip icon should be more visible
768 * classLink => Classes applied on the link element if any
769 */
770 function acym_info(array $options): void
771 {
772 if (!isset($options['textShownInTooltip'])) $options['textShownInTooltip'] = '';
773 if (!isset($options['classContainer'])) $options['classContainer'] = '';
774 if (!isset($options['classText'])) $options['classText'] = '';
775 if (!isset($options['classIcon'])) $options['classIcon'] = '';
776 if (!isset($options['isWarning'])) $options['isWarning'] = false;
777
778 $classWarning = $options['isWarning'] ? 'acym__tooltip__info__warning' : '';
779
780 acym_tooltip(
781 [
782 'hoveredText' => '<span class="acym__tooltip__info__container '.$options['classIcon'].'"><i class="acym__tooltip__info__icon acymicon-info-circle '.esc_attr(
783 $classWarning
784 ).'"></i></span>',
785 'textShownInTooltip' => acym_translation($options['textShownInTooltip']),
786 'classContainer' => 'acym__tooltip__info '.$options['classContainer'],
787 'classText' => $options['classText'],
788 ]
789 );
790 }
791
792 function acym_sortBy(array $options, string $listing, string $default = '', string $defaultSortOrdering = 'desc'): void
793 {
794 $default = empty($default) ? reset($options) : $default;
795
796 $selected = acym_getVar('string', $listing.'_ordering', $default);
797 $orderingSortOrder = acym_getVar('string', $listing.'_ordering_sort_order', $defaultSortOrdering);
798 $classSortOrder = $orderingSortOrder === 'asc' ? 'acymicon-sort-amount-asc' : 'acymicon-sort-amount-desc';
799
800 echo '<span class="acym__color__dark-gray">'.esc_html(acym_translation('ACYM_SORT_BY')).'</span>';
801 acym_select(
802 $options,
803 $listing.'_ordering',
804 $selected,
805 [
806 'id' => 'acym__listing__ordering',
807 'class' => 'acym__select acym__select__sort',
808 ],
809 'value',
810 'text',
811 null,
812 false,
813 true
814 );
815
816 $tooltipText = $orderingSortOrder === 'asc' ? acym_translation('ACYM_SORT_ASC') : acym_translation('ACYM_SORT_DESC');
817 acym_tooltip(
818 [
819 'hoveredText' => '<i class="'.$classSortOrder.' acym__listing__ordering__sort-order" aria-hidden="true"></i>',
820 'textShownInTooltip' => $tooltipText,
821 ]
822 );
823
824 echo '<input type="hidden" id="acym__listing__ordering__sort-order--input" name="'.esc_attr($listing).'_ordering_sort_order" value="'.esc_attr($orderingSortOrder).'">';
825 }
826
827 function acym_checkbox(
828 array $values,
829 string $name,
830 array $selected = [],
831 string $label = '',
832 string $parentClass = '',
833 string $labelClass = '',
834 array $dataAttr = []
835 ): void {
836 echo '<div class="'.esc_attr($parentClass).'"><div class="cell acym__label '.esc_attr($labelClass).'">'.esc_html($label).'</div><div class="cell auto grid-x">';
837 foreach ($values as $key => $value) {
838 ?>
839 <label class="cell grid-x margin-top-1">
840 <input type="checkbox"
841 name="<?php echo esc_attr($name); ?>"
842 value="<?php echo esc_attr($key); ?>"
843 <?php checked(in_array($key, $selected)); ?>
844 <?php
845 if (!empty($dataAttr[$key])) {
846 echo 'data-attr="'.esc_attr($dataAttr[$key]).'"';
847 }
848 ?>>
849 <?php echo wp_kses($value, SecurityHelper::ALLOWED_HTML_CHECKBOX_LABEL); ?>
850 </label>
851 <?php
852 }
853 echo '</div></div>';
854 }
855
856 function acym_switchFilter(array $switchOptions, string $selected, string $name, string $addClass = ''): string
857 {
858 $return = '<input type="hidden" id="acym__type-template-'.esc_attr($name).'" name="'.esc_attr($name).'" value="'.esc_attr($selected).'">';
859 foreach ($switchOptions as $value => $text) {
860 $class = 'button button-secondary acym__type__choosen cell small-6 xlarge-auto large-shrink';
861 if ($value === $selected) {
862 $class .= ' is-active';
863 }
864 $class .= ' '.$addClass;
865 $return .= '<button class="'.esc_attr($class).'" type="button" data-type="'.esc_attr($value).'">'.esc_html(acym_translation($text)).'</button>';
866 }
867
868 return $return;
869 }
870
871 function acym_filterStatus(array $options, string $selected, string $name): void
872 {
873 echo '<input type="hidden" id="acym_filter_status" name="'.esc_attr($name).'" value="'.esc_attr($selected).'"/>';
874
875 foreach ($options as $value => $text) {
876 ?>
877 <button type="button"
878 acym-data-status="<?php echo esc_attr($value); ?>"
879 class="acym__filter__status<?php echo $value === $selected ? ' font-bold acym__status__select' : ''; ?>"
880 <?php disabled(!is_null($text[1]) && empty($text[1])); ?>
881 >
882 <?php echo esc_html(acym_translation($text[0])); ?>
883 <?php
884 if (!empty($text[2]) && 'pending' == $text[2]) {
885 echo ' <i class="acymicon-exclamation-triangle acym__color__orange" style="font-size: 15px;"></i>';
886 }
887
888 if (!is_null($text[1])) {
889 echo '<span class="acym__filter__status__number"> ('.esc_html($text[1]).')</span>';
890 }
891 ?>
892 </button>
893 <?php
894 }
895 }
896
897 function acym_filterSearch(
898 string $search,
899 string $name,
900 string $placeholder = 'ACYM_SEARCH',
901 bool $showClearBtn = true,
902 string $additionalClasses = ''
903 ): void {
904 ?>
905 <div class="input-group acym__search-area <?php echo esc_attr($additionalClasses); ?>">
906 <div class="input-group-button">
907 <button class="button acym__search__button"><i class="acymicon-search"></i></button>
908 </div>
909 <input class="input-group-field acym__search-field"
910 type="text"
911 name="<?php echo esc_attr($name); ?>"
912 placeholder="<?php echo esc_attr(acym_translation($placeholder)); ?>"
913 value="<?php echo esc_attr($search); ?>">
914 <?php if ($showClearBtn) { ?>
915 <span class="acym__search-clear"><i class="acymicon-close"></i></span>
916 <?php } ?>
917 </div>
918 <?php
919 }
920
921 /**
922 * @param mixed $value
923 */
924 function acym_displayParam(string $type, $value, string $name): void
925 {
926 if (!include_once ACYM_FRONT.'Params'.DS.$type.'.php') {
927 return;
928 }
929
930 $class = 'JFormField'.ucfirst($type);
931
932 $field = new $class();
933 $field->value = $value;
934 $field->name = $name;
935
936 echo wp_kses($field->getInput(), SecurityHelper::ALLOWED_HTML_PARAM_FIELD);
937 }
938
939 function acym_externalLink(
940 string $text,
941 string $link,
942 bool $displayIcon = true,
943 bool $openInNewTab = true,
944 array $classesA = []
945 ): void {
946 $classesA[] = 'acym__external__link';
947 ?>
948 <a
949 href="<?php echo esc_url($link); ?>"
950 class="<?php echo esc_attr(implode(' ', $classesA)); ?>"
951 <?php
952 if ($openInNewTab) {
953 echo 'target="_blank"';
954 }
955 ?>
956 >
957 <?php echo esc_html(acym_translation($text)); ?>
958 <?php
959 if ($displayIcon) {
960 echo ' <i class="acymicon-external-link"></i>';
961 }
962 ?>
963 </a>
964 <?php
965 }
966
967 function acym_getFormattedAttributes(array $attributes): string
968 {
969 $params = '';
970 foreach ($attributes as $oneAttribute => $oneValue) {
971 $params .= ' '.$oneAttribute;
972
973 if ($oneValue !== true) {
974 if (is_array($oneValue) || is_object($oneValue)) {
975 $oneValue = json_encode($oneValue);
976 }
977 $params .= '="'.esc_attr($oneValue).'"';
978 }
979 }
980
981 return $params;
982 }
983