Signature code help

Need help? Post your questions here.

Moderator: moderators

Signature code help

Postby dazbobaby » Sun Sep 26, 2021 9:46 am

I need a little help getting the old signature code working, I'm not a PHP coder, so while it's high-level and I can read/follow it, I obviously don't understand why it's failing.

It doesn't show the details when I play music, I'm not using subsonic to play video, so that's not important.
Code: Select all
<?php
  //First collect some data:
$user = "*******"; //user to monitor
$admin = "*********"; //user to get nowPlaying list
$adminpass = "*********"; //pass to get nowPlaying list (plain or using enc:)
$server = "192.168.0.10:4040"; //Your subsonic server
$xml = @simplexml_load_file("http://".$server."/rest/getNowPlaying.view?u=".$admin."&p=".$adminpass."&v=1.16.1&c=sig_php");
if($xml==false) {
goto offline;
}

// Hitcounter
//$filename = 'hitcountdayz.txt';
//$handle = fopen($filename, 'r');
//$hits = trim(fgets($handle)) + 1;
//fclose($handle);

//$handle = fopen($filename, 'w');
//fwrite($handle, $hits);
//fclose($handle);
//Timestamp
//Different Timezones supported: http://phptutorial.info/?timezones
date_default_timezone_set('Europe/London');
$time = "My server time: ".date(" M: d: H:i");

    //If the server is online, check what the monitored user is listening or watching, and jump to the right code...
foreach($xml->children()->children() as $second_gen) {
$math = floor($second_gen['duration']/60);
if($second_gen['username']==$user and $second_gen['minutesAgo']<=$math) {
if($second_gen['isVideo']=='false') {
goto playing;
}
//else{
//goto watching;
//}
}
}

      //If user is offline, or the last file has finished playing...
nothing:
$imageList = array("couch.png","eq2.png","guitar.png","hifi.png","kaley3.png","kaley7.png","music4.png","music7.png","music6.png","music9.png","music11.png","music14.png","music16.png","music18.png","sony2.png","sony3.png");
$image = imagecreatefrompng($imageList[rand(1,count($imageList))-1]);
$end = imagealphablending($image, true);
$save = imagesavealpha($image, true);
$color = imagecolorallocate($image, 0, 0, 0);
$font = getcwd()."/Capture-it.ttf";
$fontSize = 14;
  //text location
$x = 7;
$y = 20;
$fontRotation = 0;
$str = "Your IP Address is $_SERVER[REMOTE_ADDR]";
  //$str = "Your browser is $_SERVER[HTTP_USER_AGENT]";
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);
$x = 5;
$y = 18;
$color = imagecolorallocate($image, 255, 255, 255);       
$fontRotation = 0;
$str = "Your IP Address is $_SERVER[REMOTE_ADDR]";
  //$str = "Your browser is $_SERVER[HTTP_USER_AGENT]";
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);

imagettftext($image, 14, 0, 572, 18, imagecolorallocate($image, 0, 0, 0), getcwd()."/Capture-it.ttf", $hits);
imagettftext($image, 14, 0, 570, 16, imagecolorallocate($image, 255, 255, 255), getcwd()."/Capture-it.ttf", $hits);
   
imagettftext($image, 14, 0, 7, 147, imagecolorallocate($image, 0, 0, 0), getcwd()."/Capture-it.ttf", $time);
imagettftext($image, 14, 0, 5, 145, imagecolorallocate($image, 255, 255, 255), getcwd()."/Capture-it.ttf", $time);

// Because Music Won't Play Itself
$strnot = "Because Music Won't Play Itself";
imagettftext($image, 24, 0, 74, 80, imagecolorallocate($image, 0, 0, 0), getcwd()."/cowboy.ttf", $strnot);
imagettftext($image, 24, 0, 72, 78, imagecolorallocate($image, 255, 255, 255), getcwd()."/cowboy.ttf", $strnot);


$strwww = "Daz-clouds.ddns.net";
imagettftext($image, 14, 0, 371, 136, imagecolorallocate($image, 30, 30, 30), getcwd()."/Capture-it.ttf", $strwww);
$strwww = "Daz-clouds.ddns.net";
imagettftext($image, 14, 0, 370, 135, imagecolorallocate($image, 255, 255, 255), getcwd()."/Capture-it.ttf", $strwww);
$strtag = "A place to learn to DJ for free";
imagettftext($image, 8, 0, 377, 146, imagecolorallocate($image, 30, 30, 30), getcwd()."/Capture-it.ttf", $strtag);
$strtag = "A place to learn to DJ for free";
imagettftext($image, 8, 0, 376, 145, imagecolorallocate($image, 255, 255, 255), getcwd()."/Capture-it.ttf", $strtag);
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT");
header("Pragma: no-cache");
imagepng($image);
imagepng($image);
imagedestroy($image);
exit();



    //If the user is playing a music file...
