PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / elementor-elements / classes / wdk-categories-tree.php

wdk-categories-tree.php in WP Directory Kit 1.5.9, at elementor-elements/classes/wdk-categories-tree.php

742 lines 27.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Wdk\Elementor\Widgets;
4
5 use Wdk\Elementor\Widgets\WdkElementorBase;
6 use Elementor\Widget_Base;
7 use Elementor\Controls_Manager;
8 use Elementor\Utils;
9 use Elementor\Typography;
10 use Elementor\Editor;
11 use Elementor\Plugin;
12 use Elementor\Repeater;
13 use Elementor\Core\Schemes;
14 use Elementor\Icons_Manager;
15 use Elementor\Group_Control_Typography;
16 use Elementor\Group_Control_Border;
17 use Elementor\Group_Control_Box_Shadow;
18
19 if (!defined('ABSPATH'))
20 exit; // Exit if accessed directly
21
22 /**
23 * @since 1.1.0
24 */
25 class WdkCategoriesTree extends WdkElementorBase {
26
27 public function __construct($data = array(), $args = null) {
28
29 \Elementor\Controls_Manager::add_tab(
30 'tab_conf',
31 esc_html__('Settings', 'wpdirectorykit')
32 );
33
34
35 \Elementor\Controls_Manager::add_tab(
36 'tab_layout',
37 esc_html__('Layout', 'wpdirectorykit')
38 );
39
40 \Elementor\Controls_Manager::add_tab(
41 'tab_content',
42 esc_html__('Main', 'wpdirectorykit')
43 );
44
45 if ($this->is_edit_mode_load()) {
46 $this->enqueue_styles_scripts();
47 }
48
49 parent::__construct($data, $args);
50 }
51
52 /**
53 * Retrieve the widget name.
54 *
55 * @since 1.1.0
56 *
57 * @access public
58 *
59 * @return string Widget name.
60 */
61 public function get_name() {
62 return 'wdk-categories-tree';
63 }
64
65 /**
66 * Retrieve the widget title.
67 *
68 * @since 1.1.0
69 *
70 * @access public
71 *
72 * @return string Widget title.
73 */
74 public function get_title() {
75 return esc_html__('Wdk Categories Tree', 'wpdirectorykit');
76 }
77
78 /**
79 * Retrieve the widget icon.
80 *
81 * @since 1.1.0
82 *
83 * @access public
84 *
85 * @return string Widget icon.
86 */
87 public function get_icon() {
88 return 'eicon-sitemap';
89 }
90
91 /**
92 * Register the widget controls.
93 *
94 * Adds different input fields to allow the user to change and customize the widget settings.
95 *
96 * @since 1.1.0
97 *
98 * @access protected
99 */
100 protected function register_controls() {
101 $this->generate_controls_conf();
102 $this->generate_controls_layout();
103 $this->generate_controls_styles();
104 $this->generate_controls_content();
105
106 $this->insert_pro_message('1');
107 parent::register_controls();
108 }
109
110 /**
111 * Render the widget output on the frontend.
112 *
113 * Written in PHP and used to generate the final HTML.
114 *
115 * @since 1.1.0
116 *
117 * @access protected
118 */
119 protected function render() {
120 parent::render();
121 $this->data['id_element'] = $this->get_id();
122 $this->data['settings'] = $this->get_settings();
123
124 $controller = 'category';
125 $this->WMVC->model($controller.'_m');
126 $this->WMVC->model('listing_m');
127 $this->WMVC->model('category_m');
128
129 $this->data['results'] = array();
130
131
132
133 if($this->data['settings']['conf_results_type'] == 'custom_categories') {
134 $categories_ids = array();
135 foreach($this->data['settings']['conf_custom_results'] as $category) {
136 if(isset($category['category_id']) && !empty($category['category_id'])) {
137 $categories_ids [] = $category['category_id'];
138 }
139 }
140 /* where in */
141 if(!empty($categories_ids)){
142 $where = array();
143 $where[$this->WMVC->{$controller.'_m'}->_table_name.'.level_0_id IN (' . implode(',', $categories_ids) . ') OR '.$this->WMVC->{$controller.'_m'}->_table_name.'.idcategory IN (' . implode(',', $categories_ids) . ')'] = NULL;
144 $this->data['categories'] = $this->WMVC->category_m->get_pagination(NULL, NULL, $where);
145 }
146 } else {
147 $this->data['categories'] = $this->WMVC->category_m->get_pagination(NULL, NULL, array());
148 }
149
150 $this->data['is_edit_mode']= false;
151 if(Plugin::$instance->editor->is_edit_mode())
152 $this->data['is_edit_mode']= true;
153
154 $this->view('wdk-categories-tree', $this->data, true);
155 }
156
157
158 private function generate_controls_conf() {
159 $this->start_controls_section(
160 'tab_conf_main_section',
161 [
162 'label' => esc_html__('Main', 'wpdirectorykit'),
163 'tab' => '1',
164 ]
165 );
166
167 $pages = array('' => __('Not Selected', 'wpdirectorykit'));
168 foreach(get_pages(array('sort_column' => 'post_title')) as $page)
169 {
170 $pages[$page->ID] = $page->post_title.' #'.$page->ID;
171 }
172
173 $this->add_control(
174 'conf_link',
175 [
176 'label' => __( 'Open results on page', 'wpdirectorykit' ),
177 'type' => \Elementor\Controls_Manager::SELECT2,
178 'default' => '',
179 'options' => $pages
180 ]
181 );
182
183
184 $this->add_control(
185 'conf_results_type',
186 [
187 'label' => __( 'Show type', 'wpdirectorykit' ),
188 'type' => \Elementor\Controls_Manager::SELECT,
189 'default' => 'results_categories',
190 'options' => [
191 'results_categories' => __( 'All Categorys', 'wpdirectorykit' ),
192 'custom_categories' => __( 'Specific', 'wpdirectorykit' ),
193 ],
194
195 ]
196 );
197
198 $this->add_control(
199 'conf_limit_root',
200 [
201 'label' => __( 'Limit Main Categories', 'wpdirectorykit' ),
202 'type' => \Elementor\Controls_Manager::NUMBER,
203 'min' => 1,
204 'max' => 50,
205 'step' => 1,
206 'default' => 9,
207 'conditions' => [
208 'terms' => [
209 [
210 'name' => 'conf_results_type',
211 'operator' => '==',
212 'value' => 'results_categories',
213 ]
214 ],
215 ],
216 ]
217 );
218
219 $this->add_control(
220 'conf_limit_sub',
221 [
222 'label' => __( 'Limit Sub Categories', 'wpdirectorykit' ),
223 'type' => \Elementor\Controls_Manager::NUMBER,
224 'min' => 1,
225 'max' => 50,
226 'step' => 1,
227 'default' => 9,
228 'conditions' => [
229 'terms' => [
230 [
231 'name' => 'conf_results_type',
232 'operator' => '==',
233 'value' => 'results_categories',
234 ]
235 ],
236 ],
237 ]
238 );
239
240 $this->add_control(
241 'show_more_subs',
242 [
243 'label' => __( 'Show Button Open More SubCategories', 'wpdirectorykit' ),
244 'type' => \Elementor\Controls_Manager::SWITCHER,
245 'label_on' => __( 'On', 'wpdirectorykit' ),
246 'label_off' => __( 'Off', 'wpdirectorykit' ),
247 'return_value' => 'yes',
248 'default' => '',
249 'separator' => 'before',
250 'conditions' => [
251 'terms' => [
252 [
253 'name' => 'conf_results_type',
254 'operator' => '==',
255 'value' => 'results_categories',
256 ]
257 ],
258 ],
259 ]
260 );
261
262 $this->add_control(
263 'show_more',
264 [
265 'label' => __( 'Show Button Open More Categories', 'wpdirectorykit' ),
266 'type' => \Elementor\Controls_Manager::SWITCHER,
267 'label_on' => __( 'On', 'wpdirectorykit' ),
268 'label_off' => __( 'Off', 'wpdirectorykit' ),
269 'return_value' => 'yes',
270 'default' => '',
271 'separator' => 'after',
272 'conditions' => [
273 'terms' => [
274 [
275 'name' => 'conf_results_type',
276 'operator' => '==',
277 'value' => 'results_categories',
278 ]
279 ],
280 ],
281 ]
282 );
283
284 if(true){
285
286 $repeater = new Repeater();
287 $repeater->start_controls_tabs( 'categories' );
288
289 $WMVC = &wdk_get_instance();
290 $WMVC->model('category_m');
291 $categories_root = array('' => esc_html__('Not Selected', 'wpdirectorykit'));
292 $categories = $WMVC->category_m->get_pagination(NULL, NULL, array('('.$WMVC->category_m->_table_name.'.level = 0)'=>NULL));
293 foreach ($categories as $key => $category) {
294 $categories_root[$category->idcategory] = $category->category_title;
295 }
296
297 $repeater->add_control(
298 'category_id',
299 [
300 'label' => __( 'Categories', 'wpdirectorykit' ),
301 'type' => \Elementor\Controls_Manager::SELECT2,
302 'default' => '',
303 'options' => $categories_root,
304 'separator' => 'after',
305 ]
306 );
307
308 $repeater->end_controls_tabs();
309
310 $this->add_control(
311 'conf_custom_results',
312 [
313 'type' => Controls_Manager::REPEATER,
314 'fields' => $repeater->get_controls(),
315 'default' => [
316 ],
317 'title_field' => '{{{ category_id }}}',
318 'conditions' => [
319 'terms' => [
320 [
321 'name' => 'conf_results_type',
322 'operator' => '==',
323 'value' => 'custom_categories',
324 ]
325 ],
326 ],
327 ]
328 );
329 }
330
331 $this->add_control(
332 'show_icon',
333 [
334 'label' => __( 'Enable Category Icons', 'wpdirectorykit' ),
335 'type' => \Elementor\Controls_Manager::SWITCHER,
336 'label_on' => __( 'On', 'wpdirectorykit' ),
337 'label_off' => __( 'Off', 'wpdirectorykit' ),
338 'return_value' => 'yes',
339 'default' => 'yes',
340 'separator' => 'before',
341 ]
342 );
343
344 $this->add_control(
345 'layout_image_type',
346 [
347 'label' => __( 'Thumbnail Type', 'wpdirectorykit' ),
348 'type' => \Elementor\Controls_Manager::SELECT,
349 'default' => 'font_icon',
350 'options' => [
351 'icon' => __( 'Icon', 'wpdirectorykit' ),
352 'image' => __( 'Image', 'wpdirectorykit' ),
353 'font_icon' => __( 'Font Icon', 'wpdirectorykit' ),
354 ],
355 'conditions' => [
356 'terms' => [
357 [
358 'name' => 'show_icon',
359 'operator' => '==',
360 'value' => 'yes',
361 ]
362 ],
363 ],
364 ]
365 );
366
367 $this->add_control(
368 'important_note',
369 [
370 'label' => '',
371 'type' => \Elementor\Controls_Manager::RAW_HTML,
372 /* translators: 1: URL. */
373 'raw' => wdk_sprintf(__( 'Manage Categories <a href="%1$s" target="_blank"> open </a>', 'wpdirectorykit' ), admin_url('admin.php?page=wdk_category')),
374 'content_classes' => 'wdk_elementor_hint',
375 ]
376 );
377
378 $this->add_responsive_control(
379 'row_gap_col',
380 [
381 'label' => __( 'Columns', 'wpdirectorykit' ),
382 'type' => Controls_Manager::SELECT,
383 'options' => [
384 '' => esc_html__('Default', 'wpdirectorykit'),
385 'auto' => esc_html__('Auto', 'wpdirectorykit'),
386 '100%' => '1',
387 '50%' => '2',
388 'calc(100% / 3)' => '3',
389 '25%' => '4',
390 '20%' => '5',
391 'auto_flexible' => 'auto flexible',
392 ],
393 'selectors_dictionary' => [
394 'auto' => '-webkit-flex:0 0 auto;flex:0 0 auto',
395 '100%' => '-webkit-flex:0 0 100%;flex:0 0 100%',
396 '50%' => '-webkit-flex:0 0 50%;flex:0 0 50%',
397 'calc(100% / 3)' => '-webkit-flex:0 0 calc(100% / 3);flex:0 0 calc(100% / 3)',
398 '25%' => '-webkit-flex:0 0 25%;flex:0 0 25%',
399 '20%' => '-webkit-flex:0 0 20%;flex:0 0 20%',
400 'auto' => '-webkit-flex:0 0 auto;flex:0 0 auto',
401 'auto_flexible' => '-webkit-flex:0 0 auto;flex:0 0 auto',
402 ],
403 'selectors' => [
404 '{{WRAPPER}} .wdk-row .wdk-col' => '{{UNIT}}',
405 ],
406 'default' => 'calc(100% / 3)',
407 'separator' => 'before',
408 ]
409 );
410
411 $this->add_responsive_control(
412 'column_gap',
413 [
414 'label' => esc_html__('Columns Gap', 'wpdirectorykit'),
415 'type' => Controls_Manager::SLIDER,
416 'default' => [
417 'size' => 10,
418 ],
419 'range' => [
420 'px' => [
421 'min' => 0,
422 'max' => 60,
423 ],
424 ],
425 'selectors' => [
426 '{{WRAPPER}} .wdk-row .wdk-col' => 'padding-left: {{SIZE}}{{UNIT}};padding-right: {{SIZE}}{{UNIT}};;',
427 '{{WRAPPER}} .wdk-row' => 'margin-left: -{{SIZE}}{{UNIT}};margin-right: -{{SIZE}}{{UNIT}};',
428 ],
429 ]
430 );
431
432 $this->add_responsive_control(
433 'row_gap',
434 [
435 'label' => esc_html__('Rows Gap', 'wpdirectorykit'),
436 'type' => Controls_Manager::SLIDER,
437 'default' => [
438 'size' => 10,
439 ],
440 'range' => [
441 'px' => [
442 'min' => 0,
443 'max' => 60,
444 ],
445 ],
446 'selectors' => [
447 '{{WRAPPER}} .wdk-row .wdk-col' => 'margin-bottom: {{SIZE}}{{UNIT}};',
448 '{{WRAPPER}} .wdk-row' => 'margin-bottom: -{{SIZE}}{{UNIT}};',
449 ],
450 ]
451 );
452
453 $this->end_controls_section();
454 }
455
456 private function generate_controls_layout() {
457 }
458
459 private function generate_controls_styles() {
460 $this->start_controls_section(
461 'sstyles_thmbn_section',
462 [
463 'label' => esc_html__('Main', 'wpdirectorykit'),
464 'tab' => Controls_Manager::TAB_STYLE,
465 ]
466 );
467
468 $this->add_responsive_control(
469 'list_gap',
470 [
471 'label' => esc_html__('Rows Gap', 'wpdirectorykit'),
472 'type' => Controls_Manager::SLIDER,
473 'default' => [
474 'size' => 10,
475 ],
476 'range' => [
477 'px' => [
478 'min' => 0,
479 'max' => 60,
480 ],
481 ],
482 'selectors' => [
483 '{{WRAPPER}} .wdk-categories .wdk-item' => 'margin-bottom: {{SIZE}}{{UNIT}};',
484 ],
485 ]
486 );
487
488 $this->end_controls_section();
489
490 $items = [
491 [
492 'key'=>'title',
493 'label'=> esc_html__('Title', 'wpdirectorykit'),
494 'selector'=>'.title',
495 'selector_hide'=>'.title-in',
496 'selector_hover'=>'.title%1$s',
497 'options'=>['typo','color','background','border','border_radius','padding','shadow','transition','margin','padding'],
498 ],
499 [
500 'key'=>'item_button',
501 'label'=> esc_html__('Item Box', 'wpdirectorykit'),
502 'selector'=>'.wdk-categories .wdk-link',
503 'selector_hover'=>'.wdk-categories .wdk-link%1$s',
504 'options'=>['color','background','border','border_radius','padding','shadow','transition'],
505 ],
506 [
507 'key'=>'category_icon',
508 'label'=> esc_html__('Category Icon', 'wpdirectorykit'),
509 'selector'=>'.title .wdk-icon',
510 'selector_hover'=>'.title%1$s .wdk-icon',
511 'options'=>['margin','color','background','border','border_radius','padding','shadow','image_size_control','image_fit_control'],
512 ],
513 [
514 'key'=>'category_image',
515 'label'=> esc_html__('Category Image', 'wpdirectorykit'),
516 'selector'=>'.title .wdk-image',
517 'selector_hover'=>'.title%1$s .wdk-image',
518 'options'=>['margin','background','border','border_radius','padding','shadow','transition','image_size_control', 'css_filters','image_fit_control'],
519 ],
520 [
521 'key'=>'category_font_icon',
522 'label'=> esc_html__('Category Font Icon', 'wpdirectorykit'),
523 'selector'=>'.title .wdk-font-icon',
524 'selector_hover'=>'.title%1$s .wdk-font-icon',
525 'options'=>['margin','background','border','border_radius','shadow','color','font-size','height','width'],
526 ],
527 [
528 'key'=>'item_icon',
529 'label'=> esc_html__('Sub Category List Item Icon', 'wpdirectorykit'),
530 'selector'=>'.wdk-categories .wdk-link i',
531 'selector_hover'=>'.wdk-categories .wdk-link%1$s i',
532 'options'=>['margin','color','background','border','border_radius','padding','shadow'],
533 ],
534 [
535 'key'=>'item_title',
536 'label'=> esc_html__('Sub Category List Item Title', 'wpdirectorykit'),
537 'selector'=>'.wdk-categories .wdk-link .wdk-title',
538 'selector_hover'=>'.wdk-categories .wdk-link%1$s .wdk-title',
539 'options'=>['margin','typo','color','background','border','border_radius','padding'],
540 ],
541 [
542 'key'=>'item_count',
543 'label'=> esc_html__('Sub Category List Item Count', 'wpdirectorykit'),
544 'selector'=>'.wdk-categories .wdk-link .wdk-count',
545 'selector_hover'=>'.wdk-categories .wdk-link%1$s .wdk-count',
546 'options'=>['margin','typo','color','background','border','border_radius','padding'],
547 ],
548 [
549 'key'=>'btn_more',
550 'label'=> esc_html__('Btn More', 'wpdirectorykit'),
551 'selector'=>'.wdk-categories-tree .btn-more',
552 'selector_hover'=>'.wdk-categories-tree .btn-more%1$s',
553 'options'=>['margin','typo','color','background','border','border_radius','padding'],
554 ],
555 ];
556
557 foreach ($items as $item) {
558 if($item['key'] == 'category_icon') {
559 $this->start_controls_section(
560 $item['key'].'_section',
561 [
562 'label' => $item['label'],
563 'tab' => Controls_Manager::TAB_STYLE,
564 'conditions' => [
565 'terms' => [
566 [
567 'name' => 'show_icon',
568 'operator' => '==',
569 'value' => 'yes',
570 ],
571 [
572 'name' => 'layout_image_type',
573 'operator' => '==',
574 'value' => 'icon',
575 ]
576 ],
577 ],
578 ]
579 );
580 } elseif($item['key'] == 'category_image') {
581 $this->start_controls_section(
582 $item['key'].'_section',
583 [
584 'label' => $item['label'],
585 'tab' => Controls_Manager::TAB_STYLE,
586 'conditions' => [
587 'terms' => [
588 [
589 'name' => 'show_icon',
590 'operator' => '==',
591 'value' => 'yes',
592 ],
593 [
594 'name' => 'layout_image_type',
595 'operator' => '==',
596 'value' => 'image',
597 ]
598 ],
599 ],
600 ]
601 );
602 } elseif($item['key'] == 'category_font_icon') {
603 $this->start_controls_section(
604 $item['key'].'_section',
605 [
606 'label' => $item['label'],
607 'tab' => Controls_Manager::TAB_STYLE,
608 'conditions' => [
609 'terms' => [
610 [
611 'name' => 'show_icon',
612 'operator' => '==',
613 'value' => 'yes',
614 ],
615 [
616 'name' => 'layout_image_type',
617 'operator' => '==',
618 'value' => 'font_icon',
619 ]
620 ],
621 ],
622 ]
623 );
624 } else {
625 $this->start_controls_section(
626 $item['key'].'_section',
627 [
628 'label' => $item['label'],
629 'tab' => Controls_Manager::TAB_STYLE,
630 ]
631 );
632 }
633
634
635 if(empty($item['selector_hide'])) {
636 $item['selector_hide'] = $item['selector'];
637 }
638
639 $this->add_responsive_control(
640 $item['key'].'_hide',
641 [
642 'label' => esc_html__( 'Hide Element', 'wpdirectorykit' ),
643 'type' => Controls_Manager::SWITCHER,
644 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
645 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
646 'return_value' => 'none',
647 'default' => '',
648 'selectors' => [
649 '{{WRAPPER}} '.$item['selector_hide'] => 'display: {{VALUE}};',
650 ],
651 ]
652 );
653 $selectors = array(
654 'normal' => '{{WRAPPER}} '.$item['selector'],
655 'hover'=>'{{WRAPPER}} '.$item['selector_hover'],
656 );
657 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
658
659 /* special for some elements */
660 if($item['key'] == 'item_icon') {
661 $this->add_control(
662 $item['key'].'_i',
663 [
664 'label' => esc_html__('Icon', 'wpdirectorykit'),
665 'type' => Controls_Manager::ICONS,
666 'label_block' => true,
667 'default' => [
668 'value' => 'fa fa-angle-right',
669 'library' => 'solid',
670 ],
671 ]
672 );
673 $this->add_responsive_control(
674 $item['key'].'_size',
675 [
676 'label' => __( 'Size', 'wpdirectorykit' ),
677 'type' => Controls_Manager::SLIDER,
678 'size_units' => [ 'px','em', 'vw', '%', 'custom' ],
679 'range' => [
680 'px' => [
681 'min' => 1,
682 'max' => 60,
683 'step' => 1,
684 ],
685 ],
686 'default' => [
687 'unit' => 'px',
688 'size' => 14,
689 ],
690 'selectors' => [
691 '{{WRAPPER}} '.$item['selector'] => 'font-size: {{SIZE}}{{UNIT}};',
692 ],
693 ]
694 );
695 }
696 if($item['key'] == 'item_count') {
697 $this->add_responsive_control(
698 $item['key'].'_align',
699 [
700 'label' => __( 'Position', 'wpdirectorykit' ),
701 'type' => Controls_Manager::CHOOSE,
702 'options' => [
703 'left' => [
704 'title' => esc_html__( 'Left', 'wpdirectorykit' ),
705 'icon' => 'eicon-text-align-left',
706 ],
707 'center' => [
708 'title' => esc_html__( 'Center', 'wpdirectorykit' ),
709 'icon' => 'eicon-text-align-center',
710 ],
711 'right' => [
712 'title' => esc_html__( 'Right', 'wpdirectorykit' ),
713 'icon' => 'eicon-text-align-right',
714 ],
715
716 ],
717 'render_type' => 'ui',
718 'selectors_dictionary' => [
719 'left' => 'text-align: left;',
720 'center' => 'text-alig: center;',
721 'right' => 'text-align: right;',
722 ],
723 'selectors' => [
724 '{{WRAPPER}} '.$item['selector'] => '{{VALUE}};',
725 ],
726 ]
727 );
728 }
729
730 $this->end_controls_section();
731 }
732 }
733
734 private function generate_controls_content() {
735
736 }
737
738 public function enqueue_styles_scripts() {
739 wp_enqueue_style('wdk-categories-tree');
740 }
741 }
742