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

514 lines 16.8 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 $css['mb-item a']['normal']['text-decoration'] = 'none';
186
187
188 if (isset($blockdata['button_spacing']) && $blockdata['button_spacing'] > 0)
189 {
190 $orientation = $this->collection->orientation;
191 $is_static = $w->ask('display/env/is_static');
192
193 $button_spacing = $blockdata['button_spacing'];
194
195 if ($orientation == 'horizontal')
196 {
197 $css['mb-item']['normal']['margin-right'] = $button_spacing . 'px';
198 }
199 if ($orientation == 'vertical')
200 {
201 $css['mb-item']['normal']['margin-bottom'] = $button_spacing . 'px';
202 }
203 }
204
205 return $css;
206
207 }
208
209 public function parse($itemObj, $args = array() )
210 {
211 $blockdata = $this->data[$this->blockname];
212
213 $use_background = isset($blockdata['use_background']) ? $blockdata['use_background'] : false;
214 // ??
215 if ($use_background)
216 {
217 // $item = $itemObj->find('.mb-item',0);
218 // $item->class .= ' social-colors';
219 // $network = $this->network->get('network');
220
221 }
222
223 return $itemObj;
224
225 }
226
227 function save_fields($data, $post)
228 {
229 $data = parent::save_fields($data, $post);
230 if (! isset($post["ignore_container"]) && ! is_null($post))
231 $data[$this->blockname]["ignore_container"] = 0;
232 if (! isset($post['use_background']) && ! is_null($post))
233 $data[$this->blockname]['use_background'] = 0;
234 return $data;
235
236 }
237
238 function fontModal()
239 {
240 ?>
241 <div class='maxmodal-data' id='add-fonts' data-load='window.maxFoundry.maxfonts.load' data-height='90%'>
242 <span class='title'><?php _e("Font Manager","maxbuttons-pro"); ?>
243
244 </span>
245
246 <span class='content'>
247 <p><?php printf(__("Select from %s fonts you would like to use and they will show up in the dropdown list", 'maxbuttons-pro'), '<span class="fontcount"></span>'); ?></p>
248 <div class="loading_overlay"></div>
249 <div class='loading'>
250 <img src="<?php echo MB()->get_plugin_url(true) ?>images/loading.gif">
251 <span><?php _e("Loading","maxbuttons-pro"); ?></span>
252 </div>
253 <div class="font_manager">
254 <div class='font_search'> <span><?php _e("Search","maxbuttons-pro") ?></span>
255 <input type='text' name='font_search' value='' />
256 </div>
257
258 <div class="font_wrap">
259 <div class='font_left'>
260 <ul class='items'>
261
262 </ul>
263 </div>
264 <div class='font_right '>
265 <ul class='items'>
266
267 </ul>
268 </div>
269 </div>
270 <div class='font_example'>
271 <span class='placeholder'><?php _e("Click on a font to see an example","maxbuttons-pro"); ?></span>
272 <span class='example_text'><?php _e("AaBbCcDdEeFfGgEeHh") ?></span>
273 </div>
274 </div>
275 </span>
276 <div class='controls'>
277 <div class='controls_inline'>
278 <button type='button' name='save_fonts' class='button-primary'><?php _e("Save changes", 'maxbuttons-pro'); ?></button> &nbsp;
279 <button type='button' class='button-primary modal_close'><?php _e("Close","maxbuttons-pro"); ?></button>
280 </div>
281 </div>
282 </div> <!-- maxmodal-data -->
283 <?php
284 }
285
286 function admin()
287 {
288 $admin = mbSocial()->admin();
289
290 ?>
291
292 <div class='options option-container layout' id='layoutBlock' data-refresh='previewBlock' >
293 <div class='title'><?php _e('Customization', 'mbsocial' ); ?></div>
294 <div class='inside'>
295 <?php
296
297 $colorsw = new maxField('switch');
298 $colorsw->label = __('Use solid colors','mbsocial');
299 $colorsw->id = 'use_background';
300 $colorsw->value = 1;
301 $colorsw->name = $colorsw->id;
302 $colorsw->inputclass = 'update_change';
303 $colorsw->checked = checked( $this->getValue('use_background'), 1, false);
304 $admin->addField( $colorsw, 'start', '');
305
306
307 $ispacer = new maxField('spacer');
308 $ispacer->label = __('Use Social Network Brand Colors','mbsocial');
309 $ispacer->publish = false;
310 $ispacer->output('','end');
311
312 $admin->addField($ispacer, '', 'end', false);
313
314 $bgcolor = new maxField('color') ;
315 $bgcolor->label = __('Background color', 'mbsocial');
316 $bgcolor->value = $this->getColorValue('background_color');
317 $bgcolor->id = 'background_color';
318 $bgcolor->name = $bgcolor->id;
319 $admin->addField($bgcolor, 'start', '');
320
321 $bgcolor_hover = new maxField('color');
322 $bgcolor_hover->label = __('Background Hover', 'mbsocial');
323 $bgcolor_hover->value = $this->getColorValue('background_color_hover');
324 $bgcolor_hover->id = 'background_color_hover';
325 $bgcolor_hover->name = $bgcolor_hover->id;
326 $admin->addField( $bgcolor_hover, '', 'end');
327
328 $color = new maxField('color');
329 $color->label = __('Color', 'mbsocial');
330 $color->value = $this->getColorValue('color');
331 $color->id = 'color';
332 $color->name = $color->id;
333 $admin->addField($color, 'start', '');
334
335 $color_hover = new maxField('color');
336 $color_hover->label = __('Hover', 'mbsocial');
337 $color_hover->value = $this->getColorValue('color_hover');
338 $color_hover->id = 'color_hover';
339 $color_hover->name = $color_hover->id;
340 $admin->addField( $color_hover, '', 'end');
341
342 // FONTS
343 /* $button = new maxField('generic');
344 $button->label = '';
345 $button->id = 'manage-fonts';
346 $button->name = 'button_fonts';
347 $button->content = '<div id="manage-fonts" class="button manage-fonts maxmodal" data-modal="add-fonts" title="' . __("Add additional fonts","maxbuttons-pro") . '" ><i class="dashicons dashicons-editor-spellcheck"></i>' . __('Font Manager', 'maxbuttons-pro') . '</div>';
348 $admin->addField($button, 'start', 'end');
349 */
350 $fonts = MB()->getClass('admin')->loadFonts();
351
352 $field_font = new maxField('generic');
353 $field_font->label = __('Font Family','maxbuttons');
354 $field_font->name = 'font';
355 $field_font->id = $field_font->name;
356 $field_font->value= $this->getValue('font');
357 $field_font->content = maxUtils::selectify($field_font->name, $fonts, $field_font->value);
358 $admin->addField($field_font,'start', 'end');
359 ?>
360
361 <?php
362 // FONT SIZE
363 //global $maxbuttons_font_sizes;
364 $sizes = apply_filters('mb/editor/fontsizes', maxUtils::generate_font_sizes(10,50) );
365
366 // *** LABEL SIZE *** //
367 $field_size = new maxField('number');
368 $field_size->label = __('Label Size', 'mbsocial');
369 $field_size->name = 'font_label_size';
370 $field_size->id= $field_size->name;
371 $field_size->inputclass = 'tiny';
372 $field_size->min = 8;
373 $field_size->value = maxUtils::strip_px($this->getValue('font_label_size'));
374 $admin->addField($field_size, 'start');
375
376 // Font style checkboxes
377 $fweight = new maxField('checkbox');
378 $fweight->icon = 'dashicons-editor-bold';
379 $fweight->title = __("Bold",'mbsocial');
380 $fweight->id = 'check_label_fweight';
381 $fweight->name = 'font_label_weight';
382 $fweight->value = 'bold';
383 $fweight->inputclass = 'check_button icon';
384 $fweight->checked = checked( $this->getValue('font_label_weight'), 'bold', false);
385 $admin->addField($fweight, 'group_start');
386
387 $fstyle = new maxField('checkbox');
388 $fstyle->icon = 'dashicons-editor-italic';
389 $fstyle->title = __("Italic",'mbsocial');
390 $fstyle->id = 'check_label_fstyle';
391 $fstyle->name = 'font_label_style';
392 $fstyle->value = 'italic';
393 $fstyle->inputclass = 'check_button icon';
394 $fstyle->checked = checked( $this->getValue('font_label_style'), 'italic', false);
395 $admin->addField($fstyle);
396
397 $fupper = new maxField('checkbox');
398 $fupper->icon = 'dashicons-arrow-up';
399 $fupper->title = __('Uppercase', 'mbsocial');
400 $fupper->id = 'check_label_fupper';
401 $fupper->name = 'font_label_upper';
402 $fupper->value = 'uppercase';
403 $fupper->inputclass = 'check_button icon';
404 $fupper->checked = checked ( $this->getValue('font_label_upper'), 'uppercase', false);
405
406 $admin->addField($fupper, '', array('group_end', 'end'));
407
408 // *** ICON SIZE *** //
409 $field_size = new maxField('number');
410 $field_size->label = __('Icon Size', 'mbsocial');
411 $field_size->name = 'font_icon_size';
412 $field_size->id= $field_size->name;
413 $field_size->inputclass = 'tiny';
414 $field_size->min = 8;
415 $field_size->value = maxUtils::strip_px($this->getValue('font_icon_size'));
416 $admin->addField($field_size, 'start');
417
418 // Font style checkboxes
419 $fweight = new maxField('checkbox');
420 $fweight->icon = 'dashicons-editor-bold';
421 $fweight->title = __("Bold",'mbsocial');
422 $fweight->id = 'check_icon_fweight';
423 $fweight->name = 'font_icon_weight';
424 $fweight->value = 'bold';
425 $fweight->inputclass = 'check_button icon';
426 $fweight->checked = checked( $this->getValue('font_icon_weight'), 'bold', false);
427 $admin->addField($fweight, 'group_start');
428
429 $fstyle = new maxField('checkbox');
430 $fstyle->icon = 'dashicons-editor-italic';
431 $fstyle->title = __("Italic",'mbsocial');
432 $fstyle->id = 'check_icon_fstyle';
433 $fstyle->name = 'font_icon_style';
434 $fstyle->value = 'italic';
435 $fstyle->inputclass = 'check_button icon';
436 $fstyle->checked = checked( $this->getValue('font_icon_style'), 'italic', false);
437 $admin->addField($fstyle, '', array('group_end', 'end'));
438
439
440 // Margins
441 $icon_url = MB()->get_plugin_url() . 'images/icons/' ;
442
443 $mtop = new maxField('number');
444 $mtop->publish = false;
445 $mtop->label = __('Margin top', 'mbsocial');
446 $mtop->id = 'margin_top';
447 $mtop->name = $mtop->id;
448 $mtop->min = 0;
449 $mtop->inputclass = 'tiny';
450 $mtop->before_input = '<img src="' . $icon_url . 'p_top.png" title="' . __("Margin Top","mbsocial") . '" >';
451 $mtop->value = maxUtils::strip_px($this->getValue('margin_top'));
452
453 //$mtop->output('start');
454 $admin->addField($mtop, 'start','', false);
455
456 $mbottom = new maxField('number');
457 $mbottom->label = __('Margin Bottom', 'mbsocial');
458 $mbottom->id = 'margin_bottom';
459 $mbottom->name = $mbottom->id;
460 $mbottom->min = 0;
461 $mbottom->inputclass = 'tiny';
462 $mbottom->before_input = '<img src="' . $icon_url . 'p_bottom.png" title="' . __("Margin Bottom","mbsocial") . '" >';
463 $mbottom->value = maxUtils::strip_px($this->getValue('margin_bottom') );
464
465 $admin->addField( $mbottom, '', 'end', false );
466
467 $mleft = new maxField('number');
468 $mleft->label = __('Margin Left', 'mbsocial');
469 $mleft->id = 'margin_left';
470 $mleft->name = $mleft->id;
471 $mleft->min = 0;
472 $mleft->inputclass = 'tiny';
473 $mleft->before_input = '<img src="' . $icon_url . 'p_left.png" title="' . __("Margin Left","mbsocial") . '" >';
474 $mleft->value = maxUtils::strip_px($this->getValue('margin_left'));
475
476 $admin->addField( $mleft,'start', '', false);
477
478 $mright = new maxField('number');
479 $mright->label = __('Margin Right', 'mbsocial');
480 $mright->id = 'margin_right';
481 $mright->name = $mright->id;
482 $mright->min = 0;
483 $mright->inputclass = 'tiny';
484 $mright->before_input = '<img src="' . $icon_url . 'p_right.png" title="' . __("Margin Right","mbsocial") . '" >';
485 $mright->value = maxUtils::strip_px($this->getValue('margin_right'));
486
487 $admin->addField( $mright, '', 'end', false);
488
489 // Spacing
490
491 $spacing = new maxField('number');
492 $spacing->label = __('Button Spacing', 'mbsocial');
493 $spacing->id = 'button_spacing';
494 $spacing->name = $spacing->id;
495 $spacing->min = 0;
496 $spacing->inputclass = 'tiny';
497 $spacing->value = maxUtils::strip_px($this->getValue('button_spacing'));
498
499 $admin->addUpdate($spacing);
500 $admin->addField($spacing, 'start', 'end');
501
502 $admin->display_fields();
503 ?>
504 </div> <!-- inside -->
505 </div> <!-- option container -->
506
507
508 <?php $this->fontModal(); ?>
509
510 <?php
511 } // admin
512
513 }
514