PluginProbe
Elementor Website Builder – more than just a page builder / 3.20.0-dev2
Elementor Website Builder – more than just a page builder v3.20.0-dev2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / google-maps.php

google-maps.php in Elementor Website Builder – more than just a page builder 3.20.0-dev2, at includes/widgets/google-maps.php

307 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 use Elementor\Modules\DynamicTags\Module as TagsModule;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor google maps widget.
12 *
13 * Elementor widget that displays an embedded google map.
14 *
15 * @since 1.0.0
16 */
17 class Widget_Google_Maps extends Widget_Base {
18
19 /**
20 * Get widget name.
21 *
22 * Retrieve google maps widget name.
23 *
24 * @since 1.0.0
25 * @access public
26 *
27 * @return string Widget name.
28 */
29 public function get_name() {
30 return 'google_maps';
31 }
32
33 /**
34 * Get widget title.
35 *
36 * Retrieve google maps widget title.
37 *
38 * @since 1.0.0
39 * @access public
40 *
41 * @return string Widget title.
42 */
43 public function get_title() {
44 return esc_html__( 'Google Maps', 'elementor' );
45 }
46
47 /**
48 * Get widget icon.
49 *
50 * Retrieve google maps widget icon.
51 *
52 * @since 1.0.0
53 * @access public
54 *
55 * @return string Widget icon.
56 */
57 public function get_icon() {
58 return 'eicon-google-maps';
59 }
60
61 /**
62 * Get widget categories.
63 *
64 * Retrieve the list of categories the google maps widget belongs to.
65 *
66 * Used to determine where to display the widget in the editor.
67 *
68 * @since 2.0.0
69 * @access public
70 *
71 * @return array Widget categories.
72 */
73 public function get_categories() {
74 return [ 'basic' ];
75 }
76
77 /**
78 * Get widget keywords.
79 *
80 * Retrieve the list of keywords the widget belongs to.
81 *
82 * @since 2.1.0
83 * @access public
84 *
85 * @return array Widget keywords.
86 */
87 public function get_keywords() {
88 return [ 'google', 'map', 'embed', 'location' ];
89 }
90
91 /**
92 * Register google maps widget controls.
93 *
94 * Adds different input fields to allow the user to change and customize the widget settings.
95 *
96 * @since 3.1.0
97 * @access protected
98 */
99 protected function register_controls() {
100 $this->start_controls_section(
101 'section_map',
102 [
103 'label' => esc_html__( 'Google Maps', 'elementor' ),
104 ]
105 );
106
107 if ( Plugin::$instance->editor->is_edit_mode() ) {
108 $api_key = get_option( 'elementor_google_maps_api_key' );
109
110 if ( ! $api_key ) {
111 $this->add_control(
112 'api_key_notification',
113 [
114 'type' => Controls_Manager::ALERT,
115 'alert_type' => 'info',
116 'content' => sprintf(
117 /* translators: 1: Integration settings link open tag, 2: Create API key link open tag, 3: Link close tag. */
118 esc_html__( 'Set your Google Maps API Key in Elementor\'s %1$sIntegrations Settings%3$s page. Create your key %2$shere.%3$s', 'elementor' ),
119 '<a href="' . Settings::get_url() . '#tab-integrations" target="_blank">',
120 '<a href="https://developers.google.com/maps/documentation/embed/get-api-key" target="_blank">',
121 '</a>'
122 ),
123 ]
124 );
125 }
126 }
127
128 $default_address = esc_html__( 'London Eye, London, United Kingdom', 'elementor' );
129 $this->add_control(
130 'address',
131 [
132 'label' => esc_html__( 'Location', 'elementor' ),
133 'type' => Controls_Manager::TEXT,
134 'dynamic' => [
135 'active' => true,
136 'categories' => [
137 TagsModule::POST_META_CATEGORY,
138 ],
139 ],
140 'ai' => [
141 'active' => false,
142 ],
143 'placeholder' => $default_address,
144 'default' => $default_address,
145 'label_block' => true,
146 ]
147 );
148
149 $this->add_control(
150 'zoom',
151 [
152 'label' => esc_html__( 'Zoom', 'elementor' ),
153 'type' => Controls_Manager::SLIDER,
154 'default' => [
155 'size' => 10,
156 ],
157 'range' => [
158 'px' => [
159 'min' => 1,
160 'max' => 20,
161 ],
162 ],
163 'separator' => 'before',
164 ]
165 );
166
167 $this->add_responsive_control(
168 'height',
169 [
170 'label' => esc_html__( 'Height', 'elementor' ),
171 'type' => Controls_Manager::SLIDER,
172 'range' => [
173 'px' => [
174 'min' => 40,
175 'max' => 1440,
176 ],
177 ],
178 'size_units' => [ 'px', 'em', 'rem', 'vh', 'custom' ],
179 'selectors' => [
180 '{{WRAPPER}} iframe' => 'height: {{SIZE}}{{UNIT}};',
181 ],
182 ]
183 );
184
185 $this->end_controls_section();
186
187 $this->start_controls_section(
188 'section_map_style',
189 [
190 'label' => esc_html__( 'Google Maps', 'elementor' ),
191 'tab' => Controls_Manager::TAB_STYLE,
192 ]
193 );
194
195 $this->start_controls_tabs( 'map_filter' );
196
197 $this->start_controls_tab( 'normal',
198 [
199 'label' => esc_html__( 'Normal', 'elementor' ),
200 ]
201 );
202
203 $this->add_group_control(
204 Group_Control_Css_Filter::get_type(),
205 [
206 'name' => 'css_filters',
207 'selector' => '{{WRAPPER}} iframe',
208 ]
209 );
210
211 $this->end_controls_tab();
212
213 $this->start_controls_tab( 'hover',
214 [
215 'label' => esc_html__( 'Hover', 'elementor' ),
216 ]
217 );
218
219 $this->add_group_control(
220 Group_Control_Css_Filter::get_type(),
221 [
222 'name' => 'css_filters_hover',
223 'selector' => '{{WRAPPER}}:hover iframe',
224 ]
225 );
226
227 $this->add_control(
228 'hover_transition',
229 [
230 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (s)',
231 'type' => Controls_Manager::SLIDER,
232 'range' => [
233 'px' => [
234 'min' => 0,
235 'max' => 3,
236 'step' => 0.1,
237 ],
238 ],
239 'selectors' => [
240 '{{WRAPPER}} iframe' => 'transition-duration: {{SIZE}}s',
241 ],
242 ]
243 );
244
245 $this->end_controls_tab();
246
247 $this->end_controls_tabs();
248
249 $this->end_controls_section();
250 }
251
252 /**
253 * Render google maps widget output on the frontend.
254 *
255 * Written in PHP and used to generate the final HTML.
256 *
257 * @since 1.0.0
258 * @access protected
259 */
260 protected function render() {
261 $settings = $this->get_settings_for_display();
262
263 if ( empty( $settings['address'] ) ) {
264 return;
265 }
266
267 if ( 0 === absint( $settings['zoom']['size'] ) ) {
268 $settings['zoom']['size'] = 10;
269 }
270
271 $api_key = esc_html( get_option( 'elementor_google_maps_api_key' ) );
272
273 $params = [
274 rawurlencode( $settings['address'] ),
275 absint( $settings['zoom']['size'] ),
276 ];
277
278 if ( $api_key ) {
279 $params[] = $api_key;
280
281 $url = 'https://www.google.com/maps/embed/v1/place?key=%3$s&q=%1$s&amp;zoom=%2$d';
282 } else {
283 $url = 'https://maps.google.com/maps?q=%1$s&amp;t=m&amp;z=%2$d&amp;output=embed&amp;iwloc=near';
284 }
285
286 ?>
287 <div class="elementor-custom-embed">
288 <iframe loading="lazy"
289 src="<?php echo esc_url( vsprintf( $url, $params ) ); ?>"
290 title="<?php echo esc_attr( $settings['address'] ); ?>"
291 aria-label="<?php echo esc_attr( $settings['address'] ); ?>"
292 ></iframe>
293 </div>
294 <?php
295 }
296
297 /**
298 * Render google maps widget output in the editor.
299 *
300 * Written as a Backbone JavaScript template and used to generate the live preview.
301 *
302 * @since 2.9.0
303 * @access protected
304 */
305 protected function content_template() {}
306 }
307