PluginProbe
WP Directory Kit / 1.3.4
WP Directory Kit v1.3.4
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 1.4.0 1.4.1 All 35 releases
wpdirectorykit / elementor-elements / classes / wdk-locations-list.php

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

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