PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
downtown-rest-api
/
classes
<?php add_action( 'rest_api_init', 'dwt_listing_search_ser', 0 ); function dwt_listing_search_ser() { register_rest_route( 'downtown/app', '/listing-search/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_get_search', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } // Listing Detial Service if (!function_exists('dwt_listing_get_search')) { function dwt_listing_get_search($request) { global $dwt_listing_api; //listings $params = array(); $lat_lng_meta_query = array(); $params = $request->get_json_params(); $latitude = ''; $longitude = ''; $limit = 15; if(isset( $dwt_listing_api['app_listing_search_page'] ) && $dwt_listing_api['app_listing_search_page'] !="") { $limit = $dwt_listing_api['app_listing_search_page']; } if(!empty($params['e_lat']) && !empty($params['e_long'])) { $latitude = $params['e_lat']; $longitude = $params['e_long']; } else if( isset( $params['r_map_lat'] ) && $params['r_map_long'] != "" ) { $latitude = $params['r_map_lat']; $longitude = $params['r_map_long']; } if(!empty($latitude) && !empty($longitude)) { $distance = '30'; if(!empty($params['e_distance']) && !empty($params['e_distance'])) { $distance = $params['e_distance']; } $data_array = array("latitude" => $latitude, "longitude" => $longitude, "distance" => $distance ); $type_lat = "'DECIMAL'"; $type_lon = "'DECIMAL'"; $lats_longs = dwt_listing_radius_search($data_array, false); if(!empty($lats_longs) && count((array)$lats_longs) > 0 ) { if( $latitude > 0 ) { $lat_lng_meta_query[] = array( 'key' => 'dwt_listing_listing_lat', 'value' => array($lats_longs['lat']['min'], $lats_longs['lat']['max']), 'compare' => 'BETWEEN', ); } else { $lat_lng_meta_query[] = array( 'key' => 'dwt_listing_listing_lat', 'value' => array($lats_longs['lat']['max'], $lats_longs['lat']['min']), 'compare' => 'BETWEEN', ); } if( $longitude > 0 ) { $lat_lng_meta_query[] = array( 'key' => 'dwt_listing_listing_long', 'value' => array($lats_longs['long']['min'], $lats_longs['long']['max']), 'compare' => 'BETWEEN', ); } else { $lat_lng_meta_query[] = array( 'key' => 'dwt_listing_listing_long', 'value' => array($lats_longs['long']['max'], $lats_longs['long']['min']), 'compare' => 'BETWEEN', ); } } } //Listing Title $listing_title = ''; if( isset( $params['by_title'] ) && $params['by_title'] != "" ) { $listing_title = $params['by_title']; } //Categories $category = ''; if( isset( $params['l_category'] ) && $params['l_category'] != "") { $category = array( array( 'taxonomy' => 'l_category', 'field' => 'term_id', 'terms' => $params['l_category'], ), ); } //Listing Street Address $street_address = ''; if( isset( $params['street_address'] ) && $params['street_address'] != "" ) { $street_address = array( 'key' => 'dwt_listing_listing_street', 'value' => trim( $params['street_address'] ), 'compare' => 'LIKE', ); } //Price Type $price_type = ''; if( isset( $params['l_price_type'] ) && $params['l_price_type'] != "") { $price_type = array( array( 'taxonomy' => 'l_price_type', 'field' => 'term_id', 'terms' => $params['l_price_type'], ), ); } //Listing Status $listing_id = array(); if( isset( $params['l_listing_status'] ) && $params['l_listing_status'] != "") { if($params['l_listing_status'] == 'all') { $listing_id = array(); } else { $listing_id = dwt_listing_search_listing_status(); if( count((array) $listing_id) == 0 ){$listing_id =array(0);} } } //Rated As //Listing By Rated $order = 'DESC'; $order_by = 'date'; $key = ''; if( isset( $params['l_rating'] ) && $params['l_rating'] != "" ) { $order = 'DESC'; if($params['l_rating'] == 'low_rated') { $order = 'ASC'; } $key = 'listing_total_average'; $order_by = 'meta_value_num'; } //Tags $tags = ''; if( isset( $params['l_tag'] ) && $params['l_tag'] != "") { $tags = array( array( 'taxonomy' => 'l_tags', 'field' => 'term_id', 'terms' => $params['l_tag'], ), ); } //Amenties $amenties = ''; if( isset( $params['amenties'] ) && is_array( $params['amenties']) && $params['amenties'] != "") { $amenties = array( 'taxonomy' => 'l_category', 'field' => 'term_id', 'terms' => $params['amenties'], ); } //Custom Location $custom_location = ''; if( isset( $params['l_location'] ) && $params['l_location'] != "" ) { $location_array = array(); if( isset( $params['l_location'] ) && $params['l_location'] != "" ) $location_array[] = $params['l_location']; $custom_location = array( array( 'taxonomy' => 'l_location', 'field' => 'term_id', 'terms' => $location_array, ), ); } //post status active only $active_listings = array( 'key' => 'dwt_listing_listing_status', 'value' => '1', 'compare' => '=' ); $featured_or_simple = ''; //condition based featured ads if(dwt_listing_text('feature_or_simple') == 0) { $featured_or_simple = array( 'key' => 'dwt_listing_is_feature', 'value' => '0', 'compare' => '=' ); } if( isset( $params['sort_by'] ) && $params['sort_by'] != "" ) { $orde_arr = explode('-', $params['sort_by']); $order = isset($orde_arr[1]) ? $orde_arr[1] : 'DESC'; $order_by = isset($orde_arr[0]) ? $orde_arr[0] : 'ID'; } $page = 1; if(!empty($params['next_page'])) { $page = $params['next_page']; } else { $page = 1; } //query $args = array ( 's' => $listing_title, 'post_type' => 'listing', 'post_status' => 'publish', 'posts_per_page' => $limit, 'post__in' => $listing_id , 'tax_query' => array( $category, $price_type, $amenties, $tags, $custom_location, ), 'meta_query' => array( $active_listings, $street_address, $featured_or_simple, $lat_lng_meta_query, ), 'meta_key' => $key, 'order'=> $order, 'orderby' => $order_by, 'paged' => $page, ); $results = new WP_Query( $args ); if ( $results->have_posts() ) { $posted_on = __("Posted on ", "dwt-listing-api"); $views = __("Views ", "dwt-listing-api"); $listingz = $data = array(); $toal_results = ''; $toal_results = esc_attr($results->found_posts); $data['total_listings'] = $toal_results . esc_html__(" Results found ", "dwt-listing-api"); $data['no_more'] = esc_html__('No more listings','downtown'); $lists = array(); $color_code = $pieces = $category_name = $categor_id = $listing_cats = $total_views = $status_type = $b_status = $is_featured = ''; while ($results->have_posts() ) { $results->the_post(); $listing_id = get_the_ID(); $media = dwt_listing_fetch_listing_gallery($listing_id); $is_featured = dwt_listing_is_listing_featured_app($listing_id); $get_percentage = dwt_listing_fetch_reviews_average($listing_id); if(isset($get_percentage) && count((array)$get_percentage['ratings']) > 0 && count((array)$get_percentage['rated_no_of_times']) > 0) { $rating_stars = $get_percentage['rated_no_of_times']; $average = $get_percentage['average']; } if(dwt_listing_business_hours_status($listing_id) !="") { $status_type = dwt_listing_business_hours_status($listing_id); if($status_type == 0) { $b_status = esc_html__('Closed','downtown'); $color_code = '#c00'; } else if($status_type == 2) { $b_status = esc_html__('Always Open','downtown'); $color_code = '#fc0'; } else { $b_status = esc_html__('Open Now','downtown'); $color_code = '#25a25a'; } } $listing_cats = dwt_listing_listing_assigned_cats_app($listing_id); if(count((array) $listing_cats) > 0 && !empty($listing_cats)) { $pieces = explode(',', $listing_cats); $categor_id = $pieces[0]; $category_name = $pieces[1]; } $rated = get_comment_meta($listing_id, 'review_stars', true); if( function_exists('pvc_get_post_views') ) $total_views = pvc_get_post_views( $listing_id); $listingz[] = array( "listing_id" => $listing_id, "category_id" => $categor_id, "category_name" => dwt_listing_convert_uniText($category_name), "listing_title" => dwt_listing_convert_uniText(get_the_title($listing_id)), "image" => dwt_listing_return_listing_idz($media,'dwt_listing_list-view1'), "is_featured" => $is_featured, "business_hours_status" => $b_status, "color_code" => $color_code, "rating_stars" => $rating_stars, "rating_avg" => $average, "total_views" => $total_views, "posted_date" => get_the_date(get_option('date_format'),$listing_id), ); } wp_reset_postdata(); $data['listings'] = $listingz; //pagination $next = $page + 1; $lastpage = ceil($results->found_posts/$limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $data['pagination'] = array("total_listings" => $results->found_posts, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); return $response = array( 'success' => true, 'data' => $data, 'message' =>'' ); } else { $msg = esc_html__("No result found.", "dwt-listing-api"); return $response = array( 'success' => false, 'data' => '', 'message' => $msg ); } } } add_action( 'rest_api_init', 'dwt_listing_search_ser_filters', 0 ); function dwt_listing_search_ser_filters() { register_rest_route( 'downtown/app', '/listing-filters/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_get_search_filters', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } // Listing Detial Service if (!function_exists('dwt_listing_get_search_filters')) { function dwt_listing_get_search_filters($request) { global $dwt_listing_api; //listings $price_type = $listing_cats = ''; $sort_types = $get_types = $l_cats = $search_filters = array(); $params = $request->get_json_params(); //Get cats $listing_cats = dwt_listing_categories_fetch('l_category' , 0 ); if(!empty($listing_cats) && count((array) $listing_cats ) > 0 ) { $l_cats[] = array("key" => "", "value" => __("Select an option", "dwt-listing-api")); foreach( $listing_cats as $cats ) { $l_cats[] = array("key" => esc_attr( $cats->term_id ), "value" => esc_html( $cats->name )); } } // Price Type $price_type = dwt_listing_categories_fetch('l_price_type' , 0 ); if(!empty($price_type) && count((array) $price_type ) > 0) { $get_types[] = array("key" => "", "value" => __("Select an option", "dwt-listing-api")); foreach( $price_type as $type ) { $get_types[] = array("key" => esc_attr( $type->term_id ), "value" => esc_html($type->name)); } } //sort options $sort_types[] = array("key" => "id-desc", "value" => __("Newest To Oldest", "dwt-listing-api")); $sort_types[] = array("key" => "id-asc", "value" => __("Oldest To New", "dwt-listing-api")); $sort_types[] = array("key" => "title-asc", "value" => __("Alphabetically [a-z]", "dwt-listing-api")); $sort_types[] = array("key" => "title-desc", "value" => __("Alphabetically [z-a]", "dwt-listing-api")); $rated_type[] = array("key" => 'high_rated', "value" => esc_html__('High to Low','dwt-listing-api')); $rated_type[] = array("key" => 'low_rated', "value" => esc_html__('Low to High','dwt-listing-api')); //common filters $search_filters[] = dwt_listing_get_fields(esc_html__("Search (e.g Pizza or Burger)", "dwt-listing-api"), esc_html__("What Are You Looking For?", "dwt-listing-api"), 'input', 'by_title', '', ''); $search_filters[] = dwt_listing_get_fields('',esc_html__("Select Category", "dwt-listing-api"), 'dropdown', 'l_category', '', $l_cats); $search_filters[] = dwt_listing_get_fields('',esc_html__("Select Price Type", "dwt-listing-api"), 'dropdown', 'l_price_type', '', $get_types); $search_filters[] = dwt_listing_get_fields(esc_html__("Location", "dwt-listing-api"),esc_html__("Address or city", "dwt-listing-api"), 'input', 'street_address', '', ''); $data['all_filters'] = $search_filters; $data['status'] = dwt_listing_get_fields(esc_html__("Status", "dwt-listing-api"),esc_html__("Open Now", "dwt-listing-api"), 'button', 'l_listing_status', '', ''); $data['rated'] = dwt_listing_get_fields(esc_html__("Rated As", "dwt-listing-api"),'', 'multi_button', 'l_rating', '', $rated_type); //sort $data['sorting'] = dwt_listing_get_fields(esc_html__("Sort By", "dwt-listing-api"), esc_html__("Select an option", "dwt-listing-api"), 'radio', 'sort_by', '', $sort_types); $data['filter_btn'] = esc_html__('Search','dwt-listing-api'); $data['current_location'] = esc_html__('Current Location','dwt-listing-api'); $data['current_radius'] = esc_html__('Radius in KM','dwt-listing-api'); $data['radius_unit'] = esc_html__('KM','dwt-listing-api'); //screen text $screen_txt['screen_title'] = esc_html__("Search", "dwt-listing-api"); return $response = array( 'success' => true, "screen_text" => $screen_txt, 'data' => $data, 'message' => ''); } }
[+]
..
[-] profile.php
[edit]
[-] listing-search.php
[edit]
[-] register.php
[edit]
[-] blog.php
[edit]
[-] reviews.php
[edit]
[-] login.php
[edit]
[+]
payments
[-] event-detail.php
[edit]
[-] author-listings.php
[edit]
[-] packages.php
[edit]
[-] categories.php
[edit]
[+]
packages
[-] events-search.php
[edit]
[-] fetch_data.php
[edit]
[-] home.php
[edit]
[-] listing-detail.php
[edit]
[+]
submit-listing
[+]
profile
[-] forget.php
[edit]
[-] settings.php
[edit]
[-] events.php
[edit]