google-maps.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. namespace Elementor;
  3. use Elementor\Modules\DynamicTags\Module as TagsModule;
  4. if ( ! defined( 'ABSPATH' ) ) {
  5. exit; // Exit if accessed directly.
  6. }
  7. /**
  8. * Elementor google maps widget.
  9. *
  10. * Elementor widget that displays an embedded google map.
  11. *
  12. * @since 1.0.0
  13. */
  14. class Widget_Google_Maps extends Widget_Base {
  15. /**
  16. * Get widget name.
  17. *
  18. * Retrieve google maps widget name.
  19. *
  20. * @since 1.0.0
  21. * @access public
  22. *
  23. * @return string Widget name.
  24. */
  25. public function get_name() {
  26. return 'google_maps';
  27. }
  28. /**
  29. * Get widget title.
  30. *
  31. * Retrieve google maps widget title.
  32. *
  33. * @since 1.0.0
  34. * @access public
  35. *
  36. * @return string Widget title.
  37. */
  38. public function get_title() {
  39. return __( 'Google Maps', 'elementor' );
  40. }
  41. /**
  42. * Get widget icon.
  43. *
  44. * Retrieve google maps widget icon.
  45. *
  46. * @since 1.0.0
  47. * @access public
  48. *
  49. * @return string Widget icon.
  50. */
  51. public function get_icon() {
  52. return 'eicon-google-maps';
  53. }
  54. /**
  55. * Get widget categories.
  56. *
  57. * Retrieve the list of categories the google maps widget belongs to.
  58. *
  59. * Used to determine where to display the widget in the editor.
  60. *
  61. * @since 2.0.0
  62. * @access public
  63. *
  64. * @return array Widget categories.
  65. */
  66. public function get_categories() {
  67. return [ 'basic' ];
  68. }
  69. /**
  70. * Get widget keywords.
  71. *
  72. * Retrieve the list of keywords the widget belongs to.
  73. *
  74. * @since 2.1.0
  75. * @access public
  76. *
  77. * @return array Widget keywords.
  78. */
  79. public function get_keywords() {
  80. return [ 'google', 'map', 'embed' ];
  81. }
  82. /**
  83. * Register google maps widget controls.
  84. *
  85. * Adds different input fields to allow the user to change and customize the widget settings.
  86. *
  87. * @since 1.0.0
  88. * @access protected
  89. */
  90. protected function _register_controls() {
  91. $this->start_controls_section(
  92. 'section_map',
  93. [
  94. 'label' => __( 'Map', 'elementor' ),
  95. ]
  96. );
  97. $default_address = __( 'London Eye, London, United Kingdom', 'elementor' );
  98. $this->add_control(
  99. 'address',
  100. [
  101. 'label' => __( 'Address', 'elementor' ),
  102. 'type' => Controls_Manager::TEXT,
  103. 'dynamic' => [
  104. 'active' => true,
  105. 'categories' => [
  106. TagsModule::POST_META_CATEGORY,
  107. ],
  108. ],
  109. 'placeholder' => $default_address,
  110. 'default' => $default_address,
  111. 'label_block' => true,
  112. ]
  113. );
  114. $this->add_control(
  115. 'zoom',
  116. [
  117. 'label' => __( 'Zoom', 'elementor' ),
  118. 'type' => Controls_Manager::SLIDER,
  119. 'default' => [
  120. 'size' => 10,
  121. ],
  122. 'range' => [
  123. 'px' => [
  124. 'min' => 1,
  125. 'max' => 20,
  126. ],
  127. ],
  128. 'separator' => 'before',
  129. ]
  130. );
  131. $this->add_responsive_control(
  132. 'height',
  133. [
  134. 'label' => __( 'Height', 'elementor' ),
  135. 'type' => Controls_Manager::SLIDER,
  136. 'range' => [
  137. 'px' => [
  138. 'min' => 40,
  139. 'max' => 1440,
  140. ],
  141. ],
  142. 'selectors' => [
  143. '{{WRAPPER}} iframe' => 'height: {{SIZE}}{{UNIT}};',
  144. ],
  145. ]
  146. );
  147. $this->add_control(
  148. 'prevent_scroll',
  149. [
  150. 'label' => __( 'Prevent Scroll', 'elementor' ),
  151. 'type' => Controls_Manager::SWITCHER,
  152. 'default' => 'yes',
  153. 'selectors' => [
  154. '{{WRAPPER}} iframe' => 'pointer-events: none;',
  155. ],
  156. ]
  157. );
  158. $this->add_control(
  159. 'view',
  160. [
  161. 'label' => __( 'View', 'elementor' ),
  162. 'type' => Controls_Manager::HIDDEN,
  163. 'default' => 'traditional',
  164. ]
  165. );
  166. $this->end_controls_section();
  167. $this->start_controls_section(
  168. 'section_map_style',
  169. [
  170. 'label' => __( 'Map', 'elementor' ),
  171. 'tab' => Controls_Manager::TAB_STYLE,
  172. ]
  173. );
  174. $this->start_controls_tabs( 'map_filter' );
  175. $this->start_controls_tab( 'normal',
  176. [
  177. 'label' => __( 'Normal', 'elementor' ),
  178. ]
  179. );
  180. $this->add_group_control(
  181. Group_Control_Css_Filter::get_type(),
  182. [
  183. 'name' => 'css_filters',
  184. 'selector' => '{{WRAPPER}} iframe',
  185. ]
  186. );
  187. $this->end_controls_tab();
  188. $this->start_controls_tab( 'hover',
  189. [
  190. 'label' => __( 'Hover', 'elementor' ),
  191. ]
  192. );
  193. $this->add_group_control(
  194. Group_Control_Css_Filter::get_type(),
  195. [
  196. 'name' => 'css_filters_hover',
  197. 'selector' => '{{WRAPPER}}:hover iframe',
  198. ]
  199. );
  200. $this->add_control(
  201. 'hover_transition',
  202. [
  203. 'label' => __( 'Transition Duration', 'elementor' ),
  204. 'type' => Controls_Manager::SLIDER,
  205. 'range' => [
  206. 'px' => [
  207. 'max' => 3,
  208. 'step' => 0.1,
  209. ],
  210. ],
  211. 'selectors' => [
  212. '{{WRAPPER}} iframe' => 'transition-duration: {{SIZE}}s',
  213. ],
  214. ]
  215. );
  216. $this->end_controls_tab();
  217. $this->end_controls_tabs();
  218. }
  219. /**
  220. * Render google maps widget output on the frontend.
  221. *
  222. * Written in PHP and used to generate the final HTML.
  223. *
  224. * @since 1.0.0
  225. * @access protected
  226. */
  227. protected function render() {
  228. $settings = $this->get_settings_for_display();
  229. if ( empty( $settings['address'] ) ) {
  230. return;
  231. }
  232. if ( 0 === absint( $settings['zoom']['size'] ) ) {
  233. $settings['zoom']['size'] = 10;
  234. }
  235. printf(
  236. '<div class="elementor-custom-embed"><iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=%s&amp;t=m&amp;z=%d&amp;output=embed&amp;iwloc=near" aria-label="%s"></iframe></div>',
  237. rawurlencode( $settings['address'] ),
  238. absint( $settings['zoom']['size'] ),
  239. esc_attr( $settings['address'] )
  240. );
  241. }
  242. /**
  243. * Render google maps widget output in the editor.
  244. *
  245. * Written as a Backbone JavaScript template and used to generate the live preview.
  246. *
  247. * @since 1.0.0
  248. * @access protected
  249. */
  250. protected function _content_template() {}
  251. }