| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\QRCode; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Classes\BlockBaseAbstract; |
| 9 |
use ABlocks\Classes\CssGenerator; |
| 10 |
use ABlocks\Controls\Alignment; |
| 11 |
use ABlocks\Controls\Range; |
| 12 |
use ABlocks\Classes\CssGeneratorV2; |
| 13 |
|
| 14 |
class Block extends BlockBaseAbstract { |
| 15 |
protected $block_name = 'qr-code'; |
| 16 |
|
| 17 |
|
| 18 |
public function build_css_v1( $attributes ) { |
| 19 |
// Generate CSS start |
| 20 |
$css_generator = new CssGenerator( $attributes ); |
| 21 |
return $css_generator->generate_css(); |
| 22 |
|
| 23 |
} |
| 24 |
public function build_css_v2( $attributes ) { |
| 25 |
// Generate CSS start |
| 26 |
$css_generator = new CssGenerator( $attributes ); |
| 27 |
$css_generator->add_class_styles( |
| 28 |
'{{WRAPPER}}.ablocks-block--qr-code:not(.ablocks-block-container), |
| 29 |
{{WRAPPER}}.ablocks-block--qr-code .ablocks-block-container', |
| 30 |
$this->get_qr_code_css( $attributes ), |
| 31 |
$this->get_qr_code_css( $attributes, 'Tablet' ), |
| 32 |
$this->get_qr_code_css( $attributes, 'Mobile' ) |
| 33 |
); |
| 34 |
return $css_generator->generate_css(); |
| 35 |
|
| 36 |
} |
| 37 |
public function build_css( $attributes ) { |
| 38 |
if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { |
| 39 |
return $this->build_css_v2( $attributes ); |
| 40 |
} |
| 41 |
return $this->build_css_v1( $attributes ); |
| 42 |
} |
| 43 |
public function get_qr_code_css( $attributes, $device = '' ) { |
| 44 |
$qr_code_css = Range::get_css( [] ); |
| 45 |
|
| 46 |
if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) { |
| 47 |
$qr_code_css['justify-content'] = $attributes['alignment'][ 'value' . $device ]; |
| 48 |
$qr_code_css['display'] = 'flex'; |
| 49 |
} |
| 50 |
return array_merge( |
| 51 |
$qr_code_css |
| 52 |
); |
| 53 |
} |
| 54 |
} |
| 55 |
|