PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.17
UiCore Elements – Free widgets and templates for Elementor v1.3.17
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 / post-grid.php

post-grid.php in UiCore Elements – Free widgets and templates for Elementor 1.3.17, at includes/widgets/post-grid.php

479 lines 15.0 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 Elementor\Group_Control_Border;
7 use Elementor\Group_Control_Box_Shadow;
8 use Elementor\Group_Control_Typography;
9 use Elementor\Group_Control_Background;
10 use UiCoreElements\UiCoreWidget;
11
12 use UiCore\Assets;
13 use UiCore\Portfolio;
14 use UiCore\Blog;
15 use UiCore\Helper;
16 use UiCoreElements\Controls\Post_Filter;
17 use UiCoreElements\Controls\Query;
18
19 defined('ABSPATH') || exit();
20
21 /**
22 * Post Grid
23 *
24 */
25
26 class PostGrid extends UiCoreWidget
27 {
28 private $_query;
29
30 public function __construct($data = [], $args = null)
31 {
32 parent::__construct($data, $args);
33 }
34 public function get_name()
35 {
36 return 'uicore-post-grid';
37 }
38 public function get_categories()
39 {
40 return ['uicore'];
41 }
42 public function get_title()
43 {
44 return __('Post Grid', 'uicore-elements');
45 }
46 public function get_icon()
47 {
48 return 'eicon-gallery-grid ui-e-widget';
49 }
50 public function get_keywords()
51 {
52 return ['post', 'grid', 'blog', 'recent', 'news'];
53 }
54 public function get_styles()
55 {
56 return [
57 'post-grid',
58 // get framework assets
59 'uicore-blog-st' => [
60 'external' => true,
61 ],
62 'uicore-portfolio-st' => [
63 'external' => true,
64 'condition' => [
65 'posts-filter_post_type' => 'portfolio',
66 ]
67 ]
68 ];
69 }
70 public function get_scripts()
71 {
72 return [];
73 }
74 public function has_widget_inner_wrapper(): bool
75 {
76 // TODO: remove after Optmized Markup experiment is merged to the core
77 return ! \Elementor\Plugin::$instance->experiments->is_feature_active('e_optimized_markup');
78 }
79
80 public function on_import($element)
81 {
82 if (!get_post_type_object($element['settings']['posts-filter_post_type'])) {
83 $element['settings']['posts-filter_post_type'] = 'post';
84 }
85
86 return $element;
87 }
88 public function on_export($element)
89 {
90 $element = Post_Filter::on_export_remove_setting_from_element($element, 'uicore-posts-filter');
91 return $element;
92 }
93
94 public function get_query()
95 {
96 return $this->_query;
97 }
98
99 protected function register_controls()
100 {
101
102 $default_columns = Helper::get_option('blog_col', 3);
103
104 $this->start_controls_section('section_post_grid_def', [
105 'label' => esc_html__('Query', 'uicore-elements'),
106 ]);
107
108 $this->add_group_control(Post_Filter::get_type(), [
109 'name' => 'posts-filter',
110 'label' => esc_html__('Posts', 'uicore-elements'),
111 ]);
112
113 $this->add_control('item_limit', [
114 'label' => esc_html__('Item Limit', 'uicore-elements'),
115 'type' => Controls_Manager::SLIDER,
116 'reder_type' => 'template',
117 'range' => [
118 'px' => [
119 'min' => 1,
120 'max' => 30,
121 ],
122 ],
123 'default' => [
124 'size' => 3,
125 ],
126 ]);
127 $this->add_control('col_number', [
128 'label' => esc_html__('Columns Number', 'uicore-elements'),
129 'type' => Controls_Manager::SLIDER,
130 'reder_type' => 'template',
131 'range' => [
132 'px' => [
133 'min' => 1,
134 'max' => 4,
135 ],
136 ],
137 'default' => [
138 'size' => $default_columns,
139 ],
140 ]);
141
142 $this->end_controls_section();
143
144 $this->start_controls_section('section_post_grid_layout', [
145 'label' => esc_html__('Layout', 'uicore-elements'),
146 ]);
147 $this->add_control(
148 'layout',
149 [
150 'label' => __('Item Style', 'uicore-elements'),
151 'type' => Controls_Manager::SELECT,
152 'default' => 'default',
153 'options' => [
154 'default' => __('Default', 'uicore-elements'),
155 'classic' => __('classic', 'uicore-elements'),
156 'grid' => __('Grid', 'uicore-elements'),
157 'horizontal' => __('Horizontal', 'uicore-elements'),
158 'masonry' => __('Masonry', 'uicore-elements'),
159 ],
160 'condition' => array(
161 'posts-filter_post_type!' => 'portfolio',
162 ),
163 ]
164 );
165
166 $this->add_control(
167 'box_style',
168 [
169 'label' => __('layout', 'uicore-elements'),
170 'type' => Controls_Manager::SELECT,
171 'default' => 'default',
172 'options' => [
173 'default' => __('Default', 'uicore-elements'),
174 'boxed' => __('Boxed', 'uicore-elements'),
175 'boxed-creative' => __('Boxed Creative', 'uicore-elements'),
176 'cover' => __('Cover', 'uicore-elements'),
177 ],
178 'condition' => array(
179 'posts-filter_post_type!' => 'portfolio',
180 ),
181 ]
182 );
183
184 $this->add_control(
185 'box_ratio',
186 [
187 'label' => __('Image Ratio', 'uicore-elements'),
188 'type' => Controls_Manager::SELECT,
189 'default' => 'default',
190 'options' => [
191 'default' => __('Default', 'uicore-elements'),
192 'square' => __('Square', 'uicore-elements'),
193 'landscape' => __('Landscape', 'uicore-elements'),
194 'portrait' => __('Portrait', 'uicore-elements'),
195 ],
196 'condition' => array(
197 'posts-filter_post_type!' => 'portfolio',
198 ),
199 ]
200 );
201 $this->add_control(
202 'extra_author',
203 [
204 'label' => __('Author', 'uicore-elements'),
205 'type' => Controls_Manager::SWITCHER,
206 'return_value' => 'yes',
207 'default' => '',
208 'reder_type' => 'template',
209 'condition' => array(
210 'posts-filter_post_type!' => 'portfolio',
211 ),
212 ]
213 );
214 $this->add_control(
215 'extra_date',
216 [
217 'label' => __('Date', 'uicore-elements'),
218 'type' => Controls_Manager::SWITCHER,
219 'return_value' => 'yes',
220 'default' => '',
221 'reder_type' => 'template',
222 'condition' => array(
223 'posts-filter_post_type!' => 'portfolio',
224 ),
225 ]
226 );
227 $this->add_control(
228 'extra_excerpt',
229 [
230 'label' => __('Excerpt', 'uicore-elements'),
231 'type' => Controls_Manager::SWITCHER,
232 'return_value' => 'yes',
233 'default' => '',
234 'reder_type' => 'template',
235 'condition' => array(
236 'posts-filter_post_type!' => 'portfolio',
237 ),
238 ]
239 );
240 $this->add_control(
241 'extra_category',
242 [
243 'label' => __('Category', 'uicore-elements'),
244 'type' => Controls_Manager::SWITCHER,
245 'return_value' => 'yes',
246 'default' => '',
247 'reder_type' => 'template',
248 'condition' => array(
249 'posts-filter_post_type!' => 'portfolio',
250 ),
251 ]
252 );
253
254 $this->end_controls_section();
255
256
257 $this->start_controls_section(
258 'section_style_typo',
259 [
260 'label' => __('Content Style', 'uicore-elements'),
261 'tab' => Controls_Manager::TAB_STYLE,
262 ]
263 );
264
265 $this->add_control(
266 'post_heading_title',
267 [
268 'label' => esc_html__('Post Title', 'uicore-elements'),
269 'type' => Controls_Manager::HEADING,
270 'separator' => 'before',
271 ]
272 );
273
274 $this->add_control(
275 'post_title_color',
276 [
277 'label' => esc_html__('Color', 'uicore-elements'),
278 'type' => Controls_Manager::COLOR,
279 'default' => '',
280 'selectors' => [
281 '{{WRAPPER}} .uicore-post-title' => 'color: {{VALUE}};',
282 ],
283 ]
284 );
285
286 $this->add_group_control(
287 Group_Control_Typography::get_type(),
288 [
289 'name' => 'post_title_typography',
290 'selector' => '{{WRAPPER}} .uicore-post-title, {{WRAPPER}} .uicore-post-title',
291 ]
292 );
293
294
295 $this->add_control(
296 'extra_excerpt_heading',
297 [
298 'label' => esc_html__('Excerpt', 'uicore-elements'),
299 'type' => Controls_Manager::HEADING,
300 'separator' => 'before',
301 ]
302 );
303 $this->add_responsive_control(
304 'extra_excerpt_bottom_space',
305 [
306 'label' => esc_html__('Spacing', 'uicore-elements'),
307 'type' => Controls_Manager::SLIDER,
308 'range' => [
309 'px' => [
310 'min' => 0,
311 'max' => 100,
312 ],
313 ],
314 'selectors' => [
315 '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'margin-top: {{SIZE}}{{UNIT}};',
316 ],
317 ]
318 );
319
320 $this->add_control(
321 'extra_excerpt_color',
322 [
323 'label' => esc_html__('Color', 'uicore-elements'),
324 'type' => Controls_Manager::COLOR,
325 'default' => '',
326 'selectors' => [
327 '{{WRAPPER}} .uicore-post-info-wrapper > p' => 'color: {{VALUE}};',
328 ],
329 ]
330 );
331
332 $this->add_group_control(
333 Group_Control_Typography::get_type(),
334 [
335 'name' => 'extra_excerpt_typography',
336 'selector' => '{{WRAPPER}} .uicore-post-info-wrapper > p',
337 ]
338 );
339
340
341 $this->add_responsive_control(
342 'box_padding',
343 [
344 'label' => esc_html__('Content Padding', 'uicore-elements'),
345 'type' => Controls_Manager::DIMENSIONS,
346 'size_units' => ['px', 'em', '%', 'rem'],
347 'separator' => 'before',
348 'selectors' => [
349 '{{WRAPPER}} .uicore-blog-grid .uicore-post .uicore-post-info' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
350 ],
351 ]
352 );
353
354 $this->add_group_control(
355 Group_Control_Background::get_type(),
356 [
357 'name' => 'box_background',
358 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
359 ]
360 );
361
362 $this->add_group_control(
363 Group_Control_Border::get_type(),
364 [
365 'name' => 'box_border',
366 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
367 'separator' => 'before',
368 ]
369 );
370
371 $this->add_control(
372 'box_border_radius',
373 [
374 'label' => esc_html__('Border Radius', 'uicore-elements'),
375 'type' => Controls_Manager::SLIDER,
376 'range' => [
377 'px' => [
378 'min' => 0,
379 'max' => 100,
380 ],
381 ],
382 'selectors' => [
383 '{{WRAPPER}} .uicore-blog-grid .uicore-post' => '--uicore-blog--radius: {{SIZE}}{{UNIT}};',
384 ],
385 ]
386 );
387
388 $this->add_group_control(
389 Group_Control_Box_Shadow::get_type(),
390 [
391 'name' => 'box_shadow_style',
392 'selector' => '{{WRAPPER}} .uicore-blog-grid .uicore-post',
393 ]
394 );
395
396
397 $this->end_controls_section();
398 }
399
400 public function query_posts($posts_per_page, $type = null)
401 {
402 $query_args = Query::get_query_args('posts-filter', $this->get_settings());
403
404 if ($type === 'portfolio') {
405 $query_args['orderby'] = 'menu_order date';
406 }
407
408 $query_args['posts_per_page'] = $posts_per_page;
409
410 $this->_query = new \WP_Query($query_args);
411 }
412
413 protected function render()
414 {
415 $settings = $this->get_settings();
416
417 $col = $settings['col_number']['size'];
418 $type = $settings['posts-filter_post_type'];
419
420 if ($type != 'portfolio') {
421 $type = str_replace(' ', '-', $settings['box_style']);
422 }
423
424 $this->query_posts($settings['item_limit']['size'], $type);
425 $wp_query = $this->get_query();
426
427 if (!$wp_query->found_posts) {
428 echo 'No Posts Found!';
429 return;
430 }
431
432
433 if ($type === 'portfolio') {
434
435 if (!class_exists('\UiCore\Portfolio\Frontend')) {
436 require_once UICORE_INCLUDES . '/portfolio/class-template.php';
437 require_once UICORE_INCLUDES . '/portfolio/class-frontend.php';
438 }
439 Portfolio\Frontend::frontend_css(true);
440 $portfolio = new Portfolio\Template('display');
441 $portfolio->portfolio_layout($wp_query, null, $col);
442 } else {
443 $layout = $settings['layout'] === 'default' ? null : $settings['layout'];
444 $style = $settings['box_style'] === 'default' ? null : $settings['box_style'];
445
446 if (isset($settings['box_ratio'])) {
447 $ratio = $settings['box_ratio'] === 'default' ? null : $settings['box_ratio'];
448 } else { //Fallback for older versions
449 $ratio = null;
450 }
451 if (isset($settings['extra_author'])) {
452 $extra = [
453 'author' => $this->is_option('extra_author', 'yes'),
454 'date' => $this->is_option('extra_date', 'yes'),
455 'excerpt' => $this->is_option('extra_excerpt', 'yes'),
456 'category' => $this->is_option('extra_category', 'yes')
457 ];
458 } else { //Fallback for older versions
459 $extra = [
460 'author' => null,
461 'date' => null,
462 'excerpt' => null,
463 'category' => null
464 ];
465 }
466
467
468 if (!class_exists('\UiCore\Blog\Frontend')) {
469 require_once UICORE_INCLUDES . '/blog/class-template.php';
470 require_once UICORE_INCLUDES . '/blog/class-frontend.php';
471 }
472 Blog\Frontend::frontend_css(true);
473 $blog = new Blog\Template('display');
474 $blog->blog_layout($wp_query, $layout, $col, null, $ratio, $extra, $style);
475 }
476 }
477 }
478 \Elementor\Plugin::instance()->widgets_manager->register(new PostGrid());
479