Пример #1
0
 function st_list_map_new($attr, $content = false)
 {
     $data = shortcode_atts(array('title' => '', 'st_list_location' => '', 'st_type' => 'st_hotel', 'zoom' => '13', 'height' => '500', 'number' => '12', 'style_map' => 'normal', 'show_circle' => 'no', 'range' => '20'), $attr, 'st_list_map_new');
     extract($data);
     $st_type = explode(',', $st_type);
     $map_lat = get_post_meta($st_list_location, 'map_lat', true);
     $map_lng = get_post_meta($st_list_location, 'map_lng', true);
     $location_center = '[' . $map_lat . ',' . $map_lng . ']';
     $class_traveler = new TravelerObject();
     $data_post = $class_traveler->get_near_by_lat_lng($map_lat, $map_lng, $st_type, $range, $number);
     global $post;
     $stt = 0;
     if (!empty($data_post)) {
         foreach ($data_post as $post) {
             setup_postdata($post);
             $map_lat = get_post_meta(get_the_ID(), 'map_lat', true);
             $map_lng = get_post_meta(get_the_ID(), 'map_lng', true);
             if (!empty($map_lat) and !empty($map_lng) and is_numeric($map_lat) and is_numeric($map_lng)) {
                 $post_type = get_post_type();
                 $data_map[$stt]['id'] = get_the_ID();
                 $data_map[$stt]['name'] = get_the_title();
                 $data_map[$stt]['post_type'] = $post_type;
                 $data_map[$stt]['lat'] = $map_lat;
                 $data_map[$stt]['lng'] = $map_lng;
                 $post_type_name = get_post_type_object($post_type);
                 $post_type_name->label;
                 switch ($post_type) {
                     case "st_hotel":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_hotel_icon_map_marker', 'http://maps.google.com/mapfiles/marker_black.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/hotel', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/hotel', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_rental":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_rental_icon_map_marker', 'http://maps.google.com/mapfiles/marker_brown.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/rental', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/rental', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_cars":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_cars_icon_map_marker', 'http://maps.google.com/mapfiles/marker_green.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/car', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/car', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_tours":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_tours_icon_map_marker', 'http://maps.google.com/mapfiles/marker_purple.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/tour', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/tour', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_holidays":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_holidays_icon_map_marker', 'http://maps.google.com/mapfiles/marker_purple.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/holiday', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/holiday', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_activity":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_activity_icon_map_marker', 'http://maps.google.com/mapfiles/marker_yellow.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/activity', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/activity', false, array('post_type' => $post_type_name->label)));
                         break;
                 }
                 $stt++;
             }
         }
         wp_reset_postdata();
         if ($location_center == '[,]') {
             $location_center = '[0,0]';
         }
         if ($show_circle == 'no') {
             $range = 0;
         }
         $data_tmp = array('location_center' => $location_center, 'zoom' => $zoom, 'data_map' => $data_map, 'height' => $height, 'style_map' => $style_map, 'st_type' => $st_type, 'number' => $number, 'title' => $title, 'range' => $range);
         $data_tmp['data_tmp'] = $data_tmp;
         $html = st()->load_template('vc-elements/st-list-map-new/html', '', $data_tmp);
     }
     return $html;
     $ids = $st_list_location;
     $_SESSION['el_st_type'] = $st_type;
     $_SESSION['el_location_id'] = $st_list_location;
     $st_list_map = new st_list_map();
     add_filter('posts_where', array($st_list_map, '_get_query_where'));
     add_filter('posts_join', array($st_list_map, '_get_query_join'));
     $html = '';
     if (!empty($ids)) {
         $query = array('post_type' => explode(',', $st_type), 'posts_per_page' => $number, 'post_status' => 'publish');
         $map_lat = get_post_meta($ids, 'map_lat', true);
         $map_lng = get_post_meta($ids, 'map_lng', true);
         $location_center = '[' . $map_lat . ',' . $map_lng . ']';
         $data_map = array();
         global $wp_query;
         query_posts($query);
         remove_filter('posts_where', array($st_list_map, '_get_query_where'));
         remove_filter('posts_join', array($st_list_map, '_get_query_join'));
         unset($_SESSION['el_st_type']);
         unset($_SESSION['el_location_id']);
         $stt = 0;
         while (have_posts()) {
             the_post();
             $map_lat = get_post_meta(get_the_ID(), 'map_lat', true);
             $map_lng = get_post_meta(get_the_ID(), 'map_lng', true);
             if (!empty($map_lat) and !empty($map_lng) and is_numeric($map_lat) and is_numeric($map_lng)) {
                 $post_type = get_post_type();
                 $data_map[$stt]['id'] = get_the_ID();
                 $data_map[$stt]['name'] = get_the_title();
                 $data_map[$stt]['post_type'] = $post_type;
                 $data_map[$stt]['lat'] = $map_lat;
                 $data_map[$stt]['lng'] = $map_lng;
                 $post_type_name = get_post_type_object($post_type);
                 $post_type_name->label;
                 switch ($post_type) {
                     case "st_hotel":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_hotel_icon_map_marker', 'http://maps.google.com/mapfiles/marker_black.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/hotel', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/hotel', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_rental":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_rental_icon_map_marker', 'http://maps.google.com/mapfiles/marker_brown.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/rental', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/rental', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_cars":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_cars_icon_map_marker', 'http://maps.google.com/mapfiles/marker_green.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/car', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/car', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_tours":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_tours_icon_map_marker', 'http://maps.google.com/mapfiles/marker_purple.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/tour', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/tour', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_holidays":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_holidays_icon_map_marker', 'http://maps.google.com/mapfiles/marker_purple.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/holiday', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/holiday', false, array('post_type' => $post_type_name->label)));
                         break;
                     case "st_activity":
                         $data_map[$stt]['icon_mk'] = st()->get_option('st_activity_icon_map_marker', 'http://maps.google.com/mapfiles/marker_yellow.png');
                         $data_map[$stt]['content_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop/activity', false, array('post_type' => $post_type_name->label)));
                         $data_map[$stt]['content_adv_html'] = preg_replace('/^\\s+|\\n|\\r|\\s+$/m', '', st()->load_template('vc-elements/st-list-map/loop-adv/activity', false, array('post_type' => $post_type_name->label)));
                         break;
                 }
                 $stt++;
             }
         }
         wp_reset_query();
         if ($location_center == '[,]') {
             $location_center = '[0,0]';
         }
         $data_tmp = array('location_center' => $location_center, 'zoom' => $zoom, 'data_map' => $data_map, 'height' => $height, 'style_map' => $style_map, 'st_type' => $st_type, 'number' => $number, 'title' => $title, 'show_search_box' => $show_search_box, 'show_data_list_map' => $show_data_list_map);
         $data_tmp['data_tmp'] = $data_tmp;
         $html = st()->load_template('vc-elements/st-list-map-new/html', '', $data_tmp);
     }
     return $html;
 }