PluginProbe
Social Share Buttons / 0.9
Social Share Buttons v0.9
trunk 0.9 1.0 1.1 1.1.1 1.1.2 1.10 1.11 1.12 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.3 1.30 1.4 1.5 1.6 1.7 1.8 1.9
share-button / classes / blocks / layout-block.php

layout-block.php in Social Share Buttons 0.9, at classes/blocks/layout-block.php

357 lines 10.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace MBSocial;
3 defined('ABSPATH') or die('No direct access permitted');
4
5 use \MaxButtons\maxField as maxField;
6 use \MaxButtons\maxBlocks as maxBlocks;
7 use \MaxButtons\maxUtils as maxUtils;
8
9 $collectionBlock["layout"] = array('order' => 40,
10 'class' => "layoutBlock"
11 );
12
13 class layoutBlock extends block
14 {
15 protected $blockname = "layout";
16 protected $fields = array(
17 "margin_left" => array("default" => "0px",
18 "css" => "margin-left",
19 "csspart" => "maxcollection"),
20
21 "margin_right" => array("default" => "0px",
22 "css" => "margin-right",
23 "csspart" => "maxcollection"),
24
25 "margin_top" => array("default" => "0px",
26 "css" => "margin-top",
27 "csspart" => "maxcollection"),
28
29 "margin_bottom" => array("default" => "0px",
30 "css" => "margin-bottom",
31 "csspart" => "maxcollection"),
32 "orientation" => array("default" => "auto"),
33
34 /*"item_margin_right" => array("default" => "0px",
35 "css" => "margin-right",
36 "csspart" => "mb-collection-item",
37 ),
38 "item_margin_bottom" => array("default" => "0px",
39 "css" => "margin-bottom",
40 "csspart" => "mb-collection-item",
41 ),
42 */
43 'size' => array('default' => 100),
44 'use_background' => array('default' => 1, ),
45 'background_color' => array('default' => '#000',
46 'css' => 'background-color',
47 'csspart' => 'maxbutton-social',
48 ),
49 'background_color_hover' => array('default' => '#000',
50 'css' => 'background-color',
51 'csspart' => 'maxbutton-social',
52 'csspseudo' => 'hover',
53 ),
54 'color' => array('default' => '#fff',
55 'css' => 'color',
56 'csspart' => 'mb-icon,mb-share-count,mb-label'),
57 'color_hover' => array('default' => '#fff',
58 'css' => 'color',
59 'csspart' => 'mb-icon,mb-share-count,mb-label',
60 'csspseudo' => 'hover'),
61
62
63 "button_spacing" => array('default' => '5',
64 ),
65 "ignore_container" => array("default" => 1),
66
67
68 /* "static_position_ver" => array("default" => "Auto",
69 ),
70 "static_position_hor" => array("default" => "Auto",
71 ),
72 */
73 );
74 /*public function map_fields($map)
75 {
76 $map = parent::map_fields($map);
77 $map["orientation"]["func"] = "updatePlacement";
78
79 return $map;
80 } */
81
82 /* function parseButtons($buttons)
83 {
84 // searches the cache for the container statement ending with -container or -center and tries to remove then
85 // not very optimal code, but this is a way to maintain cache loading while altering css.
86
87 if ($this->data["ignore_container"] == 0)
88 return $buttons; // ignore container off .
89
90 foreach($buttons as $button)
91 {
92 $cache = $button->getCache();
93
94 // chops all css statements in a different line
95 preg_match_all('/([^{]+)\s*\{\s*([^}]+)\s*}/i',$cache, $matches);
96 foreach($matches[0] as $cssline)
97 {
98 // tries to find the last part of the statement from - to {
99 preg_match_all('/.([^-])*{/i', $cssline, $item);
100
101 $item = trim(str_replace("{","",$item[0][0]));
102 if ($item == '-center' || $item == '-container')
103 {
104 $cache = str_replace($cssline,'',$cache);
105 }
106
107
108 }
109
110 //([^{]+)\s*\{\s*([^}]+)\s*} { split }
111 // match last thing .([^-])*{
112 $button->setCache($cache);
113
114 $data = $button->get();
115
116 $container = isset($data["container"]) ? $data["container"] : array();
117 foreach($container as $key => $value)
118 {
119 if ($key != 'container_enabled' && $key != 'container_center_div_wrap') // causes container to be removed otherwise
120 $container[$key] = '';
121 }
122
123 $button->setdata("container", $container);
124 }
125 return $buttons;
126
127 } */
128
129 function parseCSS($css, $args)
130 {
131 $css = parent::parseCSS($css, $args);
132
133 $hook = $this->collection->getHook();
134 $blockdata = $this->data[$this->blockname];
135
136 // if true, use network colors
137 $use_background = isset($blockdata['use_background']) ? $blockdata['use_background'] : false;
138
139 if ($use_background)
140 {
141 unset ($css['maxbutton-social']['normal']['background-color']);
142 unset ($css['maxbutton-social']['hover']['background-color']);
143 }
144
145
146 $css['mb-icon.svg path']['normal']['color'] = '#fff';
147 $css['mb-icon.svg path']['hover']['color'] = '#ff0000';
148
149 $css["collection-item"]["normal"]["float"] = "left";
150 $css["collection-item"]["normal"]["display"] = "inline-block";
151 $css["collection-item a"]["normal"]["cursor"] = "pointer"; // by default social share = call to action.
152
153
154 if ($blockdata['button_spacing'] > 0)
155 {
156 $orientation = $this->collection->orientation;
157
158
159 $button_spacing = $blockdata['button_spacing'];
160
161 if ($orientation == 'horizontal')
162 {
163 $css['collection-item']['normal']['margin-right'] = $button_spacing . 'px';
164 }
165 if ($orientation == 'vertical')
166 {
167 $css['collection-item']['normal']['margin-bottom'] = $button_spacing . 'px';
168 }
169 }
170
171 return $css;
172
173 }
174
175 public function parse($itemObj, $args = array() )
176 {
177 $blockdata = $this->data[$this->blockname];
178
179 $use_background = isset($blockdata['use_background']) ? $blockdata['use_background'] : false;
180
181 if ($use_background)
182 {
183 $item = $itemObj->find('.collection-item',0);
184 $item->class .= ' social-colors';
185 }
186
187 return $itemObj;
188
189 }
190
191 function save_fields($data, $post)
192 {
193 $data = parent::save_fields($data, $post);
194 if (! isset($post["ignore_container"]) && ! is_null($post))
195 $data[$this->blockname]["ignore_container"] = 0;
196 if (! isset($post['use_background']) && ! is_null($post))
197 $data[$this->blockname]['use_background'] = 0;
198 return $data;
199
200 }
201
202 function admin()
203 {
204 $admin = mbSocial()->admin();
205
206 ?>
207
208 <div class='options option-container layout' id='layoutBlock' data-refresh='styleBlock' >
209 <div class='title'><?php _e('Customization', 'mbsocial' ); ?></div>
210 <div class='inside'>
211 <?php
212
213
214 // Slider Width
215 /* $size = new maxField('slider');
216 $size->label = __('Size', 'mbsocial');
217 $size->id = 'size';
218 $size->name = $size->id;
219 $size->min = 25;
220 $size->max = 200;
221 $size->min_label = $size->min . '%';
222 $size->max_label = $size->max . '%';
223 $size->value = maxBlocks::getValue('size');
224
225 $admin->addField($size, 'start', 'end');
226 */
227 $colorsw = new maxField('switch');
228 $colorsw->label = __('Use solid colors','mbsocial');
229 $colorsw->id = 'use_background';
230 $colorsw->value = 1;
231 $colorsw->name = $colorsw->id;
232 $colorsw->inputclass = 'update_change';
233 $colorsw->checked = checked( maxBlocks::getValue('use_background'), 1, false);
234
235 $admin->addUpdate($colorsw);
236 $admin->addField( $colorsw, 'start', '');
237
238
239 $ispacer = new maxField('spacer');
240 $ispacer->label = __('Use Social Network Brand Colors','mbsocial');
241 $ispacer->publish = false;
242 $ispacer->output('','end');
243
244 $admin->addField($ispacer, '', 'end');
245
246 $bgcolor = new maxField('color') ;
247 $bgcolor->label = __('Background color', 'mbsocial');
248 $bgcolor->value = maxBlocks::getColorValue('background_color');
249 $bgcolor->id = 'background_color';
250 $bgcolor->name = $bgcolor->id;
251
252 $admin->addUpdate($bgcolor);
253 $admin->addField($bgcolor, 'start', '');
254
255 $bgcolor_hover = new maxField('color');
256 $bgcolor_hover->label = __('Background Hover', 'mbsocial');
257 $bgcolor_hover->value = maxBlocks::getColorValue('background_color_hover');
258 $bgcolor_hover->id = 'background_color_hover';
259 $bgcolor_hover->name = $bgcolor_hover->id;
260
261 $admin->addUpdate($bgcolor_hover);
262 $admin->addField( $bgcolor_hover, '', 'end');
263
264 $color = new maxField('color');
265 $color->label = __('Color', 'mbsocial');
266 $color->value = maxBlocks::getColorValue('color');
267 $color->id = 'color';
268 $color->name = $color->id;
269
270 $admin->addUpdate($color);
271 $admin->addField($color, 'start', '');
272
273 $color_hover = new maxField('color');
274 $color_hover->label = __('Hover', 'mbsocial');
275 $color_hover->value = maxBlocks::getColorValue('color_hover');
276 $color_hover->id = 'color_hover';
277 $color_hover->name = $color_hover->id;
278
279 $admin->addUpdate($color_hover);
280 $admin->addField( $color_hover, '', 'end');
281
282
283 // Margins
284 $icon_url = MB()->get_plugin_url() . 'images/icons/' ;
285
286 $mtop = new maxField('number');
287 $mtop->publish = false;
288 $mtop->label = __('Margin top', 'mbsocial');
289 $mtop->id = 'margin_top';
290 $mtop->name = $mtop->id;
291 $mtop->min = 0;
292 $mtop->inputclass = 'tiny';
293 $mtop->before_input = '<img src="' . $icon_url . 'p_top.png" title="' . __("Margin Top","mbsocial") . '" >';
294 $mtop->value = maxUtils::strip_px(maxBlocks::getValue('margin_top'));
295
296 //$mtop->output('start');
297 $admin->addField($mtop, 'start','');
298
299 $mbottom = new maxField('number');
300 $mbottom->label = __('Margin Bottom', 'mbsocial');
301 $mbottom->id = 'margin_bottom';
302 $mbottom->name = $mbottom->id;
303 $mbottom->min = 0;
304 $mbottom->inputclass = 'tiny';
305 $mbottom->before_input = '<img src="' . $icon_url . 'p_bottom.png" title="' . __("Margin Bottom","mbsocial") . '" >';
306 $mbottom->value = maxUtils::strip_px(maxBlocks::getValue('margin_bottom') );
307
308 $admin->addField( $mbottom, '', 'end' );
309
310 $mleft = new maxField('number');
311 $mleft->label = __('Margin Left', 'mbsocial');
312 $mleft->id = 'margin_left';
313 $mleft->name = $mleft->id;
314 $mleft->min = 0;
315 $mleft->inputclass = 'tiny';
316 $mleft->before_input = '<img src="' . $icon_url . 'p_left.png" title="' . __("Margin Left","mbsocial") . '" >';
317 $mleft->value = maxUtils::strip_px(maxBlocks::getValue('margin_left'));
318
319 $admin->addField( $mleft,'start', '');
320
321 $mright = new maxField('number');
322 $mright->label = __('Margin Right', 'mbsocial');
323 $mright->id = 'margin_right';
324 $mright->name = $mright->id;
325 $mright->min = 0;
326 $mright->inputclass = 'tiny';
327 $mright->before_input = '<img src="' . $icon_url . 'p_right.png" title="' . __("Margin Right","mbsocial") . '" >';
328 $mright->value = maxUtils::strip_px(maxBlocks::getValue('margin_right'));
329
330 $admin->addField( $mright, '', 'end');
331
332 // Spacing
333
334 $spacing = new maxField('number');
335 $spacing->label = __('Button Spacing', 'mbsocial');
336 $spacing->id = 'button_spacing';
337 $spacing->name = $spacing->id;
338 $spacing->min = 0;
339 $spacing->inputclass = 'tiny';
340 $spacing->value = maxUtils::strip_px(maxBlocks::getValue('button_spacing'));
341
342 $admin->addUpdate($spacing);
343 $admin->addField($spacing, 'start', 'end');
344
345 $admin->display_fields();
346
347 ?>
348 </div> <!-- inside -->
349 </div> <!-- option container -->
350
351
352
353 <?php
354 }
355
356 }
357