Пример #1
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_holidays')) {
         return $where;
     }
     global $wpdb;
     if (isset($_REQUEST['location_id']) && !empty($_REQUEST['location_id'])) {
         $location_id = STInput::get('location_id', '');
         $list = TravelHelper::getLocationByParent($location_id);
         if (is_array($list) && count($list)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($list as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $list = implode(',', $list);
             $where_tmp .= " OR tb.id_location IN ({$list})";
             $where .= $where_tmp . ")";
         } else {
             $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.id_location IN ('{$location_id}')) ";
         }
     } elseif (isset($_REQUEST['location_name']) && !empty($_REQUEST['location_name'])) {
         $location_name = STInput::get('location_name', '');
         $ids_location = TravelerObject::_get_location_by_name($location_name);
         if (is_array($ids_location) && count($ids_location)) {
             $ids_location_tmp = array();
             foreach ($ids_location as $item) {
                 $list = TravelHelper::getLocationByParent($item);
                 if (is_array($list) && count($list)) {
                     foreach ($list as $item) {
                         $ids_location_tmp[] = $item;
                     }
                 }
             }
             if (count($ids_location_tmp)) {
                 $ids_location = $ids_location_tmp;
             }
         }
         if (is_array($ids_location) && count($ids_location)) {
             $where .= " AND ((";
             $where_tmp = "";
             foreach ($ids_location as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $ids_location = implode(',', $ids_location);
             $where_tmp .= " OR tb.id_location IN ({$ids_location})";
             $where .= $where_tmp . ")";
             $where .= " OR (tb.address LIKE '%{$location_name}%'";
             $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%'))";
         } else {
             if (!empty($_REQUEST['search_all'])) {
                 $where .= " AND (tb.address LIKE '%{$location_name}%'";
                 $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')";
             }
         }
     } elseif (isset($_REQUEST['address']) && !empty($_REQUEST['address'])) {
         $address = STInput::request('address', '');
         $value = STInput::request('address');
         $value = explode(",", $value);
         if (!empty($value[0]) and !empty($value[2])) {
             $where .= " AND ( tb.address LIKE '%{$value[0]}%' OR tb.address LIKE '%{$value[2]}%')";
         } else {
             $where .= " AND ( tb.address LIKE '%{$address}%')";
         }
     }
     if (isset($_REQUEST['item_id']) and !empty($_REQUEST['item_id'])) {
         $item_id = STInput::request('item_id', '');
         $where .= " AND ({$wpdb->prefix}posts.ID = '{$item_id}')";
     }
     if (isset($_REQUEST['item_name']) and !empty($_REQUEST['item_name'])) {
         $item_name = STInput::request('item_name', '');
         $where .= " AND ({$wpdb->prefix}posts.post_title LIKE '%{$item_name}%')";
     }
     if (isset($_REQUEST['people']) && !empty($_REQUEST['people'])) {
         $people = STInput::get('people', 1);
         $where .= " AND (tb.max_people >= {$people})";
     }
     if (isset($_REQUEST['duration']) && !empty($_REQUEST['duration'])) {
         $duration = intval(STInput::get('duration', 1));
         $today = time();
         $where .= "AND (\r\n                        (\r\n                            tb.duration_day = {$duration}\r\n                            AND tb.type_holiday = 'daily_holiday'\r\n                        )\r\n                    )";
         /*$where .= "AND (
               (
                   tb.duration_day >= {$duration}
                   AND tb.type_holiday = 'daily_holiday'
               )
               OR (
                   (
                      (UNIX_TIMESTAMP(STR_TO_DATE(tb.check_out, '%Y-%m-%d')) - UNIX_TIMESTAMP(STR_TO_DATE(tb.check_in, '%Y-%m-%d'))) / (60*60*24) + 1
                   ) >= {$duration}
               )
           )";*/
     }
     if (isset($_REQUEST['price_range'])) {
         $price = STInput::get('price_range', '0;0');
         $priceobj = explode(';', $price);
         $priceobj[0] = TravelHelper::convert_money_to_default($priceobj[0]);
         $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
         $min_range = $priceobj[0];
         $max_range = $priceobj[1];
         /*$where .= " AND (
               (CAST(tb.child_price AS DECIMAL) >= {$min_range} and CAST(tb.child_price AS DECIMAL) <= {$max_range})
               OR (CAST(tb.adult_price AS DECIMAL) >= {$min_range} and CAST(tb.adult_price AS DECIMAL) <= {$max_range})
           ) ";*/
         $where .= " AND ( \r\n                        (CAST(tb.adult_price AS DECIMAL) >= {$min_range} and CAST(tb.adult_price AS DECIMAL) <= {$max_range})\r\n                    ) ";
     }
     $start = STInput::request("start");
     $end = STInput::request("end");
     if (!empty($start) && !empty($end)) {
         $today = date('Y-m-d');
         $check_in = date('Y-m-d', strtotime(TravelHelper::convertDateFormat(STInput::request("start"))));
         $period = TravelHelper::dateDiff($today, $check_in);
         if ($period < 0) {
             $period = 0;
         }
         $check_out = date('Y-m-d', strtotime(TravelHelper::convertDateFormat(STInput::request("end"))));
         $list_date = HolidayHelper::_holidayValidate($check_in);
         if (is_array($list_date) && count($list_date)) {
             $list = implode(',', $list_date);
         } else {
             $list = "''";
         }
         $where .= " AND {$wpdb->posts}.ID NOT IN ({$list})";
         /* $where .= " AND (
            (
                tb.type_holiday = 'specific_date'
                AND (
                    UNIX_TIMESTAMP(
                        STR_TO_DATE(tb.check_in, '%Y-%m-%d')
                    ) - UNIX_TIMESTAMP(
                        STR_TO_DATE('{$check_in}', '%Y-%m-%d')
                    ) <= 0
                )
                AND (
                    UNIX_TIMESTAMP(
                        STR_TO_DATE(tb.check_out, '%Y-%m-%d')
                    ) - UNIX_TIMESTAMP(
                        STR_TO_DATE('{$check_out}', '%Y-%m-%d')
                    ) >= 0
                )
            )
            OR (
                tb.type_holiday = 'daily_holiday'
                AND (tb.holidays_booking_period <= {$period})
            ))";*/
     }
     if (isset($_REQUEST['star_rate']) && !empty($_REQUEST['star_rate'])) {
         $stars = STInput::get('star_rate', 1);
         $stars = explode(',', $stars);
         $all_star = array();
         if (!empty($stars) && is_array($stars)) {
             foreach ($stars as $val) {
                 for ($i = $val; $i < $val + 0.9; $i += 0.1) {
                     if ($i) {
                         $all_star[] = $i;
                     }
                 }
             }
         }
         $list_star = implode(',', $all_star);
         if ($list_star) {
             $where .= " AND (tb.rate_review IN ({$list_star}))";
         }
     }
     if (isset($_REQUEST['range']) and isset($_REQUEST['location_id'])) {
         $range = STInput::request('range', '5');
         $location_id = STInput::request('location_id');
         $post_type = get_query_var('post_type');
         $map_lat = (double) get_post_meta($location_id, 'map_lat', true);
         $map_lng = (double) get_post_meta($location_id, 'map_lng', true);
         global $wpdb;
         $where .= "\r\n                    AND {$wpdb->posts}.ID IN (\r\n                            SELECT ID FROM (\r\n                                SELECT {$wpdb->posts}.*,( 6371 * acos( cos( radians({$map_lat}) ) * cos( radians( mt1.meta_value ) ) *\r\n                                                cos( radians( mt2.meta_value ) - radians({$map_lng}) ) + sin( radians({$map_lat}) ) *\r\n                                                sin( radians( mt1.meta_value ) ) ) ) AS distance\r\n                                                    FROM {$wpdb->posts}, {$wpdb->postmeta} as mt1,{$wpdb->postmeta} as mt2\r\n                                                    WHERE {$wpdb->posts}.ID = mt1.post_id\r\n                                                    and {$wpdb->posts}.ID=mt2.post_id\r\n                                                    AND mt1.meta_key = 'map_lat'\r\n                                                    and mt2.meta_key = 'map_lng'\r\n                                                    AND {$wpdb->posts}.post_status = 'publish'\r\n                                                    AND {$wpdb->posts}.post_type = '{$post_type}'\r\n                                                    AND {$wpdb->posts}.post_date < NOW()\r\n                                                    GROUP BY {$wpdb->posts}.ID HAVING distance<{$range}\r\n                                                    ORDER BY distance ASC\r\n                            ) as st_data\r\n                    )";
     }
     return $where;
 }
