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

377 lines 13.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 class responsiveBlock extends maxBlock
7 {
8 protected $blockname = 'responsive';
9 protected $fields = array("options" => '',
10 "auto_responsive" => array("default" => 0),
11 "media_query" => array("default" => array()
12 ),
13
14
15
16 );
17 // multifields for manual conversion // define +/- the same as normal fields.
18 // to find solution in parsing stuff back to button.
19 protected $multi_fields = array("mq_button_width" => array("default" => 0,
20 "css" => "width",
21 "csspseudo" => "responsive",
22
23 ),
24 "mq_button_width_unit" => array("default" => 'px',
25 "css" => "width_unit",
26 "csspseudo" => "responsive",
27 ),
28 "mq_container_width" => array("default" => 0,
29 "css" => "width",
30 "csspart" => "mb-container",
31 "csspseudo" => "responsive",
32 ),
33 "mq_container_float" => array("default" => "",
34 "css" => "float",
35 "csspart" => "mb-container",
36 "csspseudo" => "responsive",
37 ),
38 "mq_container_width_unit" => array("default" => "px",
39 "css" => "width_unit",
40 "csspart" => "mb-container",
41 ),
42 "mq_font_size" => array("default" => 90,
43 "css" => "font-size",
44 "csspart" => "mb-text",
45 ),
46 "mq_font_size_unit" => array("default" => "%",
47 "css" => "font-size_unit",
48 "csspart" => "mb-text"),
49
50 "mq_custom_minwidth" => array("default" => "0",
51 "css" => "custom_minwidth"),
52 "mq_custom_maxwidth" => array("default" => "0",
53 "css" => "custom_maxwidth"),
54 "mq_hide" => array("default" => '',
55 "css" => "display",
56 "csspart" => "mb-container, maxbutton, mb-center",
57
58 ),
59 );
60
61
62 public function parse_css($css, $mode = 'normal')
63 {
64 if ($mode != 'normal')
65 return $css;
66
67 if (! isset($this->data[$this->blockname]))
68 return $css;
69
70 $data = $this->data[$this->blockname];
71
72
73
74 if (isset($data["auto_responsive"]) && $data["auto_responsive"] == 1)
75 { // generate auto_rules for responsive.
76 $css["maxbutton"]["responsive"]["phone"][0]["width"] = "90%";
77 $css["mb-container"]["responsive"]["phone"][0]["width"] = "90%";
78 $css["mb-container"]["responsive"]["phone"][0]["float"] = "none";
79 $css["mb-text"]["responsive"]["phone"][0]["font-size"] = "90%";
80
81
82 if ( isset($this->data["text"]["font_size"]) )
83 {
84 $css["mb-text"]["responsive"]["phone"][0]["font-size"] = floor(intval($this->data["text"]["font_size"]) * 0.8) . 'px';
85 }
86
87 }
88
89 if (! isset($data["media_query"]))
90 return $css;
91
92 foreach($data["media_query"] as $query => $data ):
93 $i = 0;
94
95 foreach($data as $index => $fields):
96
97
98 foreach($fields as $field => $value)
99 {
100 $csspart = (isset($this->multi_fields[$field]["csspart"])) ? explode(",",$this->multi_fields[$field]["csspart"]) : array('maxbutton') ;
101 $css_stat = $this->multi_fields[$field]["css"];
102
103
104 if ($value == '' || $value == '0')
105 { }
106 elseif ($query != 'custom' && ($field == 'mq_custom_maxwidth' || $field == "mq_custom_minwidth"))
107 { } // skip custom fields on noncustom query
108 else
109 {
110 foreach($csspart as $j => $part)
111 {
112
113 $css[$part]["responsive"][$query][$i][$css_stat] = $value;
114 }
115
116 /* }
117 else
118 {
119
120 $css[$csspart]["responsive"][$query][$i][$css_stat] = $value;
121 } */
122 }
123
124 }
125 $i++;
126 endforeach;
127
128 endforeach;
129
130 return $css;
131 }
132
133
134 public function save_fields($data, $post)
135 {
136
137 $queries = (isset($post["media_query"])) ? $post["media_query"] : null;
138 $media_queries = array();
139
140 if (is_null($queries))
141 return $data;
142
143 foreach($queries as $i => $query)
144 {
145
146 if ($query != '')
147 {
148 //$media_queries[$query] = array();
149
150 // collect the other fields.
151 $c = isset($media_queries[$query]) ? count($media_queries[$query]) : 0;
152
153 foreach($this->multi_fields as $field => $values)
154 {
155 $default = isset($values["default"]) ? $values["default"] : '';
156
157 if (isset($post[$field][$i]))
158 {
159 $postval = $post[$field][$i];
160 if (is_numeric($default)) // sanitize.
161 {
162 $postval = intval($postval);
163 }
164 else
165 $value = sanitize_text_field($postval);
166
167 $media_queries[$query][$c][$field] = $postval;
168 }
169 }
170
171 }
172 }
173
174 $data[$this->blockname]["media_query"] = $media_queries;
175
176 $data[$this->blockname]["auto_responsive"] = (isset($post["auto_responsive"])) ? $post["auto_responsive"] : 0;
177
178 return $data;
179
180 }
181
182
183 public function admin_fields()
184 {
185 $data = isset($this->data[$this->blockname]) ? $this->data[$this->blockname] : array();
186
187 $media_names = maxUtils::get_media_query(1); // nicenames
188 $media_desc = maxUtils::get_media_query(3);
189 $units = array("px" => __("px","maxbuttons"),
190 "%" => __("%","maxbuttons")
191 );
192 $container_floats = array(
193 "" => "",
194 "none" => __("None","maxbuttons"),
195 "left" => __("Left","maxbuttons"),
196 "right" => __("Right","maxbuttons"),
197 );
198
199 foreach($this->fields as $field => $options)
200 {
201 $default = (isset($options["default"])) ? $options["default"] : '';
202 $$field = (isset($data[$field])) ? $data[$field] : $default;
203 ${$field . "_default"} = $default;
204 }
205
206 // sorting routine via array merge.
207 $fk = array_flip(array_keys($media_query));
208 $names_used = array_intersect_key($media_names,$fk);
209 $media_query = array_merge($names_used,$media_query);
210
211 ?>
212 <div class="mb_tab option-container">
213 <div class="title"><?php _e('Responsive Settings', 'maxbuttons') ?></div>
214 <div class="inside">
215
216 <div class="option-design">
217 <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>
218 <label for='auto_responsive'><?php _e("Auto Responsive", 'maxbuttons') ?> <?php _e("(Experimental)","maxbuttons") ?></label>
219
220 <div class="input checkbox">
221 <input type='checkbox' id='auto_responsive' name='auto_responsive' value='1' <?php checked(1, $auto_responsive); ?> >
222 </div>
223
224 <div class="clear"></div>
225 <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>
226 </div>
227
228
229 <div class='option-design media_queries_options'>
230 <?php
231 $i = 0 ;
232 foreach($media_query as $item => $data):
233 foreach ($data as $index => $fields):
234
235 ?>
236 <div class='media_query' data-query="<?php echo $item ?>">
237 <span class='removebutton'><img src="<?php echo MB()->get_plugin_url() ?>/assets/icons/remove.png"></span>
238
239 <input type="hidden" name="media_query[<?php echo $i ?>]" value="<?php echo $item ?>">
240 <label class='title'><?php echo $media_names[$item] ?></label>
241 <p class='description'><?php echo $media_desc[$item] ?></p>
242 <?php
243 if ($item == "custom") { $custom_class = ''; } else { $custom_class = 'hidden'; }
244
245 ?>
246 <div class="custom" <?php echo $custom_class ?> >
247 <div class="label"><?php _e("Min width","maxbuttons") ?></div>
248 <div class="input"><input type="text" class="tiny" name="mq_custom_minwidth[<?php echo $i ?>]" value="<?php echo $fields["mq_custom_minwidth"] ?>" />px</div>
249
250 <div class="label max"> <?php _e("Max width","maxbuttons"); ?></div>
251 <div class="input max"><input type="text" class="tiny" name="mq_custom_maxwidth[<?php echo $i ?>]" value="<?php echo $fields["mq_custom_maxwidth"] ?>" />px</div>
252
253
254 </div>
255
256 <div class='label'><?php _e("Font size","maxbuttons") ?></div>
257 <div class='input'><input type='text' name='mq_font_size[<?php echo $i ?>]' class='tiny' value="<?php echo $fields["mq_font_size"] ?>"> <?php echo maxUtils::selectify("mq_font_size_unit[$i]",$units,$fields["mq_font_size_unit"]) ?>
258 </div>
259
260 <div class='label'><?php _e("Button width", 'maxbuttons') ?></div>
261
262 <div class='input'><input type='text' name="mq_button_width[<?php echo $i ?>]" value="<?php echo $fields["mq_button_width"] ?>" class='tiny'> <?php echo maxUtils::selectify("mq_button_width_unit[$i]",$units,$fields["mq_button_width_unit"]) ?></div>
263
264 <div class='label'><?php _e("Container width", 'maxbuttons'); ?></div>
265
266 <div class='input'><input type='text' name="mq_container_width[<?php echo $i ?>]" value="<?php echo $fields["mq_container_width"] ?>" class='tiny'> <?php echo maxUtils::selectify("mq_container_width_unit[$i]",$units,$fields["mq_container_width_unit"]); ?>
267 </div>
268
269 <div class='label'><?php _e("Container float", "maxbuttons"); ?></div>
270 <div class="input"><?php echo maxUtils::selectify("mq_container_float[$i]",$container_floats, $fields["mq_container_float"]) ?></div>
271
272 <?php $mq_hide = (isset($fields["mq_hide"])) ? $fields["mq_hide"] : ''; ?>
273 <div class="label"><?php _e("Hide button on this view","maxbuttons"); ?></div>
274 <div class="input">
275
276 <input type="checkbox" name="mq_hide[<?php echo $i ?>]" value="none" <?php checked('none', $mq_hide ) ?> ></div>
277
278
279 </div>
280
281 <?php
282 $i++;
283 //if ($item != 'custom')
284 // unset($media_names[$item]); // remove existing queries from new query selection
285 endforeach;
286 endforeach;
287
288
289 ?>
290
291 <div class="new_query_space"></div>
292 <div class="clear"></div>
293 <div class="option-design new-query">
294 <label for='new_query'><?php _e('New Query', 'maxbuttons') ?></label>
295
296 <div class="input">
297 <select name="new_query" id="new_query">
298 <?php
299
300 foreach ($media_names as $key => $val):
301 $disabled = isset($media_query[$key]) && $key !== 'custom' ? ' DISABLED ' : '';
302 ?>
303 <option value="<?php echo $key ?>" <?php echo $disabled ?> ><?php echo $val ?></option>
304
305
306 <?php endforeach; ?>
307 </select>
308 <?php //echo maxUtils::selectify("new_query",$media_names,'' ); ?>
309 <a href='javascript:void(0)' class="button add_media_query"><?php _e("Add","maxbuttons") ?></a>
310 </div>
311
312
313 <div class="clear"></div>
314 </div>
315 </div>
316 </div> <!-- inside -->
317
318 <input type="hidden" name="next_media_index" value="<?php echo $i ?>" >
319 <div class='media_option_prot'>
320
321 <div class='media_query' data-query=''>
322 <span class='removebutton'><img src="<?php echo MB()->get_plugin_url() ?>assets/icons/remove.png"></span>
323
324 <input type="hidden" name="media_query[]" value="">
325 <label class='title'></label>
326 <p class='description'>Description here</p>
327
328 <div class="custom">
329 <div class="label"><?php _e("Min width","maxbuttons") ?></div>
330 <div class="input"><input type="text" class="tiny" name="mq_custom_minwidth[]" value="0" />px</div>
331
332 <div class="label max"> <?php _e("Max width","maxbuttons"); ?></div>
333 <div class="input max"><input type="text" class="tiny" name="mq_custom_maxwidth[]" value="0" />px</div>
334
335
336 </div>
337 <div class='label'><?php _e("Font size","maxbuttons") ?></div>
338 <div class='input'><input type='text' name='mq_font_size[]' class='tiny' value="90"> <?php echo maxUtils::selectify("mq_font_size_unit[]",$units,"%") ?>
339 </div>
340
341 <div class='label'><?php _e("Button width", "maxbuttons") ?></div>
342 <div class='input'><input type='text' name="mq_button_width[]" value="0" class='tiny'> <?php echo maxUtils::selectify("mq_button_width_unit[]",$units,""); ?></div>
343 <div class='label'><?php _e("Container width", "maxbuttons"); ?></div>
344 <div class='input'>
345 <input type='text' name="mq_container_width[]" value="0" class='tiny'> <?php echo maxUtils::selectify("mq_container_width_unit[]",$units,""); ?>
346 </div>
347
348 <div class='label'><?php _e("Container float", "maxbuttons"); ?></div>
349 <div class="input"><?php echo maxUtils::selectify("mq_container_float[]",$container_floats, "") ?></div>
350 <div class="label"><?php _e("Hide button on this view","maxbuttons"); ?></div>
351 <div class="input"><input type="checkbox" name="mq_hide[]" value="none">
352 </div>
353 `</div>
354
355 </div>
356 <div id="media_desc">
357 <?php foreach($media_desc as $key => $desc)
358 {
359 echo "<span id='$key'>$desc</span>";
360
361 }
362 ?>
363 </div>
364
365
366 </div> <!-- container -->
367
368
369
370
371 <?php
372 }
373
374 } // class
375
376 ?>
377