| 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->widget->add_render_attribute( 'group', 'class', self::LAYOUT_CLASSNAME . '__group' ); |
| 130 |
|
| 131 |
$this->render_contact_group( '1' ); |
| 132 |
|
| 133 |
if ( 'yes' === $this->settings['group_2_switcher'] ) { |
| 134 |
$this->render_contact_group( '2' ); |
| 135 |
} |
| 136 |
if ( 'yes' === $this->settings['group_3_switcher'] ) { |
| 137 |
$this->render_contact_group( '3' ); |
| 138 |
} |
| 139 |
if ( 'yes' === $this->settings['group_4_switcher'] ) { |
| 140 |
$this->render_contact_group( '4' ); |
| 141 |
} |
| 142 |
?> |
| 143 |
</div> |
| 144 |
</div> |
| 145 |
<?php |
| 146 |
} |
| 147 |
|
| 148 |
protected function render_contact_group( $group_number ) { |
| 149 |
$group_type = $this->settings[ 'group_' . $group_number . '_type' ]; |
| 150 |
|
| 151 |
?> |
| 152 |
<div <?php $this->widget->print_render_attribute_string( 'group' ); ?>> |
| 153 |
<?php |
| 154 |
if ( 'contact-links' === $group_type ) { |
| 155 |
$this->render_contact_links_group( $group_number ); |
| 156 |
} elseif ( 'text' === $group_type ) { |
| 157 |
$this->render_contact_text_group( $group_number ); |
| 158 |
} elseif ( 'social-icons' === $group_type ) { |
| 159 |
$this->render_social_icons_group( $group_number ); |
| 160 |
} |
| 161 |
?> |
| 162 |
</div> |
| 163 |
<?php |
| 164 |
} |
| 165 |
|
| 166 |
protected function render_subheading( $group_number, $subheading_type ) { |
| 167 |
$subheading_text = $this->settings[ 'group_' . $group_number . '_' . $subheading_type . '_subheading' ]; |
| 168 |
$subheading_tag = $this->settings['subheading_tag']; |
| 169 |
$subheading_classname = self::LAYOUT_CLASSNAME . '__subheading'; |
| 170 |
|
| 171 |
Widget_Utils::maybe_render_text_html( $this->widget, 'group_' . $group_number . '_' . $subheading_type . '_subheading', $subheading_classname, $subheading_text, $subheading_tag ); |
| 172 |
} |
| 173 |
|
| 174 |
protected function render_contact_links_group( $group_number ) { |
| 175 |
$this->render_subheading( $group_number, 'links' ); |
| 176 |
$this->render_contact_links( $group_number ); |
| 177 |
} |
| 178 |
|
| 179 |
protected function render_contact_links( $group_number ) { |
| 180 |
$repeater = $this->settings[ 'group_' . $group_number . '_repeater' ]; |
| 181 |
$hover_animation = $this->settings['contact_details_text_hover_animation']; |
| 182 |
|
| 183 |
$ehp_platforms = new Ehp_Social_Platforms( $this->widget ); |
| 184 |
|
| 185 |
$this->widget->add_render_attribute( 'links-container', 'class', self::LAYOUT_CLASSNAME . '__links-container' ); |
| 186 |
?> |
| 187 |
<div <?php $this->widget->print_render_attribute_string( 'links-container' ); ?>> |
| 188 |
<?php |
| 189 |
foreach ( $repeater as $key => $contact_link ) { |
| 190 |
$link = [ |
| 191 |
'platform' => $contact_link[ 'group_' . $group_number . '_platform' ], |
| 192 |
'number' => $contact_link[ 'group_' . $group_number . '_number' ] ?? '', |
| 193 |
'username' => $contact_link[ 'group_' . $group_number . '_username' ] ?? '', |
| 194 |
'email_data' => [ |
| 195 |
'group_' . $group_number . '_mail' => $contact_link[ 'group_' . $group_number . '_mail' ] ?? '', |
| 196 |
'group_' . $group_number . '_mail_subject' => $contact_link[ 'group_' . $group_number . '_mail_subject' ] ?? '', |
| 197 |
'group_' . $group_number . '_mail_body' => $contact_link[ 'group_' . $group_number . '_mail_body' ] ?? '', |
| 198 |
], |
| 199 |
'viber_action' => $contact_link[ 'group_' . $group_number . '_viber_action' ] ?? '', |
| 200 |
'url' => $contact_link[ 'group_' . $group_number . '_url' ] ?? '', |
| 201 |
'location' => $contact_link[ 'group_' . $group_number . '_waze' ] ?? '', |
| 202 |
'map' => $contact_link[ 'group_' . $group_number . '_map' ] ?? '', |
| 203 |
]; |
| 204 |
|
| 205 |
$icon = $contact_link[ 'group_' . $group_number . '_icon' ]; |
| 206 |
|
| 207 |
$contact_link_classnames = [ self::LAYOUT_CLASSNAME . '__contact-link' ]; |
| 208 |
|
| 209 |
if ( ! empty( $hover_animation ) ) { |
| 210 |
$contact_link_classnames[] = 'elementor-animation-' . $hover_animation; |
| 211 |
} |
| 212 |
|
| 213 |
$this->widget->add_render_attribute( 'contact-link-' . $key, [ |
| 214 |
'aria-label' => esc_attr( $contact_link[ 'group_' . $group_number . '_label' ] ), |
| 215 |
'class' => $contact_link_classnames, |
| 216 |
] ); |
| 217 |
|
| 218 |
if ( $ehp_platforms->is_url_link( $contact_link[ 'group_' . $group_number . '_platform' ] ) ) { |
| 219 |
$ehp_platforms->render_link_attributes( $link, 'contact-link-' . $key ); |
| 220 |
} else { |
| 221 |
$formatted_link = $ehp_platforms->get_formatted_link( $link, 'group_' . $group_number ); |
| 222 |
|
| 223 |
$this->widget->add_render_attribute( 'contact-link-' . $key, [ |
| 224 |
'href' => $formatted_link, |
| 225 |
'rel' => 'noopener noreferrer', |
| 226 |
] ); |
| 227 |
} |
| 228 |
|
| 229 |
$label_repeater_key = $this->widget->public_get_repeater_setting_key( |
| 230 |
'group_' . $group_number . '_label', |
| 231 |
'group_' . $group_number . '_repeater', |
| 232 |
$key |
| 233 |
); |
| 234 |
|
| 235 |
$this->widget->public_add_inline_editing_attributes( $label_repeater_key, 'none' ); |
| 236 |
?> |
| 237 |
<a <?php $this->widget->print_render_attribute_string( 'contact-link-' . $key ); ?>> |
| 238 |
<?php |
| 239 |
|
| 240 |
Icons_Manager::render_icon( $icon, |
| 241 |
[ |
| 242 |
'aria-hidden' => 'true', |
| 243 |
'class' => self::LAYOUT_CLASSNAME . '__contact-link-icon', |
| 244 |
] |
| 245 |
); |
| 246 |
|
| 247 |
Widget_Utils::maybe_render_text_html( |
| 248 |
$this->widget, |
| 249 |
$label_repeater_key, |
| 250 |
self::LAYOUT_CLASSNAME . '__contact-link-label', |
| 251 |
$contact_link[ 'group_' . $group_number . '_label' ], |
| 252 |
'span' |
| 253 |
); |
| 254 |
?> |
| 255 |
</a> |
| 256 |
<?php |
| 257 |
} ?> |
| 258 |
</div> |
| 259 |
<?php |
| 260 |
} |
| 261 |
|
| 262 |
protected function render_contact_text_group( $group_number ) { |
| 263 |
$text_text = $this->settings[ 'group_' . $group_number . '_text_textarea' ]; |
| 264 |
$contact_text_classname = self::LAYOUT_CLASSNAME . '__contact-text'; |
| 265 |
|
| 266 |
$this->render_subheading( $group_number, 'text' ); |
| 267 |
|
| 268 |
Widget_Utils::maybe_render_text_html( $this->widget, 'group_' . $group_number . '_text_textarea', $contact_text_classname, $text_text ); |
| 269 |
} |
| 270 |
|
| 271 |
protected function render_social_icons_group( $group_number ) { |
| 272 |
$repeater = $this->settings[ 'group_' . $group_number . '_social_repeater' ]; |
| 273 |
|
| 274 |
$this->render_subheading( $group_number, 'social' ); |
| 275 |
|
| 276 |
$this->widget->add_render_attribute( 'social-icons-container', 'class', self::LAYOUT_CLASSNAME . '__social-icons-container' ); |
| 277 |
?> |
| 278 |
<div <?php $this->widget->print_render_attribute_string( 'social-icons-container' ); ?>> |
| 279 |
<?php |
| 280 |
foreach ( $repeater as $key => $social_icon ) { |
| 281 |
$icon = $social_icon[ 'group_' . $group_number . '_social_icon' ] ?? []; |
| 282 |
$label = $social_icon[ 'group_' . $group_number . '_social_label' ] ?? ''; |
| 283 |
$url = $social_icon[ 'group_' . $group_number . '_social_link' ] ?? []; |
| 284 |
$hover_animation = $this->settings['contact_details_social_icon_hover_animation']; |
| 285 |
|
| 286 |
$social_icon_classnames = [ self::LAYOUT_CLASSNAME . '__social-link' ]; |
| 287 |
|
| 288 |
if ( ! empty( $hover_animation ) ) { |
| 289 |
$social_icon_classnames[] = 'elementor-animation-' . $hover_animation; |
| 290 |
} |
| 291 |
|
| 292 |
$this->widget->add_render_attribute( 'social-icon-' . $key, [ |
| 293 |
'aria-label' => esc_attr( $label ), |
| 294 |
'class' => $social_icon_classnames, |
| 295 |
'rel' => 'noopener noreferrer', |
| 296 |
] ); |
| 297 |
|
| 298 |
if ( ! empty( $url['url'] ) ) { |
| 299 |
$this->widget->add_link_attributes( 'social-icon-' . $key, $url ); |
| 300 |
} |
| 301 |
?> |
| 302 |
<a <?php $this->widget->print_render_attribute_string( 'social-icon-' . $key ); ?>> |
| 303 |
<?php Icons_Manager::render_icon( $icon, |
| 304 |
[ |
| 305 |
'aria-hidden' => 'true', |
| 306 |
'class' => self::LAYOUT_CLASSNAME . '__contact-social-icon', |
| 307 |
] |
| 308 |
); ?> |
| 309 |
</a> |
| 310 |
<?php |
| 311 |
} |
| 312 |
?> |
| 313 |
</div> |
| 314 |
<?php |
| 315 |
} |
| 316 |
|
| 317 |
protected function render_map_container() { |
| 318 |
$map_container_classnames = [ |
| 319 |
self::LAYOUT_CLASSNAME . '__map-container', |
| 320 |
]; |
| 321 |
|
| 322 |
if ( 0 === absint( $this->settings['map_zoom']['size'] ) ) { |
| 323 |
$this->settings['map_zoom']['size'] = 10; |
| 324 |
} |
| 325 |
|
| 326 |
$api_key = esc_html( get_option( 'elementor_google_maps_api_key' ) ); |
| 327 |
|
| 328 |
$params = [ |
| 329 |
rawurlencode( $this->settings['map_address'] ), |
| 330 |
absint( $this->settings['map_zoom']['size'] ), |
| 331 |
]; |
| 332 |
|
| 333 |
if ( $api_key ) { |
| 334 |
$params[] = $api_key; |
| 335 |
|
| 336 |
$url = 'https://www.google.com/maps/embed/v1/place?key=%3$s&q=%1$s&zoom=%2$d'; |
| 337 |
} else { |
| 338 |
$url = 'https://maps.google.com/maps?q=%1$s&t=m&z=%2$d&output=embed&iwloc=near'; |
| 339 |
} |
| 340 |
|
| 341 |
$this->widget->add_render_attribute( 'map-container', [ |
| 342 |
'class' => $map_container_classnames, |
| 343 |
] ); |
| 344 |
|
| 345 |
$map_classnames = [ |
| 346 |
self::LAYOUT_CLASSNAME . '__map', |
| 347 |
'elementor-custom-embed', |
| 348 |
]; |
| 349 |
|
| 350 |
if ( 'yes' === $this->settings['show_map_border'] ) { |
| 351 |
$map_classnames[] = 'has-border'; |
| 352 |
} |
| 353 |
|
| 354 |
$shapes = new Ehp_Shapes( $this->widget, [ |
| 355 |
'container_prefix' => 'map', |
| 356 |
'render_attribute' => 'map', |
| 357 |
'widget_name' => $this->widget->get_name(), |
| 358 |
] ); |
| 359 |
|
| 360 |
$shapes->add_shape_attributes(); |
| 361 |
|
| 362 |
$this->widget->add_render_attribute( 'map', [ |
| 363 |
'class' => $map_classnames, |
| 364 |
] ); |
| 365 |
|
| 366 |
?> |
| 367 |
<div <?php $this->widget->print_render_attribute_string( 'map-container' ); ?>> |
| 368 |
<div <?php $this->widget->print_render_attribute_string( 'map' ); ?>> |
| 369 |
<iframe loading="lazy" |
| 370 |
src="<?php echo esc_url( vsprintf( $url, $params ) ); ?>" |
| 371 |
title="<?php echo esc_attr( $this->settings['map_address'] ); ?>" |
| 372 |
aria-label="<?php echo esc_attr( $this->settings['map_address'] ); ?>" |
| 373 |
></iframe> |
| 374 |
</div> |
| 375 |
</div> |
| 376 |
<?php |
| 377 |
} |
| 378 |
|
| 379 |
public function __construct( Contact $widget ) { |
| 380 |
$this->widget = $widget; |
| 381 |
$this->settings = $widget->get_settings_for_display(); |
| 382 |
} |
| 383 |
} |
| 384 |
|