PluginProbe
WP Directory Kit / 1.5.4
WP Directory Kit v1.5.4
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.4, at elementor-elements/classes/wdk-locations-list.php

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