Adds detection for servers responding with Cloudflare challenges,
throwing a server error if detected:
"The server responded with a Cloudflare challenge, which is not
supported by RSS-Bridge! If this error persists longer than a week,
please consider opening an issue on GitHub!"
This is supposed to support maintainers to identify broken bridges
for sites with Cloudflare enabled permanently. It doesn't circumvent
the protection in any form or shape!
The Cloudflare challenge is detected by analyzing the last response
header received from the server. If the HTTP Code is not 200 (OK)
and the server name contains 'cloudflare' ('Server: cloudflare'),
RSS-Bridge assumes the server responded with a challenge.
The header parsing is based on https://stackoverflow.com/a/18682872
cURL is a powerful library specifically designed to connect to many
different types of servers with different types of protocols. For
more detailed information refer to the PHP cURL manual:
- http://php.net/manual/en/book.curl.php
Due to this change some parameters for the getContents function were
necessary (also applies to getSimpleHTMLDOM and getSimpleHTMLDOMCached):
> $use_include_path removed
This parameter has never been used and doesn't even make sense in
this context; If set to true file_get_contents would also search
for files in the include_path (specified in php.ini).
> $context replaced by $header and $opts
The $context parameter allowed for customization of the request in
order to change how file_get_contents would acquire the data (i.e.
using POST instead of GET, sending custom header, etc...)
cURL also provides facilities to specify custom headers and change
how it communicates to severs. cURL, however, is much more advanced.
- $header is an optional parameter (empty by default). It receives
an array of strings to send in the HTTP request header.
See 'CURLOPT_HTTPHEADER':
"An array of HTTP header fields to set, in the format
array('Content-type: text/plain', 'Content-length: 100')"
- php.net/manual/en/function.curl-setopt.php
- $opts is an optional parameter (empty by default). It receives
an array of options, where each option is a key-value-pair of
a cURL option (CURLOPT_*) and it's associated parameter. This
parameter accepts any of the CURLOPT_* settings.
Example (sending POST instead of GET):
$opts = array(
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => '&action=none'
);
$html = getContents($url, array(), $opts);
Refer to the cURL setopt manual for more information:
- php.net/manual/en/function.curl-setopt.php
> $offset and $maxlen removed
These options were supported by file_get_contents, but there doesn't
seem to be an equivalent in cURL. Since no caller uses them they are
safe to remove.
Compressed data / Encoding
By using cURL instead of file_get_contents RSS-Bridge no longer has
to handle compressed data manually.
See 'CURLOPT_ENCODING':
"[...] Supported encodings are "identity", "deflate", and "gzip".
If an empty string, "", is set, a header containing all supported
encoding types is sent."
- http://php.net/manual/en/function.curl-setopt.php
Notice: By default all encoding types are accepted (""). This can
be changed by setting a custom option via $opts.
Example:
$opts = array(CURLOPT_ENCODING => 'gzip');
$html = getContents($url, array(), $opts);
Proxy
The proxy implementation should still work, but there doesn't seem
to be an equivalent for 'request_fulluri = true'. To my understanding
this isn't an issue because cURL knows how to handle proxy communication.
- Do not add spaces after opening or before closing parenthesis
// Wrong
if( !is_null($var) ) {
...
}
// Right
if(!is_null($var)) {
...
}
- Add space after closing parenthesis
// Wrong
if(true){
...
}
// Right
if(true) {
...
}
- Add body into new line
- Close body in new line
// Wrong
if(true) { ... }
// Right
if(true) {
...
}
Notice: Spaces after keywords are not detected:
// Wrong (not detected)
// -> space after 'if' and missing space after 'else'
if (true) {
...
} else{
...
}
// Right
if(true) {
...
} else {
...
}
- returnError, returnServerError, returnClientError ,debugMessage are
moved to lib/error.php
- getContents, getSimpleHTMLDOM, getSimpleHTMLDOMCached are moved to
lib/contents.php
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>