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' ); $this->start_controls_section( 'section_cbxmap', array( 'label' => esc_html__( 'CBX Map', 'cbxgooglemap' ), ) ); $query = get_posts( array( 'post_type' => 'cbxgooglemap', 'orderby' => 'date', 'posts_per_page' => - 1, 'post_status' => 'publish', ) ); $googleMap_posts = array(); $googleMap_posts[''] = esc_html__('Choose Ready Map or Use custom params', 'cbxgooglemap'); foreach ( $query as $key => $data ) { $googleMap_posts[ $data->ID ] = $data->post_title; } $this->add_control( 'cbxgooglemap_post_id', array( 'label' => esc_html__( 'Predefined Map', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::SELECT, 'placeholder' => esc_html__( 'Choose Ready Map or Use custom params', 'cbxgooglemap' ), 'default' => '', 'label_block' => true, 'options' => $googleMap_posts, 'description' => esc_html__( 'Choose predefined map or create from custom attributes below', 'cbxgooglemap' ), ) ); $this->add_control( 'hr', array( 'type' => \Elementor\Controls_Manager::DIVIDER, ) ); //regular fields $this->add_control( 'cbxgooglemap_custom_1', array( 'label' => esc_html__( 'Custom Map Attributes', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::HEADING, 'default' => '', ) ); $this->add_control( 'cbxgooglemap_maptype', array( 'label' => esc_html__( 'Map Type', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => array( 'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ), 'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ), 'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ), 'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ), ), 'default' => $maptype_default, 'description' => esc_html__( 'Google Map only', 'cbxgooglemap' ), ) ); $this->add_control( 'cbxgooglemap_lat', array( 'label' => esc_html__( 'Latitude', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => esc_html__( 'Latitude', 'cbxgooglemap' ), 'default' => '', ) ); $this->add_control( 'cbxgooglemap_lng', array( 'label' => esc_html__( 'Longitude', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => esc_html__( 'Longitude', 'cbxgooglemap' ), 'default' => '', ) ); $this->add_control( 'cbxgooglemap_width', array( 'label' => esc_html__( 'Width(Numeric or with %)', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => esc_html__( 'Width', 'cbxgooglemap' ), 'default' => $width_default, ) ); $this->add_control( 'cbxgooglemap_height', array( 'label' => esc_html__( 'Height', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => esc_html__( 'Height', 'cbxgooglemap' ), 'default' => $height_default, ) ); $this->add_control( 'cbxgooglemap_zoom', array( 'label' => esc_html__( 'Zoom(Numeric Value)', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => esc_html__( 'Zoom', 'cbxgooglemap' ), 'default' => $zoom_default, ) ); $this->add_control( 'cbxgooglemap_scrollwheel', array( 'label' => esc_html__( 'Mouse Scroll Wheel', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => array( '1' => esc_html__( 'Enable', 'cbxgooglemap' ), '0' => esc_html__( 'Disable', 'cbxgooglemap' ), ), 'default' => $scrollwheel_default, ) ); $this->add_control( 'cbxgooglemap_showinfo', array( 'label' => esc_html__( 'Show Popup', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => array( '1' => esc_html__( 'Enable', 'cbxgooglemap' ), '0' => esc_html__( 'Disable', 'cbxgooglemap' ), ), 'default' => $showinfo_default, ) ); $this->add_control( 'cbxgooglemap_infow_open', array( 'label' => esc_html__( 'Info/Popup Window', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => array( '1' => esc_html__( 'Open(Default)', 'cbxgooglemap' ), '0' => esc_html__( 'On Click', 'cbxgooglemap' ), ), 'default' => $infow_open_default, ) ); $this->add_control( 'cbxgooglemap_heading', array( 'label' => esc_html__( 'Popup Heading', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => esc_html__( 'Popup Heading', 'cbxgooglemap' ), 'default' => '', ) ); $this->add_control( 'cbxgooglemap_address', array( 'label' => esc_html__( 'Location Address', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => esc_html__( 'Address', 'cbxgooglemap' ), 'default' => '', ) ); $this->add_control( 'cbxgooglemap_website', array( 'label' => esc_html__( 'Website url', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::URL, 'placeholder' => esc_html__( 'Website', 'cbxgooglemap' ), 'default' => array( 'url' => '', ), 'show_external' => false, ) ); $this->add_control( 'cbxgooglemap_mapicon', array( 'label' => esc_html__( 'Map Icon', 'cbxgooglemap' ), 'type' => \Elementor\Controls_Manager::MEDIA, 'default' => array( 'url' => '', ), ) ); $this->end_controls_section(); }//end _register_controls /** * Render google maps widget output on the frontend. * * Written in PHP and used to generate the final HTML. * * @since 1.0.0 * @access protected */ protected function render() { if ( ! class_exists( 'CBXGooglemapSettings' ) ) { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-cbxgooglemap-settings.php'; } $settings_api = new \CBXGooglemapSettings(); $general_settings = get_option( 'cbxgooglemap_general', array() ); $googlemap_api_key = $settings_api->get_field( 'apikey', $general_settings, '' ); $mapsource = intval( $settings_api->get_field( 'mapsource', $general_settings, 1 ) ); if ( $mapsource == 1 && $googlemap_api_key == '' ) { echo '

' . esc_html__( 'Google Map Api Key is invalid!', 'cbxgooglemap' ) . '

'; } else { $settings = $this->get_settings(); $id = intval( $settings['cbxgooglemap_post_id'] ); if ( $id > 0 ) { //render map from saved map echo do_shortcode( '[cbxgooglemap id="' . $id . '"]' ); } else { //render map from custom attributes $lat = sanitize_text_field( $settings['cbxgooglemap_lat'] ); $lng = sanitize_text_field( $settings['cbxgooglemap_lng'] ); $width = sanitize_text_field( $settings['cbxgooglemap_width'] ); $height = sanitize_text_field( $settings['cbxgooglemap_height'] ); $zoom = $settings['cbxgooglemap_zoom']; $scrollwheel = intval( $settings['cbxgooglemap_scrollwheel'] ); $showinfo = intval( $settings['cbxgooglemap_showinfo'] ); $infow_open = intval( $settings['cbxgooglemap_infow_open'] ); $heading = sanitize_text_field( $settings['cbxgooglemap_heading'] ); $address = sanitize_text_field( $settings['cbxgooglemap_address'] ); $maptype = sanitize_text_field( $settings['cbxgooglemap_maptype'] ); $website_data = $settings['cbxgooglemap_website']; $mapicon_data = $settings['cbxgooglemap_mapicon']; $website = isset( $website_data['url'] ) ? $website_data['url'] : ''; $mapicon = isset( $mapicon_data['url'] ) ? $mapicon_data['url'] : ''; echo do_shortcode( '[cbxgooglemap lat="' . $lat . '" lng="' . $lng . '" zoom="' . $zoom . '" scrollwheel="' . $scrollwheel . '" showinfo="' . $showinfo . '" infow_open="' . $infow_open . '" heading="' . $heading . '" maptype="' . $maptype . '" website="' . $website . '" address="' . $address . '" mapicon="' . $mapicon . '" width="' . $width . '" height="' . $height . '"]' ); } } }//end render /** * Render google maps widget output in the editor. * * Written as a Backbone JavaScript template and used to generate the live preview. * * @access protected */ protected function _content_template() { }//end _content_template }//end CBXGooglemap_ElemWidget