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=1);
24
25namespace Ampache\Module\Application\Podcast;
26
27use Ampache\Config\ConfigContainerInterface;
28use Ampache\Config\ConfigurationKeyEnum;
29use Ampache\Repository\Model\Podcast;
30use Ampache\Module\Application\ApplicationActionInterface;
31use Ampache\Module\Application\Exception\AccessDeniedException;
32use Ampache\Module\Authorization\AccessLevelEnum;
33use Ampache\Module\Authorization\GuiGatekeeperInterface;
34use Ampache\Module\System\Core;
35use Ampache\Module\Util\Ui;
36use Ampache\Module\Util\UiInterface;
37use Psr\Http\Message\ResponseInterface;
38use Psr\Http\Message\ServerRequestInterface;
39
40final class CreateAction implements ApplicationActionInterface
41{
42    public const REQUEST_KEY = 'create';
43
44    private ConfigContainerInterface $configContainer;
45
46    private UiInterface $ui;
47
48    public function __construct(
49        ConfigContainerInterface $configContainer,
50        UiInterface $ui
51    ) {
52        $this->configContainer = $configContainer;
53        $this->ui              = $ui;
54    }
55
56    public function run(ServerRequestInterface $request, GuiGatekeeperInterface $gatekeeper): ?ResponseInterface
57    {
58        if ($this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::PODCAST) === false) {
59            return null;
60        }
61
62        if (
63            $gatekeeper->mayAccess(AccessLevelEnum::TYPE_INTERFACE, AccessLevelEnum::LEVEL_MANAGER) === false ||
64            $this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::DEMO_MODE) === true ||
65            !Core::form_verify('add_podcast')
66        ) {
67            throw new AccessDeniedException();
68        }
69
70        $this->ui->showHeader();
71
72        // Try to create the sucker
73        $results = Podcast::create($_POST);
74
75        if (!$results) {
76            require_once Ui::find_template('show_add_podcast.inc.php');
77        } else {
78            $title  = T_('No Problem');
79            $body   = T_('Subscribed to the Podcast');
80            $this->ui->showConfirmation(
81                $title,
82                $body,
83                sprintf(
84                    '%s/browse.php?action=podcast',
85                    $this->configContainer->getWebPath()
86                )
87            );
88        }
89
90        $this->ui->showQueryStats();
91        $this->ui->showFooter();
92
93        return null;
94    }
95}
96