PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.0
UiCore Elements – Free widgets and templates for Elementor v1.2.0
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.2.0, at includes/widgets/post-grid.php

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