| 1 |
<?php |
| 2 |
defined('ABSPATH') or die('No direct access permitted'); |
| 3 |
$blockClass["container"] = "containerBlock"; |
| 4 |
$blockOrder[70][] = "container"; |
| 5 |
|
| 6 |
use MaxButtons\maxBlocks as maxBlocks; |
| 7 |
use MaxButtons\maxField as maxField; |
| 8 |
|
| 9 |
class containerBlock extends maxBlock |
| 10 |
{ |
| 11 |
protected $blockname = "container"; |
| 12 |
protected $fields = array("container_enabled" => array("default" => "0"), |
| 13 |
"container_center_div_wrap" => array("default" => "0"), |
| 14 |
|
| 15 |
"container_width" => array("default" => "0px", |
| 16 |
"css" => "width", |
| 17 |
"csspart" => "mb-container"), |
| 18 |
"container_margin_top" => array("default" => "0px", |
| 19 |
"css" => "margin-top", |
| 20 |
"csspart" => "mb-container"), |
| 21 |
"container_margin_right" => array("default" => "0px", |
| 22 |
"css" => "margin-right", |
| 23 |
"csspart" => "mb-container"), |
| 24 |
"container_margin_bottom" => array("default" => "0px", |
| 25 |
"css" => "margin-bottom", |
| 26 |
"csspart" => "mb-container"), |
| 27 |
"container_margin_left" => array("default" => "0px", |
| 28 |
"css" => "margin-left", |
| 29 |
"csspart" => "mb-container"), |
| 30 |
"container_alignment" => array("default" => "", |
| 31 |
"css" => "align", |
| 32 |
"csspart" => "mb-container"), |
| 33 |
); |
| 34 |
|
| 35 |
|
| 36 |
public function parse_button($domObj, $mode = 'normal') |
| 37 |
{ |
| 38 |
$data = $this->data[$this->blockname]; |
| 39 |
$id = $this->data["id"]; |
| 40 |
|
| 41 |
if ($mode == 'editor') |
| 42 |
return $domObj; // in previews no container object |
| 43 |
|
| 44 |
|
| 45 |
if ($data["container_enabled"] == 1) |
| 46 |
{ |
| 47 |
$anchor = $domObj->find("a",0); |
| 48 |
$anchor->outertext = "<span class='maxbutton-" . $id . "-container mb-container'>" . $anchor->outertext . "</span>"; |
| 49 |
|
| 50 |
|
| 51 |
if ($data["container_center_div_wrap"] == 1) // I heard you like wrapping... |
| 52 |
{ |
| 53 |
$anchor->outertext = "<span class='mb-center maxbutton-" . $id . "-center'>" . $anchor->outertext . "</span>"; |
| 54 |
|
| 55 |
} |
| 56 |
// reload the dom model with new divs |
| 57 |
$newhtml = $domObj->save(); |
| 58 |
$domObj = new simple_html_dom(); |
| 59 |
$domObj->load($newhtml); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
return $domObj; |
| 65 |
} |
| 66 |
|
| 67 |
public function parse_css($css, $mode = 'normal') |
| 68 |
{ |
| 69 |
$css = parent::parse_css($css); |
| 70 |
$data = $this->data[$this->blockname]; |
| 71 |
|
| 72 |
$csspart = 'mb-container'; |
| 73 |
$csspseudo = 'normal'; |
| 74 |
|
| 75 |
$css["mb-container"]["normal"]["display"] = "block"; |
| 76 |
$css["mb-center"]["normal"]["display"] = "block"; |
| 77 |
$css["mb-center"]["normal"]["text-align"] = "center"; |
| 78 |
|
| 79 |
if (isset($css[$csspart][$csspseudo]["align"])) |
| 80 |
{ |
| 81 |
|
| 82 |
if ($css[$csspart][$csspseudo]["align"] != '') |
| 83 |
{ |
| 84 |
|
| 85 |
$stat = explode(":", $css[$csspart][$csspseudo]["align"]); |
| 86 |
$css[$csspart][$csspseudo][ $stat[0] ] = $stat[1]; |
| 87 |
} |
| 88 |
unset($css[$csspart][$csspseudo]["align"]); |
| 89 |
} |
| 90 |
if ( isset($css[$csspart][$csspseudo]["width"]) && $data["container_width"] == 0) |
| 91 |
{ |
| 92 |
unset($css[$csspart][$csspseudo]["width"]); |
| 93 |
} |
| 94 |
return $css; |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public function admin_fields() |
| 101 |
{ |
| 102 |
$data = $this->data[$this->blockname]; |
| 103 |
foreach($this->fields as $field => $options) |
| 104 |
{ |
| 105 |
$default = (isset($options["default"])) ? $options["default"] : ''; |
| 106 |
$$field = (isset($data[$field])) ? $data[$field] : $default; |
| 107 |
${$field . "_default"} = $default; |
| 108 |
|
| 109 |
|
| 110 |
} |
| 111 |
$maxbuttons_container_alignments = array( |
| 112 |
'' => '', |
| 113 |
'display: inline-block' => 'display: inline-block', |
| 114 |
'float: left' => 'float: left', |
| 115 |
'float: right' => 'float: right' |
| 116 |
); |
| 117 |
|
| 118 |
$icon_url = MB()->get_plugin_url() . 'images/icons/' ; |
| 119 |
|
| 120 |
?> |
| 121 |
<div class="option-container mb_tab"> |
| 122 |
<div class="title"><?php _e('Container', 'maxbuttons') ?></div> |
| 123 |
<div class="inside"> |
| 124 |
<?php |
| 125 |
$fspacer = new maxField('spacer'); |
| 126 |
$fspacer->label = __('Use Container', 'maxbuttons'); |
| 127 |
$fspacer->name = ''; |
| 128 |
$fspacer->output('start'); |
| 129 |
|
| 130 |
$u_container = new maxField('checkbox'); |
| 131 |
//$u_container->label = __('Use Container', 'maxbuttons'); |
| 132 |
$u_container->name = 'container_enabled'; |
| 133 |
$u_container->id = $u_container->name; |
| 134 |
$u_container->value = 1; |
| 135 |
$u_container->checked = checked( maxBlocks::getValue('container_enabled'), 1, false); |
| 136 |
$u_container->output(false, 'end'); |
| 137 |
|
| 138 |
$fspacer = new maxField('spacer'); |
| 139 |
$fspacer->label = __('Center the container', 'maxbuttons'); |
| 140 |
$fspacer->name = ''; |
| 141 |
$fspacer->output('start'); |
| 142 |
|
| 143 |
$wrap_cont = new maxField('checkbox'); |
| 144 |
$wrap_cont->name = 'container_center_div_wrap'; |
| 145 |
$wrap_cont->id = $wrap_cont->name; |
| 146 |
$wrap_cont->value = 1; |
| 147 |
$wrap_cont->checked = checked( maxBlocks::getValue('container_center_div_wrap'), 1, false); |
| 148 |
$wrap_cont->output('','end'); |
| 149 |
|
| 150 |
$container_width = new maxField('number'); |
| 151 |
$container_width->name = 'container_width'; |
| 152 |
$container_width->id = $container_width->name; |
| 153 |
$container_width->min = 0; |
| 154 |
$container_width->value = maxUtils::strip_px( maxBlocks::getValue('container_width') ); |
| 155 |
$container_width->label = __('Width', 'maxbuttons'); |
| 156 |
$container_width->inputclass = 'small'; |
| 157 |
$container_width->output('start','end'); |
| 158 |
|
| 159 |
// Margin - trouble |
| 160 |
$ptop = new maxField('number'); |
| 161 |
$ptop->label = __('Margin', 'maxbuttons'); |
| 162 |
$ptop->id = 'container_margin_top'; |
| 163 |
$ptop->name = $ptop->id; |
| 164 |
$ptop->min = 0; |
| 165 |
$ptop->inputclass = 'tiny'; |
| 166 |
$ptop->before_input = '<img src="' . $icon_url . 'p_top.png" title="' . __("Margin Top","maxbuttons") . '" >'; |
| 167 |
$ptop->value = maxUtils::strip_px(maxBlocks::getValue('container_margin_top')); |
| 168 |
|
| 169 |
$ptop->output('start'); |
| 170 |
|
| 171 |
|
| 172 |
$pright = new maxField('number'); |
| 173 |
$pright->id = 'container_margin_right'; |
| 174 |
$pright->name = $pright->id; |
| 175 |
$pright->min = 0; |
| 176 |
$pright->inputclass = 'tiny'; |
| 177 |
$pright->before_input = '<img src="' . $icon_url . 'p_right.png" class="icon padding" title="' . __("Margin Right","maxbuttons") . '" >'; |
| 178 |
$pright->value = maxUtils::strip_px(maxBlocks::getValue('container_margin_right')); |
| 179 |
|
| 180 |
$pright->output(); |
| 181 |
|
| 182 |
$pbottom = new maxField('number'); |
| 183 |
$pbottom->id = 'container_margin_bottom'; |
| 184 |
$pbottom->name = $pbottom->id; |
| 185 |
$pbottom->min = 0; |
| 186 |
$pbottom->inputclass = 'tiny'; |
| 187 |
$pbottom->before_input = '<img src="' . $icon_url . 'p_bottom.png" class="icon padding" title="' . __("Margin Bottom","maxbuttons") . '" >'; |
| 188 |
$pbottom->value = maxUtils::strip_px(maxBlocks::getValue('container_margin_bottom')); |
| 189 |
|
| 190 |
$pbottom->output(); |
| 191 |
|
| 192 |
$pleft = new maxField('number'); |
| 193 |
$pleft->id = 'container_margin_left'; |
| 194 |
$pleft->name = $pleft->id; |
| 195 |
$pleft->min = 0; |
| 196 |
$pleft->inputclass = 'tiny'; |
| 197 |
$pleft->before_input = '<img src="' . $icon_url . 'p_left.png" class="icon padding" title="' . __("Margin Left","maxbuttons") . '" >'; |
| 198 |
$pleft->value = maxUtils::strip_px(maxBlocks::getValue('container_margin_left')); |
| 199 |
|
| 200 |
$pleft->output('','end'); |
| 201 |
|
| 202 |
|
| 203 |
$align = new maxField('generic'); |
| 204 |
$align->label = __('Alignment','maxbuttons'); |
| 205 |
$align->name = 'container_alignment'; |
| 206 |
$align->id = $align->name; |
| 207 |
$align->value= maxBlocks::getValue('container_alignment'); |
| 208 |
//$align->setDefault(maxBlocks::getDefault('container_alignment')); |
| 209 |
$align->content = maxUtils::selectify($align->name, $maxbuttons_container_alignments, $align->value); |
| 210 |
$align->output('start', 'end'); |
| 211 |
?> |
| 212 |
|
| 213 |
</div> |
| 214 |
</div> |
| 215 |
<?php |
| 216 |
} // admin_fields |
| 217 |
|
| 218 |
} // class |
| 219 |
|
| 220 |
|
| 221 |
?> |
| 222 |
|