PluginProbe
Hello Plus / 1.4.0
Hello Plus v1.4.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / content / classes / render / widget-cta-render.php

widget-cta-render.php in Hello Plus 1.4.0, at modules/content/classes/render/widget-cta-render.php

198 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace HelloPlus\Modules\Content\Classes\Render;
3
4 use HelloPlus\Modules\Content\Widgets\CTA;
5 use HelloPlus\Classes\{
6 Ehp_Button,
7 Ehp_Image,
8 Ehp_Shapes,
9 };
10
11 use Elementor\Utils;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 class Widget_CTA_Render {
18 protected CTA $widget;
19 const LAYOUT_CLASSNAME = 'ehp-cta';
20
21 protected array $settings;
22
23 public function __construct( CTA $widget ) {
24 $this->widget = $widget;
25 $this->settings = $widget->get_settings_for_display();
26 }
27
28 public function render(): void {
29 $layout_classnames = [
30 self::LAYOUT_CLASSNAME,
31 'has-preset-' . $this->settings['layout_preset'],
32 ];
33 $layout_full_height_controls = $this->settings['box_full_screen_height_controls'] ?? '';
34
35 $show_image = 'storytelling' === $this->settings['layout_preset'] || 'showcase' === $this->settings['layout_preset'];
36 $image_stretch = $this->settings['image_stretch'];
37 $has_border = $this->settings['show_box_border'];
38
39 if ( ! empty( $layout_full_height_controls ) ) {
40 foreach ( $layout_full_height_controls as $breakpoint ) {
41 $layout_classnames[] = ' is-full-height-' . $breakpoint;
42 }
43 }
44
45 if ( 'yes' === $image_stretch ) {
46 $layout_classnames[] = 'has-image-stretch';
47 }
48
49 if ( 'yes' === $has_border ) {
50 $layout_classnames[] = 'has-border';
51 }
52
53 $shapes = new Ehp_Shapes( $this->widget, [
54 'container_prefix' => 'box',
55 'render_attribute' => 'layout',
56 'widget_name' => $this->widget->get_name(),
57 ] );
58 $shapes->add_shape_attributes();
59
60 $this->widget->add_render_attribute( 'layout', [
61 'class' => $layout_classnames,
62 ] );
63
64 $elements_container_classnames = [
65 'ehp-cta__elements-container',
66 ];
67 $image_position = $this->settings['image_horizontal_position'];
68 $image_position_tablet = $this->settings['image_horizontal_position_tablet'];
69 $image_position_mobile = $this->settings['image_horizontal_position_mobile'];
70
71 if ( ! empty( $image_position ) ) {
72 $elements_container_classnames[] = 'has-image-position-' . $image_position;
73
74 if ( ! empty( $image_position_tablet ) ) {
75 $elements_container_classnames[] = 'has-image-position-md-' . $image_position_tablet;
76 }
77
78 if ( ! empty( $image_position_mobile ) ) {
79 $elements_container_classnames[] = 'has-image-position-sm-' . $image_position_mobile;
80 }
81 }
82
83 $this->widget->add_render_attribute( 'elements-container', [
84 'class' => $elements_container_classnames,
85 ] );
86 ?>
87 <div <?php $this->widget->print_render_attribute_string( 'layout' ); ?>>
88 <div class="ehp-cta__overlay"></div>
89 <div <?php $this->widget->print_render_attribute_string( 'elements-container' ); ?>>
90 <?php
91 if ( $show_image ) {
92 $this->render_image_container();
93 }
94 $this->render_text_container();
95
96 if ( 'showcase' !== $this->settings['layout_preset'] ) {
97 $this->render_ctas_container();
98 }
99 ?>
100 </div>
101 </div>
102 <?php
103 }
104
105 protected function render_image_container() {
106 $image = new Ehp_Image( $this->widget, [
107 'widget_name' => $this->widget->get_name(),
108 ] );
109 $image->render();
110 }
111
112 protected function render_text_container() {
113 $heading_text = $this->settings['heading_text'];
114 $heading_tag = $this->settings['heading_tag'];
115 $has_heading = '' !== $heading_text;
116
117 $description_text = $this->settings['description_text'];
118 $description_tag = $this->settings['description_tag'];
119 $has_description = '' !== $description_text;
120
121 $text_container_classnames = [ 'ehp-cta__text-container' ];
122
123 $this->widget->add_render_attribute( 'text-container', [
124 'class' => $text_container_classnames,
125 ] );
126 ?>
127 <div <?php $this->widget->print_render_attribute_string( 'text-container' ); ?>>
128 <?php if ( $has_heading ) {
129 $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 ) );
130 // Escaped above
131 Utils::print_unescaped_internal_string( $heading_output );
132 } ?>
133 <?php if ( $has_description ) {
134 $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 ) );
135 // Escaped above
136 Utils::print_unescaped_internal_string( $description_output );
137 } ?>
138
139 <?php
140 if ( 'showcase' === $this->settings['layout_preset'] ) {
141 $this->render_ctas_container();
142 } ?>
143 </div>
144 <?php
145 }
146
147 protected function render_ctas_container() {
148 $buttons_width = $this->settings['cta_width'];
149 $buttons_width_tablet = $this->settings['cta_width_tablet'];
150 $buttons_width_mobile = $this->settings['cta_width_mobile'];
151
152 $buttons_wrapper_classnames = [ 'ehp-cta__buttons-wrapper' ];
153
154 $this->widget->add_render_attribute( 'buttons-wrapper', [
155 'class' => $buttons_wrapper_classnames,
156 ] );
157
158 $ctas_container_wrapper = [ 'ehp-cta__ctas-container' ];
159
160 if ( $buttons_width ) {
161 $ctas_container_wrapper[] = 'has-cta-width-' . $buttons_width;
162
163 if ( $buttons_width_tablet ) {
164 $ctas_container_wrapper[] = 'has-cta-width-md-' . $buttons_width_tablet;
165 }
166
167 if ( $buttons_width_mobile ) {
168 $ctas_container_wrapper[] = 'has-cta-width-sm-' . $buttons_width_mobile;
169 }
170 }
171
172 $this->widget->add_render_attribute( 'ctas-container', [
173 'class' => $ctas_container_wrapper,
174 ] );
175
176 ?>
177 <div <?php $this->widget->print_render_attribute_string( 'ctas-container' ); ?>>
178 <div <?php $this->widget->print_render_attribute_string( 'buttons-wrapper' ); ?>>
179 <?php if ( ! empty( $this->settings['primary_cta_button_text'] ) ) {
180 $this->render_button( 'primary' );
181 } ?>
182 <?php if ( ! empty( $this->settings['secondary_cta_button_text'] ) ) {
183 $this->render_button( 'secondary' );
184 } ?>
185 </div>
186 </div>
187 <?php
188 }
189
190 public function render_button( $type ) {
191 $button = new Ehp_Button( $this->widget, [
192 'type' => $type,
193 'widget_name' => $this->widget->get_name(),
194 ] );
195 $button->render();
196 }
197 }
198