PluginProbe
WP Directory Kit / 1.1.8
WP Directory Kit v1.1.8
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.1.8, at elementor-elements/classes/wdk-listings-list.php

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