1<?php 2/* 3 * vim:set softtabstop=4 shiftwidth=4 expandtab: 4 * 5 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later) 6 * Copyright 2001 - 2020 Ampache.org 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 * 21 */ 22 23declare(strict_types=0); 24 25namespace Ampache\Module\Application\Rss; 26 27use Ampache\Config\ConfigContainerInterface; 28use Ampache\Config\ConfigurationKeyEnum; 29use Ampache\Module\Application\ApplicationActionInterface; 30use Ampache\Module\Authorization\GuiGatekeeperInterface; 31use Ampache\Module\System\Core; 32use Ampache\Module\Util\AmpacheRss; 33use Psr\Http\Message\ResponseFactoryInterface; 34use Psr\Http\Message\ResponseInterface; 35use Psr\Http\Message\ServerRequestInterface; 36use Psr\Http\Message\StreamFactoryInterface; 37 38final class ShowAction implements ApplicationActionInterface 39{ 40 public const REQUEST_KEY = 'show'; 41 42 private ConfigContainerInterface $configContainer; 43 44 private ResponseFactoryInterface $responseFactory; 45 46 private StreamFactoryInterface $streamFactory; 47 48 public function __construct( 49 ConfigContainerInterface $configContainer, 50 ResponseFactoryInterface $responseFactory, 51 StreamFactoryInterface $streamFactory 52 ) { 53 $this->configContainer = $configContainer; 54 $this->responseFactory = $responseFactory; 55 $this->streamFactory = $streamFactory; 56 } 57 58 public function run(ServerRequestInterface $request, GuiGatekeeperInterface $gatekeeper): ?ResponseInterface 59 { 60 /* Check Perms */ 61 if ( 62 $this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::USE_RSS) === false || 63 $this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::DEMO_MODE) 64 ) { 65 return null; 66 } 67 68 $type = Core::get_request('type'); 69 $rsstoken = Core::get_request('rsstoken'); 70 $rss = new AmpacheRss($type, $rsstoken); 71 $params = null; 72 73 if ($type === 'podcast') { 74 $params = []; 75 $params['object_type'] = Core::get_request('object_type'); 76 $params['object_id'] = filter_input(INPUT_GET, 'object_id', FILTER_SANITIZE_NUMBER_INT); 77 } 78 79 return $this->responseFactory->createResponse() 80 ->withHeader( 81 'Content-Type', 82 sprintf( 83 'application/xml; charset=%s', 84 $this->configContainer->get(ConfigurationKeyEnum::SITE_CHARSET) 85 ) 86 ) 87 ->withBody( 88 $this->streamFactory->createStream($rss->get_xml($params)) 89 ); 90 } 91} 92