PluginProbe
Social Share Buttons / 1.2
Social Share Buttons v1.2
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 / class-style.php

class-style.php in Social Share Buttons 1.2, at classes/class-style.php

761 lines 19.3 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\maxBlocks as maxBlocks;
6 use \MaxButtons\maxUtils as maxUtils;
7
8 class style
9 {
10 protected $collection;
11
12 public $class;
13 public $name;
14 public $description = ' Lorum Ipsum Stylum ';
15
16 // Defines if style supports label and share counts
17 public $has_share = false;
18 public $has_label = false;
19
20 /*
21 Controls what to display for this style and when
22 Usage
23 Pseudo (normal/hover) -> [item] , array('item', 'item'), 'item,item'
24 ^ one item, ^ or ^ and, show both
25 */
26 public $display = array('normal' => 'icon',
27 'hover' => array('count', 'label'),
28 );
29
30 protected $display_active = array();
31 protected $effect_active = false;
32
33 // possible ITEM css classes
34 protected $items = array('count' => 'mb-share-count',
35 'icon' => 'mb-icon-wrapper',
36 'label' => 'mb-label',
37 );
38
39 public $css = array(
40 'maxsocial' => array( // the container
41 'normal' =>
42 array('display' => 'inline-block',
43 'clear' => 'both',
44 'z-index' => 9999,
45 'position' => 'relative',
46 'width' => '100%',
47 'line-height' => '1.1',
48 'box-sizing' => 'border-box',
49 ),
50 // 'hover' => '',
51 ),
52
53 'mb-item' => array('normal' =>
54 array ( 'display' => 'flex',
55 'justify-content' => 'center',
56 'align-items' => 'center',
57 'box-sizing' => 'border-box',
58 'position' => 'relative',
59 'line-height' => 'inherit',
60 'text-align' => 'center',
61 ),
62 ),
63 'mb-social' => array('normal' => // the button
64 array ( 'display' => 'flex',
65 'justify-content' => 'center',
66 'align-items' => 'center',
67 'text-decoration' => 'none',
68 'position' => 'relative',
69 'border' => 0,
70 'box-shadow' => 'none',
71 'box-shadow-width' => 0,
72 'box-shadow-offset-left' => 0,
73 'box-shadow-offset-top' => 0,
74
75 ),
76 // 'hover' => array(),
77 ),
78 // 'mb-share-count' => array();
79 //'hover' => array('normal' => array( 'display' => 'none')),
80 //'normal' => array('hover' => array( 'display' => 'none')),
81
82 );
83
84
85 public static function registerStyle($name)
86 {
87 $class = get_called_class();
88 styles::registerStyle($class, $name);
89
90 }
91
92 public function __construct()
93 {
94
95 }
96
97 public function getCSS()
98 {
99 return $this->css;
100
101 }
102
103 /** Add effects to the styling . addCSS uses the last arg to bounce back CSS, since it's called by block
104 * @param $effect Name of the effect
105 * @param $args Arguments, some effects might need specific args.
106 */
107 public function addEffect($css, $effect, $args = array())
108 {
109 $this->effect_active = $effect;
110
111 switch($effect)
112 {
113 case 'drop':
114
115 $line_height = intval($args['line_height']) * 2;
116
117 $normcss = array(
118 'position' => 'absolute',
119 'left' => 0,
120 'bottom' => '-3px',
121 'width' => '100%',
122 'transition' => 'bottom .2s linear',
123 'z-index' => '-1',
124 'line-height' => $line_height .'px',
125 // 'display' => 'inline-block',
126 'background-color' => '#000',
127
128 );
129
130 $css = $this->addCSS($normcss, false, 'mb-label', 'normal', $css);
131 $css = $this->addCSS($normcss, false, 'mb-share-count', 'normal', $css);
132
133 $hovercss = array(
134 'bottom' => '-' . $line_height . 'px',
135 );
136
137 $css = $this->addCSS($hovercss, false, 'mb-label', 'hover', $css);
138 $css = $this->addCSS($hovercss, false, 'mb-share-count','hover', $css);
139
140 $css = $this->addCSS('overflow', 'visible', 'mb-social', 'normal', $css);
141
142 $css = $this->addCSS('z-index', '0', 'mb-social', 'normal', $css);
143 $css = $this->addCSS('position', 'static', 'mb-social', 'normal', $css);
144 $css = $this->addCSS('display', 'inline-block', 'mb-item', 'normal', $css);
145
146
147 break;
148 case 'flip':
149 $css = $this->addCSS('transform', 'translateY(0)', 'mb-label', 'hover', $css);
150 $css = $this->addCSS('transform', 'translateY(0)', 'mb-share-count','hover', $css);
151 $css = $this->addCSS('transform', 'translateY(-100%)', 'mb-icon-wrapper', 'hover', $css);
152 $css = $this->addCSS('overflow', 'hidden','mb-social', 'normal', $css);
153 $css = $this->addCSS('display','inline-block', 'mb-social', 'normal', $css);
154
155 $normcss = array(
156 'transition' => 'all .2s linear',
157 'height' => '100%',
158 'width' => '100%',
159 // 'display' => 'flex',
160 'align-items' => 'center',
161 'justify-content' => 'center',
162 'transform' => 'translateY(100%)',
163 );
164
165 $css = $this->addCSS($normcss, false, 'mb-label', 'normal', $css);
166 $css = $this->addCSS($normcss, false, 'mb-share-count', 'normal', $css);
167 $css = $this->addCSS($normcss, false, 'mb-icon-wrapper', 'normal', $css);
168 $css = $this->addCSS('transform', 'translateY(0)', 'mb-icon-wrapper', 'normal', $css);
169 $css = $this->addCSS('position', 'absolute', 'mb-icon-wrapper', 'normal', $css);
170
171 /* $css['mb-label']['hover']['transform'] = 'translateY(0)';
172 $css['mb-share-count']['hover']['transform'] = 'translateY(0)';
173 $css['mb-icon-wrapper']['hover']['transform'] = 'translateY(0)';
174 */
175 $hoverCSS = array(
176 // 'display' => 'flex',
177 'align-items' => 'center',
178 'justify-content' => 'center',
179 //'transform' => 'translateY(0)',
180 );
181
182
183 $css = $this->addCSS($hoverCSS, false, 'mb-label', 'hover', $css);
184 $css = $this->addCSS($hoverCSS, false, 'mb-share-count', 'hover', $css);
185 $css = $this->addCSS($hoverCSS, false, 'mb-icon-wrapper', 'hover', $css);
186 $css = $this->addCSS('transform', 'translateY(-100%)', 'mb-icon-wrapper', 'hover', $css); // move up
187
188
189 break;
190 case 'hover';
191 /*$color = $css['mb-social']['normal']['background-color'];
192 $css = $this->addCSS('background-color', 'darken(' . $color . ', 20%)', 'mb-social', 'hover', $css);
193 */
194 break;
195 case 'lift':
196 $line_height = intval($args['line_height']) * 1.5;
197
198 //$this->addCSS('overflow', 'hidden', 'collection-item');
199 $css = $this->addCSS('transform', 'translateY(-10px)', 'mb-icon-wrapper', 'hover', $css);
200 $css = $this->addCSS('transition', 'all .2s linear', 'mb-icon-wrapper', 'normal', $css);
201
202 $normcss = array(
203 'bottom' => '-' . $line_height . 'px',
204 'z-index' => 'auto',
205 'background' => 'transparent',
206 'position' => 'absolute',
207 'line-height' => $line_height . 'px',
208 'transition' => 'bottom .2s linear',
209 //'z-index' => '-1',
210 'width' => '100%',
211
212 );
213
214 $css = $this->addCSS($normcss, '', 'mb-label', 'normal', $css);
215 $css = $this->addCSS($normcss, '', 'mb-share-count', 'normal', $css);
216
217 $hovercss = array(
218 'bottom' => '0px',
219 'background' => 'transparent',
220
221 );
222
223 $css = $this->addCSS($hovercss, '', 'mb-label', 'hover', $css);
224 $css = $this->addCSS($hovercss, '', 'mb-share-count', 'hover', $css);
225
226 $css = $this->addCSS('overflow', 'hidden', 'mb-social', 'normal', $css);
227
228 break;
229 case 'none':
230
231 $this->display['hover'] = 'icon';
232 //$css = $this->addCSS('display', 'none', 'mb-label', 'hover', $css);
233 //$css = $this->addCSS('display', 'none', 'mb-share-count','hover', $css);
234 break;
235 case 'shift':
236 $this->display = array('normal' => 'icon,count',
237 'hover' => 'icon,label,count');
238 $line_height = $args['line_height'];
239
240 $css = $this->addCSS('overflow', 'hidden','mb-social', 'normal', $css);
241
242 $css = $this->addCSS( array(
243 'position' => 'absolute',
244 'bottom' => '3px',
245 'height' => $line_height,
246 'z-index' => '1',
247 'transition' => 'all .2s ease-in-out',
248 'background' => 'transparent',
249 'right' => 0,
250 'left' => 0,
251 ),
252 '',
253 'mb-share-count',
254 'normal',
255 $css);
256
257 $css = $this->addCSS ( array(
258 'transform' => 'translateX(60px)',
259 'bottom' => '0',
260 'background' => 'transparent',
261 ),
262 '',
263 'mb-share-count',
264 'hover',
265 $css
266 );
267
268 $css = $this->addCSS ( array (
269 'transform' => 'translateX(-60px)',
270 'position' => 'absolute',
271 'bottom' => 0,
272 'transition' => 'all .2s ease-in-out',
273 'background-color' => 'transparent',
274 'left' => 0,
275 'text-align' => 'center',
276 'width' => '100%',
277 'height' => $line_height,
278 ),
279 '',
280 'mb-label',
281 'normal',
282 $css
283 );
284
285 $css = $this->addCSS ( array (
286 'transform' => 'translateX(0px)',
287 'z-index' => '1',
288 'bottom' => '3px',
289 'background-color' => 'transparent',
290 ),
291 '',
292 'mb-label',
293 'hover',
294 $css
295 );
296
297 $css = $this->addCSS ('transform', 'translateY(-8px)', 'mb-icon-wrapper', 'hover', $css);
298 $css = $this->addCSS ('transition', 'all .2s ease-in-out', 'mb-icon-wrapper', 'normal', $css);
299
300 break;
301 case 'stretch':
302 $this->display = array('normal' => 'icon,count',
303 'hover' => 'icon,label,count');
304 $css = $this->addStretch($css,$args);
305
306 break;
307 case 'transform':
308 $scale = intval($args['scale']);
309 $scale = $scale / 10;
310 //$css['mb-social']['hover']['transform'] = 'scale(' . $scale . ')';
311 //$css['mb-social']['hover']['transform'] = 'scale(' . $scale . ')';
312 $css = $this->addCSS('transform', 'scale('. $scale . ')', 'mb-social','hover', $css);
313 break;
314 }
315
316 return $css;
317 }
318
319 protected function addStretch($css, $args)
320 {
321 $css = $this->addCSS('display', 'flex', 'maxsocial', 'normal', $css);
322
323 $css = $this->addCSS('flex', '1.2', 'mb-item', 'hover', $css);
324
325 $itemcss = array(
326 'flex' => 1,
327 'float' => 'left',
328 'height' => '100%',
329 '-webkit-transition' => 'all .2s linear',
330 'transition' => 'all .2s linear',
331 );
332 $css = $this->addCSS($itemcss, '','mb-item', 'normal', $css);
333
334 $css = $this->addCSS ( array (
335 'display' => 'block',
336 'display' => '-webkit-box',
337 'display' => '-webkit-flex',
338 'display' => '-moz-box',
339 'display' => '-ms-flexbox',
340 'display' => 'flex',
341 'text-transform' => 'none',
342 '-webkit-flex-flow' => 'row wrap',
343 '-ms-flex-flow' => 'row wrap',
344 'flex-flow' => 'row wrap',
345 'width' => '100%',
346 ),
347 '',
348 'mb-social', 'normal', $css);
349
350 $css = $this->addCSS('flex', '1.2', 'mb-social', 'hover', $css);
351
352 // the label
353 $css = $this->addCSS ( array (
354 'text-align' => 'center',
355 'flex-grow' => 3,
356 'margin' => 'auto',
357 'display' => 'none',
358 'opacity' => 0,
359 '-webkit-transition' => 'all .4s linear',
360 'transition' => 'all .4s linear',
361 ),
362 '',
363 'mb-label',
364 'normal',
365 $css
366 );
367
368 // label hover
369 $css = $this->addCSS( array(
370 'display' => 'inline-block',
371 'opacity' => '1',
372
373 ),
374 '',
375 'mb-label',
376 'hover',
377 $css
378
379 );
380
381 $css = $this->addCSS ( array (
382 'text-align' => 'center',
383 'flex-grow' => 2,
384 'margin' => 'auto',
385 ),
386 '',
387 'mb-icon-wrapper',
388 'normal',
389 $css
390 );
391
392 $css = $this->addCSS ( array (
393 // 'font-size' => '16px',
394 'margin' => 'auto 0',
395 //'flex-grow' => '1',
396 'display' => 'inline-block',
397 'transform' => 'translateX(-10px)',
398 ),
399 '',
400 'mb-share-count',
401 'normal',
402 $css
403 );
404
405 $css = $this->addCSS('flex-grow', '1', 'mb-share-count', 'hover', $css);
406
407 return $css;
408 }
409
410 /* Total element is counting all shares and displays some label */
411 protected function addTotal($css)
412 {
413 // total main element
414 //$this->addFlex('maxbutton-social-total');
415 $styleBlock = $this->collection->getBlock('styleBlock');
416 $layoutBlock = $this->collection->getBlock('layoutBlock');
417
418 $width = $styleBlock->getValue('mbs-width');
419 $height = $styleBlock->getValue('mbs-height');
420
421 // $this->css['maxbutton-social-total'];
422 //$width = $css['mb-social']['normal']['width'];
423 //$height = $css['mb-social']['normal']['height'];
424
425 /*$width = isset($css['mbsocial']['normal']['width']) ? $css['mbsocial']['normal']['width'] : 'auto';
426 $height = isset($css['mbsocial']['normal']['height']) ? $css['mbsocial']['normal']['height'] : 'auto';
427 */
428 $width = maxUtils::strip_px($width);
429 $height = maxUtils::strip_px($height);
430
431 // copy mb-item and put it to mb-item-total. Not going to be exactly the same.
432 $itemcss = $css['mb-item'];
433
434 $css = $this->addCSS($itemcss['normal'], '', 'mb-total-container', 'normal', $css);
435
436 $margin = maxUtils::strip_px($layoutBlock->getValue('button_spacing'));
437
438 if ($this->collection->orientation == 'vertical')
439 {
440 $width = $width . 'px';
441 $height = '100%';
442 }
443 else { // horizontal
444 $width = ($width + $margin) * 2;
445 $width = $width . 'px';
446 $height = $height . 'px';
447 }
448
449 // attempt to auto-custmz.
450 $count_size = (isset($css['mb-share-count']['normal']['font-size'])) ? $css['mb-share-count']['normal']['font-size'] : '13';
451 $count_size = maxUtils::strip_px($count_size);
452
453 $total_count_size = $count_size * 1.5;
454
455
456 $css = $this->addCSS ( array(
457 'width' => $width,
458 'height' => $height,
459 'display' => 'flex',
460 'align-items' => 'center',
461 'justify-content' => 'center',
462 //'font-size' => '16px',
463 ),
464 '',
465 'maxbutton-social-total',
466 'normal',
467 $css
468 );
469
470
471 $css = $this->addCSS ( array(
472 //'float' => 'left',
473 'font-size' => '20px',
474 'width' => '45%',
475 'text-align' => 'left',
476 'height' => 'inherit',
477 //'height' => 'inherit',
478 'display' => 'flex',
479 'align-items' => 'center',
480 'justify-content' => 'center',
481 ),
482 '',
483 'mb-icon-total',
484 'normal',
485 $css
486 );
487
488 $css = $this->addCSS ( array ( // *sigh*
489 'font-size' => '35px',
490 //'height' => 'auto',
491 'vertical-align' => 'top',
492 ),
493 '',
494 'mb-icon-total-icon',
495 'before',
496 $css
497 );
498
499 $css = $this->addCSS ( array (
500 'width' => '35px',
501 'height' => '35px'
502 ),
503 '',
504 'mb-icon-total-icon',
505 'normal',
506 $css
507 );
508
509 $css = $this->addCSS ( array (
510 //'float' => 'right',
511 'clear' => 'right',
512 'text-align' => 'center',
513 // 'width' => '45%',
514 'text-transform' => 'uppercase',
515 'font-size' => '13px',
516 ),
517 '',
518 'mb-label-total',
519 'normal',
520 $css
521 );
522
523 $css = $this->addCSS ( array (
524 //'float' => 'right',
525 'text-align' => 'center',
526 'font-size' => $total_count_size .'px',
527
528 ),
529 '',
530 'mb-count-total',
531 'normal',
532 $css
533 );
534
535
536 return $css;
537 }
538
539
540 public function addCSS($name, $value = '', $element = 'mb-social', $pseudo = 'normal', $css = false)
541 {
542 if (! $css && !isset($this->css[$element][$pseudo]))
543 {
544 $this->css[$element][$pseudo] = array();
545 }
546 if ($css && !isset($css[$element][$pseudo]))
547 {
548 $css[$element][$pseudo] = array();
549 }
550
551 if ( is_array($name))
552 {
553 foreach ($name as $n => $v)
554 {
555 if ($css)
556 $css[$element][$pseudo][$n] = $v;
557 else
558 {
559 $this->css[$element][$pseudo][$n] = $v;
560 }
561 }
562
563 }
564 else
565 {
566 if ($css)
567 {
568 $css[$element][$pseudo][$name] = $value;
569 }
570 else
571 $this->css[$element][$pseudo][$name] = $value;
572 }
573
574 if ($css)
575 return $css;
576 }
577
578
579
580
581 /* Function that runs before the CSS output is collected from the blocks to be brought to the CSSParser. Load with env. details will allow for relevant changes */
582 public function prepareCSS($args)
583 {
584
585 $default_args = array(
586 'orientation' => 'horizontal',
587 'is_static' => false,
588 'is_post' => false,
589 'is_mobile' => false,
590 'is_tablet' => false,
591 );
592
593 $args = wp_parse_args($args, $default_args);
594
595 if ($args['orientation'] == 'vertical')
596 {
597 $this->addCSS(array(
598 /* 'width' => $this->width . 'px',
599 'height' => $this->height . 'px', */
600 // 'width' => '100%',
601 'flex-direction' => 'column'
602 ),
603 '',
604 'maxbutton-social-total'
605 );
606
607 $this->addCSS('display', 'none', 'mb-icon-total');
608 $this->addCSS('width', 'auto', 'mb-label-total');
609 }
610
611
612 }
613
614 public function processDisplay($css = false)
615 {
616 $display = $this->display;
617 $active_displays = $this->display_active;
618
619 foreach($display as $pseudo => $item)
620 {
621 //$normal = $display['normal'];
622 $hides = array();
623
624 if (is_array($item)) // if display list is an array
625 {
626 foreach($item as $i)
627 {
628 if (in_array($i, $active_displays))
629 {
630 $hides = $this->items;
631
632 $statement = 'inline-block';
633
634 $css = $this->addCSS('display',$statement, $this->items[$i], $pseudo, $css);
635 unset($hides[$i]);
636 break;
637 }
638 }
639 }
640 elseif (strpos($item, ',') !== false) // if display list is comma-separated
641 {
642 $show_items = explode(',', $item);
643 $hides = $this->items;
644 foreach($show_items as $i)
645 {
646 unset($hides[$i]);
647 $statement = 'inline-block';
648
649 $css = $this->addCSS('display', $statement, $this->items[$i], $pseudo, $css);
650 }
651 }
652 else { // if display list is just one item.
653 $hides = $this->items;
654 unset($hides[$item]);
655
656 $statement = 'inline-block';
657
658 $css = $this->addCSS('display',$statement,$this->items[$item], $pseudo, $css);
659 }
660
661 foreach($hides as $name => $cname)
662 {
663 $css = $this->addCSS('display','none', $cname, $pseudo, $css);
664 }
665
666 }
667
668 return $css;
669 }
670
671 // Let The style know some display item has been added.
672 public function addDisplay($item)
673 {
674 $this->display_active[] = $item;
675
676 }
677
678 /* Function for changes to CSS ( eg styling exceptions ) after blocks generated CSS. Runs BEFORE the final CSS Parse run */
679 public function preParse($css)
680 {
681 $w = MBSocial()->whistle();
682
683 $css = $this->processDisplay($css);
684 //$w->tell('display/env/has_totals', true);
685
686 $display = $this->display;
687
688 $active_displays = $this->display_active;
689 $effect_active = $this->effect_active;
690
691 $has_totals = $w->ask('display/env/has_totals');
692 if ($has_totals)
693 {
694 $css = $this->addTotal($css);
695 }
696
697 if ($effect_active)
698 {
699 switch($effect_active)
700 {
701 case "flip":
702
703 $items = array('mb-share-count', 'mb-label');
704
705 foreach($items as $item)
706 {
707 if (isset($css[$item]['hover']['display']) && $css[$item]['hover']['display'] != 'none')
708 {
709 $css[$item]['hover']['display'] = 'flex';
710 $css[$item]['normal']['display'] = 'flex';
711 }
712 }
713
714 $css['mb-icon-wrapper']['hover']['display'] = 'flex';
715 $css['mb-icon-wrapper']['normal']['display'] = 'flex';
716 break;
717 case 'stretch':
718 if ( isset( $css['mb-total-container'] ) && isset($css['mb-total-container']['normal']['flex']) )
719 {
720 unset($css['mb-total-container']['normal']['flex']); // remove flex on total container
721 }
722
723 break;
724 case 'lift':
725 case 'shift':
726 case 'drop':
727
728 $items = array('mb-share-count', 'mb-label');
729
730 foreach($items as $item)
731 {
732 if (isset($css[$item]['hover']['display']) && $css[$item]['hover']['display'] != 'none')
733 {
734 $css[$item]['hover']['display'] = 'inline-block';
735 $css[$item]['normal']['display'] = 'inline-block';
736 }
737 }
738 $css['mb-icon-wrapper']['hover']['display'] = 'inline-block';
739 // $css['mb-icon-wrapper']['normal']['display'] = 'inline-block';
740
741
742 break;
743 } // switch
744 } // if
745
746 $this->display_active = array(); // just before parse, prepare for next.
747
748 return $css;
749
750 }
751
752 // function to plug into when the style is set active in a collection. Can be used to hook into style specific layout options.
753
754 public function setActive($collection)
755 {
756 $this->collection = $collection;
757 }
758
759
760 } // class
761