PluginProbe
Hello Plus / 1.2.0
Hello Plus v1.2.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-zig-zag-render.php

widget-zig-zag-render.php in Hello Plus 1.2.0, at modules/content/classes/render/widget-zig-zag-render.php

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