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

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