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

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