define_constants();
// Actions
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_action( 'sp_venue_show_map', array( $this, 'show_venue_map' ), 10, 5 );
add_action( 'sp_admin_geocoder_scripts', array( $this, 'admin_geocoder_scripts' ), 10 );
add_action( 'sp_setup_geocoder_scripts', array( $this, 'setup_geocoder_scripts' ), 10 );
add_action( 'sp_setup_venue_geocoder_scripts', array( $this, 'setup_venue_geocoder_scripts' ), 10 );
}
/**
* Define constants.
*/
private function define_constants() {
if ( !defined( 'SP_OPENSTREETMAP_VERSION' ) )
define( 'SP_OPENSTREETMAP_VERSION', '2.7' );
if ( !defined( 'SP_OPENSTREETMAP_URL' ) )
define( 'SP_OPENSTREETMAP_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'SP_OPENSTREETMAP_DIR' ) )
define( 'SP_OPENSTREETMAP_DIR', plugin_dir_path( __FILE__ ) );
}
/**
* Enqueue admin styles
*/
public function admin_styles( $hook ) {
$screen = get_current_screen();
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
wp_enqueue_style( 'leaflet_stylesheet', SP()->plugin_url() . '/assets/css/leaflet.css', array(), '1.4.0' );
wp_enqueue_style( 'control-geocoder', SP()->plugin_url() . '/assets/css/Control.Geocoder.css', array() );
}
}
/**
* Enqueue admin scripts
*/
public function admin_scripts( $hook ) {
$screen = get_current_screen();
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
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-geocoder', SP()->plugin_url() . '/assets/js/admin/sp-geocoder.js', array( 'leaflet_js', 'control-geocoder' ), SP_VERSION, true );
}
// Edit venue pages
if ( in_array( $screen->id, array( 'edit-sp_venue' ) ) ) {
wp_enqueue_script( 'leaflet_js' );
wp_enqueue_script( 'control-geocoder' );
wp_enqueue_script( 'sportspress-admin-geocoder' );
}
}
/**
* Enqueue frontend scripts
*/
public function frontend_scripts() {
if( ( is_single() || is_tax() ) && get_post_type()=='sp_event' ){
wp_enqueue_style( 'leaflet_stylesheet', SP()->plugin_url() . '/assets/css/leaflet.css', array(), '1.4.0' );
wp_enqueue_script( 'leaflet_js', SP()->plugin_url() . '/assets/js/leaflet.js', array(), '1.4.0' );
}
}
/**
* Integrate OpenStreetMap (Show Venue)
*
* @return mix
*/
public function show_venue_map( $latitude, $longitude, $address, $zoom, $maptype ) {
$lat = abs($latitude);
$lat_deg = floor($lat);
$lat_sec = ($lat - $lat_deg) * 3600;
$lat_min = floor($lat_sec / 60);
$lat_sec = floor($lat_sec - ($lat_min * 60));
$lat_dir = $latitude > 0 ? 'N' : 'S';
$lon = abs($longitude);
$lon_deg = floor($lon);
$lon_sec = ($lon - $lon_deg) * 3600;
$lon_min = floor($lon_sec / 60);
$lon_sec = floor($lon_sec - ($lon_min * 60));
$lon_dir = $longitude > 0 ? 'E' : 'W';
?>
/@,,z" target="_blank">
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' );
}
/**
* Print geocoder script in setup venue step
*/
public function setup_venue_geocoder_scripts() {
wp_print_scripts( 'leaflet_js' );
wp_print_scripts( 'control-geocoder' );
}
}
endif;
new SportsPress_OpenStreetMap();