"Fossies" - the Fresh Open Source Software Archive

Member "ampache-5.0.0/src/Module/Application/Shout/AddShoutAction.php" (31 Aug 2021, 3295 Bytes) of package /linux/www/ampache-5.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AddShoutAction.php" see the Fossies "Dox" file reference documentation.

    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 
   23 declare(strict_types=0);
   24 
   25 namespace Ampache\Module\Application\Shout;
   26 
   27 use Ampache\Config\ConfigContainerInterface;
   28 use Ampache\Repository\Model\Shoutbox;
   29 use Ampache\Module\Application\ApplicationActionInterface;
   30 use Ampache\Module\Application\Exception\AccessDeniedException;
   31 use Ampache\Module\Authorization\AccessLevelEnum;
   32 use Ampache\Module\Authorization\GuiGatekeeperInterface;
   33 use Ampache\Module\System\Core;
   34 use Ampache\Module\Util\InterfaceImplementationChecker;
   35 use Ampache\Module\Util\UiInterface;
   36 use Psr\Http\Message\ResponseFactoryInterface;
   37 use Psr\Http\Message\ResponseInterface;
   38 use Psr\Http\Message\ServerRequestInterface;
   39 use Teapot\StatusCode;
   40 
   41 final class AddShoutAction implements ApplicationActionInterface
   42 {
   43     public const REQUEST_KEY = 'add_shout';
   44 
   45     private UiInterface $ui;
   46 
   47     private ResponseFactoryInterface $responseFactory;
   48 
   49     private ConfigContainerInterface $configContainer;
   50 
   51     public function __construct(
   52         UiInterface $ui,
   53         ResponseFactoryInterface $responseFactory,
   54         ConfigContainerInterface $configContainer
   55     ) {
   56         $this->ui              = $ui;
   57         $this->responseFactory = $responseFactory;
   58         $this->configContainer = $configContainer;
   59     }
   60 
   61     public function run(ServerRequestInterface $request, GuiGatekeeperInterface $gatekeeper): ?ResponseInterface
   62     {
   63         // Must be at least a user to do this
   64         if (
   65             $gatekeeper->mayAccess(AccessLevelEnum::TYPE_INTERFACE, AccessLevelEnum::LEVEL_USER) === false ||
   66             !Core::form_verify('add_shout') ||
   67             !InterfaceImplementationChecker::is_library_item(Core::get_post('object_type'))
   68         ) {
   69             throw new AccessDeniedException();
   70         }
   71 
   72         // Remove unauthorized defined values from here
   73         if (filter_has_var(INPUT_POST, 'user')) {
   74             unset($_POST['user']);
   75         }
   76         if (filter_has_var(INPUT_POST, 'date')) {
   77             unset($_POST['date']);
   78         }
   79 
   80         Shoutbox::create($_POST);
   81 
   82         return $this->responseFactory
   83             ->createResponse(StatusCode::FOUND)
   84             ->withHeader(
   85                 'Location',
   86                 sprintf(
   87                     '%s/shout.php?action=show_add_shout&type=%s&id=%d',
   88                     $this->configContainer->getWebPath(),
   89                     $_POST['object_type'],
   90                     (int) ($_POST['object_id'])
   91                 )
   92             );
   93     }
   94 }