. * */ declare(strict_types=0); namespace Ampache\Module\Application\Test; use Ampache\Config\AmpConfig; use Ampache\Config\ConfigContainerInterface; use Ampache\Repository\Model\Preference; use Ampache\Module\Application\ApplicationActionInterface; use Ampache\Module\Authorization\GuiGatekeeperInterface; use Exception; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Teapot\StatusCode; final class ShowAction implements ApplicationActionInterface { public const REQUEST_KEY = 'show'; private ConfigContainerInterface $configContainer; private ResponseFactoryInterface $responseFactory; public function __construct( ConfigContainerInterface $configContainer, ResponseFactoryInterface $responseFactory ) { $this->configContainer = $configContainer; $this->responseFactory = $responseFactory; } /** * @param ServerRequestInterface $request * @param GuiGatekeeperInterface $gatekeeper * @return ResponseInterface|null * @throws Exception */ public function run(ServerRequestInterface $request, GuiGatekeeperInterface $gatekeeper): ?ResponseInterface { $configfile = __DIR__ . '/../../../../config/ampache.cfg.php'; // Load config from file $results = array(); if (!file_exists($configfile)) { return $this->responseFactory ->createResponse(StatusCode::FOUND) ->withHeader( 'Location', '/install.php' ); } else { // Make sure the config file is set up and parsable $results = @parse_ini_file($configfile); if (empty($results)) { $link = __DIR__ . '/../../public/test.php?action=config'; } } /* Temp Fixes */ $results = Preference::fix_preferences($results); $this->configContainer->updateConfig($results); unset($results); // Try to load localization from cookie $session_name = $this->configContainer->getSessionName(); if (filter_has_var(INPUT_COOKIE, $session_name . '_lang')) { AmpConfig::set('lang', $_COOKIE[$session_name . '_lang']); } if (!class_exists('Gettext\Translations')) { require_once __DIR__ . '/../../../../public/templates/test_error_page.inc.php'; throw new Exception('load_gettext()'); } else { load_gettext(); // Load template require_once __DIR__ . '/../../../../public/templates/show_test.inc.php'; } return null; } }