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