/** * democratic * This is for controlling democratic play */ public static function democratic($input) { // Load up democratic information $democratic = Democratic::get_current_playlist(); $democratic->set_parent(); switch ($input['method']) { case 'vote': $type = 'song'; $media = new $type($input['oid']); if (!$media->id) { echo XML_Data::error('400', T_('Media Object Invalid or Not Specified')); break; } $democratic->add_vote(array(array('object_type' => 'song', 'object_id' => $media->id))); // If everything was ok $xml_array = array('action' => $input['action'], 'method' => $input['method'], 'result' => true); echo XML_Data::keyed_array($xml_array); break; case 'devote': $type = 'song'; $media = new $type($input['oid']); if (!$media->id) { echo XML_Data::error('400', T_('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' => $input['action'], 'method' => $input['method'], 'result' => true); echo XML_Data::keyed_array($xml_array); break; case 'playlist': $objects = $democratic->get_items(); Song::build_cache($democratic->object_ids); Democratic::build_vote_cache($democratic->vote_ids); XML_Data::democratic($objects); break; case 'play': $url = $democratic->play_url(); $xml_array = array('url' => $url); echo XML_Data::keyed_array($xml_array); break; default: echo XML_Data::error('405', T_('Invalid Request')); break; } // switch on method }
debug_event('Access Denied', 'Unauthorized access attempt to API [' . $_SERVER['REMOTE_ADDR'] . ']', '3'); ob_end_clean(); echo XML_Data::error('403', T_('Unauthorized access attempt to API - ACL Error')); exit; } if ($_REQUEST['action'] != 'handshake' and $_REQUEST['action'] != 'ping') { Session::extend($_REQUEST['auth']); $GLOBALS['user'] = User::get_from_username($username); } // Get the list of possible methods for the Ampache API $methods = get_class_methods('api'); // Define list of internal functions that should be skipped $internal_functions = array('set_filter'); // Recurse through them and see if we're calling one of them foreach ($methods as $method) { if (in_array($method, $internal_functions)) { continue; } // If the method is the same as the action being called // Then let's call this function! if ($_GET['action'] == $method) { call_user_func(array('api', $method), $_GET); // We only allow a single function to be called, and we assume it's cleaned up! exit; } } // end foreach methods in API // If we manage to get here, we still need to hand out an XML document ob_end_clean(); echo XML_Data::error('405', T_('Invalid Request'));
/** * rate * This rate a library item * @param array $input */ public static function rate($input) { ob_end_clean(); $type = $input['type']; $id = $input['id']; $rating = $input['rating']; if (!Core::is_library_item($type) || !$id) { echo XML_Data::error('401', T_('Wrong library item type.')); } else { $item = new $type($id); if (!$item->id) { echo XML_Data::error('404', T_('Library item not found.')); } else { $r = new Rating($id, $type); $r->set_rating($rating); echo XML_Data::single_string('success'); } } }