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 / utils / pagination-component.php

pagination-component.php in UiCore Elements – Free widgets and templates for Elementor 1.2.0, at includes/utils/pagination-component.php

527 lines 21.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements\Utils;
3 use \Elementor\Controls_Manager;
4 use \Elementor\Group_Control_Border;
5 use \Elementor\Group_Control_Box_Shadow;
6 use \Elementor\Group_Control_Typography;
7
8 defined('ABSPATH') || exit();
9
10 /**
11 * Paginations Trait Component
12 *
13 */
14
15 trait Pagination_Trait {
16
17 function pagination_options()
18 {
19 return [
20 'numbers' => esc_html__('Numbers', 'uicore-elements'),
21 'load_more' => esc_html__('Load More', 'uicore-elements'),
22 ];
23 }
24 function TRAIT_register_pagination_controls($section = true)
25 {
26 if($section){
27 $this->start_controls_section(
28 'section_pagination',
29 [
30 'label' => esc_html__('Pagination', 'uicore-elements'),
31 ]
32 );
33 }
34
35 $this->add_control(
36 'pagination',
37 [
38 'label' => __( 'Pagination', 'uicore-elements' ),
39 'type' => Controls_Manager::SWITCHER,
40 'default'=> 'no',
41 'render_type' => 'template',
42 ]
43 );
44 $this->add_control(
45 'pagination_type',
46 [
47 'label' => esc_html__('Pagination Type', 'uicore-elements'),
48 'type' => Controls_Manager::SELECT,
49 'default' => 'numbers',
50 'options' => $this->pagination_options(),
51 'frontend_available' => true,
52 'condition' => [
53 'pagination' => 'yes',
54 ],
55 ]
56 );
57
58 if($section){
59 $this->end_controls_section();
60 }
61 }
62 function TRAIT_register_pagination_style_controls($section = true)
63 {
64 if($section){
65 $this->start_controls_section(
66 'section_style_pagination',
67 [
68 'label' => __('Pagination Style', 'uicore-elements'),
69 'tab' => Controls_Manager::TAB_STYLE,
70 'condition' => [
71 'pagination' => 'yes',
72 ],
73 ]
74 );
75 }
76
77 $this->add_group_control(
78 Group_Control_Typography::get_type(),
79 [
80 'name' => 'pagination_typography',
81 'label' => esc_html__( 'Typography', 'uicore-elements' ),
82 'selector' => '{{WRAPPER}} .uicore-page-item, {{WRAPPER}} .ui-e-load-more',
83 ]
84 );
85 $this->add_responsive_control(
86 'icon_size',
87 [
88 'label' => __( 'Previous/Next Icon Size', 'uicore-elements' ),
89 'type' => Controls_Manager::SLIDER,
90 'size_units' => [ 'px' ],
91 'range' => [
92 'px' => [
93 'min' => 0,
94 'max' => 30,
95 'step' => 1,
96 ],
97 ],
98 'default' => [
99 'unit' => 'px',
100 'size' => 16,
101 ],
102 'selectors' => [
103 '{{WRAPPER}} .uicore-pagination a.prev svg, {{WRAPPER}} .uicore-pagination a.next svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}}',
104 '{{WRAPPER}} .uicore-pagination a.prev i, {{WRAPPER}} .uicore-pagination a.next i' => 'font-size: {{SIZE}}{{UNIT}};',
105 ],
106 'condition' => [
107 'pagination_type' => 'numbers'
108 ]
109 ]
110 );
111 $this->add_responsive_control(
112 'pagination_top',
113 [
114 'label' => __( 'Pagination Top Space', 'uicore-elements' ),
115 'type' => Controls_Manager::SLIDER,
116 'size_units' => [ 'px' ],
117 'range' => [
118 'px' => [
119 'min' => 0,
120 'max' => 500,
121 'step' => 1,
122 ],
123 ],
124 'default' => [
125 'unit' => 'px',
126 'size' => 50,
127 ],
128 'selectors' => [
129 '{{WRAPPER}} .uicore-pagination' => 'margin-top: {{SIZE}}px;',
130 '{{WRAPPER}} .ui-e-load-more' => 'margin-top: {{SIZE}}px;',
131 ],
132 ]
133 );
134 $this->add_control(
135 'pagination_align',
136 [
137 'label' => esc_html__( 'Pagination Alignment', 'uicore-elements' ),
138 'type' => Controls_Manager::CHOOSE,
139 'options' => [
140 'start' => [
141 'title' => esc_html__( 'Left', 'uicore-elements' ),
142 'icon' => 'eicon-text-align-left',
143 ],
144 'center' => [
145 'title' => esc_html__( 'Center', 'uicore-elements' ),
146 'icon' => 'eicon-text-align-center',
147 ],
148 ],
149 'selectors' => [
150 '{{WRAPPER}} .uicore-pagination ul' => 'justify-content: {{VALUE}};',
151 '{{WRAPPER}} .ui-e-pagination' => 'text-align: {{VALUE}};',
152 ],
153 ]
154 );
155 // Number Specific
156 $this->add_control(
157 'pagination_padding',
158 [
159 'label' => __( 'Items Padding', 'uicore-elements' ),
160 'type' => Controls_Manager::SLIDER,
161 'size_units' => [ 'em' ],
162 'range' => [
163 'em' => [
164 'min' => 0,
165 'max' => 3,
166 'step' => 0.1,
167 ],
168 ],
169 'default' => [
170 'unit' => 'em',
171 'size' => 0.4,
172 ],
173 'selectors' => [
174 '{{WRAPPER}} .uicore-pagination ul li > *' => ' width: calc(1em + {{SIZE}}em);line-height: calc(1em + {{SIZE}}em);',
175 ],
176 'condition' => array(
177 'pagination_type' => 'numbers',
178 ),
179 ]
180 );
181 $this->add_control(
182 'pagination_gap',
183 [
184 'label' => __( 'Items Gap', 'uicore-elements' ),
185 'type' => Controls_Manager::SLIDER,
186 'size_units' => [ 'em' ],
187 'range' => [
188 'em' => [
189 'min' => 0,
190 'max' => 3,
191 'step' => 0.1,
192 ],
193 ],
194 'default' => [
195 'unit' => 'em',
196 'size' => 0.4,
197 ],
198 'selectors' => [
199 '{{WRAPPER}} .uicore-pagination ul' => 'gap: {{SIZE}}em;',
200 ],
201 'condition' => array(
202 'pagination_type' => 'numbers',
203 ),
204 ]
205 );
206 $this->add_control(
207 'pagination_radius',
208 [
209 'label' => __( 'Items Border Radius', 'uicore-elements' ),
210 'type' => Controls_Manager::SLIDER,
211 'size_units' => [ 'em' ],
212 'range' => [
213 'em' => [
214 'min' => 0,
215 'max' => 3,
216 'step' => 0.1,
217 ],
218 ],
219 'default' => [
220 'unit' => 'em',
221 'size' => 0.2,
222 ],
223 'selectors' => [
224 '{{WRAPPER}} .uicore-pagination ul li' => 'border-radius: {{SIZE}}em;',
225 ],
226 'condition' => array(
227 'pagination_type' => 'numbers',
228 ),
229 ]
230 );
231 // Load More Specific
232 $this->add_control(
233 'load_more_padding',
234 [
235 'label' => esc_html__( 'Button Padding', 'uicore-elements' ),
236 'type' => Controls_Manager::DIMENSIONS,
237 'size_units' => [ 'px', '%', 'em'],
238 'selectors' => [
239 '{{WRAPPER}} .ui-e-load-more' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
240 ],
241 'condition' => array(
242 'pagination_type' => 'load_more'
243 ),
244 ]
245 );
246 $this->add_control(
247 'load_more_radius',
248 [
249 'label' => esc_html__( 'Button Radius', 'uicore-elements' ),
250 'type' => Controls_Manager::DIMENSIONS,
251 'size_units' => [ 'px', '%', 'em'],
252 'selectors' => [
253 '{{WRAPPER}} .ui-e-load-more' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
254 ],
255 'condition' => array(
256 'pagination_type' => 'load_more'
257 ),
258 ]
259 );
260 // General Again
261 $this->start_controls_tabs(
262 'pagination_item', [
263 'condition' => [
264 'pagination' => 'yes',
265 ],
266 ]
267 );
268 $this->start_controls_tab(
269 'pagination_normal_tab',
270 [
271 'label' => esc_html__( 'Normal', 'uicore-elements' ),
272 ]
273 );
274 $this->add_control(
275 'pagination_bg',
276 [
277 'label' => esc_html__( 'Background', 'uicore-elements' ),
278 'type' => Controls_Manager::COLOR,
279 'default' => '',
280 'selectors' => [
281 '{{WRAPPER}} .uicore-pagination li' => 'background: {{VALUE}};',
282 '{{WRAPPER}} .ui-e-load-more' => 'background: {{VALUE}};',
283 ],
284 ]
285 );
286 $this->add_control(
287 'pagination_color',
288 [
289 'label' => esc_html__( 'Color', 'uicore-elements' ),
290 'type' => Controls_Manager::COLOR,
291 'default' => '',
292 'selectors' => [
293 '{{WRAPPER}} .uicore-pagination li a' => 'color: {{VALUE}};',
294 '{{WRAPPER}} .uicore-pagination svg' => 'fill: {{VALUE}};',
295 '{{WRAPPER}} .ui-e-load-more' => 'color: {{VALUE}};',
296 ],
297 ]
298 );
299 $this->add_group_control(
300 Group_Control_Border::get_type(),
301 [
302 'name' => 'pagination_border',
303 'selector' => '{{WRAPPER}} .uicore-pagination ul li, {{WRAPPER}} .ui-e-load-more',
304 'separator' => 'before',
305 ]
306 );
307 $this->add_group_control(
308 Group_Control_Box_Shadow::get_type(),
309 [
310 'name' => 'pagination_shadow',
311 'selector' => '{{WRAPPER}} .uicore-pagination ul li, {{WRAPPER}} .ui-e-load-more',
312 ]
313 );
314 $this->end_controls_tab();
315
316 $this->start_controls_tab(
317 'pagination_hover_tab',
318 [
319 'label' => esc_html__( 'Hover', 'uicore-elements' ),
320 ]
321 );
322 $this->add_control(
323 'pagination_hover_bg',
324 [
325 'label' => esc_html__( 'Background', 'uicore-elements' ),
326 'type' => Controls_Manager::COLOR,
327 'default' => '',
328 'selectors' => [
329 '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active)' => 'background: {{VALUE}};',
330 '{{WRAPPER}} .ui-e-load-more:hover' => 'background: {{VALUE}};',
331 ],
332 ]
333 );
334 $this->add_control('pagination_hover_color', [
335 'label' => esc_html__( 'Color', 'uicore-elements' ),
336 'type' => Controls_Manager::COLOR,
337 'default' => '',
338 'selectors' => [
339 '{{WRAPPER}} .uicore-pagination li:hover:not(.uicore-active) a' => 'color: {{VALUE}};',
340 '{{WRAPPER}} .uicore-pagination li:hover:not(.uicore-active) svg' => 'fill: {{VALUE}};',
341 '{{WRAPPER}} .ui-e-load-more:hover' => 'color: {{VALUE}};',
342 ],
343 ]
344 );
345 $this->add_group_control(
346 Group_Control_Border::get_type(),
347 [
348 'name' => 'pagination_border_hover',
349 'selector' => '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active), {{WRAPPER}} .ui-e-load-more:hover',
350 'separator' => 'before',
351 ]
352 );
353 $this->add_group_control(
354 Group_Control_Box_Shadow::get_type(),
355 [
356 'name' => 'pagination_shadow_hover',
357 'selector' => '{{WRAPPER}} .uicore-pagination ul li:hover:not(.uicore-active), {{WRAPPER}} .ui-e-load-more:hover',
358 ]
359 );
360 $this->end_controls_tab();
361 // Number specific
362 $this->start_controls_tab(
363 'pagination_active_tab',
364 [
365 'label' => esc_html__( 'Active', 'uicore-elements' ),
366 'condition' => [
367 'pagination_type' => 'numbers',
368 ]
369 ]
370 );
371 $this->add_control('pagination_active_bg', [
372 'label' => esc_html__( 'Background', 'uicore-elements' ),
373 'type' => Controls_Manager::COLOR,
374 'default' => '',
375 'selectors' => [
376 '{{WRAPPER}} .uicore-page-link.current' => 'background: {{VALUE}};',
377 ],
378 'condition' => [
379 'pagination_type' => 'numbers',
380 ]
381 ]
382 );
383 $this->add_control('pagination_active_color', [
384 'label' => esc_html__( 'Color', 'uicore-elements' ),
385 'type' => Controls_Manager::COLOR,
386 'default' => '',
387 'selectors' => [
388 '{{WRAPPER}} .uicore-page-link.current' => 'color: {{VALUE}};',
389 ],
390 'condition' => [
391 'pagination_type' => 'numbers',
392 ]
393 ]
394 );
395 $this->add_group_control(
396 Group_Control_Border::get_type(),
397 [
398 'name' => 'pagination_border_active',
399 'selector' => '{{WRAPPER}} .uicore-pagination li.uicore-active',
400 'separator' => 'before',
401 'condition' => [
402 'pagination_type' => 'numbers',
403 ]
404 ]
405 );
406 $this->add_group_control(
407 Group_Control_Box_Shadow::get_type(),
408 [
409 'name' => 'pagination_shadow_active',
410 'selector' => '{{WRAPPER}} .uicore-pagination li.uicore-active',
411 'condition' => [
412 'pagination_type' => 'numbers',
413 ]
414 ]
415 );
416 $this->end_controls_tab();
417
418 $this->end_controls_tabs();
419
420 if($section){
421 $this->end_controls_section();
422 }
423 }
424
425 /**
426 * sajdnek
427 *
428 * @param array $args
429 * @param string $class
430 * @author Andrei Voica <andrei@uicore.co>
431 * @since 1.0.0
432 */
433 function render_numbers($is_product, $args = [])
434 {
435 //
436 if ( $is_product ){
437 $query = $this->get_query();
438
439 //
440 $total_items = $query['limit'] ?? get_option('posts_per_page'); // TODO: using products quantity from framework maybe better
441 $total_count = wc_get_products( array_merge($query, ['limit' => -1, 'return' => 'ids']) ); // Fetch all products - TODO: -1 is very bad for performance
442 $total = ceil( count($total_count) / $total_items );
443 $current_page = max(1, get_query_var('paged'));
444
445 } else {
446 global $query;
447 }
448
449 // Set pagination args
450 $args = wp_parse_args($args, [
451 'mid_size' => 2,
452 'prev_next' => true,
453 'prev_text' => null,
454 'next_text' => null,
455 'screen_reader_text' => _x('Posts navigation', 'Frontend - Pagination', 'uicore-elements'),
456 'type' => 'array',
457 'current' => max(1, get_query_var('paged')),
458 ]);
459
460
461 // Build woo pagination args
462 if ( $is_product ) {
463
464 if ( $total && $total <= 1 ) {
465 return;
466 }
467
468 $args = apply_filters('woocommerce_pagination_args', [
469 // WPCS: XSS ok.
470 'current' => $current_page,
471 'total' => $total,
472 'prev_text' => '',
473 'next_text' => '',
474 'type' => 'array',
475 'base' => esc_url_raw( add_query_arg( 'product-page', '%#%', false ) ),
476 'screen_reader_text' => _x('Products navigation', 'Frontend - Pagination', 'uicore-elements'),
477 ]);
478
479 if ( ! wc_get_loop_prop( 'is_shortcode' ) ) {
480 $args['format'] = '';
481 $args['base'] = esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
482 }
483 }
484
485 $links = paginate_links($args);
486 $class = 'uicore-pagination';
487 $class .= !defined('UICORE_ASSETS') ? ' ui-e-pagination' : '';
488
489 if (is_array($links) || is_object($links)) { ?>
490 <nav aria-label="<?php echo esc_attr($args['screen_reader_text']); ?>" class="<?php echo esc_attr($class);?>">
491 <ul>
492 <?php foreach ($links as $key => $link) :
493 // If next/prev buttons and Uicore Framework is not active, get arrow icon and append it
494 if ( (strpos($link, 'prev') || strpos($link, 'next')) && !defined('UICORE_ASSETS') ) {
495 $svg = \file_get_contents(UICORE_ELEMENTS_ASSETS . '/media/svg/pagination-icon.svg');
496 $link = str_replace('</a>', $svg . '</a>', $link);
497 }
498 ?>
499 <li class="uicore-page-item <?php echo strpos($link, 'current') ? 'uicore-active' : ''; ?>">
500 <?php echo wp_kses_post( str_replace('page-numbers', 'uicore-page-link', $link)); ?>
501 </li>
502 <?php endforeach; ?>
503 </ul>
504 </nav>
505 <?php }
506 }
507 function render_load_more()
508 {
509 // No logic here. It's handled by ajax-request script and rest-api endpoint
510 ?>
511 <nav aria-label="Posts navigation" class="ui-e-pagination">
512 <button class="ui-e-load-more elementor-button">Load more</button>
513 </nav>
514 <?php
515 }
516 function TRAIT_render_pagination($settings, $is_product = false)
517 {
518 if( $settings['pagination'] === 'yes'){
519 if( $settings['pagination_type'] === 'load_more'){
520 $this->render_load_more();
521 } else {
522 $this->render_numbers($is_product);
523 }
524 }
525 }
526 }
527