validate_request(); try { $url = ''; if(isset($_POST['url'])) { // Not sanitize_text_field(): the agent profile link can contain "%XX" sequences // (e.g. "Alex%20Antigua") which sanitize_text_field() strips out. $url = esc_url_raw(wp_unslash($_POST['url'])); } if(!$url) { $res_array['error'] = 'Please fill required fields!'; echo json_encode($res_array); exit; } $last_char = substr($url, -1); if($last_char == '/'){ $url = substr($url, 0, -1); } update_option('lfzw_fr_listings_url', $url); LFZW_Fr_DB_Persistor::save_profile_data(); $res_array['success'] = true; } catch(Exception $e) { $res_array['error'] = $e->getMessage(); } echo json_encode($res_array); exit; } function save_listings(){ $res_array = array(); $this->validate_request(); try { $all_listings = LFZW_Fr_DB_Persistor::save_listings(); $res_array['all_listings'] = $all_listings; $res_array['total_listings'] = count($all_listings); $res_array['success'] = true; } catch(Exception $e) { $res_array['error'] = $e->getMessage(); } echo json_encode($res_array); exit; } function save_listing_details(){ $res_array = array(); $this->validate_request(); try { $list_id = ''; if(isset($_POST['list_id'])) { $list_id = sanitize_text_field($_POST['list_id']); } if(!$list_id) { $res_array['error'] = 'Listing ID is missing!'; echo json_encode($res_array); exit; } $all_listings = LFZW_Fr_DB_Persistor::save_listing_details($list_id); $res_array['success'] = true; } catch(Exception $e) { $res_array['error'] = $e->getMessage(); } echo json_encode($res_array); exit; } function search_agents() { $res_array = array(); $this->validate_request(); try { $agent_name = ''; if (isset($_POST['agent_name'])) { $agent_name = sanitize_text_field($_POST['agent_name']); } if (!$agent_name) { $res_array['error'] = 'Please fill required fields!'; echo json_encode($res_array); exit; } $agent_search = new LFZW_Fr_Agent_Search(); $agents = $agent_search->search($agent_name); $res_array['agents'] = $agents; $res_array['success'] = true; } catch(Exception $e) { $res_array['error'] = $e->getMessage(); } echo json_encode($res_array); exit; } function select_agent() { $res_array = array(); $this->validate_request(); try { $encoded_zuid = isset($_POST['encoded_zuid']) ? sanitize_text_field($_POST['encoded_zuid']) : ''; if (!$encoded_zuid) { $res_array['error'] = 'Selected agent is missing a Zillow ID!'; echo json_encode($res_array); exit; } $name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : ''; $link = isset($_POST['link']) ? esc_url_raw(wp_unslash($_POST['link'])) : ''; $image_url = isset($_POST['image_url']) ? esc_url_raw(wp_unslash($_POST['image_url'])) : ''; update_option('lfzw_encoded_zuid', $encoded_zuid); if ($link) { $last_char = substr($link, -1); if ($last_char == '/') { $link = substr($link, 0, -1); } update_option('lfzw_fr_listings_url', $link); } update_option('lfzw_fr_selected_agent', array( 'name' => $name, 'image_url' => $image_url, )); $res_array['success'] = true; } catch(Exception $e) { $res_array['error'] = $e->getMessage(); } echo json_encode($res_array); exit; } }