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

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