Add a dequeue image.
[adorno.git] / www / always.php
blob3e6d11a9266e8bff6d9ef123c17c5f07d745c121
1 <?php
2 /**
3 * @package adorno
4 * @author Andrew McMillan <andrew@mcmillan.net.nz>
5 * @copyright Morphoss Ltd <http://www.morphoss.com/>
6 * @license http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
7 */
9 if ( preg_match('{/always.php$}', $_SERVER['SCRIPT_NAME'] ) ) header('Location: index.php');
11 // Ensure the configuration starts out as an empty object.
12 $c = (object) array();
13 $c->script_start_time = microtime(true);
15 // Ditto for a few other global things
16 unset($session); unset($request); unset($dbconn); unset($_awl_dbconn); unset($include_properties);
18 // An ultra-simple exception handler to catch errors that occur
19 // before we get a more functional exception handler in place...
20 function early_exception_handler($e) {
21 echo "Uncaught early exception: ", $e->getMessage(), "\nAt line ", $e->getLine(), " of ", $e->getFile(), "\n";
23 $trace = array_reverse($e->getTrace());
24 foreach( $trace AS $k => $v ) {
25 printf( "=====================================================\n%s[%d] %s%s%s()\n", $v['file'], $v['line'], (isset($v['class'])?$v['class']:''), (isset($v['type'])?$v['type']:''), (isset($v['function'])?$v['function']:'') );
28 set_exception_handler('early_exception_handler');
31 $c->system_name = 'Adorno Headless Music Server';
32 $c->daemon_type = 'adorno';
34 error_log( "=============================================== $PHP_SELF" );
36 // Utilities
37 if ( ! @include_once('AWLUtilities.php') ) {
38 $try_paths = array(
39 '../../awl/inc'
40 , '/usr/share/awl/inc'
41 , '/usr/local/share/awl/inc'
43 foreach( $try_paths AS $awl_include_path ) {
44 if ( @file_exists($awl_include_path.'/AWLUtilities.php') ) {
45 set_include_path( $awl_include_path. PATH_SEPARATOR. get_include_path());
46 break;
49 if ( ! @include_once('AWLUtilities.php') ) {
50 echo "Could not find the AWL libraries. Are they installed? Check your include_path in php.ini!\n";
51 exit;
55 // Ensure that ../inc is in our included paths as early as possible
56 set_include_path( '../inc'. PATH_SEPARATOR. get_include_path());
59 /**
60 * We use @file_exists because things like open_basedir might noisily deny
61 * access which could break DAViCal completely by causing output to start
62 * too early.
64 if ( @file_exists('/etc/adorno/'.$_SERVER['SERVER_NAME'].'-conf.php') ) {
65 include('/etc/adorno/'.$_SERVER['SERVER_NAME'].'-conf.php');
67 else if ( @file_exists('/etc/adorno/config.php') ) {
68 include('/etc/adorno/config.php');
70 else if ( @file_exists('/usr/local/etc/adorno/'.$_SERVER['SERVER_NAME'].'-conf.php') ) {
71 include('/usr/local/etc/adorno/'.$_SERVER['SERVER_NAME'].'-conf.php');
73 else if ( @file_exists('/usr/local/etc/adorno/config.php') ) {
74 include('/usr/local/etc/adorno/config.php');
76 else if ( @file_exists('../config/config.php') ) {
77 include('../config/config.php');
79 else if ( @file_exists('config/config.php') ) {
80 include('config/config.php');
82 else {
83 include('adorno_configuration_missing.php');
84 exit;
87 if ( !isset($c->page_title) ) $c->page_title = $c->system_name;
90 param_to_global('altr','{^[A-Z#]$}');
91 param_to_global('lltr','{^[A-Z#]$}');
92 param_to_global('search','{^.*$}');
93 param_to_global('action','{^(pause|enqueue|remove|resume|next|clear|off|stop)$}');
94 param_to_global('submit','{^.*$}');
95 param_to_global('a','{^.*$}');
96 param_to_global('l','{^.*$}');
97 param_to_global('t','{^.*$}');
98 param_to_global( 'ltrtype', '{(artist|album|genre|stream)}', 'type' );
101 function build_url_params( $url_params = array() ) {
102 $std_params = array( 'ltrtype', 'altr', 'lltr', 'a', 'search' );
103 foreach( $std_params AS $p ) {
104 if ( !isset($url_params[$p]) && isset($GLOBALS[$p])
105 && ! ($p == 'ltrtype' && isset($url_params['type'])) ) {
106 $url_params[($p == 'ltrtype'?'type':$p)] = $GLOBALS[$p];
109 $params = array();
110 foreach( $url_params AS $k => $v ) {
111 $params[] = $k .'=' . rawurlencode($v);
113 $params = implode( $params, '&' );
114 if ( $params != '' ) $params = '?' . $params;
115 return $params;
119 $letter_get = ( "$altr" == "" ? "" : "&altr=$altr" ) . ( "$lltr" == "" ? "" : "&lltr=$lltr" );
120 if ( isset($search) && $search == '' ) $search = null;
121 if ( isset($search) ) $letter_get .= "&search=".urlencode($search);
124 function nice_track_name( $track ) {
125 $track = preg_replace( "#^/#", "", $track );
126 $track = preg_replace( "#^music/#", "", $track );
127 $track = preg_replace( "#^extra/#", "", $track );
128 $track = preg_replace( "#^Classified/#", "", $track );
129 $track = str_replace( "http://", "Stream/ ", $track );
130 $track = preg_replace( "#[.](mp3|ogg)$#i", "", $track );
131 $track = preg_replace( "#^/+#", "", $track );
132 $track = preg_replace( "#/+$#", "", $track );
133 $track = str_replace( "_", " ", $track );
134 $track = str_replace( "/", " &raquo; ", $track );
135 return $track;
138 include("daemonInterface.php");