PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.3
UiCore Elements – Free widgets and templates for Elementor v1.2.3
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.3, at includes/utils/pagination-component.php

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