format(); if ($playlist->has_access()) { $playlist->delete_track($_REQUEST['track_id']); // This could have performance issues $playlist->regenerate_track_numbers(); } $object_ids = $playlist->get_items(); ob_start(); $browse = new Browse(); $browse->set_type('playlist_song'); $browse->add_supplemental_object('playlist',$playlist->id); $browse->save_objects($object_ids); $browse->show_objects($object_ids); $browse->store(); $results[$browse->get_content_div()] = ob_get_clean(); break; case 'append_item': // Only song item are supported with playlists debug_event('playlist', 'Appending items to playlist {'.$_REQUEST['playlist_id'].'}...', '5'); if (!isset($_REQUEST['playlist_id']) || empty($_REQUEST['playlist_id'])) { if (!Access::check('interface','25')) { debug_event('DENIED','Error:' . $GLOBALS['user']->username . ' does not have user access, unable to create playlist','1'); break; } $name = $GLOBALS['user']->username . ' - ' . date("Y-m-d H:i:s",time()); $playlist_id = Playlist::create($name, 'private'); if (!$playlist_id) { break; } $playlist = new Playlist($playlist_id); } else { $playlist = new Playlist($_REQUEST['playlist_id']); } if (!$playlist->has_access()) { break; } $songs = array(); $item_id = $_REQUEST['item_id']; switch ($_REQUEST['item_type']) { case 'smartplaylist': $smartplaylist = new Search($item_id, 'song'); $items = $playlist->get_items(); foreach ($items as $item) { $songs[] = $item['object_id']; } break; case 'album': debug_event('playlist', 'Adding all songs of album(s) {'.$item_id.'}...', '5'); $albums_array = explode(',', $item_id); foreach ($albums_array as $a) { $album = new Album($a); $asongs = $album->get_songs(); foreach ($asongs as $song_id) { $songs[] = $song_id; } } break; case 'artist': debug_event('playlist', 'Adding all songs of artist {'.$item_id.'}...', '5'); $artist = new Artist($item_id); $songs[] = $artist->get_songs(); break; case 'song_preview': case 'song': debug_event('playlist', 'Adding song {'.$item_id.'}...', '5'); $songs = explode(',', $item_id); break; case 'playlist': $pl = new Playlist($item_id); $songs = $pl->get_songs(); break; default: debug_event('playlist', 'Adding all songs of current playlist...', '5'); $objects = $GLOBALS['user']->playlist->get_items(); foreach ($objects as $object_data) { $type = array_shift($object_data); if ($type == 'song') { $songs[] = array_shift($object_data); } } break; } if (count($songs) > 0) { Ajax::set_include_override(true); $playlist->add_songs($songs, true); /*$playlist->format(); $object_ids = $playlist->get_items(); ob_start(); require_once AmpConfig::get('prefix') . '/templates/show_playlist.inc.php'; $results['content'] = ob_get_contents(); ob_end_clean();*/ debug_event('playlist', 'Items added successfully!', '5'); ob_start(); display_notification(T_('Added to playlist')); $results['rfc3514'] = ob_get_clean(); } else { debug_event('playlist', 'No item to add. Aborting...', '5'); } break; default: $results['rfc3514'] = '0x1'; break; } echo xoutput_from_array($results);