rss-bridge/actions/DetectAction.php

56 lines
1.5 KiB
PHP
Raw Normal View History

2019-02-06 18:34:51 +01:00
<?php
2019-02-06 18:34:51 +01: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.
*
* @package Core
* @license http://unlicense.org/ UNLICENSE
* @link https://github.com/rss-bridge/rss-bridge
2019-02-06 18:34:51 +01:00
*/
2022-06-22 18:30:37 +02:00
class DetectAction implements ActionInterface
{
public $userData = [];
2019-02-06 18:34:51 +01:00
public function execute()
{
$targetURL = $this->userData['url']
or returnClientError('You must specify a url!');
2019-02-06 18:34:51 +01:00
$format = $this->userData['format']
or returnClientError('You must specify a format!');
2022-07-06 12:14:04 +02:00
$bridgeFactory = new \BridgeFactory();
2019-02-06 18:34:51 +01:00
foreach ($bridgeFactory->getBridgeClassNames() as $bridgeClassName) {
if (!$bridgeFactory->isWhitelisted($bridgeClassName)) {
continue;
}
2019-02-06 18:34:51 +01:00
$bridge = $bridgeFactory->create($bridgeClassName);
2019-02-06 18:34:51 +01:00
if ($bridge === false) {
continue;
}
2019-02-06 18:34:51 +01:00
$bridgeParams = $bridge->detectParameters($targetURL);
2019-02-06 18:34:51 +01:00
if (is_null($bridgeParams)) {
continue;
}
2019-02-06 18:34:51 +01:00
$bridgeParams['bridge'] = $bridgeClassName;
$bridgeParams['format'] = $format;
2019-02-06 18:34:51 +01:00
header('Location: ?action=display&' . http_build_query($bridgeParams), true, 301);
die();
}
2019-02-06 18:34:51 +01:00
returnClientError('No bridge found for given URL: ' . $targetURL);
}
2019-02-06 18:34:51 +01:00
}