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-listing-map.php

wdk-listing-map.php in WP Directory Kit 1.2.7, at elementor-elements/classes/wdk-listing-map.php

629 lines 24.8 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 WdkListingMap 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__('InfoWindow', '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 list of categories the widget belongs to.
53 *
54 * Used to determine where to display the widget in the editor.
55 *
56 * Note that currently Elementor supports only one category.
57 * When multiple categories passed, Elementor uses the first one.
58 *
59 * @since 1.1.0
60 *
61 * @access public
62 *
63 * @return array Widget categories.
64 */
65 public function get_categories() {
66 return [ 'wdk-elementor-listing-preview' ];
67 }
68
69 /**
70 * Retrieve the widget name.
71 *
72 * @since 1.1.0
73 *
74 * @access public
75 *
76 * @return string Widget name.
77 */
78 public function get_name() {
79 return 'wdk-listing-map';
80 }
81
82 /**
83 * Retrieve the widget title.
84 *
85 * @since 1.1.0
86 *
87 * @access public
88 *
89 * @return string Widget title.
90 */
91 public function get_title() {
92 return esc_html__('Wdk Listing Map', 'wpdirectorykit');
93 }
94
95 /**
96 * Retrieve the widget icon.
97 *
98 * @since 1.1.0
99 *
100 * @access public
101 *
102 * @return string Widget icon.
103 */
104 public function get_icon() {
105 return 'eicon-google-maps';
106 }
107
108 /**
109 * Register the widget controls.
110 *
111 * Adds different input fields to allow the user to change and customize the widget settings.
112 *
113 * @since 1.1.0
114 *
115 * @access protected
116 */
117 protected function register_controls() {
118 $this->generate_controls_conf();
119 $this->generate_controls_layout();
120 $this->generate_controls_styles();
121 $this->generate_controls_content();
122
123 $this->insert_pro_message('1');
124 parent::register_controls();
125 }
126
127 /**
128 * Render the widget output on the frontend.
129 *
130 * Written in PHP and used to generate the final HTML.
131 *
132 * @since 1.1.0
133 *
134 * @access protected
135 */
136
137 protected function render() {
138 parent::render();
139 global $wdk_listing_id;
140
141 $this->data['id_element'] = $this->get_id();
142 $this->data['settings'] = $this->get_settings();
143
144 /* default from settings */
145 $this->data['lat'] = wdk_get_option('wdk_default_lat', 51.505);
146 $this->data['lng'] = wdk_get_option('wdk_default_lng', -0.09);
147 $this->data['wdk_listing_id'] = $wdk_listing_id;
148
149 if(!Plugin::$instance->editor->is_edit_mode() && !empty($wdk_listing_id)) {
150 $this->data['lat'] = $this->data['lng'] = NULL;
151 if(!empty($this->data['settings']['field_id'])) {
152 if(strpos($this->data['settings']['field_id'],'__') !== FALSE){
153 $this->data['settings']['field_id'] = substr($this->data['settings']['field_id'], strpos($this->data['settings']['field_id'],'__')+2);
154 }
155
156 $gps = wdk_get_gps(wdk_field_value ($this->data['settings']['field_id'], $wdk_listing_id));
157 if($gps) {
158 $this->data['lat'] = $gps['lat'];
159 $this->data['lng'] = $gps['lng'];
160 }
161 } else {
162 $this->data['lat'] = wdk_field_value ('lat', $wdk_listing_id);
163 $this->data['lng'] = wdk_field_value ('lng', $wdk_listing_id);
164 }
165 } else {
166
167 }
168
169 $this->data['is_edit_mode']= false;
170 if(Plugin::$instance->editor->is_edit_mode() || empty($wdk_listing_id)) {
171 $this->data['is_edit_mode']= true;
172 }
173
174 echo $this->view('wdk-listing-map', $this->data);
175 }
176
177 private function generate_controls_conf() {
178 if(true){
179
180 $this->start_controls_section(
181 'conf_custom_map',
182 [
183 'label' => esc_html__('Map', 'wpdirectorykit'),
184 'tab' => '1',
185 ]
186 );
187
188 $WMVC = &wdk_get_instance();
189 $WMVC->model('field_m');
190 $fields_data = $WMVC->field_m->get();
191 $fields_list = array('' => esc_html__('Not Selected', 'wpdirectorykit'));
192 $order_i = 0;
193
194 $fields_list [(++$order_i).'__section'] = esc_html__('-- Section Custom fields --', 'wpdirectorykit');
195 $fields_list [(++$order_i).'__idlisting'] = esc_html__('Id listing', 'wpdirectorykit');
196 $fields_list [(++$order_i).'__post_id'] = esc_html__('Post Id', 'wpdirectorykit');
197 $fields_list [(++$order_i).'__counter_views'] = esc_html__('Views counter', 'wpdirectorykit');
198 $fields_list [(++$order_i).'__lat'] = esc_html__('Gps Lat', 'wpdirectorykit');
199 $fields_list [(++$order_i).'__lng'] = esc_html__('Gps Lng', 'wpdirectorykit');
200 $fields_list [(++$order_i).'__date'] = esc_html__('Date', 'wpdirectorykit');
201 $fields_list [(++$order_i).'__date_modified'] = esc_html__('Date Modified', 'wpdirectorykit');
202 $fields_list [(++$order_i).'__post_title'] = esc_html__('WP Title', 'wpdirectorykit');
203 $fields_list [(++$order_i).'__post_content'] = esc_html__('WP Content', 'wpdirectorykit');
204 $fields_list [(++$order_i).'__address'] = esc_html__('Address', 'wpdirectorykit');
205 $fields_list [(++$order_i).'__category_id'] = esc_html__('Category', 'wpdirectorykit');
206 $fields_list [(++$order_i).'__location_id'] = esc_html__('Location', 'wpdirectorykit');
207
208 foreach($fields_data as $field)
209 {
210 if(wmvc_show_data('field_type', $field) == 'SECTION') {
211 $fields_list [(++$order_i).'section__'.wmvc_show_data('idfield', $field)] = '-- '.esc_html__('Section', 'wpdirectorykit').' '.wmvc_show_data('field_label', $field).' --';
212 } else {
213 $fields_list[(++$order_i).'__'.wmvc_show_data('idfield', $field)] = '#'.wmvc_show_data('idfield', $field).' '.wmvc_show_data('field_label', $field).'['.wmvc_show_data('field_type', $field).']';
214 }
215 }
216 $this->add_control(
217 'field_id',
218 [
219 'label' => __( 'Marker position based on field with address (Detected gps by api)', 'wpdirectorykit' ),
220 'type' => \Elementor\Controls_Manager::SELECT,
221 'default' => '',
222 'options' => $fields_list,
223 'separator' => 'after',
224 ]
225 );
226
227 $this->add_responsive_control(
228 'conf_custom_map_height',
229 [
230 'label' => esc_html__('Height', 'wpdirectorykit'),
231 'type' => Controls_Manager::SLIDER,
232 'range' => [
233 'px' => [
234 'min' => 100,
235 'max' => 1500,
236 ],
237 ],
238 'render_type' => 'template',
239 'default' => [
240 'size' => 350,
241 ],
242 'selectors' => [
243 '{{WRAPPER}} .wdk-element #wdk_map_results' => 'height: {{SIZE}}px !important',
244 ],
245 'separator' => 'after',
246 ]
247 );
248
249 $this->add_control(
250 'conf_custom_map_zoom_index',
251 [
252 'label' => esc_html__('Zoom Index', 'wpdirectorykit'),
253 'description' => esc_html__( 'Only active if auto centering is disabled', 'wpdirectorykit' ),
254 'type' => Controls_Manager::SLIDER,
255 'range' => [
256 'px' => [
257 'min' => 1,
258 'max' => 18,
259 ],
260 ],
261 'render_type' => 'template',
262 'default' => [
263 'size' => 7,
264 ],
265 ]
266 );
267
268 $this->add_responsive_control(
269 'conf_custom_dragging',
270 [
271 'label' => esc_html__( 'Dragging', 'wpdirectorykit' ),
272 'type' => Controls_Manager::SWITCHER,
273 'none' => esc_html__( 'True', 'wpdirectorykit' ),
274 'block' => esc_html__( 'False', 'wpdirectorykit' ),
275 'render_type' => 'template',
276 'return_value' => 'yes',
277 'default' => 'yes',
278 'separator' => 'before',
279 ]
280 );
281
282
283 $this->add_responsive_control(
284 'conf_custom_popup_enable',
285 [
286 'label' => esc_html__( 'Enable Infobox', 'wpdirectorykit' ),
287 'type' => Controls_Manager::SWITCHER,
288 'none' => esc_html__( 'True', 'wpdirectorykit' ),
289 'block' => esc_html__( 'False', 'wpdirectorykit' ),
290 'render_type' => 'template',
291 'return_value' => 'yes',
292 'default' => 'yes',
293 'separator' => 'before',
294 ]
295 );
296
297 $this->add_responsive_control(
298 'puopup_custom_content',
299 [
300 'label' => esc_html__( 'Custom Fields For Infobox', 'wpdirectorykit' ),
301 'type' => Controls_Manager::SWITCHER,
302 'none' => esc_html__( 'True', 'wpdirectorykit' ),
303 'block' => esc_html__( 'False', 'wpdirectorykit' ),
304 'render_type' => 'template',
305 'return_value' => 'yes',
306 'default' => '',
307 'conditions' => [
308 'terms' => [
309 [
310 'name' => 'conf_custom_popup_enable',
311 'operator' => '==',
312 'value' => 'yes',
313 ]
314 ],
315 ]
316 ]
317 );
318
319
320 $this->add_control(
321 'conf_custom_map_styles_h',
322 [
323 'label' => __( 'Map Styles', 'wpdirectorykit' ),
324 'type' => \Elementor\Controls_Manager::HEADING,
325 'separator' => 'before',
326 ]
327 );
328
329 $this->add_control(
330 'conf_custom_map_style',
331 [
332 'label' => esc_html__('Styles List', 'wpdirectorykit'),
333 'type' => Controls_Manager::SELECT,
334 'options' => [
335 '' => esc_html__('Default', 'wpdirectorykit'),
336 'custom' => esc_html__('Custom', 'wpdirectorykit'),
337 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}{r}.png' => esc_html__('Light', 'wpdirectorykit'),
338 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png' => esc_html__('Osmde', 'wpdirectorykit'),
339 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png' => esc_html__('OpenTopoMap', 'wpdirectorykit'),
340 'https://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' => esc_html__('OpenCycleMap', 'wpdirectorykit'),
341 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}' => esc_html__('WorldImagery', 'wpdirectorykit'),
342 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png' => esc_html__('Carto DarkMatter', 'wpdirectorykit'),
343 'https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png' => esc_html__('Carto Voyager', 'wpdirectorykit'),
344 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}{r}.png' => esc_html__('Maptiler dark (demo)', 'wpdirectorykit'),
345 ],
346 'default' => '',
347 ]
348 );
349
350 $this->add_control(
351 'conf_custom_map_style_self',
352 [
353 'label' => esc_html__('Link to custom Map Style', 'wpdirectorykit'),
354 'description' => esc_html__( 'You can add some custom map by link example https://leaflet-extras.github.io/leaflet-providers/preview/ or create your custom style and put link for example on maps.cloudmade.com/editor', 'wpdirectorykit' ),
355 'type' => Controls_Manager::TEXTAREA,
356 'render_type' => 'template',
357 'conditions' => [
358 'terms' => [
359 [
360 'name' => 'conf_custom_map_style',
361 'operator' => '==',
362 'value' => 'custom',
363 ]
364 ],
365 ]
366 ]
367 );
368
369
370
371 $this->end_controls_section();
372 }
373
374
375 $this->start_controls_section(
376 'tab_conf_main_section',
377 [
378 'label' => esc_html__('Custom Popup Fields', 'wpdirectorykit'),
379 'tab' => '1',
380 'conditions' => [
381 'terms' => [
382 [
383 'name' => 'puopup_custom_content',
384 'operator' => '==',
385 'value' => 'yes',
386 ]
387 ],
388 ]
389 ]
390 );
391
392 $WMVC = &wdk_get_instance();
393 $WMVC->model('field_m');
394 $fields_data = $WMVC->field_m->get();
395 $fields_list = array('' => esc_html__('Not Selected', 'wpdirectorykit'));
396 $order_i = 0;
397
398 $fields_list [(++$order_i).'__section'] = esc_html__('-- Section Custom fields --', 'wpdirectorykit');
399 $fields_list [(++$order_i).'__idlisting'] = esc_html__('Id listing', 'wpdirectorykit');
400 $fields_list [(++$order_i).'__post_id'] = esc_html__('Post Id', 'wpdirectorykit');
401 $fields_list [(++$order_i).'__counter_views'] = esc_html__('Views counter', 'wpdirectorykit');
402 $fields_list [(++$order_i).'__lat'] = esc_html__('Gps Lat', 'wpdirectorykit');
403 $fields_list [(++$order_i).'__lng'] = esc_html__('Gps Lng', 'wpdirectorykit');
404 $fields_list [(++$order_i).'__date'] = esc_html__('Date', 'wpdirectorykit');
405 $fields_list [(++$order_i).'__date_modified'] = esc_html__('Date Modified', 'wpdirectorykit');
406 $fields_list [(++$order_i).'__post_title'] = esc_html__('WP Title', 'wpdirectorykit');
407 $fields_list [(++$order_i).'__post_content'] = esc_html__('WP Content', 'wpdirectorykit');
408 $fields_list [(++$order_i).'__address'] = esc_html__('Address', 'wpdirectorykit');
409 $fields_list [(++$order_i).'__category_id'] = esc_html__('Category', 'wpdirectorykit');
410 $fields_list [(++$order_i).'__location_id'] = esc_html__('Location', 'wpdirectorykit');
411
412 foreach($fields_data as $field)
413 {
414 if(wmvc_show_data('field_type', $field) == 'SECTION') {
415 $fields_list [(++$order_i).'section__'.wmvc_show_data('idfield', $field)] = '-- '.esc_html__('Section', 'wpdirectorykit').' '.wmvc_show_data('field_label', $field).' --';
416 } else {
417 $fields_list[(++$order_i).'__'.wmvc_show_data('idfield', $field)] = '#'.wmvc_show_data('idfield', $field).' '.wmvc_show_data('field_label', $field).'['.wmvc_show_data('field_type', $field).']';
418 }
419 }
420 $this->add_control(
421 'title_field_id',
422 [
423 'label' => __( 'Title Field', 'wpdirectorykit' ),
424 'type' => \Elementor\Controls_Manager::SELECT,
425 'default' => '',
426 'options' => $fields_list,
427 ]
428 );
429
430 $this->add_control(
431 'content_field_id',
432 [
433 'label' => __( 'Content Field', 'wpdirectorykit' ),
434 'type' => \Elementor\Controls_Manager::SELECT,
435 'default' => '',
436 'options' => $fields_list,
437 ]
438 );
439
440 $this->end_controls_section();
441
442 }
443
444 private function generate_controls_layout() {
445
446 /* default marker layout */
447 $this->generate_controls_layout_default();
448 }
449
450 private function generate_controls_styles() {
451 /* marker */
452 $this->start_controls_section(
453 'styles_marker_sec',
454 [
455 'label' => esc_html__('Marker', 'wpdirectorykit'),
456 'tab' => Controls_Manager::TAB_STYLE,
457 ]
458 );
459
460
461 $this->add_control(
462 'styles_marker_h',
463 [
464 'label' => esc_html__('Marker', 'wpdirectorykit'),
465 'type' => Controls_Manager::HEADING,
466 'separator' => 'before',
467 ]
468 );
469
470 $this->start_controls_tabs('marker_button_style');
471
472 $this->start_controls_tab(
473 'marker',
474 [
475 'label' => esc_html__('Normal', 'wpdirectorykit'),
476 ]
477 );
478
479 $this->add_control(
480 'styles_marker_color',
481 [
482 'label' => esc_html__('Marker Border Color', 'wpdirectorykit'),
483 'type' => Controls_Manager::COLOR,
484 'selectors' => [
485 '{{WRAPPER}} .wdk-element .wdk-map .wdk_marker-card::before' => 'background-color: {{VALUE}};',
486 ],
487 ]
488 );
489
490 $this->add_control(
491 'styles_marker_color_bckg',
492 [
493 'label' => esc_html__('Marker Color', 'wpdirectorykit'),
494 'type' => Controls_Manager::COLOR,
495 'selectors' => [
496 '{{WRAPPER}} .wdk-element .wdk_marker-card:after' => 'background-color: {{VALUE}};',
497 ],
498 ]
499 );
500
501 $this->add_control(
502 'styles_marker_color_text',
503 [
504 'label' => esc_html__('Marker Text Color', 'wpdirectorykit'),
505 'type' => Controls_Manager::COLOR,
506 'selectors' => [
507 '{{WRAPPER}} .wdk_face i' => 'color: {{VALUE}};',
508 ],
509 ]
510 );
511
512 $this->add_control(
513 'conf_custom_map_pin_icon',
514 [
515 'label' => esc_html__('Icon', 'wpdirectorykit'),
516 'type' => Controls_Manager::ICONS,
517 'label_block' => true,
518 'default' => [
519 'value' => 'fa fa-home',
520 'library' => 'solid',
521 ],
522 ]
523 );
524
525 $this->add_control(
526 'conf_custom_map_pin',
527 [
528 'label' => esc_html__('Custom Marker Pin Image', 'wpdirectorykit'),
529 'type' => Controls_Manager::MEDIA,
530 ]
531 );
532
533 $this->end_controls_tab();
534
535 $this->start_controls_tab(
536 'marker_hover',
537 [
538 'label' => esc_html__('Hover', 'wpdirectorykit'),
539 ]
540 );
541
542 $this->add_control(
543 'styles_marker_color_hover',
544 [
545 'label' => esc_html__('Marker Border Color', 'wpdirectorykit'),
546 'type' => Controls_Manager::COLOR,
547 'selectors' => [
548 '{{WRAPPER}} .wdk-element .wdk_marker-container:hover .wdk_marker-card:before' => 'background-color: {{VALUE}};',
549 ],
550 ]
551 );
552
553 $this->add_control(
554 'styles_marker_color_hover_bckg',
555 [
556 'label' => esc_html__('Marker Color', 'wpdirectorykit'),
557 'type' => Controls_Manager::COLOR,
558 'selectors' => [
559 '{{WRAPPER}} .wdk-element .wdk_marker-container:hover .wdk_marker-card:after' => 'background-color: {{VALUE}};',
560 ],
561 ]
562 );
563
564 $this->add_control(
565 'styles_marker_color_text_hover',
566 [
567 'label' => esc_html__('Marker Text Color', 'wpdirectorykit'),
568 'type' => Controls_Manager::COLOR,
569 'selectors' => [
570 '{{WRAPPER}} .wdk_marker-container:hover .wdk_face.back i, .wdk_marker-container:hover .wdk_face i' => 'color: {{VALUE}};',
571 ],
572 ]
573 );
574
575 $this->add_control(
576 'styles_marker_effect_duration',
577 [
578 'label' => esc_html__('Transition Duration', 'wpdirectorykit'),
579 'type' => Controls_Manager::SLIDER,
580 'render_type' => 'template',
581 'range' => [
582 'px' => [
583 'min' => 0,
584 'max' => 3000,
585 ],
586 ],
587 'selectors' => [
588 '{{WRAPPER}} .wdk_map-marker-container.clicked .wdk_face.front, .wdk_marker-container:hover .wdk_face.front' => 'transition-duration: {{SIZE}}ms',
589 ],
590 ]
591 );
592
593 $this->end_controls_tab();
594
595 $this->end_controls_tabs();
596 $this->end_controls_section();
597 }
598
599 private function generate_controls_content() {
600 }
601
602 private function generate_controls_layout_default() {
603
604 }
605
606 private function generate_controls_styles_default() {
607
608 }
609
610 public function enqueue_styles_scripts() {
611 wp_enqueue_style('leaflet');
612 wp_enqueue_style('leaflet-cluster-def');
613 wp_enqueue_style('leaflet-cluster');
614 wp_enqueue_script('leaflet');
615 wp_enqueue_script('leaflet-cluster');
616 wp_enqueue_script('leaflet-fullscreen');
617 wp_enqueue_style('leaflet-fullscreen');
618
619 wp_enqueue_style('wdk-notify');
620 wp_enqueue_script('wdk-notify');
621 wp_enqueue_style( 'wdk-listings-map' );
622
623 wp_enqueue_style('slick');
624 wp_enqueue_style('slick-theme');
625 wp_enqueue_style('wdk-hover');
626 wp_enqueue_script('slick');
627 }
628 }
629