| 1 |
<?php |
| 2 |
|
| 3 |
namespace HelloPlus\Modules\Content\Classes\Render; |
| 4 |
|
| 5 |
use Elementor\Group_Control_Background; |
| 6 |
use Elementor\Group_Control_Box_Shadow; |
| 7 |
use Elementor\Group_Control_Image_Size; |
| 8 |
use Elementor\Group_Control_Typography; |
| 9 |
use Elementor\Controls_Manager; |
| 10 |
use Elementor\Icons_Manager; |
| 11 |
use Elementor\Repeater; |
| 12 |
use Elementor\Widget_Base; |
| 13 |
use Elementor\Utils; |
| 14 |
|
| 15 |
use HelloPlus\Modules\Content\Widgets\CTA; |
| 16 |
use HelloPlus\Classes\Ehp_Button; |
| 17 |
|
| 18 |
class Widget_CTA_Render { |
| 19 |
protected CTA $widget; |
| 20 |
const LAYOUT_CLASSNAME = 'ehp-cta'; |
| 21 |
|
| 22 |
protected array $settings; |
| 23 |
|
| 24 |
public function __construct( CTA $widget ) { |
| 25 |
$this->widget = $widget; |
| 26 |
$this->settings = $widget->get_settings_for_display(); |
| 27 |
} |
| 28 |
|
| 29 |
public function render(): void { |
| 30 |
$layout_classnames = [ |
| 31 |
self::LAYOUT_CLASSNAME, |
| 32 |
'has-preset-' . $this->settings['layout_preset'], |
| 33 |
]; |
| 34 |
$layout_full_height_controls = $this->settings['box_full_screen_height_controls'] ?? ''; |
| 35 |
|
| 36 |
$show_image = 'storytelling' === $this->settings['layout_preset'] || 'showcase' === $this->settings['layout_preset']; |
| 37 |
$image_stretch = $this->settings['image_stretch']; |
| 38 |
$has_border = $this->settings['show_box_border']; |
| 39 |
|
| 40 |
$box_shape = $this->settings['box_shape']; |
| 41 |
$box_shape_mobile = $this->settings['box_shape_mobile']; |
| 42 |
$box_shape_tablet = $this->settings['box_shape_tablet']; |
| 43 |
|
| 44 |
if ( ! empty( $layout_full_height_controls ) ) { |
| 45 |
foreach ( $layout_full_height_controls as $breakpoint ) { |
| 46 |
$layout_classnames[] = ' is-full-height-' . $breakpoint; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
if ( 'yes' === $image_stretch ) { |
| 51 |
$layout_classnames[] = 'has-image-stretch'; |
| 52 |
} |
| 53 |
|
| 54 |
if ( 'yes' === $has_border ) { |
| 55 |
$layout_classnames[] = 'has-border'; |
| 56 |
} |
| 57 |
|
| 58 |
if ( ! empty( $box_shape ) ) { |
| 59 |
$layout_classnames[] = 'has-shape-' . $box_shape; |
| 60 |
|
| 61 |
if ( ! empty( $box_shape_mobile ) ) { |
| 62 |
$layout_classnames[] = 'has-shape-sm-' . $box_shape_mobile; |
| 63 |
} |
| 64 |
|
| 65 |
if ( ! empty( $box_shape_tablet ) ) { |
| 66 |
$layout_classnames[] = 'has-shape-md-' . $box_shape_tablet; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
$this->widget->add_render_attribute( 'layout', [ |
| 71 |
'class' => $layout_classnames, |
| 72 |
] ); |
| 73 |
|
| 74 |
$elements_container_classnames = [ |
| 75 |
'ehp-cta__elements-container', |
| 76 |
]; |
| 77 |
$image_position = $this->settings['image_horizontal_position']; |
| 78 |
$image_position_tablet = $this->settings['image_horizontal_position_tablet']; |
| 79 |
$image_position_mobile = $this->settings['image_horizontal_position_mobile']; |
| 80 |
|
| 81 |
if ( ! empty( $image_position ) ) { |
| 82 |
$elements_container_classnames[] = 'has-image-position-' . $image_position; |
| 83 |
|
| 84 |
if ( ! empty( $image_position_tablet ) ) { |
| 85 |
$elements_container_classnames[] = 'has-image-position-md-' . $image_position_tablet; |
| 86 |
} |
| 87 |
|
| 88 |
if ( ! empty( $image_position_mobile ) ) { |
| 89 |
$elements_container_classnames[] = 'has-image-position-sm-' . $image_position_mobile; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
$this->widget->add_render_attribute( 'elements-container', [ |
| 94 |
'class' => $elements_container_classnames, |
| 95 |
] ); |
| 96 |
?> |
| 97 |
<div <?php $this->widget->print_render_attribute_string( 'layout' ); ?>> |
| 98 |
<div class="ehp-cta__overlay"></div> |
| 99 |
<div <?php $this->widget->print_render_attribute_string( 'elements-container' ); ?>> |
| 100 |
<?php |
| 101 |
if ( $show_image ) { |
| 102 |
$this->render_image_container(); |
| 103 |
} |
| 104 |
$this->render_text_container(); |
| 105 |
|
| 106 |
if ( 'showcase' !== $this->settings['layout_preset'] ) { |
| 107 |
$this->render_ctas_container(); |
| 108 |
} |
| 109 |
?> |
| 110 |
</div> |
| 111 |
</div> |
| 112 |
<?php |
| 113 |
} |
| 114 |
|
| 115 |
protected function render_text_container() { |
| 116 |
$heading_text = $this->settings['heading_text']; |
| 117 |
$heading_tag = $this->settings['heading_tag']; |
| 118 |
$has_heading = '' !== $heading_text; |
| 119 |
|
| 120 |
$description_text = $this->settings['description_text']; |
| 121 |
$description_tag = $this->settings['description_tag']; |
| 122 |
$has_description = '' !== $description_text; |
| 123 |
|
| 124 |
$text_container_classnames = [ 'ehp-cta__text-container' ]; |
| 125 |
|
| 126 |
$this->widget->add_render_attribute( 'text-container', [ |
| 127 |
'class' => $text_container_classnames, |
| 128 |
] ); |
| 129 |
?> |
| 130 |
<div <?php $this->widget->print_render_attribute_string( 'text-container' ); ?>> |
| 131 |
<?php if ( $has_heading ) { |
| 132 |
$heading_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $heading_tag ), 'class="ehp-cta__heading"', esc_html( $heading_text ) ); |
| 133 |
// Escaped above |
| 134 |
Utils::print_unescaped_internal_string( $heading_output ); |
| 135 |
} ?> |
| 136 |
<?php if ( $has_description ) { |
| 137 |
$description_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $description_tag ), 'class="ehp-cta__description"', esc_html( $description_text ) ); |
| 138 |
// Escaped above |
| 139 |
Utils::print_unescaped_internal_string( $description_output ); |
| 140 |
} ?> |
| 141 |
|
| 142 |
<?php |
| 143 |
if ( 'showcase' === $this->settings['layout_preset'] ) { |
| 144 |
$this->render_ctas_container(); |
| 145 |
} ?> |
| 146 |
</div> |
| 147 |
<?php |
| 148 |
} |
| 149 |
|
| 150 |
protected function render_ctas_container() { |
| 151 |
$buttons_width = $this->settings['cta_width']; |
| 152 |
$buttons_width_tablet = $this->settings['cta_width_tablet']; |
| 153 |
$buttons_width_mobile = $this->settings['cta_width_mobile']; |
| 154 |
|
| 155 |
$buttons_wrapper_classnames = [ 'ehp-cta__buttons-wrapper' ]; |
| 156 |
|
| 157 |
if ( $buttons_width ) { |
| 158 |
$buttons_wrapper_classnames[] = 'has-cta-width-' . $buttons_width; |
| 159 |
|
| 160 |
if ( $buttons_width_tablet ) { |
| 161 |
$buttons_wrapper_classnames[] = 'has-cta-width-md-' . $buttons_width_tablet; |
| 162 |
} |
| 163 |
|
| 164 |
if ( $buttons_width_mobile ) { |
| 165 |
$buttons_wrapper_classnames[] = 'has-cta-width-sm-' . $buttons_width_mobile; |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
$this->widget->add_render_attribute( 'buttons-wrapper', [ |
| 170 |
'class' => $buttons_wrapper_classnames, |
| 171 |
] ); |
| 172 |
?> |
| 173 |
<div class="ehp-cta__ctas-container"> |
| 174 |
<div <?php $this->widget->print_render_attribute_string( 'buttons-wrapper' ); ?>> |
| 175 |
<?php if ( ! empty( $this->settings['primary_cta_button_text'] ) ) { |
| 176 |
$this->render_button( 'primary' ); |
| 177 |
} ?> |
| 178 |
<?php if ( ! empty( $this->settings['secondary_cta_button_text'] ) ) { |
| 179 |
$this->render_button( 'secondary' ); |
| 180 |
} ?> |
| 181 |
</div> |
| 182 |
</div> |
| 183 |
<?php |
| 184 |
} |
| 185 |
|
| 186 |
public function render_button( $type ) { |
| 187 |
$button = new Ehp_Button( $this->widget, [ |
| 188 |
'type' => $type, |
| 189 |
'widget_name' => 'cta', |
| 190 |
] ); |
| 191 |
$button->render(); |
| 192 |
} |
| 193 |
|
| 194 |
public function get_attachment_image_html_filter( $html ) { |
| 195 |
$image_classnames = 'ehp-flex-hero__img'; |
| 196 |
$image_shape = $this->settings['image_shape']; |
| 197 |
$image_shape_mobile = $this->settings['image_shape_mobile']; |
| 198 |
$image_shape_tablet = $this->settings['image_shape_tablet']; |
| 199 |
|
| 200 |
$has_border = $this->settings['show_image_border']; |
| 201 |
|
| 202 |
if ( 'yes' === $has_border ) { |
| 203 |
$image_classnames .= ' has-border'; |
| 204 |
} |
| 205 |
|
| 206 |
if ( ! empty( $image_shape ) ) { |
| 207 |
$image_classnames .= ' has-shape-' . $image_shape; |
| 208 |
|
| 209 |
if ( ! empty( $image_shape_mobile ) ) { |
| 210 |
$image_classnames .= ' has-shape-sm-' . $image_shape_mobile; |
| 211 |
} |
| 212 |
|
| 213 |
if ( ! empty( $image_shape_tablet ) ) { |
| 214 |
$image_classnames .= ' has-shape-md-' . $image_shape_tablet; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
$html = str_replace( '<img ', '<img class="' . esc_attr( $image_classnames ) . '" ', $html ); |
| 219 |
return $html; |
| 220 |
} |
| 221 |
|
| 222 |
public function render_image_container() { |
| 223 |
$image = $this->settings['image']; |
| 224 |
$has_image = ! empty( $image['url'] ); |
| 225 |
$image_wrapper_classnames = 'ehp-cta__image-container'; |
| 226 |
|
| 227 |
$this->widget->add_render_attribute( 'image', [ |
| 228 |
'class' => $image_wrapper_classnames, |
| 229 |
] ); |
| 230 |
|
| 231 |
if ( $has_image ) : |
| 232 |
?> |
| 233 |
<div <?php $this->widget->print_render_attribute_string( 'image' ); ?>> |
| 234 |
<?php |
| 235 |
add_filter( 'elementor/image_size/get_attachment_image_html', [ $this, 'get_attachment_image_html_filter' ], 10, 4 ); |
| 236 |
Group_Control_Image_Size::print_attachment_image_html( $this->settings, 'image' ); |
| 237 |
remove_filter( 'elementor/image_size/get_attachment_image_html', [ $this, 'get_attachment_image_html_filter' ], 10 ); |
| 238 |
?> |
| 239 |
</div> |
| 240 |
<?php |
| 241 |
endif; //has_image |
| 242 |
} |
| 243 |
} |
| 244 |
|