2019-02-06 20:34:51 +03:00
|
|
|
<?php
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2019-02-06 20:34:51 +03:00
|
|
|
/**
|
|
|
|
* This file is part of RSS-Bridge, a PHP project capable of generating RSS and
|
|
|
|
* Atom feeds for websites that don't have one.
|
|
|
|
*
|
|
|
|
* For the full license information, please view the UNLICENSE file distributed
|
|
|
|
* with this source code.
|
|
|
|
*
|
2022-07-01 16:10:30 +03:00
|
|
|
* @package Core
|
|
|
|
* @license http://unlicense.org/ UNLICENSE
|
|
|
|
* @link https://github.com/rss-bridge/rss-bridge
|
2019-02-06 20:34:51 +03:00
|
|
|
*/
|
|
|
|
|
2022-06-22 19:30:37 +03:00
|
|
|
class DetectAction implements ActionInterface
|
|
|
|
{
|
2022-07-08 22:06:14 +03:00
|
|
|
public function execute(array $request)
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2022-08-06 23:46:28 +03:00
|
|
|
$targetURL = $request['url'] ?? null;
|
|
|
|
$format = $request['format'] ?? null;
|
2019-02-06 20:34:51 +03:00
|
|
|
|
2022-08-06 23:46:28 +03:00
|
|
|
if (!$targetURL) {
|
|
|
|
throw new \Exception('You must specify a url!');
|
|
|
|
}
|
|
|
|
if (!$format) {
|
|
|
|
throw new \Exception('You must specify a format!');
|
|
|
|
}
|
2019-06-18 19:55:29 +03:00
|
|
|
|
2022-08-06 23:46:28 +03:00
|
|
|
$bridgeFactory = new BridgeFactory();
|
2019-02-06 20:34:51 +03:00
|
|
|
|
2022-07-08 13:54:23 +03:00
|
|
|
foreach ($bridgeFactory->getBridgeClassNames() as $bridgeClassName) {
|
|
|
|
if (!$bridgeFactory->isWhitelisted($bridgeClassName)) {
|
2022-07-01 16:10:30 +03:00
|
|
|
continue;
|
|
|
|
}
|
2019-02-06 20:34:51 +03:00
|
|
|
|
2022-07-08 13:54:23 +03:00
|
|
|
$bridge = $bridgeFactory->create($bridgeClassName);
|
2019-02-06 20:34:51 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
$bridgeParams = $bridge->detectParameters($targetURL);
|
2019-02-06 20:34:51 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
if (is_null($bridgeParams)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-02-06 20:34:51 +03:00
|
|
|
|
2022-07-08 13:54:23 +03:00
|
|
|
$bridgeParams['bridge'] = $bridgeClassName;
|
2022-07-01 16:10:30 +03:00
|
|
|
$bridgeParams['format'] = $format;
|
2019-02-06 20:34:51 +03:00
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
header('Location: ?action=display&' . http_build_query($bridgeParams), true, 301);
|
2022-08-06 23:46:28 +03:00
|
|
|
return;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-02-06 20:34:51 +03:00
|
|
|
|
2022-08-06 23:46:28 +03:00
|
|
|
throw new \Exception('No bridge found for given URL: ' . $targetURL);
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2019-02-06 20:34:51 +03:00
|
|
|
}
|