Merge pull request #321 from ThemeBoy/feature-OpenStreetMap

Feature OpenStreetMap
This commit is contained in:
Brian Miyaji
2019-03-12 16:14:12 +11:00
committed by GitHub
22 changed files with 2435 additions and 468 deletions

View File

@@ -84,12 +84,6 @@ class SP_Admin_Assets {
wp_register_script( 'jquery-fitvids', SP()->plugin_url() . '/assets/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true );
wp_register_script( 'google-maps', '//tboy.co/maps_js' );
wp_register_script( 'jquery-locationpicker', SP()->plugin_url() . '/assets/js/locationpicker.jquery.js', array( 'jquery', 'google-maps' ), '0.1.6', true );
wp_register_script( 'sportspress-admin-locationpicker', SP()->plugin_url() . '/assets/js/admin/locationpicker.js', array( 'jquery', 'google-maps', 'jquery-locationpicker' ), SP_VERSION, true );
wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true );
wp_register_script( 'sportspress-admin-colorpicker', SP()->plugin_url() . '/assets/js/admin/colorpicker.js', array( 'jquery', 'wp-color-picker', 'iris' ), SP_VERSION, true );
@@ -130,13 +124,6 @@ class SP_Admin_Assets {
wp_enqueue_script( 'sportspress-admin-widgets' );
}
// Edit venue pages
if ( in_array( $screen->id, array( 'edit-sp_venue' ) ) ) {
wp_enqueue_script( 'google-maps' );
wp_enqueue_script( 'jquery-locationpicker' );
wp_enqueue_script( 'sportspress-admin-locationpicker' );
}
// Edit color
if ( in_array( $screen->id, array( 'sp_outcome' ) ) ) {
wp_enqueue_script( 'sportspress-admin-colorpicker' );

View File

@@ -101,11 +101,19 @@ class SP_Admin_Setup_Wizard {
wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true );
wp_register_script( 'google-maps', '//tboy.co/maps_js' );
wp_register_script( 'sportspress-setup', SP()->plugin_url() . '/assets/js/admin/sportspress-setup.js', array( 'jquery', 'chosen', 'jquery-tiptip' ), SP_VERSION, true );
wp_register_script( 'jquery-locationpicker', SP()->plugin_url() . '/assets/js/locationpicker.jquery.js', array( 'jquery', 'google-maps' ), '0.1.6', true );
wp_register_script( 'sportspress-admin-locationpicker', SP()->plugin_url() . '/assets/js/admin/locationpicker.js', array( 'jquery', 'jquery-locationpicker' ), SP_VERSION, true );
if ( get_option( 'sportspress_load_googlemaps_module', 'no' ) == 'yes' ) {
wp_register_script( 'google-maps', '//tboy.co/maps_js' );
wp_register_script( 'jquery-locationpicker', SP_GOOGLEMAPS_URL . 'js/locationpicker.jquery.js', array( 'jquery', 'google-maps' ), '0.1.6', true );
wp_register_script( 'sportspress-admin-locationpicker', SP_GOOGLEMAPS_URL . 'js/admin/locationpicker.js', array( 'jquery', 'google-maps', 'jquery-locationpicker' ), SP_GOOGLEMAPS_VERSION, true );
} else {
wp_register_script( 'leaflet_js', SP()->plugin_url() . '/assets/js/leaflet.js', array(), '1.4.0' );
wp_register_script( 'control-geocoder', SP()->plugin_url() . '/assets/js/Control.Geocoder.js', array( 'leaflet_js' ) );
wp_register_script( 'sportspress-admin-setup-geocoder', SP()->plugin_url() . '/assets/js/admin/sp-setup-geocoder.js', array( 'leaflet_js', 'control-geocoder' ), SP_VERSION, true );
wp_enqueue_style( 'control-geocoder', SP()->plugin_url() . '/assets/css/Control.Geocoder.css', array() );
wp_enqueue_style( 'leaflet_stylesheet', SP()->plugin_url() . '/assets/css/leaflet.css', array(), '1.4.0' );
}
$strings = apply_filters( 'sportspress_localized_strings', array(
'none' => __( 'None', 'sportspress' ),
@@ -115,8 +123,6 @@ class SP_Admin_Setup_Wizard {
// Localize scripts
wp_localize_script( 'sportspress-setup', 'localized_strings', $strings );
wp_enqueue_script( 'google-maps' );
if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
call_user_func( $this->steps[ $this->step ]['handler'] );
}
@@ -517,6 +523,12 @@ class SP_Admin_Setup_Wizard {
* Venue Step.
*/
public function sp_setup_venue() {
if ( get_option( 'sportspress_load_googlemaps_module', 'no' ) == 'yes' ) {
wp_print_scripts( 'google-maps' );
}else{
wp_print_scripts( 'leaflet_js' );
wp_print_scripts( 'control-geocoder' );
}
?>
<h1><?php _e( 'Venue Setup', 'sportspress' ); ?></h1>
<form method="post">
@@ -531,11 +543,11 @@ class SP_Admin_Setup_Wizard {
<tr>
<th scope="row"><?php _e( 'Address', 'sportspress' ); ?></th>
<td>
<input name="address" class="sp-address" type="text">
<div class="sp-location-picker"></div>
<input name="address" id="sp_address" class="sp-address" type="text" value="Marvel Stadium, Melbourne">
<div id="sp-location-picker" class="sp-location-picker" style="width: 95%; height: 320px"></div>
<p class="description"><?php _e( "Drag the marker to the venue's location.", 'sportspress' ); ?></p>
<input name="latitude" class="sp-latitude" type="hidden" value="40.7324319">
<input name="longitude" class="sp-longitude" type="hidden" value="-73.82480799999996">
<input name="latitude" id="sp_latitude" class="sp-latitude" type="hidden" value="-37.8165647">
<input name="longitude" id="sp_longitude" class="sp-longitude" type="hidden" value="144.9475055">
</td>
</tr>
</table>
@@ -546,7 +558,12 @@ class SP_Admin_Setup_Wizard {
<?php wp_nonce_field( 'sp-setup' ); ?>
</p>
</form>
<?php wp_print_scripts( 'sportspress-admin-locationpicker' ); ?>
<?php
if ( get_option( 'sportspress_load_googlemaps_module', 'no' ) == 'yes' ) {
wp_print_scripts( 'sportspress-admin-locationpicker' );
} else {
wp_print_scripts( 'sportspress-admin-setup-geocoder' );
}?>
<?php
}

View File

@@ -103,21 +103,24 @@ class SP_Admin_Taxonomies {
$term = reset( $terms );
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$latitude = sp_array_value( $term_meta, 'sp_latitude', '40.7324319' );
$longitude = sp_array_value( $term_meta, 'sp_longitude', '-73.82480799999996' );
$latitude = sp_array_value( $term_meta, 'sp_latitude', '-37.8165647' );
$longitude = sp_array_value( $term_meta, 'sp_longitude', '144.9475055' );
$address = sp_array_value( $term_meta, 'sp_address', '' );
endif;
// Sanitize latitude and longitude, fallback to default.
if( ! is_numeric( $latitude) || ! is_numeric( $longitude) ):
$latitude = '40.7324319';
$longitude = '-73.82480799999996';
$latitude = '-37.8165647';
$longitude = '144.9475055';
endif;
?>
<div class="form-field">
<label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label>
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="">
<p><div class="sp-location-picker"></div></p>
<div id="sp-location-picker" class="sp-location-picker" style="width: 95%; height: 320px"></div>
<p><?php _e( "Drag the marker to the venue's location.", 'sportspress' ); ?></p>
</div>
<div class="form-field">
<label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label>
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="<?php echo esc_attr( $address ); ?>">
</div>
<div class="form-field">
<label for="term_meta[sp_latitude]"><?php _e( 'Latitude', 'sportspress' ); ?></label>
<input type="text" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo esc_attr( $latitude ); ?>">
@@ -127,6 +130,11 @@ class SP_Admin_Taxonomies {
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>">
</div>
<?php
if ( get_option( 'sportspress_load_googlemaps_module', 'no' ) == 'yes' ) {
wp_print_scripts( 'sportspress-admin-locationpicker' );
} else {
wp_print_scripts( 'sportspress-admin-geocoder' );
}
}
/**
@@ -137,28 +145,41 @@ class SP_Admin_Taxonomies {
*/
public function edit_venue_fields( $term ) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" ); ?>
$term_meta = get_option( "taxonomy_$t_id" );
$latitude = is_numeric( esc_attr( $term_meta['sp_latitude'] ) ) ? esc_attr( $term_meta['sp_latitude'] ) : '';
$longitude = is_numeric( esc_attr( $term_meta['sp_longitude'] ) ) ? esc_attr( $term_meta['sp_longitude'] ) : '';
$address = esc_attr( $term_meta['sp_address'] ) ? esc_attr( $term_meta['sp_address'] ) : '';
?>
<tr class="form-field">
<td colspan="2">
<p><div id="sp-location-picker" class="sp-location-picker" style="width: 95%; height: 320px"></div></p>
<p class="description"><?php _e( "Drag the marker to the venue's location.", 'sportspress' ); ?></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="<?php echo esc_attr( $term_meta['sp_address'] ) ? esc_attr( $term_meta['sp_address'] ) : ''; ?>">
<p><div class="sp-location-picker"></div></p>
<p class="description"><?php _e( "Drag the marker to the venue's location.", 'sportspress' ); ?></p>
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="<?php echo $address; ?>">
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_latitude]"><?php _e( 'Latitude', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo is_numeric( esc_attr( $term_meta['sp_latitude'] ) ) ? esc_attr( $term_meta['sp_latitude'] ) : ''; ?>">
<input type="text" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo $latitude; ?>">
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_longitude]"><?php _e( 'Longitude', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo is_numeric( esc_attr( $term_meta['sp_longitude'] ) ) ? esc_attr( $term_meta['sp_longitude'] ) : ''; ?>">
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo $longitude; ?>">
</td>
</tr>
<?php
if ( get_option( 'sportspress_load_googlemaps_module', 'no' ) == 'yes' ) {
wp_print_scripts( 'sportspress-admin-locationpicker' );
} else {
wp_print_scripts( 'sportspress-admin-geocoder' );
}
}
/**

View File

@@ -181,8 +181,8 @@ class SP_Settings_Events extends SP_Settings_Page {
),
array(
'title' => __( 'Google Maps', 'sportspress' ),
'desc' => __( 'Display maps', 'sportspress' ),
'title' => __( 'Venue Map', 'sportspress' ),
'desc' => __( 'Display venue map', 'sportspress' ),
'id' => 'sportspress_event_show_maps',
'default' => 'yes',
'type' => 'checkbox',

View File

@@ -78,6 +78,13 @@ class SP_Modules {
'link' => 'https://www.themeboy.com/sportspress-extensions/tournaments/',
'desc' => __( 'Schedule tournaments and create interactive playoff brackets.', 'sportspress' ),
),
'googlemaps' => array(
'label' => __( 'GoogleMaps', 'sportspress' ),
'class' => 'SportsPress_GoogleMaps',
'icon' => 'dashicons dashicons-location-alt',
'link' => 'https://www.themeboy.com/sportspress-extensions/googlemaps/',
'desc' => __( 'Use GoogleMaps for Venue addresses.', 'sportspress' ),
),
),
'team' => array(
'league_tables' => array(