PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.6
UiCore Elements – Free widgets and templates for Elementor v1.0.6
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.6, at includes/widgets/advanced-post-carousel.php

252 lines 7.7 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 'utils/global-testimonial' => [
65 'condition' => [
66 'layout' => 'layout_5'
67 ],
68 ],
69 'utils/carousel-effects/circular' => [
70 'condition' => [
71 'animation_style' => 'circular',
72 ]
73 ],
74 'utils/carousel-effects/fade-and-blur' => [
75 'condition' => [
76 'animation_style' => 'fade_blur',
77 ]
78 ],
79 'entrance' => [
80 'condition' => [
81 'animate_items' => 'ui-e-grid-animate'
82 ],
83 ],
84 ];
85 }
86
87 private function filter_missing_taxonomies($settings)
88 {
89 $taxonomy_filter_args = [
90 'show_in_nav_menus' => true,
91 ];
92 if (!empty($settings['posts-filter_post_type'])) {
93 $taxonomy_filter_args['object_type'] = [$settings['posts-filter_post_type']];
94 }
95
96 $taxonomies = get_taxonomies($taxonomy_filter_args, 'objects');
97
98 foreach ($taxonomies as $taxonomy => $object) {
99 $controll_id = 'posts-filter_' . $taxonomy . '_ids';
100 \error_log($controll_id);
101 \error_log(print_r($settings[$controll_id], true));
102
103 if (!isset($settings[$controll_id]) || empty($settings[$controll_id])) {
104 continue;
105 }
106
107 //if is set check if this id still exists
108 $settings[$controll_id] = array_filter($settings[$controll_id], function ($term_id) use ($object) {
109 return term_exists($term_id, $object->name);
110 });
111
112 if (empty($settings[$controll_id])) {
113 $settings[$controll_id] = null;
114 }
115 }
116
117 return $settings;
118 }
119 public function on_import($element)
120 {
121 $element['settings'] = $this->filter_missing_taxonomies($element['settings']);
122 return $element;
123 }
124 function get_query()
125 {
126 return $this->_query;
127 }
128
129 protected function register_controls()
130 {
131
132 // Contents and Settings
133 $this->start_controls_section(
134 'section_layout',
135 [
136 'label' => esc_html__('Carousel', 'uicore-elements'),
137 ]
138 );
139 $this->TRAIT_register_carousel_additional_controls(); // Grid Layouts with old masonry control
140 $this->end_controls_section();
141
142 $this->start_controls_section(
143 'section_carousel_settings',
144 [
145 'label' => __('Carousel Settings', 'uicore-elements'),
146 ]
147 );
148 $this->TRAIT_register_carousel_settings_controls(); // Carousel settings
149 $this->end_controls_section();
150
151 $this->TRAIT_register_navigation_controls();
152 $this->TRAIT_register_post_item_controls();
153 $this->TRAIT_register_post_button_controls();
154 $this->TRAIT_register_post_meta_controls();
155 $this->TRAIT_register_post_query_controls();
156 $this->TRAIT_register_filter_controls();
157
158 // Styles
159 $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'
160 $this->TRAIT_register_navigation_style_controls();
161 $this->TRAIT_register_post_content_style_controls();
162 $this->TRAIT_register_post_button_style_controls();
163 $this->TRAIT_register_post_meta_style_controls();
164 $this->TRAIT_register_filter_style_controls();
165
166 $this->start_controls_section(
167 'section_style_animations',
168 [
169 'label' => __('Animations', 'uicore-elements'),
170 'tab' => Controls_Manager::TAB_STYLE,
171 ]
172 );
173 $this->TRAIT_register_entrance_animations_controls();
174 $this->TRAIT_register_hover_animation_control(
175 'Item Hover Animation',
176 [],
177 ['underline'],
178 );
179 $this->TRAIT_register_post_animation_controls();
180 $this->end_controls_section();
181
182 // Update post component controls
183 $this->update_control('image_size', [
184 'condition' => [],
185 ]);
186 $this->update_control('content_padding', [
187 'default' => [
188 'top' => 20,
189 'right' => 20,
190 'bottom' => 20,
191 'left' => 20,
192 'unit' => 'px',
193 ],
194 ]);
195 $this->update_control('item_limit', [
196 'default' => [
197 'size' => 5,
198 ],
199 ]);
200 }
201
202 function content_template()
203 {
204 }
205
206 protected function render()
207 {
208
209 // Get query args and widget settings
210 global $wp_query;
211 $default_query = $wp_query;
212 $settings = $this->get_settings();
213 $this->TRAIT_query_posts($settings['item_limit']['size'], $settings['posts-filter_post_type']);
214 $wp_query = $this->get_query();
215
216 // Get the quantity of items and creates a loop control
217 $items = $settings['item_limit']['size'];
218 $loops = 0;
219
220 $this->TRAIT_render_filters();
221
222 // No posts found
223 if (!$wp_query->have_posts()) {
224 echo '<p style="text-align:center">' . __('No posts found.', 'uicore-elements') . '</p>';
225 } else {
226
227 ?>
228 <div class="ui-e-carousel swiper">
229 <div class='swiper-wrapper'>
230 <?php
231 while ($wp_query->have_posts()) {
232 if ($settings['sticky'] && $items == $loops) {
233 break; // sticky posts disregards posts per page, so ending the loop if $items == $loop forces the query respects the users item limit
234 }
235 $wp_query->the_post();
236 $this->TRAIT_render_item(true);
237 $loops++;
238 }
239 ?>
240 </div>
241 <?php $this->TRAIT_render_carousel_navigations(); ?>
242 </div>
243 <?php
244 }
245
246 //reset query
247 wp_reset_query();
248 $wp_query = $default_query;
249 }
250 }
251 \Elementor\Plugin::instance()->widgets_manager->register(new AdvancedPostCarousel());
252