PluginProbe
Modal Window – create popup modal window / 6.2
Modal Window – create popup modal window v6.2
6.3 trunk 2.5 3.1.1 3.1.2 3.2.2 4.0.1 4.0.3 5.0.6 5.1.1 5.2 5.2.1 5.2.2 5.2.3 5.3 5.3.1 5.3.10 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.3.8 5.3.9 All 45 releases
modal-window / admin / class-script-maker.php

class-script-maker.php in Modal Window – create popup modal window 6.2, at admin/class-script-maker.php

331 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ModalWindow;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Script_Maker {
8 private array $script;
9 /**
10 * @var mixed
11 */
12 private $param;
13 /**
14 * @var mixed
15 */
16 private $id;
17
18 public function __construct( $id, $param ) {
19 $this->id = $id;
20 $this->param = $param;
21 $this->script = [];
22 }
23
24
25 public function init(): array {
26 $this->script['overlay'] = ! empty( $this->param['include_overlay'] );
27 $this->script['blockPage'] = isset( $this->param['modal_position'] ) && $this->param['modal_position'] === 'fixed';
28 $this->script['action'] = ['load', 0];
29
30 $this->script['closeBtn'] = [
31 ! empty( $this->param['close_button_remove'] ),
32 absint( $this->param['close_delay'] ),
33 ];
34 $this->script['closeAction'] = [true, true];
35 $mobile_unit = ( $this->param['mobile_width_par'] !== 'px' ) ? '%' : 'px';
36 $this->script['mobile'] = [
37 absint( $this->param['screen_size'] ),
38 absint( $this->param['mobile_width'] ),
39 $mobile_unit,
40 ];
41 $this->script['triggers'] = [
42 'wow-modal-id-' . absint( $this->id ),
43 'wow-modal-close-' . absint( $this->id ),
44 'wow-button-close' . absint( $this->id ),
45 ];
46
47 if(!empty($this->param['open_selectors'])) {
48 $this->script['openSelectors'] = esc_html($this->param['open_selectors']);
49 }
50
51 if(!empty($this->param['close_selectors'])) {
52 $this->script['closeSelectors'] = esc_html($this->param['close_selectors']);
53 }
54
55
56 $closeForm = isset($this->param['mail_send_timer']) ? absint($this->param['mail_send_timer']) : 3;
57 $this->script['closeForm'] = $closeForm;
58
59 $this->animation();
60 $this->scrolled();
61 $this->modal_style();
62 return $this->script;
63
64 }
65
66 private function animation(): void {
67 $this->script['animation'] = [
68 $this->param['window_animate'],
69 absint( $this->param['speed_window'] ),
70 $this->param['window_animate_out'],
71 absint( $this->param['speed_window_out'] ),
72 ];
73 }
74
75 private function scrolled(): void {
76 if ( $this->param['modal_show'] === 'scroll' ) {
77 $this->script['scrolled'] = [
78 $this->param['reach_window'],
79 $this->param['reach_window_unit'],
80 ];
81 }
82 }
83
84
85 private function modal_style(): void {
86
87 $general = $this->general_style();
88 $location = $this->location();
89 $title = $this->title();
90 $close_btn = $this->close_btn();
91 $float_btn = $this->float_btn();
92 $form_style = $this->form_style();
93
94 $args = array_merge( $general, $location, $title, $close_btn, $float_btn, $form_style );
95
96 $esc_args = array_map( 'esc_attr', $args );
97
98 $this->script['style'] = $esc_args;
99 }
100
101 private function general_style(): array {
102 $param = $this->param;
103 $args = [
104 '--mw-zindex' => $param['modal_zindex'] ?? '999999',
105 '--mw-position' => $param['modal_position'] ?? 'fixed',
106 '--mw-radius' => ( $param['border_radius'] ?? '5' ) . 'px',
107 '--mw-padding' => ( $param['modal_padding'] ?? '10' ) . 'px',
108 '--mw-font-size' => ( $param['content_size'] ?? '16' ) . 'px',
109 '--mw-font-family' => $param['content_font'] ?? 'inherit',
110 '--mw-bg-color' => $param['bg_color'] ?? '#ffffff',
111 '--mw-overlay' => $param['overlay_color'] ?? 'rgba(0,0,0,.7)',
112 '--mw-scrollbar-width' => $param['scrollbar_width'] ?? 'thin',
113 '--mw-scrollbar-color' => $param['scrollbar_color'] ?? '#4F4F4F',
114 '--mw-scrollbar-track' => $param['scrollbar_background'] ?? 'rgba(255,255,255, 0)',
115 ];
116
117 $scrollbar = $param['scrollbar_width'] ?? 'thin';
118 if ( $scrollbar === 'thin' ) {
119 $args['--mw-scrollbar-thin'] = '6px';
120 }
121 if ( $scrollbar === 'auto' ) {
122 $args['--mw-scrollbar-thin'] = '8px';
123 }
124 if ( $scrollbar === 'none' ) {
125 $args['--mw-scrollbar-thin'] = '0';
126 }
127
128 $width = $param['modal_width'] ?? '662';
129 $width_unit = $param['modal_width_par'] ?? 'px';
130 $width_unit = ( $width_unit === 'pr' ) ? '%' : 'px';
131 $args['--mw-width'] = $width . $width_unit;
132
133 $height = $param['modal_height'] ?? '350';
134 $height_unit = $param['modal_height_par'] ?? 'auto';
135 $height_unit = ( $height_unit === 'pr' ) ? '%' : $height_unit;
136 $args['--mw-height'] = ( $height_unit === 'auto' ) ? 'auto' : $height . $height_unit;
137
138 if ( ! empty( $param['modal_background_img'] ) ) {
139 $args['--mw-bg-img'] = 'url(' . esc_url( $param['modal_background_img'] ) . ')';
140 }
141
142 if ( $param['shadow'] !== 'none' ) {
143 $inset = ( $param['shadow'] === 'inset' ) ? 'inset ' : '';
144 $offset_x = ( $param['shadow_h_offset'] ?? '0' ) . 'px';
145 $offset_y = ( $param['shadow_v_offset'] ?? '0' ) . 'px';
146 $blur = ( $param['shadow_blur'] ?? '0' ) . 'px';
147 $spread = ( $param['shadow_spread'] ?? '0' ) . 'px';
148 $shadow_color = $param['shadow_color'] ?? '#ffffff';
149
150 $args['--mw-shadow'] = "$inset$offset_x $offset_y $blur $spread $shadow_color";
151 }
152
153 if ( $param['border_style'] !== 'none' ) {
154 $border_width = ( $param['border_width'] ?? '0' ) . 'px';
155 $border_style = $param['border_style'] ?? 'solid';
156 $border_color = $param['border_color'] ?? '#ffffff';
157
158 $args['--mw-border'] = "$border_width $border_style $border_color";
159 }
160
161 return $args;
162 }
163
164 private function location(): array {
165 $param = $this->param;
166 $args = [];
167
168 if ( ! empty( $param['include_modal_top'] ) ) {
169 $modal_top_unit = $param['modal_top_unit'] === '%' ? 'vh' : 'px';
170 $args['--mw-inset-top'] = $param['modal_top'] . $modal_top_unit;
171 }
172
173 if ( ! empty( $param['include_modal_right'] ) ) {
174 $modal_right_unit = $param['modal_right_unit'] === '%' ? 'vh' : 'px';
175 $args['--mw-inset-right'] = $param['modal_right'] . $modal_right_unit;
176 }
177
178 if ( ! empty( $param['include_modal_bottom'] ) ) {
179 $modal_bottom_unit = $param['modal_bottom_unit'] === '%' ? 'vh' : 'px';
180 $args['--mw-inset-bottom'] = $param['modal_bottom'] . $modal_bottom_unit;
181 }
182
183 if ( ! empty( $param['include_modal_left'] ) ) {
184 $modal_left_unit = $param['modal_bottom_unit'] === '%' ? 'vh' : 'px';
185 $args['--mw-inset-left'] = $param['modal_left'] . $modal_left_unit;
186 }
187
188 return $args;
189 }
190
191 private function title(): array {
192 $param = $this->param;
193 if ( empty( $param['popup_title'] ) ) {
194 return [];
195 }
196 $args = [
197 '--mw-title-size' => ( $param['title_size'] ?? '32' ) . 'px',
198 '--mw-title-line-height' => ( $param['title_line_height'] ?? '32' ) . 'px',
199 '--mw-title-font' => $param['title_font'] ?? 'inherit',
200 '--mw-title-weight' => $param['title_font_weight'] ?? '400',
201 '--mw-title-style' => $param['title_font_style'] ?? 'normal',
202 '--mw-title-align' => $param['title_align'] ?? 'left',
203 '--mw-title-color' => $param['title_color'] ?? '#383838',
204 '--mw-title-bg' => $param['title_background'] ?? 'rgba(255, 255, 255, 0)',
205 ];
206
207 return $args;
208 }
209
210 private function close_btn(): array {
211 $param = $this->param;
212 if ( ! empty( $param['close_button_remove'] ) ) {
213 return [];
214 }
215 $args = [
216 '--mw-close-padding' => $param['close_padding'] ?? '6px 12px',
217 '--mw-close-size' => ( $param['close_size'] ?? '12' ) . 'px',
218 '--mw-close-font' => $param['close_font'] ?? 'inherit',
219 '--mw-close-weight' => $param['close_weight'] ?? '400',
220 '--mw-close-style' => $param['close_font_style'] ?? 'normal',
221 '--mw-close-radius' => ( $param['close_border_radius'] ?? '0' ) . 'px',
222 '--mw-close-box' => ( $param['close_box_size'] ?? '24' ) . 'px',
223 '--mw-close-color' => $param['close_content_color'] ?? '#ffffff',
224 '--mw-close-h-color' => $param['close_content_color_hover'] ?? '#000000',
225 '--mw-close-bg' => $param['close_background_color'] ?? '#000000',
226 '--mw-close-h-bg' => $param['close_background_hover'] ?? '#ffffff',
227 ];
228
229 $top = ( $param['close_top_position'] ?? '0' ) . 'px';
230 $right = ( $param['close_right_position'] ?? '0' ) . 'px';
231 $left = ( $param['close_left_position'] ?? '0' ) . 'px';
232 $bottom = ( $param['close_bottom_position'] ?? '0' ) . 'px';
233
234 if ( $param['close_location'] === 'topRight' ) {
235 $args['--mw-close-inset'] = "$top $right auto auto";
236 }
237
238 if ( $param['close_location'] === 'topLeft' ) {
239 $args['--mw-close-inset'] = "$top auto auto $left";
240 }
241
242 if ( $param['close_location'] === 'bottomRight' ) {
243 $args['--mw-close-inset'] = "auto $right $bottom auto";
244 }
245
246 if ( $param['close_location'] === 'bottomLeft' ) {
247 $args['--mw-close-inset'] = "auto auto $bottom $left";
248 }
249
250 return $args;
251 }
252
253 private function float_btn(): array {
254 $param = $this->param;
255 $type = $param['umodal_button'] ?? 'no';
256 if ( $type === 'no' ) {
257 return [];
258 }
259 $args = [
260 '--mw-flbtn-padding' => $param['button_padding'] ?? '14px 14px',
261 '--mw-flbtn-radius' => ( $param['button_radius'] ?? '4' ) . 'px',
262 '--mw-flbtn-size' => ( $param['button_text_size'] ?? '1.2' ) . ( $param['button_text_size_unit'] ?? 'em' ),
263 '--mw-flbtn-color' => $param['button_text_color'] ?? '#ffffff',
264 '--mw-flbtn-h-color' => $param['button_text_hcolor'] ?? '#ffffff',
265 '--mw-flbtn-bg' => $param['umodal_button_color'] ?? '#383838',
266 '--mw-flbtn-h-bg' => $param['umodal_button_hover'] ?? '#797979',
267 '--mw-anime-duration' => ( $param['button_animate_duration'] ?? '5' ) . 's',
268 '--mw-anime-iteration' => $param['button_animate_time'] ?? '5',
269 ];
270
271 $offset = ( $param['button_position'] ?? '50' ) . '%';
272 $margin = ( $param['button_margin'] ?? '-4' ) . 'px';
273
274 if ( $param['umodal_button_position'] === 'wow_modal_button_right' ) {
275 $args['--mw-flbtn-inset'] = "$offset $margin auto auto";
276 }
277
278 if ( $param['umodal_button_position'] === 'wow_modal_button_left' ) {
279 $args['--mw-flbtn-inset'] = "$offset auto auto $margin";
280 }
281
282 if ( $param['umodal_button_position'] === 'wow_modal_button_top' ) {
283 $args['--mw-flbtn-inset'] = "auto $margin $offset auto";
284 }
285
286 if ( $param['umodal_button_position'] === 'wow_modal_button_bottom' ) {
287 $args['--mw-flbtn-inset'] = "auto auto $offset $margin";
288 }
289
290 return $args;
291 }
292
293 private function form_style(): array {
294 $param = $this->param;
295
296 if ( empty( $param['include_form_name'] ) && empty( $param['include_form_email'] ) && empty( $param['include_form_text'] ) ) {
297 return [];
298 }
299
300 if ( strpos( $param['content'], "{form}" ) === false ) {
301 return [];
302 }
303
304 $args = [
305 '--mw-form-width' => $param['form_width'] ?? '100%',
306 '--mw-form-padding' => $param['form_padding'] ?? '10px',
307 '--mw-form-margin' => $param['form_margin'] ?? '0 auto',
308 '--mw-form-border' => ( $param['form_border'] ?? '1px' ) . ' solid ' . ( $param['form_border_color'] ?? '#ffffff' ),
309 '--mw-form-radius' => $param['form_radius'] ?? '0px',
310 '--mw-form-bg' => $param['form_background'] ?? '#ffffff',
311 '--mw-field-border-width' => $param['field_border'] ?? '1px',
312 '--mw-field-border-color' => $param['field_border_color'] ?? '#383838',
313 '--mw-field-radius' => $param['field_radius'] ?? '0px',
314 '--mw-field-size' => $param['form_text_size'] ?? '16px',
315 '--mw-field-input-height' => $param['form_input_height'] ?? '36px',
316 '--mw-field-textarea-height' => $param['form_textarea_height'] ?? '72px',
317 '--mw-field-bg' => $param['field_background'] ?? '#ffffff',
318 '--mw-field-color' => $param['form_text_color'] ?? '#ffffff',
319 '--mw-form-btn-size' => $param['form_button_size'] ?? '16px',
320 '--mw-form-btn-color' => $param['form_button_text_color'] ?? '#ffffff',
321 '--mw-form-btn-bg' => $param['button_background_color'] ?? '#e95645',
322 '--mw-form-btn-h-bg' => $param['button_hover_color'] ?? '#d45041',
323 '--mw-form-text-size' => ( $param['mail_send_text_size'] ?? '16' ) . 'px',
324 '--mw-form-text-color' => $param['mail_send_text_color'] ?? '#48c774',
325
326 ];
327
328 return $args;
329
330 }
331 }