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

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