| @@ -1,0 +1,720 @@ | ||
| 1 | +<?php /** @noinspection PhpUnused */ | |
| 2 | + | |
| 3 | +namespace King_Addons; | |
| 4 | + | |
| 5 | +use Elementor\Widget_Base; | |
| 6 | +use Elementor\Controls_Manager; | |
| 7 | +use Elementor\Repeater; | |
| 8 | +use Elementor\Group_Control_Typography; | |
| 9 | + | |
| 10 | +if (!defined('ABSPATH')) { | |
| 11 | + exit; | |
| 12 | +} | |
| 13 | + | |
| 14 | +class Google_Maps extends Widget_Base | |
| 15 | +{ | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + public function get_name() | |
| 20 | + { | |
| 21 | + return 'king-addons-google-maps'; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public function get_title() | |
| 25 | + { | |
| 26 | + return esc_html__('Google Maps', 'king-addons'); | |
| 27 | + } | |
| 28 | + | |
| 29 | + public function get_icon() | |
| 30 | + { | |
| 31 | + return 'king-addons-icon king-addons-google-maps'; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public function get_categories() | |
| 35 | + { | |
| 36 | + return ['king-addons']; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public function get_keywords() | |
| 40 | + { | |
| 41 | + return ['king addons', 'king', 'addons', 'kingaddons', 'king-addons', 'google maps', 'location', 'gmap', | |
| 42 | + 'cluster', 'google', 'maps', 'map', 'point', 'hotspot', 'spot']; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public function get_script_depends() | |
| 46 | + { | |
| 47 | + return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-google-maps-script', KING_ADDONS_ASSETS_UNIQUE_KEY . '-markerclusterer-markerclusterer']; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public function get_style_depends(): array | |
| 51 | + { | |
| 52 | + return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-google-maps-style']; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public function get_custom_help_url() | |
| 56 | + { | |
| 57 | + return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue'; | |
| 58 | + } | |
| 59 | + | |
| 60 | + protected function register_controls() | |
| 61 | + { | |
| 62 | + $this->start_controls_section( | |
| 63 | + 'section_google_map_general', | |
| 64 | + [ | |
| 65 | + 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('General', 'king-addons'), | |
| 66 | + 'tab' => Controls_Manager::TAB_CONTENT, | |
| 67 | + ] | |
| 68 | + ); | |
| 69 | + | |
| 70 | + if ('' == get_option('king_addons_google_map_api_key')) { | |
| 71 | + /** @noinspection HtmlUnknownTarget */ | |
| 72 | + $this->add_control( | |
| 73 | + 'gm_api_notice', | |
| 74 | + [ | |
| 75 | + 'type' => Controls_Manager::RAW_HTML, | |
| 76 | + 'raw' => sprintf(__('Please enter the <strong>Google Map API Key</strong> in the <br><a href="%s" target="_blank">Dashboard > %s > Settings</a> tab to activate this widget.', 'king-addons'), admin_url('admin.php?page=king-addons-settings'), Core::getPluginName()), | |
| 77 | + 'separator' => 'after', | |
| 78 | + 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info', | |
| 79 | + ] | |
| 80 | + ); | |
| 81 | + } | |
| 82 | + | |
| 83 | + $this->add_control( | |
| 84 | + 'gm_type', | |
| 85 | + [ | |
| 86 | + 'label' => esc_html__('Select Map Type', 'king-addons'), | |
| 87 | + 'type' => Controls_Manager::SELECT, | |
| 88 | + 'options' => [ | |
| 89 | + 'roadmap' => esc_html__('Road Map', 'king-addons'), | |
| 90 | + 'satellite' => esc_html__('Satellite', 'king-addons'), | |
| 91 | + 'hybrid' => esc_html__('Hybrid', 'king-addons'), | |
| 92 | + 'terrain' => esc_html__('Terrain', 'king-addons'), | |
| 93 | + ], | |
| 94 | + 'default' => 'roadmap', | |
| 95 | + ] | |
| 96 | + ); | |
| 97 | + | |
| 98 | + $this->add_control( | |
| 99 | + 'gm_color_scheme', | |
| 100 | + [ | |
| 101 | + 'label' => esc_html__('Color Scheme', 'king-addons'), | |
| 102 | + 'type' => Controls_Manager::SELECT, | |
| 103 | + 'options' => [ | |
| 104 | + 'default' => esc_html__('Default', 'king-addons'), | |
| 105 | + 'blue-essence' => esc_html__('Blue Essence', 'king-addons'), | |
| 106 | + 'blue-water' => esc_html__('Blue Water', 'king-addons'), | |
| 107 | + 'golden-brown' => esc_html__('Golden Brown', 'king-addons'), | |
| 108 | + 'light-grayscale' => esc_html__('Light Grayscale', 'king-addons'), | |
| 109 | + 'light-silver' => esc_html__('Light Silver', 'king-addons'), | |
| 110 | + 'midnight-commander' => esc_html__('Midnight Commander', 'king-addons'), | |
| 111 | + 'mostly-green' => esc_html__('Mostly Green', 'king-addons'), | |
| 112 | + 'mostly-white' => esc_html__('Mostly White', 'king-addons'), | |
| 113 | + 'neutral-blue' => esc_html__('Neutral Blue', 'king-addons'), | |
| 114 | + 'shades-of-grey' => esc_html__('Shades of Grey', 'king-addons'), | |
| 115 | + 'simple' => esc_html__('Simple', 'king-addons'), | |
| 116 | + 'subtle-grayscale' => esc_html__('Subtle Grayscale', 'king-addons'), | |
| 117 | + 'white-black' => esc_html__('White Black', 'king-addons'), | |
| 118 | + 'yellow-black' => esc_html__('Yellow Black', 'king-addons'), | |
| 119 | + 'custom' => esc_html__('Custom', 'king-addons'), | |
| 120 | + ], | |
| 121 | + 'default' => 'default', | |
| 122 | + 'condition' => [ | |
| 123 | + 'gm_type!' => 'satellite', | |
| 124 | + ] | |
| 125 | + ] | |
| 126 | + ); | |
| 127 | + | |
| 128 | + $this->add_control( | |
| 129 | + 'gm_custom_color_scheme', | |
| 130 | + [ | |
| 131 | + 'label' => esc_html__('Custom Style', 'king-addons'), | |
| 132 | + 'description' => __('Get custom map style code from <a href="https://snazzymaps.com/explore" target="_blank">Snazzy Maps</a> or <a href="https://mapstyle.withgoogle.com/" target="_blank">GM Styling Wizard</a> and copy/paste in this field.', 'king-addons'), | |
| 133 | + 'type' => Controls_Manager::TEXTAREA, | |
| 134 | + 'dynamic' => [ | |
| 135 | + 'active' => true, | |
| 136 | + ], | |
| 137 | + 'condition' => [ | |
| 138 | + 'gm_color_scheme' => 'custom', | |
| 139 | + ] | |
| 140 | + ] | |
| 141 | + ); | |
| 142 | + | |
| 143 | + $this->add_responsive_control( | |
| 144 | + 'gm_height', | |
| 145 | + [ | |
| 146 | + 'label' => esc_html__('Map Height', 'king-addons'), | |
| 147 | + 'type' => Controls_Manager::SLIDER, | |
| 148 | + 'default' => [ | |
| 149 | + 'size' => 500, | |
| 150 | + ], | |
| 151 | + 'range' => [ | |
| 152 | + 'px' => [ | |
| 153 | + 'min' => 100, | |
| 154 | + 'max' => 1000, | |
| 155 | + ], | |
| 156 | + ], | |
| 157 | + 'selectors' => [ | |
| 158 | + '{{WRAPPER}} .king-addons-google-map' => 'height: {{SIZE}}px;', | |
| 159 | + ], | |
| 160 | + 'separator' => 'before' | |
| 161 | + ] | |
| 162 | + ); | |
| 163 | + | |
| 164 | + $this->add_control( | |
| 165 | + 'gm_zoom_depth', | |
| 166 | + [ | |
| 167 | + 'label' => esc_html__('Zoom Depth', 'king-addons'), | |
| 168 | + 'type' => Controls_Manager::SLIDER, | |
| 169 | + 'default' => [ | |
| 170 | + 'size' => 10, | |
| 171 | + ], | |
| 172 | + 'range' => [ | |
| 173 | + 'px' => [ | |
| 174 | + 'min' => 1, | |
| 175 | + 'max' => 20, | |
| 176 | + ], | |
| 177 | + ], | |
| 178 | + ] | |
| 179 | + ); | |
| 180 | + | |
| 181 | + $this->add_control( | |
| 182 | + 'gm_zoom_on_scroll', | |
| 183 | + [ | |
| 184 | + 'label' => esc_html__('Disable Zoom on Scroll', 'king-addons'), | |
| 185 | + 'type' => Controls_Manager::SWITCHER, | |
| 186 | + 'default' => 'yes', | |
| 187 | + 'return_value' => 'cooperative', | |
| 188 | + 'separator' => 'before' | |
| 189 | + ] | |
| 190 | + ); | |
| 191 | + | |
| 192 | + $this->add_control( | |
| 193 | + 'gm_cluster_markers', | |
| 194 | + [ | |
| 195 | + 'label' => esc_html__('Cluster Markers', 'king-addons'), | |
| 196 | + 'description' => esc_html__('Combine markers in close proximity into clusters to simplify the display of markers on the map.', 'king-addons'), | |
| 197 | + 'type' => Controls_Manager::SWITCHER, | |
| 198 | + 'default' => 'yes', | |
| 199 | + ] | |
| 200 | + ); | |
| 201 | + | |
| 202 | + $this->end_controls_section(); | |
| 203 | + | |
| 204 | + $this->start_controls_section( | |
| 205 | + 'section_google_map_locations', | |
| 206 | + [ | |
| 207 | + 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Locations', 'king-addons'), | |
| 208 | + 'tab' => Controls_Manager::TAB_CONTENT, | |
| 209 | + ] | |
| 210 | + ); | |
| 211 | + | |
| 212 | + $this->add_control( | |
| 213 | + 'gm_location_helper', | |
| 214 | + [ | |
| 215 | + 'type' => Controls_Manager::RAW_HTML, | |
| 216 | + 'raw' => '<a href="https://www.latlong.net/" target="_blank">' . esc_html__('Click Here', 'king-addons') . '</a> ' . esc_html__('to find Coordinates of your location.', 'king-addons'), | |
| 217 | + 'separator' => 'after' | |
| 218 | + ] | |
| 219 | + ); | |
| 220 | + | |
| 221 | + $repeater = new Repeater(); | |
| 222 | + | |
| 223 | + $repeater->add_control( | |
| 224 | + 'gm_latitude', | |
| 225 | + [ | |
| 226 | + 'label' => esc_html__('Latitude', 'king-addons'), | |
| 227 | + 'type' => Controls_Manager::TEXT, | |
| 228 | + 'dynamic' => [ | |
| 229 | + 'active' => true, | |
| 230 | + ], | |
| 231 | + ] | |
| 232 | + ); | |
| 233 | + | |
| 234 | + $repeater->add_control( | |
| 235 | + 'gm_longitude', | |
| 236 | + [ | |
| 237 | + 'label' => esc_html__('Longitude', 'king-addons'), | |
| 238 | + 'type' => Controls_Manager::TEXT, | |
| 239 | + 'dynamic' => [ | |
| 240 | + 'active' => true, | |
| 241 | + ], | |
| 242 | + ] | |
| 243 | + ); | |
| 244 | + | |
| 245 | + $repeater->add_control( | |
| 246 | + 'gm_show_info_window', | |
| 247 | + [ | |
| 248 | + 'label' => esc_html__('Show Info Window', 'king-addons'), | |
| 249 | + 'type' => Controls_Manager::SELECT, | |
| 250 | + 'options' => [ | |
| 251 | + 'none' => esc_html__('None', 'king-addons'), | |
| 252 | + 'load' => esc_html__('on Load', 'king-addons'), | |
| 253 | + 'click' => esc_html__('on Click', 'king-addons'), | |
| 254 | + ], | |
| 255 | + 'default' => 'load', | |
| 256 | + 'separator' => 'before' | |
| 257 | + ] | |
| 258 | + ); | |
| 259 | + | |
| 260 | + $repeater->add_control( | |
| 261 | + 'gm_location_title', | |
| 262 | + [ | |
| 263 | + 'label' => esc_html__('Location Title', 'king-addons'), | |
| 264 | + 'default' => esc_html__('Location Title', 'king-addons'), | |
| 265 | + 'label_block' => true, | |
| 266 | + 'type' => Controls_Manager::TEXT, | |
| 267 | + 'dynamic' => [ | |
| 268 | + 'active' => true, | |
| 269 | + ], | |
| 270 | + 'condition' => [ | |
| 271 | + 'gm_show_info_window!' => 'none', | |
| 272 | + ] | |
| 273 | + ] | |
| 274 | + ); | |
| 275 | + | |
| 276 | + $repeater->add_control( | |
| 277 | + 'gm_location_description', | |
| 278 | + [ | |
| 279 | + 'label' => esc_html__('Location Description', 'king-addons'), | |
| 280 | + 'default' => esc_html__('Location Description', 'king-addons'), | |
| 281 | + 'type' => Controls_Manager::TEXTAREA, | |
| 282 | + 'dynamic' => [ | |
| 283 | + 'active' => true, | |
| 284 | + ], | |
| 285 | + 'condition' => [ | |
| 286 | + 'gm_show_info_window!' => 'none', | |
| 287 | + ] | |
| 288 | + ] | |
| 289 | + ); | |
| 290 | + | |
| 291 | + $repeater->add_control( | |
| 292 | + 'gm_info_window_width', | |
| 293 | + [ | |
| 294 | + 'label' => esc_html__('Info Window Width', 'king-addons'), | |
| 295 | + 'type' => Controls_Manager::SLIDER, | |
| 296 | + 'default' => [ | |
| 297 | + 'size' => 300, | |
| 298 | + ], | |
| 299 | + 'range' => [ | |
| 300 | + 'px' => [ | |
| 301 | + 'min' => 50, | |
| 302 | + 'max' => 500, | |
| 303 | + ], | |
| 304 | + ], | |
| 305 | + 'condition' => [ | |
| 306 | + 'gm_show_info_window!' => 'none', | |
| 307 | + ] | |
| 308 | + ] | |
| 309 | + ); | |
| 310 | + | |
| 311 | + $repeater->add_control( | |
| 312 | + 'gm_marker_animation', | |
| 313 | + [ | |
| 314 | + 'label' => esc_html__('Marker Animation', 'king-addons'), | |
| 315 | + 'type' => Controls_Manager::SELECT, | |
| 316 | + 'options' => [ | |
| 317 | + 'none' => esc_html__('None', 'king-addons'), | |
| 318 | + 'DROP' => esc_html__('Drop', 'king-addons'), | |
| 319 | + 'BOUNCE' => esc_html__('Bounce', 'king-addons'), | |
| 320 | + ], | |
| 321 | + 'default' => 'none', | |
| 322 | + 'separator' => 'before' | |
| 323 | + ] | |
| 324 | + ); | |
| 325 | + | |
| 326 | + $repeater->add_control( | |
| 327 | + 'gm_custom_marker', | |
| 328 | + [ | |
| 329 | + 'label' => esc_html__('Use Custom Marker', 'king-addons'), | |
| 330 | + 'type' => Controls_Manager::SWITCHER, | |
| 331 | + 'separator' => 'before' | |
| 332 | + ] | |
| 333 | + ); | |
| 334 | + | |
| 335 | + $repeater->add_control( | |
| 336 | + 'gm_marker_icon', | |
| 337 | + [ | |
| 338 | + 'label' => esc_html__('Upload Marker Icon', 'king-addons'), | |
| 339 | + 'type' => Controls_Manager::MEDIA, | |
| 340 | + 'dynamic' => [ | |
| 341 | + 'active' => true, | |
| 342 | + ], | |
| 343 | + 'condition' => [ | |
| 344 | + 'gm_custom_marker' => 'yes', | |
| 345 | + ] | |
| 346 | + ] | |
| 347 | + ); | |
| 348 | + | |
| 349 | + $repeater->add_control( | |
| 350 | + 'gm_marker_icon_size_width', | |
| 351 | + [ | |
| 352 | + 'label' => esc_html__('Marker Icon Size Width', 'king-addons'), | |
| 353 | + 'type' => Controls_Manager::SLIDER, | |
| 354 | + 'default' => [ | |
| 355 | + 'size' => 35, | |
| 356 | + ], | |
| 357 | + 'range' => [ | |
| 358 | + 'px' => [ | |
| 359 | + 'min' => 10, | |
| 360 | + 'max' => 150, | |
| 361 | + ], | |
| 362 | + ], | |
| 363 | + 'condition' => [ | |
| 364 | + 'gm_custom_marker' => 'yes', | |
| 365 | + ] | |
| 366 | + ] | |
| 367 | + ); | |
| 368 | + | |
| 369 | + $repeater->add_control( | |
| 370 | + 'gm_marker_icon_size_height', | |
| 371 | + [ | |
| 372 | + 'label' => esc_html__('Marker Icon Size Height', 'king-addons'), | |
| 373 | + 'type' => Controls_Manager::SLIDER, | |
| 374 | + 'default' => [ | |
| 375 | + 'size' => 35, | |
| 376 | + ], | |
| 377 | + 'range' => [ | |
| 378 | + 'px' => [ | |
| 379 | + 'min' => 10, | |
| 380 | + 'max' => 150, | |
| 381 | + ], | |
| 382 | + ], | |
| 383 | + 'condition' => [ | |
| 384 | + 'gm_custom_marker' => 'yes', | |
| 385 | + ] | |
| 386 | + ] | |
| 387 | + ); | |
| 388 | + | |
| 389 | + $this->add_control( | |
| 390 | + 'google_map_locations', | |
| 391 | + [ | |
| 392 | + 'type' => Controls_Manager::REPEATER, | |
| 393 | + 'fields' => $repeater->get_controls(), | |
| 394 | + 'default' => [ | |
| 395 | + [ | |
| 396 | + 'gm_location_title' => 'Central Park, New York, USA', | |
| 397 | + 'gm_location_description' => 'Our Office, call 234-567-COFFEE to get a coffee.', | |
| 398 | + 'gm_latitude' => '40.782864', | |
| 399 | + 'gm_longitude' => '-73.965355', | |
| 400 | + ], | |
| 401 | + ], | |
| 402 | + 'title_field' => '{{ gm_location_title }}', | |
| 403 | + ] | |
| 404 | + ); | |
| 405 | + | |
| 406 | + $this->end_controls_section(); | |
| 407 | + | |
| 408 | + $this->start_controls_section( | |
| 409 | + 'section_google_map_controls', | |
| 410 | + [ | |
| 411 | + 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Controls', 'king-addons'), | |
| 412 | + 'tab' => Controls_Manager::TAB_CONTENT, | |
| 413 | + ] | |
| 414 | + ); | |
| 415 | + | |
| 416 | + $this->add_control( | |
| 417 | + 'gm_controls_map_type', | |
| 418 | + [ | |
| 419 | + 'label' => esc_html__('Show Map Type Control', 'king-addons'), | |
| 420 | + 'type' => Controls_Manager::SWITCHER, | |
| 421 | + 'default' => 'yes' | |
| 422 | + ] | |
| 423 | + ); | |
| 424 | + | |
| 425 | + $this->add_control( | |
| 426 | + 'gm_controls_fullscreen', | |
| 427 | + [ | |
| 428 | + 'label' => esc_html__('Show FullScreen Control', 'king-addons'), | |
| 429 | + 'type' => Controls_Manager::SWITCHER, | |
| 430 | + 'default' => 'yes' | |
| 431 | + ] | |
| 432 | + ); | |
| 433 | + | |
| 434 | + $this->add_control( | |
| 435 | + 'gm_controls_zoom', | |
| 436 | + [ | |
| 437 | + 'label' => esc_html__('Show Zoom Control', 'king-addons'), | |
| 438 | + 'type' => Controls_Manager::SWITCHER, | |
| 439 | + 'default' => 'yes' | |
| 440 | + ] | |
| 441 | + ); | |
| 442 | + | |
| 443 | + $this->add_control( | |
| 444 | + 'gm_controls_street_view', | |
| 445 | + [ | |
| 446 | + 'label' => esc_html__('Show Street View Control', 'king-addons'), | |
| 447 | + 'type' => Controls_Manager::SWITCHER, | |
| 448 | + 'default' => 'yes' | |
| 449 | + ] | |
| 450 | + ); | |
| 451 | + | |
| 452 | + $this->end_controls_section(); | |
| 453 | + | |
| 454 | + $this->start_controls_section( | |
| 455 | + 'section_style_info_window', | |
| 456 | + [ | |
| 457 | + 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Info Window', 'king-addons'), | |
| 458 | + 'tab' => Controls_Manager::TAB_STYLE, | |
| 459 | + 'show_label' => false, | |
| 460 | + ] | |
| 461 | + ); | |
| 462 | + | |
| 463 | + $this->add_control( | |
| 464 | + 'infow_window_align', | |
| 465 | + [ | |
| 466 | + 'label' => esc_html__('Alignment', 'king-addons'), | |
| 467 | + 'type' => Controls_Manager::CHOOSE, | |
| 468 | + 'options' => [ | |
| 469 | + 'left' => [ | |
| 470 | + 'title' => esc_html__('Left', 'king-addons'), | |
| 471 | + 'icon' => 'eicon-text-align-left', | |
| 472 | + ], | |
| 473 | + 'center' => [ | |
| 474 | + 'title' => esc_html__('Center', 'king-addons'), | |
| 475 | + 'icon' => 'eicon-text-align-center', | |
| 476 | + ], | |
| 477 | + 'right' => [ | |
| 478 | + 'title' => esc_html__('Right', 'king-addons'), | |
| 479 | + 'icon' => 'eicon-text-align-right', | |
| 480 | + ], | |
| 481 | + 'justify' => [ | |
| 482 | + 'title' => esc_html__('Justified', 'king-addons'), | |
| 483 | + 'icon' => 'eicon-text-align-justify', | |
| 484 | + ], | |
| 485 | + ], | |
| 486 | + 'default' => 'center', | |
| 487 | + 'selectors' => [ | |
| 488 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-c' => 'text-align: {{VALUE}}', | |
| 489 | + ], | |
| 490 | + 'separator' => 'after', | |
| 491 | + ] | |
| 492 | + ); | |
| 493 | + | |
| 494 | + $this->add_control( | |
| 495 | + 'infow_window_title_color', | |
| 496 | + [ | |
| 497 | + 'label' => esc_html__('Title Color', 'king-addons'), | |
| 498 | + 'type' => Controls_Manager::COLOR, | |
| 499 | + 'selectors' => [ | |
| 500 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-c .king-addons-gm-iwindow h3' => 'color: {{VALUE}}', | |
| 501 | + ], | |
| 502 | + ] | |
| 503 | + ); | |
| 504 | + | |
| 505 | + $this->add_control( | |
| 506 | + 'infow_window_description_color', | |
| 507 | + [ | |
| 508 | + 'label' => esc_html__('Description Color', 'king-addons'), | |
| 509 | + 'type' => Controls_Manager::COLOR, | |
| 510 | + 'selectors' => [ | |
| 511 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-c .king-addons-gm-iwindow p' => 'color: {{VALUE}}', | |
| 512 | + ], | |
| 513 | + ] | |
| 514 | + ); | |
| 515 | + | |
| 516 | + $this->add_control( | |
| 517 | + 'infow_window_background_color', | |
| 518 | + [ | |
| 519 | + 'label' => esc_html__('Background Color', 'king-addons'), | |
| 520 | + 'type' => Controls_Manager::COLOR, | |
| 521 | + 'selectors' => [ | |
| 522 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-d' => 'background-color: {{VALUE}}', | |
| 523 | + '{{WRAPPER}} .king-addons-google-map .gm-style .gm-style-iw-c' => 'background-color: {{VALUE}}', | |
| 524 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-t:after' => 'background: {{VALUE}}', | |
| 525 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-tc:after' => 'background: {{VALUE}}' | |
| 526 | + ], | |
| 527 | + ] | |
| 528 | + ); | |
| 529 | + | |
| 530 | + $this->add_group_control( | |
| 531 | + Group_Control_Typography::get_type(), | |
| 532 | + [ | |
| 533 | + 'name' => 'infow_window_title_typography', | |
| 534 | + 'label' => esc_html__('Title Typography', 'king-addons'), | |
| 535 | + 'fields_options' => [ | |
| 536 | + 'typography' => [ | |
| 537 | + 'default' => 'custom', | |
| 538 | + ], | |
| 539 | + 'font_size' => [ | |
| 540 | + 'default' => [ | |
| 541 | + 'size' => '19', | |
| 542 | + 'unit' => 'px', | |
| 543 | + ], | |
| 544 | + ], | |
| 545 | + 'font_weight' => [ | |
| 546 | + 'default' => '600', | |
| 547 | + ] | |
| 548 | + ], | |
| 549 | + 'selector' => '{{WRAPPER}} .king-addons-google-map .gm-style-iw-c .king-addons-gm-iwindow h3' | |
| 550 | + ] | |
| 551 | + ); | |
| 552 | + | |
| 553 | + $this->add_group_control( | |
| 554 | + Group_Control_Typography::get_type(), | |
| 555 | + [ | |
| 556 | + 'name' => 'infow_window_desc_typography', | |
| 557 | + 'label' => esc_html__('Description Typography', 'king-addons'), | |
| 558 | + 'fields_options' => [ | |
| 559 | + 'typography' => [ | |
| 560 | + 'default' => 'custom', | |
| 561 | + ], | |
| 562 | + 'font_size' => [ | |
| 563 | + 'default' => [ | |
| 564 | + 'size' => '14', | |
| 565 | + 'unit' => 'px', | |
| 566 | + ], | |
| 567 | + ], | |
| 568 | + 'font_weight' => [ | |
| 569 | + 'default' => '400', | |
| 570 | + ] | |
| 571 | + ], | |
| 572 | + 'selector' => '{{WRAPPER}} .king-addons-google-map .gm-style-iw-c .king-addons-gm-iwindow p' | |
| 573 | + ] | |
| 574 | + ); | |
| 575 | + | |
| 576 | + $this->add_responsive_control( | |
| 577 | + 'infow_window_padding', | |
| 578 | + [ | |
| 579 | + 'label' => esc_html__('Padding', 'king-addons'), | |
| 580 | + 'type' => Controls_Manager::DIMENSIONS, | |
| 581 | + 'size_units' => ['px'], | |
| 582 | + 'default' => [ | |
| 583 | + 'top' => 0, | |
| 584 | + 'right' => 15, | |
| 585 | + 'bottom' => 15, | |
| 586 | + 'left' => 15, | |
| 587 | + ], | |
| 588 | + 'selectors' => [ | |
| 589 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-c .king-addons-gm-iwindow' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| 590 | + ], | |
| 591 | + 'separator' => 'before', | |
| 592 | + ] | |
| 593 | + ); | |
| 594 | + | |
| 595 | + $this->add_control( | |
| 596 | + 'infow_window_radius', | |
| 597 | + [ | |
| 598 | + 'label' => esc_html__('Border Radius', 'king-addons'), | |
| 599 | + 'type' => Controls_Manager::DIMENSIONS, | |
| 600 | + 'size_units' => ['px'], | |
| 601 | + 'default' => [ | |
| 602 | + 'top' => 5, | |
| 603 | + 'right' => 5, | |
| 604 | + 'bottom' => 5, | |
| 605 | + 'left' => 5, | |
| 606 | + ], | |
| 607 | + 'selectors' => [ | |
| 608 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-c' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| 609 | + ], | |
| 610 | + ] | |
| 611 | + ); | |
| 612 | + | |
| 613 | + $this->add_control( | |
| 614 | + 'infow_window_distance', | |
| 615 | + [ | |
| 616 | + 'label' => esc_html__('Distance from Marker', 'king-addons'), | |
| 617 | + 'type' => Controls_Manager::SLIDER, | |
| 618 | + 'default' => [ | |
| 619 | + 'size' => 10, | |
| 620 | + ], | |
| 621 | + 'range' => [ | |
| 622 | + 'px' => [ | |
| 623 | + 'min' => 0, | |
| 624 | + 'max' => 30, | |
| 625 | + ], | |
| 626 | + ], | |
| 627 | + 'selectors' => [ | |
| 628 | + '{{WRAPPER}} .king-addons-google-map .gm-style-iw-a' => 'transform: translateY(-{{SIZE}}px);', | |
| 629 | + ], | |
| 630 | + 'separator' => 'before' | |
| 631 | + ] | |
| 632 | + ); | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | +$this->end_controls_section(); | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + } | |
| 642 | + | |
| 643 | + public function get_map_settings($settings) { | |
| 644 | + $map_settings = [ | |
| 645 | + 'type' => $settings['gm_type'], | |
| 646 | + 'style' => $settings['gm_color_scheme'], | |
| 647 | + 'zoom_depth' => $settings['gm_zoom_depth']['size'], | |
| 648 | + 'zoom_on_scroll' => $settings['gm_zoom_on_scroll'], | |
| 649 | + 'cluster_markers'=> $settings['gm_cluster_markers'], | |
| 650 | + 'clusters_url' => KING_ADDONS_URL . 'includes/assets/libraries/markerclusterer/clusters/m', | |
| 651 | + ]; | |
| 652 | + | |
| 653 | + // Only set custom_style if it's not an array | |
| 654 | + if (!is_array($settings['gm_custom_color_scheme'])) { | |
| 655 | + $map_settings['custom_style'] = preg_replace( | |
| 656 | + '/\s/', | |
| 657 | + '', | |
| 658 | + strip_tags($settings['gm_custom_color_scheme']) | |
| 659 | + ); | |
| 660 | + } | |
| 661 | + | |
| 662 | + return $map_settings; | |
| 663 | + } | |
| 664 | + | |
| 665 | + public function get_map_controls($settings) { | |
| 666 | + return [ | |
| 667 | + 'type' => $settings['gm_controls_map_type'], | |
| 668 | + 'fullscreen' => $settings['gm_controls_fullscreen'], | |
| 669 | + 'zoom' => $settings['gm_controls_zoom'], | |
| 670 | + 'streetview' => $settings['gm_controls_street_view'], | |
| 671 | + ]; | |
| 672 | + } | |
| 673 | + | |
| 674 | + protected function render() { | |
| 675 | + $settings = Core::displaySettings($this); | |
| 676 | + $locations = $settings['google_map_locations'] ?? []; | |
| 677 | + | |
| 678 | + // Sanitize the first location's title (if it exists) | |
| 679 | + if (!empty($locations[0]['gm_location_title'])) { | |
| 680 | + $title = $locations[0]['gm_location_title']; | |
| 681 | + $title = preg_replace('/<\s*(img|script)[^>]*>/i', '', $title); | |
| 682 | + $title = preg_replace('/\s*on\w+="[^"]*"/i', '', $title); | |
| 683 | + $title = htmlspecialchars($title, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); | |
| 684 | + $locations[0]['gm_location_title'] = $title; | |
| 685 | + } | |
| 686 | + | |
| 687 | + // Convert arrays to JSON | |
| 688 | + $map_settings_json = json_encode( | |
| 689 | + $this->get_map_settings($settings), | |
| 690 | + JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | |
| 691 | + ); | |
| 692 | + $map_locations_json = json_encode( | |
| 693 | + $locations, | |
| 694 | + JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | |
| 695 | + ); | |
| 696 | + $map_controls_json = json_encode( | |
| 697 | + $this->get_map_controls($settings), | |
| 698 | + JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | |
| 699 | + ); | |
| 700 | + | |
| 701 | + // Build attributes for the map container | |
| 702 | + $attributes = sprintf( | |
| 703 | + ' data-settings="%s" data-locations="%s" data-controls="%s"', | |
| 704 | + esc_attr($map_settings_json), | |
| 705 | + esc_attr($map_locations_json), | |
| 706 | + esc_attr($map_controls_json) | |
| 707 | + ); | |
| 708 | + | |
| 709 | + echo '<div class="king-addons-google-map"' . $attributes . '></div>'; | |
| 710 | + | |
| 711 | + // Alert if no Google Map API Key is set | |
| 712 | + if (current_user_can('manage_options') && !get_option('king_addons_google_map_api_key')) { | |
| 713 | + /** @noinspection HtmlUnknownTarget */ | |
| 714 | + printf( | |
| 715 | + '<p class="king-addons-api-key-missing">Please go to the plugin <a href="%s" target="_blank">Settings</a> and insert a Google Map API Key to enable Google Maps.</p>', | |
| 716 | + esc_url(admin_url('admin.php?page=king-addons-settings')) | |
| 717 | + ); | |
| 718 | + } | |
| 719 | + } | |
| 720 | +} | |