*/ class CBXGoogleMap_Public { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. * * @since 1.0.0 * */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; $this->settings_api = new CBXGooglemapSettings(); } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_styles() { $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; $page = isset( $_GET['page'] ) ? esc_attr( wp_unslash( $_GET['page'] ) ) : ''; $mapsource = intval( $this->settings_api->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) ); if ( $mapsource == 0 ) { wp_register_style( 'leaflet', '//unpkg.com/leaflet@1.3.4/dist/leaflet.css', array(), $this->version, 'all' ); wp_register_style( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-public.css', array( 'leaflet' ), $this->version, 'all' ); //wp_enqueue_style( 'leaflet' ); } else { wp_register_style( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-public.css', array(), $this->version, 'all' ); } //wp_enqueue_style( 'cbxgooglemap-public' ); $elementor_preview = isset($_REQUEST['elementor-preview'])? intval($_REQUEST['elementor-preview']) : 0; if($elementor_preview > 0 || (is_admin() && CBXGooglemapHelper::is_gutenberg_page()) ){ CBXGooglemapHelper::enqueue_js_css(false, true); } }//end enqueue_styles /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_scripts() { $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; $page = isset( $_GET['page'] ) ? esc_attr( wp_unslash( $_GET['page'] ) ) : ''; $googlemap_api_key = $this->settings_api->get_option( 'apikey', 'cbxgooglemap_general', '' ); $mapsource = intval( $this->settings_api->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) ); if ( ( $mapsource == 1 && ! empty( $googlemap_api_key ) ) || $mapsource == 0 ) { wp_enqueue_script( 'jquery' ); if ( $mapsource == 1 ) { wp_register_script( 'coregooglemapapi', '//maps.googleapis.com/maps/api/js?key=' . $googlemap_api_key . '&libraries=places', array(), $this->version ); wp_register_script( 'jqcbxgooglemap', plugin_dir_url( __FILE__ ) . '../assets/js/jqcbxgooglemap.js', array( 'jquery', 'coregooglemapapi' ), $this->version, true ); wp_register_script( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-public.js', array( 'jquery', 'jqcbxgooglemap' ), $this->version, true ); //wp_enqueue_script( 'coregooglemapapi' ); //wp_enqueue_script( 'jqcbxgooglemap' ); } else { wp_register_script( 'coregooglemapapi', '//unpkg.com/leaflet@1.3.4/dist/leaflet.js', array(), $this->version ); wp_register_script( 'cbxgooglemap-public', plugin_dir_url( __FILE__ ) . '../assets/js/cbxgooglemap-public.js', array( 'jquery', 'coregooglemapapi' ), $this->version, true ); //wp_enqueue_script( 'coregooglemapapi' ); } //wp_enqueue_script( 'cbxgooglemap-public' ); $elementor_preview = isset($_REQUEST['elementor-preview'])? intval($_REQUEST['elementor-preview']) : 0; if($elementor_preview > 0 || (is_admin() && CBXGooglemapHelper::is_gutenberg_page()) ){ CBXGooglemapHelper::enqueue_js_css(true, false); } } }//end enqueue_scripts /** * Init all shortcodes */ public function init_shortcodes() { add_shortcode( 'cbxgooglemap', array( $this, 'cbxgooglemap_shortcode' ) ); }//end init_shortcodes /** * Shortcode callback */ public function cbxgooglemap_shortcode( $atts ) { $settings = $this->settings_api; CBXGooglemapHelper::enqueue_js_css(); $general_settings = get_option( 'cbxgooglemap_general', array() ); $hide_leaflet = intval($settings->get_field( 'hide_leaflet', $general_settings, 0 )); $api_key = $settings->get_field( 'apikey', $general_settings, '' ); $mapsource = intval( $settings->get_field( 'mapsource', $general_settings, 1 ) ); //if google map and api key is not present if ( $mapsource == 1 && $api_key == '' ) { return '
' . esc_html__( 'Google Map Api Key is invalid or empty. Please set in setting.', 'cbxgooglemap' ) . '
'; } $zoom_default = $settings->get_field( 'zoom', $general_settings, '8' ); if ( $zoom_default == 0 ) { $zoom_default = 8; } $width_default = $settings->get_field( 'width', $general_settings, '100%' ); if ( $width_default == '' || $width_default == 0 ) { $width_default = '100%'; } $height_default = intval( $settings->get_field( 'height', $general_settings, '300' ) ); if ( $height_default == 0 ) { $height_default = 300; } $scrollwheel_default = intval( $settings->get_field( 'scrollwheel', $general_settings, 1 ) ); $showinfo_default = intval( $settings->get_field( 'showinfo', $general_settings, 1 ) ); $infow_open_default = intval( $settings->get_field( 'infow_open', $general_settings, 1 ) ); $maptype_default = $settings->get_field( 'maptype', $general_settings, 'roadmap' ); $mapicon_default = $settings->get_field( 'mapicon', $general_settings, '' ); $atts = shortcode_atts( array( 'id' => '', 'maptype' => $maptype_default, 'lat' => '', 'lng' => '', 'width' => $width_default, 'height' => $height_default, 'zoom' => $zoom_default, 'scrollwheel' => $scrollwheel_default, 'showinfo' => $showinfo_default, 'infow_open' => $infow_open_default, //added in v1.1.2 'heading' => '', 'address' => '', 'website' => '', 'mapicon' => $mapicon_default, //added in v1.1.2 ), $atts, 'cbxgooglemap' ); $id = isset( $atts['id'] ) ? intval( $atts['id'] ) : 0; if ( $id > 0 ) { //show maps from post data $combined_field = '_cbxgooglemap_combined'; //field name for non sortable fields $meta_prefix = '_cbxgooglemap'; //field prefix for sortable fields $lat = get_post_meta( $id, $meta_prefix . 'lat', true ); $lat = ( $lat !== false ) ? $lat : ''; $lng = get_post_meta( $id, $meta_prefix . 'lng', true ); $lng = ( $lng !== false ) ? $lng : ''; if ( $lat == '' || $lng == '' ) { return esc_html__( 'Please set Latitude and Longitude both to display a map.', 'cbxgooglemap' ); } //at least we need lat lng $meta_combined = get_post_meta( $id, $combined_field, true ); $heading = get_the_title( $id ); $zoom = ( isset( $meta_combined[ $meta_prefix . 'zoom' ] ) && intval( $meta_combined[ $meta_prefix . 'zoom' ] ) > 0 ) ? intval( $meta_combined[ $meta_prefix . 'zoom' ] ) : $zoom_default; $scrollwheel = ( isset( $meta_combined[ $meta_prefix . 'scrollwheel' ] ) ) ? intval( $meta_combined[ $meta_prefix . 'scrollwheel' ] ) : $scrollwheel_default; $showinfo = ( isset( $meta_combined[ $meta_prefix . 'showinfo' ] ) ) ? intval( $meta_combined[ $meta_prefix . 'showinfo' ] ) : $showinfo_default; $infow_open = ( isset( $meta_combined[ $meta_prefix . 'infow_open' ] ) ) ? intval( $meta_combined[ $meta_prefix . 'infow_open' ] ) : $infow_open_default; $width = ( isset( $meta_combined[ $meta_prefix . 'width' ] ) && $meta_combined[ $meta_prefix . 'width' ] != '' ) ? $meta_combined[ $meta_prefix . 'width' ] : $width_default; $height = ( isset( $meta_combined[ $meta_prefix . 'height' ] ) && intval( $meta_combined[ $meta_prefix . 'height' ] ) > 0 ) ? intval( $meta_combined[ $meta_prefix . 'height' ] ) : $height_default; $address = ( isset( $meta_combined[ $meta_prefix . 'address' ] ) && esc_html( $meta_combined[ $meta_prefix . 'address' ] ) != '' ) ? esc_html( $meta_combined[ $meta_prefix . 'address' ] ) : ''; $website = ( isset( $meta_combined[ $meta_prefix . 'website' ] ) && esc_url( $meta_combined[ $meta_prefix . 'website' ] ) != '' ) ? esc_url( $meta_combined[ $meta_prefix . 'website' ] ) : ''; $mapicon = ( isset( $meta_combined[ $meta_prefix . 'mapicon' ] ) && esc_url( $meta_combined[ $meta_prefix . 'mapicon' ] ) != '' ) ? esc_url( $meta_combined[ $meta_prefix . 'mapicon' ] ) : ''; $maptype = ( isset( $meta_combined[ $meta_prefix . 'maptype' ] ) && sanitize_text_field( $meta_combined[ $meta_prefix . 'maptype' ] ) != '' ) ? sanitize_text_field( $meta_combined[ $meta_prefix . 'maptype' ] ) : ''; } else { //show map from shortcode params only $lat = isset( $atts['lat'] ) ? $atts['lat'] : ''; $lng = isset( $atts['lat'] ) ? $atts['lng'] : ''; if ( $lat == '' || $lng == '' ) { return esc_html__( 'Please set Latitude and Longitude both to display a map.', 'cbxgooglemap' ); } //at least we need lat lng $width = isset( $atts['width'] ) ? $atts['width'] : ''; $height = isset( $atts['height'] ) ? intval( $atts['height'] ) : ''; $zoom = isset( $atts['zoom'] ) ? $atts['zoom'] : $zoom_default; $heading = isset( $atts['heading'] ) ? $atts['heading'] : ''; $address = isset( $atts['address'] ) ? $atts['address'] : ''; $website = isset( $atts['website'] ) ? $atts['website'] : ''; $mapicon = isset( $atts['mapicon'] ) ? $atts['mapicon'] : ''; $maptype = isset( $atts['maptype'] ) ? $atts['maptype'] : ''; $showinfo = isset( $atts['showinfo'] ) ? intval( $atts['showinfo'] ) : $showinfo_default; $infow_open = isset( $atts['infow_open'] ) ? intval( $atts['infow_open'] ) : $infow_open_default; $scrollwheel = isset( $atts['scrollwheel'] ) ? intval( $atts['scrollwheel'] ) : $scrollwheel_default; } if ( $heading == '' && $website == '' ) { $showinfo = 0; } if ( is_numeric( $width ) ) { $width = $width . 'px'; } $extra_class = ($hide_leaflet)? 'cbxgooglemap_wrapper_hideleaflet' : ''; $output_html = '