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 / widgets / advanced-post-carousel.php

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

237 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UiCoreElements;
4
5 use Elementor\Controls_Manager;
6 use UiCoreElements\UiCoreWidget;
7 use UiCoreElements\Utils\Carousel_Trait;
8 use UiCoreElements\Utils\Animation_Trait;
9 use UiCoreElements\Utils\Grid_Trait;
10 use uicoreElements\Utils\Post_Trait;
11 use uiCoreElements\Utils\Post_Filters_Trait;
12
13 defined('ABSPATH') || exit();
14
15 class AdvancedPostCarousel extends UiCoreWidget
16 {
17 use Carousel_Trait,
18 Animation_Trait,
19 Grid_Trait,
20 Post_Filters_Trait,
21 Post_Trait;
22
23 private $_query,
24 $is_slider;
25
26 public function get_name()
27 {
28 return 'uicore-advanced-post-carousel';
29 }
30 public function get_categories()
31 {
32 return ['uicore'];
33 }
34 public function get_title()
35 {
36 return __('Advanced Post Carousel', 'uicore-elements');
37 }
38 public function get_icon()
39 {
40 return 'eicon-posts-carousel ui-e-widget';
41 }
42 public function get_keywords()
43 {
44 return ['post', 'carousel', 'slide', 'blog', 'recent', 'news'];
45 }
46 public function get_styles()
47 {
48 $styles = [
49 'advanced-post-carousel',
50 'animation', // hover animations
51 'entrance', // entrance basic style
52 ];
53 if(!class_exists('\UiCore\Core') && !class_exists('\UiCoreAnimate\Base')){
54 $styles['e-animations'] = [ // entrance animations
55 'external' => true,
56 ];
57 }
58 return $styles;
59 }
60 public function get_scripts()
61 {
62 return [
63 'carousel',
64 'entrance' => [
65 'condition' => [
66 'animate_items' => 'ui-e-grid-animate'
67 ],
68 ],
69 ];
70 }
71
72 private function filter_missing_taxonomies($settings)
73 {
74 $taxonomy_filter_args = [
75 'show_in_nav_menus' => true,
76 ];
77 if (!empty($settings['posts-filter_post_type'])) {
78 $taxonomy_filter_args['object_type'] = [$settings['posts-filter_post_type']];
79 }
80
81 $taxonomies = get_taxonomies($taxonomy_filter_args, 'objects');
82
83 foreach ($taxonomies as $taxonomy => $object) {
84 $controll_id = 'posts-filter_' . $taxonomy . '_ids';
85 \error_log($controll_id);
86 \error_log(print_r($settings[$controll_id], true));
87
88 if (!isset($settings[$controll_id]) || empty($settings[$controll_id])) {
89 continue;
90 }
91
92 //if is set check if this id still exists
93 $settings[$controll_id] = array_filter($settings[$controll_id], function ($term_id) use ($object) {
94 return term_exists($term_id, $object->name);
95 });
96
97 if (empty($settings[$controll_id])) {
98 $settings[$controll_id] = null;
99 }
100 }
101
102 return $settings;
103 }
104 public function on_import($element)
105 {
106 $element['settings'] = $this->filter_missing_taxonomies($element['settings']);
107 return $element;
108 }
109 function get_query()
110 {
111 return $this->_query;
112 }
113
114 protected function register_controls()
115 {
116
117 // Contents and Settings
118 $this->start_controls_section(
119 'section_layout',
120 [
121 'label' => esc_html__('Carousel', 'uicore-elements'),
122 ]
123 );
124 $this->TRAIT_register_carousel_additional_controls(); // Grid Layouts with old masonry control
125 $this->end_controls_section();
126
127 $this->start_controls_section(
128 'section_carousel_settings',
129 [
130 'label' => __('Carousel Settings', 'uicore-elements'),
131 ]
132 );
133 $this->TRAIT_register_carousel_settings_controls(); // Carousel settings
134 $this->end_controls_section();
135
136 $this->TRAIT_register_navigation_controls();
137 $this->TRAIT_register_post_item_controls();
138 $this->TRAIT_register_post_button_controls();
139 $this->TRAIT_register_post_meta_controls();
140 $this->TRAIT_register_post_query_controls();
141 $this->TRAIT_register_filter_controls();
142
143 // Styles
144 $this->TRAIT_register_post_item_style_controls(); // instead of using carousel item style controls, we use post item and only updates some default values after. Is a better approach because advanced post widgets inherits some APG legacy codes and methods, such as setting borders and paddings on <article> instead of 'ui-e-item'
145 $this->TRAIT_register_navigation_style_controls();
146 $this->TRAIT_register_post_content_style_controls();
147 $this->TRAIT_register_post_button_style_controls();
148 $this->TRAIT_register_post_meta_style_controls();
149 $this->TRAIT_register_filter_style_controls();
150
151 $this->start_controls_section(
152 'section_style_animations',
153 [
154 'label' => __('Animations', 'uicore-elements'),
155 'tab' => Controls_Manager::TAB_STYLE,
156 ]
157 );
158 $this->TRAIT_register_entrance_animations_controls();
159 $this->TRAIT_register_hover_animation_control(
160 'Item Hover Animation',
161 [],
162 ['underline'],
163 );
164 $this->TRAIT_register_post_animation_controls();
165 $this->end_controls_section();
166
167 // Update post component controls
168 $this->update_control('image_size', [
169 'condition' => [],
170 ]);
171 $this->update_control('content_padding', [
172 'default' => [
173 'top' => 20,
174 'right' => 20,
175 'bottom' => 20,
176 'left' => 20,
177 'unit' => 'px',
178 ],
179 ]);
180 $this->update_control('item_limit', [
181 'default' => [
182 'size' => 5,
183 ],
184 ]);
185 }
186
187 function content_template()
188 {
189 }
190
191 protected function render()
192 {
193
194 // Get query args and widget settings
195 global $wp_query;
196 $default_query = $wp_query;
197 $settings = $this->get_settings();
198 $this->TRAIT_query_posts($settings['item_limit']['size'], $settings['posts-filter_post_type']);
199 $wp_query = $this->get_query();
200
201 // Get the quantity of items and creates a loop control
202 $items = $settings['item_limit']['size'];
203 $loops = 0;
204
205 $this->TRAIT_render_filters();
206
207 // No posts found
208 if (!$wp_query->have_posts()) {
209 echo '<p style="text-align:center">' . __('No posts found.', 'uicore-elements') . '</p>';
210 } else {
211
212 ?>
213 <div class="ui-e-carousel swiper">
214 <div class='swiper-wrapper'>
215 <?php
216 while ($wp_query->have_posts()) {
217 if ($settings['sticky'] && $items == $loops) {
218 break; // sticky posts disregards posts per page, so ending the loop if $items == $loop forces the query respects the users item limit
219 }
220 $wp_query->the_post();
221 $this->TRAIT_render_item(true);
222 $loops++;
223 }
224 ?>
225 </div>
226 <?php $this->TRAIT_render_carousel_navigations(); ?>
227 </div>
228 <?php
229 }
230
231 //reset query
232 wp_reset_query();
233 $wp_query = $default_query;
234 }
235 }
236 \Elementor\Plugin::instance()->widgets_manager->register(new AdvancedPostCarousel());
237