PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.0-dev2
Elementor Website Builder – more than just a page builder v3.28.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.28.0-dev2, at includes/widgets/google-maps.php

329 lines 6.9 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 protected function is_dynamic_content(): bool {
92 return false;
93 }
94
95 /**
96 * Get style dependencies.
97 *
98 * Retrieve the list of style dependencies the widget requires.
99 *
100 * @since 3.24.0
101 * @access public
102 *
103 * @return array Widget style dependencies.
104 */
105 public function get_style_depends(): array {
106 return [ 'widget-google_maps' ];
107 }
108
109 public function has_widget_inner_wrapper(): bool {
110 return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
111 }
112
113 /**
114 * Register google maps widget controls.
115 *
116 * Adds different input fields to allow the user to change and customize the widget settings.
117 *
118 * @since 3.1.0
119 * @access protected
120 */
121 protected function register_controls() {
122 $this->start_controls_section(
123 'section_map',
124 [
125 'label' => esc_html__( 'Google Maps', 'elementor' ),
126 ]
127 );
128
129 if ( Plugin::$instance->editor->is_edit_mode() ) {
130 $api_key = get_option( 'elementor_google_maps_api_key' );
131
132 if ( ! $api_key ) {
133 $this->add_control(
134 'api_key_notification',
135 [
136 'type' => Controls_Manager::ALERT,
137 'alert_type' => 'info',
138 'content' => sprintf(
139 /* translators: 1: Integration settings link open tag, 2: Create API key link open tag, 3: Link close tag. */
140 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' ),
141 '<a href="' . Settings::get_settings_tab_url( 'integrations' ) . '" target="_blank">',
142 '<a href="https://developers.google.com/maps/documentation/embed/get-api-key" target="_blank">',
143 '</a>'
144 ),
145 ]
146 );
147 }
148 }
149
150 $default_address = esc_html__( 'London Eye, London, United Kingdom', 'elementor' );
151 $this->add_control(
152 'address',
153 [
154 'label' => esc_html__( 'Location', 'elementor' ),
155 'type' => Controls_Manager::TEXT,
156 'dynamic' => [
157 'active' => true,
158 'categories' => [
159 TagsModule::POST_META_CATEGORY,
160 ],
161 ],
162 'ai' => [
163 'active' => false,
164 ],
165 'placeholder' => $default_address,
166 'default' => $default_address,
167 'label_block' => true,
168 ]
169 );
170
171 $this->add_control(
172 'zoom',
173 [
174 'label' => esc_html__( 'Zoom', 'elementor' ),
175 'type' => Controls_Manager::SLIDER,
176 'default' => [
177 'size' => 10,
178 ],
179 'range' => [
180 'px' => [
181 'min' => 1,
182 'max' => 20,
183 ],
184 ],
185 'separator' => 'before',
186 ]
187 );
188
189 $this->add_responsive_control(
190 'height',
191 [
192 'label' => esc_html__( 'Height', 'elementor' ),
193 'type' => Controls_Manager::SLIDER,
194 'range' => [
195 'px' => [
196 'min' => 40,
197 'max' => 1440,
198 ],
199 ],
200 'size_units' => [ 'px', 'em', 'rem', 'vh', 'custom' ],
201 'selectors' => [
202 '{{WRAPPER}} iframe' => 'height: {{SIZE}}{{UNIT}};',
203 ],
204 ]
205 );
206
207 $this->end_controls_section();
208
209 $this->start_controls_section(
210 'section_map_style',
211 [
212 'label' => esc_html__( 'Google Maps', 'elementor' ),
213 'tab' => Controls_Manager::TAB_STYLE,
214 ]
215 );
216
217 $this->start_controls_tabs( 'map_filter' );
218
219 $this->start_controls_tab( 'normal',
220 [
221 'label' => esc_html__( 'Normal', 'elementor' ),
222 ]
223 );
224
225 $this->add_group_control(
226 Group_Control_Css_Filter::get_type(),
227 [
228 'name' => 'css_filters',
229 'selector' => '{{WRAPPER}} iframe',
230 ]
231 );
232
233 $this->end_controls_tab();
234
235 $this->start_controls_tab( 'hover',
236 [
237 'label' => esc_html__( 'Hover', 'elementor' ),
238 ]
239 );
240
241 $this->add_group_control(
242 Group_Control_Css_Filter::get_type(),
243 [
244 'name' => 'css_filters_hover',
245 'selector' => '{{WRAPPER}}:hover iframe',
246 ]
247 );
248
249 $this->add_control(
250 'hover_transition',
251 [
252 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (s)',
253 'type' => Controls_Manager::SLIDER,
254 'range' => [
255 'px' => [
256 'min' => 0,
257 'max' => 3,
258 'step' => 0.1,
259 ],
260 ],
261 'selectors' => [
262 '{{WRAPPER}} iframe' => 'transition-duration: {{SIZE}}s',
263 ],
264 ]
265 );
266
267 $this->end_controls_tab();
268
269 $this->end_controls_tabs();
270
271 $this->end_controls_section();
272 }
273
274 /**
275 * Render google maps widget output on the frontend.
276 *
277 * Written in PHP and used to generate the final HTML.
278 *
279 * @since 1.0.0
280 * @access protected
281 */
282 protected function render() {
283 $settings = $this->get_settings_for_display();
284
285 if ( empty( $settings['address'] ) ) {
286 return;
287 }
288
289 if ( 0 === absint( $settings['zoom']['size'] ) ) {
290 $settings['zoom']['size'] = 10;
291 }
292
293 $api_key = esc_html( get_option( 'elementor_google_maps_api_key' ) );
294
295 $params = [
296 rawurlencode( $settings['address'] ),
297 absint( $settings['zoom']['size'] ),
298 ];
299
300 if ( $api_key ) {
301 $params[] = $api_key;
302
303 $url = 'https://www.google.com/maps/embed/v1/place?key=%3$s&q=%1$s&amp;zoom=%2$d';
304 } else {
305 $url = 'https://maps.google.com/maps?q=%1$s&amp;t=m&amp;z=%2$d&amp;output=embed&amp;iwloc=near';
306 }
307
308 ?>
309 <div class="elementor-custom-embed">
310 <iframe loading="lazy"
311 src="<?php echo esc_url( vsprintf( $url, $params ) ); ?>"
312 title="<?php echo esc_attr( $settings['address'] ); ?>"
313 aria-label="<?php echo esc_attr( $settings['address'] ); ?>"
314 ></iframe>
315 </div>
316 <?php
317 }
318
319 /**
320 * Render google maps widget output in the editor.
321 *
322 * Written as a Backbone JavaScript template and used to generate the live preview.
323 *
324 * @since 2.9.0
325 * @access protected
326 */
327 protected function content_template() {}
328 }
329