$media_ids = $playlist->get_random_items(); break; case 'random': $matchlist = array(); if ($_REQUEST['genre'][0] != '-1') { $matchlist['genre'] = $_REQUEST['genre']; } if ($_REQUEST['catalog'] != '-1') { $matchlist['catalog'] = $_REQUEST['catalog']; } /* Setup the options array */ $options = array('limit' => $_REQUEST['random'], 'random_type' => $_REQUEST['random_type'], 'size_limit' => $_REQUEST['size_limit']); $media_ids = get_random_songs($options, $matchlist); break; case 'democratic': $democratic = new Democratic($_REQUEST['democratic_id']); $urls = array($democratic->play_url()); break; case 'download': $media_ids[] = array('object_type' => 'song', 'object_id' => scrub_in($_REQUEST['song_id'])); break; case 'live_stream': $object = new Radio($_REQUEST['stream_id']); if ($object->name) { $media_ids[] = array('object_type' => 'radio', 'object_id' => scrub_in($_REQUEST['stream_id'])); } break; case 'album_preview': $songs = Song_preview::get_song_previews($_REQUEST['mbid']); foreach ($songs as $song) { if (!empty($song->file)) {
/** * Get media javascript parameters. * @param \playable_item $item * @param string $force_type * @return string */ public static function get_media_js_param($item, $force_type = '') { $js = array(); foreach (array('title', 'author') as $member) { if ($member == "author") { $kmember = "artist"; } else { $kmember = $member; } $js[$kmember] = $item->{$member}; } $url = $item->url; $types = self::get_types($item, $force_type); $media = null; $urlinfo = Stream_URL::parse($url); $url = $urlinfo['base_url']; if ($urlinfo['id'] && Core::is_media($urlinfo['type'])) { $media = new $urlinfo['type']($urlinfo['id']); } else { if ($urlinfo['id'] && $urlinfo['type'] == 'song_preview') { $media = new Song_Preview($urlinfo['id']); } else { if (isset($urlinfo['demo_id'])) { $democratic = new Democratic($urlinfo['demo_id']); if ($democratic->id) { $song_id = $democratic->get_next_object(); if ($song_id) { $media = new Song($song_id); } } } } } if ($media != null) { $media->format(); if ($urlinfo['type'] == 'song') { $js['artist_id'] = $media->artist; $js['album_id'] = $media->album; $js['replaygain_track_gain'] = $media->replaygain_track_gain; $js['replaygain_track_peak'] = $media->replaygain_track_peak; $js['replaygain_album_gain'] = $media->replaygain_album_gain; $js['replaygain_album_peak'] = $media->replaygain_album_peak; } $js['media_id'] = $media->id; if ($media->type != $types['real']) { $url .= '&transcode_to=' . $types['real']; } //$url .= "&content_length=required"; } $js['filetype'] = $types['player']; $js['url'] = $url; if ($urlinfo['type'] == 'song') { $js['poster'] = $item->image_url; } debug_event("webplayer.class.php", "Return get_media_js_param {" . json_encode($js) . "}", 5); return json_encode($js); }
$show_browse = true; break; case 'send_playlist': if (!Access::check('interface', '75')) { echo xoutput_from_array(array('rfc3514' => '0x1')); exit; } $_SESSION['iframe']['target'] = AmpConfig::get('web_path') . '/stream.php?action=democratic&democratic_id=' . scrub_out($_REQUEST['democratic_id']); $results['rfc3514'] = '<script type="text/javascript">' . Core::get_reloadutil() . '("' . $_SESSION['iframe']['target'] . '")</script>'; break; case 'clear_playlist': if (!Access::check('interface', '100')) { echo xoutput_from_array(array('rfc3514' => '0x1')); exit; } $democratic = new Democratic($_REQUEST['democratic_id']); $democratic->set_parent(); $democratic->clear(); $show_browse = true; break; default: $results['rfc3514'] = '0x1'; break; } // switch on action; if ($show_browse) { ob_start(); $object_ids = $democratic->get_items(); $browse = new Browse(); $browse->set_type('democratic'); $browse->set_static_content(false);
$playlist = new Stream_Playlist($oid); // Some rudimentary security if ($uid != $playlist->user) { UI::access_denied(); exit; } $playlist->generate_playlist($playlist_type, false); exit; } /** * If we've got a tmp playlist then get the * current song, and do any other crazyness * we need to */ if ($demo_id) { $democratic = new Democratic($demo_id); $democratic->set_parent(); // If there is a cooldown we need to make sure this song isn't a repeat if (!$democratic->cooldown) { /* This takes into account votes etc and removes the */ $oid = $democratic->get_next_object(); } else { // Pull history $song_cool_check = 0; $oid = $democratic->get_next_object($song_cool_check); $oids = $democratic->get_cool_songs(); while (in_array($oid, $oids)) { $song_cool_check++; $oid = $democratic->get_next_object($song_cool_check); if ($song_cool_check >= '5') { break;
/** * 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 }
<th class="cel_default"><?php echo T_('Default'); ?> </th> <th class="cel_vote_count"><?php echo T_('Songs'); ?> </th> <th class="cel_action"><?php echo T_('Action'); ?> </th> </tr> <?php foreach ($playlists as $democratic_id) { $democratic = new Democratic($democratic_id); $democratic->format(); $playlist = new Playlist($democratic->base_playlist); $playlist->format(); ?> <tr class="<?php echo UI::flip_class(); ?> "> <td><?php echo scrub_out($democratic->name); ?> </td> <td><?php echo $playlist->f_name_link; ?>
</th> <?php if (Access::check('interface', '100')) { ?> <th class="cel_admin"><?php echo T_('Admin'); ?> </th> <?php } ?> </tr> </thead> <tbody> <?php $democratic = Democratic::get_current_playlist(); $democratic->set_parent(); foreach ($object_ids as $item) { if (!is_array($item)) { $item = (array) $item; } $media = new $item['object_type']($item['object_id']); $media->format(); ?> <tr class="<?php echo UI::flip_class(); ?> "> <td class="cel_action"> <?php if ($democratic->has_vote($item['object_id'], $item['object_type'])) {
/** * 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); }
if (!Access::check('interface', '75')) { UI::access_denied(); break; } // Get all of the non-user playlists $playlists = Democratic::get_playlists(); require_once AmpConfig::get('prefix') . UI::find_template('show_manage_democratic.inc.php'); break; case 'show_playlist': default: $democratic = Democratic::get_current_playlist(); if (!$democratic->id) { require_once AmpConfig::get('prefix') . UI::find_template('show_democratic.inc.php'); break; } $democratic->set_parent(); $democratic->format(); require_once AmpConfig::get('prefix') . UI::find_template('show_democratic.inc.php'); $objects = $democratic->get_items(); Song::build_cache($democratic->object_ids); Democratic::build_vote_cache($democratic->vote_ids); $browse = new Browse(); $browse->set_type('democratic'); $browse->set_static_content(false); $browse->save_objects($objects); $browse->show_objects(); $browse->store(); break; } // end switch on action UI::show_footer();
/** * 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; }