1<?php 2 3/* 4 * vim:set softtabstop=4 shiftwidth=4 expandtab: 5 * 6 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later) 7 * Copyright 2001 - 2020 Ampache.org 8 * 9 * This program is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU Affero General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Affero General Public License for more details. 18 * 19 * You should have received a copy of the GNU Affero General Public License 20 * along with this program. If not, see <https://www.gnu.org/licenses/>. 21 * 22 */ 23 24declare(strict_types=0); 25 26namespace Ampache\Module\Api\Method; 27 28use Ampache\Repository\Model\Playlist; 29use Ampache\Repository\Model\Search; 30use Ampache\Repository\Model\User; 31use Ampache\Module\Api\Api; 32use Ampache\Module\Api\Json_Data; 33use Ampache\Module\Api\Xml_Data; 34use Ampache\Module\Authorization\Access; 35use Ampache\Module\System\Session; 36 37/** 38 * Class PlaylistMethod 39 * @package Lib\ApiMethods 40 */ 41final class PlaylistMethod 42{ 43 private const ACTION = 'playlist'; 44 45 /** 46 * playlist 47 * MINIMUM_API_VERSION=380001 48 * 49 * This returns a single playlist 50 * 51 * @param array $input 52 * filter = (string) UID of playlist 53 * @return boolean 54 */ 55 public static function playlist(array $input) 56 { 57 if (!Api::check_parameter($input, array('filter'), self::ACTION)) { 58 return false; 59 } 60 $user = User::get_from_username(Session::username($input['auth'])); 61 $object_id = $input['filter']; 62 63 $playlist = ((int) $object_id === 0) 64 ? new Search((int) str_replace('smart_', '', $object_id), 'song', $user) 65 : new Playlist((int) $object_id); 66 if (!$playlist->id) { 67 /* HINT: Requested object string/id/type ("album", "myusername", "some song title", 1298376) */ 68 Api::error(sprintf(T_('Not Found: %s'), $object_id), '4704', self::ACTION, 'filter', $input['api_format']); 69 70 return false; 71 } 72 if (!$playlist->type == 'public' && (!$playlist->has_access($user->id) && !Access::check('interface', 100, $user->id))) { 73 Api::error(T_('Require: 100'), '4742', self::ACTION, 'account', $input['api_format']); 74 75 return false; 76 } 77 78 ob_end_clean(); 79 switch ($input['api_format']) { 80 case 'json': 81 echo Json_Data::playlists(array($object_id), $user->getId(), false, false); 82 break; 83 default: 84 echo Xml_Data::playlists(array($object_id), $user->getId()); 85 } 86 Session::extend($input['auth']); 87 88 return true; 89 } 90} 91