PluginProbe
MaxButtons – Create buttons / 6.9
MaxButtons – Create buttons v6.9
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / blocks / responsive.php

responsive.php in MaxButtons – Create buttons 6.9, at blocks/responsive.php

574 lines 20.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') or die('No direct access permitted');
3 $blockClass["responsive"] = "responsiveBlock";
4 $blockOrder[90][] = "responsive";
5
6 use MaxButtons\maxBlocks as maxBlocks;
7 use MaxButtons\maxField as maxField;
8
9
10 class responsiveBlock extends maxBlock
11 {
12 protected $blockname = 'responsive';
13 protected $fields = array("options" => '',
14 "auto_responsive" => array("default" => 0),
15 "media_query" => array("default" => array()
16 ),
17
18 );
19 // multifields for manual conversion // define +/- the same as normal fields.
20 // to find solution in parsing stuff back to button.
21 protected $multi_fields = array("mq_button_width" => array("default" => '0',
22 "css" => "width",
23 "csspseudo" => "responsive",
24
25 ),
26 "mq_button_width_unit" => array("default" => 'px',
27 "css" => "width_unit",
28 "csspseudo" => "responsive",
29 ),
30 "mq_button_height" => array("default" => '0',
31 "css" => "height",
32 "csspseudo" => "responsive",
33
34 ),
35 "mq_button_height_unit" => array("default" => 'px',
36 "css" => "height_unit",
37 "csspseudo" => "responsive",
38 ),
39 "mq_container_width" => array("default" => 0,
40 "css" => "width",
41 "csspart" => "mb-container",
42 "csspseudo" => "responsive",
43 ),
44 "mq_container_float" => array("default" => "",
45 "css" => "float",
46 "csspart" => "mb-container",
47 "csspseudo" => "responsive",
48 ),
49 "mq_container_width_unit" => array("default" => "px",
50 "css" => "width_unit",
51 "csspart" => "mb-container",
52 ),
53 "mq_font_size" => array("default" => 90,
54 "css" => "font-size",
55 "csspart" => "mb-text",
56 ),
57 "mq_font_size_unit" => array("default" => "%",
58 "css" => "font-size_unit",
59 "csspart" => "mb-text"),
60
61 "mq_custom_minwidth" => array("default" => "0",
62 "css" => "custom_minwidth"),
63 "mq_custom_maxwidth" => array("default" => "0",
64 "css" => "custom_maxwidth"),
65 "mq_hide" => array("default" => '',
66 "css" => "display",
67 "csspart" => "mb-container, maxbutton, mb-center",
68
69 ),
70 );
71
72
73 public function parse_css($css, $mode = 'normal')
74 {
75 if ($mode != 'normal')
76 return $css;
77
78 if (! isset($this->data[$this->blockname]))
79 return $css;
80
81 $data = $this->data[$this->blockname];
82
83 if (isset($data["auto_responsive"]) && $data["auto_responsive"] == 1)
84 { // generate auto_rules for responsive.
85 $css["maxbutton"]["responsive"]["phone"][0]["width"] = "90%";
86 $css["mb-container"]["responsive"]["phone"][0]["width"] = "90%";
87 $css["mb-container"]["responsive"]["phone"][0]["float"] = "none";
88 $css["mb-text"]["responsive"]["phone"][0]["font-size"] = "90%";
89
90
91 if ( isset($this->data["text"]["font_size"]) )
92 {
93 $css["mb-text"]["responsive"]["phone"][0]["font-size"] = floor(intval($this->data["text"]["font_size"]) * 0.8) . 'px';
94 }
95
96 }
97
98 if (! isset($data["media_query"]))
99 return $css;
100
101 foreach($data["media_query"] as $query => $data ):
102 $i = 0;
103
104 foreach($data as $index => $fields):
105
106
107 foreach($fields as $field => $value)
108 {
109 $csspart = (isset($this->multi_fields[$field]["csspart"])) ? explode(",",$this->multi_fields[$field]["csspart"]) : array('maxbutton') ;
110 $css_stat = $this->multi_fields[$field]["css"];
111
112
113 if ($value == '' || $value == '0')
114 { }
115 elseif ($query != 'custom' && ($field == 'mq_custom_maxwidth' || $field == "mq_custom_minwidth"))
116 { } // skip custom fields on noncustom query
117 else
118 {
119 foreach($csspart as $j => $part)
120 {
121 $part = trim($part); // spaces in array
122 $css[$part]["responsive"][$query][$i][$css_stat] = $value;
123 }
124
125 /* }
126 else
127 {
128
129 $css[$csspart]["responsive"][$query][$i][$css_stat] = $value;
130 } */
131 }
132
133 }
134 $i++;
135 endforeach;
136
137 endforeach;
138 return $css;
139 }
140
141
142 public function save_fields($data, $post)
143 {
144
145 $queries = (isset($post["media_query"])) ? $post["media_query"] : null;
146 $media_queries = array();
147
148 if (is_null($queries))
149 return $data;
150
151 foreach($queries as $i => $query)
152 {
153
154 if ($query != '')
155 {
156 //$media_queries[$query] = array();
157
158 // collect the other fields.
159 $c = isset($media_queries[$query]) ? count($media_queries[$query]) : 0;
160
161 foreach($this->multi_fields as $field => $values)
162 {
163 $default = isset($values["default"]) ? $values["default"] : '';
164
165 if (isset($post[$field][$i]))
166 {
167 $postval = $post[$field][$i];
168 if (is_numeric($default)) // sanitize.
169 {
170 $postval = intval($postval);
171 }
172 else
173 $value = sanitize_text_field($postval);
174
175 $media_queries[$query][$c][$field] = $postval;
176 }
177 }
178
179 }
180 }
181
182 $data[$this->blockname]["media_query"] = $media_queries;
183
184 $data[$this->blockname]["auto_responsive"] = (isset($post["auto_responsive"])) ? $post["auto_responsive"] : 0;
185
186 return $data;
187
188 }
189
190
191 public function admin_fields()
192 {
193 $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
194
195 $media_names = maxUtils::get_media_query(1); // nicenames
196 $media_desc = maxUtils::get_media_query(3);
197 $units = array("px" => __("px","maxbuttons"),
198 "%" => __("%","maxbuttons")
199 );
200 $container_floats = array(
201 "" => "",
202 "none" => __("None","maxbuttons"),
203 "left" => __("Left","maxbuttons"),
204 "right" => __("Right","maxbuttons"),
205 );
206
207 foreach($this->fields as $field => $options)
208 {
209 $default = (isset($options["default"])) ? $options["default"] : '';
210 $$field = (isset($data[$field])) ? $data[$field] : $default;
211 ${$field . "_default"} = $default;
212 }
213
214 // sorting routine via array merge.
215 $fk = array_flip(array_keys($media_query));
216 $names_used = array_intersect_key($media_names,$fk);
217 $media_query = array_merge($names_used,$media_query);
218
219 ?>
220 <script type='text/javascript'>
221 var responsiveMap = '<?php echo json_encode($this->multi_fields); ?>';
222 </script>
223
224 <div class="mb_tab option-container">
225 <div class="title"><?php _e('Responsive Settings', 'maxbuttons') ?></div>
226 <div class="inside responsive">
227
228 <div class="option-design">
229 <p class="note"><?php _e("Responsive settings let you decide the behavior of the button on different devices and screen sizes. For instance large buttons on small screens.","maxbuttons") ?></p>
230 <?php
231 $auto = new maxField('switch');
232 $auto->label = __('Auto Responsive (experimental)', 'maxinbound');
233 $auto->name = 'auto_responsive';
234 $auto->id = $auto->name;
235 $auto->value = '1';
236 $auto->checked = checked($auto_responsive, 1, false);
237 $auto->output ('start','end');
238 ?>
239
240 <div class="clear"></div>
241 <p class="note"><strong><?php _e("Note:","maxbuttons"); ?> </strong><?php _e(" Auto responsive settings will take a guess only on small screens. To control your responsive settings uncheck this button. This will show more options.","maxbuttons"); ?></p>
242 </div>
243
244
245 <div class="option-design new-query">
246 <label for='new_query'><?php _e('New Query', 'maxbuttons') ?></label>
247
248 <div class="input">
249 <select name="new_query" id="new_query">
250 <?php
251
252 foreach ($media_names as $key => $val):
253 $disabled = isset($media_query[$key]) && $key !== 'custom' ? ' DISABLED ' : '';
254 ?>
255 <option value="<?php echo $key ?>" <?php echo $disabled ?> ><?php echo $val ?></option>
256
257
258 <?php endforeach; ?>
259 </select>
260 <?php //echo maxUtils::selectify("new_query",$media_names,'' ); ?>
261 <a href='javascript:void(0)' class="button add_media_query"><?php _e("Add","maxbuttons") ?></a>
262 </div>
263
264
265 <div class="clear"></div>
266 </div> <!-- option design -->
267
268 <div class='option-design media_queries_options'>
269 <?php
270 $i = 0 ;
271 foreach($media_query as $item => $data):
272 foreach ($data as $index => $fields):
273
274 if (! isset($fields['mq_hide']))
275 $fields['mq_hide'] = 0;
276
277 $condition = array('target' => 'mq_hide[' . $i . ']', 'values' => 'unchecked');
278 $show_conditional = htmlentities(json_encode($condition));
279
280 ?>
281 <div class='media_query' data-query="<?php echo $item ?>" data-id="<?php echo $i ?>">
282 <span class='removebutton dashicons dashicons-no'></span>
283
284 <input type="hidden" name="media_query[<?php echo $i ?>]" value="<?php echo $item ?>">
285 <label class='title'><?php echo $media_names[$item] ?></label>
286 <p class='description'><?php echo $media_desc[$item] ?></p>
287 <?php
288 if ($item == "custom") { $custom_class = 'option custom'; } else { $custom_class = 'option custom hidden '; }
289
290 $min_width = new maxField('number');
291 $min_width->id = 'mq_custom_minwidth[' . $i . ']';
292 $min_width->name= $min_width->id;
293 $min_width->label = __('Min Width', 'maxbuttons');
294 $min_width->value = $fields['mq_custom_minwidth'];
295 $min_width->inputclass = 'small';
296 $min_width->main_class = $custom_class; // hide label
297 $min_width->output('start', '');
298
299
300 $max_width = new maxField('number');
301 $max_width->id = 'mq_custom_maxwidth[' . $i . ']';
302 $max_width->name = $max_width->id;
303 $max_width->label = __('Max Width','maxbuttons');
304 $max_width->value = $fields['mq_custom_maxwidth'];
305 $max_width->inputclass = 'small';
306 $max_width->mainclass = $custom_class;
307 $max_width->output('','end');
308
309
310 $font_size = new maxField('number');
311 $font_size->id = 'mq_font_size[' . $i . ']';
312 $font_size->name = $font_size->id;
313 $font_size->value = $fields['mq_font_size'];
314 $font_size->label = __('Font Size', 'maxbuttons');
315 $font_size->min = 0;
316 $font_size->inputclass = 'tiny';
317 $font_size->start_conditional = $show_conditional;
318 $font_size->output('start', '');
319
320 $fsize_unit = new maxField('generic');
321 $fsize_unit->id = 'mq_font_size_unit[' . $i . ']';
322 $fsize_unit->name = $fsize_unit->id;
323 $fsize_unit->value = $fields['mq_font_size_unit'];
324 $fsize_unit->content = maxUtils::selectify($fsize_unit->id, $units, $fsize_unit->value);
325 // $fsize_unit->conditional = $show_conditional;
326 $fsize_unit->output('','end');
327
328 // width
329 $width = new maxField('number');
330 $width->id = 'mq_button_width[' . $i . ']';
331 $width->name = $width->id;
332 $width->value = $fields['mq_button_width'];
333 $width->label = __('Button Width', 'maxbuttons');
334 $width->min = 0;
335 $width->inputclass = 'tiny';
336 $width->start_conditional = $show_conditional;
337 $width->output('start','');
338
339 $width_unit = new maxField('generic');
340 $width_unit->id = 'mq_button_width_unit[' . $i . ']';
341 $width_unit->name = $width_unit->id;
342 $width_unit->value = $fields['mq_button_width_unit'];
343 $width_unit->content = maxUtils::selectify($width_unit->id, $units, $width_unit->value);
344 // $width_unit->conditional = $show_conditional;
345 $width_unit->output('','');
346
347 // height
348 $height = new maxField('number');
349 $height->id = 'mq_button_height[' . $i . ']';
350 $height->name = $height->id;
351 $height->value = $fields['mq_button_height'];
352 $height->label = __("Button Height", "maxbuttons");
353 $height->min = 0;
354 $height->inputclass = 'tiny';
355 // $height->conditional = $show_conditional;
356 $height->output('','');
357
358 $height_unit = new maxField('generic');
359 $height_unit->id = 'mq_button_height_unit[' . $i . ']';
360 $height_unit->name = $height_unit->id;
361 $height_unit->value = $fields['mq_button_height_unit'];
362 $height_unit->content = maxUtils::selectify($height_unit->id, $units, $height_unit->value);
363 // $height_unit->conditional = $show_conditional;
364 $height_unit->output('','end');
365
366 $cwidth = new maxField('number');
367 $cwidth->id = 'mq_container_width[' . $i . ']';
368 $cwidth->name = $cwidth->id;
369 $cwidth->label = __('Container Width', 'maxbuttons');
370 $cwidth->value = $fields['mq_container_width'];
371 $cwidth->min = '0';
372 $cwidth->inputclass = 'tiny';
373 $cwidth->start_conditional = $show_conditional;
374 $cwidth->output('start', '');
375
376 $cwidth_unit = new maxField('generic');
377 $cwidth_unit->id = 'mq_container_width_unit[' . $i . ']';
378 $cwidth_unit->name = $cwidth_unit->id;
379 $cwidth_unit->value = $fields['mq_container_width_unit'];
380 $cwidth_unit->content = maxUtils::selectify($cwidth_unit->id, $units, $cwidth_unit->value);
381 // $cwidth_unit->conditional = $show_conditional;
382 $cwidth_unit->output('','end');
383
384 $cfloat = new maxField('generic');
385 $cfloat->id = 'mq_container_float[' . $i . ']';
386 $cfloat->name = $cfloat->id;
387 $cfloat->label = __('Container Float','maxbuttons');
388 $cfloat->value = $fields['mq_container_float'];
389 $cfloat->content = maxUtils::selectify($cfloat->id, $container_floats, $cfloat->value);
390 $cfloat->start_conditional = $show_conditional;
391 $cfloat->output('start','end');
392
393 $hide = new maxField('switch');
394 $hide->id = 'mq_hide[' . $i . ']';
395 $hide->name = $hide->id;
396 $hide->value = 'none';
397 $hide->checked = checked($fields['mq_hide'], $hide->value, false);
398 $hide->label = __('Hide button in this view','maxbuttons');
399 $hide->output('start','end');
400
401 /*
402 $preview = new maxField('button');
403 $preview->id = 'mq_preview[' . $i . ']';
404 $preview->inputclass = 'responsive_preview';
405 $preview->button_label = __('Show in preview','maxbuttons');
406 $preview->output('', 'end');
407 */
408
409 $i++;
410 //if ($item != 'custom')
411 // unset($media_names[$item]); // remove existing queries from new query selection
412 ?>
413 </div> <!-- media query -->
414 <?php
415 endforeach;
416 endforeach;
417
418
419 ?>
420 </div> <!-- option -design -->
421 <div class="new_query_space"></div>
422 </div> <!-- inside -->
423
424 <input type="hidden" name="next_media_index" value="<?php echo $i ?>" >
425
426 <div class='media_option_prot'>
427
428 <div class='media_query' data-query=''>
429 <span class='removebutton dashicons dashicons-no'></span>
430
431 <input type="hidden" name="media_query[]" value="">
432 <label class='title'></label>
433 <p class='description'>&nbsp;</p>
434 <?php
435 $custom_class = 'option hidden custom';
436 $condition = array('target' => 'mq_hide[]', 'values' => 'unchecked');
437 $show_conditional = htmlentities(json_encode($condition));
438
439 $min_width = new maxField('number');
440 $min_width->id = 'mq_custom_minwidth[]';
441 $min_width->name= $min_width->id;
442 $min_width->label = __('Min Width', 'maxbuttons');
443 // $min_width->value = $fields['mq_custom_minwidth'];
444 $min_width->inputclass = 'small';
445 $min_width->main_class = $custom_class; // hide label
446 $min_width->output('start', '');
447
448 $max_width = new maxField('number');
449 $max_width->id = 'mq_custom_maxwidth[]';
450 $max_width->name = $max_width->id;
451 $max_width->label = __('Max Width','maxbuttons');
452 // $max_width->value = $fields['mq_custom_maxwidth'];
453 $max_width->inputclass = 'small';
454 $max_width->mainclass = $custom_class;
455 $max_width->output('','end');
456
457
458 $font_size = new maxField('number');
459 $font_size->id = 'mq_font_size[]';
460 $font_size->name = $font_size->id;
461 //$font_size->value = $fields['mq_font_size'];
462 $font_size->label = __('Font Size', 'maxbuttons');
463 $font_size->min = 0;
464 $font_size->inputclass = 'tiny';
465 $font_size->start_conditional = $show_conditional;
466 $font_size->output('start', '');
467
468 $fsize_unit = new maxField('generic');
469 $fsize_unit->id = 'mq_font_size_unit[]';
470 $fsize_unit->name = $fsize_unit->id;
471 //$fsize_unit->value = $fields['mq_font_size_unit'];
472 $fsize_unit->content = maxUtils::selectify($fsize_unit->id, $units, $fsize_unit->value) ;
473 $fsize_unit->output('','end');
474
475 // width
476 $width = new maxField('number');
477 $width->id = 'mq_button_width[]';
478 $width->name = $width->id;
479 //$width->value = $fields['mq_button_width'];
480 $width->label = __('Button Width', 'maxbuttons');
481 $width->min = 0;
482 $width->inputclass = 'tiny';
483 $width->start_conditional = $show_conditional;
484 $width->output('start','');
485
486 $width_unit = new maxField('generic');
487 $width_unit->id = 'mq_button_width_unit[]';
488 $width_unit->name = $width_unit->id;
489 //$width_unit->value = $fields['mq_button_width_unit'];
490 $width_unit->content = maxUtils::selectify($width_unit->id, $units, $width_unit->value);
491 $width_unit->output('','');
492
493 // height
494 $height = new maxField('number');
495 $height->id = 'mq_button_height[]';
496 $height->name = $height->id;
497 //$height->value = $fields['mq_button_height'];
498 $height->label = __("Button Height", "maxbuttons");
499 $height->min = 0;
500 $height->inputclass = 'tiny';
501 $height->output('','');
502
503 $height_unit = new maxField('generic');
504 $height_unit->id = 'mq_button_height_unit[]';
505 $height_unit->name = $height_unit->id;
506 // $height_unit->value = $fields['mq_button_height_unit'];
507 $height_unit->content = maxUtils::selectify($height_unit->id, $units, $height_unit->value) ;
508 $height_unit->output('','end');
509
510 $cwidth = new maxField('number');
511 $cwidth->id = 'mq_container_width[]';
512 $cwidth->name = $cwidth->id;
513 $cwidth->label = __('Container Width', 'maxbuttons');
514 //$cwidth->value = $fields['mq_container_width'];
515 $cwidth->min = '1';
516 $cwidth->inputclass = 'tiny';
517 $cwidth->start_conditional = $show_conditional;
518 $cwidth->output('start', '');
519
520 $cwidth_unit = new maxField('generic');
521 $cwidth_unit->id = 'mq_container_width_unit[]';
522 $cwidth_unit->name = $cwidth_unit->id;
523 //$cwidth_unit->value = $fields['mq_container_width_unit'];
524 $cwidth_unit->content = maxUtils::selectify($cwidth_unit->id, $units, $cwidth_unit->value);
525 $cwidth_unit->output('','end');
526
527 $cfloat = new maxField('generic');
528 $cfloat->id = 'mq_container_float[]';
529 $cfloat->name = $cfloat->id;
530 $cfloat->label = __('Container Float','maxbuttons');
531 // $cfloat->value = $fields['mq_container_float'];
532 $cfloat->content = maxUtils::selectify($cfloat->id, $container_floats, $cfloat->value);
533 $cfloat->start_conditional = $show_conditional;
534 $cfloat->output('start','end');
535
536 if (! isset($fields['mq_hide']))
537 $fields['mq_hide'] = 0;
538
539 $hide = new maxField('switch');
540 $hide->id = 'mq_hide[]';
541 $hide->name = $hide->id;
542 $hide->value = 'none';
543 //$hide->checked = checked($fields['mq_hide'], $hide->value, false);
544 $hide->label = __('Hide button in this view','maxbuttons');
545 $hide->output('start','end');
546
547 /*$preview = new maxField('button');
548 $preview->id = 'mq_preview[]';
549 $preview->button_label = __('Show in preview','maxbuttons');
550 $preview->output('', 'end');
551 */
552 ?>
553 </div> <!-- /media-query -->
554
555 </div> <!-- /media-query-prot -->
556 <div id="media_desc">
557 <?php foreach($media_desc as $key => $desc)
558 {
559 echo "<span id='$key'>$desc</span>";
560
561 }
562 ?>
563 </div>
564
565
566 </div> <!-- container -->
567
568 <?php
569 }
570
571 } // class
572
573 ?>
574