| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\EcmReactionList; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
use ABlocks\Classes\BlockBaseAbstract; |
| 10 |
use ABlocks\Classes\CssGenerator; |
| 11 |
use ABlocks\Helper; |
| 12 |
use ABlocks\Controls\Typography; |
| 13 |
use ABlocks\Controls\Background; |
| 14 |
use ABlocks\Controls\Border; |
| 15 |
use ABlocks\Controls\Dimensions; |
| 16 |
use ABlocks\Controls\Range; |
| 17 |
use ABlocks\Controls\BoxShadow; |
| 18 |
use ABlocks\Controls\Color; |
| 19 |
use ABlocks\Controls\Alignment; |
| 20 |
|
| 21 |
class Block extends BlockBaseAbstract { |
| 22 |
protected $block_name = 'ecm-reaction-list'; |
| 23 |
|
| 24 |
public function build_css( $attributes ) { |
| 25 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 26 |
|
| 27 |
$css_generator->add_class_styles( |
| 28 |
'{{WRAPPER}} p.ecm-shortcode--reaction__list-title', |
| 29 |
$this->getTitleTextCSS( $attributes ), |
| 30 |
$this->getTitleTextCSS( $attributes, 'Tablet' ), |
| 31 |
$this->getTitleTextCSS( $attributes, 'Mobile' ) |
| 32 |
); |
| 33 |
$css_generator->add_class_styles( |
| 34 |
'{{WRAPPER}} ul.ecm-shortcode--reaction__list', |
| 35 |
$this->get_alignment_css( $attributes ), |
| 36 |
$this->get_alignment_css( $attributes, 'Tablet' ), |
| 37 |
$this->get_alignment_css( $attributes, 'Mobile' ) |
| 38 |
); |
| 39 |
$css_generator->add_class_styles( |
| 40 |
'{{WRAPPER}} p.ecm-shortcode--reaction__list-meta', |
| 41 |
$this->getListTextCSS( $attributes ), |
| 42 |
$this->getListTextCSS( $attributes, 'Tablet' ), |
| 43 |
$this->getListTextCSS( $attributes, 'Mobile' ) |
| 44 |
); |
| 45 |
$css_generator->add_class_styles( |
| 46 |
'{{WRAPPER}} div.ecm-shortcode--reaction', |
| 47 |
$this->nobookmarksTextCSS( $attributes ), |
| 48 |
$this->nobookmarksTextCSS( $attributes, 'Tablet' ), |
| 49 |
$this->nobookmarksTextCSS( $attributes, 'Mobile' ) |
| 50 |
); |
| 51 |
return $css_generator->generate_css(); |
| 52 |
} |
| 53 |
|
| 54 |
public function render_block_content( $attributes, $content, $block_instance ) { |
| 55 |
$attr_array = [ |
| 56 |
'user_id' => Helper::get_attribute_value( $attributes, 'user_id' ), |
| 57 |
'not_found_text' => Helper::get_attribute_value( $attributes, 'not_found_text' ), |
| 58 |
]; |
| 59 |
|
| 60 |
// if ( isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) && empty( $attr_array['product_id'] ) ) { |
| 61 |
// $attr_array['product_id'] = $block_instance->context['postId']; |
| 62 |
// } |
| 63 |
|
| 64 |
// // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
| 65 |
// if ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) ) { |
| 66 |
// $attr_array['dummy'] = true; |
| 67 |
// } |
| 68 |
|
| 69 |
$shortcode = '[ecm_reaction_list ' . Helper::attr_shortcode( $attr_array ) . ']'; |
| 70 |
echo do_shortcode( $shortcode ); |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
public function getTitleTextCSS( $attributes, $device = '' ) { |
| 75 |
// $typographyGlobal = ( isset( $attributes['couponTypographyGlobal'] ) ? $attributes['couponTypographyGlobal'] : '' ); |
| 76 |
return array_merge( |
| 77 |
[ 'color' => Color::get_css( isset( $attributes['reacTitleColor'] ) ? $attributes['reacTitleColor'] : '' ) ], |
| 78 |
|
| 79 |
Typography::get_css( $attributes['reacTitleTypography'], '', $device ), |
| 80 |
|
| 81 |
); |
| 82 |
} |
| 83 |
public function get_alignment_css( $attributes, $device = '' ) { |
| 84 |
$css = [ |
| 85 |
'flex-direction' => 'column', |
| 86 |
'display' => 'flex' |
| 87 |
]; |
| 88 |
|
| 89 |
if ( isset( $attributes['reactionAlignment'] ) ) { |
| 90 |
$css = array_merge( $css, Alignment::get_css( $attributes['reactionAlignment'], 'align-items', $device ) ); |
| 91 |
$css = array_merge( $css, Alignment::get_css( $attributes['reactionAlignment'], 'text-align', $device ) ); |
| 92 |
$css['list-style-type'] = $attributes['reactionUlStyle']; |
| 93 |
} |
| 94 |
return array_merge( |
| 95 |
[ 'color' => Color::get_css( isset( $attributes['reacTitleColor'] ) ? $attributes['reacTitleColor'] : '' ) ], |
| 96 |
Typography::get_css( $attributes['reacTitleTypography'], '', $device ), |
| 97 |
$css, |
| 98 |
); |
| 99 |
} |
| 100 |
public function getListTextCSS( $attributes, $device = '' ) { |
| 101 |
// $typographyGlobal = ( isset( $attributes['couponTypographyGlobal'] ) ? $attributes['couponTypographyGlobal'] : '' ); |
| 102 |
return array_merge( |
| 103 |
[ 'color' => Color::get_css( isset( $attributes['reacListColor'] ) ? $attributes['reacListColor'] : '' ) ], |
| 104 |
|
| 105 |
Typography::get_css( $attributes['reacListTypography'], '', $device ), |
| 106 |
|
| 107 |
); |
| 108 |
} |
| 109 |
public function nobookmarksTextCSS( $attributes, $device = '' ) { |
| 110 |
$css = ['flex-direction' => 'column']; |
| 111 |
|
| 112 |
if ( isset( $attributes['reactionAlignment'] ) ) { |
| 113 |
$css = array_merge( $css, Alignment::get_css( $attributes['reactionAlignment'], 'align-items', $device ) ); |
| 114 |
} |
| 115 |
return array_merge( |
| 116 |
[ 'color' => Color::get_css( isset( $attributes['nobookmarksColor'] ) ? $attributes['nobookmarksColor'] : '' ) ], |
| 117 |
|
| 118 |
Typography::get_css( $attributes['nobookmarksTypography'], '', $device ), |
| 119 |
$css, |
| 120 |
); |
| 121 |
} |
| 122 |
} |
| 123 |
|