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

542 lines 18.8 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 <div class="mb_tab option-container">
221 <div class="title"><?php _e('Responsive Settings', 'maxbuttons') ?></div>
222 <div class="inside responsive">
223
224 <div class="option-design">
225 <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>
226 <?php
227 $auto = new maxField('switch');
228 $auto->label = __('Auto Responsive (experimental)', 'maxinbound');
229 $auto->name = 'auto_responsive';
230 $auto->id = $auto->name;
231 $auto->value = '1';
232 $auto->checked = checked($auto_responsive, 1, false);
233 $auto->output ('start','end');
234 ?>
235
236 <div class="clear"></div>
237 <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>
238 </div>
239
240
241 <div class="option-design new-query">
242 <label for='new_query'><?php _e('New Query', 'maxbuttons') ?></label>
243
244 <div class="input">
245 <select name="new_query" id="new_query">
246 <?php
247
248 foreach ($media_names as $key => $val):
249 $disabled = isset($media_query[$key]) && $key !== 'custom' ? ' DISABLED ' : '';
250 ?>
251 <option value="<?php echo $key ?>" <?php echo $disabled ?> ><?php echo $val ?></option>
252
253
254 <?php endforeach; ?>
255 </select>
256 <?php //echo maxUtils::selectify("new_query",$media_names,'' ); ?>
257 <a href='javascript:void(0)' class="button add_media_query"><?php _e("Add","maxbuttons") ?></a>
258 </div>
259
260
261 <div class="clear"></div>
262 </div> <!-- option design -->
263
264 <div class='option-design media_queries_options'>
265 <?php
266 $i = 0 ;
267 foreach($media_query as $item => $data):
268 foreach ($data as $index => $fields):
269
270 if (! isset($fields['mq_hide']))
271 $fields['mq_hide'] = 0;
272
273 $condition = array('target' => 'mq_hide[' . $i . ']', 'values' => 'checked');
274 $show_conditional = htmlentities(json_encode($condition));
275
276 ?>
277 <div class='media_query' data-query="<?php echo $item ?>">
278 <span class='removebutton dashicons dashicons-no'></span>
279
280 <input type="hidden" name="media_query[<?php echo $i ?>]" value="<?php echo $item ?>">
281 <label class='title'><?php echo $media_names[$item] ?></label>
282 <p class='description'><?php echo $media_desc[$item] ?></p>
283 <?php
284 if ($item == "custom") { $custom_class = ''; } else { $custom_class = ' hidden '; }
285
286 $min_width = new maxField('number');
287 $min_width->id = 'mq_custom_minwidth[' . $i . ']';
288 $min_width->name= $min_width->id;
289 $min_width->label = __('Min Width', 'maxbuttons');
290 $min_width->value = $fields['mq_custom_minwidth'];
291 $min_width->inputclass = 'small' . $custom_class;
292 $min_width->main_class = $custom_class; // hide label
293 $min_width->output('start', '');
294
295 $max_width = new maxField('number');
296 $max_width->id = 'mq_custom_maxwidth[' . $i . ']';
297 $max_width->name = $max_width->id;
298 $max_width->label = __('Max Width','maxbuttons');
299 $max_width->value = $fields['mq_custom_maxwidth'];
300 $max_width->inputclass = 'small' . $custom_class;
301 $max_width->mainclass = $custom_class;
302 $max_width->output('','end');
303
304
305 $font_size = new maxField('number');
306 $font_size->id = 'mq_font_size[' . $i . ']';
307 $font_size->name = $font_size->id;
308 $font_size->value = $fields['mq_font_size'];
309 $font_size->label = __('Font Size', 'maxbuttons');
310 $font_size->min = 0;
311 $font_size->inputclass = 'tiny';
312 // $font_size->conditional = $show_conditional;
313 $font_size->output('start', '');
314
315 $fsize_unit = new maxField('generic');
316 $fsize_unit->id = 'mq_font_size_unit[' . $i . ']';
317 $fsize_unit->name = $fsize_unit->id;
318 $fsize_unit->value = $fields['mq_font_size_unit'];
319 $fsize_unit->content = maxUtils::selectify($fsize_unit->id, $units, $fsize_unit->value);
320 // $fsize_unit->conditional = $show_conditional;
321 $fsize_unit->output('','end');
322
323 // width
324 $width = new maxField('number');
325 $width->id = 'mq_button_width[' . $i . ']';
326 $width->name = $width->id;
327 $width->value = $fields['mq_button_width'];
328 $width->label = __('Button Width', 'maxbuttons');
329 $width->min = 0;
330 $width->inputclass = 'tiny';
331 // $width->conditional = $show_conditional;
332 $width->output('start','');
333
334 $width_unit = new maxField('generic');
335 $width_unit->id = 'mq_button_width_unit[' . $i . ']';
336 $width_unit->name = $width_unit->id;
337 $width_unit->value = $fields['mq_button_width_unit'];
338 $width_unit->content = maxUtils::selectify($width_unit->id, $units, $width_unit->value);
339 // $width_unit->conditional = $show_conditional;
340 $width_unit->output('','');
341
342 // height
343 $height = new maxField('number');
344 $height->id = 'mq_button_height[' . $i . ']';
345 $height->name = $height->id;
346 $height->value = $fields['mq_button_height'];
347 $height->label = __("Button Height", "maxbuttons");
348 $height->min = 0;
349 $height->inputclass = 'tiny';
350 // $height->conditional = $show_conditional;
351 $height->output('','');
352
353 $height_unit = new maxField('generic');
354 $height_unit->id = 'mq_button_height_unit[' . $i . ']';
355 $height_unit->name = $height_unit->id;
356 $height_unit->value = $fields['mq_button_height_unit'];
357 $height_unit->content = maxUtils::selectify($height_unit->id, $units, $height_unit->value);
358 // $height_unit->conditional = $show_conditional;
359 $height_unit->output('','end');
360
361 $cwidth = new maxField('number');
362 $cwidth->id = 'mq_container_width[' . $i . ']';
363 $cwidth->name = $cwidth->id;
364 $cwidth->label = __('Container Width', 'maxbuttons');
365 $cwidth->value = $fields['mq_container_width'];
366 $cwidth->min = '0';
367 $cwidth->inputclass = 'tiny';
368 // $cwidth->conditional = $show_conditional;
369 $cwidth->output('start', '');
370
371 $cwidth_unit = new maxField('generic');
372 $cwidth_unit->id = 'mq_container_width_unit[' . $i . ']';
373 $cwidth_unit->name = $cwidth_unit->id;
374 $cwidth_unit->value = $fields['mq_container_width_unit'];
375 $cwidth_unit->content = maxUtils::selectify($cwidth_unit->id, $units, $cwidth_unit->value);
376 // $cwidth_unit->conditional = $show_conditional;
377 $cwidth_unit->output('','end');
378
379 $cfloat = new maxField('generic');
380 $cfloat->id = 'mq_container_float[' . $i . ']';
381 $cfloat->name = $cfloat->id;
382 $cfloat->label = __('Container Float','maxbuttons');
383 $cfloat->value = $fields['mq_container_float'];
384 $cfloat->content = maxUtils::selectify($cfloat->id, $container_floats, $cfloat->value);
385 // $cfloat->conditional = $show_conditional;
386 $cfloat->output('start','end');
387
388 $hide = new maxField('switch');
389 $hide->id = 'mq_hide[' . $i . ']';
390 $hide->name = $hide->id;
391 $hide->value = 'none';
392 $hide->checked = checked($fields['mq_hide'], $hide->value, false);
393 $hide->label = __('Hide button in this view','maxbuttons');
394 $hide->output('start','end');
395
396 $i++;
397 //if ($item != 'custom')
398 // unset($media_names[$item]); // remove existing queries from new query selection
399 ?>
400 </div> <!-- media query -->
401 <?php
402 endforeach;
403 endforeach;
404
405
406 ?>
407 </div> <!-- option -design -->
408 <div class="new_query_space"></div>
409 </div> <!-- inside -->
410
411 <input type="hidden" name="next_media_index" value="<?php echo $i ?>" >
412 <div class='media_option_prot'>
413
414 <div class='media_query' data-query=''>
415 <span class='removebutton dashicons dashicons-no'></span>
416
417 <input type="hidden" name="media_query[]" value="">
418 <label class='title'></label>
419 <p class='description'>&nbsp;</p>
420
421 <div class="custom">
422 <div class="label"><?php _e("Min width","maxbuttons") ?></div>
423 <div class="input"><input type="text" class="tiny" name="mq_custom_minwidth[]" value="0" />px</div>
424
425 <div class="label max"> <?php _e("Max width","maxbuttons"); ?></div>
426 <div class="input max"><input type="text" class="tiny" name="mq_custom_maxwidth[]" value="0" />px</div>
427
428
429 </div>
430
431
432 <?php
433 $font_size = new maxField('number');
434 $font_size->id = 'mq_font_size[' . $i . ']';
435 $font_size->name = $font_size->id;
436 //$font_size->value = $fields['mq_font_size'];
437 $font_size->label = __('Font Size', 'maxbuttons');
438 $font_size->min = 0;
439 $font_size->inputclass = 'tiny';
440 $font_size->output('start', '');
441
442 $fsize_unit = new maxField('generic');
443 $fsize_unit->id = 'mq_font_size_unit[' . $i . ']';
444 $fsize_unit->name = $fsize_unit->id;
445 //$fsize_unit->value = $fields['mq_font_size_unit'];
446 $fsize_unit->content = maxUtils::selectify($fsize_unit->id, $units, $fsize_unit->value) ;
447 $fsize_unit->output('','end');
448
449 // width
450 $width = new maxField('number');
451 $width->id = 'mq_button_width[' . $i . ']';
452 $width->name = $width->id;
453 //$width->value = $fields['mq_button_width'];
454 $width->label = __('Button Width', 'maxbuttons');
455 $width->min = 0;
456 $width->inputclass = 'tiny';
457 $width->output('start','');
458
459 $width_unit = new maxField('generic');
460 $width_unit->id = 'mq_button_width_unit[' . $i . ']';
461 $width_unit->name = $width_unit->id;
462 //$width_unit->value = $fields['mq_button_width_unit'];
463 $width_unit->content = maxUtils::selectify($width_unit->id, $units, $width_unit->value);
464 $width_unit->output('','');
465
466 // height
467 $height = new maxField('number');
468 $height->id = 'mq_button_height[' . $i . ']';
469 $height->name = $height->id;
470 //$height->value = $fields['mq_button_height'];
471 $height->label = __("Button Height", "maxbuttons");
472 $height->min = 0;
473 $height->inputclass = 'tiny';
474 $height->output('','');
475
476 $height_unit = new maxField('generic');
477 $height_unit->id = 'mq_button_height_unit[' . $i . ']';
478 $height_unit->name = $height_unit->id;
479 $height_unit->value = $fields['mq_button_height_unit'];
480 $height_unit->content = maxUtils::selectify($height_unit->id, $units, $height_unit->value) ;
481 $height_unit->output('','end');
482
483 $cwidth = new maxField('number');
484 $cwidth->id = 'mq_container_width[' . $i . ']';
485 $cwidth->name = $cwidth->id;
486 $cwidth->label = __('Container Width', 'maxbuttons');
487 //$cwidth->value = $fields['mq_container_width'];
488 $cwidth->min = '1';
489 $cwidth->inputclass = 'tiny';
490 $cwidth->output('start', '');
491
492 $cwidth_unit = new maxField('generic');
493 $cwidth_unit->id = 'mq_container_width_unit[' . $i . ']';
494 $cwidth_unit->name = $cwidth_unit->id;
495 //$cwidth_unit->value = $fields['mq_container_width_unit'];
496 $cwidth_unit->content = maxUtils::selectify($cwidth_unit->id, $units, $cwidth_unit->value);
497 $cwidth_unit->output('','end');
498
499 $cfloat = new maxField('generic');
500 $cfloat->id = 'mq_container_float[' . $i . ']';
501 $cfloat->name = $cfloat->id;
502 $cfloat->label = __('Container Float','maxbuttons');
503 // $cfloat->value = $fields['mq_container_float'];
504 $cfloat->content = maxUtils::selectify($cfloat->id, $container_floats, $cfloat->value);
505 $cfloat->output('start','end');
506
507 if (! isset($fields['mq_hide']))
508 $fields['mq_hide'] = 0;
509
510 $hide = new maxField('switch');
511 $hide->id = 'mq_hide[' . $i . ']';
512 $hide->name = $hide->id;
513 $hide->value = 'none';
514 //$hide->checked = checked($fields['mq_hide'], $hide->value, false);
515 $hide->label = __('Hide button in this view','maxbuttons');
516 $hide->output('start','end');
517 ?>
518 </div>
519
520 </div>
521 <div id="media_desc">
522 <?php foreach($media_desc as $key => $desc)
523 {
524 echo "<span id='$key'>$desc</span>";
525
526 }
527 ?>
528 </div>
529
530
531 </div> <!-- container -->
532
533
534
535
536 <?php
537 }
538
539 } // class
540
541 ?>
542