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

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