category-list.php
512 lines
| 1 | <?php |
| 2 | namespace Elementor; |
| 3 | |
| 4 | use \Elementor\ElementsKit_Widget_Category_List_Handler as Handler; |
| 5 | use \ElementsKit_Lite\Modules\Controls\Controls_Manager as ElementsKit_Controls_Manager; |
| 6 | |
| 7 | if (! defined( 'ABSPATH' ) ) exit; |
| 8 | |
| 9 | class ElementsKit_Widget_Category_List extends Widget_Base { |
| 10 | use \ElementsKit_Lite\Widgets\Widget_Notice; |
| 11 | |
| 12 | public $base; |
| 13 | |
| 14 | public function get_name() { |
| 15 | return Handler::get_name(); |
| 16 | } |
| 17 | |
| 18 | public function get_title() { |
| 19 | return Handler::get_title(); |
| 20 | } |
| 21 | |
| 22 | public function get_icon() { |
| 23 | return Handler::get_icon(); |
| 24 | } |
| 25 | |
| 26 | public function get_keywords() { |
| 27 | return Handler::get_keywords(); |
| 28 | } |
| 29 | |
| 30 | public function get_categories() { |
| 31 | return Handler::get_categories(); |
| 32 | } |
| 33 | |
| 34 | public function get_help_url() { |
| 35 | return 'https://wpmet.com/doc/category-list/'; |
| 36 | } |
| 37 | |
| 38 | public function get_style_depends(): array { |
| 39 | return [ 'widget-icon-list' ]; |
| 40 | } |
| 41 | |
| 42 | protected function is_dynamic_content(): bool { |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | public function has_widget_inner_wrapper(): bool { |
| 47 | return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 48 | } |
| 49 | |
| 50 | protected function register_controls() { |
| 51 | $this->start_controls_section( |
| 52 | 'section_icon', |
| 53 | [ |
| 54 | 'label' => esc_html__( 'List', 'elementskit-lite' ), |
| 55 | ] |
| 56 | ); |
| 57 | |
| 58 | $this->add_control( |
| 59 | 'view', |
| 60 | [ |
| 61 | 'label' => esc_html__( 'Layout', 'elementskit-lite' ), |
| 62 | 'type' => Controls_Manager::CHOOSE, |
| 63 | 'default' => 'traditional', |
| 64 | 'options' => [ |
| 65 | 'traditional' => [ |
| 66 | 'title' => esc_html__( 'Default', 'elementskit-lite' ), |
| 67 | 'icon' => 'eicon-editor-list-ul', |
| 68 | ], |
| 69 | 'inline' => [ |
| 70 | 'title' => esc_html__( 'Inline', 'elementskit-lite' ), |
| 71 | 'icon' => 'eicon-ellipsis-h', |
| 72 | ], |
| 73 | ], |
| 74 | 'render_type' => 'template', |
| 75 | 'classes' => 'elementor-control-start-end', |
| 76 | 'label_block' => false, |
| 77 | 'style_transfer' => true, |
| 78 | ] |
| 79 | ); |
| 80 | |
| 81 | $repeater = new Repeater(); |
| 82 | |
| 83 | $repeater->add_control( |
| 84 | 'text', |
| 85 | [ |
| 86 | 'label' => esc_html__( 'Text', 'elementskit-lite' ), |
| 87 | 'type' => Controls_Manager::TEXT, |
| 88 | 'dynamic' => [ |
| 89 | 'active' => true, |
| 90 | ], |
| 91 | 'label_block' => true, |
| 92 | 'placeholder' => esc_html__( 'List Title', 'elementskit-lite' ), |
| 93 | ] |
| 94 | ); |
| 95 | |
| 96 | $repeater->add_control( |
| 97 | 'icons', |
| 98 | [ |
| 99 | 'label' => esc_html__( 'Icon', 'elementskit-lite' ), |
| 100 | 'type' => Controls_Manager::ICONS, |
| 101 | 'default' => [ |
| 102 | 'value' => 'fas fa-check', |
| 103 | 'library' => 'fa-solid', |
| 104 | ], |
| 105 | 'label_block' => true, |
| 106 | ] |
| 107 | ); |
| 108 | |
| 109 | $repeater->add_control( |
| 110 | 'list_bg_color', |
| 111 | [ |
| 112 | 'label' => esc_html__( 'Background Color', 'elementskit-lite' ), |
| 113 | 'type' => Controls_Manager::COLOR, |
| 114 | ] |
| 115 | ); |
| 116 | |
| 117 | $repeater->add_control( |
| 118 | 'link', |
| 119 | [ |
| 120 | 'label' =>esc_html__('Select Category', 'elementskit-lite'), |
| 121 | 'type' => ElementsKit_Controls_Manager::AJAXSELECT2, |
| 122 | 'options' =>'ajaxselect2/category', |
| 123 | 'label_block' => true, |
| 124 | 'multiple' => false, |
| 125 | ] |
| 126 | ); |
| 127 | |
| 128 | $this->add_control( |
| 129 | 'icon_list', |
| 130 | [ |
| 131 | 'label' => '', |
| 132 | 'type' => Controls_Manager::REPEATER, |
| 133 | 'fields' => $repeater->get_controls(), |
| 134 | 'title_field' => '<i class="{{ icons.value }}" aria-hidden="true"></i> {{{ text }}}', |
| 135 | ] |
| 136 | ); |
| 137 | |
| 138 | $this->end_controls_section(); |
| 139 | |
| 140 | $this->start_controls_section( |
| 141 | 'section_icon_list', |
| 142 | [ |
| 143 | 'label' => esc_html__( 'List', 'elementskit-lite' ), |
| 144 | 'tab' => Controls_Manager::TAB_STYLE, |
| 145 | ] |
| 146 | ); |
| 147 | |
| 148 | $this->add_responsive_control( |
| 149 | 'space_between', |
| 150 | [ |
| 151 | 'label' => esc_html__( 'Space Between', 'elementskit-lite' ), |
| 152 | 'type' => Controls_Manager::SLIDER, |
| 153 | 'range' => [ |
| 154 | 'px' => [ |
| 155 | 'max' => 50, |
| 156 | ], |
| 157 | ], |
| 158 | 'selectors' => [ |
| 159 | '{{WRAPPER}} .elementor-icon-list-items:not(.elementor-inline-items) .elementor-icon-list-item:not(:last-child)' => 'padding-bottom: calc({{SIZE}}{{UNIT}}/2)', |
| 160 | '{{WRAPPER}} .elementor-icon-list-items:not(.elementor-inline-items) .elementor-icon-list-item:not(:first-child)' => 'margin-top: calc({{SIZE}}{{UNIT}}/2)', |
| 161 | '{{WRAPPER}} .elementor-icon-list-items.elementor-inline-items .elementor-icon-list-item' => 'margin-right: calc({{SIZE}}{{UNIT}}/2); margin-left: calc({{SIZE}}{{UNIT}}/2)', |
| 162 | '{{WRAPPER}} .elementor-icon-list-items.elementor-inline-items' => 'margin-right: calc(-{{SIZE}}{{UNIT}}/2); margin-left: calc(-{{SIZE}}{{UNIT}}/2)', |
| 163 | 'body.rtl {{WRAPPER}} .elementor-icon-list-items.elementor-inline-items .elementor-icon-list-item:after' => 'left: calc(-{{SIZE}}{{UNIT}}/2)', |
| 164 | 'body:not(.rtl) {{WRAPPER}} .elementor-icon-list-items.elementor-inline-items .elementor-icon-list-item:after' => 'right: calc(-{{SIZE}}{{UNIT}}/2)', |
| 165 | ], |
| 166 | ] |
| 167 | ); |
| 168 | |
| 169 | $this->add_responsive_control( |
| 170 | 'icon_align', |
| 171 | [ |
| 172 | 'label' => esc_html__( 'Alignment', 'elementskit-lite' ), |
| 173 | 'type' => Controls_Manager::CHOOSE, |
| 174 | 'options' => [ |
| 175 | 'left' => [ |
| 176 | 'title' => esc_html__( 'Left', 'elementskit-lite' ), |
| 177 | 'icon' => 'eicon-text-align-left', |
| 178 | ], |
| 179 | 'center' => [ |
| 180 | 'title' => esc_html__( 'Center', 'elementskit-lite' ), |
| 181 | 'icon' => 'eicon-text-align-center', |
| 182 | ], |
| 183 | 'right' => [ |
| 184 | 'title' => esc_html__( 'Right', 'elementskit-lite' ), |
| 185 | 'icon' => 'eicon-text-align-right', |
| 186 | ], |
| 187 | ], |
| 188 | 'prefix_class' => 'elementor%s-align-', |
| 189 | ] |
| 190 | ); |
| 191 | |
| 192 | $this->add_control( |
| 193 | 'divider', |
| 194 | [ |
| 195 | 'label' => esc_html__( 'Divider', 'elementskit-lite' ), |
| 196 | 'type' => Controls_Manager::SWITCHER, |
| 197 | 'label_off' => esc_html__( 'Off', 'elementskit-lite' ), |
| 198 | 'label_on' => esc_html__( 'On', 'elementskit-lite' ), |
| 199 | 'selectors' => [ |
| 200 | '{{WRAPPER}} .elementor-icon-list-item:not(:last-child):after' => 'content: "";', |
| 201 | '{{WRAPPER}} .elementor-inline-items .elementor-icon-list-item:not(:last-child):after' => 'bottom: unset;', |
| 202 | ], |
| 203 | 'separator' => 'before', |
| 204 | ] |
| 205 | ); |
| 206 | |
| 207 | $this->add_control( |
| 208 | 'divider_style', |
| 209 | [ |
| 210 | 'label' => esc_html__( 'Style', 'elementskit-lite' ), |
| 211 | 'type' => Controls_Manager::SELECT, |
| 212 | 'options' => [ |
| 213 | 'solid' => esc_html__( 'Solid', 'elementskit-lite' ), |
| 214 | 'dotted' => esc_html__( 'Dotted', 'elementskit-lite' ), |
| 215 | 'dashed' => esc_html__( 'Dashed', 'elementskit-lite' ), |
| 216 | ], |
| 217 | 'default' => 'solid', |
| 218 | 'condition' => [ |
| 219 | 'divider' => 'yes', |
| 220 | ], |
| 221 | 'selectors' => [ |
| 222 | '{{WRAPPER}} .elementor-icon-list-items:not(.elementor-inline-items) .elementor-icon-list-item:not(:last-child):after' => 'border-top-style: {{VALUE}}', |
| 223 | '{{WRAPPER}} .elementor-icon-list-items.elementor-inline-items .elementor-icon-list-item:not(:last-child):after' => 'border-left-style: {{VALUE}}', |
| 224 | ], |
| 225 | ] |
| 226 | ); |
| 227 | |
| 228 | $this->add_control( |
| 229 | 'divider_weight', |
| 230 | [ |
| 231 | 'label' => esc_html__( 'Weight', 'elementskit-lite' ), |
| 232 | 'type' => Controls_Manager::SLIDER, |
| 233 | 'default' => [ |
| 234 | 'size' => 1, |
| 235 | ], |
| 236 | 'range' => [ |
| 237 | 'px' => [ |
| 238 | 'min' => 1, |
| 239 | 'max' => 20, |
| 240 | ], |
| 241 | ], |
| 242 | 'condition' => [ |
| 243 | 'divider' => 'yes', |
| 244 | ], |
| 245 | 'selectors' => [ |
| 246 | '{{WRAPPER}} .elementor-icon-list-items:not(.elementor-inline-items) .elementor-icon-list-item:not(:last-child):after' => 'border-top-width: {{SIZE}}{{UNIT}}', |
| 247 | '{{WRAPPER}} .elementor-inline-items .elementor-icon-list-item:not(:last-child):after' => 'border-left-width: {{SIZE}}{{UNIT}}', |
| 248 | ], |
| 249 | ] |
| 250 | ); |
| 251 | |
| 252 | $this->add_control( |
| 253 | 'divider_width', |
| 254 | [ |
| 255 | 'label' => esc_html__( 'Width', 'elementskit-lite' ), |
| 256 | 'type' => Controls_Manager::SLIDER, |
| 257 | 'default' => [ |
| 258 | 'unit' => '%', |
| 259 | ], |
| 260 | 'condition' => [ |
| 261 | 'divider' => 'yes', |
| 262 | 'view!' => 'inline', |
| 263 | ], |
| 264 | 'selectors' => [ |
| 265 | '{{WRAPPER}} .elementor-icon-list-item:not(:last-child):after' => 'width: {{SIZE}}{{UNIT}}', |
| 266 | ], |
| 267 | ] |
| 268 | ); |
| 269 | |
| 270 | $this->add_control( |
| 271 | 'divider_height', |
| 272 | [ |
| 273 | 'label' => esc_html__( 'Height', 'elementskit-lite' ), |
| 274 | 'type' => Controls_Manager::SLIDER, |
| 275 | 'size_units' => [ '%', 'px' ], |
| 276 | 'default' => [ |
| 277 | 'unit' => '%', |
| 278 | ], |
| 279 | 'range' => [ |
| 280 | 'px' => [ |
| 281 | 'min' => 1, |
| 282 | 'max' => 100, |
| 283 | ], |
| 284 | '%' => [ |
| 285 | 'min' => 1, |
| 286 | 'max' => 100, |
| 287 | ], |
| 288 | ], |
| 289 | 'condition' => [ |
| 290 | 'divider' => 'yes', |
| 291 | 'view' => 'inline', |
| 292 | ], |
| 293 | 'selectors' => [ |
| 294 | '{{WRAPPER}} .elementor-icon-list-item:not(:last-child):after' => 'height: {{SIZE}}{{UNIT}}', |
| 295 | ], |
| 296 | ] |
| 297 | ); |
| 298 | |
| 299 | $this->add_control( |
| 300 | 'divider_color', |
| 301 | [ |
| 302 | 'label' => esc_html__( 'Color', 'elementskit-lite' ), |
| 303 | 'type' => Controls_Manager::COLOR, |
| 304 | 'default' => '#ddd', |
| 305 | 'condition' => [ |
| 306 | 'divider' => 'yes', |
| 307 | ], |
| 308 | 'selectors' => [ |
| 309 | '{{WRAPPER}} .elementor-icon-list-item:not(:last-child):after' => 'border-color: {{VALUE}}', |
| 310 | ], |
| 311 | ] |
| 312 | ); |
| 313 | |
| 314 | $this->add_responsive_control( |
| 315 | 'list_padding', |
| 316 | [ |
| 317 | 'label' => esc_html__('Padding (px)', 'elementskit-lite'), |
| 318 | 'type' => Controls_Manager::DIMENSIONS, |
| 319 | 'size_units' => [ 'px' ], |
| 320 | 'selectors' => [ |
| 321 | '{{WRAPPER}} .elementor-icon-list-item a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 322 | ], |
| 323 | 'separator' => 'before', |
| 324 | ] |
| 325 | ); |
| 326 | |
| 327 | $this->add_responsive_control( |
| 328 | 'list_border_radius', |
| 329 | [ |
| 330 | 'label' => esc_html__('Border Radius', 'elementskit-lite'), |
| 331 | 'type' => Controls_Manager::SLIDER, |
| 332 | 'size_units' => [ 'px', '%' ], |
| 333 | 'range' => [ |
| 334 | 'px' => [ |
| 335 | 'min' => 0, |
| 336 | 'max' => 100, |
| 337 | ], |
| 338 | '%' => [ |
| 339 | 'min' => 0, |
| 340 | 'max' => 100, |
| 341 | ], |
| 342 | ], |
| 343 | 'selectors' => [ |
| 344 | '{{WRAPPER}} .elementor-icon-list-item a' => 'border-radius: {{SIZE}}{{UNIT}};', |
| 345 | ], |
| 346 | 'separator' => 'before', |
| 347 | ] |
| 348 | ); |
| 349 | |
| 350 | $this->end_controls_section(); |
| 351 | |
| 352 | $this->start_controls_section( |
| 353 | 'section_icon_style', |
| 354 | [ |
| 355 | 'label' => esc_html__( 'Icon', 'elementskit-lite' ), |
| 356 | 'tab' => Controls_Manager::TAB_STYLE, |
| 357 | ] |
| 358 | ); |
| 359 | |
| 360 | $this->add_control( |
| 361 | 'icon_color', |
| 362 | [ |
| 363 | 'label' => esc_html__( 'Color', 'elementskit-lite' ), |
| 364 | 'type' => Controls_Manager::COLOR, |
| 365 | 'default' => '', |
| 366 | 'selectors' => [ |
| 367 | '{{WRAPPER}} .elementor-icon-list-icon' => 'color: {{VALUE}}; fill: {{VALUE}};', |
| 368 | ], |
| 369 | ] |
| 370 | ); |
| 371 | |
| 372 | $this->add_control( |
| 373 | 'icon_color_hover', |
| 374 | [ |
| 375 | 'label' => esc_html__( 'Hover', 'elementskit-lite' ), |
| 376 | 'type' => Controls_Manager::COLOR, |
| 377 | 'default' => '', |
| 378 | 'selectors' => [ |
| 379 | '{{WRAPPER}} .elementor-icon-list-item:hover .elementor-icon-list-icon' => 'color: {{VALUE}}; fill: {{VALUE}};', |
| 380 | ], |
| 381 | ] |
| 382 | ); |
| 383 | |
| 384 | $this->add_responsive_control( |
| 385 | 'icon_size', |
| 386 | [ |
| 387 | 'label' => esc_html__( 'Size', 'elementskit-lite' ), |
| 388 | 'type' => Controls_Manager::SLIDER, |
| 389 | 'default' => [ |
| 390 | 'size' => 14, |
| 391 | ], |
| 392 | 'range' => [ |
| 393 | 'px' => [ |
| 394 | 'min' => 6, |
| 395 | ], |
| 396 | ], |
| 397 | 'selectors' => [ |
| 398 | '{{WRAPPER}} .elementor-icon-list-icon' => 'font-size: {{SIZE}}{{UNIT}};', |
| 399 | ], |
| 400 | ] |
| 401 | ); |
| 402 | |
| 403 | $this->end_controls_section(); |
| 404 | |
| 405 | $this->start_controls_section( |
| 406 | 'section_text_style', |
| 407 | [ |
| 408 | 'label' => esc_html__( 'Text', 'elementskit-lite' ), |
| 409 | 'tab' => Controls_Manager::TAB_STYLE, |
| 410 | ] |
| 411 | ); |
| 412 | |
| 413 | $this->add_control( |
| 414 | 'text_color', |
| 415 | [ |
| 416 | 'label' => esc_html__( 'Text Color', 'elementskit-lite' ), |
| 417 | 'type' => Controls_Manager::COLOR, |
| 418 | 'default' => '', |
| 419 | 'selectors' => [ |
| 420 | '{{WRAPPER}} .elementor-icon-list-item a' => 'color: {{VALUE}}; fill: {{VALUE}};', |
| 421 | ], |
| 422 | ] |
| 423 | ); |
| 424 | |
| 425 | $this->add_control( |
| 426 | 'text_color_hover', |
| 427 | [ |
| 428 | 'label' => esc_html__( 'Hover', 'elementskit-lite' ), |
| 429 | 'type' => Controls_Manager::COLOR, |
| 430 | 'default' => '', |
| 431 | 'selectors' => [ |
| 432 | '{{WRAPPER}} .elementor-icon-list-item:hover a' => 'color: {{VALUE}}; fill: {{VALUE}};', |
| 433 | ], |
| 434 | ] |
| 435 | ); |
| 436 | |
| 437 | $this->add_control( |
| 438 | 'text_indent', |
| 439 | [ |
| 440 | 'label' => esc_html__( 'Left Padding', 'elementskit-lite' ), |
| 441 | 'type' => Controls_Manager::SLIDER, |
| 442 | 'range' => [ |
| 443 | 'px' => [ |
| 444 | 'max' => 50, |
| 445 | ], |
| 446 | ], |
| 447 | 'selectors' => [ |
| 448 | '{{WRAPPER}} .elementor-icon-list-text' => is_rtl() ? 'padding-right: {{SIZE}}{{UNIT}};' : 'padding-left: {{SIZE}}{{UNIT}};', |
| 449 | ], |
| 450 | ] |
| 451 | ); |
| 452 | |
| 453 | $this->add_group_control( |
| 454 | Group_Control_Typography::get_type(), |
| 455 | [ |
| 456 | 'name' => 'icon_typography', |
| 457 | 'selector' => '{{WRAPPER}} .elementor-icon-list-item', |
| 458 | ] |
| 459 | ); |
| 460 | |
| 461 | $this->end_controls_section(); |
| 462 | |
| 463 | $this->insert_pro_message(); |
| 464 | } |
| 465 | |
| 466 | protected function render( ) { |
| 467 | echo '<div class="ekit-wid-con" >'; |
| 468 | $this->render_raw(); |
| 469 | echo '</div>'; |
| 470 | } |
| 471 | |
| 472 | protected function render_raw( ) { |
| 473 | $settings = $this->get_settings_for_display(); |
| 474 | |
| 475 | $this->add_render_attribute( 'icon_list', 'class', 'elementor-icon-list-items' ); |
| 476 | $this->add_render_attribute( 'list_item', 'class', 'elementor-icon-list-item' ); |
| 477 | |
| 478 | if ( 'inline' === $settings['view'] ) { |
| 479 | $this->add_render_attribute( 'icon_list', 'class', 'elementor-inline-items' ); |
| 480 | $this->add_render_attribute( 'list_item', 'class', 'elementor-inline-item' ); |
| 481 | } |
| 482 | ?> |
| 483 | <ul <?php echo $this->get_render_attribute_string( 'icon_list' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped by elementor ?>> |
| 484 | <?php |
| 485 | foreach ( $settings['icon_list'] as $index => $item ) : |
| 486 | $post = !empty( $item['link'] ) ? get_category($item['link']) : 0; |
| 487 | $text = empty($item['text']) ? (!empty($post) ? $post->name : '') : $item['text']; |
| 488 | if(!empty($item['list_bg_color'])) { |
| 489 | $this->add_render_attribute('list_bg_' . $index, 'style', 'background: ' . esc_attr($item['list_bg_color']) . ';'); |
| 490 | } |
| 491 | |
| 492 | if($post != null): |
| 493 | ?> |
| 494 | <li class="elementor-icon-list-item"> |
| 495 | <a href="<?php echo esc_url(get_category_link($post->term_id)); ?>" <?php echo $this->get_render_attribute_string('list_bg_' . $index); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped by elementor ?>> |
| 496 | <?php if (!empty($item['icons']['value'])) : ?> |
| 497 | <span class="elementor-icon-list-icon"> |
| 498 | <?php Icons_Manager::render_icon($item['icons'], [ 'aria-hidden' => 'true' ]); ?> |
| 499 | </span> |
| 500 | <?php endif; ?> |
| 501 | <span class="elementor-icon-list-text"><?php echo esc_html($text); ?></span> |
| 502 | </a> |
| 503 | </li> |
| 504 | <?php |
| 505 | endif; |
| 506 | endforeach; |
| 507 | ?> |
| 508 | </ul> |
| 509 | <?php |
| 510 | } |
| 511 | } |
| 512 |