PluginProbe
WP Directory Kit / 1.2.6
WP Directory Kit v1.2.6
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.2.6, at elementor-elements/classes/wdk-categories-tree.php

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