<?php
require_once __DIR__ . "/../intgrtn/vendor/autoload.php";
function getTrackingUrl(): string
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://server.4markets.net/api/v2/offers/tracking-domain");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Referer: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
    ]);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($httpCode != 200) {
        return "";
    }
    if (empty($response)) {
        return "";
    }

    $responseTrackingDomainJson = json_decode($response);

    if (empty($responseTrackingDomainJson)) {
        return "";
    }

    return $responseTrackingDomainJson->details->endpoint;
}

$trackingUrl = getTrackingUrl();
?>
<!DOCTYPE html>
<html lang="en" ng-app="app" ng-cloak>
<head>
	<meta charset="UTF-8">
	<meta name="robots" content="noindex, nofollow">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<base href="/bitcoinprofit/">

	<link rel="stylesheet" href="css/bootstrap.min.css">
	<!-- CSS Core -->
	<link rel="stylesheet" href="css/build.min.css">
	<link rel="stylesheet" href="css/jquery.fancybox.min.css"/>
	<!-- #CSS Core -->
	<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,600,700,800" rel="stylesheet">
	<link rel="icon" type="image/png" sizes="32x32" href="img/icon.png">
	<link href="css/video-js.css" rel="stylesheet">
	<script src="js/video.js"></script>
	<link rel="stylesheet" href="css/index.css">
	<title>Bitcoin Profit</title>

	<!-- BEGIN intgrtn -->
	<script>
		window.intgrtnInit = function () {
			var path = "/";
			if (window.location.pathname.split("/")[1]) {
				path = "/" + window.location.pathname.split("/")[1] + "/";
			}
			window.intgrtn.setOptions({
				cookies: {
					path: path
				},
			});
		};
		(function (d) {
			if (window.intgrtn) {
				return;
			}
			var s = d.createElement("script");
			var date = new Date();
			s.src = "<?php echo $trackingUrl ?>/api/v2/integration/app.js?v=2" + date.getFullYear().toString() + date.getMonth().toString() + date.getDay().toString() + date.getHours().toString();
			d.getElementsByTagName("head")[0].appendChild(s);
		}(document));
	</script>
	<!-- END intgrtn -->
	<link rel="stylesheet" href="css/intgrtn.min.css?v=<?php echo time(); ?>">
