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

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