settings = NIMAP_DATA::get_instance(); $this->language = ''; add_action( 'init', array( $this, 'shortcode_init' ) ); // Ajax //Locator search add_action( 'wp_ajax_nimap_location_store', array( $this, 'nimap_location_store' ) ); add_action( 'wp_ajax_nopriv_nimap_location_store', array( $this, 'nimap_location_store' ) ); //Store data search add_action( 'wp_ajax_nimap_store_info_search', array( $this, 'nimap_store_info_search' ) ); add_action( 'wp_ajax_nopriv_nimap_store_info_search', array( $this, 'nimap_store_info_search' ) ); } public function shortcode_init() { add_shortcode( 'nimap_store_locator', array( $this, 'render_store_locator' ) ); add_shortcode( 'nimap_store_search', array( $this, 'render_store_search' ) ); add_shortcode( 'nimap_store_detail', array( $this, 'render_store_detail' ) ); add_shortcode( 'nimap_store_widget', array( $this, 'render_store_widget' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'shortcode_register_script' ) ); // add_action( 'wp_footer', array( $this, 'add_frontend_scripts' ) ); } public function render_store_locator( $atts, $content = null ) { // if ( ! wp_script_is( 'nimap-frontend' ) ) { // wp_enqueue_script( 'nimap-frontend' ); // wp_enqueue_style( 'nimap-frontend' ); // } // // FRONTEND Public // $shortcode_attr = array(); // extract( shortcode_atts( // array( // 'template' => ( ( ! empty( $atts['template'] ) || $atts['template'] == '0' ) ? $shortcode_attr['template'] = 'template="' . $atts['template'] . '"' : '' ), // 'search_type' => ( ( ! empty( $atts['search_type'] ) || $atts['search_type'] == '0' ) ? $shortcode_attr['search_type'] = 'search_type="' . $atts['search_type'] . '"' : '' ), // 'layout' => ( ( ! empty( $atts['layout'] ) || $atts['layout'] == '0' ) ? $shortcode_attr['layout'] = 'layout="' . $atts['layout'] . '"' : '' ), // 'distance_control' => ( ( ! empty( $atts['distance_control'] ) || $atts['distance_control'] == '0' ) ? $shortcode_attr['distance_control'] = 'distance_control="' . $atts['distance_control'] . '"' : '' ), // 'head_title' => '' // ), // $atts ) ); // $shortcode_attr = implode( ' ', $shortcode_attr ); // $shortcode = '[NIMAP_STORELOCATOR ' . $shortcode_attr . ']'; // extract( shortcode_atts( array( // 'layout_type' => 'fullwidth', // 'map_lang' => '', // ), $atts ) ); if ( ! $atts ) { $atts = array(); } $all_configs = $this->settings->get_params(); if ( ! empty( $atts ) && is_array( $atts ) ) { $all_configs = shortcode_atts( $all_configs, $atts ); } $all_configs = array_merge( $all_configs, $atts ); $lang = $this->format_lang_code( $all_configs['map_language'], $all_configs['map_locale'] ); if ( $lang ) { $all_configs['lang'] = $lang; } // if ( isset( $_GET['mapppin_latitude'] ) && isset( $_GET['mapppin_longitude'] ) ) { // $all_configs['map_start_latitude'] = sanitize_text_field( wp_unslash( $_GET['mapppin_latitude'] ) ); // $all_configs['map_start_longitude'] = sanitize_text_field( wp_unslash( $_GET['mapppin_longitude'] ) ); // } // Get the JSON for the Map layout $all_configs['map_style'] = NIMAP_MULTI_LOCATOR_Function::mapStyle( $all_configs['map_style'], $all_configs['map_custom_style'] ); $all_configs = apply_filters( 'nimap_filter_locator_attrs', $all_configs ); $all_categories = array(); $terms_categories = get_terms( [ 'taxonomy' => 'nimap_store_category', 'hide_empty' => false, ] ); if ( ! is_wp_error( $terms_categories ) && is_array( $terms_categories ) ) { foreach ( $terms_categories as $_result ) { $all_categories[ $_result->term_id ] = $_result; } } $this->enqueue_scripts( 'locator', $all_configs ); $template_selected = 'location-locator.php'; $is_customize = self::is_customize_preview(); // $template_selected = isset( $all_configs['locator_template'] ) ? $all_configs['locator_template'] : $all_configs['general_store_locator_type']; // switch ( $template_selected ) { // case 'fullwidth': // $template_file = 'location-locator.php'; // break; // case '2col': // default: // $template_file = 'store-locator.php'; // } ob_start(); if ( $theme_file = locate_template( array( $template_selected ) ) ) { $template_path = $theme_file; } else { $template_path = NIMAP_TEMPLATES . $template_selected; } include $template_path; $mp_output = ob_get_contents(); ob_end_clean(); return $mp_output; } public function render_store_search( $atts ) { if ( ! $atts ) { $atts = array(); } $all_configs = $this->settings->get_params(); if ( ! empty( $atts ) && is_array( $atts ) ) { $all_configs = shortcode_atts( $all_configs, $atts ); } $all_configs = array_merge( $all_configs, $atts ); // Language if ( ! empty( $atts ) && is_array( $atts ) ) { $all_configs = shortcode_atts( $all_configs, $atts ); } $lang = $this->format_lang_code( $all_configs['map_language'], $all_configs['map_locale'] ); if ( $lang ) { $all_configs['lang'] = $lang; } $all_configs = apply_filters( 'nimap_filter_list_attrs', $all_configs ); // Get the categories $all_categories = array(); $terms_categories = get_terms( [ 'taxonomy' => 'nimap_store_category', 'hide_empty' => false, ] ); if ( ! is_wp_error( $terms_categories ) && is_array( $terms_categories ) ) { foreach ( $terms_categories as $_result ) { $all_categories[ $_result->term_id ] = $_result; } } $number_post = $this->settings->get_params( 'store_paging_enable' ) ? (int) $this->settings->get_params( 'store_paging_number' ) : - 1; $store_list = get_posts( [ 'post_type' => 'nimap_store', 'post_status' => 'publish', 'order' => 'ASC', 'numberposts' => - 1, ] ); $store_count = 0; if ( is_array( $store_list ) ) { $store_count = count( $store_list ); if ( $store_count > $number_post ) { $store_list = array_slice( $store_list, 0, $number_post ); } } $count_posts_obj = wp_count_posts( 'nimap_store' ); $count_posts = 0; if ( is_object( $count_posts_obj ) ) { foreach ( $count_posts_obj as $p_key => $p_val ) { $count_posts += intval( $p_val ); } } $this->enqueue_scripts( 'list', $all_configs ); ob_start(); $template_file = 'list-locator.php'; if ( $theme_file = locate_template( array( $template_file ) ) ) { $template_path = $theme_file; } else { $template_path = NIMAP_TEMPLATES . $template_file; } include $template_path; $mp_output = ob_get_contents(); ob_end_clean(); return $mp_output; } public function render_store_detail( $atts ) { if ( ! $atts ) { $atts = array(); } $store_id = isset( $_REQUEST['nimap-store'] ) ? absint( wp_unslash( $_REQUEST['nimap-store'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( $store_id ) { $store_post = get_post( $store_id ); if ( ! $store_post || 'nimap_store' !== $store_post->post_type || 'publish' !== $store_post->post_status ) { $store_id = 0; } } $store_id = apply_filters( 'nimap_render_store_detail_id', $store_id, $atts ); $all_configs = $this->settings->get_params(); if ( ! empty( $atts ) && is_array( $atts ) ) { $all_configs = shortcode_atts( $all_configs, $atts ); } $all_configs = array_merge( $all_configs, $atts ); if ( ! empty( $atts ) && is_array( $atts ) ) { $all_configs = shortcode_atts( $all_configs, $atts ); } $lang = $this->format_lang_code( $all_configs['map_language'], $all_configs['map_locale'] ); if ( $lang ) { $all_configs['lang'] = $lang; } $all_configs = apply_filters( 'nimap_filter_list_attrs', $all_configs ); $all_categories = array(); $terms_categories = get_terms( [ 'taxonomy' => 'nimap_store_category', 'hide_empty' => false, ] ); if ( ! is_wp_error( $terms_categories ) && is_array( $terms_categories ) ) { foreach ( $terms_categories as $_result ) { $all_categories[ $_result->term_id ] = $_result; } } $store_list = array(); if ( empty( $store_id ) ) { $store_lists = get_posts( [ 'post_type' => 'nimap_store', 'orderby' => 'date', 'order' => 'DESC', 'numberposts' => 1, ] ); if ( $store_lists && isset( $store_lists[0] ) && is_object( $store_lists[0] ) && property_exists( $store_lists[0], 'ID' ) ) { $store_id = $store_lists[0]->ID; $store_list['title'] = $store_lists[0]->post_title; } } else { $store_list['title'] = get_the_title( $store_id ); } do_action( 'nimap_render_store_detail', $store_id, $all_configs ); $all_configs['map_style'] = NIMAP_MULTI_LOCATOR_Function::mapStyle( $all_configs['map_style'], $all_configs['map_custom_style'] ); $address_meta = get_post_meta( $store_id, 'nimap_store_address', true ) ?: ''; $all_configs['select_latitude'] = $address_meta && is_array( $address_meta ) && isset( $address_meta['latitude'] ) && $address_meta['latitude'] ? floatval( $address_meta['latitude'] ) : ''; $all_configs['select_longitude'] = $address_meta && is_array( $address_meta ) && isset( $address_meta['longitude'] ) && $address_meta['longitude'] ? floatval( $address_meta['longitude'] ) : ''; $this->enqueue_scripts( 'detail', $all_configs ); ob_start(); $template_file = 'detail-locator.php'; if ( $theme_file = locate_template( array( $template_file ) ) ) { $template_path = $theme_file; } else { $template_path = NIMAP_TEMPLATES . $template_file; } include $template_path; $mp_output = ob_get_contents(); ob_end_clean(); return $mp_output; } public function render_store_widget( $atts ) { if ( ! $atts ) { $atts = array( 'widget_title' => 'Search store' ); } $all_configs = $this->settings->get_params(); if ( ! empty( $atts ) && is_array( $atts ) ) { $all_configs = shortcode_atts( $all_configs, $atts ); } $all_configs = array_merge( $all_configs, $atts ); if ( ! empty( $atts ) && is_array( $atts ) ) { $all_configs = shortcode_atts( $all_configs, $atts ); } $lang = $this->format_lang_code( $all_configs['map_language'], $all_configs['map_locale'] ); if ( $lang ) { $all_configs['lang'] = $lang; } $all_configs = apply_filters( 'nimap_filter_list_attrs', $all_configs ); $all_categories = array(); $terms_categories = get_terms( [ 'taxonomy' => 'nimap_store_category', 'hide_empty' => false, ] ); if ( ! is_wp_error( $terms_categories ) && is_array( $terms_categories ) ) { foreach ( $terms_categories as $_result ) { $all_categories[ $_result->term_id ] = $_result; } } $this->enqueue_scripts( 'widget', $all_configs ); ob_start(); $template_file = 'widget-locator.php'; if ( $theme_file = locate_template( array( $template_file ) ) ) { $template_path = $theme_file; } else { $template_path = NIMAP_TEMPLATES . $template_file; } include $template_path; $mp_output = ob_get_contents(); ob_end_clean(); return $mp_output; } function nimap_location_store() { check_ajax_referer( 'nimap-nonce', 'nonce' ); $latitude = isset( $_POST['lat'] ) ? (float) sanitize_text_field( wp_unslash( $_POST['lat'] ) ) : 0; $longitude = isset( $_POST['lng'] ) ? (float) sanitize_text_field( wp_unslash( $_POST['lng'] ) ) : 0; $search_radius = isset( $_POST['radius'] ) ? (float) sanitize_text_field( wp_unslash( $_POST['radius'] ) ) : 50; $category = isset( $_POST['category'] ) ? sanitize_text_field( wp_unslash( $_POST['category'] ) ) : ''; if ( '' === $category && isset( $_POST['filter'] ) ) { $category = sanitize_text_field( wp_unslash( $_POST['filter'] ) ); } $max_results = isset( $_POST['result'] ) ? absint( $_POST['result'] ) : 0; $server_ceiling = (int) apply_filters( 'nimap_store_query_ceiling', 200 ); if ( $server_ceiling < 1 ) { $server_ceiling = 200; } $max_count = $max_results ? min( $max_results, $server_ceiling ) : min( 99, $server_ceiling ); $fetch_limit = min( max( $max_count * 3, $max_count ), $server_ceiling ); $search_object = [ 'post_type' => 'nimap_store', 'post_status' => 'publish', 'order' => 'ASC', 'numberposts' => $fetch_limit, ]; if ( '' !== $category && absint( $category ) ) { $search_object['tax_query'] = array( array( 'taxonomy' => 'nimap_store_category', 'field' => 'term_id', 'terms' => absint( $category ), ), ); } $search_object = apply_filters( 'nimap_location_store_query_args', $search_object, $category, $max_count ); $store_list = get_posts( $search_object ); $st_unit = $this->settings->get_params( 'general_distance_unit' ); $unit = ( 'ml' === $st_unit ) ? 'ml' : 'km'; $f_location = [ 'lat' => $latitude, 'lng' => $longitude ]; $cat_filter = ( '' !== $category && absint( $category ) ) ? '' : $category; $stores_data = NIMAP_MULTI_LOCATOR_Function::getFormattedStores( $store_list, $cat_filter, $f_location, $search_radius, $unit ); $o_data = NIMAP_MULTI_LOCATOR_Function::sortStoreResults( $stores_data, $this->settings->get_params( 'filter_sort_by' ), 0, $max_count ); do_action( 'nimap_location_store_sent', $o_data, $search_object ); wp_send_json( $o_data ); } function nimap_store_info_search() { check_ajax_referer( 'nimap-nonce', 'nonce' ); $page = isset( $_POST['page'] ) ? absint( $_POST['page'] ) : 1; $category = isset( $_POST['category'] ) ? sanitize_text_field( wp_unslash( $_POST['category'] ) ) : ''; if ( '' === $category && isset( $_POST['filter'] ) ) { $category = sanitize_text_field( wp_unslash( $_POST['filter'] ) ); } $key_word = isset( $_POST['key'] ) ? sanitize_text_field( wp_unslash( $_POST['key'] ) ) : ''; $latitude = isset( $_POST['lat'] ) ? sanitize_text_field( wp_unslash( $_POST['lat'] ) ) : ''; $longitude = isset( $_POST['lng'] ) ? sanitize_text_field( wp_unslash( $_POST['lng'] ) ) : ''; $source = isset( $_POST['source'] ) ? sanitize_text_field( wp_unslash( $_POST['source'] ) ) : 'list'; $search_type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : 'list'; $search_radius = isset( $_POST['radius'] ) ? (float) sanitize_text_field( wp_unslash( $_POST['radius'] ) ) : 0; $max_results = isset( $_POST['result'] ) ? absint( $_POST['result'] ) : 0; if ( $source == 'locator' ) { $paging_enable = $this->settings->get_params( 'list_paging_enable' ); $number_post = $paging_enable ? (int) $this->settings->get_params( 'list_paging_number' ) : 999999; } else { $paging_enable = $this->settings->get_params( 'store_paging_enable' ); $number_post = $paging_enable ? (int) $this->settings->get_params( 'store_paging_number' ) : 999999; } $search_field = $this->settings->get_params( 'search_store_by_field' ) ?: 'title'; $server_ceiling = (int) apply_filters( 'nimap_store_query_ceiling', 200 ); if ( $server_ceiling < 1 ) { $server_ceiling = 200; } if ( $paging_enable && $number_post > 0 && $number_post < 999999 ) { $fetch_limit = min( max( $number_post * max( $page, 1 ), $number_post ), $server_ceiling ); } else { $fetch_limit = $server_ceiling; } if ( $max_results ) { $fetch_limit = min( max( $fetch_limit, $max_results ), $server_ceiling ); } $query_args = [ 'post_type' => 'nimap_store', 'post_status' => 'publish', 'order' => 'ASC', 'numberposts' => $fetch_limit, ]; if ( '' !== $category && absint( $category ) ) { $query_args['tax_query'] = array( array( 'taxonomy' => 'nimap_store_category', 'field' => 'term_id', 'terms' => absint( $category ), ), ); } $query_args = apply_filters( 'nimap_store_info_search_query_args', $query_args, $category, $page ); $store_list = get_posts( $query_args ); $store_count = 0; $start_index = $number_post && $paging_enable ? $number_post * ( $page - 1 ) : 0; $stores_data = []; $tax_filtered = ( '' !== $category && absint( $category ) ); foreach ( $store_list as $store_arr ) { $store_title = get_the_title( $store_arr->ID ) ?: ''; $store_category = get_the_terms( $store_arr->ID, 'nimap_store_category' ); $format_category = []; if ( $category && ! $tax_filtered ) { if ( ! $store_category || is_wp_error( $store_category ) || empty( $store_category ) ) { continue; } $exits_cat = false; foreach ( $store_category as $cat_data ) { if ( (string) $cat_data->term_id === (string) $category ) { $exits_cat = true; } $format_category[ $cat_data->term_id ] = $cat_data->name; } if ( ! $exits_cat ) { continue; } } elseif ( $store_category && is_array( $store_category ) && ! empty( $store_category ) ) { foreach ( $store_category as $cat_data ) { $format_category[ $cat_data->term_id ] = $cat_data->name; } } $store_description = get_post_meta( $store_arr->ID, 'nimap_store_description', true ) ?: ''; $store_address = get_post_meta( $store_arr->ID, 'nimap_store_address', true ) ?: ''; $store_information = get_post_meta( $store_arr->ID, 'nimap_store_information', true ) ?: ''; $store_opening = get_post_meta( $store_arr->ID, 'nimap_store_opening', true ) ?: ''; $store_image = get_post_meta( $store_arr->ID, 'nimap_store_image', true ) ?: ''; $store_address = maybe_unserialize( $store_address ); $store_information = maybe_unserialize( $store_information ); $store_opening = maybe_unserialize( $store_opening ); if ( ! is_array( $store_address ) ) { $store_address = array(); } if ( ! is_array( $store_information ) ) { $store_information = array(); } $is_match = true; if ( $key_word ) { switch ( $search_field ) { case 'address': $haystack = isset( $store_address['address'] ) ? (string) $store_address['address'] : ''; if ( ! str_contains( $haystack, $key_word ) ) { $is_match = false; } break; case 'description': if ( ! str_contains( (string) $store_description, $key_word ) ) { $is_match = false; } break; case 'phone': $haystack = isset( $store_information['phone'] ) ? (string) $store_information['phone'] : ''; if ( ! str_contains( $haystack, $key_word ) ) { $is_match = false; } break; case 'email': $haystack = isset( $store_information['email'] ) ? (string) $store_information['email'] : ''; if ( ! str_contains( $haystack, $key_word ) ) { $is_match = false; } break; case 'website': $haystack = isset( $store_information['website'] ) ? (string) $store_information['website'] : ''; if ( ! str_contains( $haystack, $key_word ) ) { $is_match = false; } break; case 'zip': $haystack = isset( $store_address['zip'] ) ? (string) $store_address['zip'] : ''; if ( ! str_contains( $haystack, $key_word ) ) { $is_match = false; } break; case 'custom': $haystack = isset( $store_information['custom'] ) ? (string) $store_information['custom'] : ''; if ( ! str_contains( $haystack, $key_word ) ) { $is_match = false; } break; default: if ( ! str_contains( (string) $store_title, $key_word ) ) { $is_match = false; } } } if ( ! $is_match ) { continue; } $s_distance = 0; if ( $latitude && $longitude ) { $st_unit = $this->settings->get_params( 'general_distance_unit' ); $location = [ 'lat' => $latitude, 'lng' => $longitude ]; $unit = ( 'ml' === $st_unit ) ? 'ml' : 'km'; $s_distance = NIMAP_MULTI_LOCATOR_Function::getStoreDistance( $store_address, $location, $unit ); if ( $search_radius ) { if ( $s_distance < 0 || $s_distance > $search_radius ) { continue; } } } $store_count += 1; $store_image = NIMAP_MULTI_LOCATOR_Function::getStoreThumbnail( $store_image, $store_title ); $category_render = NIMAP_MULTI_LOCATOR_Function::printCategory( $format_category ); $store_opening = NIMAP_MULTI_LOCATOR_Function::formatStoreOpening( $store_opening ); $website = isset( $store_information['website'] ) ? esc_url( $store_information['website'] ) : ''; $store_data = array( 'id' => absint( $store_arr->ID ), 'title' => esc_html( $store_title ), 'description' => esc_html( $store_description ), 'address' => isset( $store_address['address'] ) ? esc_html( $store_address['address'] ) : '', 'image' => $store_image['list'], 'image_info' => $store_image['info'], 'city' => isset( $store_address['city'] ) ? esc_html( $store_address['city'] ) : '', 'state' => isset( $store_address['state'] ) ? esc_html( $store_address['state'] ) : '', 'country' => isset( $store_address['country'] ) ? esc_html( $store_address['country'] ) : '', 'zip' => isset( $store_address['zip'] ) ? esc_html( $store_address['zip'] ) : '', 'phone' => isset( $store_information['phone'] ) ? esc_html( $store_information['phone'] ) : '', 'fax' => isset( $store_information['fax'] ) ? esc_html( $store_information['fax'] ) : '', 'website' => $website, 'url' => $website, 'custom' => isset( $store_information['custom'] ) ? esc_html( $store_information['custom'] ) : '', 'email' => isset( $store_information['email'] ) ? esc_html( $store_information['email'] ) : '', 'opening' => NIMAP_MULTI_LOCATOR_Function::printOpening( $store_opening ), 'category' => $category_render[0], 'category_r' => esc_html( $category_render[1] ), 'lat' => isset( $store_address['latitude'] ) ? (float) $store_address['latitude'] : 0, 'lng' => isset( $store_address['longitude'] ) ? (float) $store_address['longitude'] : 0, 'distance' => $s_distance, ); $stores_data[] = $store_data; } $sort_by = ( 'locator' === $source ) ? $this->settings->get_params( 'filter_sort_by' ) : $this->settings->get_params( 'list_sort_by' ); $sort_data = NIMAP_MULTI_LOCATOR_Function::sortStoreResults( $stores_data, $sort_by ); if ( $max_results && 'location' === $search_type ) { $sort_data = array_slice( $sort_data, 0, min( $max_results, $server_ceiling ) ); $store_count = count( $sort_data ); } $paging_block = NIMAP_MULTI_LOCATOR_Function::renderPagingResults( count( $stores_data ), $page, $number_post ); //paging $paging_data = $paging_enable && $search_type != 'location' ? array_slice( $sort_data, $start_index, $number_post ) : $sort_data; $o_data = array( 'count' => $store_count, 'paging' => wp_kses_post( $paging_block ), 'stores' => $paging_data ); do_action( 'nimap_store_info_search_sent', $o_data, $query_args ); wp_send_json( $o_data ); } public function get_directions_travel_mode() { $default = 'driving'; $travel_mode = apply_filters( 'nimap_direction_travel_mode', $default ); $allowed_modes = array( 'driving', 'bicycling', 'transit', 'walking' ); if ( ! in_array( $travel_mode, $allowed_modes ) ) { $travel_mode = $default; } return strtoupper( $travel_mode ); } public function shortcode_register_script() { $min = WP_DEBUG ? '' : '.min'; if ( ! wp_style_is( 'nimap-locator', 'registered' ) ) { wp_register_style( 'nimap-locator', NIMAP_CSS . 'nimap-locator' . $min . '.css', array(), NIMAP_VERSION ); } if ( ! wp_style_is( 'nimap-list', 'registered' ) ) { wp_register_style( 'nimap-list', NIMAP_CSS . 'nimap-list' . $min . '.css', array(), NIMAP_VERSION ); } if ( ! wp_style_is( 'nimap-details', 'registered' ) ) { wp_register_style( 'nimap-details', NIMAP_CSS . 'nimap-details' . $min . '.css', array(), NIMAP_VERSION ); } if ( ! wp_style_is( 'nimap-widget', 'registered' ) ) { wp_register_style( 'nimap-widget', NIMAP_CSS . 'nimap-widget' . $min . '.css', array(), NIMAP_VERSION ); } if ( ! wp_style_is( 'nimap-icon', 'registered' ) ) { wp_register_style( 'nimap-icon', NIMAP_CSS . 'nimap-icon.min.css', array(), NIMAP_VERSION ); } if ( ! wp_script_is( 'nimap-locator', 'registered' ) ) { wp_register_script( 'nimap-locator', NIMAP_JS . 'nimap-locator' . $min . '.js', array( 'jquery' ), NIMAP_VERSION, false ); } if ( ! wp_script_is( 'nimap-list', 'registered' ) ) { wp_register_script( 'nimap-list', NIMAP_JS . 'nimap-list' . $min . '.js', array( 'jquery' ), NIMAP_VERSION, false ); } if ( ! wp_script_is( 'nimap-details', 'registered' ) ) { wp_register_script( 'nimap-details', NIMAP_JS . 'nimap-details' . $min . '.js', array( 'jquery' ), NIMAP_VERSION, false ); } if ( ! wp_script_is( 'nimap-widget', 'registered' ) ) { wp_register_script( 'nimap-widget', NIMAP_JS . 'nimap-widget' . $min . '.js', array( 'jquery' ), NIMAP_VERSION, false ); } if ( ! wp_script_is( 'nimap-infobox', 'registered' ) ) { wp_register_script( 'nimap-infobox', NIMAP_JS . 'infobox.js', array( 'jquery' ), NIMAP_VERSION, false ); } if ( ! wp_script_is( 'nimap-markerclusterer', 'registered' ) ) { wp_register_script( 'nimap-markerclusterer', NIMAP_JS . 'markerclusterer.js', array( 'jquery' ), NIMAP_VERSION, false ); } $detail_link = get_permalink( $this->settings->get_page_locator( 'general_store_detail' ) ); $list_vars = array( 'nonce' => wp_create_nonce( 'nimap-nonce' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'storeLink' => $detail_link, 'noResults' => $this->settings->get_params( 'list_no_result_title' ), 'countResults' => $this->settings->get_params( 'list_count_title' ), 'findEmpty' => esc_html__( 'No store found', '9map-map-multi-locations' ), 'preloader' => esc_html__( 'Searching...', '9map-map-multi-locations' ), 'autoCompleteOptions' => apply_filters( 'nimap_autocomplete_options', array( 'fields' => array( 'address_components', 'geometry', 'name' ), ) ), 'iconUrl' => NIMAP_IMAGES, 'mapDistanceUnit' => $this->settings->get_params( 'general_distance_unit' ) == 'km' ? '(km)' : '(ml)', ); //locator $eq_labels = array( 'preloader' => esc_html__( 'Searching...', '9map-map-multi-locations' ), 'noResults' => $this->settings->get_params( 'list_no_result_title' ), 'countResults' => $this->settings->get_params( 'list_count_title' ), 'moreInfo' => esc_html__( 'More info', '9map-map-multi-locations' ), 'generalError' => esc_html__( 'Something went wrong, please try again!', '9map-map-multi-locations' ), 'queryLimit' => esc_html__( 'API usage limit reached', '9map-map-multi-locations' ), 'directions' => esc_html__( 'Directions', '9map-map-multi-locations' ), 'noDirectionsFound' => esc_html__( 'No route could be found between the origin and destination', '9map-map-multi-locations' ), 'startPoint' => esc_html__( 'Start location', '9map-map-multi-locations' ), 'back' => esc_html__( 'Back', '9map-map-multi-locations' ), 'streetView' => esc_html__( 'Street view', '9map-map-multi-locations' ), 'zoomHere' => esc_html__( 'Zoom here', '9map-map-multi-locations' ), 'denied' => esc_html__( 'The application does not have permission to use the Geolocation API.', '9map-map-multi-locations' ), 'unavailable' => esc_html__( 'Location information is unavailable.', '9map-map-multi-locations' ), 'timeout' => esc_html__( 'The geolocation request timed out.', '9map-map-multi-locations' ), 'generalGeoError' => esc_html__( 'An unknown error occurred.', '9map-map-multi-locations' ) ); $st_localize = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'nimap-nonce' ), 'storeLink' => $detail_link, 'apiKey' => $this->settings->get_params( 'general_api_key' ), 'markerClusters' => $this->settings->get_params( 'map_marker_clusters' ) ?: 0, 'clusterZoom' => $this->settings->get_params( 'map_cluster_zoom' ) ?: 0, 'clusterSize' => $this->settings->get_params( 'map_cluster_size' ) ?: 0, 'autoLocate' => $this->settings->get_params( 'map_auto_locate' ) ?: 0, 'directionRedirect' => $this->settings->get_params( 'map_direction_redirect' ) ?: 0, 'autoLoad' => $this->settings->get_params( 'map_auto_load_stores' ), 'zoomLevel' => $this->settings->get_params( 'map_zoom_level' ), 'markerZoomTo' => $this->settings->get_params( 'map_marker_zoom_to' ) ?: 0, 'autoZoomLevel' => $this->settings->get_params( 'map_auto_zoom_level' ), 'scrollWheel' => $this->settings->get_params( 'map_scroll_wheel' ) ?: false, 'gestureHandling' => $this->settings->get_params( 'map_gesture_handling' ), 'controlPosition' => $this->settings->get_params( 'map_control_position' ) ?: 'RIGHT_BOTTOM', 'loadLocation' => $this->settings->get_params( 'map_load_location_init' ), 'startLatlng' => $this->settings->get_params( 'map_start_latitude' ) . ',' . $this->settings->get_params( 'map_start_longitude' ), 'infoWindowStyle' => $this->settings->get_params( 'map_info_window_style' ) ?: '', 'markerIconProps' => [ 'scaledSize' => '24,35', 'origin' => '0,0', 'anchor' => '12,35' ], 'url' => NIMAP_IMAGES, 'preloader' => NIMAP_IMAGES . 'ajax-loader.gif', 'autoCompleteOptions' => apply_filters( 'nimap_autocomplete_options', array( 'fields' => array( 'address_components', 'geometry', 'name' ), // 'fields' => array( "address_components", "geometry.location", "name" ), // 'types' => array( '(regions)' ) ) ), 'autoComplete' => $this->settings->get_params( 'map_auto_complete' ) ?: 1, 'mapType' => $this->settings->get_params( 'map_type' ) ?: 'roadmap', 'mapId' => $this->settings->get_params( 'general_map_id' ) ?: 'DEMO_MAP_ID', 'mapSIconType' => $this->settings->get_params( 'map_store_marker' ), 'mapSIcon' => $this->settings->get_params( 'map_store_marker_custom' ), 'mapUIconType' => $this->settings->get_params( 'map_user_marker' ), 'mapUIcon' => $this->settings->get_params( 'map_user_marker_custom' ), 'mapTypeControl' => $this->settings->get_params( 'map_type_control' ) ?: 0, 'mapStyle' => NIMAP_MULTI_LOCATOR_Function::mapStyle( $this->settings->get_params( 'map_style' ), $this->settings->get_params( 'map_custom_style' ) ), 'mapShowDistanceRadius' => $this->settings->get_params( 'map_show_distance_radius' ) ?: 0, 'mapLatitude' => $this->settings->get_params( 'map_start_latitude' ), 'mapLongitude' => $this->settings->get_params( 'map_start_longitude' ), 'mapDistanceUnit' => $this->settings->get_params( 'general_distance_unit' ) == 'km' ? '(km)' : '(ml)', 'mapDistanceEx' => $this->settings->get_params( 'general_distance_unit' ) == 'km' ? 1000 : 1609.34, 'maxResults' => $this->settings->get_params( 'map_max_results' ) ?: 99, 'mapRadiusColor' => $this->settings->get_params( 'map_radius_color' ) ?: '#80FFFF', 'mapRadiusBorderColor' => $this->settings->get_params( 'map_radius_border_color' ) ?: '#30BAFF', 'infoWidth' => $this->settings->get_params( 'info_width' ) ?: '', 'streetView' => $this->settings->get_params( 'map_street_view' ), 'searchRadius' => $this->settings->get_params( 'map_search_radius' ) ?: 500, 'phoneUrl' => $this->settings->get_params( 'map_phone_url' ) ?: 0, 'clickableDetails' => $this->settings->get_params( 'map_clickable_details' ) ?: 0, 'markerStreetView' => $this->settings->get_params( 'map_marker_street_view' ) ?: 0, 'runFitBounds' => $this->settings->get_params( 'map_run_fit_bounds' ) ?: 0, 'directionsTravelMode' => $this->get_directions_travel_mode(), 'enableStyledDropdowns' => apply_filters( 'nimap_enable_styled_dropdown', true ), 'geoLocationTimeout' => apply_filters( 'nimap_geolocation_timeout', 8000 ), 'storeMarker' => $this->settings->get_params( 'map_store_marker' ) == 'custom' ? $this->settings->get_params( 'map_store_marker_custom' ) : '', 'startMarker' => $this->settings->get_params( 'map_user_marker' ) == 'custom' ? $this->settings->get_params( 'map_user_marker_custom' ) : '', 'storeMarkerType' => $this->settings->get_params( 'map_store_marker_custom' ), 'clusterImagePath' => NIMAP_IMAGES . 'markerclusterer/m', ); wp_localize_script( 'nimap-locator', 'nimapLocator', $st_localize ); wp_localize_script( 'nimap-locator', 'nimapLabels', $eq_labels ); $css = ''; $css .= wp_kses_post( $this->settings->get_params( 'general_store_css' ) ); wp_add_inline_style( 'nimap-locator', wp_kses_post( $css ) ); //list wp_localize_script( 'nimap-list', 'nimapList', $list_vars ); $list_column = intval( $this->settings->get_params( 'store_result_column' ) ); $list_col_width = 1 != $list_column ? ceil( 94 / $list_column ) : 100; $css = ''; $css .= '.nimap-stores-wrap .nimap-result-section-wrap .nimap-result-list-wrap .nimap-item-container {'; $css .= 'width: ' . $list_col_width . '%'; $css .= '}'; $css .= wp_kses_post( $this->settings->get_params( 'general_store_css' ) ); wp_add_inline_style( 'nimap-list', wp_kses_post( $css ) ); //details wp_localize_script( 'nimap-details', 'nimapDetail', array( 'apiKey' => $this->settings->get_params( 'general_api_key' ), 'mapZoom' => $this->settings->get_params( 'map_zoom_level' ), 'mapId' => $this->settings->get_params( 'general_map_id' ) ?: 'DEMO_MAP_ID', 'mapSIconType' => $this->settings->get_params( 'map_store_marker' ), 'mapSIcon' => $this->settings->get_params( 'map_store_marker_custom' ), 'scrollWheel' => $this->settings->get_params( 'map_scroll_wheel' ) ?: false, 'gestureHandling' => $this->settings->get_params( 'map_gesture_handling' ) ?: 'cooperative', 'mapType' => $this->settings->get_params( 'map_type' ) ?: 'roadmap', 'mapStyle' => NIMAP_MULTI_LOCATOR_Function::mapStyle( $this->settings->get_params( 'map_style' ), $this->settings->get_params( 'map_custom_style' ) ), // 'mapLatitude' => $atts['select_latitude'], // 'mapLongitude' => $atts['select_longitude'], 'country_select' => esc_html__( 'Select an option', '9map-map-multi-locations' ), 'startLatitude' => $this->settings->get_params( 'map_start_latitude' ), 'startLongitude' => $this->settings->get_params( 'map_start_longitude' ), 'isCustomize' => self::is_customize_preview(), 'startPoint' => esc_html__( 'Store location', '9map-map-multi-locations' ), 'markerUrl' => NIMAP_IMAGES, 'generalGeoError' => esc_html__( 'An unknown error occurred.', '9map-map-multi-locations' ), 'unavailable' => esc_html__( 'Location information is unavailable.', '9map-map-multi-locations' ), ) ); $css = ''; $css .= wp_kses_post( $this->settings->get_params( 'general_store_css' ) ); wp_add_inline_style( 'nimap-details', wp_kses_post( $css ) ); //widget wp_localize_script( 'nimap-widget', 'nimapWidget', $list_vars ); $css = ''; $css .= wp_kses_post( $this->settings->get_params( 'general_store_css' ) ); wp_add_inline_style( 'nimap-widget', wp_kses_post( $css ) ); } public function enqueue_scripts( $type = '', $atts = array() ) { $detail_link = get_permalink( $this->settings->get_params( 'general_store_detail' ) ); $list_vars = []; if ( $type == 'widget' || $type == 'list' ) { $list_vars = array( 'nonce' => wp_create_nonce( 'nimap-nonce' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'noResults' => $this->settings->get_params( 'list_no_result_title' ), 'countResults' => $this->settings->get_params( 'list_count_title' ), 'findEmpty' => esc_html__( 'No store found', '9map-map-multi-locations' ), 'preloader' => esc_html__( 'Searching...', '9map-map-multi-locations' ), 'autoCompleteOptions' => apply_filters( 'nimap_autocomplete_options', array( 'fields' => array( 'address_components', 'geometry', 'name' ), ) ), 'iconUrl' => NIMAP_IMAGES, 'mapDistanceUnit' => $this->settings->get_params( 'general_distance_unit' ) == 'km' ? '(km)' : '(ml)', ); } switch ( $type ) { case 'locator': wp_enqueue_script( 'nimap-locator' ); wp_enqueue_style( 'nimap-locator' ); wp_enqueue_style( 'nimap-icon' ); NIMAP_MULTI_LOCATOR_Function::registerGoogleMaps( $atts ); // wp_enqueue_script( 'nimap-infobox' ); if ( $this->settings->get_params( 'map_marker_clusters' ) ) { wp_enqueue_script( 'nimap-markerclusterer' ); // wp_localize_script( 'nimap-locator', 'nimapLocator', array( // 'clusterImagePath' => 'https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m', // ) ); } $eq_labels = array( 'preloader' => esc_html__( 'Searching...', '9map-map-multi-locations' ), 'noResults' => $this->settings->get_params( 'list_no_result_title' ), 'countResults' => $this->settings->get_params( 'list_count_title' ), 'moreInfo' => esc_html__( 'More info', '9map-map-multi-locations' ), 'generalError' => esc_html__( 'Something went wrong, please try again!', '9map-map-multi-locations' ), 'queryLimit' => esc_html__( 'API usage limit reached', '9map-map-multi-locations' ), 'directions' => esc_html__( 'Directions', '9map-map-multi-locations' ), 'noDirectionsFound' => esc_html__( 'No route could be found between the origin and destination', '9map-map-multi-locations' ), 'startPoint' => esc_html__( 'Start location', '9map-map-multi-locations' ), 'back' => esc_html__( 'Back', '9map-map-multi-locations' ), 'streetView' => esc_html__( 'Street view', '9map-map-multi-locations' ), 'zoomHere' => esc_html__( 'Zoom here', '9map-map-multi-locations' ), 'denied' => esc_html__( 'The application does not have permission to use the Geolocation API.', '9map-map-multi-locations' ), 'unavailable' => esc_html__( 'Location information is unavailable.', '9map-map-multi-locations' ), 'timeout' => esc_html__( 'The geolocation request timed out.', '9map-map-multi-locations' ), 'generalGeoError' => esc_html__( 'An unknown error occurred.', '9map-map-multi-locations' ) ); $st_localize = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'nimap-nonce' ), 'storeLink' => $detail_link, 'apiKey' => $this->settings->get_params( 'general_api_key' ), 'markerClusters' => $this->settings->get_params( 'map_marker_clusters' ) ?: 0, 'clusterZoom' => $this->settings->get_params( 'map_cluster_zoom' ) ?: 0, 'clusterSize' => $this->settings->get_params( 'map_cluster_size' ) ?: 0, 'autoLocate' => $this->settings->get_params( 'map_auto_locate' ) ?: 0, 'directionRedirect' => $this->settings->get_params( 'map_direction_redirect' ) ?: 0, 'autoLoad' => $this->settings->get_params( 'map_auto_load_stores' ), 'zoomLevel' => $this->settings->get_params( 'map_zoom_level' ), 'markerZoomTo' => $this->settings->get_params( 'map_marker_zoom_to' ) ?: 0, 'autoZoomLevel' => $this->settings->get_params( 'map_auto_zoom_level' ), 'scrollWheel' => $this->settings->get_params( 'map_scroll_wheel' ) ?: false, 'gestureHandling' => $this->settings->get_params( 'map_gesture_handling' ), 'controlPosition' => $this->settings->get_params( 'map_control_position' ) ?: 'RIGHT_BOTTOM', 'loadLocation' => $this->settings->get_params( 'map_load_location_init' ), 'startLatlng' => $this->settings->get_params( 'map_start_latitude' ) . ',' . $this->settings->get_params( 'map_start_longitude' ), 'infoWindowStyle' => $this->settings->get_params( 'map_info_window_style' ) ?: '', 'markerIconProps' => [ 'scaledSize' => '24,35', 'origin' => '0,0', 'anchor' => '12,35' ], 'url' => NIMAP_IMAGES, 'preloader' => NIMAP_IMAGES . 'ajax-loader.gif', 'autoCompleteOptions' => apply_filters( 'nimap_autocomplete_options', array( 'fields' => array( 'address_components', 'geometry', 'name' ), // 'fields' => array( "address_components", "geometry.location", "name" ), // 'types' => array( '(regions)' ) ) ), 'autoComplete' => $this->settings->get_params( 'map_auto_complete' ) ?: 1, 'mapType' => $this->settings->get_params( 'map_type' ) ?: 'roadmap', 'mapTypeControl' => $this->settings->get_params( 'map_type_control' ) ?: 0, 'mapStyle' => $atts['map_style'] ?: NIMAP_MULTI_LOCATOR_Function::mapStyle( $atts['map_style'], $atts['map_custom_style'] ), 'mapShowDistanceRadius' => $this->settings->get_params( 'map_show_distance_radius' ) ?: 0, 'mapLatitude' => $this->settings->get_params( 'map_start_latitude' ), 'mapLongitude' => $this->settings->get_params( 'map_start_longitude' ), 'mapDistanceUnit' => $this->settings->get_params( 'general_distance_unit' ) == 'km' ? '(km)' : '(ml)', 'mapDistanceEx' => $this->settings->get_params( 'general_distance_unit' ) == 'km' ? 1000 : 1609.34, 'maxResults' => $this->settings->get_params( 'map_max_results' ) ?: 99, 'mapRadiusColor' => $this->settings->get_params( 'map_radius_color' ) ?: '#80FFFF', 'mapRadiusBorderColor' => $this->settings->get_params( 'map_radius_border_color' ) ?: '#30BAFF', 'infoWidth' => $this->settings->get_params( 'info_width' ) ?: '', 'streetView' => $this->settings->get_params( 'map_street_view' ), 'searchRadius' => $this->settings->get_params( 'map_search_radius' ) ?: 500, 'phoneUrl' => $this->settings->get_params( 'map_phone_url' ) ?: 0, 'clickableDetails' => $this->settings->get_params( 'map_clickable_details' ) ?: 0, 'markerStreetView' => $this->settings->get_params( 'map_marker_street_view' ) ?: 0, 'runFitBounds' => $this->settings->get_params( 'map_run_fit_bounds' ) ?: 0, 'directionsTravelMode' => $this->get_directions_travel_mode(), 'enableStyledDropdowns' => apply_filters( 'nimap_enable_styled_dropdown', true ), 'geoLocationTimeout' => apply_filters( 'nimap_geolocation_timeout', 8000 ), 'storeMarker' => apply_filters( 'nimap_store_marker', 'store.png' ), 'startMarker' => apply_filters( 'nimap_start_marker', 'user.png' ), 'clusterImagePath' => NIMAP_IMAGES . 'markerclusterer/m', ); // wp_localize_script( 'nimap-locator', 'nimapLocator', $st_localize ); // wp_add_inline_script( 'nimap-locator', 'nimapLocator', $st_localize ); // wp_localize_script( 'nimap-locator', 'nimapLabels', $eq_labels ); // // $css = ''; // $css .= wp_kses_post( $this->settings->get_params( 'general_store_css' ) ); // wp_add_inline_style( 'nimap-locator', wp_kses_post( $css ) ); break; case 'list': wp_enqueue_script( 'nimap-list' ); wp_enqueue_style( 'nimap-list' ); wp_enqueue_style( 'nimap-icon' ); NIMAP_MULTI_LOCATOR_Function::registerGoogleMaps( $atts, 'list' ); // wp_localize_script( 'nimap-list', 'nimapList', $list_vars ); // // $list_column = intval( $this->settings->get_params( 'store_result_column' ) ); // $list_col_width = 1 != $list_column ? ceil( 94 / $list_column ) : 100; // // $css = ''; //// $css .= '.nimap-stores-wrap .nimap-result-section-wrap .nimap-result-list-container .nimap-result-list-wrap {'; //// $css .= 'grid-template-columns: repeat(' . intval( $this->settings->get_params('store_result_column') ) . ', 1fr)'; //// $css .= '}'; // $css .= '.nimap-stores-wrap .nimap-result-section-wrap .nimap-result-list-wrap .nimap-item-container {'; // $css .= 'width: ' . $list_col_width . '%'; // $css .= '}'; // $css .= wp_kses_post( $this->settings->get_params( 'general_store_css' ) ); // wp_add_inline_style( 'nimap-list', wp_kses_post( $css ) ); break; case 'detail': wp_enqueue_script( 'nimap-details' ); wp_enqueue_style( 'nimap-details' ); wp_enqueue_style( 'nimap-icon' ); NIMAP_MULTI_LOCATOR_Function::registerGoogleMaps( $atts ); // wp_localize_script( 'nimap-details', 'nimapDetail', array( // 'apiKey' => $this->settings->get_params( 'general_api_key' ), // 'mapZoom' => $atts['map_zoom_level'] ?: $this->settings->get_params( 'map_zoom_level' ), // 'scrollWheel' => $this->settings->get_params( 'map_scroll_wheel' ) ?: false, // 'gestureHandling' => $this->settings->get_params( 'map_gesture_handling' ) ?: 'cooperative', // 'mapType' => $this->settings->get_params( 'map_type' ) ?: 'roadmap', // 'mapStyle' => $atts['map_style'] ?: NIMAP_MULTI_LOCATOR_Function::mapStyle( $atts['map_style'], $atts['map_custom_style'] ), // 'mapLatitude' => $atts['select_latitude'], // 'mapLongitude' => $atts['select_longitude'], // 'country_select' => esc_html__( 'Select an option', '9map-map-multi-locations' ), // 'startLatitude' => $this->settings->get_params( 'map_start_latitude' ), // 'startLongitude' => $this->settings->get_params( 'map_start_longitude' ), // 'startPoint' => esc_html__( 'Start location', '9map-map-multi-locations' ), // 'markerUrl' => NIMAP_IMAGES, // 'generalGeoError' => esc_html__( 'An unknown error occurred.', '9map-map-multi-locations' ), // 'unavailable' => esc_html__( 'Location information is unavailable.', '9map-map-multi-locations' ), // ) // ); // // $css = ''; // $css .= wp_kses_post( $this->settings->get_params( 'general_store_css' ) ); // wp_add_inline_style( 'nimap-details', wp_kses_post( $css ) ); break; case 'widget': wp_enqueue_script( 'nimap-widget' ); wp_enqueue_style( 'nimap-widget' ); wp_enqueue_style( 'nimap-icon' ); NIMAP_MULTI_LOCATOR_Function::registerGoogleMaps( $atts, 'widget' ); // wp_localize_script( 'nimap-widget', 'nimapWidget', $list_vars ); // // $css = ''; // $css .= wp_kses_post( $this->settings->get_params( 'general_store_css' ) ); // wp_add_inline_style( 'nimap-widget', wp_kses_post( $css ) ); default: // wp_enqueue_script( '-script' ); } } public static function is_customize_preview() { if ( isset( self::$cache['is_customize_preview'] ) ) { return self::$cache['is_customize_preview']; } return self::$cache['is_customize_preview'] = is_customize_preview(); } function format_lang_code( $i_lang, $locale = '' ) { $lang = $locale == '1' ? get_locale() : ''; // Lang override by attribute if ( ! empty( $i_lang ) && strlen( (string) $i_lang ) <= 13 ) { if ( $i_lang == 'en' ) { $lang = 'en_US'; } } else { $lang = 'en_US'; } // Clean the language code if ( $lang ) { $lang = esc_sql( $lang ); } return $lang; } } }