<?php

if (!file_exists("index.html")) die;

$template = file_get_contents("index.html");

$path = str_replace(array($_SERVER['HTTP_HOST'],"/marketplace"),array('',''),$_SERVER['REQUEST_URI']);
if (substr_count($path,"?")) $path .= "&p=pp_embed"; else $path .= "?p=pp_embed";

$curl = curl_init("https://api.puntopago.net/marketplace".$path);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$res = curl_exec($curl);
$data = json_decode($res, true);

$template = preg_replace("/\:description\" content=\"\"/",":description\" content=\"".htmlspecialchars($data['description'])."\"",$template);
$template = preg_replace("/\<title\>.*\<\/title\>/","<title>".htmlspecialchars($data['title'])."</title>",$template);
$template = preg_replace("/pp\-marketplace\"\>\</","pp-marketplace\"><br><br><br>".$data['text']."<",$template);

echo $template;

?>