PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
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 / collections / layout-block.php

layout-block.php in MaxButtons – Create buttons 6.28, at collections/layout-block.php

349 lines 11.4 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 $collectionBlock["layout"] = "layoutCollectionBlock";
5
6 class layoutCollectionBlock extends collectionBlock
7 {
8 protected $blockname = "layout";
9 protected $fields = array(
10 "margin_left" => array("default" => "0px",
11 "css" => "margin-left",
12 "csspart" => "maxcollection"),
13
14 "margin_right" => array("default" => "0px",
15 "css" => "margin-right",
16 "csspart" => "maxcollection"),
17
18 "margin_top" => array("default" => "0px",
19 "css" => "margin-top",
20 "csspart" => "maxcollection"),
21
22 "margin_bottom" => array("default" => "0px",
23 "css" => "margin-bottom",
24 "csspart" => "maxcollection"),
25 "orientation" => array("default" => "auto"),
26
27 "item_margin_right" => array("default" => "0px",
28 "css" => "margin-right",
29 "csspart" => "mb-collection-item",
30 ),
31 "item_margin_bottom" => array("default" => "0px",
32 "css" => "margin-bottom",
33 "csspart" => "mb-collection-item",
34 ),
35 "ignore_container" => array("default" => 1),
36 "static_position_ver" => array("default" => "Auto",
37 ),
38 "static_position_hor" => array("default" => "Auto",
39 ),
40
41 );
42 public function map_fields($map)
43 {
44 $map = parent::map_fields($map);
45 $map["orientation"]["func"] = "updatePlacement";
46
47 return $map;
48 }
49
50 function parseButtons($buttons)
51 {
52 // searches the cache for the container statement ending with -container or -center and tries to remove then
53 // not very optimal code, but this is a way to maintain cache loading while altering css.
54
55 if ($this->data["ignore_container"] == 0)
56 return $buttons; // ignore container off .
57
58 foreach($buttons as $button)
59 {
60 $cache = $button->getCache();
61
62 // chops all css statements in a different line
63 preg_match_all('/([^{]+)\s*\{\s*([^}]+)\s*}/i',$cache, $matches);
64 foreach($matches[0] as $cssline)
65 {
66 // tries to find the last part of the statement from - to {
67 preg_match_all('/.([^-])*{/i', $cssline, $item);
68
69 $item = trim(str_replace("{","",$item[0][0]));
70 if ($item == '-center' || $item == '-container')
71 {
72 $cache = str_replace($cssline,'',$cache);
73 }
74
75
76 }
77
78 //([^{]+)\s*\{\s*([^}]+)\s*} { split }
79 // match last thing .([^-])*{
80 $button->setCache($cache);
81
82 $data = $button->get();
83
84 $container = isset($data["container"]) ? $data["container"] : array();
85 foreach($container as $key => $value)
86 {
87 if ($key != 'container_enabled' && $key != 'container_center_div_wrap') // causes container to be removed otherwise
88 $container[$key] = '';
89 }
90
91 $button->setdata("container", $container);
92 }
93 return $buttons;
94
95 }
96
97 function parseCSS($css, $args)
98 {
99 $css = parent::parseCSS($css, $args);
100
101
102 $css["mb-collection-item"]["normal"]["float"] = "left";
103 $css["mb-collection-item"]["normal"]["display"] = "inline-block";
104 $css["mb-collection-item a"]["normal"]["cursor"] = "pointer"; // by default social share = call to action.
105
106 //$button_spacing = $this->data["button_spacing"];
107 $orientation = $this->data["orientation"];
108
109 $static_position_ver = $this->data["static_position_ver"];
110 $static_position_hor = $this->data["static_position_hor"];
111
112 $basic = $this->collection->getBlock("basic");
113 $picker_data = $basic->get();
114 $placement = $picker_data["placement"];
115
116
117 if ($orientation == 'auto')
118 {
119 // $basic = $this->collection->getBlock("basic");
120
121 switch($placement) // auto align on basis of placement on screen
122 {
123 case "static-left": // vertical items
124 case "static-right":
125 $orientation = "vertical";
126 break;
127 case "static-top": // horizontal
128 case "static-bottom":
129 default:
130 $orientation = "horizontal";
131 break;
132 }
133 }
134
135 switch($orientation)
136 {
137 case "horizontal":
138 //$css["mb_collection_item"]["normal"]["float"]
139 // todo
140 //$css["mb-collection-item"]["normal"]["margin-right"] = $button_spacing . "px";
141 //$css["mb-collection-item:last-child"]["normal"]["margin-right"] = "0";
142 break;
143
144 case "vertical";
145 $css["mb-collection-item"]["normal"]["clear"] = "both";
146 //if ($button_spacing > 0)
147 //{
148 //unset($css["mb-collection-item"]["normal"]["margin-right"]) ;
149 //$css["mb-collection-item"]["normal"]["clear"] = "left";
150 //$css["mb-collection-item"]["normal"]["margin-bottom"] = $button_spacing . "px";
151
152 //}
153 break;
154
155 }
156
157 if ($args["preview"] == true)
158 return $css; // don't process move than this in preview.
159
160 switch($placement)
161 {
162 case "static-left":
163 case "static-right":
164 switch($static_position_ver)
165 {
166 case "auto":
167 case "center":
168 $css["maxcollection"]["normal"]["top"] = "50%";
169 $css["maxcollection"]["normal"]["transform"] = "translateY(-50%)";
170 break;
171 case "top":
172 // nothing
173 break;
174 case "bottom":
175 unset($css["maxcollection"]["normal"]["top"]);
176 $css["maxcollection"]["normal"]["bottom"] = "0";
177 break;
178 }
179
180 break;
181
182 case "static-top":
183 case "static-bottom":
184 switch($static_position_hor)
185 {
186 case "auto":
187 case "center":
188 $css["maxcollection"]["normal"]["left"] = "50%";
189 $css["maxcollection"]["normal"]["transform"] = "translateX(-50%)";
190 break;
191 case "left":
192
193 break;
194 case "right":
195 unset($css["maxcollection"]["normal"]["left"]);
196 $css["maxcollection"]["normal"]["right"] = "0";
197 break;
198
199 }
200 break;
201
202 }
203
204 return $css;
205
206 }
207
208 function save_fields($data, $post)
209 {
210 $data = parent::save_fields($data, $post);
211 if (! isset($post["ignore_container"]))
212 $data[$this->blockname]["ignore_container"] = 0;
213
214 return $data;
215
216 }
217
218 function admin_fields()
219 {
220 extract($this->data);
221
222 $orientation_array = array(
223 "auto" => __("Auto","maxbuttons"),
224 "horizontal" => __("Horizontal","maxbuttons"),
225 "vertical" => __("Vertical","maxbuttons")
226 );
227
228 $staticposver = array(
229 "auto" => __("Auto","maxbuttons"),
230 "center" => __("Center","maxbuttons"),
231 "top" => __("Top", "maxbuttons"),
232 "bottom" => __("Bottom", "maxbuttons"),
233 );
234 $staticposhor = array(
235 "auto" => __("Auto","maxbuttons"),
236 "center" => __("Center","maxbutton-pro"),
237 "left" => __("Left","maxbuttons"),
238 "right" => __("Right","maxbuttons"),
239 );
240
241
242
243 $px = __("px","maxbuttons");
244 ?><div class="mb_tab option-container layout-block" data-options="layout">
245 <div class="title">
246 <span class="dashicons dashicons-admin-appearance"></span>
247 <span class="title"><?php _e("Layout","maxbuttons"); ?></span>
248 <span class='manual-box'><a class='manual-toggle' href='javascript:void(0)' data-target="layout"> <?php _e("Getting Started","maxbuttons-pro"); ?> </a></span>
249 <span class='right'><button name="save" type="submit" data-form='collection_edit' class="button button-primary"><?php _e("Save All","maxbuttons"); ?></button>
250 </span>
251 </div>
252
253 <div class="inside">
254 <div class="option">
255 <label for="margin-left"><?php _e("Margin left","maxbuttons"); ?></label>
256 <input type="number" class="tiny" id="margin_left" name="margin_left" value="<?php echo intval($margin_left) ?>" class="tiny"> <?php echo $px; ?>
257 </div>
258
259 <div class="option">
260 <label for="margin-right"><?php _e("Margin right","maxbuttons"); ?></label>
261 <input type="number" name="margin_right" id="margin_right" value="<?php echo intval($margin_right) ?>" class="tiny"> <?php echo $px; ?>
262 </div>
263
264 <div class="option">
265 <label for="margin-top"><?php _e("Margin bottom","maxbuttons"); ?></label>
266 <input type="number" name="margin_bottom" id="margin_bottom" value="<?php echo maxUtils::strip_px($margin_top) ?>" class="tiny"> <?php echo $px; ?>
267 </div>
268
269 <div class="option">
270 <label for="margin-bottom"><?php _e("Margin top","maxbuttons"); ?></label>
271 <input type="number" name="margin_top" id="margin_top" value="<?php echo maxUtils::strip_px($margin_bottom) ?>" class="tiny"> <?php echo $px; ?>
272 </div>
273
274 <div class="option">
275 <label for="orientation"><?php _e("Orientation","maxbuttons"); ?></label>
276 <?php echo maxUtils::selectify("orientation", $orientation_array, $orientation); ?>
277 </div>
278
279 <div class="option">
280 <label for="item_margin_right"><?php _e("Item margin right","maxbuttons"); ?></label>
281 <input type="number" class="tiny" name="item_margin_right" id="item_margin_right" value="<?php echo maxUtils::strip_px($item_margin_right) ?>"> <?php echo $px; ?>
282 </div>
283
284 <div class="option">
285 <label for="item_margin_bottom"><?php _e("Item margin bottom","maxbuttons"); ?></label>
286 <input type="number" class="tiny" name="item_margin_bottom" id="item_margin_bottom" value="<?php echo maxUtils::strip_px($item_margin_bottom) ?>">
287 <?php echo $px ?>
288
289 </div>
290
291 <div class="option">
292 <label for="ignore_container"><?php _e("Remove container width and margins","maxbuttons"); ?></label>
293 <input type="checkbox" name="ignore_container" value="1" <?php checked($ignore_container,1) ?>>
294 <div class="help fa fa-question-circle ">
295 <span><?php _e("Removes the margins and widths of the button container.", "maxbuttons"); ?>
296 </span>
297 </div>
298
299 </div>
300 </div>
301
302 <?php
303 $condition = array("target" => "placement", "values" => array("static-left","static-right","static-top", "static-bottom")) ;
304 $static_conditional = htmlentities(json_encode($condition ));
305 ?>
306 <br>
307 <div class='conditional-option option-container' data-show="<?php echo $static_conditional ?>">
308 <div class="title"> <?php _e("Static positioning","maxbuttons"); ?></div>
309 <div class="inside">
310 <?php
311 $condition = array("target" => "placement", "values" => array("static-left","static-right")) ;
312 $static_conditional = htmlentities(json_encode($condition ));
313 ?>
314 <div class="option conditional-option" data-show="<?php echo $static_conditional ?>">
315 <label for="static_position_ver"><?php _e("Static position vertical","maxbuttons"); ?></label>
316 <?php echo maxUtils::selectify("static_position_ver", $staticposver,$static_position_ver); ?>
317
318 </div>
319 <?php
320 $condition = array("target" => "placement", "values" => array("static-top", "static-bottom")) ;
321 $static_conditional = htmlentities(json_encode($condition ));
322 ?>
323 <div class="option conditional-option" data-show="<?php echo $static_conditional ?>">
324 <label for="static_position_hor"><?php _e("Static position horizontal","maxbuttons"); ?></label>
325 <?php echo maxUtils::selectify("static_position_hor", $staticposhor,$static_position_hor); ?>
326
327 </div>
328 </div>
329 </div>
330 <!-- manual entry -->
331 <div class="manual-entry" data-manual="layout">
332 <h3><?php _e("Layout settings", "maxbuttons"); ?>
333 <span class="dashicons dashicons-no window close manual-toggle" data-target="layout"></span>
334 </h3>
335
336 <p><?php _e("The first 4 options - margins left, right, buttom and top - are for positioning the entire collection. Click the Preview tab on so you can see the changes to your collection as you make them. The Orientation options let’s you choose between Auto, Horizontal and Vertical. Image margin allows you to set the spacing between the icons.","maxbuttons"); ?></p>
337
338 </div>
339 </div> <!-- tab -->
340
341 <?php
342
343
344 }
345
346 }
347
348 ?>
349