PluginProbe
WP Directory Kit / 1.2.8
WP Directory Kit v1.2.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-locations-list.php

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

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