PluginProbe
MaxButtons – Create buttons / 7.1
MaxButtons – Create buttons v7.1
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 7.1, at blocks/responsive.php

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