1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-10 18:44:04 +02:00

feat: add url component (#3684)

* feat: add url library

* fix
This commit is contained in:
Dag
2023-09-24 18:34:09 +02:00
committed by GitHub
parent 437afd67e0
commit f321f000c1
4 changed files with 208 additions and 10 deletions

View File

@@ -305,25 +305,30 @@ class RedditBridge extends BridgeAbstract
public function detectParameters($url)
{
$parsed_url = parse_url($url);
$host = $parsed_url['host'] ?? null;
if ($host != 'www.reddit.com' && $host != 'old.reddit.com') {
try {
$urlObject = Url::fromString($url);
} catch (UrlException $e) {
return null;
}
$path = explode('/', $parsed_url['path']);
$host = $urlObject->getHost();
$path = $urlObject->getPath();
if ($path[1] == 'r') {
$pathSegments = explode('/', $path);
if ($host !== 'www.reddit.com' && $host !== 'old.reddit.com') {
return null;
}
if ($pathSegments[1] == 'r') {
return [
'context' => 'single',
'r' => $path[2]
'r' => $pathSegments[2],
];
} elseif ($path[1] == 'user') {
} elseif ($pathSegments[1] == 'user') {
return [
'context' => 'user',
'u' => $path[2]
'u' => $pathSegments[2],
];
} else {
return null;