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 / modal.php

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

225 lines 7.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 * Add the attribute data-open (should be the ID of the modal) to any element to make it open the modal.
6 */
7 function acym_modal(
8 string $button,
9 string $data,
10 ?string $id = null,
11 array $attributesModal = [],
12 array $attributesButton = [],
13 bool $isButton = true,
14 bool $isLarge = true,
15 string $classesModal = ''
16 ): void {
17 if (empty($id)) {
18 $id = 'acymodal_'.acym_rand(1000, 9000);
19 }
20
21 //TODO test with data-iframe param since it's a partial URL
22 $attributesButton['data-open'] = $id;
23
24 $attributesModal['class'] = 'reveal '.$classesModal;
25 $attributesModal['id'] = $id;
26 $attributesModal['data-reveal'] = '';
27 if ($isLarge) {
28 $attributesModal['data-reveal-larger'] = '';
29 }
30
31 if ($isButton) {
32 echo '<button type="button" ';
33 foreach ($attributesButton as $oneAttribute => $oneValue) {
34 if (is_array($oneValue) || is_object($oneValue)) {
35 $oneValue = json_encode($oneValue);
36 } elseif ($oneValue === true) {
37 $oneValue = $oneAttribute;
38 }
39
40 echo ' '.esc_attr($oneAttribute).'="'.esc_attr($oneValue).'"';
41 }
42 echo '>';
43 }
44 echo wp_kses(
45 $button,
46 [
47 'i' => [
48 'class' => true,
49 'data-acy-elementid' => true,
50 'data-open' => true,
51 'data-ajax' => true,
52 'data-iframe' => true,
53 'data-iframe-class' => true,
54 'id' => true,
55 'acym-data-domain' => true,
56 ],
57 'input' => [
58 'data-open' => true,
59 'class' => true,
60 'type' => true,
61 'value' => true,
62 'readonly' => true,
63 'onchange' => true,
64 ],
65 'span' => [
66 'class' => true,
67 ],
68 'div' => [
69 'class' => true,
70 'id' => true,
71 'data-iframe' => true,
72 'data-iframe-class' => true,
73 'data-open' => true,
74 ],
75 ]
76 );
77 if ($isButton) {
78 echo '</button>';
79 }
80
81 echo '<div ';
82 foreach ($attributesModal as $oneAttribute => $oneValue) {
83 if (is_array($oneValue) || is_object($oneValue)) {
84 $oneValue = json_encode($oneValue);
85 } elseif ($oneValue === true) {
86 $oneValue = $oneAttribute;
87 }
88
89 echo ' '.esc_attr($oneAttribute).'="'.esc_attr($oneValue).'"';
90 }
91 echo '>';
92 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped by the caller, too many cases.
93 echo $data;
94 echo '<button class="close-button" data-close aria-label="Close reveal" type="button">';
95 echo '<span aria-hidden="true">&times;</span>';
96 echo '</button></div>';
97 }
98
99 function acym_modalInclude(
100 string $button,
101 string $file,
102 string $id,
103 array $data,
104 string $classModal = '',
105 array $containerAttributes = []
106 ): void {
107 if (empty($id)) {
108 $id = 'acymodal_'.acym_rand(1000, 9000);
109 }
110
111 // Both can be used in the included file
112 $dataModal = $data;
113
114 $containerAttributes['data-open'] = $id;
115 echo '<div ';
116 foreach ($containerAttributes as $oneAttribute => $oneValue) {
117 if (is_array($oneValue) || is_object($oneValue)) {
118 $oneValue = json_encode($oneValue);
119 } elseif ($oneValue === true) {
120 $oneValue = $oneAttribute;
121 }
122
123 echo ' '.esc_attr($oneAttribute).'="'.esc_attr($oneValue).'"';
124 }
125 echo '>';
126 echo wp_kses(
127 $button,
128 [
129 'button' => [
130 'type' => true,
131 'id' => true,
132 'class' => true,
133 ],
134 'span' => [
135 'class' => true,
136 ],
137 'b' => [],
138 ]
139 );
140 echo '<div class="reveal '.esc_attr($classModal).'" id="'.esc_attr($id).'" data-reveal>';
141 include $file;
142 echo '<button type="button" class="close-button" data-close aria-label="Close reveal">';
143 echo '<span aria-hidden="true">&times;</span>';
144 echo '</button></div></div>';
145 }
146
147 function acym_modalPaginationLists(
148 string $inputEventId,
149 string $checkedLists = '[]',
150 bool $needDisplaySubscribers = false
151 ): void {
152 ?>
153 <input type="hidden" id="<?php echo esc_attr($inputEventId); ?>">
154
155 <?php if ($needDisplaySubscribers) { ?>
156 <input type="hidden" id="modal__pagination__need__display__sub">
157 <?php } ?>
158
159 <div class="cell grid-x" style="display: none;" id="acym__popup__plugin__subscription__lists__modal">
160 <input type="hidden" name="show_selected" value="false" id="modal__pagination__show-information">
161 <input type="hidden" id="modal__pagination__search__lists">
162 <input type="hidden" name="lists_selected" id="acym__modal__lists-selected" value="<?php echo esc_attr($checkedLists); ?>">
163 <div class="cell grid-x">
164 <h4 class="cell text-center acym__title acym__title__secondary">
165 <?php echo esc_html(acym_translation('ACYM_CHOOSE_LISTS')); ?>
166 </h4>
167 </div>
168 <div class="cell grid-x modal__pagination__search">
169 <?php acym_filterSearch('', 'modal_search_lists'); ?>
170 </div>
171 <div class="cell text-center padding-top-1" id="modal__pagination__search__spinner" style="display: none">
172 <i class="acymicon-circle-o-notch acymicon-spin"></i>
173 </div>
174 <div class="cell medium-6 modal__pagination__show">
175 <a href="#" class="acym__color__blue modal__pagination__show-selected modal__pagination__show-button selected">
176 <?php echo esc_html(acym_translation('ACYM_SHOW_SELECTED_LISTS')); ?>
177 </a>
178 <a href="#" class="acym__color__blue modal__pagination__show-all modal__pagination__show-button">
179 <?php echo esc_html(acym_translation('ACYM_SHOW_ALL_LISTS')); ?>
180 </a>
181 </div>
182 <div class="cell grid-x modal__pagination__listing__lists">
183 <div class="cell modal__pagination__listing__lists__in-form"></div>
184 </div>
185 </div>
186 <?php
187 }
188
189 function acym_frontModal(
190 string $iframeSrc,
191 string $buttonText,
192 bool $isButton,
193 ?string $identifier = null,
194 ?string $iframeClass = null
195 ): string {
196 static $loaded = false;
197 if (empty($loaded)) {
198 $loaded = true;
199 acym_addStyle(false, ACYM_CSS.'modal.min.css?v='.filemtime(ACYM_MEDIA.'css'.DS.'modal.min.css'));
200 acym_addScript(false, ACYM_JS.'modal.min.js?v='.filemtime(ACYM_MEDIA.'js'.DS.'modal.min.js'));
201 }
202
203 if (empty($identifier)) {
204 $identifier = 'identifier_'.acym_rand(1000, 9000);
205 }
206
207 if (empty($iframeClass)) {
208 $iframeClass = 'acym__modal__iframe';
209 }
210
211 ob_start();
212 ?>
213 <a class="<?php echo $isButton ? 'btn ' : ''; ?>acym__modal__handle" data-acym-modal="<?php echo esc_attr($identifier); ?>" href="#">
214 <?php echo esc_html(acym_translation($buttonText)); ?>
215 </a>
216 <div class="acym__modal" id="acym__modal__<?php echo esc_attr($identifier); ?>" style="display: none;">
217 <div class="acym__modal__content">
218 <div class="acym__modal__close"><span>&times;</span></div>
219 <iframe class="<?php echo esc_attr($iframeClass); ?>" src="<?php echo esc_url($iframeSrc); ?>"></iframe>
220 </div>
221 </div>
222 <?php
223 return ob_get_clean();
224 }
225