Added ability to gracefully fail the client if the connection to the server fails
<?php
/**
* Playlist displayer
*
* Greyhound - real web management for Amarok
* Copyright (C) 2008 Dan Fuhry
*
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
*/
function amarok_playlist($httpd, $socket)
{
global $theme, $playlist, $allowcontrol;
global $use_auth, $auth_data;
if ( $use_auth )
{
if ( !isset($_SERVER['PHP_AUTH_USER']) )
{
$httpd->header('WWW-Authenticate: basic');
$httpd->send_http_error($socket, 401, "A username and password are required to access this resource. Either you did not specify a username and password, or the supplied credentials were incorrect.");
return true;
}
if ( !isset($auth_data[$_SERVER['PHP_AUTH_USER']]) )
{
$httpd->header('WWW-Authenticate: basic');
$httpd->send_http_error($socket, 401, "A username and password are required to access this resource. Either you did not specify a username and password, or the supplied credentials were incorrect.");
return true;
}
else if ( $auth_data[$_SERVER['PHP_AUTH_USER']] !== $_SERVER['PHP_AUTH_PW'] )
{
$httpd->header('WWW-Authenticate: basic');
$httpd->send_http_error($socket, 401, "A username and password are required to access this resource. Either you did not specify a username and password, or the supplied credentials were incorrect.");
return true;
}
}
$iphone = ( ( strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') ||
strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') ||
strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') ||
isset($_GET['m']) )
&& !isset($_GET['f'])
);
$theme_id = ( $iphone ) ? 'iphone' : $theme;
$smarty = load_theme($theme_id);
$active = dcop_action('playlist', 'getActiveIndex');
$smarty->assign('theme', $theme_id);
$smarty->assign('playlist', $playlist);
$smarty->assign('active', $active);
$smarty->assign('scripts', array(
'ajax.js',
'domutils.js',
'volume.js',
'dom-drag.js',
'position.js'
));
$smarty->assign('allow_control', $allowcontrol);
$smarty->display('playlist.tpl');
}