. * */ //Last Edit: 15:56 14.06.2009 // added date index to getAnnouncement // added 1 second timeout to getAnnouncement // added author and url (this time for real) to announcement indexes /////// -- CONFIG STUFF -- /////// // // Steam Group RSS file define("RSS", "changeme"); // // Shoutcast Password? define("PASSWORD", "changeme"); // // Shoutcast Port? define("PORT", 8000); // // Shoutcast Server? define("SHOUTCAST", "changeme"); // /////// -- END CONFIG -- /////// // // getAnnouncement returns an array of the last Steam announcement, split into the following indexes: // // title - The title of the announcement // content - The message of the announcement // author - The poster of the announcement // url - The URL linking to the announcement // date - Publication date // // getShoutcast retuns an array with stream info, split into the following indexes: // // status - Whether or not there is a DJ (can be either 1 or 0) // listeners - Number of the current listeners // maxlisteners - Number of max. listeners set by the Server // dj - The current DJ (That is the part after the colon in the stream title) // song - The current song // bitrate - The bitrate at which the stream is broadcasted // peaklisteners - The highested numbers of listeners tuned in at the same time // history - The song history, which itself is an array containing the last 9 songs played, starting at 0. // The songs themselves are split into playedat and title. So for example, $sc['history'][0]['title'] // would be the name of the song played before the current one. // //////////////////////////////// function getAnnouncement() { $ctx = stream_context_create(array('http' => array('timeout' => 1))); $xml = file_get_contents(RSS, 0, $ctx); if (!$xml) return false; $xmlparser = xml_parser_create(); xml_parser_set_option($xmlparser, XML_OPTION_SKIP_WHITE, true); if (!xml_parse_into_struct($xmlparser, $xml, $values, $indexes)) return false; xml_parser_free($xmlparser); $pos = strrpos($values[$indexes['DESCRIPTION'][1]]['value'], ' - '); $announcement = array( 'title' => $values[$indexes['TITLE'][1]]['value'], 'content' => substr($values[$indexes['DESCRIPTION'][1]]['value'], 0, $pos), 'author' => substr($values[$indexes['DESCRIPTION'][1]]['value'], $pos + 3), 'url' => $values[$indexes['LINK'][1]]['value'], 'date' => $values[$indexes['PUBDATE'][0]]['value'] ); return $announcement; } function getShoutcast() { $fp = fsockopen(SHOUTCAST, PORT, $errno, $errstr, 10); if (!$fp) return false; else { fputs($fp, "GET /admin.cgi?pass=".PASSWORD."&mode=viewxml HTTP/1.0\r\n"); fputs($fp, "User-Agent: Mozilla\r\n\r\n"); $xml = ''; while (!feof($fp)) { $xml .= fgets($fp, 512); } fclose($fp); if (stristr($xml, 'HTTP/1.0 200 OK') == true) { $xml = trim(substr($xml, 42)); } else { return false; } $xmlparser = xml_parser_create(); if (!xml_parse_into_struct($xmlparser, $xml, $values, $indexes)) { return false; } xml_parser_free($xmlparser); $dj = ($values[$indexes['SERVERTITLE'][0]]['value']); $dj = explode(': ', $dj, 2); for($i = 1; $i < sizeof($indexes['TITLE']); $i++) { $arrhistory[$i-1] = array( "playedat"=>$values[$indexes['PLAYEDAT'][$i]]['value'], "title"=>$values[$indexes['TITLE'][$i]]['value'] ); } $sc = array( 'status' => $values[$indexes['STREAMSTATUS'][0]]['value'], 'listeners' => $values[$indexes['CURRENTLISTENERS'][0]]['value'], 'maxlisteners' => $values[$indexes['MAXLISTENERS'][0]]['value'], 'dj' => $dj[1], 'song' => $values[$indexes['SONGTITLE'][0]]['value'], 'history' => $arrhistory, 'bitrate' => $values[$indexes['BITRATE'][0]]['value'], 'peaklisteners' => $values[$indexes['PEAKLISTENERS'][0]]['value'] ); return $sc; } } ?>