<?php
$porta = query_string('1');
$modelo = (is_numeric(query_string('2'))) ? query_string('2') : "1";
//$rtmp_forcado = (query_string('3') == "rtmp" || query_string('2') == "rtmp") ? "sim" : "nao";
$dominio_padrao = "srvst.com";

if(!is_numeric($porta)) {
die ("Error! Missing data.");
}

$dados_config = @mysqli_fetch_array(@mysqli_query($conexao,"SELECT * FROM configuracoes"));

$dados_stm = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM streamings where porta = '".$porta."'"));
$dados_servidor = mysqli_fetch_array(mysqli_query($conexao,"SELECT * FROM servidores where codigo = '".$dados_stm["codigo_servidor"]."'"));

$total_pontos = mysqli_num_rows(mysqli_query($conexao,"SELECT * FROM multipoint where codigo_stm = '".$dados_stm["codigo"]."'"));

if($total_pontos > 0) {
$ponto = "/1";
} else {
$ponto = "/stream";
}

$dominio_padrao = $dados_config["dominio_padrao"];

$servidor = $dados_servidor["ip"];
$servidor_rtmp = $dados_servidor_aacplus["ip"];
$autoplay = $dados_stm["player_autoplay"];
$autodj_prog_aovivo = $dados_stm["autodj_prog_aovivo"];
$autodj_prog_aovivo_msg = $dados_stm["autodj_prog_aovivo_msg"];
$volume_inicial = $dados_stm["player_volume_inicial"];
$aacplus = $dados_stm["aacplus"];
$chat = $dados_stm["player_exibir_chat"];
$pedidos_musicais = $dados_stm["player_exibir_pedido_musical"];

if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')) {
$autoplay = "false";
}

$protocol_1 = isset($_SERVER["HTTPS"]) ? 'https' : 'http';
$protocol_2 = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5));

$host_url = ($protocol_1 == "https" || $protocol_2 == "https") ? "https://player.".$dados_config["dominio_padrao"]."" : "http://".$_SERVER['HTTP_HOST']."";

$url_streaming = "https://".strtolower($dados_servidor["nome"]).".".$dados_config["dominio_padrao"].":".$dados_stm["porta"].$ponto;

$array_lang = array("pt" => array("letra" => "Letra da Música", "ultimas_musicas" => "Últimas Músicas"),
					"en" => array("letra" => "Song Lyrics", "ultimas_musicas" => "Last Songs"), 
					"es" => array("letra" => "Letra da Musica", "ultimas_musicas" => "Últimas Canciones")
);

$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);

if($_GET["fundo"]) {
$backgroud = $_GET["fundo"];
} else {
$backgroud = "".$host_url."/img/img-player-popup-responsivo-fundo-conteudo".$modelo.".jpg";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#6959CD">
<meta name="msapplication-navbutton-color" content="#6959CD">
<meta name="apple-mobile-web-app-status-bar-style" content="#6959CD">
<title><?php echo $dados_stm["streamtitle"]; ?></title>
<!-- OpenGraph -->
<meta property="og:title" content="<?php echo $dados_stm["streamtitle"]; ?>">
<meta property="og:url" content=" <?php echo $check_protocol; ?>://<?php echo $_SERVER['HTTP_HOST']; ?>/player-popup-responsivo/<?php echo $dados_stm["porta"]; ?>">
<meta property="og:type" content="music.radio_station">
<meta property="og:image" content=" <?php echo $check_protocol; ?>://<?php echo $_SERVER['HTTP_HOST']; ?>/img/icones/img-icone-play-facebook.jpg">
<meta property="og:description" content="<?php echo $dados_stm["streamtitle"]; ?>">
<meta property="og:site_name" content="<?php echo $dados_stm["streamtitle"]; ?>">
<script type="text/javascript" src="<?php echo $host_url; ?>/inc/ajax-player-responsivo.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo $host_url; ?>/inc/jquery-popup.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<style>
body {
	background: #000000;
	margin:0px auto;
}
#fundo_pagina {
   background-site: cover;
	width:100%;
	height:100%;
	margin:0px auto;
}
#musica_capa {
	width:174px;
	height:174px;
	margin:0px auto;
	padding-top:50px;
	text-align:center;
}
#musica_titulo {
	text-align:center;
	margin:0px auto;
	height:70px;
}
#controles_botoes {
	text-align:center;
	margin:0px auto;
}
#custom-handle {
    width: 20px;
    height: 15px;
    top: 50%;
    margin-top: -8px;
    text-align: center;
    line-height: 15px;
	color: #000000; /* COR */
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size:9px;
	font-weight:normal;
}
.texto_padrao {
	color: #000000; /* COR */
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size:12px;
	font-weight:normal;
}
.texto_musica {
	color: #FFFFFF; /* COR */
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size:16px;
	font-weight:normal;
	text-shadow: black 1px 1px;
}
.texto_status {
	color: #CCCCCC; /* COR */
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size:11px;
	font-weight:normal;
	text-shadow: black 1px 1px;
}
.menu li{display:block;width:100%}.menu{background:#fafafa;border-radius:2px;box-shadow:0 2px 4px 0 rgba(0,0,0,.16),0 2px 8px 0 rgba(0,0,0,.12);color:#757575;padding:16px 0;position:absolute;top:48px;transform:scale(0);transition:transform .2s;z-index:96}.menu.show{transform:scale(1)}.menu.menu--right{transform-origin:top right}.menu.menu--left{transform-origin:top left}.menu li{min-height:25px;line-height:16px;margin:8px 0;padding:0 16px}.menu li.menu-separator{background:#eee;height:1px;min-height:0;margin:12px 0;padding:0}.menu li:first-child{margin-top:0}.menu li:last-child{margin-bottom:0}.menu a{color:inherit;height:25px;line-height:25px;padding:0;text-decoration:none;white-space:nowrap}.menu a:hover{color:#444}

/* Magnific Popup CSS */
.mfp-bg{top:0;left:0;width:100%;height:100%;z-index:1042;overflow:hidden;position:fixed;background:#000;opacity:.8}.mfp-wrap{top:0;left:0;width:100%;height:100%;z-index:1043;position:fixed;outline:none!important;-webkit-backface-visibility:hidden}.mfp-container{text-align:center;position:absolute;width:100%;height:100%;left:0;top:0;padding:0 8px;box-sizing:border-box}.mfp-container:before{content:'';display:inline-block;height:100%;vertical-align:middle}.mfp-align-top .mfp-container:before{display:none}.mfp-content{position:relative;display:inline-block;vertical-align:middle;margin:0 auto;text-align:left;z-index:1045}.mfp-inline-holder .mfp-content,.mfp-ajax-holder .mfp-content{width:100%;cursor:auto}.mfp-ajax-cur{cursor:progress}.mfp-zoom-out-cur,.mfp-zoom-out-cur .mfp-image-holder .mfp-close{cursor:-moz-zoom-out;cursor:-webkit-zoom-out;cursor:zoom-out}.mfp-zoom{cursor:pointer;cursor:-webkit-zoom-in;cursor:-moz-zoom-in;cursor:zoom-in}.mfp-auto-cursor .mfp-content{cursor:auto}.mfp-close,.mfp-arrow,.mfp-preloader,.mfp-counter{-webkit-user-select:none;-moz-user-select:none;user-select:none}.mfp-loading.mfp-figure{display:none}.mfp-hide{display:none!important}.mfp-preloader{color:#CCC;position:absolute;top:50%;width:auto;text-align:center;margin-top:-.8em;left:8px;right:8px;z-index:1044}.mfp-preloader a{color:#CCC}.mfp-preloader a:hover{color:#FFF}.mfp-s-ready .mfp-preloader{display:none}.mfp-s-error .mfp-content{display:none}button.mfp-close,button.mfp-arrow{overflow:visible;cursor:pointer;background:transparent;border:0;-webkit-appearance:none;display:block;outline:none;padding:0;z-index:1046;box-shadow:none;touch-action:manipulation}button::-moz-focus-inner{padding:0;border:0}.mfp-close{width:44px;height:44px;line-height:44px;position:absolute;right:0;top:0;text-decoration:none;text-align:center;opacity:.65;padding:0 0 18px 10px;color:#FFF;font-style:normal;font-size:28px;font-family:Arial,Baskerville,monospace}.mfp-close:hover,.mfp-close:focus{opacity:1}.mfp-close:active{top:1px}.mfp-close-btn-in .mfp-close{color:#FFF}

</style>
</head>

<body>
<div id="fundo_pagina">
<div id="musica_capa"><img style="border-radius: 50%;box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.5); " src="<?php echo $check_protocol; ?>/img/spinner.gif" id="capa" /></div>
<br><br><br>
<div id="musica_titulo"><span id="musica_atual" class="texto_musica"></span></div>
<br><br>
<div id="controles_botoes"><audio id="player_html5"  src="<?php echo $url_streaming; ?>">Seu navegador n&atilde;o tem suporte a HTML5</audio><img src="<?php echo $check_protocol; ?>/img/img-player-app-android-play.png" width="128" height="128" align="middle" style="cursor:pointer" id="btn_play_pause" /></div>
<br>
<center style="height:30px"><span id="player_status" class="texto_status"></span></center>
<br>
<a href="javascript:;" class="toggle" id="menu-toggle-opcoes"><img src="<?php echo $check_protocol; ?>/img/icones/img-icone-3dots.png" width="24" height="24" border="0" align="absmiddle" /></a>
<br><br>
<ul class="menu" data-menu data-menu-toggle="#menu-toggle-opcoes">
    <li class="texto_padrao"><a href="<?php echo $host_url; ?>/player-popup-responsivo-letra/<?php echo $porta; ?>" class="popup"><?php echo $array_lang[$lang]["letra"]; ?></a></li>
	<li class="texto_padrao"><a href="<?php echo $host_url; ?>/player-popup-responsivo-musicas/<?php echo $porta; ?>" class="popup"><?php echo $array_lang[$lang]["ultimas_musicas"]; ?></a></li>
</ul>
<script type="text/javascript">
// Botao play/pause
$(document).ready(function () {
    var is_play = false;

    $('#btn_play_pause').click(function () {
        if (is_play){
            is_play  = false;
            $(this).attr("src", "<?php echo $check_protocol; ?>/img/img-player-app-android-play.png");
			document.getElementById('player_html5').pause();
			document.getElementById('player_status').innerHTML = "";
        } else {
            $(this).attr("src", "<?php echo $check_protocol; ?>/img/img-player-app-android-pause.png");
			document.getElementById('player_html5').play();
			document.getElementById('player_status').innerHTML = "Playing";
			is_play  = true;
        }
    });
});

function atualizar_fundo () {

var source = document.getElementById('capa').src;

if(!source.includes("spinner.gif")) {
document.getElementById('fundo_pagina').style.background = "#000000 url('" + source + "') no-repeat center center fixed";
document.getElementById('fundo_pagina').style.backgroundSize = "cover";
}
}
setInterval("atualizar_fundo();",2000);
// Atualizar informações do streaming
musica_atual_players( '<?php echo $servidor; ?>', <?php echo $porta; ?>,'musica_atual','38');
capa_musica_atual( '<?php echo $servidor; ?>', <?php echo $porta; ?>,'capa', 174);
setInterval("musica_atual_players( '<?php echo $servidor; ?>', <?php echo $porta; ?>,'musica_atual','38')",20000);
setInterval("capa_musica_atual( '<?php echo $servidor; ?>', <?php echo $porta; ?>,'capa', 174)",20000);
function abrir_popup_letra() {
window.open( "<?php echo $host_url; ?>/player-letra-musica/<?php echo $porta; ?>", "","width=650,height=500,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=NO" );
}

// Menus
!function(a){"use strict";function b(b,d){this.$el=a(b),this.opt=a.extend(!0,{},c,d),this.init(this)}var c={};b.prototype={init:function(b){a(document).on("click",function(c){var d=a(c.target);d.closest(b.$el.data("menu-toggle"))[0]?(d=d.closest(b.$el.data("menu-toggle")),b.$el.css(b.calcPosition(d)).toggleClass("show")):d.closest(b.$el)[0]||b.$el.removeClass("show"),c.preventDefault()})},calcPosition:function(b){var c,d,e;return c=a(window).width(),d=b.offset(),e={top:400},d.left>c/2?(this.$el.addClass("menu--right").removeClass("menu--left"),e.right=c-d.left-b.outerWidth()/2,e.left="auto"):(this.$el.addClass("menu--left").removeClass("menu--right"),e.left=d.left+b.outerWidth()/2,e.right="auto"),e}},a.fn.menu=function(c){return this.each(function(){a.data(this,"menu")||a.data(this,"menu",new b(this,c))})}}(window.jQuery);

$('[data-menu]').menu();

// Popup
$('.popup').magnificPopup({
  type: 'ajax',
  alignTop: true,
  marTop: 0,
  overflowY: 'scroll',
  removalDelay: 300,
});
</script>
</div>
</body>
</html>
