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-contact-render.php

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

374 lines 12.6 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\Contact;
5 use HelloPlus\Classes\{
6 Ehp_Button,
7 Ehp_Image,
8 Ehp_Shapes,
9 Ehp_Social_Platforms,
10 };
11
12 use Elementor\{
13 Icons_Manager,
14 Utils,
15 };
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit; // Exit if accessed directly.
19 }
20
21 class Widget_Contact_Render {
22 protected Contact $widget;
23 const LAYOUT_CLASSNAME = 'ehp-contact';
24
25 protected array $settings;
26
27 public function render(): void {
28 $layout_classnames = [
29 self::LAYOUT_CLASSNAME,
30 'has-preset-' . $this->settings['layout_preset'],
31 ];
32 $layout_full_height_controls = $this->settings['box_full_screen_height_controls'] ?? '';
33 $show_map = 'quick-info' !== $this->settings['layout_preset'];
34
35 if ( 'yes' === $this->settings['show_box_border'] ) {
36 $layout_classnames[] = 'has-border';
37 }
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' === $this->settings['map_stretch'] ) {
46 $layout_classnames[] = 'has-map-stretch';
47 }
48
49 $elements_container_classnames = [
50 self::LAYOUT_CLASSNAME . '__elements-container',
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 if ( ! empty( $this->settings['map_position_horizontal'] ) ) {
61 $elements_container_classnames[] = 'has-map-h-position-' . $this->settings['map_position_horizontal'];
62
63 if ( ! empty( $this->settings['map_position_horizontal_tablet'] ) ) {
64 $elements_container_classnames[] = 'has-map-h-position-md-' . $this->settings['map_position_horizontal_tablet'];
65 }
66
67 if ( ! empty( $this->settings['map_position_horizontal_mobile'] ) ) {
68 $elements_container_classnames[] = 'has-map-h-position-sm-' . $this->settings['map_position_horizontal_mobile'];
69 }
70 }
71
72 if ( ! empty( $this->settings['map_position_vertical'] ) ) {
73 $elements_container_classnames[] = 'has-map-v-position-' . $this->settings['map_position_vertical'];
74
75 if ( ! empty( $this->settings['map_position_vertical_tablet'] ) ) {
76 $elements_container_classnames[] = 'has-map-v-position-md-' . $this->settings['map_position_vertical_tablet'];
77 }
78
79 if ( ! empty( $this->settings['map_position_vertical_mobile'] ) ) {
80 $elements_container_classnames[] = 'has-map-v-position-sm-' . $this->settings['map_position_vertical_mobile'];
81 }
82 }
83
84 $this->widget->add_render_attribute( 'layout', [
85 'class' => $layout_classnames,
86 ] );
87
88 $this->widget->add_render_attribute( 'elements-container', [
89 'class' => $elements_container_classnames,
90 ] );
91 ?>
92 <div <?php $this->widget->print_render_attribute_string( 'layout' ); ?>>
93 <div class="<?php echo esc_attr( self::LAYOUT_CLASSNAME ); ?>__overlay"></div>
94 <div <?php $this->widget->print_render_attribute_string( 'elements-container' ); ?>>
95 <?php
96 $this->render_text_container();
97
98 if ( $show_map ) {
99 $this->render_map_container();
100 }
101 ?>
102 </div>
103 </div>
104 <?php
105 }
106
107 protected function render_text_container() {
108 $heading_text = $this->settings['heading_text'];
109 $heading_tag = $this->settings['heading_tag'];
110
111 $description_text = $this->settings['description_text'];
112 $description_tag = $this->settings['description_tag'];
113
114 $text_container_classnames = [
115 self::LAYOUT_CLASSNAME . '__text-container',
116 ];
117 $heading_classname = self::LAYOUT_CLASSNAME . '__heading';
118 $description_classname = self::LAYOUT_CLASSNAME . '__description';
119
120 $this->widget->add_render_attribute( 'text-container', [
121 'class' => $text_container_classnames,
122 ] );
123 ?>
124 <div <?php $this->widget->print_render_attribute_string( 'text-container' ); ?>>
125 <div class="<?php echo esc_attr( self::LAYOUT_CLASSNAME ); ?>__headings">
126 <?php if ( '' !== $heading_text ) {
127 $heading_output = sprintf( '<%1$s class="%2$s">%3$s</%1$s>', Utils::validate_html_tag( $heading_tag ), $heading_classname, esc_html( $heading_text ) );
128 // Escaped above
129 Utils::print_unescaped_internal_string( $heading_output );
130 } ?>
131 <?php if ( '' !== $description_text ) {
132 $description_output = sprintf( '<%1$s class="%2$s">%3$s</%1$s>', Utils::validate_html_tag( $description_tag ), $description_classname, esc_html( $description_text ) );
133 // Escaped above
134 Utils::print_unescaped_internal_string( $description_output );
135 } ?>
136 </div>
137 <div class="<?php echo esc_attr( self::LAYOUT_CLASSNAME ); ?>__groups">
138 <?php
139 $this->render_contact_group( '1' );
140
141 if ( 'yes' === $this->settings['group_2_switcher'] ) {
142 $this->render_contact_group( '2' );
143 }
144 if ( 'yes' === $this->settings['group_3_switcher'] ) {
145 $this->render_contact_group( '3' );
146 }
147 if ( 'yes' === $this->settings['group_4_switcher'] ) {
148 $this->render_contact_group( '4' );
149 }
150 ?>
151 </div>
152 </div>
153 <?php
154 }
155
156 protected function render_contact_group( $group_number ) {
157 $group_type = $this->settings[ 'group_' . $group_number . '_type' ];
158 ?>
159 <div class="<?php echo esc_attr( self::LAYOUT_CLASSNAME ); ?>__group">
160 <?php
161 if ( 'contact-links' === $group_type ) {
162 $this->render_contact_links_group( $group_number );
163 } elseif ( 'text' === $group_type ) {
164 $this->render_contact_text_group( $group_number );
165 } elseif ( 'social-icons' === $group_type ) {
166 $this->render_social_icons_group( $group_number );
167 }
168 ?>
169 </div>
170 <?php
171 }
172
173 protected function render_subheading( $group_number, $subheading_type ) {
174 $subheading_text = $this->settings[ 'group_' . $group_number . '_' . $subheading_type . '_subheading' ];
175 $subheading_tag = $this->settings['subheading_tag'];
176
177 if ( '' !== $subheading_text ) {
178 $subheading_output = sprintf( '<%1$s class="%3$s">%2$s</%1$s>', Utils::validate_html_tag( $subheading_tag ), esc_html( $subheading_text ), self::LAYOUT_CLASSNAME . '__subheading' );
179 // Escaped above
180 Utils::print_unescaped_internal_string( $subheading_output );
181 }
182 }
183
184 protected function render_contact_links_group( $group_number ) {
185 $this->render_subheading( $group_number, 'links' );
186 $this->render_contact_links( $group_number );
187 }
188
189 protected function render_contact_links( $group_number ) {
190 $repeater = $this->settings[ 'group_' . $group_number . '_repeater' ];
191 $hover_animation = $this->settings['contact_details_text_hover_animation'];
192
193 $ehp_platforms = new Ehp_Social_Platforms( $this->widget );
194 ?>
195 <div class="<?php echo esc_attr( self::LAYOUT_CLASSNAME ); ?>__links-container">
196 <?php
197 foreach ( $repeater as $key => $contact_link ) {
198 $link = [
199 'platform' => $contact_link[ 'group_' . $group_number . '_platform' ],
200 'number' => $contact_link[ 'group_' . $group_number . '_number' ] ?? '',
201 'username' => $contact_link[ 'group_' . $group_number . '_username' ] ?? '',
202 'email_data' => [
203 'group_' . $group_number . '_mail' => $contact_link[ 'group_' . $group_number . '_mail' ] ?? '',
204 'group_' . $group_number . '_mail_subject' => $contact_link[ 'group_' . $group_number . '_mail_subject' ] ?? '',
205 'group_' . $group_number . '_mail_body' => $contact_link[ 'group_' . $group_number . '_mail_body' ] ?? '',
206 ],
207 'viber_action' => $contact_link[ 'group_' . $group_number . '_viber_action' ] ?? '',
208 'url' => $contact_link[ 'group_' . $group_number . '_url' ] ?? '',
209 'location' => $contact_link[ 'group_' . $group_number . '_waze' ] ?? '',
210 'map' => $contact_link[ 'group_' . $group_number . '_map' ] ?? '',
211 ];
212
213 $icon = $contact_link[ 'group_' . $group_number . '_icon' ];
214
215 $contact_link_classnames = [ self::LAYOUT_CLASSNAME . '__contact-link' ];
216
217 if ( ! empty( $hover_animation ) ) {
218 $contact_link_classnames[] = 'elementor-animation-' . $hover_animation;
219 }
220
221 $this->widget->add_render_attribute( 'contact-link-' . $key, [
222 'aria-label' => esc_attr( $contact_link[ 'group_' . $group_number . '_label' ] ),
223 'class' => $contact_link_classnames,
224 ] );
225
226 if ( $ehp_platforms->is_url_link( $contact_link[ 'group_' . $group_number . '_platform' ] ) ) {
227 $ehp_platforms->render_link_attributes( $link, 'contact-link-' . $key );
228 } else {
229 $formatted_link = $ehp_platforms->get_formatted_link( $link, 'contact_icon' );
230
231 $this->widget->add_render_attribute( 'contact-link-' . $key, [
232 'href' => $formatted_link,
233 'rel' => 'noopener noreferrer',
234 ] );
235 }
236
237 ?>
238 <a <?php $this->widget->print_render_attribute_string( 'contact-link-' . $key ); ?>>
239 <?php Icons_Manager::render_icon( $icon,
240 [
241 'aria-hidden' => 'true',
242 'class' => self::LAYOUT_CLASSNAME . '__contact-link-icon',
243 ]
244 ); ?>
245 <span class="<?php echo esc_attr( self::LAYOUT_CLASSNAME ); ?>__contact-link-label"><?php echo esc_html( $contact_link[ 'group_' . $group_number . '_label' ] ); ?></span>
246 </a>
247 <?php
248 } ?>
249 </div>
250 <?php
251 }
252
253 protected function render_contact_text_group( $group_number ) {
254 $text_text = $this->settings[ 'group_' . $group_number . '_text_textarea' ];
255
256 $this->render_subheading( $group_number, 'text' );
257
258 if ( '' !== $text_text ) {
259 $text_output = sprintf( '<div class="%2$s">%1$s</div>', esc_html( $text_text ), self::LAYOUT_CLASSNAME . '__contact-text' );
260 // Escaped above
261 Utils::print_unescaped_internal_string( $text_output );
262 }
263 }
264
265 protected function render_social_icons_group( $group_number ) {
266 $repeater = $this->settings[ 'group_' . $group_number . '_social_repeater' ];
267
268 $this->render_subheading( $group_number, 'social' );
269 ?>
270 <div class="<?php echo esc_attr( self::LAYOUT_CLASSNAME ); ?>__social-icons-container">
271 <?php
272 foreach ( $repeater as $key => $social_icon ) {
273 $icon = $social_icon[ 'group_' . $group_number . '_social_icon' ] ?? [];
274 $label = $social_icon[ 'group_' . $group_number . '_social_label' ] ?? '';
275 $url = $social_icon[ 'group_' . $group_number . '_social_link' ] ?? [];
276 $hover_animation = $this->settings['contact_details_social_icon_hover_animation'];
277
278 $social_icon_classnames = [ self::LAYOUT_CLASSNAME . '__social-link' ];
279
280 if ( ! empty( $hover_animation ) ) {
281 $social_icon_classnames[] = 'elementor-animation-' . $hover_animation;
282 }
283
284 $this->widget->add_render_attribute( 'social-icon-' . $key, [
285 'aria-label' => esc_attr( $label ),
286 'class' => $social_icon_classnames,
287 'rel' => 'noopener noreferrer',
288 ] );
289
290 if ( ! empty( $url['url'] ) ) {
291 $this->widget->add_link_attributes( 'social-icon-' . $key, $url );
292 }
293 ?>
294 <a <?php $this->widget->print_render_attribute_string( 'social-icon-' . $key ); ?>>
295 <?php Icons_Manager::render_icon( $icon,
296 [
297 'aria-hidden' => 'true',
298 'class' => self::LAYOUT_CLASSNAME . '__contact-social-icon',
299 ]
300 ); ?>
301 </a>
302 <?php
303 }
304 ?>
305 </div>
306 <?php
307 }
308
309 protected function render_map_container() {
310 $map_container_classnames = [
311 self::LAYOUT_CLASSNAME . '__map-container',
312 ];
313
314 if ( 0 === absint( $this->settings['map_zoom']['size'] ) ) {
315 $this->settings['map_zoom']['size'] = 10;
316 }
317
318 $api_key = esc_html( get_option( 'elementor_google_maps_api_key' ) );
319
320 $params = [
321 rawurlencode( $this->settings['map_address'] ),
322 absint( $this->settings['map_zoom']['size'] ),
323 ];
324
325 if ( $api_key ) {
326 $params[] = $api_key;
327
328 $url = 'https://www.google.com/maps/embed/v1/place?key=%3$s&q=%1$s&amp;zoom=%2$d';
329 } else {
330 $url = 'https://maps.google.com/maps?q=%1$s&amp;t=m&amp;z=%2$d&amp;output=embed&amp;iwloc=near';
331 }
332
333 $this->widget->add_render_attribute( 'map-container', [
334 'class' => $map_container_classnames,
335 ] );
336
337 $map_classnames = [
338 self::LAYOUT_CLASSNAME . '__map',
339 'elementor-custom-embed',
340 ];
341
342 if ( 'yes' === $this->settings['show_map_border'] ) {
343 $map_classnames[] = 'has-border';
344 }
345
346 $shapes = new Ehp_Shapes( $this->widget, [
347 'container_prefix' => 'map',
348 'render_attribute' => 'map',
349 'widget_name' => $this->widget->get_name(),
350 ] );
351 $shapes->add_shape_attributes();
352
353 $this->widget->add_render_attribute( 'map', [
354 'class' => $map_classnames,
355 ] );
356 ?>
357 <div <?php $this->widget->print_render_attribute_string( 'map-container' ); ?>>
358 <div <?php $this->widget->print_render_attribute_string( 'map' ); ?>>
359 <iframe loading="lazy"
360 src="<?php echo esc_url( vsprintf( $url, $params ) ); ?>"
361 title="<?php echo esc_attr( $this->settings['map_address'] ); ?>"
362 aria-label="<?php echo esc_attr( $this->settings['map_address'] ); ?>"
363 ></iframe>
364 </div>
365 </div>
366 <?php
367 }
368
369 public function __construct( Contact $widget ) {
370 $this->widget = $widget;
371 $this->settings = $widget->get_settings_for_display();
372 }
373 }
374