'; getOfficeListings($officeId = intval($_GET['oid']), $type, $propertyIds, $limit, $noslider); } elseif (!empty($_GET['office'])) { //echo ''; getOfficeListings(null, $type, $propertyIds, $limit, $noslider, sanitize_text_field($_GET['office'])); } else { die("Virhe: Toimistotunnus tai toimiston nimi vaaditaan!"); } $autoplayspeed = 10000; if (!empty($_GET['speed']) && is_numeric($_GET['speed'])) { $autoplayspeed = intval($_GET['speed']) * 1000; } function api_call($apiKey, $apiEndpoint, $target = "", $query = array(), $method = 'GET', $requestHeaders = array()) { // Build URL if (!is_null($query) &&(is_array($query) || is_object($query)) && in_array($method, array('GET','POST','DELETE'))) $url = $apiEndpoint . $target . "?" . http_build_query($query); // Configure cURL $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, TRUE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($curl, CURLOPT_MAXREDIRS, 3); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 3); // curl_setopt($curl, CURLOPT_SSLVERSION, 3); //curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); //curl_setopt($curl, CURLOPT_USERPWD, "LINEAR-API-KEY $apiKey"); //Your credentials goes here curl_setopt($curl, CURLOPT_USERAGENT, 'RE/MAX integraatio v.1'); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); // Setup headers //$request_headers[] = ""; /* if (!is_null($apiKey)) $requestHeaders[] = "LINEAR-API-KEY: " . $apiKey; curl_setopt($curl, CURLOPT_HTTPHEADER, $requestHeaders); */ if ($method != 'GET' && in_array($method, array('POST', 'PUT'))) { if (is_array($query)) $query = http_build_query($query); curl_setopt ($curl, CURLOPT_POSTFIELDS, $query); } /* echo "
";
	echo "Method $method | Querying $url with
"; //echo(urldecode($query)); print_r($requestHeaders); echo "
"; */ // Send request to API and capture any errors $response = curl_exec($curl); $error_number = curl_errno($curl); $error_message = curl_error($curl); $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $header = substr($response , 0, $header_size); $body = substr($response , $header_size); // Close cURL to be nice curl_close($curl); // Return an error is cURL has a problem if ($error_number) { return $error_message; } else { return array("header" => $header, "body" => $body); } } function strHeaders2Hash($r) { $o = array(); $r = substr($r, stripos($r, "\r\n")); $r = explode("\r\n", $r); foreach ($r as $h) { $hr = explode(": ", $h); //error_log("HR: " . print_r($hr, true)); if (empty($hr)) continue; if (is_array($hr) && !empty($hr[0])) { $o[$hr[0]] = array_key_exists(1, $hr) ? $hr[1] : ''; } } return $o; } function getOfficeListings($officeId = null, $type = 0, $propertyIds = null, $limit = 0, $order = null, $noslider = 0, $officeName = null) { $apiEndpoint = 'https://remax.fi/wp-content/themes/blocksy-child/'; $target = "get_office_listings.php"; $query = []; $query['oid'] = $officeId; $query['office'] = $officeName; $query['type'] = $type; $query['limit'] = $limit; $query['order'] = $order; if ($noslider) $query['noslider'] = 1; if ($propertyIds !== null && is_array($propertyIds)) { $query['pid'] = implode(',', $propertyIds); } $listings = []; $result = api_call('', $apiEndpoint, $target, $query); if(!empty($result['body'])) { $returnArray = strHeaders2Hash($result['header']); echo ''; echo '
'; echo $result['body']; echo '
'; } } ?>