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
BackgroundImage.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kubio\Core\Background; |
| 4 | |
| 5 | use Kubio\Core\Element; |
| 6 | use Kubio\Core\ElementBase; |
| 7 | use Kubio\Core\Utils; |
| 8 | use Kubio\Core\StyleManager\Props\BackgroundImage as BackgroundImageProp; |
| 9 | use Kubio\Core\StyleManager\Props\Background; |
| 10 | |
| 11 | class BackgroundImage extends ElementBase { |
| 12 | function __construct( $value ) { |
| 13 | parent::__construct( $value, BackgroundDefaults::getDefaultImage() ); |
| 14 | } |
| 15 | |
| 16 | function wrapperComputedStyle() { |
| 17 | |
| 18 | if ( $this->useParallaxScript() ) { |
| 19 | $url = $this->get( '0.source.url' ); |
| 20 | $url = kubio_wpml_get_translated_media_url( $url ); |
| 21 | $style['backgroundImage'] = "url(\"$url\")"; |
| 22 | } else { |
| 23 | $image = $this->getMergedValue(); |
| 24 | $image = $image[0]; |
| 25 | |
| 26 | $bg = new Background( 'background' ); |
| 27 | $bgImage = new BackgroundImageProp( $image, $bg->config( 'default' ) ); |
| 28 | $style = $bgImage->toStyle(); |
| 29 | } |
| 30 | if ( $this->useFeaturedImage() ) { |
| 31 | $url = get_the_post_thumbnail_url( null, 'full' ); |
| 32 | $url = kubio_wpml_get_translated_media_url( $url ); |
| 33 | $style['backgroundImage'] = "url(\"$url\")"; |
| 34 | } |
| 35 | |
| 36 | return $style; |
| 37 | } |
| 38 | |
| 39 | function useParallaxScript() { |
| 40 | return $this->get( '0.useParallax' ); |
| 41 | } |
| 42 | function useFeaturedImage() { |
| 43 | return $this->get( '0.useFeaturedImage' ); |
| 44 | } |
| 45 | function useBackgroundLayer() { |
| 46 | return $this->get( '0.forceBackgroundLayer' ); |
| 47 | } |
| 48 | function getClasses() { |
| 49 | $classes = array( 'background-layer' ); |
| 50 | if ( $this->useParallaxScript() ) { |
| 51 | $classes[] = 'paraxify'; |
| 52 | } |
| 53 | if ( $this->useBackgroundLayer() ) { |
| 54 | $classes[] = 'forceBackgroundLayer'; |
| 55 | } |
| 56 | |
| 57 | return $classes; |
| 58 | } |
| 59 | |
| 60 | function __toString() { |
| 61 | $classes = $this->getClasses(); |
| 62 | |
| 63 | $scriptData = Utils::useJSComponentProps( |
| 64 | 'parallax', |
| 65 | array( |
| 66 | 'enabled' => $this->useParallaxScript(), |
| 67 | 'test' => 'temp', |
| 68 | ) |
| 69 | ); |
| 70 | |
| 71 | return new Element( |
| 72 | Element::DIV, |
| 73 | array_merge( |
| 74 | $scriptData, |
| 75 | array( |
| 76 | 'style' => $this->wrapperComputedStyle(), |
| 77 | 'className' => $classes, |
| 78 | ) |
| 79 | ) |
| 80 | ) . ''; |
| 81 | } |
| 82 | } |
| 83 |