~extremepopcorn/dhlib/dhlib_ep

« back to all changes in this revision

Viewing changes to restricted/app-fortress/fortress/web/radio.php

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
        include 'std.inc.php';
 
3
        include 'radio_data.php';
 
4
        
 
5
        setup_xml_response();
 
6
        
 
7
        //don't have many songs now, so allow them to play more often
 
8
        $remember_song_count = 10;
 
9
        
 
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 );
 
17
        
 
18
        //remove those already played
 
19
        $remain_comm = array_diff( $comm, $tokens );
 
20
        $remain_demo = array_diff( $demo, $tokens );
 
21
        
 
22
        //restore empty lists
 
23
        if( count( $remain_comm ) == 0 )        
 
24
                $remain_comm = $comm;
 
25
        if( count( $remain_demo ) == 0 )
 
26
                $remain_demo = $demo;
 
27
        
 
28
        //decide what kind to play next (alternative between comm/demo)
 
29
        if( count( $tokens ) > 0 ) 
 
30
        {
 
31
                $last = array_pop( array_slice( $tokens, -1, 1 ) );
 
32
                if( array_search( $last, $comm ) !== FALSE )
 
33
                        $selectfrom = $remain_demo;
 
34
                else
 
35
                        $selectfrom = $remain_comm;
 
36
        }
 
37
        else
 
38
                $selectfrom = $remain_comm;
 
39
                
 
40
        //choose a track at random
 
41
        $select = $selectfrom[ array_rand( $selectfrom ) ];
 
42
        $song = $songs[$select];
 
43
        
 
44
        //append to token so client must not keep track
 
45
        $tokens[] = $select;
 
46
        if( count( $tokens ) > $remember_song_count )   //remember only X songs?
 
47
                $tokens = array_slice( $tokens, -$remember_song_count );
 
48
        $tokenstr = implode( ',', $tokens );
 
49
        
 
50
        print <<<EOT
 
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>
 
58
EOT;
 
59
        
 
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" );
 
64
        }
 
65
        
 
66
        print( '</track>' );
 
67
?>