| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- namespace Elementor;
- use Elementor\Modules\DynamicTags\Module as TagsModule;
- if ( ! defined( 'ABSPATH' ) ) {
- exit; // Exit if accessed directly.
- }
- /**
- * Elementor google maps widget.
- *
- * Elementor widget that displays an embedded google map.
- *
- * @since 1.0.0
- */
- class Widget_Google_Maps extends Widget_Base {
- /**
- * Get widget name.
- *
- * Retrieve google maps widget name.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget name.
- */
- public function get_name() {
- return 'google_maps';
- }
- /**
- * Get widget title.
- *
- * Retrieve google maps widget title.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget title.
- */
- public function get_title() {
- return __( 'Google Maps', 'elementor' );
- }
- /**
- * Get widget icon.
- *
- * Retrieve google maps widget icon.
- *
- * @since 1.0.0
- * @access public
- *
- * @return string Widget icon.
- */
- public function get_icon() {
- return 'eicon-google-maps';
- }
- /**
- * Get widget categories.
- *
- * Retrieve the list of categories the google maps widget belongs to.
- *
- * Used to determine where to display the widget in the editor.
- *
- * @since 2.0.0
- * @access public
- *
- * @return array Widget categories.
- */
- public function get_categories() {
- return [ 'basic' ];
- }
- /**
- * Get widget keywords.
- *
- * Retrieve the list of keywords the widget belongs to.
- *
- * @since 2.1.0
- * @access public
- *
- * @return array Widget keywords.
- */
- public function get_keywords() {
- return [ 'google', 'map', 'embed' ];
- }
- /**
- * Register google maps widget controls.
- *
- * Adds different input fields to allow the user to change and customize the widget settings.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function _register_controls() {
- $this->start_controls_section(
- 'section_map',
- [
- 'label' => __( 'Map', 'elementor' ),
- ]
- );
- $default_address = __( 'London Eye, London, United Kingdom', 'elementor' );
- $this->add_control(
- 'address',
- [
- 'label' => __( 'Address', 'elementor' ),
- 'type' => Controls_Manager::TEXT,
- 'dynamic' => [
- 'active' => true,
- 'categories' => [
- TagsModule::POST_META_CATEGORY,
- ],
- ],
- 'placeholder' => $default_address,
- 'default' => $default_address,
- 'label_block' => true,
- ]
- );
- $this->add_control(
- 'zoom',
- [
- 'label' => __( 'Zoom', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'default' => [
- 'size' => 10,
- ],
- 'range' => [
- 'px' => [
- 'min' => 1,
- 'max' => 20,
- ],
- ],
- 'separator' => 'before',
- ]
- );
- $this->add_responsive_control(
- 'height',
- [
- 'label' => __( 'Height', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'min' => 40,
- 'max' => 1440,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} iframe' => 'height: {{SIZE}}{{UNIT}};',
- ],
- ]
- );
- $this->add_control(
- 'prevent_scroll',
- [
- 'label' => __( 'Prevent Scroll', 'elementor' ),
- 'type' => Controls_Manager::SWITCHER,
- 'default' => 'yes',
- 'selectors' => [
- '{{WRAPPER}} iframe' => 'pointer-events: none;',
- ],
- ]
- );
- $this->add_control(
- 'view',
- [
- 'label' => __( 'View', 'elementor' ),
- 'type' => Controls_Manager::HIDDEN,
- 'default' => 'traditional',
- ]
- );
- $this->end_controls_section();
- $this->start_controls_section(
- 'section_map_style',
- [
- 'label' => __( 'Map', 'elementor' ),
- 'tab' => Controls_Manager::TAB_STYLE,
- ]
- );
- $this->start_controls_tabs( 'map_filter' );
- $this->start_controls_tab( 'normal',
- [
- 'label' => __( 'Normal', 'elementor' ),
- ]
- );
- $this->add_group_control(
- Group_Control_Css_Filter::get_type(),
- [
- 'name' => 'css_filters',
- 'selector' => '{{WRAPPER}} iframe',
- ]
- );
- $this->end_controls_tab();
- $this->start_controls_tab( 'hover',
- [
- 'label' => __( 'Hover', 'elementor' ),
- ]
- );
- $this->add_group_control(
- Group_Control_Css_Filter::get_type(),
- [
- 'name' => 'css_filters_hover',
- 'selector' => '{{WRAPPER}}:hover iframe',
- ]
- );
- $this->add_control(
- 'hover_transition',
- [
- 'label' => __( 'Transition Duration', 'elementor' ),
- 'type' => Controls_Manager::SLIDER,
- 'range' => [
- 'px' => [
- 'max' => 3,
- 'step' => 0.1,
- ],
- ],
- 'selectors' => [
- '{{WRAPPER}} iframe' => 'transition-duration: {{SIZE}}s',
- ],
- ]
- );
- $this->end_controls_tab();
- $this->end_controls_tabs();
- }
- /**
- * Render google maps widget output on the frontend.
- *
- * Written in PHP and used to generate the final HTML.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function render() {
- $settings = $this->get_settings_for_display();
- if ( empty( $settings['address'] ) ) {
- return;
- }
- if ( 0 === absint( $settings['zoom']['size'] ) ) {
- $settings['zoom']['size'] = 10;
- }
- printf(
- '<div class="elementor-custom-embed"><iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=%s&t=m&z=%d&output=embed&iwloc=near" aria-label="%s"></iframe></div>',
- rawurlencode( $settings['address'] ),
- absint( $settings['zoom']['size'] ),
- esc_attr( $settings['address'] )
- );
- }
- /**
- * Render google maps widget output in the editor.
- *
- * Written as a Backbone JavaScript template and used to generate the live preview.
- *
- * @since 1.0.0
- * @access protected
- */
- protected function _content_template() {}
- }
|