Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $url = 'http://199.19.105.66/asstats-xml.xsl';
- $db_file = './playlist.history';
- $fontFile = './LCD.TTF';
- $xmlData = file_get_contents($url);
- $titles = array();
- $ntitles = array();
- $charWidth = 10;
- $lineWidth = 0;
- $boxWidth = 0;
- $lineHeight = 20;
- $boxHeight = 0;
- $boxPad = 10;
- if ($xmlData != "") {
- if (preg_match_all('@<stitle>(.+?)</stitle>@is', $xmlData, $ntitles)) {
- if (!empty($ntitles[1])) {
- foreach ($ntitles[1] as $title) {
- $titles[] = trim($title);
- }
- }
- } else {
- $titles[] = 'No songs are being played currently.';
- }
- } else {
- $titles[] = 'Nope';
- }
- foreach ($titles as $title) {
- $boxHeight += $lineHeight;
- $lineWidth = $charWidth * strlen($title);
- if ($boxWidth < $lineWidth) {
- $boxWidth = $lineWidth;
- }
- }
- $boxWidth += $boxPad * 2;
- $boxHeight += $boxPad * 2;
- $image = imagecreatetruecolor($boxWidth, $boxHeight);
- $bgColor = imagecolorallocate($image, 51, 51, 51);
- imagefilledrectangle($image, 0, 0, $boxWidth, $boxHeight, $bgColor);
- $textColor = imagecolorallocate($image, 255, 255, 255);
- $i = 0;
- foreach ($titles as $title) {
- imagettftext($image, 12, 0, $boxPad, $lineHeight * $i + $boxPad * 2, $textColor, $fontFile, '* ' . $title);
- $i++;
- }
- //print_r($titles);
- header('Content-type: image/png');
- imagepng($image);
- imagedestroy($image);
- file_put_contents($db_file, implode("\r\n " . date('H:i:s A d/m/Y') . ' ', $titles), FILE_APPEND);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment