PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / trunk
Kubio AI Page Builder vtrunk
2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / Core / Background / Background.php
kubio / lib / src / Core / Background Last commit date
Background.php 1 year ago BackgroundDefaults.php 2 years ago BackgroundImage.php 1 year ago BackgroundOverlay.php 1 year ago BackgroundSlideshow.php 1 year ago BackgroundVideo.php 1 year ago
Background.php
103 lines
1 <?php
2
3 namespace Kubio\Core\Background;
4
5 use Kubio\Config;
6 use Kubio\Core\Element;
7 use Kubio\Core\LodashBasic;
8 use Kubio\Core\Styles\Utils;
9
10 class Background extends Element {
11
12 private $backgroundByType = array(
13 'video' => BackgroundVideo::class,
14 'slideshow' => BackgroundSlideshow::class,
15 'image' => BackgroundImage::class,
16 );
17
18 function __construct( $tag_name, $props, $children, $block = null ) {
19 $this->default = BackgroundDefaults::getDefaultBackground();
20
21 if ( $block ) {
22 $this->value = $block->backgroundByMedia();
23 }
24
25 $bgs = array();
26
27 $default = LodashBasic::get( $this->value, 'desktop', array() );
28 foreach ( $this->value as $media => $value_on_media ) {
29 if ( $media !== 'desktop' ) {
30 $value_on_media = LodashBasic::merge( $default, $value_on_media );
31 }
32 $bgs[] = $this->backgroundOnMedia( $media, $value_on_media );
33 }
34
35 parent::__construct(
36 Element::DIV,
37 LodashBasic::merge(
38 array(
39 'className' => 'background-wrapper',
40 ),
41 $props
42 ),
43 $bgs,
44 $block
45 );
46 }
47
48
49 function backgroundOnMedia( $media, $value ) {
50 $mergedValue = LodashBasic::merge( $this->default, $value );
51 $types = Config::value( 'props.background.enums.types' );
52
53 $children = array();
54 if ( isset( $value['overlay'] ) ) {
55 $enabled = LodashBasic::get( $value, 'overlay.enabled', false );
56 if ( $enabled ) {
57 $children[] = new BackgroundOverlay( $value['overlay'] );
58 }
59 }
60
61 $type = LodashBasic::get( $mergedValue, 'type', $types['NONE'] );
62 if ( $type !== $types['NONE'] ) {
63 if ( isset( $this->backgroundByType[ $type ] ) && $this->backgroundLayerIsEnabled( $mergedValue ) ) {
64 $BackgroundClass = $this->backgroundByType[ $type ];
65 $children[] = new $BackgroundClass( LodashBasic::get( $value, $type ) );
66 }
67 }
68
69 return new Element(
70 Element::DIV,
71 array(
72 'className' => $this->backgroundOnMediaClass( $media ),
73 ),
74 $children,
75 $this->block
76 );
77 }
78
79 function backgroundOnMediaClass( $media ) {
80 $className = Utils::composeClassForMedia(
81 $media,
82 '',
83 'background-layer-media-container',
84 true
85 );
86
87 return array( 'background-layer', $className );
88 }
89
90 function backgroundLayerIsEnabled( $background ) {
91 $type = LodashBasic::get( $background, 'type' );
92 switch ( $type ) {
93 case 'image':
94 $useParallax = LodashBasic::get( $background, 'image.0.useParallax', false );
95 $useFeaturedImage = LodashBasic::get( $background, 'image.0.useFeaturedImage', false );
96 $forceBackgroundLayer = LodashBasic::get( $background, 'image.0.forceBackgroundLayer', false );
97 return ! ! $useParallax || ! ! $useFeaturedImage || ! ! $forceBackgroundLayer;
98 default:
99 return true;
100 }
101 }
102 }
103