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