1) { //REMOVE empty Attributes if Value is valid if(!((isset($value['attributes'])) && (is_array($value['attributes']))) && (isset($value['value']))) $leaf["$key"] = $value['value']; else $leaf["$key"] = CompackTree($value); } else { $temp = $value[0]; //REMOVE empty Attributes if Value is valid if(isset($temp['attributes'])) { if(!is_array($temp['attributes']) && (isset($temp['value']))) $leaf["$key"] = $temp['value']; else $leaf["$key"] = CompackTree($temp); } else if(isset($temp['value'])) $leaf["$key"] = $temp['value']; else $leaf["$key"] = CompackTree($temp); } } else $leaf["$key"] = $value; } // while loop return $leaf; } function XMLToArray($data, $uppercase = 1) { $tree = GetXMLTree($data, $uppercase); return CompackTree($tree); } function XML2Array($data, $uppercase = 1) { return XMLToArray($data, $uppercase); } //XML handling routines function GetChildren($vals, &$i) { while($i < count($vals)) { switch ($vals[$i]['type']) { //case 'cdata': case 'complete' : if(isset($vals[$i]['attributes'])) { $value = array("attributes" => $vals[$i]['attributes'], "value" => $vals[$i]['value']); } else { $value = array("value" => $vals[$i]['value']); } $name = $vals[$i]['tag']; $children["$name"][] = $value; break; case 'open' : $siblings = GetChildren($vals, ++$i); if(isset($vals[$i]['attributes'])) { $siblings['attributes'] = $vals[$i]['attributes']; } $name = $vals[$i]['tag']; $children["$name"][] = $siblings; /* array_push($children, array("attributes" => $vals[$i]['attributes'], "children" => GetChildren($vals, ++$i)) ); */ break; case 'close' : return $children; break; default : echo "XML error, Unsupported tag type: " . $vals[$i]['type'] . "
"; } $i++; } return $children; } if (isset($_GET['songid'])) { $songid = $_GET['songid']; $host = $_SERVER['REMOTE_ADDR']; $request = 'GET /req/?songID=' . $songid . '&host=' . urlencode($host) . " HTTP/1.0\r\n\r\n"; $xmldata = ""; $fd = @fsockopen($sam_host, $sam_port, $errno, $errstr, 30); if(!empty($fd)) { fputs($fd, $request); $line= ""; while(!($line=="\r\n")) { $line = fgets($fd, 128); } // strip out the header while ($buffer = fgets($fd, 4096)) { $xmldata = $buffer; } fclose($fd); if (!empty($xmldata)) { $tree = XML2Array($xmldata); $request = Keys2Lower($tree["REQUEST"]); $code = $request["status"]["code"]; $message = $request["status"]["message"]; $requestid = $request["status"]["requestid"]; if (!empty($code)) { if ($code == 200) { $message = "Der Song wurde erfolgreich angefordert."; } } else { $message = "Invalid data returned!"; } } else { $message = "Invalid data returned!"; } } else { $message = "Unable to connect to SAM-Host. Station might be offline.
The error returned was $errstr ($errno)."; } } else { $message = 'Fehlerhafter Aufruf.'; } ?> Song-Anforderung