| 1 |
<?php |
| 2 |
|
| 3 |
namespace HelloPlus\Modules\Content\Classes\Render; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
use Elementor\Icons_Manager; |
| 10 |
use Elementor\Utils; |
| 11 |
|
| 12 |
use HelloPlus\Modules\Content\Widgets\Zig_Zag; |
| 13 |
use HelloPlus\Classes\{ |
| 14 |
Ehp_Button, |
| 15 |
Ehp_Image, |
| 16 |
}; |
| 17 |
|
| 18 |
class Widget_Zig_Zag_Render { |
| 19 |
protected Zig_Zag $widget; |
| 20 |
const LAYOUT_CLASSNAME = 'ehp-zigzag'; |
| 21 |
const ITEM_CLASSNAME = 'ehp-zigzag__item-container'; |
| 22 |
const GRAPHIC_ELEMENT_CLASSNAME = 'ehp-zigzag__graphic-element-container'; |
| 23 |
const BUTTON_CLASSNAME = 'ehp-zigzag__button'; |
| 24 |
const TEXT_CONTAINER_CLASSNAME = 'ehp-zigzag__text-container'; |
| 25 |
|
| 26 |
protected array $settings; |
| 27 |
|
| 28 |
public function __construct( Zig_Zag $widget ) { |
| 29 |
$this->widget = $widget; |
| 30 |
$this->settings = $widget->get_settings_for_display(); |
| 31 |
} |
| 32 |
|
| 33 |
public function render(): void { |
| 34 |
$first_zigzag_direction = $this->settings['first_zigzag_direction']; |
| 35 |
$has_alternate_icon_color = $this->settings['has_alternate_icon_color'] ?? 'no'; |
| 36 |
$entrance_animation = $this->settings['zigzag_animation'] ?? ''; |
| 37 |
$has_entrance_animation = ! empty( $entrance_animation ) && 'none' !== $entrance_animation; |
| 38 |
$has_alternate_animation = 'yes' === $this->settings['animation_alternate']; |
| 39 |
$image_stretch = $this->settings['image_stretch']; |
| 40 |
|
| 41 |
$layout_classnames = [ |
| 42 |
self::LAYOUT_CLASSNAME, |
| 43 |
'has-direction-' . $first_zigzag_direction, |
| 44 |
]; |
| 45 |
|
| 46 |
if ( 'yes' === $has_alternate_icon_color ) { |
| 47 |
$layout_classnames[] = 'has-alternate-icon-color'; |
| 48 |
} |
| 49 |
|
| 50 |
if ( $has_entrance_animation ) { |
| 51 |
$layout_classnames[] = 'has-entrance-animation'; |
| 52 |
} |
| 53 |
|
| 54 |
if ( $has_alternate_animation ) { |
| 55 |
$layout_classnames[] = 'has-alternate-animation'; |
| 56 |
} |
| 57 |
|
| 58 |
if ( 'yes' === $image_stretch ) { |
| 59 |
$layout_classnames[] = 'has-image-stretch'; |
| 60 |
} |
| 61 |
|
| 62 |
$this->widget->add_render_attribute( 'layout', [ |
| 63 |
'class' => $layout_classnames, |
| 64 |
] ); |
| 65 |
|
| 66 |
?> |
| 67 |
<div <?php $this->widget->print_render_attribute_string( 'layout' ); ?>> |
| 68 |
<?php |
| 69 |
$graphic_element = $this->settings['graphic_element']; |
| 70 |
$repeater = 'image' === $graphic_element ? $this->settings['image_zigzag_items'] : $this->settings['icon_zigzag_items']; |
| 71 |
|
| 72 |
$wrapper_classnames = [ |
| 73 |
'ehp-zigzag__item-wrapper', |
| 74 |
]; |
| 75 |
|
| 76 |
if ( $has_entrance_animation ) { |
| 77 |
$wrapper_classnames[] = 'hidden'; |
| 78 |
} |
| 79 |
|
| 80 |
foreach ( $repeater as $key => $item ) { |
| 81 |
$this->widget->add_render_attribute( 'zigzag-item-wrapper-' . $key, [ |
| 82 |
'class' => $wrapper_classnames, |
| 83 |
] ); |
| 84 |
|
| 85 |
$this->widget->add_render_attribute( 'zigzag-item-' . $key, [ |
| 86 |
'class' => self::ITEM_CLASSNAME, |
| 87 |
] ); |
| 88 |
?> |
| 89 |
<div <?php $this->widget->print_render_attribute_string( 'zigzag-item-wrapper-' . $key ); ?>> |
| 90 |
<div <?php $this->widget->print_render_attribute_string( 'zigzag-item-' . $key ); ?>> |
| 91 |
<?php |
| 92 |
$this->render_graphic_element_container( $item, $key ); |
| 93 |
$this->render_text_element_container( $item, $key ); |
| 94 |
?> |
| 95 |
</div> |
| 96 |
</div> |
| 97 |
<?php |
| 98 |
} ?> |
| 99 |
</div> |
| 100 |
<?php |
| 101 |
} |
| 102 |
|
| 103 |
private function render_graphic_element_container( $item, $key ) { |
| 104 |
$graphic_element = $this->settings['graphic_element']; |
| 105 |
|
| 106 |
$graphic_element_classnames = [ |
| 107 |
self::GRAPHIC_ELEMENT_CLASSNAME, |
| 108 |
]; |
| 109 |
|
| 110 |
$is_icon = 'icon' === $graphic_element && ! empty( $item['icon_graphic_icon'] ); |
| 111 |
$is_image = 'image' === $graphic_element && ! empty( $item['image_graphic_image']['url'] ); |
| 112 |
|
| 113 |
if ( $is_icon ) { |
| 114 |
$graphic_element_classnames[] = 'has-icon'; |
| 115 |
} elseif ( $is_image ) { |
| 116 |
$graphic_element_classnames[] = 'has-image'; |
| 117 |
} |
| 118 |
|
| 119 |
$this->widget->add_render_attribute( 'graphic-element-container-' . $key, [ |
| 120 |
'class' => $graphic_element_classnames, |
| 121 |
] ); |
| 122 |
?> |
| 123 |
<div <?php $this->widget->print_render_attribute_string( 'graphic-element-container-' . $key ); ?>> |
| 124 |
<?php if ( $is_image ) { |
| 125 |
$this->render_image_container( $item, 'image_graphic_image' ); |
| 126 |
} elseif ( $is_icon ) { |
| 127 |
Icons_Manager::render_icon( $item['icon_graphic_icon'], [ 'aria-hidden' => 'true' ] ); |
| 128 |
} ?> |
| 129 |
</div> |
| 130 |
<?php |
| 131 |
} |
| 132 |
|
| 133 |
private function render_image_container( $settings, $key ) { |
| 134 |
$defaults = [ |
| 135 |
'settings' => $settings, |
| 136 |
'image_key' => $key, |
| 137 |
'image' => $settings[ $key ], |
| 138 |
]; |
| 139 |
|
| 140 |
$image = new Ehp_Image( $this->widget, [ |
| 141 |
'widget_name' => $this->widget->get_name(), |
| 142 |
], $defaults ); |
| 143 |
$image->render(); |
| 144 |
} |
| 145 |
|
| 146 |
private function render_text_element_container( $item, $key ) { |
| 147 |
$graphic_element = $this->settings['graphic_element']; |
| 148 |
|
| 149 |
$title_tag = $this->settings['zigzag_title_tag'] ?? 'h2'; |
| 150 |
$title_text = $item[ $graphic_element . '_title' ] ?? ''; |
| 151 |
$has_title = ! empty( $title_text ); |
| 152 |
|
| 153 |
$description_text = $item[ $graphic_element . '_description' ] ?? ''; |
| 154 |
$has_description = ! empty( $description_text ); |
| 155 |
|
| 156 |
$is_graphic_image = 'image' === $graphic_element; |
| 157 |
$is_graphic_icon = 'icon' === $graphic_element; |
| 158 |
$text_container_classnames = [ |
| 159 |
self::TEXT_CONTAINER_CLASSNAME, |
| 160 |
]; |
| 161 |
|
| 162 |
$this->widget->add_render_attribute( 'description-' . $key, [ |
| 163 |
'class' => 'ehp-zigzag__description', |
| 164 |
] ); |
| 165 |
|
| 166 |
if ( $is_graphic_icon ) { |
| 167 |
$text_container_classnames[] = 'is-graphic-icon'; |
| 168 |
} elseif ( $is_graphic_image ) { |
| 169 |
$text_container_classnames[] = 'is-graphic-image'; |
| 170 |
} |
| 171 |
|
| 172 |
$this->widget->add_render_attribute( 'text-container-' . $key, [ |
| 173 |
'class' => $text_container_classnames, |
| 174 |
] ); |
| 175 |
?> |
| 176 |
<div <?php $this->widget->print_render_attribute_string( 'text-container-' . $key ); ?>> |
| 177 |
<?php if ( $has_title ) { |
| 178 |
$title_output = sprintf( '<%1$s %2$s %3$s>%4$s</%1$s>', Utils::validate_html_tag( $title_tag ), $this->widget->get_render_attribute_string( 'heading' ), 'class="ehp-zigzag__title"', esc_html( $title_text ) ); |
| 179 |
// Escaped above |
| 180 |
Utils::print_unescaped_internal_string( $title_output ); |
| 181 |
} ?> |
| 182 |
<?php if ( $has_description ) { ?> |
| 183 |
<p <?php $this->widget->print_render_attribute_string( 'description-' . $key ); ?>><?php echo esc_html( $description_text ); ?></p> |
| 184 |
<?php } ?> |
| 185 |
<?php if ( ! empty( $item[ $graphic_element . '_button_text' ] ) ) { |
| 186 |
$this->render_cta_button( $item, $key ); |
| 187 |
} ?> |
| 188 |
</div> |
| 189 |
<?php |
| 190 |
} |
| 191 |
|
| 192 |
public function render_cta_button( $item, $key ) { |
| 193 |
$graphic_element = $this->settings['graphic_element']; |
| 194 |
|
| 195 |
$defaults = [ |
| 196 |
'button_text' => $item[ $graphic_element . '_button_text' ] ?? '', |
| 197 |
'button_link' => $item[ $graphic_element . '_button_link' ] ?? '', |
| 198 |
'button_icon' => $item[ $graphic_element . '_button_icon' ] ?? '', |
| 199 |
'button_hover_animation' => $this->settings['primary_button_hover_animation'] ?? '', |
| 200 |
'button_has_border' => $this->settings['primary_show_button_border'], |
| 201 |
'button_type' => $this->settings['primary_button_type'] ?? '', |
| 202 |
]; |
| 203 |
|
| 204 |
$button = new Ehp_Button( $this->widget, [ |
| 205 |
'type' => 'primary', |
| 206 |
'widget_name' => $this->widget->get_name(), |
| 207 |
'key' => $key, |
| 208 |
], $defaults ); |
| 209 |
?> |
| 210 |
<div class="ehp-zigzag__button-container"> |
| 211 |
<?php $button->render(); ?> |
| 212 |
</div> |
| 213 |
<?php |
| 214 |
} |
| 215 |
} |
| 216 |
|