1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-01-17 14:18:35 +01:00
php-rss-bridge/actions/DetectAction.php

46 lines
1.4 KiB
PHP
Raw Normal View History

2019-02-06 18:34:51 +01:00
<?php
2022-06-22 18:30:37 +02:00
class DetectAction implements ActionInterface
{
public function execute(Request $request)
{
$url = $request->get('url');
$format = $request->get('format');
2019-02-06 18:34:51 +01:00
if (!$url) {
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'You must specify a url']));
}
if (!$format) {
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'You must specify a format']));
}
$bridgeFactory = new BridgeFactory();
2019-02-06 18:34:51 +01:00
foreach ($bridgeFactory->getBridgeClassNames() as $bridgeClassName) {
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
continue;
}
2019-02-06 18:34:51 +01:00
$bridge = $bridgeFactory->create($bridgeClassName);
2019-02-06 18:34:51 +01:00
$bridgeParams = $bridge->detectParameters($url);
2019-02-06 18:34:51 +01:00
if (!$bridgeParams) {
continue;
}
2019-02-06 18:34:51 +01:00
$query = [
'action' => 'display',
'bridge' => $bridgeClassName,
'format' => $format,
];
$query = array_merge($query, $bridgeParams);
return new Response('', 301, ['location' => '?' . http_build_query($query)]);
}
2019-02-06 18:34:51 +01:00
return new Response(render(__DIR__ . '/../templates/error.html.php', [
'message' => 'No bridge found for given URL: ' . $url,
]));
}
2019-02-06 18:34:51 +01:00
}