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

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