Пример #2
0
 function change_search_activity_arg($query)
 {
     $post_type = get_query_var('post_type');
     if ($query->is_search && $post_type == 'st_activity') {
         $tax = STInput::get('taxonomy');
         if (!empty($tax) and is_array($tax)) {
             $tax_query = array();
             foreach ($tax as $key => $value) {
                 if ($value) {
                     $tax_query[] = array('taxonomy' => $key, 'terms' => explode(',', $value), 'COMPARE' => "IN");
                 }
             }
             $query->set('tax_query', $tax_query);
         }
         if ($location_id = STInput::get('location_id')) {
             $ids_in = array();
             $parents = get_posts(array('numberposts' => -1, 'post_status' => 'publish', 'post_type' => 'location', 'post_parent' => $location_id));
             $ids_in[] = $location_id;
             foreach ($parents as $child) {
                 $ids_in[] = $child->ID;
             }
             $meta_query[] = array('key' => 'id_location', 'value' => $ids_in, 'compare' => 'IN');
             $query->set('meta_query', $meta_query);
             //$query->set('s','');
         } else {
             if (STInput::request('location_name')) {
                 $ids_location = TravelerObject::_get_location_by_name(STInput::get('location_name'));
                 if (!empty($ids_location)) {
                     $meta_query[] = array('key' => 'id_location', 'value' => $ids_location, 'compare' => "IN");
                 } else {
                     $meta_query[] = array('key' => 'address', 'value' => STInput::get('location_name'), 'compare' => "like");
                 }
             } elseif (STInput::request('address')) {
                 $value = STInput::request('address');
                 $value = explode(",", $value);
                 if (!empty($value[0]) and !empty($value[2])) {
                     $meta_query[] = array(array('key' => 'address', 'value' => $value[0], 'compare' => 'like'), array('key' => 'address', 'value' => $value[2], 'compare' => 'like'), "relation" => 'OR');
                 } else {
                     $meta_query[] = array('key' => 'address', 'value' => STInput::request('address'), 'compare' => "like");
                 }
             }
         }
         $is_featured = st()->get_option('is_featured_search_activity', 'off');
         if (!empty($is_featured) and $is_featured == 'on') {
             $query->set('meta_key', 'is_featured');
             $query->set('orderby', 'meta_value');
             $query->set('order', 'DESC');
         }
         if ($orderby = STInput::get('orderby')) {
             switch ($orderby) {
                 case "price_asc":
                     $query->set('meta_key', 'sale_price');
                     $query->set('orderby', 'meta_value_num');
                     $query->set('order', 'ASC');
                     break;
                 case "price_desc":
                     $query->set('meta_key', 'sale_price');
                     $query->set('orderby', 'meta_value_num');
                     $query->set('order', 'DESC');
                     break;
                 case "name_a_z":
                     $query->set('orderby', 'name');
                     $query->set('order', 'asc');
                     break;
                 case "name_z_a":
                     $query->set('orderby', 'name');
                     $query->set('order', 'desc');
                     break;
             }
         }
         if ($price = STInput::get('price_range')) {
             $priceobj = explode(';', $price);
             $meta_query[] = array('key' => 'price', 'value' => $priceobj[0], 'compare' => '>=', 'type' => "NUMERIC");
             if (isset($priceobj[1])) {
                 $meta_query[] = array('key' => 'price', 'value' => $priceobj[1], 'compare' => '<=', 'type' => "NUMERIC");
             }
             $meta_query['relation'] = 'and';
         }
         if ($price = STInput::get('start')) {
             $meta_query[] = array('key' => 'check_in', 'value' => date('Y-m-d', strtotime($price = STInput::get('start'))), 'compare' => '<=', 'meta_type' => 'DATE');
             $meta_query['relation'] = 'and';
         }
         if ($price = STInput::get('end')) {
             $meta_query[] = array('key' => 'check_out', 'value' => date('Y-m-d', strtotime($price = STInput::get('end'))), 'compare' => '>=', 'meta_type' => 'DATE');
             $meta_query['relation'] = 'and';
         }
         if ($star = STInput::get('star_rate')) {
             $meta_query[] = array('key' => 'rate_review', 'value' => explode(',', $star), 'compare' => "IN");
         }
         if (!empty($meta_query)) {
             $query->set('meta_query', $meta_query);
         }
     }
 }
