';
getOfficeListings($officeId = intval($_GET['oid']), $type, $propertyIds, $limit, $noslider);
} else {
die("Virhe: Puuttuva toimistotunnus!");
}
$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, $type = 0, $propertyIds = null, $limit = 0, $noslider = 0) {
$apiEndpoint = 'https://remax.fi/wp-content/themes/blocksy-child/';
$target = "get_office_listings.php";
$query = [];
$query['oid'] = $officeId;
$query['type'] = $type;
$query['limit'] = $limit;
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 '';
}
}
?>