\n";
$sql = "SELECT `id`, `name`, `prefix`, `disk` FROM `album` ORDER BY `name`";
$db_results = Dba::read($sql);
while ($r = Dba::fetch_assoc($db_results)) {
$selected = '';
$album_name = trim($r['prefix'] . " " . $r['name']);
if ($r['disk'] >= 1) {
$album_name .= ' [Disk ' . $r['disk'] . ']';
}
if ($r['id'] == $album_id) {
$selected = "selected=\"selected\"";
}
echo "\t\n";
} // end while
if ($allow_add) {
// Append additional option to the end with value=-1
echo "\t\n";
}
echo "\n";
} // show_album_select
static $artist_id_cnt = 0;
/**
* show_artist_select
* This is the same as show_album_select except it's *gasp* for artists! How
* inventive!
*/
function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id=0)
{
// Generate key to use for HTML element ID
if ($song_id) {
$key = "artist_select_$song_id";
} else {
$key = "artist_select_c" . ++$artist_id_cnt;
}
echo "\n";
} // show_artist_select
/**
* show_catalog_select
* Yet another one of these buggers. this shows a drop down of all of your
* catalogs.
*/
function show_catalog_select($name='catalog',$catalog_id=0,$style='')
{
echo "\n";
} // show_catalog_select
/**
* show_user_select
* This one is for users! shows a select/option statement so you can pick a user
* to blame
*/
function show_user_select($name,$selected='',$style='')
{
echo "\n";
} // show_user_select
/**
* show_playlist_select
* This one is for playlists!
*/
function show_playlist_select($name,$selected='',$style='')
{
echo "\n";
} // show_playlist_select
function xoutput_headers()
{
$output = $_REQUEST['xoutput'] ?: 'xml';
if ($output == 'xml') {
header("Content-type: text/xml; charset=" . AmpConfig::get('site_charset'));
header("Content-Disposition: attachment; filename=ajax.xml");
} else {
header("Content-type: application/json; charset=" . AmpConfig::get('site_charset'));
}
header("Expires: Tuesday, 27 Mar 1984 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
}
function xoutput_from_array($array, $callback = false, $type = '')
{
$output = $_REQUEST['xoutput'] ?: 'xml';
if ($output == 'xml') {
return xml_from_array($array, $callback, $type);
} elseif ($output == 'raw') {
$outputnode = $_REQUEST['xoutputnode'];
return $array[$outputnode];
} else {
return json_from_array($array, $callback, $type);
}
}
// FIXME: This should probably go in XML_Data
/**
* xml_from_array
* This takes a one dimensional array and creates a XML document from it. For
* use primarily by the ajax mojo.
*/
function xml_from_array($array, $callback = false, $type = '')
{
$string = '';
// If we weren't passed an array then return
if (!is_array($array)) { return $string; }
// The type is used for the different XML docs we pass
switch ($type) {
case 'itunes':
foreach ($array as $key=>$value) {
if (is_array($value)) {
$value = xoutput_from_array($value,1,$type);
$string .= "\t\t<$key>\n$value\t\t$key>\n";
} else {
if ($key == "key") {
$string .= "\t\t<$key>$value$key>\n";
} elseif (is_int($value)) {
$string .= "\t\t\t$key$value\n";
} elseif ($key == "Date Added") {
$string .= "\t\t\t$key$value\n";
} elseif (is_string($value)) {
/* We need to escape the value */
$string .= "\t\t\t$key\n";
}
}
} // end foreach
return $string;
break;
case 'xspf':
foreach ($array as $key=>$value) {
if (is_array($value)) {
$value = xoutput_from_array($value,1,$type);
$string .= "\t\t<$key>\n$value\t\t$key>\n";
} else {
if ($key == "key") {
$string .= "\t\t<$key>$value$key>\n";
} elseif (is_numeric($value)) {
$string .= "\t\t\t<$key>$value$key>\n";
} elseif (is_string($value)) {
/* We need to escape the value */
$string .= "\t\t\t<$key>$key>\n";
}
}
} // end foreach
return $string;
break;
default:
foreach ($array as $key => $value) {
// No numeric keys
if (is_numeric($key)) {
$key = 'item';
}
if (is_array($value)) {
// Call ourself
$value = xoutput_from_array($value, true);
$string .= "\t$value\n";
} else {
/* We need to escape the value */
$string .= "\t\n";
}
// end foreach elements
}
if (!$callback) {
$string = '' .
"\n\n" . $string . "\n";
}
return UI::clean_utf8($string);
break;
}
} // xml_from_array
function json_from_array($array, $callback = false, $type = '')
{
return json_encode($array);
}
/**
* xml_get_header
* This takes the type and returns the correct xml header
*/
function xml_get_header($type)
{
switch ($type) {
case 'itunes':
$header = "\n" .
"\n" .
"\n" .
"\n" .
" Major Version1\n" .
" Minor Version1\n" .
" Application Version7.0.2\n" .
" Features1\n" .
" Show Content Ratings\n" .
" Tracks\n" .
" \n";
return $header;
break;
case 'xspf':
$header = "\n" .
"";
"\n ".
"Ampache XSPF Playlist\n" .
"" . AmpConfig::get('site_title') . "\n" .
"" . AmpConfig::get('site_title') . "\n" .
"". AmpConfig::get('web_path') ."\n" .
"\n\n\n\n";
return $header;
break;
default:
$header = "\n";
return $header;
break;
}
} //xml_get_header
/**
* xml_get_footer
* This takes the type and returns the correct xml footer
*/
function xml_get_footer($type)
{
switch ($type) {
case 'itunes':
$footer = " \n" .
"\n" .
"\n";
return $footer;
break;
case 'xspf':
$footer = " \n" .
"\n";
return $footer;
break;
default:
break;
}
} // xml_get_footer
/**
* toggle_visible
* This is identical to the javascript command that it actually calls
*/
function toggle_visible($element)
{
echo '\n";
} // toggle_visible
/**
* print_bool
* This function takes a boolean value and then prints out a friendly text
* message.
*/
function print_bool($value)
{
if ($value) {
$string = '' . T_('On') . '';
} else {
$string = '' . T_('Off') . '';
}
return $string;
} // print_bool
/**
* show_now_playing
* This shows the now playing templates and does some garbage collecion
* this should really be somewhere else
*/
function show_now_playing()
{
Session::gc();
Stream::gc_now_playing();
$web_path = AmpConfig::get('web_path');
$results = Stream::get_now_playing();
require_once AmpConfig::get('prefix') . '/templates/show_now_playing.inc.php';
} // show_now_playing