| 1 |
<?php |
| 2 |
namespace HelloPlus\Modules\TemplateParts\Classes\Render; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
use Elementor\{ |
| 9 |
Group_Control_Image_Size, |
| 10 |
Icons_Manager, |
| 11 |
Utils |
| 12 |
}; |
| 13 |
|
| 14 |
use HelloPlus\Modules\TemplateParts\Widgets\Ehp_Footer; |
| 15 |
|
| 16 |
/** |
| 17 |
* class Widget_Footer_Render |
| 18 |
*/ |
| 19 |
class Widget_Footer_Render { |
| 20 |
const LAYOUT_CLASSNAME = 'ehp-footer'; |
| 21 |
const SITE_LINK_CLASSNAME = 'ehp-footer__site-link'; |
| 22 |
|
| 23 |
protected Ehp_Footer $widget; |
| 24 |
|
| 25 |
protected array $settings; |
| 26 |
|
| 27 |
public function render(): void { |
| 28 |
$layout_classnames = self::LAYOUT_CLASSNAME; |
| 29 |
$box_border = $this->settings['footer_box_border'] ?? ''; |
| 30 |
|
| 31 |
if ( 'yes' === $box_border ) { |
| 32 |
$layout_classnames .= ' has-box-border'; |
| 33 |
} |
| 34 |
|
| 35 |
$render_attributes = [ |
| 36 |
'class' => $layout_classnames, |
| 37 |
]; |
| 38 |
|
| 39 |
$this->widget->add_render_attribute( 'layout', $render_attributes ); |
| 40 |
|
| 41 |
$this->maybe_add_advanced_attributes(); |
| 42 |
|
| 43 |
?> |
| 44 |
<footer <?php $this->widget->print_render_attribute_string( 'layout' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> |
| 45 |
<div class="ehp-footer__row"> |
| 46 |
<?php |
| 47 |
$this->render_side_content(); |
| 48 |
$this->render_navigation(); |
| 49 |
$this->render_contact(); |
| 50 |
?> |
| 51 |
</div> |
| 52 |
<?php $this->render_copyright(); ?> |
| 53 |
</footer> |
| 54 |
<?php |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
protected function maybe_add_advanced_attributes() { |
| 59 |
$advanced_css_id = $this->settings['advanced_custom_css_id']; |
| 60 |
$advanced_css_classes = $this->settings['advanced_custom_css_classes']; |
| 61 |
|
| 62 |
$wrapper_render_attributes = []; |
| 63 |
if ( ! empty( $advanced_css_classes ) ) { |
| 64 |
$wrapper_render_attributes['class'] = $advanced_css_classes; |
| 65 |
} |
| 66 |
|
| 67 |
if ( ! empty( $advanced_css_id ) ) { |
| 68 |
$wrapper_render_attributes['id'] = $advanced_css_id; |
| 69 |
} |
| 70 |
if ( empty( $wrapper_render_attributes ) ) { |
| 71 |
return; |
| 72 |
} |
| 73 |
$this->widget->add_render_attribute( '_wrapper', $wrapper_render_attributes ); |
| 74 |
} |
| 75 |
|
| 76 |
public function render_side_content(): void { |
| 77 |
$description_text = $this->settings['footer_description']; |
| 78 |
$description_tag = $this->settings['footer_description_tag'] ?? 'p'; |
| 79 |
$has_description = '' !== $description_text; |
| 80 |
?> |
| 81 |
<div class="ehp-footer__side-content"> |
| 82 |
<?php $this->render_site_link(); ?> |
| 83 |
<?php if ( $has_description ) { |
| 84 |
$description_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $description_tag ), 'class="ehp-footer__description"', esc_html( $description_text ) ); |
| 85 |
// Escaped above |
| 86 |
Utils::print_unescaped_internal_string( $description_output ); |
| 87 |
} ?> |
| 88 |
<?php $this->render_social_icons(); ?> |
| 89 |
</div> |
| 90 |
<?php |
| 91 |
} |
| 92 |
|
| 93 |
public function render_site_link(): void { |
| 94 |
$site_logo_image = $this->settings['site_logo_image']; |
| 95 |
$site_title_text = $this->widget->get_site_title(); |
| 96 |
$site_title_tag = $this->settings['site_logo_title_tag'] ?? 'h2'; |
| 97 |
$site_link_classnames = self::SITE_LINK_CLASSNAME; |
| 98 |
|
| 99 |
$this->widget->add_render_attribute( 'site-link', [ |
| 100 |
'class' => $site_link_classnames, |
| 101 |
] ); |
| 102 |
|
| 103 |
$site_link = $this->get_link_url(); |
| 104 |
|
| 105 |
if ( $site_link ) { |
| 106 |
$this->widget->add_link_attributes( 'site-link', $site_link ); |
| 107 |
} |
| 108 |
|
| 109 |
if ( $site_logo_image ) { |
| 110 |
$this->settings['site_logo_image'] = $this->widget->add_site_logo_if_present( $this->settings['site_logo_image'] ); |
| 111 |
} |
| 112 |
|
| 113 |
?> |
| 114 |
<a <?php $this->widget->print_render_attribute_string( 'site-link' ); ?>> |
| 115 |
<?php if ( $site_logo_image ) { ?> |
| 116 |
<?php Group_Control_Image_Size::print_attachment_image_html( $this->settings, 'site_logo_image' ); ?> |
| 117 |
<?php } else { |
| 118 |
$site_title_output = sprintf( '<%1$s %2$s %3$s>%4$s</%1$s>', Utils::validate_html_tag( $site_title_tag ), $this->widget->get_render_attribute_string( 'heading' ), 'class="ehp-footer__site-title"', esc_html( $site_title_text ) ); |
| 119 |
// Escaped above |
| 120 |
Utils::print_unescaped_internal_string( $site_title_output ); |
| 121 |
} ?> |
| 122 |
</a> |
| 123 |
<?php |
| 124 |
} |
| 125 |
|
| 126 |
public function render_social_icons(): void { |
| 127 |
$icons = $this->settings['footer_icons'] ?? []; |
| 128 |
$icon_hover_animation = $this->settings['social_icons_hover_animation'] ?? ''; |
| 129 |
$footer_icons_classnames = 'ehp-footer__social-icons'; |
| 130 |
|
| 131 |
if ( empty( $icons ) ) { |
| 132 |
return; |
| 133 |
} |
| 134 |
|
| 135 |
$this->widget->add_render_attribute( 'icons', [ |
| 136 |
'class' => $footer_icons_classnames, |
| 137 |
] ); |
| 138 |
?> |
| 139 |
<div <?php $this->widget->print_render_attribute_string( 'icons' ); ?>> |
| 140 |
<?php |
| 141 |
foreach ( $icons as $key => $icon ) { |
| 142 |
$link = $icon['footer_icon_link']; |
| 143 |
$text = $icon['footer_icon_text']; |
| 144 |
$selected_icon = $icon['footer_selected_icon']; |
| 145 |
|
| 146 |
$icon_classnames = 'ehp-footer__social-icon'; |
| 147 |
|
| 148 |
if ( $icon_hover_animation ) { |
| 149 |
$icon_classnames .= ' elementor-animation-' . $icon_hover_animation; |
| 150 |
} |
| 151 |
|
| 152 |
$this->widget->add_render_attribute( 'icon-' . $key, [ |
| 153 |
'class' => $icon_classnames, |
| 154 |
'aria-label' => esc_html( $text ), |
| 155 |
] ); |
| 156 |
|
| 157 |
$this->widget->add_link_attributes( 'icon-' . $key, $link ); |
| 158 |
?> |
| 159 |
|
| 160 |
<?php if ( ! empty( $text ) ) : ?> |
| 161 |
<a <?php $this->widget->print_render_attribute_string( 'icon-' . $key ); ?>> |
| 162 |
<?php if ( ! empty( $selected_icon['value'] ) ) : ?> |
| 163 |
<?php Icons_Manager::render_icon( $selected_icon, [ 'aria-hidden' => 'true' ] ); ?> |
| 164 |
<?php endif; ?> |
| 165 |
</a> |
| 166 |
<?php endif; ?> |
| 167 |
<?php } ?> |
| 168 |
</div> |
| 169 |
<?php |
| 170 |
} |
| 171 |
|
| 172 |
public function render_navigation(): void { |
| 173 |
$available_menus = $this->widget->get_available_menus(); |
| 174 |
$menu_classname = 'ehp-footer__menu'; |
| 175 |
|
| 176 |
$menu_heading = $this->settings['footer_menu_heading']; |
| 177 |
$menu_heading_tag = $this->settings['footer_menu_heading_tag'] ?? 'h6'; |
| 178 |
$has_menu_heading = '' !== $menu_heading; |
| 179 |
|
| 180 |
if ( ! $available_menus ) { |
| 181 |
return; |
| 182 |
} |
| 183 |
|
| 184 |
$args = [ |
| 185 |
'echo' => false, |
| 186 |
'menu' => $this->settings['navigation_menu'], |
| 187 |
'menu_class' => $menu_classname, |
| 188 |
'menu_id' => 'menu-' . $this->widget->get_and_advance_nav_menu_index() . '-' . $this->widget->get_id(), |
| 189 |
'fallback_cb' => '__return_empty_string', |
| 190 |
'container' => '', |
| 191 |
'depth' => 1, |
| 192 |
]; |
| 193 |
|
| 194 |
add_filter( 'nav_menu_link_attributes', [ $this, 'handle_link_classes' ], 10, 4 ); |
| 195 |
|
| 196 |
$menu_html = wp_nav_menu( $args ); |
| 197 |
|
| 198 |
remove_filter( 'nav_menu_link_attributes', [ $this, 'handle_link_classes' ] ); |
| 199 |
|
| 200 |
if ( empty( $menu_html ) ) { |
| 201 |
return; |
| 202 |
} |
| 203 |
|
| 204 |
if ( $this->settings['footer_menu_heading'] ) { |
| 205 |
$this->widget->add_render_attribute( 'main-menu', 'aria-label', $this->settings['footer_menu_heading'] ); |
| 206 |
} |
| 207 |
|
| 208 |
$this->widget->add_render_attribute( 'main-menu', [ |
| 209 |
'class' => 'ehp-footer__navigation', |
| 210 |
] ); |
| 211 |
?> |
| 212 |
<div class="ehp-footer__nav-container"> |
| 213 |
<nav <?php $this->widget->print_render_attribute_string( 'main-menu' ); ?>> |
| 214 |
<?php if ( $has_menu_heading ) { |
| 215 |
$menu_heading_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $menu_heading_tag ), 'class="ehp-footer__menu-heading"', esc_html( $menu_heading ) ); |
| 216 |
// Escaped above |
| 217 |
Utils::print_unescaped_internal_string( $menu_heading_output ); |
| 218 |
} ?> |
| 219 |
<?php |
| 220 |
add_filter( 'nav_menu_link_attributes', [ $this, 'handle_link_classes' ], 10, 4 ); |
| 221 |
|
| 222 |
$args['echo'] = true; |
| 223 |
|
| 224 |
wp_nav_menu( $args ); |
| 225 |
|
| 226 |
remove_filter( 'nav_menu_link_attributes', [ $this, 'handle_link_classes' ] ); |
| 227 |
?> |
| 228 |
</nav> |
| 229 |
</div> |
| 230 |
<?php |
| 231 |
} |
| 232 |
|
| 233 |
public function render_contact(): void { |
| 234 |
$contact_text = $this->settings['footer_contact_heading']; |
| 235 |
$contact_tag = $this->settings['footer_contact_heading_tag'] ?? 'p'; |
| 236 |
$has_contact = '' !== $contact_text; |
| 237 |
|
| 238 |
$contact_information_text = $this->settings['footer_contact_information']; |
| 239 |
$contact_information_tag = $this->settings['footer_contact_information_tag'] ?? 'p'; |
| 240 |
$has_contact_information = '' !== $contact_information_text; |
| 241 |
|
| 242 |
$this->widget->add_render_attribute( 'contact', [ |
| 243 |
'class' => 'ehp-footer__contact', |
| 244 |
] ); |
| 245 |
?> |
| 246 |
<div class="ehp-footer__contact-container"> |
| 247 |
<div <?php $this->widget->print_render_attribute_string( 'contact' ); ?>> |
| 248 |
<?php if ( $has_contact ) { |
| 249 |
$contact_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $contact_tag ), 'class="ehp-footer__contact-heading"', esc_html( $contact_text ) ); |
| 250 |
// Escaped above |
| 251 |
Utils::print_unescaped_internal_string( $contact_output ); |
| 252 |
} ?> |
| 253 |
<?php if ( $has_contact_information ) { |
| 254 |
$contact_information_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $contact_information_tag ), 'class="ehp-footer__contact-information"', wp_kses_post( nl2br( esc_html( $contact_information_text ) ) ) ); |
| 255 |
// Escaped above |
| 256 |
Utils::print_unescaped_internal_string( $contact_information_output ); |
| 257 |
} ?> |
| 258 |
</div> |
| 259 |
</div> |
| 260 |
<?php |
| 261 |
} |
| 262 |
|
| 263 |
public function render_copyright(): void { |
| 264 |
$copyright_text = $this->settings['footer_copyright']; |
| 265 |
$copyright_tag = $this->settings['footer_copyright_tag'] ?? 'p'; |
| 266 |
$has_copyright = '' !== $copyright_text; |
| 267 |
?> |
| 268 |
|
| 269 |
<div class="ehp-footer__copyright"> |
| 270 |
<?php if ( $has_copyright ) { |
| 271 |
$copyright_output = sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $copyright_tag ), 'class="ehp-footer__copyright"', esc_html( $copyright_text ) ); |
| 272 |
// Escaped above |
| 273 |
Utils::print_unescaped_internal_string( $copyright_output ); |
| 274 |
} ?> |
| 275 |
</div> |
| 276 |
<?php |
| 277 |
} |
| 278 |
|
| 279 |
public function get_link_url(): array { |
| 280 |
return [ 'url' => $this->widget->get_site_url() ]; |
| 281 |
} |
| 282 |
|
| 283 |
public function handle_link_classes( $atts, $item ) { |
| 284 |
$classes = 'ehp-footer__menu-item'; |
| 285 |
$is_anchor = false !== strpos( $atts['href'], '#' ); |
| 286 |
$has_hover_animation = $this->settings['style_navigation_hover_animation'] ?? ''; |
| 287 |
|
| 288 |
if ( $has_hover_animation ) { |
| 289 |
$classes .= ' elementor-animation-' . $has_hover_animation; |
| 290 |
} |
| 291 |
|
| 292 |
if ( ! $is_anchor && in_array( 'current-menu-item', $item->classes, true ) ) { |
| 293 |
$classes .= ' is-item-active'; |
| 294 |
} |
| 295 |
|
| 296 |
if ( $is_anchor ) { |
| 297 |
$classes .= ' is-item-anchor'; |
| 298 |
} |
| 299 |
|
| 300 |
if ( empty( $atts['class'] ) ) { |
| 301 |
$atts['class'] = $classes; |
| 302 |
} else { |
| 303 |
$atts['class'] .= ' ' . $classes; |
| 304 |
} |
| 305 |
|
| 306 |
return $atts; |
| 307 |
} |
| 308 |
|
| 309 |
public function __construct( Ehp_Footer $widget ) { |
| 310 |
$this->widget = $widget; |
| 311 |
$this->settings = $widget->get_settings_for_display(); |
| 312 |
} |
| 313 |
} |
| 314 |
|