PluginProbe
Hello Plus / 1.7.0
Hello Plus v1.7.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.7.0, at modules/content/classes/render/widget-contact-render.php

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