Пример #3
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_rental')) {
         return $where;
     }
     global $wpdb;
     if ($location_id = STInput::get('location_id') and STInput::get('location_id') or get_post_type(get_the_ID()) == 'location') {
         if (!$location_id) {
             $location_id = get_the_ID();
         }
         $list = TravelHelper::getLocationByParent($location_id);
         if (is_array($list) && count($list)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($list as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $list = implode(',', $list);
             $where_tmp .= " OR tb.location_id IN ({$list})";
             $where .= $where_tmp . ")";
         } else {
             $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.location_id IN ('{$location_id}')) ";
         }
     } elseif ($location_name = STInput::request('location_name')) {
         $ids_location = TravelerObject::_get_location_by_name($location_name);
         if (is_array($ids_location) && count($ids_location)) {
             $ids_location_tmp = array();
             foreach ($ids_location as $item) {
                 $list = TravelHelper::getLocationByParent($item);
                 if (is_array($list) && count($list)) {
                     foreach ($list as $item) {
                         $ids_location_tmp[] = $item;
                     }
                 }
             }
             if (count($ids_location_tmp)) {
                 $ids_location = $ids_location_tmp;
             }
         }
         if (!empty($ids_location)) {
             $where .= " AND ((";
             $where_tmp = "";
             foreach ($ids_location as $id) {
                 if (empty($where_tmp)) {
                     $where_tmp .= " tb.multi_location LIKE '%_{$id}_%' ";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$id}_%' ";
                 }
             }
             $ids_location = implode(',', $ids_location);
             $where_tmp .= " OR (tb.location_id IN ({$ids_location})";
             $where .= $where_tmp . ")";
             $where .= " OR (tb.address LIKE '%{$location_name}%'";
             $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')))";
         } else {
             if (!empty($_REQUEST['search_all'])) {
                 $where .= " AND (tb.address LIKE '%{$location_name}%'";
                 $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')";
             }
         }
     } elseif ($address = STInput::request('address', '')) {
         $value = STInput::request('address');
         $value = explode(",", $value);
         if (!empty($value[0]) and !empty($value[2])) {
             $where .= " AND (tb.address LIKE '%{$value[0]}%' OR tb.address LIKE '%{$value[2]}%')";
         } else {
             $where .= " AND (tb.address LIKE '%{$address}%')";
         }
     }
     if (isset($_GET['start']) && isset($_GET['end']) and !empty($_GET['start']) and !empty($_GET['end'])) {
         $check_in = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['start'])));
         $check_out = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['end'])));
         $today = date('m/d/Y');
         $period = TravelHelper::dateDiff($today, $check_in);
         $adult_number = STInput::get('adult_number', 0);
         if (intval($adult_number) < 0) {
             $adult_number = 0;
         }
         $children_number = STInput::get('children_num', 0);
         if (intval($children_number) < 0) {
             $children_number = 0;
         }
         $list_rental = RentalHelper::_rentalValidate($check_in, $check_out, $adult_number, $children_number, 1);
         if (!is_array($list_rental) || count($list_rental) <= 0) {
             $list_rental = "''";
         } else {
             $list_rental = implode(',', $list_rental);
         }
         $where .= " AND {$wpdb->posts}.ID NOT IN ({$list_rental}) AND CAST(tb.rentals_booking_period AS UNSIGNED) <= {$period}";
     }
     if ($star = STInput::get('star_rate')) {
         $stars = STInput::get('star_rate', 1);
         $stars = explode(',', $stars);
         $all_star = array();
         if (!empty($stars) && is_array($stars)) {
             foreach ($stars as $val) {
                 for ($i = $val; $i < $val + 0.9; $i += 0.1) {
                     if ($i) {
                         $all_star[] = $i;
                     }
                 }
             }
         }
         $list_star = implode(',', $all_star);
         if ($list_star) {
             $where .= " AND (tb.rate_review IN ({$list_star}))";
         }
     }
     if ($price = STInput::get('price_range')) {
         $priceobj = explode(';', $price);
         $priceobj[0] = TravelHelper::convert_money_to_default($priceobj[0]);
         $where .= " AND (tb.sale_price >= {$priceobj[0]})";
         if (isset($priceobj[1])) {
             $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
             $where .= " AND (tb.sale_price <= {$priceobj[1]})";
         }
     }
     if (isset($_REQUEST['range']) and isset($_REQUEST['location_id'])) {
         $range = STInput::request('range', '5');
         $location_id = STInput::request('location_id');
         $post_type = get_query_var('post_type');
         $map_lat = (double) get_post_meta($location_id, 'map_lat', true);
         $map_lng = (double) get_post_meta($location_id, 'map_lng', true);
         global $wpdb;
         $where .= "\r\n                AND {$wpdb->posts}.ID IN (\r\n                        SELECT ID FROM (\r\n                            SELECT {$wpdb->posts}.*,( 6371 * acos( cos( radians({$map_lat}) ) * cos( radians( mt1.meta_value ) ) *\r\n                                            cos( radians( mt2.meta_value ) - radians({$map_lng}) ) + sin( radians({$map_lat}) ) *\r\n                                            sin( radians( mt1.meta_value ) ) ) ) AS distance\r\n                                                FROM {$wpdb->posts}, {$wpdb->postmeta} as mt1,{$wpdb->postmeta} as mt2\r\n                                                WHERE {$wpdb->posts}.ID = mt1.post_id\r\n                                                and {$wpdb->posts}.ID=mt2.post_id\r\n                                                AND mt1.meta_key = 'map_lat'\r\n                                                and mt2.meta_key = 'map_lng'\r\n                                                AND {$wpdb->posts}.post_status = 'publish'\r\n                                                AND {$wpdb->posts}.post_type = '{$post_type}'\r\n                                                AND {$wpdb->posts}.post_date < NOW()\r\n                                                GROUP BY {$wpdb->posts}.ID HAVING distance<{$range}\r\n                                                ORDER BY distance ASC\r\n                        ) as st_data\r\n\t            )";
     }
     if (isset($_REQUEST['item_id']) and !empty($_REQUEST['item_id'])) {
         $item_id = STInput::request('item_id', '');
         $where .= " AND ({$wpdb->prefix}posts.ID = '{$item_id}')";
     }
     if (!empty($_REQUEST['room_num_search'])) {
         $room_num_search = $_REQUEST['room_num_search'];
         $list_not_in = RentalHelper::get_list_not_in($room_num_search);
         $where .= " AND {$wpdb->prefix}posts.ID NOT IN ({$list_not_in})";
     }
     return $where;
 }
Пример #4
0
 /**
  * Add query meta max adult, children
  * @since 1.1.0
  **/
 function change_search_arg($query)
 {
     $post_type = get_query_var('post_type');
     $meta_query = array();
     if ($query->is_search && $post_type == 'st_rental') {
         add_filter('posts_where', array($this, '_alter_search_query'));
         $tax = STInput::get('taxonomy');
         if (!empty($tax) and is_array($tax)) {
             $tax_query = array();
             foreach ($tax as $key => $value) {
                 if ($value) {
                     $tax_query[] = array('taxonomy' => $key, 'terms' => explode(',', $value), 'COMPARE' => "IN");
                 }
             }
             $query->set('tax_query', $tax_query);
         }
         if ($location_id = STInput::get('location_id')) {
             $ids_in = array();
             $parents = get_posts(array('numberposts' => -1, 'post_status' => 'publish', 'post_type' => 'location', 'post_parent' => $location_id));
             $ids_in[] = $location_id;
             foreach ($parents as $child) {
                 $ids_in[] = $child->ID;
             }
             $meta_query[] = array('key' => 'location_id', 'value' => $ids_in, 'compare' => 'IN');
             //                    $query->set('s', '');
         } else {
             if (STInput::request('location_name')) {
                 $ids_location = TravelerObject::_get_location_by_name(STInput::get('location_name'));
                 if (!empty($ids_location)) {
                     $meta_query[] = array('key' => 'location_id', 'value' => $ids_location, 'compare' => "IN");
                 } else {
                     $meta_query[] = array('key' => 'address', 'value' => STInput::get('location_name'), 'compare' => "like");
                 }
             } elseif (STInput::request('address')) {
                 $value = STInput::request('address');
                 $value = explode(",", $value);
                 if (!empty($value[0]) and !empty($value[2])) {
                     $meta_query[] = array(array('key' => 'address', 'value' => $value[0], 'compare' => 'like'), array('key' => 'address', 'value' => $value[2], 'compare' => 'like'), "relation" => 'OR');
                 } else {
                     $meta_query[] = array('key' => 'address', 'value' => STInput::request('address'), 'compare' => "like");
                 }
             }
         }
         $is_featured = st()->get_option('is_featured_search_rental', 'off');
         if (!empty($is_featured) and $is_featured == 'on') {
             $query->set('meta_key', 'is_featured');
             $query->set('orderby', 'meta_value');
             $query->set('order', 'DESC');
         }
         if ($orderby = STInput::get('orderby')) {
             switch ($orderby) {
                 case "price_asc":
                     $query->set('meta_key', 'sale_price');
                     $query->set('orderby', 'meta_value');
                     $query->set('order', 'asc');
                     break;
                 case "price_desc":
                     $query->set('meta_key', 'sale_price');
                     $query->set('orderby', 'meta_value');
                     $query->set('order', 'desc');
                     break;
                 case "avg_rate":
                     $query->set('meta_key', 'rate_review');
                     $query->set('orderby', 'meta_value');
                     $query->set('order', 'desc');
                     break;
                 case "name_asc":
                     $query->set('orderby', 'title');
                     $query->set('order', 'asc');
                     break;
                 case "name_desc":
                     $query->set('orderby', 'title');
                     $query->set('order', 'desc');
                     break;
             }
         }
         $adult = intval(STInput::get('adult_num'));
         if ($adult) {
             $meta_query[] = array('key' => 'rental_max_adult', 'value' => $adult, 'compare' => '>=');
         }
         $children = intval(STInput::get('children_num'));
         if ($children) {
             $meta_query[] = array('key' => 'rental_max_children', 'value' => $children, 'compare' => '>=');
         }
         if ($star = STInput::get('star_rate')) {
             $meta_query[] = array('key' => 'rate_review', 'value' => explode(',', $star), 'compare' => "IN");
         }
         if ($price = STInput::get('price_range')) {
             $priceobj = explode(';', $price);
             $meta_query[] = array('key' => 'sale_price', 'value' => $priceobj[0], 'compare' => '>=', 'type' => "NUMERIC");
             if (isset($priceobj[1])) {
                 $meta_query[] = array('key' => 'sale_price', 'value' => $priceobj[1], 'compare' => '<=', 'type' => "NUMERIC");
             }
             $meta_query['relation'] = 'and';
         }
         if (!empty($meta_query)) {
             $query->set('meta_query', $meta_query);
         }
     } else {
         remove_filter('posts_where', array($this, '_alter_search_query'));
     }
 }
Пример #5
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_hotel')) {
         return $where;
     }
     global $wpdb;
     $where .= "";
     if (isset($_REQUEST['location_id']) && !empty($_REQUEST['location_id'])) {
         $location_id = STInput::request('location_id', '');
         $list = TravelHelper::getLocationByParent($location_id);
         if (is_array($list) && count($list)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($list as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $list = implode(',', $list);
             $where_tmp .= " OR tb.id_location IN ({$list})";
             $where .= $where_tmp . ")";
         } else {
             $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.id_location IN ('{$location_id}')) ";
         }
     } else {
         if (!empty($_REQUEST['location_name'])) {
             $location_name = STInput::request('location_name', '');
             $ids_location = TravelerObject::_get_location_by_name($location_name);
             if (is_array($ids_location) && count($ids_location)) {
                 $ids_location_tmp = array();
                 foreach ($ids_location as $item) {
                     $list = TravelHelper::getLocationByParent($item);
                     if (is_array($list) && count($list)) {
                         foreach ($list as $item) {
                             $ids_location_tmp[] = $item;
                         }
                     }
                 }
                 if (count($ids_location_tmp)) {
                     $ids_location = $ids_location_tmp;
                 }
             }
             if (is_array($ids_location) && count($ids_location)) {
                 $where .= " AND ((";
                 $where_tmp = "";
                 foreach ($ids_location as $id) {
                     if (empty($where_tmp)) {
                         $where_tmp .= " tb.multi_location LIKE '%_{$id}_%' ";
                     } else {
                         $where_tmp .= " OR tb.multi_location LIKE '%_{$id}_%' ";
                     }
                 }
                 $ids_location = implode(',', $ids_location);
                 $where_tmp .= " OR (tb.id_location IN ({$ids_location})";
                 $where .= $where_tmp . ")";
                 $where .= " OR (tb.address LIKE '%{$location_name}%'";
                 $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')))";
             } else {
                 if (!empty($_REQUEST['search_all'])) {
                     $where .= " AND (tb.address LIKE '%{$location_name}%'";
                     $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')";
                 }
             }
         } elseif (isset($_REQUEST['address']) && !empty($_REQUEST['address'])) {
             $address = STInput::request('address', '');
             $value = STInput::request('address');
             $value = explode(",", $value);
             if (!empty($value[0]) and !empty($value[2])) {
                 $where .= " AND ( tb.address LIKE '%{$value[0]}%' OR tb.address LIKE '%{$value[2]}%')";
             } else {
                 $where .= " AND ( tb.address LIKE '%{$address}%')";
             }
         }
     }
     if (isset($_GET['start']) && !empty($_GET['start']) && isset($_GET['end']) && !empty($_GET['end'])) {
         $check_in = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['start'])));
         $check_out = date('Y-m-d', strtotime(TravelHelper::convertDateFormat($_GET['end'])));
         $today = date('m/d/Y');
         $period = TravelHelper::dateDiff($today, $check_in);
         $adult_number = STInput::get('adult_number', 0);
         if (intval($adult_number) < 0) {
             $adult_number = 0;
         }
         $children_number = STInput::get('children_num', 0);
         if (intval($children_number) < 0) {
             $children_number = 0;
         }
         $number_room = STInput::get('room_num_search', 0);
         if (intval($number_room) < 0) {
             $number_room = 0;
         }
         $list_hotel = HotelHelper::_hotelValidate($check_in, $check_out, $adult_number, $children_number, $number_room);
         if (!is_array($list_hotel) || count($list_hotel) <= 0) {
             $list_hotel = "''";
         } else {
             $list_hotel = implode(',', $list_hotel);
         }
         $where .= " AND {$wpdb->prefix}posts.ID NOT IN ({$list_hotel}) AND CAST(tb.hotel_booking_period AS UNSIGNED) <= {$period}";
     }
     if (isset($_REQUEST['star_rate']) && !empty($_REQUEST['star_rate'])) {
         $stars = STInput::get('star_rate', 1);
         $stars = explode(',', $stars);
         $all_star = array();
         if (!empty($stars) && is_array($stars)) {
             foreach ($stars as $val) {
                 for ($i = $val; $i < $val + 0.9; $i += 0.1) {
                     if ($i) {
                         $all_star[] = $i;
                     }
                 }
             }
         }
         $list_star = implode(',', $all_star);
         if ($list_star) {
             $where .= " AND (tb.rate_review IN ({$list_star}))";
         }
     }
     if (isset($_REQUEST['hotel_rate']) && !empty($_REQUEST['hotel_rate'])) {
         $hotel_rate = STInput::get('hotel_rate', '');
         $where .= " AND (tb.hotel_star IN ({$hotel_rate}))";
     }
     if (isset($_REQUEST['price_range']) && !empty($_REQUEST['price_range'])) {
         $price = STInput::get('price_range', '0;0');
         $priceobj = explode(';', $price);
         // convert to default money
         $priceobj[0] = TravelHelper::convert_money_to_default($priceobj[0]);
         $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
         $where .= " AND (tb.price_avg >= {$priceobj[0]})";
         if (isset($priceobj[1])) {
             $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
             $where .= " AND (tb.price_avg <= {$priceobj[1]})";
         }
     }
     if (isset($_REQUEST['range']) and isset($_REQUEST['location_id'])) {
         $range = STInput::request('range', '5');
         $location_id = STInput::request('location_id');
         $post_type = get_query_var('post_type');
         $map_lat = (double) get_post_meta($location_id, 'map_lat', true);
         $map_lng = (double) get_post_meta($location_id, 'map_lng', true);
         global $wpdb;
         $where .= "\r\n                AND {$wpdb->posts}.ID IN (\r\n                        SELECT ID FROM (\r\n                            SELECT {$wpdb->posts}.*,( 6371 * acos( cos( radians({$map_lat}) ) * cos( radians( mt1.meta_value ) ) *\r\n                                            cos( radians( mt2.meta_value ) - radians({$map_lng}) ) + sin( radians({$map_lat}) ) *\r\n                                            sin( radians( mt1.meta_value ) ) ) ) AS distance\r\n                                                FROM {$wpdb->posts}, {$wpdb->postmeta} as mt1,{$wpdb->postmeta} as mt2\r\n                                                WHERE {$wpdb->posts}.ID = mt1.post_id\r\n                                                and {$wpdb->posts}.ID=mt2.post_id\r\n                                                AND mt1.meta_key = 'map_lat'\r\n                                                and mt2.meta_key = 'map_lng'\r\n                                                AND {$wpdb->posts}.post_status = 'publish'\r\n                                                AND {$wpdb->posts}.post_type = '{$post_type}'\r\n                                                AND {$wpdb->posts}.post_date < NOW()\r\n                                                GROUP BY {$wpdb->posts}.ID HAVING distance<{$range}\r\n                                                ORDER BY distance ASC\r\n                        ) as st_data\r\n\t            )";
     }
     if (!empty($_REQUEST['taxonomy_hotel_room'])) {
         $tax = STInput::request('taxonomy_hotel_room');
         if (!empty($tax) and is_array($tax)) {
             $tax_query = array();
             foreach ($tax as $key => $value) {
                 if ($value) {
                     $ids = "";
                     $ids_tmp = explode(',', $value);
                     if (!empty($ids_tmp)) {
                         foreach ($ids_tmp as $k => $v) {
                             if (!empty($v)) {
                                 $ids[] = $v;
                             }
                         }
                     }
                     if (!empty($ids)) {
                         $tax_query[] = array('taxonomy' => $key, 'terms' => $ids);
                     }
                 }
             }
             $where_room = '';
             if (!empty($tax_query)) {
                 $where_room = ' AND (';
                 foreach ($tax_query as $k => $v) {
                     $ids = implode(',', $v['terms']);
                     if ($k > 0) {
                         $where_room .= " AND ";
                     }
                     $where_room .= "  (\r\n                                                    SELECT COUNT(1)\r\n                                                    FROM wp_term_relationships\r\n                                                    WHERE term_taxonomy_id IN ({$ids})\r\n                                                    AND object_id = wp_posts.ID\r\n                                                  ) = " . count($v['terms']) . "  ";
                 }
                 $where_room .= " ) ";
             }
             $where .= " AND {$wpdb->posts}.ID IN\r\n                        (\r\n                           SELECT ID FROM\r\n                           (\r\n                              SELECT meta1.meta_value as ID\r\n                                    FROM {$wpdb->prefix}posts\r\n\r\n                                    INNER JOIN {$wpdb->prefix}postmeta as meta1 ON wp_posts.ID = meta1.post_id and meta1.meta_key='room_parent'\r\n                                    WHERE 1=1\r\n                                    {$where_room}\r\n                                    AND {$wpdb->prefix}posts.post_type = 'hotel_room'\r\n                                    GROUP BY meta1.meta_value\r\n                           ) as ids\r\n                        ) ";
         }
     }
     if (isset($_REQUEST['item_id']) and !empty($_REQUEST['item_id'])) {
         $item_id = STInput::request('item_id', '');
         $where .= " AND ({$wpdb->prefix}posts.ID = '{$item_id}')";
     }
     return $where;
 }
Пример #6
0
 function st_list_map($attr, $content = false)
 {
     $data = shortcode_atts(array('title' => '', 'type' => 'normal', 'st_list_location' => '', 'st_type' => 'st_hotel', 'zoom' => '13', 'height' => '500', 'number' => '12', 'fit_bounds' => 'no', 'style_map' => 'normal', 'custom_code_style' => '', 'show_search_box' => 'yes', 'show_data_list_map' => 'yes', 'range_km' => 'no', 'max_range_km' => '20', 'range_km_col' => '6'), $attr, 'st_list_map');
     extract($data);
     $data_map = array();
     $html = '';
     //if(!empty( $ids )) {
     $map_lat_center = 0;
     $map_lng_center = 0;
     if ($type == "normal") {
         $ids = $st_list_location;
         if (empty($ids)) {
             return '';
         }
         $_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'));
         $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 . ']';
         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']);
     }
     if ($type == "page_search") {
         $location_center = '[0,0]';
         $address_center = '';
         if (STInput::request('pick-up')) {
             $ids_location = TravelerObject::_get_location_by_name(STInput::get('pick-up'));
             if (!empty($ids_location)) {
                 $_REQUEST['pick-up'] = implode(',', $ids_location);
                 $map_lat_center = get_post_meta($ids_location[0], 'map_lat', true);
                 $map_lng_center = get_post_meta($ids_location[0], 'map_lng', true);
                 $location_center = '[' . $map_lat_center . ',' . $map_lng_center . ']';
                 $address_center = get_the_title($ids_location[0]);
             }
         }
         if (STInput::request('location_id')) {
             $map_lat_center = get_post_meta(STInput::request('location_id'), 'map_lat', true);
             $map_lng_center = get_post_meta(STInput::request('location_id'), 'map_lng', true);
             $location_center = '[' . $map_lat_center . ',' . $map_lng_center . ']';
             $address_center = get_the_title(STInput::request('location_id'));
         }
         if (STInput::request('location_id_pick_up')) {
             $map_lat_center = get_post_meta(STInput::request('location_id_pick_up'), 'map_lat', true);
             $map_lng_center = get_post_meta(STInput::request('location_id_pick_up'), 'map_lng', true);
             $location_center = '[' . $map_lat_center . ',' . $map_lng_center . ']';
             $address_center = get_the_title(STInput::request('location_id_pick_up'));
         }
         global $wp_query, $st_search_query;
         switch ($st_type) {
             case "st_hotel":
                 $hotel = new STHotel();
                 add_action('pre_get_posts', array($hotel, 'change_search_hotel_arg'));
                 break;
             case "st_rental":
                 $rental = new STRental();
                 add_action('pre_get_posts', array($rental, 'change_search_arg'));
                 break;
             case "st_cars":
                 $cars = new STCars();
                 add_action('pre_get_posts', array($cars, 'change_search_cars_arg'));
                 break;
             case "st_tours":
                 $tour = new STTour();
                 //add_action( 'pre_get_posts' , array( $tour , 'change_search_tour_arg' ) );
                 st()->tour->alter_search_query();
                 break;
             case "st_holidays":
                 $holiday = new STHoliday();
                 //add_action( 'pre_get_posts' , array( $holiday , 'change_search_holiday_arg' ) );
                 st()->holiday->alter_search_query();
                 break;
             case "st_activity":
                 $activity = new STActivity();
                 add_action('pre_get_posts', array($activity, 'change_search_activity_arg'));
                 break;
         }
         $query = array('post_type' => $st_type, 'posts_per_page' => $number, 'post_status' => 'publish', 's' => '');
         query_posts($query);
     }
     $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++;
         }
     }
     if ($type == "page_search") {
         $st_search_query = $wp_query;
         switch ($post_type) {
             case "st_hotel":
                 $hotel->remove_alter_search_query();
                 break;
             case "st_rental":
                 $rental->remove_alter_search_query();
                 break;
             case "st_cars":
                 $cars->remove_alter_search_query();
                 break;
             case "st_tours":
                 //remove_action( 'pre_get_posts' , array( $tour , 'change_search_tour_arg' ) );
                 st()->tour->remove_alter_search_query();
                 break;
             case "st_holidays":
                 //remove_action( 'pre_get_posts' , array( $holiday , 'change_search_holiday_arg' ) );
                 st()->holiday->remove_alter_search_query();
                 break;
             case "st_activity":
                 $activity->remove_alter_search_query();
                 break;
         }
     }
     wp_reset_query();
     if (empty($location_center) or $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, 'fit_bounds' => $fit_bounds, 'title' => $title, 'show_search_box' => $show_search_box, 'show_data_list_map' => $show_data_list_map, 'range_km' => $range_km, 'max_range_km' => $max_range_km, 'range_km_col' => $range_km_col);
     $data_tmp['data_tmp'] = $data_tmp;
     $html = st()->load_template('vc-elements/st-list-map/html', '', $data_tmp);
     // }
     return $html;
 }
Пример #7
0
 function st_search_list_half_map($attr, $content = false)
 {
     $post_type = STInput::request('post_type');
     $zoom = STInput::request('zoom');
     $number = STInput::request('number', 8);
     $style_map = STInput::request('style_map');
     $query = array('post_type' => $post_type, 'posts_per_page' => $number, 'post_status' => 'publish', 's' => '');
     $map_lat_center = 0;
     $map_lng_center = 0;
     $location_center = '[0,0]';
     $address_center = '';
     /*if(STInput::request( 'location_name' )) {
           $ids_location = TravelerObject::_get_location_by_name( STInput::get( 'location_name' ) );
           if(!empty( $ids_location )) {
               $_REQUEST['location_name'] = implode(',',$ids_location);
               $map_lat_center  = get_post_meta( $ids_location[ 0 ] , 'map_lat' , true );
               $map_lng_center  = get_post_meta( $ids_location[ 0 ] , 'map_lng' , true );
               $location_center = '[' . $map_lat_center . ',' . $map_lng_center . ']';
               $address_center  = get_the_title( $ids_location[ 0 ] );
           }
       }*/
     if (STInput::request('pick-up')) {
         $ids_location = TravelerObject::_get_location_by_name(STInput::get('pick-up'));
         if (!empty($ids_location)) {
             $_REQUEST['pick-up'] = implode(',', $ids_location);
             $map_lat_center = get_post_meta($ids_location[0], 'map_lat', true);
             $map_lng_center = get_post_meta($ids_location[0], 'map_lng', true);
             $location_center = '[' . $map_lat_center . ',' . $map_lng_center . ']';
             $address_center = get_the_title($ids_location[0]);
         }
     }
     if (STInput::request('location_id')) {
         $map_lat_center = get_post_meta(STInput::request('location_id'), 'map_lat', true);
         $map_lng_center = get_post_meta(STInput::request('location_id'), 'map_lng', true);
         $location_center = '[' . $map_lat_center . ',' . $map_lng_center . ']';
         $address_center = get_the_title(STInput::request('location_id'));
     }
     if (STInput::request('location_id_pick_up')) {
         $map_lat_center = get_post_meta(STInput::request('location_id_pick_up'), 'map_lat', true);
         $map_lng_center = get_post_meta(STInput::request('location_id_pick_up'), 'map_lng', true);
         $location_center = '[' . $map_lat_center . ',' . $map_lng_center . ']';
         $address_center = get_the_title(STInput::request('location_id_pick_up'));
     }
     $data_map = array();
     global $wp_query, $st_search_query;
     switch ($post_type) {
         case "st_hotel":
             $hotel = new STHotel();
             add_action('pre_get_posts', array($hotel, 'change_search_hotel_arg'));
             break;
         case "st_rental":
             $rental = new STRental();
             add_action('pre_get_posts', array($rental, 'change_search_arg'));
             break;
         case "st_cars":
             $cars = new STCars();
             add_action('pre_get_posts', array($cars, 'change_search_cars_arg'));
             break;
         case "st_tours":
             $tour = new STTour();
             //add_action( 'pre_get_posts' , array( $tour , 'change_search_tour_arg' ) );
             st()->tour->alter_search_query();
             break;
         case "st_holidays":
             $holiday = new STHoliday();
             //add_action( 'pre_get_posts' , array( $holiday , 'change_search_holiday_arg' ) );
             st()->holiday->alter_search_query();
             break;
         case "st_activity":
             $activity = new STActivity();
             add_action('pre_get_posts', array($activity, 'change_search_activity_arg'));
             break;
     }
     query_posts($query);
     $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)) {
             $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++;
         }
     }
     $st_search_query = $wp_query;
     switch ($post_type) {
         case "st_hotel":
             $hotel->remove_alter_search_query();
             break;
         case "st_rental":
             $rental->remove_alter_search_query();
             break;
         case "st_cars":
             $cars->remove_alter_search_query();
             break;
         case "st_tours":
             //remove_action( 'pre_get_posts' , array( $tour , 'change_search_tour_arg' ) );
             st()->tour->remove_alter_search_query();
             break;
         case "st_holidays":
             //remove_action( 'pre_get_posts' , array( $holiday , 'change_search_holiday_arg' ) );
             st()->holiday->remove_alter_search_query();
             break;
         case "st_activity":
             $activity->remove_alter_search_query();
             break;
     }
     if (!empty($_REQUEST['st_test'])) {
     }
     wp_reset_query();
     if ($location_center == '[,]' or $location_center == '[0,0]') {
         $location_center = '[21.289374,15.644531]';
         $data_map = "";
         $zoom = "3";
     }
     $data_tmp = array('location_center' => $location_center, 'zoom' => $zoom, 'data_map' => $data_map, 'style_map' => $style_map, 'number' => $number, 'address_center' => $address_center, 'map_lat_center' => $map_lat_center, 'map_lng_center' => $map_lng_center);
     echo json_encode($data_tmp);
     die;
 }
Пример #8
0
 function _get_where_query($where)
 {
     if (!TravelHelper::checkTableDuplicate('st_cars')) {
         return $where;
     }
     global $wpdb;
     if (!empty($_REQUEST['location_id_pick_up']) or !empty($_REQUEST['location_id'])) {
         $location_id = intval(STInput::get('location_id_pick_up', ''));
         if (empty($location_id)) {
             $location_id = STInput::request('location_id');
         }
         $list = TravelHelper::getLocationByParent($location_id);
         if (is_array($list) && count($list)) {
             $where .= " AND (";
             $where_tmp = "";
             foreach ($list as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $list = implode(',', $list);
             $where_tmp .= " OR tb.id_location IN ({$list})";
             $where .= $where_tmp . ")";
         } else {
             $where .= " AND (tb.multi_location LIKE '%_{$location_id}_%' OR tb.id_location IN ('{$location_id}')) ";
         }
     } elseif (!empty($_REQUEST['pick-up']) or !empty($_REQUEST['location_name'])) {
         $location_name = STInput::request('pick-up', '');
         if (empty($location_name)) {
             $location_name = STInput::request('location_name');
         }
         $ids_location = TravelerObject::_get_location_by_name($location_name);
         if (is_array($ids_location) && count($ids_location)) {
             $ids_location_tmp = array();
             foreach ($ids_location as $item) {
                 $list = TravelHelper::getLocationByParent($item);
                 if (is_array($list) && count($list)) {
                     foreach ($list as $item) {
                         $ids_location_tmp[] = $item;
                     }
                 }
             }
             if (count($ids_location_tmp)) {
                 $ids_location = $ids_location_tmp;
             }
         }
         if (!empty($ids_location)) {
             $where .= " AND ((";
             $where_tmp = "";
             foreach ($ids_location as $item) {
                 if (empty($where_tmp)) {
                     $where_tmp .= "tb.multi_location LIKE '%_{$item}_%'";
                 } else {
                     $where_tmp .= " OR tb.multi_location LIKE '%_{$item}_%'";
                 }
             }
             $ids_location = implode(',', $ids_location);
             $where_tmp .= " OR tb.id_location IN ({$ids_location})";
             $where .= $where_tmp . ")";
             $where .= " OR (tb.cars_address LIKE '%{$location_name}%'";
             $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%'))";
         } else {
             if (!empty($_REQUEST['search_all'])) {
                 $where .= " AND (tb.cars_address LIKE '%{$location_name}%'";
                 $where .= " OR {$wpdb->prefix}posts.post_title LIKE '%{$location_name}%')";
             }
         }
     }
     if (isset($_REQUEST['price_range'])) {
         $price = STInput::get('price_range', '0;0');
         $priceobj = explode(';', $price);
         $priceobj[0] = TravelHelper::convert_money_to_default($priceobj[0]);
         $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
         $where .= " AND (tb.sale_price >= {$priceobj[0]})";
         if (isset($priceobj[1])) {
             $priceobj[1] = TravelHelper::convert_money_to_default($priceobj[1]);
             $where .= " AND (tb.sale_price <= {$priceobj[1]})";
         }
     }
     if (isset($_REQUEST['pick-up-date']) && isset($_REQUEST['drop-off-date']) && !empty($_REQUEST['pick-up-date']) && !empty($_REQUEST['drop-off-date'])) {
         $pick_up_date = TravelHelper::convertDateFormat(STInput::request('pick-up-date'));
         $drop_off_date = TravelHelper::convertDateFormat(STInput::request('drop-off-date'));
         $pick_up_time = "";
         $drop_off_time = "";
         if (isset($_REQUEST['pick-up-time']) && !empty($_REQUEST['pick-up-time'])) {
             $pick_up_time = STInput::request('pick-up-time', '12:00 PM');
         }
         if (isset($_REQUEST['drop-off-time']) && !empty($_REQUEST['drop-off-time'])) {
             $drop_off_time = STInput::request('drop-off-time', '12:00 PM');
         }
         $check_in = $pick_up_date . ' ' . $pick_up_time;
         $check_in = strtotime($check_in);
         $check_out = $drop_off_date . ' ' . $drop_off_time;
         $check_out = strtotime($check_out);
         $list_date = CarHelper::_get_car_cant_order($check_in, $check_out);
         $where .= " AND ({$wpdb->posts}.ID NOT IN ({$list_date}))";
         $today = date('Y-m-d');
         $check_in = date('Y-m-d', $check_in);
         $period = TravelHelper::dateDiff($today, $check_in);
         $where .= " AND (CAST(tb.cars_booking_period AS UNSIGNED) <= {$period})";
     }
     if (isset($_REQUEST['item_id']) and !empty($_REQUEST['item_id'])) {
         $item_id = STInput::request('item_id', '');
         $where .= " AND ({$wpdb->prefix}posts.ID = '{$item_id}')";
     }
     if (isset($_REQUEST['location_id'])) {
         $table = $wpdb->prefix . 'st_cars';
         $id = STInput::request('location_id', '');
         $where .= " AND (\r\n                    tb.multi_location LIKE '%_{$id}_%'\r\n                    or tb.id_location = '{$id}'\r\n                    )";
     }
     if (isset($_REQUEST['range']) and isset($_REQUEST['location_id_pick_up'])) {
         $range = STInput::request('range', '5');
         $location_id = STInput::request('location_id_pick_up');
         $post_type = get_query_var('post_type');
         $map_lat = (double) get_post_meta($location_id, 'map_lat', true);
         $map_lng = (double) get_post_meta($location_id, 'map_lng', true);
         global $wpdb;
         $where .= "\r\n                AND {$wpdb->posts}.ID IN (\r\n                        SELECT ID FROM (\r\n                            SELECT {$wpdb->posts}.*,( 6371 * acos( cos( radians({$map_lat}) ) * cos( radians( mt1.meta_value ) ) *\r\n                                            cos( radians( mt2.meta_value ) - radians({$map_lng}) ) + sin( radians({$map_lat}) ) *\r\n                                            sin( radians( mt1.meta_value ) ) ) ) AS distance\r\n                                                FROM {$wpdb->posts}, {$wpdb->postmeta} as mt1,{$wpdb->postmeta} as mt2\r\n                                                WHERE {$wpdb->posts}.ID = mt1.post_id\r\n                                                and {$wpdb->posts}.ID=mt2.post_id\r\n                                                AND mt1.meta_key = 'map_lat'\r\n                                                and mt2.meta_key = 'map_lng'\r\n                                                AND {$wpdb->posts}.post_status = 'publish'\r\n                                                AND {$wpdb->posts}.post_type = '{$post_type}'\r\n                                                AND {$wpdb->posts}.post_date < NOW()\r\n                                                GROUP BY {$wpdb->posts}.ID HAVING distance<{$range}\r\n                                                ORDER BY distance ASC\r\n                        ) as st_data\r\n\t            )";
     }
     return $where;
 }
Пример #9
0
 function change_search_hotel_arg($query)
 {
     if (is_admin()) {
         return FALSE;
     }
     $post_type = get_query_var('post_type');
     $posts_per_page = st()->get_option('hotel_posts_per_page', 12);
     $meta_query = array();
     if ($query->is_search && $post_type == 'st_hotel') {
         add_filter('posts_where', array($this, '_alter_search_query'));
         $query->set('posts_per_page', $posts_per_page);
         $tax = STInput::get('taxonomy');
         if (!empty($tax) and is_array($tax)) {
             $tax_query = array();
             foreach ($tax as $key => $value) {
                 if ($value) {
                     $tax_query[] = array('taxonomy' => $key, 'terms' => explode(',', $value), 'COMPARE' => "IN");
                 }
             }
             $query->set('tax_query', $tax_query);
         }
         if ($location_id = STInput::get('location_id')) {
             $ids_in = array();
             $parents = get_posts(array('numberposts' => -1, 'post_status' => 'publish', 'post_type' => 'location', 'post_parent' => $location_id));
             $ids_in[] = $location_id;
             foreach ($parents as $child) {
                 $ids_in[] = $child->ID;
             }
             $meta_query[] = array('key' => 'id_location', 'value' => $ids_in, 'compare' => 'IN');
             //                    $query->set('s','');
         } else {
             if (STInput::request('location_name')) {
                 $ids_location = TravelerObject::_get_location_by_name(STInput::get('location_name'));
                 if (!empty($ids_location)) {
                     $meta_query[] = array('key' => 'id_location', 'value' => $ids_location, 'compare' => "IN");
                 } else {
                     $meta_query[] = array('key' => 'address', 'value' => STInput::get('location_name'), 'compare' => "like");
                 }
             } elseif (STInput::request('address')) {
                 $value = STInput::request('address');
                 $value = explode(",", $value);
                 if (!empty($value[0]) and !empty($value[2])) {
                     $meta_query[] = array(array('key' => 'address', 'value' => $value[0], 'compare' => 'like'), array('key' => 'address', 'value' => $value[2], 'compare' => 'like'), "relation" => 'OR');
                 } else {
                     $meta_query[] = array('key' => 'address', 'value' => STInput::request('address'), 'compare' => "like");
                 }
             }
         }
         $is_featured = st()->get_option('is_featured_search_hotel', 'off');
         if (!empty($is_featured) and $is_featured == 'on') {
             $query->set('meta_key', 'is_featured');
             $query->set('orderby', 'meta_value');
             $query->set('order', 'DESC');
         }
         if ($orderby = STInput::get('orderby')) {
             switch ($orderby) {
                 case "price_asc":
                     $query->set('meta_key', 'price_avg');
                     $query->set('orderby', 'meta_value_num');
                     $query->set('order', 'asc');
                     break;
                 case "price_desc":
                     $query->set('meta_key', 'price_avg');
                     $query->set('orderby', 'meta_value_num');
                     $query->set('order', 'desc');
                     break;
                 case "avg_rate":
                     $query->set('meta_key', 'rate_review');
                     $query->set('orderby', 'meta_value_num');
                     $query->set('order', 'desc');
                     break;
                 case "name_asc":
                     $query->set('orderby', 'title');
                     $query->set('order', 'asc');
                     break;
                 case "name_desc":
                     $query->set('orderby', 'title');
                     $query->set('order', 'desc');
                     break;
             }
         } else {
             //Default Sorting
             $query->set('orderby', 'modified');
             $query->set('order', 'desc');
         }
         if ($star = STInput::get('star_rate')) {
             $stars = explode(',', $star);
             $min_star = 0;
             if (!empty($stars)) {
                 foreach ($stars as $key => $val) {
                     if ($key == 0) {
                         $min_star = $val;
                     } else {
                         if ($val < $min_star) {
                             $min_star = $val;
                         }
                     }
                 }
             }
             if ($min_star) {
                 $meta_query[] = array('key' => 'rate_review', 'value' => $min_star, 'compare' => ">=", 'type' => 'DECIMAL');
             }
         }
         if ($hotel_rate = STInput::get('hotel_rate')) {
             $meta_query[] = array('key' => 'hotel_star', 'value' => explode(',', $hotel_rate), 'compare' => "IN");
         }
         if ($price = STInput::get('price_range')) {
             $priceobj = explode(';', $price);
             $meta_query[] = array('key' => 'price_avg', 'value' => $priceobj[0], 'compare' => '>=', 'type' => "NUMERIC");
             if (isset($priceobj[1])) {
                 $meta_query[] = array('key' => 'price_avg', 'value' => $priceobj[1], 'compare' => '<=', 'type' => "NUMERIC");
             }
             $meta_query['relation'] = 'and';
         }
         if (!empty($meta_query)) {
             $query->set('meta_query', $meta_query);
         }
     } else {
         remove_filter('posts_where', array($this, '_alter_search_query'));
     }
     return $query;
 }