<?php

/************************************************************************/
/* ShoutCast Suite for TB Source */
/* v1.0 */
/* =========================== */
/* */
/* Copyright © 2005 by SLaTkiS */
/* http://www.noviteti.com */
/* */
/************************************************************************/

$index = 1;

global $bgcolor2;

/////////////////////////
// SECTION 1 :: CONFIG //
/////////////////////////

error_reporting (E_ALL ^ E_WARNING ^ E_NOTICE);
//SHOUTcast server settings, needed to get the XML output from the DNAS
//Changeme
$shout_server = "91.121.12.172";
$shout_port = "8000";
$shout_password = "changeme";

//Set this to whatever the bitrate you are streaming at is
$bitrate="128 kbps";

//Default Album Cover
//Changeme
$default_album_cover="hier könnt ihr einen Direktlink einfügen, habe ich hjedoch bei mir ausgebaut";

//Stream Name
//Changeme
$streamname="Test-Radio";

//////////////////////////////////////
// SECTION 2 :: CONNECT AND RECEIVE //
//////////////////////////////////////

$shout_socket = fsockopen ($shout_server, $shout_port, $errno, $errstr,30);

if (!$shout_socket)
{
echo "Error: Radio zuzeit offline";
}

else
{

$xml_load = "";

// Let's say hello
fputs ($shout_socket, "GET /admin.cgi?pass=".$shout_password."&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n");

// Now get the XML

while (!feof($shout_socket)) {
$xml_load .= fgets ($shout_socket, 1000);
}

}

if ($shout_socket) {

//////////////////////////////
// SECTION 3 :: PERPARE XML //
//////////////////////////////

// For my own sanity, I'm getting OUT of XML here, replacing tags with [ ] brackets, so that
// <SONG> becomes [SONG], etc...

$xml_load = strtr ($xml_load, '<', '[');
$xml_load = strtr ($xml_load, '>', ']');

$tag_separated = explode ("]", $xml_load);

foreach ($tag_separated as $key => $value) {
$tag_separated[$key] = $value."]\n";
if (substr_count($value, "Content-Type")) {$tag_separated[$key] = "";}
}


//////////////////////////////
// SECTION 4 :: PARSING XML //
//////////////////////////////

// $titles array will hold the last 10 songs played
// Note that $titles[0] will give you the currently playing song
// -- the following are provided to let you know which stats are being grabbed by this script

$titles = array();
$currentlisteners=0;
$peaklisteners=0;
$maxlisteners=0;
$reportedlisteners=0;
$averagetime=0;
$servergenre="";
$serverurl="";
$servertitle="";

foreach ($tag_separated as $value) {
if (substr_count($value, "[/TITLE]")) {
$value = str_replace ("[/TITLE]","", $value);
array_push ($titles, $value);
}

if (substr_count ($value, "[/CURRENTLISTENERS]")) {
$value = str_replace ("[/CURRENTLISTENERS]","", $value);
$currentlisteners=$value;
}

if (substr_count ($value, "[/PEAKLISTENERS]")) {
$value = str_replace ("[/PEAKLISTENERS]","", $value);
$peaklisteners=$value;
}

if (substr_count ($value, "[/MAXLISTENERS]")) {
$value = str_replace("[/MAXLISTENERS]","", $value);
$maxlisteners=$value;
}

if (substr_count ($value, "[/REPORTEDLISTENERS]")) {
$value = str_replace("[/REPORTEDLISTENERS]","", $value);
$reportedlisteners=$value;
}

if (substr_count ($value, "[/AVERAGETIME]")) {
$value = str_replace("[/AVERAGETIME]","", $value);
$averagetime=$value;
$tmp=$averagetime / 60;
$averagesec=$averagetime % 60;
if ($averagesec < 10) {$averagesec = "0".$averagesec;}
$averagemin = sprintf ("%d",$tmp);
$averagehour = $averagemin / 60;
$averagemin = $averagemin % 60;
$averagehour = sprintf ("%d", $averagehour);
}

if (substr_count ($value, "[/SERVERGENRE]")) {
$value = str_replace("[/SERVERGENRE]","", $value);
$servergenre=$value;
}

if (substr_count ($value, "[/SERVERURL]")) {
$value = str_replace("[/SERVERURL]","", $value);
$serverurl=$value;
}

if (substr_count ($value, "[/SERVERTITLE]")) {
$value = str_replace("[/SERVERTITLE]","", $value);
$servertitle=$value;
if (substr_count ($servertitle, "N/A")) {$servertitle = "Radio zurzeit offline!";}
}

if (substr_count ($value, "[/STREAMHITS]")) {
$value = str_replace("[/STREAMHITS]","", $value);
$streamhits=$value;
}
}

// $nowplaying[0] = currently playing artist
// $nowplaying[1] = currently playing title
// Obviously, use of this requires that titles be named like so:
// Artist - Title
// If not, just use $titles[0] for the current song

$temp = $titles[0];
$nowplaying = explode (" - ",$temp);

//////////////////////////////////
// SECTION 5 :: OUTPUT THE PAGE //
//////////////////////////////////

//Show if on or off -added by bodhisattva//

$fp = fsockopen("$shout_server", $shout_port, &$errno, &$errstr, 30);
if(!$fp) {
$success=2;
}
if($success!=2){ //if connection
fputs($fp,"GET /7.html HTTP/1.0\r\nUser-Agent: XML Getter (Mozilla Compatible)\r\n\r\n");
while(!feof($fp)) {
$page .= fgets($fp, 1000);
}
fclose($fp);
$page = ereg_replace(".*<body>", "", $page); //extract data
$page = ereg_replace("</body>.*", ",", $page); //extract data
$numbers = explode(",",$page);
$currentlisteners=$numbers[0];
$connected=$numbers[1];
if($connected==1)
$wordconnected="yes";
else
$wordconnected="no";
}

if($success!=2 && $connected==1){

print "<center>&nbsp;&nbsp;<font=red><br><b>&nbsp;&nbsp;Army of Hell Power Radio1</font></b><br><br></center>";
print "<center><img src=" . $GLOBALS["PIC_BASE_URL"] . "radioonline.gif width=45 height=13 alt=Online style=vertical-align: middle;><br><br></center>";
print "&nbsp;&nbsp;Künstler: <b> $nowplaying[0]</b><br>";
print "&nbsp;&nbsp;Song: <b>$nowplaying[1]</b><br>";
print "&nbsp;&nbsp;Bitrate: <b>$bitrate</b><br>";
print "&nbsp;&nbsp;Zuhörer: <b>$currentlisteners/$maxlisteners</b><br>";
print "&nbsp;&nbsp;Zeit: <b>".date ("H:i:s")."</b><br><br>";
print "<center>&nbsp;&nbsp;<b><a
//Changeme
href=\"http://91.121.12.172:8000/listen.pls\">Reinhören!</a></b><br><br></center>";

}
else{
print "<center><br>Zeit: <b>".date ("H:i:s")."</b><br><br></center>";
print "<center><img src=" . $GLOBALS["PIC_BASE_URL"] . "radiooffline.gif width=45 height=13 alt=Online style=vertical-align: middle;><br><br></center>";
print "<center>Zur Zeit keine Sendung!</b><br><br></center>";
}
}


?>