playing:
$imageList = array("zombie1.png","zombie2.png","zombie3.png","zombie4.png","zombie5.png","zombie6.png","zombie7.png","zombie8.png","zombie9.png","zombie10.png","zombie11.png","zombie12.png","zombie13.png","zombie14.png","zombie15.png","zombie16.png","zombie17.png","zombie18.png","zombie19.png","zombie20.png","zombie21.png");
$image = imagecreatefrompng($imageList[rand(1,count($imageList))-1]);
$end = imagealphablending($image, false);
$save = imagesavealpha($image, true);
header("Content-type: image/png"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT"); 
header("Pragma: no-cache"); 
     //Get the cover art
$coverart = "http://".$server."/rest/getCoverArt.view?u=".$admin."&p=".$adminpass."&v=1.5.0&c=signature&id=".$second_gen['coverArt']."&size=150";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $coverart);
curl_setopt ($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HEADER, false);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
$rawdata = curl_exec($ch);
$image2 = imagecreatefromstring($rawdata);
curl_close($ch);
//text colour
// this part is to create the drop shadow
$color = imagecolorallocate($image, 0, 0, 0);
$font = getcwd()."/aliee13.ttf";
$fontSize = 10;
$fontRotation = -0;
$x = 156;
$y = 98;
$end = imagealphablending($image, true);
$str = "Zombie Slayin' while listening to\nArtist: ".$second_gen['artist']."\nTitle: ".$second_gen['title']."\nAlbum: ".$second_gen['album'];
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);
imagettftext($image, 12, 0, 152, 282, imagecolorallocate($image, 0, 0, 0), getcwd()."/aliee13.ttf", $time);
$strwww = "www.Mess-Hall.co.uk";
imagettftext($image, 16, 0, 173, 22, imagecolorallocate($image, 0 ,0 ,0), getcwd()."/aliee13.ttf", $strwww);
$strtag = "A Small Review of Almost Everything";
imagettftext($image, 10, 0, 165, 34, imagecolorallocate($image, 0, 0, 0), getcwd()."/aliee13.ttf", $strtag);
// End of drop shadow

//text colour
$color = imagecolorallocate($image, 255, 255, 255);
$font = getcwd()."/aliee13.ttf";
$fontSize = 10;
$fontRotation = -0;
$x = 154;
$y = 96;
// $image = imagealphablending($str, true);
$end = imagealphablending($image, true);
$str = "Zombie Slayin' while listening to\nArtist: ".$second_gen['artist']."\nTitle: ".$second_gen['title']."\nAlbum: ".$second_gen['album'];
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);
imagettftext($image, 14, 0, 572, 18, imagecolorallocate($image, 0, 0, 0), getcwd()."/Capture-it.ttf", $hits);
imagettftext($image, 14, 0, 570, 16, imagecolorallocate($image, 255, 255, 255), getcwd()."/Capture-it.ttf", $hits);
imagettftext($image, 12, 0, 150, 280, imagecolorallocate($image, 255, 255, 255), getcwd()."/aliee13.ttf", $time);
$strwww = "www.Mess-Hall.co.uk";
imagettftext($image, 16, 0, 169, 19, imagecolorallocate($image, 255, 255, 255), getcwd()."/aliee13.ttf", $strwww);
$strtag = "A Small Review of Almost Everything";
imagettftext($image, 10, 0, 162, 31, imagecolorallocate($image, 255, 255, 255), getcwd()."/aliee13.ttf", $strtag);
// End of drop shadow test

    //Cover art location
imagecopy($image, $image2, 2, 2, 0, 0, 145, 145);
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT");
header("Pragma: no-cache");
imagepng($image);
imagedestroy($image);
exit();


     //If the user is playing a VIDEO file...
watching:     
$imageList = array("graveyard.png","pushthebutton.png","worldmap.png","record.png","fantasy.png","couch.png","tron.png","eye.png","dancer.png","hifi.png","mask.png","storm.png");
$image = imagecreatefrompng($imageList[rand(1,count($imageList))-1]);
$color = imagecolorallocate($image, 255, 255, 255);
$end = imagealphablending($image, false);
$save = imagesavealpha($image, true);
$font = getcwd()."Capture-it.ttf";
$fontSize = 12;
$x = 10;
$y = 55;
$str = "Now Watching\n".$second_gen['title'];
imagealphablending($image, false);
imagesavealpha($image, true);
header("Content-type: image/png"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT"); 
header("Pragma: no-cache"); 
imagepng($image);
imagedestroy($image);
exit();

    //If the server is offline (404)...
offline:
$image = imagecreatefrompng("graveyard1.png");
$color = imagecolorallocate($image, 255, 255, 255);
$font = getcwd()."Capture-it.ttf";
$fontSize = 16;
$fontRotation = -7;
$x = 160;
$y = 65;
$str = "My server seems to be down...";
imagettftext($image, $fontSize, $fontRotation, $x, $y, $color, $font, $str);
imagettftext($image, 12, 0, 65, 295, imagecolorallocate($image, 230, 49, 150), getcwd()."/aliee13.ttf", $time);
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 19 Jan 1994 05:00:00 GMT");
header("Pragma: no-cache");
imagepng($image);
imagedestroy($image);exit();
exit();


?>


I think the problem lies with with this:
Code: Select all
    //If the server is online, check what the monitored user is listening or watching, and jump to the right code...
foreach($xml->children()->children() as $second_gen) {
$math = floor($second_gen['duration']/60);
if($second_gen['username']==$user and $second_gen['minutesAgo']<=$math) {
if($second_gen['isVideo']=='false') {
goto playing;
}
//else{
//goto watching;
//}
}
}

For some reason, the code isn't detecting that I'm playing a song, so it just shows a random image with the default text, see my signature below.

TIA.
Daz.
Image
User avatar
dazbobaby
 
Posts: 69
Joined: Tue Dec 06, 2011 12:29 pm

Re: Signature code help

Postby dazbobaby » Thu Sep 30, 2021 3:00 pm

I've sorted it, it was originally written for PHP 5, we're now 10 years on and so one tiny change created a syntax error and threw it off completely.
Image
User avatar
dazbobaby
 
Posts: 69
Joined: Tue Dec 06, 2011 12:29 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 8 guests