FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php script help!





DJHicks
im making a stats banner to show in forum sig's etc that displays the status of my shoutcast web stream... i made the banner and it works wen the stream was running using this script

Code:
<?php

$announce_colour = $_REQUEST['announce'];
$song_colour = $_REQUEST['song'];

if ( !$announce_colour ) { $announce_colour="0,0,0"; }
if ( !$song_colour ) { $song_colour="0,0,0"; }

$announce_colour=check_colour_specific( $announce_colour );
$song_colour=check_colour_specific( $song_colour );

$ip="72.29.82.28";
$port="8006";
$url="http://www.streamsolutions.co.uk/scripts/banner/Statbanner.png";

$sp=@fsockopen($ip,$port,&$errno,&$errstr,10);
if ($sp)
{
set_socket_blocking($sp,false);
fputs($sp,"GET /index.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
for($i=0; $i<30; $i++)
{
if(feof($sp)) break; // exit if connection broken
$sp_data.=fread($sp,1024);
usleep(500000);
}
$lines=split("/\n",$sp_data);
foreach ($lines as $line)
{ if ( preg_match("/SHOUTcast/",$line ) )
{ $cast_found=1; } } }
else { print "Not found\n"; exit(0); }

if ($cast_found)
{
$lines =split("<tr>",$sp_data);
foreach ($lines as $line)
{
if ( preg_match("/Stream Title:/",$line ) )
{ $data_block['stream_title']= retrieve_data ( "Stream Title:", $line ,"<b>" ,1, 1, 0, 1, "</b>"); }
if ( preg_match("/Current Song:/",$line ) )
{ $data_block['current_song']= retrieve_data ( "Current Song:", $line ,"<b>" ,1, 1, 0 ,1 ,"</b>"); }
if ( preg_match("/Server Status:/",$line ) )
{ $data_block['server_status']= retrieve_data ( "Server Status:", $line ,"<b>" ,1, 1, 0 ,1 ,"</b>"); }
}
}

# if you want to use a jpeg do
#$im = imagecreatefromjpeg ($url); /* Attempt to open */
# if you want to use a png do
 $im = imagecreatefrompng ($url); /* Attempt to open */
# if you want to use a gif do
#$im = @imagecreatefromgif ($url); /* Attempt to open */
if (!$im) { print "no image\n"; exit(0); } Header("Content-type: image/png");

$colour_array = split (",",$announce_colour );
$text_colour1 = ImageColorAllocate($im,$colour_array[0],$colour_array[1],$colour_array[2]);

$colour_array = split (",",$song_colour );
$text_colour2 = ImageColorAllocate($im,$colour_array[0],$colour_array[1],$colour_array[2]);

$string1= "Ganja Beats Net Radio";
$string2= $data_block['current_song'];
$string3= $data_block['stream_title'];

# this is image pointer,1,xpos, ypos, string, colour

ImageString($im,2,50,10,$string1,$text_colour1);
ImageString($im,1,50,35,$string2,$text_colour2);
ImageString($im,2,50,50,$string3,$text_colour2);
ImageGif($im);
ImageDestroy($im);

exit(0);

function retrieve_data ( $match, $string, $split, $pos1, $pos2, $white, $chop, $chopper )
{
$array = split($match,$string); $array = split ($split,$array[$pos1]);
if ( $white ) { $array[$pos2] = ereg_replace(" ", "", $array[$pos2]); }
if ( $chop ) { $array = split ($chopper, $array[$pos2] ); }
else { $array[0]=$array[$pos2]; }
$version = $array[0];
return $version;
}

function check_colour_specific ( $colour_string )
{
$colour_array= split (",",$colour_string );
$colour_count =0;
foreach ( $colour_array as $colour )
{ if ( $colour<0 || $colour>255 )
{ $colour_array[$colour_count]="0"; }
$colour_count++; }
if ( $colour_count<2 ) { return "0,0,0"; }
return ( $colour_array[0].",".$colour_array[1].",".$colour_array[2] );
}

?>


i need it to display - Stream is currently offline - obviously wen the streams offline

so i added the 3 lines to the end of the if cast found section

Code:
if ($cast_found)
{
$lines =split("<tr>",$sp_data);
foreach ($lines as $line)
{
if ( preg_match("/Stream Title:/",$line ) )
{ $data_block['stream_title']= retrieve_data ( "Stream Title:", $line ,"<b>" ,1, 1, 0, 1, "</b>"); }
if ( preg_match("/Current Song:/",$line ) )
{ $data_block['current_song']= retrieve_data ( "Current Song:", $line ,"<b>" ,1, 1, 0 ,1 ,"</b>"); }
if ( preg_match("/Server Status:/",$line ) )
{ $data_block['server_status']= retrieve_data ( "Server Status:", $line ,"<b>" ,1, 1, 0 ,1 ,"</b>"); }
}
}

if ( preg_match("/down:/", $line['server_status'] ) )
{ $data_block['current_song']="There is no song currently playing"; }
{ $data_block['stream_title']="Stream is currently offline"; }


i thought this worked as it displayed stream is currently offline wen the stream was offline... but i now wen the streams online instead of getting the main title, current song and title of the stream (i.e. the description section in the shoutcast source dsp) i get the main title, current song but it displays - Stream is currently offline in stead of the title of the stream

perhaps a whole new re-write? section for wen its online - so it cleary says - Ganja Beats Net Radio is Online then blah blah...

then else tag and Ganja Beats Net Radio is Offline

any ideas? - i partly found some of the code... as i have very little php knowledge... it did need some bits adding to it.. like the current song etc...

any help would be greatly appriciated... if you can come up with an easier script please write it here and i'll donate some fri$ thanks again!
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.