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