2018-07-21 19:15:07 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-08-18 23:52:01 +03:00
|
|
|
final class FrontpageAction implements ActionInterface
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2024-08-07 01:21:06 +03:00
|
|
|
public function __invoke(Request $request): Response
|
2022-08-06 23:46:28 +03:00
|
|
|
{
|
2024-08-18 20:11:11 +03:00
|
|
|
$token = $request->attribute('token');
|
|
|
|
|
2023-08-03 04:10:24 +03:00
|
|
|
$messages = [];
|
2022-11-07 20:22:54 +03:00
|
|
|
$activeBridges = 0;
|
2022-08-18 23:52:01 +03:00
|
|
|
|
|
|
|
$bridgeFactory = new BridgeFactory();
|
|
|
|
$bridgeClassNames = $bridgeFactory->getBridgeClassNames();
|
|
|
|
|
2023-08-03 04:10:24 +03:00
|
|
|
foreach ($bridgeFactory->getMissingEnabledBridges() as $missingEnabledBridge) {
|
|
|
|
$messages[] = [
|
|
|
|
'body' => sprintf('Warning : Bridge "%s" not found', $missingEnabledBridge),
|
|
|
|
'level' => 'warning'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-11-07 20:22:54 +03:00
|
|
|
$body = '';
|
2022-08-18 23:52:01 +03:00
|
|
|
foreach ($bridgeClassNames as $bridgeClassName) {
|
2023-06-11 04:16:03 +03:00
|
|
|
if ($bridgeFactory->isEnabled($bridgeClassName)) {
|
2024-08-18 20:11:11 +03:00
|
|
|
$body .= BridgeCard::render($bridgeClassName, $token);
|
2022-11-07 20:22:54 +03:00
|
|
|
$activeBridges++;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
}
|
2018-07-21 19:15:07 +03:00
|
|
|
|
2024-08-18 20:11:11 +03:00
|
|
|
$response = new Response(render(__DIR__ . '/../templates/frontpage.html.php', [
|
|
|
|
'messages' => $messages,
|
|
|
|
'admin_email' => Configuration::getConfig('admin', 'email'),
|
|
|
|
'admin_telegram' => Configuration::getConfig('admin', 'telegram'),
|
|
|
|
'bridges' => $body,
|
|
|
|
'active_bridges' => $activeBridges,
|
|
|
|
'total_bridges' => count($bridgeClassNames),
|
2024-08-07 01:21:06 +03:00
|
|
|
]));
|
2024-08-18 20:11:11 +03:00
|
|
|
|
|
|
|
// TODO: The rendered template could be cached, but beware config changes that changes the html
|
|
|
|
return $response;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2018-07-21 19:15:07 +03:00
|
|
|
}
|