PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.4
UiCore Elements – Free widgets and templates for Elementor v1.2.4
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / utils / meta-component.php

meta-component.php in UiCore Elements – Free widgets and templates for Elementor 1.2.4, at includes/utils/meta-component.php

426 lines 16.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements\Utils;
3
4 use Elementor\Controls_Manager;
5 use Elementor\Group_Control_Typography;
6 use UiCoreElements\Helper;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly
10 }
11
12 trait Meta_Trait {
13
14 function get_meta_content_controls($product_metas = false)
15 {
16
17 // Meta options
18 $options = [
19 'none' => __( 'None', 'uicore-elements' ),
20 ];
21 $generic_posts = [
22 'author' => __( 'Author', 'uicore-elements' ),
23 'date' => __( 'Posted Date', 'uicore-elements' ),
24 'updated date' => __( 'Updated Date', 'uicore-elements' ),
25 'comment' => __( 'Comments Count', 'uicore-elements' ),
26 'reading time' => __( 'Reading Time', 'uicore-elements' ),
27 'category' => __( 'Category', 'uicore-elements' ),
28 'tag' => __( 'Tag', 'uicore-elements' ),
29 ];
30 $products = [
31 'product price' => __( 'Product Price', 'uicore-elements' ),
32 'product rating' => __( 'Product Rating', 'uicore-elements' ),
33 'product stock' => __( 'Product Stock', 'uicore-elements' ),
34 'product category' => __( 'Product Category', 'uicore-elements' ),
35 'product tag' => __( 'Product Tag', 'uicore-elements' ),
36 'product attribute' => __( 'Product Attribute', 'uicore-elements' ),
37 'product sale' => __( 'Product Sale', 'uicore-elements' ),
38 ];
39 $custom = [
40 'custom meta' => __( 'Custom Meta', 'uicore-elements' ),
41 'custom taxonomy' => __( 'Custom Taxonomy', 'uicore-elements' ),
42 'custom html' => __( 'Custom HTML', 'uicore-elements' ),
43 ];
44 $portfolio = [
45 'portfolio category' => __( 'Portfolio Category', 'uicore-elements' ),
46 ];
47
48 $options = $product_metas ?
49 array_merge($options, $products, $custom) : // specific to product widgets
50 array_merge($options, $generic_posts, $products, $portfolio, $custom); // generic posts widgets
51
52
53 $repeater = new \Elementor\Repeater();
54 $repeater->add_control('type',[
55 'label' => __( 'Meta', 'uicore-elements' ),
56 'type' => Controls_Manager::SELECT,
57 'default' => '',
58 'options' => $options
59 ]
60 );
61 $repeater->add_control('type_custom',[
62 'label' => __( 'Custom Field Name', 'uicore-elements' ),
63 'type' => Controls_Manager::TEXT,
64 'condition' => [
65 'type' => ['custom meta','custom taxonomy']
66 ]
67 ]
68 );
69 $repeater->add_control('html_custom',[
70 'label' => __( 'Custom HTML', 'uicore-elements' ),
71 'type' => Controls_Manager::TEXTAREA,
72 'condition' => [
73 'type' => ['custom html']
74 ]
75 ]
76 );
77 $repeater->add_control('date_format',[
78 'label' => esc_html__( 'Date Format', 'uicore-elements' ),
79 'type' => Controls_Manager::SELECT,
80 'default' => 'default',
81 'options' => [
82 'default' => esc_html__( 'Default', 'uicore-elements' ),
83 'F j, Y' => gmdate( 'F j, Y' ),
84 'Y-m-d' => gmdate( 'Y-m-d' ),
85 'm/d/Y' => gmdate( 'm/d/Y' ),
86 'd/m/Y' => gmdate( 'd/m/Y' ),
87 'custom' => esc_html__( 'Custom', 'uicore-elements' ),
88 ],
89 'condition' => [
90 'type' => ['date','updated date']
91 ]
92 ]
93 );
94 $repeater->add_control('custom_format',[
95 'label' => esc_html__( 'Custom Format', 'uicore-elements' ),
96 'default' => get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
97 'description' => sprintf( '<a href="https://wordpress.org/documentation/article/customize-date-and-time-format/" target="_blank">%s</a>', esc_html__( 'Documentation on date and time formatting', 'uicore-elements' ) ),
98 'condition' => [
99 'date_format' => 'custom',
100 'type' => ['date','updated date']
101 ],
102 ]
103 );
104 $repeater->add_control('before',[
105 'label' => __( 'Text Before', 'uicore-elements' ),
106 'type' => Controls_Manager::TEXT,
107 'condition' => [
108 'type!' => 'none',
109 ]
110 ]
111 );
112 $repeater->add_control('after',[
113 'label' => __( 'Text After', 'uicore-elements' ),
114 'type' => Controls_Manager::TEXT,
115 'condition' => [
116 'type!' => 'none',
117 ]
118 ]
119 );
120 $repeater->add_control('autor_display',[
121 'label' => __( 'Display Type', 'uicore-elements' ),
122 'type' => Controls_Manager::SELECT,
123 'default' => 'name',
124 'options' => [
125 'name' => __( 'Name', 'uicore-elements' ),
126 'full' => __( 'Avatar & Name', 'uicore-elements' ),
127 'avatar' => __( 'Avatar', 'uicore-elements' ),
128 ],
129 'condition' => [
130 'type' => 'author',
131 ],
132 ]
133 );
134 $repeater->add_control('icon',[
135 'label' => __( 'Icon', 'uicore-elements' ),
136 'type' => Controls_Manager::ICONS,
137 'condition' => [
138 'autor_display' => 'name',
139 'type!' => 'none',
140 ],
141 ]
142 );
143 return $repeater->get_controls();
144 }
145
146 function get_meta_style_controls($position = 'tb-meta')
147 {
148 $this->add_group_control(
149 Group_Control_Typography::get_type(),
150 [
151 'name' => $position.'_meta_typography',
152 'selector' => '{{WRAPPER}} .ui-e-'.$position,
153 'separator' => 'before',
154 ]
155 );
156 $this->add_control(
157 $position.'_meta_color',
158 [
159 'label' => __( 'Text Color', 'uicore-elements' ),
160 'type' => Controls_Manager::COLOR,
161 'selectors' => [
162 '{{WRAPPER}} .ui-e-'.$position => 'color: {{VALUE}}',
163 '{{WRAPPER}} .ui-e-'.$position.' svg' => 'fill: {{VALUE}}',
164 ],
165 ]
166 );
167 $this->add_control(
168 $position.'_link_color',
169 [
170 'label' => __( 'Link Color', 'uicore-elements' ),
171 'type' => Controls_Manager::COLOR,
172 'selectors' => [
173 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item a' => 'color: {{VALUE}}',
174 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item svg' => 'fill: {{VALUE}}',
175 ],
176 ]
177 );
178 $this->add_control(
179 $position.'_linkh_color',
180 [
181 'label' => __( 'Link Hover Color', 'uicore-elements' ),
182 'type' => Controls_Manager::COLOR,
183 'selectors' => [
184 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item a:hover' => 'color: {{VALUE}}',
185 ],
186 ]
187 );
188 $this->add_control(
189 $position.'_meta_background',
190 [
191 'label' => __( 'Background Color', 'uicore-elements' ),
192 'type' => Controls_Manager::COLOR,
193 'selectors' => [
194 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item' => 'background-color: {{VALUE}}',
195
196 ],
197 ]
198 );
199 $this->add_control(
200 $position.'_meta_radius',
201 [
202 'label' => esc_html__('Border Radius', 'uicore-elements'),
203 'type' => Controls_Manager::DIMENSIONS,
204 'selectors' => [
205 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item' => 'border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;'
206 ],
207 ]
208 );
209 $this->add_group_control(
210 \Elementor\Group_Control_Box_Shadow::get_type(),
211 [
212 'name' => $position.'_meta_shadow',
213 'label' => esc_html__( 'Box Shadow', 'uicore-elements' ),
214 'selector' => '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item',
215 ]
216 );
217 $this->add_responsive_control(
218 $position.'_meta_padding',
219 [
220 'label' => esc_html__('Padding', 'uicore-elements'),
221 'type' => Controls_Manager::DIMENSIONS,
222 'size_units' => [ 'px', 'em', '%' ],
223 'selectors' => [
224 '{{WRAPPER}} .ui-e-'.$position.' .ui-e-meta-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
225 ]
226 ]
227 );
228 if($position === 'top'){
229 $this->add_responsive_control(
230 $position.'_meta_margin',
231 [
232 'label' => esc_html__('Margin', 'uicore-elements'),
233 'type' => Controls_Manager::DIMENSIONS,
234 'size_units' => [ 'px', 'em', '%' ],
235 'selectors' => [
236 '{{WRAPPER}} .ui-e-'.$position => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
237 ]
238 ]
239 );
240 }else{
241 $this->add_control($position.'_meta_margin',[
242 'label' => __( 'Meta Top Space', 'uicore-elements' ),
243 'type' => Controls_Manager::SLIDER,
244 'size_units' => [ 'em' ],
245 'separator' => 'after',
246 'range' => [
247 'px' => [
248 'min' => 0,
249 'max' => 3,
250 'step' => 0.1,
251 ],
252 ],
253 'default' => [
254 'unit' => 'em',
255 'size' => 1.2,
256 ],
257 'selectors' => [
258 '{{WRAPPER}} .ui-e-'.$position => 'margin-top: {{SIZE}}em;',
259 ],
260 ]
261 );
262 }
263
264 $this->add_responsive_control($position.'_meta_gap',[
265 'label' => __( 'Items Gap', 'uicore-elements' ),
266 'type' => Controls_Manager::SLIDER,
267 'size_units' => [ 'px' ],
268 'range' => [
269 'px' => [
270 'min' => 0,
271 'max' => 30,
272 ],
273 ],
274 'default' => [
275 'unit' => 'px',
276 'size' => 8,
277 ],
278 'selectors' => [
279 '{{WRAPPER}} .ui-e-'.$position.' ' => 'gap: {{SIZE}}px;',
280 ],
281 ]
282 );
283 $this->add_control($position.'_meta_separator',[
284 'label' => __( 'Separator', 'uicore-elements' ),
285 'type' => Controls_Manager::TEXT,
286 ]
287 );
288 if($position === 'top'){
289 $this->add_control($position.'_meta_placement',[
290 'label' => __( 'Items placement', 'uicore-elements' ),
291 'type' => Controls_Manager::SELECT,
292 'default' => '',
293 'options' => [
294 'start left' => __( 'Top Left', 'uicore-elements' ),
295 'start right' => __( 'Top Right', 'uicore-elements' ),
296 'end left' => __( 'Bottom Left', 'uicore-elements' ),
297 'end right' => __( 'Bottom Right', 'uicore-elements' ),
298 ],
299 'selectors' => [
300 '{{WRAPPER}} .ui-e-post-top-meta' => 'place-content: {{VALUE}};',
301 ],
302 ]
303 );
304 }
305 }
306
307 function get_meta_the_author($mode)
308 {
309 global $post;
310 $author_id = $post->post_author;
311 $author_name = get_the_author_meta('display_name', $author_id);
312
313 // name, full, avatar
314 if($mode === 'avatar'){
315 $display = '<img class="ui-e-meta-avatar" src="' . esc_url( get_avatar_url($author_id, array('size' => 100)) ) . '" />';
316 }elseif($mode === 'full'){
317 $display = '<img class="ui-e-meta-avatar" src="' . esc_url( get_avatar_url($author_id, array('size' => 100)) ) . '" /> '. esc_html($author_name);
318 }else{
319 $display = esc_html($author_name);
320 }
321 $link = sprintf(
322 /* translators: 1: Author archive url, 2: Author meta title, 3: Author display name */
323 '<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
324 esc_url( get_author_posts_url( $author_id) ),
325 /* translators: %s: Author's display name. */
326 esc_attr( sprintf( __( 'View %s&#8217;s posts', 'uicore-elements' ), esc_html($author_name) ) ),
327 $display
328 );
329 return $link;
330 }
331
332 function get_woo_meta($type)
333 {
334 global $product;
335
336 if (empty($product)) {
337 return 'No product found.';
338 }
339
340 switch ($type) {
341 case 'product price':
342 return $product->get_price_html();
343 case 'product rating':
344 return wc_get_rating_html( $product->get_average_rating() );
345 case 'product category':
346 return get_the_term_list($product->get_id(), 'product_cat', '', ', ', '');
347 case 'product tag':
348 return get_the_term_list($product->get_id(), 'product_tag', '', ', ', '');
349 case 'product stock' :
350 return ( $product->managing_stock() && $product->is_type('simple') && $product->get_stock_quantity() !== null ) ? $product->get_stock_quantity() : '';
351 case 'product attribute':
352 return wc_display_product_attributes($product);
353 case 'product sale' :
354 return $product->is_on_sale() ? esc_html__( 'Sale!', 'uicore-elements' ) : '';
355 default:
356 return 'Invalid meta type.';
357 }
358 }
359
360 function display_meta($meta)
361 {
362
363 if( $meta['type'] === 'none' )
364 return;
365
366 $content = '';
367 $wrapper = '<div class="ui-e-meta-item">';
368 $type = $meta['type'];
369 $prefix = $meta['before'] ? '<span>'.esc_html($meta['before']).'</span>' : '';
370 $suffix = $meta['after'] ? '<span class="ui-e-meta-after">'.esc_html($meta['after']).'</span>' : '';
371
372 ob_start();
373 \Elementor\Icons_Manager::render_icon( $meta['icon'], [ 'aria-hidden' => 'true', 'class'=> 'ui-e-meta-icon' ], 'span' );
374 $icon = ob_get_clean();
375
376 // Build content
377 switch ($type) {
378 case 'author':
379 $content .= $this->get_meta_the_author($meta['autor_display']); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
380 break;
381 case 'date':
382 $content .= Helper::format_date( get_the_date('U'), $meta['date_format'], $meta['custom_format']); // 'U' param returns the date in timestamp, necessary for format_date()
383 break;
384 case 'updated date':
385 $content .= Helper::format_date( get_the_modified_date('U'), $meta['date_format'], $meta['custom_format']); // 'U' param returns the date in timestamp, necessary for format_date()
386 break;
387 case 'category':
388 $content .= Helper::get_taxonomy('category');
389 break;
390 case 'tag':
391 $content .= Helper::get_taxonomy('post_tag');
392 break;
393 case 'portfolio category':
394 $content .= Helper::get_taxonomy('portfolio_category');
395 break;
396 case 'comment':
397 $content .= esc_html( get_comments_number() );
398 break;
399 case 'custom meta':
400 $content .= Helper::get_custom_meta($meta['type_custom']);
401 break;
402 case 'custom taxonomy':
403 $content .= Helper::get_taxonomy($meta['type_custom']);
404 break;
405 case 'custom html':
406 $content .= wp_kses_post($meta['html_custom']);
407 break;
408 case 'reading time':
409 $content .= esc_html( Helper::get_reading_time() );
410 break;
411 default:
412 if (strpos($type, 'product') === 0) {
413 if ($this->get_woo_meta($type) === false) return; // Abort if there's no data for this product meta
414 $content .= wp_kses_post($this->get_woo_meta($type));
415 } else {
416 echo \esc_html($type);
417 }
418 break;
419 }
420
421 // Only output if there's content
422 if (!empty($content)) {
423 echo $wrapper . Helper::esc_svg($icon) . $prefix . $content . $suffix . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
424 }
425 }
426 }