<?php
$root = $_SERVER['DOCUMENT_ROOT'];
$headerScriptRoot = dirname(__FILE__, 2);
if ($root == $headerScriptRoot) {
	$baseHref = '/';
} else {
	$baseHref = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], "/", 1) + 1);
}
$baseHref = str_replace("\\", "/", $baseHref);
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">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>Profit Revolution</title>
	<base href="<?= $baseHref; ?>">

	<link rel="stylesheet" href="css/style.css">
	<link rel="apple-touch-icon" sizes="180x180" href="images/favicon/apple-touch-icon.png">
	<link rel="icon" type="image/png" sizes="32x32" href="images/favicon/favicon-32x32.png">
	<link rel="icon" type="image/png" sizes="16x16" href="images/favicon/favicon-16x16.png">
	<link rel="mask-icon" href="images/favicon/safari-pinned-tab.svg" color="#ee7d0c">
	<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
	<meta name="msapplication-TileColor" content="#ee7d0c">
	<meta name="theme-color" content="#ee7d0c">
	<style type="text/css">
        .popupOverlay{
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.7);
            z-index: 999;
        }

        .popUpContent {
            position: fixed;
            max-height: 450vh;
            max-width: 400px;
            width: 90%;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            padding: 10px;
            background: #ffffff;
            z-index: 9999;
            border-radius: 5px;
        }

        .popUpContent img {
            width: 100%;
            object-fit: contain;
            max-height: 450px;
            /*max-height: 70vh;*/
        }


        .closeMOdal {
            position: absolute;
            display: inline-block;
            width: 25px;
            height: 25px;
            border-radius: 150px;
            background: #eaeaea;
            text-align: center;
            line-height: 25px;
            color: #333;
            top: -13px;
            right: -13px;
        }

	</style>
	<link rel="stylesheet" href="js/videojs/video-js.css">
	<script type="text/javascript" src="js/videojs/video.js"></script>
