<?php
require_once('../smarty/Smarty.class.php');

define('ROOT_PATH', preg_replace('/index.php/', '', $_SERVER["DOCUMENT_ROOT"].$_SERVER["DOCUMENT_URI"]));
define('TOOLS_PATH', preg_replace('|\/embed|', '', ROOT_PATH.'tools/') );

$titulo="YTLibre";
$template= new Smarty();

/* ---- ---- Variables ---- ---- */
$template->assign("titulo", $titulo);

/* ---- ---- CSS ---- ---- */
$template->assign('styles', array('frond' => '../templates/css/frond.min.css',
                                  'normalize' => '../templates/css/normalize.css')
);

/* ---- ---- ---- Generated ---- ---- ---- ---- */
if (empty($_GET['link'])){
    $template->display('../templates/index.tpl');
} else {
    /* ---- ---- video-generated ---- ---- */
    require_once ( TOOLS_PATH.'processor.php' );
    $video_decode = new Smarty();

    /* ---- ---- Variables ---- ---- */
    $video_decode->assign("titulo", $titulo);
    $video_decode->assign("videoTitle", $videoTitle);
    $video_decode->assign("videoThumbURL", $videoThumbURL);

    // Videos Loop
    $video_decode->assign("streamFormats", $streamFormats);

    // Live
    $video_decode->assign("islive", $islive);

    /* ---- ---- CSS ---- ----  */
    $video_decode->assign('styles', array('frond' => '../templates/css/frond.min.css',
                                          'normalize' => '../templates/css/normalize.css',
                                          'plyr' => '../templates/libs/plyr/plyr.css',
                                          'salida' => '../templates/css/salida.min.css')
    );

    /* ---- ---- JS ---- ---- */
    $video_decode->assign('javascript', array('plyr' => '../templates/libs/plyr/plyr.embed.min.js')
    );

    $video_decode->display('../templates/embed.tpl');
}
