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-listings-list.php

wdk-listings-list.php in WP Directory Kit 1.5.9, at elementor-elements/classes/wdk-listings-list.php

730 lines 27.2 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 WdkListingsList 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
46 if ($this->is_edit_mode_load()) {
47 $this->enqueue_styles_scripts();
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-listings-list';
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 Listings List', '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-section';
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('tab_conf');
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 $this->data['listings_count'] = 0;
125 $this->data['results'] = array();
126 $this->data['pagination_output'] = '';
127
128 $columns = array('ID', 'location_id', 'category_id', 'post_title', 'post_date', 'search', 'order_by','is_featured', 'address');
129 $external_columns = array('location_id', 'category_id', 'post_title');
130 $custom_parameters = array();
131
132 $this->data['custom_order'] = array();
133 if($this->data['settings']['custom_order_list']) {
134 foreach($this->data['settings']['custom_order_list'] as $item){
135 if(empty($item['title']) || empty($item['key'])) continue;
136 $this->data['custom_order'][] = array('title'=>$item['title'],'key'=>$item['key']);
137 }
138 }
139
140 if($this->data['settings']['conf_results_type'] == 'results_listings') {
141 $controller = 'listing';
142 $offset = NULL;
143
144 $custom_parameters['order_by'] = $this->data['settings']['conf_order_by'].' '.$this->data['settings']['conf_order'];
145
146 /* if detected custom field for order */
147 if(!empty($this->data['settings']['conf_order_by_custom'])) {
148 $custom_parameters['order_by'] = $this->data['settings']['conf_order_by_custom'].' '.$this->data['settings']['conf_order'];
149 }
150
151 if(!empty($this->data['settings']['conf_query'])) {
152 $qr_string = trim($this->data['settings']['conf_query'],'?');
153 $string_par = array();
154 parse_str($qr_string, $string_par);
155 $custom_parameters += array_map('trim', $string_par);
156 }
157 if($this->data['settings']['only_is_featured'] == 'yes') {
158 $custom_parameters['is_featured'] = 'on';
159 }
160
161 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns, $custom_parameters, TRUE);
162 $this->data['results'] = $this->WMVC->listing_m->get_pagination($this->data['settings']['per_page'], $offset, array('is_activated' => 1,'is_approved'=>1));
163 } else if($this->data['settings']['conf_results_type'] == 'custom_listings') {
164 $listings_ids = array();
165 foreach($this->data['settings']['conf_custom_results'] as $listing) {
166 if(isset($listing['listing_post_id']) && !empty($listing['listing_post_id'])) {
167 $listings_ids [] = $listing['listing_post_id'];
168 }
169 }
170 /* where in */
171 if(!empty($listings_ids)){
172 $this->WMVC->db->where( $this->WMVC->db->prefix.'wdk_listings.post_id IN(' . implode(',', $listings_ids) . ')', null, false);
173 $this->WMVC->db->where(array('is_activated' => 1));
174 $this->WMVC->db->order_by('FIELD('.$this->WMVC->db->prefix.'wdk_listings.post_id, '. implode(',', $listings_ids) . ')');
175
176 $this->data['results'] = $this->WMVC->listing_m->get();
177 }
178
179 /* hide filter header on specific results */
180 $this->data['settings']['get_filters_enable'] = '';
181 }
182
183 $this->data['is_edit_mode'] = false;
184 if(Plugin::$instance->editor->is_edit_mode())
185 $this->data['is_edit_mode'] = true;
186
187 $this->view('wdk-listings-list', $this->data, true);
188
189 }
190
191
192 private function generate_controls_conf() {
193 $this->start_controls_section(
194 'tab_conf_main_section',
195 [
196 'label' => esc_html__('Main', 'wpdirectorykit'),
197 'tab' => 'tab_conf',
198 ]
199 );
200
201 $this->add_control(
202 'conf_results_type',
203 [
204 'label' => __( 'Results type', 'wpdirectorykit' ),
205 'type' => \Elementor\Controls_Manager::SELECT,
206 'default' => 'results_listings',
207 'options' => [
208 'results_listings' => __( 'Results Listings', 'wpdirectorykit' ),
209 'custom_listings' => __( 'Specific Listings', 'wpdirectorykit' ),
210 ],
211 'separator' => 'after',
212 ]
213 );
214
215 /* conf_results_type :: results_listings */
216 if(true){
217 $this->add_control(
218 'conf_results_type_results_listings_header',
219 [
220 'label' => esc_html__('Results listings', 'wpdirectorykit'),
221 'type' => Controls_Manager::HEADING,
222 'separator' => 'before',
223 'conditions' => [
224 'terms' => [
225 [
226 'name' => 'conf_results_type',
227 'operator' => '==',
228 'value' => 'results_listings',
229 ]
230 ],
231 ],
232 ]
233 );
234
235 $this->add_control(
236 'per_page',
237 [
238 'label' => __( 'Limit Results (Per page)', 'wpdirectorykit' ),
239 'type' => \Elementor\Controls_Manager::NUMBER,
240 'min' => 1,
241 'max' => 250,
242 'step' => 1,
243 'default' => 3,
244 'conditions' => [
245 'terms' => [
246 [
247 'name' => 'conf_results_type',
248 'operator' => '==',
249 'value' => 'results_listings',
250 ]
251 ],
252 ],
253 ]
254 );
255
256 $this->add_control(
257 'only_is_featured',
258 [
259 'label' => __( 'Only show featured', 'wpdirectorykit' ),
260 'type' => \Elementor\Controls_Manager::SWITCHER,
261 'label_on' => __( 'True', 'wpdirectorykit' ),
262 'label_off' => __( 'False', 'wpdirectorykit' ),
263 'return_value' => 'yes',
264 'default' => '',
265 'conditions' => [
266 'terms' => [
267 [
268 'name' => 'conf_results_type',
269 'operator' => '==',
270 'value' => 'results_listings',
271 ]
272 ],
273 ],
274 ]
275 );
276
277 $this->add_control(
278 'conf_query',
279 [
280 'label' => __( 'Query', 'wpdirectorykit' ),
281 'type' => \Elementor\Controls_Manager::TEXTAREA,
282 'rows' => 5,
283 'default' => '',
284 'placeholder' => __( 'Type your query here, example xxx', 'wpdirectorykit' ),
285 'description' => '<span style="word-break: break-all;">'.__( 'Example (same like on url):', 'wpdirectorykit' ).
286 ' field_6_min=100&field_6_max=200&field_5=rent&is_featured=on&search_category=3&search_location=4&search_agents_ids=3'.
287 '</span>',
288 'conditions' => [
289 'terms' => [
290 [
291 'name' => 'conf_results_type',
292 'operator' => '==',
293 'value' => 'results_listings',
294 ]
295 ],
296 ],
297 ]
298 );
299
300 $this->add_control(
301 'conf_order_by',
302 [
303 'label' => __('Default Sort By Column', 'wpdirectorykit'),
304 'type' => Controls_Manager::SELECT,
305 'label_block' => true,
306 'options' => [
307 'none' => __('None', 'wpdirectorykit'),
308 'post_id' => __('ID', 'wpdirectorykit'),
309 'post_title' => __('Title', 'wpdirectorykit'),
310 ],
311 'default' => 'post_id',
312 'conditions' => [
313 'terms' => [
314 [
315 'name' => 'conf_results_type',
316 'operator' => '==',
317 'value' => 'results_listings',
318 ]
319 ],
320 ],
321 ]
322 );
323
324 $this->add_control(
325 'conf_order_by_custom',
326 [
327 'label' => __('Default Custom Sort By (Column)', 'wpdirectorykit'),
328 'description' => '<span style="word-break: break-all;">'.__( 'Example:', 'wpdirectorykit' ).
329 '<br> field_13_NUMBER - where 13 is field id, NUMBER - field type'.
330 '<br> field_4_NUMBER - where 4 is field id, NUMBER - field type'.
331 '<br> field_6_DROPDOWN - where 6 is field id, DROPDOWN - field type'.
332 '<br> category_title - Category Title'.
333 '<br> location_title - Location Title'.
334 '</span>',
335 'type' => Controls_Manager::TEXT,
336 'label_block' => true,
337 'default' => 'post_id',
338 'conditions' => [
339 'terms' => [
340 [
341 'name' => 'conf_results_type',
342 'operator' => '==',
343 'value' => 'results_listings',
344 ]
345 ],
346 ],
347 ]
348 );
349
350 $this->add_control(
351 'conf_order',
352 [
353 'label' => __('Default Listing Order', 'wpdirectorykit'),
354 'type' => Controls_Manager::SELECT,
355 'label_block' => true,
356 'options' => [
357 'asc' => __('Ascending', 'wpdirectorykit'),
358 'desc' => __('Descending', 'wpdirectorykit')
359 ],
360 'default' => 'desc',
361 'conditions' => [
362 'terms' => [
363 [
364 'name' => 'conf_results_type',
365 'operator' => '==',
366 'value' => 'results_listings',
367 ]
368 ],
369 ],
370 ]
371 );
372
373
374 }
375
376 if(true) {
377 $this->add_control(
378 'conf_results_type_custom_listings_header',
379 [
380 'label' => esc_html__('Custom listings', 'wpdirectorykit'),
381 'type' => Controls_Manager::HEADING,
382 'separator' => 'before',
383 'conditions' => [
384 'terms' => [
385 [
386 'name' => 'conf_results_type',
387 'operator' => '==',
388 'value' => 'custom_listings',
389 ]
390 ],
391 ],
392 ]
393 );
394
395
396 if(true){
397 $repeater = new Repeater();
398 $repeater->start_controls_tabs( 'listings' );
399 $repeater->add_control(
400 'listing_post_id',
401 [
402 'label' => __( 'ID Post Listing', 'wpdirectorykit' ),
403 'type' => \Elementor\Controls_Manager::NUMBER,
404 'min' => 1,
405 'step' => 1,
406 ]
407 );
408 $repeater->end_controls_tabs();
409
410
411 $this->add_control(
412 'conf_custom_results',
413 [
414 'type' => Controls_Manager::REPEATER,
415 'fields' => $repeater->get_controls(),
416 'default' => [
417 ],
418 'title_field' => '{{{ listing_post_id }}}',
419 'conditions' => [
420 'terms' => [
421 [
422 'name' => 'conf_results_type',
423 'operator' => '==',
424 'value' => 'custom_listings',
425 ]
426 ],
427 ],
428 ]
429 );
430
431 }
432 }
433
434 $this->add_control(
435 'important_note',
436 [
437 'label' => '',
438 'type' => \Elementor\Controls_Manager::RAW_HTML,
439 /* translators: 1: URL. */
440 'raw' => wdk_sprintf(__( 'Edit Result Card Designer <a href="%1$s" target="_blank"> open </a>', 'wpdirectorykit' ), admin_url('admin.php?page=wdk_resultitem')),
441 'content_classes' => 'wdk_elementor_hint',
442 ]
443 );
444
445
446 $this->end_controls_section();
447
448 $this->start_controls_section(
449 'tab_conf_main_section_order',
450 [
451 'label' => esc_html__('Custom Sort', 'wpdirectorykit'),
452 'tab' => 'tab_conf',
453 ]
454 );
455
456 $repeater_order = new Repeater();
457 $repeater_order->start_controls_tabs( 'orders' );
458 $repeater_order->add_control(
459 'key',
460 [
461 'label' => __( 'Sort Key', 'wpdirectorykit' ),
462 'type' => \Elementor\Controls_Manager::TEXT,
463 'placeholder' => 'post_id ASC',
464 'description' => '<span style="word-break: break-all;">'.__( 'Custom Fields Order Example:', 'wpdirectorykit' ).
465 '<br> field_13_NUMBER ASC - where 13 is field id, NUMBER - field type'.
466 '<br> field_4_NUMBER DESC - where 4 is field id, NUMBER - field type'.
467 '<br> field_6_DROPDOWN ASC - where 6 is field id, DROPDOWN - field type'.
468 '<br> category_title - Category Title'.
469 '<br> location_title - Location Title'.
470 '</span>',
471 ]
472 );
473 $repeater_order->add_control(
474 'title',
475 [
476 'label' => __( 'Title', 'wpdirectorykit' ),
477 'type' => \Elementor\Controls_Manager::TEXT,
478 'placeholder' => __( 'Title', 'wpdirectorykit' ),
479 ]
480 );
481 $repeater_order->end_controls_tabs();
482
483 $this->add_control(
484 'custom_order_list',
485 [
486 'type' => Controls_Manager::REPEATER,
487 'fields' => $repeater_order->get_controls(),
488 'default' => [
489 ],
490 'title_field' => '{{{ title }}}',
491 ]
492 );
493
494 $this->end_controls_section();
495
496 }
497
498 private function generate_controls_layout() {
499 $this->start_controls_section(
500 'tab_content',
501 [
502 'label' => esc_html__('Basic', 'wpdirectorykit'),
503 'tab' => 'tab_layout',
504 ]
505 );
506 $this->add_responsive_control(
507 'row_gap',
508 [
509 'label' => esc_html__('Rows Gap', 'wpdirectorykit'),
510 'type' => Controls_Manager::SLIDER,
511 'default' => [
512 'size' => 27,
513 ],
514 'range' => [
515 'px' => [
516 'min' => 0,
517 'max' => 60,
518 ],
519 ],
520 'selectors' => [
521 '{{WRAPPER}} .wdk-row .wdk-col' => 'margin-bottom: {{SIZE}}{{UNIT}};',
522 '{{WRAPPER}} .wdk-row' => 'margin-bottom: -{{SIZE}}{{UNIT}};',
523 ],
524 ]
525 );
526
527 $this->add_responsive_control(
528 'thumbnail_width',
529 [
530 'label' => esc_html__('Thumbnail width', 'wpdirectorykit'),
531 'type' => Controls_Manager::SLIDER,
532 'size_units' => [ 'px', '%' ],
533 'range' => [
534 'px' => [
535 'min' => 0,
536 'max' => 600,
537 ],
538 '%' => [
539 'min' => 0,
540 'max' => 100,
541 ],
542 ],
543 'selectors' => [
544 '{{WRAPPER}} .wdk-listings-list .listing-item .listing-img-sec' => 'flex: 0 0 {{SIZE}}{{UNIT}};',
545 ],
546 ]
547 );
548
549
550 $this->end_controls_section();
551
552 }
553
554 private function generate_controls_styles() {
555 $this->start_controls_section(
556 'sstyles_thmbn_section',
557 [
558 'label' => esc_html__('Section Image', 'wpdirectorykit'),
559 'tab' => Controls_Manager::TAB_STYLE,
560 ]
561 );
562
563 $this->add_responsive_control(
564 'styles_thmbn_des_type',
565 [
566 'label' => __( 'Design type', 'wpdirectorykit' ),
567 'type' => \Elementor\Controls_Manager::SELECT,
568 'default' => 'wdk_size_image_cover',
569 'options' => [
570 'container' => __( 'Default Sizes', 'wpdirectorykit' ),
571 'cover' => __( 'Image auto crop/resize', 'wpdirectorykit' ),
572 ],
573 'selectors_dictionary' => [
574 'container' => 'object-fit: contain;',
575 'cover' => 'object-fit: cover;',
576 ],
577 'default' => 'cover',
578 'selectors' => [
579 '{{WRAPPER}} .wdk-listings-list .listing-item .listing-img-sec img' => '{{UNIT}}',
580 ],
581 ]
582 );
583
584 $this->add_responsive_control(
585 'styles_thmbn_des_height',
586 [
587 'label' => esc_html__('Height', 'wpdirectorykit'),
588 'type' => Controls_Manager::SLIDER,
589 'range' => [
590 'px' => [
591 'min' => 15,
592 'max' => 350,
593 ],
594 ],
595 'size_units' => [ 'px' ],
596 'selectors' => [
597 '{{WRAPPER}} .wdk-listings-list .listing-item .listing-img-sec img' => 'height: {{SIZE}}{{UNIT}}',
598 ],
599 'separator' => 'after',
600 ]
601 );
602 $this->end_controls_section();
603
604 }
605
606 private function generate_controls_content() {
607 $this->start_controls_section(
608 'content_thumbnail_section',
609 [
610 'label' => esc_html__('Colors', 'wpdirectorykit'),
611 'tab' => '1',
612 ]
613 );
614
615 $this->add_control(
616 'content_thumbnail_section_header',
617 [
618 'label' => esc_html__('Color Hover Thumbnail', 'wpdirectorykit'),
619 'type' => Controls_Manager::HEADING,
620 ]
621 );
622
623 $this->add_responsive_control(
624 'content_thumbnail_section_d_background',
625 [
626 'label' => esc_html__( 'Color', 'wpdirectorykit' ),
627 'description' => esc_html__( 'Set some opacity for color', 'wpdirectorykit' ),
628 'type' => Controls_Manager::COLOR,
629 'selectors' => [
630 '{{WRAPPER}} .wdk-listing-card .wdk-thumbnail::before, {{WRAPPER}} .wdk-listing-card .wdk-thumbnail::after,{{WRAPPER}} .wdk-listing-card .overlay' => 'background-color: {{VALUE}};',
631 ],
632 ]
633 );
634
635 $this->add_control(
636 'content_thumbnail_section_header_f',
637 [
638 'label' => esc_html__('Shadow around Card, for Featured Listings', 'wpdirectorykit'),
639 'type' => Controls_Manager::HEADING,
640 ]
641 );
642
643 $this->add_group_control(
644 Group_Control_Box_Shadow::get_type(),
645 [
646 'name' => 'content_thumbnail_section_d_featured',
647 'exclude' => [
648 'field_shadow_position',
649 ],
650 'selector' => '{{WRAPPER}} .wdk-listing-card.is_featured',
651 ]
652 );
653
654 $this->end_controls_section();
655
656
657 $items = [
658 [
659 'key'=>'item_box',
660 'label'=> esc_html__('Item', 'wpdirectorykit'),
661 'selector'=>'.wdk-element .wdk-listing-card',
662 'options'=>'block',
663 ],
664 [
665 'key'=>'item_image_box',
666 'label'=> esc_html__('Image Box', 'wpdirectorykit'),
667 'selector'=>'.wdk-listings-list .listing-item .listing-img-sec img',
668 'options'=>'block',
669 ],
670 [
671 'key'=>'item_info_box',
672 'label'=> esc_html__('Text Box', 'wpdirectorykit'),
673 'selector'=>'.wdk-listings-list .listing-item .listing-inf-sec',
674 'options'=>'block',
675 ],
676 [
677 'key'=>'item_title',
678 'label'=> esc_html__('Title', 'wpdirectorykit'),
679 'selector'=>'.wdk-listings-list .listing-item .listing-inf-sec .title',
680 'options'=>'full',
681 ],
682 [
683 'key'=>'item_price',
684 'label'=> esc_html__('Price', 'wpdirectorykit'),
685 'selector'=>'.wdk-listings-list .listing-item .listing-inf-sec .price',
686 'options'=>'full',
687 ],
688 ];
689
690 foreach ($items as $item) {
691 $this->start_controls_section(
692 $item['key'].'_section',
693 [
694 'label' => $item['label'],
695 'tab' => '1',
696 ]
697 );
698 $this->add_responsive_control(
699 $item['key'].'_hide',
700 [
701 'label' => esc_html__( 'Hide Element', 'wpdirectorykit' ),
702 'type' => Controls_Manager::SWITCHER,
703 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
704 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
705 'return_value' => 'none',
706 'default' => '',
707 'selectors' => [
708 '{{WRAPPER}} '.$item['selector'] => 'display: {{VALUE}};',
709 ],
710 ]
711 );
712 $selectors = array(
713 'normal' => '{{WRAPPER}} '.$item['selector'],
714 'hover'=>'{{WRAPPER}} '.$item['selector'].'%1$s'
715 );
716
717 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
718
719 $this->end_controls_section();
720 }
721
722 }
723
724 public function enqueue_styles_scripts() {
725 wp_enqueue_style('wdk-listings-list');
726 wp_enqueue_style('wdk-notify');
727 wp_enqueue_script('wdk-notify');
728 }
729 }
730