diff options
Diffstat (limited to 'plugins/jetpack/modules/widgets/contact-info.php')
-rw-r--r-- | plugins/jetpack/modules/widgets/contact-info.php | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/plugins/jetpack/modules/widgets/contact-info.php b/plugins/jetpack/modules/widgets/contact-info.php index 552f9b91..fd5bef61 100644 --- a/plugins/jetpack/modules/widgets/contact-info.php +++ b/plugins/jetpack/modules/widgets/contact-info.php @@ -42,26 +42,10 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { * Enqueue scripts and styles. */ public function enqueue_scripts() { - $google_url = 'https://maps.googleapis.com/maps/api/js'; - /** - * Set a Google Maps API Key. - * - * @since 4.1.0 - * - * @param string $key Google Maps API Key - */ - $key = apply_filters( 'jetpack_google_maps_api_key', null ); - - if ( ! empty( $key ) ) { - $google_url = add_query_arg( 'key', $key, $google_url ); - } - - wp_enqueue_script( 'jquery' ); - wp_enqueue_script( 'google-maps', esc_url( $google_url, null, null ) ); - wp_enqueue_script( 'contact-info-map-js', plugins_url( 'contact-info/contact-info-map.js', __FILE__ ), array( 'jquery', 'google-maps' ), 20150127 ); - wp_enqueue_style( 'contact-info-map-css', plugins_url( 'contact-info/contact-info-map.css', __FILE__ ), null, 20150127 ); + wp_enqueue_style( 'contact-info-map-css', plugins_url( 'contact-info/contact-info-map.css', __FILE__ ), null, 20160623 ); } + /** * Return an associative array of default values * @@ -75,7 +59,8 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { 'address' => __( "3999 Mission Boulevard,\nSan Diego CA 92109", 'jetpack' ), 'phone' => _x( '1-202-555-1212', 'Example of a phone number', 'jetpack' ), 'hours' => __( "Lunch: 11am - 2pm \nDinner: M-Th 5pm - 11pm, Fri-Sat:5pm - 1am", 'jetpack' ), - 'showmap' => 1, + 'showmap' => 0, + 'apikey' => null, 'lat' => null, 'lon' => null ); @@ -111,12 +96,17 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { $showmap = $instance['showmap']; + /** This action is documented in modules/widgets/contact-info.php */ if ( $showmap && $this->has_good_map( $instance ) ) { - - $lat = $instance['lat']; - $lon = $instance['lon']; - - echo $this->build_map( $lat, $lon ); + /** + * Set a Google Maps API Key. + * + * @since 4.1.0 + * + * @param string $api_key Google Maps API Key + */ + $api_key = apply_filters( 'jetpack_google_maps_api_key', $instance['apikey'] ); + echo $this->build_map( $instance['address'], $api_key ); } $map_link = $this->build_map_link( $instance['address'] ); @@ -173,6 +163,7 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { $instance['address'] = wp_kses( $new_instance['address'], array() ); $instance['phone'] = wp_kses( $new_instance['phone'], array() ); $instance['hours'] = wp_kses( $new_instance['hours'], array() ); + $instance['apikey'] = wp_kses( isset( $new_instance['apikey'] ) ? $new_instance['apikey'] : $old_instance['apikey'], array() ); $instance['lat'] = isset( $old_instance['lat'] ) ? floatval( $old_instance['lat'] ) : 0; $instance['lon'] = isset( $old_instance['lon'] ) ? floatval( $old_instance['lon'] ) : 0; @@ -186,7 +177,7 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { $address = $this->urlencode_address( $instance['address'] ); $path = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=" . $address; /** This action is documented in modules/widgets/contact-info.php */ - $key = apply_filters( 'jetpack_google_maps_api_key', null ); + $key = apply_filters( 'jetpack_google_maps_api_key', $instance['apikey'] ); if ( ! empty( $key ) ) { $path = add_query_arg( 'key', $key, $path ); @@ -239,6 +230,8 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { */ function form( $instance ) { $instance = wp_parse_args( $instance, $this->defaults() ); + wp_enqueue_script( 'contact-info-admin', plugins_url( 'contact-info/contact-info-admin.js', __FILE__ ), array( 'jquery' ), 20160727 ); + ?> <p> <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label> @@ -251,7 +244,7 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { <?php if ( $this->has_good_map( $instance ) ) { ?> - <input class="" id="<?php echo esc_attr( $this->get_field_id( 'showmap' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'showmap' ) ); ?>" value="1" type="checkbox" <?php checked( $instance['showmap'], 1 ); ?> /> + <input class="jp-contact-info-showmap" id="<?php echo esc_attr( $this->get_field_id( 'showmap' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'showmap' ) ); ?>" value="1" type="checkbox" <?php checked( $instance['showmap'], 1 ); ?> /> <label for="<?php echo esc_attr( $this->get_field_id( 'showmap' ) ); ?>"><?php esc_html_e( 'Show map', 'jetpack' ); ?></label> <?php } @@ -263,6 +256,16 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { } ?> </p> + + <p class="jp-contact-info-apikey" style="<?php echo $instance['showmap'] ? '' : 'display: none;'; ?>"> + <label for="<?php echo esc_attr( $this->get_field_id( 'apikey' ) ); ?>"> + <?php _e( 'Google Maps API Key', 'jetpack' ); ?> + <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'apikey' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'apikey' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['apikey'] ); ?>" /> + <br /> + <small><?php printf( wp_kses( __( 'Google now requires an API key to use their maps on your site. <a href="%s">See our documentation</a> for instructions on acquiring a key.' ), array( 'a' => array( 'href' => true ) ) ), 'https://jetpack.com/support/extra-sidebar-widgets/contact-info-widget/' ); ?></small> + </label> + </p> + <p> <label for="<?php echo esc_attr( $this->get_field_id( 'phone' ) ); ?>"><?php esc_html_e( 'Phone:', 'jetpack' ); ?></label> <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'phone' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'phone' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['phone'] ); ?>" /> @@ -298,19 +301,14 @@ if ( ! class_exists( 'Jetpack_Contact_Info_Widget' ) ) { * * @return string HTML of the map */ - function build_map( $lat, $lon ) { + function build_map( $address, $api_key = null ) { $this->enqueue_scripts(); + $src = add_query_arg( 'q', urlencode( $address ), 'https://www.google.com/maps/embed/v1/place' ); + if ( ! empty( $api_key ) ) { + $src = add_query_arg( 'key', $api_key, $src ); + } - $lat = esc_attr( $lat ); - $lon = esc_attr( $lon ); - $html = <<<EOT - <div class="contact-map"> - <input type="hidden" class="contact-info-map-lat" value="$lat" /> - <input type="hidden" class="contact-info-map-lon" value="$lon" /> - <div class="contact-info-map-canvas"></div></div> -EOT; - - return $html; + return '<iframe width="600" height="216" frameborder="0" src="' . esc_url( $src ) . '" class="contact-map"></iframe>'; } /** |