Layers_Contact_Widget

The Layers Layers Contact Widget class.

Defined (1)

The class is defined in the following location(s).

/core/widgets/modules/contact.php  
  1. class Layers_Contact_Widget extends Layers_Widget { 
  2.  
  3. /** 
  4. * Widget construction 
  5. */ 
  6. function __construct() { 
  7.  
  8. /** 
  9. * Widget variables 
  10. * @param string $widget_title Widget title 
  11. * @param string $widget_id Widget slug for use as an ID/classname 
  12. * @param string $post_type (optional) Post type for use in widget options 
  13. * @param string $taxonomy (optional) Taxonomy slug for use as an ID/classname 
  14. * @param array $checkboxes (optional) Array of checkbox names to be saved in this widget. Don't forget these please! 
  15. */ 
  16. $this->widget_title = __( 'Contact Details & Maps' , 'layerswp' ); 
  17. $this->widget_id = 'map'; 
  18. $this->post_type = ''; 
  19. $this->taxonomy = ''; 
  20. $this->checkboxes = array( 
  21. 'show_google_map',  
  22. 'show_address',  
  23. 'show_contact_form' 
  24. ); 
  25.  
  26. /** Widget settings. */ 
  27. $widget_ops = array( 
  28. 'classname' => 'obox-layers-' . $this->widget_id .'-widget',  
  29. 'description' => __( 'This widget is used to display your ', 'layerswp' ) . $this->widget_title . '.',  
  30. 'customize_selective_refresh' => TRUE,  
  31. ); 
  32.  
  33. /** Widget control settings. */ 
  34. $control_ops = array( 
  35. 'width' => LAYERS_WIDGET_WIDTH_SMALL,  
  36. 'height' => NULL,  
  37. 'id_base' => LAYERS_THEME_SLUG . '-widget-' . $this->widget_id 
  38. ); 
  39.  
  40. /** Create the widget. */ 
  41. parent::__construct( LAYERS_THEME_SLUG . '-widget-' . $this->widget_id ,  
  42. $this->widget_title,  
  43. $widget_ops,  
  44. $control_ops 
  45. ); 
  46.  
  47. /** Setup Widget Defaults */ 
  48. $this->defaults = array ( 
  49. 'title' => __( 'Find Us', 'layerswp' ),  
  50. 'excerpt' => __( 'We are based in one of the most beautiful places on earth. Come visit us!', 'layerswp' ),  
  51. 'contact_form' => NULL,  
  52. 'address_shown' => NULL,  
  53. 'show_google_map' => 'on',  
  54. 'show_address' => 'on',  
  55. 'show_contact_form' => 'on',  
  56. 'google_maps_location' => NULL,  
  57. 'google_maps_long_lat' => NULL,  
  58. 'google_maps_zoom' => 14,  
  59. 'map_height' => 400,  
  60. 'design' => array( 
  61. 'layout' => 'layout-boxed',  
  62. 'background' => array( 
  63. 'position' => 'center',  
  64. 'repeat' => 'no-repeat' 
  65. ),  
  66. 'fonts' => array( 
  67. 'align' => 'text-center',  
  68. 'size' => 'medium',  
  69. 'color' => NULL,  
  70. 'shadow' => NULL,  
  71. 'heading-type' => 'h3',  
  72. ); 
  73.  
  74. /** 
  75. * Widget front end display 
  76. */ 
  77. function widget( $args, $instance ) { 
  78. global $wp_customize; 
  79.  
  80. $this->backup_inline_css(); 
  81.  
  82. // Turn $args array into variables. 
  83. extract( $args ); 
  84.  
  85. // Use defaults if $instance is empty. 
  86. if( empty( $instance ) && ! empty( $this->defaults ) ) { 
  87. $instance = wp_parse_args( $instance, $this->defaults ); 
  88.  
  89. // Mix in new/unset defaults on every instance load (NEW) 
  90. $instance = $this->apply_defaults( $instance ); 
  91.  
  92. // Check if we have a map present 
  93. if( isset( $instance['show_google_map'] ) && ( '' != $instance['google_maps_location'] || '' != $instance['google_maps_long_lat'] ) ) { 
  94. $hasmap = true; 
  95.  
  96. // Set the background styling 
  97. if( !empty( $instance['design'][ 'background' ] ) ) $this->inline_css .= layers_inline_styles( '#' . $widget_id, 'background', array( 'background' => $instance['design'][ 'background' ] ) ); 
  98. if( !empty( $instance['design']['fonts'][ 'color' ] ) ) $this->inline_css .= layers_inline_styles( '#' . $widget_id, 'color', array( 'selectors' => array( '.section-title .heading' , '.section-title div.excerpt' , '.section-title small', '.form.content' , 'form p' , 'form label' ) , 'color' => $instance['design']['fonts'][ 'color' ] ) ); 
  99.  
  100. // Set the map & form widths 
  101. if( isset( $hasmap ) ) { 
  102. $form_class = 'span-6'; 
  103. } else { 
  104. $form_class = 'span-12'; 
  105. $mapwidth = 'span-12'; 
  106.  
  107. // Set Display Variables 
  108. $show_address_or_contactform = ( ( '' != $instance['address_shown'] && isset( $instance['show_address'] ) ) || ( $this->check_and_return( $instance, 'contact_form' ) && $this->check_and_return( $instance, 'show_contact_form' ) ) ) ? TRUE : FALSE ; 
  109. $show_title_or_excerpt = ( '' != $instance['title'] || '' != $instance['excerpt'] ) ? TRUE : FALSE ; 
  110.  
  111. // Apply the advanced widget styling 
  112. $this->apply_widget_advanced_styling( $widget_id, $instance ); 
  113.  
  114. /** 
  115. * Generate the widget container class 
  116. */ 
  117. $widget_container_class = array(); 
  118. $widget_container_class[] = 'widget'; 
  119. $widget_container_class[] = 'layers-contact-widget'; 
  120. $widget_container_class[] = 'clearfix'; 
  121. $widget_container_class[] = 'content-vertical-massive'; 
  122. $widget_container_class[] = 'layers-contact-widget'; 
  123. $widget_container_class[] = ( 'on' == $this->check_and_return( $instance , 'design', 'background', 'darken' ) ? 'darken' : '' ); 
  124. $widget_container_class[] = $this->check_and_return( $instance , 'design', 'advanced', 'customclass' ); // Apply custom class from design-bar's advanced control. 
  125. $widget_container_class[] = $this->get_widget_spacing_class( $instance ); 
  126.  
  127. if( !$show_title_or_excerpt && !$show_address_or_contactform ) $widget_container_class[] = 'no-inset-top no-inset-bottom'; 
  128.  
  129. $widget_container_class = apply_filters( 'layers_contact_widget_container_class' , $widget_container_class, $this, $instance ); 
  130. $widget_container_class = implode( ' ', $widget_container_class ); 
  131.  
  132. // Custom Anchor 
  133. echo $this->custom_anchor( $instance ); ?> 
  134.  
  135. <div id="<?php echo esc_attr( $widget_id ); ?>" class="<?php echo esc_attr( $widget_container_class ); ?>" <?php $this->selective_refresh_atts( $args ); ?>> 
  136.  
  137. <?php do_action( 'layers_before_contact_widget_inner', $this, $instance ); ?> 
  138.  
  139. <?php if( $show_title_or_excerpt ) { ?> 
  140. <div class="container clearfix"> 
  141. <?php /**f 
  142. * Generate the Section Title Classes 
  143. */ 
  144. $section_title_class = array(); 
  145. $section_title_class[] = 'section-title clearfix'; 
  146. $section_title_class[] = $this->check_and_return( $instance , 'design', 'fonts', 'size' ); 
  147. $section_title_class[] = $this->check_and_return( $instance , 'design', 'fonts', 'align' ); 
  148. $section_title_class[] = ( $this->check_and_return( $instance, 'design', 'background' , 'color' ) && 'dark' == layers_is_light_or_dark( $this->check_and_return( $instance, 'design', 'background' , 'color' ) ) ? 'invert' : '' ); 
  149. $section_title_class = implode( ' ', $section_title_class ); ?> 
  150. <div class="<?php echo $section_title_class; ?>"> 
  151. <?php if( '' != $this->check_and_return( $instance, 'title' ) ) { ?> 
  152. <<?php echo $this->check_and_return( $instance, 'design', 'fonts', 'heading-type' ); ?> class="heading"> 
  153. <?php echo $instance['title']; ?> 
  154. </<?php echo $this->check_and_return( $instance, 'design', 'fonts', 'heading-type' ); ?>> 
  155. <?php } ?> 
  156. <?php if( '' != $this->check_and_return( $instance, 'excerpt' ) ) { ?> 
  157. <div class="excerpt"><?php echo layers_the_content( $instance['excerpt'] ); ?></div> 
  158. <?php } ?> 
  159. </div> 
  160. </div> 
  161. <?php } // if title || excerpt ?> 
  162.  
  163. <?php /** 
  164. * Generate the Widget Body Class 
  165. */ 
  166. $widget_body_class = array(); 
  167. $widget_body_class[] = 'row'; 
  168. $widget_body_class[] = $this->get_widget_layout_class( $instance ); 
  169. $widget_body_class[] = ( $this->check_and_return( $instance, 'design', 'background' , 'color' ) && 'dark' == layers_is_light_or_dark( $this->check_and_return( $instance, 'design', 'background' , 'color' ) ) ? 'invert' : '' ); 
  170. $widget_body_class = implode( ' ', $widget_body_class ); ?> 
  171. <div class="<?php echo $widget_body_class; ?>"> 
  172. <?php if( $show_address_or_contactform ) {?> 
  173. <div class="column <?php echo $form_class; ?> form content"> 
  174. <?php if( $this->check_and_return( $instance, 'show_address' ) ) { ?> 
  175. <address class="copy"> 
  176. <p><?php echo $instance['address_shown']; ?></p> 
  177. </address> 
  178. <?php } ?> 
  179. <?php if( $this->check_and_return( $instance, 'contact_form' ) ) { ?> 
  180. <?php echo do_shortcode( $instance['contact_form'] ); ?> 
  181. <?php } ?> 
  182. </div> 
  183. <?php $mapwidth = 'span-6'; ?> 
  184. <?php } // if show_contact_form || address_shown ?> 
  185.  
  186. <?php if( isset( $hasmap ) ) { ?> 
  187. <div class="column no-push-bottom <?php echo esc_attr( $mapwidth ); ?>"> 
  188. <?php if ( isset( $wp_customize ) ) { ?> 
  189. <?php if( $this->check_and_return( $instance, 'google_maps_location' ) ) { 
  190. $map_center = $instance['google_maps_location']; 
  191. } else if( $this->check_and_return( $instance, 'google_maps_long_lat' ) ) { 
  192. $map_center = $instance['google_maps_long_lat']; 
  193. } ?> 
  194. <div class="layers-map" style="height: <?php echo esc_attr( $instance['map_height'] ); ?>px; overflow: hidden;"> 
  195. <img src="https://maps.googleapis.com/maps/api/staticmap?center=<?php echo esc_attr( $map_center ); ?>&zoom=<?php echo ( isset( $instance['google_maps_zoom'] ) ? $instance['google_maps_zoom'] : 14 ) ; ?>&size=1960x<?php echo ( isset( $instance['map_height'] ) && '' != $instance['map_height'] ) ? $instance['map_height'] : 400; ?>&scale=2&markers=color:red|<?php echo esc_attr( $map_center ); ?>" class="google-map-img" /> 
  196. </div> 
  197. <?php } else { ?> 
  198. <div class="layers-map" style="height: <?php echo esc_attr( $instance['map_height'] ); ?>px;" data-zoom-level="<?php echo ( isset( $instance['google_maps_zoom'] ) ? $instance['google_maps_zoom'] : 14 ); ?>" <?php if( '' != $instance['google_maps_location'] ) { ?>data-location="<?php echo $instance['google_maps_location']; ?>"<?php } ?> <?php if( '' != $instance['google_maps_long_lat'] ) { ?>data-longlat="<?php echo $instance['google_maps_long_lat']; ?>"<?php } ?>></div> 
  199. <?php } ?> 
  200. </div> 
  201. <?php } ?> 
  202. </div> 
  203.  
  204. <?php do_action( 'layers_after_contact_widget_inner', $this, $instance ); 
  205.  
  206. // Print the Inline Styles for this Widget 
  207. $this->print_inline_css(); ?> 
  208.  
  209. </div> 
  210.  
  211. <?php if ( !isset( $wp_customize ) ) { 
  212. wp_enqueue_script( LAYERS_THEME_SLUG . "-map-api" ); 
  213. wp_enqueue_script( LAYERS_THEME_SLUG . "-map-trigger" ); 
  214. } // Enqueue the map js 
  215.  
  216. /** 
  217. * Widget update 
  218. */ 
  219. function update($new_instance, $old_instance) { 
  220. if ( isset( $this->checkboxes ) ) { 
  221. foreach( $this->checkboxes as $cb ) { 
  222. if( isset( $old_instance[ $cb ] ) ) { 
  223. $old_instance[ $cb ] = strip_tags( $new_instance[ $cb ] ); 
  224. } // foreach checkboxes 
  225. } // if checkboxes 
  226. return $new_instance; 
  227.  
  228. /** 
  229. * Widget form 
  230. * We use regulage HTML here, it makes reading the widget much easier than if we used just php to echo all the HTML out. 
  231. */ 
  232. function form( $instance ) { 
  233.  
  234. // Use defaults if $instance is empty. 
  235. if( empty( $instance ) && ! empty( $this->defaults ) ) { 
  236. $instance = wp_parse_args( $instance, $this->defaults ); 
  237.  
  238. // Mix in new/unset defaults on every instance load (NEW) 
  239. $instance = $this->apply_defaults( $instance ); 
  240.  
  241. $this->design_bar( 
  242. 'side', // CSS Class Name 
  243. array( // Widget Object 
  244. 'name' => $this->get_layers_field_name( 'design' ),  
  245. 'id' => $this->get_layers_field_id( 'design' ),  
  246. 'widget_id' => $this->widget_id,  
  247. ),  
  248. $instance, // Widget Values 
  249. apply_filters( 'layers_map_widget_design_bar_components' , array( // Components 
  250. 'layout',  
  251. 'display' => array( 
  252. 'icon-css' => 'icon-display',  
  253. 'label' => __( 'Display', 'layerswp' ),  
  254. 'elements' => array( 
  255. 'show_google_map' => array( 
  256. 'type' => 'checkbox',  
  257. 'name' => $this->get_layers_field_name( 'show_google_map' ) ,  
  258. 'id' => $this->get_layers_field_id( 'show_google_map' ) ,  
  259. 'value' => ( isset( $instance['show_google_map'] ) ) ? $instance['show_google_map'] : NULL,  
  260. 'label' => __( 'Show Google Map' , 'layerswp' ),  
  261. ),  
  262. 'map_height' => array( 
  263. 'type' => 'number',  
  264. 'name' => $this->get_layers_field_name( 'map_height' ) ,  
  265. 'id' => $this->get_layers_field_id( 'map_height' ) ,  
  266. 'min' => 150,  
  267. 'max' => 1600,  
  268. 'value' => ( isset( $instance['map_height'] ) ) ? $instance['map_height'] : NULL,  
  269. 'label' => __( 'Map Height' , 'layerswp' ),  
  270. 'data' => array( 
  271. 'show-if-selector' => '#' . $this->get_layers_field_id( 'show_google_map' ),  
  272. 'show-if-value' => 'true',  
  273. ),  
  274. ),  
  275. 'google_maps_zoom' => array( 
  276. 'type' => 'select',  
  277. 'name' => $this->get_layers_field_name( 'google_maps_zoom' ) ,  
  278. 'id' => $this->get_layers_field_id( 'google_maps_zoom' ) ,  
  279. 'value' => ( isset( $instance['google_maps_zoom'] ) ) ? $instance['google_maps_zoom'] : NULL,  
  280. 'label' => __( 'Google Map Zoom Level' , 'layerswp' ),  
  281. 'options' => array( 
  282. '16' => __( 'Close', 'layerswp' ),  
  283. '14' => __( 'Default', 'layerswp' ),  
  284. '12' => __( 'Far', 'layerswp' ),  
  285. ),  
  286. 'data' => array( 
  287. 'show-if-selector' => '#' . $this->get_layers_field_id( 'show_google_map' ),  
  288. 'show-if-value' => 'true',  
  289. ),  
  290. ),  
  291. 'show_address' => array( 
  292. 'type' => 'checkbox',  
  293. 'name' => $this->get_layers_field_name( 'show_address' ) ,  
  294. 'id' => $this->get_layers_field_id( 'show_address' ) ,  
  295. 'value' => ( isset( $instance['show_address'] ) ) ? $instance['show_address'] : NULL,  
  296. 'label' => __( 'Show Address' , 'layerswp' ),  
  297. ),  
  298. 'show_contact_form' => array( 
  299. 'type' => 'checkbox',  
  300. 'name' => $this->get_layers_field_name( 'show_contact_form' ) ,  
  301. 'id' => $this->get_layers_field_id( 'show_contact_form' ) ,  
  302. 'value' => ( isset( $instance['show_contact_form'] ) ) ? $instance['show_contact_form'] : NULL,  
  303. 'label' => __( 'Show Contact Form' , 'layerswp' ),  
  304. ),  
  305. ),  
  306. ),  
  307. 'background',  
  308. 'advanced' 
  309. ) ) 
  310. ); ?> 
  311.  
  312. <div class="layers-container-large"> 
  313.  
  314. <?php $this->form_elements()->header( array( 
  315. 'title' => __( 'Contact' , 'layerswp' ),  
  316. 'icon_class' =>'location' 
  317. ) ); ?> 
  318.  
  319. <section class="layers-accordion-section layers-content"> 
  320. <div class="layers-row layers-push-bottom clearfix"> 
  321. <div class="layers-form-item"> 
  322.  
  323. <?php echo $this->form_elements()->input( 
  324. array( 
  325. 'type' => 'text',  
  326. 'name' => $this->get_layers_field_name( 'title' ) ,  
  327. 'id' => $this->get_layers_field_id( 'title' ) ,  
  328. 'placeholder' => __( 'Enter title here' , 'layerswp' ),  
  329. 'value' => ( isset( $instance['title'] ) ) ? $instance['title'] : NULL ,  
  330. 'class' => 'layers-text layers-large' 
  331. ); ?> 
  332.  
  333. <?php $this->design_bar( 
  334. 'top', // CSS Class Name 
  335. array( // Widget Object 
  336. 'name' => $this->get_layers_field_name( 'design' ),  
  337. 'id' => $this->get_layers_field_id( 'design' ),  
  338. 'widget_id' => $this->widget_id,  
  339. 'show_trash' => FALSE,  
  340. 'inline' => TRUE,  
  341. 'align' => 'right',  
  342. ),  
  343. $instance, // Widget Values 
  344. apply_filters( 'layers_map_widget_inline_design_bar_components', array( // Components 
  345. 'fonts',  
  346. ), $this, $instance ) 
  347. ); ?> 
  348.  
  349. </div> 
  350. <div class="layers-form-item"> 
  351.  
  352. <?php echo $this->form_elements()->input( 
  353. array( 
  354. 'type' => 'rte',  
  355. 'name' => $this->get_layers_field_name( 'excerpt' ) ,  
  356. 'id' => $this->get_layers_field_id( 'excerpt' ) ,  
  357. 'placeholder' => __( 'Short Excerpt' , 'layerswp' ),  
  358. 'value' => ( isset( $instance['excerpt'] ) ) ? $instance['excerpt'] : NULL ,  
  359. 'class' => 'layers-textarea layers-large' 
  360. ); ?> 
  361.  
  362. </div> 
  363. </div> 
  364. <div class="layers-row layers-push-bottom clearfix"> 
  365.  
  366. <p class="layers-form-item"> 
  367. <label for="<?php echo $this->get_layers_field_id( 'google_maps_location' ); ?>"><?php _e( 'Google Maps Location' , 'layerswp' ); ?></label> 
  368. <?php echo $this->form_elements()->input( 
  369. array( 
  370. 'type' => 'text',  
  371. 'name' => $this->get_layers_field_name( 'google_maps_location' ) ,  
  372. 'id' => $this->get_layers_field_id( 'google_maps_location' ) ,  
  373. 'placeholder' => __( 'e.g. 300 Prestwich Str, Cape Town, South Africa' , 'layerswp' ),  
  374. 'value' => ( isset( $instance['google_maps_location'] ) ) ? $instance['google_maps_location'] : NULL 
  375. ); ?> 
  376. </p> 
  377. <p class="layers-form-item"> 
  378. <label for="<?php echo $this->get_layers_field_id( 'google_maps_long_lat' ); ?>"><?php _e( 'Google Maps Latitude & Longitude (Optional)' , 'layerswp' ); ?></label> 
  379. <?php echo $this->form_elements()->input( 
  380. array( 
  381. 'type' => 'text',  
  382. 'name' => $this->get_layers_field_name( 'google_maps_long_lat' ) ,  
  383. 'id' => $this->get_layers_field_id( 'google_maps_long_lat' ) ,  
  384. 'placeholder' => __( 'e.g. -34.038181, 18.363826' , 'layerswp' ),  
  385. 'value' => ( isset( $instance['google_maps_long_lat'] ) ) ? $instance['google_maps_long_lat'] : NULL 
  386. ); ?> 
  387. </p> 
  388.  
  389. <small class="layers-small-note layers-push-bottom"> 
  390. Having issues with your maps not displaying? Make sure you have updated your Google Maps API Key under <strong>Site Settings > Additional Scripts</strong>. 
  391. </small> 
  392.  
  393. <p class="layers-form-item layers-push-top"> 
  394. <label for="<?php echo $this->get_layers_field_id( 'address_shown' ); ?>"><?php _e( 'Address Shown' , 'layerswp' ); ?></label> 
  395. <?php echo $this->form_elements()->input( 
  396. array( 
  397. 'type' => 'rte',  
  398. 'name' => $this->get_layers_field_name( 'address_shown' ) ,  
  399. 'id' => $this->get_layers_field_id( 'address_shown' ) ,  
  400. 'placeholder' => __( 'e.g. Prestwich Str, Cape Town' , 'layerswp' ),  
  401. 'value' => ( isset( $instance['address_shown'] ) ) ? $instance['address_shown'] : NULL,  
  402. 'class' => 'layers-textarea' 
  403. ); ?> 
  404. </p> 
  405. </div> 
  406. <div class="layers-row clearfix"> 
  407. <p class="layers-form-item"> 
  408.  
  409. <label for="<?php echo $this->get_layers_field_id( 'contact_form' ); ?>"><?php _e( 'Contact Form Embed Code' , 'layerswp' ); ?></label> 
  410.  
  411. <?php echo $this->form_elements()->input( 
  412. array( 
  413. 'type' => 'textarea',  
  414. 'name' => $this->get_layers_field_name( 'contact_form' ) ,  
  415. 'id' => $this->get_layers_field_id( 'contact_form' ) ,  
  416. 'placeholder' => __( 'Contact form embed code' , 'layerswp' ),  
  417. 'value' => ( isset( $instance['contact_form'] ) ) ? $instance['contact_form'] : NULL ,  
  418. 'class' => 'layers-textarea' 
  419. ); ?> 
  420. <small class="layers-small-note"> 
  421. <?php _e( sprintf( 'Need to create a contact form? Try <a href="%1$s" target="ejejcsingle">Gravity Forms</a>', 'https://www.e-junkie.com/ecom/gb.php?cl=54585&c=ib&aff=221037' ) , 'layerswp' ); ?> 
  422. </small> 
  423. </p> 
  424. </div> 
  425. </section> 
  426. </div> 
  427.  
  428. <?php } // Form 
  429. } // Class