PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.5
UiCore Elements – Free widgets and templates for Elementor v1.0.5
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 / post-component.php

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

1,147 lines 43.5 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 use Elementor\Controls_Manager;
4 use Elementor\Plugin;
5
6 use UiCoreElements\Helper;
7 use UiCoreElements\Controls\Query;
8 use UiCoreElements\Controls\Post_Filter;
9
10 use Elementor\Group_Control_Background;
11 use Elementor\Group_Control_Border;
12 use Elementor\Group_Control_Box_Shadow;
13 use Elementor\Group_Control_Typography;
14 use Elementor\Includes\Widgets\Traits\Button_Trait;
15 use UiCoreElements\Utils\Meta_Trait;
16
17 defined('ABSPATH') || exit();
18
19 /**
20 * Post Component
21 *
22 * @since 1.0.4
23 */
24
25 trait Post_Trait {
26
27 use Button_Trait,
28 Meta_Trait;
29
30 // Control Register Content functions
31 function TRAIT_register_post_item_controls($section = true)
32 {
33 if($section) {
34 $this->start_controls_section(
35 'section_item_content',
36 [
37 'label' => esc_html__('Item', 'uicore-elements'),
38 ]
39 );
40 }
41 $this->add_control(
42 'box_style',
43 [
44 'label' => __('Item Style', 'uicore-elements'),
45 'type' => Controls_Manager::SELECT,
46 'default' => 'classic',
47 'options' => [
48 'classic' => __('Classic', 'uicore-elements'),
49 'split' => __('Split', 'uicore-elements'),
50 'overlay' => __('Overlay', 'uicore-elements'),
51 ],
52 'render_type' => 'template',
53 'prefix_class' => 'ui-e-apg-',
54 ]
55 );
56 $this->add_control(
57 'image',
58 [
59 'label' => __('Image', 'uicore-elements'),
60 'type' => Controls_Manager::SWITCHER,
61 'separator' => 'before',
62 'default' => 'yes'
63 ]
64 );
65 $this->add_control(
66 'image_size_select',
67 [
68 'label' => __('Image Size', 'uicore-elements'),
69 'type' => Controls_Manager::SELECT,
70 'default' => 'uicore-medium',
71 'options' => Helper::get_images_sizes(),
72 'condition' => [
73 'image' => 'yes',
74 ]
75 ]
76 );
77 // $this->add_control('cat_type',[
78 // 'label' => __( 'Cat Type', 'uicore-elements' ),
79 // 'type' => Controls_Manager::SELECT,
80 // 'default' => 'category',
81 // 'options' => [
82 // 'category' => __( 'Category', 'uicore-elements' ),
83 // 'custom' => __( 'Custom Taxonomy', 'uicore-elements' ),
84 // ],
85 // 'condition' => array(
86 // 'category' => 'yes',
87 // ),
88 // ]
89 // );
90 // $this->add_control('cat_type_name',[
91 // 'label' => __( 'Taxonomy', 'uicore-elements' ),
92 // 'type' => Controls_Manager::TEXT,
93 // 'placeholder' => __( 'my_custom_tax', 'uicore-elements' ),
94 // 'condition' => array(
95 // 'cat_type' => 'custom',
96 // ),
97 // ]
98 // );
99 $this->add_control(
100 'title',
101 [
102 'label' => __('Title', 'uicore-elements'),
103 'type' => Controls_Manager::SWITCHER,
104 'separator' => 'before',
105 'default' => 'yes'
106 ]
107 );
108 $this->add_control(
109 'excerpt',
110 [
111 'label' => __('Excerpt', 'uicore-elements'),
112 'type' => Controls_Manager::SWITCHER,
113 'separator' => 'before',
114 'default' => 'yes'
115 ]
116 );
117 $this->add_control(
118 'excerpt_trim',
119 [
120 'label' => __('Excerpt Length (words)', 'uicore-elements'),
121 'type' => Controls_Manager::NUMBER,
122 'min' => 5,
123 'max' => 100,
124 'step' => 1,
125 'default' => 55,
126 'condition' => array(
127 'excerpt' => 'yes',
128 ),
129 ]
130 );
131 $this->add_control(
132 'show_button',
133 [
134 'label' => __('Read More Button', 'uicore-elements'),
135 'type' => Controls_Manager::SWITCHER,
136 'separator' => 'before',
137 'default' => 'no'
138 ]
139 );
140 if($section) {
141 $this->end_controls_section();
142 }
143 }
144 function TRAIT_register_post_button_controls($section = true)
145 {
146 if($section){
147 $this->start_controls_section(
148 'section_button_content',
149 [
150 'label' => esc_html__('Button', 'uicore-elements'),
151 'condition' => array(
152 'show_button' => 'yes',
153 ),
154 ]
155 );
156 }
157
158 $this->register_button_content_controls(
159 [
160 'section_condition' => [
161 'show_button' => 'yes'
162 ],
163 'button_default_text' => 'Read More'
164 ]
165 );
166 $this->remove_control('button_type');
167 $this->remove_control('link');
168 $this->remove_control('button_css_id');
169 $this->remove_control('size');
170 $this->remove_control('align');
171
172 if($section){
173 $this->end_controls_section();
174 }
175 }
176 function TRAIT_register_post_meta_controls($section = true)
177 {
178 if($section){
179 $this->start_controls_section(
180 'section_extra_item_content',
181 [
182 'label' => esc_html__('Meta', 'uicore-elements'),
183 ]
184 );
185 }
186
187 $this->add_control(
188 'top_meta',
189 [
190 'label' => esc_html__('Top Meta', 'uicore-elements'),
191 'type' => \Elementor\Controls_Manager::REPEATER,
192 'fields' => $this->get_meta_content_controls(),
193 'default' => [
194 [
195 'type' => 'author'
196 ],
197 ],
198 'title_field' => '<span style="text-transform: capitalize">{{{ type }}}</span>',
199 'prevent_empty' => false,
200 'separator' => 'before'
201 ]
202 );
203 $this->add_control(
204 'before_title_meta',
205 [
206 'label' => esc_html__('Before Title Meta', 'uicore-elements'),
207 'type' => \Elementor\Controls_Manager::REPEATER,
208 'fields' => $this->get_meta_content_controls(),
209 'default' => [
210 [
211 'type' => 'author'
212 ],
213 ],
214 'title_field' => '<span style="text-transform: capitalize">{{{ type }}}</span>',
215 'prevent_empty' => false,
216 'separator' => 'before',
217 ]
218 );
219 $this->add_control(
220 'after_title_meta',
221 [
222 'label' => esc_html__('After Title Meta', 'uicore-elements'),
223 'type' => \Elementor\Controls_Manager::REPEATER,
224 'fields' => $this->get_meta_content_controls(),
225 'default' => [
226 [
227 'type' => 'author'
228 ],
229 ],
230 'title_field' => '<span style="text-transform: capitalize">{{{ type }}}</span>',
231 'prevent_empty' => false,
232 'separator' => 'before',
233 ]
234 );
235 $this->add_control(
236 'bottom_meta',
237 [
238 'label' => esc_html__('Bottom Meta', 'uicore-elements'),
239 'type' => \Elementor\Controls_Manager::REPEATER,
240 'fields' => $this->get_meta_content_controls(),
241 'default' => [
242 [
243 'type' => 'author'
244 ],
245 ],
246 'title_field' => '<span style="text-transform: capitalize">{{{ type }}}</span>',
247 'prevent_empty' => false,
248 'separator' => 'before',
249 ]
250 );
251 if($section){
252 $this->end_controls_section();
253 }
254 }
255 function TRAIT_register_post_query_controls($section = true)
256 {
257 if($section){
258 $this->start_controls_section(
259 'section_post_grid_def',
260 [
261 'label' => esc_html__('Query', 'uicore-elements'),
262 ]
263 );
264 }
265
266 $this->add_group_control(
267 Post_Filter::get_type(),
268 [
269 'name' => 'posts-filter',
270 'label' => esc_html__('Posts', 'uicore-elements'),
271 'description' => esc_html__('Current Query Settings > Reading', 'uicore-elements'),
272 ]
273 );
274 $this->add_control(
275 'item_limit',
276 [
277 'label' => esc_html__('Item Limit', 'uicore-elements'),
278 'type' => Controls_Manager::SLIDER,
279 'reder_type' => 'template',
280 'range' => [
281 'px' => [
282 'min' => -1,
283 'max' => 100,
284 ],
285 ],
286 'default' => [
287 'size' => 3,
288 ],
289 'condition' => array(
290 'posts-filter_post_type!' => 'current',
291 ),
292 ]
293 );
294
295 $this->add_control(
296 'offset',
297 [
298 'label' => esc_html__('Query Offset', 'uicore-elements'),
299 'type' => Controls_Manager::SLIDER,
300 'render_type' => 'template',
301 'range' => [
302 'px' => [
303 'min' => -1,
304 'max' => 10,
305 ],
306 ],
307 'default' => [
308 'size' => 0,
309 ],
310 'condition' => [
311 'pagination_type' => 'numbers',
312 ]
313 ]
314 );
315
316 $this->add_control(
317 'offset_alert',
318 [
319 'type' => Controls_Manager::ALERT,
320 'alert_type' => 'info',
321 'content' => esc_html__('Offset is disabled with Load More pagination.', 'uicore-elements'),
322 'condition' => [
323 'pagination_type!' => 'numbers',
324 ]
325 ]
326 );
327
328 $this->add_control(
329 'sticky',
330 [
331 'label' => esc_html__('Sticky Posts', 'uicore-elements'),
332 'type' => \Elementor\Controls_Manager::SWITCHER,
333 'label_on' => esc_html__('Show', 'uicore-elements'),
334 'label_off' => esc_html__('Hide', 'uicore-elements'),
335 'description' => esc_html__('Sticky posts works only on the front-end.', 'uicore-elements'),
336 'return_value' => 1,
337 'default' => 0,
338 'condition' => array(
339 'pagination!' => 'yes',
340 ),
341 ]
342 );
343
344 if($section){
345 $this->end_controls_section();
346 }
347 }
348
349 // Styles
350 function TRAIT_register_post_item_style_controls($section = true, $active_tab = false)
351 {
352 if($section){
353 $this->start_controls_section(
354 'section_style_item',
355 [
356 'label' => __('Item Style', 'uicore-elements'),
357 'tab' => Controls_Manager::TAB_STYLE,
358 ]
359 );
360 }
361
362 $this->start_controls_tabs(
363 'item_border_shadow'
364 );
365
366 $this->start_controls_tab(
367 'item_bs_normal_tab',
368 [
369 'label' => esc_html__('Normal', 'plugin-name'),
370 ]
371 );
372 $this->add_group_control(
373 Group_Control_Border::get_type(),
374 [
375 'name' => 'item_border',
376 'selector' => '{{WRAPPER}} .ui-e-item article',
377 ]
378 );
379 $this->add_group_control(
380 Group_Control_Box_Shadow::get_type(),
381 [
382 'name' => 'item_shadow',
383 'selector' => '{{WRAPPER}} .ui-e-item article',
384 ]
385 );
386 $this->end_controls_tab();
387
388 $this->start_controls_tab(
389 'item_bs_hover_tab',
390 [
391 'label' => esc_html__('Hover', 'plugin-name'),
392 ]
393 );
394 $this->add_group_control(
395 Group_Control_Border::get_type(),
396 [
397 'name' => 'item_border_hover',
398 'selector' => '{{WRAPPER}} .ui-e-item:hover article',
399 ]
400 );
401 $this->add_group_control(
402 Group_Control_Box_Shadow::get_type(),
403 [
404 'name' => 'item_shadow_hover',
405 'selector' => '{{WRAPPER}} .ui-e-item:hover article',
406 ]
407 );
408 $this->end_controls_tab();
409
410 if($active_tab){
411 $this->start_controls_tab(
412 'item_bs_active_tab',
413 [
414 'label' => esc_html__('Active', 'plugin-name'),
415 ]
416 );
417 $this->add_group_control(
418 Group_Control_Border::get_type(),
419 [
420 'name' => 'item_border_active',
421 'selector' => '{{WRAPPER}} .ui-e-item.ui-e-active article',
422 ]
423 );
424 $this->add_group_control(
425 Group_Control_Box_Shadow::get_type(),
426 [
427 'name' => 'item_shadow_active',
428 'selector' => '{{WRAPPER}} .ui-e-item.ui-e-active article',
429 ]
430 );
431 $this->end_controls_tab();
432 }
433
434 $this->end_controls_tabs();
435
436 $this->add_control(
437 'item_radius',
438 [
439 'label' => esc_html__('Border Radius', 'uicore-elements'),
440 'type' => Controls_Manager::DIMENSIONS,
441 'separator' => 'before',
442 'selectors' => [
443 '{{WRAPPER}} ' => '--ui-e-border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;'
444 ],
445 ]
446 );
447
448 if($section){
449 $this->end_controls_section();
450 }
451 }
452 function TRAIT_register_post_content_style_controls($section = true)
453 {
454 if($section){
455 $this->start_controls_section(
456 'section_style_content',
457 [
458 'label' => __('Content Style', 'uicore-elements'),
459 'tab' => Controls_Manager::TAB_STYLE,
460 ]
461 );
462 }
463 $this->add_control(
464 'image_size',
465 [
466 'label' => __('Image Height (%)', 'uicore-elements'),
467 'type' => Controls_Manager::NUMBER,
468 'min' => 1,
469 'max' => 500,
470 'step' => 1,
471 'default' => 57,
472 'selectors' => [
473 '{{WRAPPER}} .ui-e-post-top' => '--ui-e-img-size: {{VALUE}}',
474 ],
475 'condition' => [
476 'masonry!' => 'ui-e-maso',
477 ],
478 ]
479 );
480 $this->add_control(
481 'image_overflow',
482 [
483 'label' => __('Independent Border Radius and Shadow', 'uicore-elements'),
484 'type' => Controls_Manager::SWITCHER,
485 'default' => 'no',
486 'prefix_class' => 'ui-e-post-ovf-',
487 'condition' => array(
488 'box_style!' => 'overlay',
489 ),
490 ]
491 );
492 $this->add_control(
493 'image_radius',
494 [
495 'label' => esc_html__('Border Radius', 'uicore-elements'),
496 'type' => Controls_Manager::DIMENSIONS,
497 'selectors' => [
498 '{{WRAPPER}} .ui-e-post-top' => 'border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;'
499 ],
500 'condition' => array(
501 'image_overflow' => 'yes',
502 ),
503 ]
504 );
505 $this->add_group_control(
506 Group_Control_Box_Shadow::get_type(),
507 [
508 'name' => 'image_shadow',
509 'label' => esc_html__('Box Shadow', 'uicore-elements'),
510 'selector' => '{{WRAPPER}} .ui-e-post-top',
511 'condition' => array(
512 'image_overflow' => 'yes',
513 ),
514 ]
515 );
516 $this->add_responsive_control(
517 'content_align',
518 [
519 'label' => esc_html__('Content Alignment', 'uicore-elements'),
520 'type' => Controls_Manager::CHOOSE,
521 'options' => [
522 'left' => [
523 'title' => esc_html__('Left', 'uicore-elements'),
524 'icon' => 'eicon-text-align-left',
525 ],
526 'center' => [
527 'title' => esc_html__('Center', 'uicore-elements'),
528 'icon' => 'eicon-text-align-center',
529 ],
530 'stretch' => [
531 'title' => esc_html__('Justified', 'uicore-elements'),
532 'icon' => 'eicon-text-align-justify',
533 ],
534 ],
535 'selectors' => [
536 '{{WRAPPER}} .ui-e-post-content' => 'align-items: {{VALUE}}; text-align: {{VALUE}};',
537 ],
538 ]
539 );
540 $this->add_control(
541 'title_color',
542 [
543 'label' => esc_html__('Title Color', 'uicore-elements'),
544 'type' => Controls_Manager::COLOR,
545 'default' => '',
546 'separator' => 'before',
547 'selectors' => [
548 '{{WRAPPER}} .ui-e-post-title' => 'color: {{VALUE}};',
549 ],
550 ]
551 );
552 $this->add_control(
553 'title_hcolor',
554 [
555 'label' => esc_html__('Title Hover Color', 'uicore-elements'),
556 'type' => Controls_Manager::COLOR,
557 'default' => '',
558 'selectors' => [
559 '{{WRAPPER}} .ui-e-post-title:hover' => 'color: {{VALUE}};',
560 ],
561 ]
562 );
563 $this->add_group_control(
564 Group_Control_Typography::get_type(),
565 [
566 'name' => 'title_typography',
567 'label' => esc_html__('Title Typography', 'uicore-elements'),
568 'selector' => '{{WRAPPER}} .ui-e-post-title',
569 ]
570 );
571 $this->add_control(
572 'title_gap',
573 [
574 'label' => __('Title Top Space', 'uicore-elements'),
575 'type' => Controls_Manager::SLIDER,
576 'size_units' => ['em'],
577 'separator' => 'after',
578 'range' => [
579 'px' => [
580 'min' => 0,
581 'max' => 3,
582 'step' => 0.1,
583 ],
584 ],
585 'default' => [
586 'unit' => 'em',
587 'size' => 1.2,
588 ],
589 'selectors' => [
590 '{{WRAPPER}} .ui-e-post-title' => 'margin-top: {{SIZE}}em;',
591 ],
592 ]
593 );
594 $this->add_control(
595 'text_color',
596 [
597 'label' => esc_html__('Excerpt Color', 'uicore-elements'),
598 'type' => Controls_Manager::COLOR,
599 'default' => '',
600 'selectors' => [
601 '{{WRAPPER}} .ui-e-post-text' => 'color: {{VALUE}};',
602 ],
603 ]
604 );
605 $this->add_group_control(
606 Group_Control_Typography::get_type(),
607 [
608 'name' => 'text_typography',
609 'label' => esc_html__('Excerpt Typography', 'uicore-elements'),
610 'selector' => '{{WRAPPER}} .ui-e-post-text',
611 ]
612 );
613 $this->add_control(
614 'text_gap',
615 [
616 'label' => __('Excerpt Top Space', 'uicore-elements'),
617 'type' => Controls_Manager::SLIDER,
618 'size_units' => ['em'],
619 'separator' => 'after',
620 'range' => [
621 'px' => [
622 'min' => 0,
623 'max' => 3,
624 'step' => 0.1,
625 ],
626 ],
627 'default' => [
628 'unit' => 'em',
629 'size' => 0.8,
630 ],
631 'selectors' => [
632 '{{WRAPPER}} .ui-e-post-text' => 'margin-top: {{SIZE}}em;',
633 ],
634 ]
635 );
636 $this->add_responsive_control(
637 'content_padding',
638 [
639 'label' => esc_html__('Content Padding', 'uicore-elements'),
640 'type' => Controls_Manager::DIMENSIONS,
641 'size_units' => ['px', 'em', '%'],
642 'selectors' => [
643 '{{WRAPPER}} .ui-e-post-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};'
644 ]
645 ]
646 );
647 $this->add_control(
648 'content_gap',
649 [
650 'label' => __('Content Space', 'uicore-elements'),
651 'type' => Controls_Manager::SLIDER,
652 'size_units' => ['em'],
653 'separator' => 'after',
654 'range' => [
655 'px' => [
656 'min' => 0,
657 'max' => 3,
658 'step' => 0.1,
659 ],
660 ],
661 'default' => [
662 'unit' => 'em',
663 'size' => 0,
664 ],
665 'selectors' => [
666 '{{WRAPPER}} ' => '--ui-e-content-space: {{SIZE}}em;',
667 ],
668 ]
669 );
670 $this->add_group_control(
671 Group_Control_Background::get_type(),
672 [
673 'name' => 'content_bg',
674 'selector' => '{{WRAPPER}} .ui-e-post-content',
675 ]
676 );
677
678 if($section){
679 $this->end_controls_section();
680 }
681 }
682 function TRAIT_register_post_button_style_controls($section = true)
683 {
684 if($section){
685 $this->start_controls_section(
686 'section_button_style',
687 [
688 'label' => esc_html__('Button Style', 'uicore-elements'),
689 'tab' => Controls_Manager::TAB_STYLE,
690 'condition' => array(
691 'show_button' => 'yes',
692 ),
693 ]
694 );
695 }
696 $this->add_responsive_control(
697 'button_align',
698 [
699 'label' => esc_html__( 'Alignment', 'elementor' ),
700 'type' => Controls_Manager::CHOOSE,
701 'options' => [
702 'start' => [
703 'title' => esc_html__( 'Left', 'elementor' ),
704 'icon' => 'eicon-text-align-left',
705 ],
706 'center' => [
707 'title' => esc_html__( 'Center', 'elementor' ),
708 'icon' => 'eicon-text-align-center',
709 ],
710 'end' => [
711 'title' => esc_html__( 'Right', 'elementor' ),
712 'icon' => 'eicon-text-align-right',
713 ],
714 'normal' => [
715 'title' => esc_html__( 'Justified', 'elementor' ),
716 'icon' => 'eicon-text-align-justify',
717 ],
718 ],
719 'default' => 'start',
720 'selectors' => [
721 '{{WRAPPER}} .ui-e-readmore' => 'align-self: {{VALUE}};',
722 ],
723
724 ]
725 );
726 $this->register_button_style_controls(
727 [
728 'section_condition' => [
729 'show_button' => 'yes'
730 ]
731 ]
732 );
733 // Remove button alignment from Elementor button traits because (seens to be a bug), updating Selector CSS with update_control(), don't work as expected with responsiveness
734 $this->remove_responsive_control('align');
735
736 $this->TRAIT_register_post_specific_controls('button_gap');
737
738 if($section) {
739 $this->end_controls_section();
740 }
741 }
742 function TRAIT_register_post_meta_style_controls($section = true)
743 {
744 if($section) {
745 $this->start_controls_section(
746 'section_style_extra_content',
747 [
748 'label' => __('Meta Style', 'uicore-elements'),
749 'tab' => Controls_Manager::TAB_STYLE,
750 ]
751 );
752 }
753 $this->start_controls_tabs('style_extra_tabs');
754 $this->start_controls_tab(
755 'style_top_tab',
756 [
757 'label' => esc_html__('Top', 'uicore-elements'),
758 ]
759 );
760 $this->get_meta_style_controls('top');
761 $this->end_controls_tab();
762
763 $this->start_controls_tab(
764 'style_before_title_tab',
765 [
766 'label' => esc_html__('Before Title', 'uicore-elements'),
767 ]
768 );
769 $this->get_meta_style_controls('before_title');
770 $this->end_controls_tab();
771
772 $this->start_controls_tab(
773 'style_after_title_tab',
774 [
775 'label' => esc_html__('After Title', 'uicore-elements'),
776 ]
777 );
778 $this->get_meta_style_controls('after_title');
779 $this->end_controls_tab();
780
781 $this->start_controls_tab(
782 'style_bottom_tab',
783 [
784 'label' => esc_html__('Bottom', 'uicore-elements'),
785 ]
786 );
787 $this->get_meta_style_controls('bottom');
788 $this->end_controls_tab();
789 $this->end_controls_tabs();
790
791 if($section) {
792 $this->end_controls_section();
793 }
794 }
795 function TRAIT_register_post_animation_controls()
796 {
797 $this->add_control(
798 'anim_image',
799 [
800 'label' => __('Image Hover Animation', 'uicore-elements'),
801 'type' => Controls_Manager::SELECT,
802 'label_block' => true,
803 'default' => 'ui-e-img-anim-zoom',
804 'options' => [
805 '' => __('None', 'uicore-elements'),
806 'ui-e-img-anim-zoom' => __('Zoom', 'uicore-elements'),
807 ],
808 'prefix_class' => '',
809 ]
810 );
811 $this->add_control(
812 'anim_meta',
813 [
814 'label' => __('Meta Hover Animation', 'uicore-elements'),
815 'type' => Controls_Manager::SELECT,
816 'label_block' => true,
817 'default' => '',
818 'options' => [
819 '' => __('None', 'uicore-elements'),
820 'ui-e-meta-anim-show' => __('Show', 'uicore-elements'),
821 ],
822 'prefix_class' => '',
823 ]
824 );
825 $this->add_control(
826 'important_note',
827 [
828 'label' => esc_html__('Important Note', 'uicore-elements'),
829 'type' => \Elementor\Controls_Manager::RAW_HTML,
830 'raw' => '<div class="elementor-control-field-description" style="margin-top: -7px;">' . esc_html__('This works only for Below Title Meta.', 'uicore-elements') . '</div>',
831 'show_label' => false,
832 'condition' => array(
833 'box_style' => 'overlay',
834 ),
835 ]
836 );
837 $this->add_control(
838 'anim_title',
839 [
840 'label' => __('Title Hover Animation', 'uicore-elements'),
841 'type' => Controls_Manager::SELECT,
842 'label_block' => true,
843 'default' => '',
844 'options' => [
845 '' => __('None', 'uicore-elements'),
846 'ui-e-title-anim-underline' => __('Underline', 'uicore-elements'),
847 ],
848 'prefix_class' => '',
849 ]
850 );
851 $this->add_control(
852 'anim_content',
853 [
854 'label' => __('Content Hover Animation', 'uicore-elements'),
855 'type' => Controls_Manager::SELECT,
856 'label_block' => true,
857 'default' => '',
858 'options' => [
859 '' => __('None', 'uicore-elements'),
860 'ui-e-content-anim-show' => __('Show', 'uicore-elements'),
861 ],
862 'prefix_class' => '',
863 'condition' => array(
864 'box_style' => 'overlay',
865 ),
866 ]
867 );
868 $this->add_control(
869 'anim_btn',
870 [
871 'label' => __('Button Hover Animation', 'uicore-elements'),
872 'type' => Controls_Manager::SELECT,
873 'label_block' => true,
874 'default' => '',
875 'options' => [
876 '' => __('None', 'uicore-elements'),
877 'ui-e-btn-anim-show' => __('Show', 'uicore-elements'),
878 ],
879 'prefix_class' => '',
880 'condition' => [
881 'show_button' => 'yes',
882 ],
883 ]
884 );
885 }
886
887 /**
888 * Registers specific controls that can't be registered in blocks because of diferent use by different widgets or some other reason.
889 *
890 * @param string $control The control to register.
891 * @return void
892 */
893 function TRAIT_register_post_specific_controls($control)
894 {
895 switch ($control) {
896 case 'button_gap':
897 $this->add_control(
898 'button_gap',
899 [
900 'label' => __('Button Top Space', 'uicore-elements'),
901 'type' => Controls_Manager::SLIDER,
902 'size_units' => ['em'],
903 'range' => [
904 'px' => [
905 'min' => 0,
906 'max' => 3,
907 'step' => 0.1,
908 ],
909 ],
910 'default' => [
911 'unit' => 'em',
912 'size' => 0.8,
913 ],
914 'selectors' => [
915 '{{WRAPPER}} .elementor-button' => 'margin-top: {{SIZE}}em;',
916 ],
917 ]
918 );
919 break;
920 }
921 }
922
923 // Helper functions
924 function TRAIT_query_posts($posts_per_page, $type = null)
925 {
926 if (!Plugin::$instance->editor->is_edit_mode() && $this->get_settings('posts-filter_post_type') === 'current' && !isset($_GET['uicore-tb'])) {
927 global $wp_query;
928 $this->_query = $wp_query;
929 } elseif ($this->get_settings('posts-filter_post_type') === 'related') {
930 $this->_query = Helper::get_related('random', $posts_per_page);
931 } else {
932 $query_args = Query::get_query_args('posts-filter', $this->get_settings(), get_the_ID());
933
934 if ($type === 'portfolio') {
935 $query_args['orderby'] = 'menu_order date';
936 }
937
938 if ($type === 'current') {
939 unset($query_args['posts_per_page']);
940 }
941
942 $this->_query = new \WP_Query($query_args);
943 }
944 }
945
946 // Render functions
947 function get_post_image()
948 {
949
950 if ($this->get_settings_for_display('image') === 'yes') {
951 $pic_id = get_post_thumbnail_id();
952 if (!$pic_id)
953 return;
954 $size = $this->get_settings_for_display('image_size_select') ?? 'uicore-medium';
955 ?>
956 <a class="ui-e-post-img-wrapp" href="<?php echo esc_url(get_permalink()); ?>" title="<?php echo esc_attr__('View Post:', 'uicore-elements') . the_title_attribute(['echo' => false]); ?>">
957 <?php if ($this->get_settings_for_display('masonry') === 'ui-e-maso') { ?>
958 <?php the_post_thumbnail($size, ['class' => 'ui-e-post-img']); ?>
959 <?php } else { ?>
960 <div class="ui-e-post-img" style="background-image:url(<?php echo wp_get_attachment_image_url($pic_id, $size) ?>)"></div>
961 <?php } ?>
962 </a>
963 <?php
964 }
965 }
966 function get_post_title()
967 {
968 if ($this->get_settings_for_display('title') === 'yes')
969 ?>
970 <a href="<?php echo esc_url( get_permalink() );?>" title="<?php echo esc_attr__('View Post:','uicore-elements') . esc_html(the_title_attribute(['echo'=>false])); ?>">
971 <h4 class="ui-e-post-title"><span><?php echo esc_html(get_the_title()); ?></span></h4>
972 </a>
973 <?php
974 }
975 function get_post_meta($position)
976 {
977 $meta_list = $this->get_settings_for_display($position . '_meta');
978 if (!isset($meta_list[0]) || $meta_list[0]['type'] == '') {
979 return;
980 }
981 echo ($position == 'top') ? '<div class="ui-e-post-top-meta">' : '';
982 echo ($position == 'after_title') ? '<div class="ui-e-meta-wrapp">' : '';
983 echo '<div class="ui-e-post-meta ui-e-'.esc_attr($position).'">';
984 foreach ($meta_list as $meta) {
985 if($meta['type'] != 'none'){
986 echo '<div class="ui-e-meta-item">';
987 $this->display_meta($meta);
988 echo '</div>';
989
990 if( next( $meta_list ) && $this->get_settings_for_display( $position.'_meta_separator' ) ) {
991 echo '<span class="ui-e-separator">'.esc_html($this->get_settings_for_display( $position.'_meta_separator' )).'</span>';
992 }
993 }
994 }
995 echo '</div>';
996 echo ($position == 'top' || $position == 'after_title') ? '</div>' : '';
997 }
998 function get_button()
999 {
1000 $settings = $this->get_settings_for_display();
1001
1002 $this->add_render_attribute('button', 'class', ['elementor-button-link', 'elementor-button', 'ui-e-readmore']);
1003 $this->add_render_attribute('button', 'role', 'button');
1004 $this->add_render_attribute('content-wrapper', 'class', 'elementor-button-content-wrapper');
1005
1006 if (!empty($settings['button_css_id'])) {
1007 $this->add_render_attribute('button', 'id', $settings['button_css_id']);
1008 }
1009
1010 if (!empty($settings['size'])) {
1011 $this->add_render_attribute('button', 'class', 'elementor-size-' . $settings['size']);
1012 }
1013
1014 if (!empty($settings['hover_animation'])) {
1015 $this->add_render_attribute('button', 'class', 'elementor-animation-' . $settings['hover_animation']);
1016 }
1017 $this->add_render_attribute([
1018 'icon-align' => [
1019 'class' => [
1020 'elementor-button-icon',
1021 'elementor-align-icon-' . $settings['icon_align'],
1022 ],
1023 ],
1024 'text' => [
1025 'class' => 'elementor-button-text',
1026 ],
1027 ]);
1028
1029 $tbn_content = '<span ' . $this->get_render_attribute_string('content-wrapper') . '>';
1030
1031 if (!empty($settings['icon']) || !empty($settings['selected_icon']['value'])) {
1032 $tbn_content .= '<span ' . $this->get_render_attribute_string('icon-align') . '>';
1033 \ob_start();
1034 \Elementor\Icons_Manager::render_icon($settings['selected_icon'], ['aria-hidden' => 'true']);
1035 $tbn_content .= \ob_get_clean();
1036 $tbn_content .= '</span>';
1037 }
1038
1039 $tbn_content .= '<span ' . $this->get_render_attribute_string('text') . '>' . $this->get_settings_for_display('text') . '</span>';
1040 $tbn_content .= '</span>';
1041
1042 if ('product' === get_post_type()) {
1043 // WooCommerce product
1044 global $product;
1045
1046 if ($product) {
1047 // Display WooCommerce add to cart button
1048 echo wp_kses_post(apply_filters(
1049 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
1050 sprintf(
1051 '<a href="%s" data-quantity="%s" %s>%s</a>',
1052 esc_url($product->add_to_cart_url()),
1053 esc_attr(1),
1054 $this->get_render_attribute_string('button'),
1055 $tbn_content
1056 ),
1057 $product
1058 ));
1059 }
1060 } else {
1061
1062 // Default button
1063 ?>
1064 <a href="<?php echo esc_url(get_permalink()); ?>" <?php $this->print_render_attribute_string('button'); ?>>
1065 <?php echo wp_kses_post($tbn_content); ?>
1066 </a>
1067 <?php
1068 }
1069 }
1070 function TRAIT_render_item($carousel = false, $legacy = false)
1071 {
1072 $settings = $this->get_settings_for_display();
1073 $excerpt_length = $settings['excerpt_trim'];
1074
1075 // Classnames but checking if we the widget is APG (legacy version)
1076 $item_classes = $legacy ? ['ui-e-post-item', 'ui-e-item'] : ['ui-e-item'] ; // Single item lower wrap class receptor
1077 $hover_item_class = $legacy ? 'anim_item' : 'item_hover_animation'; // item hover animation class
1078
1079 // If widget is not carousel type, we set animations classes directly on item selector
1080 if(!$carousel) {
1081 $item_classes[] = 'ui-e-animations-wrp';
1082 $item_classes[] = $settings['animate_items'] === 'ui-e-grid-animate' ? 'elementor-invisible' : '';
1083 $item_classes[] = $settings[$hover_item_class] !== '' ? $settings[$hover_item_class] : '';
1084
1085 } else {
1086 // Get entrance and item hover animation classes
1087 $entrance = (isset($settings['animate_items']) && $settings['animate_items'] == 'ui-e-grid-animate') ? 'elementor-invisible' : '';
1088 $hover = isset($settings[$hover_item_class]) ? $settings[$hover_item_class] : ''; //$settings[$hover_item_class] : null;
1089 $animations = sprintf('%s %s', $entrance, $hover);
1090
1091 // Check if entrance or hover animation are set
1092 $has_animation = !empty($entrance) || !empty($hover)
1093
1094 // Prints extra wrappers required by the carousel script
1095 ?>
1096 <div class="ui-e-wrp swiper-slide">
1097 <?php if($has_animation) : ?>
1098 <div class="ui-e-animations-wrp <?php echo esc_attr($animations);?>">
1099 <?php endif; ?>
1100 <div class="ui-e-item-wrp">
1101 <?php } ?>
1102
1103 <div class="<?php echo esc_attr( implode(' ', $item_classes));?>">
1104 <article <?php post_class(); ?>>
1105 <div class="ui-e-post-top">
1106 <?php $this->get_post_image(); ?>
1107 <?php $this->get_post_meta('top'); ?>
1108 </div>
1109 <div class="ui-e-post-content">
1110 <?php $this->get_post_meta('before_title'); ?>
1111 <?php
1112 if ($this->get_settings_for_display('title') === 'yes')
1113 $this->get_post_title();
1114 ?>
1115 <?php $this->get_post_meta('after_title'); ?>
1116 <?php
1117 if ($this->get_settings_for_display('excerpt'))
1118 echo wp_kses_post('<div class="ui-e-post-text">' . wp_trim_words(get_the_excerpt(), $excerpt_length) . '</div>');
1119 ?>
1120 <?php $this->get_post_meta('bottom'); // button
1121 ?>
1122 <?php
1123 if ($this->get_settings_for_display('show_button') === 'yes') {
1124 // Add match height spacing element if carousel. May look intrusive, but is the simplest method compared
1125 // to absolute positioning or catching last content element to apply margin.
1126 if($carousel && $settings['match_height'] === 'yes'){
1127 ?>
1128 <span class="ui-e-match-height"></span>
1129 <?php
1130 }
1131 $this->get_button();
1132 }
1133 ?>
1134 </div>
1135 </article>
1136 </div>
1137
1138 <?php if($carousel) { ?>
1139 </div>
1140 <?php if($has_animation) : ?>
1141 </div>
1142 <?php endif; ?>
1143 </div>
1144 <?php }
1145 }
1146 }
1147