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

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

655 lines 24.3 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 WdkLocationsList 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-locations-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 Location 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-bullet-list';
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 = 'location';
125 $this->WMVC->model($controller.'_m');
126 $this->WMVC->model('listing_m');
127
128 $this->data['results'] = false;
129
130 if($this->data['settings']['conf_results_type'] == 'custom_locations') {
131
132 $locations_ids = array();
133 foreach($this->data['settings']['conf_custom_results'] as $location) {
134 if(isset($location['location_id']) && !empty($location['location_id'])) {
135 $locations_ids [] = (int)$location['location_id'];
136 }
137 }
138
139 /* where in */
140 if(!empty($locations_ids)){
141
142 $this->WMVC->db->select($this->WMVC->{$controller.'_m'}->_table_name.'.*, COUNT('.$this->WMVC->listing_m->_table_name.'.post_id) AS listings_counter');
143 $this->WMVC->db->join($this->WMVC->listing_m->_table_name.' ON '.$this->WMVC->listing_m->_table_name.'.location_id = '.$this->WMVC->{$controller.'_m'}->_table_name.'.idlocation', TRUE, 'LEFT');
144 $this->WMVC->db->where($this->WMVC->{$controller.'_m'}->_table_name.'.idlocation IN(' . implode(',', $locations_ids) . ')', null, false);
145 $this->WMVC->db->order_by('FIELD('.$this->WMVC->{$controller.'_m'}->_table_name.'.idlocation, '. implode(',', $locations_ids) . ')');
146 $this->WMVC->db->group_by($this->WMVC->{$controller.'_m'}->_primary_key);
147
148 $this->data['results'] = $this->WMVC->{$controller.'_m'}->get();
149 }
150
151 } else {
152 $order_by = NULL;
153 if(!empty($this->data['settings']['conf_order_by']))
154 $order_by = wdk_esc_sql_order_by($this->data['settings']['conf_order_by'].' '.$this->data['settings']['conf_order'], $this->WMVC->{$controller.'_m'}->getAllowedOrderBy());
155
156 $where = array();
157 if (!empty($this->data['settings']['only_root_enable']) && $this->data['settings']['only_root_enable'] == 'yes') {
158 $where['('.$this->WMVC->{$controller.'_m'}->_table_name.'.level = 0)'] = NULL;
159 }
160
161 static $results = array();
162 $key = $order_by.http_build_query($where).$this->data['settings']['conf_limit'];
163
164 if(!isset($results[$key])) {
165 $this->data['results'] = $results[$key] = $this->WMVC->{$controller.'_m'}->get_pagination((!empty($this->data['settings']['conf_limit'])) ? $this->data['settings']['conf_limit'] : NULL, NULL, $where, $order_by);
166 } else {
167 $this->data['results'] = $results[$key];
168 }
169
170 if(wmvc_show_data('conf_query_params', $this->data['settings'], false) && !empty($this->data['settings']['conf_query_params'])) {
171 $custom_parameters = array();
172 $qr_string = trim($this->data['settings']['conf_query_params'],'?');
173 $string_par = array();
174 parse_str($qr_string, $string_par);
175 $custom_parameters += array_map('trim', $string_par);
176
177 $columns = array('ID', 'location_id', 'category_id', 'post_title', 'post_date', 'search', 'order_by','is_featured', 'address');
178 $external_columns = array('location_id', 'category_id', 'post_title');
179
180 foreach ($this->data['results'] as $key => $item) {
181 $custom_parameters['search_location'] = wmvc_show_data('idlocation', $item, false);
182 wdk_prepare_search_query_GET($columns, $controller.'_m', $external_columns, $custom_parameters, TRUE);
183 $this->data['results'][$key]->listings_counter = $this->WMVC->listing_m->total(array('is_activated' => 1,'is_approved'=>1));
184 }
185
186 }
187 }
188
189 $this->data['is_edit_mode']= false;
190 if(Plugin::$instance->editor->is_edit_mode())
191 $this->data['is_edit_mode']= true;
192
193 $this->view('wdk-locations-list', $this->data, true);
194 }
195
196
197 private function generate_controls_conf() {
198 $this->start_controls_section(
199 'tab_conf_main_section',
200 [
201 'label' => esc_html__('Main', 'wpdirectorykit'),
202 'tab' => '1',
203 ]
204 );
205
206 $this->add_control(
207 'enable_search_sensitive',
208 [
209 'label' => __( 'Enable Search Sensitive', 'wpdirectorykit' ),
210 'type' => \Elementor\Controls_Manager::SWITCHER,
211 'label_on' => __( 'On', 'wpdirectorykit' ),
212 'label_off' => __( 'Off', 'wpdirectorykit' ),
213 'return_value' => 'true',
214 'default' => '',
215 'separator' => 'after',
216 ]
217 );
218
219 $pages = array('' => __('Not Selected', 'wpdirectorykit'));
220 foreach(get_pages(array('sort_column' => 'post_title')) as $page)
221 {
222 $pages[$page->ID] = $page->post_title.' #'.$page->ID;
223 }
224
225 $this->add_control(
226 'conf_link',
227 [
228 'label' => __( 'Open results on page', 'wpdirectorykit' ),
229 'type' => \Elementor\Controls_Manager::SELECT2,
230 'default' => '',
231 'options' => $pages
232 ]
233 );
234
235 $this->add_control(
236 'conf_results_type',
237 [
238 'label' => __( 'Show type', 'wpdirectorykit' ),
239 'type' => \Elementor\Controls_Manager::SELECT,
240 'default' => 'results_locations',
241 'options' => [
242 'results_locations' => __( 'All Locations', 'wpdirectorykit' ),
243 'custom_locations' => __( 'Specific', 'wpdirectorykit' ),
244 ],
245 ]
246 );
247
248 $this->add_control(
249 'conf_query_params',
250 [
251 'label' => __( 'Query params', 'wpdirectorykit' ),
252 'description' => __( 'Put addition query params for locations (counting required memory)', 'wpdirectorykit' ),
253 'type' => \Elementor\Controls_Manager::TEXTAREA,
254 'default' => '',
255 'conditions' => [
256 'terms' => [
257 [
258 'name' => 'conf_results_type',
259 'operator' => '==',
260 'value' => 'results_locations',
261 ]
262 ],
263 ],
264 ]
265 );
266
267 $this->add_control(
268 'suffix',
269 [
270 'label' => __( 'Title Suffix', 'wpdirectorykit' ),
271 'type' => \Elementor\Controls_Manager::TEXT,
272 'default' => '',
273 ]
274 );
275
276 $this->add_control(
277 'prefix',
278 [
279 'label' => __( 'Title Prefix', 'wpdirectorykit' ),
280 'type' => \Elementor\Controls_Manager::TEXT,
281 'default' => '',
282 ]
283 );
284
285 $this->add_control(
286 'show_icon',
287 [
288 'label' => __( 'Enable Location Icons', 'wpdirectorykit' ),
289 'type' => \Elementor\Controls_Manager::SWITCHER,
290 'label_on' => __( 'On', 'wpdirectorykit' ),
291 'label_off' => __( 'Off', 'wpdirectorykit' ),
292 'return_value' => 'true',
293 'default' => '',
294 'separator' => 'after',
295 ]
296 );
297
298 $this->add_control(
299 'important_note',
300 [
301 'label' => '',
302 'type' => \Elementor\Controls_Manager::RAW_HTML,
303 /* translators: 1: URL. */
304 'raw' => wdk_sprintf(__( 'Edit Locations <a href="%1$s" target="_blank"> open </a>', 'wpdirectorykit' ), admin_url('admin.php?page=wdk_location')),
305 'content_classes' => 'wdk_elementor_hint',
306 ]
307 );
308
309 $this->add_responsive_control(
310 'only_root_enable',
311 [
312 'label' => esc_html__( 'Show only Root', 'wpdirectorykit' ),
313 'type' => Controls_Manager::SWITCHER,
314 'none' => esc_html__( 'No', 'wpdirectorykit' ),
315 'block' => esc_html__( 'Yes', 'wpdirectorykit' ),
316 'return_value' => 'yes',
317 'default' => 'yes',
318 ]
319 );
320 $this->add_control(
321 'conf_limit',
322 [
323 'label' => __( 'Limit Locations', 'wpdirectorykit' ),
324 'description' => __( 'Set 0 for unlimit', 'wpdirectorykit' ),
325 'type' => \Elementor\Controls_Manager::NUMBER,
326 'min' => 0,
327 'max' => 500,
328 'step' => 1,
329 'default' => 6,
330 'separator' => 'before',
331 'conditions' => [
332 'terms' => [
333 [
334 'name' => 'conf_results_type',
335 'operator' => '==',
336 'value' => 'results_locations',
337 ]
338 ],
339 ],
340 ]
341 );
342
343 $this->add_control(
344 'conf_order_by',
345 [
346 'label' => __('Order By Column', 'wpdirectorykit'),
347 'type' => Controls_Manager::SELECT,
348 'label_block' => true,
349 'options' => [
350 '' => __('None', 'wpdirectorykit'),
351 'location_title' => __('Title', 'wpdirectorykit'),
352 'idlocation' => __('Location id', 'wpdirectorykit'),
353 'order_index' => __('Order index', 'wpdirectorykit'),
354 'listings_counter' => __('Most Listings', 'wpdirectorykit'),
355 ],
356 'default' => 'order_index',
357 'conditions' => [
358 'terms' => [
359 [
360 'name' => 'conf_results_type',
361 'operator' => '==',
362 'value' => 'results_locations',
363 ]
364 ],
365 ],
366 ]
367 );
368
369 $this->add_control(
370 'conf_order',
371 [
372 'label' => __('Order', 'wpdirectorykit'),
373 'type' => Controls_Manager::SELECT,
374 'label_block' => true,
375 'options' => [
376 'asc' => __('Ascending', 'wpdirectorykit'),
377 'desc' => __('Descending', 'wpdirectorykit')
378 ],
379 'default' => 'desc',
380 'conditions' => [
381 'terms' => [
382 [
383 'name' => 'conf_results_type',
384 'operator' => '==',
385 'value' => 'results_locations',
386 ]
387 ],
388 ],
389 ]
390 );
391
392 if(true){
393 $repeater = new Repeater();
394 $repeater->start_controls_tabs( 'locations' );
395 $repeater->add_control(
396 'location_id',
397 [
398 'label' => __( 'ID Location', 'wpdirectorykit' ),
399 'type' => \Elementor\Controls_Manager::NUMBER,
400 'min' => 1,
401 'step' => 1,
402 ]
403 );
404 $repeater->end_controls_tabs();
405
406
407 $this->add_control(
408 'conf_custom_results',
409 [
410 'type' => Controls_Manager::REPEATER,
411 'fields' => $repeater->get_controls(),
412 'default' => [
413 ],
414 'title_field' => '{{{ location_id }}}',
415 'conditions' => [
416 'terms' => [
417 [
418 'name' => 'conf_results_type',
419 'operator' => '==',
420 'value' => 'custom_locations',
421 ]
422 ],
423 ],
424 ]
425 );
426
427 }
428
429 $this->end_controls_section();
430
431 }
432
433 private function generate_controls_layout() {
434 }
435
436 private function generate_controls_styles() {
437 $this->start_controls_section(
438 'sstyles_thmbn_section',
439 [
440 'label' => esc_html__('Main', 'wpdirectorykit'),
441 'tab' => Controls_Manager::TAB_STYLE,
442 ]
443 );
444
445 $this->add_responsive_control(
446 'row_gap',
447 [
448 'label' => esc_html__('Rows Gap', 'wpdirectorykit'),
449 'type' => Controls_Manager::SLIDER,
450 'default' => [
451 'size' => 10,
452 ],
453 'range' => [
454 'px' => [
455 'min' => 0,
456 'max' => 60,
457 ],
458 ],
459 'selectors' => [
460 '{{WRAPPER}} .wdk-locations .wdk-item' => 'margin-bottom: {{SIZE}}{{UNIT}};',
461 ],
462 ]
463 );
464
465 $this->end_controls_section();
466
467 $items = [
468 [
469 'key'=>'item_button',
470 'label'=> esc_html__('Item Box', 'wpdirectorykit'),
471 'selector'=>'.wdk-locations .wdk-link',
472 'selector_hover'=>'.wdk-locations .wdk-link%1$s',
473 'options'=>['color','background','border','border_radius','padding','shadow','transition'],
474 ],
475 [
476 'key'=>'item_icon',
477 'label'=> esc_html__('Item Icon', 'wpdirectorykit'),
478 'selector'=>'.wdk-locations .wdk-link i',
479 'selector_hover'=>'.wdk-locations .wdk-link%1$s i',
480 'options'=>['margin','color','background','border','border_radius','padding','shadow'],
481 ],
482 [
483 'key'=>'item_icon_tree',
484 'label'=> esc_html__('Item Icon', 'wpdirectorykit'),
485 'selector'=>'.wdk-locations .wdk-link .wdk-icon',
486 'selector_hover'=>'.wdk-locations .wdk-link%1$s .wdk-icon',
487 'options'=>['margin','background','border','border_radius','padding','shadow','transition','image_size_control', 'css_filters'],
488 ],
489 [
490 'key'=>'item_title',
491 'label'=> esc_html__('Item Title', 'wpdirectorykit'),
492 'selector'=>'.wdk-locations .wdk-link .wdk-title',
493 'selector_hover'=>'.wdk-locations .wdk-link%1$s .wdk-title',
494 'options'=>['margin','typo','color','background','border','border_radius','padding'],
495 ],
496 [
497 'key'=>'item_count',
498 'label'=> esc_html__('Item Count', 'wpdirectorykit'),
499 'selector'=>'.wdk-locations .wdk-link .wdk-count',
500 'selector_hover'=>'.wdk-locations .wdk-link%1$s .wdk-count',
501 'options'=>['margin','typo','color','background','border','border_radius','padding'],
502 ],
503 ];
504
505 foreach ($items as $item) {
506
507 if($item['key'] == 'item_icon_tree') {
508 $this->start_controls_section(
509 $item['key'].'_section',
510 [
511 'label' => $item['label'],
512 'tab' => Controls_Manager::TAB_STYLE,
513 'conditions' => [
514 'terms' => [
515 [
516 'name' => 'show_icon',
517 'operator' => '==',
518 'value' => 'true',
519 ]
520 ],
521 ],
522 ]
523 );
524 } elseif($item['key'] == 'item_icon') {
525 $this->start_controls_section(
526 $item['key'].'_section',
527 [
528 'label' => $item['label'],
529 'tab' => Controls_Manager::TAB_STYLE,
530 'conditions' => [
531 'terms' => [
532 [
533 'name' => 'show_icon',
534 'operator' => '!=',
535 'value' => 'true',
536 ]
537 ],
538 ],
539 ]
540 );
541 } else {
542 $this->start_controls_section(
543 $item['key'].'_section',
544 [
545 'label' => $item['label'],
546 'tab' => Controls_Manager::TAB_STYLE,
547 ]
548 );
549 }
550
551 $this->add_responsive_control(
552 $item['key'].'_hide',
553 [
554 'label' => esc_html__( 'Hide Element', 'wpdirectorykit' ),
555 'type' => Controls_Manager::SWITCHER,
556 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
557 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
558 'return_value' => 'none',
559 'default' => '',
560 'selectors' => [
561 '{{WRAPPER}} '.$item['selector'] => 'display: {{VALUE}};',
562 ],
563 ]
564 );
565 $selectors = array(
566 'normal' => '{{WRAPPER}} '.$item['selector'],
567 'hover'=>'{{WRAPPER}} '.$item['selector_hover'],
568 );
569 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
570
571 /* special for some elements */
572 if($item['key'] == 'item_icon') {
573 $this->add_control(
574 $item['key'].'_i',
575 [
576 'label' => esc_html__('Icon', 'wpdirectorykit'),
577 'type' => Controls_Manager::ICONS,
578 'label_block' => true,
579 'default' => [
580 'value' => 'fa fa-angle-right',
581 'library' => 'solid',
582 ],
583 ]
584 );
585 $this->add_responsive_control(
586 $item['key'].'_size',
587 [
588 'label' => __( 'Size', 'wpdirectorykit' ),
589 'type' => Controls_Manager::SLIDER,
590 'size_units' => [ 'px','em', 'vw', '%', 'custom' ],
591 'range' => [
592 'px' => [
593 'min' => 1,
594 'max' => 60,
595 'step' => 1,
596 ],
597 ],
598 'default' => [
599 'unit' => 'px',
600 'size' => 14,
601 ],
602 'selectors' => [
603 '{{WRAPPER}} '.$item['selector'] => 'font-size: {{SIZE}}{{UNIT}};',
604 ],
605 ]
606 );
607
608 }
609 if($item['key'] == 'item_count') {
610 $this->add_responsive_control(
611 $item['key'].'_align',
612 [
613 'label' => __( 'Position', 'wpdirectorykit' ),
614 'type' => Controls_Manager::CHOOSE,
615 'options' => [
616 'left' => [
617 'title' => esc_html__( 'Left', 'wpdirectorykit' ),
618 'icon' => 'eicon-text-align-left',
619 ],
620 'center' => [
621 'title' => esc_html__( 'Center', 'wpdirectorykit' ),
622 'icon' => 'eicon-text-align-center',
623 ],
624 'right' => [
625 'title' => esc_html__( 'Right', 'wpdirectorykit' ),
626 'icon' => 'eicon-text-align-right',
627 ],
628
629 ],
630 'render_type' => 'ui',
631 'selectors_dictionary' => [
632 'left' => 'text-align: left;',
633 'center' => 'text-alig: center;',
634 'right' => 'text-align: right;',
635 ],
636 'selectors' => [
637 '{{WRAPPER}} '.$item['selector'] => '{{VALUE}};',
638 ],
639 ]
640 );
641 }
642 $this->end_controls_section();
643 }
644 }
645
646 private function generate_controls_content() {
647
648 }
649
650 public function enqueue_styles_scripts() {
651 wp_enqueue_style('wdk-locations-list');
652
653 }
654 }
655