| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\Paragraph; |
| 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\TextShadow; |
| 12 |
use ABlocks\Controls\TextStroke; |
| 13 |
use ABlocks\Controls\Typography; |
| 14 |
use ABlocks\Classes\CssGeneratorV2; |
| 15 |
use ABlocks\Controls\Color; |
| 16 |
class Block extends BlockBaseAbstract { |
| 17 |
protected $block_name = 'paragraph'; |
| 18 |
public function build_css_v1( $attributes ) { |
| 19 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 20 |
$css_generator->add_class_styles( |
| 21 |
'{{WRAPPER}}', |
| 22 |
$this->get_wrapper_css( $attributes ), |
| 23 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 24 |
$this->get_wrapper_css( $attributes, 'Mobile' ), |
| 25 |
); |
| 26 |
|
| 27 |
$desktop_paragraph_text_style = $this->get_paragraph_text_css( $attributes ); |
| 28 |
|
| 29 |
if ( ! empty( $attributes['textColor'] ) ) { |
| 30 |
$desktop_paragraph_text_style['color'] = $attributes['textColor']; |
| 31 |
} |
| 32 |
$css_generator->add_class_styles( |
| 33 |
'{{WRAPPER}} .ablocks-paragraph-text', |
| 34 |
$desktop_paragraph_text_style, |
| 35 |
$this->get_paragraph_text_css( $attributes, 'Tablet' ), |
| 36 |
$this->get_paragraph_text_css( $attributes, 'Mobile' ), |
| 37 |
); |
| 38 |
|
| 39 |
$css_generator->add_class_styles( |
| 40 |
'{{WRAPPER}} .ablocks-paragraph-text-drop-caps::first-letter', |
| 41 |
$this->get_paragraph_drop_text_css( $attributes ), |
| 42 |
$this->get_paragraph_drop_text_css( $attributes, 'Tablet' ), |
| 43 |
$this->get_paragraph_drop_text_css( $attributes, 'Mobile' ), |
| 44 |
); |
| 45 |
|
| 46 |
return $css_generator->generate_css(); |
| 47 |
} |
| 48 |
public function build_css_v2( $attributes ) { |
| 49 |
$css_generator = new CssGeneratorV2( $attributes, $this->block_name ); |
| 50 |
$css_generator->add_class_styles( |
| 51 |
'{{WRAPPER}}', |
| 52 |
$this->get_wrapper_css( $attributes ), |
| 53 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 54 |
$this->get_wrapper_css( $attributes, 'Mobile' ), |
| 55 |
); |
| 56 |
|
| 57 |
$css_generator->add_class_styles( |
| 58 |
'{{WRAPPER}} .ablocks-paragraph-text', |
| 59 |
$this->get_paragraph_text_css( $attributes ), |
| 60 |
$this->get_paragraph_text_css( $attributes, 'Tablet' ), |
| 61 |
$this->get_paragraph_text_css( $attributes, 'Mobile' ), |
| 62 |
); |
| 63 |
|
| 64 |
$css_generator->add_class_styles( |
| 65 |
'{{WRAPPER}} .ablocks-paragraph-text-drop-caps::first-letter', |
| 66 |
$this->get_paragraph_drop_text_css( $attributes ), |
| 67 |
$this->get_paragraph_drop_text_css( $attributes, 'Tablet' ), |
| 68 |
$this->get_paragraph_drop_text_css( $attributes, 'Mobile' ), |
| 69 |
); |
| 70 |
return $css_generator->generate_css(); |
| 71 |
} |
| 72 |
|
| 73 |
public function build_css( $attributes ) { |
| 74 |
if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { |
| 75 |
return $this->build_css_v2( $attributes ); |
| 76 |
} |
| 77 |
return $this->build_css_v1( $attributes ); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 82 |
return isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : []; |
| 83 |
} |
| 84 |
|
| 85 |
public function get_paragraph_text_css( $attributes, $device = '' ) { |
| 86 |
$typographyValueGlobal = ! empty( $attributes['typographyGlobal'] ) ? $attributes['typographyGlobal'] : array(); |
| 87 |
return array_merge( |
| 88 |
[ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ], |
| 89 |
isset( $attributes['typography'] ) ? Typography::get_css( $attributes['typography'], '', $device, $typographyValueGlobal ) : [], |
| 90 |
isset( $attributes['textStroke'] ) ? TextStroke::get_css( $attributes['textStroke'], '', $device ) : [], |
| 91 |
isset( $attributes['textShadow'] ) ? TextShadow::get_css( $attributes['textShadow'], '', $device ) : [], |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
public function get_paragraph_drop_text_css( $attributes, $device = '' ) { |
| 96 |
return [ 'color' => Color::get_css( isset( $attributes['dropCapsTextColor'] ) ? $attributes['dropCapsTextColor'] : '' ) ]; |
| 97 |
} |
| 98 |
} |
| 99 |
|