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

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

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