| 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 |
); |
| 44 |
|
| 45 |
return $css_generator->generate_css(); |
| 46 |
// Generate CSS end |
| 47 |
} |
| 48 |
|
| 49 |
public function build_css( $attributes ) { |
| 50 |
if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { |
| 51 |
return $this->build_css_v2( $attributes ); |
| 52 |
} |
| 53 |
return $this->build_css_v1( $attributes ); |
| 54 |
} |
| 55 |
public function get_video_container_css( $attributes, $device = '' ) { |
| 56 |
$css = []; |
| 57 |
if ( ! empty( $attributes['aspectRatio'] ) ) { |
| 58 |
$css['aspect-ratio'] = $attributes['aspectRatio']; |
| 59 |
} |
| 60 |
|
| 61 |
return array_merge( |
| 62 |
$css, |
| 63 |
isset( $attributes['cssFilter'] ) ? CssFilter::get_css( $attributes['cssFilter'], '', $device ) : [], |
| 64 |
); |
| 65 |
} |
| 66 |
} |
| 67 |
|