"Fossies" - the Fresh Open Source Software Archive

Member "ampache-5.0.0/src/Module/Api/Edit/AbstractEditAction.php" (31 Aug 2021, 4535 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 "AbstractEditAction.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\Api\Edit;
   26 
   27 use Ampache\Config\AmpConfig;
   28 use Ampache\Config\ConfigContainerInterface;
   29 use Ampache\Module\System\LegacyLogger;
   30 use Ampache\Repository\Model\database_object;
   31 use Ampache\Module\Application\ApplicationActionInterface;
   32 use Ampache\Module\Authorization\Access;
   33 use Ampache\Module\Authorization\GuiGatekeeperInterface;
   34 use Ampache\Module\System\Core;
   35 use Ampache\Module\Util\InterfaceImplementationChecker;
   36 use Ampache\Module\Util\ObjectTypeToClassNameMapper;
   37 use Psr\Http\Message\ResponseInterface;
   38 use Psr\Http\Message\ServerRequestInterface;
   39 use Psr\Log\LoggerInterface;
   40 
   41 abstract class AbstractEditAction implements ApplicationActionInterface
   42 {
   43     private ConfigContainerInterface $configContainer;
   44 
   45     private LoggerInterface $logger;
   46 
   47     public function __construct(
   48         ConfigContainerInterface $configContainer,
   49         LoggerInterface $logger
   50     ) {
   51         $this->configContainer = $configContainer;
   52         $this->logger          = $logger;
   53     }
   54 
   55     public function run(
   56         ServerRequestInterface $request,
   57         GuiGatekeeperInterface $gatekeeper
   58     ): ?ResponseInterface {
   59         $this->logger->debug(
   60             sprintf('Called for action: {%d}', Core::get_request('action')),
   61             [LegacyLogger::CONTEXT_TYPE => __CLASS__]
   62         );
   63 
   64         // Post first
   65         $object_type = $_POST['type'];
   66         if (empty($object_type)) {
   67             $object_type = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
   68         }
   69         $object_id = (int) Core::get_get('id');
   70 
   71         if (empty($object_type)) {
   72             $object_type = $source_object_type = filter_input(
   73                 INPUT_GET,
   74                 'object_type',
   75                 FILTER_SANITIZE_STRING,
   76                 FILTER_FLAG_NO_ENCODE_QUOTES
   77             );
   78         } else {
   79             $source_object_type = $object_type;
   80 
   81             $object_type = implode('_', explode('_', $object_type, -1));
   82         }
   83 
   84         if (!InterfaceImplementationChecker::is_library_item($object_type) && $object_type != 'share' && $object_type != 'channel' && $object_type != 'tag') {
   85             $this->logger->warning(
   86                 sprintf('Type `%d` is not based on an item library.', $object_type),
   87                 [LegacyLogger::CONTEXT_TYPE => __CLASS__]
   88             );
   89 
   90             return null;
   91         }
   92 
   93         $class_name = ObjectTypeToClassNameMapper::map($object_type);
   94         $this->logger->warning(
   95             $class_name,
   96             [LegacyLogger::CONTEXT_TYPE => __CLASS__]
   97         );
   98         $this->logger->warning(
   99             $object_id,
  100             [LegacyLogger::CONTEXT_TYPE => __CLASS__]
  101         );
  102         $libitem    = new $class_name($object_id);
  103         if (method_exists($libitem, 'format')) {
  104             $libitem->format();
  105         }
  106 
  107         $level = '50';
  108         if ($libitem->get_user_owner() == Core::get_global('user')->id) {
  109             $level = '25';
  110         }
  111         if (Core::get_request('action') == 'show_edit_playlist') {
  112             $level = '25';
  113         }
  114 
  115         // Make sure they got them rights
  116         if (!Access::check('interface', (int) $level) || AmpConfig::get('demo_mode')) {
  117             echo (string) xoutput_from_array(array('rfc3514' => '0x1'));
  118 
  119             return null;
  120         }
  121 
  122         return $this->handle($request, $gatekeeper, $source_object_type, $libitem, $object_id);
  123     }
  124 
  125     abstract protected function handle(
  126         ServerRequestInterface $request,
  127         GuiGatekeeperInterface $gatekeeper,
  128         string $object_type,
  129         database_object $libitem,
  130         int $object_id
  131     ): ?ResponseInterface;
  132 }