PluginProbe
Social Share Buttons / 1.12
Social Share Buttons v1.12
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.12, at classes/class-style.php

769 lines 19.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\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 //$css = $this->addCSS('transition', 'opacity 1.2s linear', 'mb-icon-wrapper', 'normal', $css);
195 //$css = $this->addCSS('transition', 'opacity 1.2s linear', 'mb-label', 'hover', $css);
196
197 break;
198 case 'lift':
199 $line_height = intval($args['line_height']) * 1.5;
200
201 //$this->addCSS('overflow', 'hidden', 'collection-item');
202 $css = $this->addCSS('transform', 'translateY(-10px)', 'mb-icon-wrapper', 'hover', $css);
203 $css = $this->addCSS('transition', 'all .2s linear', 'mb-icon-wrapper', 'normal', $css);
204
205 $normcss = array(
206 'bottom' => '-' . $line_height . 'px',
207 'z-index' => 'auto',
208 'background' => 'transparent',
209 'position' => 'absolute',
210 'line-height' => $line_height . 'px',
211 'transition' => 'bottom .2s linear',
212 //'z-index' => '-1',
213 'width' => '100%',
214
215 );
216
217 $css = $this->addCSS($normcss, '', 'mb-label', 'normal', $css);
218 $css = $this->addCSS($normcss, '', 'mb-share-count', 'normal', $css);
219
220 $hovercss = array(
221 'bottom' => '0px',
222 'background' => 'transparent',
223
224 );
225
226 $css = $this->addCSS($hovercss, '', 'mb-label', 'hover', $css);
227 $css = $this->addCSS($hovercss, '', 'mb-share-count', 'hover', $css);
228
229 $css = $this->addCSS('overflow', 'hidden', 'mb-social', 'normal', $css);
230
231 break;
232 case 'none':
233
234 $this->display['hover'] = 'icon';
235 //$css = $this->addCSS('display', 'none', 'mb-label', 'hover', $css);
236 //$css = $this->addCSS('display', 'none', 'mb-share-count','hover', $css);
237 break;
238 case 'shift':
239 $this->display = array('normal' => 'icon,count',
240 'hover' => 'icon,label,count');
241 $line_height = $args['line_height'];
242
243 $css = $this->addCSS('overflow', 'hidden','mb-social', 'normal', $css);
244
245 $css = $this->addCSS( array(
246 'position' => 'absolute',
247 'bottom' => '3px',
248 'height' => $line_height,
249 'z-index' => '1',
250 'transition' => 'all .2s ease-in-out',
251 'background' => 'transparent',
252 'right' => 0,
253 'left' => 0,
254 ),
255 '',
256 'mb-share-count',
257 'normal',
258 $css);
259
260 $css = $this->addCSS ( array(
261 'transform' => 'translateX(60px)',
262 'bottom' => '0',
263 'background' => 'transparent',
264 ),
265 '',
266 'mb-share-count',
267 'hover',
268 $css
269 );
270
271 $css = $this->addCSS ( array (
272 'transform' => 'translateX(-60px)',
273 'position' => 'absolute',
274 'bottom' => 0,
275 'transition' => 'all .2s ease-in-out',
276 'background-color' => 'transparent',
277 'left' => 0,
278 'text-align' => 'center',
279 'width' => '100%',
280 'height' => $line_height,
281 ),
282 '',
283 'mb-label',
284 'normal',
285 $css
286 );
287
288 $css = $this->addCSS ( array (
289 'transform' => 'translateX(0px)',
290 'z-index' => '1',
291 'bottom' => '3px',
292 'background-color' => 'transparent',
293 ),
294 '',
295 'mb-label',
296 'hover',
297 $css
298 );
299
300 $css = $this->addCSS ('transform', 'translateY(-8px)', 'mb-icon-wrapper', 'hover', $css);
301 $css = $this->addCSS ('transition', 'all .2s ease-in-out', 'mb-icon-wrapper', 'normal', $css);
302
303 break;
304 case 'stretch':
305 $this->display = array('normal' => 'icon,count',
306 'hover' => 'icon,label,count');
307 $css = $this->addStretch($css,$args);
308
309 break;
310 case 'transform':
311 $scale = intval($args['scale']);
312 $scale = $scale / 10;
313 //$css['mb-social']['hover']['transform'] = 'scale(' . $scale . ')';
314 //$css['mb-social']['hover']['transform'] = 'scale(' . $scale . ')';
315 $css = $this->addCSS('transform', 'scale('. $scale . ')', 'mb-social','hover', $css);
316 break;
317 }
318
319 return $css;
320 }
321
322 protected function addStretch($css, $args)
323 {
324 $css = $this->addCSS('display', 'flex', 'maxsocial', 'normal', $css);
325
326 $css = $this->addCSS('flex', '1.2', 'mb-item', 'hover', $css);
327
328 $itemcss = array(
329 'flex' => 1,
330 'float' => 'left',
331 'height' => '100%',
332 '-webkit-transition' => 'all .2s linear',
333 'transition' => 'all .2s linear',
334 );
335 $css = $this->addCSS($itemcss, '','mb-item', 'normal', $css);
336
337 $css = $this->addCSS ( array (
338 'display' => 'block',
339 'display' => '-webkit-box',
340 'display' => '-webkit-flex',
341 'display' => '-moz-box',
342 'display' => '-ms-flexbox',
343 'display' => 'flex',
344 'text-transform' => 'none',
345 '-webkit-flex-flow' => 'row wrap',
346 '-ms-flex-flow' => 'row wrap',
347 'flex-flow' => 'row wrap',
348 'width' => '100%',
349 ),
350 '',
351 'mb-social', 'normal', $css);
352
353 $css = $this->addCSS('flex', '1.2', 'mb-social', 'hover', $css);
354
355 // the label
356 $css = $this->addCSS ( array (
357 'text-align' => 'center',
358 'flex-grow' => 3,
359 'margin' => 'auto',
360 'display' => 'none',
361 'opacity' => 0,
362 '-webkit-transition' => 'all .4s linear',
363 'transition' => 'all .4s linear',
364 ),
365 '',
366 'mb-label',
367 'normal',
368 $css
369 );
370
371 // label hover
372 $css = $this->addCSS( array(
373 'display' => 'inline-block',
374 'opacity' => '1',
375
376 ),
377 '',
378 'mb-label',
379 'hover',
380 $css
381
382 );
383
384 $css = $this->addCSS ( array (
385 'text-align' => 'center',
386 'flex-grow' => 2,
387 'margin' => 'auto',
388 ),
389 '',
390 'mb-icon-wrapper',
391 'normal',
392 $css
393 );
394
395 $css = $this->addCSS ( array (
396 // 'font-size' => '16px',
397 'margin' => 'auto 0',
398 //'flex-grow' => '1',
399 'display' => 'inline-block',
400 'transform' => 'translateX(-10px)',
401 ),
402 '',
403 'mb-share-count',
404 'normal',
405 $css
406 );
407
408 $css = $this->addCSS('flex-grow', '1', 'mb-share-count', 'hover', $css);
409
410 return $css;
411 }
412
413 /* Total element is counting all shares and displays some label */
414 protected function addTotal($css)
415 {
416 // total main element
417 //$this->addFlex('maxbutton-social-total');
418 $styleBlock = $this->collection->getBlock('styleBlock');
419 $layoutBlock = $this->collection->getBlock('layoutBlock');
420
421 $width = $styleBlock->getValue('mbs-width');
422 $height = $styleBlock->getValue('mbs-height');
423
424 // $this->css['maxbutton-social-total'];
425 //$width = $css['mb-social']['normal']['width'];
426 //$height = $css['mb-social']['normal']['height'];
427
428 /*$width = isset($css['mbsocial']['normal']['width']) ? $css['mbsocial']['normal']['width'] : 'auto';
429 $height = isset($css['mbsocial']['normal']['height']) ? $css['mbsocial']['normal']['height'] : 'auto';
430 */
431 $width = maxUtils::strip_px($width);
432 $height = maxUtils::strip_px($height);
433
434 // copy mb-item and put it to mb-item-total. Not going to be exactly the same.
435 $itemcss = $css['mb-item'];
436
437 $css = $this->addCSS($itemcss['normal'], '', 'mb-total-container', 'normal', $css);
438
439 $margin = maxUtils::strip_px($layoutBlock->getValue('button_spacing'));
440
441 if ($this->collection->orientation == 'vertical')
442 {
443 $width = $width . 'px';
444 $height = '100%';
445 }
446 else { // horizontal
447 $width = ($width + $margin) * 2;
448 $width = $width . 'px';
449 $height = $height . 'px';
450 }
451
452 // attempt to auto-custmz.
453 $count_size = (isset($css['mb-share-count']['normal']['font-size'])) ? $css['mb-share-count']['normal']['font-size'] : '13';
454 $count_size = maxUtils::strip_px($count_size);
455
456 $total_count_size = $count_size * 1.5;
457
458
459 $css = $this->addCSS ( array(
460 'width' => $width,
461 'height' => $height,
462 'display' => 'flex',
463 'align-items' => 'center',
464 'justify-content' => 'center',
465 //'font-size' => '16px',
466 ),
467 '',
468 'maxbutton-social-total',
469 'normal',
470 $css
471 );
472
473
474 $css = $this->addCSS ( array(
475 //'float' => 'left',
476 'font-size' => '20px',
477 'width' => '45%',
478 'text-align' => 'left',
479 'height' => 'inherit',
480 //'height' => 'inherit',
481 'display' => 'flex',
482 'align-items' => 'center',
483 'justify-content' => 'center',
484 ),
485 '',
486 'mb-icon-total',
487 'normal',
488 $css
489 );
490
491 $css = $this->addCSS ( array ( // *sigh*
492 'font-size' => '35px',
493 //'height' => 'auto',
494 'vertical-align' => 'top',
495 ),
496 '',
497 'mb-icon-total-icon',
498 'before',
499 $css
500 );
501
502 $css = $this->addCSS ( array (
503 'width' => '35px',
504 'height' => '35px'
505 ),
506 '',
507 'mb-icon-total-icon',
508 'normal',
509 $css
510 );
511
512 $css = $this->addCSS ( array (
513 //'float' => 'right',
514 'clear' => 'right',
515 'text-align' => 'center',
516 // 'width' => '45%',
517 'text-transform' => 'uppercase',
518 'font-size' => '13px',
519 ),
520 '',
521 'mb-label-total',
522 'normal',
523 $css
524 );
525
526 $css = $this->addCSS ( array (
527 //'float' => 'right',
528 'text-align' => 'center',
529 'font-size' => $total_count_size .'px',
530
531 ),
532 '',
533 'mb-count-total',
534 'normal',
535 $css
536 );
537
538
539 return $css;
540 }
541
542
543 public function addCSS($name, $value = '', $element = 'mb-social', $pseudo = 'normal', $css = false)
544 {
545 if (! $css && !isset($this->css[$element][$pseudo]))
546 {
547 $this->css[$element][$pseudo] = array();
548 }
549 if ($css && !isset($css[$element][$pseudo]))
550 {
551 $css[$element][$pseudo] = array();
552 }
553
554 if ( is_array($name))
555 {
556 foreach ($name as $n => $v)
557 {
558 if ($css)
559 $css[$element][$pseudo][$n] = $v;
560 else
561 {
562 $this->css[$element][$pseudo][$n] = $v;
563 }
564 }
565
566 }
567 else
568 {
569 if ($css)
570 {
571 $css[$element][$pseudo][$name] = $value;
572 }
573 else
574 $this->css[$element][$pseudo][$name] = $value;
575 }
576
577 if ($css)
578 return $css;
579 }
580
581
582
583
584 /* 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 */
585 public function prepareCSS($args)
586 {
587
588 $default_args = array(
589 'orientation' => 'horizontal',
590 'is_static' => false,
591 'is_post' => false,
592 'is_mobile' => false,
593 'is_tablet' => false,
594 );
595
596 $args = wp_parse_args($args, $default_args);
597
598 if ($args['orientation'] == 'vertical')
599 {
600 $this->addCSS(array(
601 /* 'width' => $this->width . 'px',
602 'height' => $this->height . 'px', */
603 // 'width' => '100%',
604 'flex-direction' => 'column'
605 ),
606 '',
607 'maxbutton-social-total'
608 );
609
610 $this->addCSS('display', 'none', 'mb-icon-total');
611 $this->addCSS('width', 'auto', 'mb-label-total');
612 }
613
614
615 }
616
617 public function processDisplay($css = false)
618 {
619 $display = $this->display;
620 $active_displays = $this->display_active;
621
622 foreach($display as $pseudo => $item)
623 {
624 //$normal = $display['normal'];
625 $hides = array();
626
627 if (is_array($item)) // if display list is an array
628 {
629 foreach($item as $i)
630 {
631 if (in_array($i, $active_displays))
632 {
633 $hides = $this->items;
634
635 $statement = 'inline-block';
636
637 $css = $this->addCSS('display',$statement, $this->items[$i], $pseudo, $css);
638 // $css = $this->addCSS('opacity','1', $this->items[$i], $pseudo, $css);
639 unset($hides[$i]);
640 break;
641 }
642 }
643 }
644 elseif (strpos($item, ',') !== false) // if display list is comma-separated
645 {
646 $show_items = explode(',', $item);
647 $hides = $this->items;
648 foreach($show_items as $i)
649 {
650 unset($hides[$i]);
651 $statement = 'inline-block';
652
653 $css = $this->addCSS('display', $statement, $this->items[$i], $pseudo, $css);
654 //$css = $this->addCSS('opacity', '1', $this->items[$i], $pseudo, $css);
655 }
656 }
657 else { // if display list is just one item.
658 $hides = $this->items;
659 unset($hides[$item]);
660
661 $statement = 'inline-block';
662
663
664 $css = $this->addCSS('display',$statement,$this->items[$item], $pseudo, $css);
665 //$css = $this->addCSS('opacity','1',$this->items[$item], $pseudo, $css);
666 }
667
668 foreach($hides as $name => $cname)
669 {
670 $css = $this->addCSS('display','none', $cname, $pseudo, $css);
671 //$css = $this->addCSS('opacity','0', $cname, $pseudo, $css);
672 }
673
674 }
675
676 return $css;
677 }
678
679 // Let The style know some display item has been added.
680 public function addDisplay($item)
681 {
682 $this->display_active[] = $item;
683
684 }
685
686 /* Function for changes to CSS ( eg styling exceptions ) after blocks generated CSS. Runs BEFORE the final CSS Parse run */
687 public function preParse($css)
688 {
689 $w = MBSocial()->whistle();
690
691 $css = $this->processDisplay($css);
692 //$w->tell('display/env/has_totals', true);
693
694 $display = $this->display;
695
696 $active_displays = $this->display_active;
697 $effect_active = $this->effect_active;
698
699 $has_totals = $w->ask('display/env/has_totals');
700 if ($has_totals)
701 {
702 $css = $this->addTotal($css);
703 }
704
705 if ($effect_active)
706 {
707 switch($effect_active)
708 {
709 case "flip":
710
711 $items = array('mb-share-count', 'mb-label');
712
713 foreach($items as $item)
714 {
715 if (isset($css[$item]['hover']['display']) && $css[$item]['hover']['display'] != 'none')
716 {
717 $css[$item]['hover']['display'] = 'flex';
718 $css[$item]['normal']['display'] = 'flex';
719 }
720 }
721
722 $css['mb-icon-wrapper']['hover']['display'] = 'flex';
723 $css['mb-icon-wrapper']['normal']['display'] = 'flex';
724 break;
725 case 'stretch':
726 if ( isset( $css['mb-total-container'] ) && isset($css['mb-total-container']['normal']['flex']) )
727 {
728 unset($css['mb-total-container']['normal']['flex']); // remove flex on total container
729 }
730
731 break;
732 case 'lift':
733 case 'shift':
734 case 'drop':
735
736 $items = array('mb-share-count', 'mb-label');
737
738 foreach($items as $item)
739 {
740 if (isset($css[$item]['hover']['display']) && $css[$item]['hover']['display'] != 'none')
741 {
742 $css[$item]['hover']['display'] = 'inline-block';
743 $css[$item]['normal']['display'] = 'inline-block';
744 }
745 }
746 $css['mb-icon-wrapper']['hover']['display'] = 'inline-block';
747 // $css['mb-icon-wrapper']['normal']['display'] = 'inline-block';
748
749
750 break;
751 } // switch
752 } // if
753
754 $this->display_active = array(); // just before parse, prepare for next.
755
756 return $css;
757
758 }
759
760 // function to plug into when the style is set active in a collection. Can be used to hook into style specific layout options.
761
762 public function setActive($collection)
763 {
764 $this->collection = $collection;
765 }
766
767
768 } // class
769