Esempio n. 1
0
 static function get_api_params($all = false)
 {
     if (!class_exists('dsSearchAgent_Client')) {
         return false;
     }
     $apiParams = @dsSearchAgent_Client::GetApiParams(stripslashes_deep(@$_GET));
     // dsIDXpress doesn't add a param when showing all listings
     if (isset($_GET['idx-q-DistressTypes'])) {
         $apiParams['query.DistressTypes'] = (int) $_GET['idx-q-DistressTypes'];
     }
     if (isset($_GET['idx-q-PhotoCountMin'])) {
         $apiParams['query.PhotoCountMin'] = (int) $_GET['idx-q-PhotoCountMin'];
     }
     if (isset($_GET['idx-q-ListingStatuses'])) {
         $apiParams['query.ListingStatuses'] = (int) $_GET['idx-q-ListingStatuses'];
     }
     # if($apiParams['query.DistressTypes'] === 'all') {
     # unset($apiParams['query.DistressTypes']);
     # }
     if (empty($apiParams) || !is_array($apiParams)) {
         return false;
     }
     foreach ($apiParams as $key => $value) {
         if (!$all && preg_match('/directive|ResultsPerPage/ism', $key)) {
             continue;
         }
         if (strpos($key, 'Cities') || strpos($key, 'Areas')) {
             $value = ucwords($value);
         }
         $params[str_replace('query.', '', $key)] = $value;
     }
     foreach (self::get_numeric_params() as $key) {
         if (!empty($params) && is_array($params) && array_key_exists($key, $params)) {
             $params[$key] = floatval(str_replace(",", "", $params[$key]));
         }
     }
     if (empty($params) || !is_array($params)) {
         return false;
     }
     foreach ($params as $key => $value) {
         // Process array of results
         if (preg_match('/(.*?)\\[([0-9]+)\\](?:\\.(.+))?/ism', $key, $matches)) {
             if (isset($matches[3])) {
                 $params[$matches[1]][$matches[3]][$matches[2]] = $value;
             } else {
                 $params[$matches[1]][$matches[2]] = $value;
             }
             unset($params[$key]);
         } else {
             $matches = explode('.', $key);
             if (!empty($matches[1])) {
                 $params[$matches[0]][$matches[1]] = $value;
                 unset($params[$key], $params[$matches[1]]);
             }
         }
     }
     ksort($params);
     return $params;
 }
Esempio n. 2
0
 static function EnsureBaseUri()
 {
     $basePath = dsSearchAgent_Client::GetBasePath();
     $queryPosition = strrpos(self::$CanonicalUri, "?");
     if ($queryPosition !== false) {
         $hardPermalink = substr(self::$CanonicalUri, 0, $queryPosition);
     } else {
         $hardPermalink = self::$CanonicalUri;
     }
     $requestedPath = $_SERVER["REQUEST_URI"];
     $queryPosition = strrpos($requestedPath, "?");
     if ($queryPosition !== false) {
         $requestedPath = substr($requestedPath, 0, $queryPosition);
     } else {
         $requestedPath = $requestedPath;
     }
     $expectedPath = $basePath . urldecode($hardPermalink);
     if ($requestedPath != $expectedPath) {
         $redirect = $basePath . self::$CanonicalUri;
         $sortColumnKey = "idx-d-SortOrders<0>-Column";
         $sortDirectionKey = "idx-d-SortOrders<0>-Direction";
         $sortColumn = isset($_GET[$sortColumnKey]) ? $_GET[$sortColumnKey] : null;
         $sortDirection = isset($_GET[$sortDirectionKey]) ? $_GET[$sortDirectionKey] : null;
         if ($sortColumn !== null && $sortDirection !== null) {
             if (substr($redirect, strlen($redirect) - 1, 1) == "/") {
                 $redirect .= "?";
             } else {
                 $redirect .= "&";
             }
             $redirect .= urlencode($sortColumnKey) . "=" . urlencode($sortColumn) . "&" . urlencode($sortDirectionKey) . "=" . urlencode($sortDirection);
         }
         header("Location: {$redirect}", true, 301);
         exit;
     }
 }
Esempio n. 3
0
 public static function DisplayPage($posts)
 {
     global $wp_query;
     if (is_array($wp_query->query) && isset($wp_query->query['ds-idx-listings-page'])) {
         remove_filter("the_posts", array("dsSearchAgent_Client", "Activate"));
         if (!isset($posts[0])) {
             return $posts;
         }
         $pageData = $posts[0];
         $pageContent = trim($pageData->post_content);
         if (!empty($pageContent)) {
             $pageContent = wpautop(wpautop($pageContent)) . '<div class="dsidx-clear;"></div><hr class="dsidx-separator" />';
         }
         $wp_query->query['idx-action'] = 'results';
         $wp_query->is_page = 1;
         $wp_query->is_singular = 1;
         $wp_query->is_single = 0;
         if (!isset($_GET)) {
             $_GET = array();
         }
         $linkUrl = get_post_meta($pageData->ID, 'dsidxpress-assembled-url', true);
         $parts = parse_url($linkUrl);
         $filters = array();
         if (isset($parts['query'])) {
             parse_str($parts['query'], $filters);
         }
         $filters = array_map(array('dsIdxListingsPages', 'CleanIdxPageFilters'), $filters);
         $newPosts = dsSearchAgent_Client::Activate($posts, $filters, $pageData->ID);
         $newPosts[0]->post_content = $pageContent . $newPosts[0]->post_content;
         $newPosts[0]->post_name = $pageData->post_name;
         $newPosts[0]->ID = $pageData->ID;
         $newPosts[0]->post_title = $pageData->post_title;
         $newPosts[0]->post_type = 'ds-idx-listings-page';
         return $newPosts;
     }
     return $posts;
 }
Esempio n. 4
0
 /**
  * Get the MLS number of the current listing, if exists.
  * @global $wp_query
  * @uses dsSearchAgent_Client::GetApiParams()
  * @return mixed MLS number if exists; false if not.
  */
 function get_mls()
 {
     global $wp_query;
     if (!class_exists('dsSearchAgent_Client')) {
         return false;
     }
     if (isset($wp_query->query_vars['idx-q-MlsNumber'])) {
         return $wp_query->query_vars['idx-q-MlsNumber'];
     } else {
         $apiParams = @dsSearchAgent_Client::GetApiParams(stripslashes_deep(@$_GET));
         return isset($apiParams['query.MlsNumber']) ? $apiParams['query.MlsNumber'] : '';
     }
     return false;
 }