1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-05 10:49:37 +02:00

Finish moving stuff out of doc into class, still needs more work to deal with Version as well as variable response (JSON)

This commit is contained in:
Karl 'vollmerk' Vollmer 2009-11-23 14:54:19 +00:00
parent fe4585bdfe
commit ef21e122d1
2 changed files with 362 additions and 249 deletions

View file

@ -89,247 +89,6 @@ foreach ($methods as $method) {
} // end foreach methods in API
switch ($_REQUEST['action']) {
case 'album_songs':
$album = new Album($_REQUEST['filter']);
$songs = $album->get_songs();
// Set the offset
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
ob_end_clean();
echo xmlData::songs($songs);
break;
case 'tags':
Browse::reset_filters();
Browse::set_type('tag');
Browse::set_sort('name','ASC');
$method = $_REQUEST['exact'] ? 'exact_match' : 'alpha_match';
Api::set_filter($method,$_REQUEST['filter']);
$tags = Browse::get_objects();
// Set the offset
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
ob_end_clean();
echo xmlData::tags($tags);
break;
case 'tag':
$uid = scrub_in($_REQUEST['filter']);
ob_end_clean();
echo xmlData::tags(array($uid));
break;
case 'tag_artists':
$artists = Tag::get_tag_objects('artist',$_REQUEST['filter']);
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
ob_end_clean();
echo xmlData::artists($artists);
break;
case 'tag_albums':
$albums = Tag::get_tag_objects('album',$_REQUEST['filter']);
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
ob_end_clean();
echo xmlData::albums($albums);
break;
case 'tag_songs':
$songs = Tag::get_tag_objects('song',$_REQUEST['filter']);
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
ob_end_clean();
echo xmlData::songs($songs);
break;
case 'songs':
Browse::reset_filters();
Browse::set_type('song');
Browse::set_sort('title','ASC');
$method = $_REQUEST['exact'] ? 'exact_match' : 'alpha_match';
Api::set_filter($method,$_REQUEST['filter']);
Api::set_filter('add',$_REQUEST['add']);
Api::set_filter('update',$_REQUEST['update']);
$songs = Browse::get_objects();
// Set the offset
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
ob_end_clean();
echo xmlData::songs($songs);
break;
case 'song':
$uid = scrub_in($_REQUEST['filter']);
ob_end_clean();
echo xmlData::songs(array($uid));
break;
case 'url_to_song':
// Don't scrub in we need to give her raw and juicy to the function
$url = $_REQUEST['url'];
$song_id = Song::parse_song_url($url);
ob_end_clean();
echo xmlData::songs(array($song_id));
break;
case 'playlists':
Browse::reset_filters();
Browse::set_type('playlist');
Browse::set_sort('name','ASC');
$method = $_REQUEST['exact'] ? 'exact_match' : 'alpha_match';
Api::set_filter($method,$_REQUEST['filter']);
$playlist_ids = Browse::get_objects();
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
ob_end_clean();
echo xmlData::playlists($playlist_ids);
break;
case 'playlist':
$uid = scrub_in($_REQUEST['filter']);
ob_end_clean();
echo xmlData::playlists(array($uid));
break;
case 'playlist_songs':
$playlist = new Playlist($_REQUEST['filter']);
$items = $playlist->get_items();
foreach ($items as $object) {
if ($object['type'] == 'song') {
$songs[] = $object['object_id'];
}
} // end foreach
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
ob_end_clean();
echo xmlData::songs($songs);
break;
case 'search_songs':
$array['s_all'] = $_REQUEST['filter'];
ob_end_clean();
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
//WARNING!!! This is a horrible hack that has to be here because
//Run search references these variables, ooh the huge manatee
unset($_REQUEST['limit'],$_REQUEST['offset']);
$results = run_search($array);
echo xmlData::songs($results);
break;
case 'videos':
Browse::reset_filters();
Browse::set_type('video');
Browse::set_sort('title','ASC');
$method = $_REQUEST['exact'] ? 'exact_match' : 'alpha_match';
Api::set_filter($method,$_REQUEST['filter']);
$video_ids = Browse::get_objects();
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
echo xmlData::videos($video_ids);
break;
case 'video':
$video_id = scrub_in($_REQUEST['filter']);
echo xmlData::videos(array($video_id));
break;
case 'localplay':
// Load their localplay instance
$localplay = new Localplay(Config::get('localplay_controller'));
$localplay->connect();
switch ($_REQUEST['command']) {
case 'next':
case 'prev':
case 'play':
case 'stop':
$result_status = $localplay->$_REQUEST['command']();
$xml_array = array('localplay'=>array('command'=>array($_REQUEST['command']=>make_bool($result_status))));
echo xmlData::keyed_array($xml_array);
break;
default:
// They are doing it wrong
echo xmlData::error('405',_('Invalid Request'));
break;
} // end switch on command
break;
case 'democratic':
// Load up democratic information
$democratic = Democratic::get_current_playlist();
$democratic->set_parent();
switch ($_REQUEST['method']) {
case 'vote':
$type = 'song';
$media = new $type($_REQUEST['oid']);
if (!$media->id) {
echo xmlData::error('400',_('Media Object Invalid or Not Specified'));
break;
}
$democratic->vote(array(array('song',$media->id)));
// If everything was ok
$xml_array = array('action'=>$_REQUEST['action'],'method'=>$_REQUEST['method'],'result'=>true);
echo xmlData::keyed_array($xml_array);
break;
case 'devote':
$type = 'song';
$media = new $type($_REQUEST['oid']);
if (!$media->id) {
echo xmlData::error('400',_('Media Object Invalid or Not Specified'));
}
$uid = $democratic->get_uid_from_object_id($media->id,$type);
$democratic->remove_vote($uid);
// Everything was ok
$xml_array = array('action'=>$_REQUEST['action'],'method'=>$_REQUEST['method'],'result'=>true);
echo xmlData::keyed_array($xml_array);
break;
case 'playlist':
$objects = $democratic->get_items();
Song::build_cache($democratic->object_ids);
Democratic::build_vote_cache($democratic->vote_ids);
xmlData::democratic($objects);
break;
case 'play':
$url = $democratic->play_url();
$xml_array = array('url'=>$url);
echo xmlData::keyed_array($xml_array);
break;
default:
echo xmlData::error('405',_('Invalid Request'));
break;
} // switch on method
break;
default:
ob_end_clean();
echo xmlData::error('405',_('Invalid Request'));
break;
} // end switch action
?>
// If we manage to get here, we still need to hand out an XML document
ob_end_clean();
echo xmlData::error('405',_('Invalid Request'));