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

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

1,107 lines 41.7 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->register_button_style_controls(
697 [
698 'section_condition' => [
699 'show_button' => 'yes'
700 ]
701 ]
702 );
703 $this->TRAIT_register_post_specific_controls('button_gap');
704
705 if($section) {
706 $this->end_controls_section();
707 }
708 }
709 function TRAIT_register_post_meta_style_controls($section = true)
710 {
711 if($section) {
712 $this->start_controls_section(
713 'section_style_extra_content',
714 [
715 'label' => __('Meta Style', 'uicore-elements'),
716 'tab' => Controls_Manager::TAB_STYLE,
717 ]
718 );
719 }
720 $this->start_controls_tabs('style_extra_tabs');
721 $this->start_controls_tab(
722 'style_top_tab',
723 [
724 'label' => esc_html__('Top', 'uicore-elements'),
725 ]
726 );
727 $this->get_meta_style_controls('top');
728 $this->end_controls_tab();
729
730 $this->start_controls_tab(
731 'style_before_title_tab',
732 [
733 'label' => esc_html__('Before Title', 'uicore-elements'),
734 ]
735 );
736 $this->get_meta_style_controls('before_title');
737 $this->end_controls_tab();
738
739 $this->start_controls_tab(
740 'style_after_title_tab',
741 [
742 'label' => esc_html__('After Title', 'uicore-elements'),
743 ]
744 );
745 $this->get_meta_style_controls('after_title');
746 $this->end_controls_tab();
747
748 $this->start_controls_tab(
749 'style_bottom_tab',
750 [
751 'label' => esc_html__('Bottom', 'uicore-elements'),
752 ]
753 );
754 $this->get_meta_style_controls('bottom');
755 $this->end_controls_tab();
756 $this->end_controls_tabs();
757
758 if($section) {
759 $this->end_controls_section();
760 }
761 }
762 function TRAIT_register_post_animation_controls()
763 {
764 $this->add_control(
765 'anim_image',
766 [
767 'label' => __('Image Hover Animation', 'uicore-elements'),
768 'type' => Controls_Manager::SELECT,
769 'label_block' => true,
770 'default' => 'ui-e-img-anim-zoom',
771 'options' => [
772 '' => __('None', 'uicore-elements'),
773 'ui-e-img-anim-zoom' => __('Zoom', 'uicore-elements'),
774 ],
775 'prefix_class' => '',
776 ]
777 );
778 $this->add_control(
779 'anim_meta',
780 [
781 'label' => __('Meta Hover Animation', 'uicore-elements'),
782 'type' => Controls_Manager::SELECT,
783 'label_block' => true,
784 'default' => '',
785 'options' => [
786 '' => __('None', 'uicore-elements'),
787 'ui-e-meta-anim-show' => __('Show', 'uicore-elements'),
788 ],
789 'prefix_class' => '',
790 ]
791 );
792 $this->add_control(
793 'important_note',
794 [
795 'label' => esc_html__('Important Note', 'uicore-elements'),
796 'type' => \Elementor\Controls_Manager::RAW_HTML,
797 'raw' => '<div class="elementor-control-field-description" style="margin-top: -7px;">' . esc_html__('This works only for Below Title Meta.', 'uicore-elements') . '</div>',
798 'show_label' => false,
799 'condition' => array(
800 'box_style' => 'overlay',
801 ),
802 ]
803 );
804 $this->add_control(
805 'anim_title',
806 [
807 'label' => __('Title Hover Animation', 'uicore-elements'),
808 'type' => Controls_Manager::SELECT,
809 'label_block' => true,
810 'default' => '',
811 'options' => [
812 '' => __('None', 'uicore-elements'),
813 'ui-e-title-anim-underline' => __('Underline', 'uicore-elements'),
814 ],
815 'prefix_class' => '',
816 ]
817 );
818 $this->add_control(
819 'anim_content',
820 [
821 'label' => __('Content Hover Animation', 'uicore-elements'),
822 'type' => Controls_Manager::SELECT,
823 'label_block' => true,
824 'default' => '',
825 'options' => [
826 '' => __('None', 'uicore-elements'),
827 'ui-e-content-anim-show' => __('Show', 'uicore-elements'),
828 ],
829 'prefix_class' => '',
830 'condition' => array(
831 'box_style' => 'overlay',
832 ),
833 ]
834 );
835 $this->add_control(
836 'anim_btn',
837 [
838 'label' => __('Button Hover Animation', 'uicore-elements'),
839 'type' => Controls_Manager::SELECT,
840 'label_block' => true,
841 'default' => '',
842 'options' => [
843 '' => __('None', 'uicore-elements'),
844 'ui-e-btn-anim-show' => __('Show', 'uicore-elements'),
845 ],
846 'prefix_class' => '',
847 'condition' => [
848 'show_button' => 'yes',
849 ],
850 ]
851 );
852 }
853
854 /**
855 * Registers specific controls that can't be registered in blocks because of diferent use by different widgets or some other reason.
856 *
857 * @param string $control The control to register.
858 * @return void
859 */
860 function TRAIT_register_post_specific_controls($control)
861 {
862 switch ($control) {
863 case 'button_gap':
864 $this->add_control(
865 'button_gap',
866 [
867 'label' => __('Button Top Space', 'uicore-elements'),
868 'type' => Controls_Manager::SLIDER,
869 'size_units' => ['em'],
870 'range' => [
871 'px' => [
872 'min' => 0,
873 'max' => 3,
874 'step' => 0.1,
875 ],
876 ],
877 'default' => [
878 'unit' => 'em',
879 'size' => 0.8,
880 ],
881 'selectors' => [
882 '{{WRAPPER}} .elementor-button' => 'margin-top: {{SIZE}}em;',
883 ],
884 ]
885 );
886 break;
887 }
888 }
889
890 // Helper functions
891 function TRAIT_query_posts($posts_per_page, $type = null)
892 {
893 if (!Plugin::$instance->editor->is_edit_mode() && $this->get_settings('posts-filter_post_type') === 'current' && !isset($_GET['uicore-tb'])) {
894 global $wp_query;
895 $this->_query = $wp_query;
896 } elseif ($this->get_settings('posts-filter_post_type') === 'related') {
897 $this->_query = Helper::get_related('random', $posts_per_page);
898 } else {
899 $query_args = Query::get_query_args('posts-filter', $this->get_settings(), get_the_ID());
900
901 if ($type === 'portfolio') {
902 $query_args['orderby'] = 'menu_order date';
903 }
904
905 if ($type === 'current') {
906 unset($query_args['posts_per_page']);
907 }
908
909 $this->_query = new \WP_Query($query_args);
910 }
911 }
912
913 // Render functions
914 function get_post_image()
915 {
916
917 if ($this->get_settings_for_display('image') === 'yes') {
918 $pic_id = get_post_thumbnail_id();
919 if (!$pic_id)
920 return;
921 $size = $this->get_settings_for_display('image_size_select') ?? 'uicore-medium';
922 ?>
923 <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]); ?>">
924 <?php if ($this->get_settings_for_display('masonry') === 'ui-e-maso') { ?>
925 <?php the_post_thumbnail($size, ['class' => 'ui-e-post-img']); ?>
926 <?php } else { ?>
927 <div class="ui-e-post-img" style="background-image:url(<?php echo wp_get_attachment_image_url($pic_id, $size) ?>)"></div>
928 <?php } ?>
929 </a>
930 <?php
931 }
932 }
933 function get_post_title()
934 {
935 if ($this->get_settings_for_display('title') === 'yes')
936 ?>
937 <a href="<?php echo esc_url( get_permalink() );?>" title="<?php echo esc_attr__('View Post:','uicore-elements') . esc_html(the_title_attribute(['echo'=>false])); ?>">
938 <h4 class="ui-e-post-title"><span><?php echo esc_html(get_the_title()); ?></span></h4>
939 </a>
940 <?php
941 }
942 function get_post_meta($position)
943 {
944 $meta_list = $this->get_settings_for_display($position . '_meta');
945 if (!isset($meta_list[0]) || $meta_list[0]['type'] == '') {
946 return;
947 }
948 echo ($position == 'top') ? '<div class="ui-e-post-top-meta">' : '';
949 echo ($position == 'after_title') ? '<div class="ui-e-meta-wrapp">' : '';
950 echo '<div class="ui-e-post-meta ui-e-'.esc_attr($position).'">';
951 foreach ($meta_list as $meta) {
952 if($meta['type'] != 'none'){
953 echo '<div class="ui-e-meta-item">';
954 $this->display_meta($meta);
955 echo '</div>';
956
957 if( next( $meta_list ) && $this->get_settings_for_display( $position.'_meta_separator' ) ) {
958 echo '<span class="ui-e-separator">'.esc_html($this->get_settings_for_display( $position.'_meta_separator' )).'</span>';
959 }
960 }
961 }
962 echo '</div>';
963 echo ($position == 'top' || $position == 'after_title') ? '</div>' : '';
964 }
965 function get_button()
966 {
967 $settings = $this->get_settings_for_display();
968
969 $this->add_render_attribute('button', 'class', ['elementor-button-link', 'elementor-button', 'ui-e-readmore']);
970 $this->add_render_attribute('button', 'role', 'button');
971 $this->add_render_attribute('content-wrapper', 'class', 'elementor-button-content-wrapper');
972
973 if (!empty($settings['button_css_id'])) {
974 $this->add_render_attribute('button', 'id', $settings['button_css_id']);
975 }
976
977 if (!empty($settings['size'])) {
978 $this->add_render_attribute('button', 'class', 'elementor-size-' . $settings['size']);
979 }
980
981 if (!empty($settings['hover_animation'])) {
982 $this->add_render_attribute('button', 'class', 'elementor-animation-' . $settings['hover_animation']);
983 }
984 $this->add_render_attribute([
985 'icon-align' => [
986 'class' => [
987 'elementor-button-icon',
988 'elementor-align-icon-' . $settings['icon_align'],
989 ],
990 ],
991 'text' => [
992 'class' => 'elementor-button-text',
993 ],
994 ]);
995
996 $tbn_content = '<span ' . $this->get_render_attribute_string('content-wrapper') . '>';
997
998 if (!empty($settings['icon']) || !empty($settings['selected_icon']['value'])) {
999 $tbn_content .= '<span ' . $this->get_render_attribute_string('icon-align') . '>';
1000 \ob_start();
1001 \Elementor\Icons_Manager::render_icon($settings['selected_icon'], ['aria-hidden' => 'true']);
1002 $tbn_content .= \ob_get_clean();
1003 $tbn_content .= '</span>';
1004 }
1005
1006 $tbn_content .= '<span ' . $this->get_render_attribute_string('text') . '>' . $this->get_settings_for_display('text') . '</span>';
1007 $tbn_content .= '</span>';
1008
1009 if ('product' === get_post_type()) {
1010 // WooCommerce product
1011 global $product;
1012
1013 if ($product) {
1014 // Display WooCommerce add to cart button
1015 echo wp_kses_post(apply_filters(
1016 'woocommerce_loop_add_to_cart_link', // WPCS: XSS ok.
1017 sprintf(
1018 '<a href="%s" data-quantity="%s" %s>%s</a>',
1019 esc_url($product->add_to_cart_url()),
1020 esc_attr(1),
1021 $this->get_render_attribute_string('button'),
1022 $tbn_content
1023 ),
1024 $product
1025 ));
1026 }
1027 } else {
1028
1029 // Default button
1030 ?>
1031 <a href="<?php echo esc_url(get_permalink()); ?>" <?php $this->print_render_attribute_string('button'); ?>>
1032 <?php echo wp_kses_post($tbn_content); ?>
1033 </a>
1034 <?php
1035 }
1036 }
1037 function TRAIT_render_item($carousel = false, $legacy = false)
1038 {
1039 $settings = $this->get_settings_for_display();
1040 $excerpt_length = $settings['excerpt_trim'];
1041
1042 // Classnames but checking if we the widget is APG (legacy version)
1043 $item_classes = $legacy ? ['ui-e-post-item', 'ui-e-item'] : ['ui-e-item'] ; // Single item lower wrap class receptor
1044 $hover_item_class = $legacy ? 'anim_item' : 'item_hover_animation'; // item hover animation class
1045
1046 // If widget is not carousel type, we set animations classes directly on item selector
1047 if(!$carousel) {
1048 $item_classes[] = 'ui-e-animations-wrp';
1049 $item_classes[] = $settings['animate_items'] === 'ui-e-grid-animate' ? 'elementor-invisible' : '';
1050 $item_classes[] = $settings[$hover_item_class] !== '' ? $settings[$hover_item_class] : '';
1051
1052 } else {
1053 // Check for Animations
1054 $entrance = (isset($settings['animate_items']) && $settings['animate_items'] == 'ui-e-grid-animate') ? 'elementor-invisible' : '';
1055 $hover = isset($settings[$hover_item_class]) ? $settings[$hover_item_class] : ''; //$settings[$hover_item_class] : null;
1056 $animations = sprintf('%s %s', $entrance, $hover);
1057
1058 // Prints extra wrappers required by the carousel script
1059 ?>
1060 <div class="ui-e-wrp swiper-slide">
1061 <div class="ui-e-animations-wrp <?php echo esc_attr($animations);?>">
1062 <div class="ui-e-item-wrp">
1063 <?php } ?>
1064
1065 <div class="<?php echo esc_attr( implode(' ', $item_classes));?>">
1066 <article <?php post_class(); ?>>
1067 <div class="ui-e-post-top">
1068 <?php $this->get_post_image(); ?>
1069 <?php $this->get_post_meta('top'); ?>
1070 </div>
1071 <div class="ui-e-post-content">
1072 <?php $this->get_post_meta('before_title'); ?>
1073 <?php
1074 if ($this->get_settings_for_display('title') === 'yes')
1075 $this->get_post_title();
1076 ?>
1077 <?php $this->get_post_meta('after_title'); ?>
1078 <?php
1079 if ($this->get_settings_for_display('excerpt'))
1080 echo wp_kses_post('<div class="ui-e-post-text">' . wp_trim_words(get_the_excerpt(), $excerpt_length) . '</div>');
1081 ?>
1082 <?php $this->get_post_meta('bottom'); // button
1083 ?>
1084 <?php
1085 if ($this->get_settings_for_display('show_button') === 'yes') {
1086 // Add match height spacing element if carousel. May look intrusive, but is the simplest method compared
1087 // to absolute positioning or catching last content element to apply margin.
1088 if($carousel && $settings['match_height'] === 'yes'){
1089 ?>
1090 <span class="ui-e-match-height"></span>
1091 <?php
1092 }
1093 $this->get_button();
1094 }
1095 ?>
1096 </div>
1097 </article>
1098 </div>
1099
1100 <?php if($carousel) { ?>
1101 </div>
1102 </div>
1103 </div>
1104 <?php }
1105 }
1106 }
1107