1
0
Fork 0
forked from blallo/rss-bridge
Commit graph

206 commits

Author SHA1 Message Date
logmanoriginal
bc28c5da8e [contents] Set CURLOPT_HTTPHEADER only if the provided array contains data 2018-04-06 20:42:19 +02:00
logmanoriginal
5bd9c1611d [contents] Limit cURL protocols to HTTP and HTTPS 2018-04-06 20:42:19 +02:00
logmanoriginal
ee78e7613f [contents] Replace file_get_contents by cURL
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.
2018-04-06 20:42:19 +02:00
teromene
ac6847045c Catch Errors in order to display a message in more cases. We also catch Exceptions to maintain compat with php 5.
Add check for simplexml extension.
2018-04-04 19:02:40 +01:00
LogMANOriginal
8ba817478b
Implement customizable cache timeout (#641)
* [BridgeAbstract] Implement customizable cache timeout

The customizable cache timeout is used instead of the default cache
timeout (CACHE_TIMEOUT) if specified by the caller.

* [index] Add new global parameter '_cache_timeout'

The _cache_timeout parameter is an optional parameter that can be
used to specify a custom cache timeout. This option is enabled by
default.

It can be disabled using the named constant 'CUSTOM_CACHE_TIMEOUT'
which supports two states:

> true: Enabled (default)
> false: Disabled

* [BridgeAbstract] Change scope of 'getCacheTimeout' to public

* [html] Add cache timeout parameter to all bridges

The timeout parameter only shows if CUSTOM_CACHE_TIMEOUT has been set
to true. The default value is automatically set to the value specified
in the bridge.

* [index] Disable custom cache timeout by default
2018-03-14 18:06:36 +01:00
logmanoriginal
1b1ab6a66e [validation] Fix error on undefined optional numeric value
Providing no value for an optional numeric parameter results in
error "Parameter *** is invalid!"

This is caused by the validation function ignoring the 'required'
attribute when loading and checking input parameters.

This commit adds checks to determine whether the 'required' attri-
bute is defined and active before returning the error message.

References #570:
2017-08-17 19:02:50 +02:00
logmanoriginal
4fb1366aaf [FeedExpander] Fix Serialization of 'SimpleXMLElement' is not allowed 2017-08-10 13:35:19 +02:00
logmanoriginal
8166e33e7f [FeedExpander] Remove whitespace from source content
Whitespace at the beginning of feeds causes parsing errors. This is
an example using an ill-formatted RSS feed:

   "XML or text declaration not at start of entity"
-- https://validator.w3.org

This commit automatically removes all proceeding and trailing white-
space from the source content before resume parsing.
2017-08-10 13:20:35 +02:00
logmanoriginal
4924769549 [validation] Remove superfluous if-statement 2017-08-06 13:45:24 +02:00
logmanoriginal
e4fa963bdf [validation] Return null on invalid number 2017-08-06 13:43:23 +02:00
logmanoriginal
99e7e7876e exception: Use built-in HTTP response codes
PHP >= 5.4 provides a built-in function to generate valid HTTP
error header including the error description: http_response_code()

See: http://php.net/manual/en/function.http-response-code.php
See also: https://stackoverflow.com/a/12018482

This commit removes the '\Http' utility class and replaces all
calls to 'Http::getMessageForCode()' by 'http_response_code()'
2017-08-06 12:55:11 +02:00
logmanoriginal
62c190d841 [Bridge] Remove superfuous variables and statements 2017-08-06 00:04:07 +02:00
logmanoriginal
84d2c02a09 whitelist: Do case-insensitive whitelist matching
Matching whitelisted bridges using a case-insensitive match makes
sense for following reasons:

- Wrong upper/lower case spelling in the whitelist is not easily
discovered. Example: Misspelling 'Youtube' as 'YouTube' will not
show the 'Youtube' bridge (while it is expected to show)

- Two bridges with the same name but different letter casing are
discouraged to prevent confusion and keep the project compatible
with Windows machines
2017-08-06 00:01:32 +02:00
logmanoriginal
a4b9611e66 [phpcs] Add missing rules
- 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 {
    ...
  }
2017-07-29 19:55:12 +02:00
LogMANOriginal
38b56bf23a [index] Improve error handling (#555)
Add additional information to error message:

- Name of the bridge
- Possible solutions
- Error description
- Error code
- Error message

* Output type changed from 'text' to 'html'
* Added styles for the error page
* Added a button to remotely open a GitHub issue

Closes #525
2017-07-29 19:16:16 +02:00
Frans de Jonge
781e4f1908 [FeedExpander] Deal with empty item 2017-06-24 15:09:15 +02:00
logmanoriginal
28331e7cd6 [BridgeAbstract] Return cached infos when using cached items
Re-requesting the same feed in normal mode (not debug mode)
returns the cached version. The name and URI of the feed
however was not returned.

This adds checks to getName() and getURI() in order to return
the cached infos when using the cached version.

Notice: For this to work correctly all bridges must call to
parent::getName() and parent::getURI() respectively if the
queriedContext is not defined. Example:

switch($this->queriedContext){
	case 'My context':
		// do your stuff here!
		break;
	default: parent::getName();
}
2017-04-23 21:06:25 +02:00
Teromene
59025d96bc Add an indicator to show the HTTP status of the site. (#483) 2017-03-18 19:02:18 +00:00
logmanoriginal
a2108c784f [FeedExpander] Properly cast simplexml elements
This fixes a possible cause of
"Serialization of 'SimpleXMLElement' is not allowed"
reported via #487
2017-03-13 22:12:11 +01:00
Teromene
8b2fdb3937 Add a function to convert the background-image attribute to an actual image. 2017-03-03 14:13:29 +00:00
logmanoriginal
16bdf6b204 links: Rename defaultImageSrcTo to defaultLinkTo
This function not only fixes image sources, but also anchors
2017-02-18 13:41:45 +01:00
logmanoriginal
cf7da1d41c [html] Fix anchors after fixing images
Anchors will be fixed in a similar way as it is done with images,
so it can be done in one go.
2017-02-18 13:40:58 +01:00
logmanoriginal
bb8e7495d8 [html] Fix img src replacement not working
strpos returns false if the needle was not found. See:
http://php.net/manual/en/function.strpos.php#refsect1-function.strpos-returnvalues
2017-02-18 13:13:40 +01:00
logmanoriginal
512a4f292b bridges: Return parent::getURI by default 2017-02-15 19:38:32 +01:00
logmanoriginal
c4169f1579 bridges: Return parent::getName by default 2017-02-15 19:38:32 +01:00
logmanoriginal
d93d491d8e core: Use methods to access bridge information
Bridge information were exposed and accessed via public constants
which doesn't work if you want to generate bridges dynamically as
discussed in #402
2017-02-15 19:38:32 +01:00
logmanoriginal
c44fb25845 core: Improve documentation and style for BridgeAbstract and BridgeInterface
Public functions defined in BridgeAbstract also belong to BridgeInterface

getInput may only be used by this class or its children.
2017-02-15 19:36:29 +01:00
logmanoriginal
ff83410534 style: Fix coding styles 2017-02-14 17:28:07 +01:00
Badet Aurélien
670d8f18cb [BridgeAbstract] Enable caching of extraInfos - Issue #431 (#434)
Enable caching of extraInfos.
2017-01-03 10:28:47 +00:00
logmanoriginal
4a1e5245b3 [contents] Don't suppress errors returned by file_get_contents 2016-12-15 20:24:34 +01:00
LogMANOriginal
cad78be37b Merge pull request #445 from da2x/patch-1
Set “Accept-Encoding: gzip” header
2016-12-14 12:57:48 +01:00
Daniel Aleksandersen
278d6a0ec2 Set “Accept-Encoding: gzip” header 2016-12-12 11:29:34 +01:00
Alexis CHEMEL
f4aa3b39e8 fix BridgeAbstract 2016-12-06 01:01:07 +01:00
Badet Aurélien
c702a0e69f Bridge getExtraInfos (#432)
* add function getExtraInfos() to BridgeAbstract

* replace call to $bridge->getName() and $bridge->getURI() by $bridge->getExtraInfos()

replace call to $bridge->getName() and $bridge->getURI() by $bridge->getExtraInfos() defined by default in BridgeAbstract.
So we could pass additionals ExtraInfos from custom bridges to custom formats.
2016-11-29 00:48:59 +00:00
logmanoriginal
14c689e7a3 [core] Fix typos 2016-11-09 19:10:40 +01:00
logmanoriginal
4f4fb11789 [FormatAbstract] Allow child classes to overwrite DEFAULT_CHARSET
By using 'static' instead of 'self' the constant may
be overridden by child classes.
2016-11-09 18:41:25 +01:00
logmanoriginal
28e813620f [FormatInterface] Add missing public functions
This commit adds all missing functions to the interface
that are defined and implemented as public functions in
FormatAbstract.
2016-11-09 18:41:24 +01:00
logmanoriginal
49281a2ed3 [FeedExpander] Remove orphan getDescription function 2016-10-16 12:47:37 +02:00
logmanoriginal
b6feda2377 [contents] Use FileCache for getSimpleHTMLDOMCached 2016-10-08 16:30:01 +02:00
logmanoriginal
5c309e93dc [cache] Specify cache duration for 'purgeCache' 2016-10-08 16:18:10 +02:00
logmanoriginal
5de4a59d41 [index] Initialize cache before loading to bridge
Previously BridgeAbstract needed to know which exact implementation
of CacheInterface was used (since we only got one right now its
not a problem). Initializing the cache in index.php instead allows
to change cache types more easily.
2016-10-08 15:29:21 +02:00
logmanoriginal
5ccde61a19 [FileCache] Rename 'prepare' to 'setParameters'
This is a cosmetic change to use the same naming convention for
all methods.
2016-10-08 15:04:14 +02:00
logmanoriginal
0998cbde9d [cache] Directly implement CacheInterface in FileCache
The function 'prepare' previously implemented in CacheAbstract
is specifically required for FileCache and thus belongs to FileCache.
Since this change removes all code from CacheAbstract, it can be
removed completely.
2016-10-08 14:52:03 +02:00
logmanoriginal
9ac678aac5 [Cache] Move 'purge' function to implementations
The purge function is cache specific and thus belongs
to the specific implementation.
2016-10-07 22:33:45 +02:00
logmanoriginal
51ff8de346 [Cache] Remove orphan function utf8_encode_deep 2016-10-07 22:06:58 +02:00
logmanoriginal
ee7ddcf992 [FeedExpander] Fix SimplXMLElement serialization error
Previously FeedExpander stored SimpleXMLElement objects into
the items array. These objects cannot be serialized using the
serialize function.
2016-10-02 18:07:56 +02:00
logmanoriginal
b0784e5a42 [BridgeAbstract] Don't load cache file in DEBUG mode 2016-10-02 17:00:53 +02:00
logmanoriginal
970e216c1f Merge branch 'methods2functions' of https://framagit.org/peetah/rss-bridge 2016-10-02 16:05:58 +02:00
Pierre Mazière
a1ef589ffe [core] extract BridgeAbstract methods to make them functions
Method validateData is now afunction in lib/validation.php
validateTextValue, validateNumberValue, validateCheckboxValue
and validateListValue are now anonymous functions
defined in validateData

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
2016-09-26 00:09:29 +02:00
Pierre Mazière
747be13849 [core] extract HTMLUtils methods to make them functions
Methods displayBridgeCard, sanitize, defaultImageSrcTo are now
functions in lib/html.php
getHelperButtinsFormat and getFormHeader are now anonymous functions
defined in displayBridgeCard

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
2016-09-25 23:58:52 +02:00