2018-08-07 03:18:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Middleware;
|
|
|
|
|
2018-10-08 19:30:37 +02:00
|
|
|
use Engelsystem\Helpers\Authenticator;
|
2019-07-08 01:31:59 +02:00
|
|
|
use Engelsystem\Helpers\Translation\Translator;
|
2018-08-07 03:18:22 +02:00
|
|
|
use Engelsystem\Http\Request;
|
2018-08-11 23:46:28 +02:00
|
|
|
use Engelsystem\Http\Response;
|
2018-08-07 03:18:22 +02:00
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
use Psr\Http\Server\MiddlewareInterface;
|
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
|
|
|
|
|
|
class LegacyMiddleware implements MiddlewareInterface
|
|
|
|
{
|
|
|
|
protected $free_pages = [
|
|
|
|
'admin_event_config',
|
|
|
|
'angeltypes',
|
|
|
|
'atom',
|
|
|
|
'ical',
|
|
|
|
'public_dashboard',
|
|
|
|
'rooms',
|
|
|
|
'shift_entries',
|
|
|
|
'shifts',
|
|
|
|
'shifts_json_export',
|
|
|
|
'users',
|
|
|
|
'user_driver_licenses',
|
2019-04-24 11:01:37 +02:00
|
|
|
'user_worklog',
|
2018-08-07 03:18:22 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
/** @var ContainerInterface */
|
|
|
|
protected $container;
|
|
|
|
|
2018-10-08 19:30:37 +02:00
|
|
|
/** @var Authenticator */
|
|
|
|
protected $auth;
|
|
|
|
|
2018-08-07 03:18:22 +02:00
|
|
|
/**
|
|
|
|
* @param ContainerInterface $container
|
2018-10-08 19:30:37 +02:00
|
|
|
* @param Authenticator $auth
|
2018-08-07 03:18:22 +02:00
|
|
|
*/
|
2018-10-08 19:30:37 +02:00
|
|
|
public function __construct(ContainerInterface $container, Authenticator $auth)
|
2018-08-07 03:18:22 +02:00
|
|
|
{
|
|
|
|
$this->container = $container;
|
2018-10-08 19:30:37 +02:00
|
|
|
$this->auth = $auth;
|
2018-08-07 03:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the request the old way
|
|
|
|
*
|
|
|
|
* Should be used before a 404 is send
|
|
|
|
*
|
|
|
|
* @param ServerRequestInterface $request
|
|
|
|
* @param RequestHandlerInterface $handler
|
|
|
|
* @return ResponseInterface
|
|
|
|
*/
|
|
|
|
public function process(
|
|
|
|
ServerRequestInterface $request,
|
|
|
|
RequestHandlerInterface $handler
|
|
|
|
): ResponseInterface {
|
|
|
|
/** @var Request $appRequest */
|
|
|
|
$appRequest = $this->container->get('request');
|
|
|
|
$page = $appRequest->query->get('p');
|
|
|
|
if (empty($page)) {
|
|
|
|
$page = $appRequest->path();
|
|
|
|
$page = str_replace('-', '_', $page);
|
|
|
|
}
|
|
|
|
|
2018-08-11 23:46:28 +02:00
|
|
|
$title = $content = '';
|
2018-08-07 03:18:22 +02:00
|
|
|
if (
|
2018-08-11 23:46:28 +02:00
|
|
|
preg_match('~^\w+$~i', $page)
|
2018-11-12 14:41:23 +01:00
|
|
|
&& (in_array($page, $this->free_pages) || $this->auth->can($page))
|
2018-08-07 03:18:22 +02:00
|
|
|
) {
|
2018-08-11 23:46:28 +02:00
|
|
|
list($title, $content) = $this->loadPage($page);
|
2018-08-07 03:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($title) and empty($content)) {
|
2018-08-29 22:05:38 +02:00
|
|
|
/** @var Translator $translator */
|
|
|
|
$translator = $this->container->get('translator');
|
|
|
|
|
2018-08-29 13:58:50 +02:00
|
|
|
$page = 404;
|
2018-08-29 22:05:38 +02:00
|
|
|
$title = $translator->translate('Page not found');
|
2019-11-10 23:26:23 +01:00
|
|
|
$content = $translator->translate('page.404.text');
|
2018-08-07 03:18:22 +02:00
|
|
|
}
|
|
|
|
|
2018-08-11 23:46:28 +02:00
|
|
|
return $this->renderPage($page, $title, $content);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the legacy page content and title
|
|
|
|
*
|
|
|
|
* @param string $page
|
|
|
|
* @return array ['title', 'content']
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
|
|
|
protected function loadPage($page)
|
|
|
|
{
|
|
|
|
$title = ucfirst($page);
|
|
|
|
switch ($page) {
|
|
|
|
/** @noinspection PhpMissingBreakStatementInspection */
|
|
|
|
case 'ical':
|
|
|
|
require_once realpath(__DIR__ . '/../../includes/pages/user_ical.php');
|
|
|
|
user_ical();
|
2019-11-10 23:26:23 +01:00
|
|
|
break;
|
2018-08-11 23:46:28 +02:00
|
|
|
/** @noinspection PhpMissingBreakStatementInspection */
|
|
|
|
case 'atom':
|
|
|
|
require_once realpath(__DIR__ . '/../../includes/pages/user_atom.php');
|
|
|
|
user_atom();
|
2019-11-10 23:26:23 +01:00
|
|
|
break;
|
2018-08-11 23:46:28 +02:00
|
|
|
/** @noinspection PhpMissingBreakStatementInspection */
|
|
|
|
case 'shifts_json_export':
|
|
|
|
require_once realpath(__DIR__ . '/../../includes/controller/shifts_controller.php');
|
|
|
|
shifts_json_export_controller();
|
2019-11-10 23:26:23 +01:00
|
|
|
break;
|
2018-08-11 23:46:28 +02:00
|
|
|
case 'public_dashboard':
|
|
|
|
return public_dashboard_controller();
|
|
|
|
case 'angeltypes':
|
|
|
|
return angeltypes_controller();
|
|
|
|
case 'shift_entries':
|
|
|
|
return shift_entries_controller();
|
|
|
|
case 'shifts':
|
|
|
|
return shifts_controller();
|
|
|
|
case 'users':
|
|
|
|
return users_controller();
|
|
|
|
case 'user_angeltypes':
|
|
|
|
return user_angeltypes_controller();
|
|
|
|
case 'user_driver_licenses':
|
|
|
|
return user_driver_licenses_controller();
|
|
|
|
case 'shifttypes':
|
|
|
|
list($title, $content) = shifttypes_controller();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_event_config':
|
|
|
|
list($title, $content) = event_config_edit_controller();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'rooms':
|
|
|
|
return rooms_controller();
|
|
|
|
case 'news':
|
|
|
|
$title = news_title();
|
|
|
|
$content = user_news();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'news_comments':
|
|
|
|
require_once realpath(__DIR__ . '/../../includes/pages/user_news.php');
|
|
|
|
$title = user_news_comments_title();
|
|
|
|
$content = user_news_comments();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'user_meetings':
|
|
|
|
$title = meetings_title();
|
|
|
|
$content = user_meetings();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'user_myshifts':
|
|
|
|
$title = myshifts_title();
|
|
|
|
$content = user_myshifts();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'user_shifts':
|
|
|
|
$title = shifts_title();
|
|
|
|
$content = user_shifts();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'user_worklog':
|
|
|
|
return user_worklog_controller();
|
|
|
|
case 'user_messages':
|
|
|
|
$title = messages_title();
|
|
|
|
$content = user_messages();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'user_questions':
|
|
|
|
$title = questions_title();
|
|
|
|
$content = user_questions();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'user_settings':
|
|
|
|
$title = settings_title();
|
|
|
|
$content = user_settings();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'register':
|
|
|
|
$title = register_title();
|
|
|
|
$content = guest_register();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_questions':
|
|
|
|
$title = admin_questions_title();
|
|
|
|
$content = admin_questions();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_user':
|
|
|
|
$title = admin_user_title();
|
|
|
|
$content = admin_user();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_arrive':
|
|
|
|
$title = admin_arrive_title();
|
|
|
|
$content = admin_arrive();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_active':
|
|
|
|
$title = admin_active_title();
|
|
|
|
$content = admin_active();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_free':
|
|
|
|
$title = admin_free_title();
|
|
|
|
$content = admin_free();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_news':
|
|
|
|
require_once realpath(__DIR__ . '/../../includes/pages/admin_news.php');
|
|
|
|
$content = admin_news();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_rooms':
|
|
|
|
$title = admin_rooms_title();
|
|
|
|
$content = admin_rooms();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_groups':
|
|
|
|
$title = admin_groups_title();
|
|
|
|
$content = admin_groups();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_import':
|
|
|
|
$title = admin_import_title();
|
|
|
|
$content = admin_import();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_shifts':
|
|
|
|
$title = admin_shifts_title();
|
|
|
|
$content = admin_shifts();
|
|
|
|
return [$title, $content];
|
|
|
|
case 'admin_log':
|
|
|
|
$title = admin_log_title();
|
|
|
|
$content = admin_log();
|
|
|
|
return [$title, $content];
|
|
|
|
}
|
2018-08-07 03:18:22 +02:00
|
|
|
|
2019-09-08 02:25:49 +02:00
|
|
|
throw_redirect(page_link_to('login'));
|
2019-11-06 13:43:57 +01:00
|
|
|
|
|
|
|
return [];
|
2018-08-11 23:46:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the template
|
|
|
|
*
|
|
|
|
* @param string $page
|
|
|
|
* @param string $title
|
|
|
|
* @param string $content
|
|
|
|
* @return Response
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
|
|
|
protected function renderPage($page, $title, $content)
|
|
|
|
{
|
2018-08-29 13:58:50 +02:00
|
|
|
if (!empty($page) && is_int($page)) {
|
|
|
|
return response($content, (int)$page);
|
2018-08-25 21:16:20 +02:00
|
|
|
}
|
|
|
|
|
2018-08-26 02:54:52 +02:00
|
|
|
return response(view('layouts/app', [
|
2018-09-02 02:09:56 +02:00
|
|
|
'title' => $title,
|
|
|
|
'content' => msg() . $content,
|
2018-08-29 13:58:50 +02:00
|
|
|
]), 200);
|
2018-08-07 03:18:22 +02:00
|
|
|
}
|
|
|
|
}
|