3
include 'radio_data.php';
7
//don't have many songs now, so allow them to play more often
8
$remember_song_count = 10;
10
//use a token to prevent the songs playing multiple times and
11
//to alternate between commerical and theme songs
12
//FORMAT: token, token, ...
13
$tokenstr = get_request_def( 'token', '' );
14
//limit length, for input cleaning
15
$tokenstr = substr( $tokenstr, 0, 1000 );
16
$tokens = explode( ',', $tokenstr );
18
//remove those already played
19
$remain_comm = array_diff( $comm, $tokens );
20
$remain_demo = array_diff( $demo, $tokens );
23
if( count( $remain_comm ) == 0 )
25
if( count( $remain_demo ) == 0 )
28
//decide what kind to play next (alternative between comm/demo)
29
if( count( $tokens ) > 0 )
31
$last = array_pop( array_slice( $tokens, -1, 1 ) );
32
if( array_search( $last, $comm ) !== FALSE )
33
$selectfrom = $remain_demo;
35
$selectfrom = $remain_comm;
38
$selectfrom = $remain_comm;
40
//choose a track at random
41
$select = $selectfrom[ array_rand( $selectfrom ) ];
42
$song = $songs[$select];
44
//append to token so client must not keep track
46
if( count( $tokens ) > $remember_song_count ) //remember only X songs?
47
$tokens = array_slice( $tokens, -$remember_song_count );
48
$tokenstr = implode( ',', $tokens );
51
<track id="$select" token="$tokenstr">
52
<sound>${song['sound']}</sound>
53
<image>${song['image']}</image>
54
<about>${song['about']}</about>
55
<title>${song['title']}</title>
56
<album>${song['album']}</album>
57
<artist>${song['artist']}</artist>
60
foreach( $song['purchase'] as $p ) {
61
print( "<purchase name='" . htmlspecialchars( $p['name'], ENT_QUOTES )
62
. "' location='" . htmlspecialchars( $p['location'], ENT_QUOTES )
63
. "'>" . $p['link'] . "</purchase>\n" );