static function client_assist($action = '', $args = array(), $request = array()) { self::$enable_filter = false; $_REQUEST['action'] = esc_html($action); $_POST = $args; ob_start(); if (!class_exists('Bon_IDX_ClientAssist')) { include plugin_dir_path(Bon_IDX::$file) . 'client-assist.php'; } else { call_user_func(array('Bon_IDX_ClientAssist', $_REQUEST['action'])); } $return = ob_get_clean(); self::$enable_filter = true; return $return; }
/** * Get Listing and Search Data * * Processes the current page request to get the data about the listing or search result. * Sets a variable in $wp->wp_idx_content with the data. * * @uses htmlqp() * @uses $this->get_mls() * @uses Bon_IDX_DSAPI::get_api_params() */ function process_idx_data() { global $post, $posts, $wp_query, $wp, $wp_rewrite; // This is largely for debugging, but could also be helpful for some reason do_action('bon_idx_modify_post_content'); $idx = $this->get_params(); $params = Bon_IDX_DSAPI::get_api_params(true); if (empty($params) && !is_idx()) { return false; } foreach ((array) $params as $k => $param) { if (preg_match('/directive|ResultsPerPage/ism', $k)) { continue; } $idx[$k] = $param; $param = (array) $param; $idx[strtolower($k)] = implode(', ', $param); } $idx['mls'] = $this->get_mls(); $idx['url'] = $wp->request; $idx['title'] = isset($post->post_title) ? $post->post_title : ''; $idx['original_title'] = $idx['title']; $idx['excerpt'] = isset($post->post_excerpt) ? html_entity_decode($post->post_excerpt) : ''; if (!empty($idx['mls'])) { $idx['type'] = 'listing'; } elseif (!empty($wp_query->query_vars['idx-action'])) { if ($wp_query->query_vars['idx-action'] === 'results') { $idx['type'] = 'listings'; } elseif ($wp_query->query_vars['idx-action'] === 'details') { $idx['type'] = 'listing'; } elseif ($wp_query->query_vars['idx-action'] === 'framed') { $idx['type'] = 'advanced'; } } elseif (!empty($post->post_name) && $post->post_name === 'dsidxpress-data') { if (strpos($post->post_name, 'MLS #')) { $idx['type'] = 'listing'; } else { $idx['type'] = 'listings'; } } else { return false; } // Is this an expired listing? $idx['is_404'] = $this->is_404(); $qp = htmlqp($post->post_content); switch ($idx['type']) { case 'listing': preg_match($this->get_regex('process_listing_title'), $idx['title'], $pieces); $idx['address'] = !empty($pieces[1]) ? apply_filters('bon_idx_title_address', @$pieces[1]) : apply_filters('bon_idx_backup_address', 'MLS #' . $idx['mls'], $pieces); $idx['street'] = $this->helper->get_street_from_address($idx['address']); $idx['unit'] = apply_filters('bon_idx_title_city', @$pieces[2]); $idx['city'] = apply_filters('bon_idx_title_city', $this->helper->trim(@$pieces[3])); $idx['state'] = apply_filters('bon_idx_title_state', @$pieces[4]); $idx['zip'] = apply_filters('bon_idx_title_zip', str_replace('_', '-', @$pieces[5])); $idx['sitename'] = apply_filters('bon_idx_title_sitename', @$pieces[7]); $idx['title'] = $this->get('listing_title_template'); $idx['description'] = $this->get('listing_description_template'); // Primary Data $databox = $qp->find('#dsidx-header'); $idx['daysonmarket'] = $databox->find('th:contains(Days on Market)')->next('td')->text(); $idx['lotsize'] = $databox->find('th:contains(Lot Size)')->next('td')->text(); $idx['lotsizetype'] = $this->helper->trim(preg_replace('/[0-9,\\.]/ism', '', $this->helper->trim($idx['lotsize']))); $idx['lotsizeraw'] = $this->helper->raw_number($idx['lotsize']); $idx['lotsize'] = $this->helper->number_format($idx['lotsizeraw']); $idx['price'] = $databox->find('#dsidx-price td')->text(); $homesize_th = $databox->find('th:contains(Home size),th:contains(Finished sq.ft)'); $homesize_td = $homesize_th->next('td')->text(); $idx['homesize_title'] = $this->helper->trim($homesize_th->text()); $idx['homesize'] = $this->helper->trim($homesize_td); $idx['homesizeraw'] = !empty($homesize_td) ? $this->helper->raw_number($homesize_td) : ''; $idx['homesizesource'] = $this->helper->match($this->get_regex('homesize_source'), $homesize_td, 2); $idx['baths'] = $databox->find('th:contains(Baths)')->next('td')->text(); $idx['baths'] = $this->helper->trim(preg_replace('/baths?/ism', '', $idx['baths'])); $idx['beds'] = $databox->find('th:contains(Beds)')->next('td')->text(); $idx['status'] = $databox->find('#dsidx-status td')->text(); // If there's a message about the listing, set it here. This should be the last because it removes the table $idx['notice'] = ''; if ($qp->find('#dsidx-primary-data')->length) { $idx['notice'] = $qp->find('#dsidx-primary-data')->remove()->top()->find('.shortsale-notice')->parent()->innerHtml(); } $secondary = $qp->top()->find('#dsidx-secondary-data'); $idx['community'] = $secondary->find('th:contains(Community)')->next('td')->text(); $idx['county'] = $secondary->find('th:contains(County)')->next('td')->text(); $idx['garagespaces'] = $secondary->find('th:contains(Garage Spaces)')->next('td')->text(); $idx['lastupdated'] = $secondary->find('th:contains(Last Updated)')->next('td')->text(); $idx['yearbuilt'] = $secondary->find('th:contains(Year Built)')->next('td')->text(); $idx['totalparking'] = $secondary->find('th:contains(Total Parking)')->next('td')->text(); $idx['tract'] = $secondary->find('th:contains(Tract)')->next('td')->text(); $idx['propertytypes'] = preg_replace('/(?:.*?:)(.+)/ism', '$1', $qp->find('#dsidx-property-types')->text()); $idx['status'] = empty($idx['status']) ? $secondary->find('th:contains(Status)')->next('td')->text() : $idx['status']; $idx['daysonmarket'] = empty($idx['daysonmarket']) ? $secondary->find('th:contains(Days on Market)')->next('td')->text() : $idx['daysonmarket']; $idx['walkscoredata'] = array('th' => $secondary->find('th:contains(Walk Score)')->innerHtml(), 'td' => $secondary->find('th:contains(Walk Score)')->next('td')->innerHtml()); $idx['walkscore'] = $idx['walkscoredata']['score'] = $this->helper->raw_number($idx['walkscoredata']['td']); $idx['virtualtour'] = $qp->find('#dsidx-virtual-tour-container')->innerHtml(); // Set other data using regex $idx['PropertyID'] = $this->helper->raw_number($this->helper->match($this->get_regex('propertyid'), $post->post_content, 1, $idx['mls'])); $idx['latitude'] = $this->helper->match($this->get_regex('latitude'), $post->post_content); $idx['longitude'] = $this->helper->match($this->get_regex('longitude'), $post->post_content); $idx['photocount'] = $this->helper->raw_number($this->helper->match($this->get_regex('photocount'), $post->post_content)); $idx['photouribase'] = $this->helper->match($this->get_regex('photouribase'), $post->post_content); $idx['photocaption'] = $this->helper->match($this->get_regex('photocaption'), $post->post_content); $idx['contentdomid'] = $this->helper->match($this->get_regex('contentdomid'), $post->post_content); // No photos. if (empty($idx['photocount'])) { $idx['photolink'] = get_template_directory_uri() . '/assets/images/nophoto.png'; $idx['photo'] = $this->get_unavailable_photo(); } else { $idx['photolink'] = $idx['photouribase'] . '0-full.jpg'; $idx['photo'] = $this->process_photo('<img src="' . $idx['photouribase'] . '0-medium.jpg" alt="' . $idx['title'] . '" />', $idx); } foreach ($this->get_params('searchonly') as $key => $val) { unset($idx[$key]); } break; case 'listings': default: $idx['sqfeetmin'] = isset($idx['ImprovedSqFtMin']) ? $idx['ImprovedSqFtMin'] : ''; $idx['page'] = isset($params['directive']['ResultPage']) ? $params['directive']['ResultPage'] : 1; $idx['zip'] = isset($idx['ZipCodes']) ? implode(', ', (array) $idx['ZipCodes']) : ''; $idx['zip'] = str_replace('_', '-', $idx['zip']); $idx['Communities'] = $idx['community'] = isset($idx['Communities']) ? ucwords(implode(', ', (array) $idx['Communities'])) : ''; $idx['city'] = isset($idx['Cities']) ? implode(', ', (array) $idx['Cities']) : ''; $idx['area'] = isset($idx['Areas']) ? implode(', ', (array) $idx['Areas']) : ''; $idx['tract'] = isset($idx['TractIdentifiers']) ? ucwords(implode(', ', (array) $idx['TractIdentifiers'])) : ''; list($idx['SortOrders<0>-Direction'], $idx['SortOrders<0>-Column'], $notdefault) = $this->get_sort(); $idx['pricemax'] = isset($params['query.PriceMax']) ? $params['query.PriceMax'] : ''; $idx['pricemin'] = isset($params['query.PriceMin']) ? $params['query.PriceMin'] : ''; $idx['bedsmin'] = isset($params['query.BedsMin']) ? $params['query.BedsMin'] : ''; $idx['sqfeetmin'] = isset($params['query.ImprovedSqFtMin']) ? $params['query.ImprovedSqFtMin'] : ''; $idx['bathsmin'] = isset($params['query.BathsMin']) ? $params['query.BathsMin'] : ''; $idx['propertytypes'] = isset($params['query.PropertyTypes']) ? $params['query.PropertyTypes'] : ''; preg_match('/\\/?idx\\/(.+?)\\//ism', $wp->request, $matches); $idx['results-type'] = isset($matches[1]) ? $matches[1] : ''; $sitename = ''; $titletag = isset($post->post_title) ? $post->post_title : ''; if (sizeof($params) === 1) { if (!empty($idx['city'])) { $idx['title'] = $this->get('city_title_template'); $idx['description'] = $this->get('city_description_template'); $idx['results-type'] = 'city'; } else { if (!empty($idx['area'])) { $idx['title'] = $this->get('area_title_template'); $idx['description'] = $this->get('area_description_template'); $idx['results-type'] = 'area'; } else { if (!empty($idx['community'])) { $idx['title'] = $this->get('community_title_template'); $idx['description'] = $this->get('community_description_template'); $idx['results-type'] = 'community'; } else { if (!empty($idx['zip'])) { $idx['title'] = $this->get('zip_title_template'); $idx['description'] = $this->get('zip_description_template'); $idx['results-type'] = 'zip'; } else { if (!empty($idx['tract'])) { $idx['title'] = $this->get('tract_title_template'); $idx['description'] = $this->get('tract_description_template'); $idx['results-type'] = 'tract'; } else { if (preg_match('/\\/?idx\\/[0-9]{4-9}-(.+)/ism', $wp->request)) { // This is a link $idx['title'] = apply_filters('bon_idx_link_title_template', $idx['original_title']); $idx['description'] = $idx['excerpt']; } else { $idx['title'] = $this->get('search_title_template'); $idx['description'] = $this->get('search_description_template'); } } } } } } } else { $idx['title'] = $this->get('search_title_template'); $idx['description'] = $this->get('search_description_template'); } // Map JS has lots of good data. preg_match($this->get_regex('listingsdata'), $post->post_content, $matches); $idx['listingsdata'] = isset($matches[1]) ? json_decode('[' . $matches[1] . ']') : ''; $multiples = array(); foreach ((array) $params as $key => $value) { if (preg_match('/query\\.(.*?)\\[([0-9])\\]/ism', $key, $matches)) { $multiples[$matches[1]][$matches[2]] = $value; } } foreach ($multiples as $key => $value) { $idx[$key] = $value; } preg_match($this->get_regex('dsidx-paging-control', 'pro_paging-control'), $post->post_content, $matches); if (isset($matches[3])) { $idx['original_pagination'] = $this->helper->trim($matches[0]) . '</div>'; $idx['pagination_text'] = $this->helper->trim(strip_tags($matches[0])); $idx['start'] = $matches[1]; $idx['end'] = $this->is_pro() ? '' : $matches[2]; $idx['total'] = $this->is_pro() ? $matches[2] : $matches[3]; } break; } // If the title's blank, use the default from dsIDXpress $idx['title'] = $this->helper->trim($idx['title']); if (empty($idx['title'])) { $idx['title'] = $idx['original_title']; } // If the description is blank, use the default from dsIDXpress $idx['description'] = $this->helper->trim($idx['description']); if (empty($idx['description'])) { $idx['description'] = $idx['excerpt']; } // This will only over-write non-existing fields. // That shouldn't happen unless we're dealing with forced reg, a 404, or a blow-up. $idx = $this->process_data_from_url($idx); $idx['title'] = apply_filters('bon_idx_title_template', $idx['title'], $wp); $idx['transient'] = $this->get_transient_key($idx); ksort($idx); $idx = $this->helper->trim($idx); $wp->wp_idx_content = apply_filters('bon_idx_process_idx_data_filter', $idx); }