PluginProbe
Social Share Buttons / 1.0
Social Share Buttons v1.0
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 1.0, at classes/blocks/layout-block.php

458 lines 14.6 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\maxUtils as maxUtils;
7
8 $collectionBlock["layout"] = array('order' => 40,
9 'class' => "layoutBlock"
10 );
11
12 class layoutBlock extends block
13 {
14 protected $blockname = "layout";
15 protected $fields = array(
16 "margin_left" => array("default" => "0px",
17 "css" => "margin-left",
18 "csspart" => "maxsocial"),
19
20 "margin_right" => array("default" => "0px",
21 "css" => "margin-right",
22 "csspart" => "maxsocial"),
23
24 "margin_top" => array("default" => "0px",
25 "css" => "margin-top",
26 "csspart" => "maxsocial"),
27
28 "margin_bottom" => array("default" => "0px",
29 "css" => "margin-bottom",
30 "csspart" => "maxsocial"),
31 "orientation" => array("default" => "auto"),
32
33 "font" => array("default" => "",
34 "css" => "font-family",
35 "csspart" => 'mb-label,mb-share-count'
36 ),
37
38 "font_label_size" => array("default" => "15px",
39 "css" => "font-size",
40 "csspart" => 'mb-label' ),
41
42 "font_label_style" => array("default" => "normal",
43 "css" => "font-style",
44 "csspart" => 'mb-label'),
45
46 "font_label_weight" => array("default" => "normal",
47 "css" => "font-weight",
48 "csspart" => 'mb-label'),
49
50 "font_label_upper" => array('default' => 'none',
51 'css' => 'text-transform',
52 'csspart' => 'mb-label',
53 ),
54
55 "font_icon_size" => array("default" => "15px",
56 "css" => "font-size",
57 "csspart" => 'mb-icon' ),
58
59 "font_icon_style" => array("default" => "normal",
60 "css" => "font-style",
61 "csspart" => 'mb-icon'),
62
63 "font_icon_weight" => array("default" => "normal",
64 "css" => "font-weight",
65 "csspart" => 'mb-icon'),
66
67
68 // 'width' => array(),
69 // 'height' => array(),
70 'use_background' => array('default' => 1, ),
71 'background_color' => array('default' => '#000',
72 'css' => 'background-color',
73 'csspart' => 'mb-social',
74 ),
75 'background_color_hover' => array('default' => '#000',
76 'css' => 'background-color',
77 'csspart' => 'mb-social',
78 'csspseudo' => 'hover',
79 ),
80 'color' => array('default' => '#fff',
81 'css' => 'color',
82 'csspart' => 'mb-icon,mb-share-count,mb-label'),
83 'color_hover' => array('default' => '#fff',
84 'css' => 'color',
85 'csspart' => 'mb-icon,mb-share-count,mb-label',
86 'csspseudo' => 'hover'),
87
88
89 "button_spacing" => array('default' => '5',
90 ),
91 "ignore_container" => array("default" => 1),
92
93
94 /* "static_position_ver" => array("default" => "Auto",
95 ),
96 "static_position_hor" => array("default" => "Auto",
97 ),
98 */
99 );
100 /*public function map_fields($map)
101 {
102 $map = parent::map_fields($map);
103 $map["orientation"]["func"] = "updatePlacement";
104
105 return $map;
106 } */
107
108 /* function parseButtons($buttons)
109 {
110 // searches the cache for the container statement ending with -container or -center and tries to remove then
111 // not very optimal code, but this is a way to maintain cache loading while altering css.
112
113 if ($this->data["ignore_container"] == 0)
114 return $buttons; // ignore container off .
115
116 foreach($buttons as $button)
117 {
118 $cache = $button->getCache();
119
120 // chops all css statements in a different line
121 preg_match_all('/([^{]+)\s*\{\s*([^}]+)\s*}/i',$cache, $matches);
122 foreach($matches[0] as $cssline)
123 {
124 // tries to find the last part of the statement from - to {
125 preg_match_all('/.([^-])*{/i', $cssline, $item);
126
127 $item = trim(str_replace("{","",$item[0][0]));
128 if ($item == '-center' || $item == '-container')
129 {
130 $cache = str_replace($cssline,'',$cache);
131 }
132
133
134 }
135
136 //([^{]+)\s*\{\s*([^}]+)\s*} { split }
137 // match last thing .([^-])*{
138 $button->setCache($cache);
139
140 $data = $button->get();
141
142 $container = isset($data["container"]) ? $data["container"] : array();
143 foreach($container as $key => $value)
144 {
145 if ($key != 'container_enabled' && $key != 'container_center_div_wrap') // causes container to be removed otherwise
146 $container[$key] = '';
147 }
148
149 $button->setdata("container", $container);
150 }
151 return $buttons;
152
153 } */
154
155 function parseCSS($css, $args)
156 {
157 $css = parent::parseCSS($css, $args);
158 $w = MBSocial()->whistle();
159
160 $hook = $this->collection->getHook();
161 $blockdata = $this->data[$this->blockname];
162
163 $network = $this->network;
164
165 // if true, use network colors
166 $use_background = isset($blockdata['use_background']) ? $blockdata['use_background'] : false;
167
168 if ($use_background)
169 {
170 unset ($css['mb-social']['normal']['background-color']);
171 unset ($css['mb-social']['hover']['background-color']);
172
173 $color = $network->get('color');
174
175 $css['mb-social']['normal']['background-color'] = $color;
176 $css['mb-social']['hover']['background-color'] = "darken($color, 10%)";
177 }
178
179 $css['mb-icon.svg path']['normal']['color'] = '#fff';
180 $css['mb-icon.svg path']['hover']['color'] = '#ff0000';
181
182 $css["mb-item"]["normal"]["float"] = "left";
183 $css["mb-item"]["normal"]["display"] = "inline-block";
184 $css["mb-item a"]["normal"]["cursor"] = "pointer"; // by default social share = call to action.
185
186
187 if (isset($blockdata['button_spacing']) && $blockdata['button_spacing'] > 0)
188 {
189 $orientation = $this->collection->orientation;
190 $is_static = $w->ask('display/env/is_static');
191
192 $button_spacing = $blockdata['button_spacing'];
193
194 if ($orientation == 'horizontal')
195 {
196 $css['mb-item']['normal']['margin'] = $button_spacing . 'px';
197 }
198 if ($orientation == 'vertical')
199 {
200 $css['mb-item']['normal']['margin'] = $button_spacing . 'px';
201 }
202 }
203
204 return $css;
205
206 }
207
208 public function parse($itemObj, $args = array() )
209 {
210 $blockdata = $this->data[$this->blockname];
211
212 $use_background = isset($blockdata['use_background']) ? $blockdata['use_background'] : false;
213 // ??
214 if ($use_background)
215 {
216 // $item = $itemObj->find('.mb-item',0);
217 // $item->class .= ' social-colors';
218 // $network = $this->network->get('network');
219
220 }
221
222 return $itemObj;
223
224 }
225
226 function save_fields($data, $post)
227 {
228 $data = parent::save_fields($data, $post);
229 if (! isset($post["ignore_container"]) && ! is_null($post))
230 $data[$this->blockname]["ignore_container"] = 0;
231 if (! isset($post['use_background']) && ! is_null($post))
232 $data[$this->blockname]['use_background'] = 0;
233 return $data;
234
235 }
236
237 function admin()
238 {
239 $admin = mbSocial()->admin();
240
241 ?>
242
243 <div class='options option-container layout' id='layoutBlock' data-refresh='previewBlock' >
244 <div class='title'><?php _e('Customization', 'mbsocial' ); ?></div>
245 <div class='inside'>
246 <?php
247
248 $colorsw = new maxField('switch');
249 $colorsw->label = __('Use solid colors','mbsocial');
250 $colorsw->id = 'use_background';
251 $colorsw->value = 1;
252 $colorsw->name = $colorsw->id;
253 $colorsw->inputclass = 'update_change';
254 $colorsw->checked = checked( $this->getValue('use_background'), 1, false);
255 $admin->addField( $colorsw, 'start', '');
256
257
258 $ispacer = new maxField('spacer');
259 $ispacer->label = __('Use Social Network Brand Colors','mbsocial');
260 $ispacer->publish = false;
261 $ispacer->output('','end');
262
263 $admin->addField($ispacer, '', 'end', false);
264
265 $bgcolor = new maxField('color') ;
266 $bgcolor->label = __('Background color', 'mbsocial');
267 $bgcolor->value = $this->getColorValue('background_color');
268 $bgcolor->id = 'background_color';
269 $bgcolor->name = $bgcolor->id;
270 $admin->addField($bgcolor, 'start', '');
271
272 $bgcolor_hover = new maxField('color');
273 $bgcolor_hover->label = __('Background Hover', 'mbsocial');
274 $bgcolor_hover->value = $this->getColorValue('background_color_hover');
275 $bgcolor_hover->id = 'background_color_hover';
276 $bgcolor_hover->name = $bgcolor_hover->id;
277 $admin->addField( $bgcolor_hover, '', 'end');
278
279 $color = new maxField('color');
280 $color->label = __('Color', 'mbsocial');
281 $color->value = $this->getColorValue('color');
282 $color->id = 'color';
283 $color->name = $color->id;
284 $admin->addField($color, 'start', '');
285
286 $color_hover = new maxField('color');
287 $color_hover->label = __('Hover', 'mbsocial');
288 $color_hover->value = $this->getColorValue('color_hover');
289 $color_hover->id = 'color_hover';
290 $color_hover->name = $color_hover->id;
291 $admin->addField( $color_hover, '', 'end');
292
293 // FONTS
294 $fonts = MB()->getClass('admin')->loadFonts();
295
296 $field_font = new maxField('generic');
297 $field_font->label = __('Font Family','maxbuttons');
298 $field_font->name = 'font';
299 $field_font->id = $field_font->name;
300 $field_font->value= $this->getValue('font');
301 $field_font->content = maxUtils::selectify($field_font->name, $fonts, $field_font->value);
302 $admin->addField($field_font,'start', 'end');
303 ?>
304
305 <?php
306 // FONT SIZE
307 //global $maxbuttons_font_sizes;
308 $sizes = apply_filters('mb/editor/fontsizes', maxUtils::generate_font_sizes(10,50) );
309
310 // *** LABEL SIZE *** //
311 $field_size = new maxField('number');
312 $field_size->label = __('Label Size', 'mbsocial');
313 $field_size->name = 'font_label_size';
314 $field_size->id= $field_size->name;
315 $field_size->inputclass = 'tiny';
316 $field_size->min = 8;
317 $field_size->value = maxUtils::strip_px($this->getValue('font_label_size'));
318 $admin->addField($field_size, 'start');
319
320 // Font style checkboxes
321 $fweight = new maxField('checkbox');
322 $fweight->icon = 'dashicons-editor-bold';
323 $fweight->title = __("Bold",'mbsocial');
324 $fweight->id = 'check_label_fweight';
325 $fweight->name = 'font_label_weight';
326 $fweight->value = 'bold';
327 $fweight->inputclass = 'check_button icon';
328 $fweight->checked = checked( $this->getValue('font_label_weight'), 'bold', false);
329 $admin->addField($fweight, 'group_start');
330
331 $fstyle = new maxField('checkbox');
332 $fstyle->icon = 'dashicons-editor-italic';
333 $fstyle->title = __("Italic",'mbsocial');
334 $fstyle->id = 'check_label_fstyle';
335 $fstyle->name = 'font_label_style';
336 $fstyle->value = 'italic';
337 $fstyle->inputclass = 'check_button icon';
338 $fstyle->checked = checked( $this->getValue('font_label_style'), 'italic', false);
339 $admin->addField($fstyle);
340
341 $fupper = new maxField('checkbox');
342 $fupper->icon = 'dashicons-arrow-up';
343 $fupper->title = __('Uppercase', 'mbsocial');
344 $fupper->id = 'check_label_fupper';
345 $fupper->name = 'font_label_upper';
346 $fupper->value = 'uppercase';
347 $fupper->inputclass = 'check_button icon';
348 $fupper->checked = checked ( $this->getValue('font_label_upper'), 'uppercase', false);
349
350 $admin->addField($fupper, '', array('group_end', 'end'));
351
352 // *** ICON SIZE *** //
353 $field_size = new maxField('number');
354 $field_size->label = __('Icon Size', 'mbsocial');
355 $field_size->name = 'font_icon_size';
356 $field_size->id= $field_size->name;
357 $field_size->inputclass = 'tiny';
358 $field_size->min = 8;
359 $field_size->value = maxUtils::strip_px($this->getValue('font_icon_size'));
360 $admin->addField($field_size, 'start');
361
362 // Font style checkboxes
363 $fweight = new maxField('checkbox');
364 $fweight->icon = 'dashicons-editor-bold';
365 $fweight->title = __("Bold",'mbsocial');
366 $fweight->id = 'check_icon_fweight';
367 $fweight->name = 'font_icon_weight';
368 $fweight->value = 'bold';
369 $fweight->inputclass = 'check_button icon';
370 $fweight->checked = checked( $this->getValue('font_icon_weight'), 'bold', false);
371 $admin->addField($fweight, 'group_start');
372
373 $fstyle = new maxField('checkbox');
374 $fstyle->icon = 'dashicons-editor-italic';
375 $fstyle->title = __("Italic",'mbsocial');
376 $fstyle->id = 'check_icon_fstyle';
377 $fstyle->name = 'font_icon_style';
378 $fstyle->value = 'italic';
379 $fstyle->inputclass = 'check_button icon';
380 $fstyle->checked = checked( $this->getValue('font_icon_style'), 'italic', false);
381 $admin->addField($fstyle, '', array('group_end', 'end'));
382
383
384 // Margins
385 $icon_url = MB()->get_plugin_url() . 'images/icons/' ;
386
387 $mtop = new maxField('number');
388 $mtop->publish = false;
389 $mtop->label = __('Margin top', 'mbsocial');
390 $mtop->id = 'margin_top';
391 $mtop->name = $mtop->id;
392 $mtop->min = 0;
393 $mtop->inputclass = 'tiny';
394 $mtop->before_input = '<img src="' . $icon_url . 'p_top.png" title="' . __("Margin Top","mbsocial") . '" >';
395 $mtop->value = maxUtils::strip_px($this->getValue('margin_top'));
396
397 //$mtop->output('start');
398 $admin->addField($mtop, 'start','', false);
399
400 $mbottom = new maxField('number');
401 $mbottom->label = __('Margin Bottom', 'mbsocial');
402 $mbottom->id = 'margin_bottom';
403 $mbottom->name = $mbottom->id;
404 $mbottom->min = 0;
405 $mbottom->inputclass = 'tiny';
406 $mbottom->before_input = '<img src="' . $icon_url . 'p_bottom.png" title="' . __("Margin Bottom","mbsocial") . '" >';
407 $mbottom->value = maxUtils::strip_px($this->getValue('margin_bottom') );
408
409 $admin->addField( $mbottom, '', 'end', false );
410
411 $mleft = new maxField('number');
412 $mleft->label = __('Margin Left', 'mbsocial');
413 $mleft->id = 'margin_left';
414 $mleft->name = $mleft->id;
415 $mleft->min = 0;
416 $mleft->inputclass = 'tiny';
417 $mleft->before_input = '<img src="' . $icon_url . 'p_left.png" title="' . __("Margin Left","mbsocial") . '" >';
418 $mleft->value = maxUtils::strip_px($this->getValue('margin_left'));
419
420 $admin->addField( $mleft,'start', '', false);
421
422 $mright = new maxField('number');
423 $mright->label = __('Margin Right', 'mbsocial');
424 $mright->id = 'margin_right';
425 $mright->name = $mright->id;
426 $mright->min = 0;
427 $mright->inputclass = 'tiny';
428 $mright->before_input = '<img src="' . $icon_url . 'p_right.png" title="' . __("Margin Right","mbsocial") . '" >';
429 $mright->value = maxUtils::strip_px($this->getValue('margin_right'));
430
431 $admin->addField( $mright, '', 'end', false);
432
433 // Spacing
434
435 $spacing = new maxField('number');
436 $spacing->label = __('Button Spacing', 'mbsocial');
437 $spacing->id = 'button_spacing';
438 $spacing->name = $spacing->id;
439 $spacing->min = 0;
440 $spacing->inputclass = 'tiny';
441 $spacing->value = maxUtils::strip_px($this->getValue('button_spacing'));
442
443 $admin->addUpdate($spacing);
444 $admin->addField($spacing, 'start', 'end');
445
446 $admin->display_fields();
447
448 ?>
449 </div> <!-- inside -->
450 </div> <!-- option container -->
451
452
453
454 <?php
455 }
456
457 }
458