public static function LoadScripts()
 {
     dsidxpress_autocomplete::AddScripts(true);
 }
Beispiel #2
0
 static function ApiAction($action, $get, $idx_page_id = null)
 {
     global $wp_query;
     $options = get_option(DSIDXPRESS_OPTION_NAME);
     $post_id = !$idx_page_id ? time() : $idx_page_id;
     wp_enqueue_script("jquery-ui-dialog", false, array(), false, true);
     add_action("wp_head", array("dsSearchAgent_Client", "Header"));
     // allow wordpress to consume the page template option the user choose in the dsIDXpress settings
     if ($action == "results" && !empty($options["ResultsTemplate"])) {
         wp_cache_set($post_id, array("_wp_page_template" => array($options["ResultsTemplate"])), "post_meta");
     } else {
         if ($action == "details" && !empty($options["DetailsTemplate"])) {
             wp_cache_set($post_id, array("_wp_page_template" => array($options["DetailsTemplate"])), "post_meta");
         }
     }
     $apiParams = self::GetApiParams($get);
     // pull account options
     $apiHttpResponse = dsSearchAgent_ApiRequest::FetchData("AccountOptions");
     if (!empty($apiHttpResponse["errors"]) || $apiHttpResponse["response"]["code"] != "200") {
         switch ($apiHttpResponse["response"]["code"]) {
             case 403:
                 wp_die("We're sorry, but there’s nothing to display here; MLS data service is not activated for this account.");
                 break;
             default:
                 wp_die("We're sorry, but we ran into a temporary problem while trying to load the account data. Please check back soon.", "Account data load error");
         }
     } else {
         $account_options = json_decode($apiHttpResponse["body"]);
     }
     if ($action == "results" || $action == "search") {
         dsidxpress_autocomplete::AddScripts(false);
     }
     if ($action == "results") {
         // save search
         if (!empty($get["idx-save"]) && $get["idx-save"] == "true") {
             $apiParams["name"] = $get["idx-save-name"];
             $apiParams["updates"] = $get["idx-save-updates"] == "on" ? "true" : "false";
             $apiHttpResponse = dsSearchAgent_ApiRequest::FetchData("SaveSearch", $apiParams, false, 0);
             $response = json_decode($apiHttpResponse["body"]);
             header('Content-Type: application/json');
             echo $apiHttpResponse["body"];
             die;
         }
         // check allowed searched before registration
         $allow_results_view = 1;
         if (!empty($account_options->AllowedSearchesBeforeRegistration) && isset($_COOKIE['dsidx-visitor-results-views'])) {
             if ((int) $account_options->AllowedSearchesBeforeRegistration <= (int) $_COOKIE['dsidx-visitor-results-views']) {
                 $allow_results_view = 0;
             }
         }
         $apiParams["requester.AllowVisitorResultsView"] = $allow_results_view;
         if (isset($apiParams["query.LinkID"])) {
             $apiParams["query.ForceUsePropertySearchConstraints"] = "true";
         }
         if (isset($apiParams["query.PropertySearchID"])) {
             $apiParams["query.ForceUsePropertySearchConstraints"] = "true";
         }
         $apiParams["directive.ResultsPerPage"] = 25;
         if (isset($apiParams["directive.ResultPage"])) {
             $apiParams["directive.ResultPage"] = $apiParams["directive.ResultPage"] - 1;
         }
         $apiParams["responseDirective.IncludeMetadata"] = "true";
         $apiParams["responseDirective.IncludeLinkMetadata"] = "true";
     } else {
         if ($action == "details") {
             // check allowed searched before registration
             $allow_details_view = 1;
             if (!empty($account_options->AllowedDetailViewsBeforeRegistration) && isset($_COOKIE['dsidx-visitor-details-views'])) {
                 if ((int) $account_options->AllowedDetailViewsBeforeRegistration <= (int) $_COOKIE['dsidx-visitor-details-views']) {
                     $allow_details_view = 0;
                 }
             }
             $useJuiceBox = 'true';
             if (isset($options['ImageDisplay'])) {
                 $useJuiceBox = $options['ImageDisplay'] == "slideshow" ? 'true' : 'false';
             }
             // echo $useJuiceBox;
             $apiParams["requester.AllowVisitorDetailView"] = $allow_details_view;
             $apiParams["responseDirective.UseJuiceBoxSlideShow"] = $useJuiceBox;
             // if we have an auth cookie then record a property visit
             if (@$_COOKIE['dsidx-visitor-auth']) {
                 $visitParams = array("mlsNumber" => $apiParams["query.MlsNumber"]);
                 $apiVisitResponse = dsSearchAgent_ApiRequest::FetchData("RecordVisit", $visitParams, false, 0);
             }
             $screen_name = get_option('zillow_screen_name');
             if (!empty($screen_name)) {
                 $apiParams["responseDirective.ZillowScreenName"] = $screen_name;
             }
         }
     }
     $apiParams["responseDirective.IncludeDisclaimer"] = "true";
     $apiParams["responseDirective.IncludeDsDisclaimer"] = defined('ZPRESS_API') && ZPRESS_API != '' ? "false" : "true";
     $apiParams["responseDirective.RemoveDsDisclaimerLinks"] = isset($options['RemoveDsDisclaimerLinks']) && $options['RemoveDsDisclaimerLinks'] == 'Y' ? "true" : "false";
     $apiHttpResponse = dsSearchAgent_ApiRequest::FetchData($wp_query->query["idx-action"], $apiParams, false);
     if (!isset($apiHttpResponse["body"]) || !isset($apiHttpResponse["response"])) {
         wp_die("We're sorry, but we ran into a temporary problem while trying to load the real estate data. Please check back soon.", "Real estate data load error");
     }
     $apiData = $apiHttpResponse["body"];
     $apiData = str_replace('{$contentDomId}', $post_id, $apiData);
     if ($action == 'details' && defined('ZPRESS_API') && ZPRESS_API != '') {
         if (!isset($personal_info)) {
             $personal_info = stripslashes_deep(get_option('personal_info'));
         }
         if (!empty($personal_info['google_authorship']) && !empty($personal_info['googleplus'])) {
             $apiData .= '<p>By <a href="' . esc_url($personal_info['googleplus']) . '?rel=author" target="_blank">' . $personal_info['first_name'] . ' ' . $personal_info['last_name'] . '</a></p>';
         }
     }
     if (in_array($_SERVER["REMOTE_ADDR"], self::$DebugAllowedFrom)) {
         if (isset($get["debug-api-response"])) {
             print_r($apiHttpResponse);
             exit;
         }
     }
     if ($apiHttpResponse["response"]["code"] == "404") {
         $error_template = isset($options["404Template"]) ? $options["404Template"] : '';
         if ($error_template == '') {
         } elseif (strpos($error_template, '.php')) {
             $error_404 = locate_template('404.php');
             if (!empty($error_404)) {
                 wp_cache_set($post_id, array("_wp_page_template" => array($error_template)), "post_meta");
             }
         } elseif (is_numeric($error_template)) {
             $post_id = $error_template;
         }
         $wp_query->set('is_404', true);
         add_action('get_header', array("dsSearchAgent_Client", "Return404"));
     } else {
         if ($apiHttpResponse["response"]["code"] == "302") {
             $redirect = dsSearchAgent_Client::GetBasePath() . self::ExtractValueFromApiData($apiData, "redirect");
             header("Location: {$redirect}", true, 302);
             exit;
         } else {
             if (empty($apiHttpResponse["body"]) || !empty($apiHttpResponse["errors"]) || substr($apiHttpResponse["response"]["code"], 0, 1) == "5") {
                 wp_die("We're sorry, but we ran into a temporary problem while trying to load the real estate data. Please check back soon.", "Real estate data load error");
             }
         }
     }
     /*if ($options['ResultsTitle'] != '')
     			$title = $options['ResultsTitle'];
     		else */
     $seo_title = self::ExtractValueFromApiData($apiData, "seo_title");
     $seo_description = self::ExtractValueFromApiData($apiData, "seo_description");
     $seo_keywords = self::ExtractValueFromApiData($apiData, "seo_keywords");
     $title = self::ExtractValueFromApiData($apiData, "title");
     $dateaddedgmt = self::ExtractValueFromApiData($apiData, "dateaddedgmt");
     $description = self::ExtractValueFromApiData($apiData, "description");
     $firstimage = self::ExtractValueFromApiData($apiData, "firstimage");
     self::$meta_tag_data = array('firstimage' => $firstimage, 'title' => $title, 'description' => $description);
     self::$CanonicalUri = self::ExtractValueFromApiData($apiData, "canonical");
     self::$TriggeredAlternateUrlStructure = self::ExtractValueFromApiData($apiData, "alternate-urls");
     if (!isset($wp_query->query['ds-idx-listings-page'])) {
         if ($apiHttpResponse["response"]["code"] != "404") {
             self::EnsureBaseUri();
         }
     }
     set_query_var("name", "dsidxpress-{$action}");
     // at least a few themes require _something_ to be set here to display a good <title> tag
     set_query_var("pagename", "dsidxpress-{$action}");
     // setting pagename in case someone wants to do a custom theme file for this "page"
     if (isset($options["404Template"]) && !empty($options["404Template"]) && $post_id == $options["404Template"]) {
         $post_id = $options["404Template"];
         $post = get_post($post_id);
     } else {
         $post = (object) array("ID" => $post_id, "comment_count" => 0, "comment_status" => "closed", "ping_status" => "closed", "post_author" => 1, "post_content" => $apiData, "post_date" => $dateaddedgmt ? $dateaddedgmt : date("c"), "post_date_gmt" => $dateaddedgmt ? $dateaddedgmt : gmdate("c"), "post_excerpt" => $description, "post_name" => "dsidxpress-data", "post_parent" => 0, "post_status" => "publish", "post_title" => $title, "post_type" => "page");
     }
     if (!$idx_page_id) {
         wp_cache_set($post_id, $post, 'posts');
     }
     $posts = array($post);
     // track the detail & result views, do this at the end in case something errors or w/e
     $views = intval(@$_COOKIE["dsidx-visitor-{$action}-views"]);
     setcookie("dsidx-visitor-{$action}-views", $views + 1, time() + 60 * 60 * 24 * 30, '/');
     $dsidxpress_seo = new dsidxpress_seo($seo_title, $seo_description, $seo_keywords);
     if (!$idx_page_id && isset($seo_title)) {
         add_filter('wp_title', array($dsidxpress_seo, 'dsidxpress_title_filter'));
     }
     if (isset($seo_keywords) || isset($seo_description)) {
         add_action('wp_head', array($dsidxpress_seo, 'dsidxpress_head_action'));
     }
     add_action('wp_head', array("dsSearchAgent_Client", 'SocialMetaTags'));
     if ($action == "search") {
         dsidx_footer::ensure_disclaimer_exists("search");
     }
     return $posts;
 }