mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-05 08:07:33 +02:00
Add page for the detectParameters function
19
The-detectParameters-function.md
Normal file
19
The-detectParameters-function.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
The `detectParameters` function takes a URL and attempts to extract a valid set of parameters for the current bridge.
|
||||||
|
|
||||||
|
If the passed URL is valid for this bridge the function should return an array of parameter -> value pairs that can be used by this bridge, or an empty array if the bridge requires no parameters. If the URL is not relevant for this bridge the function should return `null`.
|
||||||
|
|
||||||
|
**Notice:** Implementing this function is optional. By default **RSS-Bridge** tries to match the supplied URL to the `URI` constant defined in the bridge which may be enough for bridges without any parameters defined.
|
||||||
|
|
||||||
|
```PHP
|
||||||
|
public function detectParameters($url){
|
||||||
|
$regex = '/^(https?:\/\/)?(www\.)?(.+?)(\/)?$/';
|
||||||
|
if(empty(static::PARAMETERS)
|
||||||
|
&& preg_match($regex, $url, $urlMatches) > 0
|
||||||
|
&& preg_match($regex, static::URI, $bridgeUriMatches) > 0
|
||||||
|
&& $urlMatches[3] === $bridgeUriMatches[3]) {
|
||||||
|
return array();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
Reference in New Issue
Block a user