4.1 KiB
getInput
The getInput
function is used to receive a value for a parameter, specified in const PARAMETERS
$this->getInput('your input name here');
getInput
will either return the value for your parameter or null
if the parameter is unknown or not specified.
getContents
The getContents
function uses cURL to acquire data from the specified URI while respecting the various settings defined at a global level by RSS-Bridge (i.e., proxy host, user agent, etc.). This function accepts a few parameters:
Parameter | Type | Optional | Description |
---|---|---|---|
url |
string | required | The URL of the contents to acquire |
header |
array | optional | An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100') , see CURLOPT_HTTPHEADER |
opts |
array | optional | An array of cURL options in the format array(CURLOPT_POST => 1); , see curl_setopt for a complete list of options. |
$header = array('Content-type:text/plain', 'Content-length: 100');
$opts = array(CURLOPT_POST => 1);
$html = getContents($url, $header, $opts);
getSimpleHTMLDOM
The getSimpleHTMLDOM
function is a wrapper for the simple_html_dom file_get_html function in order to provide context by design.
$html = getSimpleHTMLDOM('your URI');
getSimpleHTMLDOMCached
The getSimpleHTMLDOMCached
function does the same as the getSimpleHTMLDOM
function, except that the content received for the given URI is stored in a cache and loaded from cache on the next request if the specified cache duration was not reached. Use this function for data that is very unlikely to change between consecutive requests to RSS-Bridge. This function allows to specify the cache duration with the second parameter (default is 24 hours / 86400 seconds).
$html = getSimpleHTMLDOMCached('your URI', 86400); // Duration 24h
Notice: Due to the current implementation a value greater than 86400 seconds (24 hours) will not work as the cache is purged every 24 hours automatically.
returnError
Notice: Whenever possible make use of returnClientError
or returnServerError
The returnError
function aborts execution of the current bridge and returns the given error message with the provided error number:
returnError('Your error message', 404);
Check the list of error codes for applicable error numbers.
returnClientError
The returnClientError
function aborts execution of the current bridge and returns the given error message with error code 400:
returnClientError('Your error message')
Use this function when the user provided invalid parameter or a required parameter is missing.
returnServerError
The returnServerError
function aborts execution of the current bridge and returns the given error message with error code 500:
returnServerError('Your error message')
Use this function when a problem occurs that has nothing to do with the parameters provided by the user. (like: Host service gone missing, empty data received, etc...)
defaultLinkTo
Automatically replaces any relative URL in a given string or DOM object (i.e. the one returned by getSimpleHTMLDOM) with an absolute URL.
defaultLinkTo ( mixed $content, string $server ) : object
Returns a DOM object (even if provided a string).
Remarks
- Only handles
<a>
and<img>
tags.
Example
$html = '<img src="/blob/master/README.md">';
$html = defaultLinkTo($html, 'https://www.github.com/rss-bridge/rss-bridge'); // Using custom server
$html = defaultLinkTo($html, $this->getURI()); // Using bridge URL
// Output
// <img src="https://www.github.com/rss-bridge/rss-bridge/blob/master/README.md">