| @@ -1,0 +1,67 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocks\Blocks\Video; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocks\Classes\BlockBaseAbstract; | |
| 9 | +use ABlocks\Classes\CssGenerator; | |
| 10 | +use ABlocks\Classes\CssGeneratorV2; | |
| 11 | +use ABlocks\Controls\CssFilter; | |
| 12 | + | |
| 13 | +class Block extends BlockBaseAbstract { | |
| 14 | + protected $block_name = 'video'; | |
| 15 | + | |
| 16 | + public function build_css_v1( $attributes ) { | |
| 17 | + | |
| 18 | + // Generate CSS start | |
| 19 | + $css_generator = new CssGenerator( $attributes, $this->block_name ); | |
| 20 | + | |
| 21 | + // Video Container CSS | |
| 22 | + $css_generator->add_class_styles( | |
| 23 | + '{{WRAPPER}} .ablocks-block-container', | |
| 24 | + $this->get_video_container_css( $attributes ), | |
| 25 | + $this->get_video_container_css( $attributes, 'Tablet' ), | |
| 26 | + $this->get_video_container_css( $attributes, 'Mobile' ), | |
| 27 | + ); | |
| 28 | + | |
| 29 | + return $css_generator->generate_css(); | |
| 30 | + // Generate CSS end | |
| 31 | + } | |
| 32 | + public function build_css_v2( $attributes ) { | |
| 33 | + | |
| 34 | + // Generate CSS start | |
| 35 | + $css_generator = new CssGeneratorV2( $attributes, $this->block_name ); | |
| 36 | + | |
| 37 | + // Video Container CSS | |
| 38 | + $css_generator->add_class_styles( | |
| 39 | + '{{WRAPPER}}', | |
| 40 | + $this->get_video_container_css( $attributes ), | |
| 41 | + $this->get_video_container_css( $attributes, 'Tablet' ), | |
| 42 | + $this->get_video_container_css( $attributes, 'Mobile' ), | |
| 43 | + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_video_container_css( $attributes, $device ); } ) | |
| 44 | + ); | |
| 45 | + | |
| 46 | + return $css_generator->generate_css(); | |
| 47 | + // Generate CSS end | |
| 48 | + } | |
| 49 | + | |
| 50 | + public function build_css( $attributes ) { | |
| 51 | + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { | |
| 52 | + return $this->build_css_v2( $attributes ); | |
| 53 | + } | |
| 54 | + return $this->build_css_v1( $attributes ); | |
| 55 | + } | |
| 56 | + public function get_video_container_css( $attributes, $device = '' ) { | |
| 57 | + $css = []; | |
| 58 | + if ( ! empty( $attributes['aspectRatio'] ) ) { | |
| 59 | + $css['aspect-ratio'] = $attributes['aspectRatio']; | |
| 60 | + } | |
| 61 | + | |
| 62 | + return array_merge( | |
| 63 | + $css, | |
| 64 | + isset( $attributes['cssFilter'] ) ? CssFilter::get_css( $attributes['cssFilter'], '', $device ) : [], | |
| 65 | + ); | |
| 66 | + } | |
| 67 | +} | |