* 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ /** * Sub-Ajax page, requires AJAX_INCLUDE */ if (!defined('AJAX_INCLUDE')) { exit; } $democratic = Democratic::get_current_playlist(); $democratic->set_parent(); $show_browse = false; $results = array(); switch ($_REQUEST['action']) { case 'delete_vote': $democratic->remove_vote($_REQUEST['row_id']); $show_browse = true; break; case 'add_vote': $democratic->add_vote(array(array('object_type' => $_REQUEST['type'], 'object_id' => $_REQUEST['object_id']))); $show_browse = true; break; case 'delete': if (!$GLOBALS['user']->has_access('75')) { echo xoutput_from_array(array('rfc3514' => '0x1'));
/** * create_democratic * * This 'votes' on the songs; it inserts them into a tmp_playlist with user * set to -1. */ public function create_democratic() { $democratic = Democratic::get_current_playlist(); $democratic->set_parent(); $items = array(); foreach ($this->urls as $url) { $data = Stream_URL::parse($url->url); $items[] = array($data['type'], $data['id']); } $democratic->add_vote($items); }
/** * 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 }
/** * democratic * * This handles creating an xml document for democratic items, this can be a little complicated * due to the votes and all of that * * @param array $object_ids Object IDs * @return string return xml */ public static function democratic($object_ids = array()) { if (!is_array($object_ids)) { $object_ids = array(); } $democratic = Democratic::get_current_playlist(); $string = ''; foreach ($object_ids as $row_id => $data) { $song = new $data['object_type']($data['object_id']); $song->format(); //FIXME: This is duplicate code and so wrong, functions need to be improved $tag = new Tag($song->tags['0']); $song->genre = $tag->id; $song->f_genre = $tag->name; $tag_string = self::tags_string($song->tags); $rating = new Rating($song->id, 'song'); $art_url = Art::url($song->album, 'album', $_REQUEST['auth']); $string .= "<song id=\"" . $song->id . "\">\n" . "\t<title><![CDATA[" . $song->title . "]]></title>\n" . "\t<artist id=\"" . $song->artist . "\"><![CDATA[" . $song->f_artist_full . "]]></artist>\n" . "\t<album id=\"" . $song->album . "\"><![CDATA[" . $song->f_album_full . "]]></album>\n" . "\t<genre id=\"" . $song->genre . "\"><![CDATA[" . $song->f_genre . "]]></genre>\n" . $tag_string . "\t<track>" . $song->track . "</track>\n" . "\t<time>" . $song->time . "</time>\n" . "\t<mime>" . $song->mime . "</mime>\n" . "\t<url><![CDATA[" . Song::play_url($song->id, '', 'api') . "]]></url>\n" . "\t<size>" . $song->size . "</size>\n" . "\t<art><![CDATA[" . $art_url . "]]></art>\n" . "\t<preciserating>" . $rating->get_user_rating() . "</preciserating>\n" . "\t<rating>" . $rating->get_user_rating() . "</rating>\n" . "\t<averagerating>" . $rating->get_average_rating() . "</averagerating>\n" . "\t<vote>" . $democratic->get_vote($row_id) . "</vote>\n" . "</song>\n"; } // end foreach $final = self::_header() . $string . self::_footer(); return $final; }