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

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

262 lines 8.5 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
25 public function get_name()
26 {
27 return 'uicore-advanced-post-carousel';
28 }
29 public function get_categories()
30 {
31 return ['uicore'];
32 }
33 public function get_title()
34 {
35 return __('Advanced Post Carousel', 'uicore-elements');
36 }
37 public function get_icon()
38 {
39 return 'eicon-posts-carousel ui-e-widget';
40 }
41 public function get_keywords()
42 {
43 return ['post', 'carousel', 'slide', 'blog', 'recent', 'news'];
44 }
45 public function get_styles()
46 {
47 $styles = [
48 'advanced-post-carousel',
49 'carousel',
50 'post-meta',
51 'filters' => [
52 'condition' => [
53 'post_filtering' => 'yes',
54 ]
55 ],
56 'animation', // hover animations
57 'entrance', // entrance basic style
58 ];
59 if(!class_exists('\UiCore\Core') && !class_exists('\UiCoreAnimate\Base')){
60 $styles['e-animations'] = [ // entrance animations
61 'external' => true,
62 ];
63 }
64 return $styles;
65 }
66 public function get_scripts()
67 {
68 return $this->TRAIT_get_carousel_scripts();
69 }
70 public function has_widget_inner_wrapper(): bool {
71 // TODO: remove after 3.30, when the full deprecation of widget innet wrapper is ready
72 return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
73 }
74
75 private function filter_missing_taxonomies($settings)
76 {
77 $taxonomy_filter_args = [
78 'show_in_nav_menus' => true,
79 ];
80 if (!empty($settings['posts-filter_post_type'])) {
81 $taxonomy_filter_args['object_type'] = [$settings['posts-filter_post_type']];
82 }
83
84 $taxonomies = get_taxonomies($taxonomy_filter_args, 'objects');
85
86 foreach ($taxonomies as $taxonomy => $object) {
87 $controll_id = 'posts-filter_' . $taxonomy . '_ids';
88 //error_log($controll_id);
89 //error_log(print_r($settings[$controll_id], true));
90
91 if (!isset($settings[$controll_id]) || empty($settings[$controll_id])) {
92 continue;
93 }
94
95 //if is set check if this id still exists
96 $settings[$controll_id] = array_filter($settings[$controll_id], function ($term_id) use ($object) {
97 return term_exists($term_id, $object->name);
98 });
99
100 if (empty($settings[$controll_id])) {
101 $settings[$controll_id] = null;
102 }
103 }
104
105 return $settings;
106 }
107 public function on_import($element)
108 {
109 $element['settings'] = $this->filter_missing_taxonomies($element['settings']);
110 return $element;
111 }
112 function get_query()
113 {
114 return $this->_query;
115 }
116
117 protected function register_controls()
118 {
119
120 // Contents and Settings
121 $this->start_controls_section(
122 'section_layout',
123 [
124 'label' => esc_html__('Carousel', 'uicore-elements'),
125 ]
126 );
127 $this->TRAIT_register_carousel_additional_controls(); // Grid Layouts with old masonry control
128 $this->end_controls_section();
129
130 $this->start_controls_section(
131 'section_carousel_settings',
132 [
133 'label' => __('Carousel Settings', 'uicore-elements'),
134 ]
135 );
136 $this->TRAIT_register_carousel_settings_controls(); // Carousel settings
137 $this->end_controls_section();
138
139 $this->TRAIT_register_navigation_controls();
140 $this->TRAIT_register_post_item_controls();
141 $this->TRAIT_register_post_button_controls();
142 $this->TRAIT_register_post_meta_controls();
143 $this->TRAIT_register_post_query_controls();
144 $this->TRAIT_register_filter_controls();
145
146 // Styles
147 $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'
148 $this->TRAIT_register_navigation_style_controls();
149 $this->TRAIT_register_post_content_style_controls();
150 $this->TRAIT_register_post_button_style_controls();
151 $this->TRAIT_register_post_meta_style_controls();
152 $this->TRAIT_register_filter_style_controls();
153
154 $this->start_controls_section(
155 'section_style_animations',
156 [
157 'label' => __('Animations', 'uicore-elements'),
158 'tab' => Controls_Manager::TAB_STYLE,
159 ]
160 );
161 $this->TRAIT_register_entrance_animations_controls();
162 $this->TRAIT_register_hover_animation_control(
163 'Item Hover Animation',
164 [],
165 ['underline'],
166 );
167 $this->TRAIT_register_post_animation_controls();
168 $this->end_controls_section();
169
170 // Update post component controls
171 $this->update_control('image_size', [
172 'condition' => [],
173 ]);
174 $this->update_control('content_padding', [
175 'default' => [
176 'top' => 20,
177 'right' => 20,
178 'bottom' => 20,
179 'left' => 20,
180 'unit' => 'px',
181 ],
182 ]);
183 $this->update_control('item_limit', [
184 'default' => [
185 'size' => 5,
186 ],
187 ]);
188
189 // TODO: create new method to return animations list and use it throughout the plugin
190 // Update carousel animations
191 $this->update_control('animation_style', [
192 'options' => [
193 'circular' => esc_html__('Circular', 'uicore-elements'),
194 'fade_blur' => esc_html__('Fade Blur', 'uicore-elements'),
195 'default' => esc_html__('Default', 'uicore-elements'),
196 ],
197 ]);
198 }
199
200 function content_template()
201 {
202 }
203
204 protected function render()
205 {
206
207 // Get query args, settings and post type slug
208 global $wp_query;
209 $default_query = $wp_query;
210 $settings = $this->get_settings();
211
212 // Get the quantity of items and creates a loop control
213 $items = $settings['item_limit']['size'];
214 $loops = 0;
215
216 // Check if should duplicate slides and update settings
217 if ( $this->TRAIT_should_duplicate_slides($items) ) {
218 $diff = abs($this->TRAIT_get_duplication_diff($items) + 1); // +1 to fix zero based index
219 $settings['item_limit']['size'] = $items + $diff;
220 }
221
222 // Build query
223 $this->TRAIT_query_posts( $settings, $wp_query->query );
224 $wp_query = $this->get_query();
225
226 $this->TRAIT_render_filters($settings);
227
228 // No posts found
229 if (!$wp_query->have_posts()) {
230 echo '<p style="text-align:center">' . esc_html__('No posts found.', 'uicore-elements') . '</p>';
231 } else {
232
233 ?>
234 <div class="ui-e-carousel swiper">
235 <div class='swiper-wrapper'>
236 <?php
237 while ($wp_query->have_posts()) {
238
239 // sticky posts disregards posts per page, so ending the loop if $items == $loop forces the query respects the users item limit
240 // if ($settings['sticky'] && $items == $loops) {
241 // break;
242 // }
243
244 $wp_query->the_post();
245 $this->TRAIT_render_item($loops, true);
246
247 $loops++;
248 }
249 ?>
250 </div>
251 </div>
252 <?php $this->TRAIT_render_carousel_navigations(); ?>
253 <?php
254 }
255
256 //reset query
257 wp_reset_query();
258 $wp_query = $default_query;
259 }
260 }
261 \Elementor\Plugin::instance()->widgets_manager->register(new AdvancedPostCarousel